DataCard.tsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. import { FC } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import { makeStyles } from '@material-ui/core';
  4. import Progress from './Progress';
  5. import { getByteString } from '../../utils/Format';
  6. import { DataProgressProps, DataSectionProps, DataCardProps } from './Types';
  7. const getStyles = makeStyles(() => ({
  8. root: {
  9. backgroundColor: '#F6F6F6',
  10. borderTopRightRadius: '8px',
  11. borderBottomRightRadius: '8px',
  12. height: '100%',
  13. padding: '20px 16px',
  14. boxSizing: 'border-box',
  15. },
  16. title: {
  17. display: 'flex',
  18. justifyContent: 'space-between',
  19. },
  20. content: {
  21. color: '#010E29',
  22. fontSize: '20px',
  23. fontWeight: 600,
  24. lineHeight: '36px',
  25. },
  26. desc: {
  27. color: '#82838E',
  28. fontSize: '14px',
  29. lineHeight: '36px',
  30. marginLeft: "8px",
  31. },
  32. rootName: {
  33. color: '#82838E',
  34. fontSize: '20px',
  35. lineHeight: '24px',
  36. },
  37. childName: {
  38. color: '#06AFF2',
  39. fontSize: '20px',
  40. lineHeight: '24px',
  41. },
  42. ip: {
  43. color: '#010E29',
  44. fontSize: '16px',
  45. lineHeight: '24px',
  46. },
  47. sectionRoot: {
  48. borderSpacing: '0 1px',
  49. display: 'table',
  50. marginTop: '24px',
  51. width: '100%'
  52. },
  53. sectionRow: {
  54. display: 'table-row',
  55. },
  56. sectionHeaderCell: {
  57. display: 'table-cell',
  58. color: '#82838E',
  59. fontSize: '12px',
  60. lineHeight: '24px',
  61. padding: '8px 16px',
  62. textTransform: 'uppercase',
  63. width: '50%',
  64. },
  65. sectionCell: {
  66. backgroundColor: 'white',
  67. color: '#010E29',
  68. display: 'table-cell',
  69. fontSize: '14px',
  70. lineHeight: '24px',
  71. padding: '12px 16px',
  72. textTransform: 'capitalize',
  73. verticalAlign: 'middle',
  74. width: '50%',
  75. },
  76. progressTitle: {
  77. fontSize: '14px',
  78. color: '#010E29',
  79. lineHeight: '24px',
  80. display: 'flex',
  81. justifyContent: 'space-between',
  82. }
  83. }));
  84. const DataSection: FC<DataSectionProps> = (props) => {
  85. const classes = getStyles();
  86. const { titles, contents } = props;
  87. return (
  88. <div className={classes.sectionRoot}>
  89. <div className={classes.sectionRow}>
  90. {titles.map((titleEntry) => <div key={titleEntry} className={classes.sectionHeaderCell}>{titleEntry}</div>)}
  91. </div>
  92. {contents.map((contentEntry) => {
  93. return (
  94. <div key={contentEntry.label} className={classes.sectionRow}>
  95. <div className={classes.sectionCell}>
  96. {contentEntry.label}
  97. </div>
  98. <div className={classes.sectionCell}>
  99. {contentEntry.value}
  100. </div>
  101. </div>)
  102. })}
  103. </div>
  104. );
  105. }
  106. const DataProgress: FC<DataProgressProps> = ({ percent = 0, desc = '' }) => {
  107. const classes = getStyles();
  108. return (
  109. <div>
  110. <div className={classes.progressTitle}>
  111. <span>{`${Number(percent * 100).toFixed(2)}%`}</span>
  112. <span>{desc}</span>
  113. </div>
  114. <Progress percent={percent} color='#06AFF2' />
  115. </div>
  116. )
  117. };
  118. const DataCard: FC<DataCardProps & React.HTMLAttributes<HTMLDivElement>> = (props) => {
  119. const classes = getStyles();
  120. const { t } = useTranslation('systemView');
  121. const { t: commonTrans } = useTranslation();
  122. const capacityTrans: { [key in string]: string } = commonTrans('capacity');
  123. const { node, extend } = props;
  124. const hardwareTitle = [t('hardwareTitle'), t('valueTitle')];
  125. const hardwareContent = [];
  126. const infos = node?.infos?.hardware_infos || {};
  127. const {
  128. cpu_core_count: cpu = 0,
  129. cpu_core_usage: cpuUsage = 0,
  130. memory = 1,
  131. memory_usage: memoryUsage = 0,
  132. disk = 1,
  133. disk_usage: diskUsage = 0,
  134. } = infos;
  135. if (extend) {
  136. hardwareContent.push({ label: t('thCPUCount'), value: cpu });
  137. hardwareContent.push({
  138. label: t('thCPUUsage'), value: <DataProgress percent={cpuUsage / 100} />
  139. });
  140. hardwareContent.push({
  141. label: t('thMemUsage'), value: <DataProgress percent={memoryUsage / memory} desc={getByteString(memoryUsage, memory, capacityTrans)} />
  142. });
  143. hardwareContent.push({
  144. label: t('thDiskUsage'), value: <DataProgress percent={diskUsage / disk} desc={getByteString(diskUsage, disk, capacityTrans)} />
  145. });
  146. }
  147. const systemTitle = [t('systemTitle'), t('valueTitle')];
  148. const systemContent = [];
  149. const sysInfos = node?.infos?.system_info || {};
  150. const {
  151. system_version: version,
  152. deploy_mode: mode = '',
  153. created_time: create = '',
  154. updated_time: update = '',
  155. } = sysInfos;
  156. systemContent.push({ label: t('thVersion'), value: version });
  157. systemContent.push({ label: t('thDeployMode'), value: mode });
  158. systemContent.push({ label: t('thCreateTime'), value: create });
  159. systemContent.push({ label: t('thUpdateTime'), value: update });
  160. return (
  161. <div className={classes.root}>
  162. <div className={classes.title}>
  163. <div>
  164. <span className={classes.rootName}>Milvus / </span>
  165. <span className={classes.childName}>{node?.infos?.name}</span>
  166. </div>
  167. <div className={classes.ip}>{`${t('thIP')}:${infos?.ip || ''}`}</div>
  168. </div>
  169. {extend && <DataSection titles={hardwareTitle} contents={hardwareContent} />}
  170. <DataSection titles={systemTitle} contents={systemContent} />
  171. </div>
  172. );
  173. };
  174. export default DataCard;