fix: If there is no cluster console will panic will (#319)

This commit is contained in:
Zhaoxinxin 2023-11-03 11:58:06 +08:00 committed by GitHub
parent f93ae9add0
commit cbfd04915a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 51 additions and 43 deletions

View File

@ -92,22 +92,26 @@ export default function Clusters() {
}, []); }, []);
useEffect(() => { useEffect(() => {
cluster.sort((a, b) => new Date(a.created_at).getTime() - new Date(b.created_at).getTime()); if (cluster != null && cluster.length > 0) {
cluster.sort((a, b) => { cluster.sort((a, b) => new Date(a.created_at).getTime() - new Date(b.created_at).getTime());
if (a.is_default && !b.is_default) {
return -1;
} else if (!a.is_default && b.is_default) {
return 1;
} else {
return 0;
}
});
const totalPage = Math.ceil(cluster.length / DEFAULT_PAGE_SIZE); cluster.sort((a, b) => {
const currentPageData = getPaginatedList(cluster, clusterPage, DEFAULT_PAGE_SIZE); if (a.is_default && !b.is_default) {
return -1;
} else if (!a.is_default && b.is_default) {
return 1;
} else {
return 0;
}
});
setTotalPages(totalPage); const totalPage = Math.ceil(cluster.length / DEFAULT_PAGE_SIZE);
setAllClusters(currentPageData);
const currentPageData = getPaginatedList(cluster, clusterPage, DEFAULT_PAGE_SIZE);
setTotalPages(totalPage);
setAllClusters(currentPageData);
}
}, [cluster, clusterPage]); }, [cluster, clusterPage]);
const numberOfDefaultClusters = const numberOfDefaultClusters =
@ -201,7 +205,7 @@ export default function Clusters() {
<Box marginLeft="0.6rem"> <Box marginLeft="0.6rem">
<Box sx={{ display: 'flex', alignItems: 'center' }}> <Box sx={{ display: 'flex', alignItems: 'center' }}>
<Typography variant="h5" sx={{ mr: '1rem' }}> <Typography variant="h5" sx={{ mr: '1rem' }}>
{isLoading ? <Skeleton sx={{ width: '1rem' }} /> : clusterCount?.length || ''} {isLoading ? <Skeleton sx={{ width: '1rem' }} /> : clusterCount?.length || 0}
</Typography> </Typography>
<span>number of clusters</span> <span>number of clusters</span>
</Box> </Box>
@ -235,7 +239,7 @@ export default function Clusters() {
<Box sx={{ ml: '0.6rem' }}> <Box sx={{ ml: '0.6rem' }}>
<Box sx={{ display: 'flex', alignItems: 'center' }}> <Box sx={{ display: 'flex', alignItems: 'center' }}>
<Typography variant="h5" sx={{ mr: '1rem' }}> <Typography variant="h5" sx={{ mr: '1rem' }}>
{isLoading ? <Skeleton sx={{ width: '1rem' }} /> : scheduler?.length || ''} {isLoading ? <Skeleton sx={{ width: '1rem' }} /> : scheduler?.length || 0}
</Typography> </Typography>
<span>number of schedulers</span> <span>number of schedulers</span>
</Box> </Box>
@ -269,7 +273,7 @@ export default function Clusters() {
<Box sx={{ ml: '0.6rem' }}> <Box sx={{ ml: '0.6rem' }}>
<Box sx={{ display: 'flex', alignItems: 'center' }}> <Box sx={{ display: 'flex', alignItems: 'center' }}>
<Typography variant="h5" sx={{ mr: '1rem' }}> <Typography variant="h5" sx={{ mr: '1rem' }}>
{isLoading ? <Skeleton sx={{ width: '1rem' }} /> : seedPeer.length || ''} {isLoading ? <Skeleton sx={{ width: '1rem' }} /> : seedPeer.length || 0}
</Typography> </Typography>
<span>number of seed peers</span> <span>number of seed peers</span>
</Box> </Box>
@ -288,33 +292,37 @@ export default function Clusters() {
</Box> </Box>
</Paper> </Paper>
</Grid> </Grid>
<Box className={styles.searchContainer}> {cluster != null && cluster.length > 0 ? (
<Stack spacing={2} sx={{ width: '20rem' }}> <Box className={styles.searchContainer}>
<Autocomplete <Stack spacing={2} sx={{ width: '20rem' }}>
<Autocomplete
size="small"
color="secondary"
id="free-solo-demo"
freeSolo
onKeyDown={searchClusterKeyDown}
inputValue={searchClusters}
onInputChange={(_event, newInputValue) => {
setSearchClusters(newInputValue);
}}
options={(Array.isArray(clusterCount) && clusterCount.map((option) => option?.name)) || ['']}
renderInput={(params) => <TextField {...params} label="Search" />}
/>
</Stack>
<IconButton
type="button"
aria-label="search"
id="submit-button"
size="small" size="small"
color="secondary" onClick={searchCluster}
id="free-solo-demo" sx={{ width: '3rem' }}
freeSolo >
onKeyDown={searchClusterKeyDown} <SearchIcon sx={{ color: 'rgba(0,0,0,0.6)' }} />
inputValue={searchClusters} </IconButton>
onInputChange={(_event, newInputValue) => { </Box>
setSearchClusters(newInputValue); ) : (
}} <></>
options={(Array.isArray(clusterCount) && clusterCount.map((option) => option?.name)) || ['']} )}
renderInput={(params) => <TextField {...params} label="Search" />}
/>
</Stack>
<IconButton
type="button"
aria-label="search"
id="submit-button"
size="small"
onClick={searchCluster}
sx={{ width: '3rem' }}
>
<SearchIcon sx={{ color: 'rgba(0,0,0,0.6)' }} />
</IconButton>
</Box>
<Grid item xs={12} className={styles.clusterListContainer} component="form" noValidate> <Grid item xs={12} className={styles.clusterListContainer} component="form" noValidate>
{Array.isArray(allClusters) && {Array.isArray(allClusters) &&
allClusters.map((item) => ( allClusters.map((item) => (