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
scout/forge:scout/4238-the-map-page-s-counts-pillars-and-tools → main 1 commit fork
2 files
changed +80
−59
src/web/pages/map.ts +64 −51
| @@ -57,7 +57,7 @@ import { | ||
| 57 | 57 | import { liveRegionsJs } from "../client.ts"; |
| 58 | 58 | import { html, type Html } from "../html.ts"; |
| 59 | 59 | 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"; | |
| 61 | 61 | import { autonomyStatus, type AutonomyStatus } from "../../crew/autonomy.ts"; |
| 62 | 62 | import { |
| 63 | 63 | parkedTwice, |
| @@ -876,30 +876,30 @@ export function drawMap( | ||
| 876 | 876 | )} |
| 877 | 877 | ${placed.nodes.map((n) => node(base, n, g, emphasis, issueHref))} |
| 878 | 878 | </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" })} | |
| 899 | 883 | </div> |
| 900 | 884 | </div>`; |
| 901 | 885 | } |
| 902 | 886 | |
| 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 | ||
| 903 | 903 | /** The words, counted: the one quiet line under a drawing. */ |
| 904 | 904 | export function countWords(words: readonly Word[]): Record<Word, number> { |
| 905 | 905 | const out: Record<Word, number> = { |
| @@ -916,12 +916,21 @@ export function countWords(words: readonly Word[]): Record<Word, number> { | ||
| 916 | 916 | return out; |
| 917 | 917 | } |
| 918 | 918 | |
| 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 | ||
| 919 | 927 | function countsLine(counts: Record<Word, number>): Html { |
| 920 | 928 | 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 | }), | |
| 925 | 934 | )} |
| 926 | 935 | </span>`; |
| 927 | 936 | } |
| @@ -1038,14 +1047,15 @@ function pillarList(repo: Repo, rows: readonly PillarRow[]): Html { | ||
| 1038 | 1047 | r.open === 0 |
| 1039 | 1048 | ? "nothing open" |
| 1040 | 1049 | : `${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"> | |
| 1042 | 1051 | <h2>By pillar</h2> |
| 1043 | <ul> | |
| 1052 | <ul class="list setting-list"> | |
| 1044 | 1053 | ${rows.map((r) => |
| 1045 | 1054 | 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" | |
| 1049 | 1059 | >${counts(r)}: |
| 1050 | 1060 | ${(r.issues ?? []).slice(0, 8).map( |
| 1051 | 1061 | (i) => |
| @@ -1053,27 +1063,30 @@ function pillarList(repo: Repo, rows: readonly PillarRow[]): Html { | ||
| 1053 | 1063 | >#${i.number}</a |
| 1054 | 1064 | >${" "}`, |
| 1055 | 1065 | )}${(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" | |
| 1060 | 1072 | href="${r.umbrella === undefined |
| 1061 | 1073 | ? pillarHref(base, r.name) |
| 1062 | 1074 | : milestoneHref(base, r.umbrella)}" |
| 1063 | 1075 | >${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 | }), | |
| 1077 | 1090 | )} |
| 1078 | 1091 | </ul> |
| 1079 | 1092 | </section>`; |
| @@ -1242,7 +1255,7 @@ export const mapViewJs = /* js */ ` | ||
| 1242 | 1255 | var pointers = {}, drag = null; |
| 1243 | 1256 | document.addEventListener('pointerdown', function (e) { |
| 1244 | 1257 | 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; | |
| 1246 | 1259 | if (e.pointerType === 'mouse' && e.button !== 0) return; |
| 1247 | 1260 | pointers[e.pointerId] = { x: e.clientX, y: e.clientY }; |
| 1248 | 1261 | var ids = Object.keys(pointers); |
| @@ -1287,9 +1300,9 @@ export const mapViewJs = /* js */ ` | ||
| 1287 | 1300 | var canvas = canvasOf(e); |
| 1288 | 1301 | if (!canvas) return; |
| 1289 | 1302 | 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"]'); | |
| 1291 | 1304 | if (!tool) return; |
| 1292 | var what = tool.getAttribute('data-map'); | |
| 1305 | var what = tool.value; | |
| 1293 | 1306 | if (what === 'fit') setup(canvas, true); else zoom(canvas, what === 'in' ? 1.25 : 0.8); |
| 1294 | 1307 | }, true); |
| 1295 | 1308 | document.addEventListener('wheel', function (e) { |
| @@ -1301,7 +1314,7 @@ export const mapViewJs = /* js */ ` | ||
| 1301 | 1314 | }, { passive: false }); |
| 1302 | 1315 | document.addEventListener('dblclick', function (e) { |
| 1303 | 1316 | 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; | |
| 1305 | 1318 | e.preventDefault(); |
| 1306 | 1319 | var p = at(canvas, e); |
| 1307 | 1320 | 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", () => { | ||
| 345 | 345 | // The edge from a done issue recedes with it. |
| 346 | 346 | expect(page).toContain('class="map-edge map-edge-done"'); |
| 347 | 347 | // 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>'); | |
| 354 | 354 | // The lists beside it still read the graph; the critical path is the |
| 355 | 355 | // accent on the canvas alone, and spend and flow live on their boards. |
| 356 | 356 | expect(page).toContain("Ready now"); |
| @@ -372,7 +372,15 @@ describe("the map, per app and across the forge", () => { | ||
| 372 | 372 | expect(page).toMatch( |
| 373 | 373 | /<div[^>]*class="map-canvas"[^>]*id="map-canvas"[^>]*data-w="\d+"[^>]*data-h="\d+"/, |
| 374 | 374 | ); |
| 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"'); | |
| 376 | 384 | expect(page).toContain("new EventSource('/events')"); |
| 377 | 385 | expect(page).toContain("forge:swapped"); |
| 378 | 386 | // 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", () => { | ||
| 410 | 418 | // dormant has nothing ready and nobody working: it folds to its header. |
| 411 | 419 | expect(lane("lane-alice-dormant")).toContain('data-idle="1"'); |
| 412 | 420 | 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>'); | |
| 414 | 422 | // The lanes are §5's list and rows, not a page-local component (#3651). |
| 415 | 423 | expect(page).toMatch(/id="lanes"[^>]*>\s*<div\s+class="card"[^>]*>\s*<ul class="list">/); |
| 416 | 424 | expect(page).toMatch(/<details[^>]*id="lane-alice-engine"[^>]*>\s*<summary\s+class="row"/); |
new above
offline