@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.
- package/explorer/css/review.css +49 -0
- package/explorer/decision-model.js +6 -0
- package/explorer/engine/layout.js +8 -3
- package/explorer/engine/sheets.js +40 -7
- package/explorer/engine/topology.js +126 -0
- 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 +21 -2
- package/explorer/page-pieces.js +21 -2
- package/explorer/page.js +3 -3
- package/explorer/panels.js +1 -5
- package/explorer/pieces/changes.js +2 -9
- package/explorer/pieces/decision.js +10 -3
- package/explorer/pieces/layers.js +1 -0
- package/explorer/pieces/map.js +4 -23
- package/explorer/pieces/node-panel.js +15 -5
- package/explorer/pieces/proposal.js +9 -0
- package/explorer/pieces/review.js +280 -0
- 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.js +1 -2
- package/explorer/runs-map.js +108 -103
- package/explorer/runs-view.js +8 -6
- package/explorer/strings.js +1 -1
- package/explorer/view.js +6 -59
- 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,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/pieces/work-notes
|
|
3
|
+
*
|
|
4
|
+
* Release notes: the draft for a tag, Copy, and Post as draft. 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 { DRAFTS_URL, notesUrl, sinceChoices, notesSummary, validTag, confirmWords, postedWords, draftRequest } from '../forge-panel-model.js';
|
|
9
|
+
import { safeUrl, option } from './work-common.js';
|
|
10
|
+
|
|
11
|
+
export function install(ctx) {
|
|
12
|
+
const { inst, ui, m, fn, $ } = ctx;
|
|
13
|
+
const { announce } = ctx.h;
|
|
14
|
+
|
|
15
|
+
/** Loads the draft for the tag chosen (again, past the server's cache, on a refresh) */
|
|
16
|
+
async function loadNotes(refresh = false) {
|
|
17
|
+
const token = ++m.notesToken;
|
|
18
|
+
const n = ui.notes;
|
|
19
|
+
n.loading = true;
|
|
20
|
+
n.error = '';
|
|
21
|
+
n.message = '';
|
|
22
|
+
closeNotesConfirm(false);
|
|
23
|
+
fn.paint();
|
|
24
|
+
const res = await fn.request(notesUrl(n.since), refresh);
|
|
25
|
+
if (token !== m.notesToken) return;
|
|
26
|
+
n.loading = false;
|
|
27
|
+
if (res.ok) {
|
|
28
|
+
n.data = res.body;
|
|
29
|
+
announce(`Release notes drafted. ${notesSummary(n.data)}${n.data.stale ? ' This is an older answer' : ''}`);
|
|
30
|
+
} else {
|
|
31
|
+
n.error = fn.failWords(res, 'the release notes');
|
|
32
|
+
announce(n.error);
|
|
33
|
+
}
|
|
34
|
+
fn.paint();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Says something about the last Copy or Post, on the page and to a screen reader */
|
|
38
|
+
function say(words, bad = false, link = null) {
|
|
39
|
+
ui.notes.message = words;
|
|
40
|
+
ui.notes.bad = bad;
|
|
41
|
+
ui.notes.link = link;
|
|
42
|
+
paintNotes();
|
|
43
|
+
announce(words);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Copies the draft: the clipboard, else the text selected for the person to copy */
|
|
47
|
+
async function copyNotes() {
|
|
48
|
+
const data = ui.notes.data;
|
|
49
|
+
if (!data) return;
|
|
50
|
+
try {
|
|
51
|
+
if (inst.win.navigator.clipboard && inst.win.navigator.clipboard.writeText) {
|
|
52
|
+
await inst.win.navigator.clipboard.writeText(data.markdown);
|
|
53
|
+
say('Copied the release notes.');
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
} catch { /* blocked: try the old way */ }
|
|
57
|
+
const area = $('notes-preview');
|
|
58
|
+
area.focus();
|
|
59
|
+
area.select();
|
|
60
|
+
let copied = false;
|
|
61
|
+
try { copied = typeof inst.doc.execCommand === 'function' && inst.doc.execCommand('copy'); } catch { copied = false; }
|
|
62
|
+
say(copied ? 'Copied the release notes.' : 'Copying was blocked. The draft is selected: press Ctrl+C, or Command+C on a Mac.', !copied);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** The confirm step: what will happen in words, and the tag to ask for (the one the server suggests, to change) */
|
|
66
|
+
function openNotesConfirm() {
|
|
67
|
+
const n = ui.notes;
|
|
68
|
+
if (!n.data || n.posting) return;
|
|
69
|
+
if (!n.data.count) { say('There are no merged pull requests to put in a draft.', true); return; }
|
|
70
|
+
n.confirm = true;
|
|
71
|
+
n.message = '';
|
|
72
|
+
$('notes-tag').value = n.data.suggestedTag || '';
|
|
73
|
+
paintNotes();
|
|
74
|
+
$('notes-tag').focus();
|
|
75
|
+
announce('Post as a draft release. Check the tag, then create the draft.');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Closes the confirm step; the focus goes back to the button that opened it unless told not to */
|
|
79
|
+
function closeNotesConfirm(restoreFocus = true) {
|
|
80
|
+
const n = ui.notes;
|
|
81
|
+
if (!n.confirm) return;
|
|
82
|
+
n.confirm = false;
|
|
83
|
+
paintNotes();
|
|
84
|
+
if (restoreFocus) $('notes-post').focus();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** The one write: asks the server to have the forge keep the notes as a draft release for the tag typed */
|
|
88
|
+
async function postDraft() {
|
|
89
|
+
const n = ui.notes;
|
|
90
|
+
if (!n.confirm || n.posting || !n.data) return;
|
|
91
|
+
const tag = $('notes-tag').value.trim();
|
|
92
|
+
if (!validTag(tag)) { say('Give the tag the draft is for, like v0.2.0: letters, digits, dots, dashes and slashes, no spaces.', true); $('notes-tag').focus(); return; }
|
|
93
|
+
n.posting = true;
|
|
94
|
+
n.message = '';
|
|
95
|
+
paintNotes();
|
|
96
|
+
announce('Creating the draft release');
|
|
97
|
+
const res = await fn.request(DRAFTS_URL, false, draftRequest(tag, n.since));
|
|
98
|
+
n.posting = false;
|
|
99
|
+
if (res.ok) {
|
|
100
|
+
n.confirm = false;
|
|
101
|
+
say(postedWords({ forge: fn.forgeName(), tag, count: res.body.count }), false, res.body.release && res.body.release.url);
|
|
102
|
+
$('notes-post').focus();
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
say(res.status === 401 ? 'Your sign-in has ended. Sign in again to post a draft.' : fn.failWords(res), true);
|
|
106
|
+
$('notes-tag').focus();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** The Release notes view, from `ui.notes`; the typed tag and the focus are left alone */
|
|
110
|
+
function paintNotes() {
|
|
111
|
+
const n = ui.notes;
|
|
112
|
+
const data = n.data;
|
|
113
|
+
const since = $('notes-since');
|
|
114
|
+
// The choices are drawn again only when they change, so the select keeps the focus while a draft is loaded for it
|
|
115
|
+
const choices = (data ? sinceChoices(data) : [['', 'Latest tag']]).map(([v, l]) => option(v, l, false)).join('');
|
|
116
|
+
if (since.dataset.choices !== choices) { since.innerHTML = choices; since.dataset.choices = choices; }
|
|
117
|
+
since.value = n.since;
|
|
118
|
+
const area = $('notes-preview');
|
|
119
|
+
if (area.value !== (data ? data.markdown : '')) area.value = data ? data.markdown : '';
|
|
120
|
+
$('notes-copy').disabled = !data;
|
|
121
|
+
$('notes-post').disabled = !data;
|
|
122
|
+
$('notes-post').setAttribute('aria-expanded', String(n.confirm));
|
|
123
|
+
const confirm = $('notes-confirm');
|
|
124
|
+
confirm.hidden = !n.confirm;
|
|
125
|
+
if (n.confirm && data) {
|
|
126
|
+
$('notes-confirm-words').textContent = confirmWords({ forge: fn.forgeName(), repo: ui.config.forge.repo, tag: '', count: data.count });
|
|
127
|
+
$('notes-confirm-yes').textContent = n.posting ? 'Creating …' : 'Create the draft';
|
|
128
|
+
}
|
|
129
|
+
const message = $('notes-message');
|
|
130
|
+
message.hidden = !n.message;
|
|
131
|
+
message.classList.toggle('hx-forge-msg--bad', n.bad);
|
|
132
|
+
if (n.bad) message.dataset.cornState = 'failure'; else delete message.dataset.cornState;
|
|
133
|
+
message.textContent = n.message;
|
|
134
|
+
if (n.message && n.link && safeUrl(n.link)) {
|
|
135
|
+
const link = inst.doc.createElement('a');
|
|
136
|
+
link.className = 'hx-link';
|
|
137
|
+
link.dataset.corn = 'text-link';
|
|
138
|
+
link.href = n.link;
|
|
139
|
+
link.target = '_blank';
|
|
140
|
+
link.rel = 'noreferrer';
|
|
141
|
+
link.textContent = `Open the draft on ${fn.forgeName()} (new tab)`;
|
|
142
|
+
message.append(' ', link);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** The panel's lines for the Release notes view: the status, a failure, the rate limit; the rest is paintNotes */
|
|
147
|
+
function drawNotes() {
|
|
148
|
+
const n = ui.notes;
|
|
149
|
+
$('forge-status').textContent = n.loading && !n.data ? `Drafting the release notes from ${fn.forgeName()} …` : n.data ? notesSummary(n.data) : '';
|
|
150
|
+
const notice = $('forge-notice');
|
|
151
|
+
const words = n.error || (n.data && n.data.stale ? `Showing an older answer. ${n.data.stale}` : '');
|
|
152
|
+
fn.setNotice(notice, words, !!words);
|
|
153
|
+
$('forge-detail').hidden = true;
|
|
154
|
+
fn.paintIdea();
|
|
155
|
+
$('forge-rate').textContent = (n.data && n.data.rate) || '';
|
|
156
|
+
paintNotes();
|
|
157
|
+
fn.paintButton();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** The Release notes view, from the PRs list: its own page with a way back */
|
|
161
|
+
function openNotes() {
|
|
162
|
+
ui.kind = 'notes';
|
|
163
|
+
ui.actNote = null;
|
|
164
|
+
if (ui.notes.data || ui.notes.loading) { fn.paint(); announce(`Release notes. ${ui.notes.data ? notesSummary(ui.notes.data) : ''}`); } else loadNotes();
|
|
165
|
+
$('notes-title').focus();
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** Back from the Release notes to the PRs list, the focus on the button that opened them */
|
|
169
|
+
function closeNotes() {
|
|
170
|
+
ui.kind = 'pulls';
|
|
171
|
+
fn.paint();
|
|
172
|
+
$('notes-open').focus();
|
|
173
|
+
announce('All pull requests');
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
Object.assign(fn, { loadNotes, say, copyNotes, openNotesConfirm, closeNotesConfirm, postDraft, paintNotes, drawNotes, openNotes, closeNotes });
|
|
177
|
+
}
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/pieces/work-paint
|
|
3
|
+
*
|
|
4
|
+
* Drawing the panel from its state: tabs, counts, filters, the list, the detail, the Work button. 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 { addParts } from '../engine/piece.js';
|
|
9
|
+
import { workStatus } from '../agents-model.js';
|
|
10
|
+
import { loadingRowsHtml } from '../runs-view.js';
|
|
11
|
+
import { STATES, defaultFilters, filterItems, facetsOf, emptyWords } from '../forge-panel-model.js';
|
|
12
|
+
import { relativeTime } from '../review-model.js';
|
|
13
|
+
import { waiting, specGroups, workButtonName, waitingWords, runWaitingOn } from '../waiting-model.js';
|
|
14
|
+
import { specGroupsHtml } from '../waiting-view.js';
|
|
15
|
+
import { escapeHtml as escHtml } from '../../core/text.js';
|
|
16
|
+
import { plural, safeUrl, option } from './work-common.js';
|
|
17
|
+
|
|
18
|
+
export function install(ctx) {
|
|
19
|
+
const { inst, ui, m, fn, state, root, $ } = ctx;
|
|
20
|
+
const { t, refreshStubs, paintWaitingLine } = ctx.h;
|
|
21
|
+
|
|
22
|
+
/** How to find an element of the panel again after it is drawn anew, or null */
|
|
23
|
+
function findAgain(el) {
|
|
24
|
+
if (!el || !el.dataset) return null;
|
|
25
|
+
if (el.classList.contains('hx-forge-back') && el.closest('#forge-detail')) return '#forge-detail .hx-forge-back'; // the detail is drawn anew as its answer comes in
|
|
26
|
+
if (el.dataset.forgePr) return `[data-forge-pr="${el.dataset.forgePr}"]`;
|
|
27
|
+
if (el.dataset.forgeDeploy) return `[data-forge-deploy="${el.dataset.forgeDeploy}"]`;
|
|
28
|
+
if (el.dataset.forgeThread) return `[data-forge-thread="${el.dataset.forgeThread}"]`;
|
|
29
|
+
if (el.dataset.forgeNode) return `[data-forge-node="${el.dataset.forgeNode}"]`;
|
|
30
|
+
if (el.dataset.specGroupToggle) return `[data-spec-group-toggle="${el.dataset.specGroupToggle}"]`;
|
|
31
|
+
if (el.dataset.forgeMerge) return '[data-forge-merge]';
|
|
32
|
+
if (el.dataset.forgeSpec) return `[data-forge-spec="${el.dataset.forgeSpec}"]`;
|
|
33
|
+
if (el.dataset.forgeBuild) return `[data-forge-build="${el.dataset.forgeBuild}"]`;
|
|
34
|
+
if (el.dataset.forgeRerun) return `[data-forge-rerun="${el.dataset.forgeRerun}"]`;
|
|
35
|
+
if (el.dataset.forgeAgent) return `[data-forge-agent="${el.dataset.forgeAgent}"]`;
|
|
36
|
+
if (el.dataset.forgeStop) return `[data-forge-stop="${el.dataset.forgeStop}"]`;
|
|
37
|
+
if (el.dataset.forgeRetry) return `[data-forge-retry="${el.dataset.forgeRetry}"]`;
|
|
38
|
+
if (el.dataset.runReply) return `[data-run-reply="${el.dataset.runReply}"]`;
|
|
39
|
+
if (el.dataset.runAnswer) return `[data-run-answer="${el.dataset.runAnswer}"][data-run-id="${el.dataset.runId}"]`;
|
|
40
|
+
if (el.dataset.runSelect) return `[data-run-select="${el.dataset.runSelect}"]`;
|
|
41
|
+
if (el.dataset.runTimeline) return `[data-run-timeline="${el.dataset.runTimeline}"]`;
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const key0 = () => fn.detailKey();
|
|
46
|
+
|
|
47
|
+
/** Everything the panel shows, from `ui` (a row or node button that had the focus has it again) */
|
|
48
|
+
function paint() {
|
|
49
|
+
const panel = $('forge-panel');
|
|
50
|
+
if (!panel) return;
|
|
51
|
+
const had = panel.contains(inst.active()) ? inst.active() : null;
|
|
52
|
+
const again = had ? findAgain(had) : null;
|
|
53
|
+
// A list drawn again must not move what the person is looking at: the scroll of the panel stays where it was
|
|
54
|
+
const scroller = panel.querySelector('.hx-forge-body');
|
|
55
|
+
const scrolled = scroller ? scroller.scrollTop : 0;
|
|
56
|
+
const keyBefore = m.shownKey;
|
|
57
|
+
draw(panel);
|
|
58
|
+
addParts(panel); // the hooks the panel was just drawn with are parts too
|
|
59
|
+
if (scroller && scrolled && key0() === keyBefore && scroller.scrollTop !== scrolled) scroller.scrollTop = scrolled;
|
|
60
|
+
const back = again && panel.querySelector(again);
|
|
61
|
+
if (back && back !== inst.active() && !back.closest('[hidden]')) back.focus();
|
|
62
|
+
// Retry was pressed and its notice is gone (the list is being read again): the focus goes to the panel's title, never to the page
|
|
63
|
+
if (had && had.dataset && had.dataset.action === 'retry-forge' && !panel.contains(inst.active())) $('forge-title').focus();
|
|
64
|
+
// A control of a run card that is no longer drawn (the run went on): the focus goes to that run's card, never to the page
|
|
65
|
+
const hadRun = had && !had.isConnected && had.closest('[data-run]');
|
|
66
|
+
if (hadRun && !panel.contains(inst.active())) {
|
|
67
|
+
const card = [...panel.querySelectorAll('[data-run]')].find((c) => c.dataset.run === hadRun.dataset.run);
|
|
68
|
+
if (card) card.focus();
|
|
69
|
+
}
|
|
70
|
+
// A selection replaces the list: the focus goes to its back control, and returns to the row when it is let go of
|
|
71
|
+
// (a tab changed leaves the focus on the tab)
|
|
72
|
+
const key = fn.detailKey();
|
|
73
|
+
if (key !== m.shownKey && m.shownKind === ui.kind) {
|
|
74
|
+
if (key) {
|
|
75
|
+
const target = panel.querySelector('#forge-detail .hx-forge-back');
|
|
76
|
+
if (target && (had || !m.shownKey)) target.focus();
|
|
77
|
+
} else {
|
|
78
|
+
const row = m.returnTo && panel.querySelector(m.returnTo);
|
|
79
|
+
if (row && !row.closest('[hidden]')) row.focus(); else $('forge-title').focus();
|
|
80
|
+
m.returnTo = null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
m.shownKey = key;
|
|
84
|
+
m.shownKind = ui.kind;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** The tabs' counts, where there is one: the proposals, the open pull requests and issues and threads, the runs still open */
|
|
88
|
+
function paintCounts() {
|
|
89
|
+
const open = (key) => (ui.lists[key] ? ui.lists[key].items.length : null);
|
|
90
|
+
const specs = fn.specsList() && fn.specsList().items;
|
|
91
|
+
const runs = ui.runs && ui.runs.data ? ui.runs.data.open : null;
|
|
92
|
+
const counts = { specs: specs ? specs.length : null, pulls: open('pulls|open'), issues: open('issues|open'), threads: ui.config && ui.config.threads === false ? null : open('threads|open'), work: runs };
|
|
93
|
+
// What waits on you shows as a filled badge on its tab: Specs the specs to decide, Runs the runs that need an answer (spec 0010 D2); with nothing
|
|
94
|
+
// waiting, the tab shows its plain total like the others. One number a tab, and its name says so.
|
|
95
|
+
const w = fn.waitingNow();
|
|
96
|
+
const share = { specs: w.specs, work: w.runs };
|
|
97
|
+
for (const btn of root.querySelectorAll('#forge-panel [data-forge-kind]')) {
|
|
98
|
+
const kind = btn.dataset.forgeKind;
|
|
99
|
+
const el = btn.querySelector('.hx-forge-count');
|
|
100
|
+
if (!el) continue;
|
|
101
|
+
const waits = share[kind] || 0;
|
|
102
|
+
const n = waits || counts[kind];
|
|
103
|
+
el.hidden = !(kind in counts); // a tab with no count at all (Deploys) shows none; the others hold their width while empty
|
|
104
|
+
el.textContent = n ? String(n) : '';
|
|
105
|
+
// The hook says which it is: a filled badge for what waits on you, a plain count for the total
|
|
106
|
+
el.dataset.corn = waits ? 'waiting-badge' : 'count';
|
|
107
|
+
el.setAttribute('part', el.dataset.corn); // the part follows the hook
|
|
108
|
+
el.classList.toggle('hx-forge-count--waiting', !!waits);
|
|
109
|
+
const label = btn.querySelector('[data-corn-string]');
|
|
110
|
+
if (waits && label) btn.setAttribute('aria-label', `${label.textContent}, ${waitingWords(waits, t)}`); else btn.removeAttribute('aria-label');
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** The one number, wherever it shows: the tabs' badges, the Work button's, and the browser tab's title; called whenever the specs or the runs were read */
|
|
115
|
+
function paintWaiting() {
|
|
116
|
+
paintCounts();
|
|
117
|
+
paintButton();
|
|
118
|
+
paintTitle();
|
|
119
|
+
paintBarLine();
|
|
120
|
+
refreshStubs();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** The proposal bar's line: a run waits on the open proposal (spec 0010 D2) */
|
|
124
|
+
function paintBarLine(open = !!state.proposal) {
|
|
125
|
+
const run = open && state.proposalSlug && ui.runs && ui.runs.data ? runWaitingOn(ui.runs.data.runs, state.proposalSlug) : null;
|
|
126
|
+
paintWaitingLine(run, `${state.proposalSource || ''}/${state.proposalSlug || ''}`);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** What waits on you, said to the page: it puts the number before the browser tab's title (the title is the page's, never a piece's) */
|
|
130
|
+
function paintTitle() {
|
|
131
|
+
inst.emit('work:waiting', { total: fn.waitingNow().total });
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Says (on the panel's top, for the CSS) that the tabs run on past an edge: a fade shows on that side, so Deploys is not simply missing on a phone */
|
|
135
|
+
function paintTabsMore() {
|
|
136
|
+
const top = root.querySelector('#forge-panel .hx-forge-top');
|
|
137
|
+
const tabs = top && top.querySelector('.hx-forge-tabs');
|
|
138
|
+
if (!tabs) return;
|
|
139
|
+
const more = [];
|
|
140
|
+
if (tabs.scrollLeft > 1) more.push('start');
|
|
141
|
+
if (tabs.scrollWidth - tabs.clientWidth - tabs.scrollLeft > 1) more.push('end');
|
|
142
|
+
if (more.length) top.dataset.more = more.join(' '); else delete top.dataset.more;
|
|
143
|
+
// A row given the focus is scrolled clear of the fixed top, never left under it (its height changes with the theme and the width)
|
|
144
|
+
const body = top.parentElement;
|
|
145
|
+
if (body) body.style.scrollPaddingTop = `${top.offsetHeight}px`;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** A notice line: its words, and a Retry that reads the tab again (for a failure or an older answer) */
|
|
149
|
+
function setNotice(el, words, retry) {
|
|
150
|
+
el.hidden = !words;
|
|
151
|
+
el.textContent = words;
|
|
152
|
+
if (words && retry) {
|
|
153
|
+
const again = inst.doc.createElement('button');
|
|
154
|
+
again.type = 'button';
|
|
155
|
+
again.className = 'hx-btn hx-forge-act';
|
|
156
|
+
again.dataset.action = 'retry-forge';
|
|
157
|
+
again.dataset.cornKind = 'quiet';
|
|
158
|
+
again.textContent = 'Retry';
|
|
159
|
+
el.append(' ', again);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function draw(panel) {
|
|
164
|
+
for (const btn of panel.querySelectorAll('[data-forge-kind]')) btn.setAttribute('aria-pressed', String(btn.dataset.forgeKind === (ui.kind === 'notes' ? 'pulls' : ui.kind)));
|
|
165
|
+
paintCounts();
|
|
166
|
+
const notes = ui.kind === 'notes';
|
|
167
|
+
const specs = ui.kind === 'specs';
|
|
168
|
+
const showing = fn.detailKey();
|
|
169
|
+
$('forge-filters').hidden = notes || ui.kind === 'work' || specs;
|
|
170
|
+
const searchBox = $('forge-specs-search');
|
|
171
|
+
if (searchBox) searchBox.hidden = !specs || !!showing;
|
|
172
|
+
$('forge-work-filters').hidden = ui.kind !== 'work';
|
|
173
|
+
$('forge-bar').hidden = !!showing;
|
|
174
|
+
paintChip();
|
|
175
|
+
$('forge-list').hidden = notes || !!showing;
|
|
176
|
+
$('forge-notes').hidden = !notes;
|
|
177
|
+
$('notes-open').hidden = ui.kind !== 'pulls' || !!showing;
|
|
178
|
+
$('forge-foot').hidden = notes || !!showing;
|
|
179
|
+
if (notes) {
|
|
180
|
+
fn.drawNotes();
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const list = fn.current();
|
|
185
|
+
const work = ui.kind === 'work';
|
|
186
|
+
const groups = work ? fn.groupsShown() : [];
|
|
187
|
+
const shown = list && !work && !specs ? filterItems(list.items, ui.kind, ui.filters) : [];
|
|
188
|
+
const status = $('forge-status');
|
|
189
|
+
if (ui.loading && !list) status.textContent = work ? `Loading the work from ${fn.forgeName()} …` : specs ? 'Looking for proposals …' : `Loading ${fn.kindWords()}s from ${fn.forgeName()} …`;
|
|
190
|
+
else if (!list) status.textContent = '';
|
|
191
|
+
else if (work) status.textContent = workStatus(groups, list.at, m.now());
|
|
192
|
+
else if (specs) status.textContent = `${fn.waitingNow().specs ? `${fn.waitingNow().specs} ${t('toDecide').toLowerCase()} \u00b7 ` : ''}${plural(list.items.length, 'proposal')}${list.at ? `, as of ${relativeTime(list.at, m.now())}` : ''}`;
|
|
193
|
+
else status.textContent = `${shown.length} of ${plural(list.items.length, fn.kindWords())}${list.at ? `, as of ${relativeTime(list.at, m.now())}` : ''}`;
|
|
194
|
+
|
|
195
|
+
const notice = $('forge-notice');
|
|
196
|
+
const words = ui.error || (list && list.stale ? `Showing an older answer. ${list.stale}` : '') || (specs && list && list.problem ? `The spec PRs could not be listed: ${list.problem}` : '') || (work && list && list.problem ? `Spec pull requests could not all be read: ${list.problem}` : '') || (ui.kind === 'threads' && list && list.problem ? `Some threads could not all be read: ${list.problem}` : '');
|
|
197
|
+
setNotice(notice, words, !!words);
|
|
198
|
+
|
|
199
|
+
const act = $('forge-act-note');
|
|
200
|
+
if (act) {
|
|
201
|
+
act.hidden = !ui.actNote;
|
|
202
|
+
const link = ui.actNote && safeUrl(ui.actNote.url);
|
|
203
|
+
act.className = `hx-forge-notice${ui.actNote && ui.actNote.ok ? ' hx-forge-notice--ok' : ''}`;
|
|
204
|
+
if (ui.actNote && ui.actNote.ok) act.dataset.cornState = 'success'; else delete act.dataset.cornState;
|
|
205
|
+
act.innerHTML = ui.actNote ? `${escHtml(ui.actNote.text)}${link ? ` <a data-corn="text-link" class="hx-link" href="${escHtml(link)}" target="_blank" rel="noreferrer">Open on ${escHtml(fn.forgeName())} ↗</a>` : ''}` : '';
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const rows = $('forge-list');
|
|
209
|
+
const empty = (words) => `<li class="hx-forge-empty hx-faint" data-corn="empty">${escHtml(words)}</li>`;
|
|
210
|
+
rows.setAttribute('aria-busy', String(!!ui.loading && !list));
|
|
211
|
+
// A list that is being read holds its height with rows of the right size, so nothing jumps when the data comes
|
|
212
|
+
// (On Runs the list sits under the runs, whose height is not known yet: rows held there would jump when the runs arrive, so they wait. They
|
|
213
|
+
// are drawn with the work's answer all the same, which loadWork paints only once the runs are read too, failed or not.)
|
|
214
|
+
if (!list) rows.innerHTML = ui.loading && !(work && !(ui.runs && ui.runs.data)) ? loadingRowsHtml(4) : '';
|
|
215
|
+
else if (specs) {
|
|
216
|
+
const open = state.proposal ? { slug: state.proposalSlug, source: state.proposalSource } : null;
|
|
217
|
+
const groups = specGroups(list.items, { query: ui.specQuery });
|
|
218
|
+
rows.innerHTML = groups.length ? specGroupsHtml(groups, { current: open, nowMs: m.now(), draftsOpen: ui.draftsOpen, say: t })
|
|
219
|
+
: list.items.length ? `<li class="hx-forge-empty hx-faint" data-corn="empty">No spec matches \u201c${escHtml(ui.specQuery.trim())}\u201d. <button type="button" class="hx-btn hx-forge-act" data-corn-kind="quiet" data-action="clear-specs-search">Clear the search</button></li>`
|
|
220
|
+
: empty(emptyWords('specs', fn.forgeName()));
|
|
221
|
+
}
|
|
222
|
+
else if (work) rows.innerHTML = groups.length ? fn.groupsHtml(groups) : empty(ui.work.grouped.groups.length ? 'No work matches these filters.' : emptyWords('work', fn.forgeName()));
|
|
223
|
+
else rows.innerHTML = shown.length ? shown.map((i) => fn.itemHtml(i)).join('') : empty(list.items.length ? `No ${fn.kindWords()} matches these filters.` : emptyWords(ui.kind, fn.forgeName()));
|
|
224
|
+
|
|
225
|
+
const detail = $('forge-detail');
|
|
226
|
+
detail.hidden = !showing;
|
|
227
|
+
detail.setAttribute('aria-label', showing.startsWith('thread:') ? 'Selected thread' : showing.startsWith('deploy:') ? 'Selected deploy' : 'Selected pull request');
|
|
228
|
+
detail.innerHTML = fn.detailHtml();
|
|
229
|
+
|
|
230
|
+
fn.paintIdea();
|
|
231
|
+
$('forge-foot').hidden = $('notes-open').hidden && $('forge-idea').hidden;
|
|
232
|
+
const rate = (showing && ((ui.threadDetail && ui.threadDetail.rate) || (ui.detail && ui.detail.rate))) || (list && list.rate) || '';
|
|
233
|
+
$('forge-rate').textContent = rate;
|
|
234
|
+
fn.paintRuns();
|
|
235
|
+
paintButton();
|
|
236
|
+
paintTabsMore();
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** The toggles that open the panel (`data-action="toggle-forge"`: the header's, whatever it calls it) say whether it is open, and the old button which selection is lit */
|
|
240
|
+
function paintButton() {
|
|
241
|
+
for (const toggle of root.querySelectorAll('[data-action="toggle-forge"]')) toggle.setAttribute('aria-expanded', String(ui.open));
|
|
242
|
+
const btn = $('forge-btn');
|
|
243
|
+
if (!btn) return;
|
|
244
|
+
const lit = ui.selected !== null || !!ui.deployItem || ui.thread !== null || !!ui.runSel;
|
|
245
|
+
const tag = $('forge-btn-lit');
|
|
246
|
+
if (tag) {
|
|
247
|
+
tag.hidden = !lit;
|
|
248
|
+
tag.textContent = ui.runSel ? 'run' : ui.thread !== null ? `thread #${ui.thread}` : ui.deployItem ? 'deploy' : lit ? `#${ui.selected}` : '';
|
|
249
|
+
}
|
|
250
|
+
const n = fn.waitingNow().total;
|
|
251
|
+
// A run would wait for a runner that is not there: a dot, and the name says so (issue #183); it sits beside the waiting badge, not on it
|
|
252
|
+
const away = fn.runnerAway();
|
|
253
|
+
const dot = $('forge-btn-dot');
|
|
254
|
+
if (dot) dot.hidden = !away;
|
|
255
|
+
const badge = $('forge-btn-waiting');
|
|
256
|
+
if (badge) {
|
|
257
|
+
badge.hidden = n === 0;
|
|
258
|
+
badge.textContent = n ? String(n) : '';
|
|
259
|
+
}
|
|
260
|
+
btn.setAttribute('aria-label', `${workButtonName(t('issuesAndPrs'), n, t)}${away ? ', no runner online' : ''}${ui.runSel ? ', a run lit on the map' : ui.thread !== null ? `, thread ${ui.thread} selected` : ui.deployItem ? ', a deploy selected' : lit ? `, pull request ${ui.selected} selected` : ''}`);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** Whether the Filter chip applies to the view: the proposals and the release notes have nothing to filter */
|
|
264
|
+
const filterable = () => ui.kind !== 'specs' && ui.kind !== 'notes';
|
|
265
|
+
|
|
266
|
+
/** How many filters are on: a state other than the default, a label, an author, a search; on Runs, its two checkboxes */
|
|
267
|
+
function activeFilters() {
|
|
268
|
+
if (ui.kind === 'work') return Number(ui.workFilters.agentsOnly) + Number(ui.workFilters.finished);
|
|
269
|
+
if (!filterable()) return 0;
|
|
270
|
+
const f = ui.filters;
|
|
271
|
+
return Number(f.state !== defaultFilters(ui.kind).state) + Number(!!f.label) + Number(!!f.author) + Number(!!f.text);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/** The Filter chip, its count, and the box behind it */
|
|
275
|
+
function paintChip() {
|
|
276
|
+
const chip = $('forge-filter-chip');
|
|
277
|
+
const box = $('forge-filter-box');
|
|
278
|
+
const on = filterable() && !fn.detailKey();
|
|
279
|
+
const n = activeFilters();
|
|
280
|
+
chip.hidden = !on;
|
|
281
|
+
chip.setAttribute('aria-expanded', String(on && ui.filtersOpen));
|
|
282
|
+
chip.setAttribute('aria-label', n ? `Filter, ${plural(n, 'filter')} on` : 'Filter');
|
|
283
|
+
const count = chip.querySelector('.hx-forge-count');
|
|
284
|
+
count.hidden = !n;
|
|
285
|
+
count.textContent = String(n);
|
|
286
|
+
chip.classList.toggle('is-on', n > 0);
|
|
287
|
+
box.hidden = !(on && ui.filtersOpen);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** The filters' choices: the states of the kind, the labels and authors of what is loaded */
|
|
291
|
+
function paintFilters() {
|
|
292
|
+
$('forge-filters').hidden = ui.kind === 'work' || !filterable();
|
|
293
|
+
$('forge-work-filters').hidden = ui.kind !== 'work';
|
|
294
|
+
$('forge-work-agents').checked = ui.workFilters.agentsOnly;
|
|
295
|
+
$('forge-work-finished').checked = ui.workFilters.finished;
|
|
296
|
+
if (ui.kind === 'work' || !filterable()) return;
|
|
297
|
+
const items = fn.current() && ui.kind !== 'deploys' ? fn.current().items : [];
|
|
298
|
+
const { labels, authors } = facetsOf(items);
|
|
299
|
+
if (ui.filters.label && !labels.includes(ui.filters.label)) ui.filters.label = '';
|
|
300
|
+
if (ui.filters.author && !authors.includes(ui.filters.author)) ui.filters.author = '';
|
|
301
|
+
$('forge-state').innerHTML = STATES[ui.kind].map(([v, l]) => option(v, l, v === ui.filters.state)).join('');
|
|
302
|
+
$('forge-label').innerHTML = option('', 'Any label', !ui.filters.label) + labels.map((l) => option(l, l, l === ui.filters.label)).join('');
|
|
303
|
+
$('forge-author').innerHTML = option('', 'Anyone', !ui.filters.author) + authors.map((a) => option(a, a, a === ui.filters.author)).join('');
|
|
304
|
+
// A deploy has no labels and no author to pick: its list is filtered by state and the search
|
|
305
|
+
$('forge-label').parentElement.hidden = ui.kind === 'deploys' || ui.kind === 'threads';
|
|
306
|
+
$('forge-author').parentElement.hidden = ui.kind === 'deploys';
|
|
307
|
+
// …and its search reads the workflow, what it ran for, the branch and who started it, not a number or a label
|
|
308
|
+
$('forge-text').placeholder = ui.kind === 'deploys' ? 'Workflow, branch, commit, who' : ui.kind === 'threads' ? 'Title, number, author' : 'Title, number, label';
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
Object.assign(fn, { findAgain, key0, paint, paintCounts, paintWaiting, paintBarLine, paintTitle, paintTabsMore, setNotice, draw, paintButton, filterable, activeFilters, paintChip, paintFilters });
|
|
312
|
+
}
|