@widgetic/workflows 0.1.1 → 0.2.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 +107 -46
- package/dist/api/apiContext.d.ts +4 -0
- package/dist/api/apiContext.js +17 -0
- package/dist/api/types.d.ts +168 -0
- package/dist/api/types.js +3 -0
- package/dist/api/workflowsApi.d.ts +109 -0
- package/dist/api/workflowsApi.js +657 -0
- package/dist/components/Workflows.svelte +41 -17
- package/dist/components/WorkflowsEmptyState.svelte +16 -5
- package/dist/components/WorkflowsEmptyState.svelte.d.ts +5 -16
- package/dist/components/WorkflowsHeader.svelte +2 -2
- package/dist/components/WorkflowsWorkspace.svelte +87 -0
- package/dist/components/WorkflowsWorkspace.svelte.d.ts +14 -0
- package/dist/components/canvas/AddBlockMenu.svelte +101 -0
- package/dist/components/canvas/AddBlockMenu.svelte.d.ts +5 -0
- package/dist/components/canvas/CanvasToolbar.svelte +95 -0
- package/dist/components/canvas/CanvasToolbar.svelte.d.ts +9 -0
- package/dist/components/canvas/CompositionNodeView.svelte +125 -0
- package/dist/components/canvas/CompositionNodeView.svelte.d.ts +5 -0
- package/dist/components/canvas/ConditionNodeView.svelte +95 -0
- package/dist/components/canvas/ConditionNodeView.svelte.d.ts +5 -0
- package/dist/components/canvas/HandlePoint.svelte +32 -0
- package/dist/components/canvas/HandlePoint.svelte.d.ts +14 -0
- package/dist/components/canvas/TriggerNodeView.svelte +75 -0
- package/dist/components/canvas/TriggerNodeView.svelte.d.ts +5 -0
- package/dist/components/canvas/WorkflowCanvas.svelte +380 -0
- package/dist/components/canvas/WorkflowCanvas.svelte.d.ts +25 -0
- package/dist/components/canvas/WorkflowEdgeView.svelte +58 -0
- package/dist/components/canvas/WorkflowEdgeView.svelte.d.ts +4 -0
- package/dist/components/editor/EditorBanners.svelte +143 -0
- package/dist/components/editor/EditorBanners.svelte.d.ts +7 -0
- package/dist/components/editor/EditorCanvasArea.svelte +85 -0
- package/dist/components/editor/EditorCanvasArea.svelte.d.ts +3 -0
- package/dist/components/editor/EditorTabs.svelte +81 -0
- package/dist/components/editor/EditorTabs.svelte.d.ts +7 -0
- package/dist/components/editor/EditorTopBar.svelte +132 -0
- package/dist/components/editor/EditorTopBar.svelte.d.ts +9 -0
- package/dist/components/editor/RunsTab.svelte +256 -0
- package/dist/components/editor/RunsTab.svelte.d.ts +3 -0
- package/dist/components/editor/SettingsTab.svelte +180 -0
- package/dist/components/editor/SettingsTab.svelte.d.ts +7 -0
- package/dist/components/editor/WorkflowEditor.svelte +185 -0
- package/dist/components/editor/WorkflowEditor.svelte.d.ts +15 -0
- package/dist/components/index.d.ts +0 -2
- package/dist/components/index.js +0 -2
- package/dist/components/list/CreateWorkflowDialog.svelte +89 -0
- package/dist/components/list/CreateWorkflowDialog.svelte.d.ts +9 -0
- package/dist/components/list/WorkflowList.svelte +204 -0
- package/dist/components/list/WorkflowList.svelte.d.ts +12 -0
- package/dist/components/list/WorkflowRow.svelte +191 -0
- package/dist/components/list/WorkflowRow.svelte.d.ts +10 -0
- package/dist/components/panel/BlockProblems.svelte +47 -0
- package/dist/components/panel/BlockProblems.svelte.d.ts +6 -0
- package/dist/components/panel/CompositionForm.svelte +127 -0
- package/dist/components/panel/CompositionForm.svelte.d.ts +7 -0
- package/dist/components/panel/CompositionPicker.svelte +179 -0
- package/dist/components/panel/CompositionPicker.svelte.d.ts +14 -0
- package/dist/components/panel/ConditionForm.svelte +105 -0
- package/dist/components/panel/ConditionForm.svelte.d.ts +7 -0
- package/dist/components/panel/EventValueRow.svelte +85 -0
- package/dist/components/panel/EventValueRow.svelte.d.ts +12 -0
- package/dist/components/panel/NextStepSelect.svelte +70 -0
- package/dist/components/panel/NextStepSelect.svelte.d.ts +12 -0
- package/dist/components/panel/ProblemsList.svelte +101 -0
- package/dist/components/panel/ProblemsList.svelte.d.ts +3 -0
- package/dist/components/panel/RuleCard.svelte +191 -0
- package/dist/components/panel/RuleCard.svelte.d.ts +13 -0
- package/dist/components/panel/SidePanel.svelte +82 -0
- package/dist/components/panel/SidePanel.svelte.d.ts +3 -0
- package/dist/components/panel/TestRow.svelte +150 -0
- package/dist/components/panel/TestRow.svelte.d.ts +15 -0
- package/dist/components/panel/TestRunPanel.svelte +85 -0
- package/dist/components/panel/TestRunPanel.svelte.d.ts +3 -0
- package/dist/components/panel/TestTriggerCard.svelte +121 -0
- package/dist/components/panel/TestTriggerCard.svelte.d.ts +7 -0
- package/dist/components/panel/TriggerForm.svelte +385 -0
- package/dist/components/panel/TriggerForm.svelte.d.ts +7 -0
- package/dist/components/panel/VersionHistory.svelte +123 -0
- package/dist/components/panel/VersionHistory.svelte.d.ts +3 -0
- package/dist/components/ui/ActionButton.svelte +85 -0
- package/dist/components/ui/ActionButton.svelte.d.ts +27 -0
- package/dist/components/ui/ConfirmDialog.svelte +52 -0
- package/dist/components/ui/ConfirmDialog.svelte.d.ts +16 -0
- package/dist/components/ui/Icon.svelte +32 -0
- package/dist/components/ui/Icon.svelte.d.ts +9 -0
- package/dist/components/ui/Menu.svelte +211 -0
- package/dist/components/ui/Menu.svelte.d.ts +21 -0
- package/dist/components/ui/Modal.svelte +129 -0
- package/dist/components/ui/Modal.svelte.d.ts +13 -0
- package/dist/components/ui/Notice.svelte +36 -0
- package/dist/components/ui/Notice.svelte.d.ts +11 -0
- package/dist/components/ui/SelectField.svelte +74 -0
- package/dist/components/ui/SelectField.svelte.d.ts +16 -0
- package/dist/components/ui/StatusBadge.svelte +41 -0
- package/dist/components/ui/StatusBadge.svelte.d.ts +9 -0
- package/dist/components/ui/TextField.svelte +97 -0
- package/dist/components/ui/TextField.svelte.d.ts +29 -0
- package/dist/components/ui/icons.d.ts +34 -0
- package/dist/components/ui/icons.js +54 -0
- package/dist/components/ui/types.d.ts +26 -0
- package/dist/components/ui/types.js +1 -0
- package/dist/editor/apiErrorText.d.ts +10 -0
- package/dist/editor/apiErrorText.js +53 -0
- package/dist/editor/autosave.d.ts +47 -0
- package/dist/editor/autosave.js +119 -0
- package/dist/editor/blockLabels.d.ts +91 -0
- package/dist/editor/blockLabels.js +196 -0
- package/dist/editor/canvasContext.d.ts +52 -0
- package/dist/editor/canvasContext.js +37 -0
- package/dist/editor/canvasWords.d.ts +24 -0
- package/dist/editor/canvasWords.js +40 -0
- package/dist/editor/capabilityModel.d.ts +46 -0
- package/dist/editor/capabilityModel.js +113 -0
- package/dist/editor/editorState.svelte.d.ts +220 -0
- package/dist/editor/editorState.svelte.js +713 -0
- package/dist/editor/flowAdapter.d.ts +59 -0
- package/dist/editor/flowAdapter.js +166 -0
- package/dist/editor/formatCount.d.ts +5 -0
- package/dist/editor/formatCount.js +15 -0
- package/dist/editor/graphDiff.d.ts +27 -0
- package/dist/editor/graphDiff.js +64 -0
- package/dist/editor/graphModel.d.ts +154 -0
- package/dist/editor/graphModel.js +457 -0
- package/dist/editor/issueText.d.ts +64 -0
- package/dist/editor/issueText.js +101 -0
- package/dist/editor/listState.svelte.d.ts +82 -0
- package/dist/editor/listState.svelte.js +250 -0
- package/dist/editor/statsRange.d.ts +26 -0
- package/dist/editor/statsRange.js +41 -0
- package/dist/editor/testRun.d.ts +36 -0
- package/dist/editor/testRun.js +74 -0
- package/dist/editor/zonedTime.d.ts +20 -0
- package/dist/editor/zonedTime.js +134 -0
- package/dist/i18n/language.d.ts +3 -3
- package/dist/i18n/messages.d.ts +396 -4
- package/dist/i18n/messages.js +421 -8
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/types/index.d.ts +31 -3
- package/package.json +5 -1
|
@@ -0,0 +1,713 @@
|
|
|
1
|
+
import { getContext, setContext } from 'svelte';
|
|
2
|
+
import { hasErrors, validate } from '@widgetic/workflows-engine';
|
|
3
|
+
import { WorkflowsApiError, isCancelled } from '../api/workflowsApi.js';
|
|
4
|
+
import { workflowsError, workflowsWarn } from '../utils/logger.js';
|
|
5
|
+
import { pickApiErrorMessage } from './apiErrorText.js';
|
|
6
|
+
import { createDraftSaver } from './autosave.js';
|
|
7
|
+
import { toValidationContext } from './capabilityModel.js';
|
|
8
|
+
import { dropStrandedConnections, ensureOneStart, isSameGraph, listCompositionIds, makeEmptyGraph, planAddBlock, removeBlocks, removeConnections, setStartBlock } from './graphModel.js';
|
|
9
|
+
import { groupIssues } from './flowAdapter.js';
|
|
10
|
+
import { fireTestTrigger, startTestRun } from './testRun.js';
|
|
11
|
+
const DEFAULT_NOTICE_MILLISECONDS = 5000;
|
|
12
|
+
/**
|
|
13
|
+
* Everything the open workflow is: what the server says about it, the draft the person is changing, the compositions that
|
|
14
|
+
* can be used, what the draft is missing, where saving stands, and the small things the person is in the middle of
|
|
15
|
+
* (what is selected, which panel is open, a test visitor).
|
|
16
|
+
*
|
|
17
|
+
* The draft lives in two places on purpose. The canvas holds the blocks while they are dragged and drawn; this holds the
|
|
18
|
+
* same workflow as the engine's plain graph, which is what is validated, saved and published. They are kept the same in one
|
|
19
|
+
* direction each way: a change on the canvas arrives here through `acceptCanvasGraph`, and a change made in the side panel
|
|
20
|
+
* or the Add block menu goes through `commit`, which tells the canvas, whose own change then arrives here. Nothing else
|
|
21
|
+
* writes `graph`.
|
|
22
|
+
*
|
|
23
|
+
* What it never does: decide a rule of the workflow (the engine does), word a sentence (the catalog does), or draw.
|
|
24
|
+
*/
|
|
25
|
+
export class WorkflowEditorState {
|
|
26
|
+
workflowId;
|
|
27
|
+
// ---- what the server says -----------------------------------------------------------------------------------
|
|
28
|
+
workflow = $state.raw(null);
|
|
29
|
+
loadState = $state('loading');
|
|
30
|
+
loadFailure = $state.raw(null);
|
|
31
|
+
/** The compositions the workflow uses, as the API describes them. `null`: not there for this person. */
|
|
32
|
+
options = $state.raw({});
|
|
33
|
+
optionsReady = $state(false);
|
|
34
|
+
// ---- the draft ------------------------------------------------------------------------------------------------
|
|
35
|
+
graph = $state.raw(makeEmptyGraph());
|
|
36
|
+
name = $state('');
|
|
37
|
+
timezone = $state('UTC');
|
|
38
|
+
/** Bumped when the whole draft is replaced from outside (a reload, a restore), so the canvas starts again from it. */
|
|
39
|
+
draftEpoch = $state(0);
|
|
40
|
+
// ---- saving ---------------------------------------------------------------------------------------------------
|
|
41
|
+
saveState = $state('saved');
|
|
42
|
+
saveFailure = $state.raw(null);
|
|
43
|
+
// ---- what the person is doing ------------------------------------------------------------------------------
|
|
44
|
+
tab = $state('editor');
|
|
45
|
+
panel = $state('selection');
|
|
46
|
+
selectedNodeIds = $state.raw([]);
|
|
47
|
+
selectedEdgeIds = $state.raw([]);
|
|
48
|
+
busy = $state(null);
|
|
49
|
+
notice = $state.raw(null);
|
|
50
|
+
/** What a refused publish said was wrong (the server checks again with what it knows), until the next change. */
|
|
51
|
+
refusedIssues = $state.raw([]);
|
|
52
|
+
/** What the touch of a screen allows: with no pointer to draw lines with, the canvas only shows. */
|
|
53
|
+
canvasTouchOnly = $state(false);
|
|
54
|
+
/** Set when a publish was tried while the draft has problems: the blocks with problems are outlined until it is published. */
|
|
55
|
+
problemsRevealed = $state(false);
|
|
56
|
+
// ---- versions ------------------------------------------------------------------------------------------------
|
|
57
|
+
versions = $state.raw(null);
|
|
58
|
+
versionsState = $state('idle');
|
|
59
|
+
/** A published version being looked at, read-only. */
|
|
60
|
+
viewing = $state.raw(null);
|
|
61
|
+
// ---- the test visitor ------------------------------------------------------------------------------------------
|
|
62
|
+
testRun = $state.raw(null);
|
|
63
|
+
/** The canvas, while one is on the screen (a pointer that changes when the canvas comes and goes). */
|
|
64
|
+
canvas = $state.raw(null);
|
|
65
|
+
revision = 0;
|
|
66
|
+
lastSaved = { graph: makeEmptyGraph(), name: '', timezone: 'UTC' };
|
|
67
|
+
saver;
|
|
68
|
+
api;
|
|
69
|
+
reportError;
|
|
70
|
+
leave;
|
|
71
|
+
openWorkflow;
|
|
72
|
+
random;
|
|
73
|
+
noticeMilliseconds;
|
|
74
|
+
noticeTimer = null;
|
|
75
|
+
loadController = null;
|
|
76
|
+
disposed = false;
|
|
77
|
+
constructor(options) {
|
|
78
|
+
this.workflowId = options.workflowId;
|
|
79
|
+
this.api = options.api;
|
|
80
|
+
this.reportError = options.reportError;
|
|
81
|
+
this.leave = options.leave;
|
|
82
|
+
this.openWorkflow = options.openWorkflow;
|
|
83
|
+
this.random = options.random ?? Math.random;
|
|
84
|
+
this.noticeMilliseconds = options.noticeMilliseconds ?? DEFAULT_NOTICE_MILLISECONDS;
|
|
85
|
+
this.saver = createDraftSaver({
|
|
86
|
+
readSnapshot: () => this.readSaveSnapshot(),
|
|
87
|
+
send: (snapshot) => this.api.saveDraft(this.workflowId, this.toSaveInput(snapshot)),
|
|
88
|
+
onSaved: (snapshot, answer) => this.applySaved(snapshot, answer),
|
|
89
|
+
onStateChange: (state, error) => this.followSaveState(state, error),
|
|
90
|
+
isConflict: (error) => error instanceof WorkflowsApiError && error.revisionChanged,
|
|
91
|
+
delayMilliseconds: options.saveDelayMilliseconds
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
// =================================================================================================================
|
|
95
|
+
// Derived
|
|
96
|
+
// =================================================================================================================
|
|
97
|
+
/** What the engine finds missing in the draft, with what it knows about the compositions once that has arrived. */
|
|
98
|
+
issues = $derived.by(() => validate(this.graph, this.optionsReady ? toValidationContext(this.options) : undefined).issues);
|
|
99
|
+
/** The problems drawn on the canvas: those of the draft, so none while a published version is being looked at. */
|
|
100
|
+
issuesOnCanvas = $derived(groupIssues(this.viewing !== null ? [] : this.issues));
|
|
101
|
+
/** Errors stop a publish; warnings are advice. */
|
|
102
|
+
hasPublishBlockers = $derived(hasErrors(this.issues));
|
|
103
|
+
status = $derived(this.workflow?.status ?? 'draft');
|
|
104
|
+
/** Archived workflows are only looked at; so is a version, and so is a canvas on a touch screen. */
|
|
105
|
+
isReadOnly = $derived(this.status === 'archived' || this.viewing !== null);
|
|
106
|
+
canEditCanvas = $derived(!this.isReadOnly && !this.canvasTouchOnly && this.tab === 'editor');
|
|
107
|
+
hasChangesToPublish = $derived.by(() => {
|
|
108
|
+
const workflow = this.workflow;
|
|
109
|
+
if (!workflow)
|
|
110
|
+
return false;
|
|
111
|
+
if (workflow.status === 'draft')
|
|
112
|
+
return true;
|
|
113
|
+
return workflow.unpublishedChanges || this.saveState !== 'saved';
|
|
114
|
+
});
|
|
115
|
+
/** Publish can be tried: there is something to publish and nothing else in the way. The problems found are told on the try. */
|
|
116
|
+
canTryPublish = $derived(this.loadState === 'ready' &&
|
|
117
|
+
!this.isReadOnly &&
|
|
118
|
+
this.busy === null &&
|
|
119
|
+
this.saveState !== 'conflict' &&
|
|
120
|
+
this.hasChangesToPublish &&
|
|
121
|
+
this.graph.nodes.length > 0);
|
|
122
|
+
/** Publish will go through, as far as this screen can tell (the server checks again). */
|
|
123
|
+
canPublish = $derived(this.canTryPublish && !this.hasPublishBlockers);
|
|
124
|
+
selectedNode = $derived.by(() => {
|
|
125
|
+
if (this.selectedNodeIds.length !== 1)
|
|
126
|
+
return null;
|
|
127
|
+
const id = this.selectedNodeIds[0];
|
|
128
|
+
return this.graph.nodes.find((node) => node.id === id) ?? null;
|
|
129
|
+
});
|
|
130
|
+
startNodeId = $derived(this.graph.nodes.find((node) => node.type === 'composition' && node.startsHere === true)?.id ??
|
|
131
|
+
null);
|
|
132
|
+
compositionIds = $derived(listCompositionIds(this.graph));
|
|
133
|
+
/** The ids of the blocks a test visitor has passed, and where they are now, for the marks on the canvas. */
|
|
134
|
+
// Plain Sets, made anew whenever the test run changes and never changed afterwards: that is what a derived value is
|
|
135
|
+
// eslint-disable-next-line svelte/prefer-svelte-reactivity
|
|
136
|
+
testPassedIds = $derived(new Set(this.testRun?.passedNodeIds ?? []));
|
|
137
|
+
// eslint-disable-next-line svelte/prefer-svelte-reactivity
|
|
138
|
+
testTakenEdgeIds = $derived(new Set(this.testRun?.takenEdgeIds ?? []));
|
|
139
|
+
// =================================================================================================================
|
|
140
|
+
// Opening, reloading and closing
|
|
141
|
+
// =================================================================================================================
|
|
142
|
+
/** Reads the workflow and the compositions it uses. Safe to call again: it starts over from the server. */
|
|
143
|
+
async load() {
|
|
144
|
+
this.loadController?.abort();
|
|
145
|
+
const controller = new AbortController();
|
|
146
|
+
this.loadController = controller;
|
|
147
|
+
this.loadState = 'loading';
|
|
148
|
+
this.loadFailure = null;
|
|
149
|
+
try {
|
|
150
|
+
const detail = await this.api.getWorkflow(this.workflowId, { signal: controller.signal });
|
|
151
|
+
const optionsById = await this.readCompositionOptions(listCompositionIds(detail.graph), controller.signal);
|
|
152
|
+
if (this.disposed || controller.signal.aborted)
|
|
153
|
+
return;
|
|
154
|
+
this.options = optionsById;
|
|
155
|
+
this.optionsReady = true;
|
|
156
|
+
this.adoptServerDraft(detail);
|
|
157
|
+
this.loadState = 'ready';
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
if (isCancelled(error) || this.disposed)
|
|
161
|
+
return;
|
|
162
|
+
this.loadState = 'failed';
|
|
163
|
+
this.loadFailure = pickApiErrorMessage(error) ?? 'workflows.error.generic';
|
|
164
|
+
this.noteFailure('Reading the workflow failed', error);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/** Stops everything that is waiting: timers, saves, requests. Called when the editor is taken off the screen. */
|
|
168
|
+
dispose() {
|
|
169
|
+
this.disposed = true;
|
|
170
|
+
this.loadController?.abort();
|
|
171
|
+
this.saver.dispose();
|
|
172
|
+
if (this.noticeTimer !== null)
|
|
173
|
+
clearTimeout(this.noticeTimer);
|
|
174
|
+
this.noticeTimer = null;
|
|
175
|
+
this.canvas = null;
|
|
176
|
+
}
|
|
177
|
+
/** Sends what is waiting before the screen is left. Resolves to where saving stands. */
|
|
178
|
+
flushSaves() {
|
|
179
|
+
return this.saver.flush();
|
|
180
|
+
}
|
|
181
|
+
/** Leaves the workflow: what is waiting is sent first, then everything that was running is stopped. */
|
|
182
|
+
async finish() {
|
|
183
|
+
const state = await this.saver.flush();
|
|
184
|
+
this.dispose();
|
|
185
|
+
return state;
|
|
186
|
+
}
|
|
187
|
+
/** Takes what the server holds as the draft, replacing what is on the screen. */
|
|
188
|
+
adoptServerDraft(detail) {
|
|
189
|
+
this.workflow = detail;
|
|
190
|
+
this.revision = detail.revision;
|
|
191
|
+
const graph = ensureOneStart(detail.graph);
|
|
192
|
+
this.graph = graph;
|
|
193
|
+
this.name = detail.name;
|
|
194
|
+
this.timezone = detail.timezone;
|
|
195
|
+
this.lastSaved = { graph: detail.graph, name: detail.name, timezone: detail.timezone };
|
|
196
|
+
this.saver.reset();
|
|
197
|
+
this.saveFailure = null;
|
|
198
|
+
this.selectedNodeIds = [];
|
|
199
|
+
this.selectedEdgeIds = [];
|
|
200
|
+
this.refusedIssues = [];
|
|
201
|
+
this.problemsRevealed = false;
|
|
202
|
+
this.testRun = null;
|
|
203
|
+
this.draftEpoch += 1;
|
|
204
|
+
this.canvas?.loadGraph(graph);
|
|
205
|
+
}
|
|
206
|
+
/** Throws away what is unsaved on this screen and reads the draft again (after somebody else changed it). */
|
|
207
|
+
async reloadDraft() {
|
|
208
|
+
await this.load();
|
|
209
|
+
if (this.loadState === 'ready')
|
|
210
|
+
this.showNotice('info', 'workflows.editor.reloaded');
|
|
211
|
+
}
|
|
212
|
+
// =================================================================================================================
|
|
213
|
+
// The compositions
|
|
214
|
+
// =================================================================================================================
|
|
215
|
+
/** Reads what the API says about these compositions; the ones it does not know come back as `null`. */
|
|
216
|
+
async readCompositionOptions(ids, signal) {
|
|
217
|
+
const byId = Object.create(null);
|
|
218
|
+
for (const id of ids)
|
|
219
|
+
byId[id] = null;
|
|
220
|
+
if (ids.length === 0)
|
|
221
|
+
return byId;
|
|
222
|
+
const answer = await this.api.listCompositionOptions({ ids, limit: Math.max(ids.length, 1) }, { signal });
|
|
223
|
+
for (const option of answer.items)
|
|
224
|
+
byId[option.id] = option;
|
|
225
|
+
return byId;
|
|
226
|
+
}
|
|
227
|
+
/** Remembers compositions the person picked from the list, so the blocks that show them have their names at once. */
|
|
228
|
+
rememberCompositions(items) {
|
|
229
|
+
if (items.length === 0)
|
|
230
|
+
return;
|
|
231
|
+
const next = Object.assign(Object.create(null), this.options);
|
|
232
|
+
for (const item of items)
|
|
233
|
+
next[item.id] = item;
|
|
234
|
+
this.options = next;
|
|
235
|
+
}
|
|
236
|
+
/** Asks the API for compositions that the draft uses and this screen has not read yet (after a restore, say). */
|
|
237
|
+
async refreshMissingCompositions() {
|
|
238
|
+
const missing = this.compositionIds.filter((id) => !(id in this.options));
|
|
239
|
+
if (missing.length === 0)
|
|
240
|
+
return;
|
|
241
|
+
try {
|
|
242
|
+
const readBack = await this.readCompositionOptions(missing);
|
|
243
|
+
this.options = Object.assign(Object.create(null), this.options, readBack);
|
|
244
|
+
}
|
|
245
|
+
catch (error) {
|
|
246
|
+
this.noteFailure('Reading the compositions failed', error);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
// =================================================================================================================
|
|
250
|
+
// Changing the draft
|
|
251
|
+
// =================================================================================================================
|
|
252
|
+
/**
|
|
253
|
+
* A change that happened on the canvas (a block dragged, a line drawn, a block deleted): the draft follows it. Answers
|
|
254
|
+
* the draft as it is kept, which can differ from what the canvas held (the first composition left became the start), so
|
|
255
|
+
* that the canvas can take it over.
|
|
256
|
+
*/
|
|
257
|
+
acceptCanvasGraph(fromCanvas) {
|
|
258
|
+
if (this.disposed || this.viewing !== null)
|
|
259
|
+
return fromCanvas;
|
|
260
|
+
const next = ensureOneStart(fromCanvas);
|
|
261
|
+
if (!isSameGraph(next, this.graph)) {
|
|
262
|
+
this.graph = next;
|
|
263
|
+
this.afterDraftChanged();
|
|
264
|
+
void this.refreshMissingCompositions();
|
|
265
|
+
}
|
|
266
|
+
return next;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* A change made from the side panel or a menu. The canvas applies it (so it can be undone) and tells this state back,
|
|
270
|
+
* the same way a drag does. Without a canvas on the screen the draft changes directly.
|
|
271
|
+
*/
|
|
272
|
+
commit(next) {
|
|
273
|
+
if (this.isReadOnly || this.disposed)
|
|
274
|
+
return;
|
|
275
|
+
// A rule that was removed takes its line with it, so no line is left that starts from nothing.
|
|
276
|
+
const normalized = ensureOneStart(dropStrandedConnections(next));
|
|
277
|
+
if (isSameGraph(normalized, this.graph))
|
|
278
|
+
return;
|
|
279
|
+
if (this.canvas)
|
|
280
|
+
this.canvas.applyGraph(normalized);
|
|
281
|
+
else
|
|
282
|
+
this.acceptCanvasGraph(normalized);
|
|
283
|
+
}
|
|
284
|
+
/** What follows any change of the draft: a published check is stale, a test visitor may be somewhere that is gone, saving is due. */
|
|
285
|
+
afterDraftChanged() {
|
|
286
|
+
this.refusedIssues = [];
|
|
287
|
+
if (this.testRun !== null)
|
|
288
|
+
this.testRun = null;
|
|
289
|
+
this.saver.markChanged();
|
|
290
|
+
}
|
|
291
|
+
/** Replaces one block (the side panel changed it). */
|
|
292
|
+
replaceBlock(node) {
|
|
293
|
+
this.commit({
|
|
294
|
+
...this.graph,
|
|
295
|
+
nodes: this.graph.nodes.map((candidate) => (candidate.id === node.id ? node : candidate))
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
/** Draws a connection from a place of a block to another block, or takes it away (`targetNodeId` null). One line per place. */
|
|
299
|
+
connect(sourceNodeId, sourcePort, targetNodeId) {
|
|
300
|
+
const keptEdges = this.graph.edges.filter((edge) => !(edge.source === sourceNodeId && edge.sourcePort === sourcePort));
|
|
301
|
+
const withoutOld = { ...this.graph, edges: keptEdges };
|
|
302
|
+
if (targetNodeId === null) {
|
|
303
|
+
this.commit(withoutOld);
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
// A local lookup for choosing an unused id, not state
|
|
307
|
+
// eslint-disable-next-line svelte/prefer-svelte-reactivity
|
|
308
|
+
const taken = new Set([
|
|
309
|
+
...this.graph.nodes.map((node) => node.id),
|
|
310
|
+
...this.graph.edges.map((edge) => edge.id)
|
|
311
|
+
]);
|
|
312
|
+
let edgeId = `e_${Math.floor(this.random() * 36 ** 8)
|
|
313
|
+
.toString(36)
|
|
314
|
+
.padStart(8, '0')}`;
|
|
315
|
+
while (taken.has(edgeId))
|
|
316
|
+
edgeId = `${edgeId}x`;
|
|
317
|
+
const edge = {
|
|
318
|
+
id: edgeId,
|
|
319
|
+
source: sourceNodeId,
|
|
320
|
+
sourcePort,
|
|
321
|
+
target: targetNodeId
|
|
322
|
+
};
|
|
323
|
+
this.commit({ ...withoutOld, edges: [...keptEdges, edge] });
|
|
324
|
+
}
|
|
325
|
+
/** Adds a block after the selected one (or where there is room) and selects it. Resolves to why nothing was added, if so. */
|
|
326
|
+
addBlock(request) {
|
|
327
|
+
if (this.isReadOnly)
|
|
328
|
+
return null;
|
|
329
|
+
const anchorId = this.selectedNodeIds.length === 1 ? (this.selectedNodeIds[0] ?? null) : null;
|
|
330
|
+
const plan = planAddBlock(this.graph, request, anchorId, this.random);
|
|
331
|
+
if (plan.refused || !plan.node)
|
|
332
|
+
return plan.refused;
|
|
333
|
+
const nodes = [...this.graph.nodes, plan.node];
|
|
334
|
+
const edges = plan.edge ? [...this.graph.edges, plan.edge] : this.graph.edges;
|
|
335
|
+
this.commit({ ...this.graph, nodes, edges });
|
|
336
|
+
this.canvas?.selectNodes([plan.node.id]);
|
|
337
|
+
this.panel = 'selection';
|
|
338
|
+
return null;
|
|
339
|
+
}
|
|
340
|
+
/** Takes the selected blocks and lines off the draft. */
|
|
341
|
+
removeSelected() {
|
|
342
|
+
let next = this.graph;
|
|
343
|
+
if (this.selectedNodeIds.length > 0)
|
|
344
|
+
next = removeBlocks(next, this.selectedNodeIds);
|
|
345
|
+
if (this.selectedEdgeIds.length > 0)
|
|
346
|
+
next = removeConnections(next, this.selectedEdgeIds);
|
|
347
|
+
this.commit(next);
|
|
348
|
+
this.selectedNodeIds = [];
|
|
349
|
+
this.selectedEdgeIds = [];
|
|
350
|
+
}
|
|
351
|
+
removeBlock(nodeId) {
|
|
352
|
+
this.commit(removeBlocks(this.graph, [nodeId]));
|
|
353
|
+
this.selectedNodeIds = this.selectedNodeIds.filter((id) => id !== nodeId);
|
|
354
|
+
}
|
|
355
|
+
/** Makes a composition the first one visitors see. */
|
|
356
|
+
makeStart(nodeId) {
|
|
357
|
+
this.commit(setStartBlock(this.graph, nodeId));
|
|
358
|
+
}
|
|
359
|
+
/** The selection of the canvas, as the canvas reports it. */
|
|
360
|
+
followSelection(nodeIds, edgeIds) {
|
|
361
|
+
this.selectedNodeIds = nodeIds;
|
|
362
|
+
this.selectedEdgeIds = edgeIds;
|
|
363
|
+
if (nodeIds.length > 0 || edgeIds.length > 0) {
|
|
364
|
+
if (this.panel === 'history' && this.viewing === null)
|
|
365
|
+
this.panel = 'selection';
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
setName(name) {
|
|
369
|
+
if (this.isReadOnly)
|
|
370
|
+
return;
|
|
371
|
+
const trimmed = name.trim();
|
|
372
|
+
if (trimmed === '')
|
|
373
|
+
return;
|
|
374
|
+
if (trimmed === this.name)
|
|
375
|
+
return;
|
|
376
|
+
this.name = trimmed;
|
|
377
|
+
this.saver.markChanged();
|
|
378
|
+
}
|
|
379
|
+
setTimezone(timezone) {
|
|
380
|
+
if (this.isReadOnly || timezone === this.timezone)
|
|
381
|
+
return;
|
|
382
|
+
this.timezone = timezone;
|
|
383
|
+
this.refusedIssues = [];
|
|
384
|
+
this.saver.markChanged();
|
|
385
|
+
}
|
|
386
|
+
// =================================================================================================================
|
|
387
|
+
// Saving
|
|
388
|
+
// =================================================================================================================
|
|
389
|
+
/** What would go to the server now, or `null` when the server already has it. */
|
|
390
|
+
readSaveSnapshot() {
|
|
391
|
+
const snapshot = { revision: this.revision, next: { ...this.lastSaved } };
|
|
392
|
+
let changed = false;
|
|
393
|
+
if (!isSameGraph(this.graph, this.lastSaved.graph)) {
|
|
394
|
+
snapshot.graph = this.graph;
|
|
395
|
+
snapshot.next.graph = this.graph;
|
|
396
|
+
changed = true;
|
|
397
|
+
}
|
|
398
|
+
if (this.name !== this.lastSaved.name) {
|
|
399
|
+
snapshot.name = this.name;
|
|
400
|
+
snapshot.next.name = this.name;
|
|
401
|
+
changed = true;
|
|
402
|
+
}
|
|
403
|
+
if (this.timezone !== this.lastSaved.timezone) {
|
|
404
|
+
snapshot.timezone = this.timezone;
|
|
405
|
+
snapshot.next.timezone = this.timezone;
|
|
406
|
+
changed = true;
|
|
407
|
+
}
|
|
408
|
+
return changed ? snapshot : null;
|
|
409
|
+
}
|
|
410
|
+
toSaveInput(snapshot) {
|
|
411
|
+
const input = {
|
|
412
|
+
revision: snapshot.revision
|
|
413
|
+
};
|
|
414
|
+
if (snapshot.name !== undefined)
|
|
415
|
+
input.name = snapshot.name;
|
|
416
|
+
if (snapshot.timezone !== undefined)
|
|
417
|
+
input.timezone = snapshot.timezone;
|
|
418
|
+
if (snapshot.graph !== undefined)
|
|
419
|
+
input.graph = snapshot.graph;
|
|
420
|
+
return input;
|
|
421
|
+
}
|
|
422
|
+
applySaved(snapshot, answer) {
|
|
423
|
+
this.revision = answer.revision;
|
|
424
|
+
this.lastSaved = snapshot.next;
|
|
425
|
+
if (this.workflow)
|
|
426
|
+
this.workflow = { ...this.workflow, ...answer };
|
|
427
|
+
}
|
|
428
|
+
followSaveState(state, error) {
|
|
429
|
+
this.saveState = state;
|
|
430
|
+
if (state === 'failed' || state === 'conflict') {
|
|
431
|
+
this.saveFailure = pickApiErrorMessage(error) ?? 'workflows.error.generic';
|
|
432
|
+
this.noteFailure('Saving the draft failed', error);
|
|
433
|
+
}
|
|
434
|
+
else {
|
|
435
|
+
this.saveFailure = null;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
/** Tries a failed save again (the person pressed "Try again"). */
|
|
439
|
+
retrySave() {
|
|
440
|
+
void this.saver.flush();
|
|
441
|
+
}
|
|
442
|
+
// =================================================================================================================
|
|
443
|
+
// Publishing, discarding, restoring
|
|
444
|
+
// =================================================================================================================
|
|
445
|
+
/** Runs one thing the person waits for. Nothing else that changes the workflow runs meanwhile. */
|
|
446
|
+
async runBusy(kind, action, whatFailed) {
|
|
447
|
+
if (this.busy !== null)
|
|
448
|
+
return undefined;
|
|
449
|
+
this.busy = kind;
|
|
450
|
+
try {
|
|
451
|
+
return await action();
|
|
452
|
+
}
|
|
453
|
+
catch (error) {
|
|
454
|
+
if (isCancelled(error))
|
|
455
|
+
return undefined;
|
|
456
|
+
this.noteFailure(whatFailed, error);
|
|
457
|
+
this.showFailureNotice(error);
|
|
458
|
+
return undefined;
|
|
459
|
+
}
|
|
460
|
+
finally {
|
|
461
|
+
this.busy = null;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
/** Makes the draft the next version visitors get. */
|
|
465
|
+
async publish() {
|
|
466
|
+
if (!this.canTryPublish)
|
|
467
|
+
return false;
|
|
468
|
+
if (this.hasPublishBlockers) {
|
|
469
|
+
// The person pressed Publish on a draft that cannot be published: show them where it goes wrong, and publish nothing.
|
|
470
|
+
this.problemsRevealed = true;
|
|
471
|
+
this.panel = 'selection';
|
|
472
|
+
this.canvas?.selectNodes([]);
|
|
473
|
+
this.showNotice('problem', 'workflows.editor.fixProblems', {
|
|
474
|
+
count: this.issues.filter((issue) => issue.severity === 'error').length
|
|
475
|
+
});
|
|
476
|
+
return false;
|
|
477
|
+
}
|
|
478
|
+
const result = await this.runBusy('publishing', async () => {
|
|
479
|
+
const state = await this.saver.flush();
|
|
480
|
+
if (state !== 'saved') {
|
|
481
|
+
this.showNotice('problem', state === 'conflict' ? 'workflows.error.revisionChanged' : 'workflows.editor.saveFirst');
|
|
482
|
+
return null;
|
|
483
|
+
}
|
|
484
|
+
return this.api.publishWorkflow(this.workflowId, this.revision);
|
|
485
|
+
}, 'Publishing failed');
|
|
486
|
+
if (!result)
|
|
487
|
+
return false;
|
|
488
|
+
this.workflow = result.workflow;
|
|
489
|
+
this.revision = result.workflow.revision;
|
|
490
|
+
this.versions = null;
|
|
491
|
+
this.problemsRevealed = false;
|
|
492
|
+
this.refusedIssues = result.warnings;
|
|
493
|
+
this.showNotice('info', 'workflows.editor.published', { number: result.version.versionNumber });
|
|
494
|
+
return true;
|
|
495
|
+
}
|
|
496
|
+
/** Puts the draft back to what is live. */
|
|
497
|
+
async discardChanges() {
|
|
498
|
+
if (this.isReadOnly || this.busy !== null)
|
|
499
|
+
return false;
|
|
500
|
+
this.saver.reset();
|
|
501
|
+
const detail = await this.runBusy('discarding', () => this.api.discardChanges(this.workflowId, this.revision), 'Discarding changes failed');
|
|
502
|
+
if (!detail)
|
|
503
|
+
return false;
|
|
504
|
+
this.adoptServerDraft(detail);
|
|
505
|
+
this.showNotice('info', 'workflows.editor.discarded');
|
|
506
|
+
return true;
|
|
507
|
+
}
|
|
508
|
+
// ---- versions ---------------------------------------------------------------------------------------------------
|
|
509
|
+
async loadVersions() {
|
|
510
|
+
this.versionsState = 'loading';
|
|
511
|
+
try {
|
|
512
|
+
this.versions = await this.api.listVersions(this.workflowId);
|
|
513
|
+
this.versionsState = 'idle';
|
|
514
|
+
}
|
|
515
|
+
catch (error) {
|
|
516
|
+
if (isCancelled(error))
|
|
517
|
+
return;
|
|
518
|
+
this.versionsState = 'failed';
|
|
519
|
+
this.noteFailure('Reading the versions failed', error);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
openHistory() {
|
|
523
|
+
this.panel = 'history';
|
|
524
|
+
if (this.versions === null)
|
|
525
|
+
void this.loadVersions();
|
|
526
|
+
}
|
|
527
|
+
closeHistory() {
|
|
528
|
+
if (this.viewing !== null)
|
|
529
|
+
this.leaveVersion();
|
|
530
|
+
this.panel = 'selection';
|
|
531
|
+
}
|
|
532
|
+
/** Shows a published version read-only on the canvas. */
|
|
533
|
+
async viewVersion(versionId) {
|
|
534
|
+
if (this.busy !== null)
|
|
535
|
+
return;
|
|
536
|
+
try {
|
|
537
|
+
const detail = await this.api.getVersion(this.workflowId, versionId);
|
|
538
|
+
await this.saver.flush();
|
|
539
|
+
this.viewing = detail;
|
|
540
|
+
this.selectedNodeIds = [];
|
|
541
|
+
this.selectedEdgeIds = [];
|
|
542
|
+
this.testRun = null;
|
|
543
|
+
await this.ensureOptionsFor(detail.graph);
|
|
544
|
+
this.draftEpoch += 1;
|
|
545
|
+
this.canvas?.loadGraph(detail.graph);
|
|
546
|
+
}
|
|
547
|
+
catch (error) {
|
|
548
|
+
if (isCancelled(error))
|
|
549
|
+
return;
|
|
550
|
+
this.noteFailure('Reading the version failed', error);
|
|
551
|
+
this.showFailureNotice(error);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
/** Goes back from a version to the draft. */
|
|
555
|
+
leaveVersion() {
|
|
556
|
+
if (this.viewing === null)
|
|
557
|
+
return;
|
|
558
|
+
this.viewing = null;
|
|
559
|
+
this.draftEpoch += 1;
|
|
560
|
+
this.canvas?.loadGraph(this.graph);
|
|
561
|
+
}
|
|
562
|
+
/** Copies the version into the draft (the draft it replaces stays recoverable only through undo, so the screen asks first). */
|
|
563
|
+
async restoreViewedVersion() {
|
|
564
|
+
const viewing = this.viewing;
|
|
565
|
+
if (!viewing || this.busy !== null)
|
|
566
|
+
return false;
|
|
567
|
+
const detail = await this.runBusy('restoring', () => this.api.restoreVersion(this.workflowId, viewing.id, this.revision), 'Restoring a version failed');
|
|
568
|
+
if (!detail)
|
|
569
|
+
return false;
|
|
570
|
+
this.viewing = null;
|
|
571
|
+
await this.ensureOptionsFor(detail.graph);
|
|
572
|
+
this.adoptServerDraft(detail);
|
|
573
|
+
this.panel = 'selection';
|
|
574
|
+
this.showNotice('info', 'workflows.editor.restored', { number: viewing.versionNumber });
|
|
575
|
+
return true;
|
|
576
|
+
}
|
|
577
|
+
/** Reads what the API says about the compositions of a graph (a version, say) that this screen has not read yet. */
|
|
578
|
+
async ensureOptionsFor(graph) {
|
|
579
|
+
const missing = listCompositionIds(graph).filter((id) => !(id in this.options));
|
|
580
|
+
if (missing.length === 0)
|
|
581
|
+
return;
|
|
582
|
+
try {
|
|
583
|
+
this.options = Object.assign(Object.create(null), this.options, await this.readCompositionOptions(missing));
|
|
584
|
+
}
|
|
585
|
+
catch (error) {
|
|
586
|
+
this.noteFailure('Reading the compositions failed', error);
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
// ---- states of the workflow -------------------------------------------------------------------------------
|
|
590
|
+
async changeState(action) {
|
|
591
|
+
if (this.busy !== null)
|
|
592
|
+
return false;
|
|
593
|
+
await this.saver.flush();
|
|
594
|
+
const item = await this.runBusy('changingState', () => this.api.changeState(this.workflowId, action), 'Changing the state failed');
|
|
595
|
+
if (!item)
|
|
596
|
+
return false;
|
|
597
|
+
if (this.workflow)
|
|
598
|
+
this.workflow = { ...this.workflow, ...item };
|
|
599
|
+
this.revision = item.revision;
|
|
600
|
+
this.showNotice('info', STATE_NOTICE_KEYS[action]);
|
|
601
|
+
return true;
|
|
602
|
+
}
|
|
603
|
+
async duplicate() {
|
|
604
|
+
if (this.busy !== null)
|
|
605
|
+
return;
|
|
606
|
+
await this.saver.flush();
|
|
607
|
+
const copy = await this.runBusy('duplicating', () => this.api.duplicateWorkflow(this.workflowId), 'Duplicating failed');
|
|
608
|
+
if (copy)
|
|
609
|
+
this.openWorkflow(copy.id);
|
|
610
|
+
}
|
|
611
|
+
async deleteWorkflow() {
|
|
612
|
+
if (this.busy !== null)
|
|
613
|
+
return;
|
|
614
|
+
this.saver.dispose();
|
|
615
|
+
const done = await this.runBusy('deleting', async () => {
|
|
616
|
+
await this.api.deleteWorkflow(this.workflowId);
|
|
617
|
+
return true;
|
|
618
|
+
}, 'Deleting failed');
|
|
619
|
+
if (done)
|
|
620
|
+
this.leave();
|
|
621
|
+
}
|
|
622
|
+
// =================================================================================================================
|
|
623
|
+
// The test visitor
|
|
624
|
+
// =================================================================================================================
|
|
625
|
+
openTestRun() {
|
|
626
|
+
this.panel = 'test';
|
|
627
|
+
this.testRun = startTestRun(this.graph);
|
|
628
|
+
}
|
|
629
|
+
closeTestRun() {
|
|
630
|
+
this.panel = 'selection';
|
|
631
|
+
this.testRun = null;
|
|
632
|
+
}
|
|
633
|
+
restartTestRun() {
|
|
634
|
+
this.testRun = startTestRun(this.graph);
|
|
635
|
+
}
|
|
636
|
+
/** The test visitor does one thing: a trigger of the composition they are on fires, carrying these values. */
|
|
637
|
+
fireTrigger(triggerId, values) {
|
|
638
|
+
const state = this.testRun;
|
|
639
|
+
if (!state)
|
|
640
|
+
return;
|
|
641
|
+
const trigger = this.graph.nodes.find((node) => node.type === 'trigger' && node.id === triggerId);
|
|
642
|
+
if (!trigger)
|
|
643
|
+
return;
|
|
644
|
+
this.testRun = fireTestTrigger(this.graph, state, trigger, values);
|
|
645
|
+
}
|
|
646
|
+
// =================================================================================================================
|
|
647
|
+
// Saying what happened
|
|
648
|
+
// =================================================================================================================
|
|
649
|
+
showNotice(tone, messageKey, values) {
|
|
650
|
+
if (this.noticeTimer !== null)
|
|
651
|
+
clearTimeout(this.noticeTimer);
|
|
652
|
+
this.noticeTimer = null;
|
|
653
|
+
this.notice = { tone, messageKey, values };
|
|
654
|
+
if (tone === 'info') {
|
|
655
|
+
this.noticeTimer = setTimeout(() => {
|
|
656
|
+
this.notice = null;
|
|
657
|
+
this.noticeTimer = null;
|
|
658
|
+
}, this.noticeMilliseconds);
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
dismissNotice() {
|
|
662
|
+
if (this.noticeTimer !== null)
|
|
663
|
+
clearTimeout(this.noticeTimer);
|
|
664
|
+
this.noticeTimer = null;
|
|
665
|
+
this.notice = null;
|
|
666
|
+
}
|
|
667
|
+
showFailureNotice(error) {
|
|
668
|
+
const key = pickApiErrorMessage(error);
|
|
669
|
+
if (key === null)
|
|
670
|
+
return;
|
|
671
|
+
if (error instanceof WorkflowsApiError && error.issues.length > 0)
|
|
672
|
+
this.refusedIssues = error.issues;
|
|
673
|
+
this.showNotice('problem', key);
|
|
674
|
+
}
|
|
675
|
+
/** Says a failure once in the console and tells the page. */
|
|
676
|
+
noteFailure(what, error) {
|
|
677
|
+
if (isCancelled(error))
|
|
678
|
+
return;
|
|
679
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
680
|
+
workflowsError(`${what}: ${detail}`, error);
|
|
681
|
+
const sessionEnded = error instanceof WorkflowsApiError && error.sessionEnded;
|
|
682
|
+
try {
|
|
683
|
+
this.reportError({
|
|
684
|
+
message: `${what}: ${detail}`,
|
|
685
|
+
code: sessionEnded ? 'SESSION_ENDED' : 'REQUEST_FAILED',
|
|
686
|
+
fatal: false
|
|
687
|
+
});
|
|
688
|
+
}
|
|
689
|
+
catch (handlerError) {
|
|
690
|
+
workflowsWarn('The onError handler of the page threw.', handlerError);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
const STATE_NOTICE_KEYS = {
|
|
695
|
+
pause: 'workflows.editor.paused',
|
|
696
|
+
resume: 'workflows.editor.resumed',
|
|
697
|
+
archive: 'workflows.editor.archived',
|
|
698
|
+
unarchive: 'workflows.editor.unarchived'
|
|
699
|
+
};
|
|
700
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
701
|
+
// Sharing the editor with the parts of the screen
|
|
702
|
+
// ---------------------------------------------------------------------------------------------------------------------
|
|
703
|
+
const EDITOR_STATE_KEY = Symbol('workflows-editor-state');
|
|
704
|
+
export function provideEditorState(state) {
|
|
705
|
+
return setContext(EDITOR_STATE_KEY, state);
|
|
706
|
+
}
|
|
707
|
+
/** Called by a part of the editor while it is created. The editor is always there for those parts: this throws if it is not. */
|
|
708
|
+
export function useEditorState() {
|
|
709
|
+
const state = getContext(EDITOR_STATE_KEY);
|
|
710
|
+
if (!state)
|
|
711
|
+
throw new Error('[Workflows] A part of the editor was drawn outside the editor.');
|
|
712
|
+
return state;
|
|
713
|
+
}
|