@popcorn245/cornfield 0.55.0 → 0.57.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/core/contrast.js +12 -1
  2. package/core/schema.js +6 -0
  3. package/core/strings.js +1 -2
  4. package/explorer/css/account.css +1 -1
  5. package/explorer/css/changes.css +1 -1
  6. package/explorer/css/dialogs.css +1 -1
  7. package/explorer/css/node-panel.css +1 -1
  8. package/explorer/css/page.css +0 -8
  9. package/explorer/css/sheets.css +1 -1
  10. package/explorer/css/work.css +9 -30
  11. package/explorer/deep-link.js +11 -24
  12. package/explorer/engine/hint.js +2 -2
  13. package/explorer/engine/keyboard.js +1 -1
  14. package/explorer/engine/layers.js +4 -2
  15. package/explorer/engine/map-rect.js +2 -2
  16. package/explorer/engine/map-style.js +4 -1
  17. package/explorer/engine/proposal.js +3 -3
  18. package/explorer/engine/sheets.js +3 -3
  19. package/explorer/focus-room.js +1 -1
  20. package/explorer/forge-panel-model.js +2 -36
  21. package/explorer/forge-panel.js +4 -9
  22. package/explorer/index.html +2 -11
  23. package/explorer/instance-state.js +0 -6
  24. package/explorer/instance.js +15 -9
  25. package/explorer/page-pieces.js +1 -1
  26. package/explorer/page.js +5 -4
  27. package/explorer/pieces/decision.js +3 -3
  28. package/explorer/pieces/layers.js +1 -1
  29. package/explorer/pieces/node-panel.js +38 -14
  30. package/explorer/pieces/proposal.js +6 -6
  31. package/explorer/pieces/review.js +2 -2
  32. package/explorer/pieces/work-agent.js +3 -2
  33. package/explorer/pieces/work-common.js +14 -15
  34. package/explorer/pieces/work-confirm.js +11 -10
  35. package/explorer/pieces/work-data.js +24 -31
  36. package/explorer/pieces/work-deploys.js +42 -41
  37. package/explorer/pieces/work-issues.js +32 -29
  38. package/explorer/pieces/work-list.js +406 -0
  39. package/explorer/pieces/work-markup.js +9 -14
  40. package/explorer/pieces/work-notes.js +0 -1
  41. package/explorer/pieces/work-paint.js +74 -62
  42. package/explorer/pieces/work-prs.js +25 -66
  43. package/explorer/pieces/work-runs.js +47 -57
  44. package/explorer/pieces/work-specs.js +19 -2
  45. package/explorer/pieces/work-threads.js +28 -48
  46. package/explorer/pieces/work.js +38 -40
  47. package/explorer/proposal-model.js +6 -6
  48. package/explorer/proposal.js +1 -1
  49. package/explorer/runs-view.js +10 -18
  50. package/explorer/scene.js +1 -3
  51. package/explorer/sheets.js +1 -1
  52. package/explorer/tokens.css +6 -2
  53. package/explorer/waiting-view.js +3 -3
  54. package/explorer/work-badge-model.js +161 -0
  55. package/explorer/work-badges.js +143 -0
  56. package/explorer/work-model.js +80 -39
  57. package/explorer/work-view.css +11 -4
  58. package/explorer/work-view.js +193 -68
  59. package/package.json +1 -1
  60. package/explorer/pieces/work-events.js +0 -285
@@ -5,17 +5,22 @@
5
5
  * (server/work-graph.js). Page code, as house.js is for the House view: it reads `location` and listens on `document`.
6
6
  *
7
7
  * initWorkView({ offered }) once, after the config: the Work button of the view switch (shown when the config names a forge), the toggle, the clicks
8
- * openWork({ select }) opens the view (the camera fits), asks the server for the work graph (once; again on Refresh and on the poll the Work
9
- * panel makes), and selects a node of it when `select` names one; closeWork() goes back to the map
10
- * followWorkAddress() `?view=work`, `?pr=`, `?issue=`, `?run=`, `?thread=` and `?spec=` (work-model.js `workAddress`)
8
+ * openWork({ select }) opens the view (the camera fits), asks the server for the work graph (once; again on Refresh and every minute while it is open),
9
+ * and selects a node of it when `select` names one; closeWork() goes back to the map
10
+ * followWorkAddress() `?view=work`, `?pr=`, `?issue=`, `?run=`, `?thread=` and `?spec=` (work-model.js `workAddress`): the node, or for work older than the graph's
11
+ * 14 days the Work list and the node panel (pieces/work-list.js `showRef`)
11
12
  *
12
- * What it puts on the page: the view switch's Work button, with "waiting on you" as its badge (the number the Work panel's button used to say, in the same
13
- * words), the toggle at the top left of the stage ("All work" and "Waiting on you"), the lanes' titles in screen space (the map draws the lanes' panels), the words
13
+ * What it puts on the page: the view switch's Work button, with "waiting on you" as its badge, the toggles at the top left of the stage ("All work", "Waiting on you" and
14
+ * **List**, which opens the Work list (pieces/work-list.js) where the side panel sat), the lanes' titles in screen space (the map draws the lanes' panels), the words
14
15
  * and the empty lanes shown at once while the first answer is on its way (the page stays usable: the views, the Layers menu, search), "Updating…" while a refresh
15
16
  * is (the last answer stays on the map, and a refresh that fails keeps it and says so), the map's own card when the answer is refused (signed out, not a maintainer,
16
17
  * offline: pieces/status.js), and a quiet line naming what the server could not read (`problems`). It answers the node panel's `work:panel` ask with what a node says in
17
- * the Work view, and holds the keys of the view: N and P step through the lanes, an arrow goes to the nearest node that way. Every request goes through `credentialed`;
18
+ * the Work view (the Work piece draws the actions into it), the Work list's `work:pick` ask by selecting that row's node, and holds the keys of the view: N and P step through
19
+ * the lanes, an arrow goes to the nearest node that way. Every request goes through `credentialed`;
18
20
  * every word that comes from the forge is escaped or set as text, every link goes through `safeUrl` (work-model.js).
21
+ *
22
+ * The **Work layer** of the Map view (spec 0012 D4, work-badge-model.js and work-badges.js) shares this file's one read of the graph: turning the layer on asks for it only when the
23
+ * Work view has not read it, shows its loading state in the layer's row, and rides the same once-a-minute poll while it is on. Off (the default) nothing here asks for anything.
19
24
  */
20
25
 
21
26
  import { state, pageInstance } from './state.js';
@@ -24,21 +29,23 @@ import { closeDrawer } from './panels.js';
24
29
  import { announce } from './engine/keyboard.js';
25
30
  import { credentialed } from './engine/connection.js';
26
31
  import { selectNode } from './engine/selection.js';
27
- import { closeProposal } from './engine/proposal.js';
32
+ import { closeProposal, openProposal } from './engine/proposal.js';
33
+ import { themed as onGround } from './theme-model.js';
34
+ import { WORK_BADGE_LAYER, badgeIndex, badgeRowOf, badgeWords, openWorkHtml } from './work-badge-model.js';
35
+ import { createWorkBadges } from './work-badges.js';
28
36
  import { signInUrl } from './engine/source.js';
29
- import { mapStyleOf, workToken } from './engine/map-style.js';
37
+ import { mapStyleOf, workToken, workEdgeToken } from './engine/map-style.js';
30
38
  import { t } from './engine/strings.js';
31
39
  import { mount as mountStatus } from './pieces/status.js';
32
40
  import { fitGraphToViewport, fitPadding, onPaint, render } from './render.js';
33
41
  import { isPhone } from './sheets.js';
34
- import { WORK_KINDS, WORK_THEMES } from '../core/schema.js';
42
+ import { WORK_KINDS, WORK_THEMES, WORK_EDGES } from '../core/schema.js';
35
43
  import { workButtonName } from './waiting-model.js';
36
44
  import { stepFrom } from './keyboard-model.js';
37
- import { checksWords, pullUrl } from './forge-panel-model.js';
38
45
  import { RUNS_POLL_MS } from './pieces/work-common.js';
39
- import { openWorkAt, openRunLink, openIssueLink } from './forge-panel.js';
46
+ import { showWorkRef, openForge, closeForge } from './forge-panel.js';
40
47
  import {
41
- CODE_LAYER, DRAFT_LAYER, KIND_WORDS, applyFilters, arrowTarget, landingWords, applyWorkLayout, codePanelHtml, layerRowsOf, newWorkState, nodeForAddress, openedWords, panelOf, setWorkGraph, showWork, touchedBy, workAddress, workPanelHtml,
48
+ CODE_LAYER, DRAFT_LAYER, KIND_WORDS, addressOf, applyFilters, arrowTarget, landingWords, applyWorkLayout, codePanelHtml, layerRowsOf, newWorkState, nodeForAddress, openedWords, panelOf, setWorkGraph, showWork, touchedBy, workAddress, workPanelHtml,
42
49
  } from './work-model.js';
43
50
 
44
51
  const GRAPH_URL = '/api/forge/work-graph';
@@ -50,10 +57,11 @@ let els = null; // { stage, bar, all, waiting, busy, note, lanes, loading }
50
57
  let laneEls = []; // the lanes' titles on the stage, in screen space: [{ el, name, count }]
51
58
  let laneKey = null; // the lanes they were made for
52
59
  let offPaint = null;
60
+ let badges = null; // the Work layer's pills over the map (work-badges.js)
61
+ let badgeWas = false; // whether the layer wanted the graph at the last look: it asks for it when it comes on
53
62
  let card = null; // the map's own card (pieces/status.js)
54
63
  let timer = 0;
55
64
  let seq = 0; // the answer that is waited for: an older one is dropped
56
- let pullDetail = new Map(); // pull number -> { head, text } what the checks said of the head (the node panel's line)
57
65
  let wasOn = false;
58
66
 
59
67
  const inst = () => pageInstance();
@@ -67,23 +75,43 @@ export function initWorkView(opts = {}) {
67
75
  if (btn) btn.hidden = !offered;
68
76
  work();
69
77
  mount();
78
+ paintEdgeColors();
70
79
  if (!wired) {
71
80
  wired = true;
72
81
  const i = inst();
73
82
  document.addEventListener('click', onClick);
74
83
  document.addEventListener('keydown', onKey, true); // before the map's own keys: in this view N and P step through the lanes, and an arrow goes to the nearest node that way
75
84
  i.on('view', syncWork);
76
- i.on('layers', refilter);
85
+ i.on('layers', () => { refilter(); syncBadges(); });
86
+ i.on('node:words', (node) => { const items = on() ? null : badgesOf(node); return items ? `, ${badgeWords(items)}` : undefined; }); // the keyboard's landing on a badged node says its work
77
87
  i.on('work:open', ({ id }) => openWork({ select: id }));
78
88
  i.on('search:more', () => (work().status === 'ok' && !on() ? work().nodes.filter((n) => n.work) : null));
79
89
  i.on('work:waiting', ({ total }) => paintBadge(total));
90
+ i.on('work:available', ({ on: available }) => { paintList(available); i.emit('layers:redraw'); syncBadges(); });
80
91
  i.on('work:panel', (node) => panelFor(node));
81
- mapStyleOf(i).onChange(() => { if (on()) { state.workRows = layerRowsOf(work().nodes).map(themed); i.emit('layers:redraw'); } });
92
+ i.on('work:pick', (ref) => pickRef(ref));
93
+ mapStyleOf(i).onChange(() => { paintEdgeColors(); if (on()) { state.workRows = layerRowsOf(work().nodes).map(themed); i.emit('layers:redraw'); i.touchScene(); render(); } });
82
94
  }
95
+ state.workRow = () => (offered && inst().ask('work:on') ? badgeRowOf(work(), badgeColor('pull')) : null); // the Layers menu's row under Overlays (engine/layers.js `layerRows`)
83
96
  syncWork();
97
+ inst().emit('layers:redraw'); // the Layers menu's Work row, if the piece that says it is signed in has started already
98
+ syncBadges();
99
+ }
100
+
101
+ /** The List toggle is shown while the Work piece is on (a forge in the config and somebody signed in); the piece says its own `aria-expanded` */
102
+ function paintList(available) {
103
+ if (els && els.list) els.list.hidden = !available;
104
+ }
105
+
106
+ /** The colours the theme gives the Work view's lines (`--corn-work-edge-<name>`), for the scene: a name it does not set is drawn in its default (work-model.js `workEdge`) */
107
+ function paintEdgeColors() {
108
+ const values = mapStyleOf(inst()).get().values;
109
+ const colors = {};
110
+ for (const name of WORK_EDGES) if (values[workEdgeToken(name)]) colors[name] = values[workEdgeToken(name)];
111
+ state.workEdgeColors = colors;
84
112
  }
85
113
 
86
- /** The Work button's badge and its spoken name: "Work, 3 waiting on you" (the Work panel's own words: waiting-model.js) */
114
+ /** The Work button's badge and its spoken name: "Work, 3 waiting on you" (the Work list's own words: waiting-model.js) */
87
115
  function paintBadge(total) {
88
116
  const btn = $('preset-work-btn');
89
117
  if (!btn) return;
@@ -108,6 +136,7 @@ function mount() {
108
136
  bar.hidden = true;
109
137
  bar.innerHTML = '<button type="button" class="hx-work-chip" data-corn="work-chip" data-corn-kind="quiet" data-work-show="all" aria-pressed="true">All work</button>'
110
138
  + '<button type="button" class="hx-work-chip" data-corn="work-chip" data-corn-kind="quiet" data-work-show="waiting" aria-pressed="false">Waiting on you</button>'
139
+ + '<button type="button" class="hx-work-chip" data-corn="work-chip" data-corn-kind="quiet" data-action="toggle-forge" aria-expanded="false" aria-controls="forge-panel" aria-label="Work list" title="The lists of issues, pull requests, proposals, threads, runs and deploys" hidden>List</button>'
111
140
  + '<span class="hx-work-busy" hidden>Updating…</span>';
112
141
  const note = document.createElement('p');
113
142
  note.className = 'hx-work-note';
@@ -127,9 +156,12 @@ function mount() {
127
156
  loading.innerHTML = `<div class="hx-work-skeleton" aria-hidden="true">${['Talk', 'Decide', 'Build', 'Ship', 'Code it touches'].map((name) => `<div class="hx-work-skel-lane"><span class="hx-work-lane-title">${name}</span><i></i><i></i><i></i><i></i></div>`).join('')}</div>`
128
157
  + '<p class="hx-work-loading-text" role="status">Reading the work from the forge. A big repository can take several seconds the first time; the page works meanwhile.</p>';
129
158
  stage.append(lanes, loading, bar, note);
130
- els = { stage, bar, all: bar.children[0], waiting: bar.children[1], busy: bar.children[2], note, lanes, loading };
159
+ els = { stage, bar, all: bar.children[0], waiting: bar.children[1], list: bar.children[2], busy: bar.children[3], note, lanes, loading };
160
+ paintList(!!inst().ask('work:on')); // the List toggle is there while the Work piece is on: a signed-in maintainer of a forge
131
161
  if (offPaint) offPaint();
132
- offPaint = onPaint(paintLanes);
162
+ if (badges) badges.destroy();
163
+ badges = createWorkBadges({ stage, state, style: () => mapStyleOf(inst()).get(), colorOf: badgeColor, wanted: badgesDrawn });
164
+ offPaint = onPaint((scene, camera) => { paintLanes(scene, camera); badges.sync(scene, camera); });
133
165
  watchSize(stage);
134
166
  card = mountStatus(stage, inst(), { follow: false, onRetry: () => load({ again: true }), focusMap: () => { if (state.canvas) state.canvas.focus(); } });
135
167
  }
@@ -225,21 +257,57 @@ function syncWork() {
225
257
  if (stage) stage.classList.toggle('is-work', open);
226
258
  paintBar();
227
259
  if (open !== wasOn) {
228
- if (open) { paintBadge(work().counts.waiting); inst().emit('layers:redraw'); } // the Layers menu lists the Work view's rows from the first moment, the answer here or not
260
+ if (open) paintBadge(work().counts.waiting);
261
+ inst().emit('layers:redraw'); // the Layers menu lists the Work view's rows from the first moment, the answer here or not, and the map's own again (with the Work layer's row) when the view is left
229
262
  wasOn = open;
230
- clearTimeout(timer);
231
- if (open) timer = setTimeout(poll, RUNS_POLL_MS);
232
- else if (card) card.clear();
263
+ armPoll();
264
+ if (!open) {
265
+ if (card) card.clear();
266
+ closeForge({ restoreFocus: false }); // the list is the Work view's
267
+ if (!state.selectedNode) inst().emit('node:close'); // a piece of work the node panel showed from the lists, with nothing selected
268
+ }
233
269
  }
234
270
  }
235
271
 
272
+ /** The one poll: every minute while the Work view is open, or the Work layer is on (the same read, never a second one) */
273
+ function armPoll() {
274
+ clearTimeout(timer);
275
+ if (on() || layerWanted()) timer = setTimeout(poll, RUNS_POLL_MS);
276
+ }
277
+
236
278
  function poll() {
237
279
  clearTimeout(timer);
238
- if (!on()) return;
239
- if (document.visibilityState !== 'hidden') load({ again: true, quiet: true });
280
+ if (!on() && !layerWanted()) return;
281
+ // a read on its way is this minute's: a slow forge is never asked twice at once (one that has had no answer for five minutes is given up for a new one)
282
+ if (document.visibilityState !== 'hidden' && !(reading && Date.now() - reading.at < STALLED_MS)) load({ again: true, quiet: true });
240
283
  timer = setTimeout(poll, RUNS_POLL_MS);
241
284
  }
242
285
 
286
+ // ---------------------------------------------------------------------------
287
+ // The Work layer on the Map view (spec 0012 D4)
288
+ // ---------------------------------------------------------------------------
289
+
290
+ /** Whether the viewer has the Work layer on and there is a forge to read: it is what asks for the graph (not the layer's state in the Work view, which has its own layers) */
291
+ const layerWanted = () => offered && state.activeLayers[WORK_BADGE_LAYER] === true && !!inst().ask('work:on');
292
+ /** The index of what is drawn: only on the Map view, with no proposal under review (its marks are the review's), and once the answer is here; null otherwise */
293
+ const badgesDrawn = () => (layerWanted() && state.view === 'orbit' && !state.proposal && work().status === 'ok' ? work().badges : null);
294
+ /** The open work touching a node, when the layer is drawing it: the node panel and the keyboard's words read it */
295
+ const badgesOf = (node) => { const index = badgesDrawn(); return index && node ? index.get(node.id) || null : null; };
296
+ /** A kind's colour as the pill is drawn: the theme's token, deepened on a light ground as the map's own are */
297
+ const badgeColor = (kind) => onGround(colorOf(kind), state.theme);
298
+
299
+ /** The layer came on or went off (or the forge became reachable): the first time it is on, the graph is asked for unless the Work view has it */
300
+ function syncBadges() {
301
+ const want = layerWanted();
302
+ if (want === badgeWas) return;
303
+ badgeWas = want;
304
+ armPoll();
305
+ const w = work();
306
+ if (want && w.status !== 'ok' && w.status !== 'loading') load({});
307
+ else render();
308
+ inst().emit('work:changed'); // a node panel open on a badged node shows its Open work, or no longer does
309
+ }
310
+
243
311
  // ---------------------------------------------------------------------------
244
312
  // Opening, and the answer
245
313
  // ---------------------------------------------------------------------------
@@ -268,7 +336,34 @@ export function closeWork() {
268
336
  setView('orbit');
269
337
  }
270
338
 
271
- async function load({ select = null, ask = null, again = false, quiet = false } = {}) {
339
+ /** The read on its way, if there is one: what its answer is to be used for. The Work view and the Work layer share it: a second ask while it is on its way waits for it, never starts another */
340
+ let reading = null;
341
+ /** How long a read on its way keeps the minute's poll from asking again */
342
+ const STALLED_MS = 5 * RUNS_POLL_MS;
343
+
344
+ /**
345
+ * Reads the graph (spec 0012 D7): once at a time. Asked while a read is on its way (the Work layer's, or the view's), it waits for that one and adds what it wants done with the answer
346
+ * (a node to select); a refresh (`again`) or the minute's poll starts a read of its own, which takes over what the read it replaces was to do (its answer is dropped).
347
+ */
348
+ function load({ select = null, ask = null, again = false, quiet = false } = {}) {
349
+ if (reading && !again && !quiet) {
350
+ if (select) reading.select = select;
351
+ if (ask) reading.ask = ask;
352
+ reading.quiet = false;
353
+ return reading.done;
354
+ }
355
+ if (reading) { // the read on its way is dropped for this one: the node it was to select, and its being said, are this one's now
356
+ select = select || reading.select;
357
+ ask = ask || reading.ask;
358
+ quiet = quiet && reading.quiet;
359
+ }
360
+ const mine = { select, ask, quiet, done: null, at: Date.now() };
361
+ mine.done = fetchGraph(mine, again).finally(() => { if (reading === mine) reading = null; });
362
+ reading = mine;
363
+ return mine.done;
364
+ }
365
+
366
+ async function fetchGraph(request, again) {
272
367
  const i = inst();
273
368
  const mine = ++seq;
274
369
  const w = work();
@@ -278,25 +373,26 @@ async function load({ select = null, ask = null, again = false, quiet = false }
278
373
  w.status = 'loading';
279
374
  card.clear();
280
375
  paintBar();
376
+ if (!on()) i.emit('layers:redraw'); // the Work layer's row says "reading…"
281
377
  announce(i, 'Work: reading the work from the forge.');
282
- } else if (!quiet) { w.updating = true; paintBar(); } // a refresh keeps the last answer on the map until the new one is here
378
+ } else if (!request.quiet) { w.updating = true; paintBar(); } // a refresh keeps the last answer on the map until the new one is here
283
379
  let res;
284
380
  try {
285
- res = await credentialed(i)(GRAPH_URL, { headers: { accept: 'application/json', ...(again && !quiet ? { 'cache-control': 'no-cache' } : {}) } }); // Refresh asks the forge again
381
+ res = await credentialed(i)(GRAPH_URL, { headers: { accept: 'application/json', ...(again && !request.quiet ? { 'cache-control': 'no-cache' } : {}) } }); // Refresh asks the forge again
286
382
  } catch {
287
383
  if (mine !== seq) return false;
288
- return refuse(i.offline() ? { state: 'offline' } : { state: 'server', message: 'cornfield could not be reached.' }, quiet);
384
+ return refuse(i.offline() ? { state: 'offline' } : { state: 'server', message: 'cornfield could not be reached.' }, request.quiet);
289
385
  }
290
386
  if (mine !== seq) return false;
291
- if (res.status === 401 || res.status === 403) return refuse({ state: 'sign-in', status: res.status, signIn: signInUrl(location.origin, location.href) }, quiet);
387
+ if (res.status === 401 || res.status === 403) return refuse({ state: 'sign-in', status: res.status, signIn: signInUrl(location.origin, location.href) }, request.quiet);
292
388
  let body = null;
293
389
  try { body = await res.json(); } catch { body = null; }
294
390
  if (mine !== seq) return false;
295
391
  if (!res.ok || !body || body.ok === false || !Array.isArray(body.nodes)) {
296
392
  const words = res.status === 404 ? 'This server does not answer for the map of work yet: update cornfield.' : body && typeof body.error === 'string' ? body.error.slice(0, 200) : `The server answered ${res.status}.`;
297
- return refuse({ state: 'server', message: words }, quiet);
393
+ return refuse({ state: 'server', message: words }, request.quiet);
298
394
  }
299
- return arrive(body, { select, ask, quiet });
395
+ return arrive(body, request);
300
396
  }
301
397
 
302
398
  /**
@@ -320,10 +416,12 @@ function refuse(detail, quiet) {
320
416
  w.problems = [];
321
417
  w.stale = '';
322
418
  w.lastError = '';
323
- if (on()) { showWork(state); applyWorkLayout(state, { phone: isPhone() }); inst().touchScene(); inst().emit('layers:redraw'); render(); }
324
- card.show(detail);
419
+ w.badges = new Map();
420
+ if (on()) { showWork(state); applyWorkLayout(state, { phone: isPhone() }); inst().touchScene(); inst().emit('layers:redraw'); render(); } else { inst().emit('layers:redraw'); render(); } // off the Work view the layer's row says why: the map shows no card for it
421
+ if (on()) card.show(detail);
325
422
  paintBar();
326
423
  paintBadge(0);
424
+ inst().emit('work:changed');
327
425
  if (!again) announce(inst(), `Work: ${detail.state === 'sign-in' ? (detail.status === 403 ? 'this map is for the maintainers.' : 'sign in to see the work.') : detail.state === 'offline' ? 'you are offline.' : 'it could not be read.'}`);
328
426
  return false;
329
427
  }
@@ -334,7 +432,9 @@ function arrive(body, { select, ask, quiet }) {
334
432
  const first = w.status !== 'ok';
335
433
  const before = state.selectedNode ? state.selectedNode.id : null;
336
434
  const base = state.baseNodes && state.baseNodes.length ? state.baseNodes : (w.saved ? w.saved.nodes : state.nodes);
435
+ const had = w.badges ? w.badges.size : -1;
337
436
  setWorkGraph(state, body, base);
437
+ w.badges = badgeIndex(w.nodes, w.edges);
338
438
  w.status = 'ok';
339
439
  w.updating = false;
340
440
  w.lastError = '';
@@ -352,6 +452,13 @@ function arrive(body, { select, ask, quiet }) {
352
452
  }
353
453
  paintBar();
354
454
  paintBadge(w.counts.waiting);
455
+ i.emit('work:changed'); // the node panel's section for the work touching its node is drawn again, if it says something else now
456
+ if (!on()) { // the Map view: the Work layer's badges, from the same answer
457
+ if (first || !quiet || had !== w.badges.size) i.emit('layers:redraw'); // the row's count
458
+ render(); // the badges are drawn from this answer
459
+ if ((first || !quiet) && badgesDrawn()) announce(i, `Work layer: ${w.badges.size} ${w.badges.size === 1 ? 'node has' : 'nodes have'} open work.`);
460
+ return true;
461
+ }
355
462
  // One sentence: the live region says only the last thing it is given, so what the view opened on and the node an address asked for are said together
356
463
  const opened = first || !quiet ? openedWords(w.counts) : '';
357
464
  const id = select || nodeForAddress(ask, w.nodes);
@@ -360,14 +467,20 @@ function arrive(body, { select, ask, quiet }) {
360
467
  const node = state.selectedNode;
361
468
  announce(i, `${opened} ${landingWords(node, shown.indexOf(node), shown.length)}`.trim());
362
469
  } else if (ask && ask.kind) {
363
- // A run or an issue older than the graph's window (a link posted in chat weeks ago) is still in the Work panel's lists: the panel opens at it, as these links did before
364
- const older = !ask.bad && (ask.kind === 'run' || ask.kind === 'issue');
365
- announce(i, `${ask.bad || `There is no ${KIND_WORDS[ask.kind].toLowerCase()} ${ask.key} in the work now${older ? ': the Work panel looks for it' : ''}.`} ${opened}`.trim());
366
- if (older) (ask.kind === 'run' ? openRunLink(ask.key) : openIssueLink(Number(ask.key))).catch(() => {});
470
+ // Work older than the graph's window (a link posted in chat weeks ago) is in the Work list: the list opens on its tab and the node panel shows it, as a row of the list does
471
+ if (ask.bad) announce(i, `${ask.bad} ${opened}`.trim());
472
+ else {
473
+ announce(i, `${KIND_WORDS[ask.kind]} ${ask.key} is not in the work drawn here: the Work list looks for it. ${opened}`.trim());
474
+ openForge({ tab: LIST_TAB[ask.kind], quiet: true }); // what the node panel shows is said, not the list's count
475
+ showWorkRef(ask.kind, ask.key).catch(() => {});
476
+ }
367
477
  } else if (opened) announce(i, opened);
368
478
  return true;
369
479
  }
370
480
 
481
+ /** The Work list's tab for a kind of work (its names are the tabs': pieces/work-common.js TABS) */
482
+ const LIST_TAB = Object.freeze({ pull: 'pulls', issue: 'issues', thread: 'threads', run: 'work', deploy: 'deploys', proposal: 'specs' });
483
+
371
484
  /** The nodes N and P step through, in the lanes' order: what is shown */
372
485
  const shownInOrder = () => work().order.map((id) => state.nodes.find((n) => n.id === id)).filter((n) => n && !n.hidden);
373
486
 
@@ -419,37 +532,32 @@ function setWaiting(on_) {
419
532
  /** The kind's colour as the map draws it: the theme's token, else the default (the style goes on through `data-style`, which a host's CSP allows) */
420
533
  const colorOf = (kind) => { const v = mapStyleOf(inst()).get().values[workToken(kind)]; return /^#[0-9a-f]{3,8}$/i.test(v || '') ? v : WORK_THEMES[kind] ? WORK_THEMES[kind].color : ''; };
421
534
 
422
- /** What the node panel shows for a node while the Work view is open (`work:panel`): a piece of work, replaced; a node of code, with the work that touches it first (work-model.js builds the markup) */
535
+ /**
536
+ * What the node panel shows for a node (`work:panel`): a piece of work, replaced (the Work piece draws its actions into it: pieces/work-paint.js `paintDetail`); a node of code in
537
+ * the Work view, with the work that touches it first (work-model.js builds the markup). A piece of work the graph does not hold (`old`, shown from the Work list or a link) is
538
+ * shown the same way in any view.
539
+ */
423
540
  function panelFor(node) {
424
- if (!on() || !node) return undefined;
541
+ if (!node) return undefined;
425
542
  const w = work();
426
- if (node.work) {
427
- const p = panelOf(node, w.nodes, w.edges);
428
- if (node.item.kind === 'pull') loadChecks(node);
429
- return { replace: true, badge: p.kind, title: p.title, html: workPanelHtml(p, node, { color: colorOf, checks: checksLine(node) }) };
543
+ if (node.work && (on() || node.old)) {
544
+ const p = node.old ? panelOf(node, [], []) : panelOf(node, w.nodes, w.edges);
545
+ return { replace: true, badge: p.kind, title: p.title, html: workPanelHtml(p, node, { color: colorOf }) };
430
546
  }
431
- return { replace: false, html: codePanelHtml(node, touchedBy(node, w.nodes, w.edges), { color: colorOf }) };
547
+ if (on()) return { replace: false, html: codePanelHtml(node, touchedBy(node, w.nodes, w.edges), { color: colorOf }) };
548
+ const items = badgesOf(node); // the Map view with the Work layer on: the open work touching the node, each a link into the Work view
549
+ return items ? { replace: false, html: openWorkHtml(items, { color: colorOf, address: (id) => { const n = w.nodes.find((x) => x.id === id); return n ? addressOf(n) : null; } }) } : undefined;
432
550
  }
433
551
 
434
- /** What the checks of a pull request's head say, once read; "Reading the checks…" until then */
435
- const checksLine = (node) => {
436
- const got = pullDetail.get(node.item.number);
437
- return got ? got.text : 'Reading the checks…';
438
- };
439
-
440
- /** The checks are not in the graph: they are read from the pull request's own route when its node is opened, and painted into the panel when they arrive */
441
- async function loadChecks(node) {
442
- const n = node.item.number;
443
- const i = inst();
444
- let text = 'The checks could not be read.';
445
- try {
446
- const res = await credentialed(i)(pullUrl(n), { headers: { accept: 'application/json' } });
447
- const body = res.ok ? await res.json() : null;
448
- if (body && Array.isArray(body.checks)) text = checksWords(body.checks);
449
- } catch { /* said in the panel */ }
450
- pullDetail.set(n, { text });
451
- const el = document.getElementById('work-checks');
452
- if (el && state.selectedNode && state.selectedNode.id === node.id) el.textContent = text;
552
+ /** A row of the Work list (or a link) names a piece of work: its node is selected on the map, with the camera on it, and the live region says where it is; false when the view does not draw it */
553
+ function pickRef(ref) {
554
+ if (!on() || work().status !== 'ok') return false;
555
+ const id = nodeForAddress(ref, work().nodes);
556
+ if (!id || !pick(id, { frame: true, source: 'link' })) return false;
557
+ const shown = shownInOrder();
558
+ const node = state.selectedNode;
559
+ if (node) announce(inst(), landingWords(node, shown.indexOf(node), shown.length));
560
+ return true;
453
561
  }
454
562
 
455
563
  // ---------------------------------------------------------------------------
@@ -484,10 +592,24 @@ function onClick(e) {
484
592
  if (show && on()) { setWaiting(show.dataset.workShow === 'waiting'); return; }
485
593
  const act = t_.closest('[data-work-action]');
486
594
  if (!act) return;
595
+ if (act.dataset.workAction === 'open-item') { // a node panel's "Open work" link: the Work view opens on that piece of work (a new tab, by the link's own address, is left alone)
596
+ if (e.button || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
597
+ e.preventDefault();
598
+ openWork({ select: act.dataset.id });
599
+ return;
600
+ }
601
+ if (act.dataset.workAction === 'review') { reviewSpec(act.dataset.slug, act.dataset.source); return; }
487
602
  const node = state.nodes.find((n) => n.id === act.dataset.id);
488
- if (!node) return;
489
- if (act.dataset.workAction === 'open-in-work') openWorkAt(node.item);
490
- else if (act.dataset.workAction === 'show-on-map') showOnMap(node.id);
603
+ if (node && act.dataset.workAction === 'show-on-map') showOnMap(node.id);
604
+ }
605
+
606
+ /** A proposal's Review: the map is the review's (Before, Diff, After lay it over the map), so the view goes back to it and the proposal opens; Approve and Send back are the review's own */
607
+ function reviewSpec(slug, source) {
608
+ if (!slug) return;
609
+ const i = inst();
610
+ closeWork();
611
+ i.emit('node:close'); // a proposal shown from the lists has nothing selected to close it
612
+ openProposal(i, slug, source || null).catch(() => {});
491
613
  }
492
614
 
493
615
  /** A node of code, on the map: the view goes back to it, the node selected and in view */
@@ -510,7 +632,7 @@ export async function followWorkAddress(search = location.search) {
510
632
  return openWork({ ask: ask.kind ? ask : null });
511
633
  }
512
634
 
513
- /** What an address that asks for work is, for the page to decide whether it is the Work view's (the old Work panel's links are `?run=` and `?issue=` too: step 3 of spec 0012 moves them) */
635
+ /** What an address that asks for work is, for the page to decide whether it is the Work view's (the old Work list's links are `?run=` and `?issue=` too: step 3 of spec 0012 moves them) */
514
636
  export const asksForWork = (search) => workAddress(search) !== null;
515
637
 
516
638
  function spend() {
@@ -528,6 +650,10 @@ export function resetWorkViewForTests() {
528
650
  clearTimeout(timer);
529
651
  if (offPaint) offPaint();
530
652
  offPaint = null;
653
+ if (badges) badges.destroy();
654
+ badges = null;
655
+ badgeWas = false;
656
+ reading = null;
531
657
  laneEls = [];
532
658
  laneKey = null;
533
659
  wired = false;
@@ -535,7 +661,6 @@ export function resetWorkViewForTests() {
535
661
  els = null;
536
662
  card = null;
537
663
  seq++;
538
- pullDetail = new Map();
539
664
  wasOn = false;
540
665
  }
541
666
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@popcorn245/cornfield",
3
- "version": "0.55.0",
3
+ "version": "0.57.0",
4
4
  "description": "A self-hostable dev dashboard with the topology map at its centre: proposals on the map, scenarios, outages and what-if edits, for any repo.",
5
5
  "license": "MIT",
6
6
  "author": "popcorn245 (https://github.com/popcorn245)",