@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.js CHANGED
@@ -1677,6 +1677,36 @@ function ChartBuilder({ records, columns, stateId, onSave }) {
1677
1677
  function ViewLoading() {
1678
1678
  return /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center h-full text-xs text-midnight-text-muted", children: "Loading..." });
1679
1679
  }
1680
+ var SQL_CHART_TYPES = /* @__PURE__ */ new Set(["bar", "grouped-bar", "pie", "line", "scatter", "heatmap"]);
1681
+ function panelToChartConfig(chartType, config) {
1682
+ const cfg = { chartType, xFields: [], yFields: [], filters: config.filters || [] };
1683
+ switch (chartType) {
1684
+ case "bar":
1685
+ case "grouped-bar":
1686
+ if (config.group) cfg.xFields = [{ name: config.group }];
1687
+ cfg.yFields = config.yFields?.length ? config.yFields : config.value ? [{ name: config.value, agg: config.agg }] : [];
1688
+ break;
1689
+ case "pie":
1690
+ if (config.group) cfg.xFields = [{ name: config.group }];
1691
+ break;
1692
+ case "line":
1693
+ case "scatter":
1694
+ if (config.x) cfg.xFields = [{ name: config.x }];
1695
+ if (config.y) cfg.yFields = [{ name: config.y }];
1696
+ break;
1697
+ case "heatmap":
1698
+ if (config.row) cfg.xFields = [{ name: config.row }];
1699
+ if (config.col) cfg.yFields = [{ name: config.col }];
1700
+ if (config.value) cfg.valueField = { name: config.value, agg: config.agg };
1701
+ break;
1702
+ }
1703
+ return cfg;
1704
+ }
1705
+ function panelSql(chartType, config) {
1706
+ if (config.sql) return config.sql;
1707
+ if (SQL_CHART_TYPES.has(chartType)) return buildChartSQL(panelToChartConfig(chartType, config)) || "";
1708
+ return "";
1709
+ }
1680
1710
  function SqlPanel({ panel }) {
1681
1711
  const { runQuery, persistPanelData } = useDashboard();
1682
1712
  const { canRefresh } = useCapabilities();
@@ -1684,6 +1714,7 @@ function SqlPanel({ panel }) {
1684
1714
  runQueryRef.current = runQuery;
1685
1715
  const config = panel.config || {};
1686
1716
  const chartType = config.chartType || panel.type;
1717
+ const sql = panelSql(chartType, config);
1687
1718
  const precomputed = config.data;
1688
1719
  const [rows, setRows] = useState(precomputed ?? null);
1689
1720
  const [error, setError] = useState(null);
@@ -1702,7 +1733,7 @@ function SqlPanel({ panel }) {
1702
1733
  let cancelled = false;
1703
1734
  setLoading(true);
1704
1735
  setError(null);
1705
- runQueryRef.current(config.sql || "").then(
1736
+ runQueryRef.current(sql).then(
1706
1737
  (res) => {
1707
1738
  if (!cancelled) {
1708
1739
  setLoading(false);
@@ -1720,12 +1751,12 @@ function SqlPanel({ panel }) {
1720
1751
  return () => {
1721
1752
  cancelled = true;
1722
1753
  };
1723
- }, [config.sql, canRefresh]);
1754
+ }, [sql, canRefresh]);
1724
1755
  const refresh = useCallback(async () => {
1725
1756
  setRefreshing(true);
1726
1757
  setError(null);
1727
1758
  try {
1728
- const res = await runQueryRef.current(config.sql || "");
1759
+ const res = await runQueryRef.current(sql);
1729
1760
  const r = res?.rows || [];
1730
1761
  setRows(r);
1731
1762
  persistPanelData?.(panel.id, r, (/* @__PURE__ */ new Date()).toISOString());
@@ -1734,7 +1765,7 @@ function SqlPanel({ panel }) {
1734
1765
  } finally {
1735
1766
  setRefreshing(false);
1736
1767
  }
1737
- }, [config.sql, panel.id, persistPanelData]);
1768
+ }, [sql, panel.id, persistPanelData]);
1738
1769
  const refreshBtn = canRefresh ? /* @__PURE__ */ jsx(
1739
1770
  "button",
1740
1771
  {
@@ -1805,7 +1836,8 @@ function SqlPanel({ panel }) {
1805
1836
  function PanelContent({ panel, records, columns }) {
1806
1837
  const { type } = panel;
1807
1838
  const config = panel.config || {};
1808
- if (config.sql) {
1839
+ const effType = config.chartType || type;
1840
+ if (config.sql || SQL_CHART_TYPES.has(effType)) {
1809
1841
  return /* @__PURE__ */ jsx(SqlPanel, { panel });
1810
1842
  }
1811
1843
  if (!records?.length && type !== "insight") {