@dudousxd/nestjs-catalog-react 0.19.0-preview.0 → 0.20.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/dist/TraceExplorer.d.ts +11 -1
- package/dist/TraceExplorer.js +64 -3
- package/dist/WorkflowCanvas.js +840 -76
- package/dist/context.d.ts +10 -1
- package/dist/context.js +1 -0
- package/dist/workflow/graph.d.ts +24 -1
- package/dist/workflow/graph.js +164 -3
- package/dist/workflow/history.d.ts +291 -0
- package/dist/workflow/history.js +343 -0
- package/dist/workflow/model.d.ts +13 -2
- package/dist/workflow/model.js +6 -1
- package/dist/workflow/nodes.js +39 -3
- package/dist/workflow/templates.js +11 -0
- package/package.json +9 -9
package/dist/WorkflowCanvas.js
CHANGED
|
@@ -7,8 +7,8 @@ import { Background, BackgroundVariant, ConnectionLineType, Controls, MiniMap, N
|
|
|
7
7
|
// See src/styles.d.ts for why `tsc` tolerates this import.
|
|
8
8
|
import '@xyflow/react/dist/style.css';
|
|
9
9
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
10
|
-
import { ArrowRight, CircleAlert, CircleDashed, Code2, Database, ExternalLink, GitBranch, LayoutGrid, Link2, Loader2, Plug, Plus, Repeat, Save, Trash2, TriangleAlert, Unplug, } from 'lucide-react';
|
|
11
|
-
import { useReducedMotion } from 'motion/react';
|
|
10
|
+
import { ArrowRight, CircleAlert, CircleDashed, Code2, Database, ExternalLink, Filter, GitBranch, Info, LayoutGrid, Link2, Loader2, PanelRight, Plug, Plus, Repeat, Save, Trash2, TriangleAlert, Unplug, X, } from 'lucide-react';
|
|
11
|
+
import { AnimatePresence, motion, useReducedMotion } from 'motion/react';
|
|
12
12
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
13
13
|
import { connectionOptionsFor } from './ConnectionPanel';
|
|
14
14
|
import { TransformEditor } from './TransformEditor';
|
|
@@ -20,14 +20,16 @@ import { INLINE_CONNECTION, KIND_OPTIONS, ReadModeFields, SourceFields, readsInc
|
|
|
20
20
|
import { Button } from './ui/button';
|
|
21
21
|
import { ComboboxField } from './ui/combobox';
|
|
22
22
|
import { ConfirmDialog } from './ui/dialog';
|
|
23
|
-
import { TextAreaField, TextField } from './ui/field';
|
|
23
|
+
import { FieldGroup, TextAreaField, TextField } from './ui/field';
|
|
24
24
|
import { Select, SelectField } from './ui/select';
|
|
25
25
|
import { Sheet } from './ui/sheet';
|
|
26
|
+
import { Switch } from './ui/switch';
|
|
26
27
|
import { Tooltip, TooltipProvider } from './ui/tooltip';
|
|
27
28
|
import { WorkflowEdgeProvider, workflowEdgeTypes } from './workflow/edges';
|
|
28
|
-
import { NODE_HEIGHT, NODE_WIDTH, defaultLabel, flowingEdgeIds, layout, layoutIfUnarranged, nextPosition, toFlowEdges, toFlowNodes, } from './workflow/graph';
|
|
29
|
+
import { NODE_HEIGHT, NODE_WIDTH, defaultLabel, describeFilterPredicate, flowingEdgeIds, layout, layoutIfUnarranged, nextPosition, toFlowEdges, toFlowNodes, } from './workflow/graph';
|
|
30
|
+
import { HistoryControls, keepKnown, namesOf, nodeEditAction, reverted, snapshotOf, undone, useUndoShortcut, useUnsavedGuard, withEdit, } from './workflow/history';
|
|
29
31
|
import { PublishControls, RunControls, SchedulePanel, ShrinkRefusalNote, WorkflowStatusBadge, } from './workflow/lifecycle';
|
|
30
|
-
import { WORKFLOW_BRANCH_LABELS, WORKFLOW_NODE_KINDS, callableWorkflowBlock, describeDurability, isWorkflowBranchLabel, isWorkflowNodeKind, isWorkflowPredicateKind, newLocalId, nodeName, producedTypes, unreachableNodeKind, unreachablePredicateKind, } from './workflow/model';
|
|
32
|
+
import { WORKFLOW_BRANCH_LABELS, WORKFLOW_FILTER_MAX_DEPTH, WORKFLOW_FILTER_MAX_VALUES, WORKFLOW_FILTER_OPERATORS, WORKFLOW_NODE_KINDS, callableWorkflowBlock, describeDurability, isWorkflowBranchLabel, isWorkflowFilterOperator, isWorkflowFilterPredicateKind, isWorkflowNodeKind, isWorkflowPredicateKind, newLocalId, nodeName, producedTypes, unreachableFilterPredicateKind, unreachableNodeKind, unreachablePredicateKind, workflowNarrowedTypes, } from './workflow/model';
|
|
31
33
|
import { WORKFLOW_NAME } from './workflow/name';
|
|
32
34
|
import { WorkflowNodeProvider, workflowNodeTypes } from './workflow/nodes';
|
|
33
35
|
import { RunsAsPanel } from './workflow/runs';
|
|
@@ -36,6 +38,123 @@ import { PendingWireLine, WiringHint, useClickWiring, } from './workflow/wiring'
|
|
|
36
38
|
const MUTED = 'text-zinc-400 dark:text-zinc-500';
|
|
37
39
|
const RULE = 'border-zinc-200 dark:border-zinc-800';
|
|
38
40
|
const PANEL = 'bg-white dark:bg-zinc-900';
|
|
41
|
+
/**
|
|
42
|
+
* A card INSIDE a floating panel.
|
|
43
|
+
*
|
|
44
|
+
* Deliberately not {@link PANEL}. An opaque white card on a translucent panel
|
|
45
|
+
* cancels the blur it is sitting on and the rail stops reading as one surface —
|
|
46
|
+
* it becomes four white boxes with a frosted gap between them.
|
|
47
|
+
*/
|
|
48
|
+
const SUBPANEL = 'bg-zinc-50/60 dark:bg-zinc-950/40';
|
|
49
|
+
/**
|
|
50
|
+
* What a thing floating ON the canvas looks like.
|
|
51
|
+
*
|
|
52
|
+
* Translucent with a blur rather than opaque, and that is the whole point of the
|
|
53
|
+
* layout this belongs to: a panel that blanks out what is behind it turns the
|
|
54
|
+
* canvas back into a box with a border, only now the box is a worse shape. The
|
|
55
|
+
* graph stays perceptible through the chrome, so the surface reads as continuous
|
|
56
|
+
* and the panels read as sitting on it.
|
|
57
|
+
*/
|
|
58
|
+
const FLOATING = cn('rounded-xl border shadow-lg shadow-zinc-950/5 dark:shadow-zinc-950/40', 'border-zinc-200/80 bg-white/85 backdrop-blur-md', 'dark:border-zinc-800/80 dark:bg-zinc-900/85');
|
|
59
|
+
/**
|
|
60
|
+
* How much of the canvas the floating chrome covers, per edge, in CSS pixels.
|
|
61
|
+
*
|
|
62
|
+
* ONE definition, read by two things that would otherwise drift: the Tailwind
|
|
63
|
+
* insets the chrome is positioned with, and the per-side `fitView` padding the
|
|
64
|
+
* graph is fitted into. That second use is what makes a full-bleed canvas
|
|
65
|
+
* honest — React Flow fits the graph to the *viewport*, so without this it
|
|
66
|
+
* would happily centre a node underneath the action cluster and leave somebody
|
|
67
|
+
* dragging a box out from under a panel to read it.
|
|
68
|
+
*
|
|
69
|
+
* Deliberately generous rather than measured. Measuring the real panels every
|
|
70
|
+
* frame would be a ResizeObserver feeding a value into a fit that then moves
|
|
71
|
+
* the panels' backdrop, and the loop that produces is worse than 20px of slack.
|
|
72
|
+
*/
|
|
73
|
+
const CHROME = {
|
|
74
|
+
top: 150,
|
|
75
|
+
bottom: 90,
|
|
76
|
+
side: 28,
|
|
77
|
+
/** The rail's width plus its gutter, when it is open. */
|
|
78
|
+
rail: 336,
|
|
79
|
+
};
|
|
80
|
+
/** {@link CHROME} as the padding `fitView` wants. The right edge is the only side that moves. */
|
|
81
|
+
function chromeFitPadding(railOpen) {
|
|
82
|
+
return {
|
|
83
|
+
top: `${CHROME.top}px`,
|
|
84
|
+
bottom: `${CHROME.bottom}px`,
|
|
85
|
+
left: `${CHROME.side}px`,
|
|
86
|
+
right: `${railOpen ? CHROME.rail : CHROME.side}px`,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Whether the details rail starts on screen.
|
|
91
|
+
*
|
|
92
|
+
* Read once, from the width at mount, rather than subscribed to. A live media
|
|
93
|
+
* query would reopen a panel somebody had just closed because they turned their
|
|
94
|
+
* tablet, which is worse than the panel being open on a narrow screen they can
|
|
95
|
+
* shut it on.
|
|
96
|
+
*
|
|
97
|
+
* `typeof window` guards server rendering, where there is no width to ask about
|
|
98
|
+
* and a bare `window` is a crash rather than a layout bug. Open is the right
|
|
99
|
+
* answer there: it is what hydrates into on a desktop, and a panel that appears
|
|
100
|
+
* after hydration is a worse first paint than one that was always there.
|
|
101
|
+
*/
|
|
102
|
+
function railOpenByDefault() {
|
|
103
|
+
return typeof window === 'undefined' ? true : window.innerWidth >= 1024;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Every kind of node, and how it is offered.
|
|
107
|
+
*
|
|
108
|
+
* A `Record` over `WorkflowNodeKind` rather than a hand-written row of buttons,
|
|
109
|
+
* and that is a bug fix rather than a tidy-up: `filter` shipped complete — model,
|
|
110
|
+
* validator, executor, inspector, its own colour on the canvas — and could not be
|
|
111
|
+
* added from this screen at all, because the row that offers the kinds was six
|
|
112
|
+
* JSX elements somebody had typed out and only five of them had been typed. Every
|
|
113
|
+
* other exhaustiveness guard in this file caught its case; none of them could
|
|
114
|
+
* catch a list maintained by hand.
|
|
115
|
+
*
|
|
116
|
+
* So the row maps {@link WORKFLOW_NODE_KINDS} and looks each kind up here. A new
|
|
117
|
+
* kind now fails to compile in this file until somebody says how it is offered,
|
|
118
|
+
* which is the only way a palette stays complete.
|
|
119
|
+
*
|
|
120
|
+
* The icons match `KIND_STYLE` in `workflow/nodes.tsx` on purpose — the thing you
|
|
121
|
+
* press to make a box should wear the box's own mark — and `if` and `filter` keep
|
|
122
|
+
* the distinction that file argues for: a fork decides which boxes run, a funnel
|
|
123
|
+
* takes rows away. They are the two that must never be confused at a glance, so
|
|
124
|
+
* they never share an icon or a sentence.
|
|
125
|
+
*/
|
|
126
|
+
const ADD_NODE = {
|
|
127
|
+
source: {
|
|
128
|
+
icon: Plug,
|
|
129
|
+
label: 'Source',
|
|
130
|
+
hint: 'Reads records out of a system: a kind, an optional named connection, and a config.',
|
|
131
|
+
},
|
|
132
|
+
transform: {
|
|
133
|
+
icon: Repeat,
|
|
134
|
+
label: 'Transform',
|
|
135
|
+
hint: 'Code that reshapes whatever is wired into it.',
|
|
136
|
+
},
|
|
137
|
+
sink: {
|
|
138
|
+
icon: Database,
|
|
139
|
+
label: 'Sink',
|
|
140
|
+
hint: 'Writes and commits one object type. Several are fine — each commits independently.',
|
|
141
|
+
},
|
|
142
|
+
call: {
|
|
143
|
+
icon: ExternalLink,
|
|
144
|
+
label: 'Call',
|
|
145
|
+
hint: 'Hands this step to a durable workflow that already exists, by name and pinned version. It runs as a child of this load, with its own retries.',
|
|
146
|
+
},
|
|
147
|
+
if: {
|
|
148
|
+
icon: GitBranch,
|
|
149
|
+
label: 'If',
|
|
150
|
+
hint: 'Sends the rows down one of two branches, depending on an environment variable where the load runs. The other branch is skipped — a sink on it commits nothing and leaves what is published alone.',
|
|
151
|
+
},
|
|
152
|
+
filter: {
|
|
153
|
+
icon: Filter,
|
|
154
|
+
label: 'Filter',
|
|
155
|
+
hint: 'Drops the rows that fail a test you write here. Unlike an If, every box still runs — there are simply fewer rows in them from this point on.',
|
|
156
|
+
},
|
|
157
|
+
};
|
|
39
158
|
/**
|
|
40
159
|
* The value the workflow picker uses for "start a fresh one".
|
|
41
160
|
*
|
|
@@ -68,10 +187,14 @@ const ARIA_LABELS = {
|
|
|
68
187
|
'minimap.ariaLabel': `Overview of the ${WORKFLOW_NAME.singular}`,
|
|
69
188
|
};
|
|
70
189
|
function blankDraft() {
|
|
71
|
-
|
|
190
|
+
const empty = { name: '', description: '', nodes: [], edges: [] };
|
|
191
|
+
// A blank canvas has a baseline too, and it is the blank canvas: Reset on a
|
|
192
|
+
// never-saved graph means "clear it", which is exactly what going back to
|
|
193
|
+
// "nothing has been stored" should mean.
|
|
194
|
+
return { ...empty, dirty: false, past: [], baseline: snapshotOf(empty) };
|
|
72
195
|
}
|
|
73
196
|
function draftFrom(workflow) {
|
|
74
|
-
|
|
197
|
+
const loaded = {
|
|
75
198
|
id: workflow.id,
|
|
76
199
|
name: workflow.name,
|
|
77
200
|
description: workflow.description ?? '',
|
|
@@ -92,7 +215,12 @@ function draftFrom(workflow) {
|
|
|
92
215
|
edges: workflow.edges.map((edge) => ({ from: edge.from, to: edge.to })),
|
|
93
216
|
version: workflow.version,
|
|
94
217
|
dirty: false,
|
|
218
|
+
past: [],
|
|
95
219
|
};
|
|
220
|
+
// The baseline holds the SAME arrays the draft starts with, which is what
|
|
221
|
+
// makes undoing all the way back compare equal to it and go genuinely clean.
|
|
222
|
+
// See `sameSnapshot`.
|
|
223
|
+
return { ...loaded, baseline: snapshotOf(loaded) };
|
|
96
224
|
}
|
|
97
225
|
/**
|
|
98
226
|
* Transforms wired to each other, ending at one or more sinks.
|
|
@@ -162,6 +290,30 @@ function newNodeOfKind(kind, id, position, name) {
|
|
|
162
290
|
// threshold would publish happily while testing something nobody chose.
|
|
163
291
|
return { id, name, kind: 'if', predicate: { kind: 'env', envVar: '' }, position };
|
|
164
292
|
}
|
|
293
|
+
if (kind === 'filter') {
|
|
294
|
+
// One empty comparison rather than an empty `all`, and rather than nothing.
|
|
295
|
+
//
|
|
296
|
+
// Nothing is not available: the model has no "no predicate yet" state, on
|
|
297
|
+
// purpose, because a filter whose test is absent has to be given one by
|
|
298
|
+
// somebody and every default is a rule about rows nobody wrote. An empty
|
|
299
|
+
// `all` *is* representable and is refused by the validator, which is exactly
|
|
300
|
+
// why it is not the starting point — a group with no conditions keeps every
|
|
301
|
+
// row, so a filter that started that way would draw as a working node that
|
|
302
|
+
// does nothing.
|
|
303
|
+
//
|
|
304
|
+
// So it starts as one comparison with no column, which the validator refuses
|
|
305
|
+
// by name: the node says "needs a column" on the canvas from the moment it
|
|
306
|
+
// is dropped. The operator defaults to `equals` because it is the only one
|
|
307
|
+
// that is a guess about *form* rather than about data — every other choice
|
|
308
|
+
// implies something about the column's type before a column is chosen.
|
|
309
|
+
return {
|
|
310
|
+
id,
|
|
311
|
+
name,
|
|
312
|
+
kind: 'filter',
|
|
313
|
+
predicate: { kind: 'compare', column: '', operator: 'equals', value: '' },
|
|
314
|
+
position,
|
|
315
|
+
};
|
|
316
|
+
}
|
|
165
317
|
if (kind === 'sink') {
|
|
166
318
|
return { id, name, kind: 'sink', targetType: '', position };
|
|
167
319
|
}
|
|
@@ -511,20 +663,36 @@ function saveHint(blocked, unfinished) {
|
|
|
511
663
|
* list beside the canvas is empty and the real answer is "two boxes are not
|
|
512
664
|
* finished", so that case gets its own sentence and names them.
|
|
513
665
|
*/
|
|
514
|
-
function CanvasActions({ draft, stored, canEdit, blocked, unfinished, saving, running, durabilityDetail, acknowledging, onAcknowledgingChange, onSave, onRun, onLifecycleChange, onAskDelete, }) {
|
|
515
|
-
return (_jsxs("div", { className: "flex flex-wrap items-
|
|
666
|
+
function CanvasActions({ draft, stored, canEdit, blocked, unfinished, saving, running, durabilityDetail, acknowledging, reducedMotion, resetting, onAcknowledgingChange, onResettingChange, onUndo, onReset, onSave, onRun, onLifecycleChange, onAskDelete, }) {
|
|
667
|
+
return (_jsxs("div", { className: "flex flex-wrap items-center gap-1.5", children: [_jsx(HistoryControls, { draft: draft, canEdit: canEdit, reducedMotion: reducedMotion, resetting: resetting, onResettingChange: onResettingChange, onUndo: onUndo, onReset: onReset }), _jsx(Tooltip, { content: saveHint(blocked, unfinished), children: _jsxs(Button, { size: "sm", onClick: onSave, disabled: !canEdit ||
|
|
516
668
|
saving ||
|
|
517
669
|
draft.name.trim().length === 0 ||
|
|
518
|
-
(!draft.dirty && Boolean(draft.id)),
|
|
519
|
-
|
|
520
|
-
|
|
670
|
+
(!draft.dirty && Boolean(draft.id)),
|
|
671
|
+
// The amber is the whole signal — a graph that would never run says so
|
|
672
|
+
// on the button before it is pressed — so it has to survive the
|
|
673
|
+
// variant's own background. `cn` is tailwind-merge, so the later
|
|
674
|
+
// `bg-*` wins rather than fighting.
|
|
675
|
+
className: cn('shrink-0', blocked
|
|
676
|
+
? 'bg-amber-600 text-white hover:bg-amber-500 dark:bg-amber-600 dark:text-white dark:hover:bg-amber-500'
|
|
677
|
+
: 'bg-zinc-950 text-zinc-50 hover:bg-zinc-800 dark:bg-zinc-100 dark:text-zinc-950 dark:hover:bg-zinc-200'), children: [saving ? _jsx(Loader2, { size: 12, className: "animate-spin" }) : _jsx(Save, { size: 12 }), draft.dirty ? 'Save' : 'Saved'] }) }), stored && (_jsx(PublishControls, { workflow: stored, dirty: draft.dirty, canEdit: canEdit, onPublished: onLifecycleChange })), _jsx(RunControls, { workflowId: draft.id, dirty: draft.dirty, canEdit: canEdit, running: running, durabilityDetail: durabilityDetail, acknowledging: acknowledging, onAcknowledgingChange: onAcknowledgingChange, onRun: onRun }), draft.id && canEdit && (_jsx(Tooltip, { content: `Delete this ${WORKFLOW_NAME.singular}, and the connector it runs as with it.`, children: _jsx(Button, { variant: "outline", size: "icon", onClick: onAskDelete, "aria-label": `Delete this ${WORKFLOW_NAME.singular}`, className: "text-zinc-400 hover:text-red-600", children: _jsx(Trash2, { size: 12 }) }) }))] }));
|
|
521
678
|
}
|
|
522
|
-
/**
|
|
679
|
+
/**
|
|
680
|
+
* The tool dock: every kind that can be put on the canvas, and the tidy control.
|
|
681
|
+
*
|
|
682
|
+
* Bottom centre, floating, because it is the one piece of chrome somebody
|
|
683
|
+
* touches continuously while drawing and the bottom edge is where every canvas
|
|
684
|
+
* tool that has ever been good keeps its tools. It is also the only corner React
|
|
685
|
+
* Flow's own overlays do not claim.
|
|
686
|
+
*
|
|
687
|
+
* The kinds come from {@link WORKFLOW_NODE_KINDS} through {@link ADD_NODE}, so
|
|
688
|
+
* the dock cannot fall behind the model — see the note on `ADD_NODE` for the bug
|
|
689
|
+
* that made that necessary.
|
|
690
|
+
*/
|
|
523
691
|
function AddNodeBar({ refreshing, onAdd, onTidy, }) {
|
|
524
|
-
return (_jsxs("div", { className:
|
|
692
|
+
return (_jsxs("div", { className: cn('pointer-events-auto flex max-w-full items-center gap-1 overflow-x-auto p-1.5', FLOATING), children: [WORKFLOW_NODE_KINDS.map((kind) => (_jsx(AddButton, { kind: kind, onClick: () => onAdd(kind) }, kind))), _jsx("span", { className: cn('mx-1 h-6 w-px shrink-0 bg-zinc-200 dark:bg-zinc-800'), "aria-hidden": true }), _jsx(Tooltip, { content: "Lay the nodes out left to right by dependency, with every sink in the last column.", children: _jsxs(Button, { variant: "ghost", size: "sm", onClick: onTidy, "aria-label": "Tidy the layout", className: "shrink-0", children: [_jsx(LayoutGrid, { size: 12 }), _jsx("span", { className: "hidden md:inline", children: "Tidy" })] }) }), refreshing && (
|
|
525
693
|
// A background refetch says so without replacing anything: the graph on
|
|
526
694
|
// screen stays exactly where it is.
|
|
527
|
-
_jsx("span", { className: cn('
|
|
695
|
+
_jsx("span", { className: cn('shrink-0 px-1 font-mono text-[10px]', MUTED), children: "refreshing\u2026" }))] }));
|
|
528
696
|
}
|
|
529
697
|
/**
|
|
530
698
|
* Which workflow the screen should be showing.
|
|
@@ -567,6 +735,12 @@ function miniMapColor(data) {
|
|
|
567
735
|
// a graph too big to read, so it is the one place the two must not blur.
|
|
568
736
|
if (kind === 'if')
|
|
569
737
|
return '#d946ef';
|
|
738
|
+
// Rose-500, the filter's own accent (see `KIND_STYLE`), and specifically not
|
|
739
|
+
// the fuchsia beside it: the overview is where somebody looks for "where do
|
|
740
|
+
// rows disappear in this graph", and a gate and a filter are the two boxes
|
|
741
|
+
// that answer that question in completely different ways.
|
|
742
|
+
if (kind === 'filter')
|
|
743
|
+
return '#f43f5e';
|
|
570
744
|
return '#8b5cf6';
|
|
571
745
|
}
|
|
572
746
|
/**
|
|
@@ -576,8 +750,25 @@ function miniMapColor(data) {
|
|
|
576
750
|
* place of the screen, so the header and its controls stay put while a refetch
|
|
577
751
|
* resolves — and a failed read never looks like an empty workflow.
|
|
578
752
|
*/
|
|
579
|
-
function GraphSurface({ loading, failed, error, onRetry, canEdit, draft, flowNodes, flowEdges, onInspect, onEditCode, onNodesChange, onEdgesChange, onConnect, isValidConnection, onConnectEnd, onNodeEnter, onNodeLeave, onPaneClick, onDisconnect, wiring, wiringRefusal, nodeMenu, }) {
|
|
580
|
-
|
|
753
|
+
function GraphSurface({ loading, failed, error, onRetry, canEdit, draft, flowNodes, flowEdges, onInspect, onEditCode, onNodesChange, onEdgesChange, onConnect, isValidConnection, onConnectEnd, onNodeEnter, onNodeLeave, onPaneClick, onDisconnect, wiring, wiringRefusal, nodeMenu, fitPadding, }) {
|
|
754
|
+
/*
|
|
755
|
+
* Memoised because they are context values read by every node and every edge
|
|
756
|
+
* on the canvas. Written inline, as they were, each of these was a fresh
|
|
757
|
+
* object on every render of the screen — and this screen now re-renders for
|
|
758
|
+
* things the graph does not care about, like opening the rail. A new context
|
|
759
|
+
* value re-renders every consumer, which on a large graph is every box and
|
|
760
|
+
* every wire, for a panel sliding in at the side.
|
|
761
|
+
*/
|
|
762
|
+
const nodeHandlers = useMemo(() => ({ onInspect, onEditCode, canEdit, wiring }), [onInspect, onEditCode, canEdit, wiring]);
|
|
763
|
+
const edgeHandlers = useMemo(() => ({ onDisconnect, canEdit }), [onDisconnect, canEdit]);
|
|
764
|
+
return (
|
|
765
|
+
/*
|
|
766
|
+
* The surface IS the screen: pinned to all four edges, with the chrome
|
|
767
|
+
* layered over it by a sibling. Nothing here is a box in a column any more,
|
|
768
|
+
* so there is no border and no rounded corner — a full-bleed canvas that
|
|
769
|
+
* draws its own frame is a canvas pretending to still be a widget.
|
|
770
|
+
*/
|
|
771
|
+
_jsxs("div", { className: "absolute inset-0", children: [loading && _jsx(CanvasSkeleton, {}), failed && _jsx(CanvasFailure, { error: error, onRetry: onRetry }), !loading && !failed && (_jsx(WorkflowNodeProvider, { handlers: nodeHandlers, children: _jsx(WorkflowEdgeProvider, { handlers: edgeHandlers, children: _jsxs(ReactFlow, { className: CANVAS_THEME, nodes: flowNodes, edges: flowEdges, nodeTypes: workflowNodeTypes, edgeTypes: workflowEdgeTypes, onNodesChange: onNodesChange, onEdgesChange: onEdgesChange, onConnect: onConnect, isValidConnection: isValidConnection, onConnectEnd: onConnectEnd, onNodeMouseEnter: (_event, node) => onNodeEnter(node.id), onNodeMouseLeave: onNodeLeave, onPaneClick: onPaneClick, connectionLineType: ConnectionLineType.SmoothStep,
|
|
581
772
|
// Off, so there is exactly ONE click path through a handle and it
|
|
582
773
|
// is the one in `workflow/wiring.tsx`. React Flow's own click
|
|
583
774
|
// wiring connects but draws nothing while it is open and cannot
|
|
@@ -587,7 +778,14 @@ function GraphSurface({ loading, failed, error, onRetry, canEdit, draft, flowNod
|
|
|
587
778
|
// A wider drop zone than the 20px default, because these handles are
|
|
588
779
|
// the only drop target on the screen and missing one reads as the
|
|
589
780
|
// canvas ignoring you.
|
|
590
|
-
connectionRadius: 28, proOptions: { hideAttribution: false }, ariaLabelConfig: ARIA_LABELS, "aria-label": `${WORKFLOW_NAME.title} canvas. ${draft.nodes.length} nodes, ${draft.edges.length} connections.`, fitView: true, children: [_jsx(Background, { variant: BackgroundVariant.Dots, gap: 18, size: 1 }), _jsx(Controls, { showInteractive: false,
|
|
781
|
+
connectionRadius: 28, proOptions: { hideAttribution: false }, ariaLabelConfig: ARIA_LABELS, "aria-label": `${WORKFLOW_NAME.title} canvas. ${draft.nodes.length} nodes, ${draft.edges.length} connections.`, fitView: true, fitViewOptions: { padding: fitPadding }, children: [_jsx(Background, { variant: BackgroundVariant.Dots, gap: 18, size: 1 }), _jsx(Controls, { showInteractive: false, position: "bottom-left", className: cn('!bottom-[9.5rem] !overflow-hidden !rounded-lg !border !border-zinc-200', '!shadow-sm dark:!border-zinc-800 [&>button]:!border-none',
|
|
782
|
+
// Below `lg` the minimap is gone, so the zoom controls drop
|
|
783
|
+
// back down into the corner it vacated.
|
|
784
|
+
'!bottom-0 lg:!bottom-[9.5rem]') }), _jsx(MiniMap, { pannable: true, zoomable: true, position: "bottom-left", nodeColor: (node) => miniMapColor(node.data),
|
|
785
|
+
// An overview is worth least on the screen with least room for
|
|
786
|
+
// it: below `lg` it would cover a sixth of the canvas to
|
|
787
|
+
// describe the other five.
|
|
788
|
+
className: cn('!hidden lg:!block', '!overflow-hidden !rounded-lg !border !border-zinc-200 !shadow-sm dark:!border-zinc-800') }), _jsx(PendingWireLine, { pending: wiring.pending }), _jsx(WiringHint, { pending: wiring.pending, refusal: wiringRefusal, nodes: draft.nodes, onCancel: wiring.cancel }), nodeMenu] }) }) }))] }));
|
|
591
789
|
}
|
|
592
790
|
/**
|
|
593
791
|
* The wiring control that lives on a node, and the menu behind it.
|
|
@@ -869,7 +1067,50 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
869
1067
|
const [inspecting, setInspecting] = useState(null);
|
|
870
1068
|
const [editingCodeFor, setEditingCodeFor] = useState(null);
|
|
871
1069
|
const [confirmingDelete, setConfirmingDelete] = useState(false);
|
|
1070
|
+
/**
|
|
1071
|
+
* Whether the "throw away every unsaved edit" dialog is open.
|
|
1072
|
+
*
|
|
1073
|
+
* Held here rather than inside the controls because Reset is destructive of
|
|
1074
|
+
* work in exactly the way deleting the workflow is destructive of the
|
|
1075
|
+
* workflow, and this screen keeps every "are you sure" at the level that owns
|
|
1076
|
+
* the thing being destroyed.
|
|
1077
|
+
*/
|
|
1078
|
+
const [resetting, setResetting] = useState(false);
|
|
872
1079
|
const [run, setRun] = useState(null);
|
|
1080
|
+
/**
|
|
1081
|
+
* Whether the details rail is on screen.
|
|
1082
|
+
*
|
|
1083
|
+
* Open by default where there is room for it, and that default is the answer
|
|
1084
|
+
* to "the problems have to stay visible": they are visible, in full, from the
|
|
1085
|
+
* first paint on any screen that can afford 19rem. Closing it is a choice
|
|
1086
|
+
* somebody makes to get the room back, and the toggle then carries the problem
|
|
1087
|
+
* count so the *fact* of a problem never depends on the panel being open.
|
|
1088
|
+
*
|
|
1089
|
+
* Read once, from the width at mount, rather than subscribed to. A live media
|
|
1090
|
+
* query would reopen a panel somebody had just closed because they turned
|
|
1091
|
+
* their tablet, which is worse than the panel being open on a narrow screen
|
|
1092
|
+
* they can shut it on. `globalThis.innerWidth` guards the case where there is
|
|
1093
|
+
* no window at all — this component is rendered on a server by anybody using
|
|
1094
|
+
* SSR, and a bare `window` there is a crash rather than a layout bug.
|
|
1095
|
+
*/
|
|
1096
|
+
const [railOpen, setRailOpen] = useState(railOpenByDefault);
|
|
1097
|
+
/**
|
|
1098
|
+
* The region of the viewport the graph should be fitted into.
|
|
1099
|
+
*
|
|
1100
|
+
* See {@link CHROME}. The right edge is the only side that moves, because the
|
|
1101
|
+
* rail is the only panel that comes and goes.
|
|
1102
|
+
*
|
|
1103
|
+
* Declared up here with the state rather than beside its use, because both
|
|
1104
|
+
* `fitView` call sites below name it in a dependency array — and a `const` read
|
|
1105
|
+
* by a hook that runs earlier in the body is a temporal-dead-zone crash, not a
|
|
1106
|
+
* lint warning.
|
|
1107
|
+
*
|
|
1108
|
+
* Toggling the rail deliberately does NOT re-fit. That would throw away a
|
|
1109
|
+
* viewport somebody had panned to, in response to an action about a panel; the
|
|
1110
|
+
* new padding applies at the next fit that was going to happen anyway —
|
|
1111
|
+
* opening a graph, or pressing Tidy.
|
|
1112
|
+
*/
|
|
1113
|
+
const fitPadding = useMemo(() => chromeFitPadding(railOpen), [railOpen]);
|
|
873
1114
|
/**
|
|
874
1115
|
* Whether the "this load is expected to shrink" dialog is open.
|
|
875
1116
|
*
|
|
@@ -952,13 +1193,32 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
952
1193
|
// `draftId` is the trigger, not a value the body reads — which is exactly why
|
|
953
1194
|
// the rule calls it unnecessary. Dropping it would fit the view once on mount
|
|
954
1195
|
// and never again, leaving every workflow opened afterwards off-screen.
|
|
955
|
-
//
|
|
1196
|
+
// `fitPadding` is read by the body but deliberately kept OUT of the deps: it
|
|
1197
|
+
// changes when the rail is toggled, and re-fitting there would yank the
|
|
1198
|
+
// viewport away from wherever somebody had panned to, as the side effect of
|
|
1199
|
+
// opening a panel. The padding it fits with is whatever is current at the next
|
|
1200
|
+
// graph swap, which is the moment a fit is wanted.
|
|
1201
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: draftId is what the effect watches for, not something its body uses; fitPadding is read but must not re-trigger it
|
|
956
1202
|
useEffect(() => {
|
|
957
|
-
const frame = window.requestAnimationFrame(() => fitView({ padding:
|
|
1203
|
+
const frame = window.requestAnimationFrame(() => fitView({ padding: fitPadding, duration: 200 }));
|
|
958
1204
|
return () => window.cancelAnimationFrame(frame);
|
|
959
1205
|
}, [draftId, fitView]);
|
|
960
|
-
|
|
961
|
-
|
|
1206
|
+
/**
|
|
1207
|
+
* Every change to the drawing, through one door — and every one of them
|
|
1208
|
+
* recorded so it can be taken back.
|
|
1209
|
+
*
|
|
1210
|
+
* The action is REQUIRED rather than optional, which is the only thing keeping
|
|
1211
|
+
* the undo announcement honest: a default would let a new call site add an
|
|
1212
|
+
* entry that reverts something and says nothing about what.
|
|
1213
|
+
*
|
|
1214
|
+
* It may be a function of the current draft, for the labels that need to name
|
|
1215
|
+
* a node. Computing those here would mean this callback depends on
|
|
1216
|
+
* `draft.nodes` and is rebuilt on every graph change, which React Flow feels;
|
|
1217
|
+
* computing them inside the updater keeps the dependency list empty and keeps
|
|
1218
|
+
* the whole thing pure.
|
|
1219
|
+
*/
|
|
1220
|
+
const edit = useCallback((change, action) => {
|
|
1221
|
+
setDraft((current) => withEdit(current, change(current), typeof action === 'function' ? action(current) : action));
|
|
962
1222
|
}, []);
|
|
963
1223
|
const transformIds = useMemo(() => new Set(transforms.map((transform) => transform.id)), [transforms]);
|
|
964
1224
|
/**
|
|
@@ -1037,6 +1297,11 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
1037
1297
|
const { positions, removed } = nodeMovesAndRemovals(changes);
|
|
1038
1298
|
if (positions.size === 0 && removed.size === 0)
|
|
1039
1299
|
return;
|
|
1300
|
+
// The drag's own answer to "is this still one gesture". React Flow sets it
|
|
1301
|
+
// on every frame while the pointer is down and clears it on the frame that
|
|
1302
|
+
// drops the node, so a drag across the canvas is one undo step however
|
|
1303
|
+
// many hundred position changes it emitted and however long it took.
|
|
1304
|
+
const dragging = changes.some((change) => change.type === 'position' && change.dragging === true);
|
|
1040
1305
|
edit((current) => ({
|
|
1041
1306
|
...current,
|
|
1042
1307
|
nodes: current.nodes
|
|
@@ -1049,7 +1314,16 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
1049
1314
|
// would produce edges pointing at nothing, which React Flow silently
|
|
1050
1315
|
// drops from the canvas while the save still sends them.
|
|
1051
1316
|
edges: current.edges.filter((edge) => !removed.has(edge.from) && !removed.has(edge.to)),
|
|
1052
|
-
}))
|
|
1317
|
+
}), (current) => removed.size > 0
|
|
1318
|
+
? // A deletion is never folded into a move: it is the one change on
|
|
1319
|
+
// this canvas somebody is most likely to want back, and it must
|
|
1320
|
+
// not disappear into the drag that happened just before it.
|
|
1321
|
+
{ label: `deleting ${namesOf(current.nodes, removed)}` }
|
|
1322
|
+
: {
|
|
1323
|
+
label: `moving ${namesOf(current.nodes, positions.keys())}`,
|
|
1324
|
+
run: 'move',
|
|
1325
|
+
continuing: dragging,
|
|
1326
|
+
});
|
|
1053
1327
|
if (removed.size > 0) {
|
|
1054
1328
|
// Housekeeping, not a rule: a node that no longer exists cannot be
|
|
1055
1329
|
// unfinished, and leaving its id behind would hold back a later node
|
|
@@ -1066,7 +1340,9 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
1066
1340
|
edit((current) => ({
|
|
1067
1341
|
...current,
|
|
1068
1342
|
edges: current.edges.filter((edge) => !removed.has(edgeId(edge))),
|
|
1069
|
-
})
|
|
1343
|
+
}), {
|
|
1344
|
+
label: `removing ${removed.size} connection${removed.size === 1 ? '' : 's'}`,
|
|
1345
|
+
});
|
|
1070
1346
|
setAnnouncement(`${removed.size} connection${removed.size === 1 ? '' : 's'} removed.`);
|
|
1071
1347
|
}, [edit]);
|
|
1072
1348
|
/**
|
|
@@ -1109,6 +1385,8 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
1109
1385
|
edit((current) => ({
|
|
1110
1386
|
...current,
|
|
1111
1387
|
edges: current.edges.filter((candidate) => edgeId(candidate) !== id),
|
|
1388
|
+
}), (current) => ({
|
|
1389
|
+
label: `disconnecting ${namesOf(current.nodes, [edge.from])} from ${namesOf(current.nodes, [edge.to])}`,
|
|
1112
1390
|
}));
|
|
1113
1391
|
markStarted(edge.from, edge.to);
|
|
1114
1392
|
setAnnouncement('Connection removed.');
|
|
@@ -1122,7 +1400,9 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
1122
1400
|
* can make here: it inverts which half of the pipeline runs.
|
|
1123
1401
|
*/
|
|
1124
1402
|
const setBranch = useCallback((edge, branch) => {
|
|
1125
|
-
edit((current) => ({ ...current, edges: edgeOnBranch(current.edges, edge, branch) }))
|
|
1403
|
+
edit((current) => ({ ...current, edges: edgeOnBranch(current.edges, edge, branch) }), (current) => ({
|
|
1404
|
+
label: `putting ${namesOf(current.nodes, [edge.to])} on the "${branch}" branch`,
|
|
1405
|
+
}));
|
|
1126
1406
|
markStarted(edge.from, edge.to);
|
|
1127
1407
|
setAnnouncement(`${nodeLabelIn(draft.nodes, edge.to)} is now on the "${branch}" branch of ${nodeLabelIn(draft.nodes, edge.from)}.`);
|
|
1128
1408
|
}, [draft.nodes, edit, markStarted]);
|
|
@@ -1138,6 +1418,8 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
1138
1418
|
edit((current) => ({
|
|
1139
1419
|
...current,
|
|
1140
1420
|
edges: [...current.edges, newEdge(current.nodes, current.edges, from, to)],
|
|
1421
|
+
}), (current) => ({
|
|
1422
|
+
label: `connecting ${namesOf(current.nodes, [from])} to ${namesOf(current.nodes, [to])}`,
|
|
1141
1423
|
}));
|
|
1142
1424
|
markStarted(from, to);
|
|
1143
1425
|
setAnnouncement(`${nodeLabelIn(draft.nodes, from)} now feeds ${nodeLabelIn(draft.nodes, to)}.`);
|
|
@@ -1223,6 +1505,11 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
1223
1505
|
mutationFn: ({ id, options }) => client.runWorkflow(id, options),
|
|
1224
1506
|
onSuccess: (result) => {
|
|
1225
1507
|
setRun(result);
|
|
1508
|
+
// The answer to a run is written in the rail, so a run that finishes while
|
|
1509
|
+
// the rail is put away would report itself into a panel nobody can see.
|
|
1510
|
+
// Pressing Run is the clearest possible statement that somebody wants the
|
|
1511
|
+
// outcome, so this is the one place the screen opens it on their behalf.
|
|
1512
|
+
setRailOpen(true);
|
|
1226
1513
|
// A run writes rows, so the catalog snapshot every other screen reads is
|
|
1227
1514
|
// now stale. Invalidating it here is what stops the object explorer
|
|
1228
1515
|
// showing yesterday's counts beside a run that just finished.
|
|
@@ -1274,6 +1561,12 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
1274
1561
|
edit((current) => ({
|
|
1275
1562
|
...current,
|
|
1276
1563
|
nodes: runningTransform(current.nodes, nodeId, created.id),
|
|
1564
|
+
}),
|
|
1565
|
+
// Only the half of this that lives in the draft. The transform itself
|
|
1566
|
+
// was created on the server and stays there — undoing this unpicks the
|
|
1567
|
+
// node from it, which is the part of the act this canvas owns.
|
|
1568
|
+
(current) => ({
|
|
1569
|
+
label: `pointing ${namesOf(current.nodes, [nodeId])} at "${created.name}"`,
|
|
1277
1570
|
}));
|
|
1278
1571
|
markStarted(nodeId);
|
|
1279
1572
|
// Written into the cache as well as invalidated: the code sheet below
|
|
@@ -1300,14 +1593,14 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
1300
1593
|
});
|
|
1301
1594
|
const addNode = useCallback((kind) => {
|
|
1302
1595
|
const id = newLocalId(kind);
|
|
1303
|
-
|
|
1596
|
+
edit((current) => {
|
|
1304
1597
|
const node = newNodeOfKind(kind, id, nextPosition(current.nodes), uniqueName(current.nodes, kind));
|
|
1305
|
-
return { ...current, nodes: [...current.nodes, node]
|
|
1306
|
-
});
|
|
1598
|
+
return { ...current, nodes: [...current.nodes, node] };
|
|
1599
|
+
}, { label: `adding a ${kind} node` });
|
|
1307
1600
|
setUnstarted((current) => new Set([...current, id]));
|
|
1308
1601
|
setInspecting(id);
|
|
1309
1602
|
setAnnouncement(`A ${kind} node was added. Its inspector is open.`);
|
|
1310
|
-
}, []);
|
|
1603
|
+
}, [edit]);
|
|
1311
1604
|
/**
|
|
1312
1605
|
* Make the next node and wire it in, as one action.
|
|
1313
1606
|
*
|
|
@@ -1337,7 +1630,11 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
1337
1630
|
...current,
|
|
1338
1631
|
nodes: [...current.nodes, node],
|
|
1339
1632
|
edges: [...current.edges, newEdge(current.nodes, current.edges, fromId, node.id)],
|
|
1340
|
-
})
|
|
1633
|
+
}),
|
|
1634
|
+
// ONE entry, for two graph changes. The node and the wire are a single
|
|
1635
|
+
// gesture — "put the next box here" — and undoing them separately would
|
|
1636
|
+
// leave a node somebody never asked for on its own on the canvas.
|
|
1637
|
+
{ label: `adding ${nodeName(node)} wired from ${nodeName(from)}` });
|
|
1341
1638
|
setUnstarted((current) => new Set([...current, node.id]));
|
|
1342
1639
|
menu.close();
|
|
1343
1640
|
setInspecting(node.id);
|
|
@@ -1347,10 +1644,63 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
1347
1644
|
edit((current) => ({
|
|
1348
1645
|
...current,
|
|
1349
1646
|
nodes: layout(current.nodes, current.edges),
|
|
1350
|
-
})
|
|
1351
|
-
|
|
1647
|
+
}),
|
|
1648
|
+
// One entry, and a big one: Tidy moves every node at once, and it is
|
|
1649
|
+
// precisely the control somebody presses on a layout they had arranged by
|
|
1650
|
+
// hand and then wants back.
|
|
1651
|
+
{ label: 'tidying the layout' });
|
|
1652
|
+
window.requestAnimationFrame(() => fitView({ padding: fitPadding, duration: 200 }));
|
|
1352
1653
|
setAnnouncement('The nodes were laid out left to right by dependency, with every sink in the last column.');
|
|
1353
|
-
}, [edit, fitView]);
|
|
1654
|
+
}, [edit, fitView, fitPadding]);
|
|
1655
|
+
/**
|
|
1656
|
+
* One action back.
|
|
1657
|
+
*
|
|
1658
|
+
* Announced with the name of what it took back, because undo is the one
|
|
1659
|
+
* control here whose effect is routinely invisible: the node it just put back
|
|
1660
|
+
* may be off screen, and a revert nobody can see is indistinguishable from a
|
|
1661
|
+
* button that did nothing.
|
|
1662
|
+
*
|
|
1663
|
+
* The step is computed out here rather than inside the updater so the label is
|
|
1664
|
+
* available to say — and so nothing sets state from inside a `setState`
|
|
1665
|
+
* updater, which React is free to replay.
|
|
1666
|
+
*/
|
|
1667
|
+
const undo = useCallback(() => {
|
|
1668
|
+
const step = undone(draft);
|
|
1669
|
+
if (!step) {
|
|
1670
|
+
setAnnouncement('There is nothing to take back — this drawing is as it was loaded.');
|
|
1671
|
+
return;
|
|
1672
|
+
}
|
|
1673
|
+
setDraft(step.draft);
|
|
1674
|
+
// The inspector is open on a node that may have just stopped existing, and
|
|
1675
|
+
// a sheet describing a deleted node is worse than no sheet.
|
|
1676
|
+
setInspecting((current) => current && step.draft.nodes.some((node) => node.id === current) ? current : null);
|
|
1677
|
+
setUnstarted((current) => keepKnown(current, step.draft.nodes));
|
|
1678
|
+
const left = step.draft.past.length;
|
|
1679
|
+
setAnnouncement(`Undone: ${step.label}. ${left === 0 ? 'Nothing left to take back.' : `${left} ${left === 1 ? 'action' : 'actions'} left to take back.`}`);
|
|
1680
|
+
}, [draft]);
|
|
1681
|
+
/**
|
|
1682
|
+
* All the way back to the version the server last stored.
|
|
1683
|
+
*
|
|
1684
|
+
* Deliberately NOT "undo until the stack is empty". Save halfway through a
|
|
1685
|
+
* session and the baseline moves to that save, so this returns to the saved
|
|
1686
|
+
* v2 — whereas undoing forty times would walk straight past it back to the v1
|
|
1687
|
+
* the tab was opened on. Which of the two somebody means by "reset" is not in
|
|
1688
|
+
* doubt, and the confirmation says which one this is.
|
|
1689
|
+
*/
|
|
1690
|
+
const reset = useCallback(() => {
|
|
1691
|
+
const back = reverted(draft);
|
|
1692
|
+
setDraft(back);
|
|
1693
|
+
setResetting(false);
|
|
1694
|
+
setInspecting(null);
|
|
1695
|
+
setSelectedNodeIds([]);
|
|
1696
|
+
setSelectedEdgeIds([]);
|
|
1697
|
+
setUnstarted(new Set());
|
|
1698
|
+
setAnnouncement(draft.id
|
|
1699
|
+
? `Reset. The drawing is back to v${draft.version ?? 1}, as the server stored it. Nothing on the server was changed.`
|
|
1700
|
+
: 'Reset. The canvas is empty again, which is where this unsaved workflow started.');
|
|
1701
|
+
}, [draft]);
|
|
1702
|
+
useUndoShortcut({ enabled: canEdit, onUndo: undo, onSay: setAnnouncement });
|
|
1703
|
+
useUnsavedGuard(draft.dirty);
|
|
1354
1704
|
const durability = describeDurability(capabilities?.durable);
|
|
1355
1705
|
// Asked about EVERY problem, not about `live`. This is the guarantee: a graph
|
|
1356
1706
|
// that would silently do nothing is coloured as unsaveable from the moment it
|
|
@@ -1453,29 +1803,45 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
1453
1803
|
}), [client]);
|
|
1454
1804
|
return (
|
|
1455
1805
|
/*
|
|
1456
|
-
*
|
|
1457
|
-
*
|
|
1806
|
+
* THE CANVAS IS THE SCREEN.
|
|
1807
|
+
*
|
|
1808
|
+
* One positioned box filling whatever the host gives it, with exactly two
|
|
1809
|
+
* layers in it: the graph, pinned to all four edges, and the chrome floating
|
|
1810
|
+
* over the graph. Nothing is in normal flow and nothing scrolls — a
|
|
1811
|
+
* full-bleed canvas that can be scrolled away from is a canvas that is not
|
|
1812
|
+
* actually the screen.
|
|
1813
|
+
*
|
|
1814
|
+
* What that buys, and it is the whole point: the drawing surface is now the
|
|
1815
|
+
* entire viewport instead of the ~55% left over after a header, a button row
|
|
1816
|
+
* and a column of panels had taken their share.
|
|
1458
1817
|
*
|
|
1459
|
-
*
|
|
1460
|
-
*
|
|
1461
|
-
*
|
|
1462
|
-
*
|
|
1463
|
-
*
|
|
1464
|
-
*
|
|
1465
|
-
*
|
|
1818
|
+
* What it costs is occlusion — a panel over the canvas covers graph. Three
|
|
1819
|
+
* things pay that back. The chrome is compact and translucent, so what is
|
|
1820
|
+
* behind it stays perceptible. Everything permanent is either an
|
|
1821
|
+
* always-needed control or dismissible. And `fitView` is given the chrome's
|
|
1822
|
+
* own insets (see `CHROME`), so the graph is fitted into the region nothing
|
|
1823
|
+
* covers rather than into the raw viewport — which is what stops a node
|
|
1824
|
+
* being centred underneath the action cluster.
|
|
1466
1825
|
*/
|
|
1467
|
-
_jsxs("div", { className: "
|
|
1826
|
+
_jsxs("div", { className: "relative h-full min-h-0 w-full overflow-hidden", children: [_jsxs("div", { className: "pointer-events-none absolute inset-0 z-20 flex flex-col gap-3 p-3 sm:p-4", children: [_jsxs("div", { className: "flex flex-wrap items-start justify-between gap-3", children: [_jsx(WorkflowCard, { eyebrow: eyebrow, title: title, intro: intro, stored: stored, produces: produces, durability: durability, selected: selected, workflowOptions: workflowOptions, workflowsPending: workflows.isPending, draftName: draft.name, canEdit: canEdit, onSelect: (value) => {
|
|
1468
1827
|
loadedRef.current = null;
|
|
1469
1828
|
setSelected(value);
|
|
1470
|
-
},
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1829
|
+
},
|
|
1830
|
+
// Typing is one action, not one per keystroke: consecutive edits
|
|
1831
|
+
// sharing the `rename` run fold together while the run is open. See
|
|
1832
|
+
// `RUN_WINDOW_MS`.
|
|
1833
|
+
onRename: (name) => edit((current) => ({ ...current, name }), {
|
|
1834
|
+
label: 'renaming this workflow',
|
|
1835
|
+
run: 'rename',
|
|
1836
|
+
}) }), _jsxs("div", { className: "flex max-w-full flex-col items-end gap-2", children: [_jsxs("div", { className: cn('pointer-events-auto flex items-start gap-2 p-1.5', FLOATING), children: [_jsx(CanvasActions, { draft: draft, stored: stored, canEdit: canEdit, blocked: blocked, unfinished: unfinished, saving: save.isPending, running: runIt.isPending, durabilityDetail: durability.detail, acknowledging: acknowledging, reducedMotion: reducedMotion, resetting: resetting, onAcknowledgingChange: setAcknowledging, onResettingChange: setResetting, onUndo: undo, onReset: reset, onSave: saveNow, onRun: runNow, onLifecycleChange: onLifecycleChange, onAskDelete: () => setConfirmingDelete(true) }), _jsx("span", { className: "h-6 w-px shrink-0 bg-zinc-200 dark:bg-zinc-800", "aria-hidden": true }), _jsx(RailToggle, { open: railOpen, problems: live, onToggle: () => setRailOpen((o) => !o) })] }), _jsxs("div", { className: "pointer-events-auto w-[min(26rem,100%)] empty:hidden", children: [save.error && _jsx(RefusalNote, { lead: "The server refused it:", error: save.error }), runIt.error && _jsx(RefusalNote, { lead: "The run could not start:", error: runIt.error }), _jsx(ShrinkRefusalNote, { run: run, error: runIt.error, onAcknowledge: () => setAcknowledging(true) })] })] })] }), canEdit && (_jsx("div", { className: "absolute inset-x-0 bottom-3 flex justify-center px-3 sm:bottom-4 sm:px-4", children: _jsx(AddNodeBar, { refreshing: workflows.isFetching && !workflows.isPending, onAdd: addNode, onTidy: tidy }) })), _jsx("div", { className: "flex min-h-0 flex-1 justify-end pb-14", children: _jsx(AnimatePresence, { initial: false, children: railOpen && (_jsx(WiringRail, { draft: draft, problems: live, pending: pending, run: run, canEdit: canEdit, reducedMotion: reducedMotion, onInspect: setInspecting, onDisconnect: disconnect, onClose: () => setRailOpen(false), children: stored && (_jsxs(_Fragment, { children: [_jsx(SchedulePanel, { workflow: stored, canEdit: canEdit, onScheduled: onLifecycleChange }, stored.id), _jsx(RunsAsPanel, { workflowId: stored.id, status: stored.status, transforms: graphTransforms })] })) })) }) })] }), _jsx(GraphSurface, { loading: workflows.isPending, failed: workflows.isError, error: workflows.error, onRetry: () => workflows.refetch(), canEdit: canEdit, draft: draft, flowNodes: flowNodes, flowEdges: flowEdges, onInspect: setInspecting, onEditCode: setEditingCodeFor, onNodesChange: onNodesChange, onEdgesChange: onEdgesChange, onConnect: onConnect, isValidConnection: isValidConnection, onConnectEnd: announceRefusedDrop, onNodeEnter: menu.onNodeEnter, onNodeLeave: menu.onNodeLeave,
|
|
1837
|
+
// Clicking empty canvas puts away everything that is half-open: the
|
|
1838
|
+
// wiring menu, and a wire that was started and never landed. React
|
|
1839
|
+
// Flow only fires this for clicks on the pane ITSELF, so finishing a
|
|
1840
|
+
// wire on a handle does not also cancel it on the way past.
|
|
1841
|
+
onPaneClick: () => {
|
|
1842
|
+
menu.close();
|
|
1843
|
+
wiring.cancel();
|
|
1844
|
+
}, onDisconnect: disconnect, wiring: wiring, wiringRefusal: wiringRefusal, nodeMenu: _jsx(NodeWiringMenu, { node: menu.anchor, draft: draft, canEdit: canEdit, open: menu.open, onOpenChange: menu.onOpenChange, onHoverChange: menu.onHoverChange, onConnect: connect, onConnectToNew: connectToNew, onDisconnect: disconnect }), fitPadding: fitPadding }), workflows.isSuccess && workflows.data.length === 0 && _jsx(NothingDrawnYet, {}), _jsx("output", { "aria-live": "polite", className: "sr-only", children: announcement }), _jsx(NodeInspector, { node: inspectingNode, draft: draft, transforms: transforms, connections: connections, typeOptions: typeOptions, canEdit: canEdit, modelHref: modelHref, problems: problemsOf(problemsFor, inspectingNode), pending: problemsOf(pendingFor, inspectingNode), discovery: discovery, discoverable: { ...discoveryTarget(draft), onSave: saveNow, saving: save.isPending }, onDiscovered: rememberShape, onClose: () => setInspecting(null), onChange: (next) => {
|
|
1479
1845
|
// Editing any field is the clearest statement there is that somebody
|
|
1480
1846
|
// is working on this node rather than looking at one they just made.
|
|
1481
1847
|
markStarted(next.id);
|
|
@@ -1491,19 +1857,20 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
1491
1857
|
// updater below: an updater is called again on every re-render React
|
|
1492
1858
|
// decides to replay, and a `setState` in one is a side effect that
|
|
1493
1859
|
// would fire with it.
|
|
1494
|
-
|
|
1860
|
+
const before = draft.nodes.find((node) => node.id === next.id);
|
|
1861
|
+
if (readsDifferently(before, next)) {
|
|
1495
1862
|
forgetShape(next.id);
|
|
1496
1863
|
}
|
|
1497
1864
|
edit((current) => ({
|
|
1498
1865
|
...current,
|
|
1499
1866
|
nodes: current.nodes.map((node) => (node.id === next.id ? next : node)),
|
|
1500
|
-
}));
|
|
1867
|
+
}), nodeEditAction(before, next));
|
|
1501
1868
|
}, onConnect: connect, onConnectToNew: connectToNew, onDisconnect: disconnect, onBranch: setBranch, onCreateTransform: (nodeId) => createTransform.mutate(nodeId), creatingTransform: createTransform.isPending, createTransformError: createTransform.error, onDelete: (nodeId) => {
|
|
1502
1869
|
edit((current) => ({
|
|
1503
1870
|
...current,
|
|
1504
1871
|
nodes: current.nodes.filter((node) => node.id !== nodeId),
|
|
1505
1872
|
edges: current.edges.filter((edge) => edge.from !== nodeId && edge.to !== nodeId),
|
|
1506
|
-
}));
|
|
1873
|
+
}), (current) => ({ label: `deleting ${namesOf(current.nodes, [nodeId])}` }));
|
|
1507
1874
|
setInspecting(null);
|
|
1508
1875
|
setAnnouncement('Node removed, along with its connections.');
|
|
1509
1876
|
}, onEditCode: (nodeId) => setEditingCodeFor(nodeId) }), _jsx(Sheet, { open: editingCodeFor !== null, onOpenChange: (open) => {
|
|
@@ -1516,8 +1883,21 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
1516
1883
|
});
|
|
1517
1884
|
} })) : (_jsx("p", { className: cn('py-8 text-center text-xs', MUTED), children: "This node does not name a transform yet. Choose one in the inspector first \u2014 there is no code to open until it does." })) }), _jsx(ConfirmDialog, { open: confirmingDelete, onOpenChange: setConfirmingDelete, title: `Delete "${draft.name || WORKFLOW_NAME.singular}"?`, description: `The connector it runs as goes with it, and the run history keyed on that connector goes too — including the incremental watermark, so anything rebuilt later reads its source from the beginning. The snapshots it already committed stay where they are. The transforms and connections it wired together are not touched: they are shared, and other ${WORKFLOW_NAME.plural} may use them.`, confirmLabel: "Delete", pending: remove.isPending, error: remove.error instanceof Error ? remove.error.message : undefined, onConfirm: () => draft.id && remove.mutate(draft.id) })] }));
|
|
1518
1885
|
}
|
|
1519
|
-
|
|
1520
|
-
|
|
1886
|
+
/**
|
|
1887
|
+
* "a" or "an", for a name that is now generated rather than typed out.
|
|
1888
|
+
*
|
|
1889
|
+
* Worth the three lines: the row used to carry six hand-written labels, and the
|
|
1890
|
+
* moment they were derived from the kind the sixth one read "Add a if node".
|
|
1891
|
+
* That string is not decoration — it is the whole accessible name of the button,
|
|
1892
|
+
* so the only person it is wrong for is the one who cannot see the icon.
|
|
1893
|
+
*/
|
|
1894
|
+
function article(word) {
|
|
1895
|
+
return /^[aeiou]/i.test(word) ? 'an' : 'a';
|
|
1896
|
+
}
|
|
1897
|
+
function AddButton({ kind, onClick }) {
|
|
1898
|
+
const { icon: Icon, label, hint } = ADD_NODE[kind];
|
|
1899
|
+
const noun = label.toLowerCase();
|
|
1900
|
+
return (_jsx(Tooltip, { content: hint, children: _jsxs(Button, { variant: "ghost", size: "sm", onClick: onClick, "aria-label": `Add ${article(noun)} ${noun} node`, className: "shrink-0 text-zinc-600 dark:text-zinc-300", children: [_jsx(Plus, { size: 11 }), _jsx(Icon, { size: 12 }), _jsx("span", { className: "hidden md:inline", children: label })] }) }));
|
|
1521
1901
|
}
|
|
1522
1902
|
/**
|
|
1523
1903
|
* Whether a failed run resumes or restarts, stated on the screen that implies
|
|
@@ -1547,6 +1927,71 @@ function DurabilityBanner({ durability, }) {
|
|
|
1547
1927
|
function CanvasSkeleton() {
|
|
1548
1928
|
return (_jsx("div", { className: "flex h-full w-full items-center justify-center bg-zinc-50 dark:bg-zinc-950", children: _jsxs("div", { className: "flex items-center gap-3", children: [_jsx("div", { className: "h-16 w-48 animate-pulse rounded-lg bg-zinc-200 dark:bg-zinc-800" }), _jsx(ArrowRight, { size: 14, className: MUTED }), _jsx("div", { className: "h-16 w-48 animate-pulse rounded-lg bg-zinc-200 dark:bg-zinc-800" }), _jsx(ArrowRight, { size: 14, className: MUTED }), _jsx("div", { className: "h-16 w-48 animate-pulse rounded-lg bg-zinc-200 dark:bg-zinc-800" })] }) }));
|
|
1549
1929
|
}
|
|
1930
|
+
/**
|
|
1931
|
+
* Show or hide the details rail, and say what is in it while it is hidden.
|
|
1932
|
+
*
|
|
1933
|
+
* The count is the load-bearing part. A rail that can be closed is a rail that
|
|
1934
|
+
* can hide the problems list, and "there are two errors" is not something
|
|
1935
|
+
* somebody should have to open a panel to discover — so the closed state carries
|
|
1936
|
+
* the number and the colour, and opening it is what gets the sentences. The
|
|
1937
|
+
* accessible name says the same thing in words, because a red 2 on a button is
|
|
1938
|
+
* not information if you cannot see it.
|
|
1939
|
+
*/
|
|
1940
|
+
function RailToggle({ open, problems, onToggle, }) {
|
|
1941
|
+
const badge = problemBadge(problems);
|
|
1942
|
+
const hint = open
|
|
1943
|
+
? 'Hide the wiring, problems, schedule and run history, and give the canvas the room.'
|
|
1944
|
+
: `Show the wiring, problems, schedule and run history.${badge ? ` ${badge.sentence}` : ''}`;
|
|
1945
|
+
const name = open
|
|
1946
|
+
? 'Hide the details panel'
|
|
1947
|
+
: `Show the details panel${badge ? `, ${badge.summary}` : ''}`;
|
|
1948
|
+
return (_jsx(Tooltip, { content: hint, children: _jsxs(Button, { variant: "ghost", size: "sm", onClick: onToggle, "aria-expanded": open, "aria-label": name, className: "shrink-0", children: [_jsx(PanelRight, { size: 12 }), !open && badge && (_jsx("span", { className: cn('rounded px-1 font-mono text-[10px]', badge.tone), children: badge.count }))] }) }));
|
|
1949
|
+
}
|
|
1950
|
+
/**
|
|
1951
|
+
* The one number a closed rail has to carry, or nothing at all.
|
|
1952
|
+
*
|
|
1953
|
+
* Errors win over warnings rather than being summed: a graph with one error and
|
|
1954
|
+
* six warnings is an error, and "7" beside a neutral chip would be the button
|
|
1955
|
+
* averaging two different facts into one that is neither.
|
|
1956
|
+
*
|
|
1957
|
+
* Split out of {@link RailToggle} because the three shapes it produces — a
|
|
1958
|
+
* count, a colour and two grammatical forms — were four nested ternaries inside
|
|
1959
|
+
* JSX, which is how a badge ends up saying "1 errors".
|
|
1960
|
+
*/
|
|
1961
|
+
function problemBadge(problems) {
|
|
1962
|
+
const errors = problems.filter((problem) => problem.level === 'error').length;
|
|
1963
|
+
const warnings = problems.length - errors;
|
|
1964
|
+
if (errors > 0) {
|
|
1965
|
+
return {
|
|
1966
|
+
count: errors,
|
|
1967
|
+
summary: `${errors} ${errors === 1 ? 'error' : 'errors'}`,
|
|
1968
|
+
sentence: `There ${errors === 1 ? 'is' : 'are'} ${errors} ${errors === 1 ? 'error' : 'errors'}.`,
|
|
1969
|
+
tone: 'bg-red-100 text-red-700 dark:bg-red-950 dark:text-red-300',
|
|
1970
|
+
};
|
|
1971
|
+
}
|
|
1972
|
+
if (warnings > 0) {
|
|
1973
|
+
return {
|
|
1974
|
+
count: warnings,
|
|
1975
|
+
summary: `${warnings} ${warnings === 1 ? 'warning' : 'warnings'}`,
|
|
1976
|
+
sentence: `There ${warnings === 1 ? 'is' : 'are'} ${warnings} ${warnings === 1 ? 'warning' : 'warnings'}.`,
|
|
1977
|
+
tone: 'bg-amber-100 text-amber-700 dark:bg-amber-950 dark:text-amber-300',
|
|
1978
|
+
};
|
|
1979
|
+
}
|
|
1980
|
+
return null;
|
|
1981
|
+
}
|
|
1982
|
+
/**
|
|
1983
|
+
* Which graph this is, and the two fields that name it — top-left, floating.
|
|
1984
|
+
*
|
|
1985
|
+
* The corner a document's identity lives in, in every tool shaped like this one.
|
|
1986
|
+
* What is deliberately NOT here is the description paragraph: it explains the
|
|
1987
|
+
* screen to somebody arriving at it and says nothing to somebody mid-draw, so it
|
|
1988
|
+
* costs three lines of canvas forever to be read once. It is still reachable
|
|
1989
|
+
* from the button beside the title, and still read out in full to a screen
|
|
1990
|
+
* reader, which is the one audience a tooltip would have failed.
|
|
1991
|
+
*/
|
|
1992
|
+
function WorkflowCard({ eyebrow, title, intro, stored, produces, durability, selected, workflowOptions, workflowsPending, draftName, canEdit, onSelect, onRename, }) {
|
|
1993
|
+
return (_jsxs("div", { className: cn('pointer-events-auto w-[min(24rem,100%)] p-3', FLOATING), children: [_jsxs("div", { className: "flex flex-wrap items-baseline gap-x-2 gap-y-1", children: [_jsx("p", { className: cn('font-mono text-[10px] uppercase tracking-[0.18em]', MUTED), children: eyebrow }), _jsx("h1", { className: "text-sm font-semibold tracking-tight", children: title }), stored && _jsx(WorkflowStatusBadge, { workflow: stored }), _jsx(CommitsBadge, { produces: produces }), _jsx(Tooltip, { content: intro, children: _jsx(Button, { variant: "ghost", size: "icon", "aria-label": "What this screen is for", className: "ml-auto h-5 w-5", children: _jsx(Info, { size: 11 }) }) })] }), _jsx("p", { className: "sr-only", children: intro }), _jsxs("div", { className: "mt-2.5 grid gap-2", children: [_jsx(SelectField, { label: WORKFLOW_NAME.title, ariaLabel: `Which ${WORKFLOW_NAME.singular} to edit`, value: selected, onValueChange: onSelect, options: workflowOptions, disabled: workflowsPending }), _jsx(TextField, { label: "Name", value: draftName, onChange: onRename, placeholder: "Fleet readiness", disabled: !canEdit })] }), _jsx(DurabilityBanner, { durability: durability })] }));
|
|
1994
|
+
}
|
|
1550
1995
|
/**
|
|
1551
1996
|
* That there are none, said rather than drawn as a blank canvas.
|
|
1552
1997
|
*
|
|
@@ -1568,10 +2013,21 @@ function CanvasSkeleton() {
|
|
|
1568
2013
|
* wondering whether the two do different things.
|
|
1569
2014
|
*/
|
|
1570
2015
|
function NothingDrawnYet() {
|
|
1571
|
-
return (
|
|
2016
|
+
return (
|
|
2017
|
+
/*
|
|
2018
|
+
* Centred ON the canvas rather than stated above it, now that the canvas is
|
|
2019
|
+
* the screen. An empty surface is where somebody is already looking, and it
|
|
2020
|
+
* is the thing being explained.
|
|
2021
|
+
*
|
|
2022
|
+
* `pointer-events-none` throughout: it carries no control — the one that
|
|
2023
|
+
* creates a workflow is the picker in the card — and a plate over the middle
|
|
2024
|
+
* of the canvas that swallowed a pan would make the empty state feel like a
|
|
2025
|
+
* broken canvas, which is precisely the reading it exists to prevent.
|
|
2026
|
+
*/
|
|
2027
|
+
_jsx("div", { className: "pointer-events-none absolute inset-0 z-10 flex items-center justify-center p-6", children: _jsxs("div", { className: cn('max-w-md rounded-xl border border-dashed px-4 py-3 text-center backdrop-blur-sm', RULE), children: [_jsxs("p", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: ["No ", WORKFLOW_NAME.plural, " yet"] }), _jsxs("p", { className: cn('mt-1.5 text-[11px] leading-relaxed', MUTED), children: ["Nothing is missing \u2014 this deployment has never had one drawn. Add a source, wire it into a sink and save, and it becomes the first. If this deployment has connectors already loading data, they are not shown here and nothing turns them into ", WORKFLOW_NAME.plural, ' ', "automatically."] })] }) }));
|
|
1572
2028
|
}
|
|
1573
2029
|
function CanvasFailure({ error, onRetry, }) {
|
|
1574
|
-
return (_jsx("div", { className: "flex h-full w-full items-center justify-center bg-red-50 px-6 dark:bg-red-950/30", children: _jsxs("div", { className: "max-w-md text-center", children: [_jsx(CircleAlert, { size: 18, className: "mx-auto text-red-600" }), _jsxs("p", { className: "mt-2 text-sm text-red-700 dark:text-red-300", children: ["The ", WORKFLOW_NAME.plural, " could not be read, so nothing below is drawn. This is not an empty ", WORKFLOW_NAME.singular, "."] }), _jsx("p", { className: "mt-1 font-mono text-[11px] text-red-600 dark:text-red-400", children: error instanceof Error ? error.message : 'No reason was given.' }), _jsx(
|
|
2030
|
+
return (_jsx("div", { className: "flex h-full w-full items-center justify-center bg-red-50 px-6 dark:bg-red-950/30", children: _jsxs("div", { className: "max-w-md text-center", children: [_jsx(CircleAlert, { size: 18, className: "mx-auto text-red-600" }), _jsxs("p", { className: "mt-2 text-sm text-red-700 dark:text-red-300", children: ["The ", WORKFLOW_NAME.plural, " could not be read, so nothing below is drawn. This is not an empty ", WORKFLOW_NAME.singular, "."] }), _jsx("p", { className: "mt-1 font-mono text-[11px] text-red-600 dark:text-red-400", children: error instanceof Error ? error.message : 'No reason was given.' }), _jsx(Button, { variant: "outline", size: "sm", onClick: onRetry, className: "mt-3 border-red-300 text-red-700 dark:border-red-800 dark:text-red-300", children: "Try again" })] }) }));
|
|
1575
2031
|
}
|
|
1576
2032
|
/**
|
|
1577
2033
|
* The graph as a list, beside the graph as a picture.
|
|
@@ -1585,7 +2041,7 @@ function CanvasFailure({ error, onRetry, }) {
|
|
|
1585
2041
|
* The problems list sits in the same rail for the same reason: a red ring
|
|
1586
2042
|
* around a node off the left edge of the viewport communicates nothing.
|
|
1587
2043
|
*/
|
|
1588
|
-
function WiringRail({ draft, problems, pending, run, canEdit, onInspect, onDisconnect, children, }) {
|
|
2044
|
+
function WiringRail({ draft, problems, pending, run, canEdit, reducedMotion, onInspect, onDisconnect, onClose, children, }) {
|
|
1589
2045
|
const label = (id) => {
|
|
1590
2046
|
const node = draft.nodes.find((n) => n.id === id);
|
|
1591
2047
|
return node ? nodeName(node) : id;
|
|
@@ -1593,19 +2049,38 @@ function WiringRail({ draft, problems, pending, run, canEdit, onInspect, onDisco
|
|
|
1593
2049
|
const errors = problems.filter((problem) => problem.level === 'error');
|
|
1594
2050
|
const warnings = problems.filter((problem) => problem.level === 'warning');
|
|
1595
2051
|
const sinks = draft.nodes.filter((node) => node.kind === 'sink');
|
|
1596
|
-
return (
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
2052
|
+
return (
|
|
2053
|
+
/*
|
|
2054
|
+
* Floating over the right edge of the canvas rather than beside it in a
|
|
2055
|
+
* column, and NOT a modal sheet.
|
|
2056
|
+
*
|
|
2057
|
+
* The distinction matters for exactly one reason, which `ui/sheet.tsx` spells
|
|
2058
|
+
* out from the other direction: a panel that covers the canvas while a
|
|
2059
|
+
* keyboard user tabs into what is behind it leaks focus onto controls they
|
|
2060
|
+
* cannot see. That argument is about a panel that HIDES things. This one
|
|
2061
|
+
* hides nothing — it is always open when it is rendered, everything in it is
|
|
2062
|
+
* operable, and Tab flowing between it and the canvas is the correct order
|
|
2063
|
+
* rather than a leak. So no focus trap, and deliberately no Escape handler
|
|
2064
|
+
* either: Escape on this screen already means "put the half-drawn wire away"
|
|
2065
|
+
* (see `workflow/wiring.tsx`), and a second meaning would take that key away
|
|
2066
|
+
* from the gesture that needs it most.
|
|
2067
|
+
*
|
|
2068
|
+
* `dismissible` is the whole reason it may float: an always-on 19rem panel is
|
|
2069
|
+
* 19rem of canvas somebody never agreed to spend.
|
|
2070
|
+
*/
|
|
2071
|
+
_jsxs(motion.aside, { initial: reducedMotion ? false : { opacity: 0, x: 24 }, animate: { opacity: 1, x: 0 }, exit: reducedMotion ? { opacity: 0 } : { opacity: 0, x: 24 }, transition: reducedMotion ? { duration: 0 } : { type: 'spring', stiffness: 420, damping: 34 }, className: cn('pointer-events-auto flex max-h-full w-[min(19rem,calc(100vw-2rem))] flex-col', 'overflow-y-auto p-3', FLOATING), "aria-label": `${WORKFLOW_NAME.title} wiring and problems`, children: [_jsxs("div", { className: "mb-2 flex shrink-0 items-center gap-2", children: [_jsx("p", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Details" }), _jsx(Tooltip, { content: "Put this panel away and give the canvas the room.", children: _jsx(Button, { variant: "ghost", size: "icon", onClick: onClose, "aria-label": "Hide the details panel", className: "ml-auto h-5 w-5", children: _jsx(X, { size: 11 }) }) })] }), _jsxs("div", { className: "flex flex-col gap-3", children: [_jsx(PendingWork, { pending: pending, label: label, onInspect: onInspect }), _jsxs("section", { className: cn('rounded-lg border p-3', RULE, SUBPANEL), children: [_jsx("h2", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Problems" }), problems.length === 0 ? (_jsx("p", { className: cn('mt-2 text-[11px]', MUTED), children: "Nothing to flag here. The server checks it again on save." })) : (_jsx("ul", { className: "mt-2 space-y-2", children: [...errors, ...warnings].map((problem) => (_jsxs("li", { className: "flex gap-1.5 text-[11px] leading-relaxed", children: [problem.level === 'error' ? (_jsx(CircleAlert, { size: 11, className: "mt-0.5 shrink-0 text-red-500" })) : (_jsx(TriangleAlert, { size: 11, className: "mt-0.5 shrink-0 text-amber-500" })), _jsxs("span", { children: [problem.message, problem.nodeIds.length > 0 && (_jsx("span", { className: "ml-1", children: problem.nodeIds.map((nodeId) => (_jsx("button", { type: "button", onClick: () => onInspect(nodeId), className: cn('mr-1 rounded border px-1 font-mono text-[9px]', RULE, MUTED), children: label(nodeId) }, nodeId))) }))] })] }, `${problem.code}:${problem.nodeIds.join(',')}`))) }))] }), run && (_jsxs("section", { className: cn('rounded-lg border p-3', RULE, SUBPANEL), children: [_jsx("h2", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Last run" }), _jsxs("p", { className: "mt-1 text-[11px]", children: [run.status, _jsx("span", { className: cn('ml-1 font-mono text-[10px]', MUTED), children: run.durable ? 'checkpointed per node' : 'ran inline, no checkpoints' })] }), sinks.length > 0 && (_jsxs("div", { className: "mt-2", children: [_jsx("h3", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Committed" }), _jsx("ul", { className: "mt-1 space-y-1", children: sinks.map((sink) => {
|
|
2072
|
+
const outcome = run.nodes.find((node) => node.nodeId === sink.id);
|
|
2073
|
+
const type = sink.kind === 'sink' && sink.targetType ? sink.targetType : 'no type';
|
|
2074
|
+
return (_jsxs("li", { className: "flex items-center gap-1.5 text-[11px]", children: [_jsx("span", { className: "truncate font-mono text-[10px]", children: type }), _jsx("span", { className: cn('ml-auto shrink-0 font-mono text-[10px]', outcome?.status === 'failed'
|
|
2075
|
+
? 'text-red-500'
|
|
2076
|
+
: outcome?.status === 'succeeded'
|
|
2077
|
+
? 'text-emerald-600 dark:text-emerald-400'
|
|
2078
|
+
: MUTED), children: outcome
|
|
2079
|
+
? outcome.status === 'succeeded' && typeof outcome.rows === 'number'
|
|
2080
|
+
? `${outcome.rows} rows`
|
|
2081
|
+
: outcome.status
|
|
2082
|
+
: 'no outcome recorded' })] }, sink.id));
|
|
2083
|
+
}) }), _jsx("p", { className: cn('mt-1 text-[10px] leading-relaxed', MUTED), children: "Each sink commits on its own. One committing and another failing is a failed run that nevertheless wrote something, not a partial success that will be rolled back." })] })), _jsx("ul", { className: "mt-2 space-y-1", children: run.nodes.map((node) => (_jsxs("li", { className: "flex items-center gap-1.5 font-mono text-[10px]", children: [_jsx("span", { className: "truncate", children: label(node.nodeId) }), _jsx("span", { className: cn('ml-auto shrink-0', node.status === 'failed' ? 'text-red-500' : MUTED), children: node.replayed ? 'replayed' : node.status })] }, node.nodeId))) }), run.error && _jsx("p", { className: "mt-2 text-[11px] text-red-600", children: run.error })] })), _jsxs("section", { className: cn('rounded-lg border p-3', RULE, SUBPANEL), children: [_jsx("h2", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Wiring" }), draft.edges.length === 0 ? (_jsx("p", { className: cn('mt-2 text-[11px]', MUTED), children: "Nothing is wired together yet." })) : (_jsx("ul", { className: "mt-2 space-y-1", children: draft.edges.map((edge) => (_jsxs("li", { className: "flex items-center gap-1.5 text-[11px]", children: [_jsx("button", { type: "button", onClick: () => onInspect(edge.from), className: "truncate hover:underline", children: label(edge.from) }), _jsx(ArrowRight, { size: 10, className: cn('shrink-0', MUTED) }), _jsx("button", { type: "button", onClick: () => onInspect(edge.to), className: "truncate hover:underline", children: label(edge.to) }), canEdit && (_jsx(Tooltip, { content: "Remove this connection.", children: _jsx("button", { type: "button", onClick: () => onDisconnect(edge), "aria-label": `Disconnect ${label(edge.from)} from ${label(edge.to)}`, className: "ml-auto shrink-0 rounded p-0.5 text-zinc-400 hover:text-red-600", children: _jsx(Unplug, { size: 11 }) }) }))] }, edgeId(edge)))) }))] }), children] })] }));
|
|
1609
2084
|
}
|
|
1610
2085
|
/**
|
|
1611
2086
|
* What is left to do on the nodes nobody has finished.
|
|
@@ -1625,7 +2100,7 @@ function PendingWork({ pending, label, onInspect, }) {
|
|
|
1625
2100
|
const byNode = useMemo(() => problemsByNode(pending), [pending]);
|
|
1626
2101
|
if (byNode.size === 0)
|
|
1627
2102
|
return null;
|
|
1628
|
-
return (_jsxs("section", { className: cn('rounded-lg border p-3', RULE,
|
|
2103
|
+
return (_jsxs("section", { className: cn('rounded-lg border p-3', RULE, SUBPANEL), children: [_jsx("h2", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Still to do" }), _jsx("ul", { className: "mt-2 space-y-1.5", children: [...byNode.entries()].map(([nodeId, items]) => (_jsxs("li", { className: "flex gap-1.5 text-[11px] leading-relaxed", children: [_jsx(CircleDashed, { size: 11, className: cn('mt-0.5 shrink-0', MUTED) }), _jsxs("span", { children: [_jsx("button", { type: "button", onClick: () => onInspect(nodeId), className: "font-medium hover:underline", children: label(nodeId) }), _jsxs("span", { className: MUTED, children: [' — ', items.map((problem) => todoFor(problem)).join('; '), "."] })] })] }, nodeId))) }), _jsx("p", { className: cn('mt-2 text-[10px] leading-relaxed', MUTED), children: "These are not problems yet \u2014 a node that was just added is unwired and unconfigured by construction. They are checked in full the moment you save." })] }));
|
|
1629
2104
|
}
|
|
1630
2105
|
/**
|
|
1631
2106
|
* One end of a node's wiring — everything feeding it, or everything it feeds.
|
|
@@ -2233,6 +2708,288 @@ function RowCountPredicateFields({ predicate, canEdit, onChange, }) {
|
|
|
2233
2708
|
});
|
|
2234
2709
|
}, inputMode: "numeric", placeholder: "1", disabled: !canEdit, hint: "1 is \u201Cdid anything arrive at all\u201D. A larger number is for a load whose export is never legitimately small \u2014 under it, treat the upstream as broken rather than as data." }), _jsx("p", { className: cn('text-[11px] leading-relaxed', MUTED), children: "The count is the one on the single wire feeding this node, taken from what that node recorded \u2014 nothing is re-counted, and nothing is read out of the staged rows." })] }));
|
|
2235
2710
|
}
|
|
2711
|
+
/**
|
|
2712
|
+
* Building a filter's predicate, and acknowledging what it shrinks.
|
|
2713
|
+
*
|
|
2714
|
+
* Two halves, and the second one is the reason this inspector is not just a form
|
|
2715
|
+
* over a tree. The predicate editor is the ordinary part: a recursive tree of
|
|
2716
|
+
* conditions with "and"/"or" groups, built from the vocabulary core exports so a
|
|
2717
|
+
* form that offered an operator the runner cannot evaluate is a build failure
|
|
2718
|
+
* rather than a graph somebody saves and a step that throws mid-load.
|
|
2719
|
+
*
|
|
2720
|
+
* The acknowledgement is the part that matters. If this filter is the only thing
|
|
2721
|
+
* feeding a sink that *replaces* what a type publishes, then whatever it drops
|
|
2722
|
+
* disappears from that type — silently, because the run succeeds. The graph
|
|
2723
|
+
* cannot tell that apart from filtering to derive something new (see
|
|
2724
|
+
* `WorkflowFilterNode.narrows`: they are structurally identical graphs), so the
|
|
2725
|
+
* screen asks, per type, and the server refuses the graph until it is answered.
|
|
2726
|
+
* The switches below are that question, and they are shown *only* when the
|
|
2727
|
+
* question is live — offering them on a filter that narrows nothing would train
|
|
2728
|
+
* people to flip them.
|
|
2729
|
+
*/
|
|
2730
|
+
function FilterInspector({ node, graph, canEdit, onChange, }) {
|
|
2731
|
+
// Core's answer, not this file's. A canvas that worked out its own set would
|
|
2732
|
+
// offer acknowledgements the server then refuses, which is a person ticking a
|
|
2733
|
+
// box to be told no.
|
|
2734
|
+
const narrowable = workflowNarrowedTypes(graph, node.id);
|
|
2735
|
+
const acknowledged = node.narrows ?? [];
|
|
2736
|
+
const setPredicate = (predicate) => onChange({ ...node, predicate });
|
|
2737
|
+
const setNarrows = (type, on) => {
|
|
2738
|
+
const next = on ? [...acknowledged, type] : acknowledged.filter((named) => named !== type);
|
|
2739
|
+
// Stored as absent rather than as `[]`, so "acknowledged nothing" has one
|
|
2740
|
+
// spelling. The boundary normalises the same way.
|
|
2741
|
+
onChange({ ...node, narrows: next.length === 0 ? undefined : next });
|
|
2742
|
+
};
|
|
2743
|
+
return (_jsxs("div", { className: "space-y-3", children: [_jsx(FilterPredicateEditor, { predicate: node.predicate, depth: 0, canEdit: canEdit, onChange: setPredicate, onRemove: undefined }), _jsxs("p", { className: cn('font-mono text-[10px] leading-relaxed', MUTED), children: ["keeps ", describeFilterPredicate(node.predicate)] }), _jsxs("p", { className: cn('text-[11px] leading-relaxed', MUTED), children: ["Rows that match are passed on; the rest are dropped here. The run records", ' ', _jsx("strong", { children: "how many went in and how many came out" }), ", so the panel can say what this node removed \u2014 a filter whose effect is invisible is how data goes missing quietly."] }), _jsxs("p", { className: cn('text-[11px] leading-relaxed', MUTED), children: ["A column with no value never matches, not even a \u201Cdoes not equal\u201D test \u2014 that is what a database would answer, and it is what keeps this test meaning the same thing if it is ever pushed into the source query. Use ", _jsx("em", { children: "is empty" }), " to find those rows. A value the test cannot compare against \u2014 text where the test names a number \u2014 does not match either, and the run says how many of those there were."] }), narrowable.length > 0 && (_jsx(FieldGroup, { title: "What this shrinks", hint: _jsxs(_Fragment, { children: ["This filter is the only thing feeding", ' ', narrowable.length === 1 ? 'a sink that replaces' : 'sinks that replace', " what", ' ', narrowable.length === 1 ? 'a type publishes' : 'these types publish', ". So everything it drops disappears from ", narrowable.length === 1 ? 'that type' : 'those types', " the next time this graph runs, and the run reports success while doing it. Say so here if that is what you mean. If you meant to build something new out of a subset, point the sink at a different object type; if you meant to add rows rather than replace them, set the sink to incremental."] }), children: narrowable.map((type) => (_jsx(Switch, { checked: acknowledged.includes(type), onCheckedChange: (on) => setNarrows(type, on), disabled: !canEdit, label: `Replace what ${type} publishes with the rows that pass`, hint: `The published snapshot of ${type} will hold only what this filter keeps. The type's row-count bound still applies and can still refuse the commit.` }, type))) })), acknowledged.some((type) => !narrowable.includes(type)) && (_jsxs("p", { className: "text-[11px] leading-relaxed text-amber-600 dark:text-amber-400", children: ["This filter says it narrows", ' ', acknowledged
|
|
2744
|
+
.filter((type) => !narrowable.includes(type))
|
|
2745
|
+
.map((type) => `“${type}”`)
|
|
2746
|
+
.join(', '), ", and it no longer does \u2014 rows now reach that sink another way, or it merges rather than replaces. Turn it off: an acknowledgement nothing reads is worse than none, because the next reader believes it."] }))] }));
|
|
2747
|
+
}
|
|
2748
|
+
/**
|
|
2749
|
+
* One node of the predicate tree: a group, or a single condition.
|
|
2750
|
+
*
|
|
2751
|
+
* Recursive rather than flattened, because the model is a tree and a flat list
|
|
2752
|
+
* of conditions with a single and/or toggle cannot express "A and (B or C)" —
|
|
2753
|
+
* which is the second thing anybody wants after "A and B".
|
|
2754
|
+
*
|
|
2755
|
+
* `onRemove` is absent exactly at the root, which is what makes the root
|
|
2756
|
+
* unremovable without a separate flag: a predicate is required, so there is
|
|
2757
|
+
* always at least one condition and the button that would delete the last one
|
|
2758
|
+
* does not exist.
|
|
2759
|
+
*/
|
|
2760
|
+
function FilterPredicateEditor({ predicate, depth, canEdit, onChange, onRemove, }) {
|
|
2761
|
+
if (predicate.kind === 'all' || predicate.kind === 'any') {
|
|
2762
|
+
return (_jsx(FilterGroupEditor, { predicate: predicate, depth: depth, canEdit: canEdit, onChange: onChange, onRemove: onRemove }));
|
|
2763
|
+
}
|
|
2764
|
+
return (_jsx(FilterConditionEditor, { predicate: predicate, depth: depth, canEdit: canEdit, onChange: onChange, onRemove: onRemove }));
|
|
2765
|
+
}
|
|
2766
|
+
/** The word between a group's conditions, and the two ways to add another one. */
|
|
2767
|
+
function FilterGroupEditor({ predicate, depth, canEdit, onChange, onRemove, }) {
|
|
2768
|
+
const replaceChild = (index, child) => onChange({
|
|
2769
|
+
...predicate,
|
|
2770
|
+
children: predicate.children.map((existing, at) => (at === index ? child : existing)),
|
|
2771
|
+
});
|
|
2772
|
+
// Removing the last child would leave an empty group, which keeps every row
|
|
2773
|
+
// (`all`) or drops every row (`any`) and is refused by the validator. Rather
|
|
2774
|
+
// than let somebody build one and then be told, removing the second-to-last
|
|
2775
|
+
// child collapses the group into the one that is left.
|
|
2776
|
+
const removeChild = (index) => {
|
|
2777
|
+
const left = predicate.children.filter((_, at) => at !== index);
|
|
2778
|
+
onChange(left.length === 1 ? left[0] : { ...predicate, children: left });
|
|
2779
|
+
};
|
|
2780
|
+
return (_jsxs("div", { className: cn('space-y-2 rounded-md border px-2 py-2', RULE), children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("div", { className: "min-w-0 flex-1", children: _jsx(SelectField, { label: "Match", ariaLabel: "Whether every condition in this group has to match, or any one of them", value: predicate.kind, onValueChange: (kind) => {
|
|
2781
|
+
if (kind !== 'all' && kind !== 'any')
|
|
2782
|
+
return;
|
|
2783
|
+
onChange({ ...predicate, kind });
|
|
2784
|
+
}, options: [
|
|
2785
|
+
{ value: 'all', label: 'Every condition', hint: 'and' },
|
|
2786
|
+
{ value: 'any', label: 'Any one condition', hint: 'or' },
|
|
2787
|
+
], disabled: !canEdit }) }), onRemove && canEdit && (_jsx(Button, { variant: "ghost", size: "sm", onClick: onRemove, className: "mt-4 shrink-0", children: "Remove group" }))] }), predicate.children.map((child, index) => (_jsx(FilterPredicateEditor
|
|
2788
|
+
// Positional keys, because a condition has no id and nothing in this
|
|
2789
|
+
// tree is reordered — the only edits are replace-in-place, append and
|
|
2790
|
+
// remove, and a removal re-renders the whole subtree from the model
|
|
2791
|
+
// anyway. There is no draft state below this point to be preserved.
|
|
2792
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: see above
|
|
2793
|
+
, { predicate: child, depth: depth + 1, canEdit: canEdit, onChange: (next) => replaceChild(index, next), onRemove: () => removeChild(index) }, index))), canEdit && (_jsxs("div", { className: "flex gap-2", children: [_jsx(Button, { variant: "outline", size: "sm", onClick: () => onChange({ ...predicate, children: [...predicate.children, freshFilterCondition()] }), children: "Add condition" }), depth + 1 < WORKFLOW_FILTER_MAX_DEPTH && (_jsx(Button, { variant: "outline", size: "sm", onClick: () => onChange({
|
|
2794
|
+
...predicate,
|
|
2795
|
+
children: [
|
|
2796
|
+
...predicate.children,
|
|
2797
|
+
{ kind: 'any', children: [freshFilterCondition()] },
|
|
2798
|
+
],
|
|
2799
|
+
}), children: "Add group" }))] }))] }));
|
|
2800
|
+
}
|
|
2801
|
+
/** One condition: a column, a test, and whatever that test compares against. */
|
|
2802
|
+
function FilterConditionEditor({ predicate, depth, canEdit, onChange, onRemove, }) {
|
|
2803
|
+
return (_jsxs("div", { className: cn('space-y-2 rounded-md border px-2 py-2', RULE), children: [_jsx(TextField, { label: "Column", value: predicate.column, onChange: (column) => onChange({ ...predicate, column }), placeholder: "status", disabled: !canEdit, hint: "The bare name as the rows carry it \u2014 letters, digits and underscore, starting with a letter or underscore. No table prefix and no expression: the name has to be usable as an identifier so this test can one day be handed to the source as a WHERE. Rename anything else in a transform first." }), _jsx(SelectField, { label: "Test", ariaLabel: "What kind of test this condition makes", value: predicate.kind, onValueChange: (kind) => {
|
|
2804
|
+
if (!isWorkflowFilterPredicateKind(kind))
|
|
2805
|
+
return;
|
|
2806
|
+
onChange(retargetFilterCondition(predicate, kind));
|
|
2807
|
+
}, options: [
|
|
2808
|
+
{ value: 'compare', label: 'Compare against a value' },
|
|
2809
|
+
{ value: 'oneOf', label: 'Is one of a list' },
|
|
2810
|
+
{ value: 'present', label: 'Is empty, or has a value' },
|
|
2811
|
+
], disabled: !canEdit }), _jsx(FilterConditionFields, { predicate: predicate, canEdit: canEdit, onChange: onChange }), onRemove && canEdit && (_jsx("div", { className: "flex justify-end", children: _jsx(Button, { variant: "ghost", size: "sm", onClick: onRemove, children: "Remove condition" }) })), depth === 0 && canEdit && (
|
|
2812
|
+
// The root starts as a single condition, so the only way to reach a
|
|
2813
|
+
// group is from here. Wrapping rather than offering a group at the top
|
|
2814
|
+
// level keeps a one-condition filter looking like a one-condition
|
|
2815
|
+
// filter, which is what nearly all of them are.
|
|
2816
|
+
_jsx("div", { className: "flex justify-end", children: _jsx(Button, { variant: "outline", size: "sm", onClick: () => onChange({ kind: 'all', children: [predicate, freshFilterCondition()] }), children: "Add another condition" }) }))] }));
|
|
2817
|
+
}
|
|
2818
|
+
/**
|
|
2819
|
+
* The fields one kind of condition has, and none of the fields the others have.
|
|
2820
|
+
*
|
|
2821
|
+
* Split per kind and ending in a refusal, for the reason `PredicateFields`
|
|
2822
|
+
* gives about gates: a kind added to the model without a form here would be a
|
|
2823
|
+
* condition somebody can select, that shows nothing to fill in, and that decides
|
|
2824
|
+
* which rows a published type contains.
|
|
2825
|
+
*/
|
|
2826
|
+
function FilterConditionFields({ predicate, canEdit, onChange, }) {
|
|
2827
|
+
if (predicate.kind === 'present') {
|
|
2828
|
+
return (_jsx(SelectField, { label: "Has a value?", ariaLabel: "Whether the column has to be empty or has to hold something", value: predicate.operator, onValueChange: (operator) => {
|
|
2829
|
+
if (operator !== 'isNull' && operator !== 'isNotNull')
|
|
2830
|
+
return;
|
|
2831
|
+
onChange({ ...predicate, operator });
|
|
2832
|
+
}, options: [
|
|
2833
|
+
{ value: 'isNotNull', label: 'Has a value' },
|
|
2834
|
+
{ value: 'isNull', label: 'Is empty' },
|
|
2835
|
+
], disabled: !canEdit, hint: "The only test that can see an empty column. Every other test here treats an empty value as \u201Ccannot say\u201D, which never matches." }));
|
|
2836
|
+
}
|
|
2837
|
+
if (predicate.kind === 'oneOf') {
|
|
2838
|
+
return (_jsxs(_Fragment, { children: [_jsx(SelectField, { label: "In the list?", ariaLabel: "Whether the column has to be in the list or out of it", value: predicate.operator, onValueChange: (operator) => {
|
|
2839
|
+
if (operator !== 'in' && operator !== 'notIn')
|
|
2840
|
+
return;
|
|
2841
|
+
onChange({ ...predicate, operator });
|
|
2842
|
+
}, options: [
|
|
2843
|
+
{ value: 'in', label: 'Is one of these' },
|
|
2844
|
+
{ value: 'notIn', label: 'Is none of these' },
|
|
2845
|
+
], disabled: !canEdit }), _jsx(FilterValueTypeField, { value: predicate.values[0], canEdit: canEdit, onChange: (sample) => onChange({
|
|
2846
|
+
...predicate,
|
|
2847
|
+
values: predicate.values.map((existing) => castFilterValue(existing, sample)),
|
|
2848
|
+
}) }), _jsx(TextAreaField, { label: "Values", value: predicate.values.map((value) => String(value)).join('\n'), onChange: (text) => onChange({ ...predicate, values: parseFilterValues(text, predicate.values[0]) }), rows: 4, mono: true, disabled: !canEdit, hint: `One per line. At most ${WORKFLOW_FILTER_MAX_VALUES} — past that this is a join against another dataset rather than a filter, and the thing to do is read that dataset in as a second source.` })] }));
|
|
2849
|
+
}
|
|
2850
|
+
if (predicate.kind === 'compare') {
|
|
2851
|
+
return (_jsxs(_Fragment, { children: [_jsx(SelectField, { label: "Comparison", ariaLabel: "How the column is compared against the value", value: predicate.operator, onValueChange: (operator) => {
|
|
2852
|
+
if (!isWorkflowFilterOperator(operator))
|
|
2853
|
+
return;
|
|
2854
|
+
onChange({ ...predicate, operator });
|
|
2855
|
+
}, options: WORKFLOW_FILTER_OPERATORS.map((operator) => ({
|
|
2856
|
+
value: operator,
|
|
2857
|
+
label: FILTER_OPERATOR_LABELS[operator],
|
|
2858
|
+
})), disabled: !canEdit }), _jsx(FilterValueTypeField, { value: predicate.value, canEdit: canEdit, onChange: (sample) => onChange({ ...predicate, value: castFilterValue(predicate.value, sample) }) }), _jsx(FilterValueField, { value: predicate.value, canEdit: canEdit, onChange: (value) => onChange({ ...predicate, value }) })] }));
|
|
2859
|
+
}
|
|
2860
|
+
return unreachableFilterPredicateKind(predicate, 'FilterConditionFields');
|
|
2861
|
+
}
|
|
2862
|
+
/**
|
|
2863
|
+
* Each operator, spelled out in a sentence rather than in symbols.
|
|
2864
|
+
*
|
|
2865
|
+
* The node's face uses `>` and `≥` because it has 224 pixels; a dropdown has
|
|
2866
|
+
* room, and "is after / greater than" is what somebody scanning a list of ten
|
|
2867
|
+
* options is actually reading for. A `Record` keyed by the union, so an operator
|
|
2868
|
+
* added to core without a label here stops the build rather than rendering an
|
|
2869
|
+
* empty row in a select.
|
|
2870
|
+
*/
|
|
2871
|
+
const FILTER_OPERATOR_LABELS = {
|
|
2872
|
+
equals: 'equals',
|
|
2873
|
+
notEquals: 'does not equal',
|
|
2874
|
+
greaterThan: 'is greater than',
|
|
2875
|
+
greaterThanOrEqual: 'is greater than or equal to',
|
|
2876
|
+
lessThan: 'is less than',
|
|
2877
|
+
lessThanOrEqual: 'is less than or equal to',
|
|
2878
|
+
contains: 'contains',
|
|
2879
|
+
notContains: 'does not contain',
|
|
2880
|
+
startsWith: 'starts with',
|
|
2881
|
+
notStartsWith: 'does not start with',
|
|
2882
|
+
};
|
|
2883
|
+
/**
|
|
2884
|
+
* Whether the value is text, a number, or true/false.
|
|
2885
|
+
*
|
|
2886
|
+
* A visible choice rather than something inferred from what was typed, and this
|
|
2887
|
+
* is the field most likely to be mistaken for clutter. It is not: `"10"` and
|
|
2888
|
+
* `10` are different values here and neither matches the other, exactly as a
|
|
2889
|
+
* strongly-typed column would answer, and a form that guessed from the
|
|
2890
|
+
* characters would silently flip a text column's test to numeric the moment
|
|
2891
|
+
* somebody filtered on an order number. The run log reports those rows as
|
|
2892
|
+
* incomparable; this field is how they are avoided in the first place.
|
|
2893
|
+
*/
|
|
2894
|
+
function FilterValueTypeField({ value, canEdit, onChange, }) {
|
|
2895
|
+
return (_jsx(SelectField, { label: "Value type", ariaLabel: "Whether the value is text, a number, or true/false", value: typeof value === 'number' ? 'number' : typeof value === 'boolean' ? 'boolean' : 'text', onValueChange: (type) => {
|
|
2896
|
+
if (type === 'number')
|
|
2897
|
+
return onChange(0);
|
|
2898
|
+
if (type === 'boolean')
|
|
2899
|
+
return onChange(true);
|
|
2900
|
+
onChange('');
|
|
2901
|
+
}, options: [
|
|
2902
|
+
{ value: 'text', label: 'Text' },
|
|
2903
|
+
{ value: 'number', label: 'A number' },
|
|
2904
|
+
{ value: 'boolean', label: 'True or false' },
|
|
2905
|
+
], disabled: !canEdit, hint: "Text and numbers are never equal to each other here, and neither is greater or less than the other \u2014 a row whose column holds the wrong one of the two is reported on the run rather than quietly matching. Dates are text: ISO-8601 sorts correctly." }));
|
|
2906
|
+
}
|
|
2907
|
+
/** The value itself, in whichever control the chosen type deserves. */
|
|
2908
|
+
function FilterValueField({ value, canEdit, onChange, }) {
|
|
2909
|
+
if (typeof value === 'boolean') {
|
|
2910
|
+
return (_jsx(SelectField, { label: "Value", ariaLabel: "The true or false value this column is compared against", value: value ? 'true' : 'false', onValueChange: (chosen) => onChange(chosen === 'true'), options: [
|
|
2911
|
+
{ value: 'true', label: 'True' },
|
|
2912
|
+
{ value: 'false', label: 'False' },
|
|
2913
|
+
], disabled: !canEdit }));
|
|
2914
|
+
}
|
|
2915
|
+
if (typeof value === 'number') {
|
|
2916
|
+
return (_jsx(TextField, { label: "Value",
|
|
2917
|
+
// A text box with a numeric keypad rather than `type="number"`, which is
|
|
2918
|
+
// the rule the row-count threshold above already writes down: that
|
|
2919
|
+
// control drops what it cannot parse and answers a scroll wheel.
|
|
2920
|
+
value: Number.isFinite(value) ? String(value) : '', onChange: (typed) => {
|
|
2921
|
+
const cleaned = typed.replace(/[^0-9.-]/g, '');
|
|
2922
|
+
const parsed = Number.parseFloat(cleaned);
|
|
2923
|
+
// An unparseable box stores 0 rather than `NaN`: every comparison
|
|
2924
|
+
// against `NaN` is false, so a filter holding one drops every row
|
|
2925
|
+
// while looking perfectly well configured — and the model refuses to
|
|
2926
|
+
// store it, so the graph could not be saved to find that out.
|
|
2927
|
+
onChange(Number.isFinite(parsed) ? parsed : 0);
|
|
2928
|
+
}, inputMode: "numeric", placeholder: "0", disabled: !canEdit }));
|
|
2929
|
+
}
|
|
2930
|
+
return (_jsx(TextField, { label: "Value", value: value, onChange: onChange, placeholder: "OPEN", disabled: !canEdit, hint: "Compared exactly, with no trimming and no case folding. Collation is a property of the column in every database this runs against, so a case-insensitive test evaluated here and the same one evaluated in the source would legitimately disagree \u2014 normalise in a transform instead." }));
|
|
2931
|
+
}
|
|
2932
|
+
/** A condition somebody has not filled in yet. Refused by the validator until they do. */
|
|
2933
|
+
function freshFilterCondition() {
|
|
2934
|
+
return { kind: 'compare', column: '', operator: 'equals', value: '' };
|
|
2935
|
+
}
|
|
2936
|
+
/**
|
|
2937
|
+
* The same condition, asked to be a different kind of test.
|
|
2938
|
+
*
|
|
2939
|
+
* The **column is carried across** and nothing else is, which is the split worth
|
|
2940
|
+
* arguing: the column is what somebody typed and is the expensive half to
|
|
2941
|
+
* retype, while an operator and a value belong to the test that is being left
|
|
2942
|
+
* behind — `greaterThan` has no meaning for a presence check and a value has
|
|
2943
|
+
* none either.
|
|
2944
|
+
*/
|
|
2945
|
+
function retargetFilterCondition(predicate, kind) {
|
|
2946
|
+
if (kind === 'compare') {
|
|
2947
|
+
return { kind: 'compare', column: predicate.column, operator: 'equals', value: '' };
|
|
2948
|
+
}
|
|
2949
|
+
if (kind === 'oneOf') {
|
|
2950
|
+
return { kind: 'oneOf', column: predicate.column, operator: 'in', values: [''] };
|
|
2951
|
+
}
|
|
2952
|
+
if (kind === 'present') {
|
|
2953
|
+
return { kind: 'present', column: predicate.column, operator: 'isNotNull' };
|
|
2954
|
+
}
|
|
2955
|
+
// The two group kinds are reachable from the select's type but never from its
|
|
2956
|
+
// options, because a group is added by its own button and is not a *test* a
|
|
2957
|
+
// condition can be switched to. Refusing rather than building one keeps the
|
|
2958
|
+
// exhaustiveness honest without pretending this is a conversion.
|
|
2959
|
+
if (kind === 'all' || kind === 'any')
|
|
2960
|
+
return predicate;
|
|
2961
|
+
return unreachableFilterPredicateKind(kind, 'retargetFilterCondition');
|
|
2962
|
+
}
|
|
2963
|
+
/** One value, moved to the type of a sample, keeping whatever survives the move. */
|
|
2964
|
+
function castFilterValue(value, sample) {
|
|
2965
|
+
if (typeof sample === 'number') {
|
|
2966
|
+
const parsed = typeof value === 'number' ? value : Number.parseFloat(String(value));
|
|
2967
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
2968
|
+
}
|
|
2969
|
+
if (typeof sample === 'boolean')
|
|
2970
|
+
return value === true || value === 'true';
|
|
2971
|
+
return String(value);
|
|
2972
|
+
}
|
|
2973
|
+
/**
|
|
2974
|
+
* A textarea of values, one per line, in the type the list is already in.
|
|
2975
|
+
*
|
|
2976
|
+
* Blank lines are dropped rather than kept as empty strings, because a trailing
|
|
2977
|
+
* newline is what a textarea has after every entry and a list ending in `""`
|
|
2978
|
+
* would filter for a value nobody typed. An entirely empty box keeps one blank
|
|
2979
|
+
* entry: the model refuses an empty list, and clearing the box should leave a
|
|
2980
|
+
* condition to finish rather than a graph that cannot be saved with no visible
|
|
2981
|
+
* cause.
|
|
2982
|
+
*/
|
|
2983
|
+
function parseFilterValues(text, sample) {
|
|
2984
|
+
const lines = text
|
|
2985
|
+
.split('\n')
|
|
2986
|
+
.map((line) => line.trim())
|
|
2987
|
+
.filter((line) => line.length > 0);
|
|
2988
|
+
if (lines.length === 0)
|
|
2989
|
+
return [''];
|
|
2990
|
+
const cast = sample ?? '';
|
|
2991
|
+
return lines.slice(0, WORKFLOW_FILTER_MAX_VALUES).map((line) => castFilterValue(line, cast));
|
|
2992
|
+
}
|
|
2236
2993
|
/**
|
|
2237
2994
|
* The parameter box's two directions, kept together because they are inverses.
|
|
2238
2995
|
*
|
|
@@ -2274,7 +3031,7 @@ function parseConfigText(text) {
|
|
|
2274
3031
|
* a kind added without a branch here shows up as a node with a name and nothing
|
|
2275
3032
|
* to configure, which is visible on the screen rather than silent.
|
|
2276
3033
|
*/
|
|
2277
|
-
function KindInspector({ node, transforms, connections, typeOptions, canEdit, modelHref, discovery, discoverable, onDiscovered, onChange, onEditCode, onCreateTransform, creatingTransform, createTransformError, }) {
|
|
3034
|
+
function KindInspector({ node, graph, transforms, connections, typeOptions, canEdit, modelHref, discovery, discoverable, onDiscovered, onChange, onEditCode, onCreateTransform, creatingTransform, createTransformError, }) {
|
|
2278
3035
|
if (node.kind === 'transform') {
|
|
2279
3036
|
return (_jsx(TransformInspector, { node: node, transforms: transforms, canEdit: canEdit, creating: creatingTransform, createError: createTransformError, onChange: onChange, onEditCode: onEditCode, onCreate: onCreateTransform }));
|
|
2280
3037
|
}
|
|
@@ -2294,6 +3051,13 @@ function KindInspector({ node, transforms, connections, typeOptions, canEdit, mo
|
|
|
2294
3051
|
if (node.kind === 'if') {
|
|
2295
3052
|
return _jsx(IfInspector, { node: node, canEdit: canEdit, onChange: onChange }, node.id);
|
|
2296
3053
|
}
|
|
3054
|
+
if (node.kind === 'filter') {
|
|
3055
|
+
// Given the whole graph, not only the node, because the one question this
|
|
3056
|
+
// inspector cannot answer from the node alone is the important one: which
|
|
3057
|
+
// published types this filter stands in front of. See
|
|
3058
|
+
// `WorkflowFilterNode.narrows`.
|
|
3059
|
+
return (_jsx(FilterInspector, { node: node, graph: graph, canEdit: canEdit, onChange: onChange }, node.id));
|
|
3060
|
+
}
|
|
2297
3061
|
if (node.kind === 'sink') {
|
|
2298
3062
|
return (_jsx(SinkInspector, { node: node, typeOptions: typeOptions, canEdit: canEdit, modelHref: modelHref, onChange: onChange }));
|
|
2299
3063
|
}
|
|
@@ -2344,7 +3108,7 @@ function NodeInspector({ node, draft, transforms, connections, typeOptions, canE
|
|
|
2344
3108
|
return (_jsx(Sheet, { open: node !== null, onOpenChange: (open) => {
|
|
2345
3109
|
if (!open)
|
|
2346
3110
|
onClose();
|
|
2347
|
-
}, title: node ? nodeName(node) : '', description: node ? `${node.kind} node` : undefined, children: node && (_jsxs("div", { className: "space-y-4", children: [problems.length > 0 && (_jsx("ul", { className: "space-y-1.5 rounded-md border border-red-200 bg-red-50 p-2 dark:border-red-900 dark:bg-red-950/40", children: problems.map((problem) => (_jsx("li", { className: "text-[11px] leading-relaxed text-red-700 dark:text-red-300", children: problem.message }, problem.code))) })), pending.length > 0 && (_jsxs("div", { className: cn('rounded-md border p-2', RULE), children: [_jsx("p", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Still to do" }), _jsx("ul", { className: "mt-1 space-y-0.5", children: pending.map((problem) => (_jsx("li", { className: "text-[11px] leading-relaxed", children: todoFor(problem) }, problem.code))) })] })), _jsx(TextField, { label: "Name", value: node.name, onChange: (name) => onChange({ ...node, name }), placeholder: node.kind, disabled: !canEdit, hint: "What it is called on the canvas and in the wiring list. Renaming it does not change what the graph does, so it does not bump the version." }), _jsx(KindInspector, { node: node, transforms: transforms, connections: connections, typeOptions: typeOptions, canEdit: canEdit, modelHref: modelHref, discovery: discovery, discoverable: discoverable, onDiscovered: onDiscovered, onChange: onChange, onEditCode: onEditCode, onCreateTransform: onCreateTransform, creatingTransform: creatingTransform, createTransformError: createTransformError }), _jsx(WiringList, { title: "Fed by", edges: incoming, otherEnd: (edge) => label(edge.from), describeRemoval: (name) => `Stop ${name} feeding this node`, canEdit: canEdit, onDisconnect: onDisconnect, children: incoming.length > 1 && (_jsx("p", { className: cn('mt-1 text-[11px] leading-relaxed', MUTED), children: "Inputs arrive in this order, and the order is part of what the graph produces \u2014 a transform joining two feeds sees them exactly like this." })) }), _jsxs(WiringList, { title: "Feeds", edges: outgoing, otherEnd: (edge) => label(edge.to), describeRemoval: (name) => `Stop this node feeding ${name}`, canEdit: canEdit, onDisconnect: onDisconnect,
|
|
3111
|
+
}, title: node ? nodeName(node) : '', description: node ? `${node.kind} node` : undefined, children: node && (_jsxs("div", { className: "space-y-4", children: [problems.length > 0 && (_jsx("ul", { className: "space-y-1.5 rounded-md border border-red-200 bg-red-50 p-2 dark:border-red-900 dark:bg-red-950/40", children: problems.map((problem) => (_jsx("li", { className: "text-[11px] leading-relaxed text-red-700 dark:text-red-300", children: problem.message }, problem.code))) })), pending.length > 0 && (_jsxs("div", { className: cn('rounded-md border p-2', RULE), children: [_jsx("p", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Still to do" }), _jsx("ul", { className: "mt-1 space-y-0.5", children: pending.map((problem) => (_jsx("li", { className: "text-[11px] leading-relaxed", children: todoFor(problem) }, problem.code))) })] })), _jsx(TextField, { label: "Name", value: node.name, onChange: (name) => onChange({ ...node, name }), placeholder: node.kind, disabled: !canEdit, hint: "What it is called on the canvas and in the wiring list. Renaming it does not change what the graph does, so it does not bump the version." }), _jsx(KindInspector, { node: node, graph: draft, transforms: transforms, connections: connections, typeOptions: typeOptions, canEdit: canEdit, modelHref: modelHref, discovery: discovery, discoverable: discoverable, onDiscovered: onDiscovered, onChange: onChange, onEditCode: onEditCode, onCreateTransform: onCreateTransform, creatingTransform: creatingTransform, createTransformError: createTransformError }), _jsx(WiringList, { title: "Fed by", edges: incoming, otherEnd: (edge) => label(edge.from), describeRemoval: (name) => `Stop ${name} feeding this node`, canEdit: canEdit, onDisconnect: onDisconnect, children: incoming.length > 1 && (_jsx("p", { className: cn('mt-1 text-[11px] leading-relaxed', MUTED), children: "Inputs arrive in this order, and the order is part of what the graph produces \u2014 a transform joining two feeds sees them exactly like this." })) }), _jsxs(WiringList, { title: "Feeds", edges: outgoing, otherEnd: (edge) => label(edge.to), describeRemoval: (name) => `Stop this node feeding ${name}`, canEdit: canEdit, onDisconnect: onDisconnect,
|
|
2348
3112
|
// Only a gate's wires have a side to be on. `validateWorkflow`
|
|
2349
3113
|
// refuses a label on any other wire, so offering the control there
|
|
2350
3114
|
// would be offering a change the server will not take.
|