diff --git a/portal-ui/src/screens/Console/Account/AddServiceAccountHelpBox.tsx b/portal-ui/src/screens/Console/Account/AddServiceAccountHelpBox.tsx index 0bb88cd9b..e0d0a8cde 100644 --- a/portal-ui/src/screens/Console/Account/AddServiceAccountHelpBox.tsx +++ b/portal-ui/src/screens/Console/Account/AddServiceAccountHelpBox.tsx @@ -48,7 +48,7 @@ const FeatureItem = ({ ); }; -const AddUserHelpBox = ({ hasMargin = true }: { hasMargin?: boolean }) => { +const AddServiceAccountHelpBox = () => { return ( { display: "flex", flexFlow: "column", padding: "20px", - marginLeft: { - xs: "0px", - sm: "0px", - md: hasMargin ? "30px" : "", - }, marginTop: { xs: "0px", }, @@ -144,4 +139,4 @@ const AddUserHelpBox = ({ hasMargin = true }: { hasMargin?: boolean }) => { ); }; -export default AddUserHelpBox; +export default AddServiceAccountHelpBox; diff --git a/portal-ui/src/screens/Console/Common/FormLayout.tsx b/portal-ui/src/screens/Console/Common/FormLayout.tsx new file mode 100644 index 000000000..079ca0729 --- /dev/null +++ b/portal-ui/src/screens/Console/Common/FormLayout.tsx @@ -0,0 +1,51 @@ +// This file is part of MinIO Console Server +// Copyright (c) 2022 MinIO, Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +import React from "react"; +import { Box } from "@mui/material"; +import SectionTitle from "./SectionTitle"; + +type Props = { + title: string; + icon: React.ReactNode; + helpbox?: React.ReactNode; +}; + +const FormLayout: React.FC = ({ children, title, helpbox, icon }) => { + return ( + + + {title} + {children} + + + {helpbox} + + ); +}; + +export default FormLayout; diff --git a/portal-ui/src/screens/Console/Console.tsx b/portal-ui/src/screens/Console/Console.tsx index 468be2530..d4c449933 100644 --- a/portal-ui/src/screens/Console/Console.tsx +++ b/portal-ui/src/screens/Console/Console.tsx @@ -103,7 +103,7 @@ const ObjectManager = React.lazy( const Buckets = React.lazy(() => import("./Buckets/Buckets")); const Policies = React.lazy(() => import("./Policies/Policies")); -const AddPolicy = React.lazy(() => import("./Policies/AddPolicyScreen")); +const AddPolicyScreen = React.lazy(() => import("./Policies/AddPolicyScreen")); const Dashboard = React.lazy(() => import("./Dashboard/Dashboard")); const Account = React.lazy(() => import("./Account/Account")); @@ -311,7 +311,7 @@ const Console = ({ path: IAM_PAGES.POLICIES_VIEW, }, { - component: AddPolicy, + component: AddPolicyScreen, path: IAM_PAGES.POLICY_ADD, }, { diff --git a/portal-ui/src/screens/Console/Groups/AddGroup.tsx b/portal-ui/src/screens/Console/Groups/AddGroup.tsx deleted file mode 100644 index aef9d98b2..000000000 --- a/portal-ui/src/screens/Console/Groups/AddGroup.tsx +++ /dev/null @@ -1,266 +0,0 @@ -// This file is part of MinIO Console Server -// Copyright (c) 2021 MinIO, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -import React, { useEffect, useState } from "react"; -import { connect } from "react-redux"; -import { Theme } from "@mui/material/styles"; -import createStyles from "@mui/styles/createStyles"; -import withStyles from "@mui/styles/withStyles"; -import { Button, LinearProgress } from "@mui/material"; -import Grid from "@mui/material/Grid"; -import { - formFieldStyles, - modalStyleUtils, - spacingUtils, -} from "../Common/FormComponents/common/styleLibrary"; -import { setModalErrorSnackMessage } from "../../../actions"; -import { ErrorResponseHandler } from "../../../common/types"; -import api from "../../../common/api"; -import UsersSelectors from "./UsersSelectors"; -import ModalWrapper from "../Common/ModalWrapper/ModalWrapper"; -import InputBoxWrapper from "../Common/FormComponents/InputBoxWrapper/InputBoxWrapper"; -import FormSwitchWrapper from "../Common/FormComponents/FormSwitchWrapper/FormSwitchWrapper"; -import PredefinedList from "../Common/FormComponents/PredefinedList/PredefinedList"; -import { CreateGroupIcon } from "../../../icons"; - -interface IGroupProps { - open: boolean; - selectedGroup: any; - closeModalAndRefresh: any; - classes: any; - setModalErrorSnackMessage: typeof setModalErrorSnackMessage; -} - -interface MainGroupProps { - members: string[]; - name: string; - status: string; -} - -const styles = (theme: Theme) => - createStyles({ - buttonContainer: { - textAlign: "right", - }, - userSelector: { - "& .MuiPaper-root": { - padding: 0, - marginBottom: 15, - }, - }, - ...formFieldStyles, - ...spacingUtils, - ...modalStyleUtils, - }); - -const AddGroup = ({ - open, - selectedGroup, - closeModalAndRefresh, - classes, - setModalErrorSnackMessage, -}: IGroupProps) => { - //Local States - const [groupName, setGroupName] = useState(""); - const [groupEnabled, setGroupEnabled] = useState(false); - const [saving, isSaving] = useState(false); - const [selectedUsers, setSelectedUsers] = useState([]); - const [loadingGroup, isLoadingGroup] = useState(false); - const [validGroup, setValidGroup] = useState(false); - - //Effects - useEffect(() => { - if (selectedGroup !== null) { - isLoadingGroup(true); - } else { - setGroupName(""); - setSelectedUsers([]); - } - }, [selectedGroup]); - - useEffect(() => { - setValidGroup(groupName.trim() !== ""); - }, [groupName, selectedUsers]); - - useEffect(() => { - if (saving) { - const saveRecord = () => { - if (selectedGroup !== null) { - api - .invoke("PUT", `/api/v1/group?name=${encodeURI(groupName)}`, { - group: groupName, - members: selectedUsers, - status: groupEnabled ? "enabled" : "disabled", - }) - .then((res) => { - isSaving(false); - closeModalAndRefresh(); - }) - .catch((err: ErrorResponseHandler) => { - isSaving(false); - setModalErrorSnackMessage(err); - }); - } else { - api - .invoke("POST", "/api/v1/groups", { - group: groupName, - members: selectedUsers, - }) - .then((res) => { - isSaving(false); - closeModalAndRefresh(); - }) - .catch((err: ErrorResponseHandler) => { - isSaving(false); - setModalErrorSnackMessage(err); - }); - } - }; - saveRecord(); - } - }, [ - saving, - groupName, - selectedUsers, - groupEnabled, - selectedGroup, - closeModalAndRefresh, - setModalErrorSnackMessage, - ]); - - useEffect(() => { - if (selectedGroup && loadingGroup) { - const fetchGroupInfo = () => { - api - .invoke("GET", `/api/v1/group?name=${encodeURI(selectedGroup)}`) - .then((res: MainGroupProps) => { - setGroupEnabled(res.status === "enabled"); - setGroupName(res.name); - setSelectedUsers(res.members); - }) - .catch((err: ErrorResponseHandler) => { - setModalErrorSnackMessage(err); - isLoadingGroup(false); - }); - }; - fetchGroupInfo(); - } - }, [loadingGroup, selectedGroup, setModalErrorSnackMessage]); - - //Fetch Actions - const setSaving = (event: React.FormEvent) => { - event.preventDefault(); - - isSaving(true); - }; - - const resetForm = () => { - if (selectedGroup === null) { - setGroupName(""); - } - - setSelectedUsers([]); - }; - - return ( - } - > - {selectedGroup !== null && ( -
- { - setGroupEnabled(e.target.checked); - }} - switchOnly - /> -
- )} -
- - - {selectedGroup === null ? ( - - ) => { - setGroupName(e.target.value); - }} - /> - - ) : ( - - - - )} - - - - - - - - - - {saving && ( - - - - )} - -
-
- ); -}; - -const mapDispatchToProps = { - setModalErrorSnackMessage, -}; - -const connector = connect(null, mapDispatchToProps); - -export default withStyles(styles)(connector(AddGroup)); diff --git a/portal-ui/src/screens/Console/Groups/AddGroupHelpBox.tsx b/portal-ui/src/screens/Console/Groups/AddGroupHelpBox.tsx index 3945ab767..f72395c6c 100644 --- a/portal-ui/src/screens/Console/Groups/AddGroupHelpBox.tsx +++ b/portal-ui/src/screens/Console/Groups/AddGroupHelpBox.tsx @@ -43,7 +43,7 @@ const FeatureItem = ({
); }; -const AddGroupHelpBox = ({ hasMargin = true }: { hasMargin?: boolean }) => { +const AddGroupHelpBox = () => { return ( { display: "flex", flexFlow: "column", padding: "20px", - marginLeft: { - xs: "0px", - sm: "0px", - md: hasMargin ? "30px" : "", - }, marginTop: { xs: "0px", }, diff --git a/portal-ui/src/screens/Console/Groups/AddGroupScreen.tsx b/portal-ui/src/screens/Console/Groups/AddGroupScreen.tsx index 329ab9687..fa3127d4d 100644 --- a/portal-ui/src/screens/Console/Groups/AddGroupScreen.tsx +++ b/portal-ui/src/screens/Console/Groups/AddGroupScreen.tsx @@ -23,7 +23,7 @@ import { modalStyleUtils, } from "../Common/FormComponents/common/styleLibrary"; import Grid from "@mui/material/Grid"; -import { Box, Button, LinearProgress } from "@mui/material"; +import { Button, LinearProgress } from "@mui/material"; import PageHeader from "../Common/PageHeader/PageHeader"; import PageLayout from "../Common/Layout/PageLayout"; import history from "../../../../src/history"; @@ -37,7 +37,7 @@ import { IAM_PAGES } from "../../../common/SecureComponent/permissions"; import { ErrorResponseHandler } from "../../../../src/common/types"; import api from "../../../../src/common/api"; import { setErrorSnackMessage } from "../../../../src/actions"; -import SectionTitle from "../Common/SectionTitle"; +import FormLayout from "../Common/FormLayout"; interface IAddGroupProps { classes: any; @@ -152,81 +152,60 @@ const AddGroupScreen = ({ classes, setErrorSnackMessage }: IAddGroupProps) => { label={} /> - } + helpbox={} > - -
- - - }> - Create Group - - - - - - - ) => { - setGroupName(e.target.value); - }} - /> - - - - - - - - - - - - {saving && ( - - - - )} + + + + ) => { + setGroupName(e.target.value); + }} + /> - -
- -
+ + + + + + + + + + {saving && ( + + + + )} + +
diff --git a/portal-ui/src/screens/Console/Groups/Groups.tsx b/portal-ui/src/screens/Console/Groups/Groups.tsx index 0b90e4e49..8ad1ca9e9 100644 --- a/portal-ui/src/screens/Console/Groups/Groups.tsx +++ b/portal-ui/src/screens/Console/Groups/Groups.tsx @@ -45,15 +45,14 @@ import { IAM_SCOPES, } from "../../../common/SecureComponent/permissions"; import { - SecureComponent, hasPermission, + SecureComponent, } from "../../../common/SecureComponent"; import withSuspense from "../Common/Components/withSuspense"; import RBIconButton from "../Buckets/BucketDetails/SummaryItems/RBIconButton"; const DeleteGroup = withSuspense(React.lazy(() => import("./DeleteGroup"))); -const AddGroup = withSuspense(React.lazy(() => import("../Groups/AddGroup"))); const SetPolicy = withSuspense( React.lazy(() => import("../Policies/SetPolicy")) ); @@ -80,7 +79,6 @@ const styles = (theme: Theme) => }); const Groups = ({ classes, setErrorSnackMessage, history }: IGroupsProps) => { - const [addGroupOpen, setGroupOpen] = useState(false); const [selectedGroup, setSelectedGroup] = useState(null); const [deleteOpen, setDeleteOpen] = useState(false); const [loading, isLoading] = useState(false); @@ -134,11 +132,6 @@ const Groups = ({ classes, setErrorSnackMessage, history }: IGroupsProps) => { } }, [loading, setErrorSnackMessage, displayGroups]); - const closeAddModalAndRefresh = () => { - setGroupOpen(false); - isLoading(true); - }; - const closeDeleteModalAndRefresh = (refresh: boolean) => { setDeleteOpen(false); @@ -175,13 +168,6 @@ const Groups = ({ classes, setErrorSnackMessage, history }: IGroupsProps) => { return ( - {addGroupOpen && ( - - )} {deleteOpen && ( . - -import React, { useEffect, useState } from "react"; -import { connect } from "react-redux"; -import Grid from "@mui/material/Grid"; -import { Button, LinearProgress } from "@mui/material"; -import { Theme } from "@mui/material/styles"; -import createStyles from "@mui/styles/createStyles"; -import withStyles from "@mui/styles/withStyles"; -import api from "../../../common/api"; -import { Policy } from "./types"; -import { setModalErrorSnackMessage } from "../../../actions"; -import { - fieldBasic, - modalStyleUtils, - spacingUtils, -} from "../Common/FormComponents/common/styleLibrary"; -import { ErrorResponseHandler } from "../../../common/types"; -import ModalWrapper from "../Common/ModalWrapper/ModalWrapper"; -import InputBoxWrapper from "../Common/FormComponents/InputBoxWrapper/InputBoxWrapper"; -import CodeMirrorWrapper from "../Common/FormComponents/CodeMirrorWrapper/CodeMirrorWrapper"; - -const styles = (theme: Theme) => - createStyles({ - buttonContainer: { - textAlign: "right", - }, - codeMirrorContainer: { - marginBottom: 20, - marginTop: 20, - "& label": { - marginBottom: ".5rem", - }, - "& label + div": { - display: "none", - }, - }, - ...spacingUtils, - ...modalStyleUtils, - ...fieldBasic, - }); - -interface IAddPolicyProps { - classes: any; - open: boolean; - closeModalAndRefresh: (refresh: boolean) => void; - policyEdit: Policy; - setModalErrorSnackMessage: typeof setModalErrorSnackMessage; -} - -const AddPolicy = ({ - classes, - open, - closeModalAndRefresh, - policyEdit, - setModalErrorSnackMessage, -}: IAddPolicyProps) => { - const [addLoading, setAddLoading] = useState(false); - const [policyName, setPolicyName] = useState(""); - const [policyDefinition, setPolicyDefinition] = useState(""); - - const addRecord = (event: React.FormEvent) => { - event.preventDefault(); - if (addLoading) { - return; - } - setAddLoading(true); - api - .invoke("POST", "/api/v1/policies", { - name: policyName, - policy: policyDefinition, - }) - .then((res) => { - setAddLoading(false); - - closeModalAndRefresh(true); - }) - .catch((err: ErrorResponseHandler) => { - setAddLoading(false); - setModalErrorSnackMessage(err); - }); - }; - - useEffect(() => { - if (policyEdit) { - setPolicyName(policyEdit.name); - setPolicyDefinition( - policyEdit ? JSON.stringify(JSON.parse(policyEdit.policy), null, 4) : "" - ); - } - }, [policyEdit]); - - const resetForm = () => { - setPolicyName(""); - setPolicyDefinition(""); - }; - - const validSave = policyName.trim() !== ""; - - return ( - { - closeModalAndRefresh(false); - }} - title={`${policyEdit ? "Info" : "Create"} Policy`} - > -
) => { - addRecord(e); - }} - > - - - - ) => { - setPolicyName(e.target.value); - }} - value={policyName} - disabled={!!policyEdit} - /> - - - - { - setPolicyDefinition(value); - }} - editorHeight={"350px"} - /> - - - - {!policyEdit && ( - - )} - - - - {addLoading && ( - - - - )} - -
-
- ); -}; - -const mapDispatchToProps = { - setModalErrorSnackMessage, -}; - -const connector = connect(null, mapDispatchToProps); - -export default withStyles(styles)(connector(AddPolicy)); diff --git a/portal-ui/src/screens/Console/Policies/AddPolicyHelpBox.tsx b/portal-ui/src/screens/Console/Policies/AddPolicyHelpBox.tsx index 9111b1be0..f8958f49a 100644 --- a/portal-ui/src/screens/Console/Policies/AddPolicyHelpBox.tsx +++ b/portal-ui/src/screens/Console/Policies/AddPolicyHelpBox.tsx @@ -43,7 +43,8 @@ const FeatureItem = ({
); }; -const AddPolicyHelpBox = ({ hasMargin = true }: { hasMargin?: boolean }) => { + +const AddPolicyHelpBox = () => { return ( { display: "flex", flexFlow: "column", padding: "20px", - marginLeft: { - xs: "0px", - sm: "0px", - md: hasMargin ? "30px" : "", - }, - marginTop: { - xs: "0px", - }, }} > } /> - } + helpbox={} > - - - - - Create Policy - - +
) => { + addRecord(e); + }} + > + + + ) => { + setPolicyName(e.target.value); + }} + /> + + + { + setPolicyDefinition(value); + }} + editorHeight={"350px"} + /> + + + + - - - - ) => { - addRecord(e); - }} - > - - - - - - ) => { - setPolicyName(e.target.value); - }} - /> - - - { - setPolicyDefinition(value); - }} - editorHeight={"350px"} - /> - - - - - - - - - - - - - - - - - - + + + +
+ +
diff --git a/portal-ui/src/screens/Console/Users/AddUserHelpBox.tsx b/portal-ui/src/screens/Console/Users/AddUserHelpBox.tsx index 5fc962482..598ce8423 100644 --- a/portal-ui/src/screens/Console/Users/AddUserHelpBox.tsx +++ b/portal-ui/src/screens/Console/Users/AddUserHelpBox.tsx @@ -48,7 +48,7 @@ const FeatureItem = ({
); }; -const AddUserHelpBox = ({ hasMargin = true }: { hasMargin?: boolean }) => { +const AddUserHelpBox = () => { return ( { display: "flex", flexFlow: "column", padding: "20px", - marginLeft: { - xs: "0px", - sm: "0px", - md: hasMargin ? "30px" : "", - }, marginTop: { xs: "0px", }, diff --git a/portal-ui/src/screens/Console/Users/AddUserScreen.tsx b/portal-ui/src/screens/Console/Users/AddUserScreen.tsx index d2085d490..76c6ef6ec 100644 --- a/portal-ui/src/screens/Console/Users/AddUserScreen.tsx +++ b/portal-ui/src/screens/Console/Users/AddUserScreen.tsx @@ -23,7 +23,7 @@ import { modalStyleUtils, } from "../Common/FormComponents/common/styleLibrary"; import Grid from "@mui/material/Grid"; -import { Box, Button, LinearProgress } from "@mui/material"; +import { Button, LinearProgress } from "@mui/material"; import { CreateUserIcon } from "../../../icons"; import PageHeader from "../Common/PageHeader/PageHeader"; @@ -44,8 +44,9 @@ import { ErrorResponseHandler } from "../../../../src/common/types"; import api from "../../../../src/common/api"; import { setErrorSnackMessage } from "../../../../src/actions"; -import SectionTitle from "../Common/SectionTitle"; -import AddUserHelpBox from "../Account/AddServiceAccountHelpBox"; + +import FormLayout from "../Common/FormLayout"; +import AddUserHelpBox from "./AddUserHelpBox"; interface IAddUserProps { classes: any; @@ -159,120 +160,103 @@ const AddUser = ({ classes, setErrorSnackMessage }: IAddUserProps) => { } /> - } + helpbox={} > - -
) => { - saveRecord(e); - }} - > - + ) => { + saveRecord(e); + }} + > + +
+ ) => { + setAccessKey(e.target.value); + }} + /> +
+
+ ) => { + setSecretKey(e.target.value); + }} + autoComplete="current-password" + overlayIcon={ + showPassword ? ( + + ) : ( + + ) + } + overlayAction={() => setShowPassword(!showPassword)} + /> +
+ - }> - Create User - + -
- ) => { - setAccessKey(e.target.value); - }} - /> -
-
- ) => { - setSecretKey(e.target.value); - }} - autoComplete="current-password" - overlayIcon={ - showPassword ? ( - - ) : ( - - ) - } - overlayAction={() => setShowPassword(!showPassword)} - /> -
- - - - - - { - setSelectedGroups(elements); - }} - /> - - - {addLoading && ( - - - - )} -
- - - - + { + setSelectedGroups(elements); + }} + />
- -
- -
+ {addLoading && ( + + + + )} +
+ + + + + + +