@dudousxd/nestjs-catalog-react 0.4.0 → 0.7.1

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.
@@ -1,4 +1,4 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
3
3
  import { ArrowUpRight, Eye, EyeOff, RotateCcw, Search } from 'lucide-react';
4
4
  import { useMemo, useState } from 'react';
@@ -6,6 +6,8 @@ import { CoverageLedger } from './CoverageLedger';
6
6
  import { EditableField } from './EditableField';
7
7
  import { cn } from './cn';
8
8
  import { catalogQueryKeys, useCatalogClient } from './context';
9
+ import { DataTable } from './ui/data-table';
10
+ import { RichTextField } from './ui/rich-text-field';
9
11
  import { Tooltip, TooltipProvider } from './ui/tooltip';
10
12
  /**
11
13
  * Browse and label the model.
@@ -106,18 +108,93 @@ function Stat({ label, value }) {
106
108
  }
107
109
  function TypeDetail({ type, explorerHref, onPatchType, onPatchProperty, onNavigate, }) {
108
110
  const visible = type.properties.filter((p) => !p.hidden).length;
109
- 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(EditableField, { label: "description", multiline: true, 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), inputClassName: "text-sm leading-relaxed" }) }), _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: _jsxs("table", { className: "w-full text-sm", children: [_jsx("thead", { children: _jsxs("tr", { className: cn('border-b bg-zinc-50 text-left dark:bg-zinc-950', RULE), children: [_jsx(Th, { className: "w-[30%]", children: "Label" }), _jsx(Th, { className: "w-[22%]", children: "Column" }), _jsx(Th, { className: "w-[10%]", children: "Type" }), _jsx(Th, { className: "w-[12%]", children: "Unit" }), _jsx(Th, { className: "w-[20%]", children: "Meaning" }), _jsx(Th, { className: "w-[6%] text-right", children: "Shown" })] }) }), _jsx("tbody", { children: type.properties.map((property) => (_jsxs("tr", { className: cn('border-b last:border-0', HAIRLINE, property.hidden && 'opacity-45'), children: [_jsxs("td", { className: "px-3 py-2 align-top", children: [_jsx(EditableField, { label: `label for ${property.name}`, value: property.displayName, onSave: (displayName) => onPatchProperty(property.name, { displayName }), inputClassName: "text-sm" }), _jsxs("div", { className: cn('px-1.5 font-mono text-[10px]', MUTED), children: [property.name, property.primary && (_jsx(Tooltip, { content: "Primary key. Always fetched, even when hidden, so a row keeps a stable identity.", children: _jsx("span", { className: "ml-1.5 cursor-help text-sky-600 dark:text-sky-400", children: "pk" }) })), !property.nullable && !property.primary && (_jsx(Tooltip, { content: "NOT NULL in the database. Read from the ORM, not something this screen can change.", children: _jsx("span", { className: "ml-1.5 cursor-help text-amber-600", children: "required" }) }))] })] }), _jsx("td", { className: cn('px-3 py-2 align-top font-mono text-[11px]', SECONDARY), children: property.columnName }), _jsx("td", { className: "px-3 py-2 align-top", children: _jsx(ScalarBadge, { type: property.type }) }), _jsx("td", { className: "px-3 py-2 align-top", children: _jsx(EditableField, { label: `unit for ${property.name}`, value: property.unit ?? '', placeholder: "\u2014", onSave: (unit) => onPatchProperty(property.name, { unit }), inputClassName: "text-xs", className: "text-xs" }) }), _jsx("td", { className: "px-3 py-2 align-top", children: _jsx(EditableField, { label: `description for ${property.name}`, multiline: true, value: property.description ?? '', placeholder: "\u2014", onSave: (description) => onPatchProperty(property.name, { description }), className: cn('text-xs leading-snug', SECONDARY), inputClassName: "text-xs leading-snug" }) }), _jsx("td", { className: "px-3 py-2 text-right align-top", children: _jsx(Tooltip, { content: property.hidden
110
- ? `Hidden from tables and search. ${property.displayName} is still stored — showing it again needs no migration.`
111
- : `Shown in tables and search. Hiding it only changes what is displayed; the column is untouched.`, children: _jsx("button", { type: "button", "aria-label": `${property.hidden ? 'Show' : 'Hide'} ${property.displayName}`, onClick: () => onPatchProperty(property.name, {
112
- hidden: !property.hidden,
113
- }), className: cn('rounded-sm p-1 hover:bg-zinc-100 dark:hover:bg-zinc-800', MUTED), children: property.hidden ? _jsx(EyeOff, { size: 14 }) : _jsx(Eye, { size: 14 }) }) }) })] }, property.name))) })] }) })] }), _jsxs("section", { className: "mt-10 pb-16", children: [_jsx(SectionHeading, { title: "Links", note: "Read from the foreign keys." }), type.relations.length === 0 ? (_jsxs("p", { className: cn('rounded-lg border border-dashed px-4 py-6 text-center text-sm', RULE, MUTED), children: ["Nothing links to or from ", type.displayName, " yet."] })) : (_jsx("div", { className: "flex flex-wrap gap-2", children: type.relations.map((relation) => (_jsxs("button", { type: "button", onClick: () => onNavigate(relation.targetType), className: cn('group flex items-center gap-2 rounded-md border px-3 py-2 text-left transition-colors', RULE, PANEL, 'hover:border-sky-500 hover:bg-sky-100 dark:hover:bg-sky-950'), children: [_jsx("span", { className: cn('font-mono text-[10px] uppercase tracking-wider', MUTED), children: relation.kind }), _jsx("span", { className: "text-sm", children: relation.displayName }), _jsxs("span", { className: cn('font-mono text-[10px]', MUTED), children: ["\u2192 ", relation.targetType] })] }, relation.name))) }))] })] }));
111
+ 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 }) })] }), _jsxs("section", { className: "mt-10 pb-16", children: [_jsx(SectionHeading, { title: "Links", note: "Read from the foreign keys." }), type.relations.length === 0 ? (_jsxs("p", { className: cn('rounded-lg border border-dashed px-4 py-6 text-center text-sm', RULE, MUTED), children: ["Nothing links to or from ", type.displayName, " yet."] })) : (_jsx("div", { className: "flex flex-wrap gap-2", children: type.relations.map((relation) => (_jsxs("button", { type: "button", onClick: () => onNavigate(relation.targetType), className: cn('group flex items-center gap-2 rounded-md border px-3 py-2 text-left transition-colors', RULE, PANEL, 'hover:border-sky-500 hover:bg-sky-100 dark:hover:bg-sky-950'), children: [_jsx("span", { className: cn('font-mono text-[10px] uppercase tracking-wider', MUTED), children: relation.kind }), _jsx("span", { className: "text-sm", children: relation.displayName }), _jsxs("span", { className: cn('font-mono text-[10px]', MUTED), children: ["\u2192 ", relation.targetType] })] }, relation.name))) }))] })] }));
114
112
  }
115
113
  function SectionHeading({ title, note }) {
116
114
  return (_jsxs("div", { className: "mb-3", children: [_jsx("h2", { className: cn('font-mono text-[11px] uppercase tracking-[0.16em]', MUTED), children: title }), _jsx("p", { className: cn('mt-1 text-xs', MUTED), children: note })] }));
117
115
  }
118
- function Th({ children, className, }) {
119
- return (_jsx("th", { className: cn('px-3 py-2 font-mono text-[10px] font-normal uppercase tracking-[0.12em]', MUTED, className), children: children }));
120
- }
121
116
  function FieldChip({ label, value, onSave, }) {
122
117
  return (_jsxs("div", { className: cn('flex items-center gap-1.5 rounded-md border px-2 py-1', RULE, PANEL), children: [_jsx("span", { className: cn('font-mono text-[10px] uppercase tracking-wider', MUTED), children: label }), _jsx(EditableField, { label: label, value: value, placeholder: "\u2014", onSave: onSave, className: "text-xs", inputClassName: "text-xs" })] }));
123
118
  }
119
+ /**
120
+ * The properties of one type, as a table.
121
+ *
122
+ * Every cell is an editor or a badge, so what TanStack contributes here is not
123
+ * cell rendering but the column model: six columns declared once, with their
124
+ * widths beside their contents instead of in a separate header row that has to
125
+ * be kept in the same order by hand.
126
+ *
127
+ * The widths are fixed rather than content-sized, and that is the point of
128
+ * declaring them at all: these cells contain inputs, and a column that sizes to
129
+ * its content reflows the whole table on every keystroke.
130
+ */
131
+ function PropertyTable({ properties, onPatchProperty, }) {
132
+ const columns = useMemo(() => [
133
+ {
134
+ id: 'label',
135
+ header: 'Label',
136
+ accessorFn: (p) => p.displayName,
137
+ cell: ({ row }) => (_jsx(PropertyLabelCell, { property: row.original, onPatchProperty: onPatchProperty })),
138
+ },
139
+ {
140
+ id: 'column',
141
+ header: 'Column',
142
+ accessorFn: (p) => p.columnName,
143
+ cell: ({ row }) => (_jsx("span", { className: cn('font-mono text-[11px]', SECONDARY), children: row.original.columnName })),
144
+ },
145
+ {
146
+ id: 'type',
147
+ header: 'Type',
148
+ accessorFn: (p) => p.type,
149
+ cell: ({ row }) => (_jsx(ScalarBadge, { type: row.original.type })),
150
+ },
151
+ {
152
+ id: 'unit',
153
+ header: 'Unit',
154
+ accessorFn: (p) => p.unit ?? '',
155
+ cell: ({ row }) => (_jsx(EditableField, { label: `unit for ${row.original.name}`, value: row.original.unit ?? '', placeholder: "\u2014", onSave: (unit) => onPatchProperty(row.original.name, { unit }), inputClassName: "text-xs", className: "text-xs" })),
156
+ },
157
+ {
158
+ id: 'meaning',
159
+ header: 'Meaning',
160
+ accessorFn: (p) => p.description ?? '',
161
+ cell: ({ row }) => (_jsx(RichTextField, { label: `description for ${row.original.name}`, value: row.original.description ?? '', placeholder: "\u2014", onSave: (description) => onPatchProperty(row.original.name, { description }), className: cn('text-xs leading-snug', SECONDARY) })),
162
+ },
163
+ {
164
+ id: 'shown',
165
+ header: 'Shown',
166
+ accessorFn: (p) => !p.hidden,
167
+ cell: ({ row }) => (_jsx(VisibilityToggle, { property: row.original, onPatchProperty: onPatchProperty })),
168
+ },
169
+ ], [onPatchProperty]);
170
+ return (_jsx(DataTable, { data: properties, columns: columns, getRowId: (property) => property.name,
171
+ // Dimmed rather than dropped: a hidden property is still stored, and a
172
+ // screen that simply omitted it could not tell you that showing it again
173
+ // needs no migration.
174
+ rowClassName: (property) => (property.hidden ? 'opacity-45' : undefined), columnClassName: (id) => PROPERTY_WIDTHS[id],
175
+ // `align-top`, because two of these cells hold a multi-line editor and a
176
+ // row centred on the tallest one leaves the single-line cells floating.
177
+ cellClassName: () => 'align-top whitespace-normal py-2' }));
178
+ }
179
+ const PROPERTY_WIDTHS = {
180
+ label: 'w-[30%]',
181
+ column: 'w-[22%]',
182
+ type: 'w-[10%]',
183
+ unit: 'w-[12%]',
184
+ meaning: 'w-[20%]',
185
+ shown: 'w-[6%] text-right',
186
+ };
187
+ /** The label cell: the curated name, with the physical name and its constraints beneath. */
188
+ function PropertyLabelCell({ property, onPatchProperty, }) {
189
+ return (_jsxs(_Fragment, { children: [_jsx(EditableField, { label: `label for ${property.name}`, value: property.displayName, onSave: (displayName) => onPatchProperty(property.name, { displayName }), inputClassName: "text-sm" }), _jsxs("div", { className: cn('px-1.5 font-mono text-[10px]', MUTED), children: [property.name, property.primary && (_jsx(Tooltip, { content: "Primary key. Always fetched, even when hidden, so a row keeps a stable identity.", children: _jsx("span", { className: "ml-1.5 cursor-help text-sky-600 dark:text-sky-400", children: "pk" }) })), !property.nullable && !property.primary && (_jsx(Tooltip, { content: "NOT NULL in the database. Read from the ORM, not something this screen can change.", children: _jsx("span", { className: "ml-1.5 cursor-help text-amber-600", children: "required" }) }))] })] }));
190
+ }
191
+ /**
192
+ * Hiding is presentation, not schema — the tooltip says so on both sides,
193
+ * because "hidden" next to a database column reads as destructive until
194
+ * somebody tells you it is not.
195
+ */
196
+ function VisibilityToggle({ property, onPatchProperty, }) {
197
+ return (_jsx(Tooltip, { content: property.hidden
198
+ ? `Hidden from tables and search. ${property.displayName} is still stored — showing it again needs no migration.`
199
+ : 'Shown in tables and search. Hiding it only changes what is displayed; the column is untouched.', children: _jsx("button", { type: "button", "aria-label": `${property.hidden ? 'Show' : 'Hide'} ${property.displayName}`, onClick: () => onPatchProperty(property.name, { hidden: !property.hidden }), className: cn('rounded-sm p-1 hover:bg-zinc-100 dark:hover:bg-zinc-800', MUTED), children: property.hidden ? _jsx(EyeOff, { size: 14 }) : _jsx(Eye, { size: 14 }) }) }));
200
+ }
@@ -100,6 +100,73 @@ export function ConnectionPanel({ canEdit = true }) {
100
100
  }
101
101
  return (_jsxs("div", { className: "mt-6 space-y-3", children: [canEdit && (_jsxs("button", { type: "button", onClick: () => setEditing('new'), className: cn('flex items-center gap-1.5 rounded-md border px-3 py-1.5 text-xs', RULE, 'hover:bg-zinc-50 dark:hover:bg-zinc-800'), children: [_jsx(Plus, { size: 12 }), "New connection"] })), isPending && (_jsx("p", { className: cn('rounded-lg border border-dashed px-4 py-12 text-center text-sm', RULE, MUTED), children: "Reading connections\u2026" })), isError && (_jsx("p", { className: "rounded-lg border border-red-200 bg-red-50 px-4 py-8 text-center text-sm text-red-700 dark:border-red-900 dark:bg-red-950/40 dark:text-red-300", children: "Could not read the connections. This is not the same as having none \u2014 nothing here is safe to act on until it loads." })), !isPending && !isError && connections.length === 0 && (_jsx("p", { className: cn('rounded-lg border border-dashed px-4 py-12 text-center text-sm', RULE, MUTED), children: "No connections yet. A connector can still carry its own address \u2014 a connection is worth making when more than one of them shares it." })), connections.map((connection) => (_jsx(ConnectionCard, { connection: connection, users: connectors.filter((c) => c.connectionId === connection.id), canEdit: canEdit, onEdit: () => setEditing(connection), onChanged: invalidate }, connection.id)))] }));
102
102
  }
103
+ /**
104
+ * Who this connection is: name, kind, who reads through it, what it addresses.
105
+ *
106
+ * The credential line names the variable and never its value — that is the
107
+ * property worth showing, so it is shown rather than described in a doc.
108
+ */
109
+ function ConnectionIdentity({ connection, users, }) {
110
+ return (_jsxs("div", { className: "min-w-0", children: [_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx(Plug, { size: 13, className: MUTED }), _jsx("span", { className: "text-sm font-medium", children: connection.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: connection.kind }), users.length > 0 && (_jsx(Tooltip, { content: `Read through by ${users.map((c) => c.name).join(', ')}. Moving this address moves all of them at once, which is the point.`, children: _jsxs("span", { className: cn('flex cursor-help items-center gap-1 font-mono text-[10px]', MUTED), children: [_jsx(Waypoints, { size: 10 }), users.length] }) }))] }), _jsx("div", { className: cn('mt-1 font-mono text-[11px]', MUTED), children: describeConnection(connection) }), connection.description && (_jsx("p", { className: cn('mt-1 text-[11px]', MUTED), children: connection.description })), connection.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 }), connection.secretEnvVar] }) }))] }));
111
+ }
112
+ /**
113
+ * What the last check found, from the stored fields.
114
+ *
115
+ * Recorded rather than probed on every page load, because a list that reaches
116
+ * every system it names on render turns opening a tab into a burst of outbound
117
+ * connections.
118
+ */
119
+ function StoredCheckSummary({ connection }) {
120
+ if (!connection.lastCheckedAt)
121
+ return null;
122
+ return (_jsxs("div", { className: cn('mt-3 flex items-center gap-2 border-t pt-3 text-[11px]', RULE), children: [connection.lastCheckOk ? (_jsx(CircleCheck, { size: 12, "aria-hidden": true, className: "text-emerald-600" })) : (_jsx(CircleX, { size: 12, "aria-hidden": true, className: "text-red-600" })), _jsx("span", { className: "sr-only", children: connection.lastCheckOk ? 'Reachable: ' : 'Unreachable: ' }), _jsx("span", { className: MUTED, children: connection.lastCheckOk ? 'Reached' : (connection.lastCheckError ?? 'Could not reach it') }), _jsx("span", { className: cn('ml-auto font-mono text-[10px]', MUTED), children: new Date(connection.lastCheckedAt).toLocaleString() })] }));
123
+ }
124
+ /**
125
+ * What a check that just ran found, in the checker's own words.
126
+ *
127
+ * A server version, a bucket and whether anything is under the prefix, an HTTP
128
+ * status. That sentence is the whole product of the button; "OK" would prove
129
+ * only that something is listening on a port.
130
+ */
131
+ function LiveCheckResult({ result }) {
132
+ return (_jsx("div", { className: cn('mt-3 rounded-md border px-3 py-2 text-[11px]', result.ok
133
+ ? 'border-emerald-200 bg-emerald-50 text-emerald-800 dark:border-emerald-900 dark:bg-emerald-950/40 dark:text-emerald-300'
134
+ : 'border-red-200 bg-red-50 text-red-700 dark:border-red-900 dark:bg-red-950/40 dark:text-red-300'), children: _jsxs("div", { className: "flex items-start gap-2", children: [result.ok ? (_jsx(CircleCheck, { size: 13, "aria-hidden": true, className: "mt-px shrink-0" })) : (_jsx(CircleX, { size: 13, "aria-hidden": true, className: "mt-px shrink-0" })), _jsxs("div", { className: "min-w-0", children: [_jsx("div", { className: "font-medium", children: result.ok ? 'Reached it.' : 'Could not reach it.' }), _jsx("div", { className: "mt-0.5 font-mono leading-relaxed", children: result.detail }), result.error && (_jsx("div", { className: "mt-1 font-mono leading-relaxed opacity-80", children: result.error })), _jsxs("div", { className: "mt-1 font-mono text-[10px] opacity-70", children: [result.elapsedMs, " ms"] })] })] }) }));
135
+ }
136
+ /**
137
+ * Why a delete would be refused, said before it is attempted.
138
+ *
139
+ * `blockedBy` is the server's own answer to "who still reads through this",
140
+ * asked after it refused; it outranks `remove.error`, which is only the generic
141
+ * failure that came with it.
142
+ */
143
+ function deleteRefusalMessage(blockedBy, error) {
144
+ if (blockedBy && blockedBy.length > 0) {
145
+ return (_jsxs(_Fragment, { children: ["Refused: still read through by ", blockedBy.map((c) => c.name).join(', '), ". Point", ' ', blockedBy.length === 1 ? 'it' : 'them', " elsewhere first."] }));
146
+ }
147
+ if (error && !blockedBy) {
148
+ return error instanceof Error ? error.message : 'Could not delete it.';
149
+ }
150
+ return undefined;
151
+ }
152
+ /**
153
+ * The buttons on a card: test it, and — with write access — edit or delete it.
154
+ *
155
+ * The delete tooltip says up front that a connection with readers will be
156
+ * refused, so the refusal is not the first time somebody hears about it.
157
+ */
158
+ function ConnectionCardActions({ connection, users, canEdit, testing, onTest, onEdit, onAskDelete, }) {
159
+ return (_jsxs("div", { className: "flex shrink-0 items-center gap-1", children: [_jsxs("button", { type: "button", onClick: onTest, disabled: testing, className: cn('flex items-center gap-1.5 rounded-md border px-3 py-1.5 text-xs disabled:opacity-40', RULE, 'hover:bg-zinc-50 dark:hover:bg-zinc-800'), children: [testing ? _jsx(Loader2, { size: 12, className: "animate-spin" }) : _jsx(Plug, { size: 12 }), testing ? 'Reaching…' : 'Test connection'] }), canEdit && (_jsxs(_Fragment, { children: [_jsx(Tooltip, { content: `Edit ${connection.name}`, children: _jsx("button", { type: "button", onClick: onEdit, "aria-label": `Edit ${connection.name}`, className: cn('rounded-sm p-1.5 hover:text-sky-600', MUTED), children: _jsx(Pencil, { size: 12 }) }) }), _jsx(Tooltip, { content: users.length > 0
160
+ ? `${users.length} connector${users.length === 1 ? '' : 's'} read through this. Deleting it is refused while that is true.`
161
+ : `Delete ${connection.name}`, children: _jsx("button", { type: "button", onClick: onAskDelete, "aria-label": `Delete ${connection.name}`, className: cn('rounded-sm p-1.5 hover:text-red-600', MUTED), children: _jsx(Trash2, { size: 12 }) }) })] }))] }));
162
+ }
163
+ /** What deleting would actually cost, named readers and all, before it is tried. */
164
+ function deleteConsequence(users) {
165
+ if (users.length === 0) {
166
+ return 'Nothing reads through it. The connectors that used to are unaffected; only this address and the name of its credential variable go.';
167
+ }
168
+ return (_jsxs(_Fragment, { children: [users.length, " connector", users.length === 1 ? '' : 's', " read through this connection \u2014", ' ', users.map((c) => c.name).join(', '), ". Deleting it would leave", ' ', users.length === 1 ? 'it' : 'them', " without an address, and that is discovered on the next scheduled run rather than now. The server refuses while this is true."] }));
169
+ }
103
170
  function ConnectionCard({ connection, users, canEdit, onEdit, onChanged, }) {
104
171
  const client = useCatalogClient();
105
172
  const [confirming, setConfirming] = useState(false);
@@ -130,21 +197,69 @@ function ConnectionCard({ connection, users, canEdit, onEdit, onChanged, }) {
130
197
  },
131
198
  });
132
199
  const result = check.data;
133
- 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(Plug, { size: 13, className: MUTED }), _jsx("span", { className: "text-sm font-medium", children: connection.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: connection.kind }), users.length > 0 && (_jsx(Tooltip, { content: `Read through by ${users.map((c) => c.name).join(', ')}. Moving this address moves all of them at once, which is the point.`, children: _jsxs("span", { className: cn('flex cursor-help items-center gap-1 font-mono text-[10px]', MUTED), children: [_jsx(Waypoints, { size: 10 }), users.length] }) }))] }), _jsx("div", { className: cn('mt-1 font-mono text-[11px]', MUTED), children: describeConnection(connection) }), connection.description && (_jsx("p", { className: cn('mt-1 text-[11px]', MUTED), children: connection.description })), connection.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 }), connection.secretEnvVar] }) }))] }), _jsxs("div", { className: "flex shrink-0 items-center gap-1", children: [_jsxs("button", { type: "button", onClick: () => check.mutate(), disabled: check.isPending, className: cn('flex items-center gap-1.5 rounded-md border px-3 py-1.5 text-xs disabled:opacity-40', RULE, 'hover:bg-zinc-50 dark:hover:bg-zinc-800'), children: [check.isPending ? _jsx(Loader2, { size: 12, className: "animate-spin" }) : _jsx(Plug, { size: 12 }), check.isPending ? 'Reaching…' : 'Test connection'] }), canEdit && (_jsxs(_Fragment, { children: [_jsx(Tooltip, { content: `Edit ${connection.name}`, children: _jsx("button", { type: "button", onClick: onEdit, "aria-label": `Edit ${connection.name}`, className: cn('rounded-sm p-1.5 hover:text-sky-600', MUTED), children: _jsx(Pencil, { size: 12 }) }) }), _jsx(Tooltip, { content: users.length > 0
134
- ? `${users.length} connector${users.length === 1 ? '' : 's'} read through this. Deleting it is refused while that is true.`
135
- : `Delete ${connection.name}`, children: _jsx("button", { type: "button", onClick: () => {
136
- setBlockedBy(null);
137
- remove.reset();
138
- setConfirming(true);
139
- }, "aria-label": `Delete ${connection.name}`, className: cn('rounded-sm p-1.5 hover:text-red-600', MUTED), children: _jsx(Trash2, { size: 12 }) }) })] }))] })] }), !result && connection.lastCheckedAt && (_jsxs("div", { className: cn('mt-3 flex items-center gap-2 border-t pt-3 text-[11px]', RULE), children: [connection.lastCheckOk ? (_jsx(CircleCheck, { size: 12, "aria-hidden": true, className: "text-emerald-600" })) : (_jsx(CircleX, { size: 12, "aria-hidden": true, className: "text-red-600" })), _jsx("span", { className: "sr-only", children: connection.lastCheckOk ? 'Reachable: ' : 'Unreachable: ' }), _jsx("span", { className: MUTED, children: connection.lastCheckOk
140
- ? 'Reached'
141
- : (connection.lastCheckError ?? 'Could not reach it') }), _jsx("span", { className: cn('ml-auto font-mono text-[10px]', MUTED), children: new Date(connection.lastCheckedAt).toLocaleString() })] })), result && (_jsx("div", { className: cn('mt-3 rounded-md border px-3 py-2 text-[11px]', result.ok
142
- ? 'border-emerald-200 bg-emerald-50 text-emerald-800 dark:border-emerald-900 dark:bg-emerald-950/40 dark:text-emerald-300'
143
- : 'border-red-200 bg-red-50 text-red-700 dark:border-red-900 dark:bg-red-950/40 dark:text-red-300'), children: _jsxs("div", { className: "flex items-start gap-2", children: [result.ok ? (_jsx(CircleCheck, { size: 13, "aria-hidden": true, className: "mt-px shrink-0" })) : (_jsx(CircleX, { size: 13, "aria-hidden": true, className: "mt-px shrink-0" })), _jsxs("div", { className: "min-w-0", children: [_jsx("div", { className: "font-medium", children: result.ok ? 'Reached it.' : 'Could not reach it.' }), _jsx("div", { className: "mt-0.5 font-mono leading-relaxed", children: result.detail }), result.error && (_jsx("div", { className: "mt-1 font-mono leading-relaxed opacity-80", children: result.error })), _jsxs("div", { className: "mt-1 font-mono text-[10px] opacity-70", children: [result.elapsedMs, " ms"] })] })] }) })), check.error && !result && (_jsx("p", { className: "mt-3 text-[11px] text-red-600", children: check.error instanceof Error ? check.error.message : 'The check itself failed.' })), _jsx(ConfirmDialog, { open: confirming, onOpenChange: (open) => {
200
+ 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: [_jsx(ConnectionIdentity, { connection: connection, users: users }), _jsx(ConnectionCardActions, { connection: connection, users: users, canEdit: canEdit, testing: check.isPending, onTest: () => check.mutate(), onEdit: onEdit, onAskDelete: () => {
201
+ setBlockedBy(null);
202
+ remove.reset();
203
+ setConfirming(true);
204
+ } })] }), !result && _jsx(StoredCheckSummary, { connection: connection }), result && _jsx(LiveCheckResult, { result: result }), check.error && !result && (_jsx("p", { className: "mt-3 text-[11px] text-red-600", children: check.error instanceof Error ? check.error.message : 'The check itself failed.' })), _jsx(ConfirmDialog, { open: confirming, onOpenChange: (open) => {
144
205
  setConfirming(open);
145
206
  if (!open)
146
207
  setBlockedBy(null);
147
- }, title: `Delete ${connection.name}?`, description: users.length > 0 ? (_jsxs(_Fragment, { children: [users.length, " connector", users.length === 1 ? '' : 's', " read through this connection \u2014", ' ', users.map((c) => c.name).join(', '), ". Deleting it would leave", ' ', users.length === 1 ? 'it' : 'them', " without an address, and that is discovered on the next scheduled run rather than now. The server refuses while this is true."] })) : ('Nothing reads through it. The connectors that used to are unaffected; only this address and the name of its credential variable go.'), confirmLabel: remove.isPending ? 'Deleting…' : 'Delete', pending: remove.isPending, onConfirm: () => remove.mutate(), error: blockedBy && blockedBy.length > 0 ? (_jsxs(_Fragment, { children: ["Refused: still read through by ", blockedBy.map((c) => c.name).join(', '), ". Point", ' ', blockedBy.length === 1 ? 'it' : 'them', " elsewhere first."] })) : remove.error && !blockedBy ? (remove.error instanceof Error ? (remove.error.message) : ('Could not delete it.')) : undefined })] }));
208
+ }, title: `Delete ${connection.name}?`, description: deleteConsequence(users), confirmLabel: remove.isPending ? 'Deleting…' : 'Delete', pending: remove.isPending, onConfirm: () => remove.mutate(), error: deleteRefusalMessage(blockedBy, remove.error) })] }));
209
+ }
210
+ /**
211
+ * Only the config fields the chosen kind actually reads.
212
+ *
213
+ * Carrying the rest would leave a stale bucket on an HTTP connection, which
214
+ * reads as configuration somebody meant rather than as a leftover from a
215
+ * dropdown they changed.
216
+ */
217
+ function connectionConfigFor(kind, draft) {
218
+ if (kind === 's3') {
219
+ return {
220
+ bucket: draft.bucket,
221
+ ...(draft.endpoint ? { endpoint: draft.endpoint } : {}),
222
+ ...(draft.region ? { region: draft.region } : {}),
223
+ ...(draft.forcePathStyle ? { forcePathStyle: true } : {}),
224
+ };
225
+ }
226
+ return draft.url ? { url: draft.url } : {};
227
+ }
228
+ /**
229
+ * Whether there is not yet enough here to save.
230
+ *
231
+ * A SQL connection needs one of its two addresses and neither is more correct:
232
+ * the variable is the right answer in a deployment, the inline URL is the one
233
+ * that gets somebody running locally in a minute.
234
+ */
235
+ function connectionIsIncomplete(kind, draft) {
236
+ if (draft.name.trim().length === 0)
237
+ return true;
238
+ if (kind === 's3')
239
+ return draft.bucket.trim().length === 0;
240
+ if (kind === 'http')
241
+ return draft.url.trim().length === 0;
242
+ return draft.url.trim().length === 0 && draft.secretEnvVar.trim().length === 0;
243
+ }
244
+ /** A base URL, and the token sent against it. */
245
+ function HttpFields({ draft, update }) {
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
+ }
248
+ /** Either an inline URL or the variable holding one. */
249
+ 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" })] }) }));
251
+ }
252
+ /** A bucket, plus everything needed to address a non-AWS one. */
253
+ function S3Fields({ draft, update }) {
254
+ return (_jsxs(FieldGroup, { title: "Bucket", children: [_jsxs("div", { className: "grid gap-3 sm:grid-cols-2", children: [_jsx(TextField, { label: "Bucket", value: draft.bucket, onChange: (bucket) => update({ bucket }), placeholder: "fleet-drops" }), _jsx(TextField, { label: "Region", value: draft.region, onChange: (region) => update({ region }), placeholder: "Blank uses the environment's" }), _jsx(TextField, { label: "Endpoint", value: draft.endpoint, onChange: (endpoint) => update({ endpoint }), placeholder: "MinIO, e.g. http://localhost:9000" }), _jsx(TextField, { label: "Env var holding accessKeyId:secretAccessKey", value: draft.secretEnvVar, onChange: (secretEnvVar) => update({ secretEnvVar }), placeholder: "Optional", hint: "Leave blank anywhere the pod has its own role \u2014 those credentials rotate, and a static pair named here would not." })] }), _jsx(Switch, { checked: draft.forcePathStyle, onCheckedChange: (forcePathStyle) => update({ forcePathStyle }), label: "Path-style addressing", hint: "MinIO needs it; AWS does not." })] }));
255
+ }
256
+ /** The address fields for whichever kind is selected, and only those. */
257
+ function ConnectionKindFields({ kind, draft, update, }) {
258
+ if (kind === 'http')
259
+ return _jsx(HttpFields, { draft: draft, update: update });
260
+ if (kind === 'sql')
261
+ return _jsx(SqlFields, { draft: draft, update: update });
262
+ return _jsx(S3Fields, { draft: draft, update: update });
148
263
  }
149
264
  /**
150
265
  * Create or edit one.
@@ -169,44 +284,26 @@ function ConnectionForm({ connection, onClose, onSaved, }) {
169
284
  forcePathStyle: config.forcePathStyle === true,
170
285
  secretEnvVar: connection?.secretEnvVar ?? '',
171
286
  });
287
+ const update = (patch) => setDraft({ ...draft, ...patch });
172
288
  const save = useMutation({
173
289
  mutationFn: () => {
174
- // Only the fields this kind reads. Carrying the rest would leave a stale
175
- // bucket on an HTTP connection, which reads as configuration somebody
176
- // meant rather than a leftover from a dropdown they changed.
177
- const next = kind === 's3'
178
- ? {
179
- bucket: draft.bucket,
180
- ...(draft.endpoint ? { endpoint: draft.endpoint } : {}),
181
- ...(draft.region ? { region: draft.region } : {}),
182
- ...(draft.forcePathStyle ? { forcePathStyle: true } : {}),
183
- }
184
- : draft.url
185
- ? { url: draft.url }
186
- : {};
187
290
  const input = {
188
291
  id: connection?.id,
189
292
  name: draft.name.trim(),
190
293
  description: draft.description.trim() || undefined,
191
294
  kind,
192
- config: next,
295
+ config: connectionConfigFor(kind, draft),
193
296
  secretEnvVar: draft.secretEnvVar.trim() || undefined,
194
297
  };
195
298
  return client.saveConnection(input);
196
299
  },
197
300
  onSuccess: onSaved,
198
301
  });
199
- const incomplete = draft.name.trim().length === 0 ||
200
- (kind === 's3' && draft.bucket.trim().length === 0) ||
201
- (kind === 'http' && draft.url.trim().length === 0) ||
202
- // A SQL connection needs one of the two, and neither is more correct: the
203
- // variable is the right answer in a deployment, the inline URL is the one
204
- // that gets somebody running locally in a minute.
205
- (kind === 'sql' && draft.url.trim().length === 0 && draft.secretEnvVar.trim().length === 0);
302
+ const incomplete = connectionIsIncomplete(kind, draft);
206
303
  return (_jsxs("form", { className: cn('mt-6 space-y-4 rounded-lg border p-4', RULE, PANEL), onSubmit: (event) => {
207
304
  event.preventDefault();
208
305
  save.mutate();
209
- }, 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: "Fleet warehouse" }), _jsx(TextField, { label: "Description", value: draft.description, onChange: (description) => setDraft({ ...draft, description }), placeholder: "What lives behind it (optional)" }), _jsx(SelectField, { label: "Kind", ariaLabel: "Connection kind", value: kind, onValueChange: (value) => setKind(toConnectableKind(value)), options: KIND_OPTIONS })] }), kind === 'http' && (_jsx(TextField, { label: "URL", value: draft.url, onChange: (url) => setDraft({ ...draft, url }), placeholder: "https://api.example.mil/v1", hint: "The base the connectors reading through this will hang their paths off." })), kind === 'sql' && (_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) => setDraft({ ...draft, url }), placeholder: "mysql://user:pass@host/db" }), _jsx(TextField, { label: "Env var holding the URL", value: draft.secretEnvVar, onChange: (secretEnvVar) => setDraft({ ...draft, secretEnvVar }), placeholder: "FLEET_DATABASE_URL" })] }) })), kind === 's3' && (_jsxs(FieldGroup, { title: "Bucket", children: [_jsxs("div", { className: "grid gap-3 sm:grid-cols-2", children: [_jsx(TextField, { label: "Bucket", value: draft.bucket, onChange: (bucket) => setDraft({ ...draft, bucket }), placeholder: "fleet-drops" }), _jsx(TextField, { label: "Region", value: draft.region, onChange: (region) => setDraft({ ...draft, region }), placeholder: "Blank uses the environment's" }), _jsx(TextField, { label: "Endpoint", value: draft.endpoint, onChange: (endpoint) => setDraft({ ...draft, endpoint }), placeholder: "MinIO, e.g. http://localhost:9000" }), _jsx(TextField, { label: "Env var holding accessKeyId:secretAccessKey", value: draft.secretEnvVar, onChange: (secretEnvVar) => setDraft({ ...draft, secretEnvVar }), placeholder: "Optional", hint: "Leave blank anywhere the pod has its own role \u2014 those credentials rotate, and a static pair named here would not." })] }), _jsx(Switch, { checked: draft.forcePathStyle, onCheckedChange: (forcePathStyle) => setDraft({ ...draft, forcePathStyle }), label: "Path-style addressing", hint: "MinIO needs it; AWS does not." })] })), kind === 'http' && (_jsx(TextField, { label: "Credential env var", value: draft.secretEnvVar, onChange: (secretEnvVar) => setDraft({ ...draft, secretEnvVar }), placeholder: "Optional \u2014 sent as a bearer token" })), _jsxs("div", { className: "flex items-center gap-2", children: [_jsx("button", { type: "submit", disabled: save.isPending || incomplete, className: "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: save.isPending ? 'Saving…' : connection ? 'Save changes' : 'Save connection' }), _jsx("button", { type: "button", onClick: onClose, className: cn('rounded-md px-3 py-1.5 text-xs', MUTED), children: "Cancel" }), _jsx("span", { className: cn('text-[11px]', MUTED), children: "Saving does not reach it. Test the connection from its card." })] }), save.error && (_jsx("p", { className: "text-[11px] text-red-600", children: save.error instanceof Error ? save.error.message : 'Could not save.' }))] }));
306
+ }, children: [_jsxs("div", { className: "grid gap-3 sm:grid-cols-3", children: [_jsx(TextField, { label: "Name", value: draft.name, onChange: (name) => update({ name }), placeholder: "Fleet warehouse" }), _jsx(TextField, { label: "Description", value: draft.description, onChange: (description) => update({ description }), placeholder: "What lives behind it (optional)" }), _jsx(SelectField, { label: "Kind", ariaLabel: "Connection kind", value: kind, onValueChange: (value) => setKind(toConnectableKind(value)), options: KIND_OPTIONS })] }), _jsx(ConnectionKindFields, { kind: kind, draft: draft, update: update }), _jsxs("div", { className: "flex items-center gap-2", children: [_jsx("button", { type: "submit", disabled: save.isPending || incomplete, className: "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: save.isPending ? 'Saving…' : connection ? 'Save changes' : 'Save connection' }), _jsx("button", { type: "button", onClick: onClose, className: cn('rounded-md px-3 py-1.5 text-xs', MUTED), children: "Cancel" }), _jsx("span", { className: cn('text-[11px]', MUTED), children: "Saving does not reach it. Test the connection from its card." })] }), save.error && (_jsx("p", { className: "text-[11px] text-red-600", children: save.error instanceof Error ? save.error.message : 'Could not save.' }))] }));
210
307
  }
211
308
  /**
212
309
  * The options a connector form offers for "read through".
@@ -4,12 +4,13 @@ import { SortableContext, arrayMove, rectSortingStrategy, sortableKeyboardCoordi
4
4
  import { CSS } from '@dnd-kit/utilities';
5
5
  import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
6
6
  import { Download, GripVertical, LayoutGrid, Plus, RefreshCw, Trash2 } from 'lucide-react';
7
- import { useState } from 'react';
7
+ import { useMemo, useState } from 'react';
8
8
  import { CssBarChart } from './charts/css';
9
9
  import { getChartRenderer } from './charts/registry';
10
10
  import { ChartEmpty, ChartFailed, ChartSkeleton } from './charts/skeleton';
11
11
  import { cn } from './cn';
12
12
  import { useCatalogClient } from './context';
13
+ import { DataTable, renderUnknown } from './ui/data-table';
13
14
  import { Tooltip, TooltipProvider } from './ui/tooltip';
14
15
  const MUTED = 'text-zinc-400 dark:text-zinc-500';
15
16
  const RULE = 'border-zinc-200 dark:border-zinc-800';
@@ -162,6 +163,35 @@ const SPAN = {
162
163
  3: '@2xl:col-span-2 @5xl:col-span-3',
163
164
  4: '@2xl:col-span-2 @5xl:col-span-4',
164
165
  };
166
+ /**
167
+ * How many of the four columns this card spans.
168
+ *
169
+ * A pressed-state button group rather than a select: there are exactly four
170
+ * choices, the current one has to be visible at a glance while arranging a
171
+ * board, and a closed dropdown shows nothing.
172
+ */
173
+ function CardWidthPicker({ width, onWidth, }) {
174
+ return (_jsx("span", {
175
+ // A group of toggle buttons, not form fields, so `role="group"` is the
176
+ // accurate semantic — it is what the ARIA authoring practices give a
177
+ // toolbar toggle group and what Base UI's own ToggleGroup renders. A
178
+ // `<fieldset>` here would claim these are form controls and drag its
179
+ // user-agent sizing into a component the host styles.
180
+ // biome-ignore lint/a11y/useSemanticElements: fieldset is for grouping form controls; these are toggle buttons
181
+ className: cn('mr-1 flex overflow-hidden rounded-md border', RULE), role: "group", "aria-label": "Card width", children: [1, 2, 3, 4].map((size) => (_jsx(Tooltip, { content: `${size} of 4 columns wide`, children: _jsx("button", { type: "button", onClick: () => onWidth(size), "aria-pressed": width === size, className: cn('px-1.5 py-0.5 font-mono text-[10px] transition-colors', width === size
182
+ ? 'bg-zinc-950 text-zinc-50 dark:bg-zinc-100 dark:text-zinc-950'
183
+ : 'hover:bg-zinc-100 dark:hover:bg-zinc-800'), children: size }) }, size))) }));
184
+ }
185
+ /**
186
+ * The controls in a card's top-right: width, refresh, export, remove.
187
+ *
188
+ * Export appears only once there is a result, because the URL exports what the
189
+ * query returns and offering it before the first run promises a file that does
190
+ * not exist yet.
191
+ */
192
+ function CardToolbar({ width, onWidth, cached, fetching, exportHref, onRefresh, onRemove, }) {
193
+ return (_jsxs("div", { className: "flex shrink-0 items-center gap-0.5", children: [onWidth && _jsx(CardWidthPicker, { width: width, onWidth: onWidth }), _jsx(Tooltip, { content: cached ? 'Cached — refetch anyway' : 'Run again', children: _jsx("button", { type: "button", onClick: onRefresh, className: cn('rounded-sm p-1 hover:bg-zinc-100 dark:hover:bg-zinc-800', MUTED), "aria-label": "Refresh card", children: _jsx(RefreshCw, { size: 11, className: fetching ? 'animate-spin' : undefined }) }) }), exportHref && (_jsx(Tooltip, { content: "Download as CSV", children: _jsx("a", { href: exportHref, className: cn('rounded-sm p-1 hover:bg-zinc-100 dark:hover:bg-zinc-800', MUTED), "aria-label": "Export card", children: _jsx(Download, { size: 11 }) }) })), _jsx("button", { type: "button", onClick: onRemove, className: cn('rounded-sm p-1 hover:text-red-600', MUTED), "aria-label": "Remove card", children: _jsx(Trash2, { size: 11 }) })] }));
194
+ }
165
195
  function Card({ savedQueryId, width, onRemove, onWidth, dragHandle, }) {
166
196
  const client = useCatalogClient();
167
197
  const { data, isPending, isFetching, refetch, error } = useQuery({
@@ -182,9 +212,7 @@ function Card({ savedQueryId, width, onRemove, onWidth, dragHandle, }) {
182
212
  staleTime: 60_000,
183
213
  });
184
214
  const pendingKind = saved.find((query) => query.id === savedQueryId)?.visualization?.kind ?? 'table';
185
- return (_jsxs("div", { className: cn('h-full rounded-lg border p-3 transition-shadow', RULE, PANEL), children: [_jsxs("div", { className: "flex items-start justify-between gap-2", children: [dragHandle, _jsxs("div", { className: "min-w-0 flex-1", children: [_jsx("h3", { className: "truncate text-sm font-medium", children: data?.savedQuery.name ?? '…' }), data && (_jsxs("p", { className: cn('font-mono text-[10px]', MUTED), children: [data.result.rowCount, " rows", data.result.cached ? ' · cached' : ` · ${data.result.elapsedMs}ms`] }))] }), _jsxs("div", { className: "flex shrink-0 items-center gap-0.5", children: [onWidth && (_jsx("span", { className: cn('mr-1 flex overflow-hidden rounded-md border', RULE), role: "group", "aria-label": "Card width", children: [1, 2, 3, 4].map((size) => (_jsx(Tooltip, { content: `${size} of 4 columns wide`, children: _jsx("button", { type: "button", onClick: () => onWidth(size), "aria-pressed": width === size, className: cn('px-1.5 py-0.5 font-mono text-[10px] transition-colors', width === size
186
- ? 'bg-zinc-950 text-zinc-50 dark:bg-zinc-100 dark:text-zinc-950'
187
- : 'hover:bg-zinc-100 dark:hover:bg-zinc-800'), children: size }) }, size))) })), _jsx(Tooltip, { content: data?.result.cached ? 'Cached — refetch anyway' : 'Run again', children: _jsx("button", { type: "button", onClick: () => refetch(), className: cn('rounded-sm p-1 hover:bg-zinc-100 dark:hover:bg-zinc-800', MUTED), "aria-label": "Refresh card", children: _jsx(RefreshCw, { size: 11, className: isFetching ? 'animate-spin' : undefined }) }) }), data && (_jsx(Tooltip, { content: "Download as CSV", children: _jsx("a", { href: client.exportUrl(savedQueryId), className: cn('rounded-sm p-1 hover:bg-zinc-100 dark:hover:bg-zinc-800', MUTED), "aria-label": "Export card", children: _jsx(Download, { size: 11 }) }) })), _jsx("button", { type: "button", onClick: onRemove, className: cn('rounded-sm p-1 hover:text-red-600', MUTED), "aria-label": "Remove card", children: _jsx(Trash2, { size: 11 }) })] })] }), _jsx("div", { className: "mt-3", children: error ? (_jsx(ChartFailed, { height: 200, message: error instanceof Error ? error.message : 'The card failed to load.', onRetry: () => refetch() })) : isPending ? (_jsx(ChartSkeleton, { kind: pendingKind, height: 200 })) : data ? (_jsx(CardBody, { query: data.savedQuery, result: data.result })) : null })] }));
215
+ return (_jsxs("div", { className: cn('h-full rounded-lg border p-3 transition-shadow', RULE, PANEL), children: [_jsxs("div", { className: "flex items-start justify-between gap-2", children: [dragHandle, _jsxs("div", { className: "min-w-0 flex-1", children: [_jsx("h3", { className: "truncate text-sm font-medium", children: data?.savedQuery.name ?? '…' }), data && (_jsxs("p", { className: cn('font-mono text-[10px]', MUTED), children: [data.result.rowCount, " rows", data.result.cached ? ' · cached' : ` · ${data.result.elapsedMs}ms`] }))] }), _jsx(CardToolbar, { width: width, onWidth: onWidth, cached: data?.result.cached === true, fetching: isFetching, exportHref: data ? client.exportUrl(savedQueryId) : undefined, onRefresh: () => refetch(), onRemove: onRemove })] }), _jsx("div", { className: "mt-3", children: error ? (_jsx(ChartFailed, { height: 200, message: error instanceof Error ? error.message : 'The card failed to load.', onRetry: () => refetch() })) : isPending ? (_jsx(ChartSkeleton, { kind: pendingKind, height: 200 })) : data ? (_jsx(CardBody, { query: data.savedQuery, result: data.result })) : null })] }));
188
216
  }
189
217
  function CardBody({ query, result, }) {
190
218
  const viz = query.visualization ?? { kind: 'table' };
@@ -212,7 +240,21 @@ function CardBody({ query, result, }) {
212
240
  return _jsx(MiniTable, { result: result });
213
241
  }
214
242
  function MiniTable({ result }) {
215
- return (_jsx("div", { className: "overflow-x-auto", children: _jsxs("table", { className: "w-full text-[11px]", children: [_jsx("thead", { children: _jsx("tr", { className: cn('border-b', RULE), children: result.columns.slice(0, 5).map((column) => (_jsx("th", { className: cn('whitespace-nowrap px-1 py-1 text-left font-mono text-[9px] uppercase', MUTED), children: column }, column))) }) }), _jsx("tbody", { children: result.rows.slice(0, 6).map((row, index) => (
216
- // biome-ignore lint/suspicious/noArrayIndexKey: rows have no key
217
- _jsx("tr", { className: "border-b border-zinc-100 last:border-0 dark:border-zinc-900", children: result.columns.slice(0, 5).map((column) => (_jsx("td", { className: cn('whitespace-nowrap px-1 py-0.5', typeof row[column] === 'number' && 'text-right font-mono tabular-nums'), children: row[column] === null || row[column] === undefined ? '—' : String(row[column]) }, column))) }, index))) })] }) }));
243
+ // Five columns and six rows, because this is a PREVIEW inside a card — the
244
+ // whole answer lives on the query screen, and a card that tried to show it
245
+ // would be a card you cannot read at a glance, which is the only thing a card
246
+ // is for.
247
+ const shown = useMemo(() => result.columns.slice(0, 5), [result.columns]);
248
+ const columns = useMemo(() => shown.map((column) => ({
249
+ id: column,
250
+ accessorFn: (row) => row[column],
251
+ header: column,
252
+ cell: (context) => renderUnknown(context.getValue()),
253
+ })), [shown]);
254
+ const rows = useMemo(() => result.rows.slice(0, 6), [result.rows]);
255
+ const numericColumns = useMemo(() => {
256
+ const first = rows[0];
257
+ return new Set(first ? shown.filter((column) => typeof first[column] === 'number') : []);
258
+ }, [rows, shown]);
259
+ return (_jsx(DataTable, { data: rows, columns: columns, numeric: (id) => numericColumns.has(id), density: "text-[11px]" }));
218
260
  }
package/dist/FlowView.js CHANGED
@@ -41,6 +41,39 @@ export function FlowView() {
41
41
  * most important thing on this screen, and collapsing by type would hide
42
42
  * exactly that.
43
43
  */
44
+ /** An empty lane for one (publisher, type) pair, named from the type when it is known. */
45
+ function newLane(principalId, typeName, def) {
46
+ return {
47
+ principalId,
48
+ typeName,
49
+ displayName: def?.displayName ?? typeName,
50
+ icon: def?.icon,
51
+ loads: [],
52
+ schemaChanges: 0,
53
+ };
54
+ }
55
+ /**
56
+ * Fold one snapshot event into a lane's loads.
57
+ *
58
+ * A snapshot is written and then committed — two events for one load — so a
59
+ * second event updates the load already recorded rather than adding another bar
60
+ * beside it. Capped at 12 because a lane is a sparkline, not a log.
61
+ */
62
+ function recordSnapshot(lane, event) {
63
+ if (!event.snapshotId || !event.event.startsWith('snapshot.'))
64
+ return;
65
+ const committed = event.event === 'snapshot.committed';
66
+ const rows = Number(event.detail?.rowCount ?? event.detail?.rows ?? 0);
67
+ const existing = lane.loads.find((load) => load.snapshotId === event.snapshotId);
68
+ if (existing) {
69
+ existing.committed = existing.committed || committed;
70
+ existing.rows = Math.max(existing.rows, rows);
71
+ return;
72
+ }
73
+ if (lane.loads.length < 12) {
74
+ lane.loads.push({ snapshotId: event.snapshotId, rows, committed, at: event.occurredAt });
75
+ }
76
+ }
44
77
  function buildLanes(types, events) {
45
78
  const byType = new Map(types.map((t) => [t.name, t]));
46
79
  const lanes = new Map();
@@ -51,34 +84,10 @@ function buildLanes(types, events) {
51
84
  continue;
52
85
  const principalId = event.principalId ?? 'curated by hand';
53
86
  const key = `${principalId}:${event.typeName}`;
54
- const lane = lanes.get(key) ??
55
- {
56
- principalId,
57
- typeName: event.typeName,
58
- displayName: byType.get(event.typeName)?.displayName ?? event.typeName,
59
- icon: byType.get(event.typeName)?.icon,
60
- loads: [],
61
- schemaChanges: 0,
62
- };
87
+ const lane = lanes.get(key) ?? newLane(principalId, event.typeName, byType.get(event.typeName));
63
88
  if (event.event === 'schema.changed')
64
89
  lane.schemaChanges += 1;
65
- if (event.snapshotId && event.event.startsWith('snapshot.')) {
66
- const existing = lane.loads.find((l) => l.snapshotId === event.snapshotId);
67
- const committed = event.event === 'snapshot.committed';
68
- const rows = Number(event.detail?.rowCount ?? event.detail?.rows ?? 0);
69
- if (existing) {
70
- existing.committed = existing.committed || committed;
71
- existing.rows = Math.max(existing.rows, rows);
72
- }
73
- else if (lane.loads.length < 12) {
74
- lane.loads.push({
75
- snapshotId: event.snapshotId,
76
- rows,
77
- committed,
78
- at: event.occurredAt,
79
- });
80
- }
81
- }
90
+ recordSnapshot(lane, event);
82
91
  lane.lastAt = lane.lastAt ?? event.occurredAt;
83
92
  lanes.set(key, lane);
84
93
  }