Skip to content

Commit

Permalink
fix: change all page names (#261)
Browse files Browse the repository at this point in the history
Signed-off-by: zhaoxinxin <[email protected]>
  • Loading branch information
Liam-Zhao authored Aug 18, 2023
1 parent 3d0abf3 commit 0be29ce
Show file tree
Hide file tree
Showing 13 changed files with 265 additions and 256 deletions.
73 changes: 36 additions & 37 deletions src/components/clusters/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import styles from './edit.module.css';
import HelpIcon from '@mui/icons-material/Help';
import { useEffect, useState } from 'react';
import { getCluster, updateCluster } from '../../lib/api';
import React from 'react';
import CancelIcon from '@mui/icons-material/Cancel';
import CheckCircleIcon from '@mui/icons-material/CheckCircle';
import { useNavigate, useParams } from 'react-router-dom';
Expand All @@ -26,7 +25,7 @@ export default function EditCluster() {
const [successMessage, setSuccessMessage] = useState(false);
const [errorMessage, setErrorMessage] = useState(false);
const [errorMessageText, setErrorMessageText] = useState('');
const [bioError, setbioError] = useState(false);
const [bioError, setBioError] = useState(false);
const [seedPeerLoadLimitError, setSeedPeerLoadLimitError] = useState(false);
const [peerLoadLimitError, setPeerLoadLimitError] = useState(false);
const [numberOfConcurrentDownloadPiecesError, setNumberOfConcurrentDownloadPiecesError] = useState(false);
Expand All @@ -35,8 +34,8 @@ export default function EditCluster() {
const [locationError, setLocationError] = useState(false);
const [idcError, setIDCError] = useState(false);
const [cidrsError, setCIDRsError] = useState(false);
const [editLoadingButton, setEditLoadingButton] = useState(false);
const [clusters, setClusters] = useState({
const [loadingButton, setLoadingButton] = useState(false);
const [cluster, setCluster] = useState({
id: 0,
bio: '',
scopes: {
Expand Down Expand Up @@ -73,14 +72,14 @@ export default function EditCluster() {
scheduler_cluster_config: { candidate_parent_limit, filter_parent_limit },
scopes: { idc, location, cidrs },
seed_peer_cluster_config,
} = clusters;
} = cluster;

useEffect(() => {
(async function () {
try {
if (typeof params.id === 'string') {
const response = await getCluster(params.id);
setClusters(response);
const cluster = await getCluster(params.id);
setCluster(cluster);
}
} catch (error) {
if (error instanceof Error) {
Expand All @@ -99,17 +98,17 @@ export default function EditCluster() {
name: 'bio',
autoComplete: 'family-name',
value: bio,
placeholder: 'Please enter Description',
helperText: bioError ? 'Must be a number and range from 0-1000' : '',
placeholder: 'Please enter description',
helperText: bioError ? 'The length is 1-1000' : '',
error: bioError,

onChange: (e: any) => {
setClusters({ ...clusters, bio: e.target.value });
setCluster({ ...cluster, bio: e.target.value });
changeValidate(e.target.value, informationForm[0]);
},
},
syncError: false,
setError: setbioError,
setError: setBioError,

validate: (value: string) => {
const reg = /^.{0,1000}$/;
Expand All @@ -131,7 +130,7 @@ export default function EditCluster() {
error: locationError,

onChange: (e: any) => {
setClusters({ ...clusters, scopes: { ...clusters.scopes, location: e.target.value } });
setCluster({ ...cluster, scopes: { ...cluster.scopes, location: e.target.value } });
changeValidate(e.target.value, scopesForm[0]);
},
InputProps: {
Expand Down Expand Up @@ -166,7 +165,7 @@ export default function EditCluster() {
helperText: idcError ? 'Maximum length is 100' : '',
error: idcError,
onChange: (e: any) => {
setClusters({ ...clusters, scopes: { ...clusters.scopes, idc: e.target.value } });
setCluster({ ...cluster, scopes: { ...cluster.scopes, idc: e.target.value } });
changeValidate(e.target.value, scopesForm[1]);
},
InputProps: {
Expand Down Expand Up @@ -198,7 +197,7 @@ export default function EditCluster() {

onChange: (_e: any, newValue: any) => {
if (!scopesForm[2].formProps.error) {
setClusters({ ...clusters, scopes: { ...clusters.scopes, cidrs: newValue } });
setCluster({ ...cluster, scopes: { ...cluster.scopes, cidrs: newValue } });
}
},
onInputChange: (e: any) => {
Expand Down Expand Up @@ -245,9 +244,9 @@ export default function EditCluster() {
error: seedPeerLoadLimitError,

onChange: (e: any) => {
setClusters({
...clusters,
seed_peer_cluster_config: { ...clusters.seed_peer_cluster_config, load_limit: e.target.value },
setCluster({
...cluster,
seed_peer_cluster_config: { ...cluster.seed_peer_cluster_config, load_limit: e.target.value },
});
changeValidate(e.target.value, configForm[0]);
},
Expand Down Expand Up @@ -283,9 +282,9 @@ export default function EditCluster() {
value: load_limit,

onChange: (e: any) => {
setClusters({
...clusters,
peer_cluster_config: { ...clusters.peer_cluster_config, load_limit: e.target.value },
setCluster({
...cluster,
peer_cluster_config: { ...cluster.peer_cluster_config, load_limit: e.target.value },
});
changeValidate(e.target.value, configForm[1]);
},
Expand Down Expand Up @@ -323,9 +322,9 @@ export default function EditCluster() {
error: numberOfConcurrentDownloadPiecesError,

onChange: (e: any) => {
setClusters({
...clusters,
peer_cluster_config: { ...clusters.peer_cluster_config, concurrent_piece_count: e.target.value },
setCluster({
...cluster,
peer_cluster_config: { ...cluster.peer_cluster_config, concurrent_piece_count: e.target.value },
});
changeValidate(e.target.value, configForm[2]);
},
Expand Down Expand Up @@ -362,10 +361,10 @@ export default function EditCluster() {
error: candidateParentLimitError,

onChange: (e: any) => {
setClusters({
...clusters,
setCluster({
...cluster,
scheduler_cluster_config: {
...clusters.scheduler_cluster_config,
...cluster.scheduler_cluster_config,
candidate_parent_limit: e.target.value,
},
});
Expand Down Expand Up @@ -404,10 +403,10 @@ export default function EditCluster() {
error: filterParentLimitError,

onChange: (e: any) => {
setClusters({
...clusters,
setCluster({
...cluster,
scheduler_cluster_config: {
...clusters.scheduler_cluster_config,
...cluster.scheduler_cluster_config,
filter_parent_limit: e.target.value,
},
});
Expand Down Expand Up @@ -449,7 +448,7 @@ export default function EditCluster() {
};

const handleSubmit = async (event: any) => {
setEditLoadingButton(true);
setLoadingButton(true);
event.preventDefault();
const data = new FormData(event.currentTarget);

Expand Down Expand Up @@ -495,18 +494,18 @@ export default function EditCluster() {
if (canSubmit && typeof params.id === 'string') {
try {
await updateCluster(params.id, { ...formdata });
setEditLoadingButton(false);
setLoadingButton(false);
setSuccessMessage(true);
navigate(`/clusters/${params.id}`);
} catch (error) {
if (error instanceof Error) {
setErrorMessage(true);
setErrorMessageText(error.message);
setEditLoadingButton(false);
setLoadingButton(false);
}
}
} else {
setEditLoadingButton(false);
setLoadingButton(false);
}
};

Expand Down Expand Up @@ -551,7 +550,7 @@ export default function EditCluster() {
<Checkbox
checked={is_default}
onChange={(event: { target: { checked: any } }) => {
setClusters({ ...clusters, is_default: event.target.checked });
setCluster({ ...cluster, is_default: event.target.checked });
}}
sx={{ '&.MuiCheckbox-root': { color: 'var(--button-color)' } }}
/>
Expand Down Expand Up @@ -629,7 +628,7 @@ export default function EditCluster() {
</Grid>
<Box className={styles.footerButton}>
<LoadingButton
loading={editLoadingButton}
loading={loadingButton}
endIcon={<CancelIcon sx={{ color: 'var(--button-color)' }} />}
size="small"
variant="outlined"
Expand All @@ -653,14 +652,14 @@ export default function EditCluster() {
width: '8rem',
}}
onClick={() => {
setEditLoadingButton(true);
setLoadingButton(true);
navigate(`/clusters/${id}`);
}}
>
Cancel
</LoadingButton>
<LoadingButton
loading={editLoadingButton}
loading={loadingButton}
endIcon={<CheckCircleIcon />}
size="small"
variant="outlined"
Expand Down
6 changes: 3 additions & 3 deletions src/components/clusters/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ export default function Clusters() {
const searchCluster = async (event: any) => {
try {
setClusterIsLoading(true);
const response = await getClusters({ page: 1, per_page: pageSize, name: searchClusters });
setAllClusters(response.data);
setTotalPages(response.total_page || 1);
const cluster = await getClusters({ page: 1, per_page: pageSize, name: searchClusters });
setAllClusters(cluster.data);
setTotalPages(cluster.total_page || 1);
setClusterIsLoading(false);
} catch (error) {
if (error instanceof Error) {
Expand Down
19 changes: 10 additions & 9 deletions src/components/clusters/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function NewCluster() {
const [idcError, setIDCError] = useState(false);
const [cidrsError, setCIDRsError] = useState(false);
const [cidrs, setCIDRs] = useState([]);
const [editLoadingButton, setEditLoadingButton] = useState(false);
const [loadingButton, setLoadingButton] = useState(false);
const cidrsOptions = ['10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16'];
const navigate = useNavigate();

Expand Down Expand Up @@ -70,7 +70,7 @@ export default function NewCluster() {
name: 'description',
autoComplete: 'family-name',
placeholder: 'Enter a cluster description',
helperText: bioError ? 'The length is 0-40' : '',
helperText: bioError ? 'The length is 1-1000' : '',
error: bioError,

onChange: (e: any) => {
Expand Down Expand Up @@ -382,10 +382,11 @@ export default function NewCluster() {
];

const handleSubmit = async (event: any) => {
setEditLoadingButton(true);
setLoadingButton(true);

event.preventDefault();
const data = new FormData(event.currentTarget);

const name = event.currentTarget.elements.name.value;
const isDefault = event.currentTarget.elements.isDefault.checked;
const description = event.currentTarget.elements.description.value;
Expand Down Expand Up @@ -446,18 +447,18 @@ export default function NewCluster() {
if (canSubmit) {
try {
await createCluster({ ...formData });
setEditLoadingButton(false);
setLoadingButton(false);
setSuccessMessage(true);
navigate('/clusters');
} catch (error) {
if (error instanceof Error) {
setErrorMessage(true);
setErrorMessageText(error.message);
setEditLoadingButton(false);
setLoadingButton(false);
}
}
} else {
setEditLoadingButton(false);
setLoadingButton(false);
}
};

Expand Down Expand Up @@ -588,7 +589,7 @@ export default function NewCluster() {
</Grid>
<Box className={styles.footerButton}>
<LoadingButton
loading={editLoadingButton}
loading={loadingButton}
endIcon={<CancelIcon sx={{ color: 'var(--button-color)' }} />}
size="small"
variant="outlined"
Expand All @@ -612,14 +613,14 @@ export default function NewCluster() {
width: '8rem',
}}
onClick={() => {
setEditLoadingButton(true);
setLoadingButton(true);
navigate(`/clusters`);
}}
>
Cancel
</LoadingButton>
<LoadingButton
loading={editLoadingButton}
loading={loadingButton}
endIcon={<CheckCircleIcon />}
size="small"
variant="outlined"
Expand Down
Loading

0 comments on commit 0be29ce

Please sign in to comment.