import React from "react"; import type { MonitorStats } from "../../domain/monitorRuntime"; import { buildMonitorDiskListLayout, type MonitorDiskListLayout, type MonitorDiskListRow } from "../../domain/monitorDisks"; import { ResourceBar } from "../systemManager/ResourceBar"; import { DiskIoSummary } from "../systemManager/DiskIoSummary"; import { MonitorSystemDiskToggle } from "./MonitorSystemDiskToggle"; import { useI18n } from "../../application/i18n/I18nProvider"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "../ui/tooltip"; const diskCapacity = (value: number) => value >= 1024 ? `${(value / 1024).toFixed(2)} TiB` : value > 0 && value < 1 ? `${(value * 1024).toFixed(1)} MiB` : `${value.toFixed(1)} GiB`; /** Cards show the largest capacities; the list puts system mounts first. */ export function MonitorDiskUsage({ stats, limit, listLayout, onToggleSystem, }: { stats?: (Pick & Partial>) | null; limit?: number; listLayout?: MonitorDiskListLayout; onToggleSystem?: () => void; }) { const { t } = useI18n(); const reported = stats?.disks.length ? stats.disks : [{ mountPoint: "/", percent: stats?.diskPercent ?? null, used: stats?.diskUsed ?? null, total: stats?.diskTotal ?? null }]; const rows: MonitorDiskListRow[] = limit == null ? (listLayout ?? buildMonitorDiskListLayout(stats)).rows : [...reported].sort((a, b) => (b.total ?? 0) - (a.total ?? 0)) .slice(0, limit).map(disk => ({ kind: "disk", disk, alert: false })); const bareRoot = limit == null && rows.length === 1 && rows[0].kind === "disk" && rows[0].disk.mountPoint === "/"; return (
{limit != null && } {rows.map((row, index) => { if (row.kind === "system") return ( ); const { disk, alert } = row; return (
{!bareRoot && {disk.mountPoint} }
{disk.mountPoint}
{typeof disk.used === "number" && Number.isFinite(disk.used) && disk.used >= 0 && typeof disk.total === "number" && Number.isFinite(disk.total) && disk.total > 0 ? t("monitor.diskCapacity", { used: diskCapacity(disk.used), total: diskCapacity(disk.total) }) : t("monitor.diskCapacityUnknown")}
); })}
); }