@popcorn245/cornfield 0.50.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/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 +16 -1
- 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 +15 -5
- package/explorer/pieces/proposal.js +9 -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/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,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/pieces/work-specs
|
|
3
|
+
*
|
|
4
|
+
* The Specs tab: the proposals the server finds, merged into one row each, and the number of those that wait on a decision. 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 { mergeSpecs } from '../proposal-model.js';
|
|
9
|
+
import { waiting, specGroups } from '../waiting-model.js';
|
|
10
|
+
import { plural, SPECS_POLL_MS } from './work-common.js';
|
|
11
|
+
|
|
12
|
+
export function install(ctx) {
|
|
13
|
+
const { inst, ui, m, fn, $ } = ctx;
|
|
14
|
+
const { announce, t, proposalListing, loadProposalList, setT } = ctx.h;
|
|
15
|
+
|
|
16
|
+
/** The proposals the Proposals menu lists (proposal.js reads them), as a list of the panel's own shape; null before the first answer */
|
|
17
|
+
|
|
18
|
+
function specsList() {
|
|
19
|
+
const { entries, problem, forgeProblem, at } = proposalListing();
|
|
20
|
+
// One row for a proposal, however many places it is in: its spec PR and the copy in a checkout or a worktree are one (mergeSpecs)
|
|
21
|
+
if (entries && m.merged.entries !== entries) m.merged = { entries, items: mergeSpecs(entries) };
|
|
22
|
+
return entries ? { items: m.merged.items, at: at ? new Date(at).toISOString() : '', rate: '', stale: '', problem: problem || forgeProblem || '' } : null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** What waits on the maintainer now (spec 0010 D1): the specs to decide and the runs that wait on an answer, from what has been read */
|
|
26
|
+
const waitingNow = () => waiting({ specs: specsList() && specsList().items, runs: ui.runs && ui.runs.data ? ui.runs.data.runs : null });
|
|
27
|
+
|
|
28
|
+
/** Loads the Specs tab: the proposals the server finds (the list the header's Proposals menu shows, proposal.js); always asked again, worktrees come and go */
|
|
29
|
+
async function loadSpecs(token, quiet) {
|
|
30
|
+
ui.loading = true;
|
|
31
|
+
ui.error = '';
|
|
32
|
+
fn.paint();
|
|
33
|
+
await loadProposalList();
|
|
34
|
+
if (token !== m.listToken) return;
|
|
35
|
+
ui.loading = false;
|
|
36
|
+
const { entries, problem } = proposalListing();
|
|
37
|
+
if (!entries) ui.error = `Could not load the proposals. ${problem || 'cornfield did not answer.'}`;
|
|
38
|
+
if (!quiet) announce(ui.error || specsShownWords());
|
|
39
|
+
fn.paint();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** What the Specs tab says when it is read or searched: how many rows show, and how many of them wait on a decision */
|
|
43
|
+
function specsShownWords() {
|
|
44
|
+
const list = fn.current();
|
|
45
|
+
if (!list) return 'Looking for proposals';
|
|
46
|
+
const shown = specGroups(list.items, { query: ui.specQuery }).reduce((n, g) => n + g.shown, 0);
|
|
47
|
+
if (ui.specQuery.trim() && !shown) return `No spec matches ${ui.specQuery.trim()}`;
|
|
48
|
+
const decide = waitingNow().specs;
|
|
49
|
+
return `${plural(shown, 'spec')} shown${decide ? `, ${decide} ${t('toDecide').toLowerCase()}` : ''}`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Reads the proposals now, quietly (the number and the list follow); one read at a time */
|
|
53
|
+
async function readSpecsQuiet() {
|
|
54
|
+
if (m.specsReading) return;
|
|
55
|
+
m.specsReading = true;
|
|
56
|
+
try { await loadProposalList(); } finally { m.specsReading = false; }
|
|
57
|
+
fn.paintWaiting();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** The specs part of the number is read again every `SPECS_POLL_MS`, never while the page is hidden or put away; one timer at most */
|
|
61
|
+
function syncSpecsPoll() {
|
|
62
|
+
if (m.specsTimer || !ui.config) return;
|
|
63
|
+
m.specsTimer = setT(async () => {
|
|
64
|
+
m.specsTimer = 0;
|
|
65
|
+
if (!m.pageAway && !(inst.hidden())) await readSpecsQuiet();
|
|
66
|
+
syncSpecsPoll();
|
|
67
|
+
}, SPECS_POLL_MS);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
Object.assign(fn, { specsList, waitingNow, loadSpecs, specsShownWords, readSpecsQuiet, syncSpecsPoll });
|
|
71
|
+
}
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/pieces/work-threads
|
|
3
|
+
*
|
|
4
|
+
* The Threads tab: the list, a thread's messages, and the New idea form. 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 { runOnThread, threadRunWords } from '../runs-model.js';
|
|
10
|
+
import { runPillHtml } from '../runs-view.js';
|
|
11
|
+
import { defaultFilters, threadsUrl, threadUrl, IDEAS_URL, threadKindWords, threadMeta, mentionsIndex, ideaRequest, ideaWords } from '../forge-panel-model.js';
|
|
12
|
+
import { cornStateAttr } from '../corn-state.js';
|
|
13
|
+
import { relativeTime } from '../review-model.js';
|
|
14
|
+
import { escapeHtml as escHtml } from '../../core/text.js';
|
|
15
|
+
import { plural, safeUrl, backHtml, threadOf, MENTIONABLE } from './work-common.js';
|
|
16
|
+
|
|
17
|
+
export function install(ctx) {
|
|
18
|
+
const { inst, ui, m, fn, state, root, $ } = ctx;
|
|
19
|
+
const { announce, t, render, touchScene, repaintThreads } = ctx.h;
|
|
20
|
+
|
|
21
|
+
/** Forgets the selected thread without painting: another thing is being selected */
|
|
22
|
+
function dropThread() {
|
|
23
|
+
ui.runSel = null;
|
|
24
|
+
m.threadToken++;
|
|
25
|
+
ui.thread = null;
|
|
26
|
+
ui.threadDetail = null;
|
|
27
|
+
ui.threadError = '';
|
|
28
|
+
ui.litThread = null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async function selectThread(n) {
|
|
32
|
+
const token = ++m.threadToken;
|
|
33
|
+
m.pullToken++;
|
|
34
|
+
ui.runSel = null;
|
|
35
|
+
ui.selected = null;
|
|
36
|
+
ui.detail = null;
|
|
37
|
+
ui.detailError = '';
|
|
38
|
+
ui.lit = null;
|
|
39
|
+
ui.landing = null;
|
|
40
|
+
ui.deploy = null;
|
|
41
|
+
ui.deployItem = null;
|
|
42
|
+
ui.litDeploy = null;
|
|
43
|
+
ui.thread = n;
|
|
44
|
+
ui.threadDetail = null;
|
|
45
|
+
ui.threadError = '';
|
|
46
|
+
ui.litThread = null;
|
|
47
|
+
state.forgeLit = null;
|
|
48
|
+
touchScene();
|
|
49
|
+
render();
|
|
50
|
+
fn.paint();
|
|
51
|
+
const res = await fn.request(threadUrl(n), false);
|
|
52
|
+
if (token !== m.threadToken) return;
|
|
53
|
+
// An answer without a thread in it is a failure too: nothing to show or light
|
|
54
|
+
const thread = threadOf(res);
|
|
55
|
+
if (!thread) {
|
|
56
|
+
ui.threadError = res.ok ? `Thread ${n} could not be read: the answer had no thread in it. Refresh to ask again.` : fn.failWords(res, `thread ${n}`);
|
|
57
|
+
announce(ui.threadError);
|
|
58
|
+
fn.paint();
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
ui.threadDetail = { thread, at: res.body.at, rate: res.body.rate || '', stale: res.body.stale || '' };
|
|
62
|
+
fn.relight();
|
|
63
|
+
$('forge-panel').querySelector('.hx-forge-body').scrollTop = 0; // the thread's messages are what was asked for, not the row that was tapped
|
|
64
|
+
announce(threadSelectionWords());
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Lets go of the selected thread: nothing is lit any more */
|
|
68
|
+
function clearThread() {
|
|
69
|
+
const had = ui.thread;
|
|
70
|
+
dropThread();
|
|
71
|
+
state.forgeLit = null;
|
|
72
|
+
touchScene();
|
|
73
|
+
render();
|
|
74
|
+
fn.paint();
|
|
75
|
+
if (had !== null) announce(`Thread ${had} cleared`);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** What a screen reader hears when a thread is selected */
|
|
79
|
+
function threadSelectionWords() {
|
|
80
|
+
const { thread } = ui.threadDetail;
|
|
81
|
+
const lit = ui.litThread ? ui.litThread.nodes.length : 0;
|
|
82
|
+
const off = ui.litThread ? ui.litThread.unresolved.length : 0;
|
|
83
|
+
return `Thread ${thread.number}, ${thread.title}: ${plural(thread.messages.length, 'message')}, ${lit ? `${plural(lit, 'node')} lit` : 'no node mentioned'}${off ? `, ${off} named that ${off === 1 ? 'is' : 'are'} not on the map` : ''}. Read-only: reply on ${fn.forgeName()}.`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Shows a thread from the map (a node's "Mentioned in"): the panel opens on the Threads tab with that thread selected */
|
|
87
|
+
function openThread(n) {
|
|
88
|
+
if (ui.kind !== 'threads') {
|
|
89
|
+
ui.kind = 'threads';
|
|
90
|
+
ui.actNote = null;
|
|
91
|
+
ui.filters = defaultFilters('threads');
|
|
92
|
+
}
|
|
93
|
+
fn.openForge();
|
|
94
|
+
fn.paintFilters();
|
|
95
|
+
selectThread(n);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** The threads list for the node panel's "Mentioned in", read once (quietly) when a node is first selected, and when the Threads tab loads it */
|
|
99
|
+
function ensureThreadsList() {
|
|
100
|
+
if (!ui.config || ui.config.threads === false || ui.lists['threads|open'] || m.indexLoading) return;
|
|
101
|
+
m.indexLoading = true;
|
|
102
|
+
const token = ++m.indexToken;
|
|
103
|
+
fn.request(threadsUrl('open'), false).then((res) => {
|
|
104
|
+
m.indexLoading = false;
|
|
105
|
+
if (token !== m.indexToken || !res.ok || ui.lists['threads|open']) return;
|
|
106
|
+
ui.lists['threads|open'] = { items: res.body.items || [], at: res.body.at, rate: res.body.rate || '', stale: res.body.stale || '', problem: res.body.problem || '' };
|
|
107
|
+
repaintThreads();
|
|
108
|
+
if (ui.open && ui.kind === 'threads') fn.paint();
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** The threads that mention a node on the map now, or null while the list has not been read */
|
|
113
|
+
function threadsFor(nodeId) {
|
|
114
|
+
const list = ui.lists['threads|open'];
|
|
115
|
+
if (!list) return null;
|
|
116
|
+
if (!m.indexCache || m.indexCache.items !== list.items || m.indexCache.nodes !== state.nodes) m.indexCache = { items: list.items, nodes: state.nodes, map: mentionsIndex(list.items, state.nodes) };
|
|
117
|
+
return m.indexCache.map.get(nodeId) || [];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Opens or closes the form; the focus goes to the title, or back to the button */
|
|
121
|
+
function toggleIdea(open) {
|
|
122
|
+
ui.idea.open = open;
|
|
123
|
+
if (open) { ui.idea.message = ''; ui.idea.opener = ''; ui.idea.node = null; }
|
|
124
|
+
paintIdea();
|
|
125
|
+
if (open) $('idea-title').focus(); else focusIdeaOpener();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Puts the focus back on what opened the form: the node panel's button while it is still there, else the New idea button */
|
|
129
|
+
function focusIdeaOpener() {
|
|
130
|
+
const from = ui.idea.opener ? [...root.querySelectorAll('[data-thread-start]')].find((b) => b.dataset.threadStart === ui.idea.opener) : null;
|
|
131
|
+
(from && !from.closest('[inert]') ? from : $('idea-open')).focus();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** "Start a thread about this" (a node's panel): the New idea form, with the node's label as the title and its mention in the text */
|
|
135
|
+
function startThread(node) {
|
|
136
|
+
if (!node || ui.idea.busy || !ui.config || ui.config.threads === false) return;
|
|
137
|
+
if (ui.kind !== 'threads') {
|
|
138
|
+
ui.kind = 'threads';
|
|
139
|
+
ui.actNote = null;
|
|
140
|
+
ui.filters = defaultFilters('threads');
|
|
141
|
+
}
|
|
142
|
+
fn.openForge();
|
|
143
|
+
fn.paintFilters();
|
|
144
|
+
ui.idea.open = true;
|
|
145
|
+
ui.idea.message = '';
|
|
146
|
+
ui.idea.bad = false;
|
|
147
|
+
ui.idea.link = null;
|
|
148
|
+
ui.idea.node = { id: node.id, label: node.label };
|
|
149
|
+
ui.idea.opener = node.id;
|
|
150
|
+
// Never lose a draft: a title already typed stays, and text already typed stays under the mention, which is added once (`.value` is
|
|
151
|
+
// text, never markup, so the label and the id need no escaping here)
|
|
152
|
+
const title = $('idea-title');
|
|
153
|
+
if (title.value.trim() === '') title.value = String(node.label || node.id).slice(0, 256);
|
|
154
|
+
const text = $('idea-body');
|
|
155
|
+
const mention = MENTIONABLE.test(node.id) ? `[[${node.id}]]` : '';
|
|
156
|
+
if (mention && !text.value.includes(mention)) text.value = text.value.trim() === '' ? `${mention}\n\n` : `${mention}\n\n${text.value}`;
|
|
157
|
+
paintIdea();
|
|
158
|
+
$('idea-title').focus();
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** The one write: a POST to cornfield's own server, which opens an issue with the label as the maintainer */
|
|
162
|
+
async function sendIdea() {
|
|
163
|
+
if (ui.idea.busy) return;
|
|
164
|
+
const asked = ideaRequest($('idea-title').value, $('idea-body').value);
|
|
165
|
+
if (!asked) {
|
|
166
|
+
ui.idea.message = 'Give the idea a title.';
|
|
167
|
+
ui.idea.bad = true;
|
|
168
|
+
ui.idea.link = null;
|
|
169
|
+
paintIdea();
|
|
170
|
+
announce(ui.idea.message);
|
|
171
|
+
$('idea-title').focus();
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
ui.idea.busy = true;
|
|
175
|
+
ui.idea.message = '';
|
|
176
|
+
paintIdea();
|
|
177
|
+
announce(`Opening the idea on ${fn.forgeName()}`);
|
|
178
|
+
const res = await fn.post(IDEAS_URL, asked);
|
|
179
|
+
ui.idea.busy = false;
|
|
180
|
+
ui.idea.message = ideaWords(fn.forgeName(), res);
|
|
181
|
+
ui.idea.bad = !res.ok;
|
|
182
|
+
ui.idea.link = res.ok && res.body.issue ? res.body.issue.url : null;
|
|
183
|
+
if (res.ok) {
|
|
184
|
+
ui.idea.open = false;
|
|
185
|
+
$('idea-title').value = '';
|
|
186
|
+
$('idea-body').value = '';
|
|
187
|
+
}
|
|
188
|
+
paintIdea();
|
|
189
|
+
announce(ui.idea.message);
|
|
190
|
+
if (res.ok) await afterIdea(res);
|
|
191
|
+
else $('idea-title').focus();
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* After an idea is opened: the list read again, the new thread selected (so what it mentions lights), the focus back on what opened
|
|
196
|
+
* the form, and all of it said once. The idea is on the forge whatever happens here, so a failure is said, never thrown.
|
|
197
|
+
*/
|
|
198
|
+
async function afterIdea(res) {
|
|
199
|
+
const about = ui.idea.node;
|
|
200
|
+
const n = res.body && res.body.number;
|
|
201
|
+
let trouble = '';
|
|
202
|
+
try {
|
|
203
|
+
// The new thread is shown where threads are: an idea opened from Specs goes on to the Threads tab
|
|
204
|
+
if (ui.kind !== 'threads') { ui.kind = 'threads'; ui.actNote = null; ui.filters = defaultFilters('threads'); fn.paintFilters(); }
|
|
205
|
+
ui.lists = {};
|
|
206
|
+
m.primed.clear(); // the tabs' counts are read again
|
|
207
|
+
m.indexCache = null;
|
|
208
|
+
await fn.loadList(true, true);
|
|
209
|
+
if (ui.open) fn.primeCounts();
|
|
210
|
+
ensureThreadsList();
|
|
211
|
+
// The new thread is selected in the list, so what it mentions lights on the map once its messages are in
|
|
212
|
+
if (Number.isInteger(n)) await selectThread(n);
|
|
213
|
+
} catch (err) {
|
|
214
|
+
trouble = ` The list could not be read again (${err instanceof Error ? err.message : err}); Refresh asks for it.`;
|
|
215
|
+
}
|
|
216
|
+
// Then the focus goes back to what opened the form: after the selection, which draws the node's panel (and its button) again
|
|
217
|
+
try { focusIdeaOpener(); } catch { /* the page moved on */ }
|
|
218
|
+
ui.idea.opener = '';
|
|
219
|
+
ui.idea.node = null;
|
|
220
|
+
const shown = ui.thread === n && ui.threadDetail && ui.threadDetail.thread ? ` ${threadSelectionWords()}` : ui.thread === n && ui.threadError ? ` ${ui.threadError}` : '';
|
|
221
|
+
// Opened from a node: say that its "Mentioned in" lists the new thread
|
|
222
|
+
const listed = about && (threadsFor(about.id) || []).some((t) => t.number === n);
|
|
223
|
+
announce(`${ui.idea.message}${shown}${listed ? ` It is listed under Threads for ${about.label}.` : ''}${trouble}`);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** The New idea bar and form, from `ui.idea`; typed text and the focus are left alone */
|
|
227
|
+
function paintIdea() {
|
|
228
|
+
const bar = $('forge-idea');
|
|
229
|
+
if (!bar) return;
|
|
230
|
+
// An idea is a thread: with threads off (`threads: false`) there is no New idea, on Specs either
|
|
231
|
+
bar.hidden = (ui.kind !== 'threads' && ui.kind !== 'specs') || !!fn.detailKey() || !ui.config || ui.config.threads === false;
|
|
232
|
+
$('idea-open').setAttribute('aria-expanded', String(ui.idea.open));
|
|
233
|
+
$('idea-form').hidden = !ui.idea.open;
|
|
234
|
+
$('idea-send').textContent = ui.idea.busy ? 'Opening …' : 'Open the idea';
|
|
235
|
+
$('idea-send').disabled = ui.idea.busy;
|
|
236
|
+
if (ui.idea.open) {
|
|
237
|
+
const label = (ui.config && ui.config.threads && ui.config.threads.label) || 'idea';
|
|
238
|
+
$('idea-words').textContent = `This opens an issue labelled "${label}" on ${fn.forgeName()}, as you. The conversation lives there; cornfield keeps no copy of it.`;
|
|
239
|
+
}
|
|
240
|
+
const message = $('idea-message');
|
|
241
|
+
message.hidden = !ui.idea.message;
|
|
242
|
+
message.classList.toggle('hx-forge-msg--bad', ui.idea.bad);
|
|
243
|
+
if (ui.idea.bad) message.dataset.cornState = 'failure'; else delete message.dataset.cornState;
|
|
244
|
+
message.textContent = ui.idea.message;
|
|
245
|
+
if (ui.idea.message && ui.idea.link && safeUrl(ui.idea.link)) {
|
|
246
|
+
const link = inst.doc.createElement('a');
|
|
247
|
+
link.className = 'hx-link';
|
|
248
|
+
link.dataset.corn = 'text-link';
|
|
249
|
+
link.href = ui.idea.link;
|
|
250
|
+
link.target = '_blank';
|
|
251
|
+
link.rel = 'noreferrer';
|
|
252
|
+
link.textContent = `Open it on ${fn.forgeName()} (new tab)`;
|
|
253
|
+
message.append(' ', link);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** One thread in the list: a row that opens it, and a link out to the forge */
|
|
258
|
+
function threadHtml(t) {
|
|
259
|
+
const link = safeUrl(t.url);
|
|
260
|
+
const out = link ? `<a data-corn="out-link" class="hx-forge-out" href="${escHtml(link)}" target="_blank" rel="noreferrer" aria-label="Open thread ${t.number} on ${escHtml(fn.forgeName())} (new tab)">↗</a>` : '';
|
|
261
|
+
const note = [t.proposals && t.proposals.length ? `Proposal ${t.proposals.map((p) => p.slug).join(', ')}` : '', t.idea ? `Idea #${t.idea}` : ''].filter(Boolean).join(' · ');
|
|
262
|
+
// The run that is about this thread, as a word (issue #104): the Agents tab's list, read for every tab, says it; the row only names its state
|
|
263
|
+
const runs = ui.runs && ui.runs.data ? ui.runs.data.runs : null;
|
|
264
|
+
const run = runOnThread(runs, t.number);
|
|
265
|
+
const runWord = run ? `${runPillHtml({ esc: escHtml }, run, threadRunWords(runs, t.number), ` data-thread-run="${escHtml(run.runId)}"`)} ` : '';
|
|
266
|
+
return `<li class="hx-forge-item"><button type="button" class="hx-forge-row" data-forge-thread="${t.number}" aria-pressed="${ui.thread === t.number}" data-corn="row">
|
|
267
|
+
<span class="hx-forge-title">${escHtml(t.title)}</span>
|
|
268
|
+
<span class="hx-forge-meta"><span class="hx-forge-state hx-forge-state--${escHtml(t.state)}" data-corn="state-pill"${cornStateAttr(t.state)}>${escHtml(t.state === 'open' ? 'Open' : 'Closed')}</span> ${runWord}<span class="hx-forge-label" data-corn="tag">${escHtml(threadKindWords(t))}</span> ${escHtml(threadMeta(t, m.now()))}</span>${note ? `<span class="hx-forge-meta">${escHtml(note)}</span>` : ''}</button>${out}</li>`;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** The selected thread: read-only, its messages as written, a way to reply on the forge, and the nodes its text lights */
|
|
272
|
+
function threadDetailHtml() {
|
|
273
|
+
const head = (title) => `${backHtml('clear-forge-thread', 'All threads')}<h3 class="hx-forge-detail-title" data-corn="detail-title">${title}</h3>`;
|
|
274
|
+
if (ui.threadError) return `${head(`Thread ${ui.thread}`)}<p class="hx-forge-notice" data-corn="notice">${escHtml(ui.threadError)}</p>`;
|
|
275
|
+
if (!ui.threadDetail) return `${head(`Thread ${ui.thread}`)}<p class="hx-faint">Loading its messages …</p>`;
|
|
276
|
+
const { thread: t, stale } = ui.threadDetail;
|
|
277
|
+
const lit = ui.litThread;
|
|
278
|
+
const url = safeUrl(t.url);
|
|
279
|
+
const reply = url ? `<a data-corn="text-link" class="hx-link" href="${escHtml(url)}" target="_blank" rel="noreferrer">Reply on ${escHtml(fn.forgeName())} (new tab)</a>` : '';
|
|
280
|
+
const named = [
|
|
281
|
+
...(t.proposals || []).map((p) => `Proposal <code class="hx-code">${escHtml(p.slug)}</code> in pull request #${p.pull}`),
|
|
282
|
+
...(t.kind === 'proposal' ? [`Spec pull request for <code class="hx-code">${escHtml((t.slugs || []).join(', '))}</code>`] : []),
|
|
283
|
+
...(t.idea ? [`Names idea #${t.idea}`] : []),
|
|
284
|
+
];
|
|
285
|
+
const msgs = t.messages.map((msg) => {
|
|
286
|
+
const own = lit.perMessage.get(msg.id) || { nodes: [], unresolved: [] };
|
|
287
|
+
const link = safeUrl(msg.url) ? ` <a data-corn="out-link" class="hx-link" href="${escHtml(msg.url)}" target="_blank" rel="noreferrer" aria-label="Open this message on ${escHtml(fn.forgeName())} (new tab)">↗</a>` : '';
|
|
288
|
+
const chips = own.nodes.length || own.unresolved.length
|
|
289
|
+
? `<span class="hx-forge-nodes hx-thread-nodes">${own.nodes.map(fn.nodeButton).join('')}${own.unresolved.length ? `<span class="hx-faint">not on the map: ${own.unresolved.map((r) => `<code class="hx-code">${escHtml(r)}</code>`).join(' ')}</span>` : ''}</span>`
|
|
290
|
+
: '';
|
|
291
|
+
return `<li class="hx-thread-msg" data-corn="thread-message"><p class="hx-forge-meta"><strong class="hx-strong">${escHtml(msg.author ? msg.author.login : 'someone')}</strong>${msg.opening ? ' opened this' : ''} · ${escHtml(relativeTime(msg.createdAt, m.now()))}${link}</p><p class="hx-thread-body">${escHtml(msg.body.trim() === '' ? '(no text)' : msg.body)}${msg.cut ? '\n… (cut here; the rest is on the forge)' : ''}</p>${chips}</li>`;
|
|
292
|
+
}).join('');
|
|
293
|
+
const key = lit.nodes.length ? `<p class="hx-forge-key hx-faint"><span class="hx-mark-dot hx-mark-dot--changed" data-corn="mark-dot" data-corn-state="changed" aria-hidden="true"></span>a node this thread mentions</p>` : '';
|
|
294
|
+
return `${head(`#${t.number} ${escHtml(t.title)}`)}
|
|
295
|
+
<p class="hx-forge-meta"><span class="hx-forge-state hx-forge-state--${escHtml(t.state)}" data-corn="state-pill"${cornStateAttr(t.state)}>${t.state === 'open' ? 'Open' : 'Closed'}</span> ${escHtml(threadKindWords(t))} · ${escHtml(threadMeta({ ...t, comments: t.messages.length - (t.kind === 'idea' ? 1 : 0) + (t.hidden || 0) }, m.now()))}</p>
|
|
296
|
+
<p class="hx-forge-why hx-faint">Read-only here: a thread is a conversation on ${escHtml(fn.forgeName())}, so you reply there. ${reply}</p>
|
|
297
|
+
${named.length ? `<p class="hx-forge-meta">${named.join(' · ')}</p>` : ''}
|
|
298
|
+
${stale ? `<p class="hx-forge-notice" data-corn="notice">${escHtml(`This is an older answer. ${stale}`)}</p>` : ''}
|
|
299
|
+
<h4 class="hx-forge-sub">${escHtml(`Mentions: ${plural(lit.nodes.length, 'node')} on the map`)}</h4>
|
|
300
|
+
${key}
|
|
301
|
+
${lit.nodes.length ? `<span class="hx-forge-nodes hx-thread-nodes">${lit.nodes.map(fn.nodeButton).join('')}</span>` : '<p class="hx-faint">No message mentions a node. Write [[node-id]] or [[repo/path]] in a message to point at the map.</p>'}
|
|
302
|
+
${lit.unresolved.length ? `<p class="hx-forge-notice" data-corn="notice">${escHtml(lit.unresolved.join(', '))} ${lit.unresolved.length === 1 ? 'is' : 'are'} mentioned but not on the map, so ${lit.unresolved.length === 1 ? 'it stays' : 'they stay'} text.</p>` : ''}
|
|
303
|
+
<h4 class="hx-forge-sub">${escHtml(plural(t.messages.length, 'message'))}</h4>
|
|
304
|
+
${t.hidden ? `<p class="hx-forge-why hx-faint">${escHtml(plural(t.hidden, 'earlier message'))} not shown; they are on ${escHtml(fn.forgeName())}.</p>` : ''}
|
|
305
|
+
<ol class="hx-thread-msgs" aria-label="Messages">${msgs}</ol>`;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
Object.assign(fn, { dropThread, selectThread, clearThread, threadSelectionWords, openThread, ensureThreadsList, threadsFor, toggleIdea, focusIdeaOpener, startThread, sendIdea, afterIdea, paintIdea, threadHtml: (...a) => withParts(threadHtml(...a)), threadDetailHtml: (...a) => withParts(threadDetailHtml(...a)) });
|
|
309
|
+
}
|