Public: anyone can read this; the crew can change it.

Status at a glance: one badge shape, segmented progress, one-line alerts and a marked table row (borrowed from SPEC-01/HARDWARE) #13637

Merged opened this in answer to

Check · Review · Land · Live done — Landed and live in production.

Merged

mason/forge:mason/13634-status-at-a-glance-one-badge-shape-segme → main 7 commits fork 3 threads · 3 unresolved

  • Merged. mason/13634-status-at-a-glance-one-badge-shape-segme was merged into main as 2952881.

Review

Sign in to review this change.
4 files changed +118 −30
docs/design/size-budget.json +9 −9
@@ -1,27 +1,27 @@
11 {
22 "/": {
33 "js": 22016,
4 "css": 44544
4 "css": 44800
55 },
66 "/explore": {
77 "js": 21760,
8 "css": 44544
8 "css": 44800
99 },
1010 "/map": {
1111 "js": 28672,
12 "css": 46080
12 "css": 46336
1313 },
1414 "/:owner/:name": {
1515 "js": 38144,
16 "css": 44544
16 "css": 44800
1717 },
1818 "/changelog": {
1919 "js": 26368,
20 "css": 44544
20 "css": 44800
2121 },
2222 "/:owner/:name/next": {
2323 "js": 23296,
24 "css": 44800
24 "css": 45056
2525 },
2626 "/:owner/:name/space": {
2727 "js": 29696,
@@ -37,14 +37,14 @@
3737 },
3838 "/pricing": {
3939 "js": 21760,
40 "css": 44544
40 "css": 44800
4141 },
4242 "/forges/new": {
4343 "js": 21760,
44 "css": 44544
44 "css": 44800
4545 },
4646 "/claim": {
4747 "js": 24064,
48 "css": 44544
48 "css": 44800
4949 }
5050 }
src/web/style/components.ts +7
@@ -219,6 +219,13 @@ a.stat:hover { border-color: var(--border-strong); }
219219 background: color-mix(in srgb, var(--attn) 12%, transparent);
220220 }
221221 .badge .ico { width: 12px; height: 12px; }
222 /* The one status badge: a bar at the left edge, in the state's colour. The
223 word and icon are always there, so the bar is never the only cue. */
224 .badge[data-status] { position: relative; padding-left: 12px; }

Principle 6 (few borders): the badge already has a hairline border, and this adds a second mark inside it. Check that the 3px bar earns its place against the 12px left padding on a 360px phone. The queued and held opacity of .45 also gives a bar under 3:1 contrast. The word carries the meaning, so keep the bar decorative, or raise its opacity.

225 .badge[data-status]::before {
226 content: ""; position: absolute; inset: 4px auto 4px 4px; width: 3px; background: currentColor;
227 }
228 .badge[data-status="queued"]::before, .badge[data-status="held"]::before, .badge[data-status="cut"]::before { opacity: .7; }
222229 /* A loader that turns: the one icon that means "still going". */
223230 .ico-loader { animation: spin 1.1s linear infinite; }
224231 /* A button never spins at rest: only its own busy state turns the loader. */
src/web/ui.ts +57 −21
@@ -185,7 +185,10 @@ export interface BtnOptions {
185185 extra?: string;
186186 /** The element's id, for a script or a fragment link that finds it. */
187187 id?: string;
188 /** A pager's link says which way it goes (`rel="next"`): a reader of the list follows it (`bind.ts`). */
188 /**
189 * A pager's link says which way it goes (`rel="next"`): a reader of the list follows it
190 * (`bind.ts`).
191 */
189192 rel?: "next" | "prev";
190193 }
191194
@@ -384,6 +387,32 @@ export function verdictBadge(
384387 return badge(look.label, { icon: look.icon, tone: look.tone });
385388 }
386389
390 /** The closed set of states a status badge can wear. */
391 export type Status = "queued" | "running" | "ok" | "failed" | "cut" | "held";
392
393 const STATUS_VARIANT: Record<Status, string> = {
394 queued: "secondary",
395 running: "attn",
396 ok: "success",
397 failed: "danger",
398 cut: "outline",
399 held: "outline",
400 };
401
402 /**
403 * The one status badge: a quiet pill with a bar at its left edge, an icon
404 * and always a word, so it reads in black and white. `status` is the closed
405 * set above; `word` is what this thing calls that state ("Passed", "Asleep").
406 */
407 export function statusBadge(status: Status, word: string, ic: IconName): Html {
408 return html`<span
409 class="badge"
410 data-status="${status}"
411 data-variant="${STATUS_VARIANT[status]}"
412 >${icon(ic)}${word}</span
413 >`;
414 }
415
387416 /**
388417 * A run's state (docs/APPS.md): the one badge a check wears on a pull, a
389418 * row wears in a list, and a log page wears in its head. A finished deploy
@@ -392,18 +421,15 @@ export function verdictBadge(
392421 export function runStateBadge(state: RunState, kind: RunKind = "deploy"): Html {
393422 switch (state) {
394423 case "queued":
395 return badge("Queued", { icon: "clock", variant: "secondary" });
424 return statusBadge("queued", "Queued", "clock");
396425 case "running":
397 return badge("Running", { icon: "loader", tone: "attn" });
426 return statusBadge("running", "Running", "loader");
398427 case "ok":
399 return badge(kind === "agent" ? "Done" : "Passed", {
400 icon: "check",
401 tone: "success",
402 });
428 return statusBadge("ok", kind === "agent" ? "Done" : "Passed", "check");
403429 case "failed":
404 return badge("Failed", { icon: "x", tone: "danger" });
430 return statusBadge("failed", "Failed", "x");
405431 case "cancelled":
406 return badge("Cancelled", { icon: "ban", variant: "outline" });
432 return statusBadge("cut", "Cancelled", "ban");
407433 }
408434 }
409435
@@ -411,16 +437,16 @@ export function runStateBadge(state: RunState, kind: RunKind = "deploy"): Html {
411437 export function envStateBadge(state: EnvState, dormant = false): Html {
412438 switch (state) {
413439 case "stopped":
414 if (dormant) return badge("Asleep", { icon: "clock", variant: "outline" });
415 return badge("Stopped", { icon: "square", variant: "outline" });
440 if (dormant) return statusBadge("held", "Asleep", "clock");
441 return statusBadge("cut", "Stopped", "square");
416442 case "deploying":
417 return badge("Deploying", { icon: "loader", tone: "attn" });
443 return statusBadge("running", "Deploying", "loader");
418444 case "running":
419 return badge("Running", { icon: "play", tone: "success" });
445 return statusBadge("ok", "Running", "play");
420446 case "asleep":
421 return badge("Asleep", { icon: "clock", variant: "outline" });
447 return statusBadge("held", "Asleep", "clock");
422448 case "failed":
423 return badge("Failed", { icon: "alert", tone: "danger" });
449 return statusBadge("failed", "Failed", "alert");
424450 }
425451 }
426452
@@ -712,7 +738,9 @@ export function repoCounts(o: {
712738 openPulls?: number | null | undefined;
713739 /** Some origins report one number for issues *and* pulls; say so. */
714740 issuesIncludePulls?: boolean;
715 /** The repository we hold whose lists these count (`bind.ts`): absent for an origin's own numbers. */
741 /**
742 * The repository we hold whose lists these count (`bind.ts`): absent for an origin's own numbers.
743 */
716744 of?: { ownerName: string; name: string } | undefined;
717745 }): Html {
718746 const issues = o.openIssues ?? null;
@@ -777,7 +805,9 @@ export function chartBox(chart: Chart, cells: readonly Cell[], title: string): H
777805 return chartFrame(chart, drawChart(chart, cells, title));
778806 }
779807
780 /** The same box around a chart already drawn (`drawChart`'s own markup, from whoever read its rows). */
808 /**
809 * The same box around a chart already drawn (`drawChart`'s own markup, from whoever read its rows).
810 */
781811 export function chartFrame(chart: Chart, drawn: string): Html {
782812 return html`<div class="chart-box${chart === "table" ? " is-table" : ""}">${raw(drawn)}</div>`;
783813 }
@@ -971,8 +1001,9 @@ export interface RowOptions {
9711001 href?: string;
9721002 title: Html | string;
9731003 meta?: Html;
974 /** Facts about the row, one `dt`/`dd` pair each, in a `dl.row-facts` under the meta. With facts the row's
975 * main column is a `<div>`, so the `dl` is valid HTML: not for a `fold` row, whose `<summary>` takes phrasing only. */
1004 /** Facts about the row, one `dt`/`dd` pair each, in a `dl.row-facts` under the meta. With facts
1005 * the row's main column is a `<div>`, so the `dl` is valid HTML: not for a `fold` row, whose
1006 * `<summary>` takes phrasing only. */
9761007 facts?: readonly { label: string; value: Html | string }[];
9771008 /** Draw `.row-meta` even when `meta` is empty, for a script to write into. */
9781009 metaSlot?: boolean;
@@ -997,7 +1028,9 @@ export interface RowOptions {
9971028 /** The row folds: it is the `<summary>` of a `<details>` holding `body`,
9981029 * open when `open` says so. Its `lead` is the caret. */
9991030 fold?: { id: string; open: boolean; body: Html };
1000 /** Why the list's count leaves this row out on purpose (`data-apart`, `bind.ts`): a sealed report. */
1031 /**
1032 * Why the list's count leaves this row out on purpose (`data-apart`, `bind.ts`): a sealed report.
1033 */
10011034 apart?: string | undefined;
10021035 /** The row is a node of an ARIA tree: the row itself is the `treeitem` (it is what takes focus,
10031036 * so it says its level and, for a branch, `aria-expanded`), its `<li>` is `role="none"`,
@@ -1092,7 +1125,10 @@ export function tabs(items: TabItem[], ariaLabel: string): Html {
10921125 /** A segmented control built from links (a GET filter is navigation). */
10931126 export function seg(
10941127 items: { label: string; href: string; current: boolean; count?: number }[],
1095 /** These links are a list's tabs: every item a reader may open is under one (`data-rows-tabs`, `bind.ts`). */
1128 /**
1129 * These links are a list's tabs: every item a reader may open is under one (`data-rows-tabs`,
1130 * `bind.ts`).
1131 */
10961132 filters = false,
10971133 ): Html {
10981134 return html`<div class="seg"${filters ? raw(" data-rows-tabs") : null}>
test/status-badge.test.ts added +45
@@ -0,0 +1,45 @@
1 import { expect, test } from "bun:test";
2 import { envStateBadge, runStateBadge, statusBadge } from "../src/web/ui.ts";
3 import { components } from "../src/web/style/components.ts";
4
5 const RUNS = [
6 ["queued", "queued", "secondary", "Queued"],
7 ["running", "running", "attn", "Running"],
8 ["ok", "ok", "success", "Passed"],
9 ["failed", "failed", "danger", "Failed"],
10 ["cancelled", "cut", "outline", "Cancelled"],
outdated

Break this line up, and assert data-variant for each state. As written, a wrong mapping, for example failed shown as success, would still pass.

11 ] as const;
12
13 test("each run state wears the badge with its status, variant and word", () => {
14 for (const [state, status, variant, word] of RUNS) {
15 const html = String(runStateBadge(state));
16 expect(html).toContain(`data-status="${status}"`);
17 expect(html).toContain(`data-variant="${variant}"`);
18 expect(html).toContain(word);
19 }
20 });
21
22 test("each environment state maps to the right status", () => {
23 const cases = [
24 [envStateBadge("deploying"), "running"],
25 [envStateBadge("running"), "ok"],
26 [envStateBadge("failed"), "failed"],
27 [envStateBadge("stopped"), "cut"],
28 [envStateBadge("stopped", true), "held"],
29 [envStateBadge("asleep"), "held"],
30 ] as const;
31 for (const [html, status] of cases) {
32 expect(String(html)).toContain(`data-status="${status}"`);
33 }
34 });
35
36 test("an agent run that is ok says Done, and the badge always carries its word", () => {
37 expect(String(runStateBadge("ok", "agent"))).toContain("Done");
38 expect(String(statusBadge("failed", "Failed", "x"))).toContain("Failed");
39 });
40
41 test("the bar is styled for the badge, faded states stay above 3:1", () => {
42 const css = String(components);
43 expect(css).toContain('.badge[data-status]::before');

Non-blocking: the test name claims faded states stay above 3:1 but only checks that the opacity string exists. Rename it to what it asserts, or compute the contrast.

44 expect(css).toContain('[data-status="cut"]::before { opacity: .7; }');
45 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs