Public: anyone can read this; the crew can change it.
small: /settings/app shows Slug, Access and Preview data as one line each, with the reason behind a Why mark, seen on a live preview #13371
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/13370-small-settings-app-shows-slug-access-and → main 3 commits fork
4 files
changed +79
−13
src/web/pages/settings.ts +3 −3
| @@ -758,7 +758,7 @@ function appSettingsView( | ||
| 758 | 758 | mono: true, |
| 759 | 759 | required: true, |
| 760 | 760 | pattern: "[a-z0-9](-?[a-z0-9])*", |
| 761 | hint: | |
| 761 | why: | |
| 762 | 762 | domain === undefined |
| 763 | 763 | ? "The label its hostnames are built from." |
| 764 | 764 | : `Its hostnames: ${values.slug || "<slug>"}.${domain} and ${values.slug || "<slug>"}--<n>.${domain} for the preview of pull .`, |
| @@ -767,7 +767,7 @@ function appSettingsView( | ||
| 767 | 767 | ${selectField({ |
| 768 | 768 | label: "Access", |
| 769 | 769 | name: "access", |
| 770 | hint: | |
| 770 | why: | |
| 771 | 771 | values.access === "public" |
| 772 | 772 | ? `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.` |
| 773 | 773 | : `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.`, |
| @@ -787,7 +787,7 @@ function appSettingsView( | ||
| 787 | 787 | ${selectField({ |
| 788 | 788 | label: "Preview data", |
| 789 | 789 | name: "previewData", |
| 790 | hint: "What a new preview's data directory starts as. A copy is never a window: nothing a preview writes reaches production.", | |
| 790 | why: "What a new preview's data directory starts as. A copy is never a window: nothing a preview writes reaches production.", | |
| 791 | 791 | options: [ |
| 792 | 792 | { |
| 793 | 793 | value: "copy", |
src/web/style/components.ts +3
| @@ -137,6 +137,9 @@ select.input { | ||
| 137 | 137 | .setting-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; } |
| 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 | /* A text input on the line takes the room left, and may shrink below its content. */ | |
| 141 | .setting-line > input.input { flex: 1 1 14rem; min-width: 0; } | |
| 142 | .setting-line > .error { flex-basis: 100%; margin: 0; } | |
| 140 | 143 | .setting-line > .check { flex: 0 1 auto; } |
| 141 | 144 | .setting-line > details.why { margin: 0; } |
| 142 | 145 | .setting-line > details.why[open] { flex-basis: 100%; } |
src/web/ui.ts +33 −9
| @@ -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 }; |
| @@ -1300,14 +1301,36 @@ export interface FieldOptions { | ||
| 1300 | 1301 | labelHidden?: boolean; |
| 1301 | 1302 | /** Drawn right after the control, before the hint: a chip's Remove. */ |
| 1302 | 1303 | after?: Html; |
| 1304 | /** | |
| 1305 | * The reason behind the setting. Given, the field is one `.setting-line`: label, control and | |
| 1306 | * the `why()` mark on one row, the error on its own row after; `hint` is not drawn then. | |
| 1307 | */ | |
| 1308 | why?: string | Html; | |
| 1309 | } | |
| 1310 | ||
| 1311 | /** What the control's `aria-describedby` names: the reason's mark or the hint, then the error. */ | |
| 1312 | function describedBy(o: FieldOptions, id: string): string { | |
| 1313 | return [o.why !== undefined ? `why-${o.name}` : o.hint ? `${id}-hint` : "", o.error ? `${id}-err` : ""] | |
| 1314 | .filter(Boolean) | |
| 1315 | .join(" "); | |
| 1316 | } | |
| 1317 | ||
| 1318 | /** | |
| 1319 | * A field as one `.setting-line`: label, control and the why mark; an error on its own row after. | |
| 1320 | */ | |
| 1321 | function settingLineField(o: FieldOptions, id: string, label: Html): Html { | |
| 1322 | return html`<div class="field setting-line" data-setting="${o.name}" ${o.error ? raw("data-invalid") : null}> | |
| 1323 | ${label} | |
| 1324 | ${o.after ?? null} | |
| 1325 | ${why(o.name, o.why ?? "")} | |
| 1326 | ${o.error ? html`<span class="error" id="${id}-err">${o.error}</span>` : null} | |
| 1327 | </div>`; | |
| 1303 | 1328 | } |
| 1304 | 1329 | |
| 1305 | 1330 | /** Label, control, hint and error, wired together with `aria-describedby`. */ |
| 1306 | 1331 | export function field(o: FieldOptions): Html { |
| 1307 | 1332 | const id = o.id ?? `f-${o.name}`; |
| 1308 | const described = [o.hint ? `${id}-hint` : "", o.error ? `${id}-err` : ""] | |
| 1309 | .filter(Boolean) | |
| 1310 | .join(" "); | |
| 1333 | const described = describedBy(o, id); | |
| 1311 | 1334 | const aria = html`${described !== "" ? html`aria-describedby="${described}"` : null} |
| 1312 | 1335 | ${o.error ? raw('aria-invalid="true"') : null} |
| 1313 | 1336 | ${o.disabled ? raw("disabled") : null}`; |
| @@ -1350,6 +1373,7 @@ ${o.value ?? ""}</textarea | ||
| 1350 | 1373 | ? html`<label for="${id}" class="sr-only">${o.label}</label>${control}` |
| 1351 | 1374 | : html`<label for="${id}">${o.label}</label> |
| 1352 | 1375 | ${control}`; |
| 1376 | if (o.why !== undefined) return settingLineField(o, id, label); | |
| 1353 | 1377 | return html`<div class="field" ${o.error ? raw("data-invalid") : null}> |
| 1354 | 1378 | ${label} |
| 1355 | 1379 | ${o.after ?? null} |
| @@ -1367,11 +1391,8 @@ export function selectField( | ||
| 1367 | 1391 | }, |
| 1368 | 1392 | ): Html { |
| 1369 | 1393 | const id = o.id ?? `f-${o.name}`; |
| 1370 | const described = [o.hint ? `${id}-hint` : "", o.error ? `${id}-err` : ""] | |
| 1371 | .filter(Boolean) | |
| 1372 | .join(" "); | |
| 1373 | return html`<div class="field" ${o.error ? raw("data-invalid") : null}> | |
| 1374 | <label for="${id}">${o.label}</label> | |
| 1394 | const described = describedBy(o, id); | |
| 1395 | const label = html`<label for="${id}">${o.label}</label> | |
| 1375 | 1396 | <select class="input" id="${id}" name="${o.name}" |
| 1376 | 1397 | ${described !== "" ? html`aria-describedby="${described}"` : null} |
| 1377 | 1398 | ${o.error ? raw('aria-invalid="true"') : null} |
| @@ -1385,7 +1406,10 @@ export function selectField( | ||
| 1385 | 1406 | ${opt.label} |
| 1386 | 1407 | </option>`, |
| 1387 | 1408 | )} |
| 1388 | </select> | |
| 1409 | </select>`; | |
| 1410 | if (o.why !== undefined) return settingLineField(o, id, label); | |
| 1411 | return html`<div class="field" ${o.error ? raw("data-invalid") : null}> | |
| 1412 | ${label} | |
| 1389 | 1413 | ${o.hint ? html`<span class="hint" id="${id}-hint">${o.hint}</span>` : null} |
| 1390 | 1414 | ${o.error |
| 1391 | 1415 | ? html`<span class="error" id="${id}-err">${o.error}</span>` |
test/settings-lines.test.ts +40 −1
| @@ -62,7 +62,10 @@ test("every setting key is one row inside the form that posts to /settings, reas | ||
| 62 | 62 | expect(form).not.toContain('<p class="hint"'); |
| 63 | 63 | }); |
| 64 | 64 | |
| 65 | /** The names the form posts beside `card=gates` (matched by gatesForm): on main before #10999 they were exactly these. */ | |
| 65 | /** | |
| 66 | * The names the form posts beside `card=gates` (matched by gatesForm): on main before #10999 they | |
| 67 | * were exactly these. | |
| 68 | */ | |
| 66 | 69 | const POSTED = ["defaultBranch", "protect", "requireReview", "requireChecks", "landingShown", "landing", "crewOutsidersShown", "crewOutsiders", "crewHereShown", "crewHere", "polishShareShown", "polishShare"]; |
| 67 | 70 | |
| 68 | 71 | const page = async (): Promise<string> => |
| @@ -105,3 +108,39 @@ function gatesForm(html: string): string { | ||
| 105 | 108 | html.match(/<form method="post" action="\/olive\/proj\/settings">\s*<input type="hidden" name="card" value="gates" \/>([\s\S]*?)<\/form>/)?.[1] ?? "" |
| 106 | 109 | ); |
| 107 | 110 | } |
| 111 | ||
| 112 | // #13370: Settings › App — Slug, Access and Preview data are one line each, reason behind the mark. | |
| 113 | test("Settings › App shows Slug, Access and Preview data as one setting-line each, no hint span", async () => { | |
| 114 | await fetch(`${servers.url}/olive/proj/settings/app`, { | |
| 115 | method: "POST", | |
| 116 | headers: { cookie, origin: servers.url }, | |
| 117 | body: new URLSearchParams({ slug: "proj", access: "private", previewData: "copy" }), | |
| 118 | redirect: "manual", | |
| 119 | }); | |
| 120 | const html = await (await fetch(`${servers.url}/olive/proj/settings/app`, { headers: { cookie, accept: "text/html" } })).text(); | |
| 121 | for (const name of ["slug", "access", "previewData"]) { | |
| 122 | const row = html.match(new RegExp(`<div class="field setting-line" data-setting="${name}"[^>]*>([\\s\\S]*?)</details>`))?.[1]; | |
| 123 | expect(row, name).toBeDefined(); | |
| 124 | expect(row, name).toContain(`name="${name}"`); | |
| 125 | expect(row, name).toContain(`aria-describedby="why-${name}"`); | |
| 126 | expect(row, name).toContain(`id="why-${name}"`); | |
| 127 | expect(html).not.toContain(`id="f-${name}-hint"`); | |
| 128 | } | |
| 129 | expect(html).toContain("The label its hostnames are built from."); | |
| 130 | }); | |
| 131 | ||
| 132 | test("field without why keeps its hint markup; with why an error is its own row and described", async () => { | |
| 133 | const { field, selectField } = await import("../src/web/ui.ts"); | |
| 134 | const plain = String(field({ label: "L", name: "n", hint: "h" })); | |
| 135 | expect(plain).toContain('<span class="hint" id="f-n-hint">h</span>'); | |
| 136 | expect(plain).not.toContain("setting-line"); | |
| 137 | expect(String(selectField({ label: "L", name: "n", hint: "h", options: [] }))).toContain('id="f-n-hint"'); | |
| 138 | for (const out of [ | |
| 139 | String(field({ label: "L", name: "n", why: "r", error: "bad" })), | |
| 140 | String(selectField({ label: "L", name: "n", why: "r", error: "bad", options: [] })), | |
| 141 | ]) { | |
| 142 | expect(out).toContain('aria-describedby="why-n f-n-err"'); | |
| 143 | expect(out.indexOf('id="why-n"')).toBeLessThan(out.indexOf('<span class="error" id="f-n-err">')); | |
| 144 | expect(out).not.toContain('class="hint" id'); | |
| 145 | } | |
| 146 | }); |
new above
offline