@dudousxd/nestjs-catalog-react 0.8.0 → 0.10.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.
Files changed (53) hide show
  1. package/README.md +41 -5
  2. package/dist/CatalogManager.js +104 -5
  3. package/dist/DashboardBoard.d.ts +22 -0
  4. package/dist/DashboardBoard.js +88 -67
  5. package/dist/FlowView.js +47 -4
  6. package/dist/GovernanceTimeline.js +11 -1
  7. package/dist/PipelineConsole.d.ts +124 -1
  8. package/dist/PipelineConsole.js +188 -7
  9. package/dist/SavedQueryPanel.d.ts +0 -8
  10. package/dist/SavedQueryPanel.js +48 -9
  11. package/dist/charts/body.d.ts +39 -0
  12. package/dist/charts/body.js +53 -0
  13. package/dist/charts/grid.d.ts +23 -0
  14. package/dist/charts/grid.js +39 -0
  15. package/dist/context.d.ts +112 -1
  16. package/dist/context.js +31 -5
  17. package/dist/embed/EmbeddedChart.d.ts +41 -0
  18. package/dist/embed/EmbeddedChart.js +25 -0
  19. package/dist/embed/EmbeddedDashboard.d.ts +32 -0
  20. package/dist/embed/EmbeddedDashboard.js +38 -0
  21. package/dist/embed/actions.d.ts +75 -0
  22. package/dist/embed/actions.js +64 -0
  23. package/dist/embed/chart-card.d.ts +20 -0
  24. package/dist/embed/chart-card.js +89 -0
  25. package/dist/embed/index.d.ts +12 -0
  26. package/dist/embed/index.js +11 -0
  27. package/dist/embed/payload.d.ts +78 -0
  28. package/dist/embed/payload.js +42 -0
  29. package/dist/embed/slots.d.ts +52 -0
  30. package/dist/embed/slots.js +44 -0
  31. package/dist/export/css-variables.d.ts +60 -0
  32. package/dist/export/css-variables.js +137 -0
  33. package/dist/export/index.d.ts +21 -0
  34. package/dist/export/index.js +21 -0
  35. package/dist/export/pdf.d.ts +136 -0
  36. package/dist/export/pdf.js +97 -0
  37. package/dist/export/png.d.ts +88 -0
  38. package/dist/export/png.js +125 -0
  39. package/dist/export/serialize.d.ts +92 -0
  40. package/dist/export/serialize.js +298 -0
  41. package/dist/export/use-pdf-export.d.ts +66 -0
  42. package/dist/export/use-pdf-export.js +63 -0
  43. package/dist/export/use-png-export.d.ts +82 -0
  44. package/dist/export/use-png-export.js +126 -0
  45. package/dist/freshness.d.ts +37 -0
  46. package/dist/freshness.js +44 -0
  47. package/dist/index.d.ts +3 -1
  48. package/dist/index.js +21 -1
  49. package/dist/routes.d.ts +47 -1
  50. package/dist/routes.js +37 -1
  51. package/dist/sharing.d.ts +81 -0
  52. package/dist/sharing.js +72 -0
  53. package/package.json +2 -2
package/README.md CHANGED
@@ -56,6 +56,12 @@ Requires a `QueryClientProvider` from `@tanstack/react-query` above it.
56
56
  - **`<CoverageLedger />`**, **`<EditableField />`**, and the vendored primitives
57
57
  under `ui/` — the pieces, if you want to assemble something else.
58
58
 
59
+ Rendering one of these charts inside *another* application is a server-side
60
+ surface today: `GET /catalog/embed/*` serves shared charts and dashboards as
61
+ rendered rows, documented in
62
+ [`@dudousxd/nestjs-catalog`](../nestjs-catalog#embed-a-chart-in-someone-elses-application).
63
+ React components for it are being built and are not part of this package yet.
64
+
59
65
  ## Endpoints it expects
60
66
 
61
67
  The catalog screens call paths the library's own controller serves, described by
@@ -146,11 +152,41 @@ beside the node that caused it. A connection that would close a loop refuses
146
152
  itself mid-drag rather than being accepted and reported afterwards.
147
153
 
148
154
  None of that is authoritative and none of it gates a save. `POST /workflows` is
149
- the only check that counts: it can see which types exist, who may write to them
150
- and whether a transform's output fits the sink, and its refusal is shown
151
- verbatim. The rules are exported (`validateWorkflow`, `canConnect`,
152
- `wouldCycle`) so a host can run the same checks — never so it can skip the
153
- server's.
155
+ the only check that counts, and its refusal is shown verbatim. The rules are
156
+ exported (`validateWorkflow`, `canConnect`, `wouldCycle`) so a host can run the
157
+ same checks — never so it can skip the server's.
158
+
159
+ What the server checks that the canvas cannot:
160
+
161
+ - **Whether every transform the graph names still exists.** The canvas knows
162
+ what it last listed; the server reads the table.
163
+ - **Whether the signed-in principal may write the types the graph's sinks
164
+ commit.** Every sink, not just the first — a graph may carry several as long
165
+ as they commit different types — and a refusal names each type it turned
166
+ down. The same check runs again on `POST /workflows/:id/run`, because a graph
167
+ saved by somebody who held the grant can be run by somebody who does not, and
168
+ the run is what actually commits. `POST /connectors` and
169
+ `POST /connectors/:id/run` are checked the same way, against the connector's
170
+ own target type *and* the sinks of any workflow it is attached to.
171
+
172
+ These routes now require a principal: they read grants, not just a name to
173
+ attribute the write to, so a deployment that mounts the pipeline without a
174
+ principal guard will fail them rather than fall back to an anonymous identity
175
+ with nothing to check against.
176
+
177
+ What it still does **not** check, so the screen should not imply otherwise: that
178
+ a sink's target type has been published yet, and that a transform's output fits
179
+ the sink it feeds. The first surfaces when the run tries to commit; the second
180
+ is not checked anywhere.
181
+
182
+ One thing the canvas is shown but must not send back verbatim without care:
183
+ `GET /connections` and `GET /connectors` **redact the password out of any
184
+ connection URL in `config`**, because those routes need only `catalog:read`. The
185
+ placeholder reads `REDACTED`. Posting an object straight back is safe — the
186
+ server puts the stored credential back when the value it receives is exactly the
187
+ redaction of what it holds — but an inspector that renders that field as an
188
+ editable text box should say it is masked, or somebody will retype a password
189
+ they cannot see.
154
190
 
155
191
  ### Keyboard and screen readers
156
192
 
@@ -1,11 +1,12 @@
1
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
- import { ArrowUpRight, Eye, EyeOff, RotateCcw, Search } from 'lucide-react';
3
+ import { ArrowLeft, ArrowRight, ArrowUpRight, Eye, EyeOff, RotateCcw, Search, Unlink, } from 'lucide-react';
4
4
  import { useMemo, useState } from 'react';
5
5
  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 { freshnessOf, isWorthFlagging } from './freshness';
9
10
  import { DataTable } from './ui/data-table';
10
11
  import { RichTextField } from './ui/rich-text-field';
11
12
  import { Tooltip, TooltipProvider } from './ui/tooltip';
@@ -99,16 +100,86 @@ export function CatalogManager({ explorerHref, title = 'Catalog', eyebrow = 'Sem
99
100
  if (isError || !data) {
100
101
  return (_jsx("div", { className: "flex h-full items-center justify-center px-6", children: _jsxs("div", { className: "max-w-md text-center", children: [_jsx("h2", { className: "text-lg font-medium", children: "The catalog did not load" }), _jsx("p", { className: cn('mt-1 text-sm', SECONDARY), children: "The server builds it from ORM metadata at boot. Check that the API is reachable and that your account may read it." })] }) }));
101
102
  }
102
- return (_jsx(TooltipProvider, { children: _jsxs("div", { className: "flex h-full flex-col bg-zinc-50 dark:bg-zinc-950", children: [_jsxs("header", { className: cn('shrink-0 border-b px-8 py-6', RULE, PANEL), children: [_jsxs("div", { className: "flex flex-wrap items-start justify-between gap-6", children: [_jsxs("div", { children: [_jsx("p", { className: cn('font-mono text-[11px] uppercase tracking-[0.18em]', MUTED), children: eyebrow }), _jsx("h1", { className: "mt-1 text-2xl font-semibold tracking-tight", children: title }), _jsx("p", { className: cn('mt-1 max-w-xl text-sm', SECONDARY), children: intro })] }), _jsxs("div", { className: "flex items-center gap-6", children: [_jsx(Stat, { label: "Types", value: data.stats.types }), _jsx(Stat, { label: "Properties", value: data.stats.properties }), _jsx(Stat, { label: "Links", value: data.stats.relations }), _jsxs("button", { type: "button", onClick: () => resetMutation.mutate(), disabled: resetMutation.isPending, className: cn('flex items-center gap-1.5 rounded-md border px-3 py-1.5 text-xs', RULE, SECONDARY, 'transition-colors hover:bg-zinc-50 disabled:opacity-50 dark:hover:bg-zinc-800'), children: [_jsx(RotateCcw, { size: 13 }), "Reset edits"] })] })] }), _jsx("div", { className: "mt-6", children: _jsx(CoverageLedger, { types: types, selected: selected?.name, onSelect: setSelectedName }) })] }), _jsxs("div", { className: "flex min-h-0 flex-1", children: [_jsxs("aside", { className: cn('flex w-72 shrink-0 flex-col border-r', RULE, PANEL), children: [_jsxs("div", { className: cn('shrink-0 space-y-2 border-b p-3', HAIRLINE), children: [_jsxs("div", { className: "relative", children: [_jsx(Search, { size: 14, className: cn('pointer-events-none absolute left-2.5 top-1/2 -translate-y-1/2', MUTED) }), _jsx("input", { type: "text", value: filter, onChange: (e) => setFilter(e.target.value), placeholder: "Find a type or table", "aria-label": "Filter object types", className: cn('w-full rounded-md border bg-zinc-50 py-1.5 pl-8 pr-2 text-sm outline-none dark:bg-zinc-950', RULE, 'placeholder:text-zinc-400 focus:border-sky-500 focus:ring-2 focus:ring-sky-500/15') })] }), _jsxs("label", { className: cn('flex cursor-pointer items-center gap-2 px-0.5 text-xs', SECONDARY), children: [_jsx("input", { type: "checkbox", checked: onlyUnnamed, onChange: (e) => setOnlyUnnamed(e.target.checked), className: "accent-amber-500" }), "Only types nobody has named"] })] }), _jsxs("nav", { className: "min-h-0 flex-1 overflow-y-auto p-2", children: [grouped.length === 0 && (_jsxs("p", { className: cn('px-2 py-6 text-center text-xs', MUTED), children: ["Nothing matches \u201C", filter, "\u201D."] })), grouped.map(([group, groupTypes]) => (_jsxs("div", { className: "mb-3", children: [_jsxs("div", { className: "flex items-baseline justify-between px-2 py-1", children: [_jsx("span", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: group }), _jsx("span", { className: cn('font-mono text-[10px]', MUTED), children: groupTypes.length })] }), groupTypes.map((type) => (_jsxs("button", { type: "button", onClick: () => setSelectedName(type.name), className: cn('group flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left transition-colors', selected?.name === type.name
103
+ return (_jsx(TooltipProvider, { children: _jsxs("div", { className: "flex h-full flex-col bg-zinc-50 dark:bg-zinc-950", children: [_jsxs("header", { className: cn('shrink-0 border-b px-8 py-6', RULE, PANEL), children: [_jsxs("div", { className: "flex flex-wrap items-start justify-between gap-6", children: [_jsxs("div", { children: [_jsx("p", { className: cn('font-mono text-[11px] uppercase tracking-[0.18em]', MUTED), children: eyebrow }), _jsx("h1", { className: "mt-1 text-2xl font-semibold tracking-tight", children: title }), _jsx("p", { className: cn('mt-1 max-w-xl text-sm', SECONDARY), children: intro })] }), _jsxs("div", { className: "flex items-center gap-6", children: [_jsx(Stat, { label: "Types", value: data.stats.types }), _jsx(Stat, { label: "Properties", value: data.stats.properties }), _jsx(Tooltip, { content: "Relations declared across every type. A link declared at both ends counts twice \u2014 the graph draws it once.", children: _jsx("span", { className: "cursor-help", children: _jsx(Stat, { label: "Relations", value: data.stats.relations }) }) }), _jsxs("button", { type: "button", onClick: () => resetMutation.mutate(), disabled: resetMutation.isPending, className: cn('flex items-center gap-1.5 rounded-md border px-3 py-1.5 text-xs', RULE, SECONDARY, 'transition-colors hover:bg-zinc-50 disabled:opacity-50 dark:hover:bg-zinc-800'), children: [_jsx(RotateCcw, { size: 13 }), "Reset edits"] })] })] }), _jsx("div", { className: "mt-6", children: _jsx(CoverageLedger, { types: types, selected: selected?.name, onSelect: setSelectedName }) })] }), _jsxs("div", { className: "flex min-h-0 flex-1", children: [_jsxs("aside", { className: cn('flex w-72 shrink-0 flex-col border-r', RULE, PANEL), children: [_jsxs("div", { className: cn('shrink-0 space-y-2 border-b p-3', HAIRLINE), children: [_jsxs("div", { className: "relative", children: [_jsx(Search, { size: 14, className: cn('pointer-events-none absolute left-2.5 top-1/2 -translate-y-1/2', MUTED) }), _jsx("input", { type: "text", value: filter, onChange: (e) => setFilter(e.target.value), placeholder: "Find a type or table", "aria-label": "Filter object types", className: cn('w-full rounded-md border bg-zinc-50 py-1.5 pl-8 pr-2 text-sm outline-none dark:bg-zinc-950', RULE, 'placeholder:text-zinc-400 focus:border-sky-500 focus:ring-2 focus:ring-sky-500/15') })] }), _jsxs("label", { className: cn('flex cursor-pointer items-center gap-2 px-0.5 text-xs', SECONDARY), children: [_jsx("input", { type: "checkbox", checked: onlyUnnamed, onChange: (e) => setOnlyUnnamed(e.target.checked), className: "accent-amber-500" }), "Only types nobody has named"] })] }), _jsxs("nav", { className: "min-h-0 flex-1 overflow-y-auto p-2", children: [grouped.length === 0 && (_jsxs("p", { className: cn('px-2 py-6 text-center text-xs', MUTED), children: ["Nothing matches \u201C", filter, "\u201D."] })), grouped.map(([group, groupTypes]) => (_jsxs("div", { className: "mb-3", children: [_jsxs("div", { className: "flex items-baseline justify-between px-2 py-1", children: [_jsx("span", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: group }), _jsx("span", { className: cn('font-mono text-[10px]', MUTED), children: groupTypes.length })] }), groupTypes.map((type) => (_jsxs("button", { type: "button", onClick: () => setSelectedName(type.name), className: cn('group flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left transition-colors', selected?.name === type.name
103
104
  ? 'bg-sky-100 dark:bg-sky-950'
104
- : 'hover:bg-zinc-50 dark:hover:bg-zinc-800'), children: [_jsx("span", { "aria-hidden": true, className: cn('h-1.5 w-1.5 shrink-0 rounded-full', type.enriched ? 'bg-emerald-500' : 'bg-amber-400/60') }), _jsxs("span", { className: "min-w-0 flex-1", children: [_jsxs("span", { className: "block truncate text-sm", children: [type.icon ? `${type.icon} ` : '', type.displayName] }), _jsx("span", { className: cn('block truncate font-mono text-[10px]', MUTED), children: type.tableName })] })] }, type.name)))] }, group)))] })] }), _jsx("main", { className: "min-w-0 flex-1 overflow-y-auto", children: selected && (_jsx(TypeDetail, { type: selected, explorerHref: explorerHref, onPatchType: (patch) => typeMutation.mutate({ name: selected.name, patch }), onPatchProperty: (property, patch) => propertyMutation.mutate({ name: selected.name, property, patch }), onNavigate: setSelectedName }, selected.name)) })] })] }) }));
105
+ : 'hover:bg-zinc-50 dark:hover:bg-zinc-800'), children: [_jsx("span", { "aria-hidden": true, className: cn('h-1.5 w-1.5 shrink-0 rounded-full', type.enriched ? 'bg-emerald-500' : 'bg-amber-400/60') }), _jsxs("span", { className: "min-w-0 flex-1", children: [_jsxs("span", { className: "block truncate text-sm", children: [type.icon ? `${type.icon} ` : '', type.displayName] }), _jsxs("span", { className: cn('block truncate font-mono text-[10px]', MUTED), children: [type.tableName, _jsx(FreshnessNote, { type: type })] })] })] }, type.name)))] }, group)))] })] }), _jsx("main", { className: "min-w-0 flex-1 overflow-y-auto", children: selected && (_jsx(TypeDetail, { type: selected,
106
+ // The whole catalog, so the detail pane can answer what points
107
+ // AT this type. Nothing on a type records its inbound links —
108
+ // one row per declaration, and the declaration lives on the
109
+ // other end — so the only place that question can be answered
110
+ // is somewhere holding every type.
111
+ types: types, explorerHref: explorerHref, onPatchType: (patch) => typeMutation.mutate({ name: selected.name, patch }), onPatchProperty: (property, patch) => propertyMutation.mutate({ name: selected.name, property, patch }), onNavigate: setSelectedName }, selected.name)) })] })] }) }));
105
112
  }
106
113
  function Stat({ label, value }) {
107
114
  return (_jsxs("div", { className: "text-right", children: [_jsx("div", { className: "font-mono text-xl leading-none tabular-nums", children: value }), _jsx("div", { className: cn('mt-1 font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: label })] }));
108
115
  }
109
- function TypeDetail({ type, explorerHref, onPatchType, onPatchProperty, onNavigate, }) {
116
+ function TypeDetail({ type, types, explorerHref, onPatchType, onPatchProperty, onNavigate, }) {
110
117
  const visible = type.properties.filter((p) => !p.hidden).length;
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))) }))] })] }));
118
+ return (_jsxs("div", { className: "mx-auto max-w-5xl px-8 py-8", children: [_jsxs("div", { className: "flex flex-wrap items-start justify-between gap-4", children: [_jsxs("div", { className: "min-w-0", children: [_jsxs("div", { className: "flex items-baseline gap-2", children: [_jsx("span", { className: "text-2xl leading-none", children: type.icon ?? '◈' }), _jsx(EditableField, { label: "display name", value: type.displayName, onSave: (displayName) => onPatchType({ displayName }), className: "text-2xl font-semibold tracking-tight", inputClassName: "text-2xl font-semibold tracking-tight" })] }), _jsxs("div", { className: cn('mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 pl-1 font-mono text-[11px]', MUTED), children: [_jsx("span", { children: type.name }), _jsx("span", { "aria-hidden": true, children: "\u00B7" }), _jsx("span", { children: type.tableName }), _jsx("span", { "aria-hidden": true, children: "\u00B7" }), _jsxs("span", { children: ["pk ", type.primaryKey.join(', ') || 'none'] }), _jsx("span", { "aria-hidden": true, children: "\u00B7" }), _jsxs("span", { children: [visible, " of ", type.properties.length, " shown"] })] })] }), explorerHref && (_jsxs("a", { href: explorerHref(type.name), className: cn('flex items-center gap-1.5 rounded-md bg-zinc-950 px-3 py-2 text-xs text-zinc-50', 'transition-colors hover:bg-zinc-800 dark:bg-zinc-100 dark:text-zinc-950 dark:hover:bg-zinc-300'), children: ["Open ", type.pluralDisplayName, _jsx(ArrowUpRight, { size: 13 })] }))] }), _jsx("div", { className: "mt-5 border-l-2 border-sky-200 pl-4 dark:border-sky-900", children: _jsx(RichTextField, { label: "description", value: type.description ?? '', placeholder: "No one has written down what this type means yet.", onSave: (description) => onPatchType({ description }), className: cn('text-sm leading-relaxed', SECONDARY) }) }), _jsxs("div", { className: "mt-4 flex flex-wrap items-center gap-2", children: [_jsx(FieldChip, { label: "Group", value: type.group, onSave: (group) => onPatchType({ group }) }), _jsx(FieldChip, { label: "Plural", value: type.pluralDisplayName, onSave: (pluralDisplayName) => onPatchType({ pluralDisplayName }) }), _jsx(FieldChip, { label: "Icon", value: type.icon ?? '', onSave: (icon) => onPatchType({ icon }) })] }), _jsxs("section", { className: "mt-10", children: [_jsx(SectionHeading, { title: "Properties", note: "The column and its SQL type are read from the ORM. The label, description and unit are yours." }), _jsx("div", { className: cn('overflow-hidden rounded-lg border', RULE, PANEL), children: _jsx(PropertyTable, { properties: type.properties, onPatchProperty: onPatchProperty }) })] }), _jsx(LinkSection, { type: type, types: types, onPatchProperty: onPatchProperty, onNavigate: onNavigate })] }));
119
+ }
120
+ /** What each kind actually says, for people who do not read `m:n` fluently. */
121
+ const KIND_MEANING = {
122
+ 'm:1': 'Many of these point at one of those. The key is on this side.',
123
+ '1:m': 'One of these has many of those. The key is on the other side.',
124
+ '1:1': 'One of each, paired.',
125
+ 'm:n': 'Many on both sides, joined through a table of pairs.',
126
+ };
127
+ /**
128
+ * A link this type declares, together with the one that points back at it.
129
+ *
130
+ * A type carries one row per link it DECLARES, which is the honest shape — the
131
+ * declaration belongs to whoever wrote it, and inventing a mirror row on the
132
+ * other type would double every count and hand a curator a label no publisher
133
+ * owns. But it makes half the truth invisible: `@ManyToOne(() => Base)` on `Mvr`
134
+ * leaves `Base` with an empty relations list, and this screen said, in as many
135
+ * words, that nothing linked to or from it. Base is one of the most linked-to
136
+ * types in the schema.
137
+ *
138
+ * So the inbound half is derived here, from the catalog the screen already has,
139
+ * and derived is exactly what it stays: nothing about it is stored, counted or
140
+ * editable from this end.
141
+ */
142
+ function inboundLinks(type, types) {
143
+ // The other ends this type already declares. `Base.mvrs` names `Mvr.base`
144
+ // through `inverseName`, and the two are one link — listing the second as an
145
+ // inbound arrival would show a single foreign key as two separate links.
146
+ const alreadyMine = new Set(type.relations.flatMap((relation) => relation.inverseName ? [`${relation.targetType}.${relation.inverseName}`] : []));
147
+ const inbound = [];
148
+ for (const from of types) {
149
+ // A type that points at itself is already listed once, above. Showing it
150
+ // again under "points here" says there are two links where there is one.
151
+ if (from.name === type.name)
152
+ continue;
153
+ for (const relation of from.relations) {
154
+ if (relation.targetType !== type.name)
155
+ continue;
156
+ if (alreadyMine.has(`${from.name}.${relation.name}`))
157
+ continue;
158
+ inbound.push({ from, relation });
159
+ }
160
+ }
161
+ return inbound;
162
+ }
163
+ function LinkSection({ type, types, onPatchProperty, onNavigate, }) {
164
+ const inbound = useMemo(() => inboundLinks(type, types), [type, types]);
165
+ const labelFor = useMemo(() => new Map(types.map((t) => [t.name, t.displayName])), [types]);
166
+ return (_jsxs("section", { className: "mt-10 pb-16", children: [_jsx(SectionHeading, { title: "Links", note: "Read from the foreign keys. What a link is called is yours to change; where it points is not." }), type.relations.length === 0 && inbound.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."] })) : (_jsxs("div", { className: "space-y-5", children: [type.relations.length > 0 && (_jsxs("div", { children: [_jsxs("p", { className: cn('mb-2 font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: [type.displayName, " points at"] }), _jsx("ul", { className: "space-y-1.5", children: type.relations.map((relation) => (_jsx(OutboundLink, { relation: relation, targetLabel: labelFor.get(relation.targetType), onPatchProperty: onPatchProperty, onNavigate: onNavigate }, relation.name))) })] })), inbound.length > 0 && (_jsxs("div", { children: [_jsxs("p", { className: cn('mb-2 font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: ["Points at ", type.displayName] }), _jsx("ul", { className: "space-y-1.5", children: inbound.map(({ from, relation }) => (_jsx("li", { children: _jsxs("button", { type: "button", onClick: () => onNavigate(from.name), className: cn('flex w-full 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(ArrowLeft, { size: 13, className: MUTED }), _jsx("span", { className: "text-sm", children: from.displayName }), _jsxs("span", { className: cn('font-mono text-[10px]', MUTED), children: [relation.kind, " \u00B7 ", from.name, ".", relation.name] })] }) }, `${from.name}.${relation.name}`))) }), _jsx("p", { className: cn('mt-1.5 text-[11px]', MUTED), children: "Declared on the other type. Open it to rename the link." })] }))] }))] }));
167
+ }
168
+ /**
169
+ * One link this type declares.
170
+ *
171
+ * Not a single button any more, and that is the point: the label is editable and
172
+ * the target is navigable, so a control that was both meant the only way to
173
+ * rename a link was to first go somewhere else. A nested interactive element is
174
+ * also the one thing a screen reader cannot describe.
175
+ */
176
+ function OutboundLink({ relation, targetLabel, onPatchProperty, onNavigate, }) {
177
+ return (_jsxs("li", { className: cn('flex items-center gap-2 rounded-md border px-3 py-2', RULE, PANEL, relation.hidden && 'opacity-45'), children: [_jsx(Tooltip, { content: KIND_MEANING[relation.kind], children: _jsx("span", { className: cn('cursor-help font-mono text-[10px] uppercase tracking-wider', MUTED), children: relation.kind }) }), _jsx("span", { className: "min-w-0 flex-1", children: _jsx(EditableField, { label: `label for ${relation.name}`, value: relation.displayName, onSave: (displayName) => onPatchProperty(relation.name, { displayName }), className: "text-sm", inputClassName: "text-sm" }) }), _jsxs("span", { className: cn('shrink-0 font-mono text-[10px]', MUTED), children: [relation.name, relation.localKey ? ` · ${relation.localKey}` : ''] }), _jsx("span", { className: "shrink-0", children: relation.targetPublished ? (_jsxs("button", { type: "button", onClick: () => onNavigate(relation.targetType), className: cn('flex items-center gap-1.5 rounded-md px-1.5 py-0.5 text-xs transition-colors', SECONDARY, 'hover:bg-sky-100 dark:hover:bg-sky-950'), children: [_jsx(ArrowRight, { size: 13 }), targetLabel ?? relation.targetType] })) : (
178
+ // Kept, and marked. Dropping it would leave the type looking less
179
+ // connected than it is; making it navigable would send the reader to
180
+ // a type that is not there — the button used to do exactly that, and
181
+ // silently selected whichever type happened to be first.
182
+ _jsx(Tooltip, { content: `This catalog holds nothing called ${relation.targetType}. The link is real in the source schema; the type on the other end has been excluded, or nobody has published it here.`, children: _jsxs("span", { className: cn('flex cursor-help items-center gap-1.5 rounded-md px-1.5 py-0.5 text-xs', 'text-amber-700 dark:text-amber-400'), children: [_jsx(Unlink, { size: 13 }), relation.targetType] }) })) })] }));
112
183
  }
113
184
  function SectionHeading({ title, note }) {
114
185
  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 })] }));
@@ -198,3 +269,31 @@ function VisibilityToggle({ property, onPatchProperty, }) {
198
269
  ? `Hidden from tables and search. ${property.displayName} is still stored — showing it again needs no migration.`
199
270
  : '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
271
  }
272
+ /**
273
+ * The age of a type's data, beside its table name.
274
+ *
275
+ * Here rather than behind a hover or a detail pane, because the whole failure
276
+ * this addresses is that nobody thinks to look: a type whose publisher was
277
+ * deleted in January renders identically to one loaded ten minutes ago, and
278
+ * somebody reads a number off it in June.
279
+ *
280
+ * A tooltip carries the row count and the publisher — the two questions that
281
+ * follow "this is old" — without spending width on them for the types where
282
+ * nobody is asking.
283
+ */
284
+ function FreshnessNote({ type }) {
285
+ const freshness = freshnessOf(type);
286
+ const flag = isWorthFlagging(freshness);
287
+ return (_jsx("span", { className: cn('ml-2', flag && 'text-amber-600 dark:text-amber-400'), title: titleFor(type, freshness), children: freshness.kind === 'never' ? '· never loaded' : `· ${freshness.label}` }));
288
+ }
289
+ function titleFor(type, freshness) {
290
+ if (freshness.kind === 'never') {
291
+ // Said plainly, because this is the state most often mistaken for a
292
+ // problem: a type can be published by a schema and legitimately never
293
+ // loaded, and that is not the same as a load that failed.
294
+ return 'This type has a schema but no committed snapshot — nothing has ever been loaded into it.';
295
+ }
296
+ const rows = type.rowCount === undefined ? 'unknown rows' : `${type.rowCount} rows`;
297
+ const who = type.lastPrincipalId ? ` by ${type.lastPrincipalId}` : '';
298
+ return `Serving ${rows}, committed ${freshness.label}${who}.`;
299
+ }
@@ -8,3 +8,25 @@
8
8
  * query's author already made with more information than the dashboard has.
9
9
  */
10
10
  export declare function DashboardBoard(): import("react/jsx-runtime").JSX.Element;
11
+ /**
12
+ * Which chart library draws this card.
13
+ *
14
+ * On the card rather than only on the saved query, because the two answer
15
+ * different questions: the query says how this ANSWER is best drawn wherever it
16
+ * appears, and the card says how it should look HERE, beside the other cards on
17
+ * this board. A board mixing two libraries' idea of a bar reads as two boards,
18
+ * and fixing that by editing the saved query would change it everywhere else
19
+ * the query is used.
20
+ *
21
+ * A select rather than a button group — unlike width, the options are whatever
22
+ * the host registered, so there is no fixed small set to lay out, and the
23
+ * current value still has to be readable while arranging.
24
+ */
25
+ /**
26
+ * What the default option says underneath its label.
27
+ *
28
+ * Three cases, and the third is the one worth the function: a query naming a
29
+ * library nobody registered. The card falls back to the built-in, correctly and
30
+ * silently, so this line has to be the thing that says so.
31
+ */
32
+ export declare function followsHint(queryLibrary: string | undefined, available: string[]): string;
@@ -4,13 +4,15 @@ 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 { useMemo, useState } from 'react';
8
- import { CssBarChart } from './charts/css';
9
- import { getChartRenderer, registeredChartLibraries, visualizationFor } from './charts/registry';
10
- import { ChartEmpty, ChartFailed, ChartSkeleton } from './charts/skeleton';
7
+ import { useState } from 'react';
8
+ import { ChartBody } from './charts/body';
9
+ import { CHART_GRID, chartSpan } from './charts/grid';
10
+ import { registeredChartLibraries, visualizationFor } from './charts/registry';
11
+ import { ChartFailed, ChartSkeleton } from './charts/skeleton';
11
12
  import { cn } from './cn';
12
13
  import { useCatalogClient } from './context';
13
- import { DataTable, renderUnknown } from './ui/data-table';
14
+ import { ShareControl } from './sharing';
15
+ import { Select } from './ui/select';
14
16
  import { Tooltip, TooltipProvider } from './ui/tooltip';
15
17
  const MUTED = 'text-zinc-400 dark:text-zinc-500';
16
18
  const RULE = 'border-zinc-200 dark:border-zinc-800';
@@ -56,6 +58,20 @@ export function DashboardBoard() {
56
58
  mutationFn: ({ id, cards }) => client.updateDashboard(id, { cards }),
57
59
  onSuccess: invalidate,
58
60
  });
61
+ /**
62
+ * Sharing, as its own mutation rather than a third caller of `update`.
63
+ *
64
+ * Two reasons, and both are about what the screen says while it happens. A
65
+ * drag that is still saving must not disable the share button, and a refused
66
+ * share must be reported next to the share control rather than swallowed into
67
+ * whatever the last layout write did. They are also different acts: one
68
+ * arranges a board, the other hands it to an application this deployment does
69
+ * not run, which the server records as an event.
70
+ */
71
+ const share = useMutation({
72
+ mutationFn: ({ id, shared }) => client.updateDashboard(id, { shared }),
73
+ onSuccess: invalidate,
74
+ });
59
75
  const remove = useMutation({
60
76
  mutationFn: (id) => client.deleteDashboard(id),
61
77
  onSuccess: () => {
@@ -143,9 +159,9 @@ export function DashboardBoard() {
143
159
  create.mutate();
144
160
  }, children: [_jsx("input", { value: name, onChange: (e) => setName(e.target.value), placeholder: "Name", "aria-label": "Dashboard name", className: cn('min-w-0 flex-1 rounded-md border bg-white px-2 py-1 text-xs outline-none dark:bg-zinc-900', RULE) }), _jsx("button", { type: "submit", disabled: name.trim().length === 0, className: "rounded-md bg-zinc-950 px-2 text-xs text-zinc-50 disabled:opacity-40 dark:bg-zinc-100 dark:text-zinc-950", children: "Add" })] })), _jsxs("nav", { className: "min-h-0 flex-1 overflow-y-auto p-2", children: [dashboards.length === 0 && (_jsx("p", { className: cn('px-2 py-4 text-center text-[11px]', MUTED), children: "No dashboards yet." })), dashboards.map((dashboard) => (_jsxs("button", { type: "button", onClick: () => setSelectedId(dashboard.id), className: cn('flex w-full items-center gap-1.5 rounded-md px-2 py-1.5 text-left text-sm', selected?.id === dashboard.id
145
161
  ? 'bg-sky-100 dark:bg-sky-950'
146
- : 'hover:bg-zinc-50 dark:hover:bg-zinc-800'), children: [_jsx(LayoutGrid, { size: 12, className: MUTED }), _jsx("span", { className: "min-w-0 flex-1 truncate", children: dashboard.name }), _jsx("span", { className: cn('font-mono text-[10px]', MUTED), children: dashboard.cards.length })] }, dashboard.id)))] }), selected && saved.length > 0 && (_jsxs("div", { className: cn('border-t p-2', RULE), children: [_jsx("div", { className: cn('px-1 pb-1 font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Add a card" }), saved.map((query) => (_jsxs("button", { type: "button", onClick: () => addCard(query.id), className: cn('w-full truncate rounded-md px-2 py-1 text-left text-[11px]', 'transition-all hover:translate-x-0.5 hover:bg-sky-50', 'dark:hover:bg-sky-950/40'), children: ["+ ", query.name] }, query.id)))] }))] }), _jsx("main", { className: "@container min-w-0 flex-1 overflow-y-auto", children: !selected ? (_jsx("div", { className: "flex h-full items-center justify-center px-6", children: _jsxs("div", { className: "max-w-sm text-center", children: [_jsx("h2", { className: "text-lg font-medium", children: "No dashboard open" }), _jsx("p", { className: cn('mt-1 text-sm', MUTED), children: "Save a query first, then make a dashboard and add it as a card." })] }) })) : (_jsxs("div", { className: "mx-auto max-w-6xl px-8 py-6", children: [_jsxs("div", { className: "flex items-start justify-between gap-4", children: [_jsxs("div", { children: [_jsx("h1", { className: "text-2xl font-semibold tracking-tight", children: selected.name }), _jsxs("p", { className: cn('mt-0.5 font-mono text-[11px]', MUTED), children: [selected.cards.length, " cards \u00B7 by ", selected.createdBy] })] }), _jsxs("button", { type: "button", onClick: () => remove.mutate(selected.id), className: cn('flex items-center gap-1.5 rounded-md border px-3 py-1.5 text-xs', RULE, MUTED, 'hover:bg-zinc-50 dark:hover:bg-zinc-800'), children: [_jsx(Trash2, { size: 12 }), "Delete"] })] }), selected.cards.length === 0 ? (_jsx("p", { className: cn('mt-8 rounded-lg border border-dashed px-4 py-12 text-center text-sm', RULE, MUTED), children: "Empty. Add a saved query from the left." })) : (_jsx(DndContext, { sensors: sensors, collisionDetection: closestCenter, onDragEnd: onDragEnd, children: _jsx(SortableContext, { items: [...selected.cards]
162
+ : 'hover:bg-zinc-50 dark:hover:bg-zinc-800'), children: [_jsx(LayoutGrid, { size: 12, className: MUTED }), _jsx("span", { className: "min-w-0 flex-1 truncate", children: dashboard.name }), _jsx("span", { className: cn('font-mono text-[10px]', MUTED), children: dashboard.cards.length })] }, dashboard.id)))] }), selected && saved.length > 0 && (_jsxs("div", { className: cn('border-t p-2', RULE), children: [_jsx("div", { className: cn('px-1 pb-1 font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Add a card" }), saved.map((query) => (_jsxs("button", { type: "button", onClick: () => addCard(query.id), className: cn('w-full truncate rounded-md px-2 py-1 text-left text-[11px]', 'transition-all hover:translate-x-0.5 hover:bg-sky-50', 'dark:hover:bg-sky-950/40'), children: ["+ ", query.name] }, query.id)))] }))] }), _jsx("main", { className: "@container min-w-0 flex-1 overflow-y-auto", children: !selected ? (_jsx("div", { className: "flex h-full items-center justify-center px-6", children: _jsxs("div", { className: "max-w-sm text-center", children: [_jsx("h2", { className: "text-lg font-medium", children: "No dashboard open" }), _jsx("p", { className: cn('mt-1 text-sm', MUTED), children: "Save a query first, then make a dashboard and add it as a card." })] }) })) : (_jsxs("div", { className: "mx-auto max-w-6xl px-8 py-6", children: [_jsxs("div", { className: "flex items-start justify-between gap-4", children: [_jsxs("div", { children: [_jsx("h1", { className: "text-2xl font-semibold tracking-tight", children: selected.name }), _jsxs("p", { className: cn('mt-0.5 font-mono text-[11px]', MUTED), children: [selected.cards.length, " cards \u00B7 by ", selected.createdBy] })] }), _jsxs("button", { type: "button", onClick: () => remove.mutate(selected.id), className: cn('flex items-center gap-1.5 rounded-md border px-3 py-1.5 text-xs', RULE, MUTED, 'hover:bg-zinc-50 dark:hover:bg-zinc-800'), children: [_jsx(Trash2, { size: 12 }), "Delete"] })] }), _jsx(ShareControl, { className: "mt-4", kind: "dashboard", shared: selected.shared, pending: share.isPending, error: share.error, name: selected.name, onChange: (shared) => share.mutate({ id: selected.id, shared }) }), selected.cards.length === 0 ? (_jsx("p", { className: cn('mt-8 rounded-lg border border-dashed px-4 py-12 text-center text-sm', RULE, MUTED), children: "Empty. Add a saved query from the left." })) : (_jsx(DndContext, { sensors: sensors, collisionDetection: closestCenter, onDragEnd: onDragEnd, children: _jsx(SortableContext, { items: [...selected.cards]
147
163
  .sort((a, b) => a.position - b.position)
148
- .map((c) => c.id), strategy: rectSortingStrategy, children: _jsx("div", { className: "mt-6 grid grid-cols-1 gap-4 @2xl:grid-cols-2 @5xl:grid-cols-4", children: [...selected.cards]
164
+ .map((c) => c.id), strategy: rectSortingStrategy, children: _jsx("div", { className: cn('mt-6', CHART_GRID), children: [...selected.cards]
149
165
  .sort((a, b) => a.position - b.position)
150
166
  .map((card) => (_jsx(SortableCard, { id: card.id, savedQueryId: card.savedQueryId, width: card.width, ...(card.library ? { library: card.library } : {}), onRemove: () => removeCard(card.id), onWidth: (w) => setWidth(card.id, w), onLibrary: (next) => setLibrary(card.id, next) }, card.id))) }) }) }))] })) })] }) }));
151
167
  }
@@ -160,26 +176,12 @@ function SortableCard({ id, savedQueryId, width, library, onRemove, onWidth, onL
160
176
  const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({
161
177
  id,
162
178
  });
163
- return (_jsx("div", { ref: setNodeRef, style: { transform: CSS.Transform.toString(transform), transition }, className: cn(SPAN[width] ?? SPAN[2],
179
+ return (_jsx("div", { ref: setNodeRef, style: { transform: CSS.Transform.toString(transform), transition }, className: cn(chartSpan(width),
164
180
  // A grid item defaults to `min-width: auto`, so a chart wider than its
165
181
  // column pushes the column out instead of being constrained by it —
166
182
  // the same rule that made the nav overflow the page.
167
183
  'min-w-0', 'motion-safe:animate-in motion-safe:fade-in motion-safe:zoom-in-95', isDragging && 'z-10 opacity-60 shadow-lg'), children: _jsx(Card, { savedQueryId: savedQueryId, width: width, ...(library ? { library } : {}), onRemove: onRemove, onWidth: onWidth, onLibrary: onLibrary, dragHandle: _jsx("button", { type: "button", ...attributes, ...listeners, "aria-label": "Reorder card", className: cn('cursor-grab rounded-sm p-1 active:cursor-grabbing', 'hover:bg-zinc-100 dark:hover:bg-zinc-800', MUTED), children: _jsx(GripVertical, { size: 11 }) }) }) }));
168
184
  }
169
- /**
170
- * The width an operator chose, applied only where there are columns to spend.
171
- *
172
- * Below `@5xl` the grid has fewer than four columns, and a `col-span-4` there
173
- * spans past the end — which is what put a chart's axis labels outside its own
174
- * card. Every card is full width on a narrow board, two-up in the middle, and
175
- * only honours the chosen span once four columns exist to divide.
176
- */
177
- const SPAN = {
178
- 1: '@5xl:col-span-1',
179
- 2: '@2xl:col-span-2 @5xl:col-span-2',
180
- 3: '@2xl:col-span-2 @5xl:col-span-3',
181
- 4: '@2xl:col-span-2 @5xl:col-span-4',
182
- };
183
185
  /**
184
186
  * How many of the four columns this card spans.
185
187
  *
@@ -231,53 +233,46 @@ function Card({ savedQueryId, width, library, onRemove, onWidth, onLibrary, drag
231
233
  const pendingKind = saved.find((query) => query.id === savedQueryId)?.visualization?.kind ?? 'table';
232
234
  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, ...(library ? { library } : {}), ...(data?.savedQuery.visualization?.library
233
235
  ? { queryLibrary: data.savedQuery.visualization.library }
234
- : {}), onLibrary: onLibrary, 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, ...(library ? { library } : {}) })) : null })] }));
236
+ : {}), onLibrary: onLibrary, cached: data?.result.cached === true, fetching: isFetching, exportHref: data ? client.exportUrl(savedQueryId) : undefined, onRefresh: () => refetch(), onRemove: onRemove })] }), _jsx("div", { className: "mt-3", children: _jsx(CardContent, { error: error, isPending: isPending, data: data, pendingKind: pendingKind, ...(library ? { library } : {}), onRetry: () => refetch() }) })] }));
235
237
  }
236
- function CardBody({ query, result, library, }) {
237
- // Merged into the visualization rather than passed beside it, so a renderer
238
- // reading `visualization.library` sees the one it is actually being drawn as.
239
- const viz = visualizationFor(query.visualization, library);
240
- // Held at the chart's own height rather than collapsing to one line, so a
241
- // card that matched nothing does not resize the grid around it — and said in
242
- // words, because "no rows" beside a skeleton-shaped hole is the one reading
243
- // that must never be ambiguous.
244
- if (result.rowCount === 0) {
245
- return _jsx(ChartEmpty, { height: 200, message: "The query ran and matched nothing." });
246
- }
247
- if (viz.kind === 'number') {
248
- const column = viz.valueColumns?.[0] ?? result.columns[0];
249
- return (_jsxs("div", { className: "py-4 text-center", children: [_jsx("div", { className: "font-mono text-3xl tabular-nums", children: String(result.rows[0]?.[column] ?? '—') }), _jsx("div", { className: cn('mt-1 font-mono text-[10px] uppercase', MUTED), children: viz.labelColumn ?? column })] }));
250
- }
251
- if (viz.kind === 'bar' || viz.kind === 'line' || viz.kind === 'area') {
252
- // A registered library when the query names one and the host installed it;
253
- // otherwise the built-in bars. Falling back beats failing: a dashboard
254
- // should degrade to a plainer chart, not to an error message.
255
- const Renderer = getChartRenderer(viz.library);
256
- if (Renderer) {
257
- return _jsx(Renderer, { result: result, visualization: viz, height: 200 });
258
- }
259
- return _jsx(CssBarChart, { result: result, visualization: viz, height: 200 });
238
+ /**
239
+ * Which of the three things a card can be showing.
240
+ *
241
+ * Its own component rather than a ternary inside `Card`, which had grown past
242
+ * the point where the branches were readable — and this is the part of the card
243
+ * that must stay readable, because the states are easy to collapse into each
244
+ * other and the collapse is invisible until somebody's dashboard flickers.
245
+ *
246
+ * A failed query says so and offers a retry; a query that is merely refreshing
247
+ * keeps the chart it already drew, because swapping a live chart for a
248
+ * placeholder on every background refetch is the flicker the skeleton exists to
249
+ * avoid; and only a card with no data yet gets the skeleton.
250
+ *
251
+ * `isPending`, never `isFetching`, for that reason.
252
+ */
253
+ function CardContent({ error, isPending, data, pendingKind, library, onRetry, }) {
254
+ if (error) {
255
+ return (_jsx(ChartFailed, { height: 200, message: error instanceof Error ? error.message : 'The card failed to load.', onRetry: onRetry }));
260
256
  }
261
- return _jsx(MiniTable, { result: result });
257
+ if (isPending)
258
+ return _jsx(ChartSkeleton, { kind: pendingKind, height: 200 });
259
+ if (!data)
260
+ return null;
261
+ return (_jsx(CardBody, { query: data.savedQuery, result: data.result, ...(library ? { library } : {}) }));
262
262
  }
263
- function MiniTable({ result }) {
264
- // Five columns and six rows, because this is a PREVIEW inside a card — the
265
- // whole answer lives on the query screen, and a card that tried to show it
266
- // would be a card you cannot read at a glance, which is the only thing a card
267
- // is for.
268
- const shown = useMemo(() => result.columns.slice(0, 5), [result.columns]);
269
- const columns = useMemo(() => shown.map((column) => ({
270
- id: column,
271
- accessorFn: (row) => row[column],
272
- header: column,
273
- cell: (context) => renderUnknown(context.getValue()),
274
- })), [shown]);
275
- const rows = useMemo(() => result.rows.slice(0, 6), [result.rows]);
276
- const numericColumns = useMemo(() => {
277
- const first = rows[0];
278
- return new Set(first ? shown.filter((column) => typeof first[column] === 'number') : []);
279
- }, [rows, shown]);
280
- return (_jsx(DataTable, { data: rows, columns: columns, numeric: (id) => numericColumns.has(id), density: "text-[11px]" }));
263
+ function CardBody({ query, result, library, }) {
264
+ return (_jsx(ChartBody, { result: result,
265
+ // Merged into the visualization rather than passed beside it, so a
266
+ // renderer reading `visualization.library` sees the one it is actually
267
+ // being drawn as. The merge stays HERE rather than inside `ChartBody`,
268
+ // because the per-card override is a console feature: an embed has no
269
+ // card to override from, and giving it one would be an authoring control.
270
+ visualization: visualizationFor(query.visualization, library), height: 200,
271
+ // Five columns and six rows, because this is a PREVIEW inside a card —
272
+ // the whole answer lives on the query screen, and a card that tried to
273
+ // show it would be a card you cannot read at a glance, which is the only
274
+ // thing a card is for.
275
+ maxColumns: 5, maxRows: 6 }));
281
276
  }
282
277
  /**
283
278
  * Which chart library draws this card.
@@ -293,6 +288,21 @@ function MiniTable({ result }) {
293
288
  * the host registered, so there is no fixed small set to lay out, and the
294
289
  * current value still has to be readable while arranging.
295
290
  */
291
+ /**
292
+ * What the default option says underneath its label.
293
+ *
294
+ * Three cases, and the third is the one worth the function: a query naming a
295
+ * library nobody registered. The card falls back to the built-in, correctly and
296
+ * silently, so this line has to be the thing that says so.
297
+ */
298
+ export function followsHint(queryLibrary, available) {
299
+ if (!queryLibrary)
300
+ return 'the built-in renderer';
301
+ if (!available.includes(queryLibrary)) {
302
+ return `${queryLibrary} — not installed, drawing built-in`;
303
+ }
304
+ return queryLibrary;
305
+ }
296
306
  function CardLibraryPicker({ library, queryLibrary, onLibrary, }) {
297
307
  // Only what the host actually registered. Offering a library nobody
298
308
  // installed would be offering a choice that silently degrades to the
@@ -300,5 +310,16 @@ function CardLibraryPicker({ library, queryLibrary, onLibrary, }) {
300
310
  const available = registeredChartLibraries();
301
311
  if (available.length === 0)
302
312
  return null;
303
- return (_jsx(Tooltip, { content: "Which chart library draws this card. Follows the saved query unless you choose here.", children: _jsxs("select", { value: library ?? '', onChange: (event) => onLibrary(event.target.value || undefined), "aria-label": "Chart library for this card", className: cn('mr-1 rounded-md border bg-transparent px-1.5 py-0.5 font-mono text-[10px] outline-none', RULE), children: [_jsx("option", { value: "", children: queryLibrary ? `follows query (${queryLibrary})` : 'follows query (built-in)' }), available.map((name) => (_jsx("option", { value: name, children: name }, name)))] }) }));
313
+ return (_jsx(Select, { value: library ?? '', onValueChange: (next) => onLibrary(next || undefined), ariaLabel: "Chart library for this card", className: "mr-1", options: [
314
+ {
315
+ value: '',
316
+ label: 'follows query',
317
+ // The hint is the reason this is not a native `<option>`: a native
318
+ // one is a single line of unstyleable text, and what matters here is
319
+ // the second line — that the query named a library nobody installed,
320
+ // so the card is drawing something other than what it says.
321
+ hint: followsHint(queryLibrary, available),
322
+ },
323
+ ...available.map((name) => ({ value: name, label: name })),
324
+ ] }));
304
325
  }
package/dist/FlowView.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useQuery } from '@tanstack/react-query';
3
- import { ArrowRight, CircleAlert, CircleCheck, CircleDot } from 'lucide-react';
3
+ import { ArrowRight, CircleAlert, CircleCheck, CircleDot, Link2 } from 'lucide-react';
4
4
  import { useMemo } from 'react';
5
5
  import { cn } from './cn';
6
6
  import { catalogQueryKeys, useCatalogClient } from './context';
@@ -42,7 +42,7 @@ export function FlowView() {
42
42
  * exactly that.
43
43
  */
44
44
  /** An empty lane for one (publisher, type) pair, named from the type when it is known. */
45
- function newLane(principalId, typeName, def) {
45
+ function newLane(principalId, typeName, def, byType) {
46
46
  return {
47
47
  principalId,
48
48
  typeName,
@@ -50,8 +50,47 @@ function newLane(principalId, typeName, def) {
50
50
  icon: def?.icon,
51
51
  loads: [],
52
52
  schemaChanges: 0,
53
+ dependsOn: crossPublisherLinks(principalId, def, byType),
53
54
  };
54
55
  }
56
+ /**
57
+ * The links out of a type that land outside this publisher's own set.
58
+ *
59
+ * "Whose type is it" is answered by who last committed to it, which is the same
60
+ * evidence the rest of this screen runs on — a declared owner would be a claim,
61
+ * and a lane built from claims is the diagram this screen exists not to be. A
62
+ * type nobody has committed to yet has no publisher, and that is reported as its
63
+ * own state rather than folded into "someone else's": nothing has ever loaded it
64
+ * is a worse answer than somebody else loads it, and they want different fixes.
65
+ *
66
+ * Unpublished targets (`targetPublished === false`) are the sharpest case and
67
+ * are included first: the catalog does not hold the type at all, so the join has
68
+ * nowhere to land no matter who runs.
69
+ */
70
+ function crossPublisherLinks(principalId, def, byType) {
71
+ if (!def)
72
+ return [];
73
+ const seen = new Set();
74
+ const dependsOn = [];
75
+ for (const relation of def.relations) {
76
+ const target = byType.get(relation.targetType);
77
+ const publisher = target?.lastPrincipalId;
78
+ // The links this publisher can fix on its own are not this screen's news.
79
+ if (relation.targetPublished && publisher === principalId)
80
+ continue;
81
+ // One entry per target, not per link: two foreign keys into the same type
82
+ // are one dependency, and listing both says nothing the first did not.
83
+ if (seen.has(relation.targetType))
84
+ continue;
85
+ seen.add(relation.targetType);
86
+ dependsOn.push({
87
+ typeName: relation.targetType,
88
+ displayName: target?.displayName ?? relation.targetType,
89
+ ...(publisher === undefined ? {} : { publisher }),
90
+ });
91
+ }
92
+ return dependsOn;
93
+ }
55
94
  /**
56
95
  * Fold one snapshot event into a lane's loads.
57
96
  *
@@ -84,7 +123,7 @@ function buildLanes(types, events) {
84
123
  continue;
85
124
  const principalId = event.principalId ?? 'curated by hand';
86
125
  const key = `${principalId}:${event.typeName}`;
87
- const lane = lanes.get(key) ?? newLane(principalId, event.typeName, byType.get(event.typeName));
126
+ const lane = lanes.get(key) ?? newLane(principalId, event.typeName, byType.get(event.typeName), byType);
88
127
  if (event.event === 'schema.changed')
89
128
  lane.schemaChanges += 1;
90
129
  recordSnapshot(lane, event);
@@ -98,5 +137,9 @@ function Lane({ lane }) {
98
137
  const uncommitted = lane.loads.length - committed;
99
138
  return (_jsxs("div", { className: cn('rounded-lg border p-4', RULE, PANEL), children: [_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx("span", { className: "rounded-md bg-zinc-100 px-2 py-1 font-mono text-[11px] dark:bg-zinc-800", children: lane.principalId }), _jsx(ArrowRight, { size: 14, className: MUTED }), _jsxs("span", { className: "text-sm", children: [lane.icon ? `${lane.icon} ` : '', lane.displayName] }), _jsx("span", { className: cn('font-mono text-[10px]', MUTED), children: lane.typeName }), _jsx("span", { className: cn('ml-auto font-mono text-[10px]', MUTED), children: lane.lastAt ? new Date(lane.lastAt).toLocaleString() : '' })] }), _jsxs("div", { className: "mt-3 flex flex-wrap items-center gap-1.5", children: [lane.loads.length === 0 && (_jsx("span", { className: cn('text-[11px]', MUTED), children: "No loads recorded." })), [...lane.loads].reverse().map((load) => (_jsx(Tooltip, { content: _jsxs("span", { className: "font-mono text-[11px]", children: [load.snapshotId, _jsx("br", {}), load.rows, " rows \u00B7 ", load.committed ? 'committed' : 'written, never committed', _jsx("br", {}), new Date(load.at).toLocaleString()] }), children: _jsxs("span", { className: cn('flex cursor-help items-center gap-1 rounded-md border px-1.5 py-0.5 font-mono text-[10px]', load.committed
100
139
  ? 'border-emerald-200 text-emerald-700 dark:border-emerald-900 dark:text-emerald-300'
101
- : 'border-amber-200 text-amber-700 dark:border-amber-900 dark:text-amber-300'), children: [load.committed ? _jsx(CircleCheck, { size: 10 }) : _jsx(CircleDot, { size: 10 }), load.rows] }) }, load.snapshotId)))] }), _jsxs("div", { className: cn('mt-2 flex flex-wrap gap-3 font-mono text-[10px]', MUTED), children: [_jsxs("span", { children: [committed, " committed"] }), uncommitted > 0 && (_jsx(Tooltip, { content: "Written but never committed. Nobody is reading these \u2014 a publisher that stopped halfway leaves exactly this.", children: _jsxs("span", { className: "cursor-help text-amber-600", children: [uncommitted, " left uncommitted"] }) })), lane.schemaChanges > 0 && (_jsx(Tooltip, { content: "Columns were added. This catalog never drops or retypes one automatically.", children: _jsxs("span", { className: "flex cursor-help items-center gap-1", children: [_jsx(CircleAlert, { size: 10 }), lane.schemaChanges, " schema change", lane.schemaChanges === 1 ? '' : 's'] }) }))] })] }));
140
+ : 'border-amber-200 text-amber-700 dark:border-amber-900 dark:text-amber-300'), children: [load.committed ? _jsx(CircleCheck, { size: 10 }) : _jsx(CircleDot, { size: 10 }), load.rows] }) }, load.snapshotId)))] }), _jsxs("div", { className: cn('mt-2 flex flex-wrap gap-3 font-mono text-[10px]', MUTED), children: [_jsxs("span", { children: [committed, " committed"] }), uncommitted > 0 && (_jsx(Tooltip, { content: "Written but never committed. Nobody is reading these \u2014 a publisher that stopped halfway leaves exactly this.", children: _jsxs("span", { className: "cursor-help text-amber-600", children: [uncommitted, " left uncommitted"] }) })), lane.schemaChanges > 0 && (_jsx(Tooltip, { content: "Columns were added. This catalog never drops or retypes one automatically.", children: _jsxs("span", { className: "flex cursor-help items-center gap-1", children: [_jsx(CircleAlert, { size: 10 }), lane.schemaChanges, " schema change", lane.schemaChanges === 1 ? '' : 's'] }) }))] }), lane.dependsOn.length > 0 && (_jsxs("div", { className: cn('mt-2 flex flex-wrap items-center gap-1.5 font-mono text-[10px]', MUTED), children: [_jsx(Link2, { size: 10 }), _jsx("span", { children: "needs" }), lane.dependsOn.map((dependency) => (_jsx(Tooltip, { content: dependency.publisher
141
+ ? `${lane.displayName} links to ${dependency.displayName}, which ${dependency.publisher} loads. Rows here can arrive before the ones they point at, and the join comes back empty rather than failing.`
142
+ : `${lane.displayName} links to ${dependency.typeName}, and nothing has ever committed to it. Every one of those joins resolves to nothing.`, children: _jsxs("span", { className: cn('cursor-help rounded-sm border px-1.5 py-0.5', dependency.publisher
143
+ ? 'border-zinc-200 dark:border-zinc-800'
144
+ : 'border-amber-200 text-amber-700 dark:border-amber-900 dark:text-amber-300'), children: [dependency.displayName, dependency.publisher ? ` · ${dependency.publisher}` : ' · nobody'] }) }, dependency.typeName)))] }))] }));
102
145
  }