feat: add <UpDownCounter />
This commit is contained in:
parent
d3a5654e8e
commit
ceb28a75d0
22
src/client/components/UpDownCounter.tsx
Normal file
22
src/client/components/UpDownCounter.tsx
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import { CaretDownOutlined, CaretUpOutlined } from '@ant-design/icons';
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
up: string;
|
||||||
|
down: string;
|
||||||
|
}
|
||||||
|
export const UpDownCounter: React.FC<Props> = React.memo((props) => {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<div>
|
||||||
|
<CaretUpOutlined className="text-orange-500" />
|
||||||
|
<span className="ml-1">{props.up}</span>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<CaretDownOutlined className="text-green-500" />
|
||||||
|
<span className="ml-1">{props.down}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
UpDownCounter.displayName = 'UpDownCounter';
|
@ -6,6 +6,7 @@ import { ServerStatusInfo } from '../../types';
|
|||||||
import { useSocketSubscribe } from '../api/socketio';
|
import { useSocketSubscribe } from '../api/socketio';
|
||||||
import { filesize } from 'filesize';
|
import { filesize } from 'filesize';
|
||||||
import prettyMilliseconds from 'pretty-ms';
|
import prettyMilliseconds from 'pretty-ms';
|
||||||
|
import { UpDownCounter } from '../components/UpDownCounter';
|
||||||
|
|
||||||
export const Servers: React.FC = React.memo(() => {
|
export const Servers: React.FC = React.memo(() => {
|
||||||
const [isModalOpen, setIsModalOpen] = useState(false);
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||||
@ -49,20 +50,6 @@ export const Servers: React.FC = React.memo(() => {
|
|||||||
});
|
});
|
||||||
Servers.displayName = 'Servers';
|
Servers.displayName = 'Servers';
|
||||||
|
|
||||||
interface ServerInfoRecordType {
|
|
||||||
status: 'online' | 'offline';
|
|
||||||
nodeName: string;
|
|
||||||
type: string; // KVM | Hyper-V
|
|
||||||
location: string;
|
|
||||||
uptime: number; // second
|
|
||||||
load: number;
|
|
||||||
network: string;
|
|
||||||
traffic: string;
|
|
||||||
cpu: string;
|
|
||||||
ram: string;
|
|
||||||
hdd: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const ServerList: React.FC = React.memo(() => {
|
export const ServerList: React.FC = React.memo(() => {
|
||||||
const serverMap = useSocketSubscribe<Record<string, ServerStatusInfo>>(
|
const serverMap = useSocketSubscribe<Record<string, ServerStatusInfo>>(
|
||||||
'onServerStatusUpdate',
|
'onServerStatusUpdate',
|
||||||
@ -71,8 +58,6 @@ export const ServerList: React.FC = React.memo(() => {
|
|||||||
|
|
||||||
const dataSource = Object.values(serverMap);
|
const dataSource = Object.values(serverMap);
|
||||||
|
|
||||||
console.log('dataSource', dataSource);
|
|
||||||
|
|
||||||
const columns = useMemo((): ColumnsType<ServerStatusInfo> => {
|
const columns = useMemo((): ColumnsType<ServerStatusInfo> => {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
@ -109,18 +94,24 @@ export const ServerList: React.FC = React.memo(() => {
|
|||||||
key: 'nework',
|
key: 'nework',
|
||||||
title: 'Network',
|
title: 'Network',
|
||||||
render: (_, record) => {
|
render: (_, record) => {
|
||||||
return `${filesize(record.payload.network_in)} | ${filesize(
|
return (
|
||||||
record.payload.network_out
|
<UpDownCounter
|
||||||
)}`;
|
up={filesize(record.payload.network_out)}
|
||||||
|
down={filesize(record.payload.network_in)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'traffic',
|
key: 'traffic',
|
||||||
title: 'Traffic',
|
title: 'Traffic',
|
||||||
render: (_, record) => {
|
render: (_, record) => {
|
||||||
return `${filesize(record.payload.network_rx)}/s | ${filesize(
|
return (
|
||||||
record.payload.network_tx
|
<UpDownCounter
|
||||||
)}/s`;
|
up={filesize(record.payload.network_tx) + '/s'}
|
||||||
|
down={filesize(record.payload.network_rx) + '/s'}
|
||||||
|
/>
|
||||||
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user