Public: anyone can read this; the crew can change it.
small: every list page still printing a bare "No …" takes its reason and next step from src/web/empty_words.ts #16705
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/15950-small-every-list-page-still-printing-a-b → main 0 commits fork 5 threads · 5 unresolved
8 files
changed +56
−9
src/core/empty_words.ts +4
| @@ -75,6 +75,10 @@ const TABLE = { | ||
| 75 | 75 | returnVisitors: { sentence: "No visitor has come back in the window." }, |
| 76 | 76 | teams: { sentence: "No teams yet." }, |
| 77 | 77 | teamAgents: { sentence: "No agents yet." }, |
| 78 | packs: { sentence: "No packs yet." }, | |
| 79 | forgesSent: { sentence: "No forges sent yet." }, | |
| 80 | agents: { sentence: "No agents yet.", reason: "Make one below." }, | |
| 81 | displayChoices: { sentence: "No builds to choose from yet." }, | |
| 78 | 82 | loads: { sentence: "No load reports in the last 30 days." }, |
| 79 | 83 | } as const satisfies Readonly<Record<string, EmptyWords>>; |
| 80 | 84 |
src/web/empty_words.ts +10
| @@ -101,6 +101,16 @@ export function emptyLine(kind: EmptyKind, o: { reason?: string; id?: string } = | ||
| 101 | 101 | return html`<p class="muted small">${reason === undefined ? w.sentence : `${w.sentence} ${reason}`}</p>`; |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | /** A list of none that is a headed section: the table's sentence as the heading (so a screen | |
| 105 | * reader has somewhere to land), its reason beneath, and the next step at the page's own size. */ | |
| 106 | export function emptySection(kind: EmptyKind, o: { reason?: string; action?: Html } = {}): Html { | |
| 107 | const w: EmptyWords = EMPTY_WORDS[kind]; | |
| 108 | const reason = o.reason ?? w.reason; | |
| 109 | return html`<h2>${w.sentence.replace(/\.$/, "")}</h2> | |
| 110 | ${reason === undefined ? null : html`<p class="muted">${reason}</p>`} | |
| 111 | ${o.action === undefined ? null : html`<p>${o.action}</p>`}`; | |
| 112 | } | |
| 113 | ||
| 104 | 114 | /** A sentence-only empty state: the table's words in a muted paragraph, escaped by `html`. */ |
| 105 | 115 | export function emptyNote(key: NoteKey): Html { |
| 106 | 116 | return html`<p class="muted">${NOTE_WORDS[key]}</p>`; |
src/web/pages/boards-holds.ts +2 −1
| @@ -16,6 +16,7 @@ import { MAX_HOLD_PATH } from "../../crew/file_holds.ts"; | ||
| 16 | 16 | import type { Ctx } from "../../http/context.ts"; |
| 17 | 17 | import { field, readForm } from "../form.ts"; |
| 18 | 18 | import { html, type Html } from "../html.ts"; |
| 19 | import { EMPTY_WORDS } from "../empty_words.ts"; | |
| 19 | 20 | import { btn, field as formField, row, time } from "../ui.ts"; |
| 20 | 21 | import { fileHoldForm } from "./file_holds.ts"; |
| 21 | 22 | import { fold } from "../figure.ts"; |
| @@ -42,7 +43,7 @@ export function boardsHoldsCard(db: Database, viewer: User | undefined, withBoar | ||
| 42 | 43 | ? html`<p class="muted small" data-cut>Showing ${String(holds.length)} of ${String(total)} holds; release some to see the rest.</p>` |
| 43 | 44 | : null} |
| 44 | 45 | ${holds.length === 0 |
| 45 | ? html`<p class="muted" data-no-holds>No file is held.</p>` | |
| 46 | ? html`<p class="muted" data-no-holds>${EMPTY_WORDS.holds.sentence}</p>` | |
| 46 | 47 | : html`<ul class="list"> |
| 47 | 48 | ${holds.map((h) => |
| 48 | 49 | row({ |
src/web/pages/crew.ts +2 −2
| @@ -14,6 +14,7 @@ import { budgetsCard } from "../studio/crew_budgets.ts"; | ||
| 14 | 14 | import { plannerCardView } from "../studio/planner_card.ts"; |
| 15 | 15 | import { crewKeyField } from "../studio/crew_key.ts"; |
| 16 | 16 | import { fundingOf, fundingWords } from "../../spawn/funding.ts"; |
| 17 | import { emptySection } from "../empty_words.ts"; | |
| 17 | 18 | import { |
| 18 | 19 | createAgent, |
| 19 | 20 | deleteAgent, |
| @@ -703,8 +704,7 @@ function crewView( | ||
| 703 | 704 | )} |
| 704 | 705 | ${agents.length === 0 |
| 705 | 706 | ? html`<section class="mb" id="crew-empty"> |
| 706 | <h2 class="mb">No agents yet</h2> | |
| 707 | <p class="muted">Make one below.</p> | |
| 707 | ${emptySection("agents")} | |
| 708 | 708 | </section>` |
| 709 | 709 | : panel( |
| 710 | 710 | html`<div class="table-scroll"> |
src/web/pages/display.ts +2 −1
| @@ -21,6 +21,7 @@ import type { Ctx } from "../../http/context.ts"; | ||
| 21 | 21 | import { crumbsFor, forbiddenPage, loadRepo, notFoundPage, repoBase, repoHeader, repoPalette } from "../chrome.ts"; |
| 22 | 22 | import { html, raw } from "../html.ts"; |
| 23 | 23 | import { flashTo, page } from "../layout.ts"; |
| 24 | import { EMPTY_WORDS } from "../empty_words.ts"; | |
| 24 | 25 | import { btn, empty } from "../ui.ts"; |
| 25 | 26 | import { readForm } from "../form.ts"; |
| 26 | 27 | |
| @@ -91,7 +92,7 @@ export async function displayPage(ctx: Ctx): Promise<Response> { | ||
| 91 | 92 | <fieldset class="field"> |
| 92 | 93 | <legend>Choose builds</legend> |
| 93 | 94 | ${choices.length === 0 |
| 94 | ? html`<p class="hint">No builds to choose from yet.</p>` | |
| 95 | ? html`<p class="hint">${EMPTY_WORDS.displayChoices.sentence}</p>` | |
| 95 | 96 | : choices.map( |
| 96 | 97 | (key) => html`<label class="check"><input type="checkbox" name="build" value="${key}" ${chosen.includes(key) ? raw("checked") : null} /> |
| 97 | 98 | <span class="mono">${key}</span></label>`, |
src/web/pages/forges.ts +2 −2
| @@ -17,6 +17,7 @@ import { page, redirect } from "../layout.ts"; | ||
| 17 | 17 | import { undoable } from "../../spawn/claim.ts"; |
| 18 | 18 | import { changeDoor, previewDoor, previewRecoveryDoor, recoveryDoor, reissueDoor } from "../../spawn/door.ts"; |
| 19 | 19 | import { readForm } from "../form.ts"; |
| 20 | import { emptySection } from "../empty_words.ts"; | |
| 20 | 21 | import { badge, btn, row, time } from "../ui.ts"; |
| 21 | 22 | import { noRoom } from "../../spawn/door.ts"; |
| 22 | 23 | import { sizeWords, useWords } from "../../spawn/usage.ts"; |
| @@ -304,8 +305,7 @@ export async function forgesPage(ctx: Ctx): Promise<Response> { | ||
| 304 | 305 | ${everyone.length === 0 ? null : html`<p class="muted small" data-week>${weekLine(everyone, now)}</p>`} |
| 305 | 306 | ${everyone.length === 0 |
| 306 | 307 | ? html`<section class="settings-block"> |
| 307 | <h2>No forges sent yet</h2> | |
| 308 | <p>${action}</p> | |
| 308 | ${emptySection("forgesSent", { action })} | |
| 309 | 309 | </section>` |
| 310 | 310 | : html`<section class="settings-block" id="forges-compare"> |
| 311 | 311 | <h2>Side by side</h2> |
src/web/pages/packs.ts +2 −2
| @@ -15,6 +15,7 @@ import { NOT_STATED, packFacts } from "../../packs/facts.ts"; | ||
| 15 | 15 | import { html } from "../html.ts"; |
| 16 | 16 | import { flashTo, page } from "../layout.ts"; |
| 17 | 17 | import { mirrorPacks, reportWords } from "../../packs/mirror.ts"; |
| 18 | import { emptySection } from "../empty_words.ts"; | |
| 18 | 19 | import { btn, copyField, field as uiField, row, timeAgo } from "../ui.ts"; |
| 19 | 20 | import { listReposVisibleTo } from "../../core/repos.ts"; |
| 20 | 21 | import { changeRepos, editPack, getPack, history, listPacks, mayCurate, resolveRepos, slugOf, type CuratedPack, type PackRepo } from "../../packs/curated.ts"; |
| @@ -81,8 +82,7 @@ export async function packsPage(ctx: Ctx): Promise<Response> { | ||
| 81 | 82 | const body = html`${pageHead("Packs", { sub: WHAT_IS_A_PACK })} |
| 82 | 83 | ${curated.length === 0 |
| 83 | 84 | ? html`<section class="stack"> |
| 84 | <h2>No packs yet</h2> | |
| 85 | ${admin(ctx) ? html`<p>Make one from the repos you already have.</p>` : html`<p class="muted">An admin makes the first one.</p>`} | |
| 85 | ${emptySection("packs", { reason: admin(ctx) ? "Make one from the repos you already have." : "An admin makes the first one." })} | |
| 86 | 86 | </section>` |
| 87 | 87 | : html`<div class="stack">${curated.map((p) => packCard(ctx, p))}</div>`} |
| 88 | 88 | ${admin(ctx) |
test/empty-states.test.ts +32 −1
| @@ -12,7 +12,8 @@ import { createSession } from "../src/core/sessions.ts"; | ||
| 12 | 12 | import type { EmptyWords } from "../src/core/empty_words.ts"; |
| 13 | 13 | import { createUser } from "../src/core/users.ts"; |
| 14 | 14 | import { serve, type Servers } from "../src/http/server.ts"; |
| 15 | import { EMPTY_WORDS, emptyLine, emptyList, type EmptyKind } from "../src/web/empty_words.ts"; | |
| 15 | import { html } from "../src/web/html.ts"; | |
| 16 | import { EMPTY_WORDS, emptyLine, emptyList, emptySection, type EmptyKind } from "../src/web/empty_words.ts"; | |
| 16 | 17 | |
| 17 | 18 | let dir: string; |
| 18 | 19 | let app: App; |
| @@ -203,3 +204,33 @@ test("every kind in the table is one sentence, and a link needs both its label a | ||
| 203 | 204 | expect((String(emptyList(kind as Parameters<typeof emptyList>[0])).match(/<a\s/g) ?? []).length, kind).toBe(w.label && w.href ? 1 : 0); |
| 204 | 205 | } |
| 205 | 206 | }); |
| 207 | ||
| 208 | test("each list that once printed a bare 'No …' says the table's sentence, on a page that answers (#15950)", async () => { | |
| 209 | const get = async (path: string): Promise<string> => { | |
| 210 | const res = await fetch(servers.url + path, { headers: { cookie } }); | |
| 211 | expect(res.status, path).toBe(200); | |
| 212 | return res.text(); | |
| 213 | }; | |
| 214 | const forges = await get("/forges"); | |
| 215 | expect(forges).toContain("<h2>No forges sent yet</h2>"); | |
| 216 | const crew = await get("/settings/crew"); | |
| 217 | expect(crew).toMatch(/id="crew-empty">\s*<h2>No agents yet<\/h2>/); | |
| 218 | expect(crew).toContain(EMPTY_WORDS.agents.reason!); | |
| 219 | expect(await get("/boards")).toContain(`data-no-holds>${EMPTY_WORDS.holds.sentence}</p>`); | |
| 220 | }); | |
| 221 | ||
| 222 | test("the packs empty section is a heading, its reason, for admin and non-admin alike", () => { | |
| 223 | const admin = String(emptySection("packs", { reason: "Make one from the repos you already have." })); | |
| 224 | expect(admin).toContain("<h2>No packs yet</h2>"); | |
| 225 | expect(admin).toContain("Make one from the repos you already have."); | |
| 226 | const other = String(emptySection("packs", { reason: "An admin makes the first one." })); | |
| 227 | expect(other).toContain("<h2>No packs yet</h2>"); | |
| 228 | expect(other).toContain("An admin makes the first one."); | |
| 229 | }); | |
| 230 | ||
| 231 | test("an empty section escapes its words and keeps the action at the page's size", () => { | |
| 232 | const out = String(emptySection("forgesSent", { reason: "<b>x</b>", action: html`<a href="/new">Send one</a>` })); | |
| 233 | expect(out).toContain("<b>x</b>"); | |
| 234 | expect(out).toContain('<p><a href="/new">Send one</a></p>'); | |
| 235 | expect(out).not.toContain("small"); | |
| 236 | }); |
new above
offline
raw(" " + attr)puts an unescaped caller string into markup. Take a fixed attribute name and emit it escaped, or keep each page's own markup.