SystemView.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import { useState, useEffect, useRef } from 'react';
  2. import { Theme } from '@mui/material';
  3. import clsx from 'clsx';
  4. import { useNavigationHook, useInterval } from '@/hooks';
  5. import { ALL_ROUTER_TYPES } from '@/router/Types';
  6. import { MilvusService } from '@/http';
  7. import { parseJson } from '@/utils';
  8. import Topo from './Topology';
  9. import NodeListView from './NodeListView';
  10. // import LineChartCard from './LineChartCard';
  11. // import ProgressCard from './ProgressCard';
  12. import DataCard from './DataCard';
  13. import { makeStyles } from '@mui/styles';
  14. const getStyles = makeStyles((theme: Theme) => ({
  15. root: {
  16. margin: '16px',
  17. position: 'relative',
  18. display: 'flex',
  19. height: 'calc(100vh - 80px)',
  20. overflow: 'hidden',
  21. border: `1px solid ${theme.palette.divider}`,
  22. borderRadius: 8,
  23. boxShadow: '0 0 10px 0 rgba(0,0,0,0.1)',
  24. },
  25. transparent: {
  26. opacity: 0,
  27. transition: 'opacity .5s',
  28. },
  29. contentContainer: {
  30. display: 'flex',
  31. borderRadius: 8,
  32. gap: 8,
  33. width: '100%',
  34. },
  35. left: {
  36. width: '70%',
  37. background: theme.palette.background.paper,
  38. borderRadius: 8,
  39. },
  40. right: { width: '30%', borderRadius: 8 },
  41. childView: {
  42. height: '100%',
  43. width: '100%',
  44. transition: 'all .25s',
  45. position: 'absolute',
  46. // zIndex: 1000,
  47. backgroundColor: theme.palette.background.paper,
  48. borderRadius: 8,
  49. },
  50. showChildView: {
  51. top: 0,
  52. opacity: 1,
  53. },
  54. hideChildView: {
  55. top: 1600,
  56. opacity: 0,
  57. },
  58. childCloseBtn: {
  59. border: 0,
  60. backgroundColor: theme.palette.background.paper,
  61. width: '100%',
  62. },
  63. }));
  64. const SystemView: any = () => {
  65. useNavigationHook(ALL_ROUTER_TYPES.SYSTEM);
  66. // const { t } = useTranslation('systemView');
  67. const classes = getStyles();
  68. const INTERVAL = 60000;
  69. const [data, setData] = useState<{
  70. nodes: any;
  71. childNodes: any;
  72. system: any;
  73. }>({ nodes: [], childNodes: [], system: {} });
  74. const [selectedNode, setNode] = useState<any>();
  75. const [selectedCord, setCord] = useState<any>();
  76. const [showChildView, setShowChildView] = useState(false);
  77. const { nodes, childNodes } = data;
  78. useInterval(async () => {
  79. if (!selectedCord) {
  80. const res = await MilvusService.getMetrics();
  81. setData(parseJson(res));
  82. }
  83. }, INTERVAL);
  84. useEffect(() => {
  85. async function fetchData() {
  86. const res = await MilvusService.getMetrics();
  87. setData(parseJson(res));
  88. }
  89. fetchData();
  90. }, []);
  91. // let qps = system?.qps || 0;
  92. // const latency = system?.latency || 0;
  93. const childView = useRef<HTMLInputElement>(null);
  94. return (
  95. <div className={classes.root}>
  96. <div className={classes.contentContainer}>
  97. <div className={classes.left}>
  98. <Topo
  99. nodes={nodes}
  100. childNodes={childNodes}
  101. setNode={setNode}
  102. setCord={setCord}
  103. setShowChildView={setShowChildView}
  104. />
  105. </div>
  106. <div className={classes.right}>
  107. <DataCard node={selectedNode} extend={true} />
  108. </div>
  109. </div>
  110. <div
  111. ref={childView}
  112. className={clsx(
  113. classes.childView,
  114. showChildView ? classes.showChildView : classes.hideChildView
  115. )}
  116. >
  117. {selectedCord && (
  118. <NodeListView
  119. selectedCord={selectedCord}
  120. childNodes={childNodes}
  121. setCord={setCord}
  122. setShowChildView={setShowChildView}
  123. />
  124. )}
  125. </div>
  126. </div>
  127. );
  128. };
  129. export default SystemView;