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,7 +92,9 @@ export default function Clusters() {
}, []);
useEffect(() => {
if (cluster != null && cluster.length > 0) {
cluster.sort((a, b) => new Date(a.created_at).getTime() - new Date(b.created_at).getTime());
cluster.sort((a, b) => {
if (a.is_default && !b.is_default) {
return -1;
@ -104,10 +106,12 @@ export default function Clusters() {
});
const totalPage = Math.ceil(cluster.length / DEFAULT_PAGE_SIZE);
const currentPageData = getPaginatedList(cluster, clusterPage, DEFAULT_PAGE_SIZE);
setTotalPages(totalPage);
setAllClusters(currentPageData);
}
}, [cluster, clusterPage]);
const numberOfDefaultClusters =
@ -201,7 +205,7 @@ export default function Clusters() {
<Box marginLeft="0.6rem">
<Box sx={{ display: 'flex', alignItems: 'center' }}>
<Typography variant="h5" sx={{ mr: '1rem' }}>
{isLoading ? <Skeleton sx={{ width: '1rem' }} /> : clusterCount?.length || ''}
{isLoading ? <Skeleton sx={{ width: '1rem' }} /> : clusterCount?.length || 0}
</Typography>
<span>number of clusters</span>
</Box>
@ -235,7 +239,7 @@ export default function Clusters() {
<Box sx={{ ml: '0.6rem' }}>
<Box sx={{ display: 'flex', alignItems: 'center' }}>
<Typography variant="h5" sx={{ mr: '1rem' }}>
{isLoading ? <Skeleton sx={{ width: '1rem' }} /> : scheduler?.length || ''}
{isLoading ? <Skeleton sx={{ width: '1rem' }} /> : scheduler?.length || 0}
</Typography>
<span>number of schedulers</span>
</Box>
@ -269,7 +273,7 @@ export default function Clusters() {
<Box sx={{ ml: '0.6rem' }}>
<Box sx={{ display: 'flex', alignItems: 'center' }}>
<Typography variant="h5" sx={{ mr: '1rem' }}>
{isLoading ? <Skeleton sx={{ width: '1rem' }} /> : seedPeer.length || ''}
{isLoading ? <Skeleton sx={{ width: '1rem' }} /> : seedPeer.length || 0}
</Typography>
<span>number of seed peers</span>
</Box>
@ -288,6 +292,7 @@ export default function Clusters() {
</Box>
</Paper>
</Grid>
{cluster != null && cluster.length > 0 ? (
<Box className={styles.searchContainer}>
<Stack spacing={2} sx={{ width: '20rem' }}>
<Autocomplete
@ -315,6 +320,9 @@ export default function Clusters() {
<SearchIcon sx={{ color: 'rgba(0,0,0,0.6)' }} />
</IconButton>
</Box>
) : (
<></>
)}
<Grid item xs={12} className={styles.clusterListContainer} component="form" noValidate>
{Array.isArray(allClusters) &&
allClusters.map((item) => (