@dudousxd/nestjs-catalog-react 0.17.0 → 0.19.0-preview.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -13
- package/dist/CatalogManager.d.ts +23 -1
- package/dist/CatalogManager.js +76 -13
- package/dist/ConnectionPanel.d.ts +11 -7
- package/dist/ConnectionPanel.js +78 -149
- package/dist/LoadedBySection.d.ts +39 -0
- package/dist/LoadedBySection.js +143 -0
- package/dist/PipelineConsole.d.ts +23 -126
- package/dist/PipelineConsole.js +39 -551
- package/dist/WorkflowCanvas.d.ts +16 -0
- package/dist/WorkflowCanvas.js +1064 -64
- package/dist/connection-form.d.ts +241 -0
- package/dist/connection-form.js +235 -0
- package/dist/context.d.ts +236 -38
- package/dist/context.js +46 -11
- package/dist/index.d.ts +10 -3
- package/dist/index.js +63 -14
- package/dist/routes.d.ts +84 -13
- package/dist/routes.js +7 -4
- package/dist/schema-discovery.d.ts +232 -0
- package/dist/schema-discovery.js +225 -0
- package/dist/source-connection.d.ts +82 -0
- package/dist/source-connection.js +176 -0
- package/dist/source-fields.d.ts +16 -14
- package/dist/source-fields.js +28 -18
- package/dist/ui/code-editor.d.ts +44 -2
- package/dist/ui/code-editor.js +10 -2
- package/dist/ui/combobox.d.ts +97 -0
- package/dist/ui/combobox.js +80 -0
- package/dist/ui/dialog.d.ts +13 -1
- package/dist/ui/dialog.js +13 -2
- package/dist/workflow/edges.d.ts +110 -0
- package/dist/workflow/edges.js +112 -0
- package/dist/workflow/graph.d.ts +39 -1
- package/dist/workflow/graph.js +212 -52
- package/dist/workflow/index.d.ts +8 -0
- package/dist/workflow/index.js +12 -0
- package/dist/workflow/lifecycle.d.ts +135 -0
- package/dist/workflow/lifecycle.js +216 -0
- package/dist/workflow/model.d.ts +17 -3
- package/dist/workflow/model.js +7 -2
- package/dist/workflow/nodes.d.ts +4 -1
- package/dist/workflow/nodes.js +198 -10
- package/dist/workflow/runs.d.ts +38 -0
- package/dist/workflow/runs.js +101 -0
- package/dist/workflow/shape.d.ts +169 -0
- package/dist/workflow/shape.js +249 -0
- package/dist/workflow/templates.d.ts +623 -0
- package/dist/workflow/templates.js +1102 -0
- package/dist/workflow/validate.d.ts +20 -1
- package/dist/workflow/validate.js +52 -3
- package/dist/workflow/wiring.d.ts +84 -0
- package/dist/workflow/wiring.js +254 -0
- package/package.json +9 -9
package/dist/WorkflowCanvas.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { Background, BackgroundVariant, ConnectionLineType, Controls, MiniMap, NodeToolbar, Position, ReactFlow, ReactFlowProvider, useReactFlow, } from '@xyflow/react';
|
|
3
3
|
// React Flow ships its own stylesheet and renders as an unstyled pile of divs
|
|
4
4
|
// without it — no edges, every node at the top-left corner. Imported by the
|
|
@@ -7,22 +7,32 @@ 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, LayoutGrid, Link2, Loader2,
|
|
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';
|
|
11
12
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
13
|
+
import { connectionOptionsFor } from './ConnectionPanel';
|
|
12
14
|
import { TransformEditor } from './TransformEditor';
|
|
13
15
|
import { cn } from './cn';
|
|
14
16
|
import { catalogQueryKeys, useCatalogClient } from './context';
|
|
15
|
-
import {
|
|
17
|
+
import { SchemaDiscoveryPanel, narrowDiscovery, } from './schema-discovery';
|
|
18
|
+
import { SourceConnectionCreator } from './source-connection';
|
|
19
|
+
import { INLINE_CONNECTION, KIND_OPTIONS, ReadModeFields, SourceFields, readsIncrementally, sourceConfigFrom, sourceDraftFrom, toConnectorKind, usesConnection, } from './source-fields';
|
|
20
|
+
import { Button } from './ui/button';
|
|
21
|
+
import { ComboboxField } from './ui/combobox';
|
|
16
22
|
import { ConfirmDialog } from './ui/dialog';
|
|
17
|
-
import { TextField } from './ui/field';
|
|
23
|
+
import { TextAreaField, TextField } from './ui/field';
|
|
18
24
|
import { Select, SelectField } from './ui/select';
|
|
19
25
|
import { Sheet } from './ui/sheet';
|
|
20
26
|
import { Tooltip, TooltipProvider } from './ui/tooltip';
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
27
|
+
import { WorkflowEdgeProvider, workflowEdgeTypes } from './workflow/edges';
|
|
28
|
+
import { NODE_HEIGHT, NODE_WIDTH, defaultLabel, flowingEdgeIds, layout, layoutIfUnarranged, nextPosition, toFlowEdges, toFlowNodes, } from './workflow/graph';
|
|
29
|
+
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';
|
|
23
31
|
import { WORKFLOW_NAME } from './workflow/name';
|
|
24
32
|
import { WorkflowNodeProvider, workflowNodeTypes } from './workflow/nodes';
|
|
33
|
+
import { RunsAsPanel } from './workflow/runs';
|
|
25
34
|
import { canConnect, edgeId, hasBlockingProblem, problemsByNode, validateWorkflow, } from './workflow/validate';
|
|
35
|
+
import { PendingWireLine, WiringHint, useClickWiring, } from './workflow/wiring';
|
|
26
36
|
const MUTED = 'text-zinc-400 dark:text-zinc-500';
|
|
27
37
|
const RULE = 'border-zinc-200 dark:border-zinc-800';
|
|
28
38
|
const PANEL = 'bg-white dark:bg-zinc-900';
|
|
@@ -132,7 +142,57 @@ function newNodeOfKind(kind, id, position, name) {
|
|
|
132
142
|
if (kind === 'transform') {
|
|
133
143
|
return { id, name, kind: 'transform', transformId: '', position };
|
|
134
144
|
}
|
|
135
|
-
|
|
145
|
+
if (kind === 'call') {
|
|
146
|
+
// Both empty, and the graph is invalid until they are not — deliberately.
|
|
147
|
+
// There is no list of workflows to default from (see `CallableWorkflowRef`
|
|
148
|
+
// in core), and defaulting a *version* to "1" would be the one guess that
|
|
149
|
+
// matters: it would silently pin whichever code happens to be registered as
|
|
150
|
+
// version 1 in whatever deployment this graph is promoted into.
|
|
151
|
+
return { id, name, kind: 'call', callName: '', callVersion: '', config: {}, position };
|
|
152
|
+
}
|
|
153
|
+
if (kind === 'if') {
|
|
154
|
+
// No variable, so the graph is invalid until somebody names one. There is
|
|
155
|
+
// nothing to guess: which variable tells this deployment apart from another
|
|
156
|
+
// is the entire content of the node, and a default would be a decision the
|
|
157
|
+
// graph appears to make and nobody authored.
|
|
158
|
+
//
|
|
159
|
+
// The *kind* of test does get a default, and it is the deployment one,
|
|
160
|
+
// because a predicate has to be one of them and an empty variable name is a
|
|
161
|
+
// gate that visibly refuses to publish. A row-count gate with its default
|
|
162
|
+
// threshold would publish happily while testing something nobody chose.
|
|
163
|
+
return { id, name, kind: 'if', predicate: { kind: 'env', envVar: '' }, position };
|
|
164
|
+
}
|
|
165
|
+
if (kind === 'sink') {
|
|
166
|
+
return { id, name, kind: 'sink', targetType: '', position };
|
|
167
|
+
}
|
|
168
|
+
return unreachableNodeKind(kind, 'newNodeOfKind');
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* A wire, with its branch already decided when it leaves an `if`.
|
|
172
|
+
*
|
|
173
|
+
* Assigned here rather than left blank for somebody to fill in, because a blank
|
|
174
|
+
* one is refused by `validateWorkflow` and the refusal would fire on the very
|
|
175
|
+
* first wire out of a node somebody just created — the premature-error problem
|
|
176
|
+
* `partitionProblems` exists to describe, arrived at from a different direction.
|
|
177
|
+
*
|
|
178
|
+
* The first wire out of a gate is the `then`, the second is the `else`, and
|
|
179
|
+
* after that it is `then` again. That ordering is not arbitrary: those are the
|
|
180
|
+
* two somebody is drawing when they draw a gate, in that order, and a third wire
|
|
181
|
+
* is fan-out on a side they then choose in the inspector. Every one of them is
|
|
182
|
+
* editable there, so this is a default and never a decision.
|
|
183
|
+
*/
|
|
184
|
+
function newEdge(nodes, edges, from, to) {
|
|
185
|
+
const source = nodes.find((node) => node.id === from);
|
|
186
|
+
if (source?.kind !== 'if')
|
|
187
|
+
return { from, to };
|
|
188
|
+
const taken = edges.filter((edge) => edge.from === from).map((edge) => edge.branch);
|
|
189
|
+
const free = WORKFLOW_BRANCH_LABELS.find((label) => !taken.includes(label));
|
|
190
|
+
return { from, to, branch: free ?? 'then' };
|
|
191
|
+
}
|
|
192
|
+
/** The same graph with one wire moved onto the other side of its gate. */
|
|
193
|
+
function edgeOnBranch(edges, moving, branch) {
|
|
194
|
+
const id = edgeId(moving);
|
|
195
|
+
return edges.map((edge) => (edgeId(edge) === id ? { ...edge, branch } : edge));
|
|
136
196
|
}
|
|
137
197
|
/**
|
|
138
198
|
* The code a transform created from this canvas starts as: the batch, unchanged.
|
|
@@ -365,9 +425,15 @@ const TODO_FOR = {
|
|
|
365
425
|
'dead-end': 'wire it into something that ends at a sink',
|
|
366
426
|
'sink-has-no-type': 'choose the object type it commits',
|
|
367
427
|
'transform-not-named': 'choose the transform it runs',
|
|
428
|
+
'call-not-named': 'name the workflow it calls, and the version to pin',
|
|
368
429
|
'missing-transform': 'choose a transform that still exists',
|
|
369
430
|
'source-has-input': 'unwire whatever feeds it — a source reads, it is not fed',
|
|
370
431
|
'sink-has-output': 'unwire what it feeds — nothing runs after a sink',
|
|
432
|
+
'if-not-named': 'name the environment variable it decides on',
|
|
433
|
+
'if-threshold-invalid': 'give it a whole number of rows, 1 or more, to branch on',
|
|
434
|
+
'if-needs-one-input': 'leave it one input — a gate carries one stream through',
|
|
435
|
+
'branch-not-labelled': 'say whether that wire is the "then" or the "else"',
|
|
436
|
+
'branch-on-plain-edge': 'remove the branch label — only an if node branches',
|
|
371
437
|
};
|
|
372
438
|
function todoFor(problem) {
|
|
373
439
|
return TODO_FOR[problem.code] ?? 'finish setting it up';
|
|
@@ -445,19 +511,17 @@ function saveHint(blocked, unfinished) {
|
|
|
445
511
|
* list beside the canvas is empty and the real answer is "two boxes are not
|
|
446
512
|
* finished", so that case gets its own sentence and names them.
|
|
447
513
|
*/
|
|
448
|
-
function CanvasActions({ draft, canEdit, blocked, unfinished, saving, running, durabilityDetail, onSave, onRun, onAskDelete, }) {
|
|
514
|
+
function CanvasActions({ draft, stored, canEdit, blocked, unfinished, saving, running, durabilityDetail, acknowledging, onAcknowledgingChange, onSave, onRun, onLifecycleChange, onAskDelete, }) {
|
|
449
515
|
return (_jsxs("div", { className: "flex flex-wrap items-start gap-2 self-end pb-1", children: [_jsx(Tooltip, { content: saveHint(blocked, unfinished), children: _jsxs("button", { type: "button", onClick: onSave, disabled: !canEdit ||
|
|
450
516
|
saving ||
|
|
451
517
|
draft.name.trim().length === 0 ||
|
|
452
518
|
(!draft.dirty && Boolean(draft.id)), className: cn('flex items-center gap-1.5 rounded-md px-3 py-1.5 text-xs disabled:opacity-40', blocked
|
|
453
519
|
? 'bg-amber-600 text-white'
|
|
454
|
-
: 'bg-zinc-950 text-zinc-50 dark:bg-zinc-100 dark:text-zinc-950'), children: [saving ? _jsx(Loader2, { size: 12, className: "animate-spin" }) : _jsx(Save, { size: 12 }), draft.dirty ? 'Save' : 'Saved'] }) }), _jsx(Tooltip, { content:
|
|
455
|
-
? 'Save first — a run executes the stored graph, not what is on screen.'
|
|
456
|
-
: durabilityDetail, children: _jsxs("button", { type: "button", onClick: onRun, disabled: !canEdit || !draft.id || draft.dirty || running, className: cn('flex items-center gap-1.5 rounded-md border px-3 py-1.5 text-xs disabled:opacity-40', RULE, 'hover:bg-zinc-50 dark:hover:bg-zinc-800'), children: [running ? _jsx(Loader2, { size: 12, className: "animate-spin" }) : _jsx(Play, { size: 12 }), "Run"] }) }), draft.id && canEdit && (_jsx(Tooltip, { content: `Delete this ${WORKFLOW_NAME.singular}.`, children: _jsx("button", { type: "button", onClick: onAskDelete, "aria-label": `Delete this ${WORKFLOW_NAME.singular}`, className: cn('rounded-md border p-1.5 text-zinc-400 hover:text-red-600', RULE), children: _jsx(Trash2, { size: 12 }) }) }))] }));
|
|
520
|
+
: 'bg-zinc-950 text-zinc-50 dark:bg-zinc-100 dark:text-zinc-950'), 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 }) }) }))] }));
|
|
457
521
|
}
|
|
458
|
-
/** The
|
|
522
|
+
/** The four things that can be put on the canvas, and the button that tidies them. */
|
|
459
523
|
function AddNodeBar({ refreshing, onAdd, onTidy, }) {
|
|
460
|
-
return (_jsxs("div", { className: "flex shrink-0 flex-wrap items-center gap-2 px-6 pt-3", children: [_jsx(AddButton, { icon: Plug, label: "Source", hint: "Reads records out of a system: a kind, an optional named connection, and a config.", onClick: () => onAdd('source') }), _jsx(AddButton, { icon: Repeat, label: "Transform", hint: "Code that reshapes whatever is wired into it.", onClick: () => onAdd('transform') }), _jsx(AddButton, { icon: Database, label: "Sink", hint: "Writes and commits one object type. Several are fine \u2014 each commits independently.", onClick: () => onAdd('sink') }), _jsx(Tooltip, { content: "Lay the nodes out left to right by dependency, with every sink in the last column.", children: _jsxs("button", { type: "button", onClick: onTidy, className: cn('flex items-center gap-1.5 rounded-md border px-2.5 py-1.5 text-xs', RULE, MUTED, 'hover:bg-zinc-50 dark:hover:bg-zinc-800'), children: [_jsx(LayoutGrid, { size: 12 }), "Tidy"] }) }), refreshing && (
|
|
524
|
+
return (_jsxs("div", { className: "flex shrink-0 flex-wrap items-center gap-2 px-6 pt-3", children: [_jsx(AddButton, { icon: Plug, label: "Source", hint: "Reads records out of a system: a kind, an optional named connection, and a config.", onClick: () => onAdd('source') }), _jsx(AddButton, { icon: Repeat, label: "Transform", hint: "Code that reshapes whatever is wired into it.", onClick: () => onAdd('transform') }), _jsx(AddButton, { icon: Database, label: "Sink", hint: "Writes and commits one object type. Several are fine \u2014 each commits independently.", onClick: () => onAdd('sink') }), _jsx(AddButton, { icon: ExternalLink, label: "Call", 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.", onClick: () => onAdd('call') }), _jsx(AddButton, { icon: GitBranch, label: "If", hint: "Sends the rows down one of two branches, depending on an environment variable where the load runs. The other branch is skipped \u2014 a sink on it commits nothing and leaves what is published alone.", onClick: () => onAdd('if') }), _jsx(Tooltip, { content: "Lay the nodes out left to right by dependency, with every sink in the last column.", children: _jsxs("button", { type: "button", onClick: onTidy, className: cn('flex items-center gap-1.5 rounded-md border px-2.5 py-1.5 text-xs', RULE, MUTED, 'hover:bg-zinc-50 dark:hover:bg-zinc-800'), children: [_jsx(LayoutGrid, { size: 12 }), "Tidy"] }) }), refreshing && (
|
|
461
525
|
// A background refetch says so without replacing anything: the graph on
|
|
462
526
|
// screen stays exactly where it is.
|
|
463
527
|
_jsx("span", { className: cn('ml-auto font-mono text-[10px]', MUTED), children: "refreshing\u2026" }))] }));
|
|
@@ -494,6 +558,15 @@ function miniMapColor(data) {
|
|
|
494
558
|
return '#0ea5e9';
|
|
495
559
|
if (kind === 'sink')
|
|
496
560
|
return '#10b981';
|
|
561
|
+
// The same amber the node itself draws (see `KIND_STYLE`), so the overview
|
|
562
|
+
// and the canvas agree about which boxes are somebody else's workflow.
|
|
563
|
+
if (kind === 'call')
|
|
564
|
+
return '#f59e0b';
|
|
565
|
+
// Fuchsia-500, the gate's own accent, and deliberately not the violet a
|
|
566
|
+
// transform gets: the overview is where somebody looks to find the branch in
|
|
567
|
+
// a graph too big to read, so it is the one place the two must not blur.
|
|
568
|
+
if (kind === 'if')
|
|
569
|
+
return '#d946ef';
|
|
497
570
|
return '#8b5cf6';
|
|
498
571
|
}
|
|
499
572
|
/**
|
|
@@ -503,12 +576,18 @@ function miniMapColor(data) {
|
|
|
503
576
|
* place of the screen, so the header and its controls stay put while a refetch
|
|
504
577
|
* resolves — and a failed read never looks like an empty workflow.
|
|
505
578
|
*/
|
|
506
|
-
function GraphSurface({ loading, failed, error, onRetry, canEdit, draft, flowNodes, flowEdges, onInspect, onEditCode, onNodesChange, onEdgesChange, onConnect, isValidConnection, onConnectEnd, onNodeEnter, onNodeLeave, onPaneClick, nodeMenu, }) {
|
|
507
|
-
return (_jsxs("div", { className: cn('relative h-[55vh] min-h-[15rem] shrink-0 overflow-hidden rounded-lg border', 'lg:h-auto lg:min-h-0 lg:flex-1 lg:shrink', RULE), children: [loading && _jsx(CanvasSkeleton, {}), failed && _jsx(CanvasFailure, { error: error, onRetry: onRetry }), !loading && !failed && (_jsx(WorkflowNodeProvider, { handlers: { onInspect, onEditCode, canEdit }, children: _jsxs(ReactFlow, { className: CANVAS_THEME, nodes: flowNodes, edges: flowEdges, nodeTypes: workflowNodeTypes, onNodesChange: onNodesChange, onEdgesChange: onEdgesChange, onConnect: onConnect, isValidConnection: isValidConnection, onConnectEnd: onConnectEnd, onNodeMouseEnter: (_event, node) => onNodeEnter(node.id), onNodeMouseLeave: onNodeLeave, onPaneClick: onPaneClick, connectionLineType: ConnectionLineType.SmoothStep,
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
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
|
+
return (_jsxs("div", { className: cn('relative h-[55vh] min-h-[15rem] shrink-0 overflow-hidden rounded-lg border', 'lg:h-auto lg:min-h-0 lg:flex-1 lg:shrink', RULE), children: [loading && _jsx(CanvasSkeleton, {}), failed && _jsx(CanvasFailure, { error: error, onRetry: onRetry }), !loading && !failed && (_jsx(WorkflowNodeProvider, { handlers: { onInspect, onEditCode, canEdit, wiring }, children: _jsx(WorkflowEdgeProvider, { handlers: { onDisconnect, canEdit }, 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
|
+
// Off, so there is exactly ONE click path through a handle and it
|
|
582
|
+
// is the one in `workflow/wiring.tsx`. React Flow's own click
|
|
583
|
+
// wiring connects but draws nothing while it is open and cannot
|
|
584
|
+
// say why it refused — running both would mean two states
|
|
585
|
+
// disagreeing about whether a wire is in flight.
|
|
586
|
+
connectOnClick: false, nodesDraggable: canEdit, nodesConnectable: canEdit, elementsSelectable: true, nodesFocusable: true, edgesFocusable: true, deleteKeyCode: canEdit ? ['Delete', 'Backspace'] : null,
|
|
587
|
+
// A wider drop zone than the 20px default, because these handles are
|
|
588
|
+
// the only drop target on the screen and missing one reads as the
|
|
589
|
+
// 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, className: "!overflow-hidden !rounded-lg !border !border-zinc-200 !shadow-sm dark:!border-zinc-800 [&>button]:!border-none" }), _jsx(MiniMap, { pannable: true, zoomable: true, nodeColor: (node) => miniMapColor(node.data), className: "!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] }) }) }))] }));
|
|
512
591
|
}
|
|
513
592
|
/**
|
|
514
593
|
* The wiring control that lives on a node, and the menu behind it.
|
|
@@ -672,7 +751,87 @@ function nodeMovesAndRemovals(changes) {
|
|
|
672
751
|
}
|
|
673
752
|
return { positions, removed };
|
|
674
753
|
}
|
|
675
|
-
|
|
754
|
+
/**
|
|
755
|
+
* The transforms a graph actually names.
|
|
756
|
+
*
|
|
757
|
+
* Only these, because the run history's `code v3` can be turned into a
|
|
758
|
+
* comparison only when there is exactly one candidate: a run records ONE
|
|
759
|
+
* transform version, a graph may run three in a row, and picking whichever the
|
|
760
|
+
* screen loaded first would offer a diff against the wrong code.
|
|
761
|
+
*/
|
|
762
|
+
function transformsNamedBy(nodes, transforms) {
|
|
763
|
+
const named = new Set(nodes.flatMap((node) => node.kind === 'transform' && node.transformId ? [node.transformId] : []));
|
|
764
|
+
return transforms.filter((transform) => named.has(transform.id));
|
|
765
|
+
}
|
|
766
|
+
/**
|
|
767
|
+
* What a run did, said out loud once.
|
|
768
|
+
*
|
|
769
|
+
* Not "succeeded or failed": a graph may commit several types at several sinks,
|
|
770
|
+
* each independently, so the overall status is only the headline and the reader
|
|
771
|
+
* is sent to the per-sink list for what actually landed.
|
|
772
|
+
*/
|
|
773
|
+
function runAnnouncement(result) {
|
|
774
|
+
if (result.status === 'succeeded') {
|
|
775
|
+
return 'The run finished. Check each sink below for what it committed.';
|
|
776
|
+
}
|
|
777
|
+
return `The run ${result.status}. ${result.error ?? ''}`;
|
|
778
|
+
}
|
|
779
|
+
/** What a publish or an unpublish changed, for somebody who cannot see the badge. */
|
|
780
|
+
function lifecycleAnnouncement(saved) {
|
|
781
|
+
return saved.status === 'ready'
|
|
782
|
+
? 'Published. It is now ready, and runs as a connector of its own.'
|
|
783
|
+
: 'Back to draft. Nothing runs it until it is published again.';
|
|
784
|
+
}
|
|
785
|
+
/**
|
|
786
|
+
* The stored graph behind a draft, when the draft has been stored at all.
|
|
787
|
+
*
|
|
788
|
+
* A lookup rather than state of its own, so that publishing — which changes the
|
|
789
|
+
* status and mints the connector everything else is keyed on — reaches the
|
|
790
|
+
* badge, the schedule panel and the "Runs as" panel through one path instead of
|
|
791
|
+
* three copies going out of step.
|
|
792
|
+
*/
|
|
793
|
+
function storedWorkflow(list, id) {
|
|
794
|
+
if (!id)
|
|
795
|
+
return undefined;
|
|
796
|
+
return list?.find((workflow) => workflow.id === id);
|
|
797
|
+
}
|
|
798
|
+
function discoveryTarget(draft) {
|
|
799
|
+
if (!draft.id) {
|
|
800
|
+
return {
|
|
801
|
+
because: `Save this ${WORKFLOW_NAME.singular} first — discovery reads the stored node, and there is nothing stored yet. It does not need to be published.`,
|
|
802
|
+
};
|
|
803
|
+
}
|
|
804
|
+
if (draft.dirty) {
|
|
805
|
+
return {
|
|
806
|
+
because: 'Save first — discovery reads the stored node, so it would describe the source as it was before these edits.',
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
return { workflowId: draft.id };
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* Whether an edit changed where this node reads from, or only what it is
|
|
813
|
+
* called.
|
|
814
|
+
*
|
|
815
|
+
* The question a discovered shape's shelf life turns on. Everything compared
|
|
816
|
+
* here is part of the address the server would dial — the kind of system, the
|
|
817
|
+
* connection it borrows, whether it reads the lot or from a watermark, and the
|
|
818
|
+
* config that holds the URL or the statement. A name, a position and a
|
|
819
|
+
* selection are none of those, and dropping the columns for one of them would
|
|
820
|
+
* make the check disappear for the most ordinary edit there is.
|
|
821
|
+
*
|
|
822
|
+
* `config` is compared as JSON because it is an open record — both sides are
|
|
823
|
+
* built by `sourceConfigFrom`, so the key order is stable, and the failure mode
|
|
824
|
+
* of a false difference is silence rather than a wrong answer.
|
|
825
|
+
*/
|
|
826
|
+
function readsDifferently(before, after) {
|
|
827
|
+
if (before?.kind !== 'source' || after.kind !== 'source')
|
|
828
|
+
return false;
|
|
829
|
+
return (before.sourceKind !== after.sourceKind ||
|
|
830
|
+
before.connectionId !== after.connectionId ||
|
|
831
|
+
before.mode !== after.mode ||
|
|
832
|
+
JSON.stringify(before.config ?? {}) !== JSON.stringify(after.config ?? {}));
|
|
833
|
+
}
|
|
834
|
+
function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intro = 'Wire sources through transforms into sinks. Each sink commits its own object type independently, so one expensive read can feed several outputs.', canEdit = true, modelHref, }) {
|
|
676
835
|
const client = useCatalogClient();
|
|
677
836
|
const queryClient = useQueryClient();
|
|
678
837
|
const { fitView } = useReactFlow();
|
|
@@ -711,6 +870,15 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
711
870
|
const [editingCodeFor, setEditingCodeFor] = useState(null);
|
|
712
871
|
const [confirmingDelete, setConfirmingDelete] = useState(false);
|
|
713
872
|
const [run, setRun] = useState(null);
|
|
873
|
+
/**
|
|
874
|
+
* Whether the "this load is expected to shrink" dialog is open.
|
|
875
|
+
*
|
|
876
|
+
* Here rather than inside `RunControls` because there are two ways in and only
|
|
877
|
+
* one of them is a button in that row: the other is the refusal note under the
|
|
878
|
+
* canvas, which is where somebody who has just watched a load be turned away is
|
|
879
|
+
* actually looking.
|
|
880
|
+
*/
|
|
881
|
+
const [acknowledging, setAcknowledging] = useState(false);
|
|
714
882
|
/**
|
|
715
883
|
* Nodes added in this session that nobody has done anything to yet.
|
|
716
884
|
*
|
|
@@ -720,6 +888,22 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
720
888
|
* somebody finished with.
|
|
721
889
|
*/
|
|
722
890
|
const [unstarted, setUnstarted] = useState(() => new Set());
|
|
891
|
+
/**
|
|
892
|
+
* What discovery said each source node reads, for the source nodes somebody
|
|
893
|
+
* has actually asked about in this session.
|
|
894
|
+
*
|
|
895
|
+
* Component state for the same reason `unstarted` is, and kept HERE rather
|
|
896
|
+
* than inside `SchemaDiscoveryPanel` because that panel is unmounted with the
|
|
897
|
+
* inspector: the columns somebody just read would be gone by the time they
|
|
898
|
+
* looked at the Problems rail, which is where the comparison in
|
|
899
|
+
* `workflow/shape.ts` is drawn. The panel tells this through `onDiscovered`.
|
|
900
|
+
*
|
|
901
|
+
* Empty is the state every graph starts in, and it means "nobody asked" — not
|
|
902
|
+
* "nothing to report". That distinction is the whole basis of the column
|
|
903
|
+
* checks, and it survives here because the map is only ever written by a
|
|
904
|
+
* discovery somebody ran.
|
|
905
|
+
*/
|
|
906
|
+
const [shapesByNode, setShapesByNode] = useState(() => new Map());
|
|
723
907
|
/**
|
|
724
908
|
* The last thing the canvas refused, and the last thing it did.
|
|
725
909
|
*
|
|
@@ -755,6 +939,10 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
755
939
|
// Everything in a freshly loaded draft came off the server, so nothing in it
|
|
756
940
|
// is "not finished yet" — see `partitionProblems`.
|
|
757
941
|
setUnstarted(new Set());
|
|
942
|
+
// A discovered shape belongs to the node it was read for, and node ids do
|
|
943
|
+
// not cross graphs. Keeping the map would be this screen holding one graph's
|
|
944
|
+
// columns while drawing another's — silence is the right state on arrival.
|
|
945
|
+
setShapesByNode(new Map());
|
|
758
946
|
menu.reset();
|
|
759
947
|
}, [workflows.data, selected, menu.reset]);
|
|
760
948
|
// Fit after the graph swaps, on the frame after the new nodes have been laid
|
|
@@ -773,7 +961,32 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
773
961
|
setDraft((current) => ({ ...change(current), dirty: true }));
|
|
774
962
|
}, []);
|
|
775
963
|
const transformIds = useMemo(() => new Set(transforms.map((transform) => transform.id)), [transforms]);
|
|
776
|
-
|
|
964
|
+
/**
|
|
965
|
+
* The two halves of the column check, or nothing at all.
|
|
966
|
+
*
|
|
967
|
+
* `undefined` until a discovery has actually been run on this graph, and that
|
|
968
|
+
* is the load-bearing part rather than an optimisation: an implementation
|
|
969
|
+
* whose `sourceShape` always answered `undefined` would look like an answer
|
|
970
|
+
* and report the same silence, and `shape.ts` is written on the assumption
|
|
971
|
+
* that being handed a {@link ShapeKnowledge} means somebody can answer with
|
|
972
|
+
* it. An empty map is "nobody asked", and it says so by being absent.
|
|
973
|
+
*
|
|
974
|
+
* The types come from the snapshot this screen already holds, so the catalog
|
|
975
|
+
* half costs no request. A snapshot that has not arrived yet answers nothing,
|
|
976
|
+
* which reads as "this console cannot see that type" for the one render
|
|
977
|
+
* before it does — a warning, never an error, which is exactly the outcome a
|
|
978
|
+
* momentarily-unknown type deserves.
|
|
979
|
+
*/
|
|
980
|
+
const shapes = useMemo(() => {
|
|
981
|
+
if (shapesByNode.size === 0)
|
|
982
|
+
return undefined;
|
|
983
|
+
const types = new Map((snapshot?.types ?? []).map((type) => [type.name, type]));
|
|
984
|
+
return {
|
|
985
|
+
sourceShape: (nodeId) => shapesByNode.get(nodeId),
|
|
986
|
+
targetShape: (typeName) => types.get(typeName),
|
|
987
|
+
};
|
|
988
|
+
}, [shapesByNode, snapshot]);
|
|
989
|
+
const problems = useMemo(() => validateWorkflow({ nodes: draft.nodes, edges: draft.edges }, { transformIds, shapes }), [draft.nodes, draft.edges, transformIds, shapes]);
|
|
777
990
|
/**
|
|
778
991
|
* The same checks, split by whether the node they name is finished.
|
|
779
992
|
*
|
|
@@ -798,13 +1011,18 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
798
1011
|
selected: selectedIds.has(node.id),
|
|
799
1012
|
}));
|
|
800
1013
|
}, [draft.nodes, draft.edges, describe, problemsFor, runFor, selectedNodeIds]);
|
|
1014
|
+
// `useReducedMotion` returns null until it has asked, which is neither yes nor
|
|
1015
|
+
// no; coerced here because every consumer of it wants the boolean, and the
|
|
1016
|
+
// safe reading of "has not answered yet" is "do not animate".
|
|
1017
|
+
const reducedMotion = useReducedMotion() !== false;
|
|
1018
|
+
const flowing = useMemo(() => flowingEdgeIds(draft.edges, run?.nodes ?? [], { reducedMotion }), [draft.edges, run, reducedMotion]);
|
|
801
1019
|
const flowEdges = useMemo(() => {
|
|
802
1020
|
const selectedIds = new Set(selectedEdgeIds);
|
|
803
|
-
return toFlowEdges(draft.edges, draft.nodes, brokenEdgeIds).map((edge) => ({
|
|
1021
|
+
return toFlowEdges(draft.edges, draft.nodes, brokenEdgeIds, flowing).map((edge) => ({
|
|
804
1022
|
...edge,
|
|
805
1023
|
selected: selectedIds.has(edge.id),
|
|
806
1024
|
}));
|
|
807
|
-
}, [draft.edges, draft.nodes, brokenEdgeIds, selectedEdgeIds]);
|
|
1025
|
+
}, [draft.edges, draft.nodes, brokenEdgeIds, selectedEdgeIds, flowing]);
|
|
808
1026
|
/**
|
|
809
1027
|
* React Flow's changes, applied to the stored model rather than to a second
|
|
810
1028
|
* copy of the graph.
|
|
@@ -862,6 +1080,30 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
862
1080
|
const markStarted = useCallback((...ids) => {
|
|
863
1081
|
setUnstarted((current) => without(current, ids));
|
|
864
1082
|
}, []);
|
|
1083
|
+
/**
|
|
1084
|
+
* A discovery landed, so the column check has something to say about this
|
|
1085
|
+
* node.
|
|
1086
|
+
*
|
|
1087
|
+
* The response is stored as-is: `ConnectorSchemaDiscovery` already IS a
|
|
1088
|
+
* {@link SourceShape} — same `columns`, same `basis`, same `sampled` — and
|
|
1089
|
+
* that is not a coincidence worth papering over with a conversion. The two
|
|
1090
|
+
* were written against the same route. A mapping function here would be a
|
|
1091
|
+
* place for the two to quietly drift, and would have to invent an answer for
|
|
1092
|
+
* every field it did not copy.
|
|
1093
|
+
*/
|
|
1094
|
+
const rememberShape = useCallback((nodeId, shape) => {
|
|
1095
|
+
setShapesByNode((current) => new Map(current).set(nodeId, shape));
|
|
1096
|
+
}, []);
|
|
1097
|
+
/** The columns on file stop describing this node. See the caller. */
|
|
1098
|
+
const forgetShape = useCallback((nodeId) => {
|
|
1099
|
+
setShapesByNode((current) => {
|
|
1100
|
+
if (!current.has(nodeId))
|
|
1101
|
+
return current;
|
|
1102
|
+
const next = new Map(current);
|
|
1103
|
+
next.delete(nodeId);
|
|
1104
|
+
return next;
|
|
1105
|
+
});
|
|
1106
|
+
}, []);
|
|
865
1107
|
const disconnect = useCallback((edge) => {
|
|
866
1108
|
const id = edgeId(edge);
|
|
867
1109
|
edit((current) => ({
|
|
@@ -871,6 +1113,19 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
871
1113
|
markStarted(edge.from, edge.to);
|
|
872
1114
|
setAnnouncement('Connection removed.');
|
|
873
1115
|
}, [edit, markStarted]);
|
|
1116
|
+
/**
|
|
1117
|
+
* Put a wire on the other side of its gate.
|
|
1118
|
+
*
|
|
1119
|
+
* Announced, like every other wiring change on this screen, because the only
|
|
1120
|
+
* visible effect is a word on a line the reader may not be looking at — and
|
|
1121
|
+
* moving a wire from `then` to `else` is one of the largest changes anybody
|
|
1122
|
+
* can make here: it inverts which half of the pipeline runs.
|
|
1123
|
+
*/
|
|
1124
|
+
const setBranch = useCallback((edge, branch) => {
|
|
1125
|
+
edit((current) => ({ ...current, edges: edgeOnBranch(current.edges, edge, branch) }));
|
|
1126
|
+
markStarted(edge.from, edge.to);
|
|
1127
|
+
setAnnouncement(`${nodeLabelIn(draft.nodes, edge.to)} is now on the "${branch}" branch of ${nodeLabelIn(draft.nodes, edge.from)}.`);
|
|
1128
|
+
}, [draft.nodes, edit, markStarted]);
|
|
874
1129
|
const connect = useCallback((from, to) => {
|
|
875
1130
|
const verdict = canConnect(draft.nodes, draft.edges, from, to);
|
|
876
1131
|
if (!verdict.ok) {
|
|
@@ -880,7 +1135,10 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
880
1135
|
// Appended rather than inserted anywhere else: a node with several inbound
|
|
881
1136
|
// edges receives its inputs in the order the edges appear in this array,
|
|
882
1137
|
// and that order is part of what the graph produces.
|
|
883
|
-
edit((current) => ({
|
|
1138
|
+
edit((current) => ({
|
|
1139
|
+
...current,
|
|
1140
|
+
edges: [...current.edges, newEdge(current.nodes, current.edges, from, to)],
|
|
1141
|
+
}));
|
|
884
1142
|
markStarted(from, to);
|
|
885
1143
|
setAnnouncement(`${nodeLabelIn(draft.nodes, from)} now feeds ${nodeLabelIn(draft.nodes, to)}.`);
|
|
886
1144
|
}, [draft.nodes, draft.edges, edit, markStarted]);
|
|
@@ -924,6 +1182,22 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
924
1182
|
return false;
|
|
925
1183
|
return canConnect(draft.nodes, draft.edges, candidate.source, candidate.target).ok;
|
|
926
1184
|
}, [draft.nodes, draft.edges]);
|
|
1185
|
+
/**
|
|
1186
|
+
* Wiring by clicking twice, which is the gesture people actually reach for.
|
|
1187
|
+
*
|
|
1188
|
+
* Built on the same `connect` the menu, the rail and the drag all end in, so
|
|
1189
|
+
* there is one place a connection is made and one place it is refused. Why
|
|
1190
|
+
* React Flow's own `connectOnClick` is turned off in favour of this — it
|
|
1191
|
+
* connects but draws nothing, and cannot say why it refused — is written out
|
|
1192
|
+
* at the top of `workflow/wiring.tsx`.
|
|
1193
|
+
*/
|
|
1194
|
+
const { wiring, refusal: wiringRefusal } = useClickWiring({
|
|
1195
|
+
canEdit,
|
|
1196
|
+
nodes: draft.nodes,
|
|
1197
|
+
edges: draft.edges,
|
|
1198
|
+
onConnect: connect,
|
|
1199
|
+
onSay: setAnnouncement,
|
|
1200
|
+
});
|
|
927
1201
|
const save = useMutation({
|
|
928
1202
|
mutationFn: () => client.saveWorkflow({
|
|
929
1203
|
id: draft.id,
|
|
@@ -941,7 +1215,12 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
941
1215
|
},
|
|
942
1216
|
});
|
|
943
1217
|
const runIt = useMutation({
|
|
944
|
-
|
|
1218
|
+
// The options are the run's, not the graph's, and `expectShrink` is the one
|
|
1219
|
+
// that matters: it is the acknowledgement that lets a deliberately
|
|
1220
|
+
// collapsing load past the row-count bound, it reaches the server only
|
|
1221
|
+
// through this route, and it is stored nowhere — which is the only reliable
|
|
1222
|
+
// way to keep a one-time acknowledgement from becoming a standing one.
|
|
1223
|
+
mutationFn: ({ id, options }) => client.runWorkflow(id, options),
|
|
945
1224
|
onSuccess: (result) => {
|
|
946
1225
|
setRun(result);
|
|
947
1226
|
// A run writes rows, so the catalog snapshot every other screen reads is
|
|
@@ -949,11 +1228,20 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
949
1228
|
// showing yesterday's counts beside a run that just finished.
|
|
950
1229
|
queryClient.invalidateQueries({ queryKey: catalogQueryKeys.snapshot });
|
|
951
1230
|
queryClient.invalidateQueries({ queryKey: catalogQueryKeys.workflows });
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
1231
|
+
// The run is recorded against the connector, which is where the history
|
|
1232
|
+
// and the last-run fields live. Left stale, the "Runs as" panel shows a
|
|
1233
|
+
// pipeline that has never run beside a run that just finished.
|
|
1234
|
+
queryClient.invalidateQueries({ queryKey: catalogQueryKeys.runs() });
|
|
1235
|
+
queryClient.invalidateQueries({ queryKey: catalogQueryKeys.connectors });
|
|
1236
|
+
setAnnouncement(runAnnouncement(result));
|
|
955
1237
|
},
|
|
956
1238
|
});
|
|
1239
|
+
// `id` is narrowed by the controls, which are disabled without one — the empty
|
|
1240
|
+
// string here is unreachable and is what keeps this a plain call rather than a
|
|
1241
|
+
// second guard the button already applies.
|
|
1242
|
+
const runNow = useCallback((options) => {
|
|
1243
|
+
runIt.mutate({ id: draft.id ?? '', options });
|
|
1244
|
+
}, [draft.id, runIt.mutate]);
|
|
957
1245
|
/**
|
|
958
1246
|
* Write the first transform without leaving the canvas.
|
|
959
1247
|
*
|
|
@@ -1048,7 +1336,7 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
1048
1336
|
edit((current) => ({
|
|
1049
1337
|
...current,
|
|
1050
1338
|
nodes: [...current.nodes, node],
|
|
1051
|
-
edges: [...current.edges,
|
|
1339
|
+
edges: [...current.edges, newEdge(current.nodes, current.edges, fromId, node.id)],
|
|
1052
1340
|
}));
|
|
1053
1341
|
setUnstarted((current) => new Set([...current, node.id]));
|
|
1054
1342
|
menu.close();
|
|
@@ -1090,11 +1378,37 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
1090
1378
|
setUnstarted(new Set());
|
|
1091
1379
|
save.mutate();
|
|
1092
1380
|
}, [save]);
|
|
1381
|
+
/**
|
|
1382
|
+
* The stored graph behind the draft on screen, when there is one.
|
|
1383
|
+
*
|
|
1384
|
+
* Read out of the list rather than held in state of its own, so that
|
|
1385
|
+
* publishing — which changes `status`, and mints the connector everything
|
|
1386
|
+
* else here is keyed on — reaches the badge, the schedule panel and the
|
|
1387
|
+
* "Runs as" panel through one path instead of three copies going out of step.
|
|
1388
|
+
*
|
|
1389
|
+
* `loadedRef` is what makes this safe: the load effect returns early once the
|
|
1390
|
+
* draft has been built for an id, so a fresher list arriving here cannot throw
|
|
1391
|
+
* away nodes somebody has moved since.
|
|
1392
|
+
*/
|
|
1393
|
+
const stored = useMemo(() => storedWorkflow(workflows.data, draft.id), [workflows.data, draft.id]);
|
|
1394
|
+
/**
|
|
1395
|
+
* A publish, an unpublish or a schedule, written straight into the list.
|
|
1396
|
+
*
|
|
1397
|
+
* Written as well as invalidated, because the status badge is the whole
|
|
1398
|
+
* feedback for those actions: waiting for a refetch means pressing Publish
|
|
1399
|
+
* and watching nothing happen for as long as the round trip takes, which is
|
|
1400
|
+
* exactly how somebody presses it twice.
|
|
1401
|
+
*/
|
|
1402
|
+
const onLifecycleChange = useCallback((saved) => {
|
|
1403
|
+
queryClient.setQueryData(catalogQueryKeys.workflows, (current) => (current ?? []).map((workflow) => (workflow.id === saved.id ? saved : workflow)));
|
|
1404
|
+
setAnnouncement(lifecycleAnnouncement(saved));
|
|
1405
|
+
}, [queryClient]);
|
|
1093
1406
|
const inspectingNode = draft.nodes.find((node) => node.id === inspecting) ?? null;
|
|
1094
1407
|
const editingNode = draft.nodes.find((node) => node.id === editingCodeFor);
|
|
1095
1408
|
const editingTransform = editingNode?.kind === 'transform'
|
|
1096
1409
|
? transforms.find((transform) => transform.id === editingNode.transformId)
|
|
1097
1410
|
: undefined;
|
|
1411
|
+
const graphTransforms = useMemo(() => transformsNamedBy(draft.nodes, transforms), [draft.nodes, transforms]);
|
|
1098
1412
|
const typeOptions = useMemo(() => (snapshot?.types ?? []).map((type) => ({
|
|
1099
1413
|
value: type.name,
|
|
1100
1414
|
label: type.displayName,
|
|
@@ -1109,6 +1423,34 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
1109
1423
|
{ value: NEW_WORKFLOW, label: `New ${WORKFLOW_NAME.singular}` },
|
|
1110
1424
|
], [workflows.data]);
|
|
1111
1425
|
const produces = producedTypes(draft.nodes);
|
|
1426
|
+
/**
|
|
1427
|
+
* Asking a source what its columns are, and creating the type from the answer.
|
|
1428
|
+
*
|
|
1429
|
+
* Built from the client rather than taken as a prop, and the prop that used to
|
|
1430
|
+
* carry it is gone with the screen it lived on. Two calls, and the second is
|
|
1431
|
+
* the only write: discovery reads and reports, `PUT /publish/:type/schema`
|
|
1432
|
+
* creates. A pipeline that created the type it loads into would grow the
|
|
1433
|
+
* catalog by accident, and the names it invented would come from the shape of
|
|
1434
|
+
* a query rather than from somebody who meant them.
|
|
1435
|
+
*/
|
|
1436
|
+
const discovery = useMemo(() => ({
|
|
1437
|
+
discover: async (workflowId, nodeId) => narrowDiscovery(await client.discoverSourceSchema(workflowId, nodeId)),
|
|
1438
|
+
// `async` on purpose: `publishType` THROWS rather than rejecting when the
|
|
1439
|
+
// transport cannot PUT, and a bridge whose method throws synchronously
|
|
1440
|
+
// would escape the panel's error handling and take the screen with it.
|
|
1441
|
+
createType: async (draftType) => client.publishType(draftType.name, {
|
|
1442
|
+
// Only what a person confirmed on screen. Everything else about a type
|
|
1443
|
+
// — its label, its description, its units — is curation, and inventing
|
|
1444
|
+
// any of it here would put words nobody chose into a catalog whose
|
|
1445
|
+
// whole claim is that its names were chosen.
|
|
1446
|
+
properties: draftType.properties.map((property) => ({
|
|
1447
|
+
name: property.name,
|
|
1448
|
+
columnName: property.columnName,
|
|
1449
|
+
type: property.type,
|
|
1450
|
+
nullable: property.nullable,
|
|
1451
|
+
})),
|
|
1452
|
+
}),
|
|
1453
|
+
}), [client]);
|
|
1112
1454
|
return (
|
|
1113
1455
|
/*
|
|
1114
1456
|
* The screen lives inside the viewport: a header sized to its content and a
|
|
@@ -1122,18 +1464,41 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
1122
1464
|
* not save that: it fits the graph into a box, and half the box was off
|
|
1123
1465
|
* screen. See `QueryConsole` for the same pattern.
|
|
1124
1466
|
*/
|
|
1125
|
-
_jsxs("div", { className: "flex h-full min-h-0 flex-col", children: [_jsxs("div", { className: "shrink-0 px-6 pt-5", children: [_jsxs("div", { className: "flex flex-wrap items-baseline gap-x-3 gap-y-1", children: [_jsx("p", { className: cn('font-mono text-[11px] uppercase tracking-[0.18em]', MUTED), children: eyebrow }), _jsx("h1", { className: "text-xl font-semibold tracking-tight", children: title }), _jsx(CommitsBadge, { produces: produces })] }), _jsx("p", { className: "mt-0.5 max-w-3xl text-xs text-zinc-500 dark:text-zinc-400", children: intro }), _jsx(DurabilityBanner, { durability: durability }), _jsxs("div", { className: "mt-2.5 grid gap-3 sm:grid-cols-2 lg:grid-cols-3", children: [_jsx(SelectField, { label: WORKFLOW_NAME.title, ariaLabel: `Which ${WORKFLOW_NAME.singular} to edit`, value: selected, onValueChange: (value) => {
|
|
1467
|
+
_jsxs("div", { className: "flex h-full min-h-0 flex-col", children: [_jsxs("div", { className: "shrink-0 px-6 pt-5", children: [_jsxs("div", { className: "flex flex-wrap items-baseline gap-x-3 gap-y-1", children: [_jsx("p", { className: cn('font-mono text-[11px] uppercase tracking-[0.18em]', MUTED), children: eyebrow }), _jsx("h1", { className: "text-xl font-semibold tracking-tight", children: title }), stored && _jsx(WorkflowStatusBadge, { workflow: stored }), _jsx(CommitsBadge, { produces: produces })] }), _jsx("p", { className: "mt-0.5 max-w-3xl text-xs text-zinc-500 dark:text-zinc-400", children: intro }), _jsx(DurabilityBanner, { durability: durability }), workflows.isSuccess && workflows.data.length === 0 && _jsx(NothingDrawnYet, {}), _jsxs("div", { className: "mt-2.5 grid gap-3 sm:grid-cols-2 lg:grid-cols-3", children: [_jsx(SelectField, { label: WORKFLOW_NAME.title, ariaLabel: `Which ${WORKFLOW_NAME.singular} to edit`, value: selected, onValueChange: (value) => {
|
|
1126
1468
|
loadedRef.current = null;
|
|
1127
1469
|
setSelected(value);
|
|
1128
|
-
}, options: workflowOptions, disabled: workflows.isPending }), _jsx(TextField, { label: "Name", value: draft.name, onChange: (name) => edit((current) => ({ ...current, name })), placeholder: "Fleet readiness", disabled: !canEdit }), _jsx(CanvasActions, { draft: draft, canEdit: canEdit, blocked: blocked, unfinished: unfinished, saving: save.isPending, running: runIt.isPending, durabilityDetail: durability.detail, onSave: saveNow, onRun:
|
|
1470
|
+
}, options: workflowOptions, disabled: workflows.isPending }), _jsx(TextField, { label: "Name", value: draft.name, onChange: (name) => edit((current) => ({ ...current, name })), placeholder: "Fleet readiness", disabled: !canEdit }), _jsx(CanvasActions, { draft: draft, stored: stored, canEdit: canEdit, blocked: blocked, unfinished: unfinished, saving: save.isPending, running: runIt.isPending, durabilityDetail: durability.detail, acknowledging: acknowledging, onAcknowledgingChange: setAcknowledging, onSave: saveNow, onRun: runNow, onLifecycleChange: onLifecycleChange, onAskDelete: () => setConfirmingDelete(true) })] }), 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(AddNodeBar, { refreshing: workflows.isFetching && !workflows.isPending, onAdd: addNode, onTidy: tidy })), _jsxs("div", { className: "flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto px-6 pb-5 pt-3 lg:flex-row lg:overflow-hidden", children: [_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,
|
|
1471
|
+
// Clicking empty canvas puts away everything that is half-open: the
|
|
1472
|
+
// wiring menu, and a wire that was started and never landed. React
|
|
1473
|
+
// Flow only fires this for clicks on the pane ITSELF, so finishing a
|
|
1474
|
+
// wire on a handle does not also cancel it on the way past.
|
|
1475
|
+
onPaneClick: () => {
|
|
1476
|
+
menu.close();
|
|
1477
|
+
wiring.cancel();
|
|
1478
|
+
}, 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 }) }), _jsx(WiringRail, { draft: draft, problems: live, pending: pending, run: run, canEdit: canEdit, onInspect: setInspecting, onDisconnect: disconnect, 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("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) => {
|
|
1129
1479
|
// Editing any field is the clearest statement there is that somebody
|
|
1130
1480
|
// is working on this node rather than looking at one they just made.
|
|
1131
1481
|
markStarted(next.id);
|
|
1482
|
+
// A discovered shape describes the source as it was addressed when it
|
|
1483
|
+
// was read. Change where or what this node reads and the columns on
|
|
1484
|
+
// file stop being about this node, so they are dropped rather than
|
|
1485
|
+
// compared — reporting a missing column against a query somebody has
|
|
1486
|
+
// since rewritten would be the validator inventing a fact, which is
|
|
1487
|
+
// the one thing `shape.ts` refuses to do. Renaming the node keeps
|
|
1488
|
+
// them: a name is not an address.
|
|
1489
|
+
//
|
|
1490
|
+
// Asked out here, against the rendered draft, rather than inside the
|
|
1491
|
+
// updater below: an updater is called again on every re-render React
|
|
1492
|
+
// decides to replay, and a `setState` in one is a side effect that
|
|
1493
|
+
// would fire with it.
|
|
1494
|
+
if (readsDifferently(draft.nodes.find((node) => node.id === next.id), next)) {
|
|
1495
|
+
forgetShape(next.id);
|
|
1496
|
+
}
|
|
1132
1497
|
edit((current) => ({
|
|
1133
1498
|
...current,
|
|
1134
1499
|
nodes: current.nodes.map((node) => (node.id === next.id ? next : node)),
|
|
1135
1500
|
}));
|
|
1136
|
-
}, onConnect: connect, onConnectToNew: connectToNew, onDisconnect: disconnect, onCreateTransform: (nodeId) => createTransform.mutate(nodeId), creatingTransform: createTransform.isPending, createTransformError: createTransform.error, onDelete: (nodeId) => {
|
|
1501
|
+
}, onConnect: connect, onConnectToNew: connectToNew, onDisconnect: disconnect, onBranch: setBranch, onCreateTransform: (nodeId) => createTransform.mutate(nodeId), creatingTransform: createTransform.isPending, createTransformError: createTransform.error, onDelete: (nodeId) => {
|
|
1137
1502
|
edit((current) => ({
|
|
1138
1503
|
...current,
|
|
1139
1504
|
nodes: current.nodes.filter((node) => node.id !== nodeId),
|
|
@@ -1149,7 +1514,7 @@ function Canvas({ title = WORKFLOW_NAME.titlePlural, eyebrow = 'Ingestion', intr
|
|
|
1149
1514
|
queryClient.invalidateQueries({
|
|
1150
1515
|
queryKey: catalogQueryKeys.transforms,
|
|
1151
1516
|
});
|
|
1152
|
-
} })) : (_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
|
|
1517
|
+
} })) : (_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) })] }));
|
|
1153
1518
|
}
|
|
1154
1519
|
function AddButton({ icon: Icon, label, hint, onClick, }) {
|
|
1155
1520
|
return (_jsx(Tooltip, { content: hint, children: _jsxs("button", { type: "button", onClick: onClick, "aria-label": `Add a ${label.toLowerCase()} node`, className: cn('flex items-center gap-1.5 rounded-md border px-2.5 py-1.5 text-xs', RULE, 'hover:bg-zinc-50 dark:hover:bg-zinc-800'), children: [_jsx(Plus, { size: 11 }), _jsx(Icon, { size: 12 }), label] }) }));
|
|
@@ -1182,6 +1547,29 @@ function DurabilityBanner({ durability, }) {
|
|
|
1182
1547
|
function CanvasSkeleton() {
|
|
1183
1548
|
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" })] }) }));
|
|
1184
1549
|
}
|
|
1550
|
+
/**
|
|
1551
|
+
* That there are none, said rather than drawn as a blank canvas.
|
|
1552
|
+
*
|
|
1553
|
+
* The zero case used to be nearly unreachable: a deployment that had connectors
|
|
1554
|
+
* got them wrapped into graphs at boot, so `#workflows` opened onto thirteen of
|
|
1555
|
+
* them. Nothing wraps anything now — a graph exists because somebody drew one —
|
|
1556
|
+
* so a deployment that has never drawn one opens onto an empty canvas, which is
|
|
1557
|
+
* pixel-identical to a workflow whose nodes have all been deleted and to a list
|
|
1558
|
+
* that failed to load in a way the query did not notice.
|
|
1559
|
+
*
|
|
1560
|
+
* So it says which of the three it is, and what to do about it. The distinction
|
|
1561
|
+
* this file already draws between {@link CanvasSkeleton} and
|
|
1562
|
+
* {@link CanvasFailure} is the same one, for the same reason: three states that
|
|
1563
|
+
* render identically and mean different things need one of them to speak.
|
|
1564
|
+
*
|
|
1565
|
+
* It carries no button. The control that creates a workflow is the `New
|
|
1566
|
+
* workflow` option already selected in the picker three lines below this note,
|
|
1567
|
+
* and a second affordance pointing at the same act is how somebody ends up
|
|
1568
|
+
* wondering whether the two do different things.
|
|
1569
|
+
*/
|
|
1570
|
+
function NothingDrawnYet() {
|
|
1571
|
+
return (_jsxs("div", { className: cn('mt-2.5 flex flex-wrap items-baseline gap-x-2 rounded-md border border-dashed px-2.5 py-1.5', 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('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
|
+
}
|
|
1185
1573
|
function CanvasFailure({ error, onRetry, }) {
|
|
1186
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("button", { type: "button", onClick: onRetry, className: "mt-3 rounded-md border border-red-300 px-3 py-1 text-xs text-red-700 dark:border-red-800 dark:text-red-300", children: "Try again" })] }) }));
|
|
1187
1575
|
}
|
|
@@ -1197,7 +1585,7 @@ function CanvasFailure({ error, onRetry, }) {
|
|
|
1197
1585
|
* The problems list sits in the same rail for the same reason: a red ring
|
|
1198
1586
|
* around a node off the left edge of the viewport communicates nothing.
|
|
1199
1587
|
*/
|
|
1200
|
-
function WiringRail({ draft, problems, pending, run, canEdit, onInspect, onDisconnect, }) {
|
|
1588
|
+
function WiringRail({ draft, problems, pending, run, canEdit, onInspect, onDisconnect, children, }) {
|
|
1201
1589
|
const label = (id) => {
|
|
1202
1590
|
const node = draft.nodes.find((n) => n.id === id);
|
|
1203
1591
|
return node ? nodeName(node) : id;
|
|
@@ -1205,7 +1593,7 @@ function WiringRail({ draft, problems, pending, run, canEdit, onInspect, onDisco
|
|
|
1205
1593
|
const errors = problems.filter((problem) => problem.level === 'error');
|
|
1206
1594
|
const warnings = problems.filter((problem) => problem.level === 'warning');
|
|
1207
1595
|
const sinks = draft.nodes.filter((node) => node.kind === 'sink');
|
|
1208
|
-
return (_jsxs("aside", { className: "flex w-full shrink-0 flex-col gap-3 lg:w-72 lg:min-h-0 lg:overflow-y-auto", "aria-label": `${WORKFLOW_NAME.title} wiring and problems`, children: [_jsxs("section", { className: cn('rounded-lg border p-3', RULE, PANEL), 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)))) }))] }), _jsx(PendingWork, { pending: pending, label: label, onInspect: onInspect }), _jsxs("section", { className: cn('rounded-lg border p-3', RULE, PANEL), 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, PANEL), 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) => {
|
|
1596
|
+
return (_jsxs("aside", { className: "flex w-full shrink-0 flex-col gap-3 lg:w-72 lg:min-h-0 lg:overflow-y-auto", "aria-label": `${WORKFLOW_NAME.title} wiring and problems`, children: [_jsxs("section", { className: cn('rounded-lg border p-3', RULE, PANEL), 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, _jsx(PendingWork, { pending: pending, label: label, onInspect: onInspect }), _jsxs("section", { className: cn('rounded-lg border p-3', RULE, PANEL), 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, PANEL), 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) => {
|
|
1209
1597
|
const outcome = run.nodes.find((node) => node.nodeId === sink.id);
|
|
1210
1598
|
const type = sink.kind === 'sink' && sink.targetType ? sink.targetType : 'no type';
|
|
1211
1599
|
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'
|
|
@@ -1246,8 +1634,21 @@ function PendingWork({ pending, label, onInspect, }) {
|
|
|
1246
1634
|
* description of it. Only which end of the edge to name, and how removing it is
|
|
1247
1635
|
* announced, differ; `children` carries whatever belongs under the list.
|
|
1248
1636
|
*/
|
|
1249
|
-
function WiringList({ title, edges, otherEnd, describeRemoval, canEdit, onDisconnect, children, }) {
|
|
1250
|
-
return (_jsxs("section", { children: [_jsx("h3", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: title }), edges.length === 0 ? (_jsx("p", { className: cn('mt-1 text-[11px]', MUTED), children: "Nothing yet." })) : (_jsx("ul", { className: "mt-1 space-y-1", children: edges.map((edge) => (_jsxs("li", { className: "flex items-center gap-1.5 text-[11px]", children: [_jsx("span", { className: "truncate", children: otherEnd(edge) }),
|
|
1637
|
+
function WiringList({ title, edges, otherEnd, describeRemoval, canEdit, onDisconnect, onBranch, children, }) {
|
|
1638
|
+
return (_jsxs("section", { children: [_jsx("h3", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: title }), edges.length === 0 ? (_jsx("p", { className: cn('mt-1 text-[11px]', MUTED), children: "Nothing yet." })) : (_jsx("ul", { className: "mt-1 space-y-1", children: edges.map((edge) => (_jsxs("li", { className: "flex items-center gap-1.5 text-[11px]", children: [_jsx("span", { className: "truncate", children: otherEnd(edge) }), onBranch && (
|
|
1639
|
+
// Beside the wire it belongs to rather than as two lists headed
|
|
1640
|
+
// "Then" and "Else", because the branch is a property of the
|
|
1641
|
+
// wire: splitting the list would mean a wire changing sides has
|
|
1642
|
+
// to move between two controls, and the order the wires were
|
|
1643
|
+
// drawn in — which is what the canvas draws — would be lost.
|
|
1644
|
+
_jsx("div", { className: "ml-auto w-28 shrink-0", children: _jsx(Select, { ariaLabel: `Which branch feeds ${otherEnd(edge)}`, value: edge.branch ?? '', onValueChange: (branch) => {
|
|
1645
|
+
if (!isWorkflowBranchLabel(branch))
|
|
1646
|
+
return;
|
|
1647
|
+
onBranch(edge, branch);
|
|
1648
|
+
}, options: WORKFLOW_BRANCH_LABELS.map((label) => ({
|
|
1649
|
+
value: label,
|
|
1650
|
+
label,
|
|
1651
|
+
})), placeholder: "branch?", disabled: !canEdit }) })), canEdit && (_jsx(Tooltip, { content: "Remove this connection.", children: _jsx("button", { type: "button", onClick: () => onDisconnect(edge), "aria-label": describeRemoval(otherEnd(edge)), className: "ml-auto rounded p-0.5 text-zinc-400 hover:text-red-600", children: _jsx(Unplug, { size: 11 }) }) }))] }, edgeId(edge)))) })), children] }));
|
|
1251
1652
|
}
|
|
1252
1653
|
/**
|
|
1253
1654
|
* Which code runs here, and a way into it.
|
|
@@ -1293,9 +1694,23 @@ function TransformInspector({ node, transforms, canEdit, creating, createError,
|
|
|
1293
1694
|
*
|
|
1294
1695
|
* The type is set here, on the node that commits it, rather than once for the
|
|
1295
1696
|
* whole graph — several sinks may write several types.
|
|
1697
|
+
*
|
|
1698
|
+
* ## The way out to the type
|
|
1699
|
+
*
|
|
1700
|
+
* This inspector is the one place in the whole canvas that names an object type,
|
|
1701
|
+
* so it is the only honest place for a link to the model screen. It sits under
|
|
1702
|
+
* the picker rather than in the header, and it names the type rather than saying
|
|
1703
|
+
* "Open the model": the destination is that type's page, and a link whose label
|
|
1704
|
+
* describes a screen rather than a thing gives no clue what pressing it shows.
|
|
1705
|
+
*
|
|
1706
|
+
* Rendered only when a type is actually chosen. A fresh sink's `targetType` is
|
|
1707
|
+
* the empty string, and `#model?type=` names nothing — it would land on the
|
|
1708
|
+
* model screen's first type and look, exactly, like a link that worked.
|
|
1296
1709
|
*/
|
|
1297
|
-
function SinkInspector({ node, typeOptions, canEdit, onChange, }) {
|
|
1298
|
-
|
|
1710
|
+
function SinkInspector({ node, typeOptions, canEdit, modelHref, onChange, }) {
|
|
1711
|
+
const target = node.targetType.trim();
|
|
1712
|
+
const href = target.length > 0 ? modelHref?.(target) : undefined;
|
|
1713
|
+
return (_jsxs("div", { className: "space-y-3", children: [_jsx(SelectField, { label: "Commits", ariaLabel: "Which object type this sink writes", value: node.targetType, onValueChange: (targetType) => onChange({ ...node, targetType }), options: typeOptions, placeholder: "Choose one type\u2026", disabled: !canEdit, hint: "The type is set here, on the node that commits it, rather than once for the whole graph \u2014 several sinks may write several types." }), href && (_jsxs("a", { href: href, "aria-label": `Open ${target} on the model screen`, className: cn('inline-flex items-center gap-1.5 rounded-md border px-2.5 py-1.5 text-xs outline-none', RULE, 'hover:bg-zinc-50 focus-visible:ring-2 focus-visible:ring-sky-500/40 dark:hover:bg-zinc-800'), children: [_jsx(Database, { size: 12, "aria-hidden": true }), "Open ", target, _jsx(ExternalLink, { size: 12, "aria-hidden": true, className: MUTED })] })), _jsx(SelectField, { label: "Commit mode", ariaLabel: "Whether this sink replaces the dataset or merges into it", value: node.mode ?? 'full', onValueChange: (mode) => onChange({
|
|
1299
1714
|
...node,
|
|
1300
1715
|
mode: mode === 'incremental' ? 'incremental' : 'full',
|
|
1301
1716
|
}), options: [
|
|
@@ -1303,7 +1718,592 @@ function SinkInspector({ node, typeOptions, canEdit, onChange, }) {
|
|
|
1303
1718
|
{ value: 'incremental', label: 'Incremental — merge into it' },
|
|
1304
1719
|
], disabled: !canEdit }), _jsxs("p", { className: cn('text-[11px] leading-relaxed', MUTED), children: ["This sink commits ", node.targetType || 'its type', " on its own. Another sink in the same graph committing a different type is a separate commit \u2014 one can succeed while this one fails, and the run is reported as failed when any of them does."] })] }));
|
|
1305
1720
|
}
|
|
1306
|
-
|
|
1721
|
+
/**
|
|
1722
|
+
* Which workflow this node hands its step to, and what it hands it.
|
|
1723
|
+
*
|
|
1724
|
+
* ## There is a picker now, and there was not before
|
|
1725
|
+
*
|
|
1726
|
+
* This used to be two text fields and a docblock explaining why a dropdown
|
|
1727
|
+
* could not be built honestly, and that explanation is worth keeping because it
|
|
1728
|
+
* is still what the picker has to be careful about. Nothing could enumerate a
|
|
1729
|
+
* deployment's registrations: the durable engine answered
|
|
1730
|
+
* `workflowBody(name, version)` for the process asking and nothing else, and a
|
|
1731
|
+
* missing body meant *either* "not registered" *or* "its body is in another SDK
|
|
1732
|
+
* behind `registerRemote`" *or* "it is a group resolved by convention against a
|
|
1733
|
+
* live worker". A list inferred from that would have omitted precisely the
|
|
1734
|
+
* cross-SDK workflows this node exists to call, and omitted them silently — a
|
|
1735
|
+
* picker that quietly hides the thing you are looking for is worse than a text
|
|
1736
|
+
* box.
|
|
1737
|
+
*
|
|
1738
|
+
* `@dudousxd/nestjs-durable-core` **0.65.0** added
|
|
1739
|
+
* `WorkflowEngine.announcedWorkflows()`, which is not an inference: live workers
|
|
1740
|
+
* publish what they can execute on the descriptor keyspace and every pod folds
|
|
1741
|
+
* the same statements. `GET pipeline/callable-workflows` serves it as
|
|
1742
|
+
* `CallableWorkflowRef`s, and the two fields below offer them. Three properties
|
|
1743
|
+
* of that aggregate are load-bearing here and none of them may be flattened:
|
|
1744
|
+
*
|
|
1745
|
+
* - **It lists what is runnable now, not what is known about.** The announcer is
|
|
1746
|
+
* always the queue's consumer, so it is neither a superset nor a subset of any
|
|
1747
|
+
* registry. A workflow missing from it may be perfectly real.
|
|
1748
|
+
* - **It is a snapshot about one heartbeat wide.** Liveness is a TTL on the
|
|
1749
|
+
* descriptor key, so a worker that dies takes its entries with it within about
|
|
1750
|
+
* half a minute. Hence the ten-second `staleTime` below, the refetch on mount,
|
|
1751
|
+
* and the time printed under the field. It is never cached like
|
|
1752
|
+
* `capabilities`, which is stale-forever and correctly so.
|
|
1753
|
+
* - **Disagreements are surfaced, never resolved.** Two workers claiming one
|
|
1754
|
+
* `name@version` from two groups mean nobody can say which queue a run would
|
|
1755
|
+
* land on, so `callableWorkflowBlock` — core's rule, shared with the server —
|
|
1756
|
+
* refuses the entry. It is still SHOWN, greyed, with the reason: an entry
|
|
1757
|
+
* silently dropped from a picker is the failure the old docblock was about.
|
|
1758
|
+
*
|
|
1759
|
+
* The same rule refuses a bare, unversioned announcement, which is what an
|
|
1760
|
+
* un-upgraded worker of any SDK publishes. A name with no version cannot satisfy
|
|
1761
|
+
* the pin, and offering it as though it could would be a lie the node then
|
|
1762
|
+
* carries.
|
|
1763
|
+
*
|
|
1764
|
+
* ## Two searchable fields, not one select over `name@version`
|
|
1765
|
+
*
|
|
1766
|
+
* The first shape of this was a single `SelectField` listing combined
|
|
1767
|
+
* `name@version` keys, with the two text fields left underneath it. Three things
|
|
1768
|
+
* were wrong with that and all three are fixed here.
|
|
1769
|
+
*
|
|
1770
|
+
* - **A popup with no search is unusable at fleet size.** A deployment
|
|
1771
|
+
* announcing three hundred workflows renders three hundred rows, and the only
|
|
1772
|
+
* gesture over them is "scroll until you see it". Both fields are `Combobox`
|
|
1773
|
+
* now: type to narrow, on the name, the group and the description.
|
|
1774
|
+
* - **Name and version are two questions and read as two.** Choosing the
|
|
1775
|
+
* workflow and choosing which of its versions to pin are separate decisions,
|
|
1776
|
+
* and a list of `billing.reconcile@1`, `billing.reconcile@2`,
|
|
1777
|
+
* `billing.reconcile@3` makes the *name* list three times longer to answer a
|
|
1778
|
+
* question about versions. The name field lists names; the version field
|
|
1779
|
+
* lists the versions announced for the name that was chosen.
|
|
1780
|
+
* - **Three controls for two values is one too many.** The select and the text
|
|
1781
|
+
* fields said the same two things twice, and a select that could not express
|
|
1782
|
+
* what somebody typed had to be shown next to a box that could.
|
|
1783
|
+
*
|
|
1784
|
+
* ## Typing something the fleet never announced still works
|
|
1785
|
+
*
|
|
1786
|
+
* That is why these are `Combobox`es and not `Select`s, and it is the property
|
|
1787
|
+
* the whole node depends on. A deployment whose workers have not been upgraded
|
|
1788
|
+
* announces little or nothing, and a picker that became the only path would make
|
|
1789
|
+
* this node unusable there. Base UI's `Autocomplete` has no *selected value* at
|
|
1790
|
+
* all — the input's text is the value and the list is a suggestion over it — so
|
|
1791
|
+
* both fields remain typeable at all times, including when the list is empty,
|
|
1792
|
+
* unavailable, or simply does not contain what somebody is pointing at.
|
|
1793
|
+
*
|
|
1794
|
+
* ## Both halves, or neither
|
|
1795
|
+
*
|
|
1796
|
+
* Splitting one select into two raised the failure the single select could not
|
|
1797
|
+
* have: a name committed on its own, leaving a node that looks configured and
|
|
1798
|
+
* runs whatever is newest on the day it runs. See {@link CallInspector}'s
|
|
1799
|
+
* `chooseName` — choosing a name writes the version in the SAME update whenever
|
|
1800
|
+
* the fleet announces exactly one, which is the common case and stays one
|
|
1801
|
+
* action, and blanks it rather than guessing when it does not. Blank is refused
|
|
1802
|
+
* by `callIsUnnamed`, and the note under the field says so before the save does.
|
|
1803
|
+
*
|
|
1804
|
+
* ## Why the version is a required field and not a convenience
|
|
1805
|
+
*
|
|
1806
|
+
* Without it the load would run whichever version is registered on the day it
|
|
1807
|
+
* runs, so the person who owns that workflow could change what this pipeline
|
|
1808
|
+
* does by deploying theirs. With it, a mismatch stops the load and says so.
|
|
1809
|
+
* What it still cannot do is *prevent* the wrong version starting. `engine.start`
|
|
1810
|
+
* takes a pinned `version` as of durable 0.65.0, but the catalog does not pass
|
|
1811
|
+
* one, and that is a decision rather than an oversight: a pinned start is
|
|
1812
|
+
* refused outright on the two SYNTHESIZED registration paths — a child
|
|
1813
|
+
* inheriting a remote ancestor's routing, and convention routing to a live
|
|
1814
|
+
* worker group — which are exactly how a cross-SDK workflow is reached. Pinning
|
|
1815
|
+
* at the start would therefore break the calls this node exists for. So the
|
|
1816
|
+
* check still happens immediately after the start, and cancels. The note under
|
|
1817
|
+
* the fields says that in the room where somebody is typing the version, rather
|
|
1818
|
+
* than only in a docblock they will never open.
|
|
1819
|
+
*/
|
|
1820
|
+
function CallInspector({ node, canEdit, onChange, }) {
|
|
1821
|
+
// Held locally, pushed up when it parses — the same rule `SourceInspector`
|
|
1822
|
+
// follows for its text fields. Re-deriving the box from the stored config
|
|
1823
|
+
// would rewrite what somebody is halfway through typing, and a JSON editor
|
|
1824
|
+
// that reformats mid-keystroke is unusable.
|
|
1825
|
+
const [text, setText] = useState(() => configText(node.config));
|
|
1826
|
+
const [invalid, setInvalid] = useState(false);
|
|
1827
|
+
const client = useCatalogClient();
|
|
1828
|
+
// Asked here rather than by the canvas and threaded down, because this is the
|
|
1829
|
+
// only component that wants it and a call node is a small minority of the
|
|
1830
|
+
// nodes anybody draws — a canvas-level query would ask every deployment for
|
|
1831
|
+
// its fleet on every page load to serve a field most graphs never open.
|
|
1832
|
+
const announced = useQuery({
|
|
1833
|
+
queryKey: catalogQueryKeys.callableWorkflows,
|
|
1834
|
+
queryFn: () => client.listCallableWorkflows(),
|
|
1835
|
+
// Ten seconds, against the descriptor TTL of about thirty-five. Long enough
|
|
1836
|
+
// that opening and closing the sheet does not re-ask, short enough that a
|
|
1837
|
+
// worker which died while somebody was reading is gone before they choose.
|
|
1838
|
+
// Emphatically NOT `Infinity`, which is right for `capabilities` and would
|
|
1839
|
+
// here pin the list to whatever the fleet looked like when the tab opened.
|
|
1840
|
+
staleTime: 10_000,
|
|
1841
|
+
retry: false,
|
|
1842
|
+
});
|
|
1843
|
+
const pushConfig = (next) => {
|
|
1844
|
+
setText(next);
|
|
1845
|
+
const parsed = parseConfigText(next);
|
|
1846
|
+
setInvalid(parsed === undefined);
|
|
1847
|
+
if (parsed !== undefined)
|
|
1848
|
+
onChange({ ...node, config: parsed });
|
|
1849
|
+
};
|
|
1850
|
+
const refs = announced.data?.workflows ?? [];
|
|
1851
|
+
const name = node.callName.trim();
|
|
1852
|
+
const version = node.callVersion.trim();
|
|
1853
|
+
// Every announcement of the name currently in the box — including the blocked
|
|
1854
|
+
// ones, which is the point. What the version field offers is derived from
|
|
1855
|
+
// this, so an entry that cannot be pinned appears there greyed rather than
|
|
1856
|
+
// vanishing between the two fields.
|
|
1857
|
+
const forName = refs.filter((ref) => ref.name === name);
|
|
1858
|
+
const nameOptions = callableNameOptions(refs);
|
|
1859
|
+
const versionOptions = callableVersionOptions(forName);
|
|
1860
|
+
// The one announcement this node is pinned to, when it is pinned to one at
|
|
1861
|
+
// all. A node pointing at something the fleet is not announcing gets no
|
|
1862
|
+
// confirmation line rather than a nearest match — saying "a live worker
|
|
1863
|
+
// announces this" about an entry nobody announced is the lie the whole
|
|
1864
|
+
// component is arranged against.
|
|
1865
|
+
//
|
|
1866
|
+
// A blocked entry can never be it, however exactly the two strings line up:
|
|
1867
|
+
// an `ambiguous-group` entry is not a pin anybody can act on, and an entry
|
|
1868
|
+
// with no version cannot be one at all, however empty the version field
|
|
1869
|
+
// happens to be.
|
|
1870
|
+
const chosen = forName.find((ref) => ref.version !== undefined && ref.version === version && !callableWorkflowBlock(ref));
|
|
1871
|
+
const blocked = refs
|
|
1872
|
+
.map((ref) => ({ ref, block: callableWorkflowBlock(ref) }))
|
|
1873
|
+
.filter((entry) => Boolean(entry.block));
|
|
1874
|
+
// Announced, pinnable and not yet chosen: the state where the name is settled
|
|
1875
|
+
// and the version is a real question. Worth a sentence of its own because it
|
|
1876
|
+
// is the ONLY way this pair of fields can leave a node half-pinned, and the
|
|
1877
|
+
// person who just picked a name is the one who can finish it.
|
|
1878
|
+
const undecided = name.length > 0 && version.length === 0 && versionOptions.length > 0;
|
|
1879
|
+
// Two different silences, and telling somebody the wrong one is worse than
|
|
1880
|
+
// telling them nothing. An empty aggregate is a fact about the DEPLOYMENT and
|
|
1881
|
+
// the server's own sentence explains it; an empty aggregate is not what a
|
|
1882
|
+
// search that matched none of three hundred announcements means, and printing
|
|
1883
|
+
// "no durable engine resolved" over that would be a diagnosis of the wrong
|
|
1884
|
+
// thing entirely.
|
|
1885
|
+
let noNames;
|
|
1886
|
+
if (announced.isPending)
|
|
1887
|
+
noNames = 'Asking the live workers what they can execute…';
|
|
1888
|
+
else if (refs.length > 0)
|
|
1889
|
+
noNames =
|
|
1890
|
+
'No live worker announces a workflow by that name. Type it anyway if you know it is there — a worker too old to publish its registrations still runs the workflow.';
|
|
1891
|
+
else
|
|
1892
|
+
noNames =
|
|
1893
|
+
announced.data?.detail ??
|
|
1894
|
+
'Nothing here could be asked what this deployment can execute, so there is no list to choose from. Type the workflow name and the version to pin.';
|
|
1895
|
+
/**
|
|
1896
|
+
* Commit a name, and the version with it whenever the fleet leaves no choice.
|
|
1897
|
+
*
|
|
1898
|
+
* Splitting one `name@version` select into two fields is what makes this
|
|
1899
|
+
* function necessary: a name committed on its own leaves a node that looks
|
|
1900
|
+
* configured and runs whatever is newest on the day it runs, which is the
|
|
1901
|
+
* single failure the pin exists to prevent. So the version moves in the SAME
|
|
1902
|
+
* update, by three rules, in order:
|
|
1903
|
+
*
|
|
1904
|
+
* 1. **The version already held is announced for the new name** — keep it.
|
|
1905
|
+
* Re-picking the same name must not disturb a settled node, and a version
|
|
1906
|
+
* two workflows share is not a coincidence worth punishing.
|
|
1907
|
+
* 2. **The version is blank, or was the old name's** — replace it. Blank is
|
|
1908
|
+
* the fresh node; the old name's version is now stale, and leaving it would
|
|
1909
|
+
* produce a pin nobody announced while looking like one somebody chose. It
|
|
1910
|
+
* becomes the one pinnable version when there is exactly one — the common
|
|
1911
|
+
* case, and it stays one action — and blank otherwise, because a guess
|
|
1912
|
+
* between two versions is the thing the pin exists to stop. Blank is
|
|
1913
|
+
* refused by `callIsUnnamed` and said out loud under the field.
|
|
1914
|
+
* 3. **Anything else** — leave it. A version somebody typed that the fleet
|
|
1915
|
+
* never offered is theirs, and this field has no standing to erase it.
|
|
1916
|
+
*
|
|
1917
|
+
* `callableWorkflowBlock` decides what counts as pinnable throughout, here at
|
|
1918
|
+
* the moment of commit and not only where rows are greyed. A disabled row is a
|
|
1919
|
+
* rendering decision; the rule about what may be written onto the graph is not
|
|
1920
|
+
* one, and a Base UI item that stopped honouring `disabled` must not be able
|
|
1921
|
+
* to get round it.
|
|
1922
|
+
*/
|
|
1923
|
+
const chooseName = (option) => {
|
|
1924
|
+
const offered = pinnableVersions(refs, option.value);
|
|
1925
|
+
if (offered.length === 0)
|
|
1926
|
+
return;
|
|
1927
|
+
if (offered.includes(version)) {
|
|
1928
|
+
onChange({ ...node, callName: option.value });
|
|
1929
|
+
return;
|
|
1930
|
+
}
|
|
1931
|
+
const ours = version.length === 0 || pinnableVersions(refs, name).includes(version);
|
|
1932
|
+
const only = offered.length === 1 ? offered[0] : undefined;
|
|
1933
|
+
onChange({ ...node, callName: option.value, callVersion: ours ? (only ?? '') : version });
|
|
1934
|
+
};
|
|
1935
|
+
/**
|
|
1936
|
+
* Commit a version, against the name in the box.
|
|
1937
|
+
*
|
|
1938
|
+
* Looked up as an announcement rather than taken as a string, for the same
|
|
1939
|
+
* reason `chooseName` re-checks: the row carries a claim, and the claim is
|
|
1940
|
+
* what `callableWorkflowBlock` gets to refuse.
|
|
1941
|
+
*/
|
|
1942
|
+
const chooseVersion = (option) => {
|
|
1943
|
+
const ref = forName.find((candidate) => candidate.version === option.value);
|
|
1944
|
+
if (!ref || ref.version === undefined || callableWorkflowBlock(ref))
|
|
1945
|
+
return;
|
|
1946
|
+
onChange({ ...node, callName: ref.name, callVersion: ref.version });
|
|
1947
|
+
};
|
|
1948
|
+
return (_jsxs("div", { className: "space-y-3", children: [_jsx(ComboboxField, { label: "Workflow", value: node.callName, onValueChange: (callName) => onChange({ ...node, callName }), onSelect: chooseName, options: nameOptions, placeholder: "billing.reconcile", disabled: !canEdit, emptyMessage: noNames, hint: _jsxs(_Fragment, { children: ["The name it is registered under in this deployment, exactly. Type to search what a live worker says it can execute right now, read at ", readTime(announced.data?.observedAt), " \u2014 a snapshot, not a registry, so a worker that stops beating drops off it within about half a minute and one too old to announce its registrations was never on it. Anything you type is accepted whether or not it is on the list; its body may be in another language, which is the point of calling it rather than writing it here."] }) }), _jsx(ComboboxField, { label: "Version", value: node.callVersion, onValueChange: (callVersion) => onChange({ ...node, callVersion }), onSelect: chooseVersion, options: versionOptions, placeholder: "1", disabled: !canEdit, emptyMessage: name.length === 0
|
|
1949
|
+
? 'Name a workflow first, and the versions announced for it are listed here.'
|
|
1950
|
+
: `No live worker announces a version of "${name}". Type the one you mean.`, hint: "Pinned, and part of what this graph is. Registered without a version, a workflow is version 1. Repointing this at another version is an edit to this graph, and shows up as one." }), undecided && (_jsxs("p", { className: cn('text-[11px] leading-relaxed', MUTED), children: ["The fleet announces more than one version of \u201C", name, "\u201D, so nothing here picked one for you. Until you do, this node names half of what it needs and the graph will not save."] })), chosen && (_jsxs("p", { className: cn('text-[11px] leading-relaxed', MUTED), children: ["This exact pin is announced right now: ", chosen.name, "@", chosen.version, chosen.group ? `, on group ${chosen.group}` : '', chosen.workers === 1 ? ' — by one worker, so it is a single point of failure.' : '.'] })), blocked.length > 0 && (_jsx("div", { className: cn('space-y-1 text-[11px] leading-relaxed', MUTED), children: blocked.map(({ ref, block }) => (_jsx("p", { children: block.message }, callableKey(ref)))) })), _jsx(TextAreaField, { label: "Parameters", value: text, onChange: pushConfig, rows: 5, mono: true, placeholder: "{}", disabled: !canEdit, hint: invalid
|
|
1951
|
+
? 'That is not valid JSON yet, so it has not been saved onto the node.'
|
|
1952
|
+
: 'A JSON object, handed to the workflow as `input`. Beside it, under `catalog`, it also gets this run’s id and the staged rows of whatever feeds this node — handles, never the rows themselves. Not a place for a password: name an env var the callee already reads.' }), _jsx("p", { className: cn('text-[11px] leading-relaxed', MUTED), children: "This runs as a child of the load, with its own retries, and the load waits for it. If it fails, this node fails and nothing after it runs. Cancelling the load cancels it; letting the load time out does not, so a workflow you call should carry its own execution timeout." }), _jsxs("p", { className: cn('text-[11px] leading-relaxed', MUTED), children: ["Whether two loads calling it can overlap is decided by how ", _jsx("em", { children: "it" }), " was registered, not by this graph \u2014 and on the path a workflow in another language is reached by, that declaration may not be visible to the engine at all, so assume it can run alongside itself."] })] }));
|
|
1953
|
+
}
|
|
1954
|
+
/**
|
|
1955
|
+
* What identifies one announced entry among the others.
|
|
1956
|
+
*
|
|
1957
|
+
* `name@version`, and the bare name when nobody announced a version — the same
|
|
1958
|
+
* key the durable aggregate sorts on, and the reason it can identify a row at
|
|
1959
|
+
* all: the fleet reports one entry per `name@version`, so two entries can never
|
|
1960
|
+
* collide. A key of the name alone would collapse the versions into one, which
|
|
1961
|
+
* is the picker undoing the pin.
|
|
1962
|
+
*/
|
|
1963
|
+
function callableKey(ref) {
|
|
1964
|
+
return ref.version === undefined ? ref.name : `${ref.name}@${ref.version}`;
|
|
1965
|
+
}
|
|
1966
|
+
/**
|
|
1967
|
+
* The announced names, one row each, for the workflow field.
|
|
1968
|
+
*
|
|
1969
|
+
* One row per NAME here and one row per version in the field below, which is the
|
|
1970
|
+
* split this pair of fields exists to make. A single list of `name@version` keys
|
|
1971
|
+
* answers the version question inside the name question: a workflow with eight
|
|
1972
|
+
* versions takes eight rows of a list somebody is scanning for a name, and the
|
|
1973
|
+
* name they want is eight times harder to find because of versions they have not
|
|
1974
|
+
* been asked about yet.
|
|
1975
|
+
*
|
|
1976
|
+
* A name is refused only when EVERY announcement under it is refused — one
|
|
1977
|
+
* unpinnable version among four pinnable ones says nothing about the name. The
|
|
1978
|
+
* refusals themselves are per entry and belong to the version field, which shows
|
|
1979
|
+
* them; this line only reports that there is nothing pinnable left.
|
|
1980
|
+
*/
|
|
1981
|
+
function callableNameOptions(refs) {
|
|
1982
|
+
const names = [...new Set(refs.map((ref) => ref.name))].sort();
|
|
1983
|
+
return names.map((name) => callableNameOption(name, refs.filter((ref) => ref.name === name)));
|
|
1984
|
+
}
|
|
1985
|
+
/** One name, folded across every announcement of it. */
|
|
1986
|
+
function callableNameOption(name, forName) {
|
|
1987
|
+
const pinnable = forName.filter((ref) => callableWorkflowBlock(ref) === undefined);
|
|
1988
|
+
const groups = [...new Set(forName.flatMap(groupsOf))].sort();
|
|
1989
|
+
const description = forName.find((ref) => ref.description !== undefined)?.description;
|
|
1990
|
+
const workers = forName.reduce((most, ref) => Math.max(most, ref.workers ?? 0), 0);
|
|
1991
|
+
const facts = pinnable.length === 0 ? refusalFacts(forName) : [countOf(pinnable.length, 'version')];
|
|
1992
|
+
// The group is the single most useful fact here — the only signal
|
|
1993
|
+
// distinguishing "this body lives in another process, in another language"
|
|
1994
|
+
// from "this one is local", which is precisely what a missing `workflowBody`
|
|
1995
|
+
// could never tell apart.
|
|
1996
|
+
if (groups.length === 1)
|
|
1997
|
+
facts.push(`group ${groups[0]}`);
|
|
1998
|
+
if (groups.length > 1)
|
|
1999
|
+
facts.push(`groups ${groups.join(', ')}`);
|
|
2000
|
+
if (description)
|
|
2001
|
+
facts.push(description);
|
|
2002
|
+
// One worker is a single point of failure, and a graph built on it should say
|
|
2003
|
+
// so before the day it matters.
|
|
2004
|
+
if (workers > 0)
|
|
2005
|
+
facts.push(countOf(workers, 'worker'));
|
|
2006
|
+
return {
|
|
2007
|
+
value: name,
|
|
2008
|
+
label: name,
|
|
2009
|
+
hint: facts.join(' · '),
|
|
2010
|
+
// Searched but not shown. Somebody hunting the Python half of the fleet
|
|
2011
|
+
// types the group, and somebody who half-remembers what a workflow does
|
|
2012
|
+
// types that — a search over the name alone answers both with "nothing".
|
|
2013
|
+
keywords: [...groups, description ?? ''].join(' '),
|
|
2014
|
+
disabled: pinnable.length === 0,
|
|
2015
|
+
};
|
|
2016
|
+
}
|
|
2017
|
+
/**
|
|
2018
|
+
* Why nothing under a name can be pinned, in the few words a popup row has.
|
|
2019
|
+
*
|
|
2020
|
+
* Short deliberately: this line truncates inside the popup, and the full
|
|
2021
|
+
* sentences `callableWorkflowBlock` writes are printed under the fields, where
|
|
2022
|
+
* nothing truncates them.
|
|
2023
|
+
*/
|
|
2024
|
+
function refusalFacts(forName) {
|
|
2025
|
+
const codes = new Set(forName.map((ref) => callableWorkflowBlock(ref)?.code));
|
|
2026
|
+
const facts = [];
|
|
2027
|
+
if (codes.has('no-version'))
|
|
2028
|
+
facts.push('no version announced — cannot be pinned');
|
|
2029
|
+
if (codes.has('ambiguous-group'))
|
|
2030
|
+
facts.push('claimed by two groups — ambiguous');
|
|
2031
|
+
return facts;
|
|
2032
|
+
}
|
|
2033
|
+
/**
|
|
2034
|
+
* The versions announced for one name, one row each.
|
|
2035
|
+
*
|
|
2036
|
+
* Every announcement of that name, including the ones that cannot be chosen. A
|
|
2037
|
+
* bare, unversioned announcement — what an un-upgraded worker of any SDK
|
|
2038
|
+
* publishes — is a row here too, greyed and labelled as having no version: it is
|
|
2039
|
+
* a real thing the fleet said about this name, and the alternative is a picker
|
|
2040
|
+
* that quietly disagrees with the sentence printed underneath it.
|
|
2041
|
+
*/
|
|
2042
|
+
function callableVersionOptions(forName) {
|
|
2043
|
+
return forName
|
|
2044
|
+
.map(callableVersionOption)
|
|
2045
|
+
.sort((left, right) => left.label.localeCompare(right.label, undefined, { numeric: true }));
|
|
2046
|
+
}
|
|
2047
|
+
function callableVersionOption(ref) {
|
|
2048
|
+
const block = callableWorkflowBlock(ref);
|
|
2049
|
+
const facts = [];
|
|
2050
|
+
if (block?.code === 'no-version')
|
|
2051
|
+
facts.push('no version announced — cannot be pinned');
|
|
2052
|
+
if (block?.code === 'ambiguous-group')
|
|
2053
|
+
facts.push(`two groups (${groupsOf(ref).join(', ')}) — ambiguous`);
|
|
2054
|
+
if (ref.group)
|
|
2055
|
+
facts.push(`group ${ref.group}`);
|
|
2056
|
+
if (ref.description)
|
|
2057
|
+
facts.push(ref.description);
|
|
2058
|
+
if (ref.workers !== undefined)
|
|
2059
|
+
facts.push(countOf(ref.workers, 'worker'));
|
|
2060
|
+
return {
|
|
2061
|
+
// The fleet folds one entry per `name@version`, so within one name the
|
|
2062
|
+
// versions are distinct and at most one entry is bare — which makes the
|
|
2063
|
+
// empty string a safe identity for that one rather than a collision.
|
|
2064
|
+
value: ref.version ?? '',
|
|
2065
|
+
label: ref.version ?? 'no version announced',
|
|
2066
|
+
hint: facts.join(' · '),
|
|
2067
|
+
keywords: [ref.group ?? '', ref.description ?? ''].join(' '),
|
|
2068
|
+
disabled: block !== undefined,
|
|
2069
|
+
};
|
|
2070
|
+
}
|
|
2071
|
+
/** "1 worker" / "3 workers". A count whose plural is not left to the reader. */
|
|
2072
|
+
function countOf(count, noun) {
|
|
2073
|
+
return count === 1 ? `1 ${noun}` : `${count} ${noun}s`;
|
|
2074
|
+
}
|
|
2075
|
+
/**
|
|
2076
|
+
* The versions of one name that may actually be pinned.
|
|
2077
|
+
*
|
|
2078
|
+
* `callableWorkflowBlock` is the authority, not the presence of a version
|
|
2079
|
+
* string: an `ambiguous-group` entry has a perfectly good version and still may
|
|
2080
|
+
* not be committed.
|
|
2081
|
+
*/
|
|
2082
|
+
function pinnableVersions(refs, name) {
|
|
2083
|
+
const versions = [];
|
|
2084
|
+
for (const ref of refs) {
|
|
2085
|
+
if (ref.name !== name || ref.version === undefined)
|
|
2086
|
+
continue;
|
|
2087
|
+
if (callableWorkflowBlock(ref) === undefined)
|
|
2088
|
+
versions.push(ref.version);
|
|
2089
|
+
}
|
|
2090
|
+
return versions;
|
|
2091
|
+
}
|
|
2092
|
+
/**
|
|
2093
|
+
* Every group named in one announcement.
|
|
2094
|
+
*
|
|
2095
|
+
* `group` is set when the announcers agree on exactly one, and left unset when
|
|
2096
|
+
* they disagree — in which case the values are in `disagreements` and both are
|
|
2097
|
+
* worth showing. Silence contributes nothing, because silence is not a claim.
|
|
2098
|
+
*/
|
|
2099
|
+
function groupsOf(ref) {
|
|
2100
|
+
if (ref.group !== undefined)
|
|
2101
|
+
return [ref.group];
|
|
2102
|
+
return ref.disagreements?.find((entry) => entry.axis === 'group')?.values ?? [];
|
|
2103
|
+
}
|
|
2104
|
+
/**
|
|
2105
|
+
* When the fleet was asked, as a clock time.
|
|
2106
|
+
*
|
|
2107
|
+
* Printed at all because this list is a snapshot roughly one heartbeat wide, and
|
|
2108
|
+
* a screen that showed it with no time attached would be presenting a moment as
|
|
2109
|
+
* a standing fact. Falls back to the plain string rather than to nothing when
|
|
2110
|
+
* the server sends something unparseable — a server that answered is a server
|
|
2111
|
+
* that answered, and hiding its timestamp because the format surprised us would
|
|
2112
|
+
* remove the one caveat this field is here to carry.
|
|
2113
|
+
*/
|
|
2114
|
+
function readTime(observedAt) {
|
|
2115
|
+
if (!observedAt)
|
|
2116
|
+
return 'an unknown time';
|
|
2117
|
+
const at = new Date(observedAt);
|
|
2118
|
+
return Number.isNaN(at.getTime()) ? observedAt : at.toLocaleTimeString();
|
|
2119
|
+
}
|
|
2120
|
+
/**
|
|
2121
|
+
* What this gate decides on, and what the decision costs.
|
|
2122
|
+
*
|
|
2123
|
+
* ## The kind of test comes first, and switching it replaces the test
|
|
2124
|
+
*
|
|
2125
|
+
* A gate tests one thing — a variable where the load runs, or how many rows
|
|
2126
|
+
* reached it — and the model says so with a union rather than with two sets of
|
|
2127
|
+
* optional fields. The form is built the same way round: pick the kind, then
|
|
2128
|
+
* fill in the fields that kind has. Switching the picker hands back a whole new
|
|
2129
|
+
* predicate rather than merging the old one's fields into it, which does discard
|
|
2130
|
+
* a variable name somebody typed — deliberately, because the alternative is a
|
|
2131
|
+
* node quietly carrying the leftovers of a test it is no longer making, and the
|
|
2132
|
+
* next reader cannot tell which of the two it will actually do.
|
|
2133
|
+
*
|
|
2134
|
+
* ## No picker for the variable, for a different reason than the call node's
|
|
2135
|
+
*
|
|
2136
|
+
* A call node has no picker because nothing can enumerate the workflows. This
|
|
2137
|
+
* one has no picker because the list would be *wrong*: the variables that matter
|
|
2138
|
+
* are the ones this deployment has and the other one does not, so a list built
|
|
2139
|
+
* from what the console's own process can see would offer exactly the wrong set
|
|
2140
|
+
* — the ones present everywhere — and quietly omit the one somebody is looking
|
|
2141
|
+
* for. Text, and the graph is refused until it is filled in.
|
|
2142
|
+
*
|
|
2143
|
+
* ## What is said out loud here and nowhere else
|
|
2144
|
+
*
|
|
2145
|
+
* That the value never leaves the machine, because somebody typing
|
|
2146
|
+
* `CLICKHOUSE_URL` into a form is entitled to know whether they have just put a
|
|
2147
|
+
* password on a screen. That the test runs where the *load* runs rather than
|
|
2148
|
+
* here, because a variable set in the console's pod and not in the worker's is
|
|
2149
|
+
* the way this goes wrong. And that the branch is decided once and recorded, so
|
|
2150
|
+
* a resumed run cannot change its mind — which is the sentence that makes the
|
|
2151
|
+
* run panel's "took the then branch" trustworthy.
|
|
2152
|
+
*/
|
|
2153
|
+
function IfInspector({ node, canEdit, onChange, }) {
|
|
2154
|
+
const setPredicate = (predicate) => onChange({ ...node, predicate });
|
|
2155
|
+
return (_jsxs("div", { className: "space-y-3", children: [_jsx(SelectField, { label: "Decide on", ariaLabel: "What this gate branches on", value: node.predicate.kind, onValueChange: (kind) => {
|
|
2156
|
+
// Narrowed rather than trusted, because `onValueChange` hands back a
|
|
2157
|
+
// string and the model wants one of two. An unrecognised one is
|
|
2158
|
+
// dropped: a gate is never left holding a test nothing can evaluate.
|
|
2159
|
+
if (!isWorkflowPredicateKind(kind))
|
|
2160
|
+
return;
|
|
2161
|
+
setPredicate(freshPredicate(kind));
|
|
2162
|
+
}, options: [
|
|
2163
|
+
{ value: 'env', label: 'An environment variable', hint: 'where the load runs' },
|
|
2164
|
+
{
|
|
2165
|
+
value: 'rowCount',
|
|
2166
|
+
label: 'How many rows reached it',
|
|
2167
|
+
hint: 'off the run’s own record',
|
|
2168
|
+
},
|
|
2169
|
+
], disabled: !canEdit, hint: "A variable tells one deployment apart from another. A row count tells a load that found data apart from one that found none \u2014 which is how a sink is kept from committing an empty snapshot over what is live." }), _jsx(PredicateFields, { predicate: node.predicate, canEdit: canEdit, onChange: setPredicate }), _jsxs("p", { className: cn('text-[11px] leading-relaxed', MUTED), children: ["The wires out of this node are labelled ", _jsx("strong", { children: "then" }), " and ", _jsx("strong", { children: "else" }), ", under \u201CFeeds\u201D below. To invert the test, swap which one is which \u2014 there is no \u201Cnot\u201D, because two ways to say one thing is two places to look when a load goes the way you did not expect."] }), _jsxs("p", { className: cn('text-[11px] leading-relaxed', MUTED), children: ["Everything reachable only through the branch that is not taken is ", _jsx("em", { children: "skipped" }), ", never failed. A sink on that side commits nothing, so whatever it publishes stays exactly as it was \u2014 that is the point, and the run panel says so rather than leaving a blank."] }), _jsx("p", { className: cn('text-[11px] leading-relaxed', MUTED), children: "The branch is decided once, at the moment this node runs, and recorded on the run. A load that is resumed after a crash reads the decision back instead of asking again, so it cannot take one branch on the way in and the other on the way back." })] }));
|
|
2170
|
+
}
|
|
2171
|
+
/**
|
|
2172
|
+
* The test a freshly picked kind starts as.
|
|
2173
|
+
*
|
|
2174
|
+
* An env test starts blank, so the graph refuses to publish until somebody names
|
|
2175
|
+
* a variable — there is nothing to guess. A row-count test starts at 1, which is
|
|
2176
|
+
* not a guess but the *only* threshold that means "did anything arrive at all",
|
|
2177
|
+
* which is the case the predicate was built for; a bigger number is a claim
|
|
2178
|
+
* about a particular pipeline and is typed.
|
|
2179
|
+
*/
|
|
2180
|
+
function freshPredicate(kind) {
|
|
2181
|
+
if (kind === 'env')
|
|
2182
|
+
return { kind: 'env', envVar: '' };
|
|
2183
|
+
if (kind === 'rowCount')
|
|
2184
|
+
return { kind: 'rowCount', atLeast: 1 };
|
|
2185
|
+
return unreachablePredicateKind(kind, 'freshPredicate');
|
|
2186
|
+
}
|
|
2187
|
+
/**
|
|
2188
|
+
* The fields one kind of test has, and none of the fields the other has.
|
|
2189
|
+
*
|
|
2190
|
+
* Split per kind and ending in a refusal, so a predicate kind added to the model
|
|
2191
|
+
* without a form here stops the build naming this file — the same rule
|
|
2192
|
+
* `KindInspector` follows for node kinds, and for the same reason: the failure
|
|
2193
|
+
* it prevents is a node somebody can select, that shows nothing to configure,
|
|
2194
|
+
* and that runs anyway.
|
|
2195
|
+
*/
|
|
2196
|
+
function PredicateFields({ predicate, canEdit, onChange, }) {
|
|
2197
|
+
if (predicate.kind === 'env') {
|
|
2198
|
+
return _jsx(EnvPredicateFields, { predicate: predicate, canEdit: canEdit, onChange: onChange });
|
|
2199
|
+
}
|
|
2200
|
+
if (predicate.kind === 'rowCount') {
|
|
2201
|
+
return _jsx(RowCountPredicateFields, { predicate: predicate, canEdit: canEdit, onChange: onChange });
|
|
2202
|
+
}
|
|
2203
|
+
return unreachablePredicateKind(predicate, 'PredicateFields');
|
|
2204
|
+
}
|
|
2205
|
+
function EnvPredicateFields({ predicate, canEdit, onChange, }) {
|
|
2206
|
+
// Whether to compare against a value at all is a *mode*, not an empty text
|
|
2207
|
+
// box: `equals: ''` is a real test ("set, but blank") and `equals: undefined`
|
|
2208
|
+
// is a different one ("set to anything"), and a single field could not express
|
|
2209
|
+
// both — clearing the box would silently switch which question is being asked.
|
|
2210
|
+
const comparing = predicate.equals !== undefined;
|
|
2211
|
+
return (_jsxs(_Fragment, { children: [_jsx(TextField, { label: "Environment variable", value: predicate.envVar, onChange: (envVar) => onChange({ ...predicate, envVar }), placeholder: "CLICKHOUSE_URL", disabled: !canEdit, hint: "The name of a variable on the machine that runs the load \u2014 not on this one. Only its name is stored, and only \u201Cset\u201D or \u201Cnot set\u201D is ever written to the run log, so naming one that holds a credential is safe." }), _jsx(SelectField, { label: "Test", ariaLabel: "What this gate tests the variable for", value: comparing ? 'equals' : 'set', onValueChange: (mode) => onChange(mode === 'equals' ? { ...predicate, equals: '' } : { ...predicate, equals: undefined }), options: [
|
|
2212
|
+
{ value: 'set', label: 'Is set to anything' },
|
|
2213
|
+
{ value: 'equals', label: 'Equals a particular value' },
|
|
2214
|
+
], disabled: !canEdit, hint: "\u201CIs set\u201D is the deployment test: a deployment that has a ClickHouse has its URL and one that does not has nothing. Compare against a value when the variable exists everywhere and only its contents differ." }), comparing && (_jsx(TextField, { label: "Equals", value: predicate.equals ?? '', onChange: (equals) => onChange({ ...predicate, equals }), placeholder: "local", disabled: !canEdit, hint: "Compared exactly, with no trimming. An empty value here means \u201Cset, but blank\u201D, which is a different test from \u201Cis set to anything\u201D." }))] }));
|
|
2215
|
+
}
|
|
2216
|
+
/**
|
|
2217
|
+
* One threshold, and the sentence that says what it is for.
|
|
2218
|
+
*
|
|
2219
|
+
* A text box with a numeric keypad rather than `type="number"`, which is the
|
|
2220
|
+
* rule `ObjectExplorer` already writes down: that control drops what it cannot
|
|
2221
|
+
* parse and answers a scroll wheel, so a number somebody typed can change while
|
|
2222
|
+
* they are reading the form. Non-digits are stripped here instead, and an empty
|
|
2223
|
+
* box is stored as 0 — which the validator refuses by name, so a half-filled
|
|
2224
|
+
* gate says so on the canvas rather than publishing a test that always passes.
|
|
2225
|
+
*/
|
|
2226
|
+
function RowCountPredicateFields({ predicate, canEdit, onChange, }) {
|
|
2227
|
+
const digits = Number.isInteger(predicate.atLeast) && predicate.atLeast > 0;
|
|
2228
|
+
return (_jsxs(_Fragment, { children: [_jsx(TextField, { label: "At least this many rows", value: digits ? String(predicate.atLeast) : '', onChange: (typed) => {
|
|
2229
|
+
const cleaned = typed.replace(/[^0-9]/g, '');
|
|
2230
|
+
onChange({
|
|
2231
|
+
...predicate,
|
|
2232
|
+
atLeast: cleaned.length === 0 ? 0 : Number.parseInt(cleaned, 10),
|
|
2233
|
+
});
|
|
2234
|
+
}, 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
|
+
}
|
|
2236
|
+
/**
|
|
2237
|
+
* The parameter box's two directions, kept together because they are inverses.
|
|
2238
|
+
*
|
|
2239
|
+
* An empty object shows as an empty box rather than as `{}`: the node starts
|
|
2240
|
+
* with no parameters, and opening a fresh call node onto punctuation somebody
|
|
2241
|
+
* has to delete is a worse start than a placeholder.
|
|
2242
|
+
*/
|
|
2243
|
+
function configText(config) {
|
|
2244
|
+
return Object.keys(config).length === 0 ? '' : JSON.stringify(config, null, 2);
|
|
2245
|
+
}
|
|
2246
|
+
/**
|
|
2247
|
+
* A JSON object, or `undefined` for anything else — including an array and
|
|
2248
|
+
* including `null`, both of which `JSON.parse` accepts and neither of which is
|
|
2249
|
+
* a parameter bag. Blank means no parameters, which is not an error.
|
|
2250
|
+
*/
|
|
2251
|
+
function parseConfigText(text) {
|
|
2252
|
+
if (text.trim().length === 0)
|
|
2253
|
+
return {};
|
|
2254
|
+
try {
|
|
2255
|
+
const parsed = JSON.parse(text);
|
|
2256
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed))
|
|
2257
|
+
return undefined;
|
|
2258
|
+
const config = {};
|
|
2259
|
+
for (const key of Object.keys(parsed))
|
|
2260
|
+
config[key] = Reflect.get(parsed, key);
|
|
2261
|
+
return config;
|
|
2262
|
+
}
|
|
2263
|
+
catch {
|
|
2264
|
+
return undefined;
|
|
2265
|
+
}
|
|
2266
|
+
}
|
|
2267
|
+
/**
|
|
2268
|
+
* The fields that belong to one kind of node and to no other.
|
|
2269
|
+
*
|
|
2270
|
+
* Split out of `NodeInspector` rather than written inline, because that
|
|
2271
|
+
* function is otherwise about the things every node has — its name, its wiring,
|
|
2272
|
+
* its problems, deleting it — and the per-kind chain is the one part of it that
|
|
2273
|
+
* grows every time the vocabulary does. Narrowing is what the union is for, so
|
|
2274
|
+
* a kind added without a branch here shows up as a node with a name and nothing
|
|
2275
|
+
* to configure, which is visible on the screen rather than silent.
|
|
2276
|
+
*/
|
|
2277
|
+
function KindInspector({ node, transforms, connections, typeOptions, canEdit, modelHref, discovery, discoverable, onDiscovered, onChange, onEditCode, onCreateTransform, creatingTransform, createTransformError, }) {
|
|
2278
|
+
if (node.kind === 'transform') {
|
|
2279
|
+
return (_jsx(TransformInspector, { node: node, transforms: transforms, canEdit: canEdit, creating: creatingTransform, createError: createTransformError, onChange: onChange, onEditCode: onEditCode, onCreate: onCreateTransform }));
|
|
2280
|
+
}
|
|
2281
|
+
if (node.kind === 'source') {
|
|
2282
|
+
return (_jsx(SourceInspector
|
|
2283
|
+
// Keyed so the text fields reset when a different source is opened.
|
|
2284
|
+
// Without it the draft state would survive the swap and one node's URL
|
|
2285
|
+
// would appear inside another.
|
|
2286
|
+
, { node: node, connections: connections, canEdit: canEdit, discovery: discovery, discoverable: discoverable, onDiscovered: onDiscovered, onChange: onChange }, node.id));
|
|
2287
|
+
}
|
|
2288
|
+
if (node.kind === 'call') {
|
|
2289
|
+
// Keyed for the same reason the source inspector is: the parameter box
|
|
2290
|
+
// holds text somebody is midway through typing, and it must not survive
|
|
2291
|
+
// being pointed at a different node.
|
|
2292
|
+
return _jsx(CallInspector, { node: node, canEdit: canEdit, onChange: onChange }, node.id);
|
|
2293
|
+
}
|
|
2294
|
+
if (node.kind === 'if') {
|
|
2295
|
+
return _jsx(IfInspector, { node: node, canEdit: canEdit, onChange: onChange }, node.id);
|
|
2296
|
+
}
|
|
2297
|
+
if (node.kind === 'sink') {
|
|
2298
|
+
return (_jsx(SinkInspector, { node: node, typeOptions: typeOptions, canEdit: canEdit, modelHref: modelHref, onChange: onChange }));
|
|
2299
|
+
}
|
|
2300
|
+
// The chain ends in a refusal rather than a fallthrough, so a kind added to
|
|
2301
|
+
// core without a form here is a type error naming this file — which is the
|
|
2302
|
+
// whole reason the docblock above says a missing branch shows up as "a node
|
|
2303
|
+
// with a name and nothing to configure". It no longer can.
|
|
2304
|
+
return unreachableNodeKind(node, 'KindInspector');
|
|
2305
|
+
}
|
|
2306
|
+
function NodeInspector({ node, draft, transforms, connections, typeOptions, canEdit, modelHref, problems, pending, discovery, discoverable, onDiscovered, onClose, onChange, onConnect, onConnectToNew, onDisconnect, onBranch, onDelete, onEditCode, onCreateTransform, creatingTransform, createTransformError, }) {
|
|
1307
2307
|
const [pendingTarget, setPendingTarget] = useState('');
|
|
1308
2308
|
const label = (id) => {
|
|
1309
2309
|
const found = draft.nodes.find((n) => n.id === id);
|
|
@@ -1344,11 +2344,11 @@ function NodeInspector({ node, draft, transforms, connections, typeOptions, canE
|
|
|
1344
2344
|
return (_jsx(Sheet, { open: node !== null, onOpenChange: (open) => {
|
|
1345
2345
|
if (!open)
|
|
1346
2346
|
onClose();
|
|
1347
|
-
}, 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." }),
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
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,
|
|
2348
|
+
// Only a gate's wires have a side to be on. `validateWorkflow`
|
|
2349
|
+
// refuses a label on any other wire, so offering the control there
|
|
2350
|
+
// would be offering a change the server will not take.
|
|
2351
|
+
onBranch: node.kind === 'if' ? onBranch : undefined, children: [canEdit && (_jsxs("div", { className: "mt-2 flex items-end gap-2", children: [_jsx("div", { className: "min-w-0 flex-1", children: _jsx(Select, { ariaLabel: "Send this node's output to", value: pendingTarget, onValueChange: setPendingTarget, options: eligible, placeholder: eligible.length === 0
|
|
1352
2352
|
? 'Nothing can be wired from here'
|
|
1353
2353
|
: 'Send its output to…', disabled: eligible.length === 0 }) }), _jsx("button", { type: "button", onClick: () => {
|
|
1354
2354
|
if (!pendingTarget)
|
|
@@ -1375,10 +2375,10 @@ function NodeInspector({ node, draft, transforms, connections, typeOptions, canE
|
|
|
1375
2375
|
* rather than read back out of the node. Re-deriving them from the stored config
|
|
1376
2376
|
* would make a half-typed number disappear the moment it stopped parsing.
|
|
1377
2377
|
*/
|
|
1378
|
-
function SourceInspector({ node, connections, canEdit, onChange, }) {
|
|
2378
|
+
function SourceInspector({ node, connections, canEdit, discovery, discoverable, onDiscovered, onChange, }) {
|
|
1379
2379
|
const [source, setSource] = useState(() => sourceDraftFrom(node.config));
|
|
1380
2380
|
const kind = toConnectorKind(node.sourceKind ?? 'http');
|
|
1381
|
-
const options =
|
|
2381
|
+
const options = connectionOptionsFor(kind, connections);
|
|
1382
2382
|
// A connection chosen for one kind is meaningless for another, so switching
|
|
1383
2383
|
// the kind drops it rather than keeping an id the server would reject.
|
|
1384
2384
|
const chosen = options.some((option) => option.value === node.connectionId)
|
|
@@ -1409,21 +2409,21 @@ function SourceInspector({ node, connections, canEdit, onChange, }) {
|
|
|
1409
2409
|
// The connection goes with the kind it belonged to. Keeping it would
|
|
1410
2410
|
// point an S3 source at a SQL address.
|
|
1411
2411
|
push(source, { sourceKind, connectionId: undefined });
|
|
1412
|
-
}, options: KIND_OPTIONS, disabled: !canEdit }), usesConnection(kind) && (_jsx(SelectField, { label: "Read through", ariaLabel: "Connection", value: chosen, onValueChange: (value) => push(source, {
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
2412
|
+
}, options: KIND_OPTIONS, disabled: !canEdit }), usesConnection(kind) && (_jsxs(_Fragment, { children: [_jsx(SelectField, { label: "Read through", ariaLabel: "Connection", value: chosen, onValueChange: (value) => push(source, {
|
|
2413
|
+
// Omitted, never sent empty: an empty string is a connection id
|
|
2414
|
+
// the server would look up and fail to find, where absent means
|
|
2415
|
+
// "this source carries its own address".
|
|
2416
|
+
connectionId: value === INLINE_CONNECTION ? undefined : value,
|
|
2417
|
+
}), options: [
|
|
2418
|
+
{
|
|
2419
|
+
value: INLINE_CONNECTION,
|
|
2420
|
+
label: 'Configure the address here',
|
|
2421
|
+
hint: 'This source alone',
|
|
2422
|
+
},
|
|
2423
|
+
...options,
|
|
2424
|
+
], disabled: !canEdit, hint: options.length === 0
|
|
2425
|
+
? 'No connections of this kind yet. One is worth making when a second source needs the same address.'
|
|
2426
|
+
: viaConnection
|
|
2427
|
+
? 'The connection supplies the address and the credential. What stays below is only what is specific to this load.'
|
|
2428
|
+
: undefined }), _jsx(SourceConnectionCreator, { kind: kind, canEdit: canEdit, hasOptions: options.length > 0, onCreated: (connection) => push(source, { connectionId: connection.id }) })] })), _jsx(SourceFields, { kind: kind, draft: source, onChange: update, viaConnection: viaConnection, disabled: !canEdit }), _jsx(ReadModeFields, { kind: kind, mode: mode, onModeChange: (next) => push(source, { mode: next }), draft: source, onChange: update, disabled: !canEdit }), incremental && (_jsx("p", { className: cn('text-[11px] leading-relaxed', MUTED), children: "A watermark is kept per node, so two sources in the same graph reading incrementally do not overwrite each other's position." })), _jsx(SchemaDiscoveryPanel, { workflowId: discoverable.workflowId ?? '', nodeId: node.id, bridge: discovery, onDiscovered: onDiscovered, onSave: discoverable.onSave, saving: discoverable.saving, ...(discoverable.workflowId === undefined ? { disabledReason: discoverable.because } : {}) })] }));
|
|
1429
2429
|
}
|