cornfield 0.54.0 → 0.56.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 (45) hide show
  1. package/core/contrast.js +28 -0
  2. package/core/schema.js +24 -0
  3. package/explorer/css/page.css +0 -8
  4. package/explorer/css/work.css +3 -26
  5. package/explorer/deep-link.js +11 -24
  6. package/explorer/engine/layers.js +5 -2
  7. package/explorer/engine/map-style.js +8 -1
  8. package/explorer/engine/render.js +2 -1
  9. package/explorer/forge-panel-model.js +2 -36
  10. package/explorer/forge-panel.js +3 -7
  11. package/explorer/index.html +5 -11
  12. package/explorer/instance-state.js +0 -6
  13. package/explorer/instance.js +9 -5
  14. package/explorer/layer-model.js +1 -0
  15. package/explorer/page.js +8 -5
  16. package/explorer/pieces/layers.js +1 -1
  17. package/explorer/pieces/node-panel.js +26 -4
  18. package/explorer/pieces/search.js +9 -3
  19. package/explorer/pieces/work-agent.js +3 -2
  20. package/explorer/pieces/work-common.js +14 -15
  21. package/explorer/pieces/work-confirm.js +11 -10
  22. package/explorer/pieces/work-data.js +24 -31
  23. package/explorer/pieces/work-deploys.js +42 -41
  24. package/explorer/pieces/work-issues.js +32 -29
  25. package/explorer/pieces/work-list.js +406 -0
  26. package/explorer/pieces/work-markup.js +9 -15
  27. package/explorer/pieces/work-notes.js +0 -1
  28. package/explorer/pieces/work-paint.js +57 -67
  29. package/explorer/pieces/work-prs.js +25 -66
  30. package/explorer/pieces/work-runs.js +47 -57
  31. package/explorer/pieces/work-specs.js +19 -2
  32. package/explorer/pieces/work-threads.js +29 -49
  33. package/explorer/pieces/work.js +28 -28
  34. package/explorer/proposal-model.js +5 -5
  35. package/explorer/runs-view.js +10 -18
  36. package/explorer/scene.js +17 -10
  37. package/explorer/search-match.js +3 -2
  38. package/explorer/tokens.css +11 -0
  39. package/explorer/view.js +8 -1
  40. package/explorer/waiting-view.js +3 -3
  41. package/explorer/work-model.js +722 -0
  42. package/explorer/work-view.css +50 -0
  43. package/explorer/work-view.js +570 -0
  44. package/package.json +1 -1
  45. package/explorer/pieces/work-events.js +0 -285
@@ -110,7 +110,7 @@ export const markup = () => ({
110
110
  + '<a data-corn="open-link" id="drawer-file-btn" data-corn-kind="primary" class="hx-open" href="#" target="_blank" rel="noreferrer" hidden>Open file ↗</a>'
111
111
  + '<a data-corn="open-link" id="drawer-open-btn" data-corn-kind="primary" class="hx-open" href="#" target="_blank" rel="noreferrer" hidden>Open route ↗</a>'
112
112
  + '<button data-corn-kind="secondary" type="button" id="drawer-run-btn" class="hx-btn hx-foot-btn" data-action="start-run" data-corn-string="startRun" hidden>Start a run</button>'
113
- + '<button data-corn-kind="quiet" type="button" class="hx-btn hx-btn--quiet hx-foot-btn" data-action="copy-spec" data-corn-string="copySpec">Copy Spec</button>'
113
+ + '<button data-corn-kind="quiet" type="button" id="drawer-copy-btn" class="hx-btn hx-btn--quiet hx-foot-btn" data-action="copy-spec" data-corn-string="copySpec">Copy Spec</button>'
114
114
  + '<p id="copy-spec-result" class="hx-forge-result" data-corn="result" hidden></p>'
115
115
  + '</div>'
116
116
  + '</aside>',
@@ -436,6 +436,25 @@ export function mount(root, inst, options = {}) {
436
436
  openBtn.textContent = `${t(inst, 'openRoute')} ↗`;
437
437
  fileBtn.textContent = `${t(inst, 'openFile')} ↗`;
438
438
  own('drawer-run-btn').hidden = !(state.proposalSlug && inst.ask('forge:can-start'));
439
+ // The Work view (spec 0012 D5): a piece of work is shown by the page's own answer (work-view.js); a node of code in it keeps its own sections, with the work touching it first
440
+ const work = inst.ask('work:panel', node);
441
+ own('drawer-copy-btn').hidden = !!(work && work.replace); // a piece of work is no spec to copy: its JSON is the forge's, not the map's
442
+ if (work && work.replace) {
443
+ title.textContent = work.title;
444
+ title.classList.remove('hx-mono');
445
+ own('drawer-badge').textContent = work.badge;
446
+ own('drawer-host').textContent = '';
447
+ pillEl.hidden = true;
448
+ lead.hidden = true;
449
+ metaList.innerHTML = work.html;
450
+ addParts(metaList);
451
+ fileBtn.hidden = true;
452
+ openBtn.hidden = true;
453
+ own('drawer-run-btn').hidden = true;
454
+ } else if (work) {
455
+ metaList.insertAdjacentHTML('afterbegin', work.html);
456
+ addParts(metaList);
457
+ }
439
458
 
440
459
  drawer.classList.add('drawer-open');
441
460
  drawer.inert = false; // closed, it waits off screen: inert, so Tab never reaches its buttons (MAP-02)
@@ -519,10 +538,12 @@ export function mount(root, inst, options = {}) {
519
538
  scope.listen(drawer, 'click', (e) => {
520
539
  const target = e.target.closest && e.target.closest('[data-action]');
521
540
  if (!target) return;
541
+ const shut = target.dataset.action === 'close-drawer';
542
+ const back = shut && inst.ask('node:back'); // the Work list's row that chose the node, asked before the panel lets go
522
543
  const action = ACTIONS[target.dataset.action];
523
544
  if (action) action(target);
524
- // The panel's ✕: the focus would be left on a hidden button, so it goes back to the map
525
- if (target.dataset.action === 'close-drawer' && state.canvas) scope.timeout(() => state.canvas.focus(), 0);
545
+ // The panel's ✕: the focus would be left on a hidden button, so it goes back to that row, else to the map
546
+ if (shut) scope.timeout(() => { if (!(back && back()) && state.canvas) state.canvas.focus(); }, 0);
526
547
  });
527
548
  // A thread listed in the panel opens in the Work panel, and "Start a thread about this" opens its New idea form (the Work panel hears both)
528
549
  scope.listen(drawer, 'click', (e) => {
@@ -545,8 +566,9 @@ export function mount(root, inst, options = {}) {
545
566
  if (e.key !== 'Escape' || e.defaultPrevented) return;
546
567
  if (e.target.closest && e.target.closest('select, input, textarea')) return; // a field's own Escape first
547
568
  e.preventDefault();
569
+ const back = inst.ask('node:back');
548
570
  clearSelection(inst, { source: 'keyboard' });
549
- if (state.canvas) state.canvas.focus();
571
+ if (!(back && back()) && state.canvas) state.canvas.focus();
550
572
  announce(inst, 'Panel closed');
551
573
  });
552
574
 
@@ -147,11 +147,16 @@ export function mount(root, inst, options = {}) {
147
147
  return (node) => { const p = byId.get(parentOf.get(node.id)); return p ? String(p.label || '') : ''; };
148
148
  }
149
149
 
150
+ /** A match Frame all takes in: on the map, and not a piece of work found from another view (its node is the Work view's) */
151
+ const framed = (m) => m.on && !(m.node.work && state.view !== 'work');
152
+
150
153
  /** What the current query finds (kept until the query, the nodes or the scene change) */
151
154
  function currentResult() {
152
- const key = `${state.searchQuery}|${state.sceneVersion}|${state.nodes.length}`;
155
+ const more = state.view === 'work' ? null : inst.ask('search:more'); // the work the page knows, found from the map too (the Work view, spec 0012)
156
+ const key = `${state.searchQuery}|${state.sceneVersion}|${state.nodes.length}|${more ? more.length : 0}`;
153
157
  if (memo && memo.key === key && memo.nodes === state.nodes) return memo.result;
154
- const result = searchNodes(state.nodes, state.searchQuery, { visible: (n) => inst.map.isNodeVisible(n), parentLabel: parentLabeller() });
158
+ const result = searchNodes(more && more.length ? state.nodes.concat(more) : state.nodes, state.searchQuery, { visible: (n) => inst.map.isNodeVisible(n), parentLabel: parentLabeller() });
159
+ if (more) result.onMap = result.matches.filter(framed).length; // the work found from another view is not on its map: Frame all counts what it frames
155
160
  memo = { key, nodes: state.nodes, result };
156
161
  return result;
157
162
  }
@@ -255,6 +260,7 @@ export function mount(root, inst, options = {}) {
255
260
  /** Selects a match and flies the camera to it (zoom 1 or closer): what Enter, a row and N do */
256
261
  async function chooseMatch(match, { say = true } = {}) {
257
262
  const node = match.node;
263
+ if (node.work && state.view !== 'work') { inst.emit('work:open', { id: node.id }); return; } // a piece of work: the Work view opens on it
258
264
  const mine = ++chosen;
259
265
  if (!inst.map.isNodeVisible(node)) showLayerOf(node);
260
266
  state.searchCurrent = node.id;
@@ -284,7 +290,7 @@ export function mount(root, inst, options = {}) {
284
290
  /** Fits the camera to every match on the map ("Frame all") */
285
291
  function frameAll() {
286
292
  const result = currentResult();
287
- const ids = new Set(result.matches.filter((m) => m.on).map((m) => m.node.id));
293
+ const ids = new Set(result.matches.filter(framed).map((m) => m.node.id));
288
294
  if (!ids.size) return;
289
295
  inst.map.fitGraphToViewport(inst.map.fitPadding(), ids);
290
296
  showSearchStatus(inst, '');
@@ -32,7 +32,7 @@ export function install(ctx) {
32
32
  const type = ref.slice(0, at);
33
33
  const value = ref.slice(at + 1);
34
34
  const refs = again ? retryRefs(again) : type === 'proposal' ? { proposal: value } : { issue: Number(value) };
35
- ui.agent = { opener, refs, posting: false, retryOf: again ? again.runId : null };
35
+ ui.agent = { opener, refs, posting: false, retryOf: again ? again.runId : null, ref: ui.ref }; // `ref`: the piece of work in the node panel, the one its note is shown with
36
36
  // The profiles the config lists come with the runs: asked for if the Agents tab has not been opened yet
37
37
  if (!ui.runs) { await fn.loadRuns(false); if (ui.kind === 'work') fn.paint(); }
38
38
  if (!ui.agent) return;
@@ -162,8 +162,9 @@ export function install(ctx) {
162
162
  ui.agent.posting = false;
163
163
  const text = startWords(res.status, res.body);
164
164
  if (res.ok) {
165
+ const { ref } = ui.agent;
165
166
  closeAgent();
166
- ui.runNote = { text, ok: true };
167
+ ui.runNote = { text, ok: true, ref };
167
168
  announce(text);
168
169
  await fn.loadRuns(false);
169
170
  fn.paint();
@@ -7,7 +7,6 @@
7
7
 
8
8
  import { escapeHtml as escHtml } from '../../core/text.js';
9
9
  import { defaultFilters } from '../forge-panel-model.js';
10
- import { withParts } from '../engine/piece.js';
11
10
 
12
11
  export const FORGE_NAMES = { github: 'GitHub', forgejo: 'Forgejo' };
13
12
  export const SEARCH_ANNOUNCE_MS = 500;
@@ -24,8 +23,6 @@ export const plural = (n, word, more = `${word}s`) => `${n} ${n === 1 ? word : m
24
23
  /** A link only if it is the forge's web address: a forge's JSON is data, not trusted markup */
25
24
  export const safeUrl = (u) => (typeof u === 'string' && /^https?:\/\//i.test(u) ? u : null);
26
25
  export const option = (value, label, on) => `<option value="${escHtml(value)}"${on ? ' selected' : ''}>${escHtml(label)}</option>`;
27
- /** The back control of a detail: an arrow and the name of the list it returns to ("All pull requests") */
28
- export const backHtml = (action, words) => withParts(`<button data-corn="back" type="button" class="hx-forge-back" data-action="${action}"><svg width="14" height="14" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" aria-hidden="true"><path d="M10 3L5 8l5 5"/></svg><span class="hx-forge-back-text">${escHtml(words)}</span></button>`);
29
26
  /** The thread a successful answer holds, or null (a failure, or an answer without one) */
30
27
  export const threadOf = (res) => (res && res.ok && res.body && res.body.thread && typeof res.body.thread === 'object' && Array.isArray(res.body.thread.messages) ? res.body.thread : null);
31
28
 
@@ -49,27 +46,29 @@ export function freshUi() {
49
46
  filtersOpen: false, // the Filter chip's box
50
47
  filters: defaultFilters(),
51
48
  lists: {}, // `${kind}|${server state}` -> { items, at, rate, stale }
52
- work: null, // { grouped, problem, at, rate, stale } of the Agents tab
49
+ work: null, // { grouped, problem, at, rate, stale } of the Runs tab
53
50
  specQuery: '', // the Specs tab's search (spec 0010 D5)
54
51
  draftsOpen: null, // the Drafts group opened (true) or folded (false) by hand; null: as the model has it (folded past 10 rows)
55
52
  workFilters: { agentsOnly: false, finished: false },
56
53
  loading: false,
57
54
  error: '',
58
- selected: null, // the pull request's number
59
- selectedOn: '', // the tab it was selected on ('pulls' or 'work')
60
- detail: null, // { pull, files, checks, at, rate, stale } of the selected one
55
+ node: '', // the id of the piece of work the node panel shows (`pull:27`), or '' while it shows none
56
+ ref: '', // …and its row's name in the lists (`pull:27`, `proposal:<slug>`, `run:<id>`): a row that names it is pressed
57
+ item: null, // …and what the graph, or the lists, say of it (work-model.js `workNode`'s `item`)
58
+ selected: null, // the pull request's number in the node panel
59
+ detail: null, // { pull, files, checks, at, rate, stale } of the pull request in the node panel
61
60
  landing: null, // what waits to land on its approval for the selected pull request ({ slug, by, since }), or null
62
61
  detailError: '',
63
- lit: null, // litFor(detail, nodes)
64
- thread: null, // the selected thread's number (Threads tab)
65
- threadDetail: null, // { thread, at, rate, stale } of the selected one: its messages, as written
62
+ lit: null, // litFor(detail, nodes): its files on the map's nodes
63
+ thread: null, // the number of the thread in the node panel
64
+ threadDetail: null, // { thread, at, rate, stale } of the one in the node panel: its messages, as written
66
65
  threadError: '',
67
- litThread: null, // litForThread(thread, nodes)
66
+ litThread: null, // litForThread(thread, nodes): the nodes its text names
68
67
  idea: freshIdea(), // the New idea form
69
- deploy: null, // the selected deploy's id; the deploy itself is `deployItem`
68
+ deploy: null, // the id of the deploy in the node panel; the deploy itself is `deployItem`
70
69
  deployItem: null,
71
- litDeploy: null, // litForDeploy(deployItem, nodes)
72
- nodesSeen: null, // the `state.nodes` the lights were worked out for
70
+ litDeploy: null, // litForDeploy(deployItem, nodes): the nodes it restarted
71
+ nodesSeen: null, // the `state.nodes` those were worked out for
73
72
  busy: '', // the action in flight ('merge', or 'rerun:<check id>'), so a second click does nothing
74
73
  note: null, // { text, ok }: what the last action came to, for the selected pull request
75
74
  confirm: null, // { opener: selector, kind: 'merge' | 'spec' | 'build', plan?, n?, slug? } while the confirm dialog is open
@@ -77,7 +76,7 @@ export function freshUi() {
77
76
  notes: freshNotes(), // the Release notes view
78
77
  runs: null, // { data, error } of the Agents tab's runs: what /api/agent-runs answered
79
78
  runNote: null, // { text, ok }: what the last Stop came to
80
- runSel: null, // the run lit on the map (Light on the map), by id
79
+ runShown: null, // the run in the node panel, by id
81
80
  runnerSaid: null, // the runner state last shown ('online', 'offline', 'none'; null off the pull transport), so a change is said once
82
81
  runTimelines: new Set(), // the runs whose timeline is open
83
82
  runReplies: new Map(), // the reply typed so far for each waiting run, so a repaint (the runs are looked at again) keeps it
@@ -11,7 +11,7 @@ import { trapTab } from '../focusables.js';
11
11
  import { escapeHtml as escHtml } from '../../core/text.js';
12
12
 
13
13
  export function install(ctx) {
14
- const { inst, ui, m, fn, $ } = ctx;
14
+ const { inst, ui, m, fn, root, $ } = ctx;
15
15
  const { announce, t, trapFocus } = ctx.h;
16
16
 
17
17
  const confirmEl = () => $('forge-confirm');
@@ -50,8 +50,8 @@ export function install(ctx) {
50
50
  }
51
51
 
52
52
  /** What a pipeline step came to, on the panel (with a link to what it made) and through the live region */
53
- function stepNote(text, ok, url = null) {
54
- ui.actNote = { text, ok, url };
53
+ function stepNote(text, ok, url = null, ref = ui.ref) {
54
+ ui.actNote = { text, ok, url, ref }; // `ref`: the piece of work it is about, the only one whose node panel shows it
55
55
  announce(text);
56
56
  fn.paint();
57
57
  }
@@ -67,6 +67,7 @@ export function install(ctx) {
67
67
  */
68
68
  async function askPlan(action, n, slug, opener) {
69
69
  if (ui.busy || ui.confirm || ui.agent || !confirmEl()) return;
70
+ const ref = ui.ref; // the node panel may show another piece of work by the time the plan is read
70
71
  ui.busy = `plan:${action}`;
71
72
  ui.actNote = null;
72
73
  announce(action === 'spec' ? `Looking at what a spec for issue ${n} would make` : `Looking at the build issue for ${slug}`);
@@ -74,28 +75,28 @@ export function install(ctx) {
74
75
  const res = await fn.request(planUrl(action, n, slug), true);
75
76
  ui.busy = '';
76
77
  // The button was off while it asked; it has the focus again whatever the answer is
77
- const refocus = () => { const back = $('forge-panel').querySelector(opener); if (back && !back.disabled && !ui.confirm) back.focus(); };
78
+ const refocus = () => { const back = root.querySelector(opener); if (back && !back.disabled && !ui.confirm) back.focus(); };
78
79
  if (!res.ok || !res.body || !res.body.plan) {
79
- stepNote(actionWords(action, res.status, res.body, n), false);
80
+ stepNote(actionWords(action, res.status, res.body, n), false, null, ref);
80
81
  refocus();
81
82
  return;
82
83
  }
83
84
  const { plan } = res.body;
84
85
  if (plan.existing) {
85
- stepNote(existingWords(action, plan), true, plan.existing.url);
86
+ stepNote(existingWords(action, plan), true, plan.existing.url, ref);
86
87
  refocus();
87
88
  return;
88
89
  }
89
90
  fn.paint();
90
91
  if (ui.agent) return; // Start an agent was opened while the plan was read: one dialog at a time, and that one has the focus
91
92
  const what = action === 'spec' ? confirmSpec(plan, fn.forgeName()) : confirmBuild(plan, fn.forgeName());
92
- showConfirm(what, what.go, { opener, kind: action, plan, n, slug });
93
+ showConfirm(what, what.go, { opener, kind: action, plan, n, slug, ref });
93
94
  }
94
95
 
95
96
  /** A pipeline step, second half: the plan that was shown is confirmed; the server plans again and must find the same */
96
97
  async function confirmedStep() {
97
98
  if (ui.busy || !ui.confirm || !ui.confirm.plan) return;
98
- const { kind, plan, n } = ui.confirm;
99
+ const { kind, plan, n, ref } = ui.confirm;
99
100
  ui.busy = kind;
100
101
  ui.actNote = null;
101
102
  const go = confirmEl().querySelector('[data-action="forge-confirm-go"]');
@@ -107,7 +108,7 @@ export function install(ctx) {
107
108
  closeConfirm();
108
109
  ui.busy = '';
109
110
  const made = res.body && (kind === 'spec' ? res.body.pull : res.body.issue);
110
- stepNote(actionWords(kind, res.status, res.body, n), res.ok, res.ok && made ? made.url : null);
111
+ stepNote(actionWords(kind, res.status, res.body, n), res.ok, res.ok && made ? made.url : null, ref);
111
112
  // Whatever it came to, it is read again: a refusal says the issue or the pull request is not what was shown
112
113
  if (res.status !== null) {
113
114
  forgetOtherLists();
@@ -125,7 +126,7 @@ export function install(ctx) {
125
126
  el.hidden = true;
126
127
  if (m.confirmTrap) { m.confirmTrap(); m.confirmTrap = null; }
127
128
  if (!restoreFocus) return;
128
- const back = $('forge-panel').querySelector(opener) || $('forge-title');
129
+ const back = root.querySelector(opener) || $('forge-title');
129
130
  if (back && !back.disabled) back.focus();
130
131
  }
131
132
 
@@ -1,18 +1,17 @@
1
1
  /**
2
2
  * @module explorer/pieces/work-data
3
3
  *
4
- * The Work panel's asking: every request, the list a tab shows, what a selection lights on the map, the counts read quietly. Part of the Work piece (pieces/work.js): `install(ctx)` makes this part's functions for one mount, and hands the ones other parts call
4
+ * The Work list's asking: every request, the list a tab shows, what the piece of work in the node panel holds, the counts read quietly. Part of the Work piece (pieces/work.js): `install(ctx)` makes this part's functions for one mount, and hands the ones other parts call
5
5
  * to `ctx.fn`; nothing is shared between two mounts.
6
6
  */
7
7
 
8
- import { litOfRun } from '../runs-model.js';
9
8
  import { listUrl, pullUrl, filterItems, litFor, errorWords, listKeyOf, litForDeploy, threadUrl, litForThread } from '../forge-panel-model.js';
10
9
  import { plural, threadOf, FORGE_NAMES } from './work-common.js';
11
10
  import { credentialed } from '../engine/connection.js';
12
11
 
13
12
  export function install(ctx) {
14
13
  const { inst, ui, m, fn, state, $ } = ctx;
15
- const { announce, render, touchScene, repaintThreads, isOffline } = ctx.h;
14
+ const { announce, repaintThreads, isOffline } = ctx.h;
16
15
 
17
16
  /** Every request carries the maintainer's session to the base's own origin only (engine/connection.js) */
18
17
  const ask = credentialed(inst);
@@ -67,7 +66,7 @@ export function install(ctx) {
67
66
  /** Loads the list the kind and state name (again, past the server's cache, on a refresh) */
68
67
  async function loadList(refresh = false, quiet = false) {
69
68
  const token = ++m.listToken;
70
- if (ui.kind === 'work') return fn.loadWork(refresh, token);
69
+ if (ui.kind === 'work') return fn.loadWork(refresh, token, quiet);
71
70
  if (ui.kind === 'specs') return fn.loadSpecs(token, quiet);
72
71
  const key = listKey();
73
72
  ui.loading = true;
@@ -83,7 +82,7 @@ export function install(ctx) {
83
82
  // A thread's row names the state of the run that is about it (issue #104): the runs are read, once, when the tab is the first thing opened
84
83
  if (!ui.runs) fn.loadRuns(false, { say: false }).then(() => { if (ui.open && ui.kind === 'threads') fn.paint(); }, () => {});
85
84
  }
86
- if (!quiet) announce(`${plural(filterItems(ui.lists[key].items, ui.kind, ui.filters).length, kindWords())} shown${ui.lists[key].stale ? '. This is an older answer' : ''}`);
85
+ if (!quiet && !(ui.actNote && !ui.actNote.ok)) announce(`${plural(filterItems(ui.lists[key].items, ui.kind, ui.filters).length, kindWords())} shown${ui.lists[key].stale ? '. This is an older answer' : ''}`); // a link that found nothing has said so: the count would cover it
87
86
  } else {
88
87
  ui.error = failWords(res, `the ${kindWords()}s`);
89
88
  if (!quiet) announce(ui.error);
@@ -107,33 +106,26 @@ export function install(ctx) {
107
106
  if (ui.kind !== 'specs') fn.readSpecsQuiet(); // the specs part of the number is read when Work opens (spec 0010 D2)
108
107
  }
109
108
 
110
- /** What the selected pull request lights, worked out again: for the nodes now on the map */
111
- function relight() {
109
+ /** The answer the Work list already read of a piece of work it is about to show (a pull request or a thread older than the graph's window is read to be made a node): used once, never kept */
110
+ function preloaded(kind, n) {
111
+ const got = m.preload && m.preload.kind === kind && m.preload.n === n ? m.preload.res : null;
112
+ m.preload = null;
113
+ return got;
114
+ }
115
+
116
+ /** What the piece of work in the node panel holds, worked out again: for the nodes now on the map (its files, the nodes a thread or a deploy names) */
117
+ function figure() {
112
118
  ui.nodesSeen = state.nodes;
113
- if (ui.runSel) {
114
- const run = fn.runById(ui.runSel);
115
- state.forgeLit = run ? litOfRun(run) : null;
116
- } else if (ui.threadDetail && ui.threadDetail.thread) {
117
- ui.litThread = litForThread(ui.threadDetail.thread, state.nodes);
118
- state.forgeLit = { changed: ui.litThread.changed, failing: ui.litThread.failing };
119
- } else if (ui.deployItem) {
120
- ui.litDeploy = litForDeploy(ui.deployItem, state.nodes);
121
- state.forgeLit = { changed: ui.litDeploy.changed, failing: ui.litDeploy.failing };
122
- } else if (ui.detail) {
123
- ui.lit = litFor(ui.detail, state.nodes);
124
- state.forgeLit = { changed: ui.lit.changed, failing: ui.lit.failing };
125
- } else {
126
- ui.lit = null;
127
- state.forgeLit = null;
128
- }
129
- touchScene();
130
- render();
119
+ if (ui.threadDetail && ui.threadDetail.thread) ui.litThread = litForThread(ui.threadDetail.thread, state.nodes);
120
+ else if (ui.deployItem) ui.litDeploy = litForDeploy(ui.deployItem, state.nodes);
121
+ else if (ui.detail) ui.lit = litFor(ui.detail, state.nodes);
122
+ else ui.lit = null;
131
123
  fn.paint();
132
124
  }
133
125
 
134
- /** A proposal opening, or the live layer, changes the nodes: the lights follow them */
126
+ /** A proposal opening, or the live layer, changes the nodes: what the node panel holds follows them */
135
127
  function onNodesChange() {
136
- if ((ui.detail || ui.deployItem || ui.threadDetail) && state.nodes !== ui.nodesSeen) relight();
128
+ if ((ui.detail || ui.deployItem || ui.threadDetail) && state.nodes !== ui.nodesSeen) figure();
137
129
  repaintThreads();
138
130
  }
139
131
 
@@ -143,10 +135,11 @@ export function install(ctx) {
143
135
  if (ui.kind === 'notes') { await fn.loadNotes(true); return; }
144
136
  const n = ui.selected;
145
137
  await loadList(true, quiet);
138
+ if (ui.runShown) await fn.loadRuns(true, { say: false }); // the run in the node panel: as the runners now report it
146
139
  if (ui.deployItem) {
147
140
  // The list is read again: the deploy as the forge now has it (still running, now finished), else the last copy
148
141
  const again = ui.lists.deploys && ui.lists.deploys.items.find((d) => d.id === ui.deploy);
149
- if (again) { ui.deployItem = again; relight(); }
142
+ if (again) { ui.deployItem = again; figure(); }
150
143
  return;
151
144
  }
152
145
  if (ui.thread !== null) {
@@ -156,7 +149,7 @@ export function install(ctx) {
156
149
  const thread = threadOf(res);
157
150
  if (token !== m.threadToken || !thread) return;
158
151
  ui.threadDetail = { thread, at: res.body.at, rate: res.body.rate || '', stale: res.body.stale || '' };
159
- relight();
152
+ figure();
160
153
  return;
161
154
  }
162
155
  if (n !== null && ui.selected === n) {
@@ -164,7 +157,7 @@ export function install(ctx) {
164
157
  const res = await request(pullUrl(n), true);
165
158
  if (token !== m.pullToken || !res.ok) return;
166
159
  ui.detail = { pull: res.body.pull, files: res.body.files || [], checks: res.body.checks || [], specs: res.body.specs || [], at: res.body.at, rate: res.body.rate || '', stale: res.body.stale || '' };
167
- relight();
160
+ figure();
168
161
  await fn.loadLanding(n, token);
169
162
  }
170
163
  }
@@ -174,5 +167,5 @@ export function install(ctx) {
174
167
  if (ui.open && (ui.error || (ui.runs && ui.runs.error) || ui.detailError || (ui.kind === 'notes' && ui.notes.error))) refreshForge({ quiet: true });
175
168
  }
176
169
 
177
- Object.assign(fn, { forgeName, listKey, current, kindWords, failWords, request, post, loadList, primeCounts, relight, onNodesChange, refreshForge, readOnline });
170
+ Object.assign(fn, { preloaded, forgeName, listKey, current, kindWords, failWords, request, post, loadList, primeCounts, figure, onNodesChange, refreshForge, readOnline });
178
171
  }
@@ -1,26 +1,24 @@
1
1
  /**
2
2
  * @module explorer/pieces/work-deploys
3
3
  *
4
- * The Deploys tab: the list and a deploy's detail, lit on the map. Part of the Work piece (pieces/work.js): `install(ctx)` makes this part's functions for one mount, and hands the ones other parts call
4
+ * The Deploys tab: the list, and a deploy's detail in the node panel (what it restarted, its logs on the forge). Part of the Work piece (pieces/work.js): `install(ctx)` makes this part's functions for one mount, and hands the ones other parts call
5
5
  * to `ctx.fn`; nothing is shared between two mounts.
6
6
  */
7
7
 
8
8
  import { withParts } from '../engine/piece.js';
9
- import { litForDeploy, nodesForRestarts, deployWords, deployMeta } from '../forge-panel-model.js';
10
- import { cornStateAttr, markStateAttr, stateIconHtml } from '../corn-state.js';
11
- import { layerOn } from '../layer-model.js';
12
- import { LAYER_DEFS } from '../engine/layers.js';
9
+ import { nodesForRestarts, deployWords, deployMeta, listUrl } from '../forge-panel-model.js';
10
+ import { cornStateAttr, stateIconHtml } from '../corn-state.js';
13
11
  import { escapeHtml as escHtml } from '../../core/text.js';
14
- import { plural, safeUrl, backHtml } from './work-common.js';
12
+ import { plural, safeUrl } from './work-common.js';
15
13
 
16
14
  export function install(ctx) {
17
- const { ui, m, fn, state, $ } = ctx;
18
- const { announce, render, touchScene, isNodeVisible, toggleLayer } = ctx.h;
15
+ const { ui, m, fn, state } = ctx;
16
+ const { announce, isNodeVisible } = ctx.h;
19
17
 
20
- /** Selects a deploy: nothing to ask (the list holds what it restarted), so its nodes light at once */
18
+ /** Shows a deploy in the node panel: nothing to ask once the list is read (it holds what the deploy restarted) */
21
19
  function selectDeploy(id) {
22
20
  const found = ui.lists.deploys && ui.lists.deploys.items.find((d) => d.id === id);
23
- if (!found) return;
21
+ if (!found) return false;
24
22
  m.pullToken++;
25
23
  fn.dropThread();
26
24
  ui.selected = null;
@@ -29,76 +27,79 @@ export function install(ctx) {
29
27
  ui.lit = null;
30
28
  ui.deploy = id;
31
29
  ui.deployItem = found;
32
- // A container, a stack or a machine is on a layer that starts off: the layers the deploy's nodes are on come on, or nothing would light
33
- const turnedOn = [];
34
- for (const n of litForDeploy(found, state.nodes).nodes) {
35
- const layer = LAYER_DEFS.find((l) => l.key === n.type);
36
- if (layer && !layerOn(state, layer.key)) { toggleLayer(layer.key); turnedOn.push(layer.label); }
30
+ fn.figure();
31
+ fn.sayDetail(deploySelectionWords());
32
+ return true;
33
+ }
34
+
35
+ /** The deploys list is read once for a deploy the node panel shows (the graph does not hold what a deploy restarted); a deploy older than the last hundred is said, never blank */
36
+ async function showDeploy(id) {
37
+ if (!ui.lists.deploys) {
38
+ const res = await fn.request(listUrl('deploys', 'all'), false);
39
+ if (res.ok) ui.lists.deploys = { items: res.body.items || [], at: res.body.at, rate: res.body.rate || '', stale: res.body.stale || '', problem: res.body.problem || '' };
40
+ }
41
+ if (ui.node === '') return; // the panel moved on while the list was read
42
+ if (!selectDeploy(id)) {
43
+ ui.deploy = null;
44
+ ui.deployItem = null;
45
+ ui.detailError = ui.lists.deploys ? 'This deploy is older than the last hundred the forge was asked for, so what it restarted is not known here.' : 'The deploys could not be read.';
46
+ fn.paint();
37
47
  }
38
- fn.relight();
39
- $('forge-panel').querySelector('.hx-forge-body').scrollTop = 0; // the deploy's nodes are what was asked for, not the row that was tapped
40
- announce(deploySelectionWords(turnedOn));
41
48
  }
42
49
 
43
- /** Lets go of the selected deploy: nothing is lit any more */
50
+ /** Lets go of the deploy in the node panel */
44
51
  function clearDeploy() {
45
- const had = ui.deployItem;
46
52
  ui.deploy = null;
47
53
  ui.deployItem = null;
48
54
  ui.litDeploy = null;
49
- state.forgeLit = null;
50
- touchScene();
51
- render();
52
- fn.paint();
53
- if (had) announce(`Deploy ${had.name} cleared`);
54
55
  }
55
56
 
56
- /** What a deploy lights, said short, for its row: how many nodes, or that it is not mapped */
57
- function lightsWords(deploy) {
57
+ /** What a deploy restarts, said short, for its row: how many nodes, or that it is not mapped */
58
+ function restartWords(deploy) {
58
59
  if (!deploy.restarts.length) return 'Not mapped to a node';
59
60
  const { nodes } = nodesForRestarts(deploy.restarts, state.nodes);
60
- return nodes.length ? `Lights ${plural(nodes.length, 'node')}` : 'Names nodes not on the map';
61
+ return nodes.length ? `Restarts ${plural(nodes.length, 'node')}` : 'Names nodes not on the map';
61
62
  }
62
63
 
63
64
  function deployHtml(d) {
64
65
  const link = safeUrl(d.url);
65
66
  const out = link ? `<a data-corn="out-link" class="hx-forge-out" href="${escHtml(link)}" target="_blank" rel="noreferrer" aria-label="Open deploy ${escHtml(d.name)} on ${escHtml(fn.forgeName())} (new tab)">↗</a>` : '';
66
- return `<li class="hx-forge-item"><button type="button" class="hx-forge-row" data-forge-deploy="${escHtml(d.id)}" aria-pressed="${ui.deploy === d.id}" data-corn="row">
67
+ return `<li class="hx-forge-item"><button type="button" class="hx-forge-row" data-work-ref="deploy:${escHtml(d.id)}" aria-pressed="${fn.isShown(`deploy:${d.id}`)}" data-corn="row">
67
68
  <span class="hx-forge-title">${escHtml(d.name)}${d.title && d.title !== d.name ? `<span class="hx-faint"> · ${escHtml(d.title)}</span>` : ''}</span>
68
69
  <span class="hx-forge-meta"><span class="hx-forge-state hx-forge-state--${escHtml(d.state)}" data-corn="state-pill"${cornStateAttr(d.state)}>${stateIconHtml(d.state)}${escHtml(deployWords(d))}</span> ${escHtml(deployMeta(d, m.now()))}</span>
69
- <span class="hx-forge-labels"><span class="hx-forge-label" data-corn="tag">${escHtml(lightsWords(d))}</span></span></button>${out}</li>`;
70
+ <span class="hx-forge-labels"><span class="hx-forge-label" data-corn="tag">${escHtml(restartWords(d))}</span></span></button>${out}</li>`;
70
71
  }
71
72
 
72
- /** The selected deploy: what it was, and the nodes it restarted (each a button that selects it on the map) */
73
+ /** The deploy in the node panel: what it was, its logs on the forge, and the nodes it restarted (each a button that selects it on the map) */
73
74
  function deployDetailHtml() {
75
+ if (ui.detailError && !ui.deployItem) return `<p class="hx-forge-notice" data-corn="notice">${escHtml(ui.detailError)}</p>`;
74
76
  const d = ui.deployItem;
77
+ if (!d) return '<p class="hx-faint">Loading what it restarted …</p>';
75
78
  const lit = ui.litDeploy;
76
79
  const url = safeUrl(d.url);
77
- const head = `${backHtml('clear-forge-deploy', 'All deploys')}<h3 class="hx-forge-detail-title" data-corn="detail-title">${escHtml(d.name)}</h3>
78
- <p class="hx-forge-meta"><span class="hx-forge-state hx-forge-state--${escHtml(d.state)}" data-corn="state-pill"${cornStateAttr(d.state)}>${stateIconHtml(d.state)}${escHtml(deployWords(d))}</span> ${escHtml(deployMeta(d, m.now()))}${url ? ` · <a data-corn="text-link" class="hx-link" href="${escHtml(url)}" target="_blank" rel="noreferrer">Open on ${escHtml(fn.forgeName())} ↗</a>` : ''}</p>`;
80
+ const head = `<p class="hx-forge-meta"><span class="hx-forge-state hx-forge-state--${escHtml(d.state)}" data-corn="state-pill"${cornStateAttr(d.state)}>${stateIconHtml(d.state)}${escHtml(deployWords(d))}</span> ${escHtml(deployMeta(d, m.now()))}</p>
81
+ ${url ? `<div class="hx-forge-cta"><a data-corn="open-link" data-corn-kind="secondary" class="hx-btn hx-forge-open" href="${escHtml(url)}" target="_blank" rel="noreferrer">Open the logs on ${escHtml(fn.forgeName())} ↗</a></div>` : ''}`;
79
82
  const stale = ui.lists.deploys && ui.lists.deploys.stale;
80
83
  let body;
81
84
  if (!d.restarts.length) {
82
- body = '<p class="hx-forge-notice" data-corn="notice">No node is mapped to this deploy, so nothing is lit. Say what it restarts under <code class="hx-code">deploys.restarts</code> in cornfield.config.js (docs/deploys.md).</p>';
85
+ body = '<p class="hx-forge-notice" data-corn="notice">No node is mapped to this deploy. Say what it restarts under <code class="hx-code">deploys.restarts</code> in cornfield.config.js (docs/deploys.md).</p>';
83
86
  } else {
84
87
  const rows = lit.nodes.map((n) => `<li class="hx-forge-file" data-corn="file"><button data-corn="node-chip" type="button" class="hx-forge-node" data-forge-node="${escHtml(n.id)}" aria-label="Show ${escHtml(n.label)} on the map${isNodeVisible(n) ? '' : ' (its layer is off)'}">${escHtml(n.label)}${isNodeVisible(n) ? '' : ' · layer off'}</button> <span class="hx-faint">${escHtml(n.type)}</span></li>`).join('');
85
88
  const missing = lit.missing.length ? `<p class="hx-forge-notice" data-corn="notice">${escHtml(lit.missing.join(', '))} ${lit.missing.length === 1 ? 'is' : 'are'} named in the config but not on the map.</p>` : '';
86
- const key = lit.nodes.length ? `<p class="hx-forge-key hx-faint"><span class="hx-mark-dot hx-mark-dot--${d.state === 'failure' ? 'removed' : 'changed'}" data-corn="mark-dot"${markStateAttr(d.state === 'failure' ? 'removed' : 'changed')} aria-hidden="true"></span>${d.state === 'failure' ? 'restarted by a deploy that failed' : 'restarted by this deploy'}</p>` : '';
87
- body = `<h4 class="hx-forge-sub">${escHtml(`Restarted: ${plural(lit.nodes.length, 'node')} on the map`)}</h4>${key}${rows ? `<ul class="hx-forge-files">${rows}</ul>` : ''}${missing}`;
89
+ body = `<h3 class="hx-forge-sub">${escHtml(`Restarted: ${plural(lit.nodes.length, 'node')} on the map`)}</h3>${rows ? `<ul class="hx-forge-files">${rows}</ul>` : ''}${missing}`;
88
90
  }
89
91
  return `${head}${stale ? `<p class="hx-forge-notice" data-corn="notice">${escHtml(`This is an older answer. ${stale}`)}</p>` : ''}${body}`;
90
92
  }
91
93
 
92
94
  /** What a screen reader hears when a deploy is selected */
93
- function deploySelectionWords(turnedOn = []) {
95
+ function deploySelectionWords() {
94
96
  const { name, branch } = ui.deployItem;
95
97
  const lit = ui.litDeploy;
96
98
  const head = `Deploy ${name}${branch ? ` of ${branch}` : ''}, ${deployWords(ui.deployItem).toLowerCase()}`;
97
- if (!ui.deployItem.restarts.length) return `${head}. No node is mapped to it, so nothing is lit.`;
98
- const layers = turnedOn.length ? ` Turned on the ${turnedOn.join(' and ')} ${turnedOn.length === 1 ? 'layer' : 'layers'}.` : '';
99
- return `${head}: ${plural(lit.nodes.length, 'node')} restarted and lit${lit.missing.length ? `, ${lit.missing.length} named that ${lit.missing.length === 1 ? 'is' : 'are'} not on the map` : ''}.${layers}`;
99
+ if (!ui.deployItem.restarts.length) return `${head}. No node is mapped to it.`;
100
+ return `${head}: ${plural(lit.nodes.length, 'node')} restarted on the map${lit.missing.length ? `, ${lit.missing.length} named that ${lit.missing.length === 1 ? 'is' : 'are'} not on the map` : ''}.`;
100
101
  }
101
102
 
102
103
  // what other parts put in the panel gets its parts (a hook is a part of the same name)
103
- Object.assign(fn, { selectDeploy, clearDeploy, lightsWords, deployHtml: (...a) => withParts(deployHtml(...a)), deployDetailHtml: (...a) => withParts(deployDetailHtml(...a)), deploySelectionWords });
104
+ Object.assign(fn, { selectDeploy, showDeploy, clearDeploy, restartWords, deployHtml: (...a) => withParts(deployHtml(...a)), deployDetailHtml: (...a) => withParts(deployDetailHtml(...a)), deploySelectionWords });
104
105
  }