123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- import { FC, useState } from 'react';
- import { useTranslation } from 'react-i18next';
- import { makeStyles, Theme } from '@material-ui/core';
- import KeyboardArrowDown from '@material-ui/icons/KeyboardArrowDown';
- import { DataGrid } from '@mui/x-data-grid';
- import { useNavigationHook } from '../../hooks/Navigation';
- import { ALL_ROUTER_TYPES } from '../../router/Types';
- import MiniTopo from './MiniTopology';
- import { getByteString } from './Progress';
- import DataCard from './DataCard';
- import { NodeListViewProps, Node } from './Types';
- const getStyles = makeStyles((theme: Theme) => ({
- root: {
- fontFamily: 'Roboto',
- margin: '14px 40px',
- display: 'grid',
- gridTemplateColumns: 'auto 400px',
- gridTemplateRows: '40px 400px auto',
- gridTemplateAreas:
- `"a a"
- "b ."
- "b d"`,
- height: 'calc(100% - 28px)',
- },
- cardContainer: {
- display: 'grid',
- gap: '16px',
- gridTemplateColumns: 'repeat(4, minmax(300px, 1fr))',
- },
- contentContainer: {
- borderRadius: '8px',
- boxShadow: '3px 3px 10px rgba(0, 0, 0, 0.05)',
- display: 'grid',
- marginTop: '14px',
- },
- childView: {
- height: '100%',
- width: '100%',
- transition: 'all .25s',
- position: 'absolute',
- zIndex: 1000,
- backgroundColor: 'white',
- },
- childCloseBtn: {
- border: 0,
- backgroundColor: 'white',
- gridArea: 'a',
- cursor: 'pointer',
- width: '100%',
- },
- gridContainer: {
- gridArea: 'b',
- display: 'flex',
- },
- dataCard: {
- gridArea: 'd',
- }
- }));
- const NodeListView: FC<NodeListViewProps> = (props) => {
- useNavigationHook(ALL_ROUTER_TYPES.SYSTEM);
- const { t } = useTranslation('systemView');
- const { t: commonTrans } = useTranslation();
- const capacityTrans: { [key in string]: string } = commonTrans('capacity');
- const classes = getStyles();
- const [selectedChildNode, setSelectedChildNode] = useState<Node | undefined>();
- const { selectedCord, childNodes, setCord } = props;
- let rows: any[] = [];
- let columns: any[] = [
- {
- field: 'name',
- headerName: t('thName'),
- flex: 1,
- },
- {
- field: 'ip',
- headerName: t('thIP'),
- flex: 1,
- },
- {
- field: 'cpuCore',
- headerName: t('thCPUCount'),
- flex: 1,
- },
- {
- field: 'cpuUsage',
- headerName: t('thCPUUsage'),
- flex: 1,
- },
- {
- field: 'diskUsage',
- headerName: t('thDiskUsage'),
- flex: 1,
- },
- {
- field: 'memUsage',
- headerName: t('thMemUsage'),
- flex: 1,
- },
- ];
- if (selectedCord) {
- const connectedIds = selectedCord.connected.map(node => node.connected_identifier);
- rows = [];
- childNodes.forEach(node => {
- if (connectedIds.includes(node.identifier)) {
- const dataRow = {
- id: node?.identifier,
- ip: node?.infos?.hardware_infos.ip,
- cpuCore: node?.infos?.hardware_infos.cpu_core_count,
- cpuUsage: node?.infos?.hardware_infos.cpu_core_usage,
- diskUsage: getByteString(node?.infos?.hardware_infos.disk_usage, node?.infos?.hardware_infos.disk, capacityTrans),
- memUsage: getByteString(node?.infos?.hardware_infos.memory_usage, node?.infos?.hardware_infos.memory, capacityTrans),
- name: node?.infos?.name,
- }
- rows.push(dataRow);
- }
- })
- }
- return (
- <div className={classes.root}>
- <button className={classes.childCloseBtn} onClick={() => setCord(null)}>
- <KeyboardArrowDown />
- </button>
- <div className={classes.gridContainer}>
- <DataGrid
- rows={rows}
- columns={columns}
- hideFooterPagination
- hideFooterSelectedRowCount
- onRowClick={(rowData) => {
- const selectedNode = childNodes.find(node => rowData.row.id === node.identifier);
- setSelectedChildNode(selectedNode);
- }}
- />
- </div>
- <MiniTopo selectedCord={selectedCord} setCord={setCord} selectedChildNode={selectedChildNode} />
- <DataCard className={classes.dataCard} node={selectedChildNode} />
- </div>
- );
- };
- export default NodeListView;
|