@intentius/behold 0.30.0 → 0.30.2
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/AGENTS.md +97 -33
- package/README.md +78 -56
- package/dist/cli.js +6913 -2448
- package/example-choudoufu-estate/chant.workspace.json +1 -1
- package/example-terraform-estate/README.md +1 -1
- package/example-terraform-estate/chant.workspace.json +1 -1
- package/example-terralith/README.md +1 -1
- package/example-three-cloud/package-lock.json +19 -19
- package/example-three-cloud/package.json +4 -4
- package/package.json +5 -5
- package/web/app.js +330 -19
- package/web/embed.js +2 -2
- package/web/event-help-modal.js +18 -12
- package/web/event-help-modal.test.js +28 -1
- package/web/index.html +18 -0
- package/web/kiosk-ask-layout.js +85 -0
- package/web/kiosk-ask-layout.test.js +83 -0
- package/web/kiosk-ask-tips.js +467 -0
- package/web/kiosk-ask-tips.test.js +359 -0
- package/web/kiosk-ask.js +774 -0
- package/web/kiosk-ask.test.js +593 -0
- package/web/kiosk-banner.js +108 -0
- package/web/kiosk-banner.test.js +72 -0
- package/web/kiosk-center-cards.test.js +110 -0
- package/web/kiosk-estate-scene.js +203 -0
- package/web/kiosk-estate-scene.test.js +21 -0
- package/web/kiosk-event-help.js +4 -1
- package/web/kiosk-graph-pane.js +63 -0
- package/web/kiosk-graph-pane.test.js +105 -0
- package/web/kiosk-light-frame.js +196 -0
- package/web/kiosk-light.js +509 -0
- package/web/kiosk-light.test.js +297 -0
- package/web/kiosk-metrics.js +7 -4
- package/web/kiosk-modal-sticky.test.js +2 -1
- package/web/kiosk-refit.test.js +81 -0
- package/web/kiosk-reset.js +49 -0
- package/web/kiosk-reset.test.js +11 -0
- package/web/kiosk-shot.js +40 -2
- package/web/kiosk-shot.test.js +23 -1
- package/web/kiosk-vendor.js +85 -7
- package/web/kiosk-vendor.test.js +9 -9
- package/web/kiosk-watch.js +8 -4
- package/web/kiosk.html +107 -1
- package/web/kiosk.js +149 -23
- package/web/kiosk.test.js +25 -1
- package/web/layout-store.js +3 -3
- package/web/small-stage.test.js +4 -0
- package/web/terragucci-change.js +30 -13
- package/web/tool-mark.js +4 -4
- package/web/tool-mark.test.js +1 -1
- package/web/vendors/atmos.svg +1 -0
- package/web/vendors/chant.svg +1 -0
- package/web/vendors/choudoufu.svg +1 -0
- package/web/vendors/terragrunt.svg +9 -0
- package/web/vendors/terragucci.svg +1 -0
- package/web/vendors/choudoufu-128.png +0 -0
- package/web/vendors/choudoufu-64.png +0 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// The demo banner: the example's name and act, the live demo's products, and a link to its code. Everything shown is live.
|
|
2
|
+
// Pure: the model from a tool id and the list; web/kiosk.html draws it.
|
|
3
|
+
//
|
|
4
|
+
// Logo policy (web/kiosk-vendor.js): a logo appears only where its owner's published rules allow one. choudoufu's,
|
|
5
|
+
// chant's (the chant repo's docs/public/brand/logo.svg, its face) and terragucci's are ours. Terragrunt's and Atmos's icons, from gruntwork-io/terragrunt (docs/src/assets/icons/terragrunt-icon.svg)
|
|
6
|
+
// and cloudposse/atmos (docs/img/atmos-logo-128.svg), appear on the demos that use those tools (maintainer, 2026-10-24). OpenTofu, Terragrunt and Atmos are shown by name, as text, and link to their official sites.
|
|
7
|
+
|
|
8
|
+
import { vendorOf } from "./kiosk-vendor.js";
|
|
9
|
+
|
|
10
|
+
/** The products a banner may show: the name, the site, and the logo (null where no rule allows one). */
|
|
11
|
+
export const PRODUCTS = {
|
|
12
|
+
choudoufu: { name: "choudoufu", url: "https://intentius.io/choudoufu/", logo: { src: "/vendors/choudoufu.svg" } },
|
|
13
|
+
chant: { name: "chant", url: "https://intentius.io/chant/", logo: { src: "/vendors/chant.svg" } },
|
|
14
|
+
terragucci: { name: "terragucci", url: "https://intentius.io/terragucci/", logo: { src: "/vendors/terragucci.svg" } },
|
|
15
|
+
opentofu: { name: "OpenTofu", url: "https://opentofu.org/", logo: null },
|
|
16
|
+
terragrunt: { name: "Terragrunt", url: "https://terragrunt.com/", logo: { src: "/vendors/terragrunt.svg" } },
|
|
17
|
+
atmos: { name: "Atmos", url: "https://atmos.tools/", logo: { src: "/vendors/atmos.svg" } },
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/** "I", "II", "III"...: an act's number as the banner writes it. */
|
|
21
|
+
export function actNumeral(n) {
|
|
22
|
+
const r = [["X", 10], ["IX", 9], ["V", 5], ["IV", 4], ["I", 1]];
|
|
23
|
+
let out = "";
|
|
24
|
+
for (let [s, v] of r) while (n >= v) { out += s; n -= v; }
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The act the loop is on, "Act I": the scenario's place among its own tool's scenarios (demo.json's `act` and `acts`).
|
|
30
|
+
* Without `act` (an older driver) it falls back to `index` and `scenarios`, which count every tool's scenarios. Null for
|
|
31
|
+
* one act, another tool's run or none.
|
|
32
|
+
*/
|
|
33
|
+
export function actOf(tool, demo) {
|
|
34
|
+
const d = demo && demo.demo ? demo.demo : demo;
|
|
35
|
+
if (!d || d.tool !== tool) return null;
|
|
36
|
+
if (d.act !== undefined && d.act !== null) {
|
|
37
|
+
if (!Number.isInteger(d.act) || !Number.isInteger(d.acts) || d.acts < 2 || d.act < 1) return null;
|
|
38
|
+
return `Act ${actNumeral(d.act)}`;
|
|
39
|
+
}
|
|
40
|
+
if (!Number.isInteger(d.index) || !Number.isInteger(d.scenarios) || d.scenarios < 2 || d.index < 1) return null;
|
|
41
|
+
return `Act ${actNumeral(d.index)}`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The title every demo shares; the logos beside it say which demo is on. */
|
|
45
|
+
export const BANNER_TITLE = "One plan, one apply, across estates";
|
|
46
|
+
|
|
47
|
+
/** The demo whose tool demo.json names now, when it is a listed demo; else null. */
|
|
48
|
+
export function liveTool(demo) {
|
|
49
|
+
const d = demo && demo.demo ? demo.demo : demo;
|
|
50
|
+
// The base (a reset between scenarios) names the tool that just ran, not the one that is next: it is no demo going live.
|
|
51
|
+
const t = d && typeof d.tool === "string" && d.scenario !== "base" ? d.tool : null;
|
|
52
|
+
const v = t ? vendorOf(t) : null;
|
|
53
|
+
return v && v.code && v.title ? t : null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** The banner for the live demo `tool`, or null for a tool that is no listed demo. */
|
|
57
|
+
export function bannerModel(tool, act = null) {
|
|
58
|
+
const v = vendorOf(tool);
|
|
59
|
+
if (!v || !v.code || !v.title) return null;
|
|
60
|
+
return {
|
|
61
|
+
tool,
|
|
62
|
+
name: v.heading || BANNER_TITLE,
|
|
63
|
+
act,
|
|
64
|
+
products: (v.products || []).map((id) => PRODUCTS[id]).filter(Boolean),
|
|
65
|
+
code: { label: "See the code", short: "Code", url: v.code },
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Draws the model into `host` (a header element); hides it with no model. Returns whether it shows. */
|
|
70
|
+
export function drawBanner(host, model, doc = document) {
|
|
71
|
+
host.textContent = "";
|
|
72
|
+
host.hidden = !model;
|
|
73
|
+
doc.body.classList.toggle("k-bannered", !!model);
|
|
74
|
+
if (!model) return false;
|
|
75
|
+
const el = (tag, cls, text) => {
|
|
76
|
+
const n = doc.createElement(tag);
|
|
77
|
+
if (cls) n.className = cls;
|
|
78
|
+
if (text !== undefined) n.textContent = text;
|
|
79
|
+
return n;
|
|
80
|
+
};
|
|
81
|
+
const link = (cls, href, ...kids) => {
|
|
82
|
+
const a = el("a", cls);
|
|
83
|
+
a.href = href;
|
|
84
|
+
a.target = "_blank";
|
|
85
|
+
a.rel = "noopener noreferrer";
|
|
86
|
+
a.append(...kids);
|
|
87
|
+
return a;
|
|
88
|
+
};
|
|
89
|
+
const prods = el("span", "kb-products");
|
|
90
|
+
for (const p of model.products) {
|
|
91
|
+
const kids = [];
|
|
92
|
+
if (p.logo) {
|
|
93
|
+
const img = el("img", "kb-logo");
|
|
94
|
+
img.src = p.logo.src;
|
|
95
|
+
if (p.logo.src2x) img.srcset = `${p.logo.src2x} 2x`;
|
|
96
|
+
img.alt = "";
|
|
97
|
+
kids.push(img);
|
|
98
|
+
}
|
|
99
|
+
kids.push(el("span", "kb-pname", p.name));
|
|
100
|
+
prods.appendChild(link("kb-product", p.url, ...kids));
|
|
101
|
+
}
|
|
102
|
+
const code = link("kb-code", model.code.url, el("span", "kb-code-long", model.code.label), el("span", "kb-code-short", model.code.short));
|
|
103
|
+
const name = el("span", "kb-name", model.name);
|
|
104
|
+
if (model.act) name.append(el("span", "kb-act", ` - ${model.act}`));
|
|
105
|
+
host.append(name, prods);
|
|
106
|
+
host.appendChild(code);
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { actNumeral, actOf, PRODUCTS, bannerModel, liveTool } from "./kiosk-banner.js";
|
|
3
|
+
import { VENDORS } from "./kiosk-vendor.js";
|
|
4
|
+
|
|
5
|
+
const ALL = ["choudoufu-compose", "terragrunt-choudoufu", "atmos-choudoufu", "chant-compose"];
|
|
6
|
+
|
|
7
|
+
describe("the demo banner model", () => {
|
|
8
|
+
it("names the example the same for every demo but chant's, which runs across stacks, and Atmos's, which applies each component in turn", () => {
|
|
9
|
+
for (const t of ALL.filter((x) => x !== "chant-compose" && x !== "atmos-choudoufu")) expect(bannerModel(t).name).toBe("One plan, one apply, across estates");
|
|
10
|
+
expect(bannerModel("atmos-choudoufu").name).toBe("One plan across estates");
|
|
11
|
+
expect(bannerModel("chant-compose").name).toBe("One plan, one apply, across stacks");
|
|
12
|
+
});
|
|
13
|
+
it("links the public example tree", () => {
|
|
14
|
+
expect(bannerModel("choudoufu-compose").code.url).toBe("https://github.com/INTENTIUS/terragucci/tree/main/example-demo-choudoufu-compose");
|
|
15
|
+
expect(bannerModel("atmos-choudoufu").code.url).toBe("https://github.com/INTENTIUS/choudoufu/tree/main/examples/demo-atmos");
|
|
16
|
+
expect(bannerModel("terragrunt-choudoufu").code.url).toBe("https://github.com/INTENTIUS/choudoufu/tree/main/examples/demo-terragrunt");
|
|
17
|
+
expect(bannerModel("chant-compose").code.url).toBe("https://github.com/INTENTIUS/chant/tree/main/examples/demo-composed-stacks");
|
|
18
|
+
});
|
|
19
|
+
it("names the demo's own products: every product with its logo, never OpenTofu", () => {
|
|
20
|
+
expect(PRODUCTS.choudoufu.logo.src).toBe("/vendors/choudoufu.svg");
|
|
21
|
+
expect(PRODUCTS.terragucci.logo.src).toBe("/vendors/terragucci.svg");
|
|
22
|
+
expect(PRODUCTS.opentofu.logo).toBeNull();
|
|
23
|
+
expect(PRODUCTS.terragrunt.logo.src).toBe("/vendors/terragrunt.svg");
|
|
24
|
+
expect(PRODUCTS.atmos.logo.src).toBe("/vendors/atmos.svg");
|
|
25
|
+
expect(bannerModel("choudoufu-compose").products.map((p) => p.name)).toEqual(["terragucci", "choudoufu"]);
|
|
26
|
+
expect(bannerModel("terragrunt-choudoufu").products.map((p) => p.name)).toEqual(["Terragrunt", "choudoufu"]);
|
|
27
|
+
expect(bannerModel("atmos-choudoufu").products.map((p) => p.name)).toEqual(["Atmos", "choudoufu"]);
|
|
28
|
+
expect(bannerModel("chant-compose").products).toEqual([{ name: "chant", url: "https://intentius.io/chant/", logo: { src: "/vendors/chant.svg" } }]);
|
|
29
|
+
});
|
|
30
|
+
it("has no switcher and no replay: only the live demo's name, act, products and code", () => {
|
|
31
|
+
for (const t of ALL) expect(bannerModel(t)).not.toHaveProperty("switcher");
|
|
32
|
+
});
|
|
33
|
+
it("follows demo.json's tool: the live demo, else null", () => {
|
|
34
|
+
expect(liveTool({ demo: { tool: "atmos-choudoufu" } })).toBe("atmos-choudoufu");
|
|
35
|
+
expect(liveTool({ tool: "terragrunt-choudoufu" })).toBe("terragrunt-choudoufu");
|
|
36
|
+
expect(liveTool({ demo: { tool: "terraform" } })).toBeNull();
|
|
37
|
+
expect(liveTool(null)).toBeNull();
|
|
38
|
+
expect(liveTool({ demo: { tool: "atmos-choudoufu", scenario: "base" } })).toBeNull();
|
|
39
|
+
});
|
|
40
|
+
it("is none for a page that is no listed demo", () => {
|
|
41
|
+
expect(bannerModel("terraform")).toBeNull();
|
|
42
|
+
expect(bannerModel(null)).toBeNull();
|
|
43
|
+
});
|
|
44
|
+
it("never names another commercial product, nor says atomic or transaction", () => {
|
|
45
|
+
for (const t of ALL) {
|
|
46
|
+
const m = bannerModel(t);
|
|
47
|
+
const text = JSON.stringify(m) + VENDORS[t].credit;
|
|
48
|
+
expect(text).not.toMatch(/atomic|transaction|terraform|pulumi|spacelift|env0|scalr|terramate|cdk/i);
|
|
49
|
+
if (t !== "terragrunt-choudoufu") expect(text).not.toMatch(/gruntwork|terragrunt[^-]/i);
|
|
50
|
+
if (t !== "atmos-choudoufu") expect(text).not.toMatch(/atmos|cloud posse/i);
|
|
51
|
+
if (t !== "choudoufu-compose") expect(text).not.toMatch(/terragucci/i);
|
|
52
|
+
if (t === "chant-compose") expect(text).not.toMatch(/choudoufu|terragrunt|opentofu|terragucci/i);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe("the act after the title", () => {
|
|
58
|
+
it("names the act from demo.json's index for this page's tool, in roman numerals", () => {
|
|
59
|
+
expect(actOf("choudoufu-compose", { demo: { tool: "choudoufu-compose", index: 1, scenarios: 2 } })).toBe("Act I");
|
|
60
|
+
expect(actOf("choudoufu-compose", { tool: "choudoufu-compose", index: 2, scenarios: 2 })).toBe("Act II");
|
|
61
|
+
expect(actOf("choudoufu-compose", { demo: { tool: "other", index: 1, scenarios: 2 } })).toBeNull();
|
|
62
|
+
expect(actOf("choudoufu-compose", { demo: { tool: "choudoufu-compose", index: 1, scenarios: 1 } })).toBeNull();
|
|
63
|
+
expect(actOf("choudoufu-compose", null)).toBeNull();
|
|
64
|
+
expect(actOf("choudoufu-compose", { demo: { tool: "choudoufu-compose", index: 4, scenarios: 6, act: 2, acts: 2 } })).toBe("Act II");
|
|
65
|
+
expect(actOf("choudoufu-compose", { demo: { tool: "choudoufu-compose", index: 4, scenarios: 6, act: 1, acts: 1 } })).toBeNull();
|
|
66
|
+
expect(actNumeral(3)).toBe("III");
|
|
67
|
+
expect(actNumeral(4)).toBe("IV");
|
|
68
|
+
});
|
|
69
|
+
it("carries the act in the model", () => {
|
|
70
|
+
expect(bannerModel("choudoufu-compose", "Act II").act).toBe("Act II");
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// The ask-mode scene is centred in the graph area, a card's lines follow the rules, and a composed run never counts waves.
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { cardLines, composedRun, lineState, planOf } from "./kiosk-light.js";
|
|
4
|
+
import { askLayout } from "./kiosk-ask-layout.js";
|
|
5
|
+
import { shotViewBox } from "./kiosk-shot.js";
|
|
6
|
+
import { resultModel } from "./kiosk-watch.js";
|
|
7
|
+
import { ehSnapshot, cycleFacts } from "./kiosk-event-help.js";
|
|
8
|
+
import { metricsModel, steadyModel } from "./kiosk-metrics.js";
|
|
9
|
+
|
|
10
|
+
const scene = (extra = {}) => ({
|
|
11
|
+
roots: [{ path: "network", member: "demo", name: "network" }, { path: "app", member: "demo", name: "app" }],
|
|
12
|
+
cards: {},
|
|
13
|
+
estateScene: {
|
|
14
|
+
roots: [
|
|
15
|
+
{ path: "network", member: "demo", name: "network", resources: [{ address: "aws_subnet.subnet_b", action: "create", values: [{ path: "id", unknown: true }, { path: "assign_ipv6_address_on_creation", before: null, after: false }, { path: "cidr_block", before: null, after: "10.0.2.0/24" }] }] },
|
|
16
|
+
{ path: "app", member: "demo", name: "app", resources: [{ address: "aws_network_interface.worker", action: "create", values: [{ path: "id", unknown: true }, { path: "subnet_id", unknown: true }] }, { address: "aws_security_group.web", action: "replace", values: [{ path: "description", before: "old", after: "new" }, { path: "name", before: "a", after: "b" }, { path: "vpc_id", before: "v1", after: "v2" }] }] },
|
|
17
|
+
],
|
|
18
|
+
},
|
|
19
|
+
pull_request: { reads: [{ root: "app", upstream: "network", unknown: ["subnet_id"] }], upstreams: {} },
|
|
20
|
+
...extra,
|
|
21
|
+
});
|
|
22
|
+
const at = (lines, address) => lines.filter((l) => l.address === address).map((l) => `${l.kind}:${l.path}`);
|
|
23
|
+
|
|
24
|
+
describe("a card's lines (rules in order, at most two)", () => {
|
|
25
|
+
it("leads with id for a created resource, never shows a false default", () => {
|
|
26
|
+
const lines = cardLines(planOf(scene()));
|
|
27
|
+
expect(at(lines, "aws_subnet.subnet_b")).toEqual(["unknown:id"]);
|
|
28
|
+
expect(lines.some((l) => l.path === "assign_ipv6_address_on_creation")).toBe(false);
|
|
29
|
+
});
|
|
30
|
+
it("puts id, then the cross-estate read, then changes; two lines at most", () => {
|
|
31
|
+
const lines = cardLines(planOf(scene()));
|
|
32
|
+
expect(at(lines, "aws_network_interface.worker")).toEqual(["unknown:id", "unknown:subnet_id"]);
|
|
33
|
+
expect(at(lines, "aws_security_group.web")).toHaveLength(2);
|
|
34
|
+
expect(at(lines, "aws_security_group.web").every((l) => l.startsWith("changed:"))).toBe(true);
|
|
35
|
+
});
|
|
36
|
+
it("shows the real value once applied, and 'filled from' only when the report states none", () => {
|
|
37
|
+
const a = scene();
|
|
38
|
+
const plan = planOf(a);
|
|
39
|
+
const sub = cardLines(plan).find((l) => l.address === "aws_network_interface.worker" && l.path === "subnet_id");
|
|
40
|
+
const applied = { states: [{ number: 1, state: "applied", roots: ["network", "app"], composed: { members: [{ root: "network", apply: "applied", state: "written" }, { root: "app", apply: "applied", state: "written" }] } }] };
|
|
41
|
+
expect(lineState(sub, a, null)).toEqual({ state: "unknown", text: "subnet_id: known after apply" });
|
|
42
|
+
expect(lineState(sub, a, applied)).toEqual({ state: "applied", text: "subnet_id: filled from subnet_b" });
|
|
43
|
+
const wrote = { ...a, applied: { "demo/app/aws_network_interface.worker": { values: [{ path: "subnet_id", after: "subnet-123" }] }, "demo/network/aws_subnet.subnet_b": { values: [{ path: "id", after: "subnet-123" }] } } };
|
|
44
|
+
expect(lineState(sub, wrote, applied)).toEqual({ state: "applied", text: "subnet_id: subnet-123" });
|
|
45
|
+
const id = cardLines(plan).find((l) => l.address === "aws_subnet.subnet_b");
|
|
46
|
+
expect(lineState(id, wrote, applied)).toEqual({ state: "applied", text: "id: subnet-123" });
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe("the fit centres the scene in the graph area", () => {
|
|
51
|
+
const room = (w, h) => ({ width: w, height: h });
|
|
52
|
+
const stack = () => askLayout([{ id: "n", cards: [{ id: "n1", w: 340, h: 90 }] }, { id: "a", cards: ["a", "b", "c", "d"].map((k) => ({ id: k, w: 340, h: 90 })) }, { id: "e", cards: [{ id: "e1", w: 340, h: 90 }, { id: "e2", w: 340, h: 90 }] }], room(1366, 520));
|
|
53
|
+
it("centres each box on the widest, so unequal boxes do not hug the left", () => {
|
|
54
|
+
const l = stack();
|
|
55
|
+
const widest = Math.max(...Object.values(l.boxes).map((b) => b.w));
|
|
56
|
+
for (const b of Object.values(l.boxes)) expect(b.x + b.w / 2).toBeCloseTo(l.width / 2, 0);
|
|
57
|
+
expect(widest).toBe(l.width);
|
|
58
|
+
for (const [id, c] of Object.entries(l.cards)) expect(c.x).toBeGreaterThanOrEqual(0 + 18 - 0.01 + (id ? 0 : 0));
|
|
59
|
+
});
|
|
60
|
+
it.each([[1366, 768, 520], [1920, 1080, 700], [390, 844, 440]])("puts the stack's centre on the open area's centre at %ix%i", (w, h, open) => {
|
|
61
|
+
const l = stack();
|
|
62
|
+
const target = { x: 0, y: 0, x2: l.width, y2: l.height };
|
|
63
|
+
const pane = { width: w, height: open };
|
|
64
|
+
const vb = shotViewBox(target, pane, { top: 40, right: 0, bottom: 0, left: 0 });
|
|
65
|
+
const s = pane.width / vb[2];
|
|
66
|
+
const cx = (vb[0] + vb[2] / 2 - (target.x + target.x2) / 2) * s;
|
|
67
|
+
expect(Math.abs(cx)).toBeLessThan(1);
|
|
68
|
+
// vertical: the target's centre sits at the middle of what is below the 40px inset.
|
|
69
|
+
const cy = ((target.y + target.y2) / 2 - vb[1]) * s;
|
|
70
|
+
expect(cy).toBeCloseTo(40 + (open - 40) / 2, 0);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
describe("the event help's applied line", () => {
|
|
75
|
+
it("says one apply for a composed run, all N waves otherwise", () => {
|
|
76
|
+
const run = (composed) => ({ run: { present: true, commit: "c1" }, states: [1, 2, 3].map((n) => ({ number: n, state: "applied", roots: [], ...(composed && n === 1 ? { composed: { members: [] } } : {}) })), reads: [] });
|
|
77
|
+
const d = { cycle: 1, step: "applied", commit: "c1", label: "x", pull: null };
|
|
78
|
+
const text = (p) => cycleFacts(ehSnapshot({ demo: d, progress: p })).find((f) => f.kind === "applied").text;
|
|
79
|
+
expect(text(run(true))).toBe("applied together in one apply");
|
|
80
|
+
expect(text(run(false))).toBe("all 3 waves applied");
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
describe("a composed run never counts or names waves", () => {
|
|
85
|
+
const composedProgress = { run: { present: true, commit: "c1" }, states: [1, 2, 3].map((n) => ({ number: n, state: "applied", roots: [], totals: {}, ...(n === 1 ? { composed: { members: [] } } : {}) })) };
|
|
86
|
+
const demo = { step: "applied", cycle: 1, commit: "c1", label: "Applied." };
|
|
87
|
+
it("reads as one apply", () => {
|
|
88
|
+
const m = resultModel(demo, null, composedProgress);
|
|
89
|
+
expect(m.counts[0]).toBe("applied together in one apply");
|
|
90
|
+
expect(m.waves).toEqual([]);
|
|
91
|
+
expect(m.counts.join(" ")).not.toMatch(/wave/i);
|
|
92
|
+
});
|
|
93
|
+
it("keeps waves for a run that is not composed", () => {
|
|
94
|
+
const plain = { ...composedProgress, states: composedProgress.states.map(({ composed, ...w }) => w) };
|
|
95
|
+
expect(resultModel(demo, null, plain).counts[0]).toBe("3 waves applied");
|
|
96
|
+
});
|
|
97
|
+
it("detects compose.estate, compose.roots and a scene", () => {
|
|
98
|
+
expect(composedRun({ compose: { estate: true } })).toBe(true);
|
|
99
|
+
expect(composedRun({ pull_request: { compose: { roots: ["a", "b"] } } })).toBe(true);
|
|
100
|
+
expect(composedRun({ roots: [] }, null)).toBe(false);
|
|
101
|
+
});
|
|
102
|
+
it("the metrics count does not count waves", () => {
|
|
103
|
+
const answer = { compose: { estate: true }, run: { current: true, waves: [{ wave: 1, seconds: 3, roots: [] }, { wave: 2, seconds: 1, roots: [] }] } };
|
|
104
|
+
const m = metricsModel(answer);
|
|
105
|
+
expect(m.count).not.toMatch(/wave/i);
|
|
106
|
+
expect(steadyModel(m, { ...m, count: "x" }, { same: true }).count).not.toMatch(/wave/i);
|
|
107
|
+
const plain = metricsModel({ run: answer.run });
|
|
108
|
+
expect(plain.count).toBe("2 waves");
|
|
109
|
+
});
|
|
110
|
+
});
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// behold#940: ask mode's two ways of putting the roots where the room is.
|
|
2
|
+
//
|
|
3
|
+
// askDeltas the graph the page drew, its roots moved into a stack (as layout deltas web/app.js paints);
|
|
4
|
+
// sceneModel a composed choudoufu run: the graph has none of the run's resources (an estate keeps no state
|
|
5
|
+
// file, and the checkout is as of the base), so the scene is drawn from the run's reports;
|
|
6
|
+
// drawScene puts a scene model in the svg, in place of the graph's own boxes, cards and edges.
|
|
7
|
+
//
|
|
8
|
+
// The scene keeps the graph's own hooks (`data-group-id` on a box, `data-node-id` on a card, `data-edge-from`
|
|
9
|
+
// on an edge), so lighting, the reads between roots and the state labels work on it as they do on the graph.
|
|
10
|
+
// The positions come from web/kiosk-ask-layout.js; the first two are pure.
|
|
11
|
+
|
|
12
|
+
import { askLayout, orderRoots } from "./kiosk-ask-layout.js";
|
|
13
|
+
import { applyOf, cardLines, cardTitle } from "./kiosk-light.js";
|
|
14
|
+
|
|
15
|
+
/** What hangs under a card for each unknown value it carries (web/kiosk-light-frame.js drawSlots). */
|
|
16
|
+
export const SLOT_ROW = 26;
|
|
17
|
+
export const CARD_W = 340;
|
|
18
|
+
export const CARD_H = 60;
|
|
19
|
+
|
|
20
|
+
/** How many attribute lines (at most two) each card id carries. */
|
|
21
|
+
export function slotCounts(plan) {
|
|
22
|
+
const out = {};
|
|
23
|
+
for (const s of cardLines(plan)) if (s.cardId) out[s.cardId] = (out[s.cardId] || 0) + 1;
|
|
24
|
+
return out;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const upstreamFirst = (roots, edges) => {
|
|
28
|
+
const byPath = new Map(roots.map((r) => [r.path, r]));
|
|
29
|
+
return orderRoots(roots.map((r) => r.path), edges).map((p) => byPath.get(p));
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The deltas that stack the drawn graph's roots. `nodes` maps a card id to `{ rect: { x, y, w, h } }` and `boxes` a
|
|
34
|
+
* box id (`box:<root name>`) to `{ x, y, w0, h0 }`, both as the page drew them. Returns `{ deltas, layout }`, with
|
|
35
|
+
* `deltas[id] = { dx, dy }` (and `dw`, `dh` for a box), or null when no root has a box and cards to move.
|
|
36
|
+
*/
|
|
37
|
+
export function askDeltas({ roots, nodes, boxes, extras = {}, edges = [], open }) {
|
|
38
|
+
const ordered = upstreamFirst(roots, edges);
|
|
39
|
+
const input = [];
|
|
40
|
+
for (const r of ordered) {
|
|
41
|
+
const box = boxes.get(`box:${r.name}`);
|
|
42
|
+
const prefix = `${r.member}/${r.name}/`;
|
|
43
|
+
const cards = [...nodes].filter(([id, n]) => id.startsWith(prefix) && n.rect).map(([id, n]) => ({ id, w: n.rect.w, h: n.rect.h + (extras[id] || 0) }));
|
|
44
|
+
if (box && cards.length) input.push({ id: `box:${r.name}`, cards, box });
|
|
45
|
+
}
|
|
46
|
+
if (!input.length) return null;
|
|
47
|
+
const layout = askLayout(input, open);
|
|
48
|
+
const x0 = Math.min(...input.map((r) => r.box.x));
|
|
49
|
+
const y0 = Math.min(...input.map((r) => r.box.y));
|
|
50
|
+
const deltas = {};
|
|
51
|
+
for (const r of input) {
|
|
52
|
+
const b = layout.boxes[r.id];
|
|
53
|
+
deltas[r.id] = { dx: x0 + b.x - r.box.x, dy: y0 + b.y - r.box.y, dw: b.w - r.box.w0, dh: b.h - r.box.h0 };
|
|
54
|
+
for (const c of r.cards) {
|
|
55
|
+
const at = layout.cards[c.id];
|
|
56
|
+
const n = nodes.get(c.id);
|
|
57
|
+
deltas[c.id] = { dx: x0 + at.x - n.rect.x, dy: y0 + at.y - n.rect.y };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return { deltas, layout };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* A composed choudoufu run's scene: each estate's box and cards from `answer.estateScene`, laid out for `open`, and
|
|
65
|
+
* an edge for each reach the blast radius names. Null when the answer holds no scene.
|
|
66
|
+
*/
|
|
67
|
+
export function sceneModel(answer, plan, progress, open) {
|
|
68
|
+
const scene = answer && answer.estateScene && Array.isArray(answer.estateScene.roots) ? answer.estateScene.roots.filter((r) => r.resources && r.resources.length) : [];
|
|
69
|
+
if (!scene.length) return null;
|
|
70
|
+
const extras = slotCounts(plan);
|
|
71
|
+
const ordered = upstreamFirst(scene, plan.edges);
|
|
72
|
+
const input = ordered.map((r) => ({
|
|
73
|
+
id: r.path,
|
|
74
|
+
cards: r.resources.map((res) => {
|
|
75
|
+
const id = `${r.member}/${r.name}/${res.address}`;
|
|
76
|
+
return { id, w: CARD_W, h: CARD_H + (extras[id] ? extras[id] * SLOT_ROW + 10 : 0) };
|
|
77
|
+
}),
|
|
78
|
+
}));
|
|
79
|
+
const layout = askLayout(input, open);
|
|
80
|
+
const roots = ordered.map((r) => {
|
|
81
|
+
const box = layout.boxes[r.path];
|
|
82
|
+
const outcome = applyOf(r.path, progress);
|
|
83
|
+
const done = outcome ? outcome.apply === "applied" || outcome.apply === "no-changes" : null;
|
|
84
|
+
return {
|
|
85
|
+
path: r.path,
|
|
86
|
+
name: r.name,
|
|
87
|
+
member: r.member,
|
|
88
|
+
...box,
|
|
89
|
+
cards: r.resources.map((res) => {
|
|
90
|
+
const id = `${r.member}/${r.name}/${res.address}`;
|
|
91
|
+
const at = layout.cards[id];
|
|
92
|
+
const { name, type } = cardTitle(res.address);
|
|
93
|
+
// The run view says each estate's part of the apply as it happens; the reports say it once they list it as applied.
|
|
94
|
+
const applied = done === null ? res.state === "applied" : done;
|
|
95
|
+
return { id, address: res.address, name, type, action: res.action, applied, ...at, h: CARD_H };
|
|
96
|
+
}),
|
|
97
|
+
};
|
|
98
|
+
});
|
|
99
|
+
const at = new Map(roots.flatMap((r) => r.cards).map((c) => [c.id, c]));
|
|
100
|
+
const keyOf = new Map();
|
|
101
|
+
for (const r of roots) for (const c of r.cards) keyOf.set(`${r.path}/${c.address}`, c.id);
|
|
102
|
+
const edges = [];
|
|
103
|
+
// Only between roots that sit next to each other: a line past a box to one beyond it crosses what is between.
|
|
104
|
+
const place = new Map(roots.map((r, i) => [r.path, i]));
|
|
105
|
+
for (const [seed, reaches] of plan.reaches) {
|
|
106
|
+
const from = keyOf.get(seed);
|
|
107
|
+
for (const x of reaches || []) {
|
|
108
|
+
const to = keyOf.get(`${x.root}/${x.address}`);
|
|
109
|
+
if (from && to && from !== to && Math.abs(place.get(seed.slice(0, seed.indexOf("/"))) - place.get(x.root)) <= 1 && !edges.some((e) => e.from === from && e.to === to)) edges.push({ from, to, d: edgePath(at.get(from), at.get(to)) });
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return { roots, edges, width: layout.width, height: layout.height, cols: layout.cols };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** A curve from one card's edge to the other's, on the sides that face. */
|
|
116
|
+
export function edgePath(a, b) {
|
|
117
|
+
if (b.y >= a.y + a.h) {
|
|
118
|
+
const x1 = a.x + a.w / 2;
|
|
119
|
+
const y1 = a.y + a.h;
|
|
120
|
+
const x2 = b.x + b.w / 2;
|
|
121
|
+
const y2 = b.y;
|
|
122
|
+
const k = (y2 - y1) / 2;
|
|
123
|
+
return `M ${x1} ${y1} C ${x1} ${y1 + k}, ${x2} ${y2 - k}, ${x2} ${y2}`;
|
|
124
|
+
}
|
|
125
|
+
if (a.y >= b.y + b.h) return edgePath(b, a);
|
|
126
|
+
const right = b.x >= a.x;
|
|
127
|
+
const x1 = right ? a.x + a.w : a.x;
|
|
128
|
+
const x2 = right ? b.x : b.x + b.w;
|
|
129
|
+
const y1 = a.y + a.h / 2;
|
|
130
|
+
const y2 = b.y + b.h / 2;
|
|
131
|
+
const k = Math.abs(x2 - x1) / 2;
|
|
132
|
+
return `M ${x1} ${y1} C ${x1 + (right ? k : -k)} ${y1}, ${x2 + (right ? -k : k)} ${y2}, ${x2} ${y2}`;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// ---------------------------------------------------------------------------
|
|
136
|
+
// The svg.
|
|
137
|
+
// ---------------------------------------------------------------------------
|
|
138
|
+
|
|
139
|
+
const NS = "http://www.w3.org/2000/svg";
|
|
140
|
+
const make = (tag, attrs, text) => {
|
|
141
|
+
const n = document.createElementNS(NS, tag);
|
|
142
|
+
for (const [k, v] of Object.entries(attrs || {})) n.setAttribute(k, String(v));
|
|
143
|
+
if (text !== undefined) n.textContent = text;
|
|
144
|
+
return n;
|
|
145
|
+
};
|
|
146
|
+
const tone = (action) => (action === "delete" ? "var(--frame-degraded, var(--degraded))" : action === "update" || action === "replace" ? "var(--frame-pending, var(--pending))" : "var(--frame-managed, var(--managed))");
|
|
147
|
+
|
|
148
|
+
/** Take back the graph's own drawing, drop the scene. */
|
|
149
|
+
export function clearScene(svg) {
|
|
150
|
+
if (!svg) return;
|
|
151
|
+
for (const el of svg.querySelectorAll(":scope > [data-kl-scene]")) el.remove();
|
|
152
|
+
const stash = svg.__klStash;
|
|
153
|
+
if (stash) {
|
|
154
|
+
for (const el of stash) svg.appendChild(el);
|
|
155
|
+
svg.__klStash = null;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Draw `model` in place of the graph's boxes, cards and edges. The graph's own elements are set aside (kept, to come
|
|
161
|
+
* back with clearScene) the first time; every call after draws the scene again.
|
|
162
|
+
*/
|
|
163
|
+
export function drawScene(svg, model) {
|
|
164
|
+
if (!svg || !model) return;
|
|
165
|
+
if (!svg.__klStash) {
|
|
166
|
+
const keep = (el) => /^(defs|style|title|desc)$/i.test(el.tagName);
|
|
167
|
+
svg.__klStash = [...svg.children].filter((el) => !keep(el) && !el.hasAttribute("data-kl-scene"));
|
|
168
|
+
for (const el of svg.__klStash) el.remove();
|
|
169
|
+
}
|
|
170
|
+
for (const el of svg.querySelectorAll(":scope > [data-kl-scene]")) el.remove();
|
|
171
|
+
const scene = make("g", { "data-kl-scene": "1" });
|
|
172
|
+
for (const e of model.edges) {
|
|
173
|
+
const g = make("g", { "data-edge-from": e.from, "data-edge-to": e.to });
|
|
174
|
+
g.appendChild(make("path", { d: e.d, fill: "none", stroke: "var(--muted)", "stroke-width": 2, opacity: 0.45 }));
|
|
175
|
+
scene.appendChild(g);
|
|
176
|
+
}
|
|
177
|
+
for (const r of model.roots) {
|
|
178
|
+
const g = make("g", { "data-layout-box": `box:${r.name}` });
|
|
179
|
+
g.appendChild(make("rect", { "data-group-id": r.name, x: r.x, y: r.y, width: r.w, height: r.h, rx: 16, fill: "var(--panel, var(--bg))", "fill-opacity": 0.6, stroke: "var(--frame-neutral, var(--neutral))", "stroke-width": 1.5 }));
|
|
180
|
+
g.appendChild(make("text", { x: r.x + 18, y: r.y + 26, "font-size": 20, "font-weight": 700, "letter-spacing": ".5", fill: "var(--muted)" }, r.name));
|
|
181
|
+
scene.appendChild(g);
|
|
182
|
+
for (const c of r.cards) {
|
|
183
|
+
const card = make("g", { "data-node-id": c.id, "data-kl-synth": "1" });
|
|
184
|
+
const edge = c.applied ? "var(--frame-managed, var(--managed))" : "var(--frame-pending, var(--pending))";
|
|
185
|
+
card.appendChild(make("rect", { x: c.x, y: c.y, width: c.w, height: c.h, rx: 12, fill: "var(--panel, var(--bg))", stroke: edge, "stroke-width": 2 }));
|
|
186
|
+
card.appendChild(make("rect", { x: c.x, y: c.y, width: 6, height: c.h, rx: 3, fill: tone(c.action) }));
|
|
187
|
+
card.appendChild(make("text", { x: c.x + 20, y: c.y + 27, "font-size": 20, "font-weight": 700, fill: "var(--fg)" }, c.name));
|
|
188
|
+
card.appendChild(make("text", { x: c.x + 20, y: c.y + 47, "font-size": 14, fill: "var(--muted)" }, c.type + (c.action ? ` · ${c.action}` : "")));
|
|
189
|
+
scene.appendChild(card);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
svg.appendChild(scene);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Whether the scene drawn on `svg` should stay when its data goes missing: it is there, and the graph's own elements
|
|
197
|
+
* set aside under it hold no card to go back to (a composed run's graph has none, so going back is a blank pane).
|
|
198
|
+
*/
|
|
199
|
+
export function sceneHoldsOn(svg) {
|
|
200
|
+
if (!svg || !svg.__klStash || !svg.querySelector(":scope > [data-kl-scene]")) return false;
|
|
201
|
+
const own = svg.__klStash.some((el) => (el.hasAttribute && el.hasAttribute("data-node-id")) || (el.querySelector && el.querySelector("[data-node-id]")));
|
|
202
|
+
return !own;
|
|
203
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { sceneHoldsOn } from "./kiosk-estate-scene.js";
|
|
3
|
+
|
|
4
|
+
// A stand-in for an svg: `scene` is whether a drawn scene sits in it, `stash` the graph's own elements set aside.
|
|
5
|
+
const el = (cards) => ({ hasAttribute: () => false, querySelector: () => (cards ? {} : null) });
|
|
6
|
+
const svg = ({ scene = true, stash = [] } = {}) => ({ __klStash: stash, querySelector: () => (scene ? {} : null) });
|
|
7
|
+
|
|
8
|
+
describe("a scene that stays when its data goes missing", () => {
|
|
9
|
+
it("stays when the graph's own drawing has no cards to go back to (a composed run)", () => {
|
|
10
|
+
expect(sceneHoldsOn(svg({ stash: [el(false)] }))).toBe(true);
|
|
11
|
+
});
|
|
12
|
+
it("goes back to the graph when it has cards of its own", () => {
|
|
13
|
+
expect(sceneHoldsOn(svg({ stash: [el(true)] }))).toBe(false);
|
|
14
|
+
expect(sceneHoldsOn(svg({ stash: [{ hasAttribute: (a) => a === "data-node-id" }] }))).toBe(false);
|
|
15
|
+
});
|
|
16
|
+
it("is not a scene when none is drawn", () => {
|
|
17
|
+
expect(sceneHoldsOn(svg({ scene: false }))).toBe(false);
|
|
18
|
+
expect(sceneHoldsOn({ __klStash: null, querySelector: () => null })).toBe(false);
|
|
19
|
+
expect(sceneHoldsOn(null)).toBe(false);
|
|
20
|
+
});
|
|
21
|
+
});
|
package/web/kiosk-event-help.js
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
import { STRIP, matchingPull, matchingRun } from "./kiosk.js";
|
|
16
16
|
import { defaultStep } from "./kiosk-runs.js";
|
|
17
17
|
import { traceReadyWords } from "./kiosk-wave-traces.js";
|
|
18
|
+
import { COMPOSED_WORDS, composedRun } from "./kiosk-light.js";
|
|
18
19
|
import { resultBlocked, resultFailed, resultWords, waveResultOf } from "./terragucci-change.js";
|
|
19
20
|
|
|
20
21
|
export { EH_STORE, ehStore, ehStored } from "./event-help-store.js";
|
|
@@ -90,6 +91,8 @@ export function ehSnapshot({ demo = null, answer = null, progress = null, runDoc
|
|
|
90
91
|
label: demo.label || "",
|
|
91
92
|
plan: pr ? { totals: pr.totals || null, roots: pr.roots || [], reads: pr.reads || [] } : null,
|
|
92
93
|
// behold#751: each wave with its report's result, of the run view's commit.
|
|
94
|
+
// One composed apply across estates: its text never counts or names waves.
|
|
95
|
+
composed: composedRun(answer, run ? progress : null),
|
|
93
96
|
states: run ? (progress.states || []).map((s) => ({ ...s, result: waveResultOf(answer, run.commit, s.number) })) : [],
|
|
94
97
|
run: runDoc ? { id: runDoc.id, jobs: jobs.map((j) => ({ name: j.name, status: j.status, wave: waveOfJob(j.name, waves), refusal: j.status === "failure" ? yodelRefusal(jobLines(j)) : null, step: j.steps ? defaultStep(j.steps) : -1, result: resultOf(runDoc.commit, j.name, j.started_at) })) } : null,
|
|
95
98
|
approval: approval && Array.isArray(approval.rows) ? { wave: approval.wave, rows: approval.rows.filter((r) => r.state === "lit").map((r) => ({ id: r.id, at: r.at || null, actor: r.id === "approved" ? actorOf(r.text) : null, signed: !!(r.seal && /^signed/.test(r.seal.text || "")) })), ...(Array.isArray(approval.chantWaves) ? { chantWaves: approval.chantWaves } : {}) } : null,
|
|
@@ -258,7 +261,7 @@ export function cycleFacts(snap) {
|
|
|
258
261
|
// A repo with declared waves names its held wave once the run view has it; this is for a repo without them.
|
|
259
262
|
if (snap.step === "waiting" && !(snap.waves || []).length && !out.some((f) => f.kind === "held")) add({ id: `${c}|held`, kind: "held", text: "the plan waits for an approval", order: 9, critical: true });
|
|
260
263
|
// The step says the run applied: every wave the run view names, even one a read has not caught up on.
|
|
261
|
-
if (snap.step === "applied") add({ id: `${c}|applied`, kind: "applied", text: !states.length ? "the change applied" : states.length === 1 ? "the wave applied" : `all ${states.length} waves applied`, order: 990, critical: true });
|
|
264
|
+
if (snap.step === "applied") add({ id: `${c}|applied`, kind: "applied", text: !states.length ? "the change applied" : snap.composed ? COMPOSED_WORDS : states.length === 1 ? "the wave applied" : `all ${states.length} waves applied`, order: 990, critical: true });
|
|
262
265
|
if (snap.step === "reset") add({ id: `${c}|reset`, kind: "reset", text: "states back on the base", order: 995 });
|
|
263
266
|
// One fact per id (a wave's hold is said by the run view and the approval rows alike).
|
|
264
267
|
const byId = new Map();
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether the graph pane folds away (body.k-nograph hides it and gives its width to the runs).
|
|
3
|
+
*
|
|
4
|
+
* It folds for a tool whose pipeline has no graph to show, and for nothing else. It never folds:
|
|
5
|
+
* - before the page has read what it needs to know (the served project, the terragucci answer): a reload lands here
|
|
6
|
+
* for a second or two, and the pane is dark and in its place, not gone and then back;
|
|
7
|
+
* - in ask mode, where the graph is half of the story;
|
|
8
|
+
* - once the graph has been shown on this page: a read that fails or is stale for a moment (the reports being
|
|
9
|
+
* written at the apply) keeps the pane, and the last drawn scene with it.
|
|
10
|
+
*/
|
|
11
|
+
export function graphFolds({ vendor, ok, askOn, seen, pending }) {
|
|
12
|
+
if (!vendor || ok) return false;
|
|
13
|
+
return !(askOn || seen || pending);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Whether the page still has a read to wait for before it can say the graph is not coming. */
|
|
17
|
+
export function graphPending({ own, single, answer }) {
|
|
18
|
+
return single === null || (!own && (answer === null || answer === undefined));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Whether the frame may show what is in its svg. In ask mode the graph is the estate scene (web/kiosk-estate-scene.js)
|
|
23
|
+
* and never the checkout's plain resource graph: the pane holds (dark, "Drawing the graph...") until the scene is up,
|
|
24
|
+
* and a scene that is up stays when its reads go missing for a moment (a pin that fits no plan yet, a read in flight).
|
|
25
|
+
*
|
|
26
|
+
* - not in ask mode, or on the components view: always (Inspect and the rest are as they were);
|
|
27
|
+
* - a scene is drawn: yes;
|
|
28
|
+
* - the reports are in, hold no estate scene at all, and say so: yes, the repo's own graph is the scene (a repo
|
|
29
|
+
* that is not a composed run);
|
|
30
|
+
* - anything else (no reads yet, a read that failed, a scene the pin hides for now): no.
|
|
31
|
+
*/
|
|
32
|
+
export function graphMayShow({ askOn, components = false, sceneUp, answerSettled, answerHasScene }) {
|
|
33
|
+
if (!askOn || components) return true;
|
|
34
|
+
if (sceneUp) return true;
|
|
35
|
+
return !!answerSettled && !answerHasScene;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Whether the frame may tell the kiosk it has drawn. In ask mode it waits until the graph may show, and, until the
|
|
40
|
+
* kiosk has said whether ask mode is on (a load tells it right after), a short while at most: the kiosk swaps a
|
|
41
|
+
* reloaded frame in on this word, and a frame swapped in too early shows the plain graph.
|
|
42
|
+
*/
|
|
43
|
+
export function mayTellDrawn({ askHeard, waitedMs, askOn, mayShow, graceMs = 3000 }) {
|
|
44
|
+
if (!askHeard && waitedMs < graceMs) return false;
|
|
45
|
+
return !askOn || mayShow;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Whether a scene that is up stays when the scene model is gone: in ask mode always, for the plain graph never paints. */
|
|
49
|
+
export function keepsSceneInAsk({ askOn, sceneUp }) {
|
|
50
|
+
return !!askOn && !!sceneUp;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Whether a kiosk frame draws its reports' scene on an empty svg in place of the graph's refusal (`refusal`, the
|
|
55
|
+
* precondition body /api/graph answered): a composed run's scene comes from its reports alone, so a checkout the graph
|
|
56
|
+
* refuses (a chant project the view never installed) is no reason to draw nothing. Only in a frame (`bare`), and only
|
|
57
|
+
* once the reports hold a scene; without one the refusal's card stays.
|
|
58
|
+
*/
|
|
59
|
+
export function refusalHoldsScene({ refusal, bare, answer }) {
|
|
60
|
+
if (!refusal || !bare || !answer || answer.error) return false;
|
|
61
|
+
const scene = answer.estateScene;
|
|
62
|
+
return !!(scene && Array.isArray(scene.roots) && scene.roots.some((r) => r && Array.isArray(r.resources) && r.resources.length));
|
|
63
|
+
}
|