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

Closed opened this
Closed without merging

scout/forge:scout/13000-settings-has-one-line-per-setting-the-re → main 18 commits fork 5 threads · 5 unresolved

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
4 files changed +85 −15
src/web/pages/settings.ts +3 −3
@@ -733,7 +733,7 @@ function appSettingsView(
733733 mono: true,
734734 required: true,
735735 pattern: "[a-z0-9](-?[a-z0-9])*",
736 hint:
736 why:
737737 domain === undefined
738738 ? "The label its hostnames are built from."
739739 : `Its hostnames: ${values.slug || "<slug>"}.${domain} and ${values.slug || "<slug>"}--<n>.${domain} for the preview of pull #n.`,
@@ -742,7 +742,7 @@ function appSettingsView(
742742 ${selectField({
743743 label: "Access",
744744 name: "access",
745 hint:
745 why:
746746 values.access === "public"
747747 ? `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.`
748748 : `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(
762762 ${selectField({
763763 label: "Preview data",
764764 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.",
766766 options: [
767767 {
768768 value: "copy",
src/web/style/components.ts +2
@@ -138,6 +138,8 @@ select.input {
138138 .setting-line > label:not(.check) { margin: 0; }
139139 .setting-line > select.input { width: auto; max-width: 100%; flex: 0 1 14rem; }
140140 .setting-line > .check { flex: 0 1 auto; }
141 .setting-line > input.input { width: auto; max-width: 100%; flex: 1 1 14rem; min-width: 0; }
outdated

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 14rem so it fills the line.

142 .setting-line > .error { flex-basis: 100%; }
141143 .setting-line > details.why { margin: 0; }
142144 .setting-line > details.why[open] { flex-basis: 100%; }
143145 .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";
2525 import { icon, type IconName } from "./icons.ts";
2626 import { crewFace, scene, type SceneName } from "./pixel.ts";
2727 import { Html, html, raw, when } from "./html.ts";
28 import { why } from "./setting_line.ts";
2829 import { at, countAttr, listAttr, zeroAttr } from "./bind.ts";
2930
3031 export { icon, type IconName };
@@ -185,7 +186,10 @@ export interface BtnOptions {
185186 extra?: string;
186187 /** The element's id, for a script or a fragment link that finds it. */
187188 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 */
189193 rel?: "next" | "prev";
190194 }
191195
@@ -712,7 +716,9 @@ export function repoCounts(o: {
712716 openPulls?: number | null | undefined;
713717 /** Some origins report one number for issues *and* pulls; say so. */
714718 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 */
716722 of?: { ownerName: string; name: string } | undefined;
717723 }): Html {
718724 const issues = o.openIssues ?? null;
@@ -777,7 +783,9 @@ export function chartBox(chart: Chart, cells: readonly Cell[], title: string): H
777783 return chartFrame(chart, drawChart(chart, cells, title));
778784 }
779785
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 */
781789 export function chartFrame(chart: Chart, drawn: string): Html {
782790 return html`<div class="chart-box${chart === "table" ? " is-table" : ""}">${raw(drawn)}</div>`;
783791 }
@@ -971,8 +979,9 @@ export interface RowOptions {
971979 href?: string;
972980 title: Html | string;
973981 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. */
976985 facts?: readonly { label: string; value: Html | string }[];
977986 /** Draw `.row-meta` even when `meta` is empty, for a script to write into. */
978987 metaSlot?: boolean;
@@ -997,7 +1006,9 @@ export interface RowOptions {
9971006 /** The row folds: it is the `<summary>` of a `<details>` holding `body`,
9981007 * open when `open` says so. Its `lead` is the caret. */
9991008 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 */
10011012 apart?: string | undefined;
10021013 /** The row is a node of an ARIA tree: the row itself is the `treeitem` (it is what takes focus,
10031014 * 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 {
10921103 /** A segmented control built from links (a GET filter is navigation). */
10931104 export function seg(
10941105 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 */
10961110 filters = false,
10971111 ): Html {
10981112 return html`<div class="seg"${filters ? raw(" data-rows-tabs") : null}>
@@ -1264,12 +1278,17 @@ export interface FieldOptions {
12641278 labelHidden?: boolean;
12651279 /** Drawn right after the control, before the hint: a chip's Remove. */
12661280 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;
12671286 }
12681287
12691288 /** Label, control, hint and error, wired together with `aria-describedby`. */
12701289 export function field(o: FieldOptions): Html {
12711290 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` : ""]
12731292 .filter(Boolean)
12741293 .join(" ");
12751294 const aria = html`${described !== "" ? html`aria-describedby="${described}"` : null}
@@ -1314,9 +1333,10 @@ ${o.value ?? ""}</textarea
13141333 ? html`<label for="${id}" class="sr-only">${o.label}</label>${control}`
13151334 : html`<label for="${id}">${o.label}</label>
13161335 ${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}>
13181337 ${label}
13191338 ${o.after ?? null}
1339 ${o.why ? why(o.name, o.why) : null}
13201340 ${o.hint ? html`<span class="hint" id="${id}-hint">${o.hint}</span>` : null}
13211341 ${o.error
13221342 ? html`<span class="error" id="${id}-err">${o.error}</span>`
@@ -1331,10 +1351,10 @@ export function selectField(
13311351 },
13321352 ): Html {
13331353 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` : ""]
13351355 .filter(Boolean)
13361356 .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}>
13381358 <label for="${id}">${o.label}</label>
13391359 <select class="input" id="${id}" name="${o.name}"
13401360 ${described !== "" ? html`aria-describedby="${described}"` : null}
@@ -1350,6 +1370,7 @@ export function selectField(
13501370 </option>`,
13511371 )}
13521372 </select>
1373 ${o.why ? why(o.name, o.why) : null}
13531374 ${o.hint ? html`<span class="hint" id="${id}-hint">${o.hint}</span>` : null}
13541375 ${o.error
13551376 ? 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";
1313 import { createApp, type App } from "../src/app.ts";
1414 import { serve, type Servers } from "../src/http/server.ts";
1515 import { adminCookie } from "./helpers/admin.ts";
16 import { field, selectField } from "../src/web/ui.ts";
1617
1718 let dir = "";
1819 let app: App;
@@ -62,7 +63,10 @@ test("every setting key is one row inside the form that posts to /settings, reas
6263 expect(form).not.toContain('<p class="hint"');
6364 });
6465
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 */
6670 const POSTED = ["defaultBranch", "protect", "requireReview", "requireChecks", "landingShown", "landing", "crewOutsidersShown", "crewOutsiders", "polishShareShown", "polishShare"];
6771
6872 const page = async (): Promise<string> =>
@@ -103,3 +107,46 @@ function gatesForm(html: string): string {
103107 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.

104108 );
105109 }
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 hint spans for slug and access are gone, and add a case with an error to show it renders on its own row and is in aria-describedby.

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 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs