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
@@ -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
  }
@@ -1,43 +1,46 @@
1
1
  /**
2
2
  * @module explorer/pieces/work-issues
3
3
  *
4
- * The Issues tab and the deep link to an issue (its rows are drawn with the PRs' in work-prs.js). 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 Issues tab (its rows are drawn with the PRs' in work-prs.js), an issue's actions in the node panel, and an issue older than the Work view's 14 days.
5
+ * 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
6
  * to `ctx.fn`; nothing is shared between two mounts.
6
7
  */
7
8
 
8
- import { issueUrl } from '../forge-panel-model.js';
9
+ import { escapeHtml as escHtml } from '../../core/text.js';
10
+ import { issueUrl, listUrl, listKeyOf, specBlock } from '../forge-panel-model.js';
9
11
 
10
12
  export function install(ctx) {
11
- const { ui, fn, $ } = ctx;
12
- const { announce } = ctx.h;
13
+ const { ui, fn } = ctx;
14
+ const { t } = ctx.h;
13
15
 
14
- /** An issue the open list does not hold: asked for once, directly, so a closed one is called closed and a missing one missing */
15
- async function issueNotListed(n) {
16
- const res = await fn.request(issueUrl(n));
17
- if (res.ok && res.body.issue) {
18
- const { issue } = res.body;
19
- ui.actNote = { ok: false, text: issue.state === 'closed' ? `Issue ${n} is closed: ${issue.title}` : `Issue ${n} is open, but not in the list shown here: ${issue.title}`, url: issue.url };
20
- fn.paint();
21
- announce(ui.actNote.text);
22
- return false;
23
- }
24
- return fn.linkMissing(res.status === 404 ? `There is no issue ${n}.` : fn.failWords(res, `issue ${n}`));
16
+ /** An issue's actions in the node panel: Start a spec (step 1 of the pipeline) and Start an agent, each opening its confirm step; a closed issue has none */
17
+ function issueActionsHtml(item) {
18
+ const n = item.number;
19
+ if (!item.open) return `<p class="hx-faint">${escHtml(specBlock({ state: 'closed' }))}</p>`;
20
+ const spec = specBlock({ state: 'open' }) === null
21
+ ? `<button data-corn-kind="secondary" type="button" class="hx-btn hx-forge-act hx-forge-startspec" data-forge-spec="${n}" aria-label="Start a spec for issue ${n}"${ui.busy ? ' disabled' : ''}>Start a spec …</button>`
22
+ : '';
23
+ const agent = `<button data-corn-kind="secondary" type="button" class="hx-btn hx-forge-act hx-forge-startspec" data-forge-agent="issue:${n}" aria-label="${escHtml(t('startAgent'))} on issue ${n}">${escHtml(t('startAgent'))} …</button>`;
24
+ return `<div class="hx-forge-cta">${agent}${spec}</div>`;
25
25
  }
26
26
 
27
- /** `?issue=<n>`: the Issues tab with that issue's Start an agent button in view and focused, ready to press */
28
- async function openIssueLink(n) {
29
- if (!ui.config) return false;
30
- await fn.openTab('issues');
31
- const list = fn.current();
32
- if (!list) return fn.linkMissing(ui.error || 'The issues could not be read.');
33
- const item = list.items.find((i) => i.number === n);
34
- if (!item) return issueNotListed(n);
35
- fn.paint();
36
- const start = $('forge-list').querySelector(`[data-forge-agent="issue:${n}"]`);
37
- fn.bringIntoView(start);
38
- announce(`Issue ${n}: ${item.title}. Start an agent is ready`);
39
- return true;
27
+ /**
28
+ * The issue the Work list names that the graph does not draw: a list already read holds it (the open one is read for this), else the issue's own route does (a closed one, or one past the end of the list).
29
+ * `null` says why in the list and through the live region when there is none.
30
+ */
31
+ async function oldIssue(n) {
32
+ const key = listKeyOf('issues', 'open');
33
+ if (!ui.lists[key]) {
34
+ const res = await fn.request(listUrl('issues', 'open'), false);
35
+ if (res.ok && !ui.lists[key]) ui.lists[key] = { items: res.body.items || [], at: res.body.at, rate: res.body.rate || '', stale: res.body.stale || '', problem: res.body.problem || '' };
36
+ }
37
+ const hit = Object.entries(ui.lists).filter(([k]) => k.startsWith('issues|')).flatMap(([, list]) => list.items).find((i) => i.number === n); // any list read, whatever its state filter
38
+ if (hit) return hit;
39
+ const res = await fn.request(issueUrl(n));
40
+ if (res.ok && res.body.issue) return res.body.issue;
41
+ fn.linkMissing(res.status === 404 ? `There is no issue ${n}.` : fn.failWords(res, `issue ${n}`));
42
+ return null;
40
43
  }
41
44
 
42
- Object.assign(fn, { issueNotListed, openIssueLink });
45
+ Object.assign(fn, { issueActionsHtml, oldIssue });
43
46
  }