@quantumwake/terminal-ux-dashboard-components 0.1.3 → 0.1.5
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 +49 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -2
- package/dist/index.d.ts +12 -2
- package/dist/index.js +51 -24
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -649,18 +649,19 @@ var renderCell = (v) => {
|
|
|
649
649
|
if (typeof v === "boolean") return v ? "true" : "false";
|
|
650
650
|
return String(v);
|
|
651
651
|
};
|
|
652
|
-
function SqlConsole({ columns = [], stateId }) {
|
|
652
|
+
function SqlConsole({ columns = [], stateId, defaultColumnsOpen = false, defaultSql = DEFAULT_SQL, autoRun = false }) {
|
|
653
653
|
const { theme, runQuery } = useDashboard();
|
|
654
|
-
const [sql, setSql] = react.useState(
|
|
654
|
+
const [sql, setSql] = react.useState(defaultSql);
|
|
655
655
|
const [result, setResult] = react.useState(null);
|
|
656
656
|
const [error, setError] = react.useState(null);
|
|
657
657
|
const [running, setRunning] = react.useState(false);
|
|
658
|
-
const
|
|
659
|
-
|
|
658
|
+
const [columnsOpen, setColumnsOpen] = react.useState(defaultColumnsOpen);
|
|
659
|
+
const run = async (text = sql) => {
|
|
660
|
+
if (running || !text.trim()) return;
|
|
660
661
|
setRunning(true);
|
|
661
662
|
setError(null);
|
|
662
663
|
try {
|
|
663
|
-
const data = await runQuery(
|
|
664
|
+
const data = await runQuery(text, stateId);
|
|
664
665
|
setResult({ columns: data.columns || [], rows: data.rows || [] });
|
|
665
666
|
} catch (err) {
|
|
666
667
|
setResult(null);
|
|
@@ -669,6 +670,11 @@ function SqlConsole({ columns = [], stateId }) {
|
|
|
669
670
|
setRunning(false);
|
|
670
671
|
}
|
|
671
672
|
};
|
|
673
|
+
react.useEffect(() => {
|
|
674
|
+
if (!autoRun || !stateId) return;
|
|
675
|
+
setSql(defaultSql);
|
|
676
|
+
void run(defaultSql);
|
|
677
|
+
}, [stateId, autoRun, defaultSql]);
|
|
672
678
|
const onKeyDown = (e) => {
|
|
673
679
|
if ((e.metaKey || e.ctrlKey) && e.key === "Enter") {
|
|
674
680
|
e.preventDefault();
|
|
@@ -709,19 +715,34 @@ function SqlConsole({ columns = [], stateId }) {
|
|
|
709
715
|
placeholder: "SELECT ... FROM data"
|
|
710
716
|
}
|
|
711
717
|
),
|
|
712
|
-
columns.length > 0 && /* @__PURE__ */ jsxRuntime.
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
718
|
+
columns.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-2", children: [
|
|
719
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
720
|
+
"button",
|
|
721
|
+
{
|
|
722
|
+
onClick: () => setColumnsOpen((o) => !o),
|
|
723
|
+
className: "flex items-center gap-1 text-[11px] font-mono text-midnight-text-muted hover:text-midnight-text-body transition-colors",
|
|
724
|
+
children: [
|
|
725
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronDown, { className: `w-3 h-3 transition-transform ${columnsOpen ? "" : "-rotate-90"}` }),
|
|
726
|
+
"Columns (",
|
|
727
|
+
columns.length,
|
|
728
|
+
")"
|
|
729
|
+
]
|
|
730
|
+
}
|
|
731
|
+
),
|
|
732
|
+
columnsOpen && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1.5 flex flex-wrap gap-1", children: columns.map((c) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
733
|
+
"button",
|
|
734
|
+
{
|
|
735
|
+
title: `Insert ${c.name}`,
|
|
736
|
+
onClick: () => setSql((s) => `${s}${s.endsWith(" ") || s.endsWith("\n") || !s ? "" : " "}${c.name}`),
|
|
737
|
+
className: "px-1.5 py-0.5 border border-midnight-border text-[11px] font-mono text-midnight-text-muted hover:bg-midnight-raised transition-colors",
|
|
738
|
+
children: [
|
|
739
|
+
c.name,
|
|
740
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "opacity-50 ml-1", children: c.type })
|
|
741
|
+
]
|
|
742
|
+
},
|
|
743
|
+
c.name
|
|
744
|
+
)) })
|
|
745
|
+
] })
|
|
725
746
|
] }),
|
|
726
747
|
(result || error) && /* @__PURE__ */ jsxRuntime.jsx("div", { className: `flex items-center gap-4 px-3 py-1.5 border-b ${theme.border} text-xs font-mono shrink-0 ${error ? "text-red-400" : "text-midnight-text-muted"}`, children: error ? /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "flex items-center gap-1.5", children: [
|
|
727
748
|
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.AlertCircle, { className: "w-3.5 h-3.5" }),
|
|
@@ -1612,6 +1633,11 @@ function ModeTab({ active, onClick, icon: Icon, label }) {
|
|
|
1612
1633
|
}
|
|
1613
1634
|
);
|
|
1614
1635
|
}
|
|
1636
|
+
var MODE_TABS = [
|
|
1637
|
+
{ mode: "dashboard", icon: lucideReact.Sparkles, label: "Dashboard" },
|
|
1638
|
+
{ mode: "builder", icon: lucideReact.BarChart3, label: "Chart Builder" },
|
|
1639
|
+
{ mode: "sql", icon: lucideReact.Terminal, label: "SQL" }
|
|
1640
|
+
];
|
|
1615
1641
|
function DataExplorer({
|
|
1616
1642
|
records,
|
|
1617
1643
|
columns,
|
|
@@ -1623,12 +1649,15 @@ function DataExplorer({
|
|
|
1623
1649
|
savedDashboards = [],
|
|
1624
1650
|
loading = false,
|
|
1625
1651
|
analyzing = false,
|
|
1652
|
+
defaultMode = "dashboard",
|
|
1653
|
+
tabs = ["dashboard", "builder", "sql"],
|
|
1626
1654
|
onSelectState,
|
|
1627
1655
|
onRefreshStates
|
|
1628
1656
|
}) {
|
|
1629
1657
|
const { theme, newDashboard, addPanel, saveDashboard, listDashboards, searchDashboards, loadDashboard, deleteDashboard, analyzeDataset, refineDashboard } = useDashboard();
|
|
1630
1658
|
const caps = useCapabilities();
|
|
1631
|
-
const
|
|
1659
|
+
const visibleTabs = MODE_TABS.filter((t) => tabs.includes(t.mode));
|
|
1660
|
+
const [mode, setMode] = react.useState(tabs.includes(defaultMode) ? defaultMode : tabs[0] ?? "sql");
|
|
1632
1661
|
const [fullscreen, setFullscreen] = react.useState(false);
|
|
1633
1662
|
const [showSaved, setShowSaved] = react.useState(false);
|
|
1634
1663
|
const [saveName, setSaveName] = react.useState("");
|
|
@@ -1693,9 +1722,7 @@ function DataExplorer({
|
|
|
1693
1722
|
)
|
|
1694
1723
|
] }),
|
|
1695
1724
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1 mb-3 shrink-0", children: [
|
|
1696
|
-
/* @__PURE__ */ jsxRuntime.jsx(ModeTab, { active: mode ===
|
|
1697
|
-
/* @__PURE__ */ jsxRuntime.jsx(ModeTab, { active: mode === "builder", onClick: () => setMode("builder"), icon: lucideReact.BarChart3, label: "Chart Builder" }),
|
|
1698
|
-
/* @__PURE__ */ jsxRuntime.jsx(ModeTab, { active: mode === "sql", onClick: () => setMode("sql"), icon: lucideReact.Terminal, label: "SQL" }),
|
|
1725
|
+
visibleTabs.map((t) => /* @__PURE__ */ jsxRuntime.jsx(ModeTab, { active: mode === t.mode, onClick: () => setMode(t.mode), icon: t.icon, label: t.label }, t.mode)),
|
|
1699
1726
|
caps.canNew && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1700
1727
|
"button",
|
|
1701
1728
|
{
|