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

Design: the /boards data and pin forms draw their fields as §5 `.field`, not `.qf` #3910

Parked opened this
Closed without merging

scout/forge:scout/3906-design-the-boards-data-and-pin-forms-dra → main 5 commits fork 4 threads · 4 unresolved

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
7 files changed +93 −90
src/web/pages/boards-view.ts +11 −17
@@ -18,7 +18,7 @@ import { liveRegionsJs } from "../client.ts";
1818 import { notFoundPage } from "../chrome.ts";
1919 import { html, raw, when, type Html } from "../html.ts";
2020 import { fragment, page } from "../layout.ts";
21 import { btn, card, empty } from "../ui.ts";
21 import { btn, card, empty, field, selectField } from "../ui.ts";
2222 import { flowPanel } from "./flow-panel.ts";
2323 import { isPinned, listPins } from "../../boards/pins.ts";
2424 import { panelData, runFor } from "../../boards/panel_data.ts";
@@ -27,9 +27,6 @@ import { cellsOf, chartBox, paramsOf, queryFields, readParams } from "./boards.t
2727 /** The events the panels' queries read (runs, pulls, checks, issues, usage): any of them may change a chart. */
2828 const READS = "run.queued,run.started,run.finished,pull.*,check.*,issue.*,usage.*";
2929
30 const option = (value: string, selected: boolean) =>
31 html`<option value="${value}" ${selected ? raw("selected") : null}>${value}</option>`;
32
3330 /** Where a panel lives: its board's slug and its place on it, which name its data door. */
3431 export type PanelAt = { slug: string; index: number };
3532
@@ -83,7 +80,7 @@ export async function boardsList(ctx: Ctx): Promise<Response> {
8380 const listed = await listAllBoards(ctx.app, ctx.auth.user);
8481 if (!listed.ok) return notFoundPage(ctx);
8582 const make = html`<form method="post" action="/boards/new" class="bform">
86 <label class="qf"><span>New board</span><input class="input" name="title" required maxlength="${String(MAX_TITLE)}" placeholder="Title" /></label>
83 ${field({ id: "new-title", label: "New board", name: "title", required: true, maxlength: MAX_TITLE, placeholder: "Title" })}
8784 ${btn("Make board", { variant: "primary" })}
8885 </form>`;
8986 const body =
@@ -110,15 +107,12 @@ export async function boardsList(ctx: Ctx): Promise<Response> {
110107 }
111108
112109 function panelForm(slug: string, op: string, p: Panel | undefined, index: number, fields: Html): Html {
110 const at = op === "edit" ? `e${String(index)}` : "m";
113111 return html`<form method="post" action="/boards/${slug}/${op}" class="bform">
114112 ${op === "edit" ? html`<input type="hidden" name="index" value="${String(index)}" />` : null}
115 <label class="qf"><span>Panel title</span><input class="input" name="title" required maxlength="${String(MAX_TITLE)}" value="${p?.title ?? ""}" placeholder="Panel title" /></label>
116 <label class="qf"><span>Width</span><select class="input" name="w">
117 ${[1, 2, 3].slice(0, MAX_W).map((n) => html`<option value="${String(n)}" ${n === (p?.w ?? 1) ? raw("selected") : null}>${String(n)} wide</option>`)}
118 </select></label>
119 <label class="qf"><span>Height</span><select class="input" name="h">
120 ${[1, 2, 3].slice(0, MAX_H).map((n) => html`<option value="${String(n)}" ${n === (p?.h ?? 1) ? raw("selected") : null}>${String(n)} high</option>`)}
121 </select></label>
113 ${field({ id: `${at}-title`, label: "Panel title", name: "title", required: true, maxlength: MAX_TITLE, value: p?.title ?? "", placeholder: "Panel title" })}
114 ${selectField({ id: `${at}-w`, label: "Width", name: "w", options: [1, 2, 3].slice(0, MAX_W).map((n) => ({ value: String(n), label: `${String(n)} wide`, selected: n === (p?.w ?? 1) })) })}
115 ${selectField({ id: `${at}-h`, label: "Height", name: "h", options: [1, 2, 3].slice(0, MAX_H).map((n) => ({ value: String(n), label: `${String(n)} high`, selected: n === (p?.h ?? 1) })) })}
122116 ${fields}
123117 ${btn(op === "edit" ? "Save panel" : "Add panel", { variant: "primary" })}
124118 </form>`;
@@ -138,7 +132,7 @@ function manage(slug: string, board: Board, adding: Html, pins: ReturnType<typeo
138132 const one = (p: Panel, i: number) => html`<li class="row bmanage">
139133 <details>
140134 <summary><strong>${p.title}</strong> <span class="muted small">${CHART_NAMES[p.chart]} · ${String(p.w)}×${String(p.h)}</span></summary>
141 ${panelForm(slug, "edit", p, i, queryFields(paramsOf(p.query, p.chart)))}
135 ${panelForm(slug, "edit", p, i, queryFields(paramsOf(p.query, p.chart), `e${String(i)}`))}
142136 </details>
143137 ${pinForm(slug, p.title, isPinned(pins, slug, p.title))}
144138 <form method="post" action="/boards/${slug}/move" class="row-actions">
@@ -161,12 +155,12 @@ function manage(slug: string, board: Board, adding: Html, pins: ReturnType<typeo
161155 )}
162156 ${card(
163157 html`<form method="post" action="/boards/${slug}/rename" class="bform">
164 <label class="qf"><span>Board title</span><input class="input" name="title" required maxlength="${String(MAX_TITLE)}" value="${board.title}" /></label>
158 ${field({ id: "board-title", label: "Board title", name: "title", required: true, maxlength: MAX_TITLE, value: board.title })}
165159 ${btn("Rename")}
166160 </form>
167161 <form method="post" action="/boards/${slug}/settings" class="bform">
168 <label class="qf"><span>Range</span><select class="input" name="range">${RANGES.map((r) => option(r, r === board.range))}</select></label>
169 <label class="qf"><span>Live</span><select class="input" name="refresh"><option value="off" ${board.refresh === "off" ? raw("selected") : null}>off</option><option value="10s" ${board.refresh === "off" ? null : raw("selected")}>on: redraw when events arrive</option></select></label>
162 ${selectField({ id: "board-range", label: "Range", name: "range", options: RANGES.map((r) => ({ value: r, label: r, selected: r === board.range })) })}
163 ${selectField({ id: "board-refresh", label: "Live", name: "refresh", options: [{ value: "off", label: "off", selected: board.refresh === "off" }, { value: "10s", label: "on: redraw when events arrive", selected: board.refresh !== "off" }] })}
170164 ${btn("Save settings")}
171165 </form>
172166 <form method="post" action="/boards/${slug}/duplicate" class="bform">${btn("Duplicate")}</form>
@@ -190,7 +184,7 @@ export async function boardShow(ctx: Ctx): Promise<Response> {
190184 body: html`<div class="page-head"><h1>${board.title}</h1>
191185 ${btn("All boards", { href: "/boards", variant: "ghost" })}</div>
192186 ${panels}
193 ${manage(slug, board, queryFields(readParams(ctx.url.searchParams)), listPins(ctx.app.db, ctx.auth.user?.id ?? ""))}`,
187 ${manage(slug, board, queryFields(readParams(ctx.url.searchParams), "m"), listPins(ctx.app.db, ctx.auth.user?.id ?? ""))}`,
194188 scriptJs: liveRegionsJs,
195189 });
196190 notePhase(ctx.request, "render", performance.now() - rendering);
src/web/pages/boards.ts +30 −63
@@ -18,7 +18,7 @@ import { notePhase, takeSessionTime, timePhase, timePhaseAsync } from "../../cor
1818 import { notFoundPage } from "../chrome.ts";
1919 import { html, raw, when } from "../html.ts";
2020 import { page } from "../layout.ts";
21 import { btn, card, empty } from "../ui.ts";
21 import { btn, card, empty, field, selectField } from "../ui.ts";
2222
2323 const BUCKET_MS = { minute: 60_000, hour: 3_600_000, day: 86_400_000 } as const;
2424 const AGGREGATES = ["count", "sum", "avg", "max"] as const;
@@ -137,67 +137,36 @@ export function machineLinks(now: number): { label: string; href: string }[] {
137137 ];
138138 }
139139
140 const option = (value: string, label: string, selected: boolean) =>
141 html`<option value="${value}" ${selected ? raw("selected") : null}>${label}</option>`;
142
143140 /** The inputs that say a query, filled from `p`; the page's form and a panel's share them. */
144 export function queryFields(p: Params) {
141 export function queryFields(p: Params, idp: string) {
145142 const src = Object.hasOwn(SOURCES, p.source) ? SOURCES[p.source]! : undefined;
146143 const cols = src ? Object.keys(src.columns) : [];
144 const opt = (value: string, label: string, current: string) => ({ value, label, selected: value === current });
outdated

The default prefix "q" makes ids collide wherever this is called more than once on a page (boards-view.ts:141 and :193). Make the prefix required so a caller cannot forget it, and pass unique ones.

145 const pick = (name: string, label: string, options: { value: string; label: string; selected: boolean }[], hint?: string) =>
146 selectField({ label, name, id: `${idp}-${name}`, options, ...(hint ? { hint } : {}) });
147 const text = (name: string, label: string, value: string, placeholder: string) =>
outdated

Hand-rolled .field markup. Use selectField() / field() from ui.ts for every control here, passing id: ${idp}-name``.

148 field({ label, name, id: `${idp}-${name}`, value, placeholder, mono: true, maxlength: MAX_PARAM });
147149 return html`
148 <label class="qf"><span>Chart</span>
149 <select class="input" name="chart">
150 ${CHARTS.map((c) => option(c, CHART_NAMES[c], c === p.chart))}
151 </select>
152 </label>
153 <label class="qf"><span>Source</span>
154 <select class="input" name="source">
155 ${Object.keys(SOURCES).map((n) => option(n, n, n === p.source))}
156 </select>
157 </label>
158 <label class="qf"><span>Aggregate</span>
159 <select class="input" name="aggregate">
160 ${AGGREGATES.map((a) => option(a, a, a === p.aggregate))}
161 </select>
162 </label>
163 <label class="qf" title="Column to aggregate"><span>Column</span>
164 <select class="input" name="column">
165 ${option("", "(rows)", p.column === "")}
166 ${cols.filter((c) => src!.columns[c] === "number").map((c) => option(c, c, c === p.column))}
167 </select>
168 </label>
169 <label class="qf" title="Group by"><span>Group by</span>
170 <select class="input" name="by">
171 ${(Object.keys(BUCKET_MS) as Bucket[]).map((b) => option(b, `per ${b}`, b === p.by))}
172 ${cols.map((c) => option(c, `by ${c}`, c === p.by))}
173 </select>
174 </label>
175 <label class="qf" title="Series (stacked area, heat strip, table)"><span>Series</span>
176 <select class="input" name="series">
177 ${option("", "(one series)", p.series === "")}
178 ${cols.map((c) => option(c, `split by ${c}`, c === p.series))}
179 </select>
180 </label>
181 <label class="qf"><span>From</span>
182 <input class="input mono" name="from" value="${p.from}" placeholder="from 2026-10-01" maxlength="${MAX_PARAM}" />
183 </label>
184 <label class="qf"><span>To</span>
185 <input class="input mono" name="to" value="${p.to}" placeholder="to 2026-10-08" maxlength="${MAX_PARAM}" />
186 </label>
187 <label class="qf"><span>Filter column</span>
188 <select class="input" name="fcolumn">
189 ${option("", "(no filter)", p.fcolumn === "")}
190 ${cols.map((c) => option(c, c, c === p.fcolumn))}
191 </select>
192 </label>
193 <label class="qf"><span>Filter operator</span>
194 <select class="input" name="fop">
195 ${OPS.map((o) => option(o, o, o === p.fop))}
196 </select>
197 </label>
198 <label class="qf"><span>Filter value</span>
199 <input class="input mono" name="fvalue" value="${p.fvalue}" placeholder="value" maxlength="${MAX_PARAM}" />
200 </label>
150 ${pick("chart", "Chart", CHARTS.map((c) => opt(c, CHART_NAMES[c], p.chart)))}
151 ${pick("source", "Source", Object.keys(SOURCES).map((n) => opt(n, n, p.source)))}
152 ${pick("aggregate", "Aggregate", AGGREGATES.map((a) => opt(a, a, p.aggregate)))}
153 ${pick("column", "Column", [
154 opt("", "(rows)", p.column),
155 ...cols.filter((c) => src!.columns[c] === "number").map((c) => opt(c, c, p.column)),
156 ], "Column to aggregate")}
157 ${pick("by", "Group by", [
158 ...(Object.keys(BUCKET_MS) as Bucket[]).map((b) => opt(b, `per ${b}`, p.by)),
159 ...cols.map((c) => opt(c, `by ${c}`, p.by)),
160 ], "Bucket or column")}
161 ${pick("series", "Series", [
162 opt("", "(one series)", p.series),
163 ...cols.map((c) => opt(c, `split by ${c}`, p.series)),
outdated

A title attribute is not reachable by touch or keyboard. Move this text to the helper's hint (same for Group by and Series).

164 ], "Stacked area, heat strip, table")}
165 ${text("from", "From", p.from, "from 2026-10-01")}
166 ${text("to", "To", p.to, "to 2026-10-08")}
167 ${pick("fcolumn", "Filter column", [opt("", "(no filter)", p.fcolumn), ...cols.map((c) => opt(c, c, p.fcolumn))])}
168 ${pick("fop", "Filter operator", OPS.map((o) => opt(o, o, p.fop)))}
169 ${text("fvalue", "Filter value", p.fvalue, "value")}
201170 `;
202171 }
203172
@@ -252,7 +221,7 @@ export async function boardsPage(ctx: Ctx): Promise<Response> {
252221
253222 const form = card(
254223 html`<form method="get" action="/boards/data" class="bform">
255 ${queryFields(p)}
224 ${queryFields(p, "q")}
256225 ${btn("Draw", { variant: "primary" })}
257226 </form>`,
258227 { head: html`<h2>Query</h2>` },
@@ -299,10 +268,8 @@ export async function boardsPage(ctx: Ctx): Promise<Response> {
299268 (k) => html`<input type="hidden" name="${k}" value="${p[k as keyof Params]}" />`,
300269 )}
301270 <input type="hidden" name="w" value="1" /><input type="hidden" name="h" value="1" />
302 <label class="qf"><span>Board</span><select class="input" name="slug">
303 ${boards.map((b) => html`<option value="${b.slug}">${b.board.title}</option>`)}
304 </select></label>
305 <label class="qf"><span>Panel title</span><input class="input" name="title" required maxlength="80" value="${`${p.aggregate} of ${p.source}`}" /></label>
271 ${selectField({ label: "Board", name: "slug", id: "pin-slug", options: boards.map((b) => ({ value: b.slug, label: b.board.title })) })}
272 ${field({ label: "Panel title", name: "title", id: "pin-title", value: `${p.aggregate} of ${p.source}`, required: true, maxlength: 80 })}
306273 ${btn("Pin to board")}
307274 </form>`,
308275 { head: html`<h2>Pin this query</h2>` },
src/web/style/content.ts +1 −2
@@ -362,8 +362,7 @@ a.origin-chip:hover { border-color: var(--border-strong); color: var(--fg); }
362362 .bp-h2 .chart-box.is-table { height: 400px; }
363363 .bp-h3 .chart-box.is-table { height: 540px; }
364364 .bform { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 12px; margin-bottom: 8px; }
365 .bform .qf { display: flex; flex-direction: column; gap: 4px; flex: 1 1 140px; min-width: 0; }
366 .bform .qf > span { font-size: 12.5px; font-weight: 600; color: var(--fg); }
365 .bform .field { flex: 1 1 140px; min-width: 0; }
367366 .bform .btn { flex: none; }
368367 .boards-result .table { margin-top: 12px; }
369368 .bt-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 2px 16px; font-family: var(--mono); font-size: 12.5px; margin-top: 8px; }
src/web/ui.ts +7 −2
@@ -1103,7 +1103,12 @@ export function selectField(
11031103 const id = o.id ?? `f-${o.name}`;
11041104 return html`<div class="field">
11051105 <label for="${id}">${o.label}</label>
1106 <select class="input" id="${id}" name="${o.name}">
1106 <select
1107 class="input"
1108 id="${id}"
1109 name="${o.name}"
1110 ${o.hint ? html`aria-describedby="${id}-hint"` : null}
1111 >
11071112 ${o.options.map(
11081113 (opt) =>
11091114 html`<option
@@ -1114,7 +1119,7 @@ export function selectField(
11141119 </option>`,
11151120 )}
11161121 </select>
1117 ${o.hint ? html`<span class="hint">${o.hint}</span>` : null}
1122 ${o.hint ? html`<span class="hint" id="${id}-hint">${o.hint}</span>` : null}
11181123 </div>`;
11191124 }
11201125
test/boards-page.test.ts +3 −3
@@ -211,9 +211,9 @@ describe("every chart type from one seeded query", () => {
211211 });
212212 test("the chart is chosen beside the query", async () => {
213213 const body = await drawn("heat");
214 expect(body).toMatch(/<select class="input" name="chart"[^>]*>/);
215 expect(body).toContain('<option value="heat" selected>heat strip</option>');
216 expect(body).toContain('<option value="kind" selected>split by kind</option>');
214 expect(body).toMatch(/<select\s+class="input"\s+id="q-chart"\s+name="chart"[^>]*>/);
215 expect(body).toMatch(/<option\s+value="heat"\s+selected\s*>\s*heat strip\s*<\/option>/);
216 expect(body).toMatch(/<option\s+value="kind"\s+selected\s*>\s*split by kind\s*<\/option>/);
217217 });
218218 });
219219
test/boards-selectors.test.ts +29 −2
@@ -58,10 +58,13 @@ test("every query selector has a visible label and sits outside .row-actions", a
5858 expect(form![0]).not.toContain("row-actions");
5959 expect(form![0]).toContain('class="bform"');
6060 for (const name of ["chart", "source", "aggregate", "column", "by", "series", "from", "to", "fcolumn", "fop", "fvalue"]) {
61 const m = form![1]!.match(new RegExp(`<label class="qf"[^>]*><span>([^<]+)</span>\\s*<(?:select|input)[^>]* name="${name}"`));
61 const m = form![1]!.match(new RegExp(`<div class="field"[^>]*>\\s*<label for="([^"]+)">([^<]+)</label>\\s*<(?:select|input)[^>]*\\sid="\\1"\\s+name="${name}"`));
6262 expect(m, name).not.toBeNull();
63 expect(m![1]!.trim().length, name).toBeGreaterThan(0);
63 expect(m![2]!.trim().length, name).toBeGreaterThan(0);
6464 }
65 expect(html).not.toContain('class="qf"');
66 expect(html).not.toMatch(/<div class="field"[^>]*\stitle=/);
67 expect(html).toMatch(/<span class="hint" id="q-series-hint">\s*Stacked area/);
6568 });
6669
6770 test("the selector styles never hide or collapse a control", () => {
@@ -82,3 +85,27 @@ test("in every theme the label, field text and border read against their ground"
8285 expect(t.card.toLowerCase(), `${name} field ground`).not.toBe(t.fg.toLowerCase());
8386 }
8487 });
88
89 test("selectField ties its hint to the select with aria-describedby", async () => {
90 const { selectField } = await import("../src/web/ui.ts");
91 const out = String(selectField({ id: "x", label: "L", name: "n", hint: "H", options: [{ value: "a", label: "A" }] }));
92 expect(out).toMatch(/<select[^>]*aria-describedby="x-hint"/);
93 expect(out).toContain('id="x-hint"');
94 expect(String(selectField({ id: "y", label: "L", name: "n", options: [] }))).not.toContain("aria-describedby");
95 });
96
97 test("the boards list and a board draw every form field as .field with unique ids", async () => {
98 const h = { authorization: `Bearer ${token}`, origin: servers.url, "content-type": "application/x-www-form-urlencoded" };
99 const made = await fetch(`${servers.url}/boards/new`, { method: "POST", headers: h, body: "title=Forms", redirect: "manual" });
100 const slug = (made.headers.get("location") ?? "").split("/").pop()!;
101 const list = await (await fetch(`${servers.url}/boards`, { headers: h })).text();
102 expect(list).not.toContain('class="qf"');
103 expect(list).toMatch(/<label for="new-title">New board<\/label>/);
104 const page = await (await fetch(`${servers.url}/boards/${slug}`, { headers: h })).text();
105 expect(page).not.toContain('class="qf"');
106 for (const id of ["board-title", "board-range", "board-refresh", "m-title", "m-w", "m-h"]) {
107 expect(page, id).toContain(`<label for="${id}">`);
108 }
109 const ids = [...page.matchAll(/\sid="([^"]+)"/g)].map((m) => m[1]);
110 expect(new Set(ids).size).toBe(ids.length);
111 });
test/boards-store.test.ts +12 −1
@@ -216,6 +216,17 @@ describe("/boards", () => {
216216 expect((await asAdmin("/boards/scratch-b")).status).toBe(404);
217217 });
218218
219 test("no id repeats on a board page with several panels", async () => {
220 await post("/boards/new", { title: "Ids" });
221 const q = { source: "runs", aggregate: "count", column: "", by: "day", from: "", to: "", fcolumn: "", fop: "eq", fvalue: "" };
222 for (const title of ["one", "two", "three"]) await post("/boards/ids/add", { ...q, title, w: "1", h: "1" });
223 const page = await (await asAdmin("/boards/ids")).text();
224 const ids = [...page.matchAll(/\sid="([^"]+)"/g)].map((m) => m[1]!);
225 expect(ids).toContain("e2-chart");
226 expect(ids).toContain("m-chart");
227 expect(ids.filter((id, i) => ids.indexOf(id) !== i)).toEqual([]);
228 });
229
219230 test("a pinned query lands on the board", async () => {
220231 const data = await (await asAdmin("/boards/data?source=runs&by=kind")).text();
221232 expect(data).toContain('action="/boards/pin"');
@@ -235,7 +246,7 @@ describe("/boards", () => {
235246 // runs in range: three days × three kinds for the heat strip; three days of bars, the series set aside
236247 expect(page.match(/<rect class="cell"/g)?.length).toBe(9);
237248 expect(page.match(/<rect class="bar"/g)?.length).toBe(3);
238 expect(page).toContain('<option value="heat" selected>heat strip</option>');
249 expect(page).toMatch(/<option\s+value="heat"\s+selected\s*>\s*heat strip\s*<\/option>/);
239250 expect(parseBoard({ ...board, panels: [{ ...board.panels[0], chart: "pie" }] }).ok).toBe(false);
240251 await deleteBoard(app, alice, "charts");
241252 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs