@dudousxd/nestjs-catalog-react 0.13.0 → 0.15.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.
@@ -245,9 +245,28 @@ function connectionIsIncomplete(kind, draft) {
245
245
  function HttpFields({ draft, update }) {
246
246
  return (_jsxs(_Fragment, { children: [_jsx(TextField, { label: "URL", value: draft.url, onChange: (url) => update({ url }), placeholder: "https://api.example.mil/v1", hint: "The base the connectors reading through this will hang their paths off." }), _jsx(TextField, { label: "Credential env var", value: draft.secretEnvVar, onChange: (secretEnvVar) => update({ secretEnvVar }), placeholder: "Optional \u2014 sent as a bearer token" })] }));
247
247
  }
248
- /** Either an inline URL or the variable holding one. */
248
+ /**
249
+ * The connection string, and nothing beside it.
250
+ *
251
+ * This was two fields — an inline URL and the name of an environment variable
252
+ * holding one — presented side by side with a paragraph explaining when each
253
+ * applied. Two doors for one decision, and only one of them worked for a
254
+ * database with a password, which is every database anybody connects to. The
255
+ * question it produced was "what is this second field", which is the form
256
+ * asking the reader to understand its implementation.
257
+ *
258
+ * One field now. Whether the URL may REST in the catalog's own table is the
259
+ * store's decision (`allowInlineCredentials`) and not something to ask on a
260
+ * form — and it is a decision about the deployment, not about this connection.
261
+ * The server refuses and says why if the answer is no, which is a better place
262
+ * to learn it than a hint nobody reads until afterwards.
263
+ *
264
+ * `secretEnvVar` still exists on the model and is still what a hardened
265
+ * deployment should use; it is not on this screen. A host that wants it back
266
+ * has the field on the record.
267
+ */
249
268
  function SqlFields({ draft, update }) {
250
- return (_jsx(FieldGroup, { title: "Address", hint: "Name the variable holding the connection URL \u2014 that is the whole credential for most databases, so the catalog stores its name and never its value. The inline URL is here for local work.", children: _jsxs("div", { className: "grid gap-3 sm:grid-cols-2", children: [_jsx(TextField, { label: "URL (optional)", value: draft.url, onChange: (url) => update({ url }), placeholder: "mysql://user:pass@host/db" }), _jsx(TextField, { label: "Env var holding the URL", value: draft.secretEnvVar, onChange: (secretEnvVar) => update({ secretEnvVar }), placeholder: "FLEET_DATABASE_URL" })] }) }));
269
+ return (_jsx(FieldGroup, { title: "Address", hint: "The connection string, as your database gives it to you. It is served back redacted, so the password never travels in a response \u2014 but it does rest in this catalog's own table, and a deployment can refuse that.", children: _jsx(TextField, { label: "Connection URL", value: draft.url, onChange: (url) => update({ url }), placeholder: "mysql://user:pass@host:3306/database" }) }));
251
270
  }
252
271
  /** A bucket, plus everything needed to address a non-AWS one. */
253
272
  function S3Fields({ draft, update }) {
@@ -6,9 +6,10 @@ 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
- import { CredentialField, INLINE_CONNECTION, KIND_OPTIONS, ReadModeFields, SourceFields, parseRecords, readsIncrementally, sourceConfigFrom, sourceDraftFrom, sourceIsIncomplete, toConnectorKind, usesConnection, } from './source-fields';
12
+ import { INLINE_CONNECTION, KIND_OPTIONS, ReadModeFields, SourceFields, parseRecords, readsIncrementally, sourceConfigFrom, sourceDraftFrom, sourceIsIncomplete, toConnectorKind, usesConnection, } from './source-fields';
12
13
  import { ConfirmDialog } from './ui/dialog';
13
14
  import { TextField } from './ui/field';
14
15
  import { SelectField } from './ui/select';
@@ -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] })] })), runs.length > 0 && (_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, ": "] }), entry.status === 'succeeded' ? (_jsx(CircleCheck, { size: 11, "aria-hidden": true, className: "text-emerald-600" })) : entry.status === 'failed' ? (_jsx(CircleX, { size: 11, "aria-hidden": true, className: "text-red-600" })) : (_jsx(Loader2, { size: 11, "aria-hidden": true, className: "animate-spin text-sky-600" })), _jsx("span", { className: "font-mono", children: entry.snapshotId }), _jsxs("span", { className: MUTED, children: [entry.fetched, " fetched \u00B7 ", entry.written, " written", entry.transformVersion ? ` · code v${entry.transformVersion}` : ''] }), _jsx("span", { className: cn('ml-auto font-mono text-[10px]', MUTED), children: new Date(entry.startedAt).toLocaleTimeString() })] }) }, entry.id))) })] })), _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
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
  *
@@ -486,18 +556,18 @@ function ConnectorForm({ connector, transforms, connections, schemaDiscovery, on
486
556
  return (_jsxs("form", { className: cn('mt-6 space-y-4 rounded-lg border p-4', RULE, PANEL), onSubmit: (event) => {
487
557
  event.preventDefault();
488
558
  save.mutate();
489
- }, children: [_jsxs("div", { className: "grid gap-3 sm:grid-cols-3", children: [_jsx(TextField, { label: "Name", value: draft.name, onChange: (name) => setDraft({ ...draft, name }), placeholder: "Nightly fleet load" }), _jsx(TextField, { label: "Target object type", value: draft.targetType, onChange: (targetType) => setDraft({ ...draft, targetType }), placeholder: "e.g. Mvr" }), _jsx(SelectField, { label: "Source kind", ariaLabel: "Source kind", value: kind, onValueChange: (value) => setKind(toConnectorKind(value)), options: KIND_OPTIONS })] }), usesConnection(kind) && (_jsx(ConnectionPicker, { value: chosenConnection, options: connectionOptions, viaConnection: viaConnection, onChange: setConnectionId })), schemaDiscovery && connector?.id && (_jsx(SchemaDiscoveryPanel, { connectorId: connector.id, bridge: schemaDiscovery })), _jsx(SourceFields, { kind: kind, draft: source, onChange: setSource, viaConnection: viaConnection }), _jsx(ReadModeFields, { kind: kind, mode: mode, onModeChange: setMode, draft: source, onChange: setSource }), _jsxs("div", { className: "grid gap-3 sm:grid-cols-2", children: [!viaConnection && (_jsx(CredentialField, { kind: kind, value: draft.secretEnvVar, onChange: (secretEnvVar) => setDraft({ ...draft, secretEnvVar }) })), _jsx(SelectField, { label: "Transform", ariaLabel: "Transform", value: draft.transformId, onValueChange: (transformId) => setDraft({ ...draft, transformId }), options: [
490
- {
491
- value: '',
492
- label: 'No transform',
493
- hint: 'Store records as they arrive',
494
- },
495
- ...transforms.map((transform) => ({
496
- value: transform.id,
497
- label: transform.name,
498
- hint: `${transform.language} · v${transform.version}`,
499
- })),
500
- ] })] }), _jsx(Switch, { checked: enabled, onCheckedChange: setEnabled, label: "Enabled", hint: "A disabled connector keeps its configuration and its watermark, and refuses to run." }), _jsx(ConnectorFormActions, { editing: connector !== undefined, pending: save.isPending, incomplete: incomplete, error: save.error, onClose: onClose })] }));
559
+ }, children: [_jsxs("div", { className: "grid gap-3 sm:grid-cols-3", children: [_jsx(TextField, { label: "Name", value: draft.name, onChange: (name) => setDraft({ ...draft, name }), placeholder: "Nightly fleet load" }), _jsx(TextField, { label: "Target object type", value: draft.targetType, onChange: (targetType) => setDraft({ ...draft, targetType }), placeholder: "e.g. Mvr" }), _jsx(SelectField, { label: "Source kind", ariaLabel: "Source kind", value: kind, onValueChange: (value) => setKind(toConnectorKind(value)), options: KIND_OPTIONS })] }), usesConnection(kind) && (_jsx(ConnectionPicker, { value: chosenConnection, options: connectionOptions, viaConnection: viaConnection, onChange: setConnectionId })), schemaDiscovery && connector?.id && (_jsx(SchemaDiscoveryPanel, { connectorId: connector.id, bridge: schemaDiscovery })), _jsx(SourceFields, { kind: kind, draft: source, onChange: setSource, viaConnection: viaConnection }), _jsx(ReadModeFields, { kind: kind, mode: mode, onModeChange: setMode, draft: source, onChange: setSource }), _jsx("div", { className: "grid gap-3 sm:grid-cols-2", children: _jsx(SelectField, { label: "Transform", ariaLabel: "Transform", value: draft.transformId, onValueChange: (transformId) => setDraft({ ...draft, transformId }), options: [
560
+ {
561
+ value: '',
562
+ label: 'No transform',
563
+ hint: 'Store records as they arrive',
564
+ },
565
+ ...transforms.map((transform) => ({
566
+ value: transform.id,
567
+ label: transform.name,
568
+ hint: `${transform.language} · v${transform.version}`,
569
+ })),
570
+ ] }) }), _jsx(Switch, { checked: enabled, onCheckedChange: setEnabled, label: "Enabled", hint: "A disabled connector keeps its configuration and its watermark, and refuses to run." }), _jsx(ConnectorFormActions, { editing: connector !== undefined, pending: save.isPending, incomplete: incomplete, error: save.error, onClose: onClose })] }));
501
571
  }
502
572
  function TransformList({ canEdit, languages, pythonPackages, }) {
503
573
  const client = useCatalogClient();
@@ -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
  }
@@ -5,6 +5,7 @@ import { ArrowLeft, Play } from 'lucide-react';
5
5
  import { useRef, useState } from 'react';
6
6
  import { cn } from './cn';
7
7
  import { useCatalogClient } from './context';
8
+ import { RevisionHistoryButton, RevisionHistorySheet } from './diff/RevisionDiff';
8
9
  import { CodeEditor } from './ui/code-editor';
9
10
  import { TextField } from './ui/field';
10
11
  import { SelectField } from './ui/select';
@@ -89,6 +90,7 @@ export function TransformEditor({ transform, languages, pythonPackages = [], onC
89
90
  const [language, setLanguage] = useState(transform?.language ?? languages[0] ?? 'javascript');
90
91
  const [code, setCode] = useState(transform?.code ?? STARTERS[transform?.language ?? 'javascript']);
91
92
  const [sample, setSample] = useState(SAMPLE);
93
+ const [historyOpen, setHistoryOpen] = useState(false);
92
94
  const editorRef = useRef(null);
93
95
  const tryIt = useMutation({
94
96
  mutationFn: () => {
@@ -138,5 +140,10 @@ export function TransformEditor({ transform, languages, pythonPackages = [], onC
138
140
  label: option,
139
141
  })) })] }), _jsxs("div", { className: "grid gap-3 lg:grid-cols-2", children: [_jsxs("div", { className: cn('overflow-hidden rounded-lg border', RULE, PANEL), children: [_jsxs("div", { className: cn('flex items-center justify-between border-b px-3 py-1.5', RULE), children: [_jsx("span", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Code" }), _jsx("span", { className: cn('font-mono text-[10px]', MUTED), children: language === 'python' && pythonPackages.length > 0
140
142
  ? `imports: ${pythonPackages.join(', ')}`
141
- : '⌘↵ to try' })] }), _jsx(CodeEditor, { value: code, onChange: setCode, onKeyDown: onKeyDown, language: language === 'python' ? 'python' : 'tsx', label: "Transform code", textareaRef: editorRef, className: "h-72" })] }), _jsxs("div", { className: "space-y-3", children: [_jsxs("div", { className: cn('overflow-hidden rounded-lg border', RULE, PANEL), children: [_jsx("div", { className: cn('border-b px-3 py-1.5', RULE), children: _jsx("span", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Sample records" }) }), _jsx(CodeEditor, { value: sample, onChange: setSample, language: "json", label: "Sample records", className: "h-32" })] }), _jsxs("button", { type: "button", onClick: () => tryIt.mutate(), disabled: tryIt.isPending, 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: [_jsx(Play, { size: 12 }), tryIt.isPending ? 'Running…' : 'Try it'] }), _jsxs("div", { className: cn('overflow-hidden rounded-lg border', RULE, PANEL), children: [_jsx("div", { className: cn('border-b px-3 py-1.5', RULE), children: _jsx("span", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Output" }) }), _jsx(TryOutput, { result: tryIt.data, error: tryIt.error })] })] })] }), _jsx(SaveBar, { transform: transform, nameIsEmpty: name.trim().length === 0, pending: save.isPending, error: save.error, onSave: () => save.mutate() })] }));
143
+ : '⌘↵ to try' })] }), _jsx(CodeEditor, { value: code, onChange: setCode, onKeyDown: onKeyDown, language: language === 'python' ? 'python' : 'tsx', label: "Transform code", textareaRef: editorRef, className: "h-72" })] }), _jsxs("div", { className: "space-y-3", children: [_jsxs("div", { className: cn('overflow-hidden rounded-lg border', RULE, PANEL), children: [_jsx("div", { className: cn('border-b px-3 py-1.5', RULE), children: _jsx("span", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Sample records" }) }), _jsx(CodeEditor, { value: sample, onChange: setSample, language: "json", label: "Sample records", className: "h-32" })] }), _jsxs("button", { type: "button", onClick: () => tryIt.mutate(), disabled: tryIt.isPending, 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: [_jsx(Play, { size: 12 }), tryIt.isPending ? 'Running…' : 'Try it'] }), _jsxs("div", { className: cn('overflow-hidden rounded-lg border', RULE, PANEL), children: [_jsx("div", { className: cn('border-b px-3 py-1.5', RULE), children: _jsx("span", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Output" }) }), _jsx(TryOutput, { result: tryIt.data, error: tryIt.error })] })] })] }), _jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx(SaveBar, { transform: transform, nameIsEmpty: name.trim().length === 0, pending: save.isPending, error: save.error, onSave: () => save.mutate() }), transform && (_jsx(RevisionHistoryButton, { className: "ml-auto", onClick: () => setHistoryOpen(true) }))] }), transform && (_jsx(RevisionHistorySheet, { open: historyOpen, onOpenChange: setHistoryOpen, subject: { kind: 'transform', id: transform.id, name: transform.name },
144
+ // The SAVED code, not what is in the editor above. A history is what
145
+ // this catalog has recorded; comparing against an unsaved buffer would
146
+ // put a version number on text that exists only in one browser tab,
147
+ // and no run will ever have used it.
148
+ current: { version: transform.version, body: transform.code } }))] }));
142
149
  }