-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
382 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import { Context } from '@appTypes/context.ts'; | ||
import defaultTheme from '@layouts/DefaultTheme.ts'; | ||
import { Box, ThemeProvider } from '@mui/system'; | ||
import { useStore } from '@nanostores/react'; | ||
import axios from 'axios'; | ||
import React, { useCallback, useEffect, useMemo, useState } from 'react'; | ||
|
||
import FetchingBackdrop from '../backdrop/backdrop.tsx'; | ||
import VDiskTable from '../VDiskTable/VDiskTable.tsx'; | ||
|
||
const stubVDisk: VDisk = { | ||
id: 0, | ||
status: 'Offline', | ||
partition_count: 0, | ||
replicas: [], | ||
}; | ||
|
||
axios.defaults.withCredentials = true; | ||
|
||
const VDiskPage = () => { | ||
const [vdisks, setVdisks] = useState<VDisk[]>([]); | ||
const [vdiskList, setVdiskList] = useState<DTOVDisk[]>([]); | ||
const [isPageLoaded, setIsPageLoaded] = useState(false); | ||
const context = useStore(Context); | ||
|
||
const fetchVdiskList = useMemo( | ||
() => async () => { | ||
try { | ||
const [res] = await Promise.all([axios.get<DTOVDisk[]>('/api/v1/vdisks/list')]); | ||
setVdisks( | ||
res.data | ||
.map((dtoVdisk: DTOVDisk) => { | ||
return { | ||
...stubVDisk, | ||
id: dtoVdisk.id, | ||
} as VDisk; | ||
}) | ||
.sort((a, b) => (a.id < b.id ? -1 : 1)), | ||
); | ||
setVdiskList(res.data); | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
}, | ||
[], | ||
); | ||
|
||
const fetchVdisk = useCallback( | ||
(vdisk: number) => async () => { | ||
try { | ||
const [res] = await Promise.all([axios.get<VDisk>('/api/v1/vdisks/' + vdisk)]); | ||
return res.data; | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
}, | ||
[], | ||
); | ||
useEffect(() => { | ||
fetchVdiskList(); | ||
}, [fetchVdiskList]); | ||
|
||
useEffect(() => { | ||
const fetchNodes = async () => { | ||
const res = ( | ||
await Promise.all( | ||
vdiskList.map(async (vdisk) => { | ||
return fetchVdisk(vdisk.id)() | ||
.catch(console.error) | ||
.then((resultVdisk) => resultVdisk); | ||
}), | ||
) | ||
).filter((vdisk): vdisk is VDisk => { | ||
return typeof vdisk !== undefined; | ||
}); | ||
setVdisks(res.concat(vdisks.filter((item) => !res.find((n) => (n?.id || '') == item.id)))); | ||
}; | ||
if (!isPageLoaded && vdiskList.length !== 0) { | ||
fetchNodes(); | ||
setIsPageLoaded(true); | ||
} | ||
const interval = setInterval(() => { | ||
fetchNodes(); | ||
}, context.refreshTime * 1000); | ||
|
||
return () => clearInterval(interval); | ||
}, [isPageLoaded, fetchVdisk, context.enabled, context.refreshTime, vdiskList, vdisks]); | ||
|
||
if (!isPageLoaded) { | ||
return <FetchingBackdrop />; | ||
} | ||
return ( | ||
<ThemeProvider theme={defaultTheme}> | ||
<Box | ||
sx={{ | ||
marginLeft: '52px', | ||
marginRight: '52px', | ||
marginTop: '38px', | ||
'&:hover': { | ||
color: '#282A2F', | ||
}, | ||
height: '820px', | ||
backgroundColor: '#1F2125', | ||
borderColor: '#2E2E33', | ||
border: '1', | ||
}} | ||
> | ||
<VDiskTable vdisks={vdisks} /> | ||
</Box> | ||
</ThemeProvider> | ||
); | ||
}; | ||
|
||
export default VDiskPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
.greendot { | ||
height: 16px; | ||
width: 16px; | ||
background-color: #34b663; | ||
border-radius: 50%; | ||
display: inline-block; | ||
} | ||
|
||
.reddot { | ||
height: 16px; | ||
width: 16px; | ||
background-color: #c3234b; | ||
border-radius: 50%; | ||
display: inline-block; | ||
} | ||
|
||
.graydot { | ||
height: 16px; | ||
width: 16px; | ||
background-color: #7b817e; | ||
border-radius: 50%; | ||
display: inline-block; | ||
} | ||
|
||
.greyHeader { | ||
background-color: #35373c; | ||
} |
Oops, something went wrong.