@dudousxd/nestjs-catalog-react 0.19.0-preview.0 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,343 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ /**
3
+ * Taking an edit back, throwing the whole draft away, and not losing it by
4
+ * accident.
5
+ *
6
+ * WHY THIS IS ITS OWN FILE
7
+ * ------------------------
8
+ * Everything here is about the same one thing — the gap between what is on the
9
+ * canvas and what the server has — and none of it is about drawing a graph.
10
+ * `WorkflowCanvas.tsx` is already six thousand lines and is the file every
11
+ * feature wants to grow, so the rule that keeps it readable is that a concern
12
+ * with its own vocabulary gets its own module. This one has four words in it:
13
+ * an ACTION (the unit undo steps over), the PAST (the actions still takeable
14
+ * back), the BASELINE (the graph as the server last described it) and DIRTY
15
+ * (whether those two differ).
16
+ *
17
+ * WHAT THIS DOES NOT COVER, AND SAYS SO ON SCREEN
18
+ * ----------------------------------------------
19
+ * Undo is about the DRAFT and nothing else. Saving, publishing, running and
20
+ * deleting the workflow are requests the server has already answered; a control
21
+ * that appeared to unmake one of them would be promising something no client
22
+ * can deliver. The boundary is stated in {@link UNDO_SCOPE}, which is rendered —
23
+ * as a tooltip for a pointer and as text for a screen reader — rather than left
24
+ * in this comment, because a boundary somebody has to read the source to learn
25
+ * is not a boundary they will learn.
26
+ *
27
+ * WHY SNAPSHOTS RATHER THAN INVERSE COMMANDS
28
+ * ------------------------------------------
29
+ * The alternative is an undo stack of operations that know how to reverse
30
+ * themselves. That is smaller in memory and considerably more code, and every
31
+ * new gesture on the canvas is a new inverse that can be written wrongly — a
32
+ * wrong inverse is silent, and lands in a SAVED graph. A snapshot cannot be
33
+ * wrong about what the graph was. The cost is bounded by {@link UNDO_DEPTH} and
34
+ * by the fact that a snapshot holds the same node and edge ARRAYS the draft
35
+ * already held: this canvas replaces arrays rather than mutating them (see the
36
+ * copy note in `draftFrom`), so an entry costs four references, not a graph.
37
+ */
38
+ import { RotateCcw, Undo2 } from 'lucide-react';
39
+ import { useEffect } from 'react';
40
+ import { cn } from '../cn';
41
+ import { Button } from '../ui/button';
42
+ import { ConfirmDialog } from '../ui/dialog';
43
+ import { Tooltip } from '../ui/tooltip';
44
+ import { nodeName } from './model';
45
+ import { WORKFLOW_NAME } from './name';
46
+ /**
47
+ * How many actions can be taken back.
48
+ *
49
+ * A cap rather than an unbounded stack, and 50 rather than 500, because the
50
+ * promise a history makes should be one it can keep at any graph size. Fifty
51
+ * snapshots of a hundred-node graph is fifty times four references — nothing —
52
+ * but the honesty matters more than the arithmetic: an unbounded stack grows
53
+ * with how long somebody has had the tab open, which is exactly the session
54
+ * where they can least afford the tab to get slow.
55
+ *
56
+ * At the limit the OLDEST entry is dropped, so undo always steps back from
57
+ * where the person is rather than refusing. What is lost is the ability to walk
58
+ * all the way to the beginning — and that is what Reset is for, which is why the
59
+ * two controls sit beside each other and why {@link resetDescription} says how
60
+ * many actions are about to go.
61
+ */
62
+ export const UNDO_DEPTH = 50;
63
+ /**
64
+ * How long a run of edits stays open, when nothing else closes it.
65
+ *
66
+ * The fallback half of the granularity rule. A gesture with a real end — a drag
67
+ * — says so through `continuing` and ignores this entirely; a gesture without
68
+ * one — typing into a field, holding an arrow key — has only elapsed time to go
69
+ * on. 700ms is longer than a fast typist's inter-key gap and shorter than the
70
+ * pause somebody makes when they stop to think, which is the boundary between
71
+ * "still writing the name" and "wrote the name, then did something else".
72
+ */
73
+ export const RUN_WINDOW_MS = 700;
74
+ /** What undo can and cannot reach, in the words the controls use. */
75
+ export const UNDO_SCOPE = `Undo steps back through your edits to this drawing, one action at a time — up to the last ${UNDO_DEPTH}. It does not touch anything the server has already done: saving, publishing, running and deleting the ${WORKFLOW_NAME.singular} are not undone here.`;
76
+ /** Said once, when somebody reaches for a redo that deliberately does not exist. */
77
+ export const NO_REDO = 'There is no redo on this canvas. Undo only steps backwards; Reset returns the whole drawing to the last saved version.';
78
+ export function snapshotOf(draft) {
79
+ return {
80
+ name: draft.name,
81
+ description: draft.description,
82
+ nodes: draft.nodes,
83
+ edges: draft.edges,
84
+ };
85
+ }
86
+ /**
87
+ * Whether two snapshots are the same graph.
88
+ *
89
+ * Reference identity on the arrays, and that is the point rather than a
90
+ * shortcut. Nothing on this canvas mutates a node or an edge array in place —
91
+ * every path replaces — so two identical references ARE the same graph, and the
92
+ * comparison cannot report "unchanged" for a graph that has changed. It can
93
+ * report "changed" for a graph that has been edited back to where it started
94
+ * through two different arrays, and that asymmetry is the safe one: the only
95
+ * consequence is a save button that stays live and a leave-warning that still
96
+ * fires, which is a nuisance. The opposite error loses work.
97
+ *
98
+ * Undo restores the very arrays it recorded, so walking all the way back to the
99
+ * baseline compares equal and the draft goes genuinely clean — which is what
100
+ * makes the beforeunload guard below trustworthy enough to be worth having.
101
+ */
102
+ export function sameSnapshot(a, b) {
103
+ return (a.name === b.name &&
104
+ a.description === b.description &&
105
+ a.nodes === b.nodes &&
106
+ a.edges === b.edges);
107
+ }
108
+ /**
109
+ * An edit, recorded.
110
+ *
111
+ * Pure, and it has to be: this runs inside a `setState` updater, which React is
112
+ * free to call twice for the same input. Nothing here reads or writes anything
113
+ * outside its arguments except the clock, and the clock only moves a timestamp
114
+ * that two calls a microsecond apart agree about anyway.
115
+ */
116
+ export function withEdit(before, after, action) {
117
+ return { ...after, dirty: true, past: pushed(before, action) };
118
+ }
119
+ function pushed(before, action) {
120
+ const past = before.past;
121
+ const top = past.at(-1);
122
+ const now = Date.now();
123
+ if (top && action.run !== undefined && top.run === action.run) {
124
+ const open = action.continuing === true || now - top.at <= RUN_WINDOW_MS;
125
+ // The entry already holds the state from before the gesture began, so
126
+ // folding into it is simply not pushing. Its clock moves so the run stays
127
+ // open for as long as the gesture keeps producing frames.
128
+ if (open)
129
+ return [...past.slice(0, -1), { ...top, at: now }];
130
+ }
131
+ const next = [
132
+ ...past,
133
+ { before: snapshotOf(before), label: action.label, run: action.run, at: now },
134
+ ];
135
+ // Drop from the front, never refuse at the back: a person who has made
136
+ // fifty-one edits wants the fifty-first taken back, not a message about a
137
+ // limit.
138
+ return next.length > UNDO_DEPTH ? next.slice(next.length - UNDO_DEPTH) : next;
139
+ }
140
+ /** The next thing undo would take back, for a control that has to name it. */
141
+ export function nextUndo(draft) {
142
+ return draft.past.at(-1);
143
+ }
144
+ /**
145
+ * One action back.
146
+ *
147
+ * Returns the label as well as the draft because the announcement is half the
148
+ * feature: undo can revert something that is scrolled off the canvas, and a
149
+ * silent revert of an invisible thing is indistinguishable from nothing
150
+ * happening.
151
+ */
152
+ export function undone(draft) {
153
+ const top = nextUndo(draft);
154
+ if (!top)
155
+ return null;
156
+ const past = draft.past.slice(0, -1);
157
+ const restored = { ...draft, ...top.before, past };
158
+ return {
159
+ draft: { ...restored, dirty: !sameSnapshot(top.before, draft.baseline) },
160
+ label: top.label,
161
+ };
162
+ }
163
+ /**
164
+ * All the way back to the last saved version.
165
+ *
166
+ * The history goes with it. Keeping it would offer to undo the reset, which is
167
+ * a redo of everything by another name — and this module does not have one.
168
+ */
169
+ export function reverted(draft) {
170
+ return { ...draft, ...draft.baseline, past: [], dirty: false };
171
+ }
172
+ /** The ids still in the graph, for the per-node bookkeeping the canvas keeps. */
173
+ export function keepKnown(ids, nodes) {
174
+ const alive = new Set(nodes.map((node) => node.id));
175
+ const kept = [...ids].filter((id) => alive.has(id));
176
+ return kept.length === ids.size ? ids : new Set(kept);
177
+ }
178
+ /** How many nodes, named where naming them is short enough to be useful. */
179
+ export function namesOf(nodes, ids) {
180
+ const found = [...ids].map((id) => {
181
+ const node = nodes.find((candidate) => candidate.id === id);
182
+ return node ? `"${nodeName(node)}"` : id;
183
+ });
184
+ if (found.length === 0)
185
+ return 'nothing';
186
+ if (found.length === 1)
187
+ return found[0];
188
+ if (found.length === 2)
189
+ return `${found[0]} and ${found[1]}`;
190
+ return `${found.length} nodes`;
191
+ }
192
+ /**
193
+ * One edit to a node, described by which of its fields moved.
194
+ *
195
+ * The run key carries the CHANGED FIELDS, not just the node, and that is the
196
+ * difference between a useful granularity and an irritating one: typing into a
197
+ * name box folds into one action, but typing a name and then flipping a switch
198
+ * on the same node a moment later stays two — because the second edit touches a
199
+ * different field and so opens a new run. Without the field in the key those two
200
+ * would merge, and undoing the switch would silently retype the name.
201
+ *
202
+ * The fields are read through `Object.entries` rather than by name: a node is a
203
+ * union of six shapes with different fields each, and a hand-written list here
204
+ * would go quietly out of date the next time a node kind gains one — which
205
+ * shows up as an edit that mysteriously will not undo on its own.
206
+ */
207
+ export function nodeEditAction(before, after) {
208
+ const label = `editing "${nodeName(before ?? after)}"`;
209
+ if (!before)
210
+ return { label };
211
+ const was = new Map(Object.entries(before));
212
+ const now = new Map(Object.entries(after));
213
+ const fields = [...new Set([...was.keys(), ...now.keys()])]
214
+ .filter((field) => !Object.is(was.get(field), now.get(field)))
215
+ .sort();
216
+ return { label, run: `node:${after.id}:${fields.join(',')}` };
217
+ }
218
+ /** What Reset is about to do, in the numbers the person can check it against. */
219
+ export function resetDescription(draft) {
220
+ const count = draft.past.length;
221
+ const actions = count === 0
222
+ ? 'Everything unsaved'
223
+ : count >= UNDO_DEPTH
224
+ ? `At least ${count} actions`
225
+ : `${count} ${count === 1 ? 'action' : 'actions'}`;
226
+ return `${actions} will be thrown away and the drawing goes back to the version the server last stored. This cannot be undone — Undo only steps back through edits, and Reset clears them. Nothing the server holds is touched: no run is stopped, nothing is unpublished, and the stored ${WORKFLOW_NAME.singular} stays exactly as it is.`;
227
+ }
228
+ /**
229
+ * A tab that will not close on unsaved work without asking.
230
+ *
231
+ * Registered only while there IS unsaved work, which is the whole design
232
+ * constraint: a page that always warns teaches people to dismiss the dialog
233
+ * without reading it, and then it is not a guard, it is a habit. Cleaning up on
234
+ * `dirty` going false is what makes a save silence it immediately.
235
+ *
236
+ * The wording belongs to the browser — every engine ignores whatever string a
237
+ * page supplies here, and has for a decade — so this asks for the dialog and
238
+ * says nothing. `returnValue` is set as well as `preventDefault` because Chrome
239
+ * and Safari have historically disagreed about which one arms it.
240
+ *
241
+ * Nothing happens on a server: `useEffect` does not run there, so a host
242
+ * rendering this canvas into HTML sees no `window`.
243
+ */
244
+ export function useUnsavedGuard(dirty) {
245
+ useEffect(() => {
246
+ if (!dirty)
247
+ return;
248
+ const warn = (event) => {
249
+ event.preventDefault();
250
+ event.returnValue = '';
251
+ };
252
+ window.addEventListener('beforeunload', warn);
253
+ return () => window.removeEventListener('beforeunload', warn);
254
+ }, [dirty]);
255
+ }
256
+ /**
257
+ * Whether a key press belongs to something being typed into.
258
+ *
259
+ * The reason Cmd/Ctrl+Z can be bound at all. This canvas contains a name field,
260
+ * a description box, several config fields and a real code editor, and in every
261
+ * one of them Cmd+Z means "undo my typing" — a canvas-level binding that fired
262
+ * there would silently discard a graph edit instead, which is the worst possible
263
+ * outcome for a control whose entire job is not losing work.
264
+ *
265
+ * `closest` rather than the target itself: a contenteditable code surface puts
266
+ * the caret on a descendant span, so the event target is not the editable host.
267
+ * The dialog and sheet cases are the same argument one level up — a modal over
268
+ * the canvas is a different document with its own undo, and the canvas has no
269
+ * business acting on keys pressed inside it.
270
+ *
271
+ * Narrowed with `instanceof` rather than asserted: `event.target` is typed
272
+ * `EventTarget | null` and genuinely can be a `Window` or a text node.
273
+ */
274
+ export function isTypingTarget(target) {
275
+ if (!(target instanceof Element))
276
+ return false;
277
+ return (target.closest('input, textarea, select, [contenteditable="true"], [contenteditable=""], [role="textbox"]') !== null || target.closest('[role="dialog"], [role="alertdialog"], [role="menu"]') !== null);
278
+ }
279
+ /**
280
+ * Cmd/Ctrl+Z, on the canvas and nowhere else.
281
+ *
282
+ * Shift+Cmd/Ctrl+Z is caught deliberately rather than left to the browser: the
283
+ * hands that reach for it are expecting a redo, and silence would read as a
284
+ * broken shortcut. It says there is none, once, in the same live region
285
+ * everything else on this canvas speaks through.
286
+ *
287
+ * On `window` rather than on the canvas element because the canvas is not
288
+ * reliably focused — somebody who has just clicked a toolbar button, or closed
289
+ * the inspector, has focus on chrome — and a shortcut that only works when the
290
+ * right thing happens to be focused is a shortcut people stop trusting.
291
+ */
292
+ export function useUndoShortcut({ enabled, onUndo, onSay, }) {
293
+ useEffect(() => {
294
+ if (!enabled)
295
+ return;
296
+ const onKeyDown = (event) => {
297
+ if (!(event.metaKey || event.ctrlKey) || event.altKey)
298
+ return;
299
+ if (event.key.toLowerCase() !== 'z')
300
+ return;
301
+ if (isTypingTarget(event.target))
302
+ return;
303
+ // Only once the press is definitely ours: preventing the default before
304
+ // the typing check would swallow the browser's own undo in a field.
305
+ event.preventDefault();
306
+ if (event.shiftKey) {
307
+ onSay(NO_REDO);
308
+ return;
309
+ }
310
+ onUndo();
311
+ };
312
+ window.addEventListener('keydown', onKeyDown);
313
+ return () => window.removeEventListener('keydown', onKeyDown);
314
+ }, [enabled, onUndo, onSay]);
315
+ }
316
+ /**
317
+ * Undo, Reset, and the fact that there is unsaved work — as one cluster.
318
+ *
319
+ * Together because they are one subject and answer each other: the chip says
320
+ * something is at risk, Undo takes back the last thing, Reset gives up on all of
321
+ * it. Split across the screen they would be three unrelated controls, and the
322
+ * chip in particular means nothing without something to do about it.
323
+ *
324
+ * The unsaved chip is `role="status"`, so it is announced when it appears rather
325
+ * than only when somebody goes looking. It appears once per clean→dirty
326
+ * transition, because its text does not change while dirty — a status that
327
+ * re-announced on every keystroke would be unusable.
328
+ */
329
+ export function HistoryControls({ draft, canEdit, reducedMotion, resetting, onResettingChange, onUndo, onReset, }) {
330
+ const top = nextUndo(draft);
331
+ const depth = draft.past.length;
332
+ return (_jsxs(_Fragment, { children: [_jsx(Tooltip, { content: top
333
+ ? `Take back: ${top.label}. ${UNDO_SCOPE} ${depth === 1 ? 'This is the last one.' : `${depth} to go.`} Keyboard: Ctrl+Z, or ⌘Z.`
334
+ : `Nothing to take back yet. ${UNDO_SCOPE}`, children: _jsxs(Button, { variant: "ghost", size: "sm", onClick: onUndo, disabled: !canEdit || !top, "aria-label": top ? `Undo: ${top.label}` : 'Undo — nothing to take back yet', children: [_jsx(Undo2, { size: 12 }), _jsx("span", { className: "hidden md:inline", children: "Undo" })] }) }), _jsx(Tooltip, { content: "Throw away every unsaved edit and go back to the version the server last stored. Not the same as undoing repeatedly: if you saved partway through, this returns to THAT save, not to where you started.", children: _jsxs(Button, { variant: "ghost", size: "sm", onClick: () => onResettingChange(true), disabled: !canEdit || !draft.dirty, "aria-label": "Reset to the last saved version, discarding every unsaved edit",
335
+ // Coloured like the delete control beside it, and for the same reason:
336
+ // this destroys work, and a control that destroys work should look
337
+ // like one before it is pressed rather than after.
338
+ className: "text-zinc-400 hover:text-red-600", children: [_jsx(RotateCcw, { size: 12 }), _jsx("span", { className: "hidden md:inline", children: "Reset" })] }) }), draft.dirty && (_jsxs("output", { className: "flex shrink-0 items-center gap-1.5 rounded px-1.5 py-0.5 font-mono text-[10px] text-amber-700 dark:text-amber-300", children: [_jsx("span", { "aria-hidden": true, className: cn('h-1.5 w-1.5 shrink-0 rounded-full bg-amber-500',
339
+ // A quiet pulse, because the whole job of this dot is to be
340
+ // noticed in peripheral vision — and nothing at all for somebody
341
+ // who has asked their machine to stop moving things.
342
+ !reducedMotion && 'animate-pulse') }), "Unsaved"] })), _jsx("p", { className: "sr-only", children: UNDO_SCOPE }), _jsx(ConfirmDialog, { open: resetting, onOpenChange: onResettingChange, title: "Discard every unsaved edit?", description: resetDescription(draft), confirmLabel: "Discard and reset", onConfirm: onReset })] }));
343
+ }
@@ -18,8 +18,8 @@
18
18
  * executes it, it belongs to core; if only this screen has an opinion about it,
19
19
  * it belongs here.
20
20
  */
21
- export type { CallableWorkflowBlock, CallableWorkflowDisagreement, CallableWorkflowRef, CatalogWorkflow, WorkflowBranchLabel, WorkflowEdge, WorkflowCallNode, WorkflowEnvPredicate, WorkflowGraph, WorkflowIfNode, WorkflowIfPredicate, WorkflowNode, WorkflowNodeKind, WorkflowPredicateKind, WorkflowRowCountPredicate, WorkflowSinkNode, WorkflowSkipReason, WorkflowSourceNode, WorkflowTransformNode, } from '@dudousxd/nestjs-catalog/client';
22
- export { callableWorkflowBlock, isWorkflowBranchLabel, isWorkflowNodeKind, isWorkflowPredicateKind, unreachableNodeKind, unreachablePredicateKind, WORKFLOW_BRANCH_LABELS, WORKFLOW_PREDICATE_KINDS, WORKFLOW_NODE_ID_PATTERN, WORKFLOW_NODE_KINDS, } from '@dudousxd/nestjs-catalog/client';
21
+ export type { CallableWorkflowBlock, CallableWorkflowDisagreement, CallableWorkflowRef, CatalogWorkflow, WorkflowBranchLabel, WorkflowEdge, WorkflowCallNode, WorkflowEnvPredicate, WorkflowFilterAll, WorkflowFilterAny, WorkflowFilterComparison, WorkflowFilterGroup, WorkflowFilterNode, WorkflowFilterOneOf, WorkflowFilterOperator, WorkflowFilterPredicate, WorkflowFilterPredicateKind, WorkflowFilterPresence, WorkflowFilterValue, WorkflowGraph, WorkflowIfNode, WorkflowIfPredicate, WorkflowNode, WorkflowNodeKind, WorkflowPredicateKind, WorkflowRowCountPredicate, WorkflowSinkNode, WorkflowSkipReason, WorkflowSourceNode, WorkflowTransformNode, } from '@dudousxd/nestjs-catalog/client';
22
+ export { callableWorkflowBlock, isWorkflowBranchLabel, isWorkflowFilterOperator, isWorkflowFilterPredicate, isWorkflowFilterPredicateKind, isWorkflowFilterValue, isWorkflowNodeKind, isWorkflowPredicateKind, unreachableFilterOperator, unreachableFilterPredicateKind, unreachableNodeKind, unreachablePredicateKind, workflowNarrowedTypes, WORKFLOW_BRANCH_LABELS, WORKFLOW_FILTER_COLUMN_PATTERN, WORKFLOW_FILTER_MAX_DEPTH, WORKFLOW_FILTER_MAX_VALUES, WORKFLOW_FILTER_OPERATORS, WORKFLOW_FILTER_PREDICATE_KINDS, WORKFLOW_PREDICATE_KINDS, WORKFLOW_NODE_ID_PATTERN, WORKFLOW_NODE_KINDS, } from '@dudousxd/nestjs-catalog/client';
23
23
  import { type WorkflowBranchLabel, type WorkflowNode, type WorkflowSkipReason } from '@dudousxd/nestjs-catalog/client';
24
24
  /**
25
25
  * What a caller may set.
@@ -132,6 +132,17 @@ export interface WorkflowRunNode {
132
132
  */
133
133
  skippedBecause?: WorkflowSkipReason;
134
134
  rows?: number;
135
+ /**
136
+ * What a filter node was handed, where {@link rows} is what it passed on.
137
+ *
138
+ * The pair is the whole reporting contract of a filter, and both halves have
139
+ * to reach the screen or the node's effect is invisible — which is how rows go
140
+ * missing quietly. Absent on every other kind, and absent on filters that ran
141
+ * before the server recorded it; a panel must therefore check for its presence
142
+ * rather than subtract from a defaulted zero, or every historical node would
143
+ * claim to have dropped everything it produced.
144
+ */
145
+ rowsIn?: number;
135
146
  error?: string;
136
147
  startedAt?: string;
137
148
  finishedAt?: string;
@@ -23,7 +23,12 @@ export {
23
23
  // not a copy: the picker greys an entry out and the server reasons about the
24
24
  // same list, and two copies of that rule is a picker that eventually offers
25
25
  // something the rest of the system will not accept.
26
- callableWorkflowBlock, isWorkflowBranchLabel, isWorkflowNodeKind, isWorkflowPredicateKind, unreachableNodeKind, unreachablePredicateKind, WORKFLOW_BRANCH_LABELS, WORKFLOW_PREDICATE_KINDS, WORKFLOW_NODE_ID_PATTERN, WORKFLOW_NODE_KINDS, } from '@dudousxd/nestjs-catalog/client';
26
+ callableWorkflowBlock, isWorkflowBranchLabel, isWorkflowFilterOperator, isWorkflowFilterPredicate, isWorkflowFilterPredicateKind, isWorkflowFilterValue, isWorkflowNodeKind, isWorkflowPredicateKind, unreachableFilterOperator, unreachableFilterPredicateKind, unreachableNodeKind, unreachablePredicateKind,
27
+ // Core's, not a copy, for the reason every other rule here is core's: the
28
+ // inspector has to offer exactly the acknowledgements `validateWorkflow`
29
+ // requires, and a screen that worked out its own list would offer a set the
30
+ // server then refuses — with the person having ticked a box to be told no.
31
+ workflowNarrowedTypes, WORKFLOW_BRANCH_LABELS, WORKFLOW_FILTER_COLUMN_PATTERN, WORKFLOW_FILTER_MAX_DEPTH, WORKFLOW_FILTER_MAX_VALUES, WORKFLOW_FILTER_OPERATORS, WORKFLOW_FILTER_PREDICATE_KINDS, WORKFLOW_PREDICATE_KINDS, WORKFLOW_NODE_ID_PATTERN, WORKFLOW_NODE_KINDS, } from '@dudousxd/nestjs-catalog/client';
27
32
  import { WORKFLOW_NODE_ID_PATTERN, } from '@dudousxd/nestjs-catalog/client';
28
33
  export function describeDurability(durability) {
29
34
  if (!durability) {
@@ -1,11 +1,11 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Handle, Position } from '@xyflow/react';
3
- import { CircleAlert, CircleCheck, CircleSlash, Code2, Database, ExternalLink, GitBranch, Loader2, Plug, Repeat, TriangleAlert, } from 'lucide-react';
3
+ import { CircleAlert, CircleCheck, CircleSlash, Code2, Database, ExternalLink, Filter, GitBranch, Loader2, Plug, Repeat, TriangleAlert, } from 'lucide-react';
4
4
  import { motion, useReducedMotion } from 'motion/react';
5
5
  import { createContext, useContext, } from 'react';
6
6
  import { cn } from '../cn';
7
7
  import { Tooltip } from '../ui/tooltip';
8
- import { NODE_WIDTH } from './graph';
8
+ import { NODE_WIDTH, describeDrop } from './graph';
9
9
  const RULE = 'border-zinc-200 dark:border-zinc-800';
10
10
  const PANEL = 'bg-white dark:bg-zinc-900';
11
11
  const MUTED = 'text-zinc-400 dark:text-zinc-500';
@@ -83,6 +83,20 @@ const KIND_STYLE = {
83
83
  icon: GitBranch,
84
84
  noun: 'if',
85
85
  },
86
+ // Rose and a funnel. It is the only kind whose effect is *subtraction* — every
87
+ // other node either produces rows, reshapes them or decides which boxes run —
88
+ // and the whole reason it is a node rather than a transform returning a subset
89
+ // is that "rows are being dropped here" should be visible without opening
90
+ // anything. Deliberately not the fuchsia an `if` wears: both of them make a
91
+ // load smaller and they do it in completely different ways, so they are the
92
+ // two that must never be confused at a glance.
93
+ filter: {
94
+ accent: 'bg-gradient-to-b from-rose-400 to-rose-600',
95
+ chip: 'text-rose-700 dark:text-rose-300',
96
+ wash: 'bg-rose-50/70 dark:bg-rose-950/30',
97
+ icon: Filter,
98
+ noun: 'filter',
99
+ },
86
100
  };
87
101
  /**
88
102
  * Handles are styled larger than React Flow's default 6px dot.
@@ -174,7 +188,14 @@ function RunBadge({ run }) {
174
188
  ? // The single most useful fact on a resumed run, and there is
175
189
  // nowhere else on the screen to read it from.
176
190
  'Replayed from a checkpoint — this step did not run again.'
177
- : `${describeBranchTaken(run) ?? 'Ran'}${typeof run.rows === 'number' ? `, ${run.rows} rows` : ''}.`, children: _jsx("span", { className: "flex items-center", children: _jsx(CircleCheck, { size: 11, className: run.replayed ? 'text-zinc-400' : 'text-emerald-500' }) }) }));
191
+ : // A filter reports the pair rather than the total, and it is the
192
+ // one kind for which "42 rows" would be an actively misleading
193
+ // badge: the number that matters is what it *removed*, and a node
194
+ // that showed only its output would make a filter that dropped
195
+ // nine tenths of a load look identical to a source that read a
196
+ // tenth as much. `describeDrop` answers for filters and stays
197
+ // silent for everything else, so this stays one expression.
198
+ `${describeBranchTaken(run) ?? 'Ran'}${describeRunSize(run)}.`, children: _jsx("span", { className: "flex items-center", children: _jsx(CircleCheck, { size: 11, className: run.replayed ? 'text-zinc-400' : 'text-emerald-500' }) }) }));
178
199
  }
179
200
  // Drawn rather than left blank, which is what this was.
180
201
  //
@@ -202,6 +223,21 @@ function RunBadge({ run }) {
202
223
  * for whether skipping an animation costs anybody information.
203
224
  */
204
225
  const ARRIVE = { type: 'spring', stiffness: 420, damping: 34, mass: 0.7 };
226
+ /**
227
+ * How much data went through a node, in the terms that node is measured in.
228
+ *
229
+ * A filter reports the pair — in, out, and what that means as a share — because
230
+ * for a filter the number that matters is what it *removed*, and a badge showing
231
+ * only its output would make one that dropped nine tenths of a load look exactly
232
+ * like a source that read a tenth as much. Everything else reports what it
233
+ * produced, which is what "rows" has always meant on this badge.
234
+ */
235
+ function describeRunSize(run) {
236
+ const dropped = describeDrop(run);
237
+ if (dropped)
238
+ return `: ${dropped}`;
239
+ return typeof run.rows === 'number' ? `, ${run.rows} rows` : '';
240
+ }
205
241
  /** What an `if` node's badge says it decided. Absent on every other kind. */
206
242
  function describeBranchTaken(run) {
207
243
  if (!run?.branch)
@@ -66,6 +66,17 @@ const NODE_FACTORIES = {
66
66
  // wrong is a half of the graph that silently does not run, which is the one
67
67
  // failure this node had to be built not to have.
68
68
  if: (id, name, init) => ({ id, name, kind: 'if', ...init }),
69
+ // `filter` arrived third, and the map stopped the build a third time.
70
+ //
71
+ // Also unused by every template below, and this one is the clearest case of
72
+ // the three. A filter's content is a *column name and a value* — which are
73
+ // facts about one organisation's data, not about a pipeline shape — and a
74
+ // template that guessed `status = "OPEN"` would prefill a predicate that is
75
+ // wrong everywhere it is opened. Worse, a prefilled filter sitting in front of
76
+ // a sink is precisely the accident `WorkflowFilterNode.narrows` exists to make
77
+ // impossible: the template would be shipping a graph that shrinks a published
78
+ // type, with nobody having chosen it.
79
+ filter: (id, name, init) => ({ id, name, kind: 'filter', ...init }),
69
80
  };
70
81
  /* -------------------------------------------------------------------------- */
71
82
  /* Starter transform code */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dudousxd/nestjs-catalog-react",
3
- "version": "0.19.0-preview.0",
3
+ "version": "0.20.0",
4
4
  "description": "Ready-made React screens for @dudousxd/nestjs-catalog — a model manager and a generic object explorer you can drop into your own app shell.",
5
5
  "license": "MIT",
6
6
  "author": "Davide Carvalho",
@@ -45,17 +45,13 @@
45
45
  "dist",
46
46
  "LICENSE-bklit"
47
47
  ],
48
- "scripts": {
49
- "build": "tsc -p tsconfig.json",
50
- "dev": "tsc -p tsconfig.json --watch"
51
- },
52
48
  "peerDependencies": {
53
49
  "@base-ui/react": ">=1.6.0",
54
50
  "@pierre/diffs": ">=1.3.3",
55
51
  "@dnd-kit/core": ">=6",
56
52
  "@dnd-kit/sortable": ">=10",
57
53
  "@dnd-kit/utilities": ">=3",
58
- "@dudousxd/nestjs-catalog": "0.16.0-preview.0",
54
+ "@dudousxd/nestjs-catalog": ">=0.1.0",
59
55
  "@tanstack/react-query": ">=5",
60
56
  "@tanstack/react-table": ">=9",
61
57
  "@tiptap/core": ">=3",
@@ -84,7 +80,6 @@
84
80
  "@dnd-kit/core": "6.3.1",
85
81
  "@dnd-kit/sortable": "10.0.0",
86
82
  "@dnd-kit/utilities": "3.2.2",
87
- "@dudousxd/nestjs-catalog": "workspace:*",
88
83
  "@pierre/diffs": "1.3.3",
89
84
  "@tanstack/react-query": "5.99.2",
90
85
  "@tanstack/react-table": "9.0.0",
@@ -114,7 +109,8 @@
114
109
  "recharts": "2.15.4",
115
110
  "tailwind-merge": "3.4.1",
116
111
  "tiptap-markdown": "0.9.0",
117
- "typescript": "5.9.3"
112
+ "typescript": "5.9.3",
113
+ "@dudousxd/nestjs-catalog": "0.17.0"
118
114
  },
119
115
  "dependencies": {
120
116
  "clsx": "2.1.1",
@@ -160,5 +156,9 @@
160
156
  "@xyflow/react": {
161
157
  "optional": true
162
158
  }
159
+ },
160
+ "scripts": {
161
+ "build": "tsc -p tsconfig.json",
162
+ "dev": "tsc -p tsconfig.json --watch"
163
163
  }
164
- }
164
+ }