From 5600bddef69b3c5e92fc1fb58151a28951646d7d Mon Sep 17 00:00:00 2001 From: CJ Rivas Date: Sat, 7 Nov 2026 09:28:11 -0500 Subject: [PATCH] WZ: Fix fleet charts and link host cards to DSM - Host cards open their DSM login page in a new tab, with a hover and focus lift - Disk chart reports used space instead of free, to two decimals - Percent charts keep a fixed 0-100% axis, so a nearly full disk reads as full - Every chart legend is a set of checkboxes that hide and show host lines - Hidden lines persist per chart in the fleet prefs store, one list per chart - MetricChart takes one optional toggle, so a hidden line always has its checkbox - dsmUrl lives with the host model in lib/fleetApi; chart class names share one helper - Multi-line comments are one block, not stacked `//` lines; CLAUDE.md states the rule --- CLAUDE.md | 2 + .../src/components/Chart/ChartLegend.tsx | 80 ++++++- .../src/components/Chart/ChartTooltip.tsx | 9 +- .../src/components/Chart/chart.module.scss | 123 +++++++---- .../src/components/Chart/classNames.ts | 4 + .../admin-portal/src/components/Icon/Icon.tsx | 10 +- apps/admin-portal/src/lib/fleetApi.ts | 23 +- .../src/pages/Fleet/Fleet.test.tsx | 163 +++++++------- apps/admin-portal/src/pages/Fleet/Fleet.tsx | 70 +++--- .../src/pages/Fleet/HostCard.module.scss | 200 ++++++++++++------ .../admin-portal/src/pages/Fleet/HostCard.tsx | 70 +++--- .../src/pages/Fleet/MetricChart.test.tsx | 198 ++++++++++++----- .../src/pages/Fleet/MetricChart.tsx | 128 ++++++----- .../src/pages/Fleet/metricCopy.ts | 5 +- .../src/pages/Fleet/metricFrame.ts | 75 ++++--- .../src/pages/Fleet/metricScale.test.ts | 46 ++-- .../src/pages/Fleet/metricScale.ts | 16 +- .../src/stores/fleetPrefsStore.test.ts | 37 +++- .../src/stores/fleetPrefsStore.ts | 49 +++++ apps/fleet-monitor/src/api/api.test.ts | 192 ++++++++--------- apps/fleet-monitor/src/api/fleetController.ts | 32 +-- apps/fleet-monitor/src/series.test.ts | 97 +++++---- apps/fleet-monitor/src/series.ts | 101 +++++---- 23 files changed, 1100 insertions(+), 630 deletions(-) create mode 100644 apps/admin-portal/src/components/Chart/classNames.ts diff --git a/CLAUDE.md b/CLAUDE.md index 935c77c4..a0009b60 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -181,6 +181,8 @@ Everything else here is convention, and the import-alias rule in particular has - Prefer short-circuit (`&&`) over a ternary when the else branch is `null` or `undefined`, especially in React rendering. Do: `{isActive && }`. Don't: `{isActive ? : null}`. Guard the condition so it is a real boolean (`!!count && ...`), never a bare number that could render `0`. - Prefer optional chaining (`?.`). When optional chaining is used, ALWAYS pair it with nullish coalescing (`??`) to supply a fallback. - Prefer a single configurable object parameter over multiple positional parameters so argument order doesn't matter. Don't: `doSomething(foo, bar, hello)`. Do: `doSomething({ foo, bar, hello })`. +- A comment that fits on one line uses `//`. A comment that spans more than one line uses one block, `/* ... */`, or `/** ... */` when it documents an export, a type or one of its fields. Never stack `//` lines into a paragraph, and never wrap a one-line comment in `/* */`. +- Exceptions: comments inside JSX stay `{/* ... */}`, since JSX has no `//`; a trailing comment after code on the same line is always `//`; and a `/** ... */` doc comment that fits on one line stays as it is, because editors only show `/** */` comments on hover. ## Accessibility diff --git a/apps/admin-portal/src/components/Chart/ChartLegend.tsx b/apps/admin-portal/src/components/Chart/ChartLegend.tsx index 211477c5..f5fc3de6 100644 --- a/apps/admin-portal/src/components/Chart/ChartLegend.tsx +++ b/apps/admin-portal/src/components/Chart/ChartLegend.tsx @@ -1,3 +1,4 @@ +import { classNames } from '@/components/Chart/classNames' import { swatchClass, type ChartMark } from '@/components/Chart/ChartTooltip' import styles from '@/components/Chart/chart.module.scss' @@ -12,20 +13,79 @@ export type ChartLegendItem = { readonly note?: string } +/** Which series the reader left off the plot, and how to flip one. A chart + takes this whole or not at all, so a hidden series always comes with the + checkbox that brings it back. */ +export type SeriesToggle = { + /** Keys of the series currently left off the plot. */ + readonly hidden: readonly string[] + readonly onToggle: (key: string) => void +} + +/** Lets the reader choose which series are drawn. Without it the legend is a + plain key. */ +export type ChartLegendToggle = SeriesToggle & { + /** Names the group of checkboxes for a screen reader, such as "Hosts shown + on the CPU chart". */ + readonly label: string +} + type ChartLegendProps = { readonly items: readonly ChartLegendItem[] readonly mark?: ChartMark + readonly toggle?: ChartLegendToggle } -/** What each mark on the plot stands for, named in words beside its colour. */ -export const ChartLegend = ({ items, mark = 'square' }: ChartLegendProps) => ( -
    - {items.map((item) => ( -
  • -
  • - ))} +/** The swatch, name and note one entry shows, shared by both forms. */ +const EntryBody = ({ + item, + mark, +}: { + readonly item: ChartLegendItem + readonly mark: ChartMark +}) => ( + <> +