@dudousxd/nestjs-catalog-react 0.14.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CatalogManager.js +2 -1
- package/dist/LoadExpectationSection.d.ts +12 -0
- package/dist/LoadExpectationSection.js +397 -0
- package/dist/PipelineConsole.js +75 -5
- package/dist/SavedQueryPanel.js +14 -2
- package/dist/TransformEditor.js +8 -1
- package/dist/context.d.ts +114 -1
- package/dist/context.js +32 -0
- package/dist/diff/RevisionDiff.d.ts +63 -0
- package/dist/diff/RevisionDiff.js +279 -0
- package/dist/diff/line-diff.d.ts +124 -0
- package/dist/diff/line-diff.js +318 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +18 -0
- package/dist/routes.d.ts +74 -14
- package/dist/routes.js +66 -14
- package/package.json +2 -2
package/dist/CatalogManager.js
CHANGED
|
@@ -4,6 +4,7 @@ import { ArrowLeft, ArrowRight, ArrowUpRight, Eye, EyeOff, RotateCcw, Search, Un
|
|
|
4
4
|
import { useMemo, useState } from 'react';
|
|
5
5
|
import { CoverageLedger } from './CoverageLedger';
|
|
6
6
|
import { EditableField } from './EditableField';
|
|
7
|
+
import { LoadExpectationSection } from './LoadExpectationSection';
|
|
7
8
|
import { cn } from './cn';
|
|
8
9
|
import { catalogQueryKeys, useCatalogClient } from './context';
|
|
9
10
|
import { freshnessOf, isWorthFlagging } from './freshness';
|
|
@@ -115,7 +116,7 @@ function Stat({ label, value }) {
|
|
|
115
116
|
}
|
|
116
117
|
function TypeDetail({ type, types, explorerHref, onPatchType, onPatchProperty, onNavigate, }) {
|
|
117
118
|
const visible = type.properties.filter((p) => !p.hidden).length;
|
|
118
|
-
return (_jsxs("div", { className: "mx-auto max-w-5xl px-8 py-8", children: [_jsxs("div", { className: "flex flex-wrap items-start justify-between gap-4", children: [_jsxs("div", { className: "min-w-0", children: [_jsxs("div", { className: "flex items-baseline gap-2", children: [_jsx("span", { className: "text-2xl leading-none", children: type.icon ?? '◈' }), _jsx(EditableField, { label: "display name", value: type.displayName, onSave: (displayName) => onPatchType({ displayName }), className: "text-2xl font-semibold tracking-tight", inputClassName: "text-2xl font-semibold tracking-tight" })] }), _jsxs("div", { className: cn('mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 pl-1 font-mono text-[11px]', MUTED), children: [_jsx("span", { children: type.name }), _jsx("span", { "aria-hidden": true, children: "\u00B7" }), _jsx("span", { children: type.tableName }), _jsx("span", { "aria-hidden": true, children: "\u00B7" }), _jsxs("span", { children: ["pk ", type.primaryKey.join(', ') || 'none'] }), _jsx("span", { "aria-hidden": true, children: "\u00B7" }), _jsxs("span", { children: [visible, " of ", type.properties.length, " shown"] })] })] }), explorerHref && (_jsxs("a", { href: explorerHref(type.name), className: cn('flex items-center gap-1.5 rounded-md bg-zinc-950 px-3 py-2 text-xs text-zinc-50', 'transition-colors hover:bg-zinc-800 dark:bg-zinc-100 dark:text-zinc-950 dark:hover:bg-zinc-300'), children: ["Open ", type.pluralDisplayName, _jsx(ArrowUpRight, { size: 13 })] }))] }), _jsx("div", { className: "mt-5 border-l-2 border-sky-200 pl-4 dark:border-sky-900", children: _jsx(RichTextField, { label: "description", value: type.description ?? '', placeholder: "No one has written down what this type means yet.", onSave: (description) => onPatchType({ description }), className: cn('text-sm leading-relaxed', SECONDARY) }) }), _jsxs("div", { className: "mt-4 flex flex-wrap items-center gap-2", children: [_jsx(FieldChip, { label: "Group", value: type.group, onSave: (group) => onPatchType({ group }) }), _jsx(FieldChip, { label: "Plural", value: type.pluralDisplayName, onSave: (pluralDisplayName) => onPatchType({ pluralDisplayName }) }), _jsx(FieldChip, { label: "Icon", value: type.icon ?? '', onSave: (icon) => onPatchType({ icon }) })] }), _jsxs("section", { className: "mt-10", children: [_jsx(SectionHeading, { title: "Properties", note: "The column and its SQL type are read from the ORM. The label, description and unit are yours." }), _jsx("div", { className: cn('overflow-hidden rounded-lg border', RULE, PANEL), children: _jsx(PropertyTable, { properties: type.properties, onPatchProperty: onPatchProperty }) })] }), _jsx(LinkSection, { type: type, types: types, onPatchProperty: onPatchProperty, onNavigate: onNavigate })] }));
|
|
119
|
+
return (_jsxs("div", { className: "mx-auto max-w-5xl px-8 py-8", children: [_jsxs("div", { className: "flex flex-wrap items-start justify-between gap-4", children: [_jsxs("div", { className: "min-w-0", children: [_jsxs("div", { className: "flex items-baseline gap-2", children: [_jsx("span", { className: "text-2xl leading-none", children: type.icon ?? '◈' }), _jsx(EditableField, { label: "display name", value: type.displayName, onSave: (displayName) => onPatchType({ displayName }), className: "text-2xl font-semibold tracking-tight", inputClassName: "text-2xl font-semibold tracking-tight" })] }), _jsxs("div", { className: cn('mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 pl-1 font-mono text-[11px]', MUTED), children: [_jsx("span", { children: type.name }), _jsx("span", { "aria-hidden": true, children: "\u00B7" }), _jsx("span", { children: type.tableName }), _jsx("span", { "aria-hidden": true, children: "\u00B7" }), _jsxs("span", { children: ["pk ", type.primaryKey.join(', ') || 'none'] }), _jsx("span", { "aria-hidden": true, children: "\u00B7" }), _jsxs("span", { children: [visible, " of ", type.properties.length, " shown"] })] })] }), explorerHref && (_jsxs("a", { href: explorerHref(type.name), className: cn('flex items-center gap-1.5 rounded-md bg-zinc-950 px-3 py-2 text-xs text-zinc-50', 'transition-colors hover:bg-zinc-800 dark:bg-zinc-100 dark:text-zinc-950 dark:hover:bg-zinc-300'), children: ["Open ", type.pluralDisplayName, _jsx(ArrowUpRight, { size: 13 })] }))] }), _jsx("div", { className: "mt-5 border-l-2 border-sky-200 pl-4 dark:border-sky-900", children: _jsx(RichTextField, { label: "description", value: type.description ?? '', placeholder: "No one has written down what this type means yet.", onSave: (description) => onPatchType({ description }), className: cn('text-sm leading-relaxed', SECONDARY) }) }), _jsxs("div", { className: "mt-4 flex flex-wrap items-center gap-2", children: [_jsx(FieldChip, { label: "Group", value: type.group, onSave: (group) => onPatchType({ group }) }), _jsx(FieldChip, { label: "Plural", value: type.pluralDisplayName, onSave: (pluralDisplayName) => onPatchType({ pluralDisplayName }) }), _jsx(FieldChip, { label: "Icon", value: type.icon ?? '', onSave: (icon) => onPatchType({ icon }) })] }), _jsxs("section", { className: "mt-10", children: [_jsx(SectionHeading, { title: "Properties", note: "The column and its SQL type are read from the ORM. The label, description and unit are yours." }), _jsx("div", { className: cn('overflow-hidden rounded-lg border', RULE, PANEL), children: _jsx(PropertyTable, { properties: type.properties, onPatchProperty: onPatchProperty }) })] }), _jsx(LoadExpectationSection, { typeName: type.name, displayName: type.displayName }), _jsx(LinkSection, { type: type, types: types, onPatchProperty: onPatchProperty, onNavigate: onNavigate })] }));
|
|
119
120
|
}
|
|
120
121
|
/** What each kind actually says, for people who do not read `m:n` fluently. */
|
|
121
122
|
const KIND_MEANING = {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** The three, in the order the client package lists them, as a select understands them. */
|
|
2
|
+
export declare const DELETE_STRATEGIES: {
|
|
3
|
+
label: string;
|
|
4
|
+
hint: string;
|
|
5
|
+
value: "accepted" | "soft-deleted-at-source" | "periodic-full-reload";
|
|
6
|
+
}[];
|
|
7
|
+
export interface LoadExpectationSectionProps {
|
|
8
|
+
typeName: string;
|
|
9
|
+
/** What a person calls the type. Used in the sentences, which are about the type. */
|
|
10
|
+
displayName: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function LoadExpectationSection({ typeName, displayName }: LoadExpectationSectionProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { DELETE_RECONCILIATION_STRATEGIES, isDeleteReconciliationStrategy, } from '@dudousxd/nestjs-catalog/client';
|
|
3
|
+
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
4
|
+
import { Lock } from 'lucide-react';
|
|
5
|
+
import { useMemo, useState } from 'react';
|
|
6
|
+
import { cn } from './cn';
|
|
7
|
+
import { catalogQueryKeys, useCatalogClient, } from './context';
|
|
8
|
+
import { Button } from './ui/button';
|
|
9
|
+
import { DataTable } from './ui/data-table';
|
|
10
|
+
import { TextAreaField, TextField } from './ui/field';
|
|
11
|
+
import { SelectField } from './ui/select';
|
|
12
|
+
/**
|
|
13
|
+
* What a type promises about deletes and row counts, and the form that sets it.
|
|
14
|
+
*
|
|
15
|
+
* The section exists because of one state, and it is the empty one: a type with
|
|
16
|
+
* no delete strategy declared has its INCREMENTAL loads refused, and until this
|
|
17
|
+
* screen existed the only way to learn that was to run one and read the
|
|
18
|
+
* failure — or to have an engineer put the answer in `CATALOG_LOAD_EXPECTATIONS`
|
|
19
|
+
* and deploy. So the empty state is said in words rather than drawn as a blank
|
|
20
|
+
* field, and it is the first thing in the section.
|
|
21
|
+
*
|
|
22
|
+
* The other half is attribution. `because` is a sentence somebody is
|
|
23
|
+
* accountable for, so it is rendered as prose next to who wrote it and when —
|
|
24
|
+
* not as a value in the provenance table beside it, which would read as
|
|
25
|
+
* configuration and be skimmed like configuration.
|
|
26
|
+
*/
|
|
27
|
+
const MUTED = 'text-zinc-400 dark:text-zinc-500';
|
|
28
|
+
const SECONDARY = 'text-zinc-500 dark:text-zinc-400';
|
|
29
|
+
const PANEL = 'bg-white dark:bg-zinc-900';
|
|
30
|
+
const RULE = 'border-zinc-200 dark:border-zinc-800';
|
|
31
|
+
const DANGER = 'text-rose-600 dark:text-rose-400';
|
|
32
|
+
/**
|
|
33
|
+
* What each strategy is called on screen, and what it means in one line.
|
|
34
|
+
*
|
|
35
|
+
* A `Record` over the union rather than a hand-written array of options, so the
|
|
36
|
+
* list of strategies has exactly one home — `DELETE_RECONCILIATION_STRATEGIES`
|
|
37
|
+
* in `@dudousxd/nestjs-catalog/client`, which the server validates against too.
|
|
38
|
+
* A fourth strategy added there fails to compile here until somebody writes the
|
|
39
|
+
* copy for it, which is the failure worth having: the alternative is a dropdown
|
|
40
|
+
* that quietly does not offer a strategy the server accepts.
|
|
41
|
+
*/
|
|
42
|
+
const STRATEGY_COPY = {
|
|
43
|
+
accepted: {
|
|
44
|
+
label: 'Accepted — nothing reconciles them',
|
|
45
|
+
hint: 'An append-only ledger, or a dataset where a few stale rows cost less than a nightly full read.',
|
|
46
|
+
},
|
|
47
|
+
'soft-deleted-at-source': {
|
|
48
|
+
label: 'Soft-deleted at the source',
|
|
49
|
+
hint: 'The source flips a column instead of removing the row, so the watermark sees the deletion as an ordinary change.',
|
|
50
|
+
},
|
|
51
|
+
'periodic-full-reload': {
|
|
52
|
+
label: 'Periodic full reload',
|
|
53
|
+
hint: 'Full loads reconcile. Once the newest full load is older than the interval, incremental loads stop committing.',
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
/** The three, in the order the client package lists them, as a select understands them. */
|
|
57
|
+
export const DELETE_STRATEGIES = DELETE_RECONCILIATION_STRATEGIES.map((value) => ({
|
|
58
|
+
value,
|
|
59
|
+
...STRATEGY_COPY[value],
|
|
60
|
+
}));
|
|
61
|
+
/**
|
|
62
|
+
* A select hands back a string. Narrow it rather than promise it is a strategy.
|
|
63
|
+
*
|
|
64
|
+
* The empty string is a real answer and not a failure: a type may legitimately
|
|
65
|
+
* have no delete strategy chosen yet, and that is the state this section exists
|
|
66
|
+
* to make visible. Defaulting an unknown value to one of the three would invent
|
|
67
|
+
* a decision nobody made — which is the one thing this whole mechanism is for.
|
|
68
|
+
*/
|
|
69
|
+
function toDeleteStrategy(value) {
|
|
70
|
+
return isDeleteReconciliationStrategy(value) ? value : '';
|
|
71
|
+
}
|
|
72
|
+
/** How each layer should be described to somebody deciding whether they may edit. */
|
|
73
|
+
const SOURCE_LABEL = {
|
|
74
|
+
host: 'Fixed in code by this deployment',
|
|
75
|
+
stored: 'Set here, by an operator',
|
|
76
|
+
default: "The host's house-wide default",
|
|
77
|
+
none: 'Nothing declares it',
|
|
78
|
+
};
|
|
79
|
+
/** A blank field means "say nothing about this", which is not the same as zero. */
|
|
80
|
+
function numberOrNull(raw) {
|
|
81
|
+
const trimmed = raw.trim();
|
|
82
|
+
if (trimmed === '')
|
|
83
|
+
return null;
|
|
84
|
+
const value = Number(trimmed);
|
|
85
|
+
return Number.isFinite(value) ? value : null;
|
|
86
|
+
}
|
|
87
|
+
function text(value) {
|
|
88
|
+
return value === undefined ? '' : String(value);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* What the form starts as.
|
|
92
|
+
*
|
|
93
|
+
* The STORED row, except where the host has locked a field — there the resolved
|
|
94
|
+
* value is shown instead, because the control is disabled and what a disabled
|
|
95
|
+
* control must show is the value actually in force. Filling the form with the
|
|
96
|
+
* host's values where it has NOT locked them would be worse than useless: it
|
|
97
|
+
* would turn "the house default applies" into "this type stores this", the
|
|
98
|
+
* first time anybody pressed save.
|
|
99
|
+
*/
|
|
100
|
+
function draftFrom(view) {
|
|
101
|
+
const deletes = view.hostLocked.deletes ? view.resolved.deletes : view.stored?.deletes;
|
|
102
|
+
const rowCount = view.hostLocked.rowCount ? view.resolved.rowCount : view.stored?.rowCount;
|
|
103
|
+
return {
|
|
104
|
+
strategy: deletes?.strategy ?? '',
|
|
105
|
+
because: deletes?.because ?? '',
|
|
106
|
+
column: deletes?.strategy === 'soft-deleted-at-source' ? (deletes.column ?? '') : '',
|
|
107
|
+
withinMs: deletes?.strategy === 'periodic-full-reload' ? String(deletes.withinMs) : '',
|
|
108
|
+
maxShrink: text(rowCount?.maxShrink),
|
|
109
|
+
maxGrowth: text(rowCount?.maxGrowth),
|
|
110
|
+
minRows: text(rowCount?.minRows),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Everything wrong with the draft, by field.
|
|
115
|
+
*
|
|
116
|
+
* A mirror of what the server refuses with a 400, and deliberately a mirror
|
|
117
|
+
* rather than the authority: the server's answer always wins. What this buys is
|
|
118
|
+
* that the refusal arrives beside the field that caused it while somebody is
|
|
119
|
+
* typing, instead of as a message about a request they have stopped thinking
|
|
120
|
+
* about.
|
|
121
|
+
*
|
|
122
|
+
* Locked fields are skipped, because they are not being sent.
|
|
123
|
+
*/
|
|
124
|
+
function problemsWith(draft, hostLocked) {
|
|
125
|
+
return {
|
|
126
|
+
...(hostLocked.deletes ? {} : deleteProblems(draft)),
|
|
127
|
+
...(hostLocked.rowCount ? {} : rowCountProblems(draft)),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function deleteProblems(draft) {
|
|
131
|
+
if (draft.strategy === '')
|
|
132
|
+
return {};
|
|
133
|
+
const problems = {};
|
|
134
|
+
// Required for all three, including `accepted` — especially `accepted`, which
|
|
135
|
+
// is the one somebody would otherwise pick to make the refusal go away
|
|
136
|
+
// without deciding anything.
|
|
137
|
+
if (draft.because.trim() === '') {
|
|
138
|
+
problems.because = 'Required. Say why this is the right answer for this type.';
|
|
139
|
+
}
|
|
140
|
+
if (draft.strategy === 'periodic-full-reload') {
|
|
141
|
+
const withinMs = numberOrNull(draft.withinMs);
|
|
142
|
+
if (withinMs === null || withinMs <= 0) {
|
|
143
|
+
problems.withinMs = 'Required, and greater than zero: the interval is what makes this real.';
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return problems;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* A blank bound is always fine — it means "say nothing about this" — so every
|
|
150
|
+
* check here is conditional on somebody having typed something.
|
|
151
|
+
*/
|
|
152
|
+
function rowCountProblems(draft) {
|
|
153
|
+
const problems = {};
|
|
154
|
+
const maxShrink = numberOrNull(draft.maxShrink);
|
|
155
|
+
if (draft.maxShrink.trim() !== '' && (maxShrink === null || maxShrink <= 0 || maxShrink > 1)) {
|
|
156
|
+
problems.maxShrink = 'A fraction above 0 and up to 1. 0.5 refuses a load that halves the type.';
|
|
157
|
+
}
|
|
158
|
+
const maxGrowth = numberOrNull(draft.maxGrowth);
|
|
159
|
+
if (draft.maxGrowth.trim() !== '' && (maxGrowth === null || maxGrowth <= 1)) {
|
|
160
|
+
problems.maxGrowth = 'A ratio above 1. Leave it blank to never refuse growth.';
|
|
161
|
+
}
|
|
162
|
+
const minRows = numberOrNull(draft.minRows);
|
|
163
|
+
if (draft.minRows.trim() !== '' && (minRows === null || minRows < 0)) {
|
|
164
|
+
problems.minRows = 'A row count, zero or more.';
|
|
165
|
+
}
|
|
166
|
+
return problems;
|
|
167
|
+
}
|
|
168
|
+
/** The row-count fields that carry a number, as the body wants them. */
|
|
169
|
+
function rowCountFrom(draft) {
|
|
170
|
+
const maxShrink = numberOrNull(draft.maxShrink);
|
|
171
|
+
const maxGrowth = numberOrNull(draft.maxGrowth);
|
|
172
|
+
const minRows = numberOrNull(draft.minRows);
|
|
173
|
+
if (maxShrink === null && maxGrowth === null && minRows === null)
|
|
174
|
+
return undefined;
|
|
175
|
+
return {
|
|
176
|
+
...(maxShrink === null ? {} : { maxShrink }),
|
|
177
|
+
...(maxGrowth === null ? {} : { maxGrowth }),
|
|
178
|
+
...(minRows === null ? {} : { minRows }),
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
/** The chosen strategy as the union member it is, or nothing chosen. */
|
|
182
|
+
function deletesFrom(draft) {
|
|
183
|
+
const because = draft.because.trim();
|
|
184
|
+
if (draft.strategy === 'accepted')
|
|
185
|
+
return { strategy: 'accepted', because };
|
|
186
|
+
if (draft.strategy === 'soft-deleted-at-source') {
|
|
187
|
+
const column = draft.column.trim();
|
|
188
|
+
return { strategy: 'soft-deleted-at-source', because, ...(column ? { column } : {}) };
|
|
189
|
+
}
|
|
190
|
+
if (draft.strategy === 'periodic-full-reload') {
|
|
191
|
+
const withinMs = numberOrNull(draft.withinMs);
|
|
192
|
+
// Unreachable through the form — `problemsWith` disables the button first —
|
|
193
|
+
// and typed rather than asserted, so it stays unreachable if it moves.
|
|
194
|
+
if (withinMs === null)
|
|
195
|
+
return undefined;
|
|
196
|
+
return { strategy: 'periodic-full-reload', because, withinMs };
|
|
197
|
+
}
|
|
198
|
+
return undefined;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* What the form would send.
|
|
202
|
+
*
|
|
203
|
+
* A locked field is OMITTED rather than sent unchanged. The server answers 409
|
|
204
|
+
* for a write to a field the host owns, and a body that echoed the host's value
|
|
205
|
+
* back would turn every save of the other half into that refusal.
|
|
206
|
+
*/
|
|
207
|
+
function bodyFrom(draft, hostLocked) {
|
|
208
|
+
const deletes = hostLocked.deletes ? undefined : deletesFrom(draft);
|
|
209
|
+
const rowCount = hostLocked.rowCount ? undefined : rowCountFrom(draft);
|
|
210
|
+
return {
|
|
211
|
+
...(deletes ? { deletes } : {}),
|
|
212
|
+
...(rowCount ? { rowCount } : {}),
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
/** Milliseconds, in the unit a person would have said it in. */
|
|
216
|
+
function describeInterval(ms) {
|
|
217
|
+
if (!Number.isFinite(ms) || ms <= 0)
|
|
218
|
+
return `${ms} ms`;
|
|
219
|
+
const trim = (value) => String(Math.round(value * 10) / 10);
|
|
220
|
+
const hours = ms / 3_600_000;
|
|
221
|
+
if (hours >= 48)
|
|
222
|
+
return `${trim(hours / 24)} days`;
|
|
223
|
+
if (hours >= 1)
|
|
224
|
+
return `${trim(hours)} hours`;
|
|
225
|
+
return `${trim(ms / 60_000)} minutes`;
|
|
226
|
+
}
|
|
227
|
+
export function LoadExpectationSection({ typeName, displayName }) {
|
|
228
|
+
const client = useCatalogClient();
|
|
229
|
+
const { data: view, isPending, isError, error, } = useQuery({
|
|
230
|
+
queryKey: catalogQueryKeys.loadExpectation(typeName),
|
|
231
|
+
queryFn: () => client.loadExpectation(typeName),
|
|
232
|
+
// Not retried. The likely failure is a host that serves no pipeline
|
|
233
|
+
// endpoints at all, and four attempts at a 404 over thirty seconds is a
|
|
234
|
+
// section that says nothing for half a minute before saying that.
|
|
235
|
+
retry: false,
|
|
236
|
+
});
|
|
237
|
+
return (_jsxs("section", { className: "mt-10", children: [_jsxs("div", { className: "mb-3", children: [_jsx("h2", { className: cn('font-mono text-[11px] uppercase tracking-[0.16em]', MUTED), children: "Load expectation" }), _jsx("p", { className: cn('mt-1 text-xs', MUTED), children: "How this type reconciles rows deleted at the source, and how far one load may move its row count. Checked before a load is allowed to become the data everybody reads." })] }), isPending && _jsx("p", { className: cn('font-mono text-xs', MUTED), children: "Reading the expectation\u2026" }), isError && (_jsxs("div", { className: cn('rounded-lg border px-4 py-3', RULE, PANEL), children: [_jsx("p", { className: "text-sm", children: "Could not read the load expectation." }), _jsxs("p", { className: cn('mt-1 text-xs', SECONDARY), children: ["It is served by the pipeline endpoints, which are the host's rather than this library's \u2014 this deployment may not mount them, or this account may not read them. Nothing here says whether a load of ", displayName, " would be refused."] }), error instanceof Error && (_jsx("p", { className: cn('mt-1 font-mono text-[11px]', MUTED), children: error.message }))] })), view && _jsx(LoadExpectationBody, { view: view, displayName: displayName })] }));
|
|
238
|
+
}
|
|
239
|
+
function LoadExpectationBody({ view, displayName, }) {
|
|
240
|
+
const deletes = view.resolved.deletes;
|
|
241
|
+
return (_jsxs("div", { className: "space-y-4", children: [view.deletesFrom === 'none' ? (
|
|
242
|
+
// The whole reason somebody opens this section. Said in words, and
|
|
243
|
+
// said first: a blank strategy field is read as "not filled in yet",
|
|
244
|
+
// which is exactly the wrong conclusion — the load is already refused.
|
|
245
|
+
_jsxs("div", { className: cn('rounded-lg border border-amber-300 bg-amber-50 px-4 py-3', 'dark:border-amber-900 dark:bg-amber-950/40'), children: [_jsxs("p", { className: "text-sm text-amber-900 dark:text-amber-200", children: ["Nothing declares how ", displayName, " reconciles deletes, so an incremental load of it will be refused."] }), _jsx("p", { className: "mt-1 text-xs text-amber-800 dark:text-amber-300/80", children: "A full load still commits \u2014 it replaces the whole type, so deletions reconcile by construction. What is blocked is the incremental path, until somebody chooses a strategy below and writes down why." })] })) : (_jsxs("div", { className: cn('rounded-lg border px-4 py-3', RULE, PANEL), children: [_jsxs("div", { className: "flex flex-wrap items-baseline justify-between gap-2", children: [_jsxs("p", { className: "text-sm", children: ["Deletes: ", _jsx("span", { className: "font-mono", children: deletes?.strategy }), deletes?.strategy === 'periodic-full-reload' && (_jsxs("span", { className: SECONDARY, children: [' ', "\u00B7 reconciled every ", describeInterval(deletes.withinMs)] })), deletes?.strategy === 'soft-deleted-at-source' && deletes.column && (_jsxs("span", { className: SECONDARY, children: [" \u00B7 column ", deletes.column] }))] }), _jsx(SourceBadge, { source: view.deletesFrom })] }), deletes && (
|
|
246
|
+
// Prose, and marked up as prose: this is a sentence somebody is
|
|
247
|
+
// accountable for, not a config value. In the table below it would
|
|
248
|
+
// be skimmed like one.
|
|
249
|
+
_jsxs("blockquote", { className: "mt-2 border-l-2 border-sky-200 pl-4 dark:border-sky-900", children: [_jsx("p", { className: "text-sm leading-relaxed", children: deletes.because }), _jsx(Attribution, { view: view })] }))] })), _jsx(ProvenanceTable, { view: view }), _jsx(ExpectationForm, { view: view, displayName: displayName })] }));
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Who wrote the sentence above, and when.
|
|
253
|
+
*
|
|
254
|
+
* Rendered from the STORED row only. A `because` that came from the host was
|
|
255
|
+
* written in a commit, and naming the person the server happens to be running
|
|
256
|
+
* as would attribute it to somebody who never saw it.
|
|
257
|
+
*/
|
|
258
|
+
function Attribution({ view }) {
|
|
259
|
+
const stored = view.stored;
|
|
260
|
+
if (!stored) {
|
|
261
|
+
return (_jsx("p", { className: cn('mt-1.5 text-[11px]', MUTED), children: "Declared in this deployment's code. Its author is in the commit that set it, not here." }));
|
|
262
|
+
}
|
|
263
|
+
const who = stored.setByActor ? `${stored.setByActor}, through ${stored.setBy}` : stored.setBy;
|
|
264
|
+
return (_jsxs("p", { className: cn('mt-1.5 text-[11px]', MUTED), children: ["Set by ", who, " on ", new Date(stored.setAt).toLocaleString(), view.hostLocked.deletes && ' — and overridden since, by what the host declares in code.'] }));
|
|
265
|
+
}
|
|
266
|
+
function SourceBadge({ source }) {
|
|
267
|
+
return (_jsxs("span", { className: cn('flex items-center gap-1 rounded-sm bg-zinc-100 px-1.5 py-0.5 text-[10px] dark:bg-zinc-800', SECONDARY), children: [source === 'host' && _jsx(Lock, { size: 10, "aria-hidden": true }), SOURCE_LABEL[source]] }));
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Which layer won each field.
|
|
271
|
+
*
|
|
272
|
+
* Field by field rather than one badge for the whole expectation, because the
|
|
273
|
+
* resolution IS field by field — a host that pinned a row-count bound and said
|
|
274
|
+
* nothing about deletes leaves this type with two different answers to "may I
|
|
275
|
+
* change this", and one badge would have to pick one of them and be wrong about
|
|
276
|
+
* the other.
|
|
277
|
+
*/
|
|
278
|
+
function ProvenanceTable({ view }) {
|
|
279
|
+
const rows = useMemo(() => {
|
|
280
|
+
const bound = view.resolved.rowCount;
|
|
281
|
+
return [
|
|
282
|
+
{
|
|
283
|
+
id: 'deletes',
|
|
284
|
+
field: 'Delete reconciliation',
|
|
285
|
+
value: view.resolved.deletes?.strategy ?? 'not declared',
|
|
286
|
+
source: view.deletesFrom,
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
id: 'maxShrink',
|
|
290
|
+
field: 'Max shrink',
|
|
291
|
+
value: bound?.maxShrink === undefined
|
|
292
|
+
? 'not declared'
|
|
293
|
+
: `${bound.maxShrink} of the served snapshot`,
|
|
294
|
+
source: view.rowCountFrom,
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
id: 'maxGrowth',
|
|
298
|
+
field: 'Max growth',
|
|
299
|
+
// "never refused" rather than a dash: absent is the documented
|
|
300
|
+
// behaviour here, not a missing value somebody forgot to fill in.
|
|
301
|
+
value: bound?.maxGrowth === undefined ? 'growth is never refused' : `${bound.maxGrowth}×`,
|
|
302
|
+
source: view.rowCountFrom,
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
id: 'minRows',
|
|
306
|
+
field: 'Min rows for a ratio',
|
|
307
|
+
value: bound?.minRows === undefined ? 'not declared' : `${bound.minRows} rows`,
|
|
308
|
+
source: view.rowCountFrom,
|
|
309
|
+
},
|
|
310
|
+
];
|
|
311
|
+
}, [view]);
|
|
312
|
+
const columns = useMemo(() => [
|
|
313
|
+
{
|
|
314
|
+
id: 'field',
|
|
315
|
+
header: 'Field',
|
|
316
|
+
accessorFn: (row) => row.field,
|
|
317
|
+
cell: ({ row }) => (_jsx("span", { className: "text-xs", children: row.original.field })),
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
id: 'value',
|
|
321
|
+
header: 'In force',
|
|
322
|
+
accessorFn: (row) => row.value,
|
|
323
|
+
cell: ({ row }) => (_jsx("span", { className: cn('font-mono text-[11px]', SECONDARY), children: row.original.value })),
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
id: 'source',
|
|
327
|
+
header: 'Where it came from',
|
|
328
|
+
accessorFn: (row) => row.source,
|
|
329
|
+
cell: ({ row }) => (_jsx(SourceBadge, { source: row.original.source })),
|
|
330
|
+
},
|
|
331
|
+
], []);
|
|
332
|
+
return (_jsx("div", { className: cn('overflow-hidden rounded-lg border', RULE, PANEL), children: _jsx(DataTable, { data: rows, columns: columns, getRowId: (row) => row.id, columnClassName: (id) => (id === 'source' ? 'w-[34%]' : 'w-[33%]') }) }));
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* The editor.
|
|
336
|
+
*
|
|
337
|
+
* A locked field is shown and disabled rather than hidden, which is the rule
|
|
338
|
+
* this section is built around: hiding it would leave a screen that cannot
|
|
339
|
+
* explain why the type behaves the way it does, and leaving it enabled would
|
|
340
|
+
* offer an edit the server answers 409 to — an edit that silently fails is the
|
|
341
|
+
* one outcome worse than either.
|
|
342
|
+
*/
|
|
343
|
+
function ExpectationForm({ view, displayName, }) {
|
|
344
|
+
const client = useCatalogClient();
|
|
345
|
+
const queryClient = useQueryClient();
|
|
346
|
+
const [draft, setDraft] = useState(() => draftFrom(view));
|
|
347
|
+
const update = (patch) => setDraft({ ...draft, ...patch });
|
|
348
|
+
const invalidate = () => queryClient.invalidateQueries({
|
|
349
|
+
queryKey: catalogQueryKeys.loadExpectation(view.typeName),
|
|
350
|
+
});
|
|
351
|
+
const save = useMutation({
|
|
352
|
+
mutationFn: () => client.setLoadExpectation(view.typeName, bodyFrom(draft, view.hostLocked)),
|
|
353
|
+
// Refetched rather than written from the answer: what belongs on screen is
|
|
354
|
+
// the RESOLVED expectation, and resolving it against what the host declared
|
|
355
|
+
// is the server's job. See `CatalogClient.setLoadExpectation`.
|
|
356
|
+
onSuccess: invalidate,
|
|
357
|
+
});
|
|
358
|
+
const clear = useMutation({
|
|
359
|
+
mutationFn: () => client.clearLoadExpectation(view.typeName),
|
|
360
|
+
onSuccess: invalidate,
|
|
361
|
+
});
|
|
362
|
+
const problems = problemsWith(draft, view.hostLocked);
|
|
363
|
+
const body = bodyFrom(draft, view.hostLocked);
|
|
364
|
+
const nothingToSave = body.deletes === undefined && body.rowCount === undefined;
|
|
365
|
+
const everythingLocked = view.hostLocked.deletes && view.hostLocked.rowCount;
|
|
366
|
+
const blocked = Object.keys(problems).length > 0 || nothingToSave || everythingLocked;
|
|
367
|
+
return (_jsxs("form", { className: cn('space-y-4 rounded-lg border p-4', RULE, PANEL), onSubmit: (event) => {
|
|
368
|
+
event.preventDefault();
|
|
369
|
+
// Checked here as well as on the button. A disabled button is a
|
|
370
|
+
// statement about the pointer; a form still submits on Enter, and a
|
|
371
|
+
// `because` this screen let through would be stored as an empty
|
|
372
|
+
// sentence nobody can be held to.
|
|
373
|
+
if (blocked || save.isPending)
|
|
374
|
+
return;
|
|
375
|
+
save.mutate();
|
|
376
|
+
}, children: [_jsxs("p", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: ["Set it for ", displayName] }), _jsx(DeleteFields, { draft: draft, update: update, problems: problems, view: view }), _jsx(RowCountFields, { draft: draft, update: update, problems: problems, view: view }), _jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx(Button, { type: "submit", size: "sm", disabled: blocked || save.isPending, children: save.isPending ? 'Saving…' : 'Save expectation' }), view.stored && (_jsx(Button, { size: "sm", variant: "outline", disabled: clear.isPending, onClick: () => clear.mutate(), children: clear.isPending ? 'Clearing…' : 'Clear the stored one' })), everythingLocked && (_jsx("span", { className: cn('text-[11px]', SECONDARY), children: "Every field here is fixed in code, so there is nothing this screen can store." }))] }), save.error && (_jsx("p", { className: cn('text-[11px]', DANGER), children: save.error instanceof Error ? save.error.message : 'Could not save.' })), clear.error && (_jsx("p", { className: cn('text-[11px]', DANGER), children: clear.error instanceof Error ? clear.error.message : 'Could not clear it.' }))] }));
|
|
377
|
+
}
|
|
378
|
+
/** A hint, or the reason the field is refused, in its place. */
|
|
379
|
+
function hintFor(problem, otherwise) {
|
|
380
|
+
return problem ? _jsx("span", { className: DANGER, children: problem }) : otherwise;
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* The strategy, its reason, and whichever one extra field the strategy needs.
|
|
384
|
+
*
|
|
385
|
+
* The extra field is rendered per strategy rather than always: an interval box
|
|
386
|
+
* beside `accepted` is a field that does nothing, and a form full of those is
|
|
387
|
+
* how somebody comes to believe a value they typed is in force.
|
|
388
|
+
*/
|
|
389
|
+
function DeleteFields({ draft, update, problems, view }) {
|
|
390
|
+
const locked = view.hostLocked.deletes;
|
|
391
|
+
return (_jsxs(_Fragment, { children: [locked && (_jsxs("p", { className: cn('text-[11px]', SECONDARY), children: ["This deployment fixed the delete strategy in code, in its", _jsx("span", { className: "font-mono", children: " CATALOG_LOAD_EXPECTATIONS" }), ". It is shown here and cannot be changed from this screen \u2014 a write would be refused."] })), _jsxs("div", { className: "grid gap-3 sm:grid-cols-2", children: [_jsx(SelectField, { label: "Deletes", ariaLabel: "Delete reconciliation strategy", value: draft.strategy, onValueChange: (value) => update({ strategy: toDeleteStrategy(value) }), options: [...DELETE_STRATEGIES], placeholder: "Nothing chosen \u2014 incremental loads refused", disabled: locked }), draft.strategy === 'periodic-full-reload' && (_jsx(TextField, { label: "Reconcile within (ms)", value: draft.withinMs, onChange: (withinMs) => update({ withinMs }), inputMode: "numeric", placeholder: "86400000", disabled: locked, hint: hintFor(problems.withinMs, 'Once the newest full load is older than this, incremental loads stop committing.') })), draft.strategy === 'soft-deleted-at-source' && (_jsx(TextField, { label: "Column (optional)", value: draft.column, onChange: (column) => update({ column }), placeholder: "deleted_at", disabled: locked, hint: "Which column the source flips. Recorded for the next reader; nothing here verifies it." }))] }), _jsx(TextAreaField, { label: "Because", value: draft.because, onChange: (because) => update({ because }), rows: 3, placeholder: "Why this is the right answer for this type.", disabled: locked, hint: hintFor(problems.because, 'Required for every strategy. It is signed with your name and shown to whoever reads this next.') })] }));
|
|
392
|
+
}
|
|
393
|
+
/** The three bounds. All optional, and a blank one says nothing rather than zero. */
|
|
394
|
+
function RowCountFields({ draft, update, problems, view }) {
|
|
395
|
+
const locked = view.hostLocked.rowCount;
|
|
396
|
+
return (_jsxs(_Fragment, { children: [locked && (_jsx("p", { className: cn('text-[11px]', SECONDARY), children: "This deployment fixed the row-count bounds in code. They are shown here and cannot be changed from this screen." })), _jsxs("div", { className: "grid gap-3 sm:grid-cols-3", children: [_jsx(TextField, { label: "Max shrink", value: draft.maxShrink, onChange: (maxShrink) => update({ maxShrink }), inputMode: "numeric", placeholder: "0.5", disabled: locked, hint: hintFor(problems.maxShrink, 'The most of the served snapshot one load may lose.') }), _jsx(TextField, { label: "Max growth", value: draft.maxGrowth, onChange: (maxGrowth) => update({ maxGrowth }), inputMode: "numeric", placeholder: "blank \u2014 never refused", disabled: locked, hint: hintFor(problems.maxGrowth, 'A backfill is usually a good day. Leave it blank unless it is not.') }), _jsx(TextField, { label: "Min rows", value: draft.minRows, onChange: (minRows) => update({ minRows }), inputMode: "numeric", placeholder: "100", disabled: locked, hint: hintFor(problems.minRows, 'Below this, no ratio applies — a percentage of a small number is noise.') })] })] }));
|
|
397
|
+
}
|
package/dist/PipelineConsole.js
CHANGED
|
@@ -6,6 +6,7 @@ import { ConnectionPanel, connectionOptionsFor } from './ConnectionPanel';
|
|
|
6
6
|
import { TransformEditor } from './TransformEditor';
|
|
7
7
|
import { cn } from './cn';
|
|
8
8
|
import { catalogQueryKeys, useCatalogClient } from './context';
|
|
9
|
+
import { RevisionHistorySheet } from './diff/RevisionDiff';
|
|
9
10
|
// One description of what a source needs, shared with the workflow canvas's
|
|
10
11
|
// source inspector. See the header of that module for why it is not two.
|
|
11
12
|
import { INLINE_CONNECTION, KIND_OPTIONS, ReadModeFields, SourceFields, parseRecords, readsIncrementally, sourceConfigFrom, sourceDraftFrom, sourceIsIncomplete, toConnectorKind, usesConnection, } from './source-fields';
|
|
@@ -192,10 +193,6 @@ function describeSource(connector, connection) {
|
|
|
192
193
|
function ConnectorCard({ connector, transform, connection, canEdit, running, onRun, onEdit, onDeleted, }) {
|
|
193
194
|
const client = useCatalogClient();
|
|
194
195
|
const [confirming, setConfirming] = useState(false);
|
|
195
|
-
const { data: runs = [] } = useQuery({
|
|
196
|
-
queryKey: catalogQueryKeys.runs(connector.id),
|
|
197
|
-
queryFn: () => client.listRuns(connector.id),
|
|
198
|
-
});
|
|
199
196
|
const remove = useMutation({
|
|
200
197
|
mutationFn: () => client.deleteConnector(connector.id),
|
|
201
198
|
onSuccess: () => {
|
|
@@ -203,12 +200,85 @@ function ConnectorCard({ connector, transform, connection, canEdit, running, onR
|
|
|
203
200
|
onDeleted();
|
|
204
201
|
},
|
|
205
202
|
});
|
|
206
|
-
return (_jsxs("div", { className: cn('rounded-lg border p-4', RULE, PANEL), children: [_jsxs("div", { className: "flex flex-wrap items-start justify-between gap-3", children: [_jsxs("div", { className: "min-w-0", children: [_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx("span", { className: "text-sm font-medium", children: connector.name }), _jsx("span", { className: "rounded-sm bg-zinc-100 px-1.5 py-0.5 font-mono text-[10px] uppercase dark:bg-zinc-800", children: connector.kind }), _jsxs("span", { className: cn('font-mono text-[10px]', MUTED), children: ["\u2192 ", connector.targetType] }), connection && (_jsx(Tooltip, { content: `Reads through the ${connection.name} connection, which supplies the address and the credential. Moving that connection moves this connector with it.`, children: _jsxs("span", { className: cn('flex cursor-help items-center gap-1 font-mono text-[10px]', MUTED), children: [_jsx(Plug, { size: 10 }), connection.name] }) })), connector.mode === 'incremental' && (_jsx(Tooltip, { content: "Reads only what changed since the last run, and carries the rest forward.", children: _jsxs("span", { className: cn('flex cursor-help items-center gap-1 font-mono text-[10px]', MUTED), children: [_jsx(RefreshCw, { size: 10 }), "incremental"] }) })), !connector.enabled && (_jsx("span", { className: "rounded-sm bg-zinc-100 px-1.5 py-0.5 font-mono text-[10px] uppercase text-zinc-500 dark:bg-zinc-800", children: "disabled" }))] }), _jsx("div", { className: cn('mt-1 font-mono text-[11px]', MUTED), children: describeSource(connector, connection) }), connector.secretEnvVar && (_jsx(Tooltip, { content: "The catalog stores the NAME of this variable, never its value. A leaked catalog database gives away the shape of the integration, not the keys to it.", children: _jsxs("div", { className: cn('mt-1 flex w-fit cursor-help items-center gap-1 font-mono text-[10px]', MUTED), children: [_jsx(KeyRound, { size: 10 }), connector.secretEnvVar] }) }))] }), _jsxs("div", { className: "flex shrink-0 items-center gap-1", children: [_jsxs("button", { type: "button", onClick: onRun, disabled: running || !connector.enabled, className: "flex items-center gap-1.5 rounded-md bg-zinc-950 px-3 py-1.5 text-xs text-zinc-50 disabled:opacity-40 dark:bg-zinc-100 dark:text-zinc-950", children: [running ? _jsx(Loader2, { size: 12, className: "animate-spin" }) : _jsx(Play, { size: 12 }), running ? 'Running…' : 'Run now'] }), canEdit && (_jsx(Tooltip, { content: `Delete ${connector.name}`, children: _jsx("button", { type: "button", onClick: () => setConfirming(true), "aria-label": `Delete ${connector.name}`, className: cn('rounded-sm p-1.5 hover:text-red-600', MUTED), children: _jsx(Trash2, { size: 12 }) }) }))] })] }), transform && (_jsxs("button", { type: "button", onClick: onEdit, className: cn('mt-3 flex items-center gap-1.5 text-[11px]', MUTED, 'hover:text-sky-600'), children: [_jsx(Code2, { size: 11 }), transform.name, _jsxs("span", { className: "font-mono", children: [transform.language, " \u00B7 v", transform.version] })] })),
|
|
203
|
+
return (_jsxs("div", { className: cn('rounded-lg border p-4', RULE, PANEL), children: [_jsxs("div", { className: "flex flex-wrap items-start justify-between gap-3", children: [_jsxs("div", { className: "min-w-0", children: [_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx("span", { className: "text-sm font-medium", children: connector.name }), _jsx("span", { className: "rounded-sm bg-zinc-100 px-1.5 py-0.5 font-mono text-[10px] uppercase dark:bg-zinc-800", children: connector.kind }), _jsxs("span", { className: cn('font-mono text-[10px]', MUTED), children: ["\u2192 ", connector.targetType] }), connection && (_jsx(Tooltip, { content: `Reads through the ${connection.name} connection, which supplies the address and the credential. Moving that connection moves this connector with it.`, children: _jsxs("span", { className: cn('flex cursor-help items-center gap-1 font-mono text-[10px]', MUTED), children: [_jsx(Plug, { size: 10 }), connection.name] }) })), connector.mode === 'incremental' && (_jsx(Tooltip, { content: "Reads only what changed since the last run, and carries the rest forward.", children: _jsxs("span", { className: cn('flex cursor-help items-center gap-1 font-mono text-[10px]', MUTED), children: [_jsx(RefreshCw, { size: 10 }), "incremental"] }) })), !connector.enabled && (_jsx("span", { className: "rounded-sm bg-zinc-100 px-1.5 py-0.5 font-mono text-[10px] uppercase text-zinc-500 dark:bg-zinc-800", children: "disabled" }))] }), _jsx("div", { className: cn('mt-1 font-mono text-[11px]', MUTED), children: describeSource(connector, connection) }), connector.secretEnvVar && (_jsx(Tooltip, { content: "The catalog stores the NAME of this variable, never its value. A leaked catalog database gives away the shape of the integration, not the keys to it.", children: _jsxs("div", { className: cn('mt-1 flex w-fit cursor-help items-center gap-1 font-mono text-[10px]', MUTED), children: [_jsx(KeyRound, { size: 10 }), connector.secretEnvVar] }) }))] }), _jsxs("div", { className: "flex shrink-0 items-center gap-1", children: [_jsxs("button", { type: "button", onClick: onRun, disabled: running || !connector.enabled, className: "flex items-center gap-1.5 rounded-md bg-zinc-950 px-3 py-1.5 text-xs text-zinc-50 disabled:opacity-40 dark:bg-zinc-100 dark:text-zinc-950", children: [running ? _jsx(Loader2, { size: 12, className: "animate-spin" }) : _jsx(Play, { size: 12 }), running ? 'Running…' : 'Run now'] }), canEdit && (_jsx(Tooltip, { content: `Delete ${connector.name}`, children: _jsx("button", { type: "button", onClick: () => setConfirming(true), "aria-label": `Delete ${connector.name}`, className: cn('rounded-sm p-1.5 hover:text-red-600', MUTED), children: _jsx(Trash2, { size: 12 }) }) }))] })] }), transform && (_jsxs("button", { type: "button", onClick: onEdit, className: cn('mt-3 flex items-center gap-1.5 text-[11px]', MUTED, 'hover:text-sky-600'), children: [_jsx(Code2, { size: 11 }), transform.name, _jsxs("span", { className: "font-mono", children: [transform.language, " \u00B7 v", transform.version] })] })), _jsx(RecentRuns, { connectorId: connector.id, transform: transform }), _jsx(ConfirmDialog, { open: confirming, onOpenChange: setConfirming, title: `Delete ${connector.name}?`, description: "The snapshots it already wrote stay where they are \u2014 this removes the connector, its schedule and its incremental watermark. Recreating it later starts reading from the beginning again.", confirmLabel: remove.isPending ? 'Deleting…' : 'Delete', pending: remove.isPending, onConfirm: () => remove.mutate(), error: remove.error
|
|
207
204
|
? remove.error instanceof Error
|
|
208
205
|
? remove.error.message
|
|
209
206
|
: 'Could not delete it.'
|
|
210
207
|
: undefined })] }));
|
|
211
208
|
}
|
|
209
|
+
/**
|
|
210
|
+
* What this connector has done lately, and the way from a load to the code that
|
|
211
|
+
* produced it.
|
|
212
|
+
*
|
|
213
|
+
* Its own component rather than a block inside the card, because it owns state
|
|
214
|
+
* the card has no other use for — which version is being compared — and because
|
|
215
|
+
* the runs it reads are the card's only query that is not about the connector
|
|
216
|
+
* itself. Lifting it out is also what keeps `ConnectorCard` under the cognitive
|
|
217
|
+
* complexity the linter enforces, which is the linter noticing something real:
|
|
218
|
+
* a card that renders a source, a schedule, a credential, a transform, a run
|
|
219
|
+
* list AND a comparison panel is doing six things.
|
|
220
|
+
*/
|
|
221
|
+
function RecentRuns({ connectorId, transform, }) {
|
|
222
|
+
const client = useCatalogClient();
|
|
223
|
+
/**
|
|
224
|
+
* Which run's code is being compared, as the version number it recorded.
|
|
225
|
+
*
|
|
226
|
+
* This is where the question actually occurs to somebody: they are looking at
|
|
227
|
+
* a load that came out different from the last one, and the row in front of
|
|
228
|
+
* them already says `code v3`. Making that number the way in means nobody has
|
|
229
|
+
* to carry it to another screen and pick it out of a dropdown — which is the
|
|
230
|
+
* step where you pick the wrong one and conclude the code was fine.
|
|
231
|
+
*/
|
|
232
|
+
const [comparing, setComparing] = useState(null);
|
|
233
|
+
const { data: runs = [] } = useQuery({
|
|
234
|
+
queryKey: catalogQueryKeys.runs(connectorId),
|
|
235
|
+
queryFn: () => client.listRuns(connectorId),
|
|
236
|
+
});
|
|
237
|
+
if (runs.length === 0)
|
|
238
|
+
return null;
|
|
239
|
+
return (_jsxs(_Fragment, { children: [_jsxs("div", { className: cn('mt-3 border-t pt-3', RULE), children: [_jsx("div", { className: cn('mb-1.5 font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Recent runs" }), _jsx("div", { className: "space-y-1", children: runs.slice(0, 4).map((entry) => (_jsx(Tooltip, { content: entry.error ? (_jsx("span", { className: "font-mono text-[11px]", children: entry.error })) : (_jsx("span", { className: "font-mono text-[11px]", children: entry.logs.slice(-3).join('\n') || 'No logs.' })), children: _jsxs("div", { className: "flex cursor-help items-center gap-2 text-[11px]", children: [_jsxs("span", { className: "sr-only", children: [entry.status, ": "] }), _jsx(RunStatusIcon, { status: entry.status }), _jsx("span", { className: "font-mono", children: entry.snapshotId }), _jsxs("span", { className: MUTED, children: [entry.fetched, " fetched \u00B7 ", entry.written, " written"] }), _jsx(RanCodeVersion, { version: entry.transformVersion, comparable: transform !== undefined, onCompare: setComparing }), _jsx("span", { className: cn('ml-auto font-mono text-[10px]', MUTED), children: new Date(entry.startedAt).toLocaleTimeString() })] }) }, entry.id))) })] }), transform && (_jsx(RevisionHistorySheet, { open: comparing !== null, onOpenChange: (open) => {
|
|
240
|
+
if (!open)
|
|
241
|
+
setComparing(null);
|
|
242
|
+
}, subject: { kind: 'transform', id: transform.id, name: transform.name }, current: { version: transform.version, body: transform.code }, ranVersion: comparing ?? undefined }))] }));
|
|
243
|
+
}
|
|
244
|
+
function RunStatusIcon({ status }) {
|
|
245
|
+
if (status === 'succeeded')
|
|
246
|
+
return _jsx(CircleCheck, { size: 11, "aria-hidden": true, className: "text-emerald-600" });
|
|
247
|
+
if (status === 'failed')
|
|
248
|
+
return _jsx(CircleX, { size: 11, "aria-hidden": true, className: "text-red-600" });
|
|
249
|
+
return _jsx(Loader2, { size: 11, "aria-hidden": true, className: "animate-spin text-sky-600" });
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* `code v3` on a run, as a way into the comparison rather than as a fact.
|
|
253
|
+
*
|
|
254
|
+
* Where somebody is standing when the question occurs to them. The number was
|
|
255
|
+
* already on this row and already meant "this load ran that code"; what it did
|
|
256
|
+
* not have was anywhere to go, because until revisions existed the code it named
|
|
257
|
+
* had been overwritten. Making it the control means nobody carries a version
|
|
258
|
+
* number to another screen and picks it out of a dropdown — which is the step
|
|
259
|
+
* where you pick the wrong one and conclude the code was fine.
|
|
260
|
+
*
|
|
261
|
+
* Still only text when there is nothing on the other side: a connector with no
|
|
262
|
+
* transform never records a version, and a version whose transform has since
|
|
263
|
+
* been deleted has no current code to compare against. A control that opens an
|
|
264
|
+
* empty panel is a control that teaches people to stop pressing it.
|
|
265
|
+
*
|
|
266
|
+
* Its own component rather than three ternaries inside the run row, because the
|
|
267
|
+
* row is inside a `Tooltip` inside a `map` inside a card that is already at the
|
|
268
|
+
* complexity budget — and because "what does the version on a run do" is a
|
|
269
|
+
* question with one answer, which should be in one place.
|
|
270
|
+
*/
|
|
271
|
+
function RanCodeVersion({ version, comparable, onCompare, }) {
|
|
272
|
+
if (version === undefined)
|
|
273
|
+
return null;
|
|
274
|
+
if (!comparable)
|
|
275
|
+
return _jsxs("span", { className: cn('font-mono', MUTED), children: ["code v", version] });
|
|
276
|
+
return (
|
|
277
|
+
// Inside the tooltip's trigger rather than beside it, because this row IS
|
|
278
|
+
// the trigger: pulling the button out would put a gap in the hover target
|
|
279
|
+
// exactly where the pointer is heading. A click inside it bubbles normally.
|
|
280
|
+
_jsxs("button", { type: "button", onClick: () => onCompare(version), "aria-label": `Compare the code that ran (v${version}) with the current code`, className: cn('rounded-sm px-1 font-mono underline decoration-dotted underline-offset-2', MUTED, 'hover:text-sky-600'), children: ["code v", version] }));
|
|
281
|
+
}
|
|
212
282
|
/**
|
|
213
283
|
* The connection picker, above the address fields it replaces.
|
|
214
284
|
*
|
package/dist/SavedQueryPanel.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
3
|
-
import { Bookmark, Download, Timer, Trash2 } from 'lucide-react';
|
|
3
|
+
import { Bookmark, Download, History, Timer, Trash2 } from 'lucide-react';
|
|
4
4
|
import { useMemo, useState } from 'react';
|
|
5
5
|
import { registeredChartLibraries } from './charts/registry';
|
|
6
6
|
import { cn } from './cn';
|
|
7
7
|
import { useCatalogClient } from './context';
|
|
8
|
+
import { RevisionHistorySheet } from './diff/RevisionDiff';
|
|
8
9
|
import { ShareBadge, ShareControl } from './sharing';
|
|
9
10
|
import { Select } from './ui/select';
|
|
10
11
|
import { Tooltip } from './ui/tooltip';
|
|
@@ -47,6 +48,14 @@ export function SavedQueryPanel({ currentSql, openId, onLoad, }) {
|
|
|
47
48
|
const client = useCatalogClient();
|
|
48
49
|
const queryClient = useQueryClient();
|
|
49
50
|
const [saving, setSaving] = useState(false);
|
|
51
|
+
/**
|
|
52
|
+
* Which query's history is open, as the query itself rather than an id.
|
|
53
|
+
*
|
|
54
|
+
* The whole row, because the sheet is titled by name and a panel headed with
|
|
55
|
+
* an opaque id helps nobody. Looking the name back up from the id would be a
|
|
56
|
+
* second read of an array this component is already holding.
|
|
57
|
+
*/
|
|
58
|
+
const [history, setHistory] = useState(null);
|
|
50
59
|
const [draft, setDraft] = useState({
|
|
51
60
|
name: '',
|
|
52
61
|
sql: '',
|
|
@@ -115,5 +124,8 @@ export function SavedQueryPanel({ currentSql, openId, onLoad, }) {
|
|
|
115
124
|
? `Results reused for ${query.cacheTtlSeconds}s.`
|
|
116
125
|
: 'Never cached — runs every time.'), children: _jsxs("button", { type: "button", onClick: () => onLoad(query), "aria-current": query.id === openId ? 'true' : undefined, className: cn('min-w-0 flex-1 truncate rounded-md px-2 py-1 text-left text-[11px]', query.id === openId
|
|
117
126
|
? 'bg-sky-100 dark:bg-sky-950'
|
|
118
|
-
: 'hover:bg-zinc-50 dark:hover:bg-zinc-800'), children: [query.name, query.cacheTtlSeconds > 0 && (_jsxs("span", { className: cn('ml-1 font-mono text-[9px]', MUTED), children: [query.cacheTtlSeconds, "s"] }))] }) }), query.shared && _jsx(ShareBadge, { shared: true, className: "mr-1" }), _jsx(ShareControl, { layout: "row", kind: "query", shared: query.shared, pending: share.isPending, name: query.name, onChange: (shared) => share.mutate({ id: query.id, shared }), className: cn('opacity-0 group-hover:opacity-100 focus-visible:opacity-100', MUTED) }), _jsx(Tooltip, { content: "Download as CSV", children: _jsx("a", { href: client.exportUrl(query.id), className: cn('rounded-sm p-1 opacity-0 group-hover:opacity-100', MUTED), "aria-label": `Export ${query.name}`, children: _jsx(Download, { size: 11 }) }) }), _jsx("button", { type: "button", onClick: () => remove.mutate(query.id), className: cn('rounded-sm p-1 opacity-0 group-hover:opacity-100 hover:text-red-600', MUTED), "aria-label": `Delete ${query.name}`, children: _jsx(Trash2, { size: 11 }) })] }, query.id)))] }, folder))), share.error !== null && (_jsx("p", { className: "px-2 py-1 text-[11px] text-red-600", children: share.error instanceof Error ? share.error.message : 'Could not change sharing.' }))] })
|
|
127
|
+
: 'hover:bg-zinc-50 dark:hover:bg-zinc-800'), children: [query.name, query.cacheTtlSeconds > 0 && (_jsxs("span", { className: cn('ml-1 font-mono text-[9px]', MUTED), children: [query.cacheTtlSeconds, "s"] }))] }) }), query.shared && _jsx(ShareBadge, { shared: true, className: "mr-1" }), _jsx(ShareControl, { layout: "row", kind: "query", shared: query.shared, pending: share.isPending, name: query.name, onChange: (shared) => share.mutate({ id: query.id, shared }), className: cn('opacity-0 group-hover:opacity-100 focus-visible:opacity-100', MUTED) }), _jsx(Tooltip, { content: "Every SQL this query has been, and what changed between two of them", children: _jsx("button", { type: "button", onClick: () => setHistory(query), className: cn('rounded-sm p-1 opacity-0 group-hover:opacity-100 focus-visible:opacity-100', MUTED), "aria-label": `History of ${query.name}`, children: _jsx(History, { size: 11 }) }) }), _jsx(Tooltip, { content: "Download as CSV", children: _jsx("a", { href: client.exportUrl(query.id), className: cn('rounded-sm p-1 opacity-0 group-hover:opacity-100', MUTED), "aria-label": `Export ${query.name}`, children: _jsx(Download, { size: 11 }) }) }), _jsx("button", { type: "button", onClick: () => remove.mutate(query.id), className: cn('rounded-sm p-1 opacity-0 group-hover:opacity-100 hover:text-red-600', MUTED), "aria-label": `Delete ${query.name}`, children: _jsx(Trash2, { size: 11 }) })] }, query.id)))] }, folder))), share.error !== null && (_jsx("p", { className: "px-2 py-1 text-[11px] text-red-600", children: share.error instanceof Error ? share.error.message : 'Could not change sharing.' }))] }), history && (_jsx(RevisionHistorySheet, { open: true, onOpenChange: (open) => {
|
|
128
|
+
if (!open)
|
|
129
|
+
setHistory(null);
|
|
130
|
+
}, subject: { kind: 'saved-query', id: history.id, name: history.name } }))] }));
|
|
119
131
|
}
|