@popcorn245/cornfield 0.49.0 → 0.50.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 (46) hide show
  1. package/explorer/css/review.css +49 -0
  2. package/explorer/decision-model.js +6 -0
  3. package/explorer/engine/layout.js +8 -3
  4. package/explorer/engine/sheets.js +40 -7
  5. package/explorer/engine/topology.js +126 -0
  6. package/explorer/focus-room.js +1 -7
  7. package/explorer/focusables.js +1 -1
  8. package/explorer/forge-panel.js +36 -2630
  9. package/explorer/index.html +15 -147
  10. package/explorer/instance-state.js +0 -7
  11. package/explorer/instance.js +21 -2
  12. package/explorer/page-pieces.js +21 -2
  13. package/explorer/page.js +3 -3
  14. package/explorer/panels.js +1 -5
  15. package/explorer/pieces/changes.js +2 -9
  16. package/explorer/pieces/decision.js +10 -3
  17. package/explorer/pieces/layers.js +1 -0
  18. package/explorer/pieces/map.js +4 -23
  19. package/explorer/pieces/node-panel.js +15 -5
  20. package/explorer/pieces/proposal.js +9 -0
  21. package/explorer/pieces/review.js +280 -0
  22. package/explorer/pieces/work-agent.js +211 -0
  23. package/explorer/pieces/work-common.js +88 -0
  24. package/explorer/pieces/work-confirm.js +169 -0
  25. package/explorer/pieces/work-data.js +178 -0
  26. package/explorer/pieces/work-deploys.js +104 -0
  27. package/explorer/pieces/work-events.js +285 -0
  28. package/explorer/pieces/work-issues.js +43 -0
  29. package/explorer/pieces/work-markup.js +155 -0
  30. package/explorer/pieces/work-notes.js +177 -0
  31. package/explorer/pieces/work-paint.js +312 -0
  32. package/explorer/pieces/work-prs.js +253 -0
  33. package/explorer/pieces/work-runs.js +387 -0
  34. package/explorer/pieces/work-specs.js +71 -0
  35. package/explorer/pieces/work-threads.js +309 -0
  36. package/explorer/pieces/work.js +285 -0
  37. package/explorer/proposal.js +1 -2
  38. package/explorer/runs-map.js +108 -103
  39. package/explorer/runs-view.js +8 -6
  40. package/explorer/strings.js +1 -1
  41. package/explorer/view.js +6 -59
  42. package/explorer/waiting-model.js +12 -12
  43. package/explorer/waiting-view.js +6 -6
  44. package/package.json +1 -1
  45. package/explorer/feedback.js +0 -15
  46. package/explorer/waiting-line.js +0 -14
@@ -0,0 +1,169 @@
1
+ /**
2
+ * @module explorer/pieces/work-confirm
3
+ *
4
+ * The confirm step: landing a pull request, starting a spec, opening a build issue (a modal dialog over a scrim). 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
+ * to `ctx.fn`; nothing is shared between two mounts.
6
+ */
7
+
8
+ import { withParts } from '../engine/piece.js';
9
+ import { mergeBlock, confirmMerge, mergeBody, actionUrl, actionWords, planUrl, confirmSpec, confirmBuild, specBody, buildBody, existingWords } from '../forge-panel-model.js';
10
+ import { trapTab } from '../focusables.js';
11
+ import { escapeHtml as escHtml } from '../../core/text.js';
12
+
13
+ export function install(ctx) {
14
+ const { inst, ui, m, fn, $ } = ctx;
15
+ const { announce, t, trapFocus } = ctx.h;
16
+
17
+ const confirmEl = () => $('forge-confirm');
18
+
19
+ /** While the confirm step is open the focus cannot leave it: a focus that lands elsewhere is brought back */
20
+ function keepFocusIn(e) {
21
+ const el = confirmEl();
22
+ if (ui.confirm && el && !el.contains(inst.active())) el.querySelector('[data-action="forge-confirm-cancel"]').focus(); // (the focus in the root's own tree: outside it, none)
23
+ }
24
+
25
+ /** Fills and opens the confirm step; the focus goes to Cancel. `what` is the model's: title, lines, checks, previews, note */
26
+ function showConfirm(what, goLabel, state) {
27
+ const el = confirmEl();
28
+ const asCode = ['Commit', 'At commit', 'Branch', 'File', 'Proposal'];
29
+ $('forge-confirm-title').textContent = what.title;
30
+ $('forge-confirm-body').innerHTML = withParts(`<dl class="hx-confirm-facts">${what.lines.map(([k, v]) => `<dt>${escHtml(k)}</dt><dd>${asCode.includes(k) ? `<code class="hx-code">${escHtml(v)}</code>` : escHtml(v)}</dd>`).join('')}</dl>
31
+ ${(what.checks || []).length ? `<ul class="hx-confirm-checks">${what.checks.map((c) => `<li><span class="hx-forge-state hx-forge-state--success" data-corn="state-pill" data-corn-state="success">${escHtml(c.words)}</span> ${escHtml(c.name)}</li>`).join('')}</ul>` : ''}
32
+ ${(what.previews || []).map((pv) => `<p class="hx-confirm-label">${escHtml(pv.label)}</p><pre class="hx-confirm-pre" data-corn="confirm-preview" tabindex="0" role="region" aria-label="${escHtml(pv.label)}">${escHtml(pv.text)}</pre>`).join('')}
33
+ <p class="hx-confirm-note">${escHtml(what.note)}</p>`);
34
+ const go = el.querySelector('[data-action="forge-confirm-go"]');
35
+ go.disabled = false;
36
+ go.textContent = goLabel;
37
+ go.removeAttribute('aria-busy');
38
+ // The scrim covers the page for the pointer, aria-modal tells a reader the rest is out of play, and the focus stays in
39
+ ui.confirm = state;
40
+ m.confirmTrap = trapFocus(keepFocusIn);
41
+ el.hidden = false;
42
+ el.querySelector('[data-action="forge-confirm-cancel"]').focus();
43
+ announce(`${what.title} ${what.lines.map(([k, v]) => `${k}: ${v}`).join('. ')}. ${what.note} Cancel or ${goLabel}.`);
44
+ }
45
+
46
+ /** Opens the confirm step for landing the selected pull request: what will land, exactly */
47
+ function openConfirm(opener) {
48
+ if (!confirmEl() || ui.confirm || ui.agent || ui.busy || !ui.detail || mergeBlock(ui.detail)) return; // one dialog at a time
49
+ showConfirm(confirmMerge(ui.detail, fn.forgeName(), ui.config && ui.config.forge && ui.config.forge.mergeMethod), t('landIt'), { opener, kind: 'merge' });
50
+ }
51
+
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 };
55
+ announce(text);
56
+ fn.paint();
57
+ }
58
+
59
+ /** Forgets the lists of the other kind (a step made something there), so they are asked again when shown */
60
+ function forgetOtherLists() {
61
+ for (const key of Object.keys(ui.lists)) if (!key.startsWith(`${ui.kind}|`)) delete ui.lists[key];
62
+ }
63
+
64
+ /**
65
+ * A pipeline step, first half: reads the plan from the server (what would be made, from the forge now). A step that
66
+ * was done before says so and stops; otherwise the confirm step shows the plan and nothing is made until it is confirmed.
67
+ */
68
+ async function askPlan(action, n, slug, opener) {
69
+ if (ui.busy || ui.confirm || ui.agent || !confirmEl()) return;
70
+ ui.busy = `plan:${action}`;
71
+ ui.actNote = null;
72
+ announce(action === 'spec' ? `Looking at what a spec for issue ${n} would make` : `Looking at the build issue for ${slug}`);
73
+ fn.paint();
74
+ const res = await fn.request(planUrl(action, n, slug), true);
75
+ ui.busy = '';
76
+ // 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
+ if (!res.ok || !res.body || !res.body.plan) {
79
+ stepNote(actionWords(action, res.status, res.body, n), false);
80
+ refocus();
81
+ return;
82
+ }
83
+ const { plan } = res.body;
84
+ if (plan.existing) {
85
+ stepNote(existingWords(action, plan), true, plan.existing.url);
86
+ refocus();
87
+ return;
88
+ }
89
+ fn.paint();
90
+ 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
+ const what = action === 'spec' ? confirmSpec(plan, fn.forgeName()) : confirmBuild(plan, fn.forgeName());
92
+ showConfirm(what, what.go, { opener, kind: action, plan, n, slug });
93
+ }
94
+
95
+ /** A pipeline step, second half: the plan that was shown is confirmed; the server plans again and must find the same */
96
+ async function confirmedStep() {
97
+ if (ui.busy || !ui.confirm || !ui.confirm.plan) return;
98
+ const { kind, plan, n } = ui.confirm;
99
+ ui.busy = kind;
100
+ ui.actNote = null;
101
+ const go = confirmEl().querySelector('[data-action="forge-confirm-go"]');
102
+ go.disabled = true;
103
+ go.setAttribute('aria-busy', 'true');
104
+ go.textContent = 'Working …';
105
+ announce(kind === 'spec' ? `Starting the spec for issue ${n}` : `Opening the build issue for ${plan.slug}`);
106
+ const res = await fn.post(actionUrl(n, kind), kind === 'spec' ? specBody(plan) : buildBody(plan));
107
+ closeConfirm();
108
+ ui.busy = '';
109
+ 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
+ // Whatever it came to, it is read again: a refusal says the issue or the pull request is not what was shown
112
+ if (res.status !== null) {
113
+ forgetOtherLists();
114
+ if (kind === 'build' && ui.selected === n) await fn.refreshForge({ quiet: true });
115
+ else await fn.loadList(true, true);
116
+ }
117
+ }
118
+
119
+ /** Closes the confirm step; the focus goes back to the button that opened it (or the panel's title if that is gone) */
120
+ function closeConfirm({ restoreFocus = true } = {}) {
121
+ const el = confirmEl();
122
+ if (!el || !ui.confirm) return;
123
+ const { opener } = ui.confirm;
124
+ ui.confirm = null;
125
+ el.hidden = true;
126
+ if (m.confirmTrap) { m.confirmTrap(); m.confirmTrap = null; }
127
+ if (!restoreFocus) return;
128
+ const back = $('forge-panel').querySelector(opener) || $('forge-title');
129
+ if (back && !back.disabled) back.focus();
130
+ }
131
+
132
+ /** Land it, confirmed: posts the head that was shown */
133
+ async function confirmedMerge() {
134
+ if (ui.busy || !ui.detail || !ui.confirm || ui.confirm.kind !== 'merge') return;
135
+ const { pull } = ui.detail;
136
+ const body = mergeBody(ui.detail);
137
+ ui.busy = 'merge';
138
+ ui.note = null;
139
+ const go = confirmEl().querySelector('[data-action="forge-confirm-go"]');
140
+ go.disabled = true;
141
+ go.setAttribute('aria-busy', 'true');
142
+ go.textContent = 'Landing …';
143
+ announce(`Landing pull request ${pull.number}`);
144
+ const res = await fn.post(actionUrl(pull.number, 'merge'), body);
145
+ closeConfirm();
146
+ await fn.finishAction('merge', res, pull.number);
147
+ }
148
+
149
+ /** Keys inside the confirm step: Escape cancels, Tab stays between its two buttons, nothing reaches the map behind it */
150
+ function onConfirmKey(e) {
151
+ e.stopPropagation();
152
+ if (e.key === 'Escape') {
153
+ e.preventDefault();
154
+ if (!ui.busy) closeConfirm();
155
+ return;
156
+ }
157
+ trapTab(e, confirmEl());
158
+ }
159
+
160
+ function onConfirmClick(e) {
161
+ const t = e.target;
162
+ if (t === confirmEl()) { if (!ui.busy) closeConfirm(); return; } // the scrim
163
+ const action = t.closest && t.closest('[data-action]');
164
+ if (!action) return;
165
+ if (action.dataset.action === 'forge-confirm-cancel') { if (!ui.busy) closeConfirm(); } else if (action.dataset.action === 'forge-confirm-go') { if (ui.confirm && ui.confirm.kind === 'merge') confirmedMerge(); else confirmedStep(); }
166
+ }
167
+
168
+ Object.assign(fn, { confirmEl, keepFocusIn, showConfirm, openConfirm, stepNote, forgetOtherLists, askPlan, confirmedStep, closeConfirm, confirmedMerge, onConfirmKey, onConfirmClick });
169
+ }
@@ -0,0 +1,178 @@
1
+ /**
2
+ * @module explorer/pieces/work-data
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
5
+ * to `ctx.fn`; nothing is shared between two mounts.
6
+ */
7
+
8
+ import { litOfRun } from '../runs-model.js';
9
+ import { listUrl, pullUrl, filterItems, litFor, errorWords, listKeyOf, litForDeploy, threadUrl, litForThread } from '../forge-panel-model.js';
10
+ import { plural, threadOf, FORGE_NAMES } from './work-common.js';
11
+ import { credentialed } from '../engine/connection.js';
12
+
13
+ export function install(ctx) {
14
+ const { inst, ui, m, fn, state, $ } = ctx;
15
+ const { announce, render, touchScene, repaintThreads, isOffline } = ctx.h;
16
+
17
+ /** Every request carries the maintainer's session to the base's own origin only (engine/connection.js) */
18
+ const ask = credentialed(inst);
19
+ /** An answer that comes after the piece ended is not wanted: whatever was waiting for it waits for ever, and so does nothing */
20
+ const never = () => new Promise(() => {});
21
+
22
+ const forgeName = () => FORGE_NAMES[ui.config && ui.config.forge && ui.config.forge.type] || 'the forge';
23
+
24
+ const listKey = () => listKeyOf(ui.kind, ui.filters.state);
25
+
26
+ const current = () => (ui.kind === 'work' ? ui.work : ui.kind === 'specs' ? fn.specsList() : ui.lists[listKey()]) || null;
27
+
28
+ const kindWords = () => ({ specs: 'spec', pulls: 'pull request', issues: 'issue', threads: 'thread', deploys: 'deploy' })[ui.kind] || 'piece of work';
29
+
30
+ /** A failed answer in words (the model's), said as offline when the browser is, and naming what could not be loaded */
31
+ const failWords = (res, what = '') => errorWords(res.status, res.body, { offline: isOffline(), what });
32
+
33
+ /** One GET (or the one POST, with its JSON); `{ ok, status, body }`, with a status of null when the server did not answer */
34
+ async function request(url, refresh, post) {
35
+ if (ctx.dead) return never(); // nothing is asked once the piece has ended
36
+ try {
37
+ // Refresh sends `Cache-Control: no-cache`, which the server takes as "ask the forge again"
38
+ const init = post ? { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(post) } : refresh ? { cache: 'reload' } : {};
39
+ const res = await ask(url, init);
40
+ if (ctx.dead) return never();
41
+ let body = null;
42
+ try { body = await res.json(); } catch { /* no body */ }
43
+ if (ctx.dead) return never();
44
+ return { ok: !!res.ok && !!body && body.ok !== false, status: res.status, body };
45
+ } catch {
46
+ if (ctx.dead) return never();
47
+ return { ok: false, status: null, body: null };
48
+ }
49
+ }
50
+
51
+ /** One POST of JSON; `{ ok, status, body }`, with a status of null when the server did not answer */
52
+ async function post(url, payload) {
53
+ if (ctx.dead) return never();
54
+ try {
55
+ const res = await ask(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload) });
56
+ if (ctx.dead) return never();
57
+ let body = null;
58
+ try { body = await res.json(); } catch { /* no body */ }
59
+ if (ctx.dead) return never();
60
+ return { ok: !!res.ok && !!body && body.ok === true, status: res.status, body };
61
+ } catch {
62
+ if (ctx.dead) return never();
63
+ return { ok: false, status: null, body: null };
64
+ }
65
+ }
66
+
67
+ /** Loads the list the kind and state name (again, past the server's cache, on a refresh) */
68
+ async function loadList(refresh = false, quiet = false) {
69
+ const token = ++m.listToken;
70
+ if (ui.kind === 'work') return fn.loadWork(refresh, token);
71
+ if (ui.kind === 'specs') return fn.loadSpecs(token, quiet);
72
+ const key = listKey();
73
+ ui.loading = true;
74
+ ui.error = '';
75
+ fn.paint();
76
+ const res = await request(listUrl(ui.kind, ui.filters.state), refresh);
77
+ if (token !== m.listToken) return;
78
+ ui.loading = false;
79
+ if (res.ok) {
80
+ ui.lists[key] = { items: res.body.items || [], at: res.body.at, rate: res.body.rate || '', stale: res.body.stale || '', problem: res.body.problem || '' };
81
+ if (ui.kind === 'threads') {
82
+ repaintThreads();
83
+ // 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
+ if (!ui.runs) fn.loadRuns(false, { say: false }).then(() => { if (ui.open && ui.kind === 'threads') fn.paint(); }, () => {});
85
+ }
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' : ''}`);
87
+ } else {
88
+ ui.error = failWords(res, `the ${kindWords()}s`);
89
+ if (!quiet) announce(ui.error);
90
+ }
91
+ fn.paintFilters();
92
+ fn.paint();
93
+ }
94
+
95
+ /** The counts on the tabs, read quietly the first time the panel opens: the open pull requests and issues (the Threads and Runs counts come from what those tabs read anyway) */
96
+ function primeCounts() {
97
+ for (const kind of ['pulls', 'issues']) {
98
+ const key = listKeyOf(kind, 'open');
99
+ if (ui.lists[key] || m.primed.has(kind) || kind === ui.kind) continue;
100
+ m.primed.add(kind);
101
+ request(listUrl(kind, 'open'), false).then((res) => {
102
+ 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 || '' };
103
+ if (ui.open) fn.paint();
104
+ });
105
+ }
106
+ if (!m.primed.has('threads')) { m.primed.add('threads'); fn.ensureThreadsList(); }
107
+ if (ui.kind !== 'specs') fn.readSpecsQuiet(); // the specs part of the number is read when Work opens (spec 0010 D2)
108
+ }
109
+
110
+ /** What the selected pull request lights, worked out again: for the nodes now on the map */
111
+ function relight() {
112
+ 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();
131
+ fn.paint();
132
+ }
133
+
134
+ /** A proposal opening, or the live layer, changes the nodes: the lights follow them */
135
+ function onNodesChange() {
136
+ if ((ui.detail || ui.deployItem || ui.threadDetail) && state.nodes !== ui.nodesSeen) relight();
137
+ repaintThreads();
138
+ }
139
+
140
+ /** Asks the forge again, past the server's cache: the list, and the selected pull request */
141
+ async function refreshForge({ quiet = false } = {}) {
142
+ if (!quiet) announce('Asking the forge again');
143
+ if (ui.kind === 'notes') { await fn.loadNotes(true); return; }
144
+ const n = ui.selected;
145
+ await loadList(true, quiet);
146
+ if (ui.deployItem) {
147
+ // The list is read again: the deploy as the forge now has it (still running, now finished), else the last copy
148
+ const again = ui.lists.deploys && ui.lists.deploys.items.find((d) => d.id === ui.deploy);
149
+ if (again) { ui.deployItem = again; relight(); }
150
+ return;
151
+ }
152
+ if (ui.thread !== null) {
153
+ const at = ui.thread;
154
+ const token = ++m.threadToken;
155
+ const res = await request(threadUrl(at), true);
156
+ const thread = threadOf(res);
157
+ if (token !== m.threadToken || !thread) return;
158
+ ui.threadDetail = { thread, at: res.body.at, rate: res.body.rate || '', stale: res.body.stale || '' };
159
+ relight();
160
+ return;
161
+ }
162
+ if (n !== null && ui.selected === n) {
163
+ const token = ++m.pullToken;
164
+ const res = await request(pullUrl(n), true);
165
+ if (token !== m.pullToken || !res.ok) return;
166
+ 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();
168
+ await fn.loadLanding(n, token);
169
+ }
170
+ }
171
+
172
+ /** Back online: a tab that could not be read is read again, so its error does not outlive the cause (the same function each time, added once) */
173
+ function readOnline() {
174
+ if (ui.open && (ui.error || (ui.runs && ui.runs.error) || ui.detailError || (ui.kind === 'notes' && ui.notes.error))) refreshForge({ quiet: true });
175
+ }
176
+
177
+ Object.assign(fn, { forgeName, listKey, current, kindWords, failWords, request, post, loadList, primeCounts, relight, onNodesChange, refreshForge, readOnline });
178
+ }
@@ -0,0 +1,104 @@
1
+ /**
2
+ * @module explorer/pieces/work-deploys
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
5
+ * to `ctx.fn`; nothing is shared between two mounts.
6
+ */
7
+
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';
13
+ import { escapeHtml as escHtml } from '../../core/text.js';
14
+ import { plural, safeUrl, backHtml } from './work-common.js';
15
+
16
+ export function install(ctx) {
17
+ const { ui, m, fn, state, $ } = ctx;
18
+ const { announce, render, touchScene, isNodeVisible, toggleLayer } = ctx.h;
19
+
20
+ /** Selects a deploy: nothing to ask (the list holds what it restarted), so its nodes light at once */
21
+ function selectDeploy(id) {
22
+ const found = ui.lists.deploys && ui.lists.deploys.items.find((d) => d.id === id);
23
+ if (!found) return;
24
+ m.pullToken++;
25
+ fn.dropThread();
26
+ ui.selected = null;
27
+ ui.detail = null;
28
+ ui.detailError = '';
29
+ ui.lit = null;
30
+ ui.deploy = id;
31
+ 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); }
37
+ }
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
+ }
42
+
43
+ /** Lets go of the selected deploy: nothing is lit any more */
44
+ function clearDeploy() {
45
+ const had = ui.deployItem;
46
+ ui.deploy = null;
47
+ ui.deployItem = null;
48
+ ui.litDeploy = null;
49
+ state.forgeLit = null;
50
+ touchScene();
51
+ render();
52
+ fn.paint();
53
+ if (had) announce(`Deploy ${had.name} cleared`);
54
+ }
55
+
56
+ /** What a deploy lights, said short, for its row: how many nodes, or that it is not mapped */
57
+ function lightsWords(deploy) {
58
+ if (!deploy.restarts.length) return 'Not mapped to a node';
59
+ const { nodes } = nodesForRestarts(deploy.restarts, state.nodes);
60
+ return nodes.length ? `Lights ${plural(nodes.length, 'node')}` : 'Names nodes not on the map';
61
+ }
62
+
63
+ function deployHtml(d) {
64
+ const link = safeUrl(d.url);
65
+ 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
+ <span class="hx-forge-title">${escHtml(d.name)}${d.title && d.title !== d.name ? `<span class="hx-faint"> · ${escHtml(d.title)}</span>` : ''}</span>
68
+ <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
+ }
71
+
72
+ /** The selected deploy: what it was, and the nodes it restarted (each a button that selects it on the map) */
73
+ function deployDetailHtml() {
74
+ const d = ui.deployItem;
75
+ const lit = ui.litDeploy;
76
+ 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>`;
79
+ const stale = ui.lists.deploys && ui.lists.deploys.stale;
80
+ let body;
81
+ 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>';
83
+ } else {
84
+ 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
+ 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}`;
88
+ }
89
+ return `${head}${stale ? `<p class="hx-forge-notice" data-corn="notice">${escHtml(`This is an older answer. ${stale}`)}</p>` : ''}${body}`;
90
+ }
91
+
92
+ /** What a screen reader hears when a deploy is selected */
93
+ function deploySelectionWords(turnedOn = []) {
94
+ const { name, branch } = ui.deployItem;
95
+ const lit = ui.litDeploy;
96
+ 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}`;
100
+ }
101
+
102
+ // 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
+ }