@dudousxd/nestjs-catalog-react 0.7.1 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/DashboardBoard.js +54 -10
- package/dist/charts/registry.d.ts +19 -0
- package/dist/charts/registry.js +22 -0
- package/dist/ui/tabs.d.ts +11 -1
- package/dist/ui/tabs.js +2 -2
- package/package.json +2 -2
package/dist/DashboardBoard.js
CHANGED
|
@@ -6,7 +6,7 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
|
6
6
|
import { Download, GripVertical, LayoutGrid, Plus, RefreshCw, Trash2 } from 'lucide-react';
|
|
7
7
|
import { useMemo, useState } from 'react';
|
|
8
8
|
import { CssBarChart } from './charts/css';
|
|
9
|
-
import { getChartRenderer } from './charts/registry';
|
|
9
|
+
import { getChartRenderer, registeredChartLibraries, visualizationFor } from './charts/registry';
|
|
10
10
|
import { ChartEmpty, ChartFailed, ChartSkeleton } from './charts/skeleton';
|
|
11
11
|
import { cn } from './cn';
|
|
12
12
|
import { useCatalogClient } from './context';
|
|
@@ -97,6 +97,23 @@ export function DashboardBoard() {
|
|
|
97
97
|
cards: selected.cards.map((card) => (card.id === cardId ? { ...card, width } : card)),
|
|
98
98
|
});
|
|
99
99
|
}
|
|
100
|
+
function setLibrary(cardId, library) {
|
|
101
|
+
if (!selected)
|
|
102
|
+
return;
|
|
103
|
+
update.mutate({
|
|
104
|
+
id: selected.id,
|
|
105
|
+
cards: selected.cards.map((card) =>
|
|
106
|
+
// The key is REMOVED rather than set to undefined when the card goes
|
|
107
|
+
// back to following the query: `library: undefined` survives into the
|
|
108
|
+
// stored JSON on some drivers and then reads as "this card chose the
|
|
109
|
+
// built-in", which is a different statement.
|
|
110
|
+
card.id === cardId
|
|
111
|
+
? library
|
|
112
|
+
? { ...card, library }
|
|
113
|
+
: (({ library: _following, ...rest }) => rest)(card)
|
|
114
|
+
: card),
|
|
115
|
+
});
|
|
116
|
+
}
|
|
100
117
|
function addCard(savedQueryId) {
|
|
101
118
|
if (!selected)
|
|
102
119
|
return;
|
|
@@ -130,7 +147,7 @@ export function DashboardBoard() {
|
|
|
130
147
|
.sort((a, b) => a.position - b.position)
|
|
131
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]
|
|
132
149
|
.sort((a, b) => a.position - b.position)
|
|
133
|
-
.map((card) => (_jsx(SortableCard, { id: card.id, savedQueryId: card.savedQueryId, width: card.width, onRemove: () => removeCard(card.id), onWidth: (w) => setWidth(card.id, w) }, card.id))) }) }) }))] })) })] }) }));
|
|
150
|
+
.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))) }) }) }))] })) })] }) }));
|
|
134
151
|
}
|
|
135
152
|
/**
|
|
136
153
|
* A card you can pick up.
|
|
@@ -139,7 +156,7 @@ export function DashboardBoard() {
|
|
|
139
156
|
* of buttons and a link, and making the entire surface draggable means every
|
|
140
157
|
* click starts a drag the user did not ask for.
|
|
141
158
|
*/
|
|
142
|
-
function SortableCard({ id, savedQueryId, width, onRemove, onWidth, }) {
|
|
159
|
+
function SortableCard({ id, savedQueryId, width, library, onRemove, onWidth, onLibrary, }) {
|
|
143
160
|
const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({
|
|
144
161
|
id,
|
|
145
162
|
});
|
|
@@ -147,7 +164,7 @@ function SortableCard({ id, savedQueryId, width, onRemove, onWidth, }) {
|
|
|
147
164
|
// A grid item defaults to `min-width: auto`, so a chart wider than its
|
|
148
165
|
// column pushes the column out instead of being constrained by it —
|
|
149
166
|
// the same rule that made the nav overflow the page.
|
|
150
|
-
'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, onRemove: onRemove, onWidth: onWidth, 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 }) }) }) }));
|
|
167
|
+
'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 }) }) }) }));
|
|
151
168
|
}
|
|
152
169
|
/**
|
|
153
170
|
* The width an operator chose, applied only where there are columns to spend.
|
|
@@ -189,10 +206,10 @@ function CardWidthPicker({ width, onWidth, }) {
|
|
|
189
206
|
* query returns and offering it before the first run promises a file that does
|
|
190
207
|
* not exist yet.
|
|
191
208
|
*/
|
|
192
|
-
function CardToolbar({ width, onWidth, cached, fetching, exportHref, onRefresh, onRemove, }) {
|
|
193
|
-
return (_jsxs("div", { className: "flex shrink-0 items-center gap-0.5", children: [onWidth && _jsx(CardWidthPicker, { width: width, onWidth: onWidth }), _jsx(Tooltip, { content: cached ? 'Cached — refetch anyway' : 'Run again', children: _jsx("button", { type: "button", onClick: onRefresh, className: cn('rounded-sm p-1 hover:bg-zinc-100 dark:hover:bg-zinc-800', MUTED), "aria-label": "Refresh card", children: _jsx(RefreshCw, { size: 11, className: fetching ? 'animate-spin' : undefined }) }) }), exportHref && (_jsx(Tooltip, { content: "Download as CSV", children: _jsx("a", { href: exportHref, className: cn('rounded-sm p-1 hover:bg-zinc-100 dark:hover:bg-zinc-800', MUTED), "aria-label": "Export card", children: _jsx(Download, { size: 11 }) }) })), _jsx("button", { type: "button", onClick: onRemove, className: cn('rounded-sm p-1 hover:text-red-600', MUTED), "aria-label": "Remove card", children: _jsx(Trash2, { size: 11 }) })] }));
|
|
209
|
+
function CardToolbar({ width, onWidth, library, queryLibrary, onLibrary, cached, fetching, exportHref, onRefresh, onRemove, }) {
|
|
210
|
+
return (_jsxs("div", { className: "flex shrink-0 items-center gap-0.5", children: [onWidth && _jsx(CardWidthPicker, { width: width, onWidth: onWidth }), onLibrary && (_jsx(CardLibraryPicker, { library: library, queryLibrary: queryLibrary, onLibrary: onLibrary })), _jsx(Tooltip, { content: cached ? 'Cached — refetch anyway' : 'Run again', children: _jsx("button", { type: "button", onClick: onRefresh, className: cn('rounded-sm p-1 hover:bg-zinc-100 dark:hover:bg-zinc-800', MUTED), "aria-label": "Refresh card", children: _jsx(RefreshCw, { size: 11, className: fetching ? 'animate-spin' : undefined }) }) }), exportHref && (_jsx(Tooltip, { content: "Download as CSV", children: _jsx("a", { href: exportHref, className: cn('rounded-sm p-1 hover:bg-zinc-100 dark:hover:bg-zinc-800', MUTED), "aria-label": "Export card", children: _jsx(Download, { size: 11 }) }) })), _jsx("button", { type: "button", onClick: onRemove, className: cn('rounded-sm p-1 hover:text-red-600', MUTED), "aria-label": "Remove card", children: _jsx(Trash2, { size: 11 }) })] }));
|
|
194
211
|
}
|
|
195
|
-
function Card({ savedQueryId, width, onRemove, onWidth, dragHandle, }) {
|
|
212
|
+
function Card({ savedQueryId, width, library, onRemove, onWidth, onLibrary, dragHandle, }) {
|
|
196
213
|
const client = useCatalogClient();
|
|
197
214
|
const { data, isPending, isFetching, refetch, error } = useQuery({
|
|
198
215
|
queryKey: dashboardKeys.card(savedQueryId),
|
|
@@ -212,10 +229,14 @@ function Card({ savedQueryId, width, onRemove, onWidth, dragHandle, }) {
|
|
|
212
229
|
staleTime: 60_000,
|
|
213
230
|
});
|
|
214
231
|
const pendingKind = saved.find((query) => query.id === savedQueryId)?.visualization?.kind ?? 'table';
|
|
215
|
-
return (_jsxs("div", { className: cn('h-full rounded-lg border p-3 transition-shadow', RULE, PANEL), children: [_jsxs("div", { className: "flex items-start justify-between gap-2", children: [dragHandle, _jsxs("div", { className: "min-w-0 flex-1", children: [_jsx("h3", { className: "truncate text-sm font-medium", children: data?.savedQuery.name ?? '…' }), data && (_jsxs("p", { className: cn('font-mono text-[10px]', MUTED), children: [data.result.rowCount, " rows", data.result.cached ? ' · cached' : ` · ${data.result.elapsedMs}ms`] }))] }), _jsx(CardToolbar, { width: width, onWidth: onWidth,
|
|
232
|
+
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
|
+
? { 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 })] }));
|
|
216
235
|
}
|
|
217
|
-
function CardBody({ query, result, }) {
|
|
218
|
-
|
|
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);
|
|
219
240
|
// Held at the chart's own height rather than collapsing to one line, so a
|
|
220
241
|
// card that matched nothing does not resize the grid around it — and said in
|
|
221
242
|
// words, because "no rows" beside a skeleton-shaped hole is the one reading
|
|
@@ -258,3 +279,26 @@ function MiniTable({ result }) {
|
|
|
258
279
|
}, [rows, shown]);
|
|
259
280
|
return (_jsx(DataTable, { data: rows, columns: columns, numeric: (id) => numericColumns.has(id), density: "text-[11px]" }));
|
|
260
281
|
}
|
|
282
|
+
/**
|
|
283
|
+
* Which chart library draws this card.
|
|
284
|
+
*
|
|
285
|
+
* On the card rather than only on the saved query, because the two answer
|
|
286
|
+
* different questions: the query says how this ANSWER is best drawn wherever it
|
|
287
|
+
* appears, and the card says how it should look HERE, beside the other cards on
|
|
288
|
+
* this board. A board mixing two libraries' idea of a bar reads as two boards,
|
|
289
|
+
* and fixing that by editing the saved query would change it everywhere else
|
|
290
|
+
* the query is used.
|
|
291
|
+
*
|
|
292
|
+
* A select rather than a button group — unlike width, the options are whatever
|
|
293
|
+
* the host registered, so there is no fixed small set to lay out, and the
|
|
294
|
+
* current value still has to be readable while arranging.
|
|
295
|
+
*/
|
|
296
|
+
function CardLibraryPicker({ library, queryLibrary, onLibrary, }) {
|
|
297
|
+
// Only what the host actually registered. Offering a library nobody
|
|
298
|
+
// installed would be offering a choice that silently degrades to the
|
|
299
|
+
// built-in — the picker would say one thing and the card draw another.
|
|
300
|
+
const available = registeredChartLibraries();
|
|
301
|
+
if (available.length === 0)
|
|
302
|
+
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)))] }) }));
|
|
304
|
+
}
|
|
@@ -32,3 +32,22 @@ export declare function seriesFrom(result: CatalogQueryResult, visualization: Qu
|
|
|
32
32
|
};
|
|
33
33
|
/** A palette that works in both themes, so a renderer need not invent one. */
|
|
34
34
|
export declare const CHART_COLORS: string[];
|
|
35
|
+
/**
|
|
36
|
+
* Which library draws a card, given the two places that can say.
|
|
37
|
+
*
|
|
38
|
+
* Here rather than inside the board, so the precedence is one named thing a
|
|
39
|
+
* test can hold — the alternative was two lines inside a component that needs a
|
|
40
|
+
* query client and a transport to render, and a test that mirrors them can
|
|
41
|
+
* drift from them silently.
|
|
42
|
+
*
|
|
43
|
+
* The card wins because it is the more specific statement: it says how this
|
|
44
|
+
* answer should look on THIS board, while the query says how it looks wherever
|
|
45
|
+
* it appears. Reading them the other way round means editing one board changes
|
|
46
|
+
* every other board that uses the same query.
|
|
47
|
+
*
|
|
48
|
+
* When neither chose, the key is ABSENT rather than explicitly undefined. The
|
|
49
|
+
* two behave identically at the lookup, but a card is stored as JSON and "the
|
|
50
|
+
* key is there and empty" is a different statement from "nobody chose" the
|
|
51
|
+
* moment anything else reads it.
|
|
52
|
+
*/
|
|
53
|
+
export declare function visualizationFor(saved: QueryVisualization | undefined, cardLibrary: string | undefined): QueryVisualization;
|
package/dist/charts/registry.js
CHANGED
|
@@ -58,3 +58,25 @@ export function seriesFrom(result, visualization) {
|
|
|
58
58
|
}
|
|
59
59
|
/** A palette that works in both themes, so a renderer need not invent one. */
|
|
60
60
|
export const CHART_COLORS = ['#8b5cf6', '#10b981', '#f59e0b', '#0ea5e9', '#f43f5e'];
|
|
61
|
+
/**
|
|
62
|
+
* Which library draws a card, given the two places that can say.
|
|
63
|
+
*
|
|
64
|
+
* Here rather than inside the board, so the precedence is one named thing a
|
|
65
|
+
* test can hold — the alternative was two lines inside a component that needs a
|
|
66
|
+
* query client and a transport to render, and a test that mirrors them can
|
|
67
|
+
* drift from them silently.
|
|
68
|
+
*
|
|
69
|
+
* The card wins because it is the more specific statement: it says how this
|
|
70
|
+
* answer should look on THIS board, while the query says how it looks wherever
|
|
71
|
+
* it appears. Reading them the other way round means editing one board changes
|
|
72
|
+
* every other board that uses the same query.
|
|
73
|
+
*
|
|
74
|
+
* When neither chose, the key is ABSENT rather than explicitly undefined. The
|
|
75
|
+
* two behave identically at the lookup, but a card is stored as JSON and "the
|
|
76
|
+
* key is there and empty" is a different statement from "nobody chose" the
|
|
77
|
+
* moment anything else reads it.
|
|
78
|
+
*/
|
|
79
|
+
export function visualizationFor(saved, cardLibrary) {
|
|
80
|
+
const base = saved ?? { kind: 'table' };
|
|
81
|
+
return cardLibrary ? { ...base, library: cardLibrary } : base;
|
|
82
|
+
}
|
package/dist/ui/tabs.d.ts
CHANGED
|
@@ -24,11 +24,21 @@ export declare function TabsList({ children, className, ref, }: {
|
|
|
24
24
|
*/
|
|
25
25
|
ref?: Ref<HTMLDivElement>;
|
|
26
26
|
}): import("react/jsx-runtime").JSX.Element;
|
|
27
|
-
export declare function TabsTab({ value, children, className, }: {
|
|
27
|
+
export declare function TabsTab({ value, children, className, ref, }: {
|
|
28
28
|
value: string;
|
|
29
29
|
children: ReactNode;
|
|
30
30
|
/** For a caller whose strip has its own metrics — the console nav is taller. */
|
|
31
31
|
className?: string;
|
|
32
|
+
/**
|
|
33
|
+
* For a caller that has to bring the selected tab into view.
|
|
34
|
+
*
|
|
35
|
+
* Worth the prop rather than letting the caller render a marker element
|
|
36
|
+
* inside the tab: a zero-size `sr-only` marker is `position: absolute`, which
|
|
37
|
+
* escapes the strip's `overflow-x` clipping and reports the strip's full
|
|
38
|
+
* scroll extent as the DOCUMENT's width. The page then scrolls sideways —
|
|
39
|
+
* which is the bug this scrolling was introduced to fix.
|
|
40
|
+
*/
|
|
41
|
+
ref?: Ref<HTMLButtonElement>;
|
|
32
42
|
}): import("react/jsx-runtime").JSX.Element;
|
|
33
43
|
export declare function TabsPanel({ value, children, className, }: {
|
|
34
44
|
value: string;
|
package/dist/ui/tabs.js
CHANGED
|
@@ -24,8 +24,8 @@ export function Tabs({ value, onValueChange, children, className, }) {
|
|
|
24
24
|
export function TabsList({ children, className, ref, }) {
|
|
25
25
|
return (_jsx(BaseTabs.List, { ref: ref, className: cn('flex gap-1 border-b border-zinc-200 dark:border-zinc-800', className), children: children }));
|
|
26
26
|
}
|
|
27
|
-
export function TabsTab({ value, children, className, }) {
|
|
28
|
-
return (_jsx(BaseTabs.Tab, { value: value, className: cn('flex items-center gap-1.5 border-b-2 px-3 py-2 text-sm transition-colors outline-none', 'border-transparent text-zinc-500', 'hover:text-zinc-950 dark:hover:text-zinc-50', 'focus-visible:ring-2 focus-visible:ring-sky-500/30', 'data-[selected]:border-sky-600 data-[selected]:text-zinc-950', 'dark:data-[selected]:text-zinc-50', className), children: children }));
|
|
27
|
+
export function TabsTab({ value, children, className, ref, }) {
|
|
28
|
+
return (_jsx(BaseTabs.Tab, { ref: ref, value: value, className: cn('flex items-center gap-1.5 border-b-2 px-3 py-2 text-sm transition-colors outline-none', 'border-transparent text-zinc-500', 'hover:text-zinc-950 dark:hover:text-zinc-50', 'focus-visible:ring-2 focus-visible:ring-sky-500/30', 'data-[selected]:border-sky-600 data-[selected]:text-zinc-950', 'dark:data-[selected]:text-zinc-50', className), children: children }));
|
|
29
29
|
}
|
|
30
30
|
export function TabsPanel({ value, children, className, }) {
|
|
31
31
|
// Not `keepMounted`: a panel holding a half-typed connector form should keep
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dudousxd/nestjs-catalog-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Ready-made React screens for @dudousxd/nestjs-catalog — a model manager and a generic object explorer you can drop into your own app shell.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Davide Carvalho",
|
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
"@tiptap/pm": "3.29.2",
|
|
107
107
|
"tiptap-markdown": "0.9.0",
|
|
108
108
|
"@tiptap/core": "3.29.2",
|
|
109
|
-
"@dudousxd/nestjs-catalog": "0.
|
|
109
|
+
"@dudousxd/nestjs-catalog": "0.5.0"
|
|
110
110
|
},
|
|
111
111
|
"dependencies": {
|
|
112
112
|
"clsx": "2.1.1",
|