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

Main green: four new pages' bare 'No …' empty states use the shared words; the empty-words test runs first #16874

Merged opened this

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

Merged

fix/empty-words-red → main 0 commits

  • Merged. fix/empty-words-red was merged into main as b1a6173.

Review

Sign in to review this change.
19 files changed +66 −21
src/core/empty_words.ts +20 −1
@@ -5,6 +5,8 @@
55 * every kind and holds each to its sentence and its single link.
66 */
77
8 import { FLAGS_FILE } from "./app_flags.ts";
9
810 export interface EmptyWords {
911 /** One sentence, plain words, ending in a full stop. */
1012 readonly sentence: string;
@@ -16,6 +18,8 @@ export interface EmptyWords {
1618 readonly href?: string;
1719 }
1820
21 const NO_FLAG = "No flag is declared.";
22
1923 const TABLE = {
2024 board: { sentence: "No board yet.", label: "Start from a question", href: "/boards/data" },
2125 inbox: { sentence: "Nothing is waiting on you.", label: "Tell the crew something", href: "/tell" },
@@ -81,12 +85,28 @@ const TABLE = {
8185 agents: { sentence: "No agents yet.", reason: "Make one below." },
8286 displayChoices: { sentence: "No builds to choose from yet." },
8387 loads: { sentence: "No load reports in the last 30 days." },
88 // Lists drawn as one line (`emptyLine`, and `emptyText` in the terminal). A reason names the
89 // step, never where it sits: a phone lays the page out differently.
90 gifts: { sentence: "No gift yet.", reason: "Make a gift link and send it to a friend." },
91 readGrants: { sentence: "No one else reads it.", reason: "Grant read to one of your apps or one crew member." },
92 // The forge's own flags are declared in code; an app's in its repository. One sentence for both.
93 flags: { sentence: NO_FLAG },
94 appFlags: { sentence: NO_FLAG, reason: `Add a ${FLAGS_FILE} to the repository to declare one.` },
95 regValues: { sentence: "No values." },
8496 } as const satisfies Readonly<Record<string, EmptyWords>>;
8597
8698 export type EmptyKind = keyof typeof TABLE;
8799
88100 export const EMPTY_WORDS: Readonly<Record<EmptyKind, EmptyWords>> = TABLE;
89101
102 /**
103 * The sentence and its reason as one line of text: the terminal's empty screens and `emptyLine`.
104 */
105 export function emptyText(kind: EmptyKind): string {
106 const w: EmptyWords = TABLE[kind];
107 return w.reason === undefined ? w.sentence : `${w.sentence} ${w.reason}`;
108 }
109
90110 /**
91111 * The sentence-only empty states: a small note under a card heading, with no action of its own (the
92112 * page already carries the door). Each key is its sentence in camelCase, so a reader finds a note
@@ -118,7 +138,6 @@ export const NOTE_WORDS = {
118138 noChangeYet: "No change yet.",
119139 noRepositoryRunsOnItsOwn: "No repository runs on its own.",
120140 nothingOfferedYet: "Nothing offered yet.",
121 noFlagIsDeclaredYet: "No flag is declared yet.",
122141 noProjectInThisFile: "No project in this file.",
123142 noElementsPlacedInAStorey: "No elements are placed in a storey.",
124143 nothingProposedToTheParentForgeYet: "Nothing proposed to the parent forge yet.",
src/tui/screens/appflags.ts +2 −1
@@ -8,6 +8,7 @@
88 import { appFlagRows, setAppFlag } from "../../actions/app_flags.ts";
99 import type { AppFlagRow } from "../../core/app_flags.ts";
1010 import { getAppByRepo } from "../../core/apps.ts";
11 import { emptyText } from "../../core/empty_words.ts";
1112 import { canAdmin, type Repo } from "../../core/repos.ts";
1213 import { flagSummary } from "../../web/pages/app_flags.ts";
1314 import type { Ctx, Screen } from "../app/app.ts";
@@ -70,7 +71,7 @@ export function appFlagsScreen(f: Session, ctx: Ctx, repo: Repo): Screen {
7071 : !readable
7172 ? "An app's flags are its admin's."
7273 : rows.length === 0
73 ? "No flag is declared: add a flags.json to the repository."
74 ? emptyText("appFlags")
7475 : `${rows.length} for ${repo.ownerName}/${repo.name}.`;
7576 const said = wrap(text, Math.max(1, area.w)).slice(0, 3);
7677 const [head, list] = split(area, "v", [len(said.length), fill(1)]);
src/tui/screens/flags.ts +2 −1
@@ -21,6 +21,7 @@ import {
2121 type FlagValue,
2222 } from "../../core/flags.ts";
2323 import { makeWinnerDefault } from "../../actions/flag_winner.ts";
24 import { EMPTY_WORDS } from "../../core/empty_words.ts";
2425 import type { Ctx, Screen } from "../app/app.ts";
2526 import { binding } from "../app/keys.ts";
2627 import { style } from "../term/style.ts";
@@ -113,7 +114,7 @@ export function flagsScreen(f: Session, ctx: Ctx): Screen {
113114 : !allowed
114115 ? FLAGS_ADMIN_ONLY
115116 : names().length === 0
116 ? "No flag is declared yet."
117 ? EMPTY_WORDS.flags.sentence
117118 : usesOf(names()[state.index] ?? names()[0]!);
118119 s.text(head!.x, head!.y, truncate(text, head!.w), style(c.mutedFg, c.bg), head!.x + head!.w);
119120 drawList(s, list!, c, state, rows());
src/tui/screens/gifts.ts +2 −1
@@ -5,6 +5,7 @@
55 */
66
77 import { giveGift, GIFT_WORDS, isSubscriber, readGifts } from "../../actions/gifts.ts";
8 import { emptyText } from "../../core/empty_words.ts";
89 import { publicOrigin } from "../../core/public_origin.ts";
910 import type { Ctx, Screen } from "../app/app.ts";
1011 import { binding } from "../app/keys.ts";
@@ -38,7 +39,7 @@ export function giftsScreen(f: Session, ctx: Ctx): Screen {
3839 state.clamp(rows.length);
3940 const [head, body] = split(area, "v", [len(2), fill(1)]);
4041 s.text(head!.x, head!.y, truncate(note !== "" ? note : `${left} gifts left: n makes a one-use link for a friend's forge`, head!.w), style(c.mutedFg, c.bg), head!.x + head!.w);
41 if (rows.length === 0) s.text(body!.x, body!.y, truncate("No gift yet.", body!.w), style(c.mutedFg, c.bg), body!.x + body!.w);
42 if (rows.length === 0) s.text(body!.x, body!.y, truncate(emptyText("gifts"), body!.w), style(c.mutedFg, c.bg), body!.x + body!.w);
4243 else drawList(s, body!, c, state, rows);
4344 },
4445 key(e) {
src/web/empty_words.ts +4 −5
@@ -6,7 +6,7 @@
66 */
77
88 import { html, type Html } from "./html.ts";
9 import { EMPTY_WORDS, NOTE_WORDS, type EmptyKind, type EmptyWords, type NoteKey } from "../core/empty_words.ts";
9 import { EMPTY_WORDS, emptyText, NOTE_WORDS, type EmptyKind, type EmptyWords, type NoteKey } from "../core/empty_words.ts";
1010 import { btn, empty, type IconName } from "./ui.ts";
1111
1212 export { EMPTY_WORDS, type EmptyKind };
@@ -95,10 +95,9 @@ export function emptyList(kind: keyof typeof ICONS, o: EmptyOptions = {}): Html
9595 * the compact form for small inline lists (a fieldset, a list item, a narrow phone), where the
9696 * picture block would cost layout and bytes; any kind may be drawn this way. */
9797 export function emptyLine(kind: EmptyKind, o: { reason?: string; id?: string } = {}): Html {
98 const w: EmptyWords = EMPTY_WORDS[kind];
99 const reason = o.reason ?? w.reason;
100 if (o.id !== undefined) return html`<p class="muted small" id="${o.id}">${reason === undefined ? w.sentence : `${w.sentence} ${reason}`}</p>`;
101 return html`<p class="muted small">${reason === undefined ? w.sentence : `${w.sentence} ${reason}`}</p>`;
98 const text = o.reason === undefined ? emptyText(kind) : `${EMPTY_WORDS[kind].sentence} ${o.reason}`;
99 if (o.id !== undefined) return html`<p class="muted small" id="${o.id}">${text}</p>`;
100 return html`<p class="muted small">${text}</p>`;
102101 }
103102
104103 /** A list of none that is a headed section: the table's sentence as the heading (so a screen
src/web/pages/app_flags.ts +3 −2
@@ -5,13 +5,14 @@
55 */
66
77 import { setAppFlag } from "../../actions/app_flags.ts";
8 import { FLAGS_FILE, type AppFlagRow } from "../../core/app_flags.ts";
8 import type { AppFlagRow } from "../../core/app_flags.ts";
99 import type { Ctx } from "../../http/context.ts";
1010 import { adminForm } from "../admin_form.ts";
1111 import { repoBase } from "../chrome.ts";
1212 import { field } from "../form.ts";
1313 import { html, type Html } from "../html.ts";
1414 import { flashTo } from "../layout.ts";
15 import { emptyLine } from "../empty_words.ts";
1516 import { row, rowList } from "../ui.ts";
1617
1718 /** One line of what is set. */
@@ -41,7 +42,7 @@ export function appFlagsView(base: string, rows: readonly AppFlagRow[]): Html {
4142 <p class="muted small">Choose who sees each flag the app declares.</p>
4243 ${items.length > 0
4344 ? rowList(items, { bare: true })
44 : html`<p class="muted small">No flag is declared: add a <span class="mono">${FLAGS_FILE}</span> to the repository.</p>`}
45 : emptyLine("appFlags")}
4546 </section>`;
4647 }
4748
src/web/pages/flags.ts +2 −2
@@ -7,7 +7,7 @@
77 */
88
99 import { sshOn } from "../../settings/ssh.ts";
10 import { emptyNote } from "../empty_words.ts";
10 import { emptyLine } from "../empty_words.ts";
1111 import { readFlags } from "../../actions/flags_view.ts";
1212 import { checkInput, FLAGS_ADMIN_ONLY, flagRegistry, usesLine, winnerOffer, mayManageFlags, useFlagRegistry, type FlagValue } from "../../core/flags.ts";
1313 import { makeWinnerDefault } from "../../actions/flag_winner.ts";
@@ -111,7 +111,7 @@ export function flagsPage(ctx: Ctx): Response {
111111 const body = html`<section class="settings-block">
112112 <h2>Flags</h2>
113113 ${names.length === 0
114 ? emptyNote("noFlagIsDeclaredYet")
114 ? emptyLine("flags")
115115 : html`<ul class="list setting-list">
116116 ${rows}
117117 </ul>`}
src/web/pages/gifts.ts +2 −1
@@ -11,6 +11,7 @@ import type { Ctx } from "../../http/context.ts";
1111 import { notFoundPage, signInFirst } from "../chrome.ts";
1212 import { readForm } from "../form.ts";
1313 import { html, type Html } from "../html.ts";
14 import { emptyLine } from "../empty_words.ts";
1415 import { btn, copyField, dot } from "../ui.ts";
1516 import { accountShell } from "./account.ts";
1617
@@ -44,7 +45,7 @@ export function giftsBlock(ctx: Ctx, shown?: Shown, refusal?: string): Html | nu
4445 ${copyField("gift-link", shown.link, "The link to send", "Copy the link")}
4546 </div>`}
4647 <form method="post" action="/settings/gifts">${btn("Make a gift link", { variant: "primary" })}</form>
47 ${lines.length === 0 ? html`<p class="muted small">No gift yet.</p>` : html`<dl class="status-rows">${lines}</dl>`}
48 ${lines.length === 0 ? emptyLine("gifts") : html`<dl class="status-rows">${lines}</dl>`}
4849 </section>`;
4950 }
5051
src/web/pages/read-grants.ts +2 −1
@@ -11,6 +11,7 @@ import { forbiddenPage, loadRepo, NOT_YOURS_TO_DO, repoBase, repoNotFound } from
1111 import { field, readForm } from "../form.ts";
1212 import { html, type Html } from "../html.ts";
1313 import { flashTo } from "../layout.ts";
14 import { emptyLine } from "../empty_words.ts";
1415 import { btn, confirmAction, field as formField, selectField, time } from "../ui.ts";
1516
1617 /**
@@ -24,7 +25,7 @@ export function readGrantsSection(ctx: Ctx, repo: Repo): Html | null {
2425 <h2>Who may read this</h2>
2526 <p class="muted">Let one of your apps, or one crew member, read this mirror's commits, branches and pulls, and nothing else, until you revoke it.</p>
2627 ${grants.length === 0
27 ? html`<p class="muted small">No one else reads it.</p>`
28 ? emptyLine("readGrants")
2829 : html`<dl class="status-rows">
2930 ${grants.map(
3031 (g) => html`<div class="status-row">
src/web/render/reg.ts +2 −1
@@ -9,6 +9,7 @@
99 */
1010
1111 import { escapeHtml, html, raw } from "../html.ts";
12 import { emptyLine } from "../empty_words.ts";
1213 import { fileSize } from "../ui.ts";
1314 import type { Rendered, RenderInput } from "./renderers.ts";
1415
@@ -187,7 +188,7 @@ export function registry(input: RenderInput): Rendered {
187188 .join("");
188189 const table =
189190 k.values.length === 0
190 ? `<p class="muted small">No values.</p>`
191 ? String(emptyLine("regValues"))
191192 : `<table class="table" data-dense aria-label="Values of ${escapeHtml(k.path)}"><thead><tr><th scope="col">Name</th><th scope="col">Type</th><th scope="col">Data</th></tr></thead><tbody>${rows}</tbody></table>`;
192193 const left = k.left > 0 ? `<p class="muted small">${noun(k.left, "more value", "more values")} in the raw file.</p>` : "";
193194 sections += `<section><h3>${code(k.path)}</h3>${table}${left}</section>`;
test/app-flags.test.ts +6
@@ -13,6 +13,8 @@ import { newApp } from "../src/actions/apps.ts";
1313 import { commitToBranch } from "../src/actions/repos.ts";
1414 import { appEnv } from "../src/apps/process.ts";
1515 import { parseDecls } from "../src/core/app_flags.ts";
16 import { appFlagsView } from "../src/web/pages/app_flags.ts";
17 import { emptyLine } from "../src/web/empty_words.ts";
1618 import { bucket } from "../src/core/flags.ts";
1719 import { createToken } from "../src/core/tokens.ts";
1820 import { createRepo } from "../src/actions/repos.ts";
@@ -31,6 +33,10 @@ test("a declaration keeps what is valid and drops the rest", () => {
3133 expect(parseDecls(undefined)).toEqual({});
3234 });
3335
36 test("an app that declares no flag says the table's line, drawn by emptyLine", () => {
37 expect(String(appFlagsView("/alice/budgeting", []))).toContain(String(emptyLine("appFlags")));
38 });
39
3440 test("the app is told where its flags are", () => {
3541 const env = appEnv({ port: 1, dataDir: "/d", env: "production", url: "http://a", commitOid: "abc", forgeUrl: "https://forge.test/", repo: "alice/budgeting", identityKey: "k" });
3642 expect(env["FORGE_FLAGS_URL"]).toBe("https://forge.test/api/v1/repos/alice/budgeting/flags");
test/empty-notes.test.ts +1 −1
@@ -16,7 +16,7 @@ test("every note is plain words ending in a full stop", () => {
1616
1717 test("emptyNote draws the table's sentence in one muted paragraph", () => {
1818 expect(String(emptyNote("noGateHasRunYet"))).toBe('<p class="muted">No gate has run yet.</p>');
19 expect(String(emptyNote("noFlagIsDeclaredYet"))).toContain(NOTE_WORDS.noFlagIsDeclaredYet);
19 expect(String(emptyNote("noChangeYet"))).toContain(NOTE_WORDS.noChangeYet);
2020 });
2121
2222 // Pages that word their own empty note, by file. Move one onto NOTE_WORDS and lower its count.
test/empty-words-all.test.ts +2
@@ -2,6 +2,8 @@
22 * One table of empty words (#15851): every empty state a page registers has an entry (a sentence; a
33 * reason and one link only where they add something and the place exists), and a page that words
44 * its own "No …" empty state is named below until it moves.
5 *
6 * @tree-scan: walks all of src/web/ through readdirSync on a parameter.
57 */
68 import { expect, test } from "bun:test";
79 import { readdirSync, readFileSync, statSync } from "node:fs";
test/flags-language.test.ts +1 −1
@@ -65,5 +65,5 @@ test("no flag declared is one plain sentence, no card", async () => {
6565 useFlagRegistry(makeFlags({}));
6666 const body = await page();
6767 expect(body).not.toContain('class="card');
68 expect(body).toContain("No flag is declared yet.");
68 expect(body).toContain("No flag is declared.");
6969 });
test/gifts-page.test.ts +3
@@ -12,6 +12,7 @@ import { insertCode, noteRedeemed, revokeCode } from "../src/billing/codes.ts";
1212 import { createSession } from "../src/core/sessions.ts";
1313 import { createUser } from "../src/core/users.ts";
1414 import { serve, type Servers } from "../src/http/server.ts";
15 import { emptyLine } from "../src/web/empty_words.ts";
1516 import { quietLogs } from "./helpers/globals.ts";
1617
1718 quietLogs();
@@ -59,6 +60,8 @@ test("a person without a paid forge sees no block and cannot make a link", async
5960
6061 test("one tap makes a link shown once; the settings then list it as waiting", async () => {
6162 expect(await get(sub)).toContain("Make a gift link");
63 // No gift yet: the table's line, drawn by emptyLine, not words of the page's own.
64 expect(await get(sub)).toContain(String(emptyLine("gifts")));
6265 const res = await make(sub);
6366 expect(res.status).toBe(200);
6467 expect(res.headers.get("cache-control")).toBe("no-store");
test/gifts-tui.test.ts +3 −1
@@ -12,6 +12,7 @@ import { createUser, type User } from "../src/core/users.ts";
1212 import { createForgeApp } from "../src/tui/forge.ts";
1313 import { entry, giftsScreen } from "../src/tui/screens/gifts.ts";
1414 import { headlessTerminal } from "../src/tui/term/terminal.ts";
15 import { emptyText } from "../src/core/empty_words.ts";
1516 import { quietLogs } from "./helpers/globals.ts";
1617 import { settleApp } from "./helpers/tui.ts";
1718
@@ -57,7 +58,8 @@ test("a subscriber makes a gift link and sees it listed as waiting", async () =>
5758 const { tui, session } = open(sub);
5859 tui.ctx.push(giftsScreen(session, tui.ctx));
5960 await settleApp(tui);
60 expect(tui.screen.toText()).toContain("No gift yet.");
61 // The table's sentence and reason, as the page says them.
62 expect(tui.screen.toText()).toContain(emptyText("gifts"));
6163 tui.dispatch(key("n"));
6264 await settleApp(tui);
6365 expect(tui.screen.toText()).toMatch(/forge-[a-z0-9]{4}-[a-z0-9]{4}/);
test/keys-flags-list.test.ts +1 −1
@@ -64,6 +64,6 @@ test("each flag row is one data-nav row whose primary link is its owner issue",
6464 test("the empty list draws no flag data-nav row", async () => {
6565 useFlagRegistry(makeFlags({}));
6666 const text = await get();
67 expect(text).toContain("No flag is declared yet.");
67 expect(text).toContain("No flag is declared.");
6868 expect(text).not.toMatch(/class="row"[^>]*data-nav tabindex="-1"/);
6969 });
test/origin-read-grant.test.ts +3 −1
@@ -35,6 +35,7 @@ import { syncsSettled } from "../src/origins/sync.ts";
3535 import { mirrorAndWait, newFakeState, serveFakeForge, type FakeForge } from "./fake-origin.ts";
3636 import { seedAdmin } from "./helpers/admin.ts";
3737 import { proveAll } from "./helpers/verified.ts";
38 import { emptyLine } from "../src/web/empty_words.ts";
3839
3940
4041 const LOGIN = "octo";
@@ -175,7 +176,8 @@ describe("a read grant on a read-only mirror", () => {
175176 const page = (path = `/alice/${NAME}/settings`) => fetch(`${servers.url}${path}`, { headers: { cookie } });
176177 const html = await (await page()).text();
177178 expect(html).toContain("Who may read this");
178 expect(html).toContain("No one else reads it.");
179 // The table's line, drawn by emptyLine, not words of the page's own.
180 expect(html).toContain(String(emptyLine("readGrants")));
179181 const form = new URLSearchParams({ kind: "app", name: "morning-paper" });
180182 const res = await fetch(`${servers.url}/alice/${NAME}/settings/read-grants`, {
181183 method: "POST",
test/render-registry.test.ts +5
@@ -4,6 +4,7 @@ import { aboutReg, decodeReg, DELETE_CAP, KEY_CAP, parseReg, registry, VALUE_CAP
44 import { fileKind, RENDER_CAP } from "../src/web/render/kinds.ts";
55 import { RENDERERS } from "../src/web/render/renderers.ts";
66 import { registryView } from "../src/tui/screens/workspace_registry.ts";
7 import { emptyLine } from "../src/web/empty_words.ts";
78
89 const enc = (s: string): Uint8Array => new TextEncoder().encode(s);
910 const utf16 = (s: string): Uint8Array => {
@@ -53,6 +54,10 @@ describe("registry", () => {
5354 expect(out).toContain("<td>dword</td><td>0x00000001 (1)</td>");
5455 });
5556
57 test("a key with no values says the table's line, drawn by emptyLine", () => {
58 expect(String(registry(input(enc(HEAD + "[HKEY_A]\r\n"))).content)).toContain(String(emptyLine("regValues")));
59 });
60
5661 test("every value is escaped", () => {
5762 const body = enc(HEAD + '[HKEY_A\\<script>1</script>]\n"<b>n</b>"="<img src=x onerror=1>"\n"<i>v</i>"=-\n[-HKEY_<u>]\n');
5863 const out = String(registry(input(body)).content);

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs