Skip to content

Commit 2305c05

Browse files
bexsoftBenjamin Perez
andauthored
Added error notifications to console (#557)
Co-authored-by: Benjamin Perez <[email protected]>
1 parent b5a3398 commit 2305c05

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1291
-1068
lines changed

portal-ui/src/actions.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// This file is part of MinIO Console Server
2-
// Copyright (c) 2020 MinIO, Inc.
2+
// Copyright (c) 2021 MinIO, Inc.
33
//
44
// This program is free software: you can redistribute it and/or modify
55
// it under the terms of the GNU Affero General Public License as published by
@@ -23,6 +23,9 @@ import {
2323
SET_LOADING_PROGRESS,
2424
SET_SNACK_BAR_MESSAGE,
2525
SET_SERVER_DIAG_STAT,
26+
SET_ERROR_SNACK_MESSAGE,
27+
SET_SNACK_MODAL_MESSAGE,
28+
SET_MODAL_ERROR_MESSAGE,
2629
} from "./types";
2730

2831
export function userLoggedIn(loggedIn: boolean) {
@@ -67,16 +70,37 @@ export const setLoadingProgress = (progress: number) => {
6770
};
6871
};
6972

73+
export const setServerDiagStat = (status: string) => {
74+
return {
75+
type: SET_SERVER_DIAG_STAT,
76+
serverDiagnosticStatus: status,
77+
};
78+
};
79+
7080
export const setSnackBarMessage = (message: string) => {
7181
return {
7282
type: SET_SNACK_BAR_MESSAGE,
73-
snackBarMessage: message,
83+
message,
7484
};
7585
};
7686

77-
export const setServerDiagStat = (status: string) => {
87+
export const setErrorSnackMessage = (message: string) => {
7888
return {
79-
type: SET_SERVER_DIAG_STAT,
80-
serverDiagnosticStatus: status,
89+
type: SET_ERROR_SNACK_MESSAGE,
90+
message,
91+
};
92+
};
93+
94+
export const setModalSnackMessage = (message: string) => {
95+
return {
96+
type: SET_SNACK_MODAL_MESSAGE,
97+
message,
98+
};
99+
};
100+
101+
export const setModalErrorSnackMessage = (message: string) => {
102+
return {
103+
type: SET_MODAL_ERROR_MESSAGE,
104+
message,
81105
};
82106
};

portal-ui/src/reducer.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ import {
2424
USER_LOGGED,
2525
SET_LOADING_PROGRESS,
2626
SET_SNACK_BAR_MESSAGE,
27+
SET_ERROR_SNACK_MESSAGE,
2728
SET_SERVER_DIAG_STAT,
29+
SET_SNACK_MODAL_MESSAGE,
30+
SET_MODAL_ERROR_MESSAGE,
2831
} from "./types";
2932

3033
const initialState: SystemState = {
@@ -36,7 +39,14 @@ const initialState: SystemState = {
3639
serverNeedsRestart: false,
3740
serverIsLoading: false,
3841
loadingProgress: 100,
39-
snackBarMessage: "",
42+
snackBar: {
43+
message: "",
44+
type: "message",
45+
},
46+
modalSnackBar: {
47+
message: "",
48+
type: "message",
49+
},
4050
serverDiagnosticStatus: "",
4151
};
4252

@@ -79,7 +89,22 @@ export function systemReducer(
7989
case SET_SNACK_BAR_MESSAGE:
8090
return {
8191
...state,
82-
snackBarMessage: action.snackBarMessage,
92+
snackBar: { message: action.message, type: "message" },
93+
};
94+
case SET_ERROR_SNACK_MESSAGE:
95+
return {
96+
...state,
97+
snackBar: { message: action.message, type: "error" },
98+
};
99+
case SET_SNACK_MODAL_MESSAGE:
100+
return {
101+
...state,
102+
modalSnackBar: { message: action.message, type: "message" },
103+
};
104+
case SET_MODAL_ERROR_MESSAGE:
105+
return {
106+
...state,
107+
modalSnackBar: { message: action.message, type: "error" },
83108
};
84109
case SET_SERVER_DIAG_STAT:
85110
return {

portal-ui/src/screens/Console/Account/Account.tsx

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

1717
import React, { useState, useEffect } from "react";
18+
import { connect } from "react-redux";
1819
import { createStyles, Theme, withStyles } from "@material-ui/core/styles";
1920
import Grid from "@material-ui/core/Grid";
2021
import api from "../../../common/api";
2122
import { Button } from "@material-ui/core";
2223
import Typography from "@material-ui/core/Typography";
2324
import { NewServiceAccount } from "../Common/CredentialsPrompt/types";
25+
import { setErrorSnackMessage } from "../../../actions";
2426
import AddServiceAccount from "./AddServiceAccount";
2527
import DeleteServiceAccount from "./DeleteServiceAccount";
2628
import CredentialsPrompt from "../Common/CredentialsPrompt/CredentialsPrompt";
@@ -39,7 +41,6 @@ import {
3941
import Divider from "@material-ui/core/Divider";
4042
import LockIcon from "@material-ui/icons/Lock";
4143
import ChangePasswordModal from "./ChangePasswordModal";
42-
import ErrorBlock from "../../shared/ErrorBlock";
4344

4445
const styles = (theme: Theme) =>
4546
createStyles({
@@ -86,12 +87,12 @@ const styles = (theme: Theme) =>
8687

8788
interface IServiceAccountsProps {
8889
classes: any;
90+
displayErrorMessage: typeof setErrorSnackMessage;
8991
}
9092

91-
const Account = ({ classes }: IServiceAccountsProps) => {
93+
const Account = ({ classes, displayErrorMessage }: IServiceAccountsProps) => {
9294
const [records, setRecords] = useState<string[]>([]);
9395
const [loading, setLoading] = useState<boolean>(false);
94-
const [error, setError] = useState<string>("");
9596
const [filter, setFilter] = useState<string>("");
9697
const [addScreenOpen, setAddScreenOpen] = useState<boolean>(false);
9798
const [deleteOpen, setDeleteOpen] = useState<boolean>(false);
@@ -121,14 +122,13 @@ const Account = ({ classes }: IServiceAccountsProps) => {
121122

122123
setLoading(false);
123124
setRecords(serviceAccounts);
124-
setError("");
125125
})
126126
.catch((err) => {
127-
setError(err);
127+
displayErrorMessage(err);
128128
setLoading(false);
129129
});
130130
}
131-
}, [loading, setLoading, setRecords, setError]);
131+
}, [loading, setLoading, setRecords, displayErrorMessage]);
132132

133133
const fetchRecords = () => {
134134
setLoading(true);
@@ -276,11 +276,6 @@ const Account = ({ classes }: IServiceAccountsProps) => {
276276
<Grid item xs={12}>
277277
<br />
278278
</Grid>
279-
{error !== "" && (
280-
<Grid item xs={12}>
281-
<ErrorBlock errorMessage={error} withBreak={false} />
282-
</Grid>
283-
)}
284279
<Grid item xs={12}>
285280
<TableWrapper
286281
isLoading={loading}
@@ -297,4 +292,8 @@ const Account = ({ classes }: IServiceAccountsProps) => {
297292
);
298293
};
299294

300-
export default withStyles(styles)(Account);
295+
const connector = connect(null, {
296+
displayErrorMessage: setErrorSnackMessage,
297+
});
298+
299+
export default withStyles(styles)(connector(Account));

portal-ui/src/screens/Console/Account/AddServiceAccount.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import ModalWrapper from "../Common/ModalWrapper/ModalWrapper";
2323
import api from "../../../common/api";
2424
import { NewServiceAccount } from "../Common/CredentialsPrompt/types";
2525
import CodeMirrorWrapper from "../Common/FormComponents/CodeMirrorWrapper/CodeMirrorWrapper";
26-
import ErrorBlock from "../../shared/ErrorBlock";
26+
import { setModalErrorSnackMessage } from "../../../actions";
27+
import { connect } from "react-redux";
2728

2829
const styles = (theme: Theme) =>
2930
createStyles({
@@ -46,15 +47,16 @@ interface IAddServiceAccountProps {
4647
classes: any;
4748
open: boolean;
4849
closeModalAndRefresh: (res: NewServiceAccount | null) => void;
50+
setModalErrorSnackMessage: typeof setModalErrorSnackMessage;
4951
}
5052

5153
const AddServiceAccount = ({
5254
classes,
5355
open,
5456
closeModalAndRefresh,
57+
setModalErrorSnackMessage,
5558
}: IAddServiceAccountProps) => {
5659
const [addSending, setAddSending] = useState(false);
57-
const [addError, setAddError] = useState("");
5860
const [policyDefinition, setPolicyDefinition] = useState("");
5961

6062
useEffect(() => {
@@ -65,18 +67,17 @@ const AddServiceAccount = ({
6567
})
6668
.then((res) => {
6769
setAddSending(false);
68-
setAddError("");
6970
closeModalAndRefresh(res);
7071
})
7172
.catch((err) => {
7273
setAddSending(false);
73-
setAddError(err);
74+
setModalErrorSnackMessage(err);
7475
});
7576
}
7677
}, [
7778
addSending,
7879
setAddSending,
79-
setAddError,
80+
setModalErrorSnackMessage,
8081
policyDefinition,
8182
closeModalAndRefresh,
8283
]);
@@ -107,11 +108,6 @@ const AddServiceAccount = ({
107108
>
108109
<Grid container>
109110
<Grid item xs={12} className={classes.formScrollable}>
110-
{addError !== "" && (
111-
<Grid item xs={12}>
112-
<ErrorBlock errorMessage={addError} withBreak={false} />
113-
</Grid>
114-
)}
115111
<div className={classes.infoDetails}>
116112
Service Accounts inherit the policy explicitly attached to the
117113
parent user and the policy attached to each group in which the
@@ -157,4 +153,10 @@ const AddServiceAccount = ({
157153
);
158154
};
159155

160-
export default withStyles(styles)(AddServiceAccount);
156+
const mapDispatchToProps = {
157+
setModalErrorSnackMessage,
158+
};
159+
160+
const connector = connect(null, mapDispatchToProps);
161+
162+
export default withStyles(styles)(connector(AddServiceAccount));

portal-ui/src/screens/Console/Account/ChangePasswordModal.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

1717
import React, { useState } from "react";
18+
import { connect } from "react-redux";
1819
import { createStyles, Theme, withStyles } from "@material-ui/core/styles";
1920
import ModalWrapper from "../Common/ModalWrapper/ModalWrapper";
2021
import Grid from "@material-ui/core/Grid";
@@ -27,7 +28,7 @@ import {
2728
} from "../Common/FormComponents/common/styleLibrary";
2829
import { ChangePasswordRequest } from "../Buckets/types";
2930
import api from "../../../common/api";
30-
import ErrorBlock from "../../shared/ErrorBlock";
31+
import { setModalErrorSnackMessage } from "../../../actions";
3132

3233
const styles = (theme: Theme) =>
3334
createStyles({
@@ -43,24 +44,25 @@ interface IChangePasswordProps {
4344
classes: any;
4445
open: boolean;
4546
closeModal: () => void;
47+
setModalErrorSnackMessage: typeof setModalErrorSnackMessage;
4648
}
4749

4850
const ChangePassword = ({
4951
classes,
5052
open,
5153
closeModal,
54+
setModalErrorSnackMessage,
5255
}: IChangePasswordProps) => {
5356
const [currentPassword, setCurrentPassword] = useState<string>("");
5457
const [newPassword, setNewPassword] = useState<string>("");
5558
const [reNewPassword, setReNewPassword] = useState<string>("");
5659
const [loading, setLoading] = useState<boolean>(false);
57-
const [error, setError] = useState<string>("");
5860

5961
const changePassword = (event: React.FormEvent) => {
6062
event.preventDefault();
6163

6264
if (newPassword !== reNewPassword) {
63-
setError("New passwords don't match");
65+
setModalErrorSnackMessage("New passwords don't match");
6466
return;
6567
}
6668

@@ -78,7 +80,6 @@ const ChangePassword = ({
7880
.invoke("POST", "/api/v1/account/change-password", request)
7981
.then((res) => {
8082
setLoading(false);
81-
setError("");
8283
setNewPassword("");
8384
setReNewPassword("");
8485
setCurrentPassword("");
@@ -89,7 +90,7 @@ const ChangePassword = ({
8990
setNewPassword("");
9091
setReNewPassword("");
9192
setCurrentPassword("");
92-
setError(err);
93+
setModalErrorSnackMessage(err);
9394
});
9495
};
9596

@@ -115,11 +116,6 @@ const ChangePassword = ({
115116
>
116117
<Grid container>
117118
<Grid item xs={12} className={classes.formScrollable}>
118-
{error !== "" && (
119-
<Grid item xs={12}>
120-
<ErrorBlock errorMessage={error} />
121-
</Grid>
122-
)}
123119
<Grid item xs={12}>
124120
<InputBoxWrapper
125121
id="current-password"
@@ -185,4 +181,8 @@ const ChangePassword = ({
185181
) : null;
186182
};
187183

188-
export default withStyles(styles)(ChangePassword);
184+
const connector = connect(null, {
185+
setModalErrorSnackMessage,
186+
});
187+
188+
export default withStyles(styles)(connector(ChangePassword));

0 commit comments

Comments
 (0)