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
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/13634-status-at-a-glance-one-badge-shape-segme → main 7 commits fork 3 threads · 3 unresolved
4 files
changed +118
−30
docs/design/size-budget.json +9 −9
| @@ -1,27 +1,27 @@ | ||
| 1 | 1 | { |
| 2 | 2 | "/": { |
| 3 | 3 | "js": 22016, |
| 4 | "css": 44544 | |
| 4 | "css": 44800 | |
| 5 | 5 | }, |
| 6 | 6 | "/explore": { |
| 7 | 7 | "js": 21760, |
| 8 | "css": 44544 | |
| 8 | "css": 44800 | |
| 9 | 9 | }, |
| 10 | 10 | "/map": { |
| 11 | 11 | "js": 28672, |
| 12 | "css": 46080 | |
| 12 | "css": 46336 | |
| 13 | 13 | }, |
| 14 | 14 | "/:owner/:name": { |
| 15 | 15 | "js": 38144, |
| 16 | "css": 44544 | |
| 16 | "css": 44800 | |
| 17 | 17 | }, |
| 18 | 18 | "/changelog": { |
| 19 | 19 | "js": 26368, |
| 20 | "css": 44544 | |
| 20 | "css": 44800 | |
| 21 | 21 | }, |
| 22 | 22 | "/:owner/:name/next": { |
| 23 | 23 | "js": 23296, |
| 24 | "css": 44800 | |
| 24 | "css": 45056 | |
| 25 | 25 | }, |
| 26 | 26 | "/:owner/:name/space": { |
| 27 | 27 | "js": 29696, |
| @@ -37,14 +37,14 @@ | ||
| 37 | 37 | }, |
| 38 | 38 | "/pricing": { |
| 39 | 39 | "js": 21760, |
| 40 | "css": 44544 | |
| 40 | "css": 44800 | |
| 41 | 41 | }, |
| 42 | 42 | "/forges/new": { |
| 43 | 43 | "js": 21760, |
| 44 | "css": 44544 | |
| 44 | "css": 44800 | |
| 45 | 45 | }, |
| 46 | 46 | "/claim": { |
| 47 | 47 | "js": 24064, |
| 48 | "css": 44544 | |
| 48 | "css": 44800 | |
| 49 | 49 | } |
| 50 | 50 | } |
src/web/style/components.ts +7
| @@ -219,6 +219,13 @@ a.stat:hover { border-color: var(--border-strong); } | ||
| 219 | 219 | background: color-mix(in srgb, var(--attn) 12%, transparent); |
| 220 | 220 | } |
| 221 | 221 | .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; } | |
| 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; } | |
| 222 | 229 | /* A loader that turns: the one icon that means "still going". */ |
| 223 | 230 | .ico-loader { animation: spin 1.1s linear infinite; } |
| 224 | 231 | /* 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 { | ||
| 185 | 185 | extra?: string; |
| 186 | 186 | /** The element's id, for a script or a fragment link that finds it. */ |
| 187 | 187 | 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 | */ | |
| 189 | 192 | rel?: "next" | "prev"; |
| 190 | 193 | } |
| 191 | 194 | |
| @@ -384,6 +387,32 @@ export function verdictBadge( | ||
| 384 | 387 | return badge(look.label, { icon: look.icon, tone: look.tone }); |
| 385 | 388 | } |
| 386 | 389 | |
| 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 | ||
| 387 | 416 | /** |
| 388 | 417 | * A run's state (docs/APPS.md): the one badge a check wears on a pull, a |
| 389 | 418 | * row wears in a list, and a log page wears in its head. A finished deploy |
| @@ -392,18 +421,15 @@ export function verdictBadge( | ||
| 392 | 421 | export function runStateBadge(state: RunState, kind: RunKind = "deploy"): Html { |
| 393 | 422 | switch (state) { |
| 394 | 423 | case "queued": |
| 395 | return badge("Queued", { icon: "clock", variant: "secondary" }); | |
| 424 | return statusBadge("queued", "Queued", "clock"); | |
| 396 | 425 | case "running": |
| 397 | return badge("Running", { icon: "loader", tone: "attn" }); | |
| 426 | return statusBadge("running", "Running", "loader"); | |
| 398 | 427 | 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"); | |
| 403 | 429 | case "failed": |
| 404 | return badge("Failed", { icon: "x", tone: "danger" }); | |
| 430 | return statusBadge("failed", "Failed", "x"); | |
| 405 | 431 | case "cancelled": |
| 406 | return badge("Cancelled", { icon: "ban", variant: "outline" }); | |
| 432 | return statusBadge("cut", "Cancelled", "ban"); | |
| 407 | 433 | } |
| 408 | 434 | } |
| 409 | 435 | |
| @@ -411,16 +437,16 @@ export function runStateBadge(state: RunState, kind: RunKind = "deploy"): Html { | ||
| 411 | 437 | export function envStateBadge(state: EnvState, dormant = false): Html { |
| 412 | 438 | switch (state) { |
| 413 | 439 | 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"); | |
| 416 | 442 | case "deploying": |
| 417 | return badge("Deploying", { icon: "loader", tone: "attn" }); | |
| 443 | return statusBadge("running", "Deploying", "loader"); | |
| 418 | 444 | case "running": |
| 419 | return badge("Running", { icon: "play", tone: "success" }); | |
| 445 | return statusBadge("ok", "Running", "play"); | |
| 420 | 446 | case "asleep": |
| 421 | return badge("Asleep", { icon: "clock", variant: "outline" }); | |
| 447 | return statusBadge("held", "Asleep", "clock"); | |
| 422 | 448 | case "failed": |
| 423 | return badge("Failed", { icon: "alert", tone: "danger" }); | |
| 449 | return statusBadge("failed", "Failed", "alert"); | |
| 424 | 450 | } |
| 425 | 451 | } |
| 426 | 452 | |
| @@ -712,7 +738,9 @@ export function repoCounts(o: { | ||
| 712 | 738 | openPulls?: number | null | undefined; |
| 713 | 739 | /** Some origins report one number for issues *and* pulls; say so. */ |
| 714 | 740 | 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 | */ | |
| 716 | 744 | of?: { ownerName: string; name: string } | undefined; |
| 717 | 745 | }): Html { |
| 718 | 746 | const issues = o.openIssues ?? null; |
| @@ -777,7 +805,9 @@ export function chartBox(chart: Chart, cells: readonly Cell[], title: string): H | ||
| 777 | 805 | return chartFrame(chart, drawChart(chart, cells, title)); |
| 778 | 806 | } |
| 779 | 807 | |
| 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 | */ | |
| 781 | 811 | export function chartFrame(chart: Chart, drawn: string): Html { |
| 782 | 812 | return html`<div class="chart-box${chart === "table" ? " is-table" : ""}">${raw(drawn)}</div>`; |
| 783 | 813 | } |
| @@ -971,8 +1001,9 @@ export interface RowOptions { | ||
| 971 | 1001 | href?: string; |
| 972 | 1002 | title: Html | string; |
| 973 | 1003 | 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. */ | |
| 976 | 1007 | facts?: readonly { label: string; value: Html | string }[]; |
| 977 | 1008 | /** Draw `.row-meta` even when `meta` is empty, for a script to write into. */ |
| 978 | 1009 | metaSlot?: boolean; |
| @@ -997,7 +1028,9 @@ export interface RowOptions { | ||
| 997 | 1028 | /** The row folds: it is the `<summary>` of a `<details>` holding `body`, |
| 998 | 1029 | * open when `open` says so. Its `lead` is the caret. */ |
| 999 | 1030 | 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 | */ | |
| 1001 | 1034 | apart?: string | undefined; |
| 1002 | 1035 | /** The row is a node of an ARIA tree: the row itself is the `treeitem` (it is what takes focus, |
| 1003 | 1036 | * 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 { | ||
| 1092 | 1125 | /** A segmented control built from links (a GET filter is navigation). */ |
| 1093 | 1126 | export function seg( |
| 1094 | 1127 | 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 | */ | |
| 1096 | 1132 | filters = false, |
| 1097 | 1133 | ): Html { |
| 1098 | 1134 | 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 |
||
| 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 | }); |
new above
offline
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.