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

A component gallery at /design/components, where the parts the cold-read audit blames are judged #16644

Merged opened this

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

Merged

scout/forge:scout/5912-a-component-gallery-at-design-components → main 0 commits fork 4 threads · 4 unresolved

  • Merged. scout/5912-a-component-gallery-at-design-components was merged into main as a57ee53.

Review

Sign in to review this change.
11 files changed +288 −1
docs/design/audit.md +1
@@ -82,6 +82,7 @@ Machine routes are not pages and have no entry: `/audit.csv`,
8282 - `/releases` — `pages/releases.ts` · the forge's kept releases and rollback · `/settings/backups` (both are "go back") · none seen.
8383 - `/design` — `studio/design.ts` · the forge's theme: colour and scale fields, four side-by-side samples, publish and revert for an admin, history; a non-admin reads it · `/design/components` · none seen.
8484 - `/design/components` — `studio/design.ts` · the forge's components drawn with the live theme, searchable, signed in · `/design` · none seen.
85 - `/design/gallery` — `pages/design-components.ts` · every component §5 names, once at the window's width, public and static, so a part the cold-read audit blames is judged in one place · `/design/components` (the live-theme explorer, signed in) · none seen.
8586 - `/changelog` — `pages/changelog.ts` · the last 30 releases with their dates and pulls, public · `/releases` (the signed-in kept releases) · none seen.
8687 - `/displays` — `pages/displays.ts` · every display the viewer may read, each with its layout, repository and showcased demos; a stranger signs in first · none yet (read only; a repository's display is its own page) · none seen.
8788 - `/api` — `pages/api.ts` · the forge's OpenAPI operations by area, with search and Try it, public · the footer, the OpenAPI document, the terminal's API screen · none seen. An app's own spec is its `/:owner/:name/api` tab.
src/http/server.ts +2
@@ -47,6 +47,7 @@ import { prerenderComments } from "../web/prerender.ts";
4747 import { heapCensusSubmit, systemPage, systemStream } from "../web/pages/system.ts";
4848 import { bottleneckPage } from "../web/pages/bottleneck.ts";
4949 import { contributePage } from "../web/pages/contribute.ts";
50 import { designComponentsPage } from "../web/pages/design-components.ts";
5051 import { pipelinePage } from "../web/pages/pipeline.ts";
5152 import { adminDataPage, appDataCsv, appDataPage, dataPage } from "../web/pages/data.ts";
5253 import { fleetAct, fleetReceipt, fleetUndo } from "../web/pages/fleet-ops.ts";
@@ -1311,6 +1312,7 @@ export function buildRouter(): Router<Handler> {
13111312 router.add("GET", "/boards/:slug", boardShow);
13121313 router.add("GET", "/boards/:slug/live", boardLive);
13131314 router.add("POST", "/boards/:slug/:op", boardPost);
1315 router.add("GET", "/design/gallery", designComponentsPage);
13141316 router.add("GET", "/admin/data", adminDataPage);
13151317 router.add("GET", "/admin/limits", limitsPage);
13161318 router.add("GET", "/admin/flows", allFlowsPage);
src/web/pages/design-components.ts added +137
@@ -0,0 +1,137 @@
1 /**
2 * The component gallery (`/design/gallery`): every component docs/DESIGN.md
3 * §5 names, drawn by the function that draws it on the real pages (or, where the
4 * part belongs to one page, the markup that page gives its class), once, at the
5 * window's own width: a media query reads the window, so to judge the phone
6 * layout, make the window 390 px wide. When the cold-read audit blames a heading, a button or a
7 * list, this is where it is judged. Nothing here reads the database or the
8 * request: it is the same page for everyone, and every sample is static text.
9 */
10
11 import { notePhase, takeSessionTime } from "../../core/route_timing.ts";
12 import { THEMES } from "../../design/themes.ts";
13 import type { Ctx } from "../../http/context.ts";
14 import { Html, html, raw } from "../html.ts";
15 import { pageHead } from "../chrome.ts";
16 import { page } from "../layout.ts";
17 import {
18 labelCss, avatar, badge, btn, card, counts, crumbs, disclosure, dot, empty, field, iconBtn, kbd, labelChip,
19 listCard, menu, meter, nameMark, pager, pill, row, seg, sha, stat, stateBadge, tabs, tlComment,
20 tlEvent, userTag, verdictBadge, runStateBadge, envStateBadge,
21 } from "../ui.ts";
22
23 const r = (markup: string): Html => raw(markup);
24
25 const sampleRows = [
26 row({ href: "#", title: "Make the feed answer in under 50 ms", meta: html`#41 · opened by <b>scout</b>`, state: "open" }),
27 row({ href: "#", title: "Escape every output", meta: html`#38 · merged`, state: "merged" }),
28 ];
29
30 /** One entry per row of the §5 table, keyed by the name in bold there. */
31 export const samples: readonly (readonly [name: string, sample: Html])[] = [
32 ["page head", pageHead("A page title", { sub: "One plain sentence on what the page is for." })],
33 ["button", html`<div class="gallery-line">${btn("Primary", { variant: "primary" })}${btn("Secondary", { variant: "secondary" })}${btn("Outline", { variant: "outline" })}${btn("Ghost", { variant: "ghost" })}${btn("Danger", { variant: "danger" })}${btn("Small", { size: "sm" })}${btn("Disabled", { disabled: true })}</div>`],
34 ["icon button", iconBtn("check", "Mark done")],
35 ["input / textarea / select", html`<div class="gallery-col"><input class="input" aria-label="Text" value="An input" /><textarea class="input" aria-label="Notes" rows="2">A textarea</textarea><select class="input" aria-label="Choice"><option>A select</option></select></div>`],
36 ["form field", field({ label: "Name", name: "gallery-name", value: "scout", hint: "Lowercase, no spaces." })],
37 ["checkbox", r(`<label class="check"><input type="checkbox" checked /> Notify me</label>`)],
38 ["badge", html`<div class="gallery-line">${badge("default")}${badge("accent", { tone: "attn" })}${badge("danger", { tone: "danger" })}${badge("outline", { variant: "outline" })}${stateBadge("open")}</div>`],
39 ["stat", html`<div class="stats">${stat({ label: "Ships", value: 12, note: "this week" })}${stat({ label: "Forks", value: 3 })}</div>`],
40 ["label chip", labelChip({ name: "bug", color: "d73a4a" })],
41 ["author", html`<div class="gallery-line">${userTag("scout")}</div>`],
42 ["name mark", html`${nameMark("crew")}${nameMark("owner")}`],
43 ["avatar", html`<div class="gallery-line">${avatar("scout")}${avatar("scout", "lg")}</div>`],
44 ["count", counts([{ icon: "comment", value: 4, label: "comments" }])],
45 ["stat pill", html`${pill(7)} ${pill(2, "accent")} ${pill(9, "danger")}`],
46 ["status dot", html`${dot("success")} ${dot("attn")} ${dot("danger")}`],
47 ["sha", sha("0123456789abcdef0123456789abcdef01234567")],
48 ["progress bar", r(`<progress max="10" value="6" aria-label="6 of 10 done"></progress>`)],
49 ["meter", meter(64, "Budget used")],
50 ["kbd", kbd(["g", "i"])],
51 ["card", card(html`<p>Body text inside a card.</p><p class="muted">A second line, so the card holds more than one sentence.</p>`, { head: html`<h3>Card head</h3>`, foot: html`<span>foot</span>` })],
52 ["list row", listCard(sampleRows)],
53 ["edit row", r(`<form class="edit-row" onsubmit="return false"><input class="input" aria-label="Title" value="Rename me" /><button class="btn" type="button">Save</button></form>`)],
54 ["colour field", html`<label class="color-field"><input type="color" value="${THEMES.light.tokens.accent}" aria-label="Colour" /> <span>accent</span></label>`],
55 ["table", r(`<table class="table"><thead><tr><th>Name</th><th>State</th></tr></thead><tbody><tr><td>feed</td><td>live</td></tr><tr><td>map</td><td>live</td></tr></tbody></table>`)],
56 ["tabs", tabs([{ label: "Issues", href: "#", count: 4, current: true }, { label: "Pulls", href: "#", current: false }], "Gallery tabs")],
57 ["segmented control", seg([{ label: "Open", href: "#", current: true }, { label: "Closed", href: "#", current: false }])],
58 ["menu", menu({ trigger: "Actions", items: [{ label: "Rename", href: "#" }, { label: "Archive", href: "#" }] })],
59 ["disclosure", disclosure("More detail", html`<p>Hidden until opened.</p>`)],
60 ["dialog", r(`<div class="dialog gallery-static" role="dialog" aria-label="Sample dialog"><div class="dialog-head"><h2>Delete this?</h2></div><div class="dialog-foot"><button class="btn" type="button">Cancel</button></div><p>Delete this?</p></div>`)],
outdated

Hand-rolled dialog with an inline style. Use the named dialog component, or a gallery class that sets position, so the sample is what the real page draws. The same applies to lines 63 and 85.

61 ["tooltip", r(`<span class="btn" data-tip="A tip, on hover and focus" tabindex="0">Hover me</span>`)],
62 ["toast / flash", r(`<div class="toast" role="status">Saved.</div>`)],
63 ["command palette", r(`<div class="dialog palette gallery-static"><input class="input" aria-label="Search" placeholder="Type a command" /><div class="palette-list" role="listbox" aria-label="Results"></div></div>`)],
64 ["breadcrumb", crumbs([{ label: "forge", href: "#" }, { label: "design", href: "#" }, { label: "components" }])],
65 ["pagination", pager({ prev: "#", next: "#", note: "Page 2" })],
66 ["timeline item", html`${tlEvent({ icon: "check", body: html`<span>scout closed this</span>` })}${tlComment(card(html`<p>A comment.</p><p class="muted">Posted just now.</p>`))}`],
67 ["empty state", empty({ icon: "lock", title: "Nothing here yet", note: "It will show up when it happens." })],
68 ["diff file", r(`<div class="diff-file"><div class="diff-file-head">src/a.ts</div><pre class="code">+ added\n- removed</pre></div>`)],
69 ["code block", r(`<pre class="code">const x = 1;</pre>`)],
70 ["prose", r(`<div class="prose"><h3>A heading</h3><p>A paragraph with <a href="#">a link</a> and <code>code</code>.</p></div>`)],
71 ["settings shell", r(`<div class="settings"><nav class="settings-nav"><a href="#">Profile</a></nav><div class="settings-main"><p>Main column</p></div></div>`)],
72 ["repo header", r(`<header class="repo-head"><h2>trevato/forge</h2></header>`)],
73 ["where strip", r(`<div class="where"><span class="where-place">production</span></div>`)],
74 ["live-browse banner", r(`<p class="live-note">Reading the live app, not a commit.</p>`)],
75 ["where-it-lives block", r(`<div class="where-block"><p>Lives at forge.example</p></div>`)],
76 ["mirror stages", r(`<div class="list stages" aria-live="polite"><div class="row"><div class="row-main"><span class="row-title">Fetch</span></div></div></div>`)],
77 ["origin chip", r(`<span class="repo-origin"><span class="origin-chip">from github</span></span>`)],
78 ["origin state badge", badge("mirrored")],
79 ["imported author", r(`<span class="byline origin-by"><span class="byline-name">octocat</span></span>`)],
80 ["pin toggle", r(`<div class="repo-where"><form class="where-pin" onsubmit="return false"><button class="btn" type="button">Pin</button></form></div>`)],
81 ["device code", r(`<code class="device-code">ABCD-1234</code>`)],
82 ["sticky action", r(`<div class="sticky-action"><button class="btn" data-variant="primary" type="button">Save</button></div>`)],
83 ["count group", r(`<div class="counts"><span class="count">3 issues</span><span class="count">1 pull</span></div>`)],
84 ["file explorer", r(`<div class="code-layout"><div class="explorer-panel"><div class="explorer"><a class="ex-dir" href="#">src</a><a class="ex-file" href="#">main.ts</a></div></div></div>`)],
85 ["fuzzy finder", r(`<div class="dialog palette finder gallery-static"><input class="input" aria-label="Find a file" placeholder="Find a file" /><div class="palette-list" role="listbox" aria-label="Files"></div></div>`)],
86 ["file editor", r(`<form class="editor-form" onsubmit="return false"><div class="editor-head">main.ts</div><div class="editor-wrap"><textarea class="editor" aria-label="File" rows="3">const x = 1;</textarea></div></form>`)],
87 ["branch row", r(`<div class="branch-row"><span>main</span><span class="branch-div"><span class="ahead">2</span><span class="behind">0</span></span></div>`)],
88 ["code hit", r(`<div class="code-hit"><span class="code-line">const <mark>feed</mark> = 1;</span></div>`)],
89 ["verdict badge", html`${verdictBadge("approved")} ${verdictBadge("changes_requested")}`],
90 ["reviews chip", r(`<span class="reviews-chip">2 reviews</span>`)],
91 ["review card", r(`<div class="card review-card"><div class="review-verdicts">approved by atlas</div></div>`)],
92 ["review thread", card(html`<p class="dc-review">Rename this.</p><p class="muted">Open · on src/a.ts</p>`)],
93 ["propose card", r(`<fieldset class="editor-target propose"><legend>Propose</legend><span class="propose-line">to a new branch</span></fieldset>`)],
94 ["run state badge", html`${runStateBadge("ok")} ${runStateBadge("failed")} ${runStateBadge("running")}`],
95 ["env state badge", html`${envStateBadge("running")} ${envStateBadge("deploying")} ${envStateBadge("failed")}`],
96 ["app strip", r(`<div class="app-strip"><span>lab</span><span>production</span></div>`)],
97 ["environment card", r(`<div class="card env-card"><div class="env-facts">serving · 3 min ago</div><div class="env-error">last build failed</div></div>`)],
98 ["checks line", r(`<p class="checks-line"><span class="ok">12 passed</span> <span class="bad">1 failed</span> <span class="now">1 running</span></p>`)],
99 ["run log", r(`<pre class="run-log">bun test v1\n 12 pass\n</pre>`)],
100 ["assignee card", r(`<div class="card"><form class="edit-row" onsubmit="return false"><select class="input" aria-label="Assignee"><option>scout</option></select></form></div>`)],
101 ["inbox", listCard(sampleRows)],
102 ["look", r(`<div class="looks"><figure class="look"><figcaption>Home at 390</figcaption></figure></div>`)],
103 ["board", r(`<div class="board"><div class="board-grid"><div class="board-region">A region</div></div></div>`)],
104 ["stacked bar chart", r(`<div class="plots"><div class="plot"><span class="plot-name">Spend</span></div><div class="plot-legend">by day</div></div>`)],
105 ["chart", r(`<div class="chart-box"><svg class="chart" viewBox="0 0 100 20" role="img" aria-label="A rising line"><polyline fill="none" stroke="currentColor" points="0,18 40,12 100,2"/></svg></div>`)],
106 ];
107
108 const slug = (name: string) => name.replace(/[^a-z0-9]+/gi, "-").replace(/^-|-$/g, "").toLowerCase();
109
110 const galleryCss = /* css */ `
111 .gallery-index{display:flex;flex-wrap:wrap;gap:4px 12px;margin:0 0 16px}
112 .gallery-part{margin:0 0 24px;min-width:0}
113 .gallery-part h2{font-size:15px;margin:0 0 8px}
114 .gallery-frame{min-width:0;max-width:100%;padding:0 0 12px;border-bottom:1px solid var(--border);overflow-x:auto}
115 .gallery-line{display:flex;flex-wrap:wrap;gap:8px;align-items:center}
outdated

Principle 6: a dashed box around each sample. Use a hairline where the frame ends. Also use var(--border) with no hex fallback, and give the small label var(--muted) rather than opacity.

116 .gallery-col{display:grid;gap:8px}
117 .gallery-static{position:static;display:block;transform:none;margin:0}
118 `;
119
120 export function galleryBody(): Html {
121 return html`${pageHead("Component gallery", { sub: `The ${samples.length} components docs/DESIGN.md §5 names, each drawn once, so a part the cold-read audit blames can be judged.` })}
122 <nav class="gallery-index" aria-label="Components">${samples.map(([name]) => html`<a href="#c-${slug(name)}">${name}</a>`)}</nav>
123 ${samples.map(
124 ([name, sample]) => html`<section class="gallery-part" id="c-${slug(name)}" data-component="${name}">
outdated

Principle 1: this sub explains the page's mechanism. Say what the page is for in one sentence. Principle 2: a 390 px-wide div does not trigger the phone layout, because media queries read the window.

125 <h2>${name}</h2>
126 <div class="gallery-frame">${sample}</div>
127 </section>`,
128 )}`;
129 }
130
131 export function designComponentsPage(ctx: Ctx): Response {
132 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
133 const rendering = performance.now();
134 const res = page({ ctx, title: "Component gallery", wide: true, styleCss: galleryCss + labelCss([{ name: "bug", color: "d73a4a" }]), body: galleryBody() });
135 notePhase(ctx.request, "render", performance.now() - rendering);
136 return res;
137 }
src/web/studio/design.ts +1 −1
@@ -578,7 +578,7 @@ export function componentsPage(ctx: Ctx): Response {
578578 const cell = (e: Entry, mode: "light" | "dark"): Html =>
579579 html`<div class="cx-cell cx-${mode}"><p class="small">${mode}</p>${e.render()}</div>`;
580580 const body = html`${homeTabs("design")}${pageHead("Components", { sub: "The forge's own components against the theme" })}
581 <p class="small"><a href="/design">Theme editor</a>${parsed.ok ? "" : html` · <span role="alert">${parsed.error}</span>`}</p>
581 <p class="small"><a href="/design">Theme editor</a> · <a href="/design/gallery">Component gallery</a>${parsed.ok ? "" : html` · <span role="alert">${parsed.error}</span>`}</p>
outdated

Principle 8 (plain words): "at 390 and 1440 px" is no longer true. The gallery draws each component once, at the window's width. Rename the link to "Component gallery" so it says what the page is.

582582 <form method="get" action="/design/components" role="search">
583583 ${field({ label: "Filter", name: "q", value: q, type: "search", maxlength: 80 })}
584584 ${btn("Filter", { variant: "secondary" })}
test/design-components.test.ts added +65
@@ -0,0 +1,65 @@
1 /**
2 * /design/gallery (#5912): every component DESIGN.md §5 names is on the page, once.
3 */
4
5 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
6 import { mkdtemp, readFile, rm } from "node:fs/promises";
7 import { tmpdir } from "node:os";
8 import { join } from "node:path";
9 import { createApp, type App } from "../src/app.ts";
10 import { serve, type Servers } from "../src/http/server.ts";
11 import { samples } from "../src/web/pages/design-components.ts";
12
13 /** The bold name opening each row of the §5 vocabulary table. */
14 async function namedComponents(): Promise<string[]> {
15 const doc = await readFile(join(import.meta.dir, "../docs/design/sections/5-components.md"), "utf8");
16 const start = doc.indexOf("## 5. The component vocabulary");
17 const end = doc.indexOf("Two things are deliberately", start);
18 return [...doc.slice(start, end).matchAll(/^\| \*\*([^*]+)\*\*/gm)].map((m) => m[1]!.trim());
19 }
20
21 describe("component gallery", () => {
22 let dataDir: string;
23 let app: App;
24 let servers: Servers;
25 beforeAll(async () => {
26 dataDir = await mkdtemp(join(tmpdir(), "forge-gallery-"));
27 app = createApp({ dataDir, port: 0, forgeRepo: "acme/forge" });
28 servers = await serve(app);
29 });
30 afterAll(async () => {
31 servers.stop();
32 app.close();
33 await rm(dataDir, { recursive: true, force: true });
34 });
35
36 test("answers 200 and lists every component §5 names", async () => {
37 const names = await namedComponents();
38 expect(names.length).toBeGreaterThan(60);
39 const res = await fetch(`${servers.url}/design/gallery`);
40 expect(res.status).toBe(200);
41 expect(res.headers.get("x-content-type-options")).toBe("nosniff");
42 const body = await res.text();
43 for (const name of names) {
44 const section = body.split(`data-component="${name.replace(/&/g, "&amp;")}"`)[1];
45 expect(section, `${name} is missing from the gallery`).toBeDefined();
46 expect(section!.slice(0, 20000)).toContain("gallery-frame");
47 }
48 });
49
50 test("shows nothing §5 does not name", async () => {
51 const names = new Set(await namedComponents());
52 for (const [name] of samples) expect(names.has(name), `${name} is not in §5`).toBe(true);
53 });
54
55 test("the rendered page keeps one hairline frame per sample, with no box or fixed width", async () => {
56 const body = await (await fetch(`${servers.url}/design/gallery`)).text();
57 const parts = body.split('class="gallery-part"').slice(1);
58 expect(parts.length).toBe(samples.length);
59 for (const part of parts) expect(part.split('class="gallery-frame"').length - 1).toBe(1);
60 expect(body).toContain(".gallery-frame{min-width:0;max-width:100%;padding:0 0 12px;border-bottom:1px solid var(--border)");
61 expect(body).not.toMatch(/gallery[^{]*\{[^}]*(dashed|opacity)/);
62 expect(body).not.toMatch(/data-w=/);
63 expect(body).toMatch(/type="color" value="#[0-9a-f]{6}"/i);
64 });
65 });
test/design-theme.test.ts +2
@@ -195,6 +195,8 @@ describe("design tab over http", () => {
195195 expect(text).toContain("cx-dark");
196196 expect(text).toContain("Badge");
197197 expect(text).not.toContain("Empty state");
198 expect(text).toContain(`<a href="/design/gallery">Component gallery</a>`);
199 expect(text).not.toContain("390 and 1440");
198200 });
199201
200202 test("a publish is pushed to an open page within 2 s", async () => {
test/palette-roster.test.ts +4
@@ -230,6 +230,7 @@ test("a site-admin person is offered the whole roster", () => {
230230 ["experiments", "Experiments", "what each cloud machine costs and answers"],
231231 ["bets", "Bets", "back, stop and finish a repository\'s bets"],
232232 ["origins", "Connected accounts", "the hosts your mirrors come from"],
233 ["design-gallery", "Component gallery", "every component the design names"],
233234 ["domains", "Failure domains", "failure domains and their last drill"],
234235 ["feed", "Feed", "what happened, ranked; r replies on a post about an issue or pull, l likes, h who liked, p its permalink, o a run's log"],
235236 ["feature-review", "Menu entries to review", "absorbed apps whose declared name or page changed: accept them"],
@@ -343,6 +344,7 @@ test("a site-admin agent is offered the roster without the person-only entries",
343344 ["cloud", "Cloud accounts", "provider tokens, what they are used for, today's calls"],
344345 ["pinned", "Pinned forges", "deploy, update and roll back a forge on your cloud"],
345346 ["experiments", "Experiments", "what each cloud machine costs and answers"],
347 ["design-gallery", "Component gallery", "every component the design names"],
346348 ["feed", "Feed", "what happened, ranked; r replies on a post about an issue or pull, l likes, h who liked, p its permalink, o a run's log"],
347349 ["feature-feed", "Feature feeds", "the feed items about an absorbed app, as Settings › Features shows them"],
348350 ["front", "Front page", "the apps a first visitor sees, ranked; an admin pins or hides"],
@@ -460,6 +462,7 @@ test("a member person is offered the signed-in roster without the admin entries"
460462 ["bulk", "Bulk actions", "your last bulk actions; u undoes one inside its day"],
461463 ["bets", "Bets", "back, stop and finish a repository\'s bets"],
462464 ["origins", "Connected accounts", "the hosts your mirrors come from"],
465 ["design-gallery", "Component gallery", "every component the design names"],
463466 ["feed", "Feed", "what happened, ranked; r replies on a post about an issue or pull, l likes, h who liked, p its permalink, o a run's log"],
464467 ["feature-feed", "Feature feeds", "the feed items about an absorbed app, as Settings › Features shows them"],
465468 ["front", "Front page", "the apps a first visitor sees, ranked; an admin pins or hides"],
@@ -521,6 +524,7 @@ test("signed out, the palette offers sign-in and the public entries", () => {
521524 ["health-voice", "Health — spoken", "how the forge is, in two plain sentences"],
522525 ["audit", "Who can do what", "each app's doors from its contract.json: yes, own or no"],
523526 ["apps-crew", "What the crew is doing", "one plain sentence per app: who is on what"],
527 ["design-gallery", "Component gallery", "every component the design names"],
524528 ["front", "Front page", "the apps a first visitor sees, ranked; an admin pins or hides"],
525529 ["origin-ahead", "New commits upstream", "mirrors whose origin has moved on: take them"],
526530 ["security", "Security", "what the forge enforces for everyone, and how to report a problem"],

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs