NodeListView.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. import { FC, useState } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import { makeStyles, Theme } from '@material-ui/core';
  4. import KeyboardArrowDown from '@material-ui/icons/KeyboardArrowDown';
  5. import { DataGrid } from '@mui/x-data-grid';
  6. import { useNavigationHook } from '../../hooks/Navigation';
  7. import { ALL_ROUTER_TYPES } from '../../router/Types';
  8. import MiniTopo from './MiniTopology';
  9. import { getByteString } from './Progress';
  10. import DataCard from './DataCard';
  11. import { NodeListViewProps, Node } from './Types';
  12. const getStyles = makeStyles((theme: Theme) => ({
  13. root: {
  14. fontFamily: 'Roboto',
  15. margin: '14px 40px',
  16. display: 'grid',
  17. gridTemplateColumns: 'auto 400px',
  18. gridTemplateRows: '40px 400px auto',
  19. gridTemplateAreas:
  20. `"a a"
  21. "b ."
  22. "b d"`,
  23. height: 'calc(100% - 28px)',
  24. },
  25. cardContainer: {
  26. display: 'grid',
  27. gap: '16px',
  28. gridTemplateColumns: 'repeat(4, minmax(300px, 1fr))',
  29. },
  30. contentContainer: {
  31. borderRadius: '8px',
  32. boxShadow: '3px 3px 10px rgba(0, 0, 0, 0.05)',
  33. display: 'grid',
  34. marginTop: '14px',
  35. },
  36. childView: {
  37. height: '100%',
  38. width: '100%',
  39. transition: 'all .25s',
  40. position: 'absolute',
  41. zIndex: 1000,
  42. backgroundColor: 'white',
  43. },
  44. childCloseBtn: {
  45. border: 0,
  46. backgroundColor: 'white',
  47. gridArea: 'a',
  48. cursor: 'pointer',
  49. width: '100%',
  50. },
  51. gridContainer: {
  52. gridArea: 'b',
  53. display: 'flex',
  54. },
  55. dataCard: {
  56. gridArea: 'd',
  57. }
  58. }));
  59. const NodeListView: FC<NodeListViewProps> = (props) => {
  60. useNavigationHook(ALL_ROUTER_TYPES.SYSTEM);
  61. const { t } = useTranslation('systemView');
  62. const { t: commonTrans } = useTranslation();
  63. const capacityTrans: { [key in string]: string } = commonTrans('capacity');
  64. const classes = getStyles();
  65. const [selectedChildNode, setSelectedChildNode] = useState<Node | undefined>();
  66. const { selectedCord, childNodes, setCord } = props;
  67. let rows: any[] = [];
  68. let columns: any[] = [
  69. {
  70. field: 'name',
  71. headerName: t('thName'),
  72. flex: 1,
  73. },
  74. {
  75. field: 'ip',
  76. headerName: t('thIP'),
  77. flex: 1,
  78. },
  79. {
  80. field: 'cpuCore',
  81. headerName: t('thCPUCount'),
  82. flex: 1,
  83. },
  84. {
  85. field: 'cpuUsage',
  86. headerName: t('thCPUUsage'),
  87. flex: 1,
  88. },
  89. {
  90. field: 'diskUsage',
  91. headerName: t('thDiskUsage'),
  92. flex: 1,
  93. },
  94. {
  95. field: 'memUsage',
  96. headerName: t('thMemUsage'),
  97. flex: 1,
  98. },
  99. ];
  100. if (selectedCord) {
  101. const connectedIds = selectedCord.connected.map(node => node.connected_identifier);
  102. rows = [];
  103. childNodes.forEach(node => {
  104. if (connectedIds.includes(node.identifier)) {
  105. const dataRow = {
  106. id: node?.identifier,
  107. ip: node?.infos?.hardware_infos.ip,
  108. cpuCore: node?.infos?.hardware_infos.cpu_core_count,
  109. cpuUsage: node?.infos?.hardware_infos.cpu_core_usage,
  110. diskUsage: getByteString(node?.infos?.hardware_infos.disk_usage, node?.infos?.hardware_infos.disk, capacityTrans),
  111. memUsage: getByteString(node?.infos?.hardware_infos.memory_usage, node?.infos?.hardware_infos.memory, capacityTrans),
  112. name: node?.infos?.name,
  113. }
  114. rows.push(dataRow);
  115. }
  116. })
  117. }
  118. return (
  119. <div className={classes.root}>
  120. <button className={classes.childCloseBtn} onClick={() => setCord(null)}>
  121. <KeyboardArrowDown />
  122. </button>
  123. <div className={classes.gridContainer}>
  124. <DataGrid
  125. rows={rows}
  126. columns={columns}
  127. hideFooterPagination
  128. hideFooterSelectedRowCount
  129. onRowClick={(rowData) => {
  130. const selectedNode = childNodes.find(node => rowData.row.id === node.identifier);
  131. setSelectedChildNode(selectedNode);
  132. }}
  133. />
  134. </div>
  135. <MiniTopo selectedCord={selectedCord} setCord={setCord} selectedChildNode={selectedChildNode} />
  136. <DataCard className={classes.dataCard} node={selectedChildNode} />
  137. </div>
  138. );
  139. };
  140. export default NodeListView;