@intentius/behold 0.29.31 → 0.29.33
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/package.json +1 -1
- package/web/app.js +93 -2
- package/web/event-help-modal.js +280 -0
- package/web/event-help-modal.test.js +180 -0
- package/web/event-help-store.js +23 -0
- package/web/index.html +4 -1
- package/web/kiosk-event-help-ui.js +389 -0
- package/web/kiosk-event-help.js +237 -0
- package/web/kiosk-event-help.test.js +144 -0
- package/web/kiosk-runs.js +18 -1
- package/web/kiosk-trace.js +8 -3
- package/web/kiosk-wave-traces.js +104 -0
- package/web/kiosk-wave-traces.test.js +53 -0
- package/web/kiosk.html +30 -0
- package/web/kiosk.js +218 -16
package/web/kiosk.js
CHANGED
|
@@ -18,6 +18,8 @@ import { PICK_HOLD_MS, annMark, mergeRun, startRuns, statusIcon } from "./kiosk-
|
|
|
18
18
|
import { MODES, MODE_STORE, badges as waveBadges, badgeTitle, captionModel, doraLine, modeStored, placeBeside, resultModel, shotFor, stepTone, tailLines } from "./kiosk-watch.js";
|
|
19
19
|
import { shotMessage } from "./kiosk-shot.js";
|
|
20
20
|
import { mountTrace } from "./kiosk-trace.js";
|
|
21
|
+
import { startEventHelp } from "./kiosk-event-help-ui.js";
|
|
22
|
+
import { miniWaterfall, phaseWords, waveTraces } from "./kiosk-wave-traces.js";
|
|
21
23
|
import { PANEL_STEPS, PANEL_TITLE, approvalModel, cycleRuns, digestHex, rowFacts } from "./kiosk-approval.js";
|
|
22
24
|
import { getThemeName, mountThemePicker, onThemeChange } from "./theme.js";
|
|
23
25
|
import { cssString, hoverCss, hoverFromMessage, hoverLinks, hoverMessage, isLightBg, rootSegments, rootText } from "./kiosk-roots.js";
|
|
@@ -908,12 +910,48 @@ function drawResult(host, model, s) {
|
|
|
908
910
|
const counts = el("ul", "k-result-counts");
|
|
909
911
|
for (const c of model.counts) counts.appendChild(el("li", null, c));
|
|
910
912
|
host.appendChild(counts);
|
|
911
|
-
|
|
913
|
+
// behold#571: each wave's trace as one bar of its phases; a click opens the whole trace. A wave without one keeps its numbers.
|
|
914
|
+
const rows = miniWaterfall(s.waveTraces || {});
|
|
915
|
+
const traced = new Set(rows.map((r) => r.wave));
|
|
916
|
+
const untraced = model.waves.filter((w) => !traced.has(w.wave));
|
|
917
|
+
if (untraced.length) {
|
|
912
918
|
const list = el("dl", "k-result-waves");
|
|
913
|
-
for (const w of
|
|
919
|
+
for (const w of untraced) list.append(el("dt", null, `Wave ${w.wave}`), el("dd", null, w.words));
|
|
914
920
|
host.appendChild(list);
|
|
915
921
|
}
|
|
922
|
+
if (rows.length) {
|
|
923
|
+
const wf = el("div", "k-wf");
|
|
924
|
+
for (const r of rows) {
|
|
925
|
+
const row = el("button", "k-wf-row");
|
|
926
|
+
row.type = "button";
|
|
927
|
+
const held = r.bars.find((b) => b.phase === "held");
|
|
928
|
+
row.title = `${TRACE_OPEN_WORDS} · ${r.bars.map(phaseWords).join(" · ")}`;
|
|
929
|
+
const track = el("span", "k-wf-track");
|
|
930
|
+
for (const b of r.bars) {
|
|
931
|
+
const seg = el("i", `k-wf-seg k-wf-${b.phase}`);
|
|
932
|
+
seg.style.left = `${(b.at * 100).toFixed(2)}%`;
|
|
933
|
+
seg.style.width = `${Math.max(0.6, b.width * 100).toFixed(2)}%`;
|
|
934
|
+
seg.title = phaseWords(b);
|
|
935
|
+
track.appendChild(seg);
|
|
936
|
+
}
|
|
937
|
+
row.append(el("span", "k-wf-wave", `Wave ${r.wave}`), track, el("span", "k-wf-ms", held ? phaseWords(held) : r.words), el("span", "k-wf-go", TRACE_LINK_WORDS));
|
|
938
|
+
row.addEventListener("click", () => s.openWave && s.openWave(r.wave, "trace"));
|
|
939
|
+
wf.appendChild(row);
|
|
940
|
+
}
|
|
941
|
+
const key = el("p", "k-wf-key");
|
|
942
|
+
for (const [cls, words] of PHASE_KEY) {
|
|
943
|
+
const k = el("span");
|
|
944
|
+
k.append(el("i", `k-wf-sw k-wf-${cls}`), words);
|
|
945
|
+
key.appendChild(k);
|
|
946
|
+
}
|
|
947
|
+
wf.appendChild(key);
|
|
948
|
+
host.appendChild(wf);
|
|
949
|
+
}
|
|
916
950
|
}
|
|
951
|
+
/** behold#571: the words of a trace's links, and the phases' key. */
|
|
952
|
+
export const TRACE_LINK_WORDS = "Trace";
|
|
953
|
+
export const TRACE_OPEN_WORDS = "Open this wave's trace";
|
|
954
|
+
export const PHASE_KEY = [["plan", "plan"], ["held", "held for an approval"], ["apply", "apply"], ["report", "report and upload"]];
|
|
917
955
|
|
|
918
956
|
/** behold#571: the head over the intro, in the card's box between scenarios, and the title of "What is this?". */
|
|
919
957
|
export const INTRO_HEAD = "What this demo is about";
|
|
@@ -1025,6 +1063,10 @@ function fade(b) {
|
|
|
1025
1063
|
b.classList.toggle("k-more-above", b.scrollTop > 1);
|
|
1026
1064
|
}
|
|
1027
1065
|
|
|
1066
|
+
/** behold#571: how often a cycle's run's traces are read again, and how long after a run ends they still are. */
|
|
1067
|
+
export const TRACE_POLL_MS = 8_000;
|
|
1068
|
+
export const TRACE_SETTLE_MS = 90_000;
|
|
1069
|
+
|
|
1028
1070
|
/** behold#571: the longest a reloaded frame loads out of sight before it swaps in anyway. */
|
|
1029
1071
|
export const FRAME_SWAP_MS = 30_000;
|
|
1030
1072
|
/** behold#571: how long the first frame load waits for demo.json, so it opens on the step's checkout. */
|
|
@@ -1040,7 +1082,7 @@ export const DEMO_POLL_MS = 3_000;
|
|
|
1040
1082
|
* countdown. When the roots the step is about change, move the framed view
|
|
1041
1083
|
* with a `behold:view` message; the frame takes them only from this origin.
|
|
1042
1084
|
*/
|
|
1043
|
-
export function startKiosk({ bar, frame, side, main, views, read = null, tools = null, watch = null }, { fetchJson = defaultFetch, now = () => new Date(), origin = location.origin, tool = null } = {}) {
|
|
1085
|
+
export function startKiosk({ bar, frame, side, main, views, read = null, tools = null, watch = null, eh = null }, { fetchJson = defaultFetch, now = () => new Date(), origin = location.origin, tool = null } = {}) {
|
|
1044
1086
|
const s = { demo: null, answer: null, progress: null, components: false, pick: null, view: "resources", roots: [], waves: [], light: false, hover: null, frameHover: null, held: null };
|
|
1045
1087
|
// behold#571: Watch or Inspect, the viewer's pick kept in their browser; Watch until they pick Inspect.
|
|
1046
1088
|
const shelf = typeof localStorage !== "undefined" ? (() => { try { return localStorage; } catch { return null; } })() : null;
|
|
@@ -1049,6 +1091,10 @@ export function startKiosk({ bar, frame, side, main, views, read = null, tools =
|
|
|
1049
1091
|
s.watchHeld = null;
|
|
1050
1092
|
s.boxes = null;
|
|
1051
1093
|
s.shot = null;
|
|
1094
|
+
// behold#571: event-help, started further down once what it reads is in place.
|
|
1095
|
+
let ehApi = null;
|
|
1096
|
+
// behold#571: each wave's trace, from Tempo (web/kiosk-wave-traces.js).
|
|
1097
|
+
s.waveTraces = {};
|
|
1052
1098
|
// behold#571: the frame loading out of sight while the shown one stays up (openFrame), and a message to both.
|
|
1053
1099
|
let buffer = null;
|
|
1054
1100
|
const post = (msg) => {
|
|
@@ -1133,7 +1179,9 @@ export function startKiosk({ bar, frame, side, main, views, read = null, tools =
|
|
|
1133
1179
|
}
|
|
1134
1180
|
const a = hoverLinks(s.hover, s.waves);
|
|
1135
1181
|
const b = hoverLinks(s.frameHover, s.waves);
|
|
1136
|
-
|
|
1182
|
+
// behold#571 event-help: an event's things light as a hover lights them, while its tip is up.
|
|
1183
|
+
const c = hoverLinks(s.hover || s.frameHover ? null : s.ehLit, s.waves);
|
|
1184
|
+
const links = { roots: [...new Set([...a.roots, ...b.roots, ...c.roots])], waves: [...new Set([...a.waves, ...b.waves, ...c.waves])] };
|
|
1137
1185
|
style.textContent = [
|
|
1138
1186
|
// behold#571: the held wave's job row, lit as the hold panel is; a hover's light comes after it and wins.
|
|
1139
1187
|
Number.isInteger(s.held) ? `.r-job[data-k-wave="${s.held}"] { ${HELD_JOB_RULE} }` : "",
|
|
@@ -1143,7 +1191,7 @@ export function startKiosk({ bar, frame, side, main, views, read = null, tools =
|
|
|
1143
1191
|
};
|
|
1144
1192
|
// behold#571: with nothing pointed at, the frame lights the held wave's box, as the hold panel and its job row are lit.
|
|
1145
1193
|
const tellHover = (h) => {
|
|
1146
|
-
const lit = h || (Number.isInteger(s.held) ? { wave: s.held } : null);
|
|
1194
|
+
const lit = h || s.ehLit || (Number.isInteger(s.held) ? { wave: s.held } : null);
|
|
1147
1195
|
post(hoverMessage(lit));
|
|
1148
1196
|
};
|
|
1149
1197
|
const hoverAt = (target) => {
|
|
@@ -1277,6 +1325,7 @@ export function startKiosk({ bar, frame, side, main, views, read = null, tools =
|
|
|
1277
1325
|
}
|
|
1278
1326
|
tellFrame(false);
|
|
1279
1327
|
tellShot(false);
|
|
1328
|
+
if (ehApi) ehApi.tick();
|
|
1280
1329
|
};
|
|
1281
1330
|
|
|
1282
1331
|
// ---------------------------------------------------------------------------
|
|
@@ -1287,6 +1336,9 @@ export function startKiosk({ bar, frame, side, main, views, read = null, tools =
|
|
|
1287
1336
|
let lastShot = null;
|
|
1288
1337
|
let drawerOpen = false;
|
|
1289
1338
|
let drawerHover = false;
|
|
1339
|
+
// behold#571: a wave the viewer opened the drawer on, its trace or its log; null follows the step.
|
|
1340
|
+
let drawerWave = null;
|
|
1341
|
+
let drawerView = null;
|
|
1290
1342
|
const isPhone = () => typeof matchMedia === "function" && matchMedia("(max-width: 600px)").matches;
|
|
1291
1343
|
const runsParent = main ? main.parentNode : null;
|
|
1292
1344
|
const runsNext = main ? main.nextSibling : null;
|
|
@@ -1325,6 +1377,8 @@ export function startKiosk({ bar, frame, side, main, views, read = null, tools =
|
|
|
1325
1377
|
draw();
|
|
1326
1378
|
};
|
|
1327
1379
|
s.followSteps = () => {
|
|
1380
|
+
drawerWave = null;
|
|
1381
|
+
drawerView = null;
|
|
1328
1382
|
watchHoldAt = null;
|
|
1329
1383
|
s.watchHeld = null;
|
|
1330
1384
|
lastShot = null;
|
|
@@ -1337,16 +1391,25 @@ export function startKiosk({ bar, frame, side, main, views, read = null, tools =
|
|
|
1337
1391
|
watchHoldAt = null;
|
|
1338
1392
|
s.watchHeld = null;
|
|
1339
1393
|
lastShot = null;
|
|
1394
|
+
// The steps lead again: a drawer the viewer opened on a wave folds away with the hold.
|
|
1395
|
+
drawerWave = null;
|
|
1396
|
+
drawerView = null;
|
|
1340
1397
|
return;
|
|
1341
1398
|
}
|
|
1342
1399
|
s.watchHeld = { secs: Math.ceil(left / 1000) };
|
|
1343
1400
|
}
|
|
1401
|
+
/** behold#571: the caption's top, or event-help's trail's when it sits over the caption. */
|
|
1402
|
+
const captionTop = (cap) => {
|
|
1403
|
+
const trail = eh && eh.trailHost;
|
|
1404
|
+
const r = trail && !trail.hidden && trail.getBoundingClientRect ? trail.getBoundingClientRect() : null;
|
|
1405
|
+
return r && r.height && r.top < cap.top ? r.top : cap.top;
|
|
1406
|
+
};
|
|
1344
1407
|
/** How much of the frame the overlays cover, in the frame's pixels: the caption below, and the callout, drawer or card beside the shot. */
|
|
1345
1408
|
const shotInsets = (shot) => {
|
|
1346
1409
|
if (!watch || !frame || isPhone() || !frame.getBoundingClientRect) return {};
|
|
1347
1410
|
const f = frame.getBoundingClientRect();
|
|
1348
1411
|
const cap = watch.caption.getBoundingClientRect();
|
|
1349
|
-
const bottom = Math.max(0, f.bottom - cap
|
|
1412
|
+
const bottom = Math.max(0, f.bottom - captionTop(cap)) + 16;
|
|
1350
1413
|
const side = shot.kind === "held" ? watch.callout : shot.kind === "active" ? watch.drawer : shot.kind === "result" ? watch.result : null;
|
|
1351
1414
|
// The result card sits right beside the graph (placeBeside's gap): an inset of its width and that gap centres the two together.
|
|
1352
1415
|
const right = side && !side.hidden && side.offsetWidth ? side.offsetWidth + (shot.kind === "result" ? 18 : 44) : 0;
|
|
@@ -1380,13 +1443,20 @@ export function startKiosk({ bar, frame, side, main, views, read = null, tools =
|
|
|
1380
1443
|
const call = shot.kind === "held" && gate;
|
|
1381
1444
|
watch.callout.hidden = !call;
|
|
1382
1445
|
if (call) drawCallout(watch.callout, s, hold, badgeTitle(nums[hold.wave]));
|
|
1383
|
-
const
|
|
1384
|
-
const
|
|
1446
|
+
const opened = drawerWave !== null;
|
|
1447
|
+
const drawer = shot.kind === "active" || opened;
|
|
1448
|
+
const drawerOn = opened ? drawerWave : shot.waves[0];
|
|
1449
|
+
const open = drawer && (drawerOpen || drawerHover || opened);
|
|
1385
1450
|
watch.drawer.hidden = !drawer;
|
|
1386
1451
|
watch.drawer.classList.toggle("k-open", open);
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
const
|
|
1452
|
+
watch.drawer.classList.toggle("k-trace-only", opened && drawerView === "trace");
|
|
1453
|
+
// A drawer opened on a wave's trace is headed by that wave's job, not the step's.
|
|
1454
|
+
const tr = opened && drawerView === "trace" ? s.waveTraces[drawerOn] : null;
|
|
1455
|
+
const tail = tr ? { job: `Wave ${drawerOn} · ${tr.job}`, status: tr.trace.result === "failed" || tr.trace.result === "refused" ? "failure" : tr.trace.result === "waiting" ? "waiting" : "success", lines: [] } : tailLines(runsApi && runsApi.run ? runsApi.run.doc : null);
|
|
1456
|
+
if (drawer) drawDrawer(watch.drawer, tail, badgeTitle(nums[drawerOn]), open);
|
|
1457
|
+
if (drawer) traceDrawer(d, drawerOn);
|
|
1458
|
+
// A drawer the viewer opened on a wave takes the card's place beside the graph until it folds.
|
|
1459
|
+
const result = shot.kind === "result" && !opened ? resultModel(d, s.metrics, s.progress) : null;
|
|
1390
1460
|
watch.result.hidden = !result;
|
|
1391
1461
|
if (result) drawResult(watch.result, result, s);
|
|
1392
1462
|
// On a phone the delivery numbers stack under the rest, where the header has no room for them.
|
|
@@ -1397,13 +1467,20 @@ export function startKiosk({ bar, frame, side, main, views, read = null, tools =
|
|
|
1397
1467
|
}
|
|
1398
1468
|
foot.textContent = doraLine(s.metrics) || "";
|
|
1399
1469
|
watch.badges.replaceChildren();
|
|
1400
|
-
const skip = call ? hold.wave : drawer ?
|
|
1470
|
+
const skip = call ? hold.wave : drawer ? drawerOn : null;
|
|
1401
1471
|
// At applied the result card lists every wave's numbers, so the boxes carry none.
|
|
1402
1472
|
for (const [n, words] of shot.kind === "result" && result ? [] : Object.entries(nums)) {
|
|
1403
1473
|
if (Number(n) === skip) continue;
|
|
1404
1474
|
const b = el("span", "k-badge", words);
|
|
1405
1475
|
b.dataset.kWave = n;
|
|
1406
1476
|
b.title = `Wave ${n}: ${badgeTitle(words)}`;
|
|
1477
|
+
// behold#571: a wave whose trace Tempo has opens it from its numbers.
|
|
1478
|
+
if (s.waveTraces[n]) {
|
|
1479
|
+
b.classList.add("k-badge-trace");
|
|
1480
|
+
b.title = `${b.title} · ${TRACE_OPEN_WORDS}`;
|
|
1481
|
+
b.appendChild(el("span", "k-badge-go", TRACE_LINK_WORDS));
|
|
1482
|
+
b.addEventListener("click", () => s.openWave(Number(n), "trace"));
|
|
1483
|
+
}
|
|
1407
1484
|
watch.badges.appendChild(b);
|
|
1408
1485
|
}
|
|
1409
1486
|
placeWatch();
|
|
@@ -1418,8 +1495,10 @@ export function startKiosk({ bar, frame, side, main, views, read = null, tools =
|
|
|
1418
1495
|
const host = watch.drawer.querySelector("#k-traces");
|
|
1419
1496
|
const runDoc = runsApi && runsApi.run ? runsApi.run.doc : null;
|
|
1420
1497
|
const w = (s.waves || []).find((x) => x.wave === wave);
|
|
1421
|
-
|
|
1422
|
-
|
|
1498
|
+
const tr = s.waveTraces[wave];
|
|
1499
|
+
if (!host || !d || !d.repo || (!tr && (!runDoc || !w))) return;
|
|
1500
|
+
// The wave's own trace when Tempo has it (its run and job: a resumed run applies waves in one job), else its job in the drawer's run.
|
|
1501
|
+
const target = tr ? { project: d.repo, run: tr.run, job: tr.job } : { project: d.repo, run: String(runDoc.id), job: w.job };
|
|
1423
1502
|
const key = `${target.project}|${target.run}|${target.job}`;
|
|
1424
1503
|
if (trace && trace.key === key) return;
|
|
1425
1504
|
if (trace) trace.api.update(target);
|
|
@@ -1436,7 +1515,7 @@ export function startKiosk({ bar, frame, side, main, views, read = null, tools =
|
|
|
1436
1515
|
}
|
|
1437
1516
|
const L = watch.layer.getBoundingClientRect();
|
|
1438
1517
|
const F = frame.getBoundingClientRect();
|
|
1439
|
-
const capTop = watch.caption.getBoundingClientRect()
|
|
1518
|
+
const capTop = captionTop(watch.caption.getBoundingClientRect()) - L.top;
|
|
1440
1519
|
const view = { x: F.left - L.left, y: F.top - L.top, w: F.width, h: capTop - (F.top - L.top) };
|
|
1441
1520
|
const boxOf = (n) => {
|
|
1442
1521
|
const waves = (s.boxes && s.boxes.waves) || {};
|
|
@@ -1466,7 +1545,7 @@ export function startKiosk({ bar, frame, side, main, views, read = null, tools =
|
|
|
1466
1545
|
taken.push({ x: p.x, y: p.y, x2: p.x + size.w, y2: p.y + size.h });
|
|
1467
1546
|
};
|
|
1468
1547
|
put(watch.callout, s.held);
|
|
1469
|
-
put(watch.drawer, s.shot && s.shot.waves[0]);
|
|
1548
|
+
put(watch.drawer, drawerWave !== null ? drawerWave : s.shot && s.shot.waves[0]);
|
|
1470
1549
|
put(watch.result, null); // beside the whole graph
|
|
1471
1550
|
const hits = (r) => taken.some((t) => r.x < t.x2 && r.x2 > t.x && r.y < t.y2 && r.y2 > t.y);
|
|
1472
1551
|
for (const b of watch.badges.children) {
|
|
@@ -1494,6 +1573,7 @@ export function startKiosk({ bar, frame, side, main, views, read = null, tools =
|
|
|
1494
1573
|
if (e.data.type === "behold:viewer") return holdShot();
|
|
1495
1574
|
if (e.data.type !== "behold:boxes") return;
|
|
1496
1575
|
s.boxes = e.data;
|
|
1576
|
+
if (ehApi) ehApi.follow();
|
|
1497
1577
|
if (queued) return;
|
|
1498
1578
|
queued = true;
|
|
1499
1579
|
requestAnimationFrame(() => {
|
|
@@ -1510,6 +1590,13 @@ export function startKiosk({ bar, frame, side, main, views, read = null, tools =
|
|
|
1510
1590
|
const head = watch.drawer && watch.drawer.querySelector(".k-drawer-head");
|
|
1511
1591
|
if (head) {
|
|
1512
1592
|
head.addEventListener("click", () => {
|
|
1593
|
+
// A drawer the viewer opened on a wave folds away; the step's drawer folds to its last lines.
|
|
1594
|
+
if (drawerWave !== null) {
|
|
1595
|
+
drawerWave = null;
|
|
1596
|
+
drawerView = null;
|
|
1597
|
+
drawerOpen = false;
|
|
1598
|
+
return draw();
|
|
1599
|
+
}
|
|
1513
1600
|
drawerOpen = !drawerOpen;
|
|
1514
1601
|
holdShot();
|
|
1515
1602
|
});
|
|
@@ -1526,6 +1613,121 @@ export function startKiosk({ bar, frame, side, main, views, read = null, tools =
|
|
|
1526
1613
|
});
|
|
1527
1614
|
}
|
|
1528
1615
|
}
|
|
1616
|
+
// ---------------------------------------------------------------------------
|
|
1617
|
+
// behold#571: event-help, the "Tips" (web/kiosk-event-help-ui.js).
|
|
1618
|
+
s.ehLit = null;
|
|
1619
|
+
ehApi = eh && typeof document !== "undefined"
|
|
1620
|
+
? startEventHelp({
|
|
1621
|
+
doc: document,
|
|
1622
|
+
store: shelf,
|
|
1623
|
+
switchHost: eh.switchHost,
|
|
1624
|
+
trailHost: eh.trailHost,
|
|
1625
|
+
tipsHost: eh.tipsHost,
|
|
1626
|
+
modalHost: eh.modalHost,
|
|
1627
|
+
now: () => now().getTime(),
|
|
1628
|
+
shown: () => shownNow().getTime(),
|
|
1629
|
+
light: (lit) => {
|
|
1630
|
+
s.ehLit = lit;
|
|
1631
|
+
glow();
|
|
1632
|
+
tellHover(s.hover);
|
|
1633
|
+
},
|
|
1634
|
+
openTrace: (wave) => s.openWave(wave, "trace"),
|
|
1635
|
+
// The modal shows behold's own approval panel, as the kiosk draws it.
|
|
1636
|
+
panel: (kind) => (kind === "held" && s.approval ? approvalPanel(s.approval, s) : null),
|
|
1637
|
+
get: () => {
|
|
1638
|
+
const d = s.demo && s.demo.demo;
|
|
1639
|
+
if (!d) return null;
|
|
1640
|
+
const appr = pendingApproval(d, s.progress);
|
|
1641
|
+
return {
|
|
1642
|
+
demo: d,
|
|
1643
|
+
answer: s.answer,
|
|
1644
|
+
progress: s.progress,
|
|
1645
|
+
runDoc: runsApi && runsApi.run ? runsApi.run.doc : null,
|
|
1646
|
+
// The cycle's runs the approval panel reads, for the failures of runs the pane no longer shows.
|
|
1647
|
+
runDocs: ap.list,
|
|
1648
|
+
approval: s.approval && Array.isArray(s.approval.rows) ? s.approval : null,
|
|
1649
|
+
metrics: s.metrics,
|
|
1650
|
+
waves: s.waves,
|
|
1651
|
+
boxes: s.boxes,
|
|
1652
|
+
frame,
|
|
1653
|
+
watch: s.watchMode,
|
|
1654
|
+
caption: watch ? watch.caption : null,
|
|
1655
|
+
replay: s.mode === "replay",
|
|
1656
|
+
approveLine: appr ? appr.approve : null,
|
|
1657
|
+
label: d.label || "",
|
|
1658
|
+
result: resultModel(d, s.metrics, s.progress),
|
|
1659
|
+
waveTraces: s.waveTraces,
|
|
1660
|
+
};
|
|
1661
|
+
},
|
|
1662
|
+
})
|
|
1663
|
+
: null;
|
|
1664
|
+
|
|
1665
|
+
/**
|
|
1666
|
+
* behold#571: open a wave's trace (or its log) from where its numbers are:
|
|
1667
|
+
* its badge, the result card, its box, a tip. In Watch, the drawer on its
|
|
1668
|
+
* box; in Inspect, the job pane on its job.
|
|
1669
|
+
*/
|
|
1670
|
+
s.openWave = (n, view = "trace") => {
|
|
1671
|
+
const tr = s.waveTraces[n];
|
|
1672
|
+
const v = view === "trace" && tr ? "trace" : "log";
|
|
1673
|
+
const w = (s.waves || []).find((x) => x.wave === n);
|
|
1674
|
+
if (!s.watchMode) {
|
|
1675
|
+
if (runsApi && runsApi.showJob && (tr || w)) runsApi.showJob(tr && v === "trace" ? tr.run : runsApi.run && runsApi.run.doc ? runsApi.run.doc.id : null, tr && v === "trace" ? tr.job : w.job, v === "trace" ? "trace" : "steps");
|
|
1676
|
+
return;
|
|
1677
|
+
}
|
|
1678
|
+
drawerWave = n;
|
|
1679
|
+
drawerView = v;
|
|
1680
|
+
drawerOpen = true;
|
|
1681
|
+
if (v === "log" && w && runsApi && runsApi.showJob) runsApi.showJob(runsApi.run && runsApi.run.doc ? runsApi.run.doc.id : null, w.job, "steps");
|
|
1682
|
+
holdShot();
|
|
1683
|
+
};
|
|
1684
|
+
if (typeof window !== "undefined" && window.addEventListener) {
|
|
1685
|
+
window.addEventListener("message", (e) => {
|
|
1686
|
+
if (e.origin !== origin || !frame || e.source !== frame.contentWindow || !e.data || e.data.type !== "behold:wave") return;
|
|
1687
|
+
if (Number.isInteger(e.data.wave)) s.openWave(e.data.wave, "trace");
|
|
1688
|
+
});
|
|
1689
|
+
}
|
|
1690
|
+
// behold#571: the cycle's runs' traces, read while the waves run and for a while after each run ends (Tempo has a job's spans seconds to a minute after it finishes).
|
|
1691
|
+
const traceReads = new Map();
|
|
1692
|
+
let tracesBusy = false;
|
|
1693
|
+
let tracesCycle = null;
|
|
1694
|
+
const readTraces = async () => {
|
|
1695
|
+
const d = s.demo && s.demo.demo;
|
|
1696
|
+
// A new cycle starts with none: the last one's traces are not this one's.
|
|
1697
|
+
if (d && d.cycle !== tracesCycle) {
|
|
1698
|
+
tracesCycle = d.cycle;
|
|
1699
|
+
s.waveTraces = {};
|
|
1700
|
+
drawerWave = null;
|
|
1701
|
+
drawerView = null;
|
|
1702
|
+
}
|
|
1703
|
+
if (tracesBusy || !d || !d.repo || !runsApi || !runsApi.index || !runsApi.index.doc) return;
|
|
1704
|
+
if (!["merged", "applying", "waiting", "approved", "failed", "resumed", "applied"].includes(d.step)) return;
|
|
1705
|
+
tracesBusy = true;
|
|
1706
|
+
try {
|
|
1707
|
+
const t = now().getTime();
|
|
1708
|
+
for (const r of cycleRuns(runsApi.index.doc.runs, d)) {
|
|
1709
|
+
if (r.status === "queued") continue;
|
|
1710
|
+
const key = `${d.cycle}|${r.id}`;
|
|
1711
|
+
const had = traceReads.get(key);
|
|
1712
|
+
const ended = r.ended_at ? Date.parse(r.ended_at) : null;
|
|
1713
|
+
// Done: ended a while ago, and read once since.
|
|
1714
|
+
if (had && ended && t - ended > TRACE_SETTLE_MS && had.at > ended + TRACE_SETTLE_MS) continue;
|
|
1715
|
+
if (had && t - had.at < TRACE_POLL_MS) continue;
|
|
1716
|
+
const a = await fetchServed(`/api/traces?project=${encodeURIComponent(d.repo)}&run=${encodeURIComponent(r.id)}`);
|
|
1717
|
+
traceReads.set(key, { at: t, answer: a && !a.error ? a : had ? had.answer : null });
|
|
1718
|
+
}
|
|
1719
|
+
const mine = [...traceReads].filter(([k]) => k.startsWith(`${d.cycle}|`)).map(([, v]) => v.answer);
|
|
1720
|
+
const next = waveTraces(mine);
|
|
1721
|
+
if (JSON.stringify(Object.keys(next).map((k) => [k, next[k].run, next[k].trace.start])) !== JSON.stringify(Object.keys(s.waveTraces).map((k) => [k, s.waveTraces[k].run, s.waveTraces[k].trace.start]))) {
|
|
1722
|
+
s.waveTraces = next;
|
|
1723
|
+
draw();
|
|
1724
|
+
}
|
|
1725
|
+
} finally {
|
|
1726
|
+
tracesBusy = false;
|
|
1727
|
+
}
|
|
1728
|
+
};
|
|
1729
|
+
setInterval(() => void readTraces(), 2_000);
|
|
1730
|
+
|
|
1529
1731
|
s.setMetrics = (m) => {
|
|
1530
1732
|
s.metrics = m;
|
|
1531
1733
|
draw();
|