You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tailchat/server/admin/app/ra/routes/network/index.tsx

97 lines
2.5 KiB
TypeScript

import React from 'react';
import { request } from '../../request';
import { useRequest } from 'ahooks';
import {
CircularProgress,
Table,
TableBody,
TableCell,
TableHead,
TableRow,
Typography,
Box,
} from '@mui/material';
import _uniq from 'lodash/uniq';
import { ChipItems } from '../../components/ChipItems';
/**
* Tailchat 网络状态
*/
export const TailchatNetwork: React.FC = React.memo(() => {
const { data, loading } = useRequest(async () => {
const { data } = await request('/network/all');
return data;
});
if (loading) {
return <CircularProgress />;
}
return (
<Box
sx={{
paddingTop: 2,
paddingBottom: 2,
maxWidth: '100vw',
}}
>
<Typography variant="h6" gutterBottom>
</Typography>
<Table sx={{ minWidth: 650 }} aria-label="simple table">
<TableHead>
<TableRow>
<TableCell>ID</TableCell>
<TableCell></TableCell>
<TableCell>CPU</TableCell>
<TableCell>IP</TableCell>
<TableCell>SDK</TableCell>
</TableRow>
</TableHead>
<TableBody>
{(data.nodes ?? []).map((row) => (
<TableRow
key={row.name}
sx={{ '&:last-child td, &:last-child th': { border: 0 } }}
>
<TableCell component="th" scope="row">
{row.id}
{row.local && <span> (*)</span>}
</TableCell>
<TableCell>{row.hostname}</TableCell>
<TableCell>{row.cpu}%</TableCell>
<TableCell>
<ChipItems items={row.ipList ?? []} />
</TableCell>
<TableCell>{row.client.version}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
<Typography variant="h6" gutterBottom>
</Typography>
<Box flexWrap="wrap" overflow="hidden">
<ChipItems items={_uniq<string>(data.services ?? [])} />
</Box>
<Typography variant="h6" gutterBottom>
</Typography>
<Box flexWrap="wrap" overflow="hidden">
<ChipItems items={_uniq<string>(data.actions ?? [])} />
</Box>
<Typography variant="h6" gutterBottom>
</Typography>
<Box flexWrap="wrap" overflow="hidden">
<ChipItems items={_uniq<string>(data.events ?? [])} />
</Box>
</Box>
);
});
TailchatNetwork.displayName = 'TailchatNetwork';