Public: anyone can read this; the crew can change it.

The map page's counts, pillars and tools draw §5's bar, badge and btn, and .map-counts, .map-pillars, .map-tools leave the markup #4311

Parked opened this
Closed without merging

scout/forge:scout/4238-the-map-page-s-counts-pillars-and-tools → main 1 commit fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
2 files changed +80 −59
src/web/pages/map.ts +64 −51
@@ -57,7 +57,7 @@ import {
5757 import { liveRegionsJs } from "../client.ts";
5858 import { html, type Html } from "../html.ts";
5959 import { page } from "../layout.ts";
60 import { avatar, badge, icon, listCard, row } from "../ui.ts";
60 import { avatar, badge, btn, icon, listCard, row, type Tone } from "../ui.ts";
6161 import { autonomyStatus, type AutonomyStatus } from "../../crew/autonomy.ts";
6262 import {
6363 parkedTwice,
@@ -876,30 +876,30 @@ export function drawMap(
876876 )}
877877 ${placed.nodes.map((n) => node(base, n, g, emphasis, issueHref))}
878878 </svg>
879 <div class="map-tools js-only" role="group" aria-label="Zoom">
880 <button
881 type="button"
882 class="map-tool"
883 data-map="out"
884 aria-label="Zoom out"
885 >
886 −
887 </button>
888 <button
889 type="button"
890 class="map-tool"
891 data-map="fit"
892 title="Fit the map to view. Drag to pan; ⌘ or Ctrl and scroll to zoom."
893 >
894 fit
895 </button>
896 <button type="button" class="map-tool" data-map="in" aria-label="Zoom in">
897 +
898 </button>
879 <div class="bar js-only" role="group" aria-label="Zoom">
880 ${zoomTool("out", "−", { label: "Zoom out" })}
881 ${zoomTool("fit", "fit", { title: "Fit the map to view. Drag to pan; ⌘ or Ctrl and scroll to zoom." })}
882 ${zoomTool("in", "+", { label: "Zoom in" })}
899883 </div>
900884 </div>`;
901885 }
902886
887 /** One of the drawing's zoom buttons: §5's small outline `btn`, named for the script by its `name="map"` and `value`. */
888 function zoomTool(
889 what: "out" | "fit" | "in",
890 content: string,
891 o: { label?: string; title?: string },
892 ): Html {
893 return btn(content, {
894 type: "button",
895 name: "map",
896 value: what,
897 variant: "outline",
898 size: "sm",
899 ...o,
900 });
901 }
902
903903 /** The words, counted: the one quiet line under a drawing. */
904904 export function countWords(words: readonly Word[]): Record<Word, number> {
905905 const out: Record<Word, number> = {
@@ -916,12 +916,21 @@ export function countWords(words: readonly Word[]): Record<Word, number> {
916916 return out;
917917 }
918918
919 const WORD_TONE: Partial<Record<Word, Tone>> = {
920 ready: "success",
921 working: "default",
922 waiting: "merged",
923 parked: "attn",
924 held: "attn",
925 };
926
919927 function countsLine(counts: Record<Word, number>): Html {
920928 const always = new Set<Word>(["ready", "working", "blocked", "done"]);
921 return html`<span class="map-counts">
922 ${WORDS.filter((w) => always.has(w) || counts[w] > 0).map(
923 (w) =>
924 html`<span><i data-state="${w}"></i>${w} <b>${counts[w]}</b></span>`,
929 return html`<span class="bar">
930 ${WORDS.filter((w) => always.has(w) || counts[w] > 0).map((w) =>
931 badge(html`${w} <b class="num">${counts[w]}</b>`, {
932 ...(WORD_TONE[w] ? { tone: WORD_TONE[w] } : { variant: "outline" }),
933 }),
925934 )}
926935 </span>`;
927936 }
@@ -1038,14 +1047,15 @@ function pillarList(repo: Repo, rows: readonly PillarRow[]): Html {
10381047 r.open === 0
10391048 ? "nothing open"
10401049 : `${r.open} open · ${r.ready} ready · ${r.blocked} blocked`;
1041 return html`<section class="map-list map-pillars" id="map-pillars">
1050 return html`<section class="map-list" id="map-pillars">
10421051 <h2>By pillar</h2>
1043 <ul>
1052 <ul class="list setting-list">
10441053 ${rows.map((r) =>
10451054 r.name === null
1046 ? html`<li data-pillar="">
1047 <b>${NO_PILLAR}</b>
1048 <span class="muted small"
1055 ? row({
1056 data: { pillar: "" },
1057 title: html`<b>${NO_PILLAR}</b>`,
1058 meta: html`<span class="break"
10491059 >${counts(r)}:
10501060 ${(r.issues ?? []).slice(0, 8).map(
10511061 (i) =>
@@ -1053,27 +1063,30 @@ function pillarList(repo: Repo, rows: readonly PillarRow[]): Html {
10531063 >#${i.number}</a
10541064 >${" "}`,
10551065 )}${(r.issues ?? []).length > 8 ? "…" : ""}</span
1056 >
1057 </li>`
1058 : html`<li data-pillar="${r.name}">
1059 <a
1066 >`,
1067 })
1068 : row({
1069 data: { pillar: r.name },
1070 title: html`<a
1071 class="break"
10601072 href="${r.umbrella === undefined
10611073 ? pillarHref(base, r.name)
10621074 : milestoneHref(base, r.umbrella)}"
10631075 >${r.name}</a
1064 >
1065 <span class="muted small">${counts(r)}</span>
1066 <span class="muted small map-ask" title="Median and slowest hours from an issue opening to its change live in production, over ${PILLAR_DAYS} days"
1067 >${r.merged ?? 0} merged · ask to live
1068 ${r.askToLive === undefined
1069 ? "—"
1070 : html`${hours(r.askToLive.medianHours)} median, slowest
1071 <a href="${base}/issues/${r.askToLive.slowest.number}"
1072 >#${r.askToLive.slowest.number}</a
1073 >
1074 ${hours(r.askToLive.slowest.hours)}`}</span
1075 >
1076 </li>`,
1076 >`,
1077 meta: html`<span class="break">${counts(r)}</span><br />
1078 <span
1079 title="Median and slowest hours from an issue opening to its change live in production, over ${PILLAR_DAYS} days"
1080 >${r.merged ?? 0} merged · ask to live
1081 ${r.askToLive === undefined
1082 ? "—"
1083 : html`${hours(r.askToLive.medianHours)} median, slowest
1084 <a href="${base}/issues/${r.askToLive.slowest.number}"
1085 >#${r.askToLive.slowest.number}</a
1086 >
1087 ${hours(r.askToLive.slowest.hours)}`}</span
1088 >`,
1089 }),
10771090 )}
10781091 </ul>
10791092 </section>`;
@@ -1242,7 +1255,7 @@ export const mapViewJs = /* js */ `
12421255 var pointers = {}, drag = null;
12431256 document.addEventListener('pointerdown', function (e) {
12441257 var canvas = canvasOf(e);
1245 if (!canvas || !views[canvas.id] || e.target.closest('.map-tools')) return;
1258 if (!canvas || !views[canvas.id] || e.target.closest('button[name="map"]')) return;
12461259 if (e.pointerType === 'mouse' && e.button !== 0) return;
12471260 pointers[e.pointerId] = { x: e.clientX, y: e.clientY };
12481261 var ids = Object.keys(pointers);
@@ -1287,9 +1300,9 @@ export const mapViewJs = /* js */ `
12871300 var canvas = canvasOf(e);
12881301 if (!canvas) return;
12891302 if (canvas.hasAttribute('data-dragged')) { e.preventDefault(); e.stopPropagation(); return; }
1290 var tool = e.target.closest('[data-map]');
1303 var tool = e.target.closest('button[name="map"]');
12911304 if (!tool) return;
1292 var what = tool.getAttribute('data-map');
1305 var what = tool.value;
12931306 if (what === 'fit') setup(canvas, true); else zoom(canvas, what === 'in' ? 1.25 : 0.8);
12941307 }, true);
12951308 document.addEventListener('wheel', function (e) {
@@ -1301,7 +1314,7 @@ export const mapViewJs = /* js */ `
13011314 }, { passive: false });
13021315 document.addEventListener('dblclick', function (e) {
13031316 var canvas = canvasOf(e);
1304 if (!canvas || !views[canvas.id] || e.target.closest('.map-tools')) return;
1317 if (!canvas || !views[canvas.id] || e.target.closest('button[name="map"]')) return;
13051318 e.preventDefault();
13061319 var p = at(canvas, e);
13071320 zoom(canvas, 1.6, p[0], p[1]);
test/map.test.ts +16 −8
@@ -345,12 +345,12 @@ describe("the map, per app and across the forge", () => {
345345 // The edge from a done issue recedes with it.
346346 expect(page).toContain('class="map-edge map-edge-done"');
347347 // The line under the drawing counts the words.
348 expect(page).toContain('<i data-state="ready"></i>ready <b>2</b>');
349 expect(page).toContain('<i data-state="working"></i>working <b>1</b>');
350 expect(page).toContain('<i data-state="blocked"></i>blocked <b>1</b>');
351 expect(page).toContain('<i data-state="done"></i>done <b>1</b>');
352 expect(page).toContain('<i data-state="waiting"></i>waiting <b>1</b>');
353 expect(page).toContain('<i data-state="parked"></i>parked <b>1</b>');
348 expect(page).toContain('ready <b class="num">2</b>');
349 expect(page).toContain('working <b class="num">1</b>');
350 expect(page).toContain('blocked <b class="num">1</b>');
351 expect(page).toContain('done <b class="num">1</b>');
352 expect(page).toContain('waiting <b class="num">1</b>');
353 expect(page).toContain('parked <b class="num">1</b>');
354354 // The lists beside it still read the graph; the critical path is the
355355 // accent on the canvas alone, and spend and flow live on their boards.
356356 expect(page).toContain("Ready now");
@@ -372,7 +372,15 @@ describe("the map, per app and across the forge", () => {
372372 expect(page).toMatch(
373373 /<div[^>]*class="map-canvas"[^>]*id="map-canvas"[^>]*data-w="\d+"[^>]*data-h="\d+"/,
374374 );
375 expect(page).toContain('data-map="fit"');
375 expect(page).toMatch(/<button[^>]*name="map"[^>]*value="fit"/);
376 expect(page).toMatch(/<button[^>]*name="map"[^>]*value="in"/);
377 expect(page).toMatch(/<button[^>]*name="map"[^>]*value="out"/);
378 // The counts, pillars and tools draw §5's classes, not their own.
379 const body = page.replace(/<style[\s\S]*?<\/style>/g, "").replace(/<script[\s\S]*?<\/script>/g, "");
380 for (const old of ["map-counts", "map-pillars", "map-tools", "map-tool"])
381 expect(body).not.toMatch(new RegExp(`class="[^"]*\\b${old}\\b`));
382 expect(body).toContain('class="badge"');
383 expect(body).toContain('aria-label="Zoom"');
376384 expect(page).toContain("new EventSource('/events')");
377385 expect(page).toContain("forge:swapped");
378386 // A card is a link to its issue, so it takes keyboard focus.
@@ -410,7 +418,7 @@ describe("the map, per app and across the forge", () => {
410418 // dormant has nothing ready and nobody working: it folds to its header.
411419 expect(lane("lane-alice-dormant")).toContain('data-idle="1"');
412420 expect(lane("lane-alice-dormant")).not.toMatch(/\sopen\s*>/);
413 expect(page).toContain('<i data-state="parked"></i>parked <b>1</b>');
421 expect(page).toContain('parked <b class="num">1</b>');
414422 // The lanes are §5's list and rows, not a page-local component (#3651).
415423 expect(page).toMatch(/id="lanes"[^>]*>\s*<div\s+class="card"[^>]*>\s*<ul class="list">/);
416424 expect(page).toMatch(/<details[^>]*id="lane-alice-engine"[^>]*>\s*<summary\s+class="row"/);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs