@powerhousedao/workflow 6.2.3-dev.46 → 6.2.3-dev.48
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/dist/browser/{BlockSelector-B41mSc0W.js → BlockSelector-Do2fNhEF.js} +2 -2
- package/dist/browser/BlockSelector-Do2fNhEF.js.map +1 -0
- package/dist/browser/{connection-form-CkRzKggD.js → connection-form-BfIxO-uq.js} +2 -2
- package/dist/browser/{connection-form-CkRzKggD.js.map → connection-form-BfIxO-uq.js.map} +1 -1
- package/dist/browser/{data-tree-BugZMgLk.js → data-tree-CEBkvtSf.js} +2 -2
- package/dist/browser/{data-tree-BugZMgLk.js.map → data-tree-CEBkvtSf.js.map} +1 -1
- package/dist/browser/{editor-DvK4LPwF.js → editor-BXxj5Do5.js} +1055 -180
- package/dist/browser/editor-BXxj5Do5.js.map +1 -0
- package/dist/browser/{editor-9eSmoDTm.js → editor-C3l2HgXA.js} +54 -12
- package/dist/browser/editor-C3l2HgXA.js.map +1 -0
- package/dist/browser/{editor-ldDYxtLV.js → editor-C6NhkZ3S.js} +3 -3
- package/dist/browser/{editor-ldDYxtLV.js.map → editor-C6NhkZ3S.js.map} +1 -1
- package/dist/browser/editors/connection-editor/module.js +1 -1
- package/dist/browser/editors/workflow-editor/module.js +1 -1
- package/dist/browser/editors/workflow-studio/module.js +1 -1
- package/dist/browser/{trigger-text-C37YRggR.js → trigger-text-Dwaxi16C.js} +36 -3
- package/dist/browser/trigger-text-Dwaxi16C.js.map +1 -0
- package/dist/node/{BlockSelector-BMnBzXcA.mjs → BlockSelector-CrPnitOU.mjs} +2 -2
- package/dist/node/BlockSelector-CrPnitOU.mjs.map +1 -0
- package/dist/node/{connection-form-DZFudcoD.mjs → connection-form-MHDKPohk.mjs} +2 -2
- package/dist/node/{connection-form-DZFudcoD.mjs.map → connection-form-MHDKPohk.mjs.map} +1 -1
- package/dist/node/{data-tree-CR8IOshA.mjs → data-tree-Ccyc8y8I.mjs} +2 -2
- package/dist/node/{data-tree-CR8IOshA.mjs.map → data-tree-Ccyc8y8I.mjs.map} +1 -1
- package/dist/node/{editor-NUaiiO4B.mjs → editor-B4TEgA0j.mjs} +54 -12
- package/dist/node/editor-B4TEgA0j.mjs.map +1 -0
- package/dist/node/{editor-BV5CYmUI.mjs → editor-DKpQGzMS.mjs} +1055 -180
- package/dist/node/editor-DKpQGzMS.mjs.map +1 -0
- package/dist/node/{editor-D_P9-st9.mjs → editor-J42uGqnf.mjs} +3 -3
- package/dist/node/{editor-D_P9-st9.mjs.map → editor-J42uGqnf.mjs.map} +1 -1
- package/dist/node/editors/connection-editor/module.mjs +1 -1
- package/dist/node/editors/workflow-editor/module.mjs +1 -1
- package/dist/node/editors/workflow-studio/module.mjs +1 -1
- package/dist/node/pieces/reactor/descriptor.json +1 -1
- package/dist/node/pieces/reactor/package.json +1 -1
- package/dist/node/{trigger-text-78ZhfT-b.mjs → trigger-text-qK_Nr5Pw.mjs} +36 -3
- package/dist/node/trigger-text-qK_Nr5Pw.mjs.map +1 -0
- package/dist/powerhouse.manifest.json +1 -1
- package/dist/style.css +268 -15
- package/dist/types/editors/shared/controls.d.ts +1 -0
- package/dist/types/editors/shared/controls.d.ts.map +1 -1
- package/dist/types/editors/workflow-editor/document/useWorkflowModel.d.ts.map +1 -1
- package/dist/types/editors/workflow-editor/ui/ConnectionField.d.ts.map +1 -1
- package/dist/types/editors/workflow-editor/ui/ConnectionName.d.ts +8 -0
- package/dist/types/editors/workflow-editor/ui/ConnectionName.d.ts.map +1 -0
- package/dist/types/editors/workflow-editor/ui/ReactorConnectionField.d.ts.map +1 -1
- package/dist/types/editors/workflow-editor/ui/WorkflowEditorApp.d.ts.map +1 -1
- package/dist/types/editors/workflow-editor/ui/ap-nodes.d.ts.map +1 -1
- package/dist/types/editors/workflow-editor/ui/model.d.ts +2 -0
- package/dist/types/editors/workflow-editor/ui/model.d.ts.map +1 -1
- package/dist/types/editors/workflow-editor/ui/trigger-text.d.ts +2 -0
- package/dist/types/editors/workflow-editor/ui/trigger-text.d.ts.map +1 -1
- package/dist/types/editors/workflow-studio/components/ScrollFade.d.ts +7 -0
- package/dist/types/editors/workflow-studio/components/ScrollFade.d.ts.map +1 -0
- package/dist/types/editors/workflow-studio/components/Sidebar.d.ts +1 -0
- package/dist/types/editors/workflow-studio/components/Sidebar.d.ts.map +1 -1
- package/dist/types/editors/workflow-studio/components/WorkflowBoard.d.ts +1 -0
- package/dist/types/editors/workflow-studio/components/WorkflowBoard.d.ts.map +1 -1
- package/dist/types/editors/workflow-studio/components/WorkflowGraph.d.ts +41 -0
- package/dist/types/editors/workflow-studio/components/WorkflowGraph.d.ts.map +1 -0
- package/dist/types/editors/workflow-studio/components/WorkflowMenu.d.ts +2 -0
- package/dist/types/editors/workflow-studio/components/WorkflowMenu.d.ts.map +1 -1
- package/dist/types/editors/workflow-studio/components/WorkflowSteps.d.ts.map +1 -1
- package/dist/types/editors/workflow-studio/components/WorkflowStudio.d.ts.map +1 -1
- package/dist/types/editors/workflow-studio/components/chain.d.ts +4 -0
- package/dist/types/editors/workflow-studio/components/chain.d.ts.map +1 -1
- package/dist/types/editors/workflow-studio/components/fit-geometry.test.d.ts +2 -0
- package/dist/types/editors/workflow-studio/components/fit-geometry.test.d.ts.map +1 -0
- package/dist/types/editors/workflow-studio/components/graph-layout.d.ts +29 -0
- package/dist/types/editors/workflow-studio/components/graph-layout.d.ts.map +1 -0
- package/dist/types/editors/workflow-studio/components/graph-layout.test.d.ts +2 -0
- package/dist/types/editors/workflow-studio/components/graph-layout.test.d.ts.map +1 -0
- package/dist/types/editors/workflow-studio/components/use-collapsed.d.ts +5 -0
- package/dist/types/editors/workflow-studio/components/use-collapsed.d.ts.map +1 -0
- package/dist/types/editors/workflow-studio/components/use-hash-selection.d.ts +4 -4
- package/dist/types/editors/workflow-studio/components/use-hash-selection.d.ts.map +1 -1
- package/dist/types/editors/workflow-studio/components/workflow-order.d.ts +19 -0
- package/dist/types/editors/workflow-studio/components/workflow-order.d.ts.map +1 -0
- package/dist/types/editors/workflow-studio/components/workflow-order.test.d.ts +2 -0
- package/dist/types/editors/workflow-studio/components/workflow-order.test.d.ts.map +1 -0
- package/dist/types/scripts/ui-stack.d.ts +8 -2
- package/dist/types/scripts/ui-stack.d.ts.map +1 -1
- package/package.json +8 -8
- package/dist/browser/BlockSelector-B41mSc0W.js.map +0 -1
- package/dist/browser/editor-9eSmoDTm.js.map +0 -1
- package/dist/browser/editor-DvK4LPwF.js.map +0 -1
- package/dist/browser/trigger-text-C37YRggR.js.map +0 -1
- package/dist/node/BlockSelector-BMnBzXcA.mjs.map +0 -1
- package/dist/node/editor-BV5CYmUI.mjs.map +0 -1
- package/dist/node/editor-NUaiiO4B.mjs.map +0 -1
- package/dist/node/trigger-text-78ZhfT-b.mjs.map +0 -1
|
@@ -1,25 +1,67 @@
|
|
|
1
1
|
import { K as CORE_PIECE, it as triggerBlock, l as runsOfPages, nt as stepBlock, q as MANUAL_TRIGGER, tt as sameBlock } from "./runtime-queries-BM6I7dDA.mjs";
|
|
2
2
|
import { y as actions } from "./module-BsqRZox1.mjs";
|
|
3
|
-
import { A as runTone, C as formatDuration, D as runStats, E as formatWhen, Et as Select, It as DocumentErrorBoundary, Lt as DocumentLoadError, M as toneOf, N as workflowHealth, Nt as textInputClass, O as runStatusLabel, Pt as Icon, Rt as errorMessage, S as formatAbsolute, T as formatTrigger, _ as RUN_TONE, b as TONE_TEXT, bt as Button, g as RUN_STATUSES, h as CONNECTION_TONE, ht as useRunQuery, j as statusLabel, k as runTimeline, m as usePieceLogos, mt as useRunPagesQuery, t as BlockLogo, u as blockMeta, ut as WorkflowRuntimeProvider, v as STEP_TONE, vt as useRuntimeActions, w as formatMs, x as durationMs, y as TONE_DOT } from "./BlockSelector-
|
|
3
|
+
import { A as runTone, C as formatDuration, D as runStats, E as formatWhen, Et as Select, It as DocumentErrorBoundary, Lt as DocumentLoadError, M as toneOf, N as workflowHealth, Nt as textInputClass, O as runStatusLabel, Pt as Icon, Rt as errorMessage, S as formatAbsolute, T as formatTrigger, _ as RUN_TONE, b as TONE_TEXT, bt as Button, g as RUN_STATUSES, h as CONNECTION_TONE, ht as useRunQuery, j as statusLabel, k as runTimeline, m as usePieceLogos, mt as useRunPagesQuery, t as BlockLogo, u as blockMeta, ut as WorkflowRuntimeProvider, v as STEP_TONE, vt as useRuntimeActions, w as formatMs, x as durationMs, y as TONE_DOT } from "./BlockSelector-CrPnitOU.mjs";
|
|
4
4
|
import { r as useWorkflowDocumentsInSelectedDrive } from "./workflow-BpfdBHyS.mjs";
|
|
5
|
-
import { a as StepError, f as StatusToggle, i as DataViewer, l as PublishState, o as Modal, r as describeTrigger } from "./trigger-text-
|
|
6
|
-
import { Fragment, useCallback, useEffect, useId, useMemo, useRef, useState } from "react";
|
|
5
|
+
import { a as StepError, f as StatusToggle, i as DataViewer, l as PublishState, o as Modal, r as describeTrigger } from "./trigger-text-qK_Nr5Pw.mjs";
|
|
6
|
+
import { Fragment, useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
7
7
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
-
import {
|
|
8
|
+
import { generateId } from "document-model";
|
|
9
|
+
import { addDocument, addFolder, deleteNode, setSelectedNode, showDeleteNodeModal, useDispatch, useDocumentSafe, useFileNodesInSelectedDrive, useNodesInSelectedDrive, usePHToast, useSelectedDrive, useSelectedNode, useSetPHAppConfig } from "@powerhousedao/reactor-browser";
|
|
10
|
+
import { addFolder as addFolder$1, moveNode, updateNode } from "@powerhousedao/shared/document-drive";
|
|
11
|
+
import { ConnectTooltip, ConnectTooltipProvider } from "@powerhousedao/design-system/connect";
|
|
12
|
+
//#region editors/workflow-studio/components/step-outline.ts
|
|
13
|
+
function stepOutline(args) {
|
|
14
|
+
const inbound = /* @__PURE__ */ new Map();
|
|
15
|
+
for (const edge of args.edges) {
|
|
16
|
+
const list = inbound.get(edge.to) ?? [];
|
|
17
|
+
list.push(edge);
|
|
18
|
+
inbound.set(edge.to, list);
|
|
19
|
+
}
|
|
20
|
+
const decided = args.triggerId ? [args.triggerId] : [];
|
|
21
|
+
const rows = [];
|
|
22
|
+
const seen = /* @__PURE__ */ new Set();
|
|
23
|
+
const firstDecided = (edges) => edges.reduce((first, edge) => decided.indexOf(edge.from) < decided.indexOf(first.from) ? edge : first);
|
|
24
|
+
let progressed = true;
|
|
25
|
+
while (progressed) {
|
|
26
|
+
progressed = false;
|
|
27
|
+
for (const step of args.steps) {
|
|
28
|
+
if (seen.has(step.id)) continue;
|
|
29
|
+
const edges = inbound.get(step.id) ?? [];
|
|
30
|
+
const entry = !args.triggerId && edges.length === 0;
|
|
31
|
+
if (!entry) {
|
|
32
|
+
if (edges.length === 0) continue;
|
|
33
|
+
if (!edges.every((edge) => decided.includes(edge.from))) continue;
|
|
34
|
+
}
|
|
35
|
+
seen.add(step.id);
|
|
36
|
+
decided.push(step.id);
|
|
37
|
+
const port = entry ? null : firstDecided(edges).port;
|
|
38
|
+
rows.push({
|
|
39
|
+
step,
|
|
40
|
+
port: port === "next" ? null : port
|
|
41
|
+
});
|
|
42
|
+
progressed = true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
rows,
|
|
47
|
+
orphans: args.steps.filter((step) => !seen.has(step.id))
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
9
51
|
//#region editors/workflow-studio/components/chain.tsx
|
|
10
|
-
const RING$
|
|
52
|
+
const RING$2 = {
|
|
11
53
|
ok: "ring-wf-ok",
|
|
12
54
|
fail: "ring-wf-fail",
|
|
13
55
|
warn: "ring-wf-warn",
|
|
14
56
|
run: "ring-wf-run",
|
|
15
|
-
idle: "ring-foreground/15"
|
|
57
|
+
idle: "ring-foreground/15 dark:ring-foreground/30"
|
|
16
58
|
};
|
|
17
59
|
const RAIL$1 = {
|
|
18
60
|
ok: "bg-wf-ok",
|
|
19
61
|
fail: "bg-wf-fail",
|
|
20
62
|
warn: "bg-wf-warn",
|
|
21
63
|
run: "bg-wf-run",
|
|
22
|
-
idle: "bg-foreground/15"
|
|
64
|
+
idle: "bg-foreground/15 dark:bg-foreground/30"
|
|
23
65
|
};
|
|
24
66
|
const MAX_STOPS = 6;
|
|
25
67
|
function MiniChain(props) {
|
|
@@ -38,11 +80,14 @@ function MiniChain(props) {
|
|
|
38
80
|
className: `h-0.5 ${md ? "w-5" : "w-3"} ${RAIL$1[tones[index]]}`
|
|
39
81
|
}) : null, /* @__PURE__ */ jsx("span", {
|
|
40
82
|
title: link.status ? `${link.label}: ${link.status.toLowerCase()}` : link.label,
|
|
41
|
-
className: `flex shrink-0 items-center justify-center rounded-full bg-card
|
|
42
|
-
children: /* @__PURE__ */ jsx(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
83
|
+
className: `flex shrink-0 items-center justify-center rounded-full bg-card ${md ? "h-8 w-8" : "h-6 w-6"} ${link.status === "SKIPPED" ? "border-[1.5px] border-dashed border-foreground/40" : `ring-[1.5px] dark:bg-white ${RING$2[tones[index]]}`}`,
|
|
84
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
85
|
+
className: link.status === "SKIPPED" ? "flex opacity-40" : "flex",
|
|
86
|
+
children: /* @__PURE__ */ jsx(BlockLogo, {
|
|
87
|
+
bare: true,
|
|
88
|
+
block: link.block,
|
|
89
|
+
size: md ? 16 : 14
|
|
90
|
+
})
|
|
46
91
|
})
|
|
47
92
|
})]
|
|
48
93
|
}, link.id)), overflow ? /* @__PURE__ */ jsxs("li", {
|
|
@@ -72,6 +117,16 @@ function triggerOfKind(kind) {
|
|
|
72
117
|
name: kind
|
|
73
118
|
};
|
|
74
119
|
}
|
|
120
|
+
/** A workflow's steps in the order a run reaches them, coloured by a run. */
|
|
121
|
+
function workflowLinks(workflow, latest) {
|
|
122
|
+
const status = new Map((latest?.steps ?? []).map((step) => [step.stepKey, step.status]));
|
|
123
|
+
return stepOutline(workflow).rows.map(({ step }) => ({
|
|
124
|
+
id: step.id,
|
|
125
|
+
block: stepBlock(step),
|
|
126
|
+
label: step.name || step.key,
|
|
127
|
+
status: status.get(step.key)
|
|
128
|
+
}));
|
|
129
|
+
}
|
|
75
130
|
/** A run's own chain: the trigger, then every step it recorded. */
|
|
76
131
|
function runLinks(run, trigger) {
|
|
77
132
|
return [{
|
|
@@ -103,7 +158,7 @@ function RunStrip(props) {
|
|
|
103
158
|
const recent = props.runs.slice(0, STRIP_LENGTH).reverse();
|
|
104
159
|
const padding = STRIP_LENGTH - recent.length;
|
|
105
160
|
return /* @__PURE__ */ jsxs("span", {
|
|
106
|
-
className:
|
|
161
|
+
className: `flex h-5 gap-[3px] ${props.centered ? "items-center" : "items-end"}`,
|
|
107
162
|
"aria-label": recent.length === 0 ? "No runs yet" : `Last ${recent.length} runs: ${recent.map((run) => run.status.toLowerCase()).join(", ")}`,
|
|
108
163
|
children: [Array.from({ length: padding }, (_, index) => /* @__PURE__ */ jsx("span", {
|
|
109
164
|
"aria-hidden": true,
|
|
@@ -766,7 +821,124 @@ function RunsView(props) {
|
|
|
766
821
|
});
|
|
767
822
|
}
|
|
768
823
|
//#endregion
|
|
824
|
+
//#region editors/workflow-studio/components/workflow-order.ts
|
|
825
|
+
const DIGITS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
826
|
+
const HOME_FOLDER = /^([0-9A-Za-z]+) · (.*)$/s;
|
|
827
|
+
function compareKeys(a, b) {
|
|
828
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
829
|
+
}
|
|
830
|
+
function midpoint(a, b) {
|
|
831
|
+
if (b !== null) {
|
|
832
|
+
let n = 0;
|
|
833
|
+
while ((a[n] ?? "0") === b[n]) n++;
|
|
834
|
+
if (n > 0) return b.slice(0, n) + midpoint(a.slice(n), b.slice(n));
|
|
835
|
+
}
|
|
836
|
+
const digitA = a ? DIGITS.indexOf(a[0]) : 0;
|
|
837
|
+
const digitB = b !== null ? DIGITS.indexOf(b[0]) : 62;
|
|
838
|
+
if (digitB - digitA > 1) return DIGITS[Math.round((digitA + digitB) / 2)];
|
|
839
|
+
if (b !== null && b.length > 1) return b.slice(0, 1);
|
|
840
|
+
return DIGITS[digitA] + midpoint(a.slice(1), null);
|
|
841
|
+
}
|
|
842
|
+
/** A key that sorts after `before` and before `after`. */
|
|
843
|
+
function keyBetween(before, after) {
|
|
844
|
+
return midpoint(before ?? "", after ?? null);
|
|
845
|
+
}
|
|
846
|
+
/** `count` ascending keys, evenly spread. */
|
|
847
|
+
function spreadKeys(count) {
|
|
848
|
+
let width = 1;
|
|
849
|
+
while (62 ** width <= count) width++;
|
|
850
|
+
const span = 62 ** width;
|
|
851
|
+
return Array.from({ length: count }, (_, i) => {
|
|
852
|
+
let value = Math.floor((i + 1) * span / (count + 1));
|
|
853
|
+
let key = "";
|
|
854
|
+
for (let d = 0; d < width; d++) {
|
|
855
|
+
key = DIGITS[value % 62] + key;
|
|
856
|
+
value = Math.floor(value / 62);
|
|
857
|
+
}
|
|
858
|
+
return key.replace(/0+$/, "");
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
function homeFolderName(key, name) {
|
|
862
|
+
return `${key} · ${name || "Workflow"}`;
|
|
863
|
+
}
|
|
864
|
+
function orderWorkflows(workflows, nodes) {
|
|
865
|
+
const byId = new Map(nodes.map((node) => [node.id, node]));
|
|
866
|
+
const childCount = /* @__PURE__ */ new Map();
|
|
867
|
+
for (const node of nodes) if (node.parentFolder) childCount.set(node.parentFolder, (childCount.get(node.parentFolder) ?? 0) + 1);
|
|
868
|
+
return workflows.map((node) => {
|
|
869
|
+
const parent = node.parentFolder ? byId.get(node.parentFolder) : void 0;
|
|
870
|
+
if (parent?.kind !== "folder" || parent.parentFolder || childCount.get(parent.id) !== 1) return { node };
|
|
871
|
+
const match = HOME_FOLDER.exec(parent.name);
|
|
872
|
+
return match ? {
|
|
873
|
+
node,
|
|
874
|
+
folder: parent,
|
|
875
|
+
key: match[1]
|
|
876
|
+
} : { node };
|
|
877
|
+
}).sort((a, b) => {
|
|
878
|
+
if (a.key === void 0 || b.key === void 0) {
|
|
879
|
+
if (a.key !== b.key) return a.key === void 0 ? -1 : 1;
|
|
880
|
+
} else {
|
|
881
|
+
const byKey = compareKeys(a.key, b.key);
|
|
882
|
+
if (byKey !== 0) return byKey;
|
|
883
|
+
}
|
|
884
|
+
return compareKeys(a.node.id, b.node.id);
|
|
885
|
+
});
|
|
886
|
+
}
|
|
887
|
+
/** The key for a new workflow, after every other one. */
|
|
888
|
+
function nextKey(ordered) {
|
|
889
|
+
return keyBetween(ordered.at(-1)?.key, null);
|
|
890
|
+
}
|
|
891
|
+
/** The node to delete to remove a workflow: its home folder, if it has one. */
|
|
892
|
+
function deletionTarget(workflowId, nodes) {
|
|
893
|
+
const node = nodes.find((n) => n.id === workflowId);
|
|
894
|
+
if (node?.kind !== "file") return node;
|
|
895
|
+
return orderWorkflows([node], nodes)[0].folder ?? node;
|
|
896
|
+
}
|
|
897
|
+
function folderTail(item, names) {
|
|
898
|
+
const name = names.get(item.node.id) || item.node.name;
|
|
899
|
+
return item.folder ? HOME_FOLDER.exec(item.folder.name)?.[2] ?? name : name;
|
|
900
|
+
}
|
|
901
|
+
function reorderActions(ordered, from, to, names = /* @__PURE__ */ new Map()) {
|
|
902
|
+
if (from === to || !ordered[from]) return [];
|
|
903
|
+
const next = [...ordered];
|
|
904
|
+
const [moved] = next.splice(from, 1);
|
|
905
|
+
next.splice(to, 0, moved);
|
|
906
|
+
const before = to > 0 ? next[to - 1] : void 0;
|
|
907
|
+
const after = to < next.length - 1 ? next[to + 1] : void 0;
|
|
908
|
+
if (moved.folder && (!before || before.key !== void 0) && (!after || after.key !== void 0) && (!before || !after || compareKeys(before.key, after.key) < 0)) {
|
|
909
|
+
const key = keyBetween(before?.key, after?.key);
|
|
910
|
+
return [updateNode({
|
|
911
|
+
id: moved.folder.id,
|
|
912
|
+
name: homeFolderName(key, folderTail(moved, names))
|
|
913
|
+
})];
|
|
914
|
+
}
|
|
915
|
+
const keys = spreadKeys(next.length);
|
|
916
|
+
return next.flatMap((item, i) => {
|
|
917
|
+
const name = homeFolderName(keys[i], folderTail(item, names));
|
|
918
|
+
if (item.folder) return item.folder.name === name ? [] : [updateNode({
|
|
919
|
+
id: item.folder.id,
|
|
920
|
+
name
|
|
921
|
+
})];
|
|
922
|
+
const folderId = generateId();
|
|
923
|
+
return [addFolder$1({
|
|
924
|
+
id: folderId,
|
|
925
|
+
name,
|
|
926
|
+
parentFolder: null
|
|
927
|
+
}), moveNode({
|
|
928
|
+
srcFolder: item.node.id,
|
|
929
|
+
targetParentFolder: folderId
|
|
930
|
+
})];
|
|
931
|
+
});
|
|
932
|
+
}
|
|
933
|
+
//#endregion
|
|
769
934
|
//#region editors/workflow-studio/components/WorkflowMenu.tsx
|
|
935
|
+
/** Deletes a workflow with its home folder, reading the drive's nodes now. */
|
|
936
|
+
async function deleteWorkflow(workflowId) {
|
|
937
|
+
const driveId = window.ph?.selectedDriveId;
|
|
938
|
+
if (!driveId) throw new Error("No drive is selected");
|
|
939
|
+
const nodes = window.ph?.drives?.find((drive) => drive.header.id === driveId)?.state.global.nodes ?? [];
|
|
940
|
+
await deleteNode(driveId, deletionTarget(workflowId, nodes)?.id ?? workflowId);
|
|
941
|
+
}
|
|
770
942
|
function DeleteWorkflowDialog(props) {
|
|
771
943
|
const [typed, setTyped] = useState("");
|
|
772
944
|
const [error, setError] = useState(null);
|
|
@@ -867,7 +1039,6 @@ function WorkflowMenu(props) {
|
|
|
867
1039
|
const [open, setOpen] = useState(false);
|
|
868
1040
|
const [confirming, setConfirming] = useState(false);
|
|
869
1041
|
const [, dispatch] = useDispatch(props.document);
|
|
870
|
-
const driveId = useSelectedDriveId();
|
|
871
1042
|
const ref = useRef(null);
|
|
872
1043
|
const state = props.document.state.global;
|
|
873
1044
|
const name = state.name || props.nodeName || "Untitled workflow";
|
|
@@ -931,8 +1102,7 @@ function WorkflowMenu(props) {
|
|
|
931
1102
|
name,
|
|
932
1103
|
onCancel: () => setConfirming(false),
|
|
933
1104
|
onConfirm: async () => {
|
|
934
|
-
|
|
935
|
-
await deleteNode(driveId, props.document.header.id);
|
|
1105
|
+
await deleteWorkflow(props.document.header.id);
|
|
936
1106
|
setConfirming(false);
|
|
937
1107
|
props.onDeleted?.();
|
|
938
1108
|
}
|
|
@@ -961,6 +1131,8 @@ function Row(props) {
|
|
|
961
1131
|
"aria-current": props.active ? "true" : void 0,
|
|
962
1132
|
className: `flex min-w-0 grow items-center gap-2.5 rounded-md px-2 py-1.5 text-left text-[13px] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring ${props.active ? "font-medium text-foreground" : "text-foreground/80"}`,
|
|
963
1133
|
onClick: props.onClick,
|
|
1134
|
+
onKeyDown: props.onKeyDown,
|
|
1135
|
+
"aria-keyshortcuts": props.keyShortcuts,
|
|
964
1136
|
children: props.children
|
|
965
1137
|
}), props.trailing]
|
|
966
1138
|
});
|
|
@@ -968,17 +1140,26 @@ function Row(props) {
|
|
|
968
1140
|
const ROW_ACTION = "flex h-6 w-6 shrink-0 items-center justify-center rounded text-muted-foreground opacity-0 hover:bg-background hover:text-foreground focus-visible:opacity-100 group-hover:opacity-100";
|
|
969
1141
|
const DELETE_ACTION = `${ROW_ACTION} hover:text-wf-fail`;
|
|
970
1142
|
function DeleteButton(props) {
|
|
971
|
-
|
|
1143
|
+
const [confirming, setConfirming] = useState(false);
|
|
1144
|
+
const isWorkflow = props.node.documentType === WORKFLOW_TYPE$2;
|
|
1145
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("button", {
|
|
972
1146
|
type: "button",
|
|
973
1147
|
title: "Delete",
|
|
974
1148
|
"aria-label": `Delete ${props.label}`,
|
|
975
1149
|
className: DELETE_ACTION,
|
|
976
|
-
onClick: () => showDeleteNodeModal(props.node),
|
|
1150
|
+
onClick: () => isWorkflow ? setConfirming(true) : showDeleteNodeModal(props.node),
|
|
977
1151
|
children: /* @__PURE__ */ jsx(Icon, {
|
|
978
1152
|
name: "trash",
|
|
979
1153
|
className: "h-3.5 w-3.5"
|
|
980
1154
|
})
|
|
981
|
-
})
|
|
1155
|
+
}), confirming ? /* @__PURE__ */ jsx(DeleteWorkflowDialog, {
|
|
1156
|
+
name: props.label,
|
|
1157
|
+
onCancel: () => setConfirming(false),
|
|
1158
|
+
onConfirm: async () => {
|
|
1159
|
+
await deleteWorkflow(props.node.id);
|
|
1160
|
+
setConfirming(false);
|
|
1161
|
+
}
|
|
1162
|
+
}) : null] });
|
|
982
1163
|
}
|
|
983
1164
|
function NodeRow(props) {
|
|
984
1165
|
const { node } = props;
|
|
@@ -989,6 +1170,8 @@ function NodeRow(props) {
|
|
|
989
1170
|
if (error !== void 0) return /* @__PURE__ */ jsxs(Row, {
|
|
990
1171
|
active: props.active,
|
|
991
1172
|
onClick: props.onOpen,
|
|
1173
|
+
onKeyDown: props.onKeyDown,
|
|
1174
|
+
keyShortcuts: props.keyShortcuts,
|
|
992
1175
|
trailing: /* @__PURE__ */ jsx("span", {
|
|
993
1176
|
className: "mr-1.5 flex shrink-0 items-center",
|
|
994
1177
|
children: /* @__PURE__ */ jsx(DeleteButton, {
|
|
@@ -1016,6 +1199,8 @@ function NodeRow(props) {
|
|
|
1016
1199
|
return /* @__PURE__ */ jsxs(Row, {
|
|
1017
1200
|
active: props.active,
|
|
1018
1201
|
onClick: props.onOpen,
|
|
1202
|
+
onKeyDown: props.onKeyDown,
|
|
1203
|
+
keyShortcuts: props.keyShortcuts,
|
|
1019
1204
|
trailing: /* @__PURE__ */ jsxs("span", {
|
|
1020
1205
|
className: "mr-1.5 flex shrink-0 items-center",
|
|
1021
1206
|
children: [props.onEdit ? /* @__PURE__ */ jsx("button", {
|
|
@@ -1050,12 +1235,30 @@ function NodeRow(props) {
|
|
|
1050
1235
|
})]
|
|
1051
1236
|
});
|
|
1052
1237
|
}
|
|
1238
|
+
function DropLine(props) {
|
|
1239
|
+
return /* @__PURE__ */ jsx("span", {
|
|
1240
|
+
"aria-hidden": true,
|
|
1241
|
+
className: `pointer-events-none absolute inset-x-3 z-10 h-0.5 rounded-full bg-primary ${props.edge === "top" ? "-top-px" : "-bottom-px"}`
|
|
1242
|
+
});
|
|
1243
|
+
}
|
|
1053
1244
|
function Section(props) {
|
|
1245
|
+
const { onReorder } = props;
|
|
1246
|
+
const headingId = useId();
|
|
1247
|
+
const [drag, setDrag] = useState(null);
|
|
1248
|
+
const count = props.nodes.length;
|
|
1249
|
+
const drop = (from, at) => {
|
|
1250
|
+
const to = at > from ? at - 1 : at;
|
|
1251
|
+
if (to !== from) onReorder?.(from, to);
|
|
1252
|
+
};
|
|
1253
|
+
const showLine = (at) => drag !== null && drag.at === at && at !== drag.from && at !== drag.from + 1;
|
|
1054
1254
|
return /* @__PURE__ */ jsxs("div", {
|
|
1055
1255
|
className: "mt-5",
|
|
1256
|
+
role: "group",
|
|
1257
|
+
"aria-labelledby": headingId,
|
|
1056
1258
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
1057
1259
|
className: "mb-1 flex items-center justify-between pl-4 pr-3",
|
|
1058
1260
|
children: [/* @__PURE__ */ jsx("h3", {
|
|
1261
|
+
id: headingId,
|
|
1059
1262
|
className: "text-xs font-medium text-muted-foreground",
|
|
1060
1263
|
children: props.title
|
|
1061
1264
|
}), /* @__PURE__ */ jsx("button", {
|
|
@@ -1075,12 +1278,56 @@ function Section(props) {
|
|
|
1075
1278
|
children: props.empty
|
|
1076
1279
|
}) : /* @__PURE__ */ jsx("div", {
|
|
1077
1280
|
className: "flex flex-col gap-0.5",
|
|
1078
|
-
children: props.nodes.map((node) => /* @__PURE__ */
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1281
|
+
children: props.nodes.map((node, i) => /* @__PURE__ */ jsxs("div", {
|
|
1282
|
+
className: `relative ${drag?.from === i ? "opacity-50" : ""}`,
|
|
1283
|
+
draggable: Boolean(onReorder),
|
|
1284
|
+
onDragStart: (event) => {
|
|
1285
|
+
event.dataTransfer.effectAllowed = "move";
|
|
1286
|
+
event.dataTransfer.setData("text/plain", node.id);
|
|
1287
|
+
setDrag({
|
|
1288
|
+
from: i,
|
|
1289
|
+
at: i
|
|
1290
|
+
});
|
|
1291
|
+
},
|
|
1292
|
+
onDragOver: (event) => {
|
|
1293
|
+
if (!drag) return;
|
|
1294
|
+
event.preventDefault();
|
|
1295
|
+
event.dataTransfer.dropEffect = "move";
|
|
1296
|
+
const box = event.currentTarget.getBoundingClientRect();
|
|
1297
|
+
const at = event.clientY < box.top + box.height / 2 ? i : i + 1;
|
|
1298
|
+
if (at !== drag.at) setDrag({
|
|
1299
|
+
...drag,
|
|
1300
|
+
at
|
|
1301
|
+
});
|
|
1302
|
+
},
|
|
1303
|
+
onDrop: (event) => {
|
|
1304
|
+
event.preventDefault();
|
|
1305
|
+
if (drag) drop(drag.from, drag.at);
|
|
1306
|
+
setDrag(null);
|
|
1307
|
+
},
|
|
1308
|
+
onDragEnd: () => setDrag(null),
|
|
1309
|
+
children: [
|
|
1310
|
+
showLine(i) ? /* @__PURE__ */ jsx(DropLine, { edge: "top" }) : null,
|
|
1311
|
+
/* @__PURE__ */ jsx(NodeRow, {
|
|
1312
|
+
node,
|
|
1313
|
+
lastRunStatus: props.lastRuns?.get(node.id),
|
|
1314
|
+
active: props.activeId === node.id,
|
|
1315
|
+
onOpen: () => props.onOpen(node),
|
|
1316
|
+
onEdit: props.onEdit ? () => props.onEdit(node) : void 0,
|
|
1317
|
+
keyShortcuts: onReorder ? "Alt+ArrowUp Alt+ArrowDown" : void 0,
|
|
1318
|
+
onKeyDown: onReorder ? (event) => {
|
|
1319
|
+
if (!event.altKey) return;
|
|
1320
|
+
if (event.key === "ArrowUp" && i > 0) {
|
|
1321
|
+
event.preventDefault();
|
|
1322
|
+
onReorder(i, i - 1);
|
|
1323
|
+
} else if (event.key === "ArrowDown" && i < count - 1) {
|
|
1324
|
+
event.preventDefault();
|
|
1325
|
+
onReorder(i, i + 1);
|
|
1326
|
+
}
|
|
1327
|
+
} : void 0
|
|
1328
|
+
}),
|
|
1329
|
+
i === count - 1 && showLine(count) ? /* @__PURE__ */ jsx(DropLine, { edge: "bottom" }) : null
|
|
1330
|
+
]
|
|
1084
1331
|
}, node.id))
|
|
1085
1332
|
})]
|
|
1086
1333
|
});
|
|
@@ -1107,6 +1354,7 @@ function Sidebar(props) {
|
|
|
1107
1354
|
onOpen: props.onOpenWorkflow,
|
|
1108
1355
|
onEdit: props.onEditWorkflow,
|
|
1109
1356
|
onCreate: props.onCreateWorkflow,
|
|
1357
|
+
onReorder: props.onReorderWorkflow,
|
|
1110
1358
|
creating: props.creating
|
|
1111
1359
|
}),
|
|
1112
1360
|
/* @__PURE__ */ jsx(Section, {
|
|
@@ -1138,11 +1386,13 @@ function useHashSelection() {
|
|
|
1138
1386
|
window.removeEventListener("popstate", sync);
|
|
1139
1387
|
};
|
|
1140
1388
|
}, []);
|
|
1141
|
-
return [selected, useCallback((id) => {
|
|
1389
|
+
return [selected, useCallback((id, options) => {
|
|
1142
1390
|
setSelected(id);
|
|
1143
1391
|
const url = new URL(window.location.href);
|
|
1144
1392
|
url.hash = id ?? "";
|
|
1145
|
-
window.
|
|
1393
|
+
if (url.href === window.location.href) return;
|
|
1394
|
+
if (options?.replace) window.history.replaceState(null, "", url);
|
|
1395
|
+
else window.history.pushState(null, "", url);
|
|
1146
1396
|
}, [])];
|
|
1147
1397
|
}
|
|
1148
1398
|
//#endregion
|
|
@@ -1169,46 +1419,647 @@ function useRuns(scope, active = true) {
|
|
|
1169
1419
|
};
|
|
1170
1420
|
}
|
|
1171
1421
|
//#endregion
|
|
1172
|
-
//#region editors/workflow-studio/components/
|
|
1173
|
-
|
|
1422
|
+
//#region editors/workflow-studio/components/ScrollFade.tsx
|
|
1423
|
+
const FADE = 40;
|
|
1424
|
+
function fadeMask(start, end) {
|
|
1425
|
+
if (!start && !end) return void 0;
|
|
1426
|
+
return `linear-gradient(to right, ${start ? `transparent, black ${FADE}px` : "black"}, ${end ? `black calc(100% - ${FADE}px), transparent` : "black"})`;
|
|
1427
|
+
}
|
|
1428
|
+
function ScrollFade(props) {
|
|
1429
|
+
const ref = useRef(null);
|
|
1430
|
+
const [edges, setEdges] = useState({
|
|
1431
|
+
start: false,
|
|
1432
|
+
end: false
|
|
1433
|
+
});
|
|
1434
|
+
useEffect(() => {
|
|
1435
|
+
const element = ref.current;
|
|
1436
|
+
if (!element) return;
|
|
1437
|
+
const measure = () => {
|
|
1438
|
+
const start = element.scrollLeft > 1;
|
|
1439
|
+
const end = element.scrollLeft + element.clientWidth < element.scrollWidth - 1;
|
|
1440
|
+
setEdges((prev) => prev.start === start && prev.end === end ? prev : {
|
|
1441
|
+
start,
|
|
1442
|
+
end
|
|
1443
|
+
});
|
|
1444
|
+
};
|
|
1445
|
+
measure();
|
|
1446
|
+
const resize = new ResizeObserver(measure);
|
|
1447
|
+
resize.observe(element);
|
|
1448
|
+
if (element.firstElementChild) resize.observe(element.firstElementChild);
|
|
1449
|
+
element.addEventListener("scroll", measure, { passive: true });
|
|
1450
|
+
return () => {
|
|
1451
|
+
resize.disconnect();
|
|
1452
|
+
element.removeEventListener("scroll", measure);
|
|
1453
|
+
};
|
|
1454
|
+
}, []);
|
|
1455
|
+
const mask = fadeMask(edges.start, edges.end);
|
|
1456
|
+
return /* @__PURE__ */ jsx("span", {
|
|
1457
|
+
ref,
|
|
1458
|
+
className: `block ${props.clip ? "overflow-hidden" : "overflow-x-auto"} ${props.className ?? ""}`,
|
|
1459
|
+
style: {
|
|
1460
|
+
maskImage: mask,
|
|
1461
|
+
WebkitMaskImage: mask
|
|
1462
|
+
},
|
|
1463
|
+
children: props.children
|
|
1464
|
+
});
|
|
1465
|
+
}
|
|
1466
|
+
//#endregion
|
|
1467
|
+
//#region editors/workflow-studio/components/use-collapsed.ts
|
|
1468
|
+
const KEY = "workflow-studio:collapsed";
|
|
1469
|
+
function read() {
|
|
1470
|
+
try {
|
|
1471
|
+
const parsed = JSON.parse(localStorage.getItem(KEY) ?? "[]");
|
|
1472
|
+
return new Set(Array.isArray(parsed) ? parsed.filter((id) => typeof id === "string") : []);
|
|
1473
|
+
} catch {
|
|
1474
|
+
return /* @__PURE__ */ new Set();
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
function write(ids) {
|
|
1478
|
+
try {
|
|
1479
|
+
localStorage.setItem(KEY, JSON.stringify([...ids]));
|
|
1480
|
+
} catch {}
|
|
1481
|
+
}
|
|
1482
|
+
function useCollapsed() {
|
|
1483
|
+
const [collapsed, setCollapsed] = useState(read);
|
|
1484
|
+
return {
|
|
1485
|
+
isCollapsed: (id) => collapsed.has(id),
|
|
1486
|
+
toggle: useCallback((id) => {
|
|
1487
|
+
setCollapsed((previous) => {
|
|
1488
|
+
const next = new Set(previous);
|
|
1489
|
+
if (!next.delete(id)) next.add(id);
|
|
1490
|
+
write(next);
|
|
1491
|
+
return next;
|
|
1492
|
+
});
|
|
1493
|
+
}, [])
|
|
1494
|
+
};
|
|
1495
|
+
}
|
|
1496
|
+
//#endregion
|
|
1497
|
+
//#region editors/workflow-studio/components/graph-layout.ts
|
|
1498
|
+
const TRIGGER_NODE = "trigger";
|
|
1499
|
+
const SIDE_PORTS = /* @__PURE__ */ new Set(["false", "error"]);
|
|
1500
|
+
function graphLayout(args) {
|
|
1501
|
+
const { rows } = stepOutline(args);
|
|
1502
|
+
const nodeId = (id) => id === args.triggerId ? TRIGGER_NODE : id;
|
|
1503
|
+
const placed = /* @__PURE__ */ new Map([[TRIGGER_NODE, {
|
|
1504
|
+
col: 0,
|
|
1505
|
+
lane: 0
|
|
1506
|
+
}]]);
|
|
1507
|
+
const taken = /* @__PURE__ */ new Set();
|
|
1174
1508
|
const inbound = /* @__PURE__ */ new Map();
|
|
1509
|
+
const outbound = /* @__PURE__ */ new Map();
|
|
1175
1510
|
for (const edge of args.edges) {
|
|
1176
1511
|
const list = inbound.get(edge.to) ?? [];
|
|
1177
1512
|
list.push(edge);
|
|
1178
1513
|
inbound.set(edge.to, list);
|
|
1514
|
+
outbound.set(edge.from, (outbound.get(edge.from) ?? 0) + 1);
|
|
1179
1515
|
}
|
|
1180
|
-
const
|
|
1181
|
-
const
|
|
1182
|
-
const
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
step,
|
|
1200
|
-
port: port === "next" ? null : port
|
|
1201
|
-
});
|
|
1202
|
-
progressed = true;
|
|
1203
|
-
}
|
|
1516
|
+
const drops = (edge) => SIDE_PORTS.has(edge.port) && (outbound.get(edge.from) ?? 0) > 1;
|
|
1517
|
+
const nodes = [];
|
|
1518
|
+
for (const { step } of rows) {
|
|
1519
|
+
const from = (inbound.get(step.id) ?? []).filter((edge) => placed.has(nodeId(edge.from)));
|
|
1520
|
+
const col = Math.max(1, ...from.map((edge) => placed.get(nodeId(edge.from)).col + 1));
|
|
1521
|
+
let lane = Math.min(...from.map((edge) => placed.get(nodeId(edge.from)).lane + (drops(edge) ? 1 : 0)), from.length === 0 ? 0 : Infinity);
|
|
1522
|
+
const port = from.length === 1 && from[0].port !== "next" ? from[0].port : null;
|
|
1523
|
+
while (taken.has(`${col}:${lane}`)) lane++;
|
|
1524
|
+
taken.add(`${col}:${lane}`);
|
|
1525
|
+
placed.set(step.id, {
|
|
1526
|
+
col,
|
|
1527
|
+
lane
|
|
1528
|
+
});
|
|
1529
|
+
nodes.push({
|
|
1530
|
+
step,
|
|
1531
|
+
col,
|
|
1532
|
+
lane,
|
|
1533
|
+
port
|
|
1534
|
+
});
|
|
1204
1535
|
}
|
|
1205
1536
|
return {
|
|
1206
|
-
|
|
1207
|
-
|
|
1537
|
+
nodes,
|
|
1538
|
+
edges: args.edges.map((edge) => ({
|
|
1539
|
+
...edge,
|
|
1540
|
+
from: nodeId(edge.from)
|
|
1541
|
+
})).filter((edge) => placed.has(edge.from) && placed.has(edge.to)).map((edge) => {
|
|
1542
|
+
const a = placed.get(edge.from);
|
|
1543
|
+
const b = placed.get(edge.to);
|
|
1544
|
+
const clear = (lane) => !nodes.some((node) => node.lane === lane && node.col > a.col && node.col < b.col);
|
|
1545
|
+
const low = Math.max(a.lane, b.lane);
|
|
1546
|
+
const high = Math.min(a.lane, b.lane);
|
|
1547
|
+
const track = clear(low) ? {
|
|
1548
|
+
lane: low,
|
|
1549
|
+
under: false
|
|
1550
|
+
} : clear(high) ? {
|
|
1551
|
+
lane: high,
|
|
1552
|
+
under: false
|
|
1553
|
+
} : {
|
|
1554
|
+
lane: high,
|
|
1555
|
+
under: true
|
|
1556
|
+
};
|
|
1557
|
+
return {
|
|
1558
|
+
from: edge.from,
|
|
1559
|
+
to: edge.to,
|
|
1560
|
+
port: edge.port,
|
|
1561
|
+
track
|
|
1562
|
+
};
|
|
1563
|
+
}),
|
|
1564
|
+
cols: Math.max(0, ...nodes.map((node) => node.col)),
|
|
1565
|
+
lanes: Math.max(1, ...nodes.map((node) => node.lane + 1))
|
|
1566
|
+
};
|
|
1567
|
+
}
|
|
1568
|
+
//#endregion
|
|
1569
|
+
//#region editors/workflow-studio/components/WorkflowGraph.tsx
|
|
1570
|
+
const STACK_GAP = 16;
|
|
1571
|
+
const MAX_STRETCH = 1.5;
|
|
1572
|
+
function fitGraph(base, cols, room) {
|
|
1573
|
+
if (!room || room.width <= 0 || cols === 0) return {
|
|
1574
|
+
g: base,
|
|
1575
|
+
stacked: false,
|
|
1576
|
+
perRow: Math.max(cols, 1)
|
|
1577
|
+
};
|
|
1578
|
+
const tailOf = (col) => base.label ? col / 2 : base.r;
|
|
1579
|
+
const span = (n, lead) => lead + (n - 1) * base.col + base.r + tailOf(base.col);
|
|
1580
|
+
const beside = room.width - room.pill;
|
|
1581
|
+
const stacked = span(cols, base.lead) > beside;
|
|
1582
|
+
const lead = stacked ? base.pillLogoX * 2 : base.lead;
|
|
1583
|
+
const space = stacked ? room.width : beside;
|
|
1584
|
+
const fits = Math.floor((space - lead - base.r - tailOf(base.col)) / base.col) + 1;
|
|
1585
|
+
const perRow = stacked ? Math.min(cols, Math.max(2, fits)) : cols;
|
|
1586
|
+
const fill = base.label ? (space - lead - base.r) / (perRow - .5) : perRow > 1 ? (space - lead - 2 * base.r) / (perRow - 1) : base.col;
|
|
1587
|
+
const col = Math.floor(Math.min(base.col * MAX_STRETCH, Math.max(base.col, fill)));
|
|
1588
|
+
return {
|
|
1589
|
+
g: {
|
|
1590
|
+
...base,
|
|
1591
|
+
col,
|
|
1592
|
+
lead
|
|
1593
|
+
},
|
|
1594
|
+
stacked,
|
|
1595
|
+
perRow
|
|
1596
|
+
};
|
|
1597
|
+
}
|
|
1598
|
+
const GEOMETRY = {
|
|
1599
|
+
sm: {
|
|
1600
|
+
r: 12,
|
|
1601
|
+
col: 144,
|
|
1602
|
+
lane: 80,
|
|
1603
|
+
lead: 40,
|
|
1604
|
+
top: 14,
|
|
1605
|
+
dip: 60,
|
|
1606
|
+
label: 34,
|
|
1607
|
+
subtitle: false,
|
|
1608
|
+
nameText: "text-xs leading-4",
|
|
1609
|
+
logo: 14,
|
|
1610
|
+
circle: "h-6 w-6",
|
|
1611
|
+
pill: "h-7 pl-1 pr-2.5 text-[12px]",
|
|
1612
|
+
pillLogo: "h-5 w-5",
|
|
1613
|
+
pillLogoX: 14,
|
|
1614
|
+
portText: "text-[10px]"
|
|
1615
|
+
},
|
|
1616
|
+
md: {
|
|
1617
|
+
r: 18,
|
|
1618
|
+
col: 168,
|
|
1619
|
+
lane: 112,
|
|
1620
|
+
lead: 48,
|
|
1621
|
+
top: 18,
|
|
1622
|
+
dip: 86,
|
|
1623
|
+
label: 54,
|
|
1624
|
+
subtitle: true,
|
|
1625
|
+
nameText: "text-[13px] leading-[18px]",
|
|
1626
|
+
logo: 20,
|
|
1627
|
+
circle: "h-9 w-9",
|
|
1628
|
+
pill: "h-9 pl-1.5 pr-3 text-[13px]",
|
|
1629
|
+
pillLogo: "h-6 w-6",
|
|
1630
|
+
pillLogoX: 18,
|
|
1631
|
+
portText: "text-[11px]"
|
|
1632
|
+
}
|
|
1633
|
+
};
|
|
1634
|
+
const RING$1 = {
|
|
1635
|
+
ok: "ring-wf-ok",
|
|
1636
|
+
fail: "ring-wf-fail",
|
|
1637
|
+
warn: "ring-wf-warn",
|
|
1638
|
+
run: "ring-wf-run",
|
|
1639
|
+
idle: "ring-foreground/15 dark:ring-foreground/30"
|
|
1640
|
+
};
|
|
1641
|
+
const STROKE = {
|
|
1642
|
+
ok: "text-wf-ok",
|
|
1643
|
+
fail: "text-wf-fail",
|
|
1644
|
+
warn: "text-wf-warn",
|
|
1645
|
+
run: "text-wf-run",
|
|
1646
|
+
idle: "text-foreground/15 dark:text-foreground/30"
|
|
1647
|
+
};
|
|
1648
|
+
const PORT_PILL = {
|
|
1649
|
+
true: "bg-wf-ok/10 text-wf-ok ring-wf-ok/30",
|
|
1650
|
+
false: "bg-foreground/5 text-muted-foreground ring-foreground/15",
|
|
1651
|
+
error: "bg-wf-fail/10 text-wf-fail ring-wf-fail/30"
|
|
1652
|
+
};
|
|
1653
|
+
const PORT_TEXT = {
|
|
1654
|
+
true: "Runs when the condition is true",
|
|
1655
|
+
false: "Runs when the condition is false",
|
|
1656
|
+
error: "Runs when the step before it fails"
|
|
1657
|
+
};
|
|
1658
|
+
function roundedPath(points, radius = 6) {
|
|
1659
|
+
let d = `M ${points[0][0]} ${points[0][1]}`;
|
|
1660
|
+
for (let i = 1; i < points.length - 1; i++) {
|
|
1661
|
+
const [px, py] = points[i - 1];
|
|
1662
|
+
const [x, y] = points[i];
|
|
1663
|
+
const [nx, ny] = points[i + 1];
|
|
1664
|
+
const r = Math.min(radius, Math.hypot(x - px, y - py) / 2, Math.hypot(nx - x, ny - y) / 2);
|
|
1665
|
+
const inX = x - Math.sign(x - px) * r;
|
|
1666
|
+
const inY = y - Math.sign(y - py) * r;
|
|
1667
|
+
const outX = x + Math.sign(nx - x) * r;
|
|
1668
|
+
const outY = y + Math.sign(ny - y) * r;
|
|
1669
|
+
d += ` L ${inX} ${inY} Q ${x} ${y} ${outX} ${outY}`;
|
|
1670
|
+
}
|
|
1671
|
+
const [lx, ly] = points[points.length - 1];
|
|
1672
|
+
return `${d} L ${lx} ${ly}`;
|
|
1673
|
+
}
|
|
1674
|
+
function simplify(route) {
|
|
1675
|
+
const points = [];
|
|
1676
|
+
for (const point of route) {
|
|
1677
|
+
const last = points.at(-1);
|
|
1678
|
+
if (last && last[0] === point[0] && last[1] === point[1]) continue;
|
|
1679
|
+
const prev = points.at(-2);
|
|
1680
|
+
if (prev && last && (prev[0] === last[0] && last[0] === point[0] || prev[1] === last[1] && last[1] === point[1])) points.pop();
|
|
1681
|
+
points.push(point);
|
|
1682
|
+
}
|
|
1683
|
+
return points;
|
|
1684
|
+
}
|
|
1685
|
+
function edgeRoute(g, source, target, trackY, stacked) {
|
|
1686
|
+
const dir = target.dir;
|
|
1687
|
+
const after = source ? source.x + dir * g.col / 2 : g.lead / 2;
|
|
1688
|
+
const fromAbove = !source && stacked;
|
|
1689
|
+
const x1 = source ? source.x + dir * g.r : fromAbove ? after : 0;
|
|
1690
|
+
const y1 = source ? source.y : fromAbove ? -16 : g.top;
|
|
1691
|
+
const x2 = target.x - dir * g.r;
|
|
1692
|
+
const y2 = target.y;
|
|
1693
|
+
const before = target.x - dir * g.col / 2;
|
|
1694
|
+
return {
|
|
1695
|
+
points: simplify([
|
|
1696
|
+
[x1, y1],
|
|
1697
|
+
[after, y1],
|
|
1698
|
+
[after, trackY],
|
|
1699
|
+
[before, trackY],
|
|
1700
|
+
[before, y2],
|
|
1701
|
+
[x2, y2]
|
|
1702
|
+
]),
|
|
1703
|
+
label: {
|
|
1704
|
+
x: ((trackY === y1 ? x1 : after) + (trackY === y2 ? x2 : before)) / 2,
|
|
1705
|
+
y: trackY
|
|
1706
|
+
}
|
|
1707
|
+
};
|
|
1708
|
+
}
|
|
1709
|
+
function wrapRoute(g, source, target, ends) {
|
|
1710
|
+
const turn = source.dir > 0 ? ends.right : ends.left;
|
|
1711
|
+
const x1 = source.x + source.dir * g.r;
|
|
1712
|
+
const before = target.x - target.dir * g.col / 2;
|
|
1713
|
+
const y = (target.row - source.row) % 2 === 1 ? target.y : target.y - g.lane / 2;
|
|
1714
|
+
return {
|
|
1715
|
+
points: simplify([
|
|
1716
|
+
[x1, source.y],
|
|
1717
|
+
[turn, source.y],
|
|
1718
|
+
[turn, y],
|
|
1719
|
+
[before, y],
|
|
1720
|
+
[before, target.y],
|
|
1721
|
+
[target.x - target.dir * g.r, target.y]
|
|
1722
|
+
]),
|
|
1723
|
+
label: {
|
|
1724
|
+
x: (x1 + turn) / 2,
|
|
1725
|
+
y: source.y
|
|
1726
|
+
}
|
|
1727
|
+
};
|
|
1728
|
+
}
|
|
1729
|
+
function Mark({ label, className, onOpen, children, ref, onClick, ...rest }) {
|
|
1730
|
+
return onOpen ? /* @__PURE__ */ jsx("button", {
|
|
1731
|
+
...rest,
|
|
1732
|
+
ref,
|
|
1733
|
+
type: "button",
|
|
1734
|
+
"aria-label": label,
|
|
1735
|
+
className: `${className} focus-visible:outline-none focus-visible:ring-[3px]`,
|
|
1736
|
+
onClick: (event) => {
|
|
1737
|
+
onClick?.(event);
|
|
1738
|
+
onOpen();
|
|
1739
|
+
},
|
|
1740
|
+
children
|
|
1741
|
+
}) : /* @__PURE__ */ jsx("span", {
|
|
1742
|
+
...rest,
|
|
1743
|
+
ref,
|
|
1744
|
+
onClick,
|
|
1745
|
+
className,
|
|
1746
|
+
children
|
|
1747
|
+
});
|
|
1748
|
+
}
|
|
1749
|
+
function Tip(props) {
|
|
1750
|
+
return /* @__PURE__ */ jsx(ConnectTooltip, {
|
|
1751
|
+
content: props.content,
|
|
1752
|
+
side: "bottom",
|
|
1753
|
+
delayDuration: 100,
|
|
1754
|
+
className: "max-w-64 rounded-md border-solid border-foreground/10 bg-card px-2.5 py-1.5 text-foreground shadow-lg",
|
|
1755
|
+
children: props.children
|
|
1756
|
+
});
|
|
1757
|
+
}
|
|
1758
|
+
function stepSummary(record, ran) {
|
|
1759
|
+
if (!ran) return "Not run yet";
|
|
1760
|
+
if (!record) return "Not reached in the latest run";
|
|
1761
|
+
const took = record.startedAt && record.endedAt ? ` · ${formatDuration(record.startedAt, record.endedAt)}` : "";
|
|
1762
|
+
return `${statusLabel(record.status)} in the latest run${took}`;
|
|
1763
|
+
}
|
|
1764
|
+
function StepTip(props) {
|
|
1765
|
+
const { step } = props.node;
|
|
1766
|
+
const meta = blockMeta(stepBlock(step));
|
|
1767
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
1768
|
+
className: "flex flex-col gap-0.5",
|
|
1769
|
+
children: [
|
|
1770
|
+
/* @__PURE__ */ jsx("span", {
|
|
1771
|
+
className: "font-medium",
|
|
1772
|
+
children: step.name || step.key
|
|
1773
|
+
}),
|
|
1774
|
+
/* @__PURE__ */ jsxs("span", {
|
|
1775
|
+
className: "text-muted-foreground",
|
|
1776
|
+
children: [
|
|
1777
|
+
meta.displayName,
|
|
1778
|
+
" · ",
|
|
1779
|
+
meta.subtitle
|
|
1780
|
+
]
|
|
1781
|
+
}),
|
|
1782
|
+
props.node.port ? /* @__PURE__ */ jsx("span", {
|
|
1783
|
+
className: "text-muted-foreground",
|
|
1784
|
+
children: PORT_TEXT[props.node.port] ?? `Runs on "${props.node.port}"`
|
|
1785
|
+
}) : null,
|
|
1786
|
+
/* @__PURE__ */ jsx("span", {
|
|
1787
|
+
className: "mt-1",
|
|
1788
|
+
children: stepSummary(props.record, props.ran)
|
|
1789
|
+
}),
|
|
1790
|
+
props.record?.error ? /* @__PURE__ */ jsx("span", {
|
|
1791
|
+
className: "line-clamp-3 text-wf-fail",
|
|
1792
|
+
children: props.record.error
|
|
1793
|
+
}) : null
|
|
1794
|
+
]
|
|
1795
|
+
});
|
|
1796
|
+
}
|
|
1797
|
+
function WorkflowGraph(props) {
|
|
1798
|
+
const { state, latest } = props;
|
|
1799
|
+
const frame = useRef(null);
|
|
1800
|
+
const pill = useRef(null);
|
|
1801
|
+
const [room, setRoom] = useState(null);
|
|
1802
|
+
useLayoutEffect(() => {
|
|
1803
|
+
const element = frame.current;
|
|
1804
|
+
if (!props.fit || !element) return;
|
|
1805
|
+
const measure = () => {
|
|
1806
|
+
const next = {
|
|
1807
|
+
width: element.clientWidth,
|
|
1808
|
+
pill: pill.current?.offsetWidth ?? 0
|
|
1809
|
+
};
|
|
1810
|
+
setRoom((prev) => prev?.width === next.width && prev.pill === next.pill ? prev : next);
|
|
1811
|
+
};
|
|
1812
|
+
measure();
|
|
1813
|
+
const observer = new ResizeObserver(measure);
|
|
1814
|
+
observer.observe(element);
|
|
1815
|
+
if (pill.current) observer.observe(pill.current);
|
|
1816
|
+
return () => observer.disconnect();
|
|
1817
|
+
}, [props.fit]);
|
|
1818
|
+
const layout = graphLayout({
|
|
1819
|
+
triggerId: state.trigger?.id,
|
|
1820
|
+
steps: state.steps,
|
|
1821
|
+
edges: state.edges
|
|
1822
|
+
});
|
|
1823
|
+
const { g, stacked, perRow } = fitGraph(GEOMETRY[props.size ?? "sm"], layout.cols, props.fit ? room : null);
|
|
1824
|
+
const rowOf = (col) => Math.floor((col - 1) / perRow);
|
|
1825
|
+
const rows = Math.max(1, Math.ceil(layout.cols / perRow));
|
|
1826
|
+
const rowLanes = Array.from({ length: rows }, () => 1);
|
|
1827
|
+
for (const node of layout.nodes) {
|
|
1828
|
+
const row = rowOf(node.col);
|
|
1829
|
+
rowLanes[row] = Math.max(rowLanes[row], node.lane + 1);
|
|
1830
|
+
}
|
|
1831
|
+
const rowTop = [];
|
|
1832
|
+
for (let row = 0, y = g.top; row < rows; y += rowLanes[row] * g.lane, row++) rowTop.push(y);
|
|
1833
|
+
const spot = (col, lane) => {
|
|
1834
|
+
const row = rowOf(col);
|
|
1835
|
+
const slot = (col - 1) % perRow;
|
|
1836
|
+
const back = row % 2 === 1;
|
|
1837
|
+
return {
|
|
1838
|
+
x: g.lead + (back ? perRow - 1 - slot : slot) * g.col + g.r,
|
|
1839
|
+
y: rowTop[row] + lane * g.lane,
|
|
1840
|
+
row,
|
|
1841
|
+
dir: back ? -1 : 1
|
|
1842
|
+
};
|
|
1843
|
+
};
|
|
1844
|
+
const records = new Map((latest?.steps ?? []).map((record) => [record.stepKey, record]));
|
|
1845
|
+
const toneOfStep = (key) => {
|
|
1846
|
+
const status = records.get(key)?.status;
|
|
1847
|
+
return status ? toneOf(STEP_TONE, status) : "idle";
|
|
1208
1848
|
};
|
|
1849
|
+
const at = new Map(layout.nodes.map((node) => [node.step.id, node]));
|
|
1850
|
+
const lastX = g.lead + (Math.min(perRow, layout.cols) - 1) * g.col + g.r;
|
|
1851
|
+
const width = layout.cols > 0 ? lastX + (g.label ? g.col / 2 : g.r) : 0;
|
|
1852
|
+
const ends = {
|
|
1853
|
+
left: g.lead / 2,
|
|
1854
|
+
right: lastX + g.col / 2
|
|
1855
|
+
};
|
|
1856
|
+
const trackY = (edge, row) => rowTop[row] + edge.track.lane * g.lane + (edge.track.under ? g.dip : 0);
|
|
1857
|
+
const routes = layout.edges.map((edge) => {
|
|
1858
|
+
const from = edge.from === "trigger" ? null : at.get(edge.from);
|
|
1859
|
+
const to = at.get(edge.to);
|
|
1860
|
+
const source = from ? spot(from.col, from.lane) : null;
|
|
1861
|
+
const target = spot(to.col, to.lane);
|
|
1862
|
+
const wraps = source !== null && source.row !== target.row;
|
|
1863
|
+
return {
|
|
1864
|
+
key: `${edge.from}-${edge.port}-${edge.to}`,
|
|
1865
|
+
edge,
|
|
1866
|
+
tone: toneOfStep(to.step.key),
|
|
1867
|
+
under: !wraps && edge.track.under,
|
|
1868
|
+
route: wraps ? wrapRoute(g, source, target, ends) : edgeRoute(g, source, target, trackY(edge, target.row), stacked)
|
|
1869
|
+
};
|
|
1870
|
+
});
|
|
1871
|
+
const dips = routes.filter((route) => route.under).map(({ route, edge }) => route.label.y + (PORT_PILL[edge.port] ? 10 : 4));
|
|
1872
|
+
const height = Math.max(...layout.nodes.map((node) => spot(node.col, node.lane).y + (g.label ? g.r + 6 + g.label : g.top)), ...dips);
|
|
1873
|
+
const labelBox = (x) => {
|
|
1874
|
+
let w = Math.min(g.col - 16, 2 * (width - x));
|
|
1875
|
+
let left = x - w / 2;
|
|
1876
|
+
if (stacked && left < -12) {
|
|
1877
|
+
left += Math.min(-12 - left, 16);
|
|
1878
|
+
if (left < -12) {
|
|
1879
|
+
w -= -12 - left;
|
|
1880
|
+
left = -12;
|
|
1881
|
+
}
|
|
1882
|
+
}
|
|
1883
|
+
return {
|
|
1884
|
+
left,
|
|
1885
|
+
width: w
|
|
1886
|
+
};
|
|
1887
|
+
};
|
|
1888
|
+
const trigger = state.trigger ? triggerBlock(state.trigger) : null;
|
|
1889
|
+
const triggerMeta = trigger ? blockMeta(trigger) : null;
|
|
1890
|
+
return /* @__PURE__ */ jsx(ConnectTooltipProvider, {
|
|
1891
|
+
disableHoverableContent: true,
|
|
1892
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
1893
|
+
ref: frame,
|
|
1894
|
+
className: stacked ? "flex flex-col items-start" : "flex items-start",
|
|
1895
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
1896
|
+
ref: pill,
|
|
1897
|
+
className: "flex shrink-0",
|
|
1898
|
+
children: /* @__PURE__ */ jsx(Tip, {
|
|
1899
|
+
content: /* @__PURE__ */ jsxs("span", {
|
|
1900
|
+
className: "flex flex-col gap-0.5",
|
|
1901
|
+
children: [
|
|
1902
|
+
/* @__PURE__ */ jsx("span", {
|
|
1903
|
+
className: "font-medium",
|
|
1904
|
+
children: triggerMeta?.displayName ?? "No trigger"
|
|
1905
|
+
}),
|
|
1906
|
+
triggerMeta ? /* @__PURE__ */ jsx("span", {
|
|
1907
|
+
className: "text-muted-foreground",
|
|
1908
|
+
children: triggerMeta.subtitle
|
|
1909
|
+
}) : null,
|
|
1910
|
+
/* @__PURE__ */ jsx("span", {
|
|
1911
|
+
className: "mt-1",
|
|
1912
|
+
children: latest ? `Last fired ${formatWhen(latest.startedAt)}` : "Not fired yet"
|
|
1913
|
+
})
|
|
1914
|
+
]
|
|
1915
|
+
}),
|
|
1916
|
+
children: /* @__PURE__ */ jsxs(Mark, {
|
|
1917
|
+
label: `Trigger: ${props.triggerText}`,
|
|
1918
|
+
onOpen: props.onOpen,
|
|
1919
|
+
className: `flex shrink-0 items-center gap-1.5 rounded-full bg-card font-medium text-foreground ring-[1.5px] ${g.pill} ${latest ? RING$1.ok : RING$1.idle}`,
|
|
1920
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
1921
|
+
className: `flex items-center justify-center rounded-full dark:bg-white ${g.pillLogo}`,
|
|
1922
|
+
children: trigger ? /* @__PURE__ */ jsx(BlockLogo, {
|
|
1923
|
+
bare: true,
|
|
1924
|
+
block: trigger,
|
|
1925
|
+
size: g.logo - 2
|
|
1926
|
+
}) : null
|
|
1927
|
+
}), props.triggerText]
|
|
1928
|
+
})
|
|
1929
|
+
})
|
|
1930
|
+
}), layout.nodes.length > 0 ? /* @__PURE__ */ jsxs("ol", {
|
|
1931
|
+
className: `relative shrink-0 ${stacked ? "" : "-ml-px"}`,
|
|
1932
|
+
style: {
|
|
1933
|
+
width,
|
|
1934
|
+
height,
|
|
1935
|
+
marginTop: stacked ? STACK_GAP : 0
|
|
1936
|
+
},
|
|
1937
|
+
"aria-label": layout.nodes.map((node) => {
|
|
1938
|
+
const status = records.get(node.step.key)?.status;
|
|
1939
|
+
const label = node.step.name || node.step.key;
|
|
1940
|
+
return status ? `${label}: ${status.toLowerCase()}` : label;
|
|
1941
|
+
}).join(", "),
|
|
1942
|
+
children: [
|
|
1943
|
+
/* @__PURE__ */ jsx("svg", {
|
|
1944
|
+
"aria-hidden": true,
|
|
1945
|
+
className: "absolute inset-0 overflow-visible",
|
|
1946
|
+
width,
|
|
1947
|
+
height,
|
|
1948
|
+
children: routes.map(({ key, edge, route, tone }) => /* @__PURE__ */ jsx("path", {
|
|
1949
|
+
d: roundedPath(route.points),
|
|
1950
|
+
fill: "none",
|
|
1951
|
+
stroke: "currentColor",
|
|
1952
|
+
strokeWidth: 2,
|
|
1953
|
+
strokeDasharray: edge.port === "error" ? "3 3" : void 0,
|
|
1954
|
+
className: STROKE[tone]
|
|
1955
|
+
}, key))
|
|
1956
|
+
}),
|
|
1957
|
+
routes.map(({ key, edge, route }) => PORT_PILL[edge.port] ? /* @__PURE__ */ jsx("span", {
|
|
1958
|
+
"aria-hidden": true,
|
|
1959
|
+
className: "pointer-events-none absolute z-[1] -translate-x-1/2 -translate-y-1/2 rounded-full bg-card",
|
|
1960
|
+
style: {
|
|
1961
|
+
left: route.label.x,
|
|
1962
|
+
top: route.label.y
|
|
1963
|
+
},
|
|
1964
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
1965
|
+
className: `block rounded-full px-1.5 font-medium leading-4 ring-1 ring-inset ${g.portText} ${PORT_PILL[edge.port]}`,
|
|
1966
|
+
children: edge.port
|
|
1967
|
+
})
|
|
1968
|
+
}, key) : null),
|
|
1969
|
+
layout.nodes.map((node) => {
|
|
1970
|
+
const record = records.get(node.step.key);
|
|
1971
|
+
const skipped = record?.status === "SKIPPED";
|
|
1972
|
+
const name = node.step.name || node.step.key;
|
|
1973
|
+
const { x, y } = spot(node.col, node.lane);
|
|
1974
|
+
const tip = /* @__PURE__ */ jsx(StepTip, {
|
|
1975
|
+
node,
|
|
1976
|
+
record,
|
|
1977
|
+
ran: Boolean(latest)
|
|
1978
|
+
});
|
|
1979
|
+
return /* @__PURE__ */ jsxs("li", { children: [/* @__PURE__ */ jsx("span", {
|
|
1980
|
+
className: "absolute",
|
|
1981
|
+
style: {
|
|
1982
|
+
left: x - g.r,
|
|
1983
|
+
top: y - g.r
|
|
1984
|
+
},
|
|
1985
|
+
children: /* @__PURE__ */ jsx(Tip, {
|
|
1986
|
+
content: tip,
|
|
1987
|
+
children: /* @__PURE__ */ jsx(Mark, {
|
|
1988
|
+
label: `${name}: ${record ? record.status.toLowerCase() : "not run"}`,
|
|
1989
|
+
onOpen: props.onOpen,
|
|
1990
|
+
className: `flex items-center justify-center rounded-full bg-card transition-shadow ${g.circle} ${skipped ? "border-[1.5px] border-dashed border-foreground/40" : `ring-[1.5px] hover:ring-[3px] dark:bg-white ${RING$1[toneOfStep(node.step.key)]}`}`,
|
|
1991
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
1992
|
+
className: skipped ? "flex opacity-40" : "flex",
|
|
1993
|
+
children: /* @__PURE__ */ jsx(BlockLogo, {
|
|
1994
|
+
bare: true,
|
|
1995
|
+
block: stepBlock(node.step),
|
|
1996
|
+
size: g.logo
|
|
1997
|
+
})
|
|
1998
|
+
})
|
|
1999
|
+
})
|
|
2000
|
+
})
|
|
2001
|
+
}), g.label ? /* @__PURE__ */ jsxs("span", {
|
|
2002
|
+
"aria-hidden": true,
|
|
2003
|
+
className: "pointer-events-none absolute flex flex-col items-center text-center",
|
|
2004
|
+
style: {
|
|
2005
|
+
...labelBox(x),
|
|
2006
|
+
top: y + g.r + 6
|
|
2007
|
+
},
|
|
2008
|
+
children: [/* @__PURE__ */ jsx(Tip, {
|
|
2009
|
+
content: tip,
|
|
2010
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
2011
|
+
className: `pointer-events-auto line-clamp-2 max-w-full font-medium text-foreground [overflow-wrap:anywhere] ${g.nameText}`,
|
|
2012
|
+
children: name
|
|
2013
|
+
})
|
|
2014
|
+
}), g.subtitle ? /* @__PURE__ */ jsx("span", {
|
|
2015
|
+
className: "max-w-full truncate text-xs text-muted-foreground",
|
|
2016
|
+
children: blockMeta(stepBlock(node.step)).displayName
|
|
2017
|
+
}) : null]
|
|
2018
|
+
}) : null] }, node.step.id);
|
|
2019
|
+
})
|
|
2020
|
+
]
|
|
2021
|
+
}) : null]
|
|
2022
|
+
})
|
|
2023
|
+
});
|
|
1209
2024
|
}
|
|
1210
2025
|
//#endregion
|
|
1211
2026
|
//#region editors/workflow-studio/components/WorkflowBoard.tsx
|
|
2027
|
+
function CollapsedChain(props) {
|
|
2028
|
+
const trigger = props.state.trigger ? triggerBlock(props.state.trigger) : null;
|
|
2029
|
+
const links = workflowLinks({
|
|
2030
|
+
triggerId: props.state.trigger?.id,
|
|
2031
|
+
steps: props.state.steps,
|
|
2032
|
+
edges: props.state.edges
|
|
2033
|
+
}, props.latest);
|
|
2034
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
2035
|
+
className: "flex min-w-0 items-center",
|
|
2036
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
2037
|
+
title: props.triggerText,
|
|
2038
|
+
className: `flex h-6 max-w-full shrink-0 items-center gap-1.5 rounded-full bg-card pl-0.5 pr-2.5 text-[12px] font-medium text-foreground ring-[1.5px] ${props.latest ? "ring-wf-ok" : "ring-foreground/15 dark:ring-foreground/30"}`,
|
|
2039
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
2040
|
+
className: "flex h-5 w-5 shrink-0 items-center justify-center rounded-full dark:bg-white",
|
|
2041
|
+
children: trigger ? /* @__PURE__ */ jsx(BlockLogo, {
|
|
2042
|
+
bare: true,
|
|
2043
|
+
block: trigger,
|
|
2044
|
+
size: 12
|
|
2045
|
+
}) : null
|
|
2046
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
2047
|
+
className: "truncate",
|
|
2048
|
+
children: props.triggerText
|
|
2049
|
+
})]
|
|
2050
|
+
}), links.length > 0 ? /* @__PURE__ */ jsxs("span", {
|
|
2051
|
+
className: "flex min-w-0 shrink-[100] items-center",
|
|
2052
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
2053
|
+
"aria-hidden": true,
|
|
2054
|
+
className: "h-0.5 w-3 shrink-0 bg-foreground/15 dark:bg-foreground/30"
|
|
2055
|
+
}), /* @__PURE__ */ jsx(ScrollFade, {
|
|
2056
|
+
clip: true,
|
|
2057
|
+
className: "-my-1 min-w-0 py-1 pl-0.5",
|
|
2058
|
+
children: /* @__PURE__ */ jsx(MiniChain, { links })
|
|
2059
|
+
})]
|
|
2060
|
+
}) : null]
|
|
2061
|
+
});
|
|
2062
|
+
}
|
|
1212
2063
|
function RowToggle(props) {
|
|
1213
2064
|
const [, dispatch] = useDispatch(props.document);
|
|
1214
2065
|
const state = props.document.state.global;
|
|
@@ -1228,44 +2079,24 @@ function summary(rows) {
|
|
|
1228
2079
|
}
|
|
1229
2080
|
function WorkflowBoard(props) {
|
|
1230
2081
|
usePieceLogos();
|
|
2082
|
+
const { isCollapsed, toggle } = useCollapsed();
|
|
1231
2083
|
const documents = useWorkflowDocumentsInSelectedDrive() ?? [];
|
|
1232
2084
|
const runs = props.runs ?? [];
|
|
2085
|
+
const positions = new Map(props.order.map((id, i) => [id, i]));
|
|
2086
|
+
const position = (id) => positions.get(id) ?? positions.size;
|
|
1233
2087
|
const rows = documents.map((document) => {
|
|
1234
2088
|
const state = document.state.global;
|
|
1235
2089
|
const workflowRuns = runs.filter((run) => run.workflowId === document.header.id);
|
|
1236
|
-
const latest = workflowRuns.at(0);
|
|
1237
|
-
const statusByKey = new Map((latest?.steps ?? []).map((step) => [step.stepKey, step.status]));
|
|
1238
|
-
const outline = stepOutline({
|
|
1239
|
-
triggerId: state.trigger?.id,
|
|
1240
|
-
steps: state.steps,
|
|
1241
|
-
edges: state.edges
|
|
1242
|
-
});
|
|
1243
|
-
const links = [...state.trigger ? [{
|
|
1244
|
-
id: state.trigger.id,
|
|
1245
|
-
block: triggerBlock(state.trigger),
|
|
1246
|
-
label: "Trigger",
|
|
1247
|
-
status: latest ? "SUCCEEDED" : void 0
|
|
1248
|
-
}] : [], ...outline.rows.map((row) => ({
|
|
1249
|
-
id: row.step.id,
|
|
1250
|
-
block: stepBlock(row.step),
|
|
1251
|
-
label: row.step.name || row.step.key,
|
|
1252
|
-
status: statusByKey.get(row.step.key)
|
|
1253
|
-
}))];
|
|
1254
2090
|
return {
|
|
1255
2091
|
document,
|
|
1256
2092
|
id: document.header.id,
|
|
1257
2093
|
name: state.name || document.header.name || "Untitled workflow",
|
|
2094
|
+
description: state.description,
|
|
1258
2095
|
status: state.status,
|
|
1259
2096
|
trigger: describeTrigger(state.trigger),
|
|
1260
|
-
links,
|
|
1261
2097
|
runs: workflowRuns
|
|
1262
2098
|
};
|
|
1263
|
-
}).sort((a, b) =>
|
|
1264
|
-
const at = a.runs[0]?.startedAt ?? "";
|
|
1265
|
-
const bt = b.runs[0]?.startedAt ?? "";
|
|
1266
|
-
if (at !== bt) return bt.localeCompare(at);
|
|
1267
|
-
return a.name.localeCompare(b.name);
|
|
1268
|
-
});
|
|
2099
|
+
}).sort((a, b) => position(a.id) - position(b.id));
|
|
1269
2100
|
return /* @__PURE__ */ jsxs("section", {
|
|
1270
2101
|
className: "mb-10",
|
|
1271
2102
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
@@ -1296,68 +2127,117 @@ function WorkflowBoard(props) {
|
|
|
1296
2127
|
})]
|
|
1297
2128
|
}) : /* @__PURE__ */ jsx("ul", {
|
|
1298
2129
|
"aria-label": "Workflows",
|
|
1299
|
-
className: "
|
|
2130
|
+
className: "rounded-xl border border-solid border-foreground/10 bg-card",
|
|
1300
2131
|
children: rows.map((row) => {
|
|
1301
2132
|
const latest = row.runs.at(0);
|
|
1302
2133
|
const latestTone = toneOf(RUN_TONE, latest?.status);
|
|
1303
2134
|
const health = workflowHealth(row.status, latest?.status, Boolean(row.document.state.global.published));
|
|
2135
|
+
const collapsed = isCollapsed(row.id);
|
|
1304
2136
|
return /* @__PURE__ */ jsxs("li", {
|
|
1305
|
-
className: "
|
|
1306
|
-
children: [/* @__PURE__ */ jsxs("
|
|
2137
|
+
className: "group/row border-b border-solid border-foreground/10 first:rounded-t-xl last:rounded-b-xl last:border-b-0",
|
|
2138
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
2139
|
+
className: `flex items-start transition-colors group-first/row:rounded-t-xl has-[[data-row-header]:hover]:bg-accent/40 has-[[data-row-header]:focus-visible]:bg-accent/40 ${collapsed ? "group-last/row:rounded-b-xl" : ""}`,
|
|
2140
|
+
children: [/* @__PURE__ */ jsxs("button", {
|
|
2141
|
+
type: "button",
|
|
2142
|
+
"data-row-header": true,
|
|
2143
|
+
"aria-expanded": !collapsed,
|
|
2144
|
+
"aria-label": `${collapsed ? "Expand" : "Collapse"} ${row.name}`,
|
|
2145
|
+
className: "group/header @container flex min-w-0 flex-1 cursor-pointer items-start gap-1 py-4 pl-2 pr-5 text-left focus-visible:outline-none",
|
|
2146
|
+
onClick: () => toggle(row.id),
|
|
2147
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
2148
|
+
"aria-hidden": true,
|
|
2149
|
+
className: "flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors group-hover/header:bg-accent group-hover/header:text-foreground group-focus-visible/header:bg-accent group-focus-visible/header:text-foreground",
|
|
2150
|
+
children: /* @__PURE__ */ jsx(Icon, {
|
|
2151
|
+
name: "chevron",
|
|
2152
|
+
className: `h-3.5 w-3.5 transition-transform ${collapsed ? "" : "rotate-90"}`
|
|
2153
|
+
})
|
|
2154
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
2155
|
+
className: `grid w-full grid-rows-[1.5rem] items-center gap-x-6 ${collapsed ? "grid-cols-[minmax(10rem,2fr)_minmax(0,3fr)] @[44rem]:grid-cols-[minmax(10rem,2fr)_minmax(0,3fr)_auto] @[60rem]:grid-cols-[minmax(10rem,2fr)_minmax(0,3fr)_minmax(0,10rem)_auto]" : "grid-cols-[minmax(0,1fr)_auto] md:grid-cols-[minmax(0,1fr)_minmax(0,10rem)_auto]"}`,
|
|
2156
|
+
children: [
|
|
2157
|
+
/* @__PURE__ */ jsxs("span", {
|
|
2158
|
+
className: "flex min-w-0 items-center gap-2",
|
|
2159
|
+
children: [
|
|
2160
|
+
/* @__PURE__ */ jsx("span", {
|
|
2161
|
+
title: health.label,
|
|
2162
|
+
className: "flex",
|
|
2163
|
+
children: /* @__PURE__ */ jsx(StatusDot, {
|
|
2164
|
+
tone: health.tone,
|
|
2165
|
+
hollow: health.hollow
|
|
2166
|
+
})
|
|
2167
|
+
}),
|
|
2168
|
+
/* @__PURE__ */ jsx("span", {
|
|
2169
|
+
className: "min-w-0 truncate text-[15px] font-semibold text-foreground",
|
|
2170
|
+
children: row.name
|
|
2171
|
+
}),
|
|
2172
|
+
row.status !== "ENABLED" ? /* @__PURE__ */ jsx("span", {
|
|
2173
|
+
className: "shrink-0 rounded-full bg-muted px-2 py-0.5 text-[11px] text-muted-foreground",
|
|
2174
|
+
children: statusLabel(row.status)
|
|
2175
|
+
}) : null
|
|
2176
|
+
]
|
|
2177
|
+
}),
|
|
2178
|
+
collapsed ? /* @__PURE__ */ jsx(CollapsedChain, {
|
|
2179
|
+
state: row.document.state.global,
|
|
2180
|
+
triggerText: row.trigger,
|
|
2181
|
+
latest
|
|
2182
|
+
}) : null,
|
|
2183
|
+
/* @__PURE__ */ jsx("span", {
|
|
2184
|
+
className: `hidden text-[13px] ${collapsed ? "@[60rem]:block" : "md:block"}`,
|
|
2185
|
+
title: latest ? formatAbsolute(latest.startedAt) : void 0,
|
|
2186
|
+
children: latest ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("span", {
|
|
2187
|
+
className: `font-medium ${latestTone === "fail" ? "text-wf-fail" : latestTone === "ok" ? "text-wf-ok" : "text-foreground"}`,
|
|
2188
|
+
children: statusLabel(latest.status)
|
|
2189
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
2190
|
+
className: "ml-1.5 text-xs text-muted-foreground",
|
|
2191
|
+
children: formatWhen(latest.startedAt)
|
|
2192
|
+
})] }) : /* @__PURE__ */ jsx("span", {
|
|
2193
|
+
className: "text-muted-foreground",
|
|
2194
|
+
children: "Not run yet"
|
|
2195
|
+
})
|
|
2196
|
+
}),
|
|
2197
|
+
collapsed ? /* @__PURE__ */ jsx("span", {
|
|
2198
|
+
className: "hidden @[44rem]:block",
|
|
2199
|
+
children: /* @__PURE__ */ jsx(RunStrip, {
|
|
2200
|
+
centered: true,
|
|
2201
|
+
runs: row.runs
|
|
2202
|
+
})
|
|
2203
|
+
}) : /* @__PURE__ */ jsx(RunStrip, {
|
|
2204
|
+
centered: true,
|
|
2205
|
+
runs: row.runs
|
|
2206
|
+
})
|
|
2207
|
+
]
|
|
2208
|
+
})]
|
|
2209
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
2210
|
+
className: "mt-4 flex h-6 shrink-0 items-center gap-1 pr-3",
|
|
2211
|
+
children: [/* @__PURE__ */ jsx(RowToggle, { document: row.document }), /* @__PURE__ */ jsx(WorkflowMenu, { document: row.document })]
|
|
2212
|
+
})]
|
|
2213
|
+
}), collapsed ? null : /* @__PURE__ */ jsxs("button", {
|
|
1307
2214
|
type: "button",
|
|
1308
|
-
|
|
2215
|
+
"aria-label": `Open ${row.name}`,
|
|
2216
|
+
className: "group/content relative flex w-full cursor-pointer flex-col gap-3 pb-4 pl-9 pr-5 pt-1 text-left transition-colors hover:bg-accent/50 focus-visible:bg-accent/50 focus-visible:outline-none group-last/row:rounded-b-xl",
|
|
1309
2217
|
onClick: () => props.onOpen(row.id),
|
|
1310
2218
|
children: [
|
|
1311
2219
|
/* @__PURE__ */ jsxs("span", {
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
title: health.label,
|
|
1318
|
-
className: "flex",
|
|
1319
|
-
children: /* @__PURE__ */ jsx(StatusDot, {
|
|
1320
|
-
tone: health.tone,
|
|
1321
|
-
hollow: health.hollow
|
|
1322
|
-
})
|
|
1323
|
-
}),
|
|
1324
|
-
/* @__PURE__ */ jsx("span", {
|
|
1325
|
-
className: "truncate text-[15px] font-semibold text-foreground",
|
|
1326
|
-
children: row.name
|
|
1327
|
-
}),
|
|
1328
|
-
row.status !== "ENABLED" ? /* @__PURE__ */ jsx("span", {
|
|
1329
|
-
className: "shrink-0 rounded-full bg-muted px-2 py-0.5 text-[11px] text-muted-foreground",
|
|
1330
|
-
children: statusLabel(row.status)
|
|
1331
|
-
}) : null
|
|
1332
|
-
]
|
|
1333
|
-
}), /* @__PURE__ */ jsx("span", {
|
|
1334
|
-
className: "mt-0.5 block truncate pl-4 text-[13px] text-muted-foreground",
|
|
1335
|
-
children: row.trigger
|
|
2220
|
+
"aria-hidden": true,
|
|
2221
|
+
className: "pointer-events-none absolute right-5 top-1 flex items-center gap-1 text-xs font-medium text-muted-foreground opacity-0 transition-opacity group-hover/content:opacity-100 group-focus-visible/content:opacity-100",
|
|
2222
|
+
children: ["Open workflow", /* @__PURE__ */ jsx(Icon, {
|
|
2223
|
+
name: "arrowRight",
|
|
2224
|
+
className: "h-3.5 w-3.5"
|
|
1336
2225
|
})]
|
|
1337
2226
|
}),
|
|
1338
|
-
/* @__PURE__ */ jsx("span", {
|
|
1339
|
-
className: "
|
|
1340
|
-
children:
|
|
1341
|
-
}),
|
|
1342
|
-
/* @__PURE__ */ jsx(
|
|
1343
|
-
className: "
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
className: "block text-xs text-muted-foreground",
|
|
1350
|
-
children: formatWhen(latest.startedAt)
|
|
1351
|
-
})] }) : /* @__PURE__ */ jsx("span", {
|
|
1352
|
-
className: "text-muted-foreground",
|
|
1353
|
-
children: "Not run yet"
|
|
2227
|
+
row.description ? /* @__PURE__ */ jsx("span", {
|
|
2228
|
+
className: "max-w-prose pl-4 text-[13px] leading-5 text-muted-foreground",
|
|
2229
|
+
children: row.description
|
|
2230
|
+
}) : null,
|
|
2231
|
+
/* @__PURE__ */ jsx(ScrollFade, {
|
|
2232
|
+
className: "max-w-full py-1 pl-4 pr-1",
|
|
2233
|
+
children: /* @__PURE__ */ jsx(WorkflowGraph, {
|
|
2234
|
+
fit: true,
|
|
2235
|
+
state: row.document.state.global,
|
|
2236
|
+
triggerText: row.trigger,
|
|
2237
|
+
latest
|
|
1354
2238
|
})
|
|
1355
|
-
})
|
|
1356
|
-
/* @__PURE__ */ jsx(RunStrip, { runs: row.runs })
|
|
2239
|
+
})
|
|
1357
2240
|
]
|
|
1358
|
-
}), /* @__PURE__ */ jsxs("span", {
|
|
1359
|
-
className: "flex shrink-0 items-center gap-1 pr-3",
|
|
1360
|
-
children: [/* @__PURE__ */ jsx(RowToggle, { document: row.document }), /* @__PURE__ */ jsx(WorkflowMenu, { document: row.document })]
|
|
1361
2241
|
})]
|
|
1362
2242
|
}, row.id);
|
|
1363
2243
|
})
|
|
@@ -1422,20 +2302,6 @@ function TrackStop(props) {
|
|
|
1422
2302
|
]
|
|
1423
2303
|
});
|
|
1424
2304
|
}
|
|
1425
|
-
function Track(props) {
|
|
1426
|
-
const tones = props.stops.map((stop) => stop.status ? toneOf(STEP_TONE, stop.status) : "idle");
|
|
1427
|
-
return /* @__PURE__ */ jsx("ol", {
|
|
1428
|
-
className: "-mx-6 flex overflow-x-auto px-6 py-1.5",
|
|
1429
|
-
children: props.stops.map((stop, index) => /* @__PURE__ */ jsx(TrackStop, {
|
|
1430
|
-
stop,
|
|
1431
|
-
first: index === 0,
|
|
1432
|
-
last: index === props.stops.length - 1,
|
|
1433
|
-
inbound: tones[index],
|
|
1434
|
-
outbound: tones[index + 1] ?? "idle",
|
|
1435
|
-
onClick: props.onOpenEditor
|
|
1436
|
-
}, stop.id))
|
|
1437
|
-
});
|
|
1438
|
-
}
|
|
1439
2305
|
function WorkflowSteps(props) {
|
|
1440
2306
|
const { state } = props;
|
|
1441
2307
|
usePieceLogos();
|
|
@@ -1475,15 +2341,6 @@ function WorkflowSteps(props) {
|
|
|
1475
2341
|
]
|
|
1476
2342
|
})
|
|
1477
2343
|
});
|
|
1478
|
-
const trigger = state.trigger ? triggerBlock(state.trigger) : null;
|
|
1479
|
-
const triggerMeta = trigger ? blockMeta(trigger) : null;
|
|
1480
|
-
const stops = [...state.trigger && trigger && triggerMeta ? [{
|
|
1481
|
-
id: state.trigger.id,
|
|
1482
|
-
title: triggerMeta.displayName,
|
|
1483
|
-
subtitle: "Trigger",
|
|
1484
|
-
block: trigger,
|
|
1485
|
-
status: props.latestRun ? "SUCCEEDED" : void 0
|
|
1486
|
-
}] : [], ...outline.rows.map((row) => stopFor(row.step, row.port))];
|
|
1487
2344
|
return /* @__PURE__ */ jsxs("section", {
|
|
1488
2345
|
className: "mt-8 border-t border-solid border-border pt-6",
|
|
1489
2346
|
children: [
|
|
@@ -1501,9 +2358,16 @@ function WorkflowSteps(props) {
|
|
|
1501
2358
|
className: "mb-3 text-xs text-wf-warn",
|
|
1502
2359
|
children: "No trigger set, so this workflow never starts on its own."
|
|
1503
2360
|
}) : null,
|
|
1504
|
-
/* @__PURE__ */ jsx(
|
|
1505
|
-
|
|
1506
|
-
|
|
2361
|
+
/* @__PURE__ */ jsx(ScrollFade, {
|
|
2362
|
+
className: "-mx-1 px-1 py-1.5",
|
|
2363
|
+
children: /* @__PURE__ */ jsx(WorkflowGraph, {
|
|
2364
|
+
state,
|
|
2365
|
+
triggerText: describeTrigger(state.trigger),
|
|
2366
|
+
latest: props.latestRun,
|
|
2367
|
+
onOpen: props.onOpenEditor,
|
|
2368
|
+
size: "md",
|
|
2369
|
+
fit: true
|
|
2370
|
+
})
|
|
1507
2371
|
}),
|
|
1508
2372
|
outline.orphans.length > 0 ? /* @__PURE__ */ jsxs("div", {
|
|
1509
2373
|
className: "mt-5",
|
|
@@ -1613,7 +2477,10 @@ function WorkflowHeader(props) {
|
|
|
1613
2477
|
}),
|
|
1614
2478
|
/* @__PURE__ */ jsx(Fact, {
|
|
1615
2479
|
label: "Recent runs",
|
|
1616
|
-
children: stats.total > 0 ? /* @__PURE__ */ jsx(RunStrip, {
|
|
2480
|
+
children: stats.total > 0 ? /* @__PURE__ */ jsx(RunStrip, {
|
|
2481
|
+
centered: true,
|
|
2482
|
+
runs: props.runs ?? []
|
|
2483
|
+
}) : /* @__PURE__ */ jsx("span", {
|
|
1617
2484
|
className: "text-muted-foreground",
|
|
1618
2485
|
children: "None yet"
|
|
1619
2486
|
})
|
|
@@ -1648,36 +2515,48 @@ function WorkflowStudio(props) {
|
|
|
1648
2515
|
}
|
|
1649
2516
|
function Studio(props) {
|
|
1650
2517
|
const { fireWorkflow } = useRuntimeActions();
|
|
1651
|
-
const [drive] = useSelectedDrive();
|
|
2518
|
+
const [drive, dispatchDrive] = useSelectedDrive();
|
|
2519
|
+
const nodes = useNodesInSelectedDrive() ?? [];
|
|
1652
2520
|
const fileNodes = useFileNodesInSelectedDrive() ?? [];
|
|
2521
|
+
const workflowDocuments = useWorkflowDocumentsInSelectedDrive() ?? [];
|
|
1653
2522
|
const selectedNode = useSelectedNode();
|
|
1654
2523
|
const selectedNodeId = selectedNode?.id;
|
|
1655
2524
|
const toast = usePHToast();
|
|
1656
2525
|
const [selectedId, select] = useHashSelection();
|
|
1657
2526
|
const [creating, setCreating] = useState(false);
|
|
1658
2527
|
const driveId = drive.header.id;
|
|
1659
|
-
const
|
|
2528
|
+
const orderedWorkflows = orderWorkflows(fileNodes.filter((node) => node.documentType === WORKFLOW_TYPE), nodes);
|
|
2529
|
+
const workflows = orderedWorkflows.map((item) => item.node);
|
|
1660
2530
|
const connections = fileNodes.filter((node) => node.documentType === CONNECTION_TYPE);
|
|
1661
2531
|
const editorOpen = Boolean(props.children && selectedNodeId);
|
|
1662
2532
|
const create = (documentType, baseName, count) => {
|
|
1663
2533
|
if (creating) return;
|
|
1664
2534
|
setCreating(true);
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
2535
|
+
const name = `${baseName} ${count + 1}`;
|
|
2536
|
+
(documentType === WORKFLOW_TYPE ? addFolder(driveId, homeFolderName(nextKey(orderedWorkflows), name)).then((folder) => addDocument(driveId, name, documentType, folder.id).catch(async (error) => {
|
|
2537
|
+
await deleteNode(driveId, folder.id).catch(() => void 0);
|
|
2538
|
+
throw error;
|
|
2539
|
+
})) : addDocument(driveId, name, documentType)).then((node) => go(node.id, node.id)).catch((error) => {
|
|
1669
2540
|
toast?.(error instanceof Error ? error.message : `Failed to create ${baseName}`, { type: "error" });
|
|
1670
2541
|
}).finally(() => setCreating(false));
|
|
1671
2542
|
};
|
|
1672
|
-
const
|
|
1673
|
-
|
|
1674
|
-
|
|
2543
|
+
const reorder = (from, to) => {
|
|
2544
|
+
const names = new Map(workflowDocuments.map((doc) => [doc.header.id, doc.state.global.name]));
|
|
2545
|
+
const actions = reorderActions(orderedWorkflows, from, to, names);
|
|
2546
|
+
if (actions.length === 0) return;
|
|
2547
|
+
dispatchDrive(actions, (errors) => toast?.(errors[0]?.message ?? "Failed to reorder workflows", { type: "error" }));
|
|
2548
|
+
};
|
|
2549
|
+
const go = (id, editor) => {
|
|
2550
|
+
const before = window.location.pathname;
|
|
2551
|
+
if ((editor ?? null) !== (selectedNodeId ?? null)) setSelectedNode(editor);
|
|
2552
|
+
select(id, { replace: window.location.pathname !== before });
|
|
1675
2553
|
};
|
|
2554
|
+
const showRuns = (node) => go(node?.id);
|
|
1676
2555
|
const liveTarget = workflows.find((node) => node.id === selectedId) ?? null;
|
|
1677
2556
|
const connectionSelected = connections.some((node) => node.id === selectedId);
|
|
1678
2557
|
const wasEditing = useRef(editorOpen);
|
|
1679
2558
|
useEffect(() => {
|
|
1680
|
-
if (wasEditing.current && !editorOpen && connectionSelected) select(void 0);
|
|
2559
|
+
if (wasEditing.current && !editorOpen && connectionSelected) select(void 0, { replace: true });
|
|
1681
2560
|
wasEditing.current = editorOpen;
|
|
1682
2561
|
}, [
|
|
1683
2562
|
editorOpen,
|
|
@@ -1686,7 +2565,7 @@ function Studio(props) {
|
|
|
1686
2565
|
]);
|
|
1687
2566
|
const selectionExists = fileNodes.some((node) => node.id === selectedId);
|
|
1688
2567
|
useEffect(() => {
|
|
1689
|
-
if (selectedId && fileNodes.length > 0 && !selectionExists) select(void 0);
|
|
2568
|
+
if (selectedId && fileNodes.length > 0 && !selectionExists) select(void 0, { replace: true });
|
|
1690
2569
|
}, [
|
|
1691
2570
|
fileNodes.length,
|
|
1692
2571
|
select,
|
|
@@ -1712,20 +2591,15 @@ function Studio(props) {
|
|
|
1712
2591
|
activeId: selectedId,
|
|
1713
2592
|
allRunsActive: !selectedId,
|
|
1714
2593
|
creating,
|
|
2594
|
+
onReorderWorkflow: reorder,
|
|
1715
2595
|
onShowAllRuns: () => showRuns(null),
|
|
1716
2596
|
onOpenWorkflow: (node) => showRuns(node),
|
|
1717
|
-
onEditWorkflow: (node) =>
|
|
1718
|
-
|
|
1719
|
-
setSelectedNode(node.id);
|
|
1720
|
-
},
|
|
1721
|
-
onOpenConnection: (node) => {
|
|
1722
|
-
select(node.id);
|
|
1723
|
-
setSelectedNode(node.id);
|
|
1724
|
-
},
|
|
2597
|
+
onEditWorkflow: (node) => go(node.id, node.id),
|
|
2598
|
+
onOpenConnection: (node) => go(node.id, node.id),
|
|
1725
2599
|
onCreateWorkflow: () => create(WORKFLOW_TYPE, "Workflow", workflows.length),
|
|
1726
2600
|
onCreateConnection: () => create(CONNECTION_TYPE, "Connection", connections.length)
|
|
1727
2601
|
}), /* @__PURE__ */ jsx("main", {
|
|
1728
|
-
className: "min-w-0 flex-1 overflow-y-auto",
|
|
2602
|
+
className: "relative min-w-0 flex-1 overflow-y-auto",
|
|
1729
2603
|
children: editorOpen ? /* @__PURE__ */ jsx("div", {
|
|
1730
2604
|
className: "flex h-full min-h-0 flex-col",
|
|
1731
2605
|
children: /* @__PURE__ */ jsx("div", {
|
|
@@ -1742,12 +2616,13 @@ function Studio(props) {
|
|
|
1742
2616
|
children: [liveTarget ? /* @__PURE__ */ jsx(WorkflowHeader, {
|
|
1743
2617
|
node: liveTarget,
|
|
1744
2618
|
runs,
|
|
1745
|
-
onEdit: () =>
|
|
1746
|
-
onDeleted: () => select(void 0)
|
|
2619
|
+
onEdit: () => go(liveTarget.id, liveTarget.id),
|
|
2620
|
+
onDeleted: () => select(void 0, { replace: true })
|
|
1747
2621
|
}, liveTarget.id) : /* @__PURE__ */ jsx(WorkflowBoard, {
|
|
1748
2622
|
runs,
|
|
2623
|
+
order: workflows.map((node) => node.id),
|
|
1749
2624
|
creating,
|
|
1750
|
-
onOpen: (workflowId) =>
|
|
2625
|
+
onOpen: (workflowId) => go(workflowId),
|
|
1751
2626
|
onCreate: () => create(WORKFLOW_TYPE, "Workflow", workflows.length)
|
|
1752
2627
|
}), /* @__PURE__ */ jsx(RunsView, {
|
|
1753
2628
|
title: liveTarget ? "Runs" : "Recent runs",
|
|
@@ -1787,4 +2662,4 @@ function Editor(props) {
|
|
|
1787
2662
|
//#endregion
|
|
1788
2663
|
export { Editor as default };
|
|
1789
2664
|
|
|
1790
|
-
//# sourceMappingURL=editor-
|
|
2665
|
+
//# sourceMappingURL=editor-DKpQGzMS.mjs.map
|