Public: anyone can read this; the crew can change it.
/settings has one line per setting: the reason moves behind the setting's name #13062
scout/forge:scout/13000-settings-has-one-line-per-setting-the-re → main 18 commits fork 5 threads · 5 unresolved
4 files
changed +85
−15
src/web/pages/settings.ts +3 −3
| @@ -733,7 +733,7 @@ function appSettingsView( | ||
| 733 | 733 | mono: true, |
| 734 | 734 | required: true, |
| 735 | 735 | pattern: "[a-z0-9](-?[a-z0-9])*", |
| 736 | hint: | |
| 736 | why: | |
| 737 | 737 | domain === undefined |
| 738 | 738 | ? "The label its hostnames are built from." |
| 739 | 739 | : `Its hostnames: ${values.slug || "<slug>"}.${domain} and ${values.slug || "<slug>"}--<n>.${domain} for the preview of pull .`, |
| @@ -742,7 +742,7 @@ function appSettingsView( | ||
| 742 | 742 | ${selectField({ |
| 743 | 743 | label: "Access", |
| 744 | 744 | name: "access", |
| 745 | hint: | |
| 745 | why: | |
| 746 | 746 | values.access === "public" |
| 747 | 747 | ? `Right now anyone with the link can open it, signed in or not. The code stays as ${repo.visibility} as the repository is: the two are set separately.` |
| 748 | 748 | : `Right now a visitor is asked to sign in and let through only if they can write this repository, are on its crew, or are named under Who may enter (${named.length === 0 ? "nobody is" : named.join(", ")}); reading the code is not enough, so it stays this way if the repository is made public. Everyone else sees not found. Choose Public to share it with anyone.`, |
| @@ -762,7 +762,7 @@ function appSettingsView( | ||
| 762 | 762 | ${selectField({ |
| 763 | 763 | label: "Preview data", |
| 764 | 764 | name: "previewData", |
| 765 | hint: "What a new preview's data directory starts as. A copy is never a window: nothing a preview writes reaches production.", | |
| 765 | why: "What a new preview's data directory starts as. A copy is never a window: nothing a preview writes reaches production.", | |
| 766 | 766 | options: [ |
| 767 | 767 | { |
| 768 | 768 | value: "copy", |
src/web/style/components.ts +2
| @@ -138,6 +138,8 @@ select.input { | ||
| 138 | 138 | .setting-line > label:not(.check) { margin: 0; } |
| 139 | 139 | .setting-line > select.input { width: auto; max-width: 100%; flex: 0 1 14rem; } |
| 140 | 140 | .setting-line > .check { flex: 0 1 auto; } |
| 141 | .setting-line > input.input { width: auto; max-width: 100%; flex: 1 1 14rem; min-width: 0; } | |
| 142 | .setting-line > .error { flex-basis: 100%; } | |
| 141 | 143 | .setting-line > details.why { margin: 0; } |
| 142 | 144 | .setting-line > details.why[open] { flex-basis: 100%; } |
| 143 | 145 | .setting-line > .setting-changed { margin-left: auto; } |
src/web/ui.ts +32 −11
| @@ -25,6 +25,7 @@ import { drawChart, type Cell, type Chart } from "../boards/chart.ts"; | ||
| 25 | 25 | import { icon, type IconName } from "./icons.ts"; |
| 26 | 26 | import { crewFace, scene, type SceneName } from "./pixel.ts"; |
| 27 | 27 | import { Html, html, raw, when } from "./html.ts"; |
| 28 | import { why } from "./setting_line.ts"; | |
| 28 | 29 | import { at, countAttr, listAttr, zeroAttr } from "./bind.ts"; |
| 29 | 30 | |
| 30 | 31 | export { icon, type IconName }; |
| @@ -185,7 +186,10 @@ export interface BtnOptions { | ||
| 185 | 186 | extra?: string; |
| 186 | 187 | /** The element's id, for a script or a fragment link that finds it. */ |
| 187 | 188 | id?: string; |
| 188 | /** A pager's link says which way it goes (`rel="next"`): a reader of the list follows it (`bind.ts`). */ | |
| 189 | /** | |
| 190 | * A pager's link says which way it goes (`rel="next"`): a reader of the list follows it | |
| 191 | * (`bind.ts`). | |
| 192 | */ | |
| 189 | 193 | rel?: "next" | "prev"; |
| 190 | 194 | } |
| 191 | 195 | |
| @@ -712,7 +716,9 @@ export function repoCounts(o: { | ||
| 712 | 716 | openPulls?: number | null | undefined; |
| 713 | 717 | /** Some origins report one number for issues *and* pulls; say so. */ |
| 714 | 718 | issuesIncludePulls?: boolean; |
| 715 | /** The repository we hold whose lists these count (`bind.ts`): absent for an origin's own numbers. */ | |
| 719 | /** | |
| 720 | * The repository we hold whose lists these count (`bind.ts`): absent for an origin's own numbers. | |
| 721 | */ | |
| 716 | 722 | of?: { ownerName: string; name: string } | undefined; |
| 717 | 723 | }): Html { |
| 718 | 724 | const issues = o.openIssues ?? null; |
| @@ -777,7 +783,9 @@ export function chartBox(chart: Chart, cells: readonly Cell[], title: string): H | ||
| 777 | 783 | return chartFrame(chart, drawChart(chart, cells, title)); |
| 778 | 784 | } |
| 779 | 785 | |
| 780 | /** The same box around a chart already drawn (`drawChart`'s own markup, from whoever read its rows). */ | |
| 786 | /** | |
| 787 | * The same box around a chart already drawn (`drawChart`'s own markup, from whoever read its rows). | |
| 788 | */ | |
| 781 | 789 | export function chartFrame(chart: Chart, drawn: string): Html { |
| 782 | 790 | return html`<div class="chart-box${chart === "table" ? " is-table" : ""}">${raw(drawn)}</div>`; |
| 783 | 791 | } |
| @@ -971,8 +979,9 @@ export interface RowOptions { | ||
| 971 | 979 | href?: string; |
| 972 | 980 | title: Html | string; |
| 973 | 981 | meta?: Html; |
| 974 | /** Facts about the row, one `dt`/`dd` pair each, in a `dl.row-facts` under the meta. With facts the row's | |
| 975 | * main column is a `<div>`, so the `dl` is valid HTML: not for a `fold` row, whose `<summary>` takes phrasing only. */ | |
| 982 | /** Facts about the row, one `dt`/`dd` pair each, in a `dl.row-facts` under the meta. With facts | |
| 983 | * the row's main column is a `<div>`, so the `dl` is valid HTML: not for a `fold` row, whose | |
| 984 | * `<summary>` takes phrasing only. */ | |
| 976 | 985 | facts?: readonly { label: string; value: Html | string }[]; |
| 977 | 986 | /** Draw `.row-meta` even when `meta` is empty, for a script to write into. */ |
| 978 | 987 | metaSlot?: boolean; |
| @@ -997,7 +1006,9 @@ export interface RowOptions { | ||
| 997 | 1006 | /** The row folds: it is the `<summary>` of a `<details>` holding `body`, |
| 998 | 1007 | * open when `open` says so. Its `lead` is the caret. */ |
| 999 | 1008 | fold?: { id: string; open: boolean; body: Html }; |
| 1000 | /** Why the list's count leaves this row out on purpose (`data-apart`, `bind.ts`): a sealed report. */ | |
| 1009 | /** | |
| 1010 | * Why the list's count leaves this row out on purpose (`data-apart`, `bind.ts`): a sealed report. | |
| 1011 | */ | |
| 1001 | 1012 | apart?: string | undefined; |
| 1002 | 1013 | /** The row is a node of an ARIA tree: the row itself is the `treeitem` (it is what takes focus, |
| 1003 | 1014 | * so it says its level and, for a branch, `aria-expanded`), its `<li>` is `role="none"`, |
| @@ -1092,7 +1103,10 @@ export function tabs(items: TabItem[], ariaLabel: string): Html { | ||
| 1092 | 1103 | /** A segmented control built from links (a GET filter is navigation). */ |
| 1093 | 1104 | export function seg( |
| 1094 | 1105 | items: { label: string; href: string; current: boolean; count?: number }[], |
| 1095 | /** These links are a list's tabs: every item a reader may open is under one (`data-rows-tabs`, `bind.ts`). */ | |
| 1106 | /** | |
| 1107 | * These links are a list's tabs: every item a reader may open is under one (`data-rows-tabs`, | |
| 1108 | * `bind.ts`). | |
| 1109 | */ | |
| 1096 | 1110 | filters = false, |
| 1097 | 1111 | ): Html { |
| 1098 | 1112 | return html`<div class="seg"${filters ? raw(" data-rows-tabs") : null}> |
| @@ -1264,12 +1278,17 @@ export interface FieldOptions { | ||
| 1264 | 1278 | labelHidden?: boolean; |
| 1265 | 1279 | /** Drawn right after the control, before the hint: a chip's Remove. */ |
| 1266 | 1280 | after?: Html; |
| 1281 | /** | |
| 1282 | * The reason, behind a mark on the same line as the control (setting_line.ts), in place of | |
| 1283 | * `hint`. | |
| 1284 | */ | |
| 1285 | why?: string | Html; | |
| 1267 | 1286 | } |
| 1268 | 1287 | |
| 1269 | 1288 | /** Label, control, hint and error, wired together with `aria-describedby`. */ |
| 1270 | 1289 | export function field(o: FieldOptions): Html { |
| 1271 | 1290 | const id = o.id ?? `f-${o.name}`; |
| 1272 | const described = [o.hint ? `${id}-hint` : "", o.error ? `${id}-err` : ""] | |
| 1291 | const described = [o.hint ? `${id}-hint` : "", o.why ? `why-${o.name}` : "", o.error ? `${id}-err` : ""] | |
| 1273 | 1292 | .filter(Boolean) |
| 1274 | 1293 | .join(" "); |
| 1275 | 1294 | const aria = html`${described !== "" ? html`aria-describedby="${described}"` : null} |
| @@ -1314,9 +1333,10 @@ ${o.value ?? ""}</textarea | ||
| 1314 | 1333 | ? html`<label for="${id}" class="sr-only">${o.label}</label>${control}` |
| 1315 | 1334 | : html`<label for="${id}">${o.label}</label> |
| 1316 | 1335 | ${control}`; |
| 1317 | return html`<div class="field" ${o.error ? raw("data-invalid") : null}> | |
| 1336 | return html`<div class="field${o.why ? " setting-line" : ""}" ${o.why ? html`data-setting="${o.name}" ` : null}${o.error ? raw("data-invalid") : null}> | |
| 1318 | 1337 | ${label} |
| 1319 | 1338 | ${o.after ?? null} |
| 1339 | ${o.why ? why(o.name, o.why) : null} | |
| 1320 | 1340 | ${o.hint ? html`<span class="hint" id="${id}-hint">${o.hint}</span>` : null} |
| 1321 | 1341 | ${o.error |
| 1322 | 1342 | ? html`<span class="error" id="${id}-err">${o.error}</span>` |
| @@ -1331,10 +1351,10 @@ export function selectField( | ||
| 1331 | 1351 | }, |
| 1332 | 1352 | ): Html { |
| 1333 | 1353 | const id = o.id ?? `f-${o.name}`; |
| 1334 | const described = [o.hint ? `${id}-hint` : "", o.error ? `${id}-err` : ""] | |
| 1354 | const described = [o.hint ? `${id}-hint` : "", o.why ? `why-${o.name}` : "", o.error ? `${id}-err` : ""] | |
| 1335 | 1355 | .filter(Boolean) |
| 1336 | 1356 | .join(" "); |
| 1337 | return html`<div class="field" ${o.error ? raw("data-invalid") : null}> | |
| 1357 | return html`<div class="field${o.why ? " setting-line" : ""}" ${o.why ? html`data-setting="${o.name}" ` : null}${o.error ? raw("data-invalid") : null}> | |
| 1338 | 1358 | <label for="${id}">${o.label}</label> |
| 1339 | 1359 | <select class="input" id="${id}" name="${o.name}" |
| 1340 | 1360 | ${described !== "" ? html`aria-describedby="${described}"` : null} |
| @@ -1350,6 +1370,7 @@ export function selectField( | ||
| 1350 | 1370 | </option>`, |
| 1351 | 1371 | )} |
| 1352 | 1372 | </select> |
| 1373 | ${o.why ? why(o.name, o.why) : null} | |
| 1353 | 1374 | ${o.hint ? html`<span class="hint" id="${id}-hint">${o.hint}</span>` : null} |
| 1354 | 1375 | ${o.error |
| 1355 | 1376 | ? html`<span class="error" id="${id}-err">${o.error}</span>` |
test/settings-lines.test.ts +48 −1
| @@ -13,6 +13,7 @@ import { join } from "node:path"; | ||
| 13 | 13 | import { createApp, type App } from "../src/app.ts"; |
| 14 | 14 | import { serve, type Servers } from "../src/http/server.ts"; |
| 15 | 15 | import { adminCookie } from "./helpers/admin.ts"; |
| 16 | import { field, selectField } from "../src/web/ui.ts"; | |
| 16 | 17 | |
| 17 | 18 | let dir = ""; |
| 18 | 19 | let app: App; |
| @@ -62,7 +63,10 @@ test("every setting key is one row inside the form that posts to /settings, reas | ||
| 62 | 63 | expect(form).not.toContain('<p class="hint"'); |
| 63 | 64 | }); |
| 64 | 65 | |
| 65 | /** The names the form posts beside `card=gates` (matched by gatesForm): on main before #10999 they were exactly these. */ | |
| 66 | /** | |
| 67 | * The names the form posts beside `card=gates` (matched by gatesForm): on main before #10999 they | |
| 68 | * were exactly these. | |
| 69 | */ | |
| 66 | 70 | const POSTED = ["defaultBranch", "protect", "requireReview", "requireChecks", "landingShown", "landing", "crewOutsidersShown", "crewOutsiders", "polishShareShown", "polishShare"]; |
| 67 | 71 | |
| 68 | 72 | const page = async (): Promise<string> => |
| @@ -103,3 +107,46 @@ function gatesForm(html: string): string { | ||
| 103 | 107 | html.match(/<form method="post" action="\/olive\/proj\/settings">\s*<input type="hidden" name="card" value="gates" \/>([\s\S]*?)<\/form>/)?.[1] ?? "" |
outdated
Confirm this test fails on the base (revert ui.ts/settings.ts, run it) and say so on the pull; the author said they could not. |
||
| 104 | 108 | ); |
| 105 | 109 | } |
| 110 | ||
| 111 | test("the app section's slug, access and preview data are lines with their reason behind a mark", async () => { | |
| 112 | const html = await ( | |
| 113 | await fetch(`${servers.url}/olive/proj/settings/app`, { headers: { cookie, accept: "text/html" } }) | |
| 114 | ).text(); | |
| 115 | for (const key of ["slug", "access", "previewData"]) { | |
| 116 | const row = html.match(new RegExp(`<div class="field setting-line"[^>]*data-setting="${key}"[^>]*>([\\s\\S]*?)</details>`))?.[1]; | |
| 117 | expect(row, key).toBeDefined(); | |
| 118 | expect(row, key).toContain(`name="${key}"`); | |
| 119 | expect(row, key).toContain(`aria-describedby="why-${key}"`); | |
| 120 | expect(row, key).toContain(`id="why-${key}"`); | |
| 121 | } | |
outdated
Also assert the old |
||
| 122 | expect(html).not.toContain('id="f-previewData-hint"'); | |
| 123 | }); | |
| 124 | ||
| 125 | test("no app setting falls back to a hint paragraph under the control", async () => { | |
| 126 | const html = await ( | |
| 127 | await fetch(`${servers.url}/olive/proj/settings/app`, { headers: { cookie, accept: "text/html" } }) | |
| 128 | ).text(); | |
| 129 | for (const key of ["slug", "access", "previewData"]) { | |
| 130 | expect(html, key).not.toContain(`id="f-${key}-hint"`); | |
| 131 | expect(html, key).not.toContain(`<span class="hint" id="f-${key}-hint"`); | |
| 132 | } | |
| 133 | }); | |
| 134 | ||
| 135 | test("a setting line with an error keeps the error after the mark, and the control is described by both", () => { | |
| 136 | const cases = [ | |
| 137 | String(field({ label: "Slug", name: "slug", value: "Bad Slug", why: "The label its hostnames are built from.", error: "Use lowercase letters, digits and single dashes." })), | |
| 138 | String(selectField({ label: "Access", name: "access", why: "Who may open it.", error: "Choose one of the options.", options: [{ value: "public", label: "Public" }] })), | |
| 139 | ]; | |
| 140 | for (const out of cases) { | |
| 141 | const name = out.includes('name="slug"') ? "slug" : "access"; | |
| 142 | expect(out, name).toMatch(new RegExp(`<div class="field setting-line" data-setting="${name}"\\s+data-invalid>`)); | |
| 143 | expect(out, name).toContain(`aria-describedby="why-${name} f-${name}-err"`); | |
| 144 | const mark = out.indexOf(`id="why-${name}"`); | |
| 145 | const err = out.indexOf(`<span class="error" id="f-${name}-err">`); | |
| 146 | expect(mark, name).toBeGreaterThan(-1); | |
| 147 | // The error comes after the mark, so `.setting-line > .error` puts it on its own row under the | |
| 148 | // control. | |
| 149 | expect(err, name).toBeGreaterThan(mark); | |
| 150 | expect(out, name).not.toContain('class="hint" id='); | |
| 151 | } | |
| 152 | }); |
new above
offline
Principle 3: 14rem for the text input is narrow for a slug on a 360px phone beside the mark; show it at 390px, and consider
flex: 1 1 14remso it fills the line.