@popcorn245/cornfield 0.56.0 → 0.57.1

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 (43) hide show
  1. package/core/strings.js +1 -1
  2. package/explorer/css/account.css +1 -1
  3. package/explorer/css/changes.css +1 -1
  4. package/explorer/css/dialogs.css +1 -1
  5. package/explorer/css/node-panel.css +1 -1
  6. package/explorer/css/sheets.css +1 -1
  7. package/explorer/css/work.css +6 -4
  8. package/explorer/engine/hint.js +2 -2
  9. package/explorer/engine/keyboard.js +1 -1
  10. package/explorer/engine/layers.js +4 -2
  11. package/explorer/engine/map-rect.js +2 -2
  12. package/explorer/engine/proposal.js +3 -3
  13. package/explorer/engine/sheets.js +3 -3
  14. package/explorer/focus-room.js +1 -1
  15. package/explorer/forge-panel-model.js +3 -2
  16. package/explorer/forge-panel.js +1 -1
  17. package/explorer/index.html +1 -1
  18. package/explorer/instance.js +6 -4
  19. package/explorer/page-pieces.js +1 -1
  20. package/explorer/pieces/decision.js +3 -3
  21. package/explorer/pieces/layers.js +1 -1
  22. package/explorer/pieces/node-panel.js +29 -9
  23. package/explorer/pieces/proposal.js +6 -6
  24. package/explorer/pieces/review.js +2 -2
  25. package/explorer/pieces/work-agent.js +4 -4
  26. package/explorer/pieces/work-confirm.js +3 -3
  27. package/explorer/pieces/work-issues.js +1 -1
  28. package/explorer/pieces/work-list.js +2 -0
  29. package/explorer/pieces/work-paint.js +23 -0
  30. package/explorer/pieces/work-prs.js +15 -5
  31. package/explorer/pieces/work-threads.js +1 -1
  32. package/explorer/pieces/work.js +10 -0
  33. package/explorer/proposal-model.js +1 -1
  34. package/explorer/proposal.js +1 -1
  35. package/explorer/runs-view.js +2 -2
  36. package/explorer/sheets.js +1 -1
  37. package/explorer/tokens.css +2 -2
  38. package/explorer/work-badge-model.js +161 -0
  39. package/explorer/work-badges.js +143 -0
  40. package/explorer/work-model.js +22 -4
  41. package/explorer/work-view.css +10 -0
  42. package/explorer/work-view.js +119 -22
  43. package/package.json +1 -1
@@ -18,6 +18,9 @@
18
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
19
  * the lanes, an arrow goes to the nearest node that way. Every request goes through `credentialed`;
20
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.
21
24
  */
22
25
 
23
26
  import { state, pageInstance } from './state.js';
@@ -27,6 +30,9 @@ import { announce } from './engine/keyboard.js';
27
30
  import { credentialed } from './engine/connection.js';
28
31
  import { selectNode } from './engine/selection.js';
29
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';
30
36
  import { signInUrl } from './engine/source.js';
31
37
  import { mapStyleOf, workToken, workEdgeToken } from './engine/map-style.js';
32
38
  import { t } from './engine/strings.js';
@@ -39,7 +45,7 @@ import { stepFrom } from './keyboard-model.js';
39
45
  import { RUNS_POLL_MS } from './pieces/work-common.js';
40
46
  import { showWorkRef, openForge, closeForge } from './forge-panel.js';
41
47
  import {
42
- 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,
43
49
  } from './work-model.js';
44
50
 
45
51
  const GRAPH_URL = '/api/forge/work-graph';
@@ -51,6 +57,8 @@ let els = null; // { stage, bar, all, waiting, busy, note, lanes, loading }
51
57
  let laneEls = []; // the lanes' titles on the stage, in screen space: [{ el, name, count }]
52
58
  let laneKey = null; // the lanes they were made for
53
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
54
62
  let card = null; // the map's own card (pieces/status.js)
55
63
  let timer = 0;
56
64
  let seq = 0; // the answer that is waited for: an older one is dropped
@@ -74,16 +82,20 @@ export function initWorkView(opts = {}) {
74
82
  document.addEventListener('click', onClick);
75
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
76
84
  i.on('view', syncWork);
77
- 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
78
87
  i.on('work:open', ({ id }) => openWork({ select: id }));
79
88
  i.on('search:more', () => (work().status === 'ok' && !on() ? work().nodes.filter((n) => n.work) : null));
80
89
  i.on('work:waiting', ({ total }) => paintBadge(total));
81
- i.on('work:available', ({ on: available }) => paintList(available));
90
+ i.on('work:available', ({ on: available }) => { paintList(available); i.emit('layers:redraw'); syncBadges(); });
82
91
  i.on('work:panel', (node) => panelFor(node));
83
92
  i.on('work:pick', (ref) => pickRef(ref));
84
93
  mapStyleOf(i).onChange(() => { paintEdgeColors(); if (on()) { state.workRows = layerRowsOf(work().nodes).map(themed); i.emit('layers:redraw'); i.touchScene(); render(); } });
85
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`)
86
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();
87
99
  }
88
100
 
89
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` */
@@ -99,7 +111,7 @@ function paintEdgeColors() {
99
111
  state.workEdgeColors = colors;
100
112
  }
101
113
 
102
- /** 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) */
103
115
  function paintBadge(total) {
104
116
  const btn = $('preset-work-btn');
105
117
  if (!btn) return;
@@ -147,7 +159,9 @@ function mount() {
147
159
  els = { stage, bar, all: bar.children[0], waiting: bar.children[1], list: bar.children[2], busy: bar.children[3], note, lanes, loading };
148
160
  paintList(!!inst().ask('work:on')); // the List toggle is there while the Work piece is on: a signed-in maintainer of a forge
149
161
  if (offPaint) offPaint();
150
- 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); });
151
165
  watchSize(stage);
152
166
  card = mountStatus(stage, inst(), { follow: false, onRetry: () => load({ again: true }), focusMap: () => { if (state.canvas) state.canvas.focus(); } });
153
167
  }
@@ -243,11 +257,11 @@ function syncWork() {
243
257
  if (stage) stage.classList.toggle('is-work', open);
244
258
  paintBar();
245
259
  if (open !== wasOn) {
246
- 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
247
262
  wasOn = open;
248
- clearTimeout(timer);
249
- if (open) timer = setTimeout(poll, RUNS_POLL_MS);
250
- else {
263
+ armPoll();
264
+ if (!open) {
251
265
  if (card) card.clear();
252
266
  closeForge({ restoreFocus: false }); // the list is the Work view's
253
267
  if (!state.selectedNode) inst().emit('node:close'); // a piece of work the node panel showed from the lists, with nothing selected
@@ -255,13 +269,45 @@ function syncWork() {
255
269
  }
256
270
  }
257
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
+
258
278
  function poll() {
259
279
  clearTimeout(timer);
260
- if (!on()) return;
261
- 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 });
262
283
  timer = setTimeout(poll, RUNS_POLL_MS);
263
284
  }
264
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
+
265
311
  // ---------------------------------------------------------------------------
266
312
  // Opening, and the answer
267
313
  // ---------------------------------------------------------------------------
@@ -290,7 +336,34 @@ export function closeWork() {
290
336
  setView('orbit');
291
337
  }
292
338
 
293
- 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) {
294
367
  const i = inst();
295
368
  const mine = ++seq;
296
369
  const w = work();
@@ -300,25 +373,26 @@ async function load({ select = null, ask = null, again = false, quiet = false }
300
373
  w.status = 'loading';
301
374
  card.clear();
302
375
  paintBar();
376
+ if (!on()) i.emit('layers:redraw'); // the Work layer's row says "reading…"
303
377
  announce(i, 'Work: reading the work from the forge.');
304
- } 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
305
379
  let res;
306
380
  try {
307
- 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
308
382
  } catch {
309
383
  if (mine !== seq) return false;
310
- 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);
311
385
  }
312
386
  if (mine !== seq) return false;
313
- 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);
314
388
  let body = null;
315
389
  try { body = await res.json(); } catch { body = null; }
316
390
  if (mine !== seq) return false;
317
391
  if (!res.ok || !body || body.ok === false || !Array.isArray(body.nodes)) {
318
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}.`;
319
- return refuse({ state: 'server', message: words }, quiet);
393
+ return refuse({ state: 'server', message: words }, request.quiet);
320
394
  }
321
- return arrive(body, { select, ask, quiet });
395
+ return arrive(body, request);
322
396
  }
323
397
 
324
398
  /**
@@ -342,10 +416,12 @@ function refuse(detail, quiet) {
342
416
  w.problems = [];
343
417
  w.stale = '';
344
418
  w.lastError = '';
345
- if (on()) { showWork(state); applyWorkLayout(state, { phone: isPhone() }); inst().touchScene(); inst().emit('layers:redraw'); render(); }
346
- 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);
347
422
  paintBar();
348
423
  paintBadge(0);
424
+ inst().emit('work:changed');
349
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.'}`);
350
426
  return false;
351
427
  }
@@ -356,7 +432,9 @@ function arrive(body, { select, ask, quiet }) {
356
432
  const first = w.status !== 'ok';
357
433
  const before = state.selectedNode ? state.selectedNode.id : null;
358
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;
359
436
  setWorkGraph(state, body, base);
437
+ w.badges = badgeIndex(w.nodes, w.edges);
360
438
  w.status = 'ok';
361
439
  w.updating = false;
362
440
  w.lastError = '';
@@ -374,6 +452,13 @@ function arrive(body, { select, ask, quiet }) {
374
452
  }
375
453
  paintBar();
376
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
+ }
377
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
378
463
  const opened = first || !quiet ? openedWords(w.counts) : '';
379
464
  const id = select || nodeForAddress(ask, w.nodes);
@@ -459,7 +544,9 @@ function panelFor(node) {
459
544
  const p = node.old ? panelOf(node, [], []) : panelOf(node, w.nodes, w.edges);
460
545
  return { replace: true, badge: p.kind, title: p.title, html: workPanelHtml(p, node, { color: colorOf }) };
461
546
  }
462
- return on() ? { replace: false, html: codePanelHtml(node, touchedBy(node, w.nodes, w.edges), { color: colorOf }) } : undefined;
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;
463
550
  }
464
551
 
465
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 */
@@ -505,6 +592,12 @@ function onClick(e) {
505
592
  if (show && on()) { setWaiting(show.dataset.workShow === 'waiting'); return; }
506
593
  const act = t_.closest('[data-work-action]');
507
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
+ }
508
601
  if (act.dataset.workAction === 'review') { reviewSpec(act.dataset.slug, act.dataset.source); return; }
509
602
  const node = state.nodes.find((n) => n.id === act.dataset.id);
510
603
  if (node && act.dataset.workAction === 'show-on-map') showOnMap(node.id);
@@ -539,7 +632,7 @@ export async function followWorkAddress(search = location.search) {
539
632
  return openWork({ ask: ask.kind ? ask : null });
540
633
  }
541
634
 
542
- /** 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) */
543
636
  export const asksForWork = (search) => workAddress(search) !== null;
544
637
 
545
638
  function spend() {
@@ -557,6 +650,10 @@ export function resetWorkViewForTests() {
557
650
  clearTimeout(timer);
558
651
  if (offPaint) offPaint();
559
652
  offPaint = null;
653
+ if (badges) badges.destroy();
654
+ badges = null;
655
+ badgeWas = false;
656
+ reading = null;
560
657
  laneEls = [];
561
658
  laneKey = null;
562
659
  wired = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@popcorn245/cornfield",
3
- "version": "0.56.0",
3
+ "version": "0.57.1",
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)",