@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.
- package/README.md +41 -5
- package/dist/CatalogManager.js +104 -5
- package/dist/DashboardBoard.d.ts +22 -0
- package/dist/DashboardBoard.js +88 -67
- package/dist/FlowView.js +47 -4
- package/dist/GovernanceTimeline.js +11 -1
- package/dist/PipelineConsole.d.ts +124 -1
- package/dist/PipelineConsole.js +188 -7
- package/dist/SavedQueryPanel.d.ts +0 -8
- package/dist/SavedQueryPanel.js +48 -9
- package/dist/charts/body.d.ts +39 -0
- package/dist/charts/body.js +53 -0
- package/dist/charts/grid.d.ts +23 -0
- package/dist/charts/grid.js +39 -0
- package/dist/context.d.ts +112 -1
- package/dist/context.js +31 -5
- package/dist/embed/EmbeddedChart.d.ts +41 -0
- package/dist/embed/EmbeddedChart.js +25 -0
- package/dist/embed/EmbeddedDashboard.d.ts +32 -0
- package/dist/embed/EmbeddedDashboard.js +38 -0
- package/dist/embed/actions.d.ts +75 -0
- package/dist/embed/actions.js +64 -0
- package/dist/embed/chart-card.d.ts +20 -0
- package/dist/embed/chart-card.js +89 -0
- package/dist/embed/index.d.ts +12 -0
- package/dist/embed/index.js +11 -0
- package/dist/embed/payload.d.ts +78 -0
- package/dist/embed/payload.js +42 -0
- package/dist/embed/slots.d.ts +52 -0
- package/dist/embed/slots.js +44 -0
- package/dist/export/css-variables.d.ts +60 -0
- package/dist/export/css-variables.js +137 -0
- package/dist/export/index.d.ts +21 -0
- package/dist/export/index.js +21 -0
- package/dist/export/pdf.d.ts +136 -0
- package/dist/export/pdf.js +97 -0
- package/dist/export/png.d.ts +88 -0
- package/dist/export/png.js +125 -0
- package/dist/export/serialize.d.ts +92 -0
- package/dist/export/serialize.js +298 -0
- package/dist/export/use-pdf-export.d.ts +66 -0
- package/dist/export/use-pdf-export.js +63 -0
- package/dist/export/use-png-export.d.ts +82 -0
- package/dist/export/use-png-export.js +126 -0
- package/dist/freshness.d.ts +37 -0
- package/dist/freshness.js +44 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +21 -1
- package/dist/routes.d.ts +47 -1
- package/dist/routes.js +37 -1
- package/dist/sharing.d.ts +81 -0
- package/dist/sharing.js +72 -0
- package/package.json +2 -2
|
@@ -5,6 +5,7 @@ import { useMemo, useState } from 'react';
|
|
|
5
5
|
import { CATALOG_EVENT_META, TraceExplorer, eventMeta, } from './TraceExplorer';
|
|
6
6
|
import { cn } from './cn';
|
|
7
7
|
import { useCatalogClient } from './context';
|
|
8
|
+
import { Select } from './ui/select';
|
|
8
9
|
import { Tooltip, TooltipProvider } from './ui/tooltip';
|
|
9
10
|
const MUTED = 'text-zinc-400 dark:text-zinc-500';
|
|
10
11
|
const RULE = 'border-zinc-200 dark:border-zinc-800';
|
|
@@ -60,7 +61,16 @@ export function GovernanceTimeline({ traceSource, } = {}) {
|
|
|
60
61
|
return (_jsx(Tooltip, { content: option.meaning, children: _jsxs("button", { type: "button", onClick: () => setView(option.id), className: cn('flex items-center gap-1.5 px-2.5 py-1 text-xs transition-colors', view === option.id
|
|
61
62
|
? 'bg-zinc-100 text-zinc-950 dark:bg-zinc-800 dark:text-zinc-50'
|
|
62
63
|
: cn(MUTED, 'hover:bg-zinc-50 dark:hover:bg-zinc-800/60')), children: [_jsx(Icon, { size: 12 }), option.label] }) }, option.id));
|
|
63
|
-
}) }), view === 'events' && (_jsxs(_Fragment, { children: [
|
|
64
|
+
}) }), view === 'events' && (_jsxs(_Fragment, { children: [_jsx(Select, { value: event, onValueChange: setEvent, ariaLabel: "Filter by event", options: [
|
|
65
|
+
{ value: '', label: 'Every event' },
|
|
66
|
+
...Object.entries(CATALOG_EVENT_META).map(([id, meta]) => ({
|
|
67
|
+
value: id,
|
|
68
|
+
label: meta.label,
|
|
69
|
+
})),
|
|
70
|
+
] }), _jsx(Select, { value: principal, onValueChange: setPrincipal, ariaLabel: "Filter by application", options: [
|
|
71
|
+
{ value: '', label: 'Every application' },
|
|
72
|
+
...principals.map((id) => ({ value: id, label: id })),
|
|
73
|
+
] })] }))] }), view === 'traces' && (_jsx("div", { className: "mt-6", children: _jsx(TraceExplorer, { source: traceSource }) })), view === 'events' && (_jsxs(_Fragment, { children: [isLoading && (_jsx("p", { className: cn('py-10 text-center font-mono text-sm', MUTED), children: "Reading the trail\u2026" })), !isLoading && events.length === 0 && (_jsx("p", { className: cn('mt-6 rounded-lg border border-dashed px-4 py-12 text-center text-sm', RULE, MUTED), children: "Nothing recorded yet. Publish something and it will appear here." })), _jsx("div", { className: "mt-6 space-y-6", children: grouped.map(([day, entries]) => (_jsxs("div", { children: [_jsx("div", { className: cn('mb-2 font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: day }), _jsx("div", { className: cn('overflow-hidden rounded-lg border', RULE, PANEL), children: entries.map((entry) => (_jsx(Row, { entry: entry }, entry.id))) })] }, day))) })] }))] }) }) }));
|
|
64
74
|
}
|
|
65
75
|
function Row({ entry }) {
|
|
66
76
|
// One shared map with the trace view. Two copies drifted the first time a new
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ScalarType } from '@dudousxd/nestjs-catalog/client';
|
|
1
2
|
export interface PipelineConsoleProps {
|
|
2
3
|
/** Heading copy, so the host can call this whatever its users call it. */
|
|
3
4
|
title?: string;
|
|
@@ -8,6 +9,93 @@ export interface PipelineConsoleProps {
|
|
|
8
9
|
* regardless; this only stops the console offering buttons that always 403.
|
|
9
10
|
*/
|
|
10
11
|
canEdit?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Asking a connector what its source looks like, and creating the type from
|
|
14
|
+
* the answer.
|
|
15
|
+
*
|
|
16
|
+
* A prop rather than two more methods on `CatalogClient`, and that is not a
|
|
17
|
+
* design preference — it is the honest report of a boundary. `CatalogClient`
|
|
18
|
+
* carries no `discoverConnectorSchema` and no publish call of any kind, and
|
|
19
|
+
* both live in `context.tsx`, so a console that reached for them would be
|
|
20
|
+
* naming methods that do not exist. Wiring is one function each:
|
|
21
|
+
*
|
|
22
|
+
* discover: POST <pipelineBasePath>/connectors/:id/discover
|
|
23
|
+
* createType: PUT <publishBasePath>/publish/:name/schema
|
|
24
|
+
*
|
|
25
|
+
* Omit it and the connector editor simply does not offer discovery, which is
|
|
26
|
+
* the correct state for a host that has not mounted those routes. Supply
|
|
27
|
+
* `discover` without `createType` and the panel does everything up to the
|
|
28
|
+
* confirmation and then shows the exact request it would have sent — the
|
|
29
|
+
* publish route requires `catalog:write` and per-type ownership, and a host
|
|
30
|
+
* that has deliberately not given its console that has to be able to say so
|
|
31
|
+
* without the screen pretending the button is merely broken.
|
|
32
|
+
*/
|
|
33
|
+
schemaDiscovery?: SchemaDiscoveryBridge;
|
|
34
|
+
}
|
|
35
|
+
export interface SchemaDiscoveryBridge {
|
|
36
|
+
discover(connectorId: string): Promise<ConnectorSchemaDiscovery>;
|
|
37
|
+
/**
|
|
38
|
+
* Create the type from what a person confirmed. Absent is a supported state —
|
|
39
|
+
* see {@link PipelineConsoleProps.schemaDiscovery}.
|
|
40
|
+
*/
|
|
41
|
+
createType?(draft: DiscoveredTypeDraft): Promise<unknown>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* What `POST pipeline/connectors/:id/discover` answers, mirrored for the browser.
|
|
45
|
+
*
|
|
46
|
+
* Mirrored rather than imported, exactly as `PipelineCapabilities` is in
|
|
47
|
+
* `context.tsx`: the authority is `schema-discovery.ts` in
|
|
48
|
+
* `@dudousxd/nestjs-catalog-pipeline`, which is a NestJS package with a
|
|
49
|
+
* `node:fs` import in its dependency graph and has no business in a browser
|
|
50
|
+
* bundle. The two are kept honest by being the documented response of one route,
|
|
51
|
+
* and by this screen treating every field it renders as something the server may
|
|
52
|
+
* not have sent.
|
|
53
|
+
*/
|
|
54
|
+
export interface DiscoveredColumn {
|
|
55
|
+
/**
|
|
56
|
+
* The column as the source spells it, which is also the property name. The
|
|
57
|
+
* server explains at length why it is not tidied: the store matches records to
|
|
58
|
+
* properties by property NAME, so a renamed property is a column that loads
|
|
59
|
+
* null on every run and reports success.
|
|
60
|
+
*/
|
|
61
|
+
name: string;
|
|
62
|
+
/** `null` means discovery reached no conclusion — which is not a type. */
|
|
63
|
+
type: ScalarType | null;
|
|
64
|
+
confidence: 'reported' | 'inferred' | 'unknown';
|
|
65
|
+
sourceType: string;
|
|
66
|
+
/** `null` where the source did not say. Postgres never does. */
|
|
67
|
+
nullable: boolean | null;
|
|
68
|
+
note?: string;
|
|
69
|
+
}
|
|
70
|
+
export interface SchemaDrift {
|
|
71
|
+
added: string[];
|
|
72
|
+
removed: string[];
|
|
73
|
+
retyped: Array<{
|
|
74
|
+
property: string;
|
|
75
|
+
was: ScalarType;
|
|
76
|
+
now: ScalarType;
|
|
77
|
+
}>;
|
|
78
|
+
}
|
|
79
|
+
export interface ConnectorSchemaDiscovery {
|
|
80
|
+
connectorId: string;
|
|
81
|
+
connectorName: string;
|
|
82
|
+
targetType: string;
|
|
83
|
+
typeExists: boolean;
|
|
84
|
+
basis: 'driver' | 'sample';
|
|
85
|
+
sampled: number;
|
|
86
|
+
caveat: string;
|
|
87
|
+
columns: DiscoveredColumn[];
|
|
88
|
+
drift: SchemaDrift | null;
|
|
89
|
+
}
|
|
90
|
+
/** The subset of a published type this screen is able to state. */
|
|
91
|
+
export interface DiscoveredTypeDraft {
|
|
92
|
+
name: string;
|
|
93
|
+
properties: Array<{
|
|
94
|
+
name: string;
|
|
95
|
+
columnName: string;
|
|
96
|
+
type: ScalarType;
|
|
97
|
+
nullable: boolean;
|
|
98
|
+
}>;
|
|
11
99
|
}
|
|
12
100
|
/**
|
|
13
101
|
* Where data comes from, and the code that shapes it.
|
|
@@ -17,4 +105,39 @@ export interface PipelineConsoleProps {
|
|
|
17
105
|
* without its transform is a URL, and a transform without the connector it
|
|
18
106
|
* feeds is code nobody can place.
|
|
19
107
|
*/
|
|
20
|
-
export declare function PipelineConsole({ title, eyebrow, intro, canEdit, }: PipelineConsoleProps): import("react/jsx-runtime").JSX.Element;
|
|
108
|
+
export declare function PipelineConsole({ title, eyebrow, intro, canEdit, schemaDiscovery, }: PipelineConsoleProps): import("react/jsx-runtime").JSX.Element;
|
|
109
|
+
/** What a person decided about one discovered column. */
|
|
110
|
+
export interface ColumnChoice {
|
|
111
|
+
include: boolean;
|
|
112
|
+
/** Empty means nothing has been chosen yet — see {@link initialChoices}. */
|
|
113
|
+
type: ScalarType | '';
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Where the checkboxes start, and why the untyped ones start off.
|
|
117
|
+
*
|
|
118
|
+
* A column discovery could type is proposed; a column it could not is present,
|
|
119
|
+
* visible, and **excluded** until somebody says what it is. Pre-selecting it
|
|
120
|
+
* with a plausible default is the failure that matters — a wrong type becomes a
|
|
121
|
+
* wrong column in a lake nobody re-checks, and everything downstream reads it
|
|
122
|
+
* as fact rather than as the guess it was.
|
|
123
|
+
*
|
|
124
|
+
* Keyed by position rather than by name on purpose: `SELECT a.id, b.id` gives
|
|
125
|
+
* two columns called `id`, and a map would silently merge their choices.
|
|
126
|
+
*/
|
|
127
|
+
export declare function initialChoices(columns: DiscoveredColumn[]): ColumnChoice[];
|
|
128
|
+
/**
|
|
129
|
+
* The type this would create, and everything standing in the way of creating it.
|
|
130
|
+
*
|
|
131
|
+
* Pure, and separate from the panel, because these are the rules that decide
|
|
132
|
+
* whether a schema somebody approved is one the publish route will accept — and
|
|
133
|
+
* rules that live inside a component are rules only a rendered DOM can check.
|
|
134
|
+
*
|
|
135
|
+
* `columnName` is sent as well as `name`, and they are the same string. The
|
|
136
|
+
* publish service maps `columnName` to `sourceColumn` and `name` to the property
|
|
137
|
+
* itself, and the store reads records by property name; sending them equal is
|
|
138
|
+
* what makes a load match. See the server's `DiscoveredColumn.name`.
|
|
139
|
+
*/
|
|
140
|
+
export declare function proposalFrom(discovery: ConnectorSchemaDiscovery, choices: ColumnChoice[]): {
|
|
141
|
+
draft: DiscoveredTypeDraft;
|
|
142
|
+
problems: string[];
|
|
143
|
+
};
|
package/dist/PipelineConsole.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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 { Cable, CircleCheck, CircleX, Code2, KeyRound, Loader2, Play, Plug, Plus, RefreshCw, Trash2, } from 'lucide-react';
|
|
3
|
+
import { Cable, CircleCheck, CircleX, Code2, KeyRound, Loader2, Play, Plug, Plus, RefreshCw, ScanSearch, Trash2, TriangleAlert, } from 'lucide-react';
|
|
4
4
|
import { useState } from 'react';
|
|
5
5
|
import { ConnectionPanel, connectionOptionsFor } from './ConnectionPanel';
|
|
6
6
|
import { TransformEditor } from './TransformEditor';
|
|
@@ -26,7 +26,7 @@ const PANEL = 'bg-white dark:bg-zinc-900';
|
|
|
26
26
|
* without its transform is a URL, and a transform without the connector it
|
|
27
27
|
* feeds is code nobody can place.
|
|
28
28
|
*/
|
|
29
|
-
export function PipelineConsole({ title = 'Connectors', eyebrow = 'Ingestion', intro = 'A source, code that reshapes it, and a snapshot at the end. Running one goes through exactly the same append-and-commit a publisher uses, so there is one way rows arrive rather than two.', canEdit = true, }) {
|
|
29
|
+
export function PipelineConsole({ title = 'Connectors', eyebrow = 'Ingestion', intro = 'A source, code that reshapes it, and a snapshot at the end. Running one goes through exactly the same append-and-commit a publisher uses, so there is one way rows arrive rather than two.', canEdit = true, schemaDiscovery, }) {
|
|
30
30
|
const client = useCatalogClient();
|
|
31
31
|
const [tab, setTab] = useState('connectors');
|
|
32
32
|
const { data: capabilities } = useQuery({
|
|
@@ -39,9 +39,9 @@ export function PipelineConsole({ title = 'Connectors', eyebrow = 'Ingestion', i
|
|
|
39
39
|
});
|
|
40
40
|
return (_jsx(TooltipProvider, { children: _jsx("div", { className: "h-full overflow-y-auto", children: _jsxs("div", { className: "mx-auto max-w-5xl px-8 py-8", 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: "mt-1 max-w-2xl text-sm text-zinc-500 dark:text-zinc-400", children: intro }), _jsxs(Tabs, { value: tab, onValueChange: setTab, className: "mt-6", children: [_jsxs(TabsList, { children: [_jsxs(TabsTab, { value: "connections", children: [_jsx(Plug, { size: 13 }), "Connections"] }), _jsxs(TabsTab, { value: "connectors", children: [_jsx(Cable, { size: 13 }), "Connectors"] }), _jsxs(TabsTab, { value: "transforms", children: [_jsx(Code2, { size: 13 }), "Transforms"] }), _jsx(Tooltip, { content: capabilities?.pythonPackages?.length
|
|
41
41
|
? `Python transforms may import ${capabilities.pythonPackages.join(', ')} — provisioned by the image, not by this service.`
|
|
42
|
-
: 'Which languages this deployment can actually execute.', children: _jsx("span", { className: cn('ml-auto cursor-help self-center font-mono text-[10px]', MUTED), children: capabilities ? `runs ${capabilities.languages.join(' · ')}` : 'checking…' }) })] }), _jsx(TabsPanel, { value: "connections", children: _jsx(ConnectionPanel, { canEdit: canEdit }) }), _jsx(TabsPanel, { value: "connectors", children: _jsx(ConnectorList, { canEdit: canEdit }) }), _jsx(TabsPanel, { value: "transforms", children: _jsx(TransformList, { canEdit: canEdit, languages: capabilities?.languages ?? ['javascript'], pythonPackages: capabilities?.pythonPackages ?? [] }) })] })] }) }) }));
|
|
42
|
+
: 'Which languages this deployment can actually execute.', children: _jsx("span", { className: cn('ml-auto cursor-help self-center font-mono text-[10px]', MUTED), children: capabilities ? `runs ${capabilities.languages.join(' · ')}` : 'checking…' }) })] }), _jsx(TabsPanel, { value: "connections", children: _jsx(ConnectionPanel, { canEdit: canEdit }) }), _jsx(TabsPanel, { value: "connectors", children: _jsx(ConnectorList, { canEdit: canEdit, schemaDiscovery: schemaDiscovery }) }), _jsx(TabsPanel, { value: "transforms", children: _jsx(TransformList, { canEdit: canEdit, languages: capabilities?.languages ?? ['javascript'], pythonPackages: capabilities?.pythonPackages ?? [] }) })] })] }) }) }));
|
|
43
43
|
}
|
|
44
|
-
function ConnectorList({ canEdit }) {
|
|
44
|
+
function ConnectorList({ canEdit, schemaDiscovery, }) {
|
|
45
45
|
const client = useCatalogClient();
|
|
46
46
|
const queryClient = useQueryClient();
|
|
47
47
|
const [editing, setEditing] = useState(null);
|
|
@@ -76,7 +76,7 @@ function ConnectorList({ canEdit }) {
|
|
|
76
76
|
onSuccess: invalidateRun,
|
|
77
77
|
});
|
|
78
78
|
if (editing) {
|
|
79
|
-
return (_jsx(ConnectorForm, { connector: editing === 'new' ? undefined : editing, transforms: transforms, connections: connections, onClose: () => setEditing(null), onSaved: () => {
|
|
79
|
+
return (_jsx(ConnectorForm, { connector: editing === 'new' ? undefined : editing, transforms: transforms, connections: connections, schemaDiscovery: schemaDiscovery, onClose: () => setEditing(null), onSaved: () => {
|
|
80
80
|
setEditing(null);
|
|
81
81
|
queryClient.invalidateQueries({ queryKey: catalogQueryKeys.connectors });
|
|
82
82
|
} }));
|
|
@@ -190,7 +190,188 @@ function connectionPickerHint(optionCount, viaConnection) {
|
|
|
190
190
|
function ConnectorFormActions({ editing, pending, incomplete, error, onClose, }) {
|
|
191
191
|
return (_jsxs(_Fragment, { children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("button", { type: "submit", disabled: pending || 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: pending ? 'Saving…' : editing ? 'Save changes' : 'Save connector' }), _jsx("button", { type: "button", onClick: onClose, className: cn('rounded-md px-3 py-1.5 text-xs', MUTED), children: "Cancel" })] }), error ? (_jsx("p", { className: "text-[11px] text-red-600", children: error instanceof Error ? error.message : 'Could not save.' })) : null] }));
|
|
192
192
|
}
|
|
193
|
-
|
|
193
|
+
/**
|
|
194
|
+
* Every type the catalog can hold, in the order a person scans for one.
|
|
195
|
+
*
|
|
196
|
+
* `unknown` is last and named plainly, because choosing it is a decision: the
|
|
197
|
+
* store gives it a TEXT column and stringifies whatever arrives. It is the right
|
|
198
|
+
* answer for a column nobody can classify and the wrong answer for one nobody
|
|
199
|
+
* looked at, which is exactly why discovery never picks it on anyone's behalf.
|
|
200
|
+
*/
|
|
201
|
+
const SCALAR_TYPES = [
|
|
202
|
+
'string',
|
|
203
|
+
'number',
|
|
204
|
+
'boolean',
|
|
205
|
+
'date',
|
|
206
|
+
'uuid',
|
|
207
|
+
'json',
|
|
208
|
+
'unknown',
|
|
209
|
+
];
|
|
210
|
+
/**
|
|
211
|
+
* Where the checkboxes start, and why the untyped ones start off.
|
|
212
|
+
*
|
|
213
|
+
* A column discovery could type is proposed; a column it could not is present,
|
|
214
|
+
* visible, and **excluded** until somebody says what it is. Pre-selecting it
|
|
215
|
+
* with a plausible default is the failure that matters — a wrong type becomes a
|
|
216
|
+
* wrong column in a lake nobody re-checks, and everything downstream reads it
|
|
217
|
+
* as fact rather than as the guess it was.
|
|
218
|
+
*
|
|
219
|
+
* Keyed by position rather than by name on purpose: `SELECT a.id, b.id` gives
|
|
220
|
+
* two columns called `id`, and a map would silently merge their choices.
|
|
221
|
+
*/
|
|
222
|
+
export function initialChoices(columns) {
|
|
223
|
+
return columns.map((column) => ({ include: column.type !== null, type: column.type ?? '' }));
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* The type this would create, and everything standing in the way of creating it.
|
|
227
|
+
*
|
|
228
|
+
* Pure, and separate from the panel, because these are the rules that decide
|
|
229
|
+
* whether a schema somebody approved is one the publish route will accept — and
|
|
230
|
+
* rules that live inside a component are rules only a rendered DOM can check.
|
|
231
|
+
*
|
|
232
|
+
* `columnName` is sent as well as `name`, and they are the same string. The
|
|
233
|
+
* publish service maps `columnName` to `sourceColumn` and `name` to the property
|
|
234
|
+
* itself, and the store reads records by property name; sending them equal is
|
|
235
|
+
* what makes a load match. See the server's `DiscoveredColumn.name`.
|
|
236
|
+
*/
|
|
237
|
+
export function proposalFrom(discovery, choices) {
|
|
238
|
+
const chosen = discovery.columns
|
|
239
|
+
.map((column, index) => ({ column, choice: choices[index] ?? { include: false, type: '' } }))
|
|
240
|
+
.filter((entry) => entry.choice.include);
|
|
241
|
+
const problems = [];
|
|
242
|
+
const untyped = chosen.filter((entry) => entry.choice.type === '');
|
|
243
|
+
if (untyped.length > 0) {
|
|
244
|
+
problems.push(`Choose a type for ${untyped.map((entry) => `"${entry.column.name}"`).join(', ')}, or leave ${untyped.length === 1 ? 'it' : 'them'} out.`);
|
|
245
|
+
}
|
|
246
|
+
const counts = new Map();
|
|
247
|
+
for (const entry of chosen) {
|
|
248
|
+
counts.set(entry.column.name, (counts.get(entry.column.name) ?? 0) + 1);
|
|
249
|
+
}
|
|
250
|
+
const duplicated = [...counts].filter(([, count]) => count > 1).map(([name]) => `"${name}"`);
|
|
251
|
+
if (duplicated.length > 0) {
|
|
252
|
+
problems.push(`${duplicated.join(', ')} appears more than once. A record is an object, so only one of them can survive — leave the others out.`);
|
|
253
|
+
}
|
|
254
|
+
const properties = [];
|
|
255
|
+
for (const entry of chosen) {
|
|
256
|
+
if (entry.choice.type === '')
|
|
257
|
+
continue;
|
|
258
|
+
properties.push({
|
|
259
|
+
name: entry.column.name,
|
|
260
|
+
columnName: entry.column.name,
|
|
261
|
+
type: entry.choice.type,
|
|
262
|
+
// Not stated is published nullable. A column marked NOT NULL that the
|
|
263
|
+
// source sometimes leaves empty is a load that fails at 3am; a nullable
|
|
264
|
+
// column that never holds a null costs nothing at all.
|
|
265
|
+
nullable: entry.column.nullable ?? true,
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
if (properties.length === 0) {
|
|
269
|
+
problems.push('Nothing is selected, and a type with no properties is refused.');
|
|
270
|
+
}
|
|
271
|
+
return { draft: { name: discovery.targetType, properties }, problems };
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* What the source looks like, offered to the person who has to name it.
|
|
275
|
+
*
|
|
276
|
+
* Only for a SAVED connector: discovery runs the connector's own configured
|
|
277
|
+
* read, and there is nothing to read from a form that has not been stored yet.
|
|
278
|
+
*
|
|
279
|
+
* The screen's job is to make the difference between what was *reported* and
|
|
280
|
+
* what was *inferred* impossible to miss, because that difference is the whole
|
|
281
|
+
* value of the report. A driver describing a `NUMERIC` column is the database
|
|
282
|
+
* speaking; forty records that all happened to hold a string is a sample, and
|
|
283
|
+
* the forty-first is where somebody finds out.
|
|
284
|
+
*/
|
|
285
|
+
function SchemaDiscoveryPanel({ connectorId, bridge, }) {
|
|
286
|
+
// Counted rather than timestamped so a second discovery always remounts the
|
|
287
|
+
// table below, dropping the choices somebody made against a column list that
|
|
288
|
+
// no longer exists.
|
|
289
|
+
const [discovered, setDiscovered] = useState();
|
|
290
|
+
const discover = useMutation({
|
|
291
|
+
mutationFn: () => bridge.discover(connectorId),
|
|
292
|
+
onSuccess: (value) => setDiscovered((previous) => ({ run: (previous?.run ?? 0) + 1, value })),
|
|
293
|
+
});
|
|
294
|
+
return (_jsxs("div", { className: cn('rounded-md border border-dashed p-3', RULE), children: [_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsxs("button", { type: "button", onClick: () => discover.mutate(), disabled: discover.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: [discover.isPending ? (_jsx(Loader2, { size: 12, className: "animate-spin" })) : (_jsx(ScanSearch, { size: 12 })), discover.isPending ? 'Reading the source…' : 'Discover schema'] }), _jsx("span", { className: cn('text-[11px]', MUTED), children: "Reads the source and reports its columns. Creates nothing on its own." })] }), discover.error ? (_jsx("p", { className: "mt-2 text-[11px] text-red-600", children: discover.error instanceof Error ? discover.error.message : 'Could not read the source.' })) : null, discovered && (_jsx(DiscoveredSchema, { discovery: discovered.value, createType: bridge.createType }, discovered.run))] }));
|
|
295
|
+
}
|
|
296
|
+
function DiscoveredSchema({ discovery, createType, }) {
|
|
297
|
+
const [choices, setChoices] = useState(() => initialChoices(discovery.columns));
|
|
298
|
+
const { draft, problems } = proposalFrom(discovery, choices);
|
|
299
|
+
const setChoice = (index, next) => setChoices((current) => current.map((choice, position) => (position === index ? { ...choice, ...next } : choice)));
|
|
300
|
+
return (_jsxs("div", { className: "mt-3 space-y-3", children: [_jsx("p", { className: cn('text-[11px]', MUTED), children: discovery.caveat }), _jsx(DriftReport, { drift: discovery.drift, targetType: discovery.targetType }), discovery.columns.length === 0 ? (_jsx("p", { className: cn('text-[11px]', MUTED), children: "No columns came back." })) : (_jsxs("table", { className: "w-full text-left text-[11px]", children: [_jsx("thead", { className: cn('font-mono uppercase tracking-[0.14em]', MUTED), children: _jsxs("tr", { children: [_jsx("th", { className: "w-6 pb-1 font-normal", children: _jsx("span", { className: "sr-only", children: "Include" }) }), _jsx("th", { className: "pb-1 font-normal", children: "Column" }), _jsx("th", { className: "pb-1 font-normal", children: "Type" }), _jsx("th", { className: "pb-1 font-normal", children: "Null" }), _jsx("th", { className: "pb-1 font-normal", children: "Source" })] }) }), _jsx("tbody", { children: discovery.columns.map((column, index) => (_jsx(ColumnRow
|
|
301
|
+
// The source may legally return two columns of one name, so the
|
|
302
|
+
// position has to be part of the key: on its own the name would
|
|
303
|
+
// collide, and React would reuse one row's choice for the other.
|
|
304
|
+
, { column: column, choice: choices[index] ?? { include: false, type: '' }, onChange: (next) => setChoice(index, next) }, `${column.name}-${index}`))) })] })), problems.map((problem) => (_jsxs("p", { className: "flex items-start gap-1.5 text-[11px] text-amber-600", children: [_jsx(TriangleAlert, { size: 11, className: "mt-0.5 shrink-0", "aria-hidden": true }), problem] }, problem))), _jsx(Confirmation, { discovery: discovery, draft: draft, problems: problems, createType: createType })] }));
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* The act that creates the type — the only thing on this screen that writes.
|
|
308
|
+
*
|
|
309
|
+
* Its own component because it has three states and they are not variations on
|
|
310
|
+
* a button: nothing has been created yet, something has, or this console has no
|
|
311
|
+
* way to create anything and has to hand over the request instead.
|
|
312
|
+
*/
|
|
313
|
+
function Confirmation({ discovery, draft, problems, createType, }) {
|
|
314
|
+
const [created, setCreated] = useState(false);
|
|
315
|
+
const create = useMutation({
|
|
316
|
+
mutationFn: () => {
|
|
317
|
+
if (!createType)
|
|
318
|
+
return Promise.reject(new Error('This console cannot create types.'));
|
|
319
|
+
return createType(draft);
|
|
320
|
+
},
|
|
321
|
+
onSuccess: () => setCreated(true),
|
|
322
|
+
});
|
|
323
|
+
if (!createType)
|
|
324
|
+
return _jsx(UnwiredConfirmation, { draft: draft });
|
|
325
|
+
if (created) {
|
|
326
|
+
return (_jsxs("p", { className: "flex items-center gap-1.5 text-[11px] text-emerald-600", children: [_jsx(CircleCheck, { size: 11, "aria-hidden": true }), discovery.targetType, " now exists with ", draft.properties.length, " properties. Running this connector will load into it."] }));
|
|
327
|
+
}
|
|
328
|
+
return (_jsxs("div", { className: "space-y-1", children: [_jsx("button", { type: "button", onClick: () => create.mutate(), disabled: problems.length > 0 || create.isPending, 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: create.isPending
|
|
329
|
+
? 'Creating…'
|
|
330
|
+
: discovery.typeExists
|
|
331
|
+
? `Update ${discovery.targetType}`
|
|
332
|
+
: `Create ${discovery.targetType}` }), _jsx("p", { className: cn('text-[11px]', MUTED), children: discovery.typeExists
|
|
333
|
+
? 'Adds and retypes properties. Display names, descriptions and classifications somebody wrote are kept.'
|
|
334
|
+
: 'This is the act that creates the type. Nothing has been created up to here.' }), create.error ? (_jsx("p", { className: "text-[11px] text-red-600", children: create.error instanceof Error ? create.error.message : 'Could not create it.' })) : null] }));
|
|
335
|
+
}
|
|
336
|
+
/** One column, with the two decisions a person can make about it. */
|
|
337
|
+
function ColumnRow({ column, choice, onChange, }) {
|
|
338
|
+
return (_jsxs(_Fragment, { children: [_jsxs("tr", { className: cn('border-t', RULE), children: [_jsx("td", { className: "py-1 align-top", children: _jsx("input", { type: "checkbox", checked: choice.include, "aria-label": `Include ${column.name}`, onChange: (event) => onChange({ include: event.target.checked }) }) }), _jsx("td", { className: "py-1 align-top font-mono", children: column.name }), _jsxs("td", { className: "py-1 align-top", children: [_jsxs("select", { value: choice.type, "aria-label": `Type for ${column.name}`, onChange: (event) => {
|
|
339
|
+
const next = SCALAR_TYPES.find((scalar) => scalar === event.target.value);
|
|
340
|
+
onChange({ type: next ?? '' });
|
|
341
|
+
}, className: cn('rounded-sm border bg-transparent px-1 py-0.5 font-mono text-[11px]', RULE, choice.type === '' && 'text-amber-600'), children: [_jsx("option", { value: "", children: "not typed" }), SCALAR_TYPES.map((scalar) => (_jsx("option", { value: scalar, children: scalar }, scalar)))] }), column.confidence === 'inferred' && (_jsx("span", { className: cn('ml-1.5 font-mono text-[10px]', MUTED), children: "inferred" }))] }), _jsx("td", { className: cn('py-1 align-top font-mono', MUTED), children: column.nullable === null ? 'not stated' : column.nullable ? 'nullable' : 'not null' }), _jsx("td", { className: cn('py-1 align-top font-mono', MUTED), children: column.sourceType })] }), column.note && (_jsxs("tr", { children: [_jsx("td", {}), _jsx("td", { colSpan: 4, className: "pb-1.5 text-[11px] text-amber-600", children: column.note })] }))] }));
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* What the source says now against what the type says now.
|
|
345
|
+
*
|
|
346
|
+
* The part worth having. A first discovery happens once per source; drift
|
|
347
|
+
* happens for as long as the connector exists, and every one of these is silent
|
|
348
|
+
* today — an added column is dropped by the store, a removed one loads as null,
|
|
349
|
+
* and a retyped one is coerced into whatever the catalog still believes.
|
|
350
|
+
*/
|
|
351
|
+
function DriftReport({ drift, targetType }) {
|
|
352
|
+
if (!drift) {
|
|
353
|
+
return (_jsxs("p", { className: cn('text-[11px]', MUTED), children: [targetType, " does not exist yet, so there is nothing to compare against."] }));
|
|
354
|
+
}
|
|
355
|
+
const quiet = drift.added.length === 0 && drift.removed.length === 0 && drift.retyped.length === 0;
|
|
356
|
+
if (quiet) {
|
|
357
|
+
return (_jsxs("p", { className: "flex items-center gap-1.5 text-[11px] text-emerald-600", children: [_jsx(CircleCheck, { size: 11, "aria-hidden": true }), "The source still matches ", targetType, "."] }));
|
|
358
|
+
}
|
|
359
|
+
return (_jsxs("div", { className: "space-y-1 rounded-md border border-amber-300 bg-amber-50 p-2 dark:border-amber-900 dark:bg-amber-950/30", children: [_jsxs("p", { className: "font-mono text-[10px] uppercase tracking-[0.14em] text-amber-700 dark:text-amber-400", children: ["Drift since ", targetType, " was written down"] }), drift.added.length > 0 && (_jsxs("p", { className: "text-[11px] text-amber-700 dark:text-amber-300", children: ["New in the source, and dropped by every load until the type has them:", ' ', _jsx("span", { className: "font-mono", children: drift.added.join(', ') })] })), drift.removed.length > 0 && (_jsxs("p", { className: "text-[11px] text-amber-700 dark:text-amber-300", children: ["On the type, absent from the source, so they load as null:", ' ', _jsx("span", { className: "font-mono", children: drift.removed.join(', ') })] })), drift.retyped.map((change) => (_jsxs("p", { className: "text-[11px] text-amber-700 dark:text-amber-300", children: [_jsx("span", { className: "font-mono", children: change.property }), " is ", change.now, " in the source and", ' ', change.was, " here \u2014 every load coerces it, and a value that will not convert becomes null."] }, change.property)))] }));
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* The confirmation, for a console whose host did not wire one.
|
|
363
|
+
*
|
|
364
|
+
* The request is printed rather than the button being greyed out with a
|
|
365
|
+
* shrug. Creating a type is a `PUT` a person can make with a terminal, and a
|
|
366
|
+
* host that deliberately kept type creation out of its console — because the
|
|
367
|
+
* publish route is owned by an application principal, or because schema changes
|
|
368
|
+
* go through review — has a reader here who still needs the body somebody
|
|
369
|
+
* approved on this screen.
|
|
370
|
+
*/
|
|
371
|
+
function UnwiredConfirmation({ draft }) {
|
|
372
|
+
return (_jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: cn('text-[11px]', MUTED), children: "This console cannot create types \u2014 nothing is wired to the publish route. What was confirmed above is this request:" }), _jsx("pre", { className: cn('overflow-x-auto rounded-md border p-2 font-mono text-[10px]', RULE, 'bg-zinc-50 dark:bg-zinc-950'), children: `PUT /publish/${draft.name}/schema\n${JSON.stringify(draft, null, 2)}` })] }));
|
|
373
|
+
}
|
|
374
|
+
function ConnectorForm({ connector, transforms, connections, schemaDiscovery, onClose, onSaved, }) {
|
|
194
375
|
const client = useCatalogClient();
|
|
195
376
|
const [kind, setKind] = useState(toConnectorKind(connector?.kind ?? 'http'));
|
|
196
377
|
const [connectionId, setConnectionId] = useState(connector?.connectionId ?? INLINE_CONNECTION);
|
|
@@ -255,7 +436,7 @@ function ConnectorForm({ connector, transforms, connections, onClose, onSaved, }
|
|
|
255
436
|
return (_jsxs("form", { className: cn('mt-6 space-y-4 rounded-lg border p-4', RULE, PANEL), onSubmit: (event) => {
|
|
256
437
|
event.preventDefault();
|
|
257
438
|
save.mutate();
|
|
258
|
-
}, children: [_jsxs("div", { className: "grid gap-3 sm:grid-cols-3", children: [_jsx(TextField, { label: "Name", value: draft.name, onChange: (name) => setDraft({ ...draft, name }), placeholder: "Nightly fleet load" }), _jsx(TextField, { label: "Target object type", value: draft.targetType, onChange: (targetType) => setDraft({ ...draft, targetType }), placeholder: "e.g. Mvr" }), _jsx(SelectField, { label: "Source kind", ariaLabel: "Source kind", value: kind, onValueChange: (value) => setKind(toConnectorKind(value)), options: KIND_OPTIONS })] }), usesConnection(kind) && (_jsx(ConnectionPicker, { value: chosenConnection, options: connectionOptions, viaConnection: viaConnection, onChange: setConnectionId })), _jsx(SourceFields, { kind: kind, draft: source, onChange: setSource, viaConnection: viaConnection }), _jsx(ReadModeFields, { kind: kind, mode: mode, onModeChange: setMode, draft: source, onChange: setSource }), _jsxs("div", { className: "grid gap-3 sm:grid-cols-2", children: [!viaConnection && (_jsx(CredentialField, { kind: kind, value: draft.secretEnvVar, onChange: (secretEnvVar) => setDraft({ ...draft, secretEnvVar }) })), _jsx(SelectField, { label: "Transform", ariaLabel: "Transform", value: draft.transformId, onValueChange: (transformId) => setDraft({ ...draft, transformId }), options: [
|
|
439
|
+
}, children: [_jsxs("div", { className: "grid gap-3 sm:grid-cols-3", children: [_jsx(TextField, { label: "Name", value: draft.name, onChange: (name) => setDraft({ ...draft, name }), placeholder: "Nightly fleet load" }), _jsx(TextField, { label: "Target object type", value: draft.targetType, onChange: (targetType) => setDraft({ ...draft, targetType }), placeholder: "e.g. Mvr" }), _jsx(SelectField, { label: "Source kind", ariaLabel: "Source kind", value: kind, onValueChange: (value) => setKind(toConnectorKind(value)), options: KIND_OPTIONS })] }), usesConnection(kind) && (_jsx(ConnectionPicker, { value: chosenConnection, options: connectionOptions, viaConnection: viaConnection, onChange: setConnectionId })), schemaDiscovery && connector?.id && (_jsx(SchemaDiscoveryPanel, { connectorId: connector.id, bridge: schemaDiscovery })), _jsx(SourceFields, { kind: kind, draft: source, onChange: setSource, viaConnection: viaConnection }), _jsx(ReadModeFields, { kind: kind, mode: mode, onModeChange: setMode, draft: source, onChange: setSource }), _jsxs("div", { className: "grid gap-3 sm:grid-cols-2", children: [!viaConnection && (_jsx(CredentialField, { kind: kind, value: draft.secretEnvVar, onChange: (secretEnvVar) => setDraft({ ...draft, secretEnvVar }) })), _jsx(SelectField, { label: "Transform", ariaLabel: "Transform", value: draft.transformId, onValueChange: (transformId) => setDraft({ ...draft, transformId }), options: [
|
|
259
440
|
{
|
|
260
441
|
value: '',
|
|
261
442
|
label: 'No transform',
|
|
@@ -2,14 +2,6 @@ import type { SavedQuery } from '@dudousxd/nestjs-catalog/client';
|
|
|
2
2
|
export declare const savedQueryKeys: {
|
|
3
3
|
all: readonly ["catalog", "saved-queries"];
|
|
4
4
|
};
|
|
5
|
-
/**
|
|
6
|
-
* The saved-query list, and the form for adding to it.
|
|
7
|
-
*
|
|
8
|
-
* Saving asks for a cache TTL up front rather than defaulting to some global
|
|
9
|
-
* number, because only the person writing the query knows whether a
|
|
10
|
-
* five-minute-old answer is fine. Zero — never cache — is the default, so the
|
|
11
|
-
* surprising behaviour is the one you have to ask for.
|
|
12
|
-
*/
|
|
13
5
|
export declare function SavedQueryPanel({ currentSql, onLoad, }: {
|
|
14
6
|
currentSql: string;
|
|
15
7
|
onLoad: (query: SavedQuery) => void;
|
package/dist/SavedQueryPanel.js
CHANGED
|
@@ -5,6 +5,8 @@ import { useMemo, useState } from 'react';
|
|
|
5
5
|
import { registeredChartLibraries } from './charts/registry';
|
|
6
6
|
import { cn } from './cn';
|
|
7
7
|
import { useCatalogClient } from './context';
|
|
8
|
+
import { ShareBadge, ShareControl } from './sharing';
|
|
9
|
+
import { Select } from './ui/select';
|
|
8
10
|
import { Tooltip } from './ui/tooltip';
|
|
9
11
|
const MUTED = 'text-zinc-400 dark:text-zinc-500';
|
|
10
12
|
const RULE = 'border-zinc-200 dark:border-zinc-800';
|
|
@@ -18,7 +20,29 @@ export const savedQueryKeys = {
|
|
|
18
20
|
* number, because only the person writing the query knows whether a
|
|
19
21
|
* five-minute-old answer is fine. Zero — never cache — is the default, so the
|
|
20
22
|
* surprising behaviour is the one you have to ask for.
|
|
23
|
+
*
|
|
24
|
+
* The list also carries the sharing state and the way back out of it. "Let
|
|
25
|
+
* other apps embed this" is a checkbox on the save form, which used to be the
|
|
26
|
+
* ONLY place `shared` could be set: a query shared by a slip of the mouse
|
|
27
|
+
* stayed shared, because no screen afterwards could reach the flag and the only
|
|
28
|
+
* way to revoke the grant was deleting the query. The badge is why a mistake is
|
|
29
|
+
* noticed at all — it renders without hovering, so a shared query announces
|
|
30
|
+
* itself in the list rather than waiting to be discovered from the embed API.
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* The kinds a visualization can be, as the single list both the picker and the
|
|
34
|
+
* narrowing read. A `as 'table'` cast — which is what this replaces — claims a
|
|
35
|
+
* value the compiler then stops checking, and a new kind added to the union
|
|
36
|
+
* would not have shown up in the dropdown.
|
|
21
37
|
*/
|
|
38
|
+
const CHART_KINDS = ['table', 'bar', 'line', 'area', 'number'];
|
|
39
|
+
function asChartKind(value) {
|
|
40
|
+
const found = CHART_KINDS.find((kind) => kind === value);
|
|
41
|
+
// The picker only ever offers these, so the fallback is unreachable in
|
|
42
|
+
// practice; it is here because narrowing a string has to end somewhere, and
|
|
43
|
+
// a table is the kind that renders any result.
|
|
44
|
+
return found ?? 'table';
|
|
45
|
+
}
|
|
22
46
|
export function SavedQueryPanel({ currentSql, onLoad, }) {
|
|
23
47
|
const client = useCatalogClient();
|
|
24
48
|
const queryClient = useQueryClient();
|
|
@@ -46,6 +70,17 @@ export function SavedQueryPanel({ currentSql, onLoad, }) {
|
|
|
46
70
|
mutationFn: (id) => client.deleteSavedQuery(id),
|
|
47
71
|
onSuccess: invalidate,
|
|
48
72
|
});
|
|
73
|
+
/**
|
|
74
|
+
* The first call site `updateSavedQuery` has ever had.
|
|
75
|
+
*
|
|
76
|
+
* It was on the client, typed to take the whole of `Partial<SaveQueryInput>`
|
|
77
|
+
* — `shared` included — and reachable from nothing. A method no screen calls
|
|
78
|
+
* is a capability the product does not have, whatever the type says.
|
|
79
|
+
*/
|
|
80
|
+
const share = useMutation({
|
|
81
|
+
mutationFn: ({ id, shared }) => client.updateSavedQuery(id, { shared }),
|
|
82
|
+
onSuccess: invalidate,
|
|
83
|
+
});
|
|
49
84
|
const grouped = useMemo(() => {
|
|
50
85
|
const byFolder = new Map();
|
|
51
86
|
for (const query of saved) {
|
|
@@ -59,20 +94,24 @@ export function SavedQueryPanel({ currentSql, onLoad, }) {
|
|
|
59
94
|
return (_jsxs("div", { className: cn('border-t', RULE), children: [_jsxs("div", { className: "flex items-center justify-between px-3 py-2", children: [_jsx("span", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Saved" }), _jsx("button", { type: "button", onClick: () => setSaving((open) => !open), disabled: currentSql.trim().length === 0, className: cn('rounded-sm p-1 disabled:opacity-30', MUTED, 'hover:bg-zinc-100 hover:text-zinc-900 dark:hover:bg-zinc-800'), "aria-label": "Save the current query", children: _jsx(Bookmark, { size: 12 }) })] }), saving && (_jsxs("form", { className: "space-y-1.5 px-3 pb-3", onSubmit: (e) => {
|
|
60
95
|
e.preventDefault();
|
|
61
96
|
save.mutate();
|
|
62
|
-
}, children: [_jsx("input", { value: draft.name, onChange: (e) => setDraft({ ...draft, name: e.target.value }), placeholder: "Name", "aria-label": "Query name", className: cn('w-full rounded-md border bg-white px-2 py-1 text-xs outline-none dark:bg-zinc-900', RULE, 'focus:border-sky-500') }), _jsx("input", { value: draft.folder ?? '', onChange: (e) => setDraft({ ...draft, folder: e.target.value }), placeholder: "Folder (optional)", "aria-label": "Folder", className: cn('w-full rounded-md border bg-white px-2 py-1 text-xs outline-none dark:bg-zinc-900', RULE, 'focus:border-sky-500') }), _jsxs("div", { className: "flex gap-1.5", children: [_jsx(
|
|
97
|
+
}, children: [_jsx("input", { value: draft.name, onChange: (e) => setDraft({ ...draft, name: e.target.value }), placeholder: "Name", "aria-label": "Query name", className: cn('w-full rounded-md border bg-white px-2 py-1 text-xs outline-none dark:bg-zinc-900', RULE, 'focus:border-sky-500') }), _jsx("input", { value: draft.folder ?? '', onChange: (e) => setDraft({ ...draft, folder: e.target.value }), placeholder: "Folder (optional)", "aria-label": "Folder", className: cn('w-full rounded-md border bg-white px-2 py-1 text-xs outline-none dark:bg-zinc-900', RULE, 'focus:border-sky-500') }), _jsxs("div", { className: "flex gap-1.5", children: [_jsx(Select, { value: draft.visualization?.kind ?? 'table', onValueChange: (kind) => setDraft({
|
|
63
98
|
...draft,
|
|
64
|
-
visualization: {
|
|
65
|
-
|
|
66
|
-
kind: e.target.value,
|
|
67
|
-
},
|
|
68
|
-
}), "aria-label": "Chart type", className: cn('min-w-0 flex-1 rounded-md border bg-white px-1 py-1 text-[11px] outline-none dark:bg-zinc-900', RULE), children: ['table', 'bar', 'line', 'area', 'number'].map((kind) => (_jsx("option", { value: kind, children: kind }, kind))) }), _jsx("select", { value: draft.visualization?.library ?? 'css', onChange: (e) => setDraft({
|
|
99
|
+
visualization: { ...(draft.visualization ?? {}), kind: asChartKind(kind) },
|
|
100
|
+
}), ariaLabel: "Chart type", className: "min-w-0 flex-1", options: CHART_KINDS.map((kind) => ({ value: kind, label: kind })) }), _jsx(Select, { value: draft.visualization?.library ?? '', onValueChange: (library) => setDraft({
|
|
69
101
|
...draft,
|
|
70
102
|
visualization: {
|
|
71
103
|
...(draft.visualization ?? { kind: 'table' }),
|
|
72
|
-
|
|
104
|
+
// Empty means "the built-in renderer", stored as absent.
|
|
105
|
+
...(library ? { library } : { library: undefined }),
|
|
73
106
|
},
|
|
74
|
-
}),
|
|
107
|
+
}), ariaLabel: "Chart library", className: "min-w-0 flex-1", options: [
|
|
108
|
+
{ value: '', label: 'built-in', hint: 'no dependency' },
|
|
109
|
+
...registeredChartLibraries().map((library) => ({
|
|
110
|
+
value: library,
|
|
111
|
+
label: library,
|
|
112
|
+
})),
|
|
113
|
+
] })] }), _jsxs("label", { className: cn('flex items-center gap-1.5 text-[11px]', MUTED), children: [_jsx("input", { type: "checkbox", checked: draft.shared ?? false, onChange: (e) => setDraft({ ...draft, shared: e.target.checked }), className: "accent-sky-500" }), "Let other apps embed this"] }), _jsxs("label", { className: cn('flex items-center gap-1.5 text-[11px]', MUTED), children: [_jsx(Timer, { size: 11 }), "Reuse the result for", _jsx("input", { type: "number", min: 0, value: draft.cacheTtlSeconds ?? 0, onChange: (e) => setDraft({ ...draft, cacheTtlSeconds: Number(e.target.value) }), "aria-label": "Cache seconds", className: cn('w-14 rounded-md border bg-white px-1 py-0.5 text-right text-[11px] outline-none dark:bg-zinc-900', RULE) }), "s"] }), _jsx("button", { type: "submit", disabled: save.isPending || draft.name.trim().length === 0, className: "w-full rounded-md bg-zinc-950 px-2 py-1 text-xs text-zinc-50 disabled:opacity-40 dark:bg-zinc-100 dark:text-zinc-950", children: save.isPending ? 'Saving…' : 'Save this query' }), save.error && (_jsx("p", { className: "text-[11px] text-red-600", children: save.error instanceof Error ? save.error.message : 'Could not save.' }))] })), _jsxs("div", { className: "max-h-64 overflow-y-auto px-2 pb-2", children: [saved.length === 0 && (_jsx("p", { className: cn('px-2 py-3 text-center text-[11px]', MUTED), children: "Nothing saved yet." })), grouped.map(([folder, list]) => (_jsxs("div", { className: "mb-2", children: [_jsx("div", { className: cn('px-2 py-1 font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: folder }), list.map((query) => (_jsxs("div", { className: "group flex items-center", children: [_jsx(Tooltip, { side: "right", content: query.description ??
|
|
75
114
|
(query.cacheTtlSeconds > 0
|
|
76
115
|
? `Results reused for ${query.cacheTtlSeconds}s.`
|
|
77
|
-
: 'Never cached — runs every time.'), children: _jsxs("button", { type: "button", onClick: () => onLoad(query), className: "min-w-0 flex-1 truncate rounded-md px-2 py-1 text-left text-[11px] hover:bg-zinc-50 dark:hover:bg-zinc-800", children: [query.name, query.cacheTtlSeconds > 0 && (_jsxs("span", { className: cn('ml-1 font-mono text-[9px]', MUTED), children: [query.cacheTtlSeconds, "s"] }))] }) }), _jsx(Tooltip, { content: "Download as CSV", children: _jsx("a", { href: client.exportUrl(query.id), className: cn('rounded-sm p-1 opacity-0 group-hover:opacity-100', MUTED), "aria-label": `Export ${query.name}`, children: _jsx(Download, { size: 11 }) }) }), _jsx("button", { type: "button", onClick: () => remove.mutate(query.id), className: cn('rounded-sm p-1 opacity-0 group-hover:opacity-100 hover:text-red-600', MUTED), "aria-label": `Delete ${query.name}`, children: _jsx(Trash2, { size: 11 }) })] }, query.id)))] }, folder)))] })] }));
|
|
116
|
+
: 'Never cached — runs every time.'), children: _jsxs("button", { type: "button", onClick: () => onLoad(query), className: "min-w-0 flex-1 truncate rounded-md px-2 py-1 text-left text-[11px] hover:bg-zinc-50 dark:hover:bg-zinc-800", children: [query.name, query.cacheTtlSeconds > 0 && (_jsxs("span", { className: cn('ml-1 font-mono text-[9px]', MUTED), children: [query.cacheTtlSeconds, "s"] }))] }) }), query.shared && _jsx(ShareBadge, { shared: true, className: "mr-1" }), _jsx(ShareControl, { layout: "row", kind: "query", shared: query.shared, pending: share.isPending, name: query.name, onChange: (shared) => share.mutate({ id: query.id, shared }), className: cn('opacity-0 group-hover:opacity-100 focus-visible:opacity-100', MUTED) }), _jsx(Tooltip, { content: "Download as CSV", children: _jsx("a", { href: client.exportUrl(query.id), className: cn('rounded-sm p-1 opacity-0 group-hover:opacity-100', MUTED), "aria-label": `Export ${query.name}`, children: _jsx(Download, { size: 11 }) }) }), _jsx("button", { type: "button", onClick: () => remove.mutate(query.id), className: cn('rounded-sm p-1 opacity-0 group-hover:opacity-100 hover:text-red-600', MUTED), "aria-label": `Delete ${query.name}`, children: _jsx(Trash2, { size: 11 }) })] }, query.id)))] }, folder))), share.error !== null && (_jsx("p", { className: "px-2 py-1 text-[11px] text-red-600", children: share.error instanceof Error ? share.error.message : 'Could not change sharing.' }))] })] }));
|
|
78
117
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { CatalogQueryResult, QueryVisualization } from '@dudousxd/nestjs-catalog/client';
|
|
2
|
+
/**
|
|
3
|
+
* A result plus a visualization, drawn.
|
|
4
|
+
*
|
|
5
|
+
* Lifted out of `DashboardBoard`'s `CardBody` when the embed components needed
|
|
6
|
+
* the same thing, and lifted rather than copied on purpose: "how a bar chart is
|
|
7
|
+
* drawn" has to have exactly one answer. Two implementations do not disagree on
|
|
8
|
+
* the day they are written — they disagree six months later, when somebody
|
|
9
|
+
* tightens the empty state or changes which column a number reads, and the
|
|
10
|
+
* console and the embedded copy of the same dashboard start showing different
|
|
11
|
+
* things to different people with no way to tell which is right.
|
|
12
|
+
*
|
|
13
|
+
* What is NOT here is the decision about which library draws: that is
|
|
14
|
+
* `visualizationFor`, and it stays with the caller, because the console has a
|
|
15
|
+
* per-card override and an embed deliberately does not.
|
|
16
|
+
*/
|
|
17
|
+
export interface ChartBodyProps {
|
|
18
|
+
result: CatalogQueryResult;
|
|
19
|
+
/**
|
|
20
|
+
* Already resolved — pass what `visualizationFor` returned, not the saved
|
|
21
|
+
* query's raw value, or a card's library override is silently dropped.
|
|
22
|
+
*/
|
|
23
|
+
visualization: QueryVisualization;
|
|
24
|
+
/** Rough pixel height the surrounding box has to spare. */
|
|
25
|
+
height?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Cap the table preview.
|
|
28
|
+
*
|
|
29
|
+
* Absent means "show what you were given", which is what an embed wants: a
|
|
30
|
+
* host that asked for a table and got five of its twelve columns, with no
|
|
31
|
+
* control to see the rest, has been handed a broken component. The console
|
|
32
|
+
* passes a cap because a dashboard card is a PREVIEW — the whole answer lives
|
|
33
|
+
* one click away on the query screen, and a card you cannot read at a glance
|
|
34
|
+
* is not a card.
|
|
35
|
+
*/
|
|
36
|
+
maxColumns?: number;
|
|
37
|
+
maxRows?: number;
|
|
38
|
+
}
|
|
39
|
+
export declare function ChartBody({ result, visualization, height, maxColumns, maxRows, }: ChartBodyProps): import("react/jsx-runtime").JSX.Element;
|