Public: anyone can read this; the crew can change it.
Empty words: move the apps and forges pages onto the shared table #15906
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/15902-empty-words-move-the-apps-and-forges-pag → main 6 commits fork 2 threads · 2 unresolved
12 files
changed +111
−78
src/core/empty_words.ts +27 −24
| @@ -5,45 +5,44 @@ | ||
| 5 | 5 | * every kind and holds each to its sentence and its single link. |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | export type EmptyKind = "board" | "inbox" | "runs" | "apps" | "people" | "waves" | |
| 9 | | "builds" | |
| 10 | | "releases" | |
| 11 | | "forks" | |
| 12 | | "repos" | |
| 13 | | "commits" | |
| 14 | | "displays" | |
| 15 | | "issues" | |
| 16 | | "pulls" | |
| 17 | | "branches" | |
| 18 | | "labels" | |
| 19 | | "events"; | |
| 20 | ||
| 21 | 8 | export interface EmptyWords { |
| 22 | 9 | /** One sentence, plain words, ending in a full stop. */ |
| 23 | 10 | readonly sentence: string; |
| 24 | /** | |
| 25 | * Why it is empty, in one calm sentence, only where the page does not already say it: a list that | |
| 26 | * names what it is carries none (nothing explains itself twice). | |
| 27 | */ | |
| 11 | /** Said under the sentence, only where the page does not already say what the list is. */ | |
| 28 | 12 | readonly reason?: string; |
| 29 | 13 | /** The one action's words, only where one exists. */ |
| 30 | 14 | readonly label?: string; |
| 31 | /** | |
| 32 | * Where the action goes, only where that place exists unscoped; a repository's list hands in its | |
| 33 | * own (`emptyList(kind, { href })`), and a label with no href and none handed in draws no link. | |
| 34 | */ | |
| 15 | /** Where the action goes, only where that place exists unscoped; a list hands in its own. */ | |
| 35 | 16 | readonly href?: string; |
| 36 | 17 | } |
| 37 | 18 | |
| 38 | export const EMPTY_WORDS: Readonly<Record<EmptyKind, EmptyWords>> = { | |
| 19 | const TABLE = { | |
| 39 | 20 | board: { sentence: "No board yet.", label: "Start from a question", href: "/boards/data" }, |
| 40 | 21 | inbox: { sentence: "Nothing is waiting on you.", label: "Tell the crew something", href: "/tell" }, |
| 41 | 22 | runs: { sentence: "No run is open.", label: "Start with an issue", href: "/issues" }, |
| 42 | 23 | apps: { sentence: "Nothing runs here yet.", label: "New app", href: "/apps/new" }, |
| 43 | 24 | waves: { sentence: "No waves yet.", label: "Tell the crew", href: "/tell" }, |
| 44 | 25 | people: { sentence: "Nobody has joined yet.", label: "Invite someone", href: "/admin/limits" }, |
| 45 | builds: { sentence: "No builds yet.", label: "Pin one from a branch" }, | |
| 26 | // Lists whose place exists only inside a page that already offers the next step (a form just | |
| 27 | // below): no label, so no link. | |
| 28 | appReleases: { sentence: "No release yet.", reason: "A release is recorded when production first serves a new version." }, | |
| 29 | templates: { sentence: "No template is marked." }, | |
| 30 | variants: { sentence: "No variants yet.", reason: "Register a branch to run it as a variant." }, | |
| 31 | cloudAccounts: { sentence: "No cloud account is sealed yet.", reason: "Add one below: pick a provider, name it, paste its credential." }, | |
| 32 | cloudReads: { sentence: "No credential has been read yet." }, | |
| 33 | vendorCalls: { sentence: "No vendor call today.", reason: "Rows are kept 90 days." }, | |
| 34 | forgeNames: { sentence: "No other name yet.", reason: "Add one below, or allow one when a forge asks." }, | |
| 35 | forgesOwn: { sentence: "No forge has asked for a name, and none has one of its own." }, | |
| 36 | refused: { sentence: "No first ask has been refused." }, | |
| 37 | databases: { sentence: "No database yet.", reason: "An app's SQLite files appear here once it has written one under its data directory." }, | |
| 38 | rows: { sentence: "No rows." }, | |
| 39 | talkRepos: { sentence: "No repository yet." }, | |
| 40 | talkFiles: { sentence: "No files touched yet." }, | |
| 41 | talkPulls: { sentence: "No open pull yet." }, | |
| 42 | talkHidden: { sentence: "Not a repository you can see." }, | |
| 43 | talkIdle: { sentence: "Nothing running yet." }, | |
| 46 | 44 | releases: { sentence: "No releases yet.", reason: "A pull landed on the forge's own repository is recorded here." }, |
| 45 | builds: { sentence: "No builds yet.", label: "Pin one from a branch" }, | |
| 47 | 46 | forks: { sentence: "No forks yet.", reason: "A fork is a copy under another name that can propose changes back here, and follows this one until it has work of its own." }, |
| 48 | 47 | repos: { sentence: "No repositories yet.", label: "New repository", href: "/new" }, |
| 49 | 48 | commits: { sentence: "No commits yet.", reason: "Push a branch and its history shows up here." }, |
| @@ -53,4 +52,8 @@ export const EMPTY_WORDS: Readonly<Record<EmptyKind, EmptyWords>> = { | ||
| 53 | 52 | labels: { sentence: "No labels yet." }, |
| 54 | 53 | events: { sentence: "No events yet." }, |
| 55 | 54 | displays: { sentence: "No displays yet.", reason: "Add a display.json to a repository's default branch to make one." }, |
| 56 | }; | |
| 55 | } as const satisfies Readonly<Record<string, EmptyWords>>; | |
| 56 | ||
| 57 | export type EmptyKind = keyof typeof TABLE; | |
| 58 | ||
| 59 | export const EMPTY_WORDS: Readonly<Record<EmptyKind, EmptyWords>> = TABLE; |
src/web/empty_words.ts +27 −12
| @@ -5,21 +5,26 @@ | ||
| 5 | 5 | * `test/empty-states.test.ts` walks every kind and holds each to its sentence and its single link. |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | import type { Html } from "./html.ts"; | |
| 9 | import { EMPTY_WORDS, type EmptyKind } from "../core/empty_words.ts"; | |
| 8 | import { html, type Html } from "./html.ts"; | |
| 9 | import { EMPTY_WORDS, type EmptyKind, type EmptyWords } from "../core/empty_words.ts"; | |
| 10 | 10 | import { btn, empty, type IconName } from "./ui.ts"; |
| 11 | 11 | |
| 12 | 12 | export { EMPTY_WORDS, type EmptyKind }; |
| 13 | 13 | |
| 14 | const ICONS: Readonly<Record<EmptyKind, IconName>> = { | |
| 14 | /** The kinds drawn as a block with a picture; every other kind is a quiet line (`emptyLine`). */ | |
| 15 | const ICONS = { | |
| 15 | 16 | board: "activity", |
| 16 | 17 | inbox: "check", |
| 17 | 18 | runs: "bot", |
| 18 | apps: "repo", | |
| 19 | apps: "rocket", | |
| 19 | 20 | people: "users", |
| 20 | 21 | waves: "activity", |
| 21 | builds: "pin", | |
| 22 | 22 | releases: "activity", |
| 23 | appReleases: "tag", | |
| 24 | variants: "branch", | |
| 25 | databases: "folder", | |
| 26 | rows: "search", | |
| 27 | builds: "pin", | |
| 23 | 28 | forks: "fork", |
| 24 | 29 | repos: "repo", |
| 25 | 30 | commits: "commit", |
| @@ -29,32 +34,42 @@ const ICONS: Readonly<Record<EmptyKind, IconName>> = { | ||
| 29 | 34 | branches: "branch", |
| 30 | 35 | labels: "tag", |
| 31 | 36 | events: "activity", |
| 32 | }; | |
| 37 | } as const satisfies Partial<Record<EmptyKind, IconName>>; | |
| 33 | 38 | |
| 34 | 39 | export interface EmptyOptions { |
| 35 | 40 | /** Where the action goes, when it is not the table's (a repository's own issues, say). */ |
| 36 | 41 | href?: string; |
| 37 | 42 | /** Leave the link out: the viewer cannot take the action, or the page already offers it. */ |
| 38 | 43 | noAction?: boolean; |
| 44 | /** A reason that fits this one list (a filter that matched nothing), over the table's. */ | |
| 45 | reason?: string; | |
| 46 | /** Alias of `reason`, for a list whose reason is read live. */ | |
| 47 | note?: string; | |
| 39 | 48 | /** A filtered view names its filter ("No closed issues"); the reason stays the table's. */ |
| 40 | 49 | title?: string; |
| 41 | /** A list whose reason is its own (an origin's list, read live) hands it in. */ | |
| 42 | note?: string; | |
| 43 | 50 | /** A page that has its own action (a link back to the unfiltered list) hands it in. */ |
| 44 | 51 | action?: Html; |
| 45 | 52 | bind?: string | undefined; |
| 46 | 53 | } |
| 47 | 54 | |
| 48 | export function emptyList(kind: EmptyKind, o: EmptyOptions = {}): Html { | |
| 49 | const w = EMPTY_WORDS[kind]; | |
| 50 | const note = o.note ?? w.reason; | |
| 55 | export function emptyList(kind: keyof typeof ICONS, o: EmptyOptions = {}): Html { | |
| 56 | const w: EmptyWords = EMPTY_WORDS[kind]; | |
| 57 | const reason = o.reason ?? o.note ?? w.reason; | |
| 51 | 58 | const href = o.href ?? w.href; |
| 52 | 59 | const action = o.action ?? (o.noAction || w.label === undefined || href === undefined ? undefined : btn(w.label, { href, variant: "link" })); |
| 53 | 60 | return empty({ |
| 54 | 61 | icon: ICONS[kind], |
| 55 | 62 | title: o.title ?? w.sentence, |
| 56 | ...(note === undefined ? {} : { note }), | |
| 63 | ...(reason === undefined ? {} : { note: reason }), | |
| 57 | 64 | ...(action === undefined ? {} : { action }), |
| 58 | 65 | bind: o.bind, |
| 59 | 66 | }); |
| 60 | 67 | } |
| 68 | ||
| 69 | /** A list of none inside a block that already has its next step (a form just below): one muted | |
| 70 | * line, the sentence and its reason, no picture and no link, so the form stays in view. */ | |
| 71 | export function emptyLine(kind: Exclude<EmptyKind, keyof typeof ICONS>, o: { reason?: string } = {}): Html { | |
| 72 | const w: EmptyWords = EMPTY_WORDS[kind]; | |
| 73 | const reason = o.reason ?? w.reason; | |
| 74 | return html`<p class="muted small">${reason === undefined ? w.sentence : `${w.sentence} ${reason}`}</p>`; | |
| 75 | } |
src/web/pages/app_releases.ts +3 −5
| @@ -10,7 +10,8 @@ import { releaseFacts } from "../../release/app_words.ts"; | ||
| 10 | 10 | import { loadRepo, notFoundPage, pageHead, repoBase } from "../chrome.ts"; |
| 11 | 11 | import { html } from "../html.ts"; |
| 12 | 12 | import { page } from "../layout.ts"; |
| 13 | import { empty, row, sha, time } from "../ui.ts"; | |
| 13 | import { row, sha, time } from "../ui.ts"; | |
| 14 | import { emptyList } from "../empty_words.ts"; | |
| 14 | 15 | |
| 15 | 16 | export function appReleasesPage(ctx: Ctx): Response { |
| 16 | 17 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| @@ -23,10 +24,7 @@ export function appReleasesPage(ctx: Ctx): Response { | ||
| 23 | 24 | body: html`<div class="narrow-wide"> |
| 24 | 25 | ${pageHead("Releases", { sub: `Each version ${repo.ownerName}/${repo.name} first served in production.` })} |
| 25 | 26 | ${releases.length === 0 |
| 26 | ? empty({ | |
| 27 | title: "No release yet", | |
| 28 | note: "A release is recorded when production first serves a new version.", | |
| 29 | }) | |
| 27 | ? emptyList("appReleases", { noAction: true }) | |
| 30 | 28 | : html`<ul class="list" aria-label="Releases">${releases.map((r) => |
| 31 | 29 | row({ |
| 32 | 30 | title: html`${r.version} · ${r.subject}`, |
src/web/pages/app_templates.ts +2 −1
| @@ -13,6 +13,7 @@ import { field, readForm } from "../form.ts"; | ||
| 13 | 13 | import { html } from "../html.ts"; |
| 14 | 14 | import { flashTo, page } from "../layout.ts"; |
| 15 | 15 | import { btn, empty, field as formField, icon, row } from "../ui.ts"; |
| 16 | import { emptyLine } from "../empty_words.ts"; | |
| 16 | 17 | import { accountSections } from "./origins.ts"; |
| 17 | 18 | |
| 18 | 19 | function denied(ctx: Ctx): Response | undefined { |
| @@ -59,7 +60,7 @@ export function appTemplatesPage(ctx: Ctx): Response { | ||
| 59 | 60 | }); |
| 60 | 61 | const body = html`<section class="settings-block"> |
| 61 | 62 | <p class="muted">The repositories New app can copy.</p> |
| 62 | ${rows.length === 0 ? html`<p class="muted">No template is marked.</p>` : html`<ul class="list setting-list">${rows}</ul>`} | |
| 63 | ${rows.length === 0 ? emptyLine("templates") : html`<ul class="list setting-list">${rows}</ul>`} | |
| 63 | 64 | <form method="post" action="/settings/app-templates"> |
| 64 | 65 | <input type="hidden" name="marked" value="1" /> |
| 65 | 66 | ${formField({ label: "Mark a repository", name: "repo", placeholder: "owner/name", mono: true, required: true })} |
src/web/pages/app_variants.ts +3 −2
| @@ -22,7 +22,8 @@ import { crumbsFor, loadRepo, notFoundPage, repoBase, repoHeader, repoPalette, s | ||
| 22 | 22 | import { field as formValue, readForm, type Form } from "../form.ts"; |
| 23 | 23 | import { html, when, type Html } from "../html.ts"; |
| 24 | 24 | import { flashTo, page } from "../layout.ts"; |
| 25 | import { badge, btn, confirmAction, disclosure, empty, field, listCard, row } from "../ui.ts"; | |
| 25 | import { badge, btn, confirmAction, disclosure, field, listCard, row } from "../ui.ts"; | |
| 26 | import { emptyList } from "../empty_words.ts"; | |
| 26 | 27 | |
| 27 | 28 | const hidden = (error: string): boolean => error === "unauthorized" || error === "not_found" || error === "forbidden"; |
| 28 | 29 | |
| @@ -79,7 +80,7 @@ export async function variantBoardPage(ctx: Ctx): Promise<Response> { | ||
| 79 | 80 | <h2 class="mt">Variants</h2> |
| 80 | 81 | <p class="muted small">A branch kept running beside production, with values of its own: ${budget}.</p> |
| 81 | 82 | ${board.cards.length === 0 |
| 82 | ? empty({ title: "No variants yet", note: "Register a branch to run it as a variant." }) | |
| 83 | ? emptyList("variants", { noAction: true }) | |
| 83 | 84 | : listCard(board.cards.map((c) => variantRow(base, c, writer)))} |
| 84 | 85 | ${when(writer && board.cards.length < VARIANTS_MAX, () => html`<form method="post" action="${base}/variants" class="mt"> |
| 85 | 86 | <h3>Run a branch as a variant</h3> |
src/web/pages/cloud.ts +4 −3
| @@ -32,6 +32,7 @@ import { field, readForm } from "../form.ts"; | ||
| 32 | 32 | import { html, type Html } from "../html.ts"; |
| 33 | 33 | import { flashTo, page } from "../layout.ts"; |
| 34 | 34 | import { btn, confirmAction, icon, row, time } from "../ui.ts"; |
| 35 | import { emptyLine } from "../empty_words.ts"; | |
| 35 | 36 | import { accountSections } from "./origins.ts"; |
| 36 | 37 | |
| 37 | 38 | const BACK = "/settings/cloud"; |
| @@ -100,7 +101,7 @@ function accountsCard(accounts: CloudAccount[], reads: CloudRead[], uses: Map<st | ||
| 100 | 101 | <p class="muted small">Paste a credential once; the forge checks it read-only, seals it, and never shows it again.</p> |
| 101 | 102 | ${rows.length > 0 |
| 102 | 103 | ? html`<ul class="list setting-list">${rows}</ul>` |
| 103 | : html`<p class="muted small">No cloud account is sealed yet. Add one below: pick a provider, name it, paste its credential.</p>`} | |
| 104 | : emptyLine("cloudAccounts")} | |
| 104 | 105 | </section> |
| 105 | 106 | <section class="settings-block"> |
| 106 | 107 | <h2>Add an account</h2> |
| @@ -123,7 +124,7 @@ function readsCard(reads: CloudRead[]): Html { | ||
| 123 | 124 | return html`<section class="settings-block"> |
| 124 | 125 | <h2>Every read</h2> |
| 125 | 126 | ${reads.length === 0 |
| 126 | ? html`<p class="muted small">No credential has been read yet.</p>` | |
| 127 | ? emptyLine("cloudReads") | |
| 127 | 128 | : html`<ul class="list"> |
| 128 | 129 | ${reads.map((r) => |
| 129 | 130 | row({ |
| @@ -227,7 +228,7 @@ export function cloudAuditPage(ctx: Ctx): Response { | ||
| 227 | 228 | html`<section class="settings-block"> |
| 228 | 229 | <h2>Today's vendor calls</h2> |
| 229 | 230 | ${rows.length === 0 |
| 230 | ? html`<p class="muted small">No vendor call today. Rows are kept 90 days.</p>` | |
| 231 | ? emptyLine("vendorCalls") | |
| 231 | 232 | : html`<ul class="list"> |
| 232 | 233 | ${rows.map((r) => |
| 233 | 234 | row({ |
src/web/pages/data_view.ts +5 −7
| @@ -11,7 +11,8 @@ import { PAGE_SIZE, rows, tables, topValues, type RowsResult } from "../../data/ | ||
| 11 | 11 | import { query } from "../../data/query.ts"; |
| 12 | 12 | import type { Source } from "../../data/sources.ts"; |
| 13 | 13 | import { html, type Html } from "../html.ts"; |
| 14 | import { btn, empty, field, iconBtn, pager, row } from "../ui.ts"; | |
| 14 | import { btn, field, iconBtn, pager, row } from "../ui.ts"; | |
| 15 | import { emptyList } from "../empty_words.ts"; | |
| 15 | 16 | |
| 16 | 17 | /** Longest SQL an address may carry. */ |
| 17 | 18 | export const SQL_MAX = 4000; |
| @@ -96,10 +97,7 @@ export async function dataBody(view: DataView, q: URLSearchParams): Promise<Html | ||
| 96 | 97 | const envOf = (s: Source) => s.id.split(":")[2] ?? ""; |
| 97 | 98 | const files = |
| 98 | 99 | sources.length === 0 |
| 99 | ? empty({ | |
| 100 | title: "No database yet", | |
| 101 | note: "An app's SQLite files appear here once it has written one under its data directory.", | |
| 102 | }) | |
| 100 | ? emptyList("databases", { noAction: true }) | |
| 103 | 101 | : view.byEnv |
| 104 | 102 | ? html`${[...new Set(sources.map(envOf))].map( |
| 105 | 103 | (env) => html`<h2>${env}</h2><ul class="list">${sources.filter((s) => envOf(s) === env).map(fileRow)}</ul>`, |
| @@ -192,7 +190,7 @@ export async function dataBody(view: DataView, q: URLSearchParams): Promise<Html | ||
| 192 | 190 | </form> |
| 193 | 191 | ${note ? html`<p class="muted small">${note}</p>` : null} |
| 194 | 192 | ${exact && text !== "" ? html`<p class="muted small">Rows where ${col ?? ""} equals “${text}”. Filtering again finds rows that contain the text.</p>` : null} |
| 195 | ${shown.rows.length === 0 ? empty({ title: "No rows", note: text !== "" ? "Nothing matches that filter." : "This table is empty." }) : grid(cols, shown.rows, `${tableName} in ${source.label}`, header, true)} | |
| 193 | ${shown.rows.length === 0 ? emptyList("rows", { noAction: true, reason: text !== "" ? "Nothing matches that filter." : "This table is empty." }) : grid(cols, shown.rows, `${tableName} in ${source.label}`, header, true)} | |
| 196 | 194 | ${pager({ |
| 197 | 195 | note: `${shown.total} rows`, |
| 198 | 196 | words: { prev: "Previous page", next: "Next page" }, |
| @@ -226,7 +224,7 @@ export async function dataBody(view: DataView, q: URLSearchParams): Promise<Html | ||
| 226 | 224 | const ms = Math.max(1, Math.round(performance.now() - t0)); |
| 227 | 225 | out = result.ok |
| 228 | 226 | ? html`${out} |
| 229 | ${result.rows.length === 0 ? empty({ title: "No rows" }) : grid(result.columns, result.rows, "Query result", (c) => html`<th scope="col">${c}</th>`, false)} | |
| 227 | ${result.rows.length === 0 ? emptyList("rows", { noAction: true }) : grid(result.columns, result.rows, "Query result", (c) => html`<th scope="col">${c}</th>`, false)} | |
| 230 | 228 | <p class="muted small">${String(result.rowsRead)} rows read${result.truncated ? " (cut)" : ""} · ${String(result.elapsedMs)} ms</p>` |
| 231 | 229 | : html`${out}<p role="alert" class="muted">${result.message} · ${String(ms)} ms</p>`; |
| 232 | 230 | } |
src/web/pages/forges-refused.ts +2 −1
| @@ -12,6 +12,7 @@ import { notFoundPage, pageHead } from "../chrome.ts"; | ||
| 12 | 12 | import { html } from "../html.ts"; |
| 13 | 13 | import { page } from "../layout.ts"; |
| 14 | 14 | import { time } from "../ui.ts"; |
| 15 | import { emptyLine } from "../empty_words.ts"; | |
| 15 | 16 | |
| 16 | 17 | export { REFUSED_SHOWN }; |
| 17 | 18 | |
| @@ -27,7 +28,7 @@ export function forgesRefusedPage(ctx: Ctx): Response { | ||
| 27 | 28 | body: html`<div class="narrow-wide" data-refused> |
| 28 | 29 | ${pageHead("Refused first asks", { sub: `The last ${REFUSED_SHOWN} first asks the forge turned away, newest first.` })} |
| 29 | 30 | ${rows.length === 0 |
| 30 | ? html`<p class="muted">No first ask has been refused.</p>` | |
| 31 | ? emptyLine("refused") | |
| 31 | 32 | : html`<ul class="list setting-list"> |
| 32 | 33 | ${rows.map( |
| 33 | 34 | (r) => html`<li data-refusal> |
src/web/pages/hosted-forges.ts +3 −6
| @@ -34,6 +34,7 @@ import { backTo, field as formField, readForm } from "../form.ts"; | ||
| 34 | 34 | import { html, type Html } from "../html.ts"; |
| 35 | 35 | import { flashTo, page } from "../layout.ts"; |
| 36 | 36 | import { badge, btn, field, row, time } from "../ui.ts"; |
| 37 | import { emptyLine } from "../empty_words.ts"; | |
| 37 | 38 | import { accountSections } from "./origins.ts"; |
| 38 | 39 | |
| 39 | 40 | /** What the switch turns on, in the words the page and every pointer to it use. */ |
| @@ -179,9 +180,7 @@ export async function hostedForgesPage(ctx: Ctx): Promise<Response> { | ||
| 179 | 180 | </ul> |
| 180 | 181 | <h3 class="mt" id="reach-also">and also:</h3> |
| 181 | 182 | ${view.everyForge.length === 0 |
| 182 | ? html`<p class="muted small"> | |
| 183 | No other name yet. Add one below, or allow one when a forge asks. | |
| 184 | </p>` | |
| 183 | ? emptyLine("forgeNames") | |
| 185 | 184 | : html`<ul class="list setting-list" data-reach-every> |
| 186 | 185 | ${view.everyForge.map((g) => |
| 187 | 186 | row({ |
| @@ -216,9 +215,7 @@ export async function hostedForgesPage(ctx: Ctx): Promise<Response> { | ||
| 216 | 215 | </form> |
| 217 | 216 | <h3 class="mt" id="reach-forges">and for one forge only:</h3> |
| 218 | 217 | ${view.forges.length === 0 |
| 219 | ? html`<p class="muted small"> | |
| 220 | No forge has asked for a name, and none has one of its own. | |
| 221 | </p>` | |
| 218 | ? emptyLine("forgesOwn") | |
| 222 | 219 | : html`${waiting.length === 0 |
| 223 | 220 | ? null |
| 224 | 221 | : html`<p class="small" role="status" data-reach-waiting> |
src/web/pages/talk_preview.ts +8 −7
| @@ -16,6 +16,7 @@ import type { User } from "../../core/users.ts"; | ||
| 16 | 16 | import type { Work } from "../../core/talk_work.ts"; |
| 17 | 17 | import type { Ctx } from "../../http/context.ts"; |
| 18 | 18 | import { html, raw, type Html } from "../html.ts"; |
| 19 | import { emptyLine } from "../empty_words.ts"; | |
| 19 | 20 | |
| 20 | 21 | export interface Pane { |
| 21 | 22 | readonly html: Html; |
| @@ -27,27 +28,27 @@ export const VIEWS = ["preview", "code", "diff"] as const; | ||
| 27 | 28 | export type View = (typeof VIEWS)[number]; |
| 28 | 29 | |
| 29 | 30 | export function talkPane(ctx: Ctx, user: User, name: string | undefined, works: ReadonlyMap<string, Work>, view: View = "preview", apps?: Apps): Pane { |
| 30 | const empty = (words: string): Pane => ({ | |
| 31 | const empty = (words: Html): Pane => ({ | |
| 31 | 32 | frame: undefined, |
| 32 | html: html`<aside class="talk-pane" aria-label="Preview"><p class="muted small">${words}</p></aside>`, | |
| 33 | html: html`<aside class="talk-pane" aria-label="Preview">${words}</aside>`, | |
| 33 | 34 | }); |
| 34 | if (name === undefined) return empty("No repository yet."); | |
| 35 | if (name === undefined) return empty(emptyLine("talkRepos")); | |
| 35 | 36 | const ws = workspaceOf(ctx.app, user, name, apps); |
| 36 | if (ws === undefined) return empty("Not a repository you can see."); | |
| 37 | if (ws === undefined) return empty(emptyLine("talkHidden")); | |
| 37 | 38 | const { pull, url } = ws; |
| 38 | 39 | const tab = (id: View, label: string): Html => html`<a href="?pane=${id}"${view === id ? raw(' aria-current="page"') : null}>${label}</a>`; |
| 39 | 40 | const files = [...new Map([...works.values()].flatMap((w) => w.links).filter((l) => l.href.includes("/blob/")).map((l) => [l.href, l] as const)).values()].slice(0, 12); |
| 40 | 41 | const panel = |
| 41 | 42 | view === "code" |
| 42 | 43 | ? files.length === 0 |
| 43 | ? html`<p class="muted small">No files touched yet.</p>` | |
| 44 | ? emptyLine("talkFiles") | |
| 44 | 45 | : html`<ul class="list">${files.map((f) => html`<li><a href="${f.href}">${f.label}</a></li>`)}</ul>` |
| 45 | 46 | : view === "diff" |
| 46 | 47 | ? pull === undefined |
| 47 | ? html`<p class="muted small">No open pull yet.</p>` | |
| 48 | ? emptyLine("talkPulls") | |
| 48 | 49 | : html`<p><a class="btn" href="/${name}/pulls/${String(pull)}/files">Diff of pull #${String(pull)}</a></p>` |
| 49 | 50 | : url === undefined |
| 50 | ? html`<p class="muted small">Nothing running yet.</p>` | |
| 51 | ? emptyLine("talkIdle") | |
| 51 | 52 | : html`<iframe class="talk-frame" data-frame src="${url}" title="Live preview of ${name}" referrerpolicy="no-referrer" sandbox="allow-scripts allow-same-origin allow-forms allow-popups"></iframe>`; |
| 52 | 53 | return { |
| 53 | 54 | frame: ws.origin, |
test/empty-states.test.ts +27 −2
| @@ -9,9 +9,10 @@ import { join } from "node:path"; | ||
| 9 | 9 | import { createRepo } from "../src/actions/repos.ts"; |
| 10 | 10 | import { createApp, type App } from "../src/app.ts"; |
| 11 | 11 | import { createSession } from "../src/core/sessions.ts"; |
| 12 | import type { EmptyWords } from "../src/core/empty_words.ts"; | |
| 12 | 13 | import { createUser } from "../src/core/users.ts"; |
| 13 | 14 | import { serve, type Servers } from "../src/http/server.ts"; |
| 14 | import { EMPTY_WORDS, emptyList } from "../src/web/empty_words.ts"; | |
| 15 | import { EMPTY_WORDS, emptyLine, emptyList, type EmptyKind } from "../src/web/empty_words.ts"; | |
| 15 | 16 | |
| 16 | 17 | let dir: string; |
| 17 | 18 | let app: App; |
| @@ -106,7 +107,7 @@ test("the six lists take their empty sentence from one table, each with a single | ||
| 106 | 107 | // people: the signed-in admin is always one, so test/keys-people-list.test.ts holds its sentence |
| 107 | 108 | const pages: Record<string, string> = { board: "/boards", inbox: "/live/on-you", runs: "/root/fresh/runs", apps: "/apps", waves: "/root/fresh/waves" }; |
| 108 | 109 | for (const [kind, path] of Object.entries(pages)) { |
| 109 | const w = EMPTY_WORDS[kind as keyof typeof EMPTY_WORDS]; | |
| 110 | const w: EmptyWords = EMPTY_WORDS[kind as EmptyKind]; | |
| 110 | 111 | const blocks = emptyBlocks(await (await fetch(servers.url + path, { headers: { cookie } })).text()); |
| 111 | 112 | const mine = blocks.filter((b) => b.includes(w.sentence)); |
| 112 | 113 | expect(mine.length).toBe(1); |
| @@ -134,6 +135,30 @@ test("emptyList takes its link from the table unless the page names one, and can | ||
| 134 | 135 | expect(people.match(/<a\s/g)?.length).toBe(1); |
| 135 | 136 | }); |
| 136 | 137 | |
| 138 | test("a kind with a reason draws it under the sentence", () => { | |
| 139 | const out = String(emptyList("appReleases")); | |
| 140 | expect(out).toContain(EMPTY_WORDS.appReleases.sentence); | |
| 141 | expect(out).toContain(EMPTY_WORDS.appReleases.reason!); | |
| 142 | }); | |
| 143 | ||
| 144 | test("a reason given by the page wins over the table's", () => { | |
| 145 | const out = String(emptyList("databases", { reason: "Nothing matches that filter." })); | |
| 146 | expect(out).toContain("Nothing matches that filter."); | |
| 147 | expect(out).not.toContain(EMPTY_WORDS.databases.reason); | |
| 148 | }); | |
| 149 | ||
| 150 | test("a kind with no label draws no link, even when the page names a place", () => { | |
| 151 | expect(String(emptyList("rows"))).not.toMatch(/<a\s/); | |
| 152 | expect(String(emptyList("rows", { href: "/somewhere" }))).not.toContain("/somewhere"); | |
| 153 | }); | |
| 154 | ||
| 155 | test("emptyLine is one muted line: sentence and reason, no picture, no link", () => { | |
| 156 | const out = String(emptyLine("forgeNames")); | |
| 157 | expect(out).toBe(`<p class="muted small">${EMPTY_WORDS.forgeNames.sentence} ${EMPTY_WORDS.forgeNames.reason}</p>`); | |
| 158 | expect(String(emptyLine("templates"))).toBe(`<p class="muted small">${EMPTY_WORDS.templates.sentence}</p>`); | |
| 159 | expect(String(emptyLine("talkFiles", { reason: "Ask the crew." }))).toContain("No files touched yet. Ask the crew."); | |
| 160 | }); | |
| 161 | ||
| 137 | 162 | // One table for every list page a fresh admin can open (#13947): a page that draws an empty state |
| 138 | 163 | // has exactly one link or form in it, or is named in ALLOWED with the reason it has none. A failing |
| 139 | 164 | // page is named in the failure, so the fix points at the page. |
test/empty-words-all.test.ts −8
| @@ -29,9 +29,6 @@ const OWN_WORDS: Readonly<Record<string, number>> = { | ||
| 29 | 29 | "src/web/pages/account.ts": 2, |
| 30 | 30 | "src/web/pages/accounts.ts": 1, |
| 31 | 31 | "src/web/pages/admin-limits.ts": 1, |
| 32 | "src/web/pages/app_releases.ts": 1, | |
| 33 | "src/web/pages/app_templates.ts": 1, | |
| 34 | "src/web/pages/app_variants.ts": 1, | |
| 35 | 32 | "src/web/pages/audit.ts": 1, |
| 36 | 33 | "src/web/pages/bets.ts": 3, |
| 37 | 34 | "src/web/pages/billing.ts": 2, |
| @@ -42,10 +39,8 @@ const OWN_WORDS: Readonly<Record<string, number>> = { | ||
| 42 | 39 | "src/web/pages/browse.ts": 1, |
| 43 | 40 | "src/web/pages/build_shots.ts": 1, |
| 44 | 41 | "src/web/pages/capacity.ts": 1, |
| 45 | "src/web/pages/cloud.ts": 3, | |
| 46 | 42 | "src/web/pages/commits.ts": 1, |
| 47 | 43 | "src/web/pages/contribute.ts": 1, |
| 48 | "src/web/pages/data_view.ts": 3, | |
| 49 | 44 | "src/web/pages/display.ts": 1, |
| 50 | 45 | "src/web/pages/economics.ts": 1, |
| 51 | 46 | "src/web/pages/family.ts": 1, |
| @@ -53,9 +48,7 @@ const OWN_WORDS: Readonly<Record<string, number>> = { | ||
| 53 | 48 | "src/web/pages/flags.ts": 1, |
| 54 | 49 | "src/web/pages/flow-panel.ts": 1, |
| 55 | 50 | "src/web/pages/flows-all.ts": 1, |
| 56 | "src/web/pages/forges-refused.ts": 1, | |
| 57 | 51 | "src/web/pages/grants.ts": 1, |
| 58 | "src/web/pages/hosted-forges.ts": 2, | |
| 59 | 52 | "src/web/pages/inventory.ts": 1, |
| 60 | 53 | "src/web/pages/issues.ts": 1, |
| 61 | 54 | "src/web/pages/looks.ts": 1, |
| @@ -69,7 +62,6 @@ const OWN_WORDS: Readonly<Record<string, number>> = { | ||
| 69 | 62 | "src/web/pages/settings.ts": 1, |
| 70 | 63 | "src/web/pages/sources.ts": 1, |
| 71 | 64 | "src/web/pages/system.ts": 6, |
| 72 | "src/web/pages/talk_preview.ts": 3, | |
| 73 | 65 | "src/web/pages/teams.ts": 1, |
| 74 | 66 | "src/web/pages/trusted.ts": 1, |
| 75 | 67 | "src/web/pages/visitors.ts": 1, |
new above
offline
Hard to read:
a ?? b ? x : yplus!. Namereasonandhrefonce. And add tests for reason, per-call reason and no-label.