Files
Netcatty/components/systemManager/ResourceBar.tsx
T
27f26d8e69 feat(monitor): 优化磁盘IO展示与系统分区告警 [4030] (#4031)
* feat(monitor): 优化磁盘IO展示与系统分区告警 [4030]

* fix(monitor): 修复磁盘监控评审问题 [4030]

* fix(monitor): align Partitions bars with Memory; hide bare / label

Label-above-bar for partition list; single-root `/` hides the label and
centers the bar like Memory/CPU (unchanged). Multi-disk keeps top align +
system alerts. Disk IO adds a spacer row to track usage labels.

Review crops under .github/review/ for PR discussion (drop before merge OK).

* fix(monitor): keep bare-/ align; multi-disk labels stay left

Address Chris density feedback: keep the single root label hidden and vertically centered with Memory, and restore side-by-side labels for multiple disks. Remove the Disk I/O spacer and update the review crops.

* chore(monitor): drop PR #4031 discussion review crops

---------

Co-authored-by: wendeng.dong <wendeng.dong@sailuntire.com>
Co-authored-by: 陈大猫 <16399091+binaricat@users.noreply.github.com>
2026-10-27 23:54:58 -07:00

53 lines
1.6 KiB
TypeScript

import React, { memo } from 'react';
import { cn } from '../../lib/utils';
interface ResourceBarProps {
label: string;
value: number | null | undefined;
className?: string;
/** Slightly taller track for GPU cards. */
size?: 'sm' | 'md';
danger?: boolean;
}
function barTone(clamped: number): string {
if (clamped > 85) return 'bg-destructive/80';
if (clamped > 60) return 'bg-amber-500/80';
return 'bg-primary/75';
}
export const ResourceBar = memo(function ResourceBar({
label,
value,
className,
size = 'sm',
danger = false,
}: ResourceBarProps) {
const finite = typeof value === 'number' && Number.isFinite(value);
const clamped = finite ? Math.max(0, Math.min(100, value)) : 0;
return (
<div className={cn('flex items-center gap-2 min-w-0', className)}>
{label ? (
<span className="text-[10px] text-muted-foreground w-7 shrink-0">{label}</span>
) : null}
<div
className={cn(
'flex-1 rounded-full bg-muted/50 overflow-hidden min-w-[48px]',
size === 'md' ? 'h-1.5' : 'h-1',
)}
>
<div
className={cn(
'h-full rounded-full transition-[width,background-color] duration-500 ease-out motion-reduce:transition-none',
finite ? (danger ? 'bg-destructive/80' : barTone(clamped)) : 'opacity-0',
)}
style={{ width: `${clamped}%` }}
/>
</div>
<span className={cn('text-[10px] tabular-nums w-10 text-right shrink-0', danger ? 'text-destructive font-medium' : 'text-muted-foreground')}>
{finite ? `${value.toFixed(1)}%` : '--'}
</span>
</div>
);
});