|
| 1 | +import React from 'react'; |
| 2 | +import { request } from '../request'; |
| 3 | +import { useRequest } from 'ahooks'; |
| 4 | +import { |
| 5 | + CircularProgress, |
| 6 | + Table, |
| 7 | + TableBody, |
| 8 | + TableCell, |
| 9 | + TableHead, |
| 10 | + TableRow, |
| 11 | + Typography, |
| 12 | + Box, |
| 13 | +} from '@mui/material'; |
| 14 | +import _uniq from 'lodash/uniq'; |
| 15 | +import { ChipItems } from '../components/ChipItems'; |
| 16 | + |
| 17 | +/** |
| 18 | + * Tailchat 网络状态 |
| 19 | + */ |
| 20 | +export const TailchatNetwork: React.FC = React.memo(() => { |
| 21 | + const { data, loading } = useRequest(async () => { |
| 22 | + const { data } = await request('/network/all'); |
| 23 | + |
| 24 | + return data; |
| 25 | + }); |
| 26 | + |
| 27 | + if (loading) { |
| 28 | + return <CircularProgress />; |
| 29 | + } |
| 30 | + |
| 31 | + return ( |
| 32 | + <Box |
| 33 | + sx={{ |
| 34 | + paddingTop: 2, |
| 35 | + paddingBottom: 2, |
| 36 | + maxWidth: '100vw', |
| 37 | + }} |
| 38 | + > |
| 39 | + <Typography variant="h6" gutterBottom> |
| 40 | + 节点列表 |
| 41 | + </Typography> |
| 42 | + <Table sx={{ minWidth: 650 }} aria-label="simple table"> |
| 43 | + <TableHead> |
| 44 | + <TableRow> |
| 45 | + <TableCell>ID</TableCell> |
| 46 | + <TableCell>主机名</TableCell> |
| 47 | + <TableCell>CPU占用</TableCell> |
| 48 | + <TableCell>IP地址列表</TableCell> |
| 49 | + <TableCell>SDK版本</TableCell> |
| 50 | + </TableRow> |
| 51 | + </TableHead> |
| 52 | + <TableBody> |
| 53 | + {(data.nodes ?? []).map((row) => ( |
| 54 | + <TableRow |
| 55 | + key={row.name} |
| 56 | + sx={{ '&:last-child td, &:last-child th': { border: 0 } }} |
| 57 | + > |
| 58 | + <TableCell component="th" scope="row"> |
| 59 | + {row.id} |
| 60 | + {row.local && <span> (*)</span>} |
| 61 | + </TableCell> |
| 62 | + <TableCell>{row.hostname}</TableCell> |
| 63 | + <TableCell>{row.cpu}%</TableCell> |
| 64 | + <TableCell> |
| 65 | + <ChipItems items={row.ipList ?? []} /> |
| 66 | + </TableCell> |
| 67 | + <TableCell>{row.client.version}</TableCell> |
| 68 | + </TableRow> |
| 69 | + ))} |
| 70 | + </TableBody> |
| 71 | + </Table> |
| 72 | + |
| 73 | + <Typography variant="h6" gutterBottom> |
| 74 | + 服务列表 |
| 75 | + </Typography> |
| 76 | + <Box flexWrap="wrap" overflow="hidden"> |
| 77 | + <ChipItems items={_uniq<string>(data.services ?? [])} /> |
| 78 | + </Box> |
| 79 | + |
| 80 | + <Typography variant="h6" gutterBottom> |
| 81 | + 操作列表 |
| 82 | + </Typography> |
| 83 | + <Box flexWrap="wrap" overflow="hidden"> |
| 84 | + <ChipItems items={_uniq<string>(data.actions ?? [])} /> |
| 85 | + </Box> |
| 86 | + |
| 87 | + <Typography variant="h6" gutterBottom> |
| 88 | + 事件列表 |
| 89 | + </Typography> |
| 90 | + <Box flexWrap="wrap" overflow="hidden"> |
| 91 | + <ChipItems items={_uniq<string>(data.events ?? [])} /> |
| 92 | + </Box> |
| 93 | + </Box> |
| 94 | + ); |
| 95 | +}); |
| 96 | +TailchatNetwork.displayName = 'TailchatNetwork'; |
0 commit comments