@popcorn245/cornfield 0.50.0 → 0.51.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.
- package/explorer/camera-frame.js +82 -0
- package/explorer/camera.js +7 -73
- package/explorer/check-model.js +3 -44
- package/explorer/cloud-model.js +2 -101
- package/explorer/cloud-panel.js +107 -0
- package/explorer/css/review.css +2 -0
- package/explorer/engine/connection.js +4 -1
- package/explorer/engine/map-rect.js +97 -0
- package/explorer/engine/player.js +2 -1
- package/explorer/engine/proposal.js +28 -7
- package/explorer/engine/server-load.js +64 -0
- package/explorer/engine/sheets.js +4 -86
- package/explorer/engine/source-address.js +58 -0
- package/explorer/engine/source.js +16 -45
- package/explorer/engine/theme-sheet.js +23 -1
- package/explorer/engine/topology.js +1 -1
- package/explorer/focus-room.js +1 -7
- package/explorer/focusables.js +1 -1
- package/explorer/forge-panel.js +36 -2630
- package/explorer/index.html +15 -147
- package/explorer/instance-state.js +0 -7
- package/explorer/instance.js +19 -2
- package/explorer/layer-model.js +1 -1
- package/explorer/outage-model.js +6 -76
- package/explorer/outage-scenario.js +83 -0
- package/explorer/page-pieces.js +21 -2
- package/explorer/page.js +3 -3
- package/explorer/panels.js +1 -5
- package/explorer/pieces/layers.js +1 -0
- package/explorer/pieces/node-panel.js +19 -8
- package/explorer/pieces/proposal.js +9 -0
- package/explorer/pieces/review-source.js +84 -0
- package/explorer/pieces/review.js +145 -12
- package/explorer/pieces/scope.js +23 -54
- package/explorer/pieces/status.js +5 -1
- package/explorer/pieces/work-agent.js +211 -0
- package/explorer/pieces/work-common.js +88 -0
- package/explorer/pieces/work-confirm.js +169 -0
- package/explorer/pieces/work-data.js +178 -0
- package/explorer/pieces/work-deploys.js +104 -0
- package/explorer/pieces/work-events.js +285 -0
- package/explorer/pieces/work-issues.js +43 -0
- package/explorer/pieces/work-markup.js +155 -0
- package/explorer/pieces/work-notes.js +177 -0
- package/explorer/pieces/work-paint.js +312 -0
- package/explorer/pieces/work-prs.js +253 -0
- package/explorer/pieces/work-runs.js +387 -0
- package/explorer/pieces/work-specs.js +71 -0
- package/explorer/pieces/work-threads.js +309 -0
- package/explorer/pieces/work.js +285 -0
- package/explorer/proposal-marks.js +220 -0
- package/explorer/proposal-model.js +23 -211
- package/explorer/proposal.js +1 -2
- package/explorer/runs-map.js +108 -103
- package/explorer/runs-view.js +8 -6
- package/explorer/scenario.js +2 -1
- package/explorer/scene.js +2 -2
- package/explorer/selection-model.js +2 -42
- package/explorer/selection-view.js +1 -1
- package/explorer/selection-words.js +52 -0
- package/explorer/strings.js +1 -1
- package/explorer/verdict-paint.js +51 -0
- package/explorer/waiting-model.js +12 -12
- package/explorer/waiting-view.js +6 -6
- package/package.json +1 -1
- package/explorer/feedback.js +0 -15
- package/explorer/waiting-line.js +0 -14
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/pieces/work-prs
|
|
3
|
+
*
|
|
4
|
+
* The PRs tab: the list rows, a pull request's detail (files, checks, merge, rerun, landing) and the lights it puts 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 { runOnPull, pullRunWords, statusWords } from '../runs-model.js';
|
|
10
|
+
import { loadingRowsHtml, runPillHtml } from '../runs-view.js';
|
|
11
|
+
import { pullUrl, stateWords, metaWords, checkWords, checksWords, landingUrl, cancelLandingUrl, landingWords, mergeBlock, rerunWhy, actionUrl, actionWords, specBlock, buildOffers, approvalWarning } from '../forge-panel-model.js';
|
|
12
|
+
import { cornStateAttr, stateIconHtml } from '../corn-state.js';
|
|
13
|
+
import { relativeTime } from '../review-model.js';
|
|
14
|
+
import { waiting } from '../waiting-model.js';
|
|
15
|
+
import { escapeHtml as escHtml } from '../../core/text.js';
|
|
16
|
+
import { plural, safeUrl, backHtml } from './work-common.js';
|
|
17
|
+
|
|
18
|
+
export function install(ctx) {
|
|
19
|
+
const { ui, m, fn, state, $ } = ctx;
|
|
20
|
+
const { announce, t, render, touchScene, isNodeVisible } = ctx.h;
|
|
21
|
+
|
|
22
|
+
/** Selects a pull request: asks for its files and checks, then lights what they are on the map */
|
|
23
|
+
async function selectPull(n) {
|
|
24
|
+
const token = ++m.pullToken;
|
|
25
|
+
fn.dropThread();
|
|
26
|
+
ui.deploy = null;
|
|
27
|
+
ui.deployItem = null;
|
|
28
|
+
ui.litDeploy = null;
|
|
29
|
+
ui.selected = n;
|
|
30
|
+
ui.selectedOn = ui.kind; // the PRs list or the Runs tab's groups: its detail replaces that list only
|
|
31
|
+
ui.detail = null;
|
|
32
|
+
ui.landing = null;
|
|
33
|
+
ui.detailError = '';
|
|
34
|
+
ui.lit = null;
|
|
35
|
+
ui.note = null;
|
|
36
|
+
state.forgeLit = null;
|
|
37
|
+
touchScene();
|
|
38
|
+
render();
|
|
39
|
+
fn.paint();
|
|
40
|
+
const res = await fn.request(pullUrl(n), false);
|
|
41
|
+
if (token !== m.pullToken) return;
|
|
42
|
+
if (!res.ok) {
|
|
43
|
+
ui.detailError = fn.failWords(res, `pull request ${n}`);
|
|
44
|
+
announce(ui.detailError);
|
|
45
|
+
fn.paint();
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
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 || '' };
|
|
49
|
+
fn.relight();
|
|
50
|
+
// The run that made it is on the detail: the runs are read once, if the config has any
|
|
51
|
+
if (!ui.runs && ui.config.agents && ui.config.agents.runs) fn.loadRuns(false, { say: false }).then(() => { if (ui.selected === n) fn.paint(); }, () => {});
|
|
52
|
+
await loadLanding(n, token);
|
|
53
|
+
$('forge-panel').querySelector('.hx-forge-body').scrollTop = 0; // the pull request's files are what was asked for, not the row that was tapped
|
|
54
|
+
announce(selectionWords());
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Asks the server whether the selected pull request waits to land on its approval (a read of the server's own state, not of the forge); nothing is shown when it does not */
|
|
58
|
+
async function loadLanding(n, token) {
|
|
59
|
+
if (!(ui.config && ui.config.forge && ui.config.forge.approveLands)) return; // the key is off: nothing to ask
|
|
60
|
+
const res = await fn.request(landingUrl(n), true);
|
|
61
|
+
if (token !== m.pullToken || ui.selected !== n) return;
|
|
62
|
+
ui.landing = res.ok && res.body && res.body.landing ? res.body.landing : null;
|
|
63
|
+
fn.paint();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Stops the landing that waits on the selected pull request: a POST from this page, then the pull request is read again */
|
|
67
|
+
async function cancelLanding(n) {
|
|
68
|
+
if (ui.busy) return;
|
|
69
|
+
ui.busy = 'landing';
|
|
70
|
+
ui.note = null;
|
|
71
|
+
fn.paint();
|
|
72
|
+
const res = await fn.post(cancelLandingUrl(n), {});
|
|
73
|
+
ui.busy = '';
|
|
74
|
+
ui.note = { text: res.ok ? `Pull request #${n} will not land on its own. It stays open.` : `Not cancelled: ${(res.body && res.body.error) || 'cornfield did not answer.'}`, ok: res.ok };
|
|
75
|
+
announce(ui.note.text);
|
|
76
|
+
ui.landing = null;
|
|
77
|
+
fn.paint();
|
|
78
|
+
if (ui.selected === n) await fn.refreshForge({ quiet: true });
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Lets go of the selected pull request: nothing is lit any more */
|
|
82
|
+
function clearPull() {
|
|
83
|
+
m.pullToken++;
|
|
84
|
+
const had = ui.selected;
|
|
85
|
+
if (ui.confirm) fn.closeConfirm({ restoreFocus: false });
|
|
86
|
+
ui.selected = null;
|
|
87
|
+
ui.note = null;
|
|
88
|
+
ui.detail = null;
|
|
89
|
+
ui.landing = null;
|
|
90
|
+
ui.detailError = '';
|
|
91
|
+
ui.lit = null;
|
|
92
|
+
state.forgeLit = null;
|
|
93
|
+
touchScene();
|
|
94
|
+
render();
|
|
95
|
+
fn.paint();
|
|
96
|
+
if (had !== null) announce(`Pull request ${had} cleared`);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** What a screen reader hears when a pull request is selected */
|
|
100
|
+
function selectionWords() {
|
|
101
|
+
const { pull, files, checks } = ui.detail;
|
|
102
|
+
const mapped = ui.lit ? ui.lit.files.filter((f) => f.nodes.length).length : 0;
|
|
103
|
+
const lit = ui.lit ? new Set([...ui.lit.changed, ...ui.lit.failing]).size : 0;
|
|
104
|
+
return `Pull request ${pull.number}, ${pull.title}: ${plural(files.length, 'file')}, ${mapped} on the map${lit ? `, ${plural(lit, 'node')} lit` : ''}. ${checksWords(checks)}.`;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function itemHtml(item, before = '', after = '') {
|
|
108
|
+
if (ui.kind === 'deploys') return fn.deployHtml(item);
|
|
109
|
+
if (ui.kind === 'threads') return fn.threadHtml(item);
|
|
110
|
+
const link = safeUrl(item.url);
|
|
111
|
+
const labels = item.labels.length ? `<span class="hx-forge-labels">${item.labels.map((l) => `<span class="hx-forge-label" data-corn="tag">${escHtml(l)}</span>`).join('')}</span>` : '';
|
|
112
|
+
const inner = `<span class="hx-forge-title">${escHtml(item.title)}</span>
|
|
113
|
+
<span class="hx-forge-meta"><span class="hx-forge-state hx-forge-state--${escHtml(item.draft ? 'draft' : item.state)}" data-corn="state-pill"${cornStateAttr(item.draft ? 'draft' : item.state)}>${escHtml(stateWords(item))}</span> ${escHtml(metaWords(item, m.now()))}</span>${before}${after}${labels}`;
|
|
114
|
+
const out = link ? `<a data-corn="out-link" class="hx-forge-out" href="${escHtml(link)}" target="_blank" rel="noreferrer" aria-label="Open ${escHtml(item.head ? 'pull request' : 'issue')} ${item.number} on ${escHtml(fn.forgeName())} (new tab)">↗</a>` : '';
|
|
115
|
+
if (ui.kind !== 'issues') {
|
|
116
|
+
return `<li class="hx-forge-item"><button type="button" class="hx-forge-row" data-forge-pr="${item.number}" aria-pressed="${ui.selected === item.number}" data-corn="row">${inner}</button>${out}</li>`;
|
|
117
|
+
}
|
|
118
|
+
// An issue has no more to show here: its row is the link out; an open one also starts its spec (step 1 of the pipeline)
|
|
119
|
+
const spec = specBlock(item) === null
|
|
120
|
+
? `<button data-corn-kind="secondary" type="button" class="hx-btn hx-forge-act hx-forge-startspec" data-forge-spec="${item.number}" aria-label="Start a spec for issue ${item.number}"${ui.busy ? ' disabled' : ''}>Start a spec …</button>`
|
|
121
|
+
: '';
|
|
122
|
+
const agent = item.state === 'open'
|
|
123
|
+
? `<button data-corn-kind="secondary" type="button" class="hx-btn hx-forge-act hx-forge-startspec" data-forge-agent="issue:${item.number}" aria-label="${escHtml(t('startAgent'))} on issue ${item.number}">${escHtml(t('startAgent'))} …</button>`
|
|
124
|
+
: '';
|
|
125
|
+
return link
|
|
126
|
+
? `<li class="hx-forge-item"><a class="hx-forge-row" href="${escHtml(link)}" target="_blank" rel="noreferrer" data-corn="row">${inner}<span class="hx-sr-only"> (opens ${escHtml(fn.forgeName())} in a new tab)</span></a>${spec}${agent}</li>`
|
|
127
|
+
: `<li class="hx-forge-item"><div class="hx-forge-row" data-corn="row">${inner}</div>${spec}${agent}</li>`;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Which selection replaces the list now, as a key ('pr:12', 'thread:3', 'deploy:9004'), or '' while the list shows. A selection stays lit on the map but shows only on the tab it belongs to. */
|
|
131
|
+
function detailKey() {
|
|
132
|
+
if (ui.kind === 'threads' && ui.thread !== null) return `thread:${ui.thread}`;
|
|
133
|
+
if (ui.kind === 'deploys' && ui.deployItem) return `deploy:${ui.deploy}`;
|
|
134
|
+
if (ui.selected !== null && ui.kind === ui.selectedOn) return `pr:${ui.selected}`;
|
|
135
|
+
return '';
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function detailHtml() {
|
|
139
|
+
const shown = detailKey();
|
|
140
|
+
if (shown.startsWith('thread:')) return fn.threadDetailHtml();
|
|
141
|
+
if (shown.startsWith('deploy:')) return fn.deployDetailHtml();
|
|
142
|
+
if (!shown) return '';
|
|
143
|
+
const head = (title, meta) => `${backHtml('clear-forge-pr', ui.kind === 'work' ? 'All work' : 'All pull requests')}${meta || ''}<h3 class="hx-forge-detail-title" data-corn="detail-title">${title}</h3>`;
|
|
144
|
+
if (ui.detailError) return `${head(`Pull request ${ui.selected}`)}<p class="hx-forge-notice" data-corn="notice">${escHtml(ui.detailError)}</p>`;
|
|
145
|
+
if (!ui.detail) return `${head(`Pull request ${ui.selected}`)}<p class="hx-faint">Loading its files and checks …</p><ul class="hx-forge-list" aria-hidden="true">${loadingRowsHtml(4)}</ul>`;
|
|
146
|
+
const { pull, checks, stale } = ui.detail;
|
|
147
|
+
const lit = ui.lit;
|
|
148
|
+
const mapped = lit.files.filter((f) => f.nodes.length).length;
|
|
149
|
+
const url = safeUrl(pull.url);
|
|
150
|
+
const failing = new Map(lit.checks.map((c) => [c.check.id, c]));
|
|
151
|
+
|
|
152
|
+
const checkRows = checks.map((c) => {
|
|
153
|
+
const failed = failing.get(c.id);
|
|
154
|
+
const lights = failed
|
|
155
|
+
? `<span class="hx-faint hx-forge-lights">${failed.tests.length
|
|
156
|
+
? `Lights ${failed.tests.map((t) => `<code class="hx-code">${escHtml(t.path)}</code>${t.nodes.length ? '' : ' (not on the map)'}`).join(', ')}`
|
|
157
|
+
: 'Names no test file, so lights nothing'}</span>`
|
|
158
|
+
: '';
|
|
159
|
+
const name = safeUrl(c.url) ? `<a data-corn="text-link" class="hx-link" href="${escHtml(c.url)}" target="_blank" rel="noreferrer">${escHtml(c.name)}</a>` : `<span class="hx-name">${escHtml(c.name)}</span>`;
|
|
160
|
+
const why = rerunWhy(c, fn.forgeName());
|
|
161
|
+
const again = c.state === 'failure' && c.canRerun
|
|
162
|
+
? `<button data-corn-kind="secondary" type="button" class="hx-btn hx-forge-act" data-forge-rerun="${escHtml(c.id)}" aria-label="Re-run ${escHtml(c.name)}"${ui.busy ? ' disabled' : ''}>Re-run</button>`
|
|
163
|
+
: '';
|
|
164
|
+
const whyNot = why ? `<span class="hx-faint hx-forge-lights">${escHtml(why)}</span>` : '';
|
|
165
|
+
return `<li class="hx-forge-check"><span class="hx-forge-state hx-forge-state--${escHtml(c.state)}" data-corn="state-pill"${cornStateAttr(c.state)}>${stateIconHtml(c.state)}${escHtml(checkWords(c))}</span> ${name}${again}${lights}${whyNot}</li>`;
|
|
166
|
+
}).join('');
|
|
167
|
+
|
|
168
|
+
const fileRows = lit.files.map((f) => {
|
|
169
|
+
const nodes = f.nodes.length
|
|
170
|
+
? f.nodes.map((n) => `<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>`).join('')
|
|
171
|
+
: '<span class="hx-faint">not on the map</span>';
|
|
172
|
+
const renamed = f.status === 'renamed' && f.previousPath ? `<span class="hx-faint"> from ${escHtml(f.previousPath)}</span>` : '';
|
|
173
|
+
return `<li class="hx-forge-file" data-corn="file"><span class="hx-forge-fstatus">${escHtml(f.status)}</span> <code class="hx-code">${escHtml(f.path)}</code>${renamed} <span class="hx-good">+${f.additions}</span> <span class="hx-forge-del">−${f.deletions}</span><span class="hx-forge-nodes">${nodes}</span></li>`;
|
|
174
|
+
}).join('');
|
|
175
|
+
|
|
176
|
+
// Land it is the one primary action, with Open on the forge beside it; a pull request that cannot land says why in one line
|
|
177
|
+
const block = mergeBlock(ui.detail);
|
|
178
|
+
const land = block
|
|
179
|
+
? `<button type="button" class="hx-btn hx-btn--approve" disabled data-corn-kind="approve">${escHtml(t('landIt'))}</button>`
|
|
180
|
+
: `<button type="button" class="hx-btn hx-btn--approve hx-forge-act" data-forge-merge="${escHtml(String(pull.number))}"${ui.busy ? ' disabled' : ''} data-corn-kind="approve">${escHtml(t('landIt'))} …</button>`;
|
|
181
|
+
const act = `<div class="hx-forge-cta">${land}${url ? `<a data-corn="open-link" data-corn-kind="secondary" class="hx-btn hx-forge-open" href="${escHtml(url)}" target="_blank" rel="noreferrer">Open on ${escHtml(fn.forgeName())} ↗</a>` : ''}</div>${block ? `<p class="hx-forge-why hx-faint">${escHtml(block)}</p>` : ''}${approvalWarning(ui.detail) ? `<p class="hx-forge-why hx-faint" data-corn="notice" data-corn-state="waiting">${escHtml(approvalWarning(ui.detail))}</p>` : ''}`;
|
|
182
|
+
// A spec approved with `proposals.approveLands` waits for its checks: said here, with a way to stop it
|
|
183
|
+
const waiting = ui.landing && pull.state === 'open'
|
|
184
|
+
? `<div class="hx-forge-step"><p class="hx-forge-notice hx-forge-notice--ok" role="status" data-corn="notice" data-corn-state="success">${escHtml(landingWords(ui.landing, m.now()))}</p><button data-corn-kind="secondary" type="button" class="hx-btn hx-forge-act" data-forge-landing-cancel="${pull.number}"${ui.busy ? ' disabled' : ''}>Cancel</button></div>`
|
|
185
|
+
: '';
|
|
186
|
+
const note = ui.note ? `<p class="hx-forge-notice${ui.note.ok ? ' hx-forge-notice--ok' : ''}" data-corn="notice"${ui.note.ok ? ' data-corn-state="success"' : ''}>${escHtml(ui.note.text)}</p>` : '';
|
|
187
|
+
// Step 2 of the pipeline: a spec pull request with an approved proposal opens its build issue
|
|
188
|
+
const offers = buildOffers(ui.detail);
|
|
189
|
+
const build = offers.length
|
|
190
|
+
? `<h4 class="hx-forge-subact">Build issue</h4>${offers.map((o) => (o.offer
|
|
191
|
+
? `<div class="hx-forge-step"><button type="button" class="hx-btn hx-btn--approve hx-forge-act" data-forge-build="${escHtml(o.slug)}" aria-label="Open the build issue for ${escHtml(o.slug)}"${ui.busy ? ' disabled' : ''} data-corn-kind="approve">Open the build issue …</button><p class="hx-forge-why hx-faint"><code class="hx-code">${escHtml(o.slug)}</code> is approved. Opens a confirm step that shows the issue. Nothing is built.</p></div>`
|
|
192
|
+
: `<p class="hx-forge-why hx-faint"><code class="hx-code">${escHtml(o.slug)}</code>: ${escHtml(o.why)}</p>`)).join('')}`
|
|
193
|
+
: '';
|
|
194
|
+
|
|
195
|
+
const key = lit.changed.size || lit.failing.size
|
|
196
|
+
? `<p class="hx-forge-key hx-faint">${lit.changed.size ? '<span class="hx-mark-dot hx-mark-dot--changed" data-corn="mark-dot" data-corn-state="changed" aria-hidden="true"></span>a file this pull request changes ' : ''}${lit.failing.size ? '<span class="hx-mark-dot hx-mark-dot--removed" data-corn="mark-dot" data-corn-state="removed" aria-hidden="true"></span>a test a failing check names' : ''}</p>`
|
|
197
|
+
: '';
|
|
198
|
+
// Its run: who is running it, their state, the time and the cost (the runs are read for the Runs tab, and once for the first PR selected)
|
|
199
|
+
const runs = ui.runs && ui.runs.data ? ui.runs.data.runs : null;
|
|
200
|
+
const made = runOnPull(runs, pull.number);
|
|
201
|
+
const runSection = made
|
|
202
|
+
? `<h4 class="hx-forge-sub">Run</h4><p class="hx-forge-runline"${cornStateAttr(made.status)} data-corn="run">${runPillHtml({ esc: escHtml }, made, statusWords(made))} ${escHtml(pullRunWords(made, m.now(), { state: false }))}</p>`
|
|
203
|
+
: '';
|
|
204
|
+
const meta = `<p class="hx-forge-meta hx-forge-dmeta"><span class="hx-forge-state hx-forge-state--${escHtml(pull.draft ? 'draft' : pull.state)}" data-corn="state-pill"${cornStateAttr(pull.draft ? 'draft' : pull.state)}>${escHtml(stateWords(pull))}</span> <span data-corn="count">#${escHtml(String(pull.number))}</span> <span>${escHtml(pull.head.ref)} → ${escHtml(pull.base.ref)}</span> <span>${escHtml(pull.author ? pull.author.login : 'someone')}</span> <span>${escHtml(relativeTime(pull.createdAt || pull.updatedAt, m.now()))}</span></p>`;
|
|
205
|
+
return `${head(escHtml(pull.title), meta)}
|
|
206
|
+
${act}
|
|
207
|
+
${stale ? `<p class="hx-forge-notice" data-corn="notice">${escHtml(`This is an older answer. ${stale}`)}</p>` : ''}
|
|
208
|
+
${note}
|
|
209
|
+
${waiting}
|
|
210
|
+
${build}
|
|
211
|
+
<h4 class="hx-forge-sub">Checks: ${escHtml(checksWords(checks))}</h4>
|
|
212
|
+
${checks.length ? `<ul class="hx-forge-checks">${checkRows}</ul>` : ''}
|
|
213
|
+
<h4 class="hx-forge-sub">${escHtml(plural(lit.files.length, 'file'))} changed, ${mapped} on the map</h4>
|
|
214
|
+
${key}
|
|
215
|
+
<ul class="hx-forge-files">${fileRows}</ul>
|
|
216
|
+
${runSection}`;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** A node button, as in a pull request's files: it selects the node on the map */
|
|
220
|
+
const nodeButton = (n) => `<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>`;
|
|
221
|
+
|
|
222
|
+
/** What an action came to: said on the panel and through the live region, and everything is read again from the forge */
|
|
223
|
+
async function finishAction(action, res, n) {
|
|
224
|
+
const text = actionWords(action, res.status, res.body, n);
|
|
225
|
+
ui.busy = '';
|
|
226
|
+
ui.note = { text, ok: res.ok };
|
|
227
|
+
announce(text);
|
|
228
|
+
fn.paint();
|
|
229
|
+
if (res.status === null) return;
|
|
230
|
+
// The other tabs' answers are from before it: they are read again when next shown (the server let go of its own copies)
|
|
231
|
+
if (ui.kind === 'work') ui.lists = {};
|
|
232
|
+
else { ui.lists = { [fn.listKey()]: ui.lists[fn.listKey()] }; ui.work = null; }
|
|
233
|
+
// Whatever it came to (a refusal says the pull request is not what was shown), the panel looks again
|
|
234
|
+
if (ui.selected === n) await fn.refreshForge({ quiet: true });
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** Re-runs one failed check on the head that is shown */
|
|
238
|
+
async function rerunCheck(id) {
|
|
239
|
+
if (ui.busy || !ui.detail) return;
|
|
240
|
+
const { pull, checks } = ui.detail;
|
|
241
|
+
const check = checks.find((c) => c.id === id);
|
|
242
|
+
if (!check || check.state !== 'failure' || !check.canRerun) return;
|
|
243
|
+
ui.busy = `rerun:${id}`;
|
|
244
|
+
ui.note = null;
|
|
245
|
+
announce(`Re-running ${check.name}`);
|
|
246
|
+
fn.paint();
|
|
247
|
+
const res = await fn.post(actionUrl(pull.number, 'rerun'), { sha: pull.head.sha, check: id });
|
|
248
|
+
await finishAction('rerun', res, pull.number);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// what other parts put in the panel gets its parts (a hook is a part of the same name)
|
|
252
|
+
Object.assign(fn, { selectPull, loadLanding, cancelLanding, clearPull, selectionWords, itemHtml: (...a) => withParts(itemHtml(...a)), detailKey, detailHtml: (...a) => withParts(detailHtml(...a)), nodeButton: (n) => withParts(nodeButton(n)), finishAction, rerunCheck });
|
|
253
|
+
}
|
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/pieces/work-runs
|
|
3
|
+
*
|
|
4
|
+
* The Runs tab: the groups, a run, Stop, answer, the brief, the poll, and the runs 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 { WORK_URL, groupWork, filterGroups, groupWords, workStatus, markWords } from '../agents-model.js';
|
|
10
|
+
import { runsUrl, stopUrl, answerUrl, answerBody, answerWordsFor, runsStatus, runnerState, runnerWords, triggerNotice, totalsLines, handLines, stopWords, changeWords } from '../runs-model.js';
|
|
11
|
+
import { runsHtml, totalsHtml, loadingRowsHtml, loadingLinesHtml } from '../runs-view.js';
|
|
12
|
+
import { waiting } from '../waiting-model.js';
|
|
13
|
+
import { escapeHtml as escHtml } from '../../core/text.js';
|
|
14
|
+
import { safeUrl, RUNS_POLL_MS } from './work-common.js';
|
|
15
|
+
|
|
16
|
+
export function install(ctx) {
|
|
17
|
+
const { inst, ui, m, fn, state, root, $ } = ctx;
|
|
18
|
+
const { announce, t, sayResult, clearResult, resultOf, notSentWords, setRunsOnMap, setT, clearT } = ctx.h;
|
|
19
|
+
|
|
20
|
+
const groupsShown = () => (ui.work ? filterGroups(ui.work.grouped.groups, ui.workFilters) : []);
|
|
21
|
+
|
|
22
|
+
/** Loads the Agents tab: everything it groups, in one answer */
|
|
23
|
+
async function loadWork(refresh, token) {
|
|
24
|
+
ui.loading = true;
|
|
25
|
+
ui.error = '';
|
|
26
|
+
fn.paint();
|
|
27
|
+
const [res] = await Promise.all([fn.request(WORK_URL, refresh), loadRuns(refresh)]);
|
|
28
|
+
if (token !== m.listToken) return;
|
|
29
|
+
ui.loading = false;
|
|
30
|
+
if (res.ok) {
|
|
31
|
+
const b = res.body;
|
|
32
|
+
ui.work = { grouped: groupWork(b), problem: b.specsProblem || '', at: b.at, rate: b.rate || '', stale: b.stale || '' };
|
|
33
|
+
announce(`${workStatus(groupsShown(), '', m.now())}${ui.work.stale ? '. This is an older answer' : ''}`);
|
|
34
|
+
} else {
|
|
35
|
+
ui.error = fn.failWords(res, 'the work');
|
|
36
|
+
announce(ui.error);
|
|
37
|
+
}
|
|
38
|
+
fn.paint();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Loads the runs for the Agents tab (a refresh also has cornfield look at the forge for their reports first); a failure is a line, never a blank panel */
|
|
42
|
+
async function loadRuns(refresh, { say = true } = {}) {
|
|
43
|
+
const before = ui.runs && ui.runs.data ? ui.runs.data.runs : null;
|
|
44
|
+
const res = await fn.request(runsUrl(refresh), refresh);
|
|
45
|
+
ui.runs = res.ok && Array.isArray(res.body.runs) ? { data: res.body, error: '' } : { data: ui.runs && ui.runs.data, error: fn.failWords(res, 'the runs') };
|
|
46
|
+
fn.paintWaiting(); // the number follows the runs, whether or not the panel is open
|
|
47
|
+
if (!(ui.runs && ui.runs.data)) return;
|
|
48
|
+
// The map shows the open runs' nodes; a run lit on the map follows its nodes; what changed is said, once the first answer is in
|
|
49
|
+
setRunsOnMap(ui.runs.data.runs);
|
|
50
|
+
syncRunsPoll();
|
|
51
|
+
if (ui.runSel) relightRun();
|
|
52
|
+
const said = say ? changeWords(before, ui.runs.data.runs) : [];
|
|
53
|
+
// A runner appearing or going quiet is said once, when the state changes (the line itself is plain text, not a live region). The state last
|
|
54
|
+
// shown is kept, not worked out again from the last listing: a runner that goes quiet is the same listing judged later
|
|
55
|
+
const was = ui.runnerSaid;
|
|
56
|
+
const is = runnerState(ui.runs.data.runnerPresence, m.now());
|
|
57
|
+
ui.runnerSaid = is;
|
|
58
|
+
if (say && was && is && was !== is) said.push(runnerWords(ui.runs.data.runnerPresence, m.now()));
|
|
59
|
+
if (said.length) announce(said.join('. '));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Looks at the runs again in `RUNS_POLL_MS`, but only while one is open: a run's answer that has none open disarms it, and the next answer
|
|
64
|
+
* with one open (a run requested here, or a look from elsewhere) arms it again. One timer at most; never while the page is hidden or put
|
|
65
|
+
* away (`pagehide`). So the marks on the map and the words follow the runs.
|
|
66
|
+
*/
|
|
67
|
+
function syncRunsPoll() {
|
|
68
|
+
const open = !!(ui.runs && ui.runs.data && ui.runs.data.open > 0);
|
|
69
|
+
if (!open || m.pageAway) {
|
|
70
|
+
clearT(m.runsTimer);
|
|
71
|
+
m.runsTimer = 0;
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (m.runsTimer) return;
|
|
75
|
+
m.runsTimer = setT(async () => {
|
|
76
|
+
m.runsTimer = 0;
|
|
77
|
+
if (!(inst.hidden())) {
|
|
78
|
+
await loadRuns(false);
|
|
79
|
+
fn.paint();
|
|
80
|
+
}
|
|
81
|
+
syncRunsPoll();
|
|
82
|
+
}, RUNS_POLL_MS);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** The page is being put away (closed, or into the back-forward cache): no look until it is shown again */
|
|
86
|
+
function onPageHide() { m.pageAway = true; syncRunsPoll(); }
|
|
87
|
+
|
|
88
|
+
function onPageShow() { m.pageAway = false; syncRunsPoll(); }
|
|
89
|
+
|
|
90
|
+
/** One piece of work in a group: a pull request (a row that selects it, as in the Pull requests tab) or a branch with none */
|
|
91
|
+
function workHtml(e) {
|
|
92
|
+
const mark = e.mark ? `<span class="hx-forge-agentline"><span class="hx-forge-agent" title="Agent-made: ${escHtml(markWords(e.mark))}" data-corn="badge">Agent</span><span class="hx-forge-why hx-faint">${escHtml(markWords(e.mark))}</span></span>` : '';
|
|
93
|
+
if (e.type === 'pull') {
|
|
94
|
+
const also = e.issues.slice(1);
|
|
95
|
+
const note = [e.proposal ? `Spec PR for ${e.proposal}` : '', also.length ? `Also closes ${also.map((n) => `#${n}`).join(', ')}` : ''].filter(Boolean);
|
|
96
|
+
return fn.itemHtml(e.pull, mark, note.length ? `<span class="hx-forge-meta">${escHtml(note.join(' · '))}</span>` : '');
|
|
97
|
+
}
|
|
98
|
+
return `<li class="hx-forge-item"><div class="hx-forge-row hx-forge-branch" data-corn="row"><span class="hx-forge-title"><span class="hx-sr-only">Branch </span><code class="hx-code">${escHtml(e.branch.name)}</code></span><span class="hx-forge-meta"><span class="hx-forge-state hx-forge-state--draft" data-corn="state-pill" data-corn-state="draft">Branch</span> no pull request yet</span>${mark}</div></li>`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** The Agents tab's groups, each a heading and its work */
|
|
102
|
+
function groupsHtml(groups) {
|
|
103
|
+
return groups.map((g, i) => {
|
|
104
|
+
const link = g.issue && safeUrl(g.issue.url) ? ` <a data-corn="text-link" class="hx-link hx-forge-gout" href="${escHtml(g.issue.url)}" target="_blank" rel="noreferrer" aria-label="Open issue ${g.number} on ${escHtml(fn.forgeName())} (new tab)">↗</a>` : '';
|
|
105
|
+
const startRef = g.kind === 'issue' && g.issue && g.issue.state === 'open' ? `issue:${g.number}` : g.kind === 'proposal' ? `proposal:${g.slug}` : null;
|
|
106
|
+
const start = startRef ? ` <button data-corn-kind="secondary" type="button" class="hx-btn hx-forge-act" data-forge-agent="${escHtml(startRef)}" aria-label="${escHtml(t('startAgent'))} on ${escHtml(g.kind === 'issue' ? `issue ${g.number}` : `proposal ${g.slug}`)}">${escHtml(t('startAgent'))} …</button>` : '';
|
|
107
|
+
return `<li class="hx-forge-group"><h3 class="hx-forge-gtitle" id="forge-group-${i}">${escHtml(g.title)}${link}</h3>${start}<p class="hx-forge-meta">${escHtml(groupWords(g))}</p><ul class="hx-forge-list" aria-labelledby="forge-group-${i}">${g.entries.map(workHtml).join('')}</ul></li>`;
|
|
108
|
+
}).join('');
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** The runs of the Agents tab: state, what each is about, links, and Stop. A runner's words are escaped like any text from the forge. */
|
|
112
|
+
function paintRuns() {
|
|
113
|
+
const box = $('forge-runs');
|
|
114
|
+
if (!box) return;
|
|
115
|
+
box.hidden = ui.kind !== 'work' || !!fn.detailKey();
|
|
116
|
+
if (box.hidden) return;
|
|
117
|
+
const data = ui.runs && ui.runs.data;
|
|
118
|
+
$('forge-runs-status').textContent = data ? runsStatus(data) : ui.loading ? 'Loading the runs …' : '';
|
|
119
|
+
const note = $('forge-runs-note');
|
|
120
|
+
const failed = ui.runs && ui.runs.error;
|
|
121
|
+
const words = failed || (ui.runNote ? ui.runNote.text : '');
|
|
122
|
+
note.className = `hx-forge-notice${!failed && ui.runNote && ui.runNote.ok ? ' hx-forge-notice--ok' : ''}`;
|
|
123
|
+
if (!failed && ui.runNote && ui.runNote.ok) note.dataset.cornState = 'success'; else delete note.dataset.cornState;
|
|
124
|
+
fn.setNotice(note, words, !!failed);
|
|
125
|
+
paintRunner('forge-runs-runner', data);
|
|
126
|
+
const waiting = !data && !failed && !!ui.loading; // the runner line and the totals hold their place while the runs load (not beside a failure)
|
|
127
|
+
if (waiting) { const r = $('forge-runs-runner'); r.hidden = false; r.innerHTML = loadingLinesHtml(1); }
|
|
128
|
+
const trig = $('forge-runs-trigger');
|
|
129
|
+
if (trig) {
|
|
130
|
+
const skipped = data ? triggerNotice(data) : '';
|
|
131
|
+
trig.hidden = !skipped;
|
|
132
|
+
trig.textContent = skipped;
|
|
133
|
+
}
|
|
134
|
+
const totals = $('forge-runs-totals');
|
|
135
|
+
if (totals) {
|
|
136
|
+
const lines = data ? totalsLines(data.totals) : [];
|
|
137
|
+
totals.hidden = !lines.length && !waiting;
|
|
138
|
+
totals.innerHTML = waiting ? loadingLinesHtml(3) : totalsHtml(viewContext(), lines);
|
|
139
|
+
}
|
|
140
|
+
const hand = $('forge-runs-hand');
|
|
141
|
+
if (hand) {
|
|
142
|
+
const lines = data ? handLines(data) : [];
|
|
143
|
+
hand.hidden = !lines.length;
|
|
144
|
+
hand.innerHTML = lines.map((l) => `<li>${escHtml(l)}</li>`).join('');
|
|
145
|
+
}
|
|
146
|
+
const list = $('forge-runs-list');
|
|
147
|
+
list.setAttribute('aria-busy', String(!data && !!ui.loading));
|
|
148
|
+
if (!data) { list.innerHTML = ui.loading ? loadingRowsHtml(3) : ''; return; }
|
|
149
|
+
patchList(list, data.runs.length ? runsHtml(viewContext(), data.runs) : '<li class="hx-forge-empty hx-faint" data-corn="empty">No agent has been asked for yet. Start one from an issue or a proposal: Issues, then Start an agent.</li>');
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Draws a list again without disturbing what the person is doing in it. The new rows are made first and set against the old by their key
|
|
154
|
+
* (a run's id, a compare group's): a row that has not changed is left alone, a row that has is replaced, and **a row that holds the focus in
|
|
155
|
+
* a field, or a reply typed and not sent, is kept as it is** (its result line is the one part brought up to date), so the caret, the
|
|
156
|
+
* selection, the focus and the text stay where they were. A row whose field is no longer asked for is replaced like any other.
|
|
157
|
+
*/
|
|
158
|
+
function patchList(list, html) {
|
|
159
|
+
const tpl = inst.doc.createElement('template');
|
|
160
|
+
tpl.innerHTML = withParts(html);
|
|
161
|
+
const fresh = [...tpl.content.children];
|
|
162
|
+
const keyOf = (el) => el.dataset.key || el.dataset.run || null;
|
|
163
|
+
const old = new Map([...list.children].filter((el) => keyOf(el)).map((el) => [keyOf(el), el]));
|
|
164
|
+
const typing = (el) => el.contains(inst.active()) && inst.active().matches('input, textarea');
|
|
165
|
+
const redraw = new Set(m.redrawRuns); // runs the page has just acted on: their cards say what the action did, so they are drawn anew (the focus is put back by hand)
|
|
166
|
+
m.redrawRuns.clear();
|
|
167
|
+
const unsent = (el) => [...el.querySelectorAll('[data-run-reply]')].some((f) => f.value !== '');
|
|
168
|
+
const target = fresh.map((f) => {
|
|
169
|
+
const was = keyOf(f) && old.get(keyOf(f));
|
|
170
|
+
if (!was) return f;
|
|
171
|
+
if (was.outerHTML === f.outerHTML) return was;
|
|
172
|
+
const field = was.querySelector('[data-run-reply]');
|
|
173
|
+
const twin = field && f.querySelector(`[data-run-reply="${field.dataset.runReply}"]`);
|
|
174
|
+
if (!redraw.has(keyOf(f)) && (typing(was) || unsent(was)) && twin) {
|
|
175
|
+
// The field stays (the very element, never taken out of the page, so the focus, caret, selection and a phone's keyboard stay);
|
|
176
|
+
// everything around it is the new card's, so a state that changed is shown (graftAround)
|
|
177
|
+
const theirs = twin.getAttribute('value') || '';
|
|
178
|
+
graftAround(was, field, twin);
|
|
179
|
+
// The typed text is in `ui.runReplies` as well, always (every keystroke); a field that differs from it was changed by the page itself
|
|
180
|
+
if (field.value !== theirs) field.value = theirs;
|
|
181
|
+
return was;
|
|
182
|
+
}
|
|
183
|
+
return f;
|
|
184
|
+
});
|
|
185
|
+
target.forEach((node, i) => {
|
|
186
|
+
const at = list.children[i];
|
|
187
|
+
if (at === node) return;
|
|
188
|
+
if (at && keyOf(at) && keyOf(at) === keyOf(node)) at.replaceWith(node); else list.insertBefore(node, at || null);
|
|
189
|
+
});
|
|
190
|
+
while (list.children.length > target.length) list.lastElementChild.remove();
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Makes `root` (an old row) what `fresh` (its new drawing) is, except that `keep` (inside `root`) stays the same element in the same place,
|
|
195
|
+
* standing for `twin` (its match inside `fresh`): at each level from `keep` up to `root`, the parent takes the new parent's attributes and
|
|
196
|
+
* children, with the kept branch in its place. `keep` itself is never taken out of the page.
|
|
197
|
+
*/
|
|
198
|
+
function graftAround(root, keep, twin) {
|
|
199
|
+
const sync = (to, from) => {
|
|
200
|
+
for (const a of [...to.attributes]) if (!from.hasAttribute(a.name) && a.name !== 'value') to.removeAttribute(a.name);
|
|
201
|
+
for (const a of [...from.attributes]) if (a.name !== 'value' && to.getAttribute(a.name) !== a.value) to.setAttribute(a.name, a.value);
|
|
202
|
+
};
|
|
203
|
+
sync(keep, twin);
|
|
204
|
+
let w = keep;
|
|
205
|
+
let f = twin;
|
|
206
|
+
while (w !== root && w.parentElement && f.parentElement) {
|
|
207
|
+
const wp = w.parentElement;
|
|
208
|
+
const fp = f.parentElement;
|
|
209
|
+
sync(wp, fp);
|
|
210
|
+
const kids = [...fp.childNodes];
|
|
211
|
+
const at = kids.indexOf(f);
|
|
212
|
+
for (const n of [...wp.childNodes]) if (n !== w) n.remove();
|
|
213
|
+
for (const n of kids.slice(0, at)) wp.insertBefore(n, w);
|
|
214
|
+
for (const n of kids.slice(at + 1)) wp.append(n);
|
|
215
|
+
w = wp;
|
|
216
|
+
f = fp;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** Whether a run would wait for a runner that is not there (pull transport only; issue #183, spec 0007 D1) */
|
|
221
|
+
function runnerAway() {
|
|
222
|
+
const data = ui.runs && ui.runs.data;
|
|
223
|
+
const state = data ? runnerState(data.runnerPresence, m.now()) : null;
|
|
224
|
+
return state === 'offline' || state === 'none';
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** The Start dialog's button: "Ask the runner", or "Queue it (no runner online)" while no runner polls, so the click says what it does */
|
|
228
|
+
function askRunnerWords() {
|
|
229
|
+
return runnerAway() ? `${t('queueIt')} (no runner online)` : t('askRunner');
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* The one line on whether a runner is polling (pull transport only), in the Runs view and the Start dialog; hidden where it does not apply.
|
|
234
|
+
* While no runner is online it is a notice at the top of the view, not the faint line: a run asked for would wait (issue #183).
|
|
235
|
+
*/
|
|
236
|
+
function paintRunner(id, data) {
|
|
237
|
+
const el = $(id);
|
|
238
|
+
if (!el) return;
|
|
239
|
+
const words = data ? runnerWords(data.runnerPresence, m.now()) : '';
|
|
240
|
+
el.hidden = !words;
|
|
241
|
+
el.textContent = words;
|
|
242
|
+
const state = data ? runnerState(data.runnerPresence, m.now()) : null;
|
|
243
|
+
const away = state === 'offline' || state === 'none';
|
|
244
|
+
el.className = away ? 'hx-forge-notice' : 'hx-forge-meta';
|
|
245
|
+
if (away) { el.dataset.corn = 'notice'; el.setAttribute('part', 'notice'); el.dataset.cornState = 'waiting'; } else { delete el.dataset.corn; el.removeAttribute('part'); delete el.dataset.cornState; }
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** What the Runs view needs to know of the page */
|
|
249
|
+
function viewContext() {
|
|
250
|
+
const f = ui.config && ui.config.forge;
|
|
251
|
+
const base = f && safeUrl(f.url) ? f.url.replace(/\/+$/, '') : null;
|
|
252
|
+
return {
|
|
253
|
+
esc: escHtml, t, safeUrl, forgeName: fn.forgeName(), forgeType: f ? f.type : 'github', repoUrl: base && f.repo ? `${base}/${f.repo}` : null,
|
|
254
|
+
now: m.now(), nodes: state.nodes, selected: ui.runSel, timelines: ui.runTimelines, replies: ui.runReplies, busy: !!ui.busy,
|
|
255
|
+
results: { get: (id) => resultOf(id) },
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const runById = (id) => ((ui.runs && ui.runs.data && ui.runs.data.runs) || []).find((r) => r.runId === id) || null;
|
|
260
|
+
|
|
261
|
+
/** The nodes of a selected run, worked out again (the runs were read again, or the map changed) */
|
|
262
|
+
function relightRun() {
|
|
263
|
+
if (!runById(ui.runSel)) ui.runSel = null;
|
|
264
|
+
fn.relight();
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/** Lights the nodes of a run on the map, like a pull request; the same button lets go of it */
|
|
268
|
+
function selectRun(id) {
|
|
269
|
+
const run = runById(id);
|
|
270
|
+
if (!run) return;
|
|
271
|
+
if (ui.runSel === id) {
|
|
272
|
+
ui.runSel = null;
|
|
273
|
+
fn.relight();
|
|
274
|
+
announce(`Run ${id} no longer lit on the map`);
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
const had = ui.runSel;
|
|
278
|
+
m.pullToken++;
|
|
279
|
+
fn.dropThread();
|
|
280
|
+
Object.assign(ui, { selected: null, detail: null, detailError: '', lit: null, landing: null, note: null, deploy: null, deployItem: null, litDeploy: null });
|
|
281
|
+
ui.runSel = id;
|
|
282
|
+
fn.relight();
|
|
283
|
+
const n = (run.nodes || []).length;
|
|
284
|
+
announce(n ? `Run ${id}: ${n} ${n === 1 ? 'node' : 'nodes'} lit on the map${had ? '' : ''}` : `Run ${id} has no node on the map yet`);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/** Opens or closes the timeline of a run (it stays open when the list is drawn again) */
|
|
288
|
+
function toggleTimeline(id) {
|
|
289
|
+
if (ui.runTimelines.has(id)) ui.runTimelines.delete(id); else ui.runTimelines.add(id);
|
|
290
|
+
fn.paint();
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/** Gives the focus to the first of `selectors` that is there and not disabled, inside the card of a run (else the card itself) */
|
|
294
|
+
function focusInRun(runId, selectors) {
|
|
295
|
+
const panel = $('forge-panel');
|
|
296
|
+
const card = panel && [...panel.querySelectorAll('[data-run]')].find((c) => c.dataset.run === runId);
|
|
297
|
+
if (!card) return;
|
|
298
|
+
const to = selectors.map((sel) => card.querySelector(sel)).find((el) => el && !el.disabled) || card;
|
|
299
|
+
if (to !== inst.active()) to.focus();
|
|
300
|
+
if (to.matches('input') && typeof to.setSelectionRange === 'function') to.setSelectionRange(to.value.length, to.value.length); // typing goes on at the end of what is there
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/** Lets go of a reply that was not sent because its run stopped waiting: the field goes, and the focus goes to the run's card */
|
|
304
|
+
function discardReply(runId) {
|
|
305
|
+
ui.runReplies.delete(runId);
|
|
306
|
+
m.redrawRuns.add(runId);
|
|
307
|
+
fn.paint();
|
|
308
|
+
focusInRun(runId, []);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/** Asks a run to stop: one POST, then the runs are read again. What it came to is said in the run's own card, and to a screen reader */
|
|
312
|
+
async function stopRun(runId) {
|
|
313
|
+
if (ui.busy) return;
|
|
314
|
+
ui.busy = 'stop';
|
|
315
|
+
ui.runNote = null;
|
|
316
|
+
clearResult(runId);
|
|
317
|
+
announce('Asking this run to stop'); // the focus is in the run's card, whose controls name it
|
|
318
|
+
fn.paint();
|
|
319
|
+
const res = await fn.post(stopUrl(runId), {});
|
|
320
|
+
ui.busy = '';
|
|
321
|
+
sayResult(runId, res.status === null ? notSentWords('The stop request') : stopWords(res.status, res.body, 'this run'), res.ok);
|
|
322
|
+
await loadRuns(false, { say: false });
|
|
323
|
+
m.redrawRuns.add(runId);
|
|
324
|
+
fn.paint();
|
|
325
|
+
// The Stop button is gone once the stop is asked for: the focus goes to the run's row, never to the page
|
|
326
|
+
focusInRun(runId, [`[data-forge-stop="${runId}"]`]);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** Answers a waiting run: Continue, Stop, or a reply with the text typed. One POST, then the runs are read again */
|
|
330
|
+
async function answerRun(runId, action) {
|
|
331
|
+
if (ui.busy) return;
|
|
332
|
+
const text = ui.runReplies.get(runId) || '';
|
|
333
|
+
clearResult(runId);
|
|
334
|
+
if (action === 'reply' && text.trim() === '') {
|
|
335
|
+
sayResult(runId, 'Write a reply first.', false);
|
|
336
|
+
fn.paint();
|
|
337
|
+
focusInRun(runId, [`[data-run-reply="${runId}"]`]);
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
// Where the focus goes back to once it is sent: the reply field after a reply (empty, for the next one), the button after Continue; while the
|
|
341
|
+
// buttons are disabled the focus has nowhere to stay, so it is put back by hand. A run that no longer asks (a Stop) gets its Timeline button
|
|
342
|
+
const back = action === 'reply' ? `[data-run-reply="${runId}"]` : `[data-run-answer="${action}"][data-run-id="${runId}"]`;
|
|
343
|
+
ui.busy = 'answer';
|
|
344
|
+
ui.runNote = null;
|
|
345
|
+
announce(action === 'reply' ? 'Sending your reply' : 'Sending your answer');
|
|
346
|
+
fn.paint();
|
|
347
|
+
const res = await fn.post(answerUrl(runId), answerBody(action, text));
|
|
348
|
+
ui.busy = '';
|
|
349
|
+
if (res.ok && action === 'reply') ui.runReplies.delete(runId); // sent: the field is empty for the next; a reply that was not sent stays as it was typed
|
|
350
|
+
const words = res.status === null ? notSentWords(action === 'reply' ? 'Your reply' : 'The answer') : answerWordsFor(res.status, res.body, 'this run', action);
|
|
351
|
+
sayResult(runId, words, res.ok);
|
|
352
|
+
await loadRuns(false, { say: false });
|
|
353
|
+
m.redrawRuns.add(runId);
|
|
354
|
+
fn.paint();
|
|
355
|
+
focusInRun(runId, [back, `[data-run-timeline="${runId}"]`]);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/** Answer, on the proposal bar's line: Work opens on Runs at that run with its reply field focused */
|
|
359
|
+
async function answerFromBar(id) {
|
|
360
|
+
if (!(await openRunLink(id))) return;
|
|
361
|
+
const field = $('forge-runs-list').querySelector(`[data-run-reply="${id}"]`);
|
|
362
|
+
if (field) field.focus();
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/** Takes the person to another run of the list: the row scrolls into view and has the focus */
|
|
366
|
+
function goToRun(runId) {
|
|
367
|
+
fn.bringIntoView([...root.querySelectorAll('#forge-runs-list [data-run]')].find((r) => r.dataset.run === runId));
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/** `?run=<runId>`: the Agents tab with that run lit and in view. A run that is not there is said, never a blank panel. */
|
|
371
|
+
async function openRunLink(id) {
|
|
372
|
+
if (!ui.config) return false;
|
|
373
|
+
await fn.openTab('work');
|
|
374
|
+
if (!(ui.runs && ui.runs.data)) await loadRuns(false, { say: false });
|
|
375
|
+
let run = runById(id);
|
|
376
|
+
// A run asked for a moment ago may not be in what was read before: ask once more, past the cache
|
|
377
|
+
if (!run && ui.runs && ui.runs.data) { await loadRuns(true, { say: false }); run = runById(id); }
|
|
378
|
+
if (!run) return fn.linkMissing(ui.runs && ui.runs.data ? `There is no run ${id}.` : (ui.runs && ui.runs.error) || 'The runs could not be read.');
|
|
379
|
+
if (ui.runSel !== id) selectRun(id);
|
|
380
|
+
fn.paint();
|
|
381
|
+
fn.bringIntoView($('forge-runs-list').querySelector(`[data-run="${id}"]`));
|
|
382
|
+
announce(`Run ${id}, in the Runs view`);
|
|
383
|
+
return true;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
Object.assign(fn, { groupsShown, loadWork, loadRuns, syncRunsPoll, onPageHide, onPageShow, workHtml: (...a) => withParts(workHtml(...a)), groupsHtml: (...a) => withParts(groupsHtml(...a)), paintRuns, patchList, graftAround, runnerAway, askRunnerWords, paintRunner, viewContext, runById, relightRun, selectRun, toggleTimeline, focusInRun, discardReply, stopRun, answerRun, answerFromBar, goToRun, openRunLink });
|
|
387
|
+
}
|