@antelopejs/dms-automation 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -22
- package/dist/cluster/bus.js +8 -6
- package/dist/cluster/bus.js.map +1 -1
- package/dist/cluster/leader.js.map +1 -1
- package/dist/data/procedures-query.d.ts +19 -0
- package/dist/data/procedures-query.js +105 -0
- package/dist/data/procedures-query.js.map +1 -0
- package/dist/data/procedures-table.d.ts +5 -20
- package/dist/data/procedures-table.js +10 -106
- package/dist/data/procedures-table.js.map +1 -1
- package/dist/data/runs-table.d.ts +3 -3
- package/dist/data/runs-table.js.map +1 -1
- package/dist/db/models/automation_template.model.d.ts +13 -13
- package/dist/db/models/automation_template.model.js +13 -14
- package/dist/db/models/automation_template.model.js.map +1 -1
- package/dist/db/models/procedure.model.d.ts +7 -5
- package/dist/db/models/procedure_run.model.d.ts +9 -6
- package/dist/db/models/procedure_run.model.js +8 -8
- package/dist/db/models/procedure_run.model.js.map +1 -1
- package/dist/db/models/stats.model.js.map +1 -1
- package/dist/db/models/type_switch.model.d.ts +7 -5
- package/dist/db/tables/procedure_run.table.d.ts +2 -1
- package/dist/db/tables/procedure_run.table.js.map +1 -1
- package/dist/implementations/dms-automation/index.d.ts +2 -2
- package/dist/implementations/dms-automation/index.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/pages/category.js.map +1 -1
- package/dist/pages/index.js.map +1 -1
- package/dist/pages/overview.js.map +1 -1
- package/dist/pages/procedures.js.map +1 -1
- package/dist/pages/runs.js.map +1 -1
- package/dist/pages/shared.js +1 -1
- package/dist/pages/shared.js.map +1 -1
- package/dist/realtime.d.ts +2 -1
- package/dist/realtime.js.map +1 -1
- package/dist/routes/action-types.d.ts +3 -2
- package/dist/routes/action-types.js.map +1 -1
- package/dist/routes/data-node-types.d.ts +1 -1
- package/dist/routes/deleteConfirm.js +4 -3
- package/dist/routes/deleteConfirm.js.map +1 -1
- package/dist/routes/graphSchema.d.ts +2 -1
- package/dist/routes/graphSchema.js +13 -10
- package/dist/routes/graphSchema.js.map +1 -1
- package/dist/routes/library.d.ts +12 -1
- package/dist/routes/library.js +38 -34
- package/dist/routes/library.js.map +1 -1
- package/dist/routes/procedureChecks.js +5 -5
- package/dist/routes/procedureChecks.js.map +1 -1
- package/dist/routes/procedureRuns.d.ts +3 -3
- package/dist/routes/procedureRuns.js +1 -1
- package/dist/routes/procedureRuns.js.map +1 -1
- package/dist/routes/procedureSchemas.d.ts +7 -6
- package/dist/routes/procedureSchemas.js +4 -2
- package/dist/routes/procedureSchemas.js.map +1 -1
- package/dist/routes/procedures.d.ts +15 -14
- package/dist/routes/procedures.js +2 -1
- package/dist/routes/procedures.js.map +1 -1
- package/dist/routes/requests.d.ts +12 -6
- package/dist/routes/requests.js +2 -1
- package/dist/routes/requests.js.map +1 -1
- package/dist/routes/runs.d.ts +9 -8
- package/dist/routes/runs.js +5 -3
- package/dist/routes/runs.js.map +1 -1
- package/dist/routes/stats.js.map +1 -1
- package/dist/routes/templates.d.ts +5 -4
- package/dist/routes/templates.js +2 -1
- package/dist/routes/templates.js.map +1 -1
- package/dist/routes/trigger-types.d.ts +3 -2
- package/dist/routes/trigger-types.js.map +1 -1
- package/dist/routes/typeConfigShared.d.ts +2 -1
- package/dist/routes/typeConfigShared.js.map +1 -1
- package/dist/routes/zodJson.d.ts +3 -0
- package/dist/routes/zodJson.js +21 -0
- package/dist/routes/zodJson.js.map +1 -0
- package/dist/runtime/armErrors.d.ts +0 -1
- package/dist/runtime/armErrors.js +5 -12
- package/dist/runtime/armErrors.js.map +1 -1
- package/dist/runtime/boundRunLog.d.ts +7 -5
- package/dist/runtime/boundRunLog.js +24 -20
- package/dist/runtime/boundRunLog.js.map +1 -1
- package/dist/runtime/builtins/actions/http.d.ts +7 -3
- package/dist/runtime/builtins/actions/http.js +33 -22
- package/dist/runtime/builtins/actions/http.js.map +1 -1
- package/dist/runtime/builtins/actions/log.d.ts +5 -4
- package/dist/runtime/builtins/actions/log.js.map +1 -1
- package/dist/runtime/builtins/data/boolean.d.ts +2 -1
- package/dist/runtime/builtins/data/boolean.js +4 -5
- package/dist/runtime/builtins/data/boolean.js.map +1 -1
- package/dist/runtime/builtins/data/compare.js +8 -10
- package/dist/runtime/builtins/data/compare.js.map +1 -1
- package/dist/runtime/builtins/data/constant.js +1 -1
- package/dist/runtime/builtins/data/constant.js.map +1 -1
- package/dist/runtime/builtins/data/json.js +4 -5
- package/dist/runtime/builtins/data/json.js.map +1 -1
- package/dist/runtime/builtins/data/math.js +4 -4
- package/dist/runtime/builtins/data/math.js.map +1 -1
- package/dist/runtime/builtins/data/object.js +27 -27
- package/dist/runtime/builtins/data/object.js.map +1 -1
- package/dist/runtime/builtins/data/string.js +13 -18
- package/dist/runtime/builtins/data/string.js.map +1 -1
- package/dist/runtime/builtins/nodes/action.js +16 -5
- package/dist/runtime/builtins/nodes/action.js.map +1 -1
- package/dist/runtime/builtins/nodes/data.js +2 -2
- package/dist/runtime/builtins/nodes/data.js.map +1 -1
- package/dist/runtime/builtins/nodes/delay.js +2 -2
- package/dist/runtime/builtins/nodes/delay.js.map +1 -1
- package/dist/runtime/builtins/nodes/forRange.js +2 -2
- package/dist/runtime/builtins/nodes/forRange.js.map +1 -1
- package/dist/runtime/builtins/nodes/foreach.js +2 -2
- package/dist/runtime/builtins/nodes/foreach.js.map +1 -1
- package/dist/runtime/builtins/nodes/groupInput.js +2 -2
- package/dist/runtime/builtins/nodes/groupInput.js.map +1 -1
- package/dist/runtime/builtins/nodes/groupOutput.js +2 -2
- package/dist/runtime/builtins/nodes/groupOutput.js.map +1 -1
- package/dist/runtime/builtins/nodes/if.js +2 -2
- package/dist/runtime/builtins/nodes/if.js.map +1 -1
- package/dist/runtime/builtins/nodes/parallel.js +2 -2
- package/dist/runtime/builtins/nodes/parallel.js.map +1 -1
- package/dist/runtime/builtins/nodes/retry.js +13 -5
- package/dist/runtime/builtins/nodes/retry.js.map +1 -1
- package/dist/runtime/builtins/nodes/setVariable.js +2 -2
- package/dist/runtime/builtins/nodes/setVariable.js.map +1 -1
- package/dist/runtime/builtins/nodes/switch.js +8 -3
- package/dist/runtime/builtins/nodes/switch.js.map +1 -1
- package/dist/runtime/builtins/nodes/trigger.js +2 -2
- package/dist/runtime/builtins/nodes/trigger.js.map +1 -1
- package/dist/runtime/builtins/nodes/tryCatch.js +2 -2
- package/dist/runtime/builtins/nodes/tryCatch.js.map +1 -1
- package/dist/runtime/builtins/triggers/cron.d.ts +4 -3
- package/dist/runtime/builtins/triggers/cron.js +5 -7
- package/dist/runtime/builtins/triggers/cron.js.map +1 -1
- package/dist/runtime/builtins/triggers/webhook.d.ts +11 -7
- package/dist/runtime/builtins/triggers/webhook.js +15 -12
- package/dist/runtime/builtins/triggers/webhook.js.map +1 -1
- package/dist/runtime/declaredProcedures.d.ts +2 -2
- package/dist/runtime/declaredProcedures.js +3 -2
- package/dist/runtime/declaredProcedures.js.map +1 -1
- package/dist/runtime/describe.d.ts +3 -1
- package/dist/runtime/describe.js +14 -13
- package/dist/runtime/describe.js.map +1 -1
- package/dist/runtime/executor.d.ts +2 -1
- package/dist/runtime/executor.js +18 -13
- package/dist/runtime/executor.js.map +1 -1
- package/dist/runtime/flatten.d.ts +1 -1
- package/dist/runtime/flatten.js +1 -1
- package/dist/runtime/flatten.js.map +1 -1
- package/dist/runtime/graphIssues.d.ts +2 -2
- package/dist/runtime/graphIssues.js +39 -32
- package/dist/runtime/graphIssues.js.map +1 -1
- package/dist/runtime/graphVersion.d.ts +1 -1
- package/dist/runtime/graphVersion.js +4 -3
- package/dist/runtime/graphVersion.js.map +1 -1
- package/dist/runtime/nodeKinds.d.ts +6 -5
- package/dist/runtime/nodeKinds.js.map +1 -1
- package/dist/runtime/reconcile.d.ts +3 -0
- package/dist/runtime/reconcile.js +178 -0
- package/dist/runtime/reconcile.js.map +1 -0
- package/dist/runtime/registry.d.ts +3 -3
- package/dist/runtime/resolveInputs.d.ts +13 -8
- package/dist/runtime/resolveInputs.js +18 -18
- package/dist/runtime/resolveInputs.js.map +1 -1
- package/dist/runtime/resolveSubgraph.js +4 -5
- package/dist/runtime/resolveSubgraph.js.map +1 -1
- package/dist/runtime/retention.js.map +1 -1
- package/dist/runtime/runProcedure.d.ts +3 -2
- package/dist/runtime/runProcedure.js +2 -1
- package/dist/runtime/runProcedure.js.map +1 -1
- package/dist/runtime/schedule.js +3 -0
- package/dist/runtime/schedule.js.map +1 -1
- package/dist/runtime/schemaProperties.d.ts +3 -0
- package/dist/runtime/schemaProperties.js +7 -0
- package/dist/runtime/schemaProperties.js.map +1 -0
- package/dist/runtime/serialQueue.d.ts +1 -1
- package/dist/runtime/serialQueue.js +4 -4
- package/dist/runtime/serialQueue.js.map +1 -1
- package/dist/runtime/sideEffects.d.ts +2 -2
- package/dist/runtime/subscriptions.d.ts +6 -4
- package/dist/runtime/subscriptions.js +21 -180
- package/dist/runtime/subscriptions.js.map +1 -1
- package/dist/runtime/subwalk.js.map +1 -1
- package/dist/runtime/templateCacheState.d.ts +6 -0
- package/dist/runtime/templateCacheState.js +10 -0
- package/dist/runtime/templateCacheState.js.map +1 -0
- package/dist/runtime/templateUsages.js +4 -5
- package/dist/runtime/templateUsages.js.map +1 -1
- package/dist/runtime/topo.js +2 -4
- package/dist/runtime/topo.js.map +1 -1
- package/dist/runtime/trace.d.ts +5 -2
- package/dist/runtime/trace.js +27 -17
- package/dist/runtime/trace.js.map +1 -1
- package/dist/runtime/triggerHandles.d.ts +4 -3
- package/dist/runtime/triggerHandles.js +9 -1
- package/dist/runtime/triggerHandles.js.map +1 -1
- package/dist/runtime/typeOrigin.js +12 -1
- package/dist/runtime/typeOrigin.js.map +1 -1
- package/dist/runtime/validate.js.map +1 -1
- package/dist/runtime/validateTemplate.js.map +1 -1
- package/dist/runtime/withTimeout.js.map +1 -1
- package/dist/runtime/wording.js +12 -8
- package/dist/runtime/wording.js.map +1 -1
- package/dist/stats/health-banner.js.map +1 -1
- package/dist/stats/health.js.map +1 -1
- package/dist/stats/kpi.js +1 -1
- package/dist/stats/kpi.js.map +1 -1
- package/dist/stats/overview.js +2 -1
- package/dist/stats/overview.js.map +1 -1
- package/dist/types/dataValue.d.ts +7 -0
- package/dist/types/dataValue.js +56 -0
- package/dist/types/dataValue.js.map +1 -0
- package/dist/types/graph.d.ts +19 -13
- package/dist/types/graph.js +8 -0
- package/dist/types/graph.js.map +1 -1
- package/dist/types/guards.d.ts +8 -0
- package/dist/types/guards.js +35 -0
- package/dist/types/guards.js.map +1 -0
- package/dist/types/runLog.d.ts +8 -7
- package/dist/types/runLog.js.map +1 -1
- package/frontend-vue/app/build/components/editor/EditorBanners.vue +120 -0
- package/frontend-vue/app/build/components/editor/EditorChoiceModal.vue +44 -0
- package/frontend-vue/app/build/components/editor/EditorForkModal.vue +51 -0
- package/frontend-vue/app/build/components/editor/EditorHeader.vue +146 -0
- package/frontend-vue/app/build/components/editor/EditorSaveTemplateModal.vue +105 -0
- package/frontend-vue/app/build/components/editor/NodeInspectorDocs.vue +28 -0
- package/frontend-vue/app/build/components/editor/NodeInspectorRun.vue +48 -0
- package/frontend-vue/app/build/composables/editor/useBuilderMount.ts +129 -0
- package/frontend-vue/app/build/composables/editor/useBuilderSave.ts +256 -0
- package/frontend-vue/app/build/composables/editor/useBuilderShortcuts.ts +270 -0
- package/frontend-vue/app/build/composables/editor/useDraftProblems.ts +288 -0
- package/frontend-vue/app/build/composables/editor/useEditorContext.ts +388 -0
- package/frontend-vue/app/build/composables/editor/useEditorLoad.ts +158 -0
- package/frontend-vue/app/build/composables/editor/useForkToLocal.ts +193 -0
- package/frontend-vue/app/build/composables/editor/useGraphHistory.ts +113 -0
- package/frontend-vue/app/build/composables/editor/useGroupEditing.ts +445 -0
- package/frontend-vue/app/build/composables/editor/usePalette.ts +41 -0
- package/frontend-vue/app/build/composables/editor/useProcedureActions.ts +96 -0
- package/frontend-vue/app/build/composables/editor/useRunOverlay.ts +466 -0
- package/frontend-vue/app/build/composables/editor/useSaveAsTemplate.ts +172 -0
- package/frontend-vue/app/build/composables/editor/useSavedTriggers.ts +100 -0
- package/frontend-vue/app/build/composables/editor/useSubgraphNavigation.ts +270 -0
- package/frontend-vue/app/build/composables/editor/useUnsavedGuards.ts +233 -0
- package/frontend-vue/app/build/composables/graphCanvas/connect.ts +273 -0
- package/frontend-vue/app/build/composables/graphCanvas/edgeEvents.ts +172 -0
- package/frontend-vue/app/build/composables/graphCanvas/edges.ts +55 -0
- package/frontend-vue/app/build/composables/graphCanvas/handles.ts +181 -0
- package/frontend-vue/app/build/composables/graphCanvas/linkMenu.ts +123 -0
- package/frontend-vue/app/build/composables/graphCanvas/nodeData.ts +222 -0
- package/frontend-vue/app/build/composables/graphCanvas/placement.ts +248 -0
- package/frontend-vue/app/build/composables/graphCanvas/selection.ts +150 -0
- package/frontend-vue/app/build/composables/graphCanvas/types.ts +188 -0
- package/frontend-vue/app/build/composables/graphCanvas/view.ts +230 -0
- package/frontend-vue/app/build/types/editor.ts +94 -0
- package/frontend-vue/app/build/utils/editor/apiErrors.ts +74 -0
- package/frontend-vue/app/build/utils/editor/graphShape.ts +68 -0
- package/frontend-vue/app/build/utils/editor/groupPlan.ts +322 -0
- package/frontend-vue/app/build/utils/editor/groupPorts.ts +210 -0
- package/frontend-vue/app/build/utils/editor/keyboard.ts +22 -0
- package/frontend-vue/app/build/utils/inspectorFields.ts +117 -0
- package/frontend-vue/app/build/utils/templates.ts +88 -0
- package/frontend-vue/app/components/AttentionList.vue +2 -6
- package/frontend-vue/app/components/Catalog.vue +2 -1
- package/frontend-vue/app/components/Editor/GraphCanvas.vue +78 -1337
- package/frontend-vue/app/components/Editor/NodeInspector.vue +31 -123
- package/frontend-vue/app/components/Editor.vue +134 -3484
- package/frontend-vue/app/components/Templates.vue +14 -84
- package/frontend-vue/build/backend-boundary.ts +122 -0
- package/frontend-vue/dms.frontend.build.ts +2 -0
- package/frontend-vue/eslint-rules/index.mjs +103 -0
- package/frontend-vue/eslint.config.mjs +15 -0
- package/frontend-vue/package.json +8 -5
- package/frontend-vue/pnpm-lock.yaml +168 -139
- package/frontend-vue/tests/api-error-presentation.test.cjs +254 -0
- package/frontend-vue/tests/helpers/setup.cjs +44 -0
- package/package.json +18 -15
- package/skills/dms-automation/SKILL.md +2 -2
- package/skills/dms-automation/cases.json +58 -0
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
import { computed, nextTick, watch } from "vue";
|
|
2
|
+
import type { EditorContext } from "./useEditorContext";
|
|
3
|
+
import type { DockRun } from "../../../components/Editor/BottomDock.vue";
|
|
4
|
+
import type { NodeRunState } from "../../../components/Editor/nodes/GenericNode.vue";
|
|
5
|
+
import {
|
|
6
|
+
type RunDetail,
|
|
7
|
+
type TraceStep,
|
|
8
|
+
} from "../../../composables/useAutomationRuns";
|
|
9
|
+
import {
|
|
10
|
+
describeDuration,
|
|
11
|
+
describeTime,
|
|
12
|
+
stepTitle,
|
|
13
|
+
} from "../../../utils/describe";
|
|
14
|
+
import { issuesOf } from "../../utils/editor/apiErrors";
|
|
15
|
+
import type { GraphHistory } from "./useGraphHistory";
|
|
16
|
+
import type { DraftProblems } from "./useDraftProblems";
|
|
17
|
+
import type { SavedTriggers } from "./useSavedTriggers";
|
|
18
|
+
import type { UnsavedGuards } from "./useUnsavedGuards";
|
|
19
|
+
|
|
20
|
+
/** The runs shown over the canvas: a test of the draft, or a stored run being debugged. */
|
|
21
|
+
export function useRunOverlay(
|
|
22
|
+
ctx: EditorContext,
|
|
23
|
+
history: GraphHistory,
|
|
24
|
+
problems: DraftProblems,
|
|
25
|
+
triggers: SavedTriggers,
|
|
26
|
+
guards: UnsavedGuards,
|
|
27
|
+
) {
|
|
28
|
+
const { presentError } = useApiErrorPresenter();
|
|
29
|
+
const {
|
|
30
|
+
$authFetch,
|
|
31
|
+
builderPath,
|
|
32
|
+
confirm,
|
|
33
|
+
dateTimeFormat,
|
|
34
|
+
dockCollapsed,
|
|
35
|
+
dockTab,
|
|
36
|
+
editorMode,
|
|
37
|
+
issues,
|
|
38
|
+
locale,
|
|
39
|
+
overlayIsTest,
|
|
40
|
+
overlayRun,
|
|
41
|
+
procedures,
|
|
42
|
+
processI18n,
|
|
43
|
+
props,
|
|
44
|
+
queryValue,
|
|
45
|
+
router,
|
|
46
|
+
runNowOpen,
|
|
47
|
+
runsApi,
|
|
48
|
+
selected,
|
|
49
|
+
selectedId,
|
|
50
|
+
selectedNodeId,
|
|
51
|
+
subgraphPath,
|
|
52
|
+
t,
|
|
53
|
+
testPayload,
|
|
54
|
+
testPayloadSource,
|
|
55
|
+
testTriggerNodeId,
|
|
56
|
+
testing,
|
|
57
|
+
toast,
|
|
58
|
+
} = ctx;
|
|
59
|
+
const { isDirty } = history;
|
|
60
|
+
const { changeCount, savedName, selectNode, summariesRead } = problems;
|
|
61
|
+
const { ofSelected, selectedProcedureUrl } = triggers;
|
|
62
|
+
const { askChoice } = guards;
|
|
63
|
+
|
|
64
|
+
// ---------------------------------------------------------------------------
|
|
65
|
+
// Runs over the canvas: Test run of the draft, debugging a stored run (AU-05)
|
|
66
|
+
// ---------------------------------------------------------------------------
|
|
67
|
+
|
|
68
|
+
// The dock's last runs: its tab counts the failed ones, folded too.
|
|
69
|
+
const RECENT_RUNS = 8;
|
|
70
|
+
const recentRunsRead = useApiData<DockRun[]>(selectedProcedureUrl("runs"), {
|
|
71
|
+
query: { limit: RECENT_RUNS },
|
|
72
|
+
});
|
|
73
|
+
const recentRuns = computed(() => {
|
|
74
|
+
const list = ofSelected(recentRunsRead);
|
|
75
|
+
return Array.isArray(list) ? list.slice(0, RECENT_RUNS) : [];
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// The last real payload of the trigger a Test run starts from, which fills
|
|
79
|
+
// the test payload the user then edits. Left to the browser: it is shown
|
|
80
|
+
// only once the dock's payload tab is opened, and may be large.
|
|
81
|
+
const lastPayloadRead = useApiData<{
|
|
82
|
+
last: { runId: string; payload: unknown } | null;
|
|
83
|
+
}>(selectedProcedureUrl("last-payload"), {
|
|
84
|
+
query: () =>
|
|
85
|
+
testTriggerNodeId.value ? { triggerNodeId: testTriggerNodeId.value } : {},
|
|
86
|
+
server: false,
|
|
87
|
+
// Copied into an editable field: the page's refreshes leave the draft alone.
|
|
88
|
+
refreshOnPageRefresh: false,
|
|
89
|
+
});
|
|
90
|
+
// Each answer (or failure) of another procedure or trigger replaces the
|
|
91
|
+
// payload; the previous procedure's, still on screen meanwhile, does not.
|
|
92
|
+
watch(
|
|
93
|
+
[() => lastPayloadRead.data.value, () => lastPayloadRead.error.value],
|
|
94
|
+
([answer, error]) => {
|
|
95
|
+
if (!error && lastPayloadRead.placeholder.value) return;
|
|
96
|
+
const last = error ? null : answer?.last;
|
|
97
|
+
testPayload.value = JSON.stringify(last?.payload ?? {}, null, 2);
|
|
98
|
+
testPayloadSource.value = last?.runId ?? null;
|
|
99
|
+
},
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
const runStates = computed<Record<string, NodeRunState> | undefined>(() => {
|
|
103
|
+
const run = overlayRun.value;
|
|
104
|
+
if (!run || subgraphPath.value.length > 1) return undefined;
|
|
105
|
+
const out: Record<string, NodeRunState> = {};
|
|
106
|
+
for (const step of run.trace.steps) {
|
|
107
|
+
const id = step.nodeId.split("__")[0]!;
|
|
108
|
+
const previous = out[id];
|
|
109
|
+
const status = step.status === "failed" ? "failed" : "ok";
|
|
110
|
+
if (!previous || status === "failed") {
|
|
111
|
+
out[id] = {
|
|
112
|
+
status,
|
|
113
|
+
durationMs: (previous?.durationMs ?? 0) + (step.durationMs ?? 0),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
for (const skipped of run.trace.skipped)
|
|
118
|
+
out[skipped.nodeId] = { status: "skipped" };
|
|
119
|
+
return out;
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
const overlaySteps = computed<TraceStep[] | null>(() =>
|
|
123
|
+
overlayIsTest.value ? (overlayRun.value?.trace.steps ?? null) : null,
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
// The dock's "Test run" tab only exists while a test run is on screen.
|
|
127
|
+
watch(overlaySteps, (steps) => {
|
|
128
|
+
if (!steps && dockTab.value === "test") dockTab.value = "problems";
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
/** The step of the selected node in the run on screen, for the inspector. */
|
|
132
|
+
const selectedRunStep = computed<TraceStep | null>(() => {
|
|
133
|
+
const id = selectedNodeId.value;
|
|
134
|
+
const steps = overlayRun.value?.trace.steps ?? [];
|
|
135
|
+
if (!id) return null;
|
|
136
|
+
const own = steps.filter(
|
|
137
|
+
(s) => s.nodeId === id || s.nodeId.startsWith(`${id}__`),
|
|
138
|
+
);
|
|
139
|
+
return own.find((s) => s.status === "failed") ?? own.at(-1) ?? null;
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
const overlayLabel = computed(() => {
|
|
143
|
+
const run = overlayRun.value;
|
|
144
|
+
if (!run) return "";
|
|
145
|
+
const when = describeTime(run.startedAt, dateTimeFormat);
|
|
146
|
+
return overlayIsTest.value
|
|
147
|
+
? t("dms_automation.editor.debug.testLabel", { when })
|
|
148
|
+
: t("dms_automation.editor.debug.runLabel", {
|
|
149
|
+
run: run._id.slice(-6),
|
|
150
|
+
when,
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
/** A real run of an older version than the one open says so. */
|
|
155
|
+
const overlayDescription = computed(() => {
|
|
156
|
+
const run = overlayRun.value;
|
|
157
|
+
const version = selected.value?.version;
|
|
158
|
+
if (
|
|
159
|
+
!run ||
|
|
160
|
+
overlayIsTest.value ||
|
|
161
|
+
!run.procedureVersion ||
|
|
162
|
+
!version ||
|
|
163
|
+
run.procedureVersion === version
|
|
164
|
+
)
|
|
165
|
+
return overlayLabel.value;
|
|
166
|
+
return `${overlayLabel.value} · ${t("dms_automation.editor.debug.olderVersion", { run: run.procedureVersion, current: version })}`;
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
const overlaySummary = computed(() => {
|
|
170
|
+
const run = overlayRun.value;
|
|
171
|
+
if (!run) return "";
|
|
172
|
+
const duration = describeDuration(run.durationMs, locale.value);
|
|
173
|
+
if (run.status === "failed") {
|
|
174
|
+
const step = stepTitle(run.failedStep, processI18n);
|
|
175
|
+
return step
|
|
176
|
+
? t("dms_automation.editor.debug.failedAt", { step, duration })
|
|
177
|
+
: t("dms_automation.editor.debug.failed", { duration });
|
|
178
|
+
}
|
|
179
|
+
return t("dms_automation.editor.debug.passed", { duration });
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
/** The overlay banner's tone and icon, by how the run ended. */
|
|
183
|
+
const overlayLook = computed(() => {
|
|
184
|
+
const status = overlayRun.value?.status;
|
|
185
|
+
if (status === "failed")
|
|
186
|
+
return { tone: "error", icon: "i-ph-bug" } as const;
|
|
187
|
+
return { tone: "success", icon: "i-ph-check-circle" } as const;
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
/** Shows a stored run over the canvas; a test run is told by its kind. */
|
|
191
|
+
function displayRun(run: RunDetail) {
|
|
192
|
+
overlayRun.value = run;
|
|
193
|
+
overlayIsTest.value = run.kind === "test";
|
|
194
|
+
if (run.failedNodeId) selectNode(run.failedNodeId.split("__")[0]!);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
async function showRun(runId: string): Promise<RunDetail> {
|
|
198
|
+
const run = await runsApi.getRun(runId);
|
|
199
|
+
displayRun(run);
|
|
200
|
+
return run;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* `?run=`: the run is shown over the procedure it ran, which the builder
|
|
205
|
+
* opens if another one is asked; a run that no longer exists is said.
|
|
206
|
+
*/
|
|
207
|
+
async function openRunFromUrl(runId: string) {
|
|
208
|
+
const notFound = () => {
|
|
209
|
+
toast.add({
|
|
210
|
+
title: t("dms_automation.editor.debug.runNotFound"),
|
|
211
|
+
color: "warning",
|
|
212
|
+
icon: "i-ph-warning",
|
|
213
|
+
});
|
|
214
|
+
exitDebug();
|
|
215
|
+
};
|
|
216
|
+
let run: RunDetail;
|
|
217
|
+
try {
|
|
218
|
+
run = await runsApi.getRun(runId);
|
|
219
|
+
} catch (error) {
|
|
220
|
+
presentError(error, {
|
|
221
|
+
fallbackKey: "dms_automation.editor.debug.runNotFound",
|
|
222
|
+
});
|
|
223
|
+
exitDebug();
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
if (run.procedureId !== selectedId.value) {
|
|
227
|
+
if (!procedures.value.some((p) => p._id === run.procedureId)) {
|
|
228
|
+
notFound();
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
selectedId.value = run.procedureId;
|
|
232
|
+
// Switching clears the run on screen: show this one after it.
|
|
233
|
+
await nextTick();
|
|
234
|
+
}
|
|
235
|
+
displayRun(run);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function exitDebug() {
|
|
239
|
+
overlayRun.value = null;
|
|
240
|
+
overlayIsTest.value = false;
|
|
241
|
+
if (queryValue("run"))
|
|
242
|
+
void router.replace(`${builderPath()}?selected=${selectedId.value}`);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/** A step a test runs for real, as `POST /procedures/:id/test-effects` lists it. */
|
|
246
|
+
interface RealEffectStep {
|
|
247
|
+
nodeId: string;
|
|
248
|
+
typeId: string;
|
|
249
|
+
typeName: string;
|
|
250
|
+
label?: string;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Asks before a test that acts for real: the steps that would (actions that
|
|
255
|
+
* cannot simulate) are listed. Resolves `true` at once when there are none.
|
|
256
|
+
*/
|
|
257
|
+
async function confirmRealEffects(
|
|
258
|
+
procedureId: string,
|
|
259
|
+
graph: unknown,
|
|
260
|
+
): Promise<boolean> {
|
|
261
|
+
const { realEffects } = await $authFetch<{ realEffects: RealEffectStep[] }>(
|
|
262
|
+
`${props.apiUrl}/procedures/${procedureId}/test-effects`,
|
|
263
|
+
{
|
|
264
|
+
method: "POST",
|
|
265
|
+
body: { graph },
|
|
266
|
+
},
|
|
267
|
+
);
|
|
268
|
+
if (realEffects.length === 0) return true;
|
|
269
|
+
return await confirm({
|
|
270
|
+
title: t("dms_automation.editor.testEffects.title"),
|
|
271
|
+
description: t("dms_automation.editor.testEffects.description", {
|
|
272
|
+
count: realEffects.length,
|
|
273
|
+
}),
|
|
274
|
+
color: "warning",
|
|
275
|
+
icon: "i-ph-flask",
|
|
276
|
+
confirmLabel: t("dms_automation.editor.testEffects.confirm"),
|
|
277
|
+
initialFocus: "cancel",
|
|
278
|
+
impact: realEffects.map((step) => ({
|
|
279
|
+
icon: "i-ph-lightning",
|
|
280
|
+
label: processI18n(step.typeName),
|
|
281
|
+
...(step.label ? { count: step.label } : {}),
|
|
282
|
+
})),
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
async function onTestRun() {
|
|
287
|
+
const current = selected.value;
|
|
288
|
+
// One test at a time: Ctrl+Enter pressed again waits for it.
|
|
289
|
+
if (!current || editorMode.value !== "procedure" || testing.value) return;
|
|
290
|
+
let payload: unknown;
|
|
291
|
+
try {
|
|
292
|
+
payload = JSON.parse(testPayload.value || "null");
|
|
293
|
+
} catch (error) {
|
|
294
|
+
dockTab.value = "payload";
|
|
295
|
+
dockCollapsed.value = false;
|
|
296
|
+
presentError(error, {
|
|
297
|
+
fallbackKey: "dms_automation.editor.dock.invalidJson",
|
|
298
|
+
});
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
testing.value = true;
|
|
302
|
+
try {
|
|
303
|
+
// Steps that act for real (an e-mail sent, a record written) are named
|
|
304
|
+
// before the test runs, never after: closing the question runs nothing.
|
|
305
|
+
if (!(await confirmRealEffects(current._id, current.graph))) return;
|
|
306
|
+
// The previous result leaves the canvas while this test runs.
|
|
307
|
+
overlayRun.value = null;
|
|
308
|
+
overlayIsTest.value = false;
|
|
309
|
+
const res = await $authFetch<{ runId: string }>(
|
|
310
|
+
`${props.apiUrl}/procedures/${current._id}/test`,
|
|
311
|
+
{
|
|
312
|
+
method: "POST",
|
|
313
|
+
body: {
|
|
314
|
+
graph: current.graph,
|
|
315
|
+
payload,
|
|
316
|
+
triggerNodeId: testTriggerNodeId.value,
|
|
317
|
+
confirmRealEffects: true,
|
|
318
|
+
},
|
|
319
|
+
},
|
|
320
|
+
);
|
|
321
|
+
await showRun(res.runId);
|
|
322
|
+
dockTab.value = "test";
|
|
323
|
+
dockCollapsed.value = false;
|
|
324
|
+
void recentRunsRead.refresh();
|
|
325
|
+
} catch (e) {
|
|
326
|
+
const refused = issuesOf(e);
|
|
327
|
+
if (refused) {
|
|
328
|
+
issues.value = refused;
|
|
329
|
+
dockTab.value = "problems";
|
|
330
|
+
dockCollapsed.value = false;
|
|
331
|
+
}
|
|
332
|
+
presentError(e, {
|
|
333
|
+
fallbackKey: "dms_automation.editor.testRunError",
|
|
334
|
+
});
|
|
335
|
+
} finally {
|
|
336
|
+
testing.value = false;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/** Run now runs the saved graph: with unsaved changes, say so first. */
|
|
341
|
+
async function openRunNow() {
|
|
342
|
+
if (!selected.value) return;
|
|
343
|
+
if (isDirty.value) {
|
|
344
|
+
// Closing the question (Escape, ✕, a click outside) runs nothing.
|
|
345
|
+
const choice = await askChoice({
|
|
346
|
+
title: t("dms_automation.editor.runSaved.title"),
|
|
347
|
+
description: t("dms_automation.editor.runSaved.description", {
|
|
348
|
+
count: changeCount.value,
|
|
349
|
+
}),
|
|
350
|
+
choices: [
|
|
351
|
+
{
|
|
352
|
+
value: "cancel",
|
|
353
|
+
label: t("dms_automation.common.cancel"),
|
|
354
|
+
color: "neutral",
|
|
355
|
+
variant: "ghost",
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
value: "test",
|
|
359
|
+
label: t("dms_automation.editor.runSaved.testDraft"),
|
|
360
|
+
color: "neutral",
|
|
361
|
+
variant: "outline",
|
|
362
|
+
},
|
|
363
|
+
{
|
|
364
|
+
value: "saved",
|
|
365
|
+
label: t("dms_automation.editor.runSaved.runSaved"),
|
|
366
|
+
color: "warning",
|
|
367
|
+
},
|
|
368
|
+
],
|
|
369
|
+
dismiss: "cancel",
|
|
370
|
+
});
|
|
371
|
+
if (choice === "cancel") return;
|
|
372
|
+
if (choice === "test") {
|
|
373
|
+
await onTestRun();
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
runNowOpen.value = true;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/** A run of the saved version ended: show it, and say how it went. */
|
|
381
|
+
async function onRunStarted(runId: string) {
|
|
382
|
+
const name = savedName.value;
|
|
383
|
+
const trace = {
|
|
384
|
+
label: t("dms_automation.runs.trace"),
|
|
385
|
+
onClick: () => void router.push(`${props.traceUrl}?run=${runId}`),
|
|
386
|
+
};
|
|
387
|
+
void recentRunsRead.refresh();
|
|
388
|
+
void summariesRead.refresh();
|
|
389
|
+
let run: RunDetail;
|
|
390
|
+
try {
|
|
391
|
+
run = await showRun(runId);
|
|
392
|
+
} catch (error) {
|
|
393
|
+
presentError(error, {
|
|
394
|
+
fallbackKey: "dms_automation.editor.runStarted",
|
|
395
|
+
params: { name },
|
|
396
|
+
actions: [
|
|
397
|
+
{ labelKey: "dms_automation.runs.trace", onSelect: trace.onClick },
|
|
398
|
+
],
|
|
399
|
+
});
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
const step = stepTitle(run.failedStep, processI18n);
|
|
403
|
+
const failed = run.status === "failed";
|
|
404
|
+
toast.add({
|
|
405
|
+
title: failed
|
|
406
|
+
? step
|
|
407
|
+
? t("dms_automation.editor.runFailedAt", { name, step })
|
|
408
|
+
: t("dms_automation.editor.runFailed", { name })
|
|
409
|
+
: t("dms_automation.editor.runSucceeded", { name }),
|
|
410
|
+
color: failed ? "error" : "success",
|
|
411
|
+
icon: failed ? "i-ph-x-circle" : "i-ph-check-circle",
|
|
412
|
+
actions: [trace],
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Debugging a real run: once the fix is saved, run it again with the payload
|
|
418
|
+
* it received, on the saved version, and show the new run in its place.
|
|
419
|
+
*/
|
|
420
|
+
async function rerunOverlay() {
|
|
421
|
+
const run = overlayRun.value;
|
|
422
|
+
if (!run || overlayIsTest.value) return;
|
|
423
|
+
let newRunId: string | null = null;
|
|
424
|
+
const confirmed = await confirm({
|
|
425
|
+
title: t("dms_automation.runs.rerunConfirmTitle"),
|
|
426
|
+
description: t("dms_automation.runs.rerunConfirmDescription"),
|
|
427
|
+
color: "warning",
|
|
428
|
+
icon: "i-ph-arrow-clockwise",
|
|
429
|
+
confirmLabel: t("dms_automation.runs.rerun"),
|
|
430
|
+
onConfirm: async () => {
|
|
431
|
+
newRunId = (await runsApi.rerun(run._id)).runId;
|
|
432
|
+
},
|
|
433
|
+
});
|
|
434
|
+
if (!confirmed || !newRunId) return;
|
|
435
|
+
await onRunStarted(newRunId);
|
|
436
|
+
if (queryValue("run"))
|
|
437
|
+
void router.replace(
|
|
438
|
+
`${builderPath()}?selected=${selectedId.value}&run=${newRunId}`,
|
|
439
|
+
);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
function openTrace(runId: string) {
|
|
443
|
+
void router.push(`${props.traceUrl}?run=${runId}`);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
return {
|
|
447
|
+
recentRunsRead,
|
|
448
|
+
recentRuns,
|
|
449
|
+
runStates,
|
|
450
|
+
overlaySteps,
|
|
451
|
+
selectedRunStep,
|
|
452
|
+
overlayLabel,
|
|
453
|
+
overlayDescription,
|
|
454
|
+
overlaySummary,
|
|
455
|
+
overlayLook,
|
|
456
|
+
exitDebug,
|
|
457
|
+
onTestRun,
|
|
458
|
+
openRunNow,
|
|
459
|
+
onRunStarted,
|
|
460
|
+
rerunOverlay,
|
|
461
|
+
openTrace,
|
|
462
|
+
openRunFromUrl,
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
export type RunOverlay = ReturnType<typeof useRunOverlay>;
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { computed, ref, watch } from "vue";
|
|
2
|
+
import type { EditorContext } from "./useEditorContext";
|
|
3
|
+
import type { GraphNode } from "../../../composables/useGraphConnect";
|
|
4
|
+
import { formatTemplateError } from "../../utils/editor/apiErrors";
|
|
5
|
+
import type { GraphHistory } from "./useGraphHistory";
|
|
6
|
+
import type { SubgraphNavigation } from "./useSubgraphNavigation";
|
|
7
|
+
import type { BuilderSave } from "./useBuilderSave";
|
|
8
|
+
|
|
9
|
+
/** The row layout of the save-as-template form. */
|
|
10
|
+
export const TEMPLATE_ROW = {
|
|
11
|
+
layout: "form",
|
|
12
|
+
spacing: "list",
|
|
13
|
+
inset: false,
|
|
14
|
+
} as const;
|
|
15
|
+
|
|
16
|
+
export const TEMPLATE_NAME_ID = "save-template-name";
|
|
17
|
+
|
|
18
|
+
/** Saving a local group as a template, and linking the group to it. */
|
|
19
|
+
export function useSaveAsTemplate(
|
|
20
|
+
ctx: EditorContext,
|
|
21
|
+
history: GraphHistory,
|
|
22
|
+
nav: SubgraphNavigation,
|
|
23
|
+
save: BuilderSave,
|
|
24
|
+
) {
|
|
25
|
+
const { presentError } = useApiErrorPresenter();
|
|
26
|
+
const {
|
|
27
|
+
$authFetch,
|
|
28
|
+
currentGraph,
|
|
29
|
+
isCurrentGraphReadOnly,
|
|
30
|
+
selected,
|
|
31
|
+
selectedNode,
|
|
32
|
+
t,
|
|
33
|
+
templatesRead,
|
|
34
|
+
toast,
|
|
35
|
+
} = ctx;
|
|
36
|
+
const { isDirty } = history;
|
|
37
|
+
const { groupName, onUpdateNode } = nav;
|
|
38
|
+
const { onSave } = save;
|
|
39
|
+
|
|
40
|
+
// Visible when the user has selected a single local group (kind === 'group',
|
|
41
|
+
// no templateId). On submit:
|
|
42
|
+
// 1. POST /api/automation/templates with { name, description, icon, ports,
|
|
43
|
+
// subgraph } from the local group.
|
|
44
|
+
// 2. On success: mutate the in-graph node — set templateId = res._id, drop
|
|
45
|
+
// subgraph. The save flow (onGraphUpdate → onSave by user) propagates.
|
|
46
|
+
// 3. On failure (Zod or template cycle): render the error body inline in
|
|
47
|
+
// the modal; the graph is NOT touched.
|
|
48
|
+
const selectedLocalGroupNode = computed<GraphNode | null>(() => {
|
|
49
|
+
const n = selectedNode.value;
|
|
50
|
+
if (!n || n.kind !== "group") return null;
|
|
51
|
+
if (n.templateId) return null;
|
|
52
|
+
return n;
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const canSaveAsTemplate = computed<boolean>(() => {
|
|
56
|
+
if (!selected.value) return false;
|
|
57
|
+
if (isCurrentGraphReadOnly.value) return false;
|
|
58
|
+
return selectedLocalGroupNode.value !== null;
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const saveAsTemplateOpen = ref<boolean>(false);
|
|
62
|
+
const saveAsTemplateName = ref<string>("");
|
|
63
|
+
const saveAsTemplateDescription = ref<string>("");
|
|
64
|
+
const saveAsTemplateIcon = ref<string>("i-ph-package");
|
|
65
|
+
const saveAsTemplateSubmitting = ref<boolean>(false);
|
|
66
|
+
const saveAsTemplateError = ref<string | null>(null);
|
|
67
|
+
|
|
68
|
+
// A missing name shows under its field; what the server refuses (issues, a
|
|
69
|
+
// reference cycle) stays in the banner above the buttons.
|
|
70
|
+
const templateFieldErrors = useFieldErrors({
|
|
71
|
+
fields: { name: TEMPLATE_NAME_ID },
|
|
72
|
+
});
|
|
73
|
+
watch(saveAsTemplateName, () => templateFieldErrors.clear("name"));
|
|
74
|
+
|
|
75
|
+
function openSaveAsTemplate() {
|
|
76
|
+
const n = selectedLocalGroupNode.value;
|
|
77
|
+
if (!n) return;
|
|
78
|
+
saveAsTemplateName.value = groupName(n);
|
|
79
|
+
saveAsTemplateDescription.value = "";
|
|
80
|
+
saveAsTemplateIcon.value = "i-ph-package";
|
|
81
|
+
saveAsTemplateError.value = null;
|
|
82
|
+
templateFieldErrors.clear();
|
|
83
|
+
saveAsTemplateSubmitting.value = false;
|
|
84
|
+
saveAsTemplateOpen.value = true;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function convertLocalGroupToTemplateInstance(
|
|
88
|
+
nodeId: string,
|
|
89
|
+
templateId: string,
|
|
90
|
+
): void {
|
|
91
|
+
const g = currentGraph.value;
|
|
92
|
+
if (!g) return;
|
|
93
|
+
const existing = g.nodes.find((n) => n.id === nodeId && n.kind === "group");
|
|
94
|
+
if (!existing) return;
|
|
95
|
+
const updated: GraphNode = { ...existing, templateId };
|
|
96
|
+
delete updated.subgraph;
|
|
97
|
+
onUpdateNode(updated);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async function submitSaveAsTemplate() {
|
|
101
|
+
const n = selectedLocalGroupNode.value;
|
|
102
|
+
if (!n) return;
|
|
103
|
+
const name = saveAsTemplateName.value.trim();
|
|
104
|
+
if (!name) {
|
|
105
|
+
await templateFieldErrors.setError(
|
|
106
|
+
"name",
|
|
107
|
+
t("dms_automation.editor.saveTemplateModal.nameRequired"),
|
|
108
|
+
);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (!n.subgraph) {
|
|
112
|
+
saveAsTemplateError.value = t(
|
|
113
|
+
"dms_automation.editor.saveTemplateModal.noSubgraph",
|
|
114
|
+
);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
saveAsTemplateSubmitting.value = true;
|
|
118
|
+
saveAsTemplateError.value = null;
|
|
119
|
+
try {
|
|
120
|
+
const body = {
|
|
121
|
+
name,
|
|
122
|
+
description: saveAsTemplateDescription.value.trim(),
|
|
123
|
+
icon: saveAsTemplateIcon.value.trim() || "i-ph-package",
|
|
124
|
+
ports: Array.isArray(n.ports) ? n.ports : [],
|
|
125
|
+
subgraph: n.subgraph,
|
|
126
|
+
};
|
|
127
|
+
const created = await $authFetch<{ _id: string }>(
|
|
128
|
+
"/api/automation/templates",
|
|
129
|
+
{ method: "POST", body },
|
|
130
|
+
);
|
|
131
|
+
// The template exists now: the procedure links to it once saved. A
|
|
132
|
+
// draft with nothing else unsaved is saved at once; one with other
|
|
133
|
+
// changes is left to the user, who is told.
|
|
134
|
+
const linkOnly = !isDirty.value;
|
|
135
|
+
convertLocalGroupToTemplateInstance(n.id, created._id);
|
|
136
|
+
saveAsTemplateOpen.value = false;
|
|
137
|
+
void templatesRead.refresh();
|
|
138
|
+
toast.add({
|
|
139
|
+
title: t("dms_automation.templates.saved", { name }),
|
|
140
|
+
description: linkOnly
|
|
141
|
+
? undefined
|
|
142
|
+
: t("dms_automation.editor.saveTemplateModal.saveToLink"),
|
|
143
|
+
color: "success",
|
|
144
|
+
icon: "i-ph-check-circle",
|
|
145
|
+
});
|
|
146
|
+
if (linkOnly) await onSave();
|
|
147
|
+
} catch (e) {
|
|
148
|
+
const validation = formatTemplateError(e);
|
|
149
|
+
if (validation) saveAsTemplateError.value = validation;
|
|
150
|
+
else
|
|
151
|
+
presentError(e, { fallbackKey: "dms_automation.templates.saveError" });
|
|
152
|
+
} finally {
|
|
153
|
+
saveAsTemplateSubmitting.value = false;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
selectedLocalGroupNode,
|
|
159
|
+
canSaveAsTemplate,
|
|
160
|
+
saveAsTemplateOpen,
|
|
161
|
+
saveAsTemplateName,
|
|
162
|
+
saveAsTemplateDescription,
|
|
163
|
+
saveAsTemplateIcon,
|
|
164
|
+
saveAsTemplateSubmitting,
|
|
165
|
+
saveAsTemplateError,
|
|
166
|
+
templateFieldErrors,
|
|
167
|
+
openSaveAsTemplate,
|
|
168
|
+
submitSaveAsTemplate,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export type SaveAsTemplate = ReturnType<typeof useSaveAsTemplate>;
|