@popcorn245/cornfield 0.55.0 → 0.56.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/core/contrast.js +12 -1
  2. package/core/schema.js +6 -0
  3. package/core/strings.js +0 -1
  4. package/explorer/css/page.css +0 -8
  5. package/explorer/css/work.css +3 -26
  6. package/explorer/deep-link.js +11 -24
  7. package/explorer/engine/map-style.js +4 -1
  8. package/explorer/forge-panel-model.js +2 -36
  9. package/explorer/forge-panel.js +3 -8
  10. package/explorer/index.html +1 -10
  11. package/explorer/instance-state.js +0 -6
  12. package/explorer/instance.js +9 -5
  13. package/explorer/page.js +5 -4
  14. package/explorer/pieces/node-panel.js +9 -5
  15. package/explorer/pieces/work-agent.js +3 -2
  16. package/explorer/pieces/work-common.js +14 -15
  17. package/explorer/pieces/work-confirm.js +11 -10
  18. package/explorer/pieces/work-data.js +24 -31
  19. package/explorer/pieces/work-deploys.js +42 -41
  20. package/explorer/pieces/work-issues.js +32 -29
  21. package/explorer/pieces/work-list.js +406 -0
  22. package/explorer/pieces/work-markup.js +9 -14
  23. package/explorer/pieces/work-notes.js +0 -1
  24. package/explorer/pieces/work-paint.js +57 -62
  25. package/explorer/pieces/work-prs.js +25 -66
  26. package/explorer/pieces/work-runs.js +47 -57
  27. package/explorer/pieces/work-specs.js +19 -2
  28. package/explorer/pieces/work-threads.js +28 -48
  29. package/explorer/pieces/work.js +28 -40
  30. package/explorer/proposal-model.js +5 -5
  31. package/explorer/runs-view.js +10 -18
  32. package/explorer/scene.js +1 -3
  33. package/explorer/tokens.css +4 -0
  34. package/explorer/waiting-view.js +3 -3
  35. package/explorer/work-model.js +79 -38
  36. package/explorer/work-view.css +3 -4
  37. package/explorer/work-view.js +77 -49
  38. package/package.json +1 -1
  39. package/explorer/pieces/work-events.js +0 -285
@@ -15,9 +15,10 @@
15
15
  */
16
16
 
17
17
  import { NODE_THEMES } from '../core/schema.js';
18
- import { WORK_KINDS, WORK_THEMES, workType } from '../core/schema.js';
18
+ import { WORK_KINDS, WORK_THEMES, WORK_EDGE_THEMES, workType } from '../core/schema.js';
19
19
  import { relativeTime } from './review-model.js';
20
- import { SPEC_STATE_WORDS } from './waiting-model.js';
20
+ import { SPEC_STATE_WORDS, specStateOf } from './waiting-model.js';
21
+ import { runName, canAnswer } from './runs-model.js';
21
22
  import { cornState } from './corn-state.js';
22
23
  import { escapeHtml as esc } from '../core/text.js';
23
24
  import { safeUrl } from './pieces/work-common.js';
@@ -105,6 +106,52 @@ export function termsOf(item) {
105
106
  /** A node the graph names that the map does not hold: a planned one, by its type (an unknown type reads as a page) */
106
107
  const plannedType = (type) => (typeof type === 'string' && Object.hasOwn(NODE_THEMES, type) ? type : 'page');
107
108
 
109
+ /**
110
+ * The node of a piece of work: what the scene draws and the node panel shows for it. `item` is a node of the server's graph, or an old piece of work made
111
+ * by `oldItem` (older than the graph's 14 days, or past its caps: the Work list reaches it, and the node panel shows it by the same path, `old: true`).
112
+ */
113
+ export function workNode(item, degree = 0) {
114
+ const theme = WORK_THEMES[item.kind];
115
+ const title = text(item.title) || tagOf(item);
116
+ const draft = isDraft(item);
117
+ return {
118
+ id: item.id, type: workType(item.kind), work: item.kind, shape: theme.shape, label: item.kind === 'deploy' ? `Deploy · ${clip(title, LABEL_CHARS)}` : `${tagOf(item)} · ${clip(title, LABEL_CHARS)}`,
119
+ title, item, r: theme.r, color: theme.color, letters: theme.letters, terms: termsOf(item), groupName: draft ? DRAFT_LAYER_WORDS : LAYER_WORDS[item.kind],
120
+ draft, waiting: item.waiting === true, updated: text(item.updated), stage: text(item.stage), degree, x: 0, y: 0,
121
+ };
122
+ }
123
+
124
+ /** What the Work list holds that the graph does not: a node for it, drawn nowhere (`old`), for the node panel */
125
+ export const oldNode = (item) => ({ ...workNode(item), old: true });
126
+
127
+ /**
128
+ * A piece of work the graph does not hold (older than its 14 days, or past its caps), as a node of the graph would give it, made from what the Work list read
129
+ * of it: a pull request or an issue of the lists, a thread, a run of the runs list, a deploy, a proposal of the specs list. Null for a kind or a shape it cannot read.
130
+ * Every word of it is the forge's: the panel escapes it, and `url` is an http(s) link or nothing.
131
+ * @param {string} kind pull | issue | thread | run | deploy | proposal
132
+ * @param {object} src the list's own item
133
+ */
134
+ export function oldItem(kind, src) {
135
+ if (!src || typeof src !== 'object') return null;
136
+ const who = (a) => (a && typeof a.login === 'string' ? a.login : null);
137
+ const base = { kind, title: text(src.title), url: safeUrl(src.url), updated: text(src.updatedAt) || text(src.createdAt), waiting: false };
138
+ const num = Number.isInteger(src.number) ? src.number : null;
139
+ switch (kind) {
140
+ case 'pull': return num === null ? null : { ...base, id: `pull:${num}`, stage: 'build', state: text(src.state), open: src.state === 'open', number: num, draft: src.draft === true, author: who(src.author) };
141
+ case 'issue': return num === null ? null : { ...base, id: `issue:${num}`, stage: 'talk', state: text(src.state), open: src.state === 'open', number: num, author: who(src.author) };
142
+ case 'thread': return num === null ? null : { ...base, id: `thread:${num}`, stage: 'talk', state: text(src.state), open: src.state === 'open', number: num, threadKind: text(src.kind), author: who(src.author) };
143
+ case 'run': return typeof src.runId === 'string' ? { ...base, id: `run:${src.runId}`, stage: 'build', title: runName(src), state: text(src.status), open: src.open === true, waiting: canAnswer(src), runId: src.runId, number: null, url: safeUrl(src.report && src.report.url) || safeUrl(src.comment && src.comment.url) || safeUrl(src.pull && src.pull.url), updated: text(src.lastActivity) || text(src.requestedAt), runKind: text(src.kind), requestedBy: src.requestedBy ?? null } : null;
144
+ case 'deploy': return typeof src.id === 'string' ? { ...base, id: `deploy:${src.id}`, stage: 'ship', title: text(src.title) || text(src.name), state: text(src.state), open: src.state === 'queued' || src.state === 'running', deployId: src.id, number: null, updated: text(src.updatedAt) || text(src.createdAt), name: text(src.name), branch: text(src.branch), sha: text(src.sha), author: who(src.actor) } : null;
145
+ case 'proposal': {
146
+ if (typeof src.slug !== 'string') return null;
147
+ const { state, counted } = specStateOf(src);
148
+ const pull = src.pull && Number.isInteger(src.pull.number) ? src.pull : null;
149
+ return { ...base, id: `proposal:${src.slug}`, stage: 'decide', title: text(src.title) || src.slug, state, open: true, waiting: counted, slug: src.slug, number: pull ? pull.number : null, url: safeUrl(pull && pull.url), updated: text(pull && (pull.updatedAt || pull.createdAt)), draft: state === 'local', author: who(pull && pull.author), source: text(src.source) };
150
+ }
151
+ default: return null;
152
+ }
153
+ }
154
+
108
155
  /**
109
156
  * The scene of the Work view.
110
157
  * @param {{ nodes?: object[], edges?: { from: string, to: string, rel: string }[] } | null} graph the server's answer
@@ -142,16 +189,7 @@ export function workScene(graph, mapNodes) {
142
189
  const degree = new Map();
143
190
  for (const e of edges) { degree.set(e.from, (degree.get(e.from) || 0) + 1); degree.set(e.to, (degree.get(e.to) || 0) + 1); }
144
191
  const nodes = [];
145
- for (const item of work.values()) {
146
- const theme = WORK_THEMES[item.kind];
147
- const title = text(item.title) || tagOf(item);
148
- const draft = isDraft(item);
149
- nodes.push({
150
- id: item.id, type: workType(item.kind), work: item.kind, shape: theme.shape, label: item.kind === 'deploy' ? `Deploy · ${clip(title, LABEL_CHARS)}` : `${tagOf(item)} · ${clip(title, LABEL_CHARS)}`,
151
- title, item, r: theme.r, color: theme.color, letters: theme.letters, terms: termsOf(item), groupName: draft ? DRAFT_LAYER_WORDS : LAYER_WORDS[item.kind],
152
- draft, waiting: item.waiting === true, updated: text(item.updated), stage: text(item.stage), degree: degree.get(item.id) || 0, x: 0, y: 0,
153
- });
154
- }
192
+ for (const item of work.values()) nodes.push(workNode(item, degree.get(item.id) || 0));
155
193
  let code = 0;
156
194
  for (const [id, by] of touched) {
157
195
  const base = onMap.get(id);
@@ -165,8 +203,6 @@ export function workScene(graph, mapNodes) {
165
203
  const waiting = nodes.filter((n) => n.waiting).length;
166
204
  return { nodes, edges, counts: { work: work.size, code, waiting } };
167
205
  }
168
- /** The colours of the lines of the Work view: a work-to-work link, a link to code, and what a proposal adds */
169
- const WORK_EDGE_COLORS = { work: '#818cf8', code: '#cbd5e1', adds: '#2dd4bf' };
170
206
 
171
207
  /**
172
208
  * One line of the Work view for the scene (spec 0012 D2, D3): a work-to-work link solid, `mentions` dotted, `adds` dashed; the word of its rel beside a lit one. The scene calls it
@@ -178,10 +214,12 @@ const WORK_EDGE_COLORS = { work: '#818cf8', code: '#cbd5e1', adds: '#2dd4bf' };
178
214
  * @param {boolean} focused whether a node is selected
179
215
  * @param {string} key the line's key
180
216
  * @param {{ PROPOSED_DASH: number[], USAGE_DASH: number[] }} dashes the map's two dash patterns
217
+ * @param {Partial<Record<'work' | 'code' | 'adds', string>>} [colors] what the theme's `--corn-work-edge-<name>` tokens say (`state.workEdgeColors`); a name it does not set is drawn in its default (core/schema.js WORK_EDGE_THEMES)
181
218
  */
182
- export function workEdge(edge, source, target, connected, focused, key, dashes) {
219
+ export function workEdge(edge, source, target, connected, focused, key, dashes, colors) {
183
220
  const lit = focused && connected;
184
- const color = WORK_EDGE_COLORS[edge.kind === 'adds' ? 'adds' : edge.tone === 'work' ? 'work' : 'code'];
221
+ const name = edge.kind === 'adds' ? 'adds' : edge.tone === 'work' ? 'work' : 'code';
222
+ const color = (colors && colors[name]) || WORK_EDGE_THEMES[name];
185
223
  const faded = source.dim === true && target.dim === true; // "Waiting on you" is on and neither end waits
186
224
  return {
187
225
  key, from: edge.from, to: edge.to, kind: edge.kind,
@@ -435,15 +473,15 @@ export function pillStateOf(item) {
435
473
  return PILL_OF[item.state] || (item.open ? 'open' : 'closed');
436
474
  }
437
475
 
438
- /** What the page says of what comes next, under the connections: what the action in the Work panel will do (the actions move here in step 3) */
476
+ /** What the node panel says of what comes next, above the actions: what each will do */
439
477
  export function saysOf(item) {
440
478
  switch (item.kind) {
441
- case 'proposal': return item.waiting ? 'This waits on you. Open it in the Work panel to open the review, approve or send it back.' : 'Open it in the Work panel for the review.';
442
- case 'pull': return item.state === 'open' ? 'Open it in the Work panel to merge when the checks pass, or run the failed ones again.' : 'Nothing waits on you.';
443
- case 'issue': return item.open ? 'Open it in the Work panel to start an agent on it.' : 'Nothing waits on you.';
444
- case 'run': return item.waiting ? 'This waits on your answer. Open it in the Work panel to answer, continue or stop it.' : item.open ? 'Open it in the Work panel to follow it or stop it.' : 'Nothing waits on you.';
445
- case 'thread': return 'Open it in the Work panel to read it and reply.';
446
- default: return 'Open it in the Work panel for its logs, or to run it again.';
479
+ case 'proposal': return item.waiting ? 'This waits on you. Review opens it over the map (Before, Diff, After); there you approve it or send it back.' : 'Review opens it over the map (Before, Diff, After).';
480
+ case 'pull': return item.state === 'open' ? 'Land it merges this pull request at the head shown, once every check has passed; a failed check can be run again.' : 'Nothing waits on you.';
481
+ case 'issue': return item.open ? 'Start an agent asks a runner to work on this issue; a confirm step shows what will be asked.' : 'Nothing waits on you.';
482
+ case 'run': return item.waiting ? 'This waits on your answer: reply, continue or stop it.' : item.open ? 'You can stop it while it works.' : 'Nothing waits on you.';
483
+ case 'thread': return 'A thread is a conversation on the forge: read it here, and reply there.';
484
+ default: return 'Its logs are on the forge; here is what it restarted.';
447
485
  }
448
486
  }
449
487
 
@@ -483,20 +521,26 @@ const dotOf = (kind, color) => { const c = typeof color === 'function' ? color(k
483
521
  const linkButton = (l) => `<button type="button" class="hx-linkbtn" data-corn="node-link" data-action="select-node" data-id="${esc(l.id)}">${esc(l.label)}</button>`;
484
522
 
485
523
  /**
486
- * The node panel's markup for a piece of work (`panelOf`'s answer): its state, what it is connected to (each a button that selects that node), the checks of a pull request,
487
- * the words saying what the action will do, "Open in Work" (the actions move to the node panel in step 3), and a link to the forge when the address is a web one.
524
+ * The node panel's markup for a piece of work (`panelOf`'s answer): its state, what it is connected to (each a button that selects that node), the words saying what the
525
+ * actions will do, the place the actions go (`forge-detail`: the Work piece fills it, pieces/work-paint.js `paintDetail`: Land it, the checks, a run's answer field, Start an agent ...),
526
+ * and a link to the forge when the address is a web one and the actions do not carry it.
488
527
  * @param {ReturnType<typeof panelOf>} p
489
528
  * @param {object} node
490
- * @param {{ color?: (kind: string) => string, checks?: string }} [opts] `color`: a kind's colour as the map draws it; `checks`: the words of a pull request's checks
529
+ * @param {{ color?: (kind: string) => string }} [opts] `color`: a kind's colour as the map draws it
491
530
  */
492
- export function workPanelHtml(p, node, { color = () => '', checks = '' } = {}) {
531
+ export function workPanelHtml(p, node, { color = () => '' } = {}) {
493
532
  const url = safeUrl(p.url);
494
- const links = p.links.length
495
- ? `<div class="hx-fact" data-corn="section"><div class="hx-fact-k">Connected</div><div class="hx-fact-v"><ul class="hx-work-links" data-corn="work-links">${p.links.map((l) => `<li data-corn="work-link"><span class="hx-work-rel">${esc(l.rel)}</span>${dotOf(l.work, color)}${linkButton(l)}${l.planned ? ' <span class="hx-faint">planned</span>' : ''}</li>`).join('')}</ul></div></div>`
496
- : '<div class="hx-fact" data-corn="section"><div class="hx-fact-k">Connected</div><div class="hx-fact-v hx-faint">Nothing it is linked to is drawn.</div></div>';
497
- const checked = node.item.kind === 'pull' ? `<div class="hx-fact" data-corn="section"><div class="hx-fact-k">Checks</div><div class="hx-fact-v" id="work-checks" data-corn="work-checks">${esc(checks)}</div></div>` : '';
498
- const actions = `<div class="hx-work-actions" data-corn="work-actions"><p class="hx-faint">${esc(p.says)}</p><button type="button" class="hx-btn hx-btn--primary hx-foot-btn" data-corn-kind="primary" data-work-action="open-in-work" data-id="${esc(node.id)}">Open in Work</button>${url ? `<a class="hx-btn hx-btn--quiet hx-foot-btn" data-corn-kind="quiet" data-corn="open-link" href="${esc(url)}" target="_blank" rel="noreferrer">Open on the forge ↗</a>` : ''}</div>`;
499
- return `<div class="hx-work-head" data-corn="work-head"><p class="hx-work-pills" data-corn="work-pills">${p.pills.map(pill).join(' ')}</p><p class="hx-faint">${esc(p.tag)}${p.meta ? ` · ${esc(p.meta)}` : ''}</p></div>${links}${checked}${actions}`;
533
+ const kind = node.item.kind;
534
+ const links = node.old
535
+ ? '<div class="hx-fact" data-corn="section"><div class="hx-fact-k">Connected</div><div class="hx-fact-v hx-faint">Its links are not drawn here: it is older than the 14 days the map of work covers, or past its limits.</div></div>'
536
+ : p.links.length
537
+ ? `<div class="hx-fact" data-corn="section"><div class="hx-fact-k">Connected</div><div class="hx-fact-v"><ul class="hx-work-links" data-corn="work-links">${p.links.map((l) => `<li data-corn="work-link"><span class="hx-work-rel">${esc(l.rel)}</span>${dotOf(l.work, color)}${linkButton(l)}${l.planned ? ' <span class="hx-faint">planned</span>' : ''}</li>`).join('')}</ul></div></div>`
538
+ : '<div class="hx-fact" data-corn="section"><div class="hx-fact-k">Connected</div><div class="hx-fact-v hx-faint">Nothing it is linked to is drawn.</div></div>';
539
+ // A pull request's (a spec's too) and a deploy's own actions carry their link to the forge; the others get it here
540
+ const specPull = kind === 'proposal' && Number.isInteger(node.item.number); // its pull request's actions carry the link
541
+ const out = url && kind !== 'pull' && kind !== 'deploy' && !specPull ? `<a class="hx-btn hx-btn--quiet hx-foot-btn" data-corn-kind="quiet" data-corn="open-link" href="${esc(url)}" target="_blank" rel="noreferrer">Open on the forge ↗</a>` : '';
542
+ const actions = `<div class="hx-work-actions" data-corn="work-actions"><p class="hx-faint">${esc(p.says)}</p><section id="forge-detail" class="hx-forge-detail" data-corn="work-detail" aria-label="Actions" data-work-kind="${esc(kind)}" data-work-ref="${esc(node.id)}"></section>${out}</div>`;
543
+ return `<div class="hx-work-head" data-corn="work-head"><p class="hx-work-pills" data-corn="work-pills">${p.pills.map(pill).join(' ')}</p><p class="hx-faint">${esc(p.tag)}${p.meta ? ` · ${esc(p.meta)}` : ''}</p></div>${links}${actions}`;
500
544
  }
501
545
 
502
546
  /** The node panel's section for a node of code in the Work view: the work that touches it, and "Show on the map" (a planned node is not on the map yet) */
@@ -520,9 +564,6 @@ export function touchedBy(node, nodes, edges) {
520
564
  return out.sort((a, b) => Number(b.waiting) - Number(a.waiting) || a.label.localeCompare(b.label));
521
565
  }
522
566
 
523
- /** The checks line of a pull request, from `GET /api/forge/pulls/<n>`'s `checks` ("1 failed, 1 still running", "All 3 passed", "No checks") */
524
- export { checksWords } from './forge-panel-model.js';
525
-
526
567
  // ---------------------------------------------------------------------------
527
568
  // The keyboard (N and P step through the lanes; an arrow goes to the nearest node that way)
528
569
  // ---------------------------------------------------------------------------
@@ -580,7 +621,7 @@ export function workAddress(search) {
580
621
  return params.get('view') === 'work' ? { view: true } : null;
581
622
  }
582
623
 
583
- /** The id of the node an address names, among the nodes of the view, or null (a spec by its number, `0100`, or by its whole slug) */
624
+ /** The id of the node an address or a row of the Work list names, among the nodes of the view, or null (a spec by its number, `0100`, or by its whole slug; a deploy by its id) */
584
625
  export function nodeForAddress(ask, nodes) {
585
626
  if (!ask || !ask.kind) return null;
586
627
  const mine = nodes.filter((n) => n.work === ask.kind);
@@ -588,7 +629,7 @@ export function nodeForAddress(ask, nodes) {
588
629
  if (ask.kind === 'issue' && !mine.some((n) => String(n.item.number) === ask.key)) { const idea = nodes.find((n) => n.work === 'thread' && String(n.item.number) === ask.key); if (idea) return idea.id; } // an idea is an issue on the forge, drawn as a thread
589
630
  const hit = ask.kind === 'proposal'
590
631
  ? mine.find((n) => n.item.slug === ask.key) || mine.find((n) => specNumber(text(n.item.slug)) === ask.key)
591
- : ask.kind === 'run' ? mine.find((n) => n.item.runId === ask.key) : mine.find((n) => String(n.item.number) === ask.key);
632
+ : ask.kind === 'run' ? mine.find((n) => n.item.runId === ask.key) : ask.kind === 'deploy' ? mine.find((n) => n.item.deployId === ask.key) : mine.find((n) => String(n.item.number) === ask.key);
592
633
  return hit ? hit.id : null;
593
634
  }
594
635
 
@@ -1,9 +1,10 @@
1
- /* The Work view (explorer/work-view.js, spec 0012): the toggle at the top left of the stage, the line of what could not be read, and the node panel's work detail. */
1
+ /* The Work view (explorer/work-view.js, spec 0012): the toggles at the top left of the stage (All work, Waiting on you, List), the line of what could not be read, and the node panel's work detail. */
2
2
  .hx-work-bar { position: absolute; z-index: 4; left: var(--corn-space-4); top: var(--corn-space-4); display: flex; gap: var(--corn-space-2); }
3
3
  .hx-work-bar { align-items: center; }
4
4
  .hx-work-bar[hidden] { display: none; }
5
5
  .hx-work-chip { box-sizing: border-box; min-height: 2rem; padding: 0 var(--corn-space-4); border: var(--corn-border) solid var(--corn-line); border-radius: var(--corn-radius-pill); background: var(--corn-surface-1); color: var(--corn-text-2); font-family: inherit; font-size: var(--corn-text-xs); font-weight: 600; cursor: pointer; }
6
- .hx-work-chip[aria-pressed="true"] { background: var(--corn-accent); border-color: var(--corn-accent); color: var(--corn-text-on-accent); }
6
+ .hx-work-chip[aria-pressed="true"], .hx-work-chip[aria-expanded="true"] { background: var(--corn-accent); border-color: var(--corn-accent); color: var(--corn-text-on-accent); }
7
+ .hx-work-chip[hidden] { display: none; }
7
8
  .hx-work-chip:focus-visible { outline: var(--corn-focus-width) solid var(--corn-focus); outline-offset: var(--corn-focus-offset); }
8
9
  .hx-work-note { position: absolute; z-index: 3; left: var(--corn-space-4); bottom: var(--corn-space-4); max-width: min(32rem, calc(100% - var(--corn-space-8))); margin: 0; padding: var(--corn-space-2) var(--corn-space-3); border-radius: var(--corn-radius); background: var(--corn-surface-1); color: var(--corn-text-2); font-size: var(--corn-text-xs); }
9
10
  .hx-work-note[hidden] { display: none; }
@@ -44,8 +45,6 @@
44
45
  .hx-stage.is-work .hx-hint { display: none; } /* the toggles' row is where the hint would sit */
45
46
  .hx-work-skeleton { grid-template-columns: 1fr; grid-auto-rows: min-content; top: calc(var(--corn-space-4) + var(--hx-control-h) * 2 + var(--corn-space-6)); overflow: hidden; }
46
47
  .hx-work-skel-lane i:nth-of-type(n + 3) { display: none; }
47
- /* The header's own Work button (the panel, until step 3 of spec 0012 retires it) is not on a phone: the view switch's Work carries the badge */
48
- .hx-work[data-corn="forge-button"] { display: none; }
49
48
  }
50
49
  /* The Layers menu in the Work view lists the Work view's rows; the map's keys (its kinds of line, the cloud's, the runs' and the proposal marks') are about the map */
51
50
  body:has(.hx-stage.is-work) .hx-layers :is([data-corn="legend-key"], [data-corn="menu-section"]) { display: none; }
@@ -5,16 +5,18 @@
5
5
  * (server/work-graph.js). Page code, as house.js is for the House view: it reads `location` and listens on `document`.
6
6
  *
7
7
  * initWorkView({ offered }) once, after the config: the Work button of the view switch (shown when the config names a forge), the toggle, the clicks
8
- * openWork({ select }) opens the view (the camera fits), asks the server for the work graph (once; again on Refresh and on the poll the Work
9
- * panel makes), and selects a node of it when `select` names one; closeWork() goes back to the map
10
- * followWorkAddress() `?view=work`, `?pr=`, `?issue=`, `?run=`, `?thread=` and `?spec=` (work-model.js `workAddress`)
8
+ * openWork({ select }) opens the view (the camera fits), asks the server for the work graph (once; again on Refresh and every minute while it is open),
9
+ * and selects a node of it when `select` names one; closeWork() goes back to the map
10
+ * followWorkAddress() `?view=work`, `?pr=`, `?issue=`, `?run=`, `?thread=` and `?spec=` (work-model.js `workAddress`): the node, or for work older than the graph's
11
+ * 14 days the Work list and the node panel (pieces/work-list.js `showRef`)
11
12
  *
12
- * What it puts on the page: the view switch's Work button, with "waiting on you" as its badge (the number the Work panel's button used to say, in the same
13
- * words), the toggle at the top left of the stage ("All work" and "Waiting on you"), the lanes' titles in screen space (the map draws the lanes' panels), the words
13
+ * What it puts on the page: the view switch's Work button, with "waiting on you" as its badge, the toggles at the top left of the stage ("All work", "Waiting on you" and
14
+ * **List**, which opens the Work list (pieces/work-list.js) where the side panel sat), the lanes' titles in screen space (the map draws the lanes' panels), the words
14
15
  * and the empty lanes shown at once while the first answer is on its way (the page stays usable: the views, the Layers menu, search), "Updating…" while a refresh
15
16
  * is (the last answer stays on the map, and a refresh that fails keeps it and says so), the map's own card when the answer is refused (signed out, not a maintainer,
16
17
  * offline: pieces/status.js), and a quiet line naming what the server could not read (`problems`). It answers the node panel's `work:panel` ask with what a node says in
17
- * the Work view, and holds the keys of the view: N and P step through the lanes, an arrow goes to the nearest node that way. Every request goes through `credentialed`;
18
+ * the Work view (the Work piece draws the actions into it), the Work list's `work:pick` ask by selecting that row's node, and holds the keys of the view: N and P step through
19
+ * the lanes, an arrow goes to the nearest node that way. Every request goes through `credentialed`;
18
20
  * every word that comes from the forge is escaped or set as text, every link goes through `safeUrl` (work-model.js).
19
21
  */
20
22
 
@@ -24,19 +26,18 @@ import { closeDrawer } from './panels.js';
24
26
  import { announce } from './engine/keyboard.js';
25
27
  import { credentialed } from './engine/connection.js';
26
28
  import { selectNode } from './engine/selection.js';
27
- import { closeProposal } from './engine/proposal.js';
29
+ import { closeProposal, openProposal } from './engine/proposal.js';
28
30
  import { signInUrl } from './engine/source.js';
29
- import { mapStyleOf, workToken } from './engine/map-style.js';
31
+ import { mapStyleOf, workToken, workEdgeToken } from './engine/map-style.js';
30
32
  import { t } from './engine/strings.js';
31
33
  import { mount as mountStatus } from './pieces/status.js';
32
34
  import { fitGraphToViewport, fitPadding, onPaint, render } from './render.js';
33
35
  import { isPhone } from './sheets.js';
34
- import { WORK_KINDS, WORK_THEMES } from '../core/schema.js';
36
+ import { WORK_KINDS, WORK_THEMES, WORK_EDGES } from '../core/schema.js';
35
37
  import { workButtonName } from './waiting-model.js';
36
38
  import { stepFrom } from './keyboard-model.js';
37
- import { checksWords, pullUrl } from './forge-panel-model.js';
38
39
  import { RUNS_POLL_MS } from './pieces/work-common.js';
39
- import { openWorkAt, openRunLink, openIssueLink } from './forge-panel.js';
40
+ import { showWorkRef, openForge, closeForge } from './forge-panel.js';
40
41
  import {
41
42
  CODE_LAYER, DRAFT_LAYER, KIND_WORDS, applyFilters, arrowTarget, landingWords, applyWorkLayout, codePanelHtml, layerRowsOf, newWorkState, nodeForAddress, openedWords, panelOf, setWorkGraph, showWork, touchedBy, workAddress, workPanelHtml,
42
43
  } from './work-model.js';
@@ -53,7 +54,6 @@ let offPaint = null;
53
54
  let card = null; // the map's own card (pieces/status.js)
54
55
  let timer = 0;
55
56
  let seq = 0; // the answer that is waited for: an older one is dropped
56
- let pullDetail = new Map(); // pull number -> { head, text } what the checks said of the head (the node panel's line)
57
57
  let wasOn = false;
58
58
 
59
59
  const inst = () => pageInstance();
@@ -67,6 +67,7 @@ export function initWorkView(opts = {}) {
67
67
  if (btn) btn.hidden = !offered;
68
68
  work();
69
69
  mount();
70
+ paintEdgeColors();
70
71
  if (!wired) {
71
72
  wired = true;
72
73
  const i = inst();
@@ -77,12 +78,27 @@ export function initWorkView(opts = {}) {
77
78
  i.on('work:open', ({ id }) => openWork({ select: id }));
78
79
  i.on('search:more', () => (work().status === 'ok' && !on() ? work().nodes.filter((n) => n.work) : null));
79
80
  i.on('work:waiting', ({ total }) => paintBadge(total));
81
+ i.on('work:available', ({ on: available }) => paintList(available));
80
82
  i.on('work:panel', (node) => panelFor(node));
81
- mapStyleOf(i).onChange(() => { if (on()) { state.workRows = layerRowsOf(work().nodes).map(themed); i.emit('layers:redraw'); } });
83
+ i.on('work:pick', (ref) => pickRef(ref));
84
+ mapStyleOf(i).onChange(() => { paintEdgeColors(); if (on()) { state.workRows = layerRowsOf(work().nodes).map(themed); i.emit('layers:redraw'); i.touchScene(); render(); } });
82
85
  }
83
86
  syncWork();
84
87
  }
85
88
 
89
+ /** The List toggle is shown while the Work piece is on (a forge in the config and somebody signed in); the piece says its own `aria-expanded` */
90
+ function paintList(available) {
91
+ if (els && els.list) els.list.hidden = !available;
92
+ }
93
+
94
+ /** The colours the theme gives the Work view's lines (`--corn-work-edge-<name>`), for the scene: a name it does not set is drawn in its default (work-model.js `workEdge`) */
95
+ function paintEdgeColors() {
96
+ const values = mapStyleOf(inst()).get().values;
97
+ const colors = {};
98
+ for (const name of WORK_EDGES) if (values[workEdgeToken(name)]) colors[name] = values[workEdgeToken(name)];
99
+ state.workEdgeColors = colors;
100
+ }
101
+
86
102
  /** The Work button's badge and its spoken name: "Work, 3 waiting on you" (the Work panel's own words: waiting-model.js) */
87
103
  function paintBadge(total) {
88
104
  const btn = $('preset-work-btn');
@@ -108,6 +124,7 @@ function mount() {
108
124
  bar.hidden = true;
109
125
  bar.innerHTML = '<button type="button" class="hx-work-chip" data-corn="work-chip" data-corn-kind="quiet" data-work-show="all" aria-pressed="true">All work</button>'
110
126
  + '<button type="button" class="hx-work-chip" data-corn="work-chip" data-corn-kind="quiet" data-work-show="waiting" aria-pressed="false">Waiting on you</button>'
127
+ + '<button type="button" class="hx-work-chip" data-corn="work-chip" data-corn-kind="quiet" data-action="toggle-forge" aria-expanded="false" aria-controls="forge-panel" aria-label="Work list" title="The lists of issues, pull requests, proposals, threads, runs and deploys" hidden>List</button>'
111
128
  + '<span class="hx-work-busy" hidden>Updating…</span>';
112
129
  const note = document.createElement('p');
113
130
  note.className = 'hx-work-note';
@@ -127,7 +144,8 @@ function mount() {
127
144
  loading.innerHTML = `<div class="hx-work-skeleton" aria-hidden="true">${['Talk', 'Decide', 'Build', 'Ship', 'Code it touches'].map((name) => `<div class="hx-work-skel-lane"><span class="hx-work-lane-title">${name}</span><i></i><i></i><i></i><i></i></div>`).join('')}</div>`
128
145
  + '<p class="hx-work-loading-text" role="status">Reading the work from the forge. A big repository can take several seconds the first time; the page works meanwhile.</p>';
129
146
  stage.append(lanes, loading, bar, note);
130
- els = { stage, bar, all: bar.children[0], waiting: bar.children[1], busy: bar.children[2], note, lanes, loading };
147
+ els = { stage, bar, all: bar.children[0], waiting: bar.children[1], list: bar.children[2], busy: bar.children[3], note, lanes, loading };
148
+ paintList(!!inst().ask('work:on')); // the List toggle is there while the Work piece is on: a signed-in maintainer of a forge
131
149
  if (offPaint) offPaint();
132
150
  offPaint = onPaint(paintLanes);
133
151
  watchSize(stage);
@@ -229,7 +247,11 @@ function syncWork() {
229
247
  wasOn = open;
230
248
  clearTimeout(timer);
231
249
  if (open) timer = setTimeout(poll, RUNS_POLL_MS);
232
- else if (card) card.clear();
250
+ else {
251
+ if (card) card.clear();
252
+ closeForge({ restoreFocus: false }); // the list is the Work view's
253
+ if (!state.selectedNode) inst().emit('node:close'); // a piece of work the node panel showed from the lists, with nothing selected
254
+ }
233
255
  }
234
256
  }
235
257
 
@@ -360,14 +382,20 @@ function arrive(body, { select, ask, quiet }) {
360
382
  const node = state.selectedNode;
361
383
  announce(i, `${opened} ${landingWords(node, shown.indexOf(node), shown.length)}`.trim());
362
384
  } else if (ask && ask.kind) {
363
- // A run or an issue older than the graph's window (a link posted in chat weeks ago) is still in the Work panel's lists: the panel opens at it, as these links did before
364
- const older = !ask.bad && (ask.kind === 'run' || ask.kind === 'issue');
365
- announce(i, `${ask.bad || `There is no ${KIND_WORDS[ask.kind].toLowerCase()} ${ask.key} in the work now${older ? ': the Work panel looks for it' : ''}.`} ${opened}`.trim());
366
- if (older) (ask.kind === 'run' ? openRunLink(ask.key) : openIssueLink(Number(ask.key))).catch(() => {});
385
+ // Work older than the graph's window (a link posted in chat weeks ago) is in the Work list: the list opens on its tab and the node panel shows it, as a row of the list does
386
+ if (ask.bad) announce(i, `${ask.bad} ${opened}`.trim());
387
+ else {
388
+ announce(i, `${KIND_WORDS[ask.kind]} ${ask.key} is not in the work drawn here: the Work list looks for it. ${opened}`.trim());
389
+ openForge({ tab: LIST_TAB[ask.kind], quiet: true }); // what the node panel shows is said, not the list's count
390
+ showWorkRef(ask.kind, ask.key).catch(() => {});
391
+ }
367
392
  } else if (opened) announce(i, opened);
368
393
  return true;
369
394
  }
370
395
 
396
+ /** The Work list's tab for a kind of work (its names are the tabs': pieces/work-common.js TABS) */
397
+ const LIST_TAB = Object.freeze({ pull: 'pulls', issue: 'issues', thread: 'threads', run: 'work', deploy: 'deploys', proposal: 'specs' });
398
+
371
399
  /** The nodes N and P step through, in the lanes' order: what is shown */
372
400
  const shownInOrder = () => work().order.map((id) => state.nodes.find((n) => n.id === id)).filter((n) => n && !n.hidden);
373
401
 
@@ -419,37 +447,30 @@ function setWaiting(on_) {
419
447
  /** The kind's colour as the map draws it: the theme's token, else the default (the style goes on through `data-style`, which a host's CSP allows) */
420
448
  const colorOf = (kind) => { const v = mapStyleOf(inst()).get().values[workToken(kind)]; return /^#[0-9a-f]{3,8}$/i.test(v || '') ? v : WORK_THEMES[kind] ? WORK_THEMES[kind].color : ''; };
421
449
 
422
- /** What the node panel shows for a node while the Work view is open (`work:panel`): a piece of work, replaced; a node of code, with the work that touches it first (work-model.js builds the markup) */
450
+ /**
451
+ * What the node panel shows for a node (`work:panel`): a piece of work, replaced (the Work piece draws its actions into it: pieces/work-paint.js `paintDetail`); a node of code in
452
+ * the Work view, with the work that touches it first (work-model.js builds the markup). A piece of work the graph does not hold (`old`, shown from the Work list or a link) is
453
+ * shown the same way in any view.
454
+ */
423
455
  function panelFor(node) {
424
- if (!on() || !node) return undefined;
456
+ if (!node) return undefined;
425
457
  const w = work();
426
- if (node.work) {
427
- const p = panelOf(node, w.nodes, w.edges);
428
- if (node.item.kind === 'pull') loadChecks(node);
429
- return { replace: true, badge: p.kind, title: p.title, html: workPanelHtml(p, node, { color: colorOf, checks: checksLine(node) }) };
458
+ if (node.work && (on() || node.old)) {
459
+ const p = node.old ? panelOf(node, [], []) : panelOf(node, w.nodes, w.edges);
460
+ return { replace: true, badge: p.kind, title: p.title, html: workPanelHtml(p, node, { color: colorOf }) };
430
461
  }
431
- return { replace: false, html: codePanelHtml(node, touchedBy(node, w.nodes, w.edges), { color: colorOf }) };
462
+ return on() ? { replace: false, html: codePanelHtml(node, touchedBy(node, w.nodes, w.edges), { color: colorOf }) } : undefined;
432
463
  }
433
464
 
434
- /** What the checks of a pull request's head say, once read; "Reading the checks…" until then */
435
- const checksLine = (node) => {
436
- const got = pullDetail.get(node.item.number);
437
- return got ? got.text : 'Reading the checks…';
438
- };
439
-
440
- /** The checks are not in the graph: they are read from the pull request's own route when its node is opened, and painted into the panel when they arrive */
441
- async function loadChecks(node) {
442
- const n = node.item.number;
443
- const i = inst();
444
- let text = 'The checks could not be read.';
445
- try {
446
- const res = await credentialed(i)(pullUrl(n), { headers: { accept: 'application/json' } });
447
- const body = res.ok ? await res.json() : null;
448
- if (body && Array.isArray(body.checks)) text = checksWords(body.checks);
449
- } catch { /* said in the panel */ }
450
- pullDetail.set(n, { text });
451
- const el = document.getElementById('work-checks');
452
- if (el && state.selectedNode && state.selectedNode.id === node.id) el.textContent = text;
465
+ /** A row of the Work list (or a link) names a piece of work: its node is selected on the map, with the camera on it, and the live region says where it is; false when the view does not draw it */
466
+ function pickRef(ref) {
467
+ if (!on() || work().status !== 'ok') return false;
468
+ const id = nodeForAddress(ref, work().nodes);
469
+ if (!id || !pick(id, { frame: true, source: 'link' })) return false;
470
+ const shown = shownInOrder();
471
+ const node = state.selectedNode;
472
+ if (node) announce(inst(), landingWords(node, shown.indexOf(node), shown.length));
473
+ return true;
453
474
  }
454
475
 
455
476
  // ---------------------------------------------------------------------------
@@ -484,10 +505,18 @@ function onClick(e) {
484
505
  if (show && on()) { setWaiting(show.dataset.workShow === 'waiting'); return; }
485
506
  const act = t_.closest('[data-work-action]');
486
507
  if (!act) return;
508
+ if (act.dataset.workAction === 'review') { reviewSpec(act.dataset.slug, act.dataset.source); return; }
487
509
  const node = state.nodes.find((n) => n.id === act.dataset.id);
488
- if (!node) return;
489
- if (act.dataset.workAction === 'open-in-work') openWorkAt(node.item);
490
- else if (act.dataset.workAction === 'show-on-map') showOnMap(node.id);
510
+ if (node && act.dataset.workAction === 'show-on-map') showOnMap(node.id);
511
+ }
512
+
513
+ /** A proposal's Review: the map is the review's (Before, Diff, After lay it over the map), so the view goes back to it and the proposal opens; Approve and Send back are the review's own */
514
+ function reviewSpec(slug, source) {
515
+ if (!slug) return;
516
+ const i = inst();
517
+ closeWork();
518
+ i.emit('node:close'); // a proposal shown from the lists has nothing selected to close it
519
+ openProposal(i, slug, source || null).catch(() => {});
491
520
  }
492
521
 
493
522
  /** A node of code, on the map: the view goes back to it, the node selected and in view */
@@ -535,7 +564,6 @@ export function resetWorkViewForTests() {
535
564
  els = null;
536
565
  card = null;
537
566
  seq++;
538
- pullDetail = new Map();
539
567
  wasOn = false;
540
568
  }
541
569
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@popcorn245/cornfield",
3
- "version": "0.55.0",
3
+ "version": "0.56.0",
4
4
  "description": "A self-hostable dev dashboard with the topology map at its centre: proposals on the map, scenarios, outages and what-if edits, for any repo.",
5
5
  "license": "MIT",
6
6
  "author": "popcorn245 (https://github.com/popcorn245)",