@dudousxd/nestjs-catalog-react 0.7.2 → 0.9.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/DashboardBoard.d.ts +22 -0
- package/dist/DashboardBoard.js +134 -69
- package/dist/GovernanceTimeline.js +11 -1
- 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/charts/registry.d.ts +19 -0
- package/dist/charts/registry.js +22 -0
- package/dist/context.d.ts +71 -0
- package/dist/context.js +20 -3
- 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/index.d.ts +3 -1
- package/dist/index.js +21 -1
- package/dist/routes.d.ts +25 -1
- package/dist/routes.js +25 -1
- package/dist/sharing.d.ts +81 -0
- package/dist/sharing.js +72 -0
- 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
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
server
|
|
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
|
|
package/dist/DashboardBoard.d.ts
CHANGED
|
@@ -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;
|
package/dist/DashboardBoard.js
CHANGED
|
@@ -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 {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
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 {
|
|
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: () => {
|
|
@@ -97,6 +113,23 @@ export function DashboardBoard() {
|
|
|
97
113
|
cards: selected.cards.map((card) => (card.id === cardId ? { ...card, width } : card)),
|
|
98
114
|
});
|
|
99
115
|
}
|
|
116
|
+
function setLibrary(cardId, library) {
|
|
117
|
+
if (!selected)
|
|
118
|
+
return;
|
|
119
|
+
update.mutate({
|
|
120
|
+
id: selected.id,
|
|
121
|
+
cards: selected.cards.map((card) =>
|
|
122
|
+
// The key is REMOVED rather than set to undefined when the card goes
|
|
123
|
+
// back to following the query: `library: undefined` survives into the
|
|
124
|
+
// stored JSON on some drivers and then reads as "this card chose the
|
|
125
|
+
// built-in", which is a different statement.
|
|
126
|
+
card.id === cardId
|
|
127
|
+
? library
|
|
128
|
+
? { ...card, library }
|
|
129
|
+
: (({ library: _following, ...rest }) => rest)(card)
|
|
130
|
+
: card),
|
|
131
|
+
});
|
|
132
|
+
}
|
|
100
133
|
function addCard(savedQueryId) {
|
|
101
134
|
if (!selected)
|
|
102
135
|
return;
|
|
@@ -126,11 +159,11 @@ export function DashboardBoard() {
|
|
|
126
159
|
create.mutate();
|
|
127
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
|
|
128
161
|
? 'bg-sky-100 dark:bg-sky-950'
|
|
129
|
-
: '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]
|
|
130
163
|
.sort((a, b) => a.position - b.position)
|
|
131
|
-
.map((c) => c.id), strategy: rectSortingStrategy, children: _jsx("div", { className:
|
|
164
|
+
.map((c) => c.id), strategy: rectSortingStrategy, children: _jsx("div", { className: cn('mt-6', CHART_GRID), children: [...selected.cards]
|
|
132
165
|
.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))) }) }) }))] })) })] }) }));
|
|
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))) }) }) }))] })) })] }) }));
|
|
134
167
|
}
|
|
135
168
|
/**
|
|
136
169
|
* A card you can pick up.
|
|
@@ -139,30 +172,16 @@ export function DashboardBoard() {
|
|
|
139
172
|
* of buttons and a link, and making the entire surface draggable means every
|
|
140
173
|
* click starts a drag the user did not ask for.
|
|
141
174
|
*/
|
|
142
|
-
function SortableCard({ id, savedQueryId, width, onRemove, onWidth, }) {
|
|
175
|
+
function SortableCard({ id, savedQueryId, width, library, onRemove, onWidth, onLibrary, }) {
|
|
143
176
|
const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({
|
|
144
177
|
id,
|
|
145
178
|
});
|
|
146
|
-
return (_jsx("div", { ref: setNodeRef, style: { transform: CSS.Transform.toString(transform), transition }, className: cn(
|
|
179
|
+
return (_jsx("div", { ref: setNodeRef, style: { transform: CSS.Transform.toString(transform), transition }, className: cn(chartSpan(width),
|
|
147
180
|
// A grid item defaults to `min-width: auto`, so a chart wider than its
|
|
148
181
|
// column pushes the column out instead of being constrained by it —
|
|
149
182
|
// 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 }) }) }) }));
|
|
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 }) }) }) }));
|
|
151
184
|
}
|
|
152
|
-
/**
|
|
153
|
-
* The width an operator chose, applied only where there are columns to spend.
|
|
154
|
-
*
|
|
155
|
-
* Below `@5xl` the grid has fewer than four columns, and a `col-span-4` there
|
|
156
|
-
* spans past the end — which is what put a chart's axis labels outside its own
|
|
157
|
-
* card. Every card is full width on a narrow board, two-up in the middle, and
|
|
158
|
-
* only honours the chosen span once four columns exist to divide.
|
|
159
|
-
*/
|
|
160
|
-
const SPAN = {
|
|
161
|
-
1: '@5xl:col-span-1',
|
|
162
|
-
2: '@2xl:col-span-2 @5xl:col-span-2',
|
|
163
|
-
3: '@2xl:col-span-2 @5xl:col-span-3',
|
|
164
|
-
4: '@2xl:col-span-2 @5xl:col-span-4',
|
|
165
|
-
};
|
|
166
185
|
/**
|
|
167
186
|
* How many of the four columns this card spans.
|
|
168
187
|
*
|
|
@@ -189,10 +208,10 @@ function CardWidthPicker({ width, onWidth, }) {
|
|
|
189
208
|
* query returns and offering it before the first run promises a file that does
|
|
190
209
|
* not exist yet.
|
|
191
210
|
*/
|
|
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 }) })] }));
|
|
211
|
+
function CardToolbar({ width, onWidth, library, queryLibrary, onLibrary, cached, fetching, exportHref, onRefresh, onRemove, }) {
|
|
212
|
+
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
213
|
}
|
|
195
|
-
function Card({ savedQueryId, width, onRemove, onWidth, dragHandle, }) {
|
|
214
|
+
function Card({ savedQueryId, width, library, onRemove, onWidth, onLibrary, dragHandle, }) {
|
|
196
215
|
const client = useCatalogClient();
|
|
197
216
|
const { data, isPending, isFetching, refetch, error } = useQuery({
|
|
198
217
|
queryKey: dashboardKeys.card(savedQueryId),
|
|
@@ -212,49 +231,95 @@ function Card({ savedQueryId, width, onRemove, onWidth, dragHandle, }) {
|
|
|
212
231
|
staleTime: 60_000,
|
|
213
232
|
});
|
|
214
233
|
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,
|
|
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
|
|
235
|
+
? { queryLibrary: data.savedQuery.visualization.library }
|
|
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() }) })] }));
|
|
216
237
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
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 }));
|
|
229
256
|
}
|
|
230
|
-
if (
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
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
|
+
}
|
|
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 }));
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Which chart library draws this card.
|
|
279
|
+
*
|
|
280
|
+
* On the card rather than only on the saved query, because the two answer
|
|
281
|
+
* different questions: the query says how this ANSWER is best drawn wherever it
|
|
282
|
+
* appears, and the card says how it should look HERE, beside the other cards on
|
|
283
|
+
* this board. A board mixing two libraries' idea of a bar reads as two boards,
|
|
284
|
+
* and fixing that by editing the saved query would change it everywhere else
|
|
285
|
+
* the query is used.
|
|
286
|
+
*
|
|
287
|
+
* A select rather than a button group — unlike width, the options are whatever
|
|
288
|
+
* the host registered, so there is no fixed small set to lay out, and the
|
|
289
|
+
* current value still has to be readable while arranging.
|
|
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`;
|
|
239
303
|
}
|
|
240
|
-
return
|
|
304
|
+
return queryLibrary;
|
|
241
305
|
}
|
|
242
|
-
function
|
|
243
|
-
//
|
|
244
|
-
//
|
|
245
|
-
//
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
306
|
+
function CardLibraryPicker({ library, queryLibrary, onLibrary, }) {
|
|
307
|
+
// Only what the host actually registered. Offering a library nobody
|
|
308
|
+
// installed would be offering a choice that silently degrades to the
|
|
309
|
+
// built-in — the picker would say one thing and the card draw another.
|
|
310
|
+
const available = registeredChartLibraries();
|
|
311
|
+
if (available.length === 0)
|
|
312
|
+
return null;
|
|
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
|
+
] }));
|
|
260
325
|
}
|
|
@@ -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
|
|
@@ -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;
|