@quantumwake/terminal-ux-dashboard-components 0.1.0 → 0.1.1

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
@@ -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';
@@ -1014,6 +1014,8 @@ var ChartPreview = ({
1014
1014
  };
1015
1015
  function ChartBuilder({ records, columns, stateId, onSave }) {
1016
1016
  const { theme, runQuery } = useDashboard();
1017
+ const runQueryRef = useRef(runQuery);
1018
+ runQueryRef.current = runQuery;
1017
1019
  const [chartType, setChartType] = useState("bar");
1018
1020
  const [xFields, setXFields] = useState([]);
1019
1021
  const [yFields, setYFields] = useState([]);
@@ -1047,7 +1049,7 @@ function ChartBuilder({ records, columns, stateId, onSave }) {
1047
1049
  let cancelled = false;
1048
1050
  setSqlLoading(true);
1049
1051
  setSqlError(null);
1050
- runQuery(generatedSql, stateId).then((res) => {
1052
+ runQueryRef.current(generatedSql, stateId).then((res) => {
1051
1053
  if (cancelled) return;
1052
1054
  setSqlLoading(false);
1053
1055
  setSqlRows(res.rows || []);
@@ -1060,7 +1062,7 @@ function ChartBuilder({ records, columns, stateId, onSave }) {
1060
1062
  return () => {
1061
1063
  cancelled = true;
1062
1064
  };
1063
- }, [engineMode, generatedSql, runQuery, stateId]);
1065
+ }, [engineMode, generatedSql, stateId]);
1064
1066
  const addField = (zone, field) => {
1065
1067
  switch (zone) {
1066
1068
  case "x":
@@ -1343,6 +1345,8 @@ function ViewLoading() {
1343
1345
  }
1344
1346
  function SqlPanel({ panel }) {
1345
1347
  const { runQuery } = useDashboard();
1348
+ const runQueryRef = useRef(runQuery);
1349
+ runQueryRef.current = runQuery;
1346
1350
  const config = panel.config || {};
1347
1351
  const chartType = config.chartType || panel.type;
1348
1352
  const [rows, setRows] = useState(null);
@@ -1353,7 +1357,7 @@ function SqlPanel({ panel }) {
1353
1357
  setLoading(true);
1354
1358
  setError(null);
1355
1359
  const sql = config.sql || "";
1356
- runQuery(sql).then(
1360
+ runQueryRef.current(sql).then(
1357
1361
  (res) => {
1358
1362
  if (cancelled) return;
1359
1363
  setLoading(false);
@@ -1369,7 +1373,7 @@ function SqlPanel({ panel }) {
1369
1373
  return () => {
1370
1374
  cancelled = true;
1371
1375
  };
1372
- }, [config.sql, runQuery]);
1376
+ }, [config.sql]);
1373
1377
  if (loading && !rows) {
1374
1378
  return /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center h-full text-xs text-midnight-text-muted", children: "Running\u2026" });
1375
1379
  }