@quantumwake/terminal-ux-dashboard-components 0.1.10 → 0.1.12
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 +37 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +37 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1684,6 +1684,36 @@ function ChartBuilder({ records, columns, stateId, onSave }) {
|
|
|
1684
1684
|
function ViewLoading() {
|
|
1685
1685
|
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center h-full text-xs text-midnight-text-muted", children: "Loading..." });
|
|
1686
1686
|
}
|
|
1687
|
+
var SQL_CHART_TYPES = /* @__PURE__ */ new Set(["bar", "grouped-bar", "pie", "line", "scatter", "heatmap"]);
|
|
1688
|
+
function panelToChartConfig(chartType, config) {
|
|
1689
|
+
const cfg = { chartType, xFields: [], yFields: [], filters: config.filters || [] };
|
|
1690
|
+
switch (chartType) {
|
|
1691
|
+
case "bar":
|
|
1692
|
+
case "grouped-bar":
|
|
1693
|
+
if (config.group) cfg.xFields = [{ name: config.group }];
|
|
1694
|
+
cfg.yFields = config.yFields?.length ? config.yFields : config.value ? [{ name: config.value, agg: config.agg }] : [];
|
|
1695
|
+
break;
|
|
1696
|
+
case "pie":
|
|
1697
|
+
if (config.group) cfg.xFields = [{ name: config.group }];
|
|
1698
|
+
break;
|
|
1699
|
+
case "line":
|
|
1700
|
+
case "scatter":
|
|
1701
|
+
if (config.x) cfg.xFields = [{ name: config.x }];
|
|
1702
|
+
if (config.y) cfg.yFields = [{ name: config.y }];
|
|
1703
|
+
break;
|
|
1704
|
+
case "heatmap":
|
|
1705
|
+
if (config.row) cfg.xFields = [{ name: config.row }];
|
|
1706
|
+
if (config.col) cfg.yFields = [{ name: config.col }];
|
|
1707
|
+
if (config.value) cfg.valueField = { name: config.value, agg: config.agg };
|
|
1708
|
+
break;
|
|
1709
|
+
}
|
|
1710
|
+
return cfg;
|
|
1711
|
+
}
|
|
1712
|
+
function panelSql(chartType, config) {
|
|
1713
|
+
if (config.sql) return config.sql;
|
|
1714
|
+
if (SQL_CHART_TYPES.has(chartType)) return buildChartSQL(panelToChartConfig(chartType, config)) || "";
|
|
1715
|
+
return "";
|
|
1716
|
+
}
|
|
1687
1717
|
function SqlPanel({ panel }) {
|
|
1688
1718
|
const { runQuery, persistPanelData } = useDashboard();
|
|
1689
1719
|
const { canRefresh } = useCapabilities();
|
|
@@ -1691,6 +1721,7 @@ function SqlPanel({ panel }) {
|
|
|
1691
1721
|
runQueryRef.current = runQuery;
|
|
1692
1722
|
const config = panel.config || {};
|
|
1693
1723
|
const chartType = config.chartType || panel.type;
|
|
1724
|
+
const sql = panelSql(chartType, config);
|
|
1694
1725
|
const precomputed = config.data;
|
|
1695
1726
|
const [rows, setRows] = react.useState(precomputed ?? null);
|
|
1696
1727
|
const [error, setError] = react.useState(null);
|
|
@@ -1709,7 +1740,7 @@ function SqlPanel({ panel }) {
|
|
|
1709
1740
|
let cancelled = false;
|
|
1710
1741
|
setLoading(true);
|
|
1711
1742
|
setError(null);
|
|
1712
|
-
runQueryRef.current(
|
|
1743
|
+
runQueryRef.current(sql).then(
|
|
1713
1744
|
(res) => {
|
|
1714
1745
|
if (!cancelled) {
|
|
1715
1746
|
setLoading(false);
|
|
@@ -1727,12 +1758,12 @@ function SqlPanel({ panel }) {
|
|
|
1727
1758
|
return () => {
|
|
1728
1759
|
cancelled = true;
|
|
1729
1760
|
};
|
|
1730
|
-
}, [
|
|
1761
|
+
}, [sql, canRefresh]);
|
|
1731
1762
|
const refresh = react.useCallback(async () => {
|
|
1732
1763
|
setRefreshing(true);
|
|
1733
1764
|
setError(null);
|
|
1734
1765
|
try {
|
|
1735
|
-
const res = await runQueryRef.current(
|
|
1766
|
+
const res = await runQueryRef.current(sql);
|
|
1736
1767
|
const r = res?.rows || [];
|
|
1737
1768
|
setRows(r);
|
|
1738
1769
|
persistPanelData?.(panel.id, r, (/* @__PURE__ */ new Date()).toISOString());
|
|
@@ -1741,7 +1772,7 @@ function SqlPanel({ panel }) {
|
|
|
1741
1772
|
} finally {
|
|
1742
1773
|
setRefreshing(false);
|
|
1743
1774
|
}
|
|
1744
|
-
}, [
|
|
1775
|
+
}, [sql, panel.id, persistPanelData]);
|
|
1745
1776
|
const refreshBtn = canRefresh ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1746
1777
|
"button",
|
|
1747
1778
|
{
|
|
@@ -1812,7 +1843,8 @@ function SqlPanel({ panel }) {
|
|
|
1812
1843
|
function PanelContent({ panel, records, columns }) {
|
|
1813
1844
|
const { type } = panel;
|
|
1814
1845
|
const config = panel.config || {};
|
|
1815
|
-
|
|
1846
|
+
const effType = config.chartType || type;
|
|
1847
|
+
if (config.sql || SQL_CHART_TYPES.has(effType)) {
|
|
1816
1848
|
return /* @__PURE__ */ jsxRuntime.jsx(SqlPanel, { panel });
|
|
1817
1849
|
}
|
|
1818
1850
|
if (!records?.length && type !== "insight") {
|