Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce renders in password when adding a user #2120

Merged
merged 1 commit into from
Jun 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 8 additions & 35 deletions portal-ui/src/screens/Console/Users/AddUserScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import UserSelector from "./UserSelector";
import PasswordSelector from "./PasswordSelector";
import React, { Fragment } from "react";
import { Theme } from "@mui/material/styles";
import createStyles from "@mui/styles/createStyles";
Expand All @@ -30,14 +31,11 @@ import { CreateUserIcon } from "../../../icons";

import PageHeader from "../Common/PageHeader/PageHeader";
import PageLayout from "../Common/Layout/PageLayout";
import InputBoxWrapper from "../Common/FormComponents/InputBoxWrapper/InputBoxWrapper";

import PolicySelectors from "../Policies/PolicySelectors";
import BackLink from "../../../common/BackLink";
import GroupsSelectors from "./GroupsSelectors";

import RemoveRedEyeIcon from "@mui/icons-material/RemoveRedEye";
import VisibilityOffIcon from "@mui/icons-material/VisibilityOff";
import { IAM_PAGES } from "../../../common/SecureComponent/permissions";
import { useNavigate } from "react-router-dom";
import FormLayout from "../Common/FormLayout";
Expand All @@ -49,8 +47,6 @@ import {AppState} from "../../../store";
import {
setSelectedGroups,
setAddLoading,
setShowPassword,
setSecretKey,
setSendEnabled,
} from "./AddUsersSlice";
interface IAddUserProps {
Expand Down Expand Up @@ -78,29 +74,28 @@ const styles = (theme: Theme) =>

const AddUser = ({ classes }: IAddUserProps) => {
const dispatch = useAppDispatch();
const showPassword = useSelector(
(state: AppState) => state.createUser.showPassword
)
const selectedPolicies = useSelector(
(state: AppState) => state.createUser.selectedPolicies
)
const selectedGroups = useSelector(
(state: AppState) => state.createUser.selectedGroups
)
const secretKey = useSelector(
(state: AppState) => state.createUser.secretKey
)
const addLoading = useSelector(
(state: AppState) => state.createUser.addLoading
)
const sendEnabled = useSelector(
(state: AppState) => state.createUser.sendEnabled
)
const secretKeylength = useSelector(
(state: AppState) => state.createUser.secretKeylength
)
const navigate = useNavigate();
dispatch(setSendEnabled());


const saveRecord = (event: React.FormEvent) => {
event.preventDefault();
if (secretKey.length < 8) {
if (secretKeylength < 8) {
dispatch(
setErrorSnackMessage({
errorMessage: "Passwords must be at least 8 characters long",
Expand Down Expand Up @@ -141,29 +136,7 @@ const AddUser = ({ classes }: IAddUserProps) => {
<UserSelector classes={classes} />
</div>
<div className={classes.formFieldRow}>
<InputBoxWrapper
className={classes.spacerBottom}
classes={{
inputLabel: classes.sizedLabel,
}}
id="standard-multiline-static"
name="standard-multiline-static"
label="Password"
type={showPassword ? "text" : "password"}
value={secretKey}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
dispatch(setSecretKey(e.target.value));
}}
autoComplete="current-password"
overlayIcon={
showPassword ? (
<VisibilityOffIcon />
) : (
<RemoveRedEyeIcon />
)
}
overlayAction={() => dispatch(setShowPassword(!showPassword))}
/>
<PasswordSelector classes={classes} />
</div>
<Grid container item spacing="20">
<Grid item xs={12}>
Expand Down
3 changes: 3 additions & 0 deletions portal-ui/src/screens/Console/Users/AddUsersSlice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface ICreateUser {
sendEnabled: boolean;
addLoading: boolean;
apinoerror: boolean;
secretKeylength: number;
}

const initialState: ICreateUser = {
Expand All @@ -39,6 +40,7 @@ const initialState: ICreateUser = {
secretKey: "",
selectedGroups: [],
selectedPolicies: [],
secretKeylength: 0,
};

export const createUserSlice = createSlice({
Expand All @@ -56,6 +58,7 @@ export const createUserSlice = createSlice({
},
setSecretKey: (state, action: PayloadAction<string>) => {
state.secretKey = action.payload;
state.secretKeylength = state.secretKey.length;
},
setSelectedPolicies: (state, action: PayloadAction<string[]>) => {
state.selectedPolicies = action.payload;
Expand Down
63 changes: 63 additions & 0 deletions portal-ui/src/screens/Console/Users/PasswordSelector.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// 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 <http://www.gnu.org/licenses/>.

import React from "react";
import InputBoxWrapper from "../Common/FormComponents/InputBoxWrapper/InputBoxWrapper";
import {setSecretKey, setShowPassword} from "./AddUsersSlice";
import { useSelector } from "react-redux";
import {AppState, useAppDispatch} from "../../../store";
import VisibilityOffIcon from "@mui/icons-material/VisibilityOff";
import RemoveRedEyeIcon from "@mui/icons-material/RemoveRedEye";

interface IAddUserProps2 {
classes: any;
}

const PasswordSelector = ({ classes }: IAddUserProps2 ) => {
const dispatch = useAppDispatch();
const showPassword = useSelector(
(state: AppState) => state.createUser.showPassword
)
const secretKey = useSelector(
(state: AppState) => state.createUser.secretKey
)
return (
<InputBoxWrapper
className={classes.spacerBottom}
classes={{
inputLabel: classes.sizedLabel,
}}
id="standard-multiline-static"
name="standard-multiline-static"
label="Password"
type={showPassword ? "text" : "password"}
value={secretKey}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
dispatch(setSecretKey(e.target.value));
}}
autoComplete="current-password"
overlayIcon={
showPassword ? (
<VisibilityOffIcon />
) : (
<RemoveRedEyeIcon />
)
}
overlayAction={() => dispatch(setShowPassword(!showPassword))}
/>
);
};
export default PasswordSelector;