import { Loader } from "lucide-react"; import { GaugeCard } from "../Monitor/GaugeCard"; import { fmt } from "../../utils/units"; import type { MonitoringSample, DashboardInfo } from "../../types"; interface Props { monitor: MonitoringSample | null; history: MonitoringSample[]; dashboard: DashboardInfo | null; loading: boolean; } function pluck( history: MonitoringSample[], key: K, ): number[] { return history.map((s) => (s[key] as number | null) ?? 0); } function pcieLink( width: number | null | undefined, gen: number | null | undefined, ): string | null { if (width == null && gen == null) return null; return `x${width ?? "?"} Gen${gen ?? "?"}`; } /** A static label/value pair. Renders nothing when the value is unavailable. */ function InfoItem({ label, value, accent, }: { label: string; value: string | null | undefined; accent?: string; }) { if (value == null || value === "") return null; return (
{label} {value}
); } function TempRow({ label, value }: { label: string; value: number | null }) { if (value == null) return null; return (
{label} {fmt.celsius(value)}
); } export function Dashboard({ monitor, history, dashboard: d, loading }: Props) { if (loading && !d) { return (
Loading dashboard…
); } const throttleLabel = monitor?.throttle_reasons_label ?? null; const isThrottled = throttleLabel != null && throttleLabel !== "No"; const memUsed = monitor?.mem_used_mib ?? null; const memTotal = monitor?.mem_total_mib ?? null; const memLabel = memUsed != null && memTotal != null ? `${memUsed.toFixed(0)} / ${memTotal.toFixed(0)} MiB` : "—"; const powerLimit = d?.power_limit_w ?? null; const powerRange = d?.power_min_limit_w != null && d?.power_max_limit_w != null ? `${d.power_min_limit_w}–${d.power_max_limit_w} W` : null; return (
{/* ── Critical row ─────────────────────────────────────────────── */}
{/* Throttling */}
Throttling
{throttleLabel ?? "—"}
{/* GPU Voltage */}
GPU Voltage
{fmt.mv(monitor?.voltage_mv)}
{/* Temperature */}
Temperature
{/* ── Live Monitor ─────────────────────────────────────────────── */}
Live Monitor
0 ? powerLimit : 600} />
{/* ── GPU Information ──────────────────────────────────────────── */}
GPU Information
); }