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

Merged opened this

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

Merged

mason/forge:mason/15950-small-every-list-page-still-printing-a-b → main 0 commits fork 5 threads · 5 unresolved

  • Merged. mason/15950-small-every-list-page-still-printing-a-b was merged into main as e00ef3f.

Review

Sign in to review this change.
8 files changed +56 −9
src/core/empty_words.ts +4
@@ -75,6 +75,10 @@ const TABLE = {
7575 returnVisitors: { sentence: "No visitor has come back in the window." },
7676 teams: { sentence: "No teams yet." },
7777 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." },
7882 loads: { sentence: "No load reports in the last 30 days." },
7983 } as const satisfies Readonly<Record<string, EmptyWords>>;
8084
src/web/empty_words.ts +10
@@ -101,6 +101,16 @@ export function emptyLine(kind: EmptyKind, o: { reason?: string; id?: string } =
101101 return html`<p class="muted small">${reason === undefined ? w.sentence : `${w.sentence} ${reason}`}</p>`;
102102 }
103103
outdated

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.

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
104114 /** A sentence-only empty state: the table's words in a muted paragraph, escaped by `html`. */
105115 export function emptyNote(key: NoteKey): Html {
106116 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";
1616 import type { Ctx } from "../../http/context.ts";
1717 import { field, readForm } from "../form.ts";
1818 import { html, type Html } from "../html.ts";
19 import { EMPTY_WORDS } from "../empty_words.ts";
1920 import { btn, field as formField, row, time } from "../ui.ts";
2021 import { fileHoldForm } from "./file_holds.ts";
2122 import { fold } from "../figure.ts";
@@ -42,7 +43,7 @@ export function boardsHoldsCard(db: Database, viewer: User | undefined, withBoar
4243 ? html`<p class="muted small" data-cut>Showing ${String(holds.length)} of ${String(total)} holds; release some to see the rest.</p>`
4344 : null}
4445 ${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>`
4647 : html`<ul class="list">
4748 ${holds.map((h) =>
4849 row({
src/web/pages/crew.ts +2 −2
@@ -14,6 +14,7 @@ import { budgetsCard } from "../studio/crew_budgets.ts";
1414 import { plannerCardView } from "../studio/planner_card.ts";
1515 import { crewKeyField } from "../studio/crew_key.ts";
1616 import { fundingOf, fundingWords } from "../../spawn/funding.ts";
17 import { emptySection } from "../empty_words.ts";
1718 import {
1819 createAgent,
1920 deleteAgent,
@@ -703,8 +704,7 @@ function crewView(
703704 )}
704705 ${agents.length === 0
705706 ? 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")}
outdated

The <h2> is dropped and the section #crew-empty is left with one small muted line. The page's only next step ("Make one below.") is now the least visible thing on it. Principle 3 asks for rhythm, not smaller type.

708708 </section>`
709709 : panel(
710710 html`<div class="table-scroll">
src/web/pages/display.ts +2 −1
@@ -21,6 +21,7 @@ import type { Ctx } from "../../http/context.ts";
2121 import { crumbsFor, forbiddenPage, loadRepo, notFoundPage, repoBase, repoHeader, repoPalette } from "../chrome.ts";
2222 import { html, raw } from "../html.ts";
2323 import { flashTo, page } from "../layout.ts";
24 import { EMPTY_WORDS } from "../empty_words.ts";
2425 import { btn, empty } from "../ui.ts";
2526 import { readForm } from "../form.ts";
2627
@@ -91,7 +92,7 @@ export async function displayPage(ctx: Ctx): Promise<Response> {
9192 <fieldset class="field">
9293 <legend>Choose builds</legend>
9394 ${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>`
9596 : choices.map(
9697 (key) => html`<label class="check"><input type="checkbox" name="build" value="${key}" ${chosen.includes(key) ? raw("checked") : null} />
9798 <span class="mono">${key}</span></label>`,
src/web/pages/forges.ts +2 −2
@@ -17,6 +17,7 @@ import { page, redirect } from "../layout.ts";
1717 import { undoable } from "../../spawn/claim.ts";
1818 import { changeDoor, previewDoor, previewRecoveryDoor, recoveryDoor, reissueDoor } from "../../spawn/door.ts";
1919 import { readForm } from "../form.ts";
20 import { emptySection } from "../empty_words.ts";
2021 import { badge, btn, row, time } from "../ui.ts";
2122 import { noRoom } from "../../spawn/door.ts";
2223 import { sizeWords, useWords } from "../../spawn/usage.ts";
@@ -304,8 +305,7 @@ export async function forgesPage(ctx: Ctx): Promise<Response> {
304305 ${everyone.length === 0 ? null : html`<p class="muted small" data-week>${weekLine(everyone, now)}</p>`}
305306 ${everyone.length === 0
306307 ? html`<section class="settings-block">
307 <h2>No forges sent yet</h2>
308 <p>${action}</p>
308 ${emptySection("forgesSent", { action })}
outdated

The <h2> is gone, so the section has no heading and the next step shrinks to small muted text. Keep a heading and give the action normal size. The matching sentences below use sentence: and bypass the table, so forgesMatch is dead words.

309309 </section>`
310310 : html`<section class="settings-block" id="forges-compare">
311311 <h2>Side by side</h2>
src/web/pages/packs.ts +2 −2
@@ -15,6 +15,7 @@ import { NOT_STATED, packFacts } from "../../packs/facts.ts";
1515 import { html } from "../html.ts";
1616 import { flashTo, page } from "../layout.ts";
1717 import { mirrorPacks, reportWords } from "../../packs/mirror.ts";
18 import { emptySection } from "../empty_words.ts";
1819 import { btn, copyField, field as uiField, row, timeAgo } from "../ui.ts";
1920 import { listReposVisibleTo } from "../../core/repos.ts";
2021 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> {
8182 const body = html`${pageHead("Packs", { sub: WHAT_IS_A_PACK })}
8283 ${curated.length === 0
8384 ? 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." })}
8686 </section>`
8787 : html`<div class="stack">${curated.map((p) => packCard(ctx, p))}</div>`}
8888 ${admin(ctx)
test/empty-states.test.ts +32 −1
@@ -12,7 +12,8 @@ import { createSession } from "../src/core/sessions.ts";
1212 import type { EmptyWords } from "../src/core/empty_words.ts";
1313 import { createUser } from "../src/core/users.ts";
1414 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";
1617
1718 let dir: string;
1819 let app: App;
@@ -203,3 +204,33 @@ test("every kind in the table is one sentence, and a link needs both its label a
203204 expect((String(emptyList(kind as Parameters<typeof emptyList>[0])).match(/<a\s/g) ?? []).length, kind).toBe(w.label && w.href ? 1 : 0);
204205 }
205206 });
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 };
outdated

continue on a non-200 lets this test pass without ever checking crew or holds. Assert status 200 for each page, and add packs, displayChoices and forgesMatch.

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("&lt;b&gt;x&lt;/b&gt;");
234 expect(out).toContain('<p><a href="/new">Send one</a></p>');
235 expect(out).not.toContain("small");
236 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs