@quantumwake/terminal-ux-dashboard-components 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +11 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +12 -7
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -11,6 +11,13 @@ interface SavedDashboard {
|
|
|
11
11
|
name: string;
|
|
12
12
|
[key: string]: unknown;
|
|
13
13
|
}
|
|
14
|
+
interface PanelInput {
|
|
15
|
+
title: string;
|
|
16
|
+
type: string;
|
|
17
|
+
config: Record<string, unknown>;
|
|
18
|
+
width: number;
|
|
19
|
+
height: number;
|
|
20
|
+
}
|
|
14
21
|
interface DashboardCapabilities {
|
|
15
22
|
runQuery: (sql: string, stateId?: string) => Promise<QueryResult>;
|
|
16
23
|
saveDashboard?: (name?: string) => Promise<void> | void;
|
|
@@ -20,6 +27,7 @@ interface DashboardCapabilities {
|
|
|
20
27
|
deleteDashboard?: (id: string) => Promise<void> | void;
|
|
21
28
|
analyzeDataset?: () => Promise<void> | void;
|
|
22
29
|
refineDashboard?: (prompt: string) => Promise<void> | void;
|
|
30
|
+
addPanel?: (panel: PanelInput) => void;
|
|
23
31
|
removePanel?: (panelId: string) => void;
|
|
24
32
|
}
|
|
25
33
|
interface DashboardContextValue extends DashboardCapabilities {
|
|
@@ -40,6 +48,7 @@ declare function useCapabilities(): {
|
|
|
40
48
|
canDelete: boolean;
|
|
41
49
|
canAnalyze: boolean;
|
|
42
50
|
canRefine: boolean;
|
|
51
|
+
canAddPanel: boolean;
|
|
43
52
|
canEditPanels: boolean;
|
|
44
53
|
};
|
|
45
54
|
|
|
@@ -474,4 +483,4 @@ interface DataExplorerProps {
|
|
|
474
483
|
}
|
|
475
484
|
declare function DataExplorer({ records, columns, states, activeStateId, profile, dashboard, dashboardId, savedDashboards, loading, analyzing, onSelectState, onRefreshStates, }: DataExplorerProps): react.JSX.Element;
|
|
476
485
|
|
|
477
|
-
export { type AggFn, type BarDatum, BarView, type BarViewProps, ChartBuilder, type ChartBuilderColumn, type ChartBuilderProps, type ChartConfig, type ChartField, type ChartFilter, type ChartPanel, type ChartStyle, ChartStyleControls, type ChartStyleControlsProps, type ChartType, DEFAULT_CHART_STYLE, type Dashboard$1 as Dashboard, type DashboardCapabilities, type DashboardContextValue, type DashboardPanel$1 as DashboardPanel, DashboardProvider, type DashboardProviderProps, DashboardRenderer, type DashboardRendererProps, type DashboardTheme, DataExplorer, type DataExplorerProps, type HeatmapSerie, HeatmapView, type HeatmapViewProps, type InsightConfig, InsightView, type InsightViewProps, LEGEND_ANCHORS, type LegendAnchor, type LegendPosition, type LineSerie, LineView, type LineViewProps, type MetricConfig, MetricView, type MetricViewProps, type PieDatum, PieView, type PieViewProps, PivotView, type PivotViewProps, type QueryResult, type Row, type SavedDashboard, type ScatterSerie, ScatterView, type ScatterViewProps, SqlConsole, type SqlConsoleColumn, type SqlConsoleProps, type TitleAlign, aggExpr, aggregate, axisLegend, buildChartSQL, buildNivoTheme, compileWhere, groupBy, legendConfig, qIdent, qLit, shapeChartData, useCapabilities, useDashboard, withStyleDefaults };
|
|
486
|
+
export { type AggFn, type BarDatum, BarView, type BarViewProps, ChartBuilder, type ChartBuilderColumn, type ChartBuilderProps, type ChartConfig, type ChartField, type ChartFilter, type ChartPanel, type ChartStyle, ChartStyleControls, type ChartStyleControlsProps, type ChartType, DEFAULT_CHART_STYLE, type Dashboard$1 as Dashboard, type DashboardCapabilities, type DashboardContextValue, type DashboardPanel$1 as DashboardPanel, DashboardProvider, type DashboardProviderProps, DashboardRenderer, type DashboardRendererProps, type DashboardTheme, DataExplorer, type DataExplorerProps, type HeatmapSerie, HeatmapView, type HeatmapViewProps, type InsightConfig, InsightView, type InsightViewProps, LEGEND_ANCHORS, type LegendAnchor, type LegendPosition, type LineSerie, LineView, type LineViewProps, type MetricConfig, MetricView, type MetricViewProps, type PanelInput, type PieDatum, PieView, type PieViewProps, PivotView, type PivotViewProps, type QueryResult, type Row, type SavedDashboard, type ScatterSerie, ScatterView, type ScatterViewProps, SqlConsole, type SqlConsoleColumn, type SqlConsoleProps, type TitleAlign, aggExpr, aggregate, axisLegend, buildChartSQL, buildNivoTheme, compileWhere, groupBy, legendConfig, qIdent, qLit, shapeChartData, useCapabilities, useDashboard, withStyleDefaults };
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,13 @@ interface SavedDashboard {
|
|
|
11
11
|
name: string;
|
|
12
12
|
[key: string]: unknown;
|
|
13
13
|
}
|
|
14
|
+
interface PanelInput {
|
|
15
|
+
title: string;
|
|
16
|
+
type: string;
|
|
17
|
+
config: Record<string, unknown>;
|
|
18
|
+
width: number;
|
|
19
|
+
height: number;
|
|
20
|
+
}
|
|
14
21
|
interface DashboardCapabilities {
|
|
15
22
|
runQuery: (sql: string, stateId?: string) => Promise<QueryResult>;
|
|
16
23
|
saveDashboard?: (name?: string) => Promise<void> | void;
|
|
@@ -20,6 +27,7 @@ interface DashboardCapabilities {
|
|
|
20
27
|
deleteDashboard?: (id: string) => Promise<void> | void;
|
|
21
28
|
analyzeDataset?: () => Promise<void> | void;
|
|
22
29
|
refineDashboard?: (prompt: string) => Promise<void> | void;
|
|
30
|
+
addPanel?: (panel: PanelInput) => void;
|
|
23
31
|
removePanel?: (panelId: string) => void;
|
|
24
32
|
}
|
|
25
33
|
interface DashboardContextValue extends DashboardCapabilities {
|
|
@@ -40,6 +48,7 @@ declare function useCapabilities(): {
|
|
|
40
48
|
canDelete: boolean;
|
|
41
49
|
canAnalyze: boolean;
|
|
42
50
|
canRefine: boolean;
|
|
51
|
+
canAddPanel: boolean;
|
|
43
52
|
canEditPanels: boolean;
|
|
44
53
|
};
|
|
45
54
|
|
|
@@ -474,4 +483,4 @@ interface DataExplorerProps {
|
|
|
474
483
|
}
|
|
475
484
|
declare function DataExplorer({ records, columns, states, activeStateId, profile, dashboard, dashboardId, savedDashboards, loading, analyzing, onSelectState, onRefreshStates, }: DataExplorerProps): react.JSX.Element;
|
|
476
485
|
|
|
477
|
-
export { type AggFn, type BarDatum, BarView, type BarViewProps, ChartBuilder, type ChartBuilderColumn, type ChartBuilderProps, type ChartConfig, type ChartField, type ChartFilter, type ChartPanel, type ChartStyle, ChartStyleControls, type ChartStyleControlsProps, type ChartType, DEFAULT_CHART_STYLE, type Dashboard$1 as Dashboard, type DashboardCapabilities, type DashboardContextValue, type DashboardPanel$1 as DashboardPanel, DashboardProvider, type DashboardProviderProps, DashboardRenderer, type DashboardRendererProps, type DashboardTheme, DataExplorer, type DataExplorerProps, type HeatmapSerie, HeatmapView, type HeatmapViewProps, type InsightConfig, InsightView, type InsightViewProps, LEGEND_ANCHORS, type LegendAnchor, type LegendPosition, type LineSerie, LineView, type LineViewProps, type MetricConfig, MetricView, type MetricViewProps, type PieDatum, PieView, type PieViewProps, PivotView, type PivotViewProps, type QueryResult, type Row, type SavedDashboard, type ScatterSerie, ScatterView, type ScatterViewProps, SqlConsole, type SqlConsoleColumn, type SqlConsoleProps, type TitleAlign, aggExpr, aggregate, axisLegend, buildChartSQL, buildNivoTheme, compileWhere, groupBy, legendConfig, qIdent, qLit, shapeChartData, useCapabilities, useDashboard, withStyleDefaults };
|
|
486
|
+
export { type AggFn, type BarDatum, BarView, type BarViewProps, ChartBuilder, type ChartBuilderColumn, type ChartBuilderProps, type ChartConfig, type ChartField, type ChartFilter, type ChartPanel, type ChartStyle, ChartStyleControls, type ChartStyleControlsProps, type ChartType, DEFAULT_CHART_STYLE, type Dashboard$1 as Dashboard, type DashboardCapabilities, type DashboardContextValue, type DashboardPanel$1 as DashboardPanel, DashboardProvider, type DashboardProviderProps, DashboardRenderer, type DashboardRendererProps, type DashboardTheme, DataExplorer, type DataExplorerProps, type HeatmapSerie, HeatmapView, type HeatmapViewProps, type InsightConfig, InsightView, type InsightViewProps, LEGEND_ANCHORS, type LegendAnchor, type LegendPosition, type LineSerie, LineView, type LineViewProps, type MetricConfig, MetricView, type MetricViewProps, type PanelInput, type PieDatum, PieView, type PieViewProps, PivotView, type PivotViewProps, type QueryResult, type Row, type SavedDashboard, type ScatterSerie, ScatterView, type ScatterViewProps, SqlConsole, type SqlConsoleColumn, type SqlConsoleProps, type TitleAlign, aggExpr, aggregate, axisLegend, buildChartSQL, buildNivoTheme, compileWhere, groupBy, legendConfig, qIdent, qLit, shapeChartData, useCapabilities, useDashboard, withStyleDefaults };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createContext, useContext, useMemo, useState, useEffect, Suspense } from 'react';
|
|
1
|
+
import { createContext, useContext, useMemo, useState, useRef, useEffect, Suspense } from 'react';
|
|
2
2
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
3
3
|
import { ResponsiveBar } from '@nivo/bar';
|
|
4
4
|
import { ResponsivePie } from '@nivo/pie';
|
|
@@ -32,6 +32,7 @@ function useCapabilities() {
|
|
|
32
32
|
canDelete: !!c.deleteDashboard,
|
|
33
33
|
canAnalyze: !!c.analyzeDataset,
|
|
34
34
|
canRefine: !!c.refineDashboard,
|
|
35
|
+
canAddPanel: !!c.addPanel,
|
|
35
36
|
canEditPanels: !!c.removePanel
|
|
36
37
|
};
|
|
37
38
|
}
|
|
@@ -1014,6 +1015,8 @@ var ChartPreview = ({
|
|
|
1014
1015
|
};
|
|
1015
1016
|
function ChartBuilder({ records, columns, stateId, onSave }) {
|
|
1016
1017
|
const { theme, runQuery } = useDashboard();
|
|
1018
|
+
const runQueryRef = useRef(runQuery);
|
|
1019
|
+
runQueryRef.current = runQuery;
|
|
1017
1020
|
const [chartType, setChartType] = useState("bar");
|
|
1018
1021
|
const [xFields, setXFields] = useState([]);
|
|
1019
1022
|
const [yFields, setYFields] = useState([]);
|
|
@@ -1047,7 +1050,7 @@ function ChartBuilder({ records, columns, stateId, onSave }) {
|
|
|
1047
1050
|
let cancelled = false;
|
|
1048
1051
|
setSqlLoading(true);
|
|
1049
1052
|
setSqlError(null);
|
|
1050
|
-
|
|
1053
|
+
runQueryRef.current(generatedSql, stateId).then((res) => {
|
|
1051
1054
|
if (cancelled) return;
|
|
1052
1055
|
setSqlLoading(false);
|
|
1053
1056
|
setSqlRows(res.rows || []);
|
|
@@ -1060,7 +1063,7 @@ function ChartBuilder({ records, columns, stateId, onSave }) {
|
|
|
1060
1063
|
return () => {
|
|
1061
1064
|
cancelled = true;
|
|
1062
1065
|
};
|
|
1063
|
-
}, [engineMode, generatedSql,
|
|
1066
|
+
}, [engineMode, generatedSql, stateId]);
|
|
1064
1067
|
const addField = (zone, field) => {
|
|
1065
1068
|
switch (zone) {
|
|
1066
1069
|
case "x":
|
|
@@ -1343,6 +1346,8 @@ function ViewLoading() {
|
|
|
1343
1346
|
}
|
|
1344
1347
|
function SqlPanel({ panel }) {
|
|
1345
1348
|
const { runQuery } = useDashboard();
|
|
1349
|
+
const runQueryRef = useRef(runQuery);
|
|
1350
|
+
runQueryRef.current = runQuery;
|
|
1346
1351
|
const config = panel.config || {};
|
|
1347
1352
|
const chartType = config.chartType || panel.type;
|
|
1348
1353
|
const [rows, setRows] = useState(null);
|
|
@@ -1353,7 +1358,7 @@ function SqlPanel({ panel }) {
|
|
|
1353
1358
|
setLoading(true);
|
|
1354
1359
|
setError(null);
|
|
1355
1360
|
const sql = config.sql || "";
|
|
1356
|
-
|
|
1361
|
+
runQueryRef.current(sql).then(
|
|
1357
1362
|
(res) => {
|
|
1358
1363
|
if (cancelled) return;
|
|
1359
1364
|
setLoading(false);
|
|
@@ -1369,7 +1374,7 @@ function SqlPanel({ panel }) {
|
|
|
1369
1374
|
return () => {
|
|
1370
1375
|
cancelled = true;
|
|
1371
1376
|
};
|
|
1372
|
-
}, [config.sql
|
|
1377
|
+
}, [config.sql]);
|
|
1373
1378
|
if (loading && !rows) {
|
|
1374
1379
|
return /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center h-full text-xs text-midnight-text-muted", children: "Running\u2026" });
|
|
1375
1380
|
}
|
|
@@ -1614,7 +1619,7 @@ function DataExplorer({
|
|
|
1614
1619
|
onSelectState,
|
|
1615
1620
|
onRefreshStates
|
|
1616
1621
|
}) {
|
|
1617
|
-
const { theme, saveDashboard, listDashboards, searchDashboards, loadDashboard, deleteDashboard, analyzeDataset, refineDashboard } = useDashboard();
|
|
1622
|
+
const { theme, addPanel, saveDashboard, listDashboards, searchDashboards, loadDashboard, deleteDashboard, analyzeDataset, refineDashboard } = useDashboard();
|
|
1618
1623
|
const caps = useCapabilities();
|
|
1619
1624
|
const [mode, setMode] = useState("dashboard");
|
|
1620
1625
|
const [fullscreen, setFullscreen] = useState(false);
|
|
@@ -1752,7 +1757,7 @@ function DataExplorer({
|
|
|
1752
1757
|
)
|
|
1753
1758
|
] }, d.id))
|
|
1754
1759
|
] }),
|
|
1755
|
-
/* @__PURE__ */ jsx("div", { className: `border ${theme.border} bg-midnight-surface flex-1 flex flex-col min-h-0`, children: mode === "sql" ? /* @__PURE__ */ jsx(SqlConsole, { columns, stateId: activeStateId ?? void 0 }) : mode === "builder" ? /* @__PURE__ */ jsx(ChartBuilder, { records, columns, stateId: activeStateId ?? void 0 }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1760
|
+
/* @__PURE__ */ jsx("div", { className: `border ${theme.border} bg-midnight-surface flex-1 flex flex-col min-h-0`, children: mode === "sql" ? /* @__PURE__ */ jsx(SqlConsole, { columns, stateId: activeStateId ?? void 0 }) : mode === "builder" ? /* @__PURE__ */ jsx(ChartBuilder, { records, columns, stateId: activeStateId ?? void 0, onSave: addPanel }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1756
1761
|
/* @__PURE__ */ jsx("div", { className: "flex-1 min-h-0 overflow-auto", children: dashboard ? /* @__PURE__ */ jsx(DashboardRenderer, { dashboard, records, columns }) : /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center justify-center h-full gap-4 text-midnight-text-muted", children: [
|
|
1757
1762
|
/* @__PURE__ */ jsx(Sparkles, { className: "w-8 h-8" }),
|
|
1758
1763
|
/* @__PURE__ */ jsx("p", { className: "text-sm", children: caps.canAnalyze ? /* @__PURE__ */ jsxs(Fragment, { children: [
|