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

Merged opened this

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

Merged

mason/forge:mason/13370-small-settings-app-shows-slug-access-and → main 3 commits fork

  • Merged. mason/13370-small-settings-app-shows-slug-access-and was merged into main as 173cb7c.

Review

Sign in to review this change.
4 files changed +79 −13
src/web/pages/settings.ts +3 −3
@@ -758,7 +758,7 @@ function appSettingsView(
758758 mono: true,
759759 required: true,
760760 pattern: "[a-z0-9](-?[a-z0-9])*",
761 hint:
761 why:
762762 domain === undefined
763763 ? "The label its hostnames are built from."
764764 : `Its hostnames: ${values.slug || "<slug>"}.${domain} and ${values.slug || "<slug>"}--<n>.${domain} for the preview of pull #n.`,
@@ -767,7 +767,7 @@ function appSettingsView(
767767 ${selectField({
768768 label: "Access",
769769 name: "access",
770 hint:
770 why:
771771 values.access === "public"
772772 ? `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.`
773773 : `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(
787787 ${selectField({
788788 label: "Preview data",
789789 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.",
791791 options: [
792792 {
793793 value: "copy",
src/web/style/components.ts +3
@@ -137,6 +137,9 @@ select.input {
137137 .setting-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
138138 .setting-line > label:not(.check) { margin: 0; }
139139 .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; }
140143 .setting-line > .check { flex: 0 1 auto; }
141144 .setting-line > details.why { margin: 0; }
142145 .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";
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 };
@@ -1300,14 +1301,36 @@ export interface FieldOptions {
13001301 labelHidden?: boolean;
13011302 /** Drawn right after the control, before the hint: a chip's Remove. */
13021303 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>`;
13031328 }
13041329
13051330 /** Label, control, hint and error, wired together with `aria-describedby`. */
13061331 export function field(o: FieldOptions): Html {
13071332 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);
13111334 const aria = html`${described !== "" ? html`aria-describedby="${described}"` : null}
13121335 ${o.error ? raw('aria-invalid="true"') : null}
13131336 ${o.disabled ? raw("disabled") : null}`;
@@ -1350,6 +1373,7 @@ ${o.value ?? ""}</textarea
13501373 ? html`<label for="${id}" class="sr-only">${o.label}</label>${control}`
13511374 : html`<label for="${id}">${o.label}</label>
13521375 ${control}`;
1376 if (o.why !== undefined) return settingLineField(o, id, label);
13531377 return html`<div class="field" ${o.error ? raw("data-invalid") : null}>
13541378 ${label}
13551379 ${o.after ?? null}
@@ -1367,11 +1391,8 @@ export function selectField(
13671391 },
13681392 ): Html {
13691393 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>
13751396 <select class="input" id="${id}" name="${o.name}"
13761397 ${described !== "" ? html`aria-describedby="${described}"` : null}
13771398 ${o.error ? raw('aria-invalid="true"') : null}
@@ -1385,7 +1406,10 @@ export function selectField(
13851406 ${opt.label}
13861407 </option>`,
13871408 )}
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}
13891413 ${o.hint ? html`<span class="hint" id="${id}-hint">${o.hint}</span>` : null}
13901414 ${o.error
13911415 ? 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
6262 expect(form).not.toContain('<p class="hint"');
6363 });
6464
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 */
6669 const POSTED = ["defaultBranch", "protect", "requireReview", "requireChecks", "landingShown", "landing", "crewOutsidersShown", "crewOutsiders", "crewHereShown", "crewHere", "polishShareShown", "polishShare"];
6770
6871 const page = async (): Promise<string> =>
@@ -105,3 +108,39 @@ function gatesForm(html: string): string {
105108 html.match(/<form method="post" action="\/olive\/proj\/settings">\s*<input type="hidden" name="card" value="gates" \/>([\s\S]*?)<\/form>/)?.[1] ?? ""
106109 );
107110 }
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 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs