@dudousxd/nestjs-catalog-react 0.1.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/LICENSE-bklit +21 -0
- package/README.md +282 -0
- package/dist/AccessConsole.d.ts +40 -0
- package/dist/AccessConsole.js +160 -0
- package/dist/CatalogManager.d.ts +12 -0
- package/dist/CatalogManager.js +123 -0
- package/dist/ConnectionPanel.d.ts +41 -0
- package/dist/ConnectionPanel.js +228 -0
- package/dist/CoverageLedger.d.ts +16 -0
- package/dist/CoverageLedger.js +16 -0
- package/dist/DashboardBoard.d.ts +10 -0
- package/dist/DashboardBoard.js +206 -0
- package/dist/EditableField.d.ts +18 -0
- package/dist/EditableField.js +61 -0
- package/dist/FlowView.d.ts +13 -0
- package/dist/FlowView.js +93 -0
- package/dist/GovernanceTimeline.d.ts +16 -0
- package/dist/GovernanceTimeline.js +93 -0
- package/dist/ObjectExplorer.d.ts +9 -0
- package/dist/ObjectExplorer.js +153 -0
- package/dist/PipelineConsole.d.ts +20 -0
- package/dist/PipelineConsole.js +272 -0
- package/dist/QueryConsole.d.ts +11 -0
- package/dist/QueryConsole.js +144 -0
- package/dist/SavedQueryPanel.d.ts +16 -0
- package/dist/SavedQueryPanel.js +78 -0
- package/dist/TraceExplorer.d.ts +54 -0
- package/dist/TraceExplorer.js +342 -0
- package/dist/TransformEditor.d.ts +23 -0
- package/dist/TransformEditor.js +129 -0
- package/dist/WorkflowCanvas.d.ts +24 -0
- package/dist/WorkflowCanvas.js +701 -0
- package/dist/charts/bklit/animation.d.ts +19 -0
- package/dist/charts/bklit/animation.js +28 -0
- package/dist/charts/bklit/area-chart-loading.d.ts +33 -0
- package/dist/charts/bklit/area-chart-loading.js +30 -0
- package/dist/charts/bklit/area-chart.d.ts +47 -0
- package/dist/charts/bklit/area-chart.js +65 -0
- package/dist/charts/bklit/area-gradient-defs.d.ts +28 -0
- package/dist/charts/bklit/area-gradient-defs.js +23 -0
- package/dist/charts/bklit/area.d.ts +75 -0
- package/dist/charts/bklit/area.js +112 -0
- package/dist/charts/bklit/bar-chart-loading.d.ts +16 -0
- package/dist/charts/bklit/bar-chart-loading.js +22 -0
- package/dist/charts/bklit/bar-chart.d.ts +54 -0
- package/dist/charts/bklit/bar-chart.js +440 -0
- package/dist/charts/bklit/bar-depth-geometry.d.ts +41 -0
- package/dist/charts/bklit/bar-depth-geometry.js +46 -0
- package/dist/charts/bklit/bar-squares-layout.d.ts +36 -0
- package/dist/charts/bklit/bar-squares-layout.js +46 -0
- package/dist/charts/bklit/bar-squares.d.ts +48 -0
- package/dist/charts/bklit/bar-squares.js +206 -0
- package/dist/charts/bklit/bar-x-axis.d.ts +13 -0
- package/dist/charts/bklit/bar-x-axis.js +81 -0
- package/dist/charts/bklit/bar-y-axis.d.ts +11 -0
- package/dist/charts/bklit/bar-y-axis.js +72 -0
- package/dist/charts/bklit/bar.d.ts +40 -0
- package/dist/charts/bklit/bar.js +207 -0
- package/dist/charts/bklit/chart-child-passthrough.d.ts +25 -0
- package/dist/charts/bklit/chart-child-passthrough.js +82 -0
- package/dist/charts/bklit/chart-config-context.d.ts +34 -0
- package/dist/charts/bklit/chart-config-context.js +55 -0
- package/dist/charts/bklit/chart-context.d.ts +207 -0
- package/dist/charts/bklit/chart-context.js +200 -0
- package/dist/charts/bklit/chart-defs.d.ts +21 -0
- package/dist/charts/bklit/chart-defs.js +57 -0
- package/dist/charts/bklit/chart-formatters.d.ts +16 -0
- package/dist/charts/bklit/chart-formatters.js +26 -0
- package/dist/charts/bklit/chart-legend-hover.d.ts +21 -0
- package/dist/charts/bklit/chart-legend-hover.js +26 -0
- package/dist/charts/bklit/chart-loading-label.d.ts +9 -0
- package/dist/charts/bklit/chart-loading-label.js +29 -0
- package/dist/charts/bklit/chart-phase.d.ts +39 -0
- package/dist/charts/bklit/chart-phase.js +20 -0
- package/dist/charts/bklit/chart-reveal-clip.d.ts +32 -0
- package/dist/charts/bklit/chart-reveal-clip.js +23 -0
- package/dist/charts/bklit/dash-tail-stroke.d.ts +17 -0
- package/dist/charts/bklit/dash-tail-stroke.js +21 -0
- package/dist/charts/bklit/decimate-time-series.d.ts +18 -0
- package/dist/charts/bklit/decimate-time-series.js +120 -0
- package/dist/charts/bklit/fade-edges.d.ts +42 -0
- package/dist/charts/bklit/fade-edges.js +34 -0
- package/dist/charts/bklit/filter-data-by-x-domain.d.ts +13 -0
- package/dist/charts/bklit/filter-data-by-x-domain.js +50 -0
- package/dist/charts/bklit/generate-chart-skeleton-data.d.ts +24 -0
- package/dist/charts/bklit/generate-chart-skeleton-data.js +33 -0
- package/dist/charts/bklit/grid.d.ts +57 -0
- package/dist/charts/bklit/grid.js +88 -0
- package/dist/charts/bklit/highlight-segment-bounds.d.ts +26 -0
- package/dist/charts/bklit/highlight-segment-bounds.js +35 -0
- package/dist/charts/bklit/highlight-segment.d.ts +30 -0
- package/dist/charts/bklit/highlight-segment.js +22 -0
- package/dist/charts/bklit/indicator-fade.d.ts +23 -0
- package/dist/charts/bklit/indicator-fade.js +41 -0
- package/dist/charts/bklit/line-chart-loading.d.ts +33 -0
- package/dist/charts/bklit/line-chart-loading.js +30 -0
- package/dist/charts/bklit/line-chart.d.ts +45 -0
- package/dist/charts/bklit/line-chart.js +99 -0
- package/dist/charts/bklit/line-loading-pulse.d.ts +19 -0
- package/dist/charts/bklit/line-loading-pulse.js +132 -0
- package/dist/charts/bklit/line-loading-timing.d.ts +18 -0
- package/dist/charts/bklit/line-loading-timing.js +18 -0
- package/dist/charts/bklit/line-series-terminal-marker.d.ts +15 -0
- package/dist/charts/bklit/line-series-terminal-marker.js +54 -0
- package/dist/charts/bklit/line.d.ts +63 -0
- package/dist/charts/bklit/line.js +104 -0
- package/dist/charts/bklit/loading-sweep.d.ts +65 -0
- package/dist/charts/bklit/loading-sweep.js +182 -0
- package/dist/charts/bklit/motion-utils.d.ts +17 -0
- package/dist/charts/bklit/motion-utils.js +27 -0
- package/dist/charts/bklit/path-stroke-utils.d.ts +28 -0
- package/dist/charts/bklit/path-stroke-utils.js +64 -0
- package/dist/charts/bklit/pattern-area.d.ts +20 -0
- package/dist/charts/bklit/pattern-area.js +27 -0
- package/dist/charts/bklit/pattern-preset.d.ts +34 -0
- package/dist/charts/bklit/pattern-preset.js +82 -0
- package/dist/charts/bklit/projection-config.d.ts +19 -0
- package/dist/charts/bklit/projection-config.js +88 -0
- package/dist/charts/bklit/projection-line-end-marker.d.ts +14 -0
- package/dist/charts/bklit/projection-line-end-marker.js +35 -0
- package/dist/charts/bklit/projection-line.d.ts +39 -0
- package/dist/charts/bklit/projection-line.js +87 -0
- package/dist/charts/bklit/projection-utils.d.ts +54 -0
- package/dist/charts/bklit/projection-utils.js +252 -0
- package/dist/charts/bklit/reference-area-config.d.ts +18 -0
- package/dist/charts/bklit/reference-area-config.js +47 -0
- package/dist/charts/bklit/reference-area-registration-context.d.ts +7 -0
- package/dist/charts/bklit/reference-area-registration-context.js +15 -0
- package/dist/charts/bklit/series-bar-layout.d.ts +26 -0
- package/dist/charts/bklit/series-bar-layout.js +39 -0
- package/dist/charts/bklit/series-dash-tail-overlay.d.ts +16 -0
- package/dist/charts/bklit/series-dash-tail-overlay.js +47 -0
- package/dist/charts/bklit/series-highlight-layer.d.ts +31 -0
- package/dist/charts/bklit/series-highlight-layer.js +20 -0
- package/dist/charts/bklit/series-hover-dim.d.ts +28 -0
- package/dist/charts/bklit/series-hover-dim.js +34 -0
- package/dist/charts/bklit/series-markers.d.ts +13 -0
- package/dist/charts/bklit/series-markers.js +106 -0
- package/dist/charts/bklit/series-path-utils.d.ts +18 -0
- package/dist/charts/bklit/series-path-utils.js +68 -0
- package/dist/charts/bklit/series-point-marker.d.ts +47 -0
- package/dist/charts/bklit/series-point-marker.js +47 -0
- package/dist/charts/bklit/static-chart-preview-context.d.ts +15 -0
- package/dist/charts/bklit/static-chart-preview-context.js +20 -0
- package/dist/charts/bklit/time-series-chart-shell.d.ts +46 -0
- package/dist/charts/bklit/time-series-chart-shell.js +398 -0
- package/dist/charts/bklit/tooltip/chart-tooltip.d.ts +75 -0
- package/dist/charts/bklit/tooltip/chart-tooltip.js +158 -0
- package/dist/charts/bklit/tooltip/date-ticker.d.ts +10 -0
- package/dist/charts/bklit/tooltip/date-ticker.js +85 -0
- package/dist/charts/bklit/tooltip/index.d.ts +15 -0
- package/dist/charts/bklit/tooltip/index.js +15 -0
- package/dist/charts/bklit/tooltip/tooltip-box.d.ts +56 -0
- package/dist/charts/bklit/tooltip/tooltip-box.js +122 -0
- package/dist/charts/bklit/tooltip/tooltip-content.d.ts +26 -0
- package/dist/charts/bklit/tooltip/tooltip-content.js +8 -0
- package/dist/charts/bklit/tooltip/tooltip-dot.d.ts +27 -0
- package/dist/charts/bklit/tooltip/tooltip-dot.js +62 -0
- package/dist/charts/bklit/tooltip/tooltip-indicator.d.ts +44 -0
- package/dist/charts/bklit/tooltip/tooltip-indicator.js +73 -0
- package/dist/charts/bklit/use-animated-series-path.d.ts +18 -0
- package/dist/charts/bklit/use-animated-series-path.js +101 -0
- package/dist/charts/bklit/use-animated-y-domains.d.ts +13 -0
- package/dist/charts/bklit/use-animated-y-domains.js +158 -0
- package/dist/charts/bklit/use-chart-interaction.d.ts +40 -0
- package/dist/charts/bklit/use-chart-interaction.js +252 -0
- package/dist/charts/bklit/use-chart-phase-orchestrator.d.ts +22 -0
- package/dist/charts/bklit/use-chart-phase-orchestrator.js +147 -0
- package/dist/charts/bklit/use-enter-complete.d.ts +16 -0
- package/dist/charts/bklit/use-enter-complete.js +22 -0
- package/dist/charts/bklit/use-grid-shimmer.d.ts +15 -0
- package/dist/charts/bklit/use-grid-shimmer.js +71 -0
- package/dist/charts/bklit/use-highlight-segment.d.ts +22 -0
- package/dist/charts/bklit/use-highlight-segment.js +42 -0
- package/dist/charts/bklit/use-mount-progress.d.ts +12 -0
- package/dist/charts/bklit/use-mount-progress.js +30 -0
- package/dist/charts/bklit/use-scheduled-tooltip.d.ts +8 -0
- package/dist/charts/bklit/use-scheduled-tooltip.js +84 -0
- package/dist/charts/bklit/visx-pattern.d.ts +27 -0
- package/dist/charts/bklit/visx-pattern.js +28 -0
- package/dist/charts/bklit/x-axis.d.ts +26 -0
- package/dist/charts/bklit/x-axis.js +423 -0
- package/dist/charts/bklit/y-axis-scales.d.ts +34 -0
- package/dist/charts/bklit/y-axis-scales.js +80 -0
- package/dist/charts/bklit/y-axis-ticks.d.ts +20 -0
- package/dist/charts/bklit/y-axis-ticks.js +32 -0
- package/dist/charts/bklit/y-domain-utils.d.ts +26 -0
- package/dist/charts/bklit/y-domain-utils.js +96 -0
- package/dist/charts/bklit.d.ts +2 -0
- package/dist/charts/bklit.js +90 -0
- package/dist/charts/components/shimmering-text.d.ts +31 -0
- package/dist/charts/components/shimmering-text.js +39 -0
- package/dist/charts/css.d.ts +35 -0
- package/dist/charts/css.js +64 -0
- package/dist/charts/recharts.d.ts +28 -0
- package/dist/charts/recharts.js +48 -0
- package/dist/charts/registry.d.ts +34 -0
- package/dist/charts/registry.js +60 -0
- package/dist/charts/skeleton.d.ts +55 -0
- package/dist/charts/skeleton.js +66 -0
- package/dist/cn.d.ts +10 -0
- package/dist/cn.js +13 -0
- package/dist/context.d.ts +346 -0
- package/dist/context.js +95 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +65 -0
- package/dist/routes.d.ts +70 -0
- package/dist/routes.js +73 -0
- package/dist/source-fields.d.ts +111 -0
- package/dist/source-fields.js +204 -0
- package/dist/ui/chart.d.ts +54 -0
- package/dist/ui/chart.js +122 -0
- package/dist/ui/dialog.d.ts +27 -0
- package/dist/ui/dialog.js +24 -0
- package/dist/ui/field.d.ts +29 -0
- package/dist/ui/field.js +31 -0
- package/dist/ui/select.d.ts +42 -0
- package/dist/ui/select.js +30 -0
- package/dist/ui/sheet.d.ts +38 -0
- package/dist/ui/sheet.js +37 -0
- package/dist/ui/switch.d.ts +17 -0
- package/dist/ui/switch.js +14 -0
- package/dist/ui/tabs.d.ts +30 -0
- package/dist/ui/tabs.js +36 -0
- package/dist/ui/tooltip.d.ts +37 -0
- package/dist/ui/tooltip.js +43 -0
- package/dist/workflow/graph.d.ts +112 -0
- package/dist/workflow/graph.js +297 -0
- package/dist/workflow/index.d.ts +16 -0
- package/dist/workflow/index.js +16 -0
- package/dist/workflow/model.d.ts +151 -0
- package/dist/workflow/model.js +97 -0
- package/dist/workflow/name.d.ts +28 -0
- package/dist/workflow/name.js +28 -0
- package/dist/workflow/nodes.d.ts +40 -0
- package/dist/workflow/nodes.js +86 -0
- package/dist/workflow/validate.d.ts +104 -0
- package/dist/workflow/validate.js +199 -0
- package/package.json +148 -0
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { DndContext, KeyboardSensor, PointerSensor, closestCenter, useSensor, useSensors, } from '@dnd-kit/core';
|
|
3
|
+
import { SortableContext, arrayMove, rectSortingStrategy, sortableKeyboardCoordinates, useSortable, } from '@dnd-kit/sortable';
|
|
4
|
+
import { CSS } from '@dnd-kit/utilities';
|
|
5
|
+
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
6
|
+
import { Download, GripVertical, LayoutGrid, Plus, RefreshCw, Trash2 } from 'lucide-react';
|
|
7
|
+
import { useState } from 'react';
|
|
8
|
+
import { CssBarChart } from './charts/css';
|
|
9
|
+
import { getChartRenderer } from './charts/registry';
|
|
10
|
+
import { ChartEmpty, ChartFailed, ChartSkeleton } from './charts/skeleton';
|
|
11
|
+
import { cn } from './cn';
|
|
12
|
+
import { useCatalogClient } from './context';
|
|
13
|
+
import { Tooltip, TooltipProvider } from './ui/tooltip';
|
|
14
|
+
const MUTED = 'text-zinc-400 dark:text-zinc-500';
|
|
15
|
+
const RULE = 'border-zinc-200 dark:border-zinc-800';
|
|
16
|
+
const PANEL = 'bg-white dark:bg-zinc-900';
|
|
17
|
+
const dashboardKeys = {
|
|
18
|
+
all: ['catalog', 'dashboards'],
|
|
19
|
+
card: (id) => ['catalog', 'dashboard-card', id],
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Saved queries, laid out on a page.
|
|
23
|
+
*
|
|
24
|
+
* Each card runs its own saved query and honours the TTL that query was saved
|
|
25
|
+
* with — so a dashboard of cached cards costs one round trip and no database
|
|
26
|
+
* work, and a dashboard of uncached ones is honest about being expensive. The
|
|
27
|
+
* alternative, a dashboard-wide refresh policy, would override a decision the
|
|
28
|
+
* query's author already made with more information than the dashboard has.
|
|
29
|
+
*/
|
|
30
|
+
export function DashboardBoard() {
|
|
31
|
+
const client = useCatalogClient();
|
|
32
|
+
const queryClient = useQueryClient();
|
|
33
|
+
const [selectedId, setSelectedId] = useState(null);
|
|
34
|
+
const [creating, setCreating] = useState(false);
|
|
35
|
+
const [name, setName] = useState('');
|
|
36
|
+
const { data: dashboards = [] } = useQuery({
|
|
37
|
+
queryKey: dashboardKeys.all,
|
|
38
|
+
queryFn: () => client.listDashboards(),
|
|
39
|
+
});
|
|
40
|
+
const { data: saved = [] } = useQuery({
|
|
41
|
+
queryKey: ['catalog', 'saved-queries'],
|
|
42
|
+
queryFn: () => client.listSavedQueries(),
|
|
43
|
+
});
|
|
44
|
+
const invalidate = () => queryClient.invalidateQueries({ queryKey: dashboardKeys.all });
|
|
45
|
+
const create = useMutation({
|
|
46
|
+
mutationFn: () => client.saveDashboard({ name }),
|
|
47
|
+
onSuccess: (dashboard) => {
|
|
48
|
+
setCreating(false);
|
|
49
|
+
setName('');
|
|
50
|
+
setSelectedId(dashboard.id);
|
|
51
|
+
invalidate();
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
const update = useMutation({
|
|
55
|
+
mutationFn: ({ id, cards }) => client.updateDashboard(id, { cards }),
|
|
56
|
+
onSuccess: invalidate,
|
|
57
|
+
});
|
|
58
|
+
const remove = useMutation({
|
|
59
|
+
mutationFn: (id) => client.deleteDashboard(id),
|
|
60
|
+
onSuccess: () => {
|
|
61
|
+
setSelectedId(null);
|
|
62
|
+
invalidate();
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
const selected = dashboards.find((d) => d.id === selectedId) ?? dashboards[0] ?? null;
|
|
66
|
+
// Pointer with a small activation distance so a click on a card's buttons is
|
|
67
|
+
// not swallowed as the start of a drag; keyboard so the layout is reachable
|
|
68
|
+
// without a mouse, which native HTML5 drag never is.
|
|
69
|
+
const sensors = useSensors(useSensor(PointerSensor, { activationConstraint: { distance: 6 } }), useSensor(KeyboardSensor, {
|
|
70
|
+
coordinateGetter: sortableKeyboardCoordinates,
|
|
71
|
+
}));
|
|
72
|
+
function onDragEnd(event) {
|
|
73
|
+
if (!selected)
|
|
74
|
+
return;
|
|
75
|
+
const { active, over } = event;
|
|
76
|
+
if (!over || active.id === over.id)
|
|
77
|
+
return;
|
|
78
|
+
const ordered = [...selected.cards].sort((a, b) => a.position - b.position);
|
|
79
|
+
const from = ordered.findIndex((c) => c.id === active.id);
|
|
80
|
+
const to = ordered.findIndex((c) => c.id === over.id);
|
|
81
|
+
if (from === -1 || to === -1)
|
|
82
|
+
return;
|
|
83
|
+
update.mutate({
|
|
84
|
+
id: selected.id,
|
|
85
|
+
cards: arrayMove(ordered, from, to).map((card, index) => ({
|
|
86
|
+
...card,
|
|
87
|
+
position: index,
|
|
88
|
+
})),
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
function setWidth(cardId, width) {
|
|
92
|
+
if (!selected)
|
|
93
|
+
return;
|
|
94
|
+
update.mutate({
|
|
95
|
+
id: selected.id,
|
|
96
|
+
cards: selected.cards.map((card) => (card.id === cardId ? { ...card, width } : card)),
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
function addCard(savedQueryId) {
|
|
100
|
+
if (!selected)
|
|
101
|
+
return;
|
|
102
|
+
update.mutate({
|
|
103
|
+
id: selected.id,
|
|
104
|
+
cards: [
|
|
105
|
+
...selected.cards,
|
|
106
|
+
{
|
|
107
|
+
id: `card-${Date.now()}`,
|
|
108
|
+
savedQueryId,
|
|
109
|
+
width: 2,
|
|
110
|
+
position: selected.cards.length,
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
function removeCard(cardId) {
|
|
116
|
+
if (!selected)
|
|
117
|
+
return;
|
|
118
|
+
update.mutate({
|
|
119
|
+
id: selected.id,
|
|
120
|
+
cards: selected.cards.filter((c) => c.id !== cardId),
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
return (_jsx(TooltipProvider, { children: _jsxs("div", { className: "flex h-full min-h-0", children: [_jsxs("aside", { className: cn('flex w-60 shrink-0 flex-col border-r', RULE, PANEL), children: [_jsxs("div", { className: cn('flex items-center justify-between border-b px-3 py-2', RULE), children: [_jsx("span", { className: cn('font-mono text-[10px] uppercase tracking-[0.14em]', MUTED), children: "Dashboards" }), _jsx("button", { type: "button", onClick: () => setCreating((o) => !o), className: cn('rounded-sm p-1 hover:bg-zinc-100 dark:hover:bg-zinc-800', MUTED), "aria-label": "New dashboard", children: _jsx(Plus, { size: 12 }) })] }), creating && (_jsxs("form", { className: "flex gap-1 p-2", onSubmit: (e) => {
|
|
124
|
+
e.preventDefault();
|
|
125
|
+
create.mutate();
|
|
126
|
+
}, 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
|
|
127
|
+
? 'bg-violet-100 dark:bg-violet-950'
|
|
128
|
+
: '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-violet-50', 'dark:hover:bg-violet-950/40'), children: ["+ ", query.name] }, query.id)))] }))] }), _jsx("main", { className: "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]
|
|
129
|
+
.sort((a, b) => a.position - b.position)
|
|
130
|
+
.map((c) => c.id), strategy: rectSortingStrategy, children: _jsx("div", { className: "mt-6 grid grid-cols-4 gap-4", children: [...selected.cards]
|
|
131
|
+
.sort((a, b) => a.position - b.position)
|
|
132
|
+
.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))) }) }) }))] })) })] }) }));
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* A card you can pick up.
|
|
136
|
+
*
|
|
137
|
+
* The drag handle is its own control rather than the whole card: a card is full
|
|
138
|
+
* of buttons and a link, and making the entire surface draggable means every
|
|
139
|
+
* click starts a drag the user did not ask for.
|
|
140
|
+
*/
|
|
141
|
+
function SortableCard({ id, savedQueryId, width, onRemove, onWidth, }) {
|
|
142
|
+
const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({
|
|
143
|
+
id,
|
|
144
|
+
});
|
|
145
|
+
return (_jsx("div", { ref: setNodeRef, style: { transform: CSS.Transform.toString(transform), transition }, className: cn(SPAN[width] ?? 'col-span-2', '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 }) }) }) }));
|
|
146
|
+
}
|
|
147
|
+
const SPAN = {
|
|
148
|
+
1: 'col-span-1',
|
|
149
|
+
2: 'col-span-2',
|
|
150
|
+
3: 'col-span-3',
|
|
151
|
+
4: 'col-span-4',
|
|
152
|
+
};
|
|
153
|
+
function Card({ savedQueryId, width, onRemove, onWidth, dragHandle, }) {
|
|
154
|
+
const client = useCatalogClient();
|
|
155
|
+
const { data, isPending, isFetching, refetch, error } = useQuery({
|
|
156
|
+
queryKey: dashboardKeys.card(savedQueryId),
|
|
157
|
+
queryFn: () => client.runSavedQuery(savedQueryId),
|
|
158
|
+
});
|
|
159
|
+
/**
|
|
160
|
+
* The saved query itself, so the skeleton knows which chart is coming.
|
|
161
|
+
*
|
|
162
|
+
* Read from the list the board already loaded — same key, so this is a cache
|
|
163
|
+
* hit rather than a second request. Without it the card cannot know whether
|
|
164
|
+
* bars or a number are about to appear, and a generic grey box that turns
|
|
165
|
+
* into a chart is exactly the placeholder this is meant to replace.
|
|
166
|
+
*/
|
|
167
|
+
const { data: saved = [] } = useQuery({
|
|
168
|
+
queryKey: ['catalog', 'saved-queries'],
|
|
169
|
+
queryFn: () => client.listSavedQueries(),
|
|
170
|
+
staleTime: 60_000,
|
|
171
|
+
});
|
|
172
|
+
const pendingKind = saved.find((query) => query.id === savedQueryId)?.visualization?.kind ?? 'table';
|
|
173
|
+
return (_jsxs("div", { className: cn('h-full rounded-lg border p-3 transition-shadow', RULE, PANEL), children: [_jsxs("div", { className: "flex items-start justify-between gap-2", children: [dragHandle, _jsxs("div", { className: "min-w-0 flex-1", children: [_jsx("h3", { className: "truncate text-sm font-medium", children: data?.savedQuery.name ?? '…' }), data && (_jsxs("p", { className: cn('font-mono text-[10px]', MUTED), children: [data.result.rowCount, " rows", data.result.cached ? ' · cached' : ` · ${data.result.elapsedMs}ms`] }))] }), _jsxs("div", { className: "flex shrink-0 items-center gap-0.5", children: [onWidth && (_jsx("span", { className: cn('mr-1 flex overflow-hidden rounded-md border', RULE), role: "group", "aria-label": "Card width", children: [1, 2, 3, 4].map((size) => (_jsx(Tooltip, { content: `${size} of 4 columns wide`, children: _jsx("button", { type: "button", onClick: () => onWidth(size), "aria-pressed": width === size, className: cn('px-1.5 py-0.5 font-mono text-[10px] transition-colors', width === size
|
|
174
|
+
? 'bg-zinc-950 text-zinc-50 dark:bg-zinc-100 dark:text-zinc-950'
|
|
175
|
+
: 'hover:bg-zinc-100 dark:hover:bg-zinc-800'), children: size }) }, size))) })), _jsx(Tooltip, { content: data?.result.cached ? 'Cached — refetch anyway' : 'Run again', children: _jsx("button", { type: "button", onClick: () => refetch(), className: cn('rounded-sm p-1 hover:bg-zinc-100 dark:hover:bg-zinc-800', MUTED), "aria-label": "Refresh card", children: _jsx(RefreshCw, { size: 11, className: isFetching ? 'animate-spin' : undefined }) }) }), data && (_jsx(Tooltip, { content: "Download as CSV", children: _jsx("a", { href: client.exportUrl(savedQueryId), className: cn('rounded-sm p-1 hover:bg-zinc-100 dark:hover:bg-zinc-800', MUTED), "aria-label": "Export card", children: _jsx(Download, { size: 11 }) }) })), _jsx("button", { type: "button", onClick: onRemove, className: cn('rounded-sm p-1 hover:text-red-600', MUTED), "aria-label": "Remove card", children: _jsx(Trash2, { size: 11 }) })] })] }), _jsx("div", { className: "mt-3", children: error ? (_jsx(ChartFailed, { height: 200, message: error instanceof Error ? error.message : 'The card failed to load.', onRetry: () => refetch() })) : isPending ? (_jsx(ChartSkeleton, { kind: pendingKind, height: 200 })) : data ? (_jsx(CardBody, { query: data.savedQuery, result: data.result })) : null })] }));
|
|
176
|
+
}
|
|
177
|
+
function CardBody({ query, result, }) {
|
|
178
|
+
const viz = query.visualization ?? { kind: 'table' };
|
|
179
|
+
// Held at the chart's own height rather than collapsing to one line, so a
|
|
180
|
+
// card that matched nothing does not resize the grid around it — and said in
|
|
181
|
+
// words, because "no rows" beside a skeleton-shaped hole is the one reading
|
|
182
|
+
// that must never be ambiguous.
|
|
183
|
+
if (result.rowCount === 0) {
|
|
184
|
+
return _jsx(ChartEmpty, { height: 200, message: "The query ran and matched nothing." });
|
|
185
|
+
}
|
|
186
|
+
if (viz.kind === 'number') {
|
|
187
|
+
const column = viz.valueColumns?.[0] ?? result.columns[0];
|
|
188
|
+
return (_jsxs("div", { className: "py-4 text-center", children: [_jsx("div", { className: "font-mono text-3xl tabular-nums", children: String(result.rows[0]?.[column] ?? '—') }), _jsx("div", { className: cn('mt-1 font-mono text-[10px] uppercase', MUTED), children: viz.labelColumn ?? column })] }));
|
|
189
|
+
}
|
|
190
|
+
if (viz.kind === 'bar' || viz.kind === 'line' || viz.kind === 'area') {
|
|
191
|
+
// A registered library when the query names one and the host installed it;
|
|
192
|
+
// otherwise the built-in bars. Falling back beats failing: a dashboard
|
|
193
|
+
// should degrade to a plainer chart, not to an error message.
|
|
194
|
+
const Renderer = getChartRenderer(viz.library);
|
|
195
|
+
if (Renderer) {
|
|
196
|
+
return _jsx(Renderer, { result: result, visualization: viz, height: 200 });
|
|
197
|
+
}
|
|
198
|
+
return _jsx(CssBarChart, { result: result, visualization: viz, height: 200 });
|
|
199
|
+
}
|
|
200
|
+
return _jsx(MiniTable, { result: result });
|
|
201
|
+
}
|
|
202
|
+
function MiniTable({ result }) {
|
|
203
|
+
return (_jsx("div", { className: "overflow-x-auto", children: _jsxs("table", { className: "w-full text-[11px]", children: [_jsx("thead", { children: _jsx("tr", { className: cn('border-b', RULE), children: result.columns.slice(0, 5).map((column) => (_jsx("th", { className: cn('whitespace-nowrap px-1 py-1 text-left font-mono text-[9px] uppercase', MUTED), children: column }, column))) }) }), _jsx("tbody", { children: result.rows.slice(0, 6).map((row, index) => (
|
|
204
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: rows have no key
|
|
205
|
+
_jsx("tr", { className: "border-b border-zinc-100 last:border-0 dark:border-zinc-900", children: result.columns.slice(0, 5).map((column) => (_jsx("td", { className: cn('whitespace-nowrap px-1 py-0.5', typeof row[column] === 'number' && 'text-right font-mono tabular-nums'), children: row[column] === null || row[column] === undefined ? '—' : String(row[column]) }, column))) }, index))) })] }) }));
|
|
206
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
interface EditableFieldProps {
|
|
2
|
+
value: string;
|
|
3
|
+
placeholder?: string;
|
|
4
|
+
onSave: (next: string) => void;
|
|
5
|
+
multiline?: boolean;
|
|
6
|
+
className?: string;
|
|
7
|
+
inputClassName?: string;
|
|
8
|
+
label: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Click to edit, Enter to save, Escape to cancel.
|
|
12
|
+
*
|
|
13
|
+
* Every field this wraps is presentation-only — a label, a description, a unit.
|
|
14
|
+
* None of it reaches a migration, which is the only reason it is safe to make
|
|
15
|
+
* editing this casual.
|
|
16
|
+
*/
|
|
17
|
+
export declare function EditableField({ value, placeholder, onSave, multiline, className, inputClassName, label, }: EditableFieldProps): import("react/jsx-runtime").JSX.Element;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Check, Pencil, X } from 'lucide-react';
|
|
3
|
+
import { useEffect, useRef, useState } from 'react';
|
|
4
|
+
import { cn } from './cn';
|
|
5
|
+
/**
|
|
6
|
+
* Click to edit, Enter to save, Escape to cancel.
|
|
7
|
+
*
|
|
8
|
+
* Every field this wraps is presentation-only — a label, a description, a unit.
|
|
9
|
+
* None of it reaches a migration, which is the only reason it is safe to make
|
|
10
|
+
* editing this casual.
|
|
11
|
+
*/
|
|
12
|
+
export function EditableField({ value, placeholder = 'Not named yet', onSave, multiline = false, className, inputClassName, label, }) {
|
|
13
|
+
const [editing, setEditing] = useState(false);
|
|
14
|
+
const [draft, setDraft] = useState(value);
|
|
15
|
+
// Two refs rather than one union-typed ref: React types `ref` per element, so
|
|
16
|
+
// a shared `HTMLInputElement | HTMLTextAreaElement` ref satisfies neither.
|
|
17
|
+
const inputRef = useRef(null);
|
|
18
|
+
const textareaRef = useRef(null);
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (!editing)
|
|
21
|
+
setDraft(value);
|
|
22
|
+
}, [value, editing]);
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (!editing)
|
|
25
|
+
return;
|
|
26
|
+
const node = multiline ? textareaRef.current : inputRef.current;
|
|
27
|
+
node?.focus();
|
|
28
|
+
node?.select();
|
|
29
|
+
}, [editing, multiline]);
|
|
30
|
+
function commit() {
|
|
31
|
+
const next = draft.trim();
|
|
32
|
+
if (next !== value)
|
|
33
|
+
onSave(next);
|
|
34
|
+
setEditing(false);
|
|
35
|
+
}
|
|
36
|
+
function cancel() {
|
|
37
|
+
setDraft(value);
|
|
38
|
+
setEditing(false);
|
|
39
|
+
}
|
|
40
|
+
if (editing) {
|
|
41
|
+
const shared = {
|
|
42
|
+
value: draft,
|
|
43
|
+
'aria-label': label,
|
|
44
|
+
onChange: (e) => setDraft(e.target.value),
|
|
45
|
+
onBlur: commit,
|
|
46
|
+
onKeyDown: (e) => {
|
|
47
|
+
if (e.key === 'Escape') {
|
|
48
|
+
e.preventDefault();
|
|
49
|
+
cancel();
|
|
50
|
+
}
|
|
51
|
+
if (e.key === 'Enter' && (!multiline || e.metaKey || e.ctrlKey)) {
|
|
52
|
+
e.preventDefault();
|
|
53
|
+
commit();
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
className: cn('w-full rounded-sm border border-violet-500 bg-white px-1.5 py-0.5 dark:bg-zinc-900', 'outline-none ring-2 ring-violet-500/20', inputClassName),
|
|
57
|
+
};
|
|
58
|
+
return (_jsxs("div", { className: cn('flex items-start gap-1.5', className), children: [multiline ? (_jsx("textarea", { ...shared, ref: textareaRef, rows: 3 })) : (_jsx("input", { ...shared, ref: inputRef, type: "text" })), _jsx("button", { type: "button", onMouseDown: (e) => e.preventDefault(), onClick: commit, "aria-label": `Save ${label}`, className: "mt-0.5 rounded-sm p-0.5 text-emerald-600 hover:bg-emerald-100 dark:hover:bg-emerald-950", children: _jsx(Check, { size: 14 }) }), _jsx("button", { type: "button", onMouseDown: (e) => e.preventDefault(), onClick: cancel, "aria-label": `Cancel editing ${label}`, className: "mt-0.5 rounded-sm p-0.5 text-zinc-400 hover:bg-zinc-100 dark:hover:bg-zinc-800", children: _jsx(X, { size: 14 }) })] }));
|
|
59
|
+
}
|
|
60
|
+
return (_jsxs("button", { type: "button", onClick: () => setEditing(true), "aria-label": `Edit ${label}`, className: cn('group/edit flex w-full items-start gap-1.5 rounded-sm px-1.5 py-0.5 text-left', 'border border-transparent hover:border-zinc-200 hover:bg-zinc-50', 'dark:hover:border-zinc-800 dark:hover:bg-zinc-950', 'focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-violet-500', className), children: [_jsx("span", { className: cn(!value && 'italic text-zinc-400 dark:text-zinc-500'), children: value || placeholder }), _jsx(Pencil, { size: 12, className: "mt-1 shrink-0 opacity-0 transition-opacity group-hover/edit:opacity-60" })] }));
|
|
61
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The flow: which application feeds which type, and how that has been going.
|
|
3
|
+
*
|
|
4
|
+
* Reconstructed from the audit trail rather than declared anywhere. A catalog
|
|
5
|
+
* has no DAG to draw because nobody writes one — the graph is whatever the
|
|
6
|
+
* publishers actually did, and inferring it from what happened is both less
|
|
7
|
+
* work and more truthful than a diagram someone has to remember to update.
|
|
8
|
+
*
|
|
9
|
+
* Deliberately not an orchestrator. Scheduling, retries and backfill already
|
|
10
|
+
* live in the publisher's own durable engine; duplicating them here would mean
|
|
11
|
+
* two systems believing they own when a load runs.
|
|
12
|
+
*/
|
|
13
|
+
export declare function FlowView(): import("react/jsx-runtime").JSX.Element;
|
package/dist/FlowView.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useQuery } from '@tanstack/react-query';
|
|
3
|
+
import { ArrowRight, CircleAlert, CircleCheck, CircleDot } from 'lucide-react';
|
|
4
|
+
import { useMemo } from 'react';
|
|
5
|
+
import { cn } from './cn';
|
|
6
|
+
import { catalogQueryKeys, useCatalogClient } from './context';
|
|
7
|
+
import { Tooltip, TooltipProvider } from './ui/tooltip';
|
|
8
|
+
const MUTED = 'text-zinc-400 dark:text-zinc-500';
|
|
9
|
+
const RULE = 'border-zinc-200 dark:border-zinc-800';
|
|
10
|
+
const PANEL = 'bg-white dark:bg-zinc-900';
|
|
11
|
+
/**
|
|
12
|
+
* The flow: which application feeds which type, and how that has been going.
|
|
13
|
+
*
|
|
14
|
+
* Reconstructed from the audit trail rather than declared anywhere. A catalog
|
|
15
|
+
* has no DAG to draw because nobody writes one — the graph is whatever the
|
|
16
|
+
* publishers actually did, and inferring it from what happened is both less
|
|
17
|
+
* work and more truthful than a diagram someone has to remember to update.
|
|
18
|
+
*
|
|
19
|
+
* Deliberately not an orchestrator. Scheduling, retries and backfill already
|
|
20
|
+
* live in the publisher's own durable engine; duplicating them here would mean
|
|
21
|
+
* two systems believing they own when a load runs.
|
|
22
|
+
*/
|
|
23
|
+
export function FlowView() {
|
|
24
|
+
const client = useCatalogClient();
|
|
25
|
+
const { data: snapshot } = useQuery({
|
|
26
|
+
queryKey: catalogQueryKeys.snapshot,
|
|
27
|
+
queryFn: () => client.snapshot(),
|
|
28
|
+
});
|
|
29
|
+
const { data: events = [], isLoading } = useQuery({
|
|
30
|
+
queryKey: ['catalog', 'flow-events'],
|
|
31
|
+
queryFn: () => client.listEvents({ limit: 500 }),
|
|
32
|
+
refetchInterval: 20_000,
|
|
33
|
+
});
|
|
34
|
+
const lanes = useMemo(() => buildLanes(snapshot?.types ?? [], events), [snapshot, events]);
|
|
35
|
+
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: "Flow" }), _jsx("h1", { className: "mt-1 text-2xl font-semibold tracking-tight", children: "Who feeds what" }), _jsx("p", { className: "mt-1 max-w-2xl text-sm text-zinc-500 dark:text-zinc-400", children: "Built from what the publishers actually did, not from a diagram somebody maintains. Scheduling and retries stay in each publisher's own engine \u2014 two systems believing they own when a load runs is worse than no picture at all." }), isLoading && (_jsx("p", { className: cn('py-10 text-center font-mono text-sm', MUTED), children: "Reading the trail\u2026" })), !isLoading && lanes.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 has published yet." })), _jsx("div", { className: "mt-6 space-y-3", children: lanes.map((lane) => (_jsx(Lane, { lane: lane }, `${lane.principalId}:${lane.typeName}`))) })] }) }) }));
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* One lane per (publisher, type) pair.
|
|
39
|
+
*
|
|
40
|
+
* The pair, not the type: two applications feeding one type would be the single
|
|
41
|
+
* most important thing on this screen, and collapsing by type would hide
|
|
42
|
+
* exactly that.
|
|
43
|
+
*/
|
|
44
|
+
function buildLanes(types, events) {
|
|
45
|
+
const byType = new Map(types.map((t) => [t.name, t]));
|
|
46
|
+
const lanes = new Map();
|
|
47
|
+
// Events arrive newest first; walking them in that order keeps each lane's
|
|
48
|
+
// loads sorted without a second pass.
|
|
49
|
+
for (const event of events) {
|
|
50
|
+
if (!event.typeName)
|
|
51
|
+
continue;
|
|
52
|
+
const principalId = event.principalId ?? 'curated by hand';
|
|
53
|
+
const key = `${principalId}:${event.typeName}`;
|
|
54
|
+
const lane = lanes.get(key) ??
|
|
55
|
+
{
|
|
56
|
+
principalId,
|
|
57
|
+
typeName: event.typeName,
|
|
58
|
+
displayName: byType.get(event.typeName)?.displayName ?? event.typeName,
|
|
59
|
+
icon: byType.get(event.typeName)?.icon,
|
|
60
|
+
loads: [],
|
|
61
|
+
schemaChanges: 0,
|
|
62
|
+
};
|
|
63
|
+
if (event.event === 'schema.changed')
|
|
64
|
+
lane.schemaChanges += 1;
|
|
65
|
+
if (event.snapshotId && event.event.startsWith('snapshot.')) {
|
|
66
|
+
const existing = lane.loads.find((l) => l.snapshotId === event.snapshotId);
|
|
67
|
+
const committed = event.event === 'snapshot.committed';
|
|
68
|
+
const rows = Number(event.detail?.rowCount ?? event.detail?.rows ?? 0);
|
|
69
|
+
if (existing) {
|
|
70
|
+
existing.committed = existing.committed || committed;
|
|
71
|
+
existing.rows = Math.max(existing.rows, rows);
|
|
72
|
+
}
|
|
73
|
+
else if (lane.loads.length < 12) {
|
|
74
|
+
lane.loads.push({
|
|
75
|
+
snapshotId: event.snapshotId,
|
|
76
|
+
rows,
|
|
77
|
+
committed,
|
|
78
|
+
at: event.occurredAt,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
lane.lastAt = lane.lastAt ?? event.occurredAt;
|
|
83
|
+
lanes.set(key, lane);
|
|
84
|
+
}
|
|
85
|
+
return [...lanes.values()].sort((a, b) => (b.lastAt ?? '').localeCompare(a.lastAt ?? ''));
|
|
86
|
+
}
|
|
87
|
+
function Lane({ lane }) {
|
|
88
|
+
const committed = lane.loads.filter((l) => l.committed).length;
|
|
89
|
+
const uncommitted = lane.loads.length - committed;
|
|
90
|
+
return (_jsxs("div", { className: cn('rounded-lg border p-4', RULE, PANEL), children: [_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx("span", { className: "rounded-md bg-zinc-100 px-2 py-1 font-mono text-[11px] dark:bg-zinc-800", children: lane.principalId }), _jsx(ArrowRight, { size: 14, className: MUTED }), _jsxs("span", { className: "text-sm", children: [lane.icon ? `${lane.icon} ` : '', lane.displayName] }), _jsx("span", { className: cn('font-mono text-[10px]', MUTED), children: lane.typeName }), _jsx("span", { className: cn('ml-auto font-mono text-[10px]', MUTED), children: lane.lastAt ? new Date(lane.lastAt).toLocaleString() : '' })] }), _jsxs("div", { className: "mt-3 flex flex-wrap items-center gap-1.5", children: [lane.loads.length === 0 && (_jsx("span", { className: cn('text-[11px]', MUTED), children: "No loads recorded." })), [...lane.loads].reverse().map((load) => (_jsx(Tooltip, { content: _jsxs("span", { className: "font-mono text-[11px]", children: [load.snapshotId, _jsx("br", {}), load.rows, " rows \u00B7 ", load.committed ? 'committed' : 'written, never committed', _jsx("br", {}), new Date(load.at).toLocaleString()] }), children: _jsxs("span", { className: cn('flex cursor-help items-center gap-1 rounded-md border px-1.5 py-0.5 font-mono text-[10px]', load.committed
|
|
91
|
+
? 'border-emerald-200 text-emerald-700 dark:border-emerald-900 dark:text-emerald-300'
|
|
92
|
+
: 'border-amber-200 text-amber-700 dark:border-amber-900 dark:text-amber-300'), children: [load.committed ? _jsx(CircleCheck, { size: 10 }) : _jsx(CircleDot, { size: 10 }), load.rows] }) }, load.snapshotId)))] }), _jsxs("div", { className: cn('mt-2 flex flex-wrap gap-3 font-mono text-[10px]', MUTED), children: [_jsxs("span", { children: [committed, " committed"] }), uncommitted > 0 && (_jsx(Tooltip, { content: "Written but never committed. Nobody is reading these \u2014 a publisher that stopped halfway leaves exactly this.", children: _jsxs("span", { className: "cursor-help text-amber-600", children: [uncommitted, " left uncommitted"] }) })), lane.schemaChanges > 0 && (_jsx(Tooltip, { content: "Columns were added. This catalog never drops or retypes one automatically.", children: _jsxs("span", { className: "flex cursor-help items-center gap-1", children: [_jsx(CircleAlert, { size: 10 }), lane.schemaChanges, " schema change", lane.schemaChanges === 1 ? '' : 's'] }) }))] })] }));
|
|
93
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type CatalogTraceSource } from './TraceExplorer';
|
|
2
|
+
/**
|
|
3
|
+
* What happened, to what, by whom.
|
|
4
|
+
*
|
|
5
|
+
* The same events the library publishes on `aviary:catalog:*`, recorded as they
|
|
6
|
+
* happen. A diagnostics channel only reaches observers listening at the time,
|
|
7
|
+
* and the governance question is always asked afterwards.
|
|
8
|
+
*/
|
|
9
|
+
export declare function GovernanceTimeline({ traceSource, }?: {
|
|
10
|
+
/**
|
|
11
|
+
* Where the trace view reads from. Optional: when the host's catalog client
|
|
12
|
+
* already exposes `listTraces`, the screen finds it and nothing needs
|
|
13
|
+
* passing. See `useTraceSource`.
|
|
14
|
+
*/
|
|
15
|
+
traceSource?: CatalogTraceSource;
|
|
16
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useQuery } from '@tanstack/react-query';
|
|
3
|
+
import { List, Waypoints } from 'lucide-react';
|
|
4
|
+
import { useMemo, useState } from 'react';
|
|
5
|
+
import { CATALOG_EVENT_META, TraceExplorer, eventMeta, } from './TraceExplorer';
|
|
6
|
+
import { cn } from './cn';
|
|
7
|
+
import { useCatalogClient } from './context';
|
|
8
|
+
import { Tooltip, TooltipProvider } from './ui/tooltip';
|
|
9
|
+
const MUTED = 'text-zinc-400 dark:text-zinc-500';
|
|
10
|
+
const RULE = 'border-zinc-200 dark:border-zinc-800';
|
|
11
|
+
const PANEL = 'bg-white dark:bg-zinc-900';
|
|
12
|
+
const VIEWS = [
|
|
13
|
+
{
|
|
14
|
+
id: 'traces',
|
|
15
|
+
label: 'Traces',
|
|
16
|
+
icon: Waypoints,
|
|
17
|
+
meaning: 'One story per load: what started it, what happened in between, and how it ended.',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
id: 'events',
|
|
21
|
+
label: 'Events',
|
|
22
|
+
icon: List,
|
|
23
|
+
meaning: 'Every recorded event, newest first, exactly as it was written.',
|
|
24
|
+
},
|
|
25
|
+
];
|
|
26
|
+
/**
|
|
27
|
+
* What happened, to what, by whom.
|
|
28
|
+
*
|
|
29
|
+
* The same events the library publishes on `aviary:catalog:*`, recorded as they
|
|
30
|
+
* happen. A diagnostics channel only reaches observers listening at the time,
|
|
31
|
+
* and the governance question is always asked afterwards.
|
|
32
|
+
*/
|
|
33
|
+
export function GovernanceTimeline({ traceSource, } = {}) {
|
|
34
|
+
const client = useCatalogClient();
|
|
35
|
+
const [view, setView] = useState('traces');
|
|
36
|
+
const [event, setEvent] = useState('');
|
|
37
|
+
const [principal, setPrincipal] = useState('');
|
|
38
|
+
const { data: events = [], isLoading } = useQuery({
|
|
39
|
+
queryKey: ['catalog', 'events', event, principal],
|
|
40
|
+
queryFn: () => client.listEvents({
|
|
41
|
+
event: event || undefined,
|
|
42
|
+
principalId: principal || undefined,
|
|
43
|
+
limit: 200,
|
|
44
|
+
}),
|
|
45
|
+
refetchInterval: 15_000,
|
|
46
|
+
});
|
|
47
|
+
const principals = useMemo(() => [...new Set(events.map((e) => e.principalId).filter(Boolean))], [events]);
|
|
48
|
+
const grouped = useMemo(() => {
|
|
49
|
+
const byDay = new Map();
|
|
50
|
+
for (const entry of events) {
|
|
51
|
+
const day = new Date(entry.occurredAt).toDateString();
|
|
52
|
+
const list = byDay.get(day) ?? [];
|
|
53
|
+
list.push(entry);
|
|
54
|
+
byDay.set(day, list);
|
|
55
|
+
}
|
|
56
|
+
return [...byDay.entries()];
|
|
57
|
+
}, [events]);
|
|
58
|
+
return (_jsx(TooltipProvider, { children: _jsx("div", { className: "h-full overflow-y-auto", children: _jsxs("div", { className: "mx-auto max-w-4xl px-8 py-8", children: [_jsx("p", { className: cn('font-mono text-[11px] uppercase tracking-[0.18em]', MUTED), children: "Governance" }), _jsx("h1", { className: "mt-1 text-2xl font-semibold tracking-tight", children: "What happened" }), _jsx("p", { className: cn('mt-1 max-w-2xl text-sm', 'text-zinc-500 dark:text-zinc-400'), children: "Every load, schema change and curation edit, as it happened. Recorded from the same events the library publishes, because a channel only reaches whoever was listening at the time." }), _jsxs("div", { className: "mt-5 flex flex-wrap items-center gap-2", children: [_jsx("div", { className: cn('flex overflow-hidden rounded-md border', RULE), children: VIEWS.map((option) => {
|
|
59
|
+
const Icon = option.icon;
|
|
60
|
+
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
|
+
? 'bg-zinc-100 text-zinc-950 dark:bg-zinc-800 dark:text-zinc-50'
|
|
62
|
+
: 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: [_jsxs("select", { value: event, onChange: (e) => setEvent(e.target.value), "aria-label": "Filter by event", className: cn('rounded-md border bg-white px-2 py-1 text-xs outline-none dark:bg-zinc-900', RULE), children: [_jsx("option", { value: "", children: "Every event" }), Object.entries(CATALOG_EVENT_META).map(([id, meta]) => (_jsx("option", { value: id, children: meta.label }, id)))] }), _jsxs("select", { value: principal, onChange: (e) => setPrincipal(e.target.value), "aria-label": "Filter by application", className: cn('rounded-md border bg-white px-2 py-1 text-xs outline-none dark:bg-zinc-900', RULE), children: [_jsx("option", { value: "", children: "Every application" }), principals.map((id) => (_jsx("option", { value: id, children: id }, id)))] })] }))] }), 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
|
+
}
|
|
65
|
+
function Row({ entry }) {
|
|
66
|
+
// One shared map with the trace view. Two copies drifted the first time a new
|
|
67
|
+
// event was added and one screen kept rendering it as a bare event name.
|
|
68
|
+
const meta = eventMeta(entry.event);
|
|
69
|
+
const Icon = meta.icon;
|
|
70
|
+
return (_jsxs("div", { className: "flex items-start gap-3 border-b border-zinc-100 px-4 py-2.5 last:border-0 dark:border-zinc-900", children: [_jsx(Tooltip, { content: meta.meaning, side: "right", children: _jsx("span", { className: cn('mt-0.5 shrink-0 cursor-help', meta.tone), children: _jsx(Icon, { size: 14 }) }) }), _jsxs("div", { className: "min-w-0 flex-1", children: [_jsxs("div", { className: "flex flex-wrap items-baseline gap-x-2", children: [_jsx("span", { className: "text-sm", children: meta.label }), entry.typeName && _jsx("span", { className: "font-mono text-[11px]", children: entry.typeName }), entry.snapshotId && (_jsx("span", { className: cn('font-mono text-[10px]', MUTED), children: entry.snapshotId }))] }), _jsx("div", { className: cn('font-mono text-[10px]', MUTED), children: detailOf(entry) })] }), _jsxs("div", { className: "shrink-0 text-right", children: [entry.principalId && _jsx("div", { className: "font-mono text-[11px]", children: entry.principalId }), _jsx("div", { className: cn('font-mono text-[10px]', MUTED), children: new Date(entry.occurredAt).toLocaleTimeString() })] })] }));
|
|
71
|
+
}
|
|
72
|
+
/** One line of the payload, chosen per event rather than dumped as JSON. */
|
|
73
|
+
function detailOf(entry) {
|
|
74
|
+
const detail = entry.detail ?? {};
|
|
75
|
+
switch (entry.event) {
|
|
76
|
+
case 'snapshot.committed':
|
|
77
|
+
return `${detail.rowCount ?? '?'} rows now served`;
|
|
78
|
+
case 'snapshot.written':
|
|
79
|
+
return `${detail.rows ?? '?'} rows in this batch`;
|
|
80
|
+
case 'schema.changed': {
|
|
81
|
+
const added = Array.isArray(detail.addedColumns) ? detail.addedColumns : [];
|
|
82
|
+
return detail.created
|
|
83
|
+
? `table created with ${added.length} columns`
|
|
84
|
+
: `added ${added.join(', ')}`;
|
|
85
|
+
}
|
|
86
|
+
case 'type.curated': {
|
|
87
|
+
const changed = Array.isArray(detail.changed) ? detail.changed.join(', ') : '';
|
|
88
|
+
return detail.property ? `${detail.property}: ${changed}` : changed;
|
|
89
|
+
}
|
|
90
|
+
default:
|
|
91
|
+
return '';
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface ObjectExplorerProps {
|
|
2
|
+
/** Which type to open. Omit to fall back to `?type=` then the first type. */
|
|
3
|
+
type?: string;
|
|
4
|
+
pageSize?: number;
|
|
5
|
+
/** Where to send the "back" link. Omit to hide it. */
|
|
6
|
+
backHref?: string;
|
|
7
|
+
backLabel?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function ObjectExplorer({ type: typeProp, pageSize, backHref, backLabel, }: ObjectExplorerProps): import("react/jsx-runtime").JSX.Element;
|