feat: add colorized text for server status which help user find problem

This commit is contained in:
moonrailgun 2024-07-22 00:16:36 +08:00
parent f814691538
commit f2b20c5ef9
2 changed files with 49 additions and 7 deletions

View File

@ -0,0 +1,23 @@
import { cn } from '@/utils/style';
import React, { PropsWithChildren } from 'react';
interface ColorizedTextProps extends PropsWithChildren {
className?: string;
percent: number;
}
export const ColorizedText: React.FC<ColorizedTextProps> = React.memo(
(props) => {
return (
<span
className={cn(props.className, {
'text-yellow-500': props.percent > 0.8,
'text-red-600': props.percent >= 0.9,
'text-red-900': props.percent >= 0.99,
})}
>
{props.children}
</span>
);
}
);
ColorizedText.displayName = 'ColorizedText';

View File

@ -15,6 +15,7 @@ import { UpDownCounter } from '../UpDownCounter';
import { ScrollArea, ScrollBar } from '../ui/scroll-area'; import { ScrollArea, ScrollBar } from '../ui/scroll-area';
import { ServerRowExpendView } from './ServerRowExpendView'; import { ServerRowExpendView } from './ServerRowExpendView';
import { FaDocker } from 'react-icons/fa'; import { FaDocker } from 'react-icons/fa';
import { ColorizedText } from './ColorizedText';
const columnHelper = createColumnHelper<ServerStatusInfo>(); const columnHelper = createColumnHelper<ServerStatusInfo>();
@ -119,7 +120,11 @@ export const ServerList: React.FC<ServerListProps> = React.memo((props) => {
columnHelper.accessor('payload.cpu', { columnHelper.accessor('payload.cpu', {
header: 'CPU', header: 'CPU',
size: 80, size: 80,
cell: (props) => `${props.getValue()}%`, cell: (props) => (
<ColorizedText percent={props.getValue() / 100}>
{props.getValue()}%
</ColorizedText>
),
}), }),
columnHelper.display({ columnHelper.display({
header: 'RAM', header: 'RAM',
@ -127,9 +132,16 @@ export const ServerList: React.FC<ServerListProps> = React.memo((props) => {
cell: (props) => ( cell: (props) => (
<div className="text-xs"> <div className="text-xs">
<div> <div>
{filesize(props.row.original.payload.memory_used * 1024, { <ColorizedText
base: 2, percent={
})}{' '} props.row.original.payload.memory_used /
props.row.original.payload.memory_total
}
>
{filesize(props.row.original.payload.memory_used * 1024, {
base: 2,
})}
</ColorizedText>{' '}
/{' '} /{' '}
</div> </div>
<div> <div>
@ -146,9 +158,16 @@ export const ServerList: React.FC<ServerListProps> = React.memo((props) => {
cell: (props) => ( cell: (props) => (
<div className="text-xs"> <div className="text-xs">
<div> <div>
{filesize(props.row.original.payload.hdd_used * 1024 * 1024, { <ColorizedText
base: 2, percent={
})}{' '} props.row.original.payload.hdd_used /
props.row.original.payload.hdd_total
}
>
{filesize(props.row.original.payload.hdd_used * 1024 * 1024, {
base: 2,
})}
</ColorizedText>{' '}
/{' '} /{' '}
</div> </div>
<div> <div>