@devtable/dashboard 0.2.0 → 0.4.0

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.
@@ -32,10 +32,10 @@ var __objRest = (source, exclude) => {
32
32
  import React from "react";
33
33
  import _ from "lodash";
34
34
  import { WidthProvider, Responsive } from "react-grid-layout";
35
- import { Text, Table, Group, LoadingOverlay, Box, Textarea, Button, TextInput, ActionIcon, useMantineTheme, ColorSwatch, Select, Slider, Switch, JsonInput, Divider, Modal, AppShell, Navbar, Tabs, Tooltip, Container, SegmentedControl } from "@mantine/core";
35
+ import { Text, Table, Group, LoadingOverlay, Box, Textarea, Button, TextInput, ActionIcon, useMantineTheme, ColorSwatch, Select, Switch, Slider, JsonInput, Divider, Modal, AppShell, Navbar, Tabs, Tooltip, Menu, Container, SegmentedControl } from "@mantine/core";
36
36
  import { useRequest } from "ahooks";
37
37
  import axios from "axios";
38
- import { Trash, DeviceFloppy, Settings, Refresh, InfoCircle, Paint, PlayerPlay, PlaylistAdd, Recycle, Share } from "tabler-icons-react";
38
+ import { Trash, DeviceFloppy, InfoCircle, Refresh, Settings, Paint, PlayerPlay, PlaylistAdd, Recycle, Share } from "tabler-icons-react";
39
39
  import { useElementSize, randomId, useInputState, useListState } from "@mantine/hooks";
40
40
  import ReactEChartsCore from "echarts-for-react/lib/core";
41
41
  import * as echarts from "echarts/core";
@@ -94,15 +94,20 @@ function getSQLParams(context, definitions) {
94
94
  ret[curr.key] = formatSQL(curr.value, context);
95
95
  return ret;
96
96
  }, {});
97
- return _.defaultsDeep(context, sqlSnippetRecord);
97
+ return _.merge({}, sqlSnippetRecord, context);
98
98
  }
99
99
  const queryBySQL = (sql, context, definitions, title) => async () => {
100
100
  if (!sql) {
101
101
  return [];
102
102
  }
103
+ const needParams = sql.includes("$");
103
104
  const params = getSQLParams(context, definitions);
105
+ if (needParams && Object.keys(params).length === 0) {
106
+ console.error(`[queryBySQL] insufficient params for {${title}}'s SQL`);
107
+ return [];
108
+ }
104
109
  const formattedSQL = formatSQL(sql, params);
105
- if (sql.includes("$")) {
110
+ if (needParams) {
106
111
  console.groupCollapsed(`Final SQL for: ${title}`);
107
112
  console.log(formattedSQL);
108
113
  console.groupEnd();
@@ -218,7 +223,7 @@ function Sunbrust({
218
223
  const chartData = React.useMemo(() => {
219
224
  return data.map((d) => ({
220
225
  name: d[label_field],
221
- value: d[value_field]
226
+ value: Number(d[value_field])
222
227
  }));
223
228
  }, [data, label_field, value_field]);
224
229
  const max = React.useMemo(() => {
@@ -240,7 +245,7 @@ function Sunbrust({
240
245
  }
241
246
  }
242
247
  }), []);
243
- const option = _.defaultsDeep(defaultOption$1, labelOption, restConf, {
248
+ const option = _.merge(defaultOption$1, labelOption, restConf, {
244
249
  series: {
245
250
  data: chartData
246
251
  }
@@ -265,7 +270,14 @@ const defaultOption = {
265
270
  xAxis: {
266
271
  type: "category"
267
272
  },
268
- yAxis: {}
273
+ yAxis: {},
274
+ grid: {
275
+ top: 30,
276
+ left: 10,
277
+ right: 10,
278
+ bottom: 10,
279
+ containLabel: true
280
+ }
269
281
  };
270
282
  function VizLineBarChart({
271
283
  conf,
@@ -461,11 +473,16 @@ function VizText({
461
473
  return /* @__PURE__ */ jsx(Fragment, {
462
474
  children: paragraphs.map((_a, index2) => {
463
475
  var _b = _a, {
464
- template
476
+ template,
477
+ size
465
478
  } = _b, rest = __objRest(_b, [
466
- "template"
479
+ "template",
480
+ "size"
467
481
  ]);
468
482
  return /* @__PURE__ */ jsx(Text, __spreadProps(__spreadValues({}, rest), {
483
+ sx: {
484
+ fontSize: size
485
+ },
469
486
  children: interpolateString(template, data[0])
470
487
  }), `${template}---${index2}`);
471
488
  })
@@ -705,7 +722,6 @@ function SQLSnippetsForm({
705
722
  sqlSnippets,
706
723
  setSQLSnippets
707
724
  }) {
708
- const submitButton = React.useRef(null);
709
725
  const initialValues = React.useMemo(() => ({
710
726
  snippets: formList(sqlSnippets != null ? sqlSnippets : [])
711
727
  }), [sqlSnippets]);
@@ -717,12 +733,6 @@ function SQLSnippetsForm({
717
733
  value: ""
718
734
  });
719
735
  const changed = React.useMemo(() => !_.isEqual(form.values, initialValues), [form.values, initialValues]);
720
- React.useEffect(() => {
721
- var _a;
722
- if (changed) {
723
- (_a = submitButton == null ? void 0 : submitButton.current) == null ? void 0 : _a.click();
724
- }
725
- }, [changed, submitButton.current]);
726
736
  const submit = ({
727
737
  snippets
728
738
  }) => {
@@ -731,19 +741,13 @@ function SQLSnippetsForm({
731
741
  return /* @__PURE__ */ jsx(Group, {
732
742
  direction: "column",
733
743
  sx: {
734
- width: "100%"
744
+ width: "100%",
745
+ position: "relative"
735
746
  },
736
747
  grow: true,
737
748
  children: /* @__PURE__ */ jsxs("form", {
738
749
  onSubmit: form.onSubmit(submit),
739
- children: [/* @__PURE__ */ jsx("button", {
740
- ref: submitButton,
741
- type: "submit",
742
- style: {
743
- display: "none"
744
- },
745
- children: "Ghost submit"
746
- }), form.values.snippets.map((_item, index2) => /* @__PURE__ */ jsxs(Group, {
750
+ children: [form.values.snippets.map((_item, index2) => /* @__PURE__ */ jsxs(Group, {
747
751
  direction: "column",
748
752
  grow: true,
749
753
  my: 0,
@@ -773,19 +777,24 @@ function SQLSnippetsForm({
773
777
  size: 16
774
778
  })
775
779
  })]
776
- }, index2)), /* @__PURE__ */ jsx(Group, {
780
+ }, index2)), /* @__PURE__ */ jsxs(Group, {
777
781
  position: "center",
778
782
  mt: "xl",
779
783
  grow: true,
780
784
  sx: {
781
- width: "60%"
785
+ width: "80%"
782
786
  },
783
787
  mx: "auto",
784
- children: /* @__PURE__ */ jsx(Button, {
785
- color: "blue",
788
+ children: [/* @__PURE__ */ jsx(Button, {
789
+ variant: "default",
786
790
  onClick: addSnippet,
787
791
  children: "Add a snippet"
788
- })
792
+ }), /* @__PURE__ */ jsx(Button, {
793
+ color: "blue",
794
+ type: "submit",
795
+ disabled: !changed,
796
+ children: "Submit"
797
+ })]
789
798
  })]
790
799
  })
791
800
  });
@@ -806,6 +815,7 @@ WHERE \${author_time_condition}`;
806
815
  width: "100%"
807
816
  },
808
817
  noCopy: true,
818
+ trim: false,
809
819
  colorScheme: "dark",
810
820
  children: `-- You may refer context data *by name*
811
821
  -- in SQL or VizConfig.
@@ -814,7 +824,7 @@ ${sampleSQL}
814
824
 
815
825
  -- where author_time_condition is:
816
826
  author_time BETWEEN '\${timeRange?.[0].toISOString()}' AND '\${timeRange?.[1].toISOString()}'
817
- `
827
+ `
818
828
  }), /* @__PURE__ */ jsx(Text, {
819
829
  weight: 700,
820
830
  children: "SQL Snippets"
@@ -1101,7 +1111,6 @@ function VizLineBarChartPanel({
1101
1111
  conf,
1102
1112
  setConf
1103
1113
  }) {
1104
- const submitButton = React.useRef(null);
1105
1114
  const _a = conf, {
1106
1115
  series
1107
1116
  } = _a, restConf = __objRest(_a, [
@@ -1121,13 +1130,7 @@ function VizLineBarChartPanel({
1121
1130
  stack: "",
1122
1131
  color: "#000"
1123
1132
  });
1124
- const changed = React.useMemo(() => !_.isEqual(form.values, initialValues), [form.values, initialValues]);
1125
- React.useEffect(() => {
1126
- var _a2;
1127
- if (changed) {
1128
- (_a2 = submitButton == null ? void 0 : submitButton.current) == null ? void 0 : _a2.click();
1129
- }
1130
- }, [changed, submitButton.current]);
1133
+ React.useMemo(() => !_.isEqual(form.values, initialValues), [form.values, initialValues]);
1131
1134
  return /* @__PURE__ */ jsx(Group, {
1132
1135
  direction: "column",
1133
1136
  mt: "md",
@@ -1143,13 +1146,14 @@ function VizLineBarChartPanel({
1143
1146
  },
1144
1147
  children: [/* @__PURE__ */ jsx(Text, {
1145
1148
  children: "Chart Config"
1146
- }), /* @__PURE__ */ jsx("button", {
1147
- ref: submitButton,
1149
+ }), /* @__PURE__ */ jsx(ActionIcon, {
1148
1150
  type: "submit",
1149
- style: {
1150
- display: "none"
1151
- },
1152
- children: "Ghost submit"
1151
+ mr: 5,
1152
+ variant: "filled",
1153
+ color: "blue",
1154
+ children: /* @__PURE__ */ jsx(DeviceFloppy, {
1155
+ size: 20
1156
+ })
1153
1157
  })]
1154
1158
  }), /* @__PURE__ */ jsx(TextInput, __spreadValues({
1155
1159
  size: "md",
@@ -1220,20 +1224,17 @@ function VizLineBarChartPanel({
1220
1224
  })
1221
1225
  });
1222
1226
  }
1223
- function SunburstPanel(_a) {
1224
- var _b = _a, {
1225
- conf: _c
1226
- } = _b, _d = _c, {
1227
- columns
1228
- } = _d, restConf = __objRest(_d, [
1229
- "columns"
1230
- ]), {
1231
- setConf
1232
- } = _b;
1227
+ function SunburstPanel({
1228
+ conf: {
1229
+ label_field,
1230
+ value_field
1231
+ },
1232
+ setConf
1233
+ }) {
1233
1234
  const form = useForm({
1234
1235
  initialValues: {
1235
- label_field: "name",
1236
- value_field: "value"
1236
+ label_field,
1237
+ value_field
1237
1238
  }
1238
1239
  });
1239
1240
  return /* @__PURE__ */ jsx(Group, {
@@ -1289,52 +1290,6 @@ function SunburstPanel(_a) {
1289
1290
  })
1290
1291
  });
1291
1292
  }
1292
- const marks$1 = [{
1293
- "value": 0,
1294
- "label": "xs"
1295
- }, {
1296
- "value": 25,
1297
- "label": "sm"
1298
- }, {
1299
- "value": 50,
1300
- "label": "md"
1301
- }, {
1302
- "value": 75,
1303
- "label": "lg"
1304
- }, {
1305
- "value": 100,
1306
- "label": "xl"
1307
- }];
1308
- function MantineSizeSlider({
1309
- label,
1310
- value,
1311
- onChange
1312
- }) {
1313
- var _a, _b;
1314
- const [mark, setMark] = React.useState((_b = (_a = marks$1.find((m2) => m2.label === value)) == null ? void 0 : _a.value) != null ? _b : marks$1[0].value);
1315
- React.useEffect(() => {
1316
- const match = marks$1.find((s) => s.value === mark);
1317
- if (match) {
1318
- onChange(match.label);
1319
- }
1320
- }, [mark]);
1321
- return /* @__PURE__ */ jsxs(Group, {
1322
- direction: "column",
1323
- grow: true,
1324
- spacing: "xs",
1325
- mb: "lg",
1326
- children: [/* @__PURE__ */ jsx(Text, {
1327
- children: label
1328
- }), /* @__PURE__ */ jsx(Slider, {
1329
- label: null,
1330
- marks: marks$1,
1331
- value: mark,
1332
- onChange: setMark,
1333
- step: 25,
1334
- placeholder: "Pick a font size"
1335
- })]
1336
- });
1337
- }
1338
1293
  const valueTypes = Object.values(ValueType).map((v) => ({
1339
1294
  label: v,
1340
1295
  value: v
@@ -1353,16 +1308,16 @@ function ValueTypeSelector({
1353
1308
  sx
1354
1309
  });
1355
1310
  }
1356
- function VizTablePanel(_e) {
1357
- var _f = _e, {
1358
- conf: _g
1359
- } = _f, _h = _g, {
1311
+ function VizTablePanel(_a) {
1312
+ var _b = _a, {
1313
+ conf: _c
1314
+ } = _b, _d = _c, {
1360
1315
  columns
1361
- } = _h, restConf = __objRest(_h, [
1316
+ } = _d, restConf = __objRest(_d, [
1362
1317
  "columns"
1363
1318
  ]), {
1364
1319
  setConf
1365
- } = _f;
1320
+ } = _b;
1366
1321
  const form = useForm({
1367
1322
  initialValues: __spreadValues({
1368
1323
  id_field: "id",
@@ -1428,10 +1383,20 @@ function VizTablePanel(_e) {
1428
1383
  flexGrow: 1
1429
1384
  }
1430
1385
  },
1431
- children: [/* @__PURE__ */ jsx(MantineSizeSlider, __spreadValues({
1432
- label: "Horizontal Spacing"
1433
- }, form.getInputProps("horizontalSpacing"))), /* @__PURE__ */ jsx(MantineSizeSlider, __spreadValues({
1434
- label: "Vertical Spacing"
1386
+ children: [/* @__PURE__ */ jsx(TextInput, __spreadValues({
1387
+ label: "Horizontal Spacing",
1388
+ placeholder: "10px, 1em, 1rem, 100%...",
1389
+ required: true,
1390
+ sx: {
1391
+ flex: 1
1392
+ }
1393
+ }, form.getInputProps("horizontalSpacing"))), /* @__PURE__ */ jsx(TextInput, __spreadValues({
1394
+ label: "Vertical Spacing",
1395
+ placeholder: "10px, 1em, 1rem, 100%...",
1396
+ required: true,
1397
+ sx: {
1398
+ flex: 1
1399
+ }
1435
1400
  }, form.getInputProps("verticalSpacing")))]
1436
1401
  }), /* @__PURE__ */ jsx(Group, {
1437
1402
  position: "apart",
@@ -1442,8 +1407,13 @@ function VizTablePanel(_e) {
1442
1407
  flexGrow: 1
1443
1408
  }
1444
1409
  },
1445
- children: /* @__PURE__ */ jsx(MantineSizeSlider, __spreadValues({
1446
- label: "Font Size"
1410
+ children: /* @__PURE__ */ jsx(TextInput, __spreadValues({
1411
+ label: "Font Size",
1412
+ placeholder: "10px, 1em, 1rem, 100%...",
1413
+ required: true,
1414
+ sx: {
1415
+ flex: 1
1416
+ }
1447
1417
  }, form.getInputProps("size")))
1448
1418
  }), /* @__PURE__ */ jsxs(Group, {
1449
1419
  direction: "column",
@@ -1575,7 +1545,7 @@ const marks = [{
1575
1545
  label: "bold",
1576
1546
  value: 100
1577
1547
  }];
1578
- function MantineFontSizeSlider({
1548
+ function MantineFontWeightSlider({
1579
1549
  label,
1580
1550
  value,
1581
1551
  onChange
@@ -1684,7 +1654,17 @@ function VizTextPanel({
1684
1654
  children: [/* @__PURE__ */ jsx(Text, {
1685
1655
  children: "Color"
1686
1656
  }), /* @__PURE__ */ jsx(MantineColorSelector, __spreadValues({}, form.getListInputProps("paragraphs", index2, "color")))]
1687
- }), /* @__PURE__ */ jsxs(Group, {
1657
+ }), /* @__PURE__ */ jsx(Group, {
1658
+ direction: "column",
1659
+ grow: true,
1660
+ children: /* @__PURE__ */ jsx(TextInput, __spreadValues({
1661
+ label: "Font Size",
1662
+ placeholder: "10px, 1em, 1rem, 100%...",
1663
+ sx: {
1664
+ flex: 1
1665
+ }
1666
+ }, form.getListInputProps("paragraphs", index2, "size")))
1667
+ }), /* @__PURE__ */ jsx(Group, {
1688
1668
  position: "apart",
1689
1669
  grow: true,
1690
1670
  sx: {
@@ -1693,11 +1673,9 @@ function VizTextPanel({
1693
1673
  maxWidth: "100%"
1694
1674
  }
1695
1675
  },
1696
- children: [/* @__PURE__ */ jsx(MantineSizeSlider, __spreadValues({
1697
- label: "Font Size"
1698
- }, form.getListInputProps("paragraphs", index2, "size"))), /* @__PURE__ */ jsx(MantineFontSizeSlider, __spreadValues({
1676
+ children: /* @__PURE__ */ jsx(MantineFontWeightSlider, __spreadValues({
1699
1677
  label: "Font Weight"
1700
- }, form.getListInputProps("paragraphs", index2, "weight")))]
1678
+ }, form.getListInputProps("paragraphs", index2, "weight")))
1701
1679
  }), /* @__PURE__ */ jsx(ActionIcon, {
1702
1680
  color: "red",
1703
1681
  variant: "hover",
@@ -1815,7 +1793,10 @@ function VizConfig({}) {
1815
1793
  children: [/* @__PURE__ */ jsx(EditTitle, {}), /* @__PURE__ */ jsx(EditDescription, {}), /* @__PURE__ */ jsx(Divider, {}), /* @__PURE__ */ jsx(EditVizConf, {})]
1816
1794
  });
1817
1795
  }
1818
- function PanelSettings({}) {
1796
+ function PanelSettingsModal({
1797
+ opened,
1798
+ close
1799
+ }) {
1819
1800
  const {
1820
1801
  freezeLayout
1821
1802
  } = React.useContext(LayoutStateContext);
@@ -1825,153 +1806,141 @@ function PanelSettings({}) {
1825
1806
  viz,
1826
1807
  title
1827
1808
  } = React.useContext(PanelContext);
1828
- const [opened, setOpened] = React.useState(false);
1829
- const open = () => setOpened(true);
1830
1809
  React.useEffect(() => {
1831
1810
  freezeLayout(opened);
1832
1811
  }, [opened]);
1833
- return /* @__PURE__ */ jsxs(Fragment, {
1834
- children: [/* @__PURE__ */ jsx(Modal, {
1835
- size: "96vw",
1836
- overflow: "inside",
1837
- opened,
1838
- onClose: () => setOpened(false),
1839
- title,
1840
- trapFocus: true,
1841
- onDragStart: (e) => {
1842
- e.stopPropagation();
1843
- },
1844
- children: /* @__PURE__ */ jsx(AppShell, {
1845
- sx: {
1846
- height: "90vh",
1847
- maxHeight: "calc(100vh - 185px)",
1848
- ".mantine-AppShell-body": {
1849
- height: "100%"
1850
- },
1851
- main: {
1852
- height: "100%",
1853
- width: "100%"
1854
- }
1812
+ return /* @__PURE__ */ jsx(Modal, {
1813
+ size: "96vw",
1814
+ overflow: "inside",
1815
+ opened,
1816
+ onClose: close,
1817
+ title,
1818
+ trapFocus: true,
1819
+ onDragStart: (e) => {
1820
+ e.stopPropagation();
1821
+ },
1822
+ children: /* @__PURE__ */ jsx(AppShell, {
1823
+ sx: {
1824
+ height: "90vh",
1825
+ maxHeight: "calc(100vh - 185px)",
1826
+ ".mantine-AppShell-body": {
1827
+ height: "100%"
1855
1828
  },
1856
- padding: "md",
1857
- navbar: /* @__PURE__ */ jsx(Navbar, {
1858
- width: {
1859
- base: "40%"
1860
- },
1829
+ main: {
1861
1830
  height: "100%",
1862
- p: "xs",
1863
- children: /* @__PURE__ */ jsxs(Tabs, {
1864
- initialTab: 1,
1865
- children: [/* @__PURE__ */ jsx(Tabs.Tab, {
1866
- label: "Context",
1867
- children: /* @__PURE__ */ jsx(ContextInfo, {})
1868
- }), /* @__PURE__ */ jsx(Tabs.Tab, {
1869
- label: "SQL Snippets",
1870
- children: /* @__PURE__ */ jsx(SQLSnippetsTab, {})
1871
- }), /* @__PURE__ */ jsx(Tabs.Tab, {
1872
- label: "SQL",
1873
- children: /* @__PURE__ */ jsx(QueryEditor, {})
1874
- }), /* @__PURE__ */ jsxs(Tabs.Tab, {
1875
- label: "Data",
1876
- children: [/* @__PURE__ */ jsx(LoadingOverlay, {
1877
- visible: loading
1878
- }), /* @__PURE__ */ jsx(QueryResult, {})]
1879
- }), /* @__PURE__ */ jsx(Tabs.Tab, {
1880
- label: "Viz Config",
1881
- children: /* @__PURE__ */ jsx(VizConfig, {})
1882
- })]
1883
- })
1884
- }),
1885
- children: /* @__PURE__ */ jsx(ErrorBoundary, {
1886
- children: /* @__PURE__ */ jsx(Viz, {
1887
- viz,
1888
- data,
1889
- loading
1890
- })
1831
+ width: "100%"
1832
+ }
1833
+ },
1834
+ padding: "md",
1835
+ navbar: /* @__PURE__ */ jsx(Navbar, {
1836
+ width: {
1837
+ base: "40%"
1838
+ },
1839
+ height: "100%",
1840
+ p: "xs",
1841
+ children: /* @__PURE__ */ jsxs(Tabs, {
1842
+ initialTab: 1,
1843
+ children: [/* @__PURE__ */ jsx(Tabs.Tab, {
1844
+ label: "Context",
1845
+ children: /* @__PURE__ */ jsx(ContextInfo, {})
1846
+ }), /* @__PURE__ */ jsx(Tabs.Tab, {
1847
+ label: "SQL Snippets",
1848
+ children: /* @__PURE__ */ jsx(SQLSnippetsTab, {})
1849
+ }), /* @__PURE__ */ jsx(Tabs.Tab, {
1850
+ label: "SQL",
1851
+ children: /* @__PURE__ */ jsx(QueryEditor, {})
1852
+ }), /* @__PURE__ */ jsxs(Tabs.Tab, {
1853
+ label: "Data",
1854
+ children: [/* @__PURE__ */ jsx(LoadingOverlay, {
1855
+ visible: loading
1856
+ }), /* @__PURE__ */ jsx(QueryResult, {})]
1857
+ }), /* @__PURE__ */ jsx(Tabs.Tab, {
1858
+ label: "Viz Config",
1859
+ children: /* @__PURE__ */ jsx(VizConfig, {})
1860
+ })]
1861
+ })
1862
+ }),
1863
+ children: /* @__PURE__ */ jsx(ErrorBoundary, {
1864
+ children: /* @__PURE__ */ jsx(Viz, {
1865
+ viz,
1866
+ data,
1867
+ loading
1891
1868
  })
1892
1869
  })
1893
- }), /* @__PURE__ */ jsx(ActionIcon, {
1894
- variant: "hover",
1895
- color: "blue",
1896
- loading,
1897
- onClick: open,
1898
- children: /* @__PURE__ */ jsx(Settings, {
1899
- size: 16
1900
- })
1901
- })]
1870
+ })
1902
1871
  });
1903
1872
  }
1904
- function PanelTitle({
1905
- title,
1906
- description
1907
- }) {
1873
+ function PanelTitleBar({}) {
1874
+ const [opened, setOpened] = React.useState(false);
1875
+ const open = () => setOpened(true);
1876
+ const close = () => setOpened(false);
1877
+ const {
1878
+ title,
1879
+ description,
1880
+ loading,
1881
+ refreshData
1882
+ } = React.useContext(PanelContext);
1883
+ const {
1884
+ inEditMode
1885
+ } = React.useContext(LayoutStateContext);
1908
1886
  return /* @__PURE__ */ jsxs(Group, {
1909
- position: "center",
1887
+ position: "apart",
1888
+ noWrap: true,
1910
1889
  sx: {
1911
1890
  borderBottom: "1px solid #eee",
1912
1891
  paddingBottom: "5px"
1913
1892
  },
1914
- children: [!description && /* @__PURE__ */ jsx(Text, {
1915
- weight: "bold",
1916
- sx: {
1917
- marginLeft: "5px",
1918
- display: "inline"
1919
- },
1920
- children: title
1921
- }), description && /* @__PURE__ */ jsx("div", {
1922
- children: /* @__PURE__ */ jsxs(Tooltip, {
1893
+ children: [/* @__PURE__ */ jsx(Group, {
1894
+ children: description && /* @__PURE__ */ jsx(Tooltip, {
1923
1895
  label: description,
1924
1896
  withArrow: true,
1925
- children: [/* @__PURE__ */ jsx(InfoCircle, {
1897
+ children: /* @__PURE__ */ jsx(InfoCircle, {
1926
1898
  size: 12,
1927
1899
  style: {
1928
1900
  verticalAlign: "baseline",
1929
1901
  cursor: "pointer"
1930
1902
  }
1931
- }), /* @__PURE__ */ jsx(Text, {
1932
- weight: "bold",
1933
- sx: {
1934
- marginLeft: "5px",
1935
- display: "inline"
1936
- },
1937
- children: title
1938
- })]
1903
+ })
1939
1904
  })
1940
- })]
1941
- });
1942
- }
1943
- function PanelTitleBar({}) {
1944
- const {
1945
- title,
1946
- description,
1947
- loading,
1948
- refreshData
1949
- } = React.useContext(PanelContext);
1950
- const {
1951
- inEditMode
1952
- } = React.useContext(LayoutStateContext);
1953
- return /* @__PURE__ */ jsxs(Fragment, {
1954
- children: [/* @__PURE__ */ jsx(PanelTitle, {
1955
- title,
1956
- description
1957
- }), /* @__PURE__ */ jsxs(Group, {
1905
+ }), /* @__PURE__ */ jsx(Group, {
1906
+ grow: true,
1907
+ position: "center",
1908
+ children: /* @__PURE__ */ jsx(Text, {
1909
+ lineClamp: 1,
1910
+ weight: "bold",
1911
+ children: title
1912
+ })
1913
+ }), /* @__PURE__ */ jsx(Group, {
1958
1914
  position: "right",
1959
1915
  spacing: 0,
1960
1916
  sx: {
1961
- position: "absolute",
1962
- right: "15px",
1963
- top: "4px",
1964
1917
  height: "28px"
1965
1918
  },
1966
- children: [/* @__PURE__ */ jsx(ActionIcon, {
1967
- variant: "hover",
1968
- color: "blue",
1969
- loading,
1970
- onClick: refreshData,
1971
- children: /* @__PURE__ */ jsx(Refresh, {
1972
- size: 16
1973
- })
1974
- }), inEditMode && /* @__PURE__ */ jsx(PanelSettings, {})]
1919
+ children: /* @__PURE__ */ jsxs(Menu, {
1920
+ children: [/* @__PURE__ */ jsx(Menu.Item, {
1921
+ onClick: refreshData,
1922
+ icon: /* @__PURE__ */ jsx(Refresh, {
1923
+ size: 14
1924
+ }),
1925
+ children: "Refresh"
1926
+ }), inEditMode && /* @__PURE__ */ jsx(Menu.Item, {
1927
+ onClick: open,
1928
+ icon: /* @__PURE__ */ jsx(Settings, {
1929
+ size: 14
1930
+ }),
1931
+ children: "Settings"
1932
+ }), /* @__PURE__ */ jsx(Divider, {}), /* @__PURE__ */ jsx(Menu.Item, {
1933
+ color: "red",
1934
+ disabled: true,
1935
+ icon: /* @__PURE__ */ jsx(Trash, {
1936
+ size: 14
1937
+ }),
1938
+ children: "Delete"
1939
+ })]
1940
+ })
1941
+ }), inEditMode && /* @__PURE__ */ jsx(PanelSettingsModal, {
1942
+ opened,
1943
+ close
1975
1944
  })]
1976
1945
  });
1977
1946
  }
@@ -1992,7 +1961,7 @@ function Panel({
1992
1961
  const [sql, setSQL] = React.useState(initialSQL);
1993
1962
  const [viz, setViz] = React.useState(initialViz);
1994
1963
  React.useEffect(() => {
1995
- update({
1964
+ update == null ? void 0 : update({
1996
1965
  id,
1997
1966
  layout,
1998
1967
  title,
@@ -2036,7 +2005,7 @@ function Panel({
2036
2005
  });
2037
2006
  }
2038
2007
  var index = "";
2039
- const ResponsiveReactGridLayout = WidthProvider(Responsive);
2008
+ const ResponsiveReactGridLayout$1 = WidthProvider(Responsive);
2040
2009
  function DashboardLayout({
2041
2010
  panels,
2042
2011
  setPanels,
@@ -2074,7 +2043,7 @@ function DashboardLayout({
2074
2043
  }));
2075
2044
  setPanels.setState(newPanels);
2076
2045
  }, [panels, setPanels]);
2077
- return /* @__PURE__ */ jsx(ResponsiveReactGridLayout, {
2046
+ return /* @__PURE__ */ jsx(ResponsiveReactGridLayout$1, {
2078
2047
  onBreakpointChange,
2079
2048
  onLayoutChange,
2080
2049
  className,
@@ -2195,7 +2164,6 @@ function Dashboard({
2195
2164
  className = "dashboard"
2196
2165
  }) {
2197
2166
  const [layoutFrozen, freezeLayout] = React.useState(false);
2198
- const [newCounter, setNewCounter] = React.useState(0);
2199
2167
  const [breakpoint, setBreakpoint] = React.useState();
2200
2168
  const [localCols, setLocalCols] = React.useState();
2201
2169
  const [panels, setPanels] = useListState(dashboard.panels);
@@ -2220,15 +2188,13 @@ function Dashboard({
2220
2188
  await update(d);
2221
2189
  };
2222
2190
  const addPanel = () => {
2223
- console.log("adding", "n" + newCounter);
2224
- setNewCounter((v) => v + 1);
2225
- const id = "n" + newCounter;
2191
+ const id = randomId();
2226
2192
  const newItem = {
2227
2193
  id,
2228
2194
  layout: {
2229
- x: panels.length * 2 % (localCols || 12),
2195
+ x: 0,
2230
2196
  y: Infinity,
2231
- w: 4,
2197
+ w: 3,
2232
2198
  h: 4
2233
2199
  },
2234
2200
  title: `New Panel - ${id}`,
@@ -2280,4 +2246,67 @@ function Dashboard({
2280
2246
  })
2281
2247
  });
2282
2248
  }
2283
- export { ContextInfoContext, Dashboard, DashboardLayout, DashboardMode, DefinitionContext, LayoutStateContext, Panel, PanelContext, initialContextInfoContext };
2249
+ const ResponsiveReactGridLayout = WidthProvider(Responsive);
2250
+ function ReadOnlyDashboardLayout({
2251
+ panels,
2252
+ className = "layout",
2253
+ cols = {
2254
+ lg: 12,
2255
+ md: 10,
2256
+ sm: 8,
2257
+ xs: 6,
2258
+ xxs: 4
2259
+ },
2260
+ rowHeight = 10
2261
+ }) {
2262
+ return /* @__PURE__ */ jsx(ResponsiveReactGridLayout, {
2263
+ className,
2264
+ cols,
2265
+ rowHeight,
2266
+ isDraggable: false,
2267
+ isResizable: false,
2268
+ children: panels.map((_a) => {
2269
+ var _b = _a, {
2270
+ id
2271
+ } = _b, rest = __objRest(_b, [
2272
+ "id"
2273
+ ]);
2274
+ return /* @__PURE__ */ jsx("div", {
2275
+ "data-grid": rest.layout,
2276
+ children: /* @__PURE__ */ jsx(Panel, __spreadValues({
2277
+ id
2278
+ }, rest))
2279
+ }, id);
2280
+ })
2281
+ });
2282
+ }
2283
+ function ReadOnlyDashboard({
2284
+ dashboard,
2285
+ className = "dashboard"
2286
+ }) {
2287
+ const [panels, setPanels] = useListState(dashboard.panels);
2288
+ const [sqlSnippets, setSQLSnippets] = React.useState(dashboard.definition.sqlSnippets);
2289
+ const definitions = React.useMemo(() => ({
2290
+ sqlSnippets,
2291
+ setSQLSnippets
2292
+ }), [sqlSnippets, setSQLSnippets]);
2293
+ return /* @__PURE__ */ jsx("div", {
2294
+ className,
2295
+ children: /* @__PURE__ */ jsx(DefinitionContext.Provider, {
2296
+ value: definitions,
2297
+ children: /* @__PURE__ */ jsx(LayoutStateContext.Provider, {
2298
+ value: {
2299
+ layoutFrozen: true,
2300
+ freezeLayout: () => {
2301
+ },
2302
+ mode: DashboardMode.Use,
2303
+ inEditMode: false
2304
+ },
2305
+ children: /* @__PURE__ */ jsx(ReadOnlyDashboardLayout, {
2306
+ panels
2307
+ })
2308
+ })
2309
+ })
2310
+ });
2311
+ }
2312
+ export { ContextInfoContext, Dashboard, DashboardLayout, DashboardMode, DefinitionContext, LayoutStateContext, Panel, PanelContext, ReadOnlyDashboard, initialContextInfoContext };
@@ -1,4 +1,4 @@
1
- (function(p,y){typeof exports=="object"&&typeof module!="undefined"?y(exports,require("react"),require("lodash"),require("react-grid-layout"),require("@mantine/core"),require("ahooks"),require("axios"),require("tabler-icons-react"),require("@mantine/hooks"),require("echarts-for-react/lib/core"),require("echarts/core"),require("echarts/charts"),require("echarts/renderers"),require("echarts/components"),require("numbro"),require("echarts-gl"),require("@mantine/prism"),require("@mantine/form"),require("react-hook-form")):typeof define=="function"&&define.amd?define(["exports","react","lodash","react-grid-layout","@mantine/core","ahooks","axios","tabler-icons-react","@mantine/hooks","echarts-for-react/lib/core","echarts/core","echarts/charts","echarts/renderers","echarts/components","numbro","echarts-gl","@mantine/prism","@mantine/form","react-hook-form"],y):(p=typeof globalThis!="undefined"?globalThis:p||self,y(p.dashboard={},p.React,p._,p["react-grid-layout"],p["@mantine/core"],p.ahooks,p.axios,p["tabler-icons-react"],p["@mantine/hooks"],p["echarts-for-react/lib/core"],p["echarts/core"],p["echarts/charts"],p["echarts/renderers"],p["echarts/components"],p.numbro,p["echarts-gl"],p["@mantine/prism"],p["@mantine/form"],p["react-hook-form"]))})(this,function(p,y,C,T,t,Ce,we,S,L,Te,_e,ee,te,A,ze,Gt,M,I,N){"use strict";var Lt=Object.defineProperty,It=Object.defineProperties;var kt=Object.getOwnPropertyDescriptors;var Z=Object.getOwnPropertySymbols;var ye=Object.prototype.hasOwnProperty,Se=Object.prototype.propertyIsEnumerable;var ve=(p,y,C)=>y in p?Lt(p,y,{enumerable:!0,configurable:!0,writable:!0,value:C}):p[y]=C,m=(p,y)=>{for(var C in y||(y={}))ye.call(y,C)&&ve(p,C,y[C]);if(Z)for(var C of Z(y))Se.call(y,C)&&ve(p,C,y[C]);return p},D=(p,y)=>It(p,kt(y));var P=(p,y)=>{var C={};for(var T in p)ye.call(p,T)&&y.indexOf(T)<0&&(C[T]=p[T]);if(p!=null&&Z)for(var T of Z(p))y.indexOf(T)<0&&Se.call(p,T)&&(C[T]=p[T]);return C};function V(n){return n&&typeof n=="object"&&"default"in n?n:{default:n}}function Pe(n){if(n&&n.__esModule)return n;var i=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});return n&&Object.keys(n).forEach(function(r){if(r!=="default"){var a=Object.getOwnPropertyDescriptor(n,r);Object.defineProperty(i,r,a.get?a:{enumerable:!0,get:function(){return n[r]}})}}),i.default=n,Object.freeze(i)}var u=V(y),_=V(C),Le=V(we),ne=V(Te),F=Pe(_e),se=V(ze),E=(n=>(n.Use="use",n.Edit="edit",n))(E||{});const Ie={layoutFrozen:!1,freezeLayout:()=>{},mode:E.Edit,inEditMode:!1},R=u.default.createContext(Ie),ke=(n=>(i,r,a={})=>{const o=m({"X-Requested-With":"XMLHttpRequest","Content-Type":a.string?"application/x-www-form-urlencoded":"application/json"},a.headers),s={baseURL:"http://localhost:31200",method:n,url:i,params:n==="GET"?r:a.params,headers:o};return n==="POST"&&(s.data=a.string?JSON.stringify(r):r),Le.default(s).then(l=>l.data).catch(l=>Promise.reject(l))})("POST");function ue(n,i){const r=Object.keys(i),a=Object.values(i);return new Function(...r,`return \`${n}\`;`)(...a)}function Ge(n,i){const r=i.sqlSnippets.reduce((a,o)=>(a[o.key]=ue(o.value,n),a),{});return _.default.defaultsDeep(n,r)}const De=(n,i,r,a)=>async()=>{if(!n)return[];const o=Ge(i,r),s=ue(n,o);return n.includes("$")&&(console.groupCollapsed(`Final SQL for: ${a}`),console.log(s),console.groupEnd()),await ke("/query",{sql:s})},de={},Ee=de,ie=u.default.createContext(de),Oe={data:[],loading:!1,title:"",setTitle:()=>{},description:"",setDescription:()=>{},sql:"",setSQL:()=>{},viz:{type:"",conf:{}},setViz:()=>{},refreshData:()=>{}},k=u.default.createContext(Oe);var Q={exports:{}},J={};/**
1
+ (function(p,S){typeof exports=="object"&&typeof module!="undefined"?S(exports,require("react"),require("lodash"),require("react-grid-layout"),require("@mantine/core"),require("ahooks"),require("axios"),require("tabler-icons-react"),require("@mantine/hooks"),require("echarts-for-react/lib/core"),require("echarts/core"),require("echarts/charts"),require("echarts/renderers"),require("echarts/components"),require("numbro"),require("echarts-gl"),require("@mantine/prism"),require("@mantine/form"),require("react-hook-form")):typeof define=="function"&&define.amd?define(["exports","react","lodash","react-grid-layout","@mantine/core","ahooks","axios","tabler-icons-react","@mantine/hooks","echarts-for-react/lib/core","echarts/core","echarts/charts","echarts/renderers","echarts/components","numbro","echarts-gl","@mantine/prism","@mantine/form","react-hook-form"],S):(p=typeof globalThis!="undefined"?globalThis:p||self,S(p.dashboard={},p.React,p._,p["react-grid-layout"],p["@mantine/core"],p.ahooks,p.axios,p["tabler-icons-react"],p["@mantine/hooks"],p["echarts-for-react/lib/core"],p["echarts/core"],p["echarts/charts"],p["echarts/renderers"],p["echarts/components"],p.numbro,p["echarts-gl"],p["@mantine/prism"],p["@mantine/form"],p["react-hook-form"]))})(this,function(p,S,C,w,t,ve,ye,y,z,Se,Ce,X,H,A,we,It,M,I,B){"use strict";var zt=Object.defineProperty,Pt=Object.defineProperties;var Lt=Object.getOwnPropertyDescriptors;var K=Object.getOwnPropertySymbols;var ge=Object.prototype.hasOwnProperty,be=Object.prototype.propertyIsEnumerable;var xe=(p,S,C)=>S in p?zt(p,S,{enumerable:!0,configurable:!0,writable:!0,value:C}):p[S]=C,m=(p,S)=>{for(var C in S||(S={}))ge.call(S,C)&&xe(p,C,S[C]);if(K)for(var C of K(S))be.call(S,C)&&xe(p,C,S[C]);return p},q=(p,S)=>Pt(p,Lt(S));var L=(p,S)=>{var C={};for(var w in p)ge.call(p,w)&&S.indexOf(w)<0&&(C[w]=p[w]);if(p!=null&&K)for(var w of K(p))S.indexOf(w)<0&&be.call(p,w)&&(C[w]=p[w]);return C};function $(n){return n&&typeof n=="object"&&"default"in n?n:{default:n}}function Te(n){if(n&&n.__esModule)return n;var i=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});return n&&Object.keys(n).forEach(function(r){if(r!=="default"){var a=Object.getOwnPropertyDescriptor(n,r);Object.defineProperty(i,r,a.get?a:{enumerable:!0,get:function(){return n[r]}})}}),i.default=n,Object.freeze(i)}var d=$(S),T=$(C),_e=$(ye),Z=$(Se),R=Te(Ce),ae=$(we),D=(n=>(n.Use="use",n.Edit="edit",n))(D||{});const ze={layoutFrozen:!1,freezeLayout:()=>{},mode:D.Edit,inEditMode:!1},j=d.default.createContext(ze),Pe=(n=>(i,r,a={})=>{const l=m({"X-Requested-With":"XMLHttpRequest","Content-Type":a.string?"application/x-www-form-urlencoded":"application/json"},a.headers),o={baseURL:"http://localhost:31200",method:n,url:i,params:n==="GET"?r:a.params,headers:l};return n==="POST"&&(o.data=a.string?JSON.stringify(r):r),_e.default(o).then(s=>s.data).catch(s=>Promise.reject(s))})("POST");function le(n,i){const r=Object.keys(i),a=Object.values(i);return new Function(...r,`return \`${n}\`;`)(...a)}function Le(n,i){const r=i.sqlSnippets.reduce((a,l)=>(a[l.key]=le(l.value,n),a),{});return T.default.merge({},r,n)}const Ie=(n,i,r,a)=>async()=>{if(!n)return[];const l=n.includes("$"),o=Le(i,r);if(l&&Object.keys(o).length===0)return console.error(`[queryBySQL] insufficient params for {${a}}'s SQL`),[];const s=le(n,o);return l&&(console.groupCollapsed(`Final SQL for: ${a}`),console.log(s),console.groupEnd()),await Pe("/query",{sql:s})},oe={},De=oe,ee=d.default.createContext(oe),Ge={data:[],loading:!1,title:"",setTitle:()=>{},description:"",setDescription:()=>{},sql:"",setSQL:()=>{},viz:{type:"",conf:{}},setViz:()=>{},refreshData:()=>{}},G=d.default.createContext(Ge);var W={exports:{}},J={};/**
2
2
  * @license React
3
3
  * react-jsx-runtime.production.min.js
4
4
  *
@@ -6,16 +6,16 @@
6
6
  *
7
7
  * This source code is licensed under the MIT license found in the
8
8
  * LICENSE file in the root directory of this source tree.
9
- */var qe=u.default,Ae=Symbol.for("react.element"),Me=Symbol.for("react.fragment"),Ne=Object.prototype.hasOwnProperty,$e=qe.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Be={key:!0,ref:!0,__self:!0,__source:!0};function ce(n,i,r){var a,o={},s=null,l=null;r!==void 0&&(s=""+r),i.key!==void 0&&(s=""+i.key),i.ref!==void 0&&(l=i.ref);for(a in i)Ne.call(i,a)&&!Be.hasOwnProperty(a)&&(o[a]=i[a]);if(n&&n.defaultProps)for(a in i=n.defaultProps,i)o[a]===void 0&&(o[a]=i[a]);return{$$typeof:Ae,type:n,key:s,ref:l,props:o,_owner:$e.current}}J.Fragment=Me,J.jsx=ce,J.jsxs=ce,Q.exports=J;const e=Q.exports.jsx,c=Q.exports.jsxs,W=Q.exports.Fragment;class pe extends u.default.Component{constructor(i){super(i),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}render(){return this.state.hasError?e("h1",{children:"Something went wrong."}):this.props.children}}F.use([ee.SunburstChart,te.CanvasRenderer]);const Fe={tooltip:{show:!0},series:{type:"sunburst",radius:[0,"90%"],emphasis:{focus:"ancestor"}}};function Ve({conf:n,data:i,width:r,height:a}){const h=n,{label_field:o="name",value_field:s="value"}=h,l=P(h,["label_field","value_field"]),d=u.default.useMemo(()=>i.map(g=>({name:g[o],value:g[s]})),[i,o,s]),f=u.default.useMemo(()=>{var g,v;return(v=(g=_.default.maxBy(d,z=>z.value))==null?void 0:g.value)!=null?v:1},[d]),x=u.default.useMemo(()=>({series:{label:{formatter:({name:g,value:v})=>v/f<.2?" ":g}}}),[]),b=_.default.defaultsDeep(Fe,x,l,{series:{data:d}});return e(ne.default,{echarts:F,option:b,style:{width:r,height:a}})}F.use([ee.BarChart,ee.LineChart,A.GridComponent,A.LegendComponent,A.TooltipComponent,te.CanvasRenderer]);const je={legend:{show:!0},tooltip:{trigger:"axis"},xAxis:{type:"category"},yAxis:{}};function Re({conf:n,data:i,width:r,height:a}){const o=u.default.useMemo(()=>{const s={dataset:{source:i}},l={xAxis:{data:i.map(f=>f[n.x_axis_data_key])}},d=n.series.map(b=>{var h=b,{y_axis_data_key:f}=h,x=P(h,["y_axis_data_key"]);return m({data:i.map(g=>g[f])},x)});return _.default.assign({},je,s,l,{series:d})},[n,i]);return!r||!a?null:e(ne.default,{echarts:F,option:o,style:{width:r,height:a}})}var O=(n=>(n.string="string",n.number="number",n.eloc="eloc",n.percentage="percentage",n))(O||{});function Qe({value:n}){return e(t.Text,{component:"span",children:n})}function Je({value:n}){return e(t.Text,{component:"span",children:n})}function We({value:n}){const i=se.default(n).format({thousandSeparated:!0});return e(t.Text,{component:"span",children:i})}function Ue({value:n}){const i=se.default(n).format({output:"percent",mantissa:3});return e(t.Text,{component:"span",children:i})}function Ye({value:n,type:i}){switch(i){case O.string:return e(Qe,{value:n});case O.eloc:return e(Je,{value:n});case O.number:return e(We,{value:n});case O.percentage:return e(Ue,{value:n})}}function Ke({conf:n,data:i,width:r,height:a}){const b=n,{id_field:o,use_raw_columns:s,columns:l}=b,d=P(b,["id_field","use_raw_columns","columns"]),f=u.default.useMemo(()=>s?Object.keys(i==null?void 0:i[0]):l.map(h=>h.label),[s,l,i]),x=u.default.useMemo(()=>s?Object.keys(i==null?void 0:i[0]).map(h=>({label:h,value_field:h,value_type:O.string})):l,[s,l,i]);return c(t.Table,D(m({sx:{maxHeight:a}},d),{children:[e("thead",{children:e("tr",{children:f.map(h=>e("th",{children:h},h))})}),e("tbody",{children:i.map((h,g)=>e("tr",{children:x.map(({value_field:v,value_type:z})=>e("td",{children:e(t.Group,{sx:{"&, .mantine-Text-root":{fontFamily:"monospace"}},children:e(Ye,{value:h[v],type:z})})},h[v]))},o?h[o]:`row-${g}`))})]}))}function Xe(n,i={}){const r=Object.keys(i),a=Object.values(i);try{return new Function(...r,`return \`${n}\`;`)(...a)}catch(o){return o.message}}function He({conf:{paragraphs:n},data:i}){return e(W,{children:n.map((s,o)=>{var l=s,{template:r}=l,a=P(l,["template"]);return e(t.Text,D(m({},a),{children:Xe(r,i[0])}),`${r}---${o}`)})})}F.use([A.GridComponent,A.VisualMapComponent,A.LegendComponent,A.TooltipComponent,te.CanvasRenderer]);function Ze({conf:n,data:i,width:r,height:a}){const h=n,{x_axis_data_key:o,y_axis_data_key:s,z_axis_data_key:l}=h,d=P(h,["x_axis_data_key","y_axis_data_key","z_axis_data_key"]),f=u.default.useMemo(()=>_.default.minBy(i,g=>g[l])[l],[i,l]),x=u.default.useMemo(()=>_.default.maxBy(i,g=>g[l])[l],[i,l]),b=D(m({tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:f,max:x,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:{type:"value"},yAxis3D:{type:"value"},zAxis3D:{type:"value"},grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}}},d),{series:[{type:"bar3D",wireframe:{},data:i.map(g=>[g[o],g[s],g[l]])}]});return e(ne.default,{echarts:F,option:b,style:{width:r,height:a}})}var Et="";function et(n,i,r,a){const o={width:n,height:i,data:r,conf:a.conf};switch(a.type){case"sunburst":return e(Ve,m({},o));case"line-bar":return e(Re,m({},o));case"table":return e(Ke,m({},o));case"text":return e(He,m({},o));case"bar-3d":return e(Ze,m({},o));default:return null}}function me({viz:n,data:i,loading:r}){const{ref:a,width:o,height:s}=L.useElementSize(),l=u.default.useMemo(()=>!Array.isArray(i)||i.length===0,[i]);return r?e("div",{className:"viz-root",ref:a,children:e(t.LoadingOverlay,{visible:r})}):c("div",{className:"viz-root",ref:a,children:[l&&e(t.Text,{color:"gray",align:"center",children:"nothing to show"}),!l&&et(o,s,i,n)]})}function tt({}){const n=u.default.useContext(ie),i="SELECT *\nFROM commit\nWHERE author_time BETWEEN '${timeRange?.[0].toISOString()}' AND '${timeRange?.[1].toISOString()}'";return c(t.Group,{direction:"column",children:[e(M.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:`-- You may refer context data *by name*
9
+ */var ke=d.default,qe=Symbol.for("react.element"),Ee=Symbol.for("react.fragment"),Oe=Object.prototype.hasOwnProperty,Ae=ke.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Me={key:!0,ref:!0,__self:!0,__source:!0};function se(n,i,r){var a,l={},o=null,s=null;r!==void 0&&(o=""+r),i.key!==void 0&&(o=""+i.key),i.ref!==void 0&&(s=i.ref);for(a in i)Oe.call(i,a)&&!Me.hasOwnProperty(a)&&(l[a]=i[a]);if(n&&n.defaultProps)for(a in i=n.defaultProps,i)l[a]===void 0&&(l[a]=i[a]);return{$$typeof:qe,type:n,key:o,ref:s,props:l,_owner:Ae.current}}J.Fragment=Ee,J.jsx=se,J.jsxs=se,W.exports=J;const e=W.exports.jsx,c=W.exports.jsxs,ue=W.exports.Fragment;class de extends d.default.Component{constructor(i){super(i),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}render(){return this.state.hasError?e("h1",{children:"Something went wrong."}):this.props.children}}R.use([X.SunburstChart,H.CanvasRenderer]);const Be={tooltip:{show:!0},series:{type:"sunburst",radius:[0,"90%"],emphasis:{focus:"ancestor"}}};function Ne({conf:n,data:i,width:r,height:a}){const x=n,{label_field:l="name",value_field:o="value"}=x,s=L(x,["label_field","value_field"]),u=d.default.useMemo(()=>i.map(g=>({name:g[l],value:Number(g[o])})),[i,l,o]),f=d.default.useMemo(()=>{var g,v;return(v=(g=T.default.maxBy(u,P=>P.value))==null?void 0:g.value)!=null?v:1},[u]),h=d.default.useMemo(()=>({series:{label:{formatter:({name:g,value:v})=>v/f<.2?" ":g}}}),[]),b=T.default.merge(Be,h,s,{series:{data:u}});return e(Z.default,{echarts:R,option:b,style:{width:r,height:a}})}R.use([X.BarChart,X.LineChart,A.GridComponent,A.LegendComponent,A.TooltipComponent,H.CanvasRenderer]);const Fe={legend:{show:!0},tooltip:{trigger:"axis"},xAxis:{type:"category"},yAxis:{},grid:{top:30,left:10,right:10,bottom:10,containLabel:!0}};function Re({conf:n,data:i,width:r,height:a}){const l=d.default.useMemo(()=>{const o={dataset:{source:i}},s={xAxis:{data:i.map(f=>f[n.x_axis_data_key])}},u=n.series.map(b=>{var x=b,{y_axis_data_key:f}=x,h=L(x,["y_axis_data_key"]);return m({data:i.map(g=>g[f])},h)});return T.default.assign({},Fe,o,s,{series:u})},[n,i]);return!r||!a?null:e(Z.default,{echarts:R,option:l,style:{width:r,height:a}})}var E=(n=>(n.string="string",n.number="number",n.eloc="eloc",n.percentage="percentage",n))(E||{});function $e({value:n}){return e(t.Text,{component:"span",children:n})}function je({value:n}){return e(t.Text,{component:"span",children:n})}function Ve({value:n}){const i=ae.default(n).format({thousandSeparated:!0});return e(t.Text,{component:"span",children:i})}function Qe({value:n}){const i=ae.default(n).format({output:"percent",mantissa:3});return e(t.Text,{component:"span",children:i})}function We({value:n,type:i}){switch(i){case E.string:return e($e,{value:n});case E.eloc:return e(je,{value:n});case E.number:return e(Ve,{value:n});case E.percentage:return e(Qe,{value:n})}}function Je({conf:n,data:i,width:r,height:a}){const b=n,{id_field:l,use_raw_columns:o,columns:s}=b,u=L(b,["id_field","use_raw_columns","columns"]),f=d.default.useMemo(()=>o?Object.keys(i==null?void 0:i[0]):s.map(x=>x.label),[o,s,i]),h=d.default.useMemo(()=>o?Object.keys(i==null?void 0:i[0]).map(x=>({label:x,value_field:x,value_type:E.string})):s,[o,s,i]);return c(t.Table,q(m({sx:{maxHeight:a}},u),{children:[e("thead",{children:e("tr",{children:f.map(x=>e("th",{children:x},x))})}),e("tbody",{children:i.map((x,g)=>e("tr",{children:h.map(({value_field:v,value_type:P})=>e("td",{children:e(t.Group,{sx:{"&, .mantine-Text-root":{fontFamily:"monospace"}},children:e(We,{value:x[v],type:P})})},x[v]))},l?x[l]:`row-${g}`))})]}))}function Ue(n,i={}){const r=Object.keys(i),a=Object.values(i);try{return new Function(...r,`return \`${n}\`;`)(...a)}catch(l){return l.message}}function Ye({conf:{paragraphs:n},data:i}){return e(ue,{children:n.map((s,o)=>{var u=s,{template:r,size:a}=u,l=L(u,["template","size"]);return e(t.Text,q(m({},l),{sx:{fontSize:a},children:Ue(r,i[0])}),`${r}---${o}`)})})}R.use([A.GridComponent,A.VisualMapComponent,A.LegendComponent,A.TooltipComponent,H.CanvasRenderer]);function Ke({conf:n,data:i,width:r,height:a}){const x=n,{x_axis_data_key:l,y_axis_data_key:o,z_axis_data_key:s}=x,u=L(x,["x_axis_data_key","y_axis_data_key","z_axis_data_key"]),f=d.default.useMemo(()=>T.default.minBy(i,g=>g[s])[s],[i,s]),h=d.default.useMemo(()=>T.default.maxBy(i,g=>g[s])[s],[i,s]),b=q(m({tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:f,max:h,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:{type:"value"},yAxis3D:{type:"value"},zAxis3D:{type:"value"},grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}}},u),{series:[{type:"bar3D",wireframe:{},data:i.map(g=>[g[l],g[o],g[s]])}]});return e(Z.default,{echarts:R,option:b,style:{width:r,height:a}})}var Gt="";function Xe(n,i,r,a){const l={width:n,height:i,data:r,conf:a.conf};switch(a.type){case"sunburst":return e(Ne,m({},l));case"line-bar":return e(Re,m({},l));case"table":return e(Je,m({},l));case"text":return e(Ye,m({},l));case"bar-3d":return e(Ke,m({},l));default:return null}}function ce({viz:n,data:i,loading:r}){const{ref:a,width:l,height:o}=z.useElementSize(),s=d.default.useMemo(()=>!Array.isArray(i)||i.length===0,[i]);return r?e("div",{className:"viz-root",ref:a,children:e(t.LoadingOverlay,{visible:r})}):c("div",{className:"viz-root",ref:a,children:[s&&e(t.Text,{color:"gray",align:"center",children:"nothing to show"}),!s&&Xe(l,o,i,n)]})}function He({}){const n=d.default.useContext(ee),i="SELECT *\nFROM commit\nWHERE author_time BETWEEN '${timeRange?.[0].toISOString()}' AND '${timeRange?.[1].toISOString()}'";return c(t.Group,{direction:"column",children:[e(M.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:`-- You may refer context data *by name*
10
10
  -- in SQL or VizConfig.
11
11
 
12
- ${i}`}),e(t.Text,{weight:700,children:"Avaiable context entries"}),e(M.Prism,{language:"json",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:JSON.stringify(n,null,2)})]})}var Ot="";function nt({}){const{sql:n,setSQL:i}=u.default.useContext(k),[r,a]=u.default.useState(!0),o=d=>{i(d.target.value)},s=u.default.useCallback(()=>{a(d=>!d)},[]),l=u.default.useCallback(()=>{i(d=>d.trim())},[i]);return c(t.Box,{className:"sql-query-editor-root",sx:{height:"100%"},children:[e(t.Textarea,{value:n,onChange:o,minRows:20,maxRows:20}),c(t.Group,{m:"md",position:"right",children:[e(t.Button,{color:"blue",onClick:l,children:"Format"}),e(t.Button,{variant:"default",onClick:s,children:"Toggle Preview"})]}),r&&e(M.Prism,{language:"sql",withLineNumbers:!0,noCopy:!0,colorScheme:"dark",children:n})]})}const it=nt;function rt({}){const{data:n}=u.default.useContext(k);return c("div",{className:"query-result-root",children:[c(t.Group,{mb:"xs",children:[e(t.Text,{weight:"bold",children:"Data Length: "}),n.length]}),e(M.Prism,{language:"json",colorScheme:"dark",children:JSON.stringify(n,null,2)})]})}const at={sqlSnippets:[],setSQLSnippets:()=>{}},U=u.default.createContext(at);function lt({sqlSnippets:n,setSQLSnippets:i}){const r=u.default.useRef(null),a=u.default.useMemo(()=>({snippets:I.formList(n!=null?n:[])}),[n]),o=I.useForm({initialValues:a}),s=()=>o.addListItem("snippets",{key:L.randomId(),value:""}),l=u.default.useMemo(()=>!_.default.isEqual(o.values,a),[o.values,a]);u.default.useEffect(()=>{var f;l&&((f=r==null?void 0:r.current)==null||f.click())},[l,r.current]);const d=({snippets:f})=>{i(f)};return e(t.Group,{direction:"column",sx:{width:"100%"},grow:!0,children:c("form",{onSubmit:o.onSubmit(d),children:[e("button",{ref:r,type:"submit",style:{display:"none"},children:"Ghost submit"}),o.values.snippets.map((f,x)=>c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[e(t.TextInput,m({label:"Key",required:!0},o.getListInputProps("snippets",x,"key"))),e(t.Textarea,m({minRows:3,label:"Value",required:!0},o.getListInputProps("snippets",x,"value"))),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>o.removeListItem("snippets",x),sx:{position:"absolute",top:15,right:5},children:e(S.Trash,{size:16})})]},x)),e(t.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:e(t.Button,{color:"blue",onClick:s,children:"Add a snippet"})})]})})}function ot({}){const{sqlSnippets:n,setSQLSnippets:i}=u.default.useContext(U),r=`SELECT *
12
+ ${i}`}),e(t.Text,{weight:700,children:"Avaiable context entries"}),e(M.Prism,{language:"json",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:JSON.stringify(n,null,2)})]})}var kt="";function Ze({}){const{sql:n,setSQL:i}=d.default.useContext(G),[r,a]=d.default.useState(!0),l=u=>{i(u.target.value)},o=d.default.useCallback(()=>{a(u=>!u)},[]),s=d.default.useCallback(()=>{i(u=>u.trim())},[i]);return c(t.Box,{className:"sql-query-editor-root",sx:{height:"100%"},children:[e(t.Textarea,{value:n,onChange:l,minRows:20,maxRows:20}),c(t.Group,{m:"md",position:"right",children:[e(t.Button,{color:"blue",onClick:s,children:"Format"}),e(t.Button,{variant:"default",onClick:o,children:"Toggle Preview"})]}),r&&e(M.Prism,{language:"sql",withLineNumbers:!0,noCopy:!0,colorScheme:"dark",children:n})]})}const et=Ze;function tt({}){const{data:n}=d.default.useContext(G);return c("div",{className:"query-result-root",children:[c(t.Group,{mb:"xs",children:[e(t.Text,{weight:"bold",children:"Data Length: "}),n.length]}),e(M.Prism,{language:"json",colorScheme:"dark",children:JSON.stringify(n,null,2)})]})}const nt={sqlSnippets:[],setSQLSnippets:()=>{}},V=d.default.createContext(nt);function it({sqlSnippets:n,setSQLSnippets:i}){const r=d.default.useMemo(()=>({snippets:I.formList(n!=null?n:[])}),[n]),a=I.useForm({initialValues:r}),l=()=>a.addListItem("snippets",{key:z.randomId(),value:""}),o=d.default.useMemo(()=>!T.default.isEqual(a.values,r),[a.values,r]),s=({snippets:u})=>{i(u)};return e(t.Group,{direction:"column",sx:{width:"100%",position:"relative"},grow:!0,children:c("form",{onSubmit:a.onSubmit(s),children:[a.values.snippets.map((u,f)=>c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[e(t.TextInput,m({label:"Key",required:!0},a.getListInputProps("snippets",f,"key"))),e(t.Textarea,m({minRows:3,label:"Value",required:!0},a.getListInputProps("snippets",f,"value"))),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>a.removeListItem("snippets",f),sx:{position:"absolute",top:15,right:5},children:e(y.Trash,{size:16})})]},f)),c(t.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"80%"},mx:"auto",children:[e(t.Button,{variant:"default",onClick:l,children:"Add a snippet"}),e(t.Button,{color:"blue",type:"submit",disabled:!o,children:"Submit"})]})]})})}function rt({}){const{sqlSnippets:n,setSQLSnippets:i}=d.default.useContext(V),r=`SELECT *
13
13
  FROM commit
14
- WHERE \${author_time_condition}`;return c(t.Group,{direction:"column",children:[e(M.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:`-- You may refer context data *by name*
14
+ WHERE \${author_time_condition}`;return c(t.Group,{direction:"column",children:[e(M.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,trim:!1,colorScheme:"dark",children:`-- You may refer context data *by name*
15
15
  -- in SQL or VizConfig.
16
16
 
17
17
  ${r}
18
18
 
19
19
  -- where author_time_condition is:
20
20
  author_time BETWEEN '\${timeRange?.[0].toISOString()}' AND '\${timeRange?.[1].toISOString()}'
21
- `}),e(t.Text,{weight:700,children:"SQL Snippets"}),e(lt,{sqlSnippets:n,setSQLSnippets:i})]})}function st(){const{description:n,setDescription:i}=u.default.useContext(k),[r,a]=L.useInputState(n),o=n!==r,s=u.default.useCallback(()=>{!o||i(r)},[o,r]);return e(t.Textarea,{label:"Panel Description",value:r,onChange:a,minRows:2,rightSection:e(t.ActionIcon,{disabled:!o,onClick:s,sx:{alignSelf:"flex-start",marginTop:"4px"},children:e(S.DeviceFloppy,{size:20})})})}function ut(){const{title:n,setTitle:i}=u.default.useContext(k),[r,a]=L.useInputState(n),o=n!==r,s=u.default.useCallback(()=>{!o||i(r)},[o,r]);return e(t.TextInput,{label:"Panel Title",value:r,onChange:a,rightSection:e(t.ActionIcon,{disabled:!o,onClick:s,children:e(S.DeviceFloppy,{size:20})})})}function dt({conf:n,setConf:i}){const r=_.default.assign({},{x_axis_data_key:"x",y_axis_data_key:"y",z_axis_data_key:"z",xAxis3D:{type:"value",name:"X Axis Name"},yAxis3D:{type:"value",name:"Y Axis Name"},zAxis3D:{type:"value",name:"Z Axis Name"}},n),{control:a,handleSubmit:o,formState:s}=N.useForm({defaultValues:r});return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:o(i),children:[e(t.Text,{children:"X Axis"}),c(t.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[e(N.Controller,{name:"x_axis_data_key",control:a,render:({field:l})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Data Key"},l))}),e(N.Controller,{name:"xAxis3D.name",control:a,render:({field:l})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Name"},l))})]}),e(t.Text,{mt:"lg",children:"Y Axis"}),c(t.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[e(N.Controller,{name:"y_axis_data_key",control:a,render:({field:l})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Data Key"},l))}),e(N.Controller,{name:"yAxis3D.name",control:a,render:({field:l})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Name"},l))})]}),e(t.Text,{mt:"lg",children:"Z Axis"}),c(t.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[e(N.Controller,{name:"z_axis_data_key",control:a,render:({field:l})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Data Key"},l))}),e(N.Controller,{name:"zAxis3D.name",control:a,render:({field:l})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Name"},l))})]}),e(t.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:c(t.Button,{color:"blue",type:"submit",children:[e(S.DeviceFloppy,{size:20}),e(t.Text,{ml:"md",children:"Save"})]})})]})})}function he({value:n,onChange:i}){const r=t.useMantineTheme(),a=u.default.useMemo(()=>Object.entries(r.colors).map(([s,l])=>({label:s,value:l[6]})),[r]),o=u.default.useMemo(()=>a.some(s=>s.value===n),[n,a]);return c(t.Group,{position:"apart",spacing:"xs",children:[e(t.TextInput,{placeholder:"Set any color",value:o?"":n,onChange:s=>i(s.currentTarget.value),rightSection:e(t.ColorSwatch,{color:o?"transparent":n,radius:4}),variant:o?"filled":"default",sx:{maxWidth:"100%",flexGrow:1}}),e(t.Text,{sx:{flexGrow:0},children:"or"}),e(t.Select,{data:a,value:n,onChange:i,variant:o?"default":"filled",placeholder:"Pick a theme color",icon:e(t.ColorSwatch,{color:o?n:"transparent",radius:4}),sx:{maxWidth:"100%",flexGrow:1}})]})}function ct({conf:n,setConf:i}){const r=u.default.useRef(null),x=n,{series:a}=x,o=P(x,["series"]),s=u.default.useMemo(()=>m({series:I.formList(a!=null?a:[])},o),[a,o]),l=I.useForm({initialValues:s}),d=()=>l.addListItem("series",{type:"bar",name:L.randomId(),showSymbol:!1,y_axis_data_key:"value",stack:"",color:"#000"}),f=u.default.useMemo(()=>!_.default.isEqual(l.values,s),[l.values,s]);return u.default.useEffect(()=>{var b;f&&((b=r==null?void 0:r.current)==null||b.click())},[f,r.current]),e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:l.onSubmit(i),children:[c(t.Group,{position:"apart",mb:"lg",sx:{position:"relative"},children:[e(t.Text,{children:"Chart Config"}),e("button",{ref:r,type:"submit",style:{display:"none"},children:"Ghost submit"})]}),e(t.TextInput,m({size:"md",mb:"lg",label:"X Axis Data Key"},l.getInputProps("x_axis_data_key"))),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{mt:"xl",mb:0,children:"Series"}),l.values.series.map((b,h)=>c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[e(t.TextInput,m({label:"Label",required:!0,sx:{flex:1}},l.getListInputProps("series",h,"name"))),c(t.Group,{direction:"row",grow:!0,noWrap:!0,children:[e(t.TextInput,m({label:"Y Axis Data key",required:!0},l.getListInputProps("series",h,"y_axis_data_key"))),e(t.TextInput,m({label:"Stack ID",placeholder:"Stack bars by this ID"},l.getListInputProps("series",h,"stack")))]}),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{children:"Color"}),e(he,m({},l.getListInputProps("series",h,"color")))]}),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>l.removeListItem("series",h),sx:{position:"absolute",top:15,right:5},children:e(S.Trash,{size:16})})]},h)),e(t.Group,{position:"center",mt:"xs",children:e(t.Button,{onClick:d,children:"Add a Series"})})]})]})})}function pt(a){var o=a,{conf:s}=o,l=s,{columns:n}=l,i=P(l,["columns"]),{setConf:r}=o;const d=I.useForm({initialValues:{label_field:"name",value_field:"value"}});return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:d.onSubmit(r),children:[c(t.Group,{position:"apart",mb:"lg",sx:{position:"relative"},children:[e(t.Text,{children:"Sunburst Config"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",children:e(S.DeviceFloppy,{size:20})})]}),c(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,p:"md",mb:"sm",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[e(t.TextInput,m({label:"Label Field",required:!0,sx:{flex:1}},d.getInputProps("label_field"))),e(t.TextInput,m({label:"Value Field",placeholder:"get column value by this field",required:!0,sx:{flex:1}},d.getInputProps("value_field")))]})]})})}const Y=[{value:0,label:"xs"},{value:25,label:"sm"},{value:50,label:"md"},{value:75,label:"lg"},{value:100,label:"xl"}];function K({label:n,value:i,onChange:r}){var s,l;const[a,o]=u.default.useState((l=(s=Y.find(d=>d.label===i))==null?void 0:s.value)!=null?l:Y[0].value);return u.default.useEffect(()=>{const d=Y.find(f=>f.value===a);d&&r(d.label)},[a]),c(t.Group,{direction:"column",grow:!0,spacing:"xs",mb:"lg",children:[e(t.Text,{children:n}),e(t.Slider,{label:null,marks:Y,value:a,onChange:o,step:25,placeholder:"Pick a font size"})]})}const mt=Object.values(O).map(n=>({label:n,value:n}));function ht({label:n,value:i,onChange:r,sx:a}){return e(t.Select,{label:n,data:mt,value:i,onChange:r,sx:a})}function ft(a){var o=a,{conf:s}=o,l=s,{columns:n}=l,i=P(l,["columns"]),{setConf:r}=o;const d=I.useForm({initialValues:m({id_field:"id",use_raw_columns:!0,columns:I.formList(n!=null?n:[]),size:"sm",horizontalSpacing:"sm",verticalSpacing:"sm",striped:!1,highlightOnHover:!1},i)}),f=()=>d.addListItem("columns",{label:L.randomId(),value_field:"value",value_type:O.string});return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:d.onSubmit(r),children:[c(t.Group,{position:"apart",mb:"lg",sx:{position:"relative"},children:[e(t.Text,{children:"Table Config"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",children:e(S.DeviceFloppy,{size:20})})]}),c(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,p:"md",mb:"sm",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[e(t.TextInput,m({size:"md",mb:"lg",label:"ID Field"},d.getInputProps("id_field"))),c(t.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:[e(K,m({label:"Horizontal Spacing"},d.getInputProps("horizontalSpacing"))),e(K,m({label:"Vertical Spacing"},d.getInputProps("verticalSpacing")))]}),e(t.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:e(K,m({label:"Font Size"},d.getInputProps("size")))}),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{children:"Other"}),c(t.Group,{position:"apart",grow:!0,children:[e(t.Switch,m({label:"Striped"},d.getInputProps("striped",{type:"checkbox"}))),e(t.Switch,m({label:"Highlight on hover"},d.getInputProps("highlightOnHover",{type:"checkbox"})))]})]})]}),c(t.Group,{direction:"column",mt:"xs",spacing:"xs",grow:!0,p:"md",mb:"xl",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[e(t.Switch,m({label:"Use Original Data Columns"},d.getInputProps("use_raw_columns",{type:"checkbox"}))),!d.values.use_raw_columns&&c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{mt:"xl",mb:0,children:"Custom Columns"}),d.values.columns.map((x,b)=>c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[c(t.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:[e(t.TextInput,m({label:"Label",required:!0,sx:{flex:1}},d.getListInputProps("columns",b,"label"))),e(t.TextInput,m({label:"Value Field",placeholder:"get column value by this field",required:!0,sx:{flex:1}},d.getListInputProps("columns",b,"value_field"))),e(ht,m({label:"Value Type",sx:{flex:1}},d.getListInputProps("columns",b,"value_type")))]}),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>d.removeListItem("columns",b),sx:{position:"absolute",top:15,right:5},children:e(S.Trash,{size:16})})]},b)),e(t.Group,{position:"center",mt:"xs",children:e(t.Button,{onClick:f,children:"Add a Column"})})]})]}),e(t.Text,{weight:500,mb:"md",children:"Current Configuration:"}),e(M.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(d.values,null,2)})]})})}const X=[{label:"initial",value:0},{label:"500",value:25},{label:"700",value:50},{label:"semibold",value:75},{label:"bold",value:100}];function xt({label:n,value:i,onChange:r}){var s,l;const[a,o]=u.default.useState((l=(s=X.find(d=>d.label===i))==null?void 0:s.value)!=null?l:X[0].value);return u.default.useEffect(()=>{const d=X.find(f=>f.value===a);d&&r(d.label)},[a]),c(t.Group,{direction:"column",grow:!0,spacing:"xs",mb:"lg",children:[e(t.Text,{children:n}),e(t.Slider,{label:null,marks:X,value:a,onChange:o,step:25,placeholder:"Pick a font size"})]})}const fe=[{align:"center",size:"xl",weight:"bold",color:"black",template:"Time: ${new Date().toISOString()}"},{align:"center",size:"md",weight:"bold",color:"red",template:"Platform: ${navigator.userAgentData.platform}."}];function gt({conf:n,setConf:i}){var o;const r=I.useForm({initialValues:{paragraphs:I.formList((o=n.paragraphs)!=null?o:fe)}}),a=()=>r.addListItem("paragraphs",D(m({},fe[0]),{template:L.randomId()}));return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:r.onSubmit(i),children:[r.values.paragraphs.length===0&&e(t.Text,{color:"dimmed",align:"center",children:"Empty"}),c(t.Group,{position:"apart",mb:"xs",sx:{" + .mantine-Group-root":{marginTop:0}},children:[e(t.Text,{children:"Paragraphs"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",children:e(S.DeviceFloppy,{size:20})})]}),r.values.paragraphs.map((s,l)=>c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[e(t.TextInput,m({placeholder:"Time: ${new Date().toISOString()}",label:"Content Template",required:!0,sx:{flex:1}},r.getListInputProps("paragraphs",l,"template"))),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{children:"Color"}),e(he,m({},r.getListInputProps("paragraphs",l,"color")))]}),c(t.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:[e(K,m({label:"Font Size"},r.getListInputProps("paragraphs",l,"size"))),e(xt,m({label:"Font Weight"},r.getListInputProps("paragraphs",l,"weight")))]}),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>r.removeListItem("paragraphs",l),sx:{position:"absolute",top:15,right:5},children:e(S.Trash,{size:16})})]},l)),e(t.Group,{position:"center",mt:"md",children:e(t.Button,{onClick:a,children:"Add a Paragraph"})}),e(t.Text,{size:"sm",weight:500,mt:"md",children:"Current Configuration:"}),e(M.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(r.values,null,2)})]})})}const re=[{value:"text",label:"Text",Panel:gt},{value:"table",label:"Table",Panel:ft},{value:"sunburst",label:"Sunburst",Panel:pt},{value:"bar-3d",label:"Bar Chart (3D)",Panel:dt},{value:"line-bar",label:"Line-Bar Chart",Panel:ct}];function bt(){const{viz:n,setViz:i}=u.default.useContext(k),[r,a]=L.useInputState(n.type),o=n.type!==r,s=u.default.useCallback(()=>{!o||i(x=>D(m({},x),{type:r}))},[o,r]),l=x=>{i(b=>D(m({},b),{conf:x}))},d=x=>{try{l(JSON.parse(x))}catch(b){console.error(b)}},f=u.default.useMemo(()=>{var x;return(x=re.find(b=>b.value===r))==null?void 0:x.Panel},[r,re]);return c(W,{children:[e(t.Select,{label:"Visualization",value:r,onChange:a,data:re,rightSection:e(t.ActionIcon,{disabled:!o,onClick:s,children:e(S.DeviceFloppy,{size:20})})}),f&&e(f,{conf:n.conf,setConf:l}),!f&&e(t.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(n.conf,null,2),onChange:d})]})}function vt({}){return c(t.Group,{grow:!0,direction:"column",children:[e(ut,{}),e(st,{}),e(t.Divider,{}),e(bt,{})]})}function yt({}){const{freezeLayout:n}=u.default.useContext(R),{data:i,loading:r,viz:a,title:o}=u.default.useContext(k),[s,l]=u.default.useState(!1),d=()=>l(!0);return u.default.useEffect(()=>{n(s)},[s]),c(W,{children:[e(t.Modal,{size:"96vw",overflow:"inside",opened:s,onClose:()=>l(!1),title:o,trapFocus:!0,onDragStart:f=>{f.stopPropagation()},children:e(t.AppShell,{sx:{height:"90vh",maxHeight:"calc(100vh - 185px)",".mantine-AppShell-body":{height:"100%"},main:{height:"100%",width:"100%"}},padding:"md",navbar:e(t.Navbar,{width:{base:"40%"},height:"100%",p:"xs",children:c(t.Tabs,{initialTab:1,children:[e(t.Tabs.Tab,{label:"Context",children:e(tt,{})}),e(t.Tabs.Tab,{label:"SQL Snippets",children:e(ot,{})}),e(t.Tabs.Tab,{label:"SQL",children:e(it,{})}),c(t.Tabs.Tab,{label:"Data",children:[e(t.LoadingOverlay,{visible:r}),e(rt,{})]}),e(t.Tabs.Tab,{label:"Viz Config",children:e(vt,{})})]})}),children:e(pe,{children:e(me,{viz:a,data:i,loading:r})})})}),e(t.ActionIcon,{variant:"hover",color:"blue",loading:r,onClick:d,children:e(S.Settings,{size:16})})]})}function St({title:n,description:i}){return c(t.Group,{position:"center",sx:{borderBottom:"1px solid #eee",paddingBottom:"5px"},children:[!i&&e(t.Text,{weight:"bold",sx:{marginLeft:"5px",display:"inline"},children:n}),i&&e("div",{children:c(t.Tooltip,{label:i,withArrow:!0,children:[e(S.InfoCircle,{size:12,style:{verticalAlign:"baseline",cursor:"pointer"}}),e(t.Text,{weight:"bold",sx:{marginLeft:"5px",display:"inline"},children:n})]})})]})}function Ct({}){const{title:n,description:i,loading:r,refreshData:a}=u.default.useContext(k),{inEditMode:o}=u.default.useContext(R);return c(W,{children:[e(St,{title:n,description:i}),c(t.Group,{position:"right",spacing:0,sx:{position:"absolute",right:"15px",top:"4px",height:"28px"},children:[e(t.ActionIcon,{variant:"hover",color:"blue",loading:r,onClick:a,children:e(S.Refresh,{size:16})}),o&&e(yt,{})]})]})}var qt="";function xe({viz:n,sql:i,title:r,description:a,update:o,layout:s,id:l}){const d=u.default.useContext(ie),f=u.default.useContext(U),[x,b]=u.default.useState(r),[h,g]=u.default.useState(a),[v,z]=u.default.useState(i),[w,q]=u.default.useState(n);u.default.useEffect(()=>{o({id:l,layout:s,title:x,description:h,sql:v,viz:w})},[x,h,v,w,l,s]);const{data:$=[],loading:B,refresh:ae}=Ce.useRequest(De(v,d,f,x),{refreshDeps:[d,f]}),le=ae;return e(k.Provider,{value:{data:$,loading:B,title:x,setTitle:b,description:h,setDescription:g,sql:v,setSQL:z,viz:w,setViz:q,refreshData:le},children:c(t.Container,{className:"panel-root",children:[e(Ct,{}),e(pe,{children:e(me,{viz:w,data:$,loading:B})})]})})}var At="";const wt=T.WidthProvider(T.Responsive);function ge({panels:n,setPanels:i,className:r="layout",cols:a={lg:12,md:10,sm:8,xs:6,xxs:4},rowHeight:o=10,onRemoveItem:s,isDraggable:l,isResizable:d,setLocalCols:f,setBreakpoint:x}){const b=(g,v)=>{x(g),f(v)},h=u.default.useCallback(g=>{const v=new Map;g.forEach($=>{var B=$,{i:w}=B,q=P(B,["i"]);v.set(w,q)});const z=n.map(w=>D(m({},w),{layout:v.get(w.id)}));i.setState(z)},[n,i]);return e(wt,{onBreakpointChange:b,onLayoutChange:h,className:r,cols:a,rowHeight:o,isDraggable:l,isResizable:d,children:n.map((w,z)=>{var q=w,{id:g}=q,v=P(q,["id"]);return e("div",{"data-grid":v.layout,children:e(xe,D(m({id:g},v),{destroy:()=>s(g),update:$=>{i.setItem(z,$)}}))},g)})})}function be(n,i){return c(t.Text,{sx:{svg:{verticalAlign:"text-bottom"}},children:[n," ",i]})}function Tt({mode:n,setMode:i}){return e(t.SegmentedControl,{value:n,onChange:i,data:[{label:be(e(S.PlayerPlay,{size:20}),"Use"),value:E.Use},{label:be(e(S.Paint,{size:20}),"Edit"),value:E.Edit}]})}function _t({mode:n,setMode:i,hasChanges:r,addPanel:a,saveChanges:o}){const s=n===E.Edit;return c(t.Group,{position:"apart",pt:"sm",pb:"xs",children:[e(t.Group,{position:"left",children:e(Tt,{mode:n,setMode:i})}),s&&c(t.Group,{position:"right",children:[e(t.Button,{variant:"default",size:"sm",onClick:a,leftIcon:e(S.PlaylistAdd,{size:20}),children:"Add a Panel"}),e(t.Button,{variant:"default",size:"sm",onClick:o,disabled:!r,leftIcon:e(S.DeviceFloppy,{size:20}),children:"Save Changes"}),e(t.Button,{color:"red",size:"sm",disabled:!r,leftIcon:e(S.Recycle,{size:20}),children:"Revert Changes"})]}),!s&&e(t.Button,{variant:"default",size:"sm",disabled:!0,leftIcon:e(S.Share,{size:20}),children:"Share"})]})}function zt({dashboard:n,update:i,className:r="dashboard"}){const[a,o]=u.default.useState(!1),[s,l]=u.default.useState(0),[d,f]=u.default.useState(),[x,b]=u.default.useState(),[h,g]=L.useListState(n.panels),[v,z]=u.default.useState(n.definition.sqlSnippets),[w,q]=u.default.useState(E.Edit),$=u.default.useMemo(()=>{const G=j=>JSON.parse(JSON.stringify(j));return _.default.isEqual(G(h),G(n.panels))?!_.default.isEqual(v,n.definition.sqlSnippets):!0},[n,h,v]),B=async()=>{const G=_.default.merge({},n,{panels:h},{definition:{sqlSnippets:v}});await i(G)},ae=()=>{console.log("adding","n"+s),l(j=>j+1);const G="n"+s,H={id:G,layout:{x:h.length*2%(x||12),y:1/0,w:4,h:4},title:`New Panel - ${G}`,description:"description goes here",sql:"",viz:{type:"table",conf:{}}};g.append(H)},le=G=>{const H=h.findIndex(j=>j.id===G);g.remove(H)},oe=w===E.Edit,Pt=u.default.useMemo(()=>({sqlSnippets:v,setSQLSnippets:z}),[v,z]);return e("div",{className:r,children:e(U.Provider,{value:Pt,children:c(R.Provider,{value:{layoutFrozen:a,freezeLayout:o,mode:w,inEditMode:oe},children:[e(_t,{mode:w,setMode:q,hasChanges:$,addPanel:ae,saveChanges:B}),e(ge,{panels:h,setPanels:g,isDraggable:oe&&!a,isResizable:oe&&!a,onRemoveItem:le,setLocalCols:b,setBreakpoint:f})]})})})}p.ContextInfoContext=ie,p.Dashboard=zt,p.DashboardLayout=ge,p.DashboardMode=E,p.DefinitionContext=U,p.LayoutStateContext=R,p.Panel=xe,p.PanelContext=k,p.initialContextInfoContext=Ee,Object.defineProperties(p,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
21
+ `}),e(t.Text,{weight:700,children:"SQL Snippets"}),e(it,{sqlSnippets:n,setSQLSnippets:i})]})}function at(){const{description:n,setDescription:i}=d.default.useContext(G),[r,a]=z.useInputState(n),l=n!==r,o=d.default.useCallback(()=>{!l||i(r)},[l,r]);return e(t.Textarea,{label:"Panel Description",value:r,onChange:a,minRows:2,rightSection:e(t.ActionIcon,{disabled:!l,onClick:o,sx:{alignSelf:"flex-start",marginTop:"4px"},children:e(y.DeviceFloppy,{size:20})})})}function lt(){const{title:n,setTitle:i}=d.default.useContext(G),[r,a]=z.useInputState(n),l=n!==r,o=d.default.useCallback(()=>{!l||i(r)},[l,r]);return e(t.TextInput,{label:"Panel Title",value:r,onChange:a,rightSection:e(t.ActionIcon,{disabled:!l,onClick:o,children:e(y.DeviceFloppy,{size:20})})})}function ot({conf:n,setConf:i}){const r=T.default.assign({},{x_axis_data_key:"x",y_axis_data_key:"y",z_axis_data_key:"z",xAxis3D:{type:"value",name:"X Axis Name"},yAxis3D:{type:"value",name:"Y Axis Name"},zAxis3D:{type:"value",name:"Z Axis Name"}},n),{control:a,handleSubmit:l,formState:o}=B.useForm({defaultValues:r});return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:l(i),children:[e(t.Text,{children:"X Axis"}),c(t.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[e(B.Controller,{name:"x_axis_data_key",control:a,render:({field:s})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Data Key"},s))}),e(B.Controller,{name:"xAxis3D.name",control:a,render:({field:s})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Name"},s))})]}),e(t.Text,{mt:"lg",children:"Y Axis"}),c(t.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[e(B.Controller,{name:"y_axis_data_key",control:a,render:({field:s})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Data Key"},s))}),e(B.Controller,{name:"yAxis3D.name",control:a,render:({field:s})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Name"},s))})]}),e(t.Text,{mt:"lg",children:"Z Axis"}),c(t.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[e(B.Controller,{name:"z_axis_data_key",control:a,render:({field:s})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Data Key"},s))}),e(B.Controller,{name:"zAxis3D.name",control:a,render:({field:s})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Name"},s))})]}),e(t.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:c(t.Button,{color:"blue",type:"submit",children:[e(y.DeviceFloppy,{size:20}),e(t.Text,{ml:"md",children:"Save"})]})})]})})}function pe({value:n,onChange:i}){const r=t.useMantineTheme(),a=d.default.useMemo(()=>Object.entries(r.colors).map(([o,s])=>({label:o,value:s[6]})),[r]),l=d.default.useMemo(()=>a.some(o=>o.value===n),[n,a]);return c(t.Group,{position:"apart",spacing:"xs",children:[e(t.TextInput,{placeholder:"Set any color",value:l?"":n,onChange:o=>i(o.currentTarget.value),rightSection:e(t.ColorSwatch,{color:l?"transparent":n,radius:4}),variant:l?"filled":"default",sx:{maxWidth:"100%",flexGrow:1}}),e(t.Text,{sx:{flexGrow:0},children:"or"}),e(t.Select,{data:a,value:n,onChange:i,variant:l?"default":"filled",placeholder:"Pick a theme color",icon:e(t.ColorSwatch,{color:l?n:"transparent",radius:4}),sx:{maxWidth:"100%",flexGrow:1}})]})}function st({conf:n,setConf:i}){const u=n,{series:r}=u,a=L(u,["series"]),l=d.default.useMemo(()=>m({series:I.formList(r!=null?r:[])},a),[r,a]),o=I.useForm({initialValues:l}),s=()=>o.addListItem("series",{type:"bar",name:z.randomId(),showSymbol:!1,y_axis_data_key:"value",stack:"",color:"#000"});return d.default.useMemo(()=>!T.default.isEqual(o.values,l),[o.values,l]),e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:o.onSubmit(i),children:[c(t.Group,{position:"apart",mb:"lg",sx:{position:"relative"},children:[e(t.Text,{children:"Chart Config"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",children:e(y.DeviceFloppy,{size:20})})]}),e(t.TextInput,m({size:"md",mb:"lg",label:"X Axis Data Key"},o.getInputProps("x_axis_data_key"))),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{mt:"xl",mb:0,children:"Series"}),o.values.series.map((f,h)=>c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[e(t.TextInput,m({label:"Label",required:!0,sx:{flex:1}},o.getListInputProps("series",h,"name"))),c(t.Group,{direction:"row",grow:!0,noWrap:!0,children:[e(t.TextInput,m({label:"Y Axis Data key",required:!0},o.getListInputProps("series",h,"y_axis_data_key"))),e(t.TextInput,m({label:"Stack ID",placeholder:"Stack bars by this ID"},o.getListInputProps("series",h,"stack")))]}),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{children:"Color"}),e(pe,m({},o.getListInputProps("series",h,"color")))]}),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>o.removeListItem("series",h),sx:{position:"absolute",top:15,right:5},children:e(y.Trash,{size:16})})]},h)),e(t.Group,{position:"center",mt:"xs",children:e(t.Button,{onClick:s,children:"Add a Series"})})]})]})})}function ut({conf:{label_field:n,value_field:i},setConf:r}){const a=I.useForm({initialValues:{label_field:n,value_field:i}});return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:a.onSubmit(r),children:[c(t.Group,{position:"apart",mb:"lg",sx:{position:"relative"},children:[e(t.Text,{children:"Sunburst Config"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",children:e(y.DeviceFloppy,{size:20})})]}),c(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,p:"md",mb:"sm",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[e(t.TextInput,m({label:"Label Field",required:!0,sx:{flex:1}},a.getInputProps("label_field"))),e(t.TextInput,m({label:"Value Field",placeholder:"get column value by this field",required:!0,sx:{flex:1}},a.getInputProps("value_field")))]})]})})}const dt=Object.values(E).map(n=>({label:n,value:n}));function ct({label:n,value:i,onChange:r,sx:a}){return e(t.Select,{label:n,data:dt,value:i,onChange:r,sx:a})}function pt(a){var l=a,{conf:o}=l,s=o,{columns:n}=s,i=L(s,["columns"]),{setConf:r}=l;const u=I.useForm({initialValues:m({id_field:"id",use_raw_columns:!0,columns:I.formList(n!=null?n:[]),size:"sm",horizontalSpacing:"sm",verticalSpacing:"sm",striped:!1,highlightOnHover:!1},i)}),f=()=>u.addListItem("columns",{label:z.randomId(),value_field:"value",value_type:E.string});return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:u.onSubmit(r),children:[c(t.Group,{position:"apart",mb:"lg",sx:{position:"relative"},children:[e(t.Text,{children:"Table Config"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",children:e(y.DeviceFloppy,{size:20})})]}),c(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,p:"md",mb:"sm",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[e(t.TextInput,m({size:"md",mb:"lg",label:"ID Field"},u.getInputProps("id_field"))),c(t.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:[e(t.TextInput,m({label:"Horizontal Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1}},u.getInputProps("horizontalSpacing"))),e(t.TextInput,m({label:"Vertical Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1}},u.getInputProps("verticalSpacing")))]}),e(t.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:e(t.TextInput,m({label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1}},u.getInputProps("size")))}),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{children:"Other"}),c(t.Group,{position:"apart",grow:!0,children:[e(t.Switch,m({label:"Striped"},u.getInputProps("striped",{type:"checkbox"}))),e(t.Switch,m({label:"Highlight on hover"},u.getInputProps("highlightOnHover",{type:"checkbox"})))]})]})]}),c(t.Group,{direction:"column",mt:"xs",spacing:"xs",grow:!0,p:"md",mb:"xl",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[e(t.Switch,m({label:"Use Original Data Columns"},u.getInputProps("use_raw_columns",{type:"checkbox"}))),!u.values.use_raw_columns&&c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{mt:"xl",mb:0,children:"Custom Columns"}),u.values.columns.map((h,b)=>c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[c(t.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:[e(t.TextInput,m({label:"Label",required:!0,sx:{flex:1}},u.getListInputProps("columns",b,"label"))),e(t.TextInput,m({label:"Value Field",placeholder:"get column value by this field",required:!0,sx:{flex:1}},u.getListInputProps("columns",b,"value_field"))),e(ct,m({label:"Value Type",sx:{flex:1}},u.getListInputProps("columns",b,"value_type")))]}),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>u.removeListItem("columns",b),sx:{position:"absolute",top:15,right:5},children:e(y.Trash,{size:16})})]},b)),e(t.Group,{position:"center",mt:"xs",children:e(t.Button,{onClick:f,children:"Add a Column"})})]})]}),e(t.Text,{weight:500,mb:"md",children:"Current Configuration:"}),e(M.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(u.values,null,2)})]})})}const U=[{label:"initial",value:0},{label:"500",value:25},{label:"700",value:50},{label:"semibold",value:75},{label:"bold",value:100}];function mt({label:n,value:i,onChange:r}){var o,s;const[a,l]=d.default.useState((s=(o=U.find(u=>u.label===i))==null?void 0:o.value)!=null?s:U[0].value);return d.default.useEffect(()=>{const u=U.find(f=>f.value===a);u&&r(u.label)},[a]),c(t.Group,{direction:"column",grow:!0,spacing:"xs",mb:"lg",children:[e(t.Text,{children:n}),e(t.Slider,{label:null,marks:U,value:a,onChange:l,step:25,placeholder:"Pick a font size"})]})}const me=[{align:"center",size:"xl",weight:"bold",color:"black",template:"Time: ${new Date().toISOString()}"},{align:"center",size:"md",weight:"bold",color:"red",template:"Platform: ${navigator.userAgentData.platform}."}];function ht({conf:n,setConf:i}){var l;const r=I.useForm({initialValues:{paragraphs:I.formList((l=n.paragraphs)!=null?l:me)}}),a=()=>r.addListItem("paragraphs",q(m({},me[0]),{template:z.randomId()}));return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:r.onSubmit(i),children:[r.values.paragraphs.length===0&&e(t.Text,{color:"dimmed",align:"center",children:"Empty"}),c(t.Group,{position:"apart",mb:"xs",sx:{" + .mantine-Group-root":{marginTop:0}},children:[e(t.Text,{children:"Paragraphs"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",children:e(y.DeviceFloppy,{size:20})})]}),r.values.paragraphs.map((o,s)=>c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[e(t.TextInput,m({placeholder:"Time: ${new Date().toISOString()}",label:"Content Template",required:!0,sx:{flex:1}},r.getListInputProps("paragraphs",s,"template"))),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{children:"Color"}),e(pe,m({},r.getListInputProps("paragraphs",s,"color")))]}),e(t.Group,{direction:"column",grow:!0,children:e(t.TextInput,m({label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",sx:{flex:1}},r.getListInputProps("paragraphs",s,"size")))}),e(t.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:e(mt,m({label:"Font Weight"},r.getListInputProps("paragraphs",s,"weight")))}),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>r.removeListItem("paragraphs",s),sx:{position:"absolute",top:15,right:5},children:e(y.Trash,{size:16})})]},s)),e(t.Group,{position:"center",mt:"md",children:e(t.Button,{onClick:a,children:"Add a Paragraph"})}),e(t.Text,{size:"sm",weight:500,mt:"md",children:"Current Configuration:"}),e(M.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(r.values,null,2)})]})})}const te=[{value:"text",label:"Text",Panel:ht},{value:"table",label:"Table",Panel:pt},{value:"sunburst",label:"Sunburst",Panel:ut},{value:"bar-3d",label:"Bar Chart (3D)",Panel:ot},{value:"line-bar",label:"Line-Bar Chart",Panel:st}];function ft(){const{viz:n,setViz:i}=d.default.useContext(G),[r,a]=z.useInputState(n.type),l=n.type!==r,o=d.default.useCallback(()=>{!l||i(h=>q(m({},h),{type:r}))},[l,r]),s=h=>{i(b=>q(m({},b),{conf:h}))},u=h=>{try{s(JSON.parse(h))}catch(b){console.error(b)}},f=d.default.useMemo(()=>{var h;return(h=te.find(b=>b.value===r))==null?void 0:h.Panel},[r,te]);return c(ue,{children:[e(t.Select,{label:"Visualization",value:r,onChange:a,data:te,rightSection:e(t.ActionIcon,{disabled:!l,onClick:o,children:e(y.DeviceFloppy,{size:20})})}),f&&e(f,{conf:n.conf,setConf:s}),!f&&e(t.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(n.conf,null,2),onChange:u})]})}function xt({}){return c(t.Group,{grow:!0,direction:"column",children:[e(lt,{}),e(at,{}),e(t.Divider,{}),e(ft,{})]})}function gt({opened:n,close:i}){const{freezeLayout:r}=d.default.useContext(j),{data:a,loading:l,viz:o,title:s}=d.default.useContext(G);return d.default.useEffect(()=>{r(n)},[n]),e(t.Modal,{size:"96vw",overflow:"inside",opened:n,onClose:i,title:s,trapFocus:!0,onDragStart:u=>{u.stopPropagation()},children:e(t.AppShell,{sx:{height:"90vh",maxHeight:"calc(100vh - 185px)",".mantine-AppShell-body":{height:"100%"},main:{height:"100%",width:"100%"}},padding:"md",navbar:e(t.Navbar,{width:{base:"40%"},height:"100%",p:"xs",children:c(t.Tabs,{initialTab:1,children:[e(t.Tabs.Tab,{label:"Context",children:e(He,{})}),e(t.Tabs.Tab,{label:"SQL Snippets",children:e(rt,{})}),e(t.Tabs.Tab,{label:"SQL",children:e(et,{})}),c(t.Tabs.Tab,{label:"Data",children:[e(t.LoadingOverlay,{visible:l}),e(tt,{})]}),e(t.Tabs.Tab,{label:"Viz Config",children:e(xt,{})})]})}),children:e(de,{children:e(ce,{viz:o,data:a,loading:l})})})})}function bt({}){const[n,i]=d.default.useState(!1),r=()=>i(!0),a=()=>i(!1),{title:l,description:o,loading:s,refreshData:u}=d.default.useContext(G),{inEditMode:f}=d.default.useContext(j);return c(t.Group,{position:"apart",noWrap:!0,sx:{borderBottom:"1px solid #eee",paddingBottom:"5px"},children:[e(t.Group,{children:o&&e(t.Tooltip,{label:o,withArrow:!0,children:e(y.InfoCircle,{size:12,style:{verticalAlign:"baseline",cursor:"pointer"}})})}),e(t.Group,{grow:!0,position:"center",children:e(t.Text,{lineClamp:1,weight:"bold",children:l})}),e(t.Group,{position:"right",spacing:0,sx:{height:"28px"},children:c(t.Menu,{children:[e(t.Menu.Item,{onClick:u,icon:e(y.Refresh,{size:14}),children:"Refresh"}),f&&e(t.Menu.Item,{onClick:r,icon:e(y.Settings,{size:14}),children:"Settings"}),e(t.Divider,{}),e(t.Menu.Item,{color:"red",disabled:!0,icon:e(y.Trash,{size:14}),children:"Delete"})]})}),f&&e(gt,{opened:n,close:a})]})}var qt="";function ne({viz:n,sql:i,title:r,description:a,update:l,layout:o,id:s}){const u=d.default.useContext(ee),f=d.default.useContext(V),[h,b]=d.default.useState(r),[x,g]=d.default.useState(a),[v,P]=d.default.useState(i),[_,O]=d.default.useState(n);d.default.useEffect(()=>{l==null||l({id:s,layout:o,title:h,description:x,sql:v,viz:_})},[h,x,v,_,s,o]);const{data:N=[],loading:F,refresh:Q}=ve.useRequest(Ie(v,u,f,h),{refreshDeps:[u,f]}),ie=Q;return e(G.Provider,{value:{data:N,loading:F,title:h,setTitle:b,description:x,setDescription:g,sql:v,setSQL:P,viz:_,setViz:O,refreshData:ie},children:c(t.Container,{className:"panel-root",children:[e(bt,{}),e(de,{children:e(ce,{viz:_,data:N,loading:F})})]})})}var Et="";const vt=w.WidthProvider(w.Responsive);function he({panels:n,setPanels:i,className:r="layout",cols:a={lg:12,md:10,sm:8,xs:6,xxs:4},rowHeight:l=10,onRemoveItem:o,isDraggable:s,isResizable:u,setLocalCols:f,setBreakpoint:h}){const b=(g,v)=>{h(g),f(v)},x=d.default.useCallback(g=>{const v=new Map;g.forEach(N=>{var F=N,{i:_}=F,O=L(F,["i"]);v.set(_,O)});const P=n.map(_=>q(m({},_),{layout:v.get(_.id)}));i.setState(P)},[n,i]);return e(vt,{onBreakpointChange:b,onLayoutChange:x,className:r,cols:a,rowHeight:l,isDraggable:s,isResizable:u,children:n.map((_,P)=>{var O=_,{id:g}=O,v=L(O,["id"]);return e("div",{"data-grid":v.layout,children:e(ne,q(m({id:g},v),{destroy:()=>o(g),update:N=>{i.setItem(P,N)}}))},g)})})}function fe(n,i){return c(t.Text,{sx:{svg:{verticalAlign:"text-bottom"}},children:[n," ",i]})}function yt({mode:n,setMode:i}){return e(t.SegmentedControl,{value:n,onChange:i,data:[{label:fe(e(y.PlayerPlay,{size:20}),"Use"),value:D.Use},{label:fe(e(y.Paint,{size:20}),"Edit"),value:D.Edit}]})}function St({mode:n,setMode:i,hasChanges:r,addPanel:a,saveChanges:l}){const o=n===D.Edit;return c(t.Group,{position:"apart",pt:"sm",pb:"xs",children:[e(t.Group,{position:"left",children:e(yt,{mode:n,setMode:i})}),o&&c(t.Group,{position:"right",children:[e(t.Button,{variant:"default",size:"sm",onClick:a,leftIcon:e(y.PlaylistAdd,{size:20}),children:"Add a Panel"}),e(t.Button,{variant:"default",size:"sm",onClick:l,disabled:!r,leftIcon:e(y.DeviceFloppy,{size:20}),children:"Save Changes"}),e(t.Button,{color:"red",size:"sm",disabled:!r,leftIcon:e(y.Recycle,{size:20}),children:"Revert Changes"})]}),!o&&e(t.Button,{variant:"default",size:"sm",disabled:!0,leftIcon:e(y.Share,{size:20}),children:"Share"})]})}function Ct({dashboard:n,update:i,className:r="dashboard"}){const[a,l]=d.default.useState(!1),[o,s]=d.default.useState(),[u,f]=d.default.useState(),[h,b]=z.useListState(n.panels),[x,g]=d.default.useState(n.definition.sqlSnippets),[v,P]=d.default.useState(D.Edit),_=d.default.useMemo(()=>{const k=re=>JSON.parse(JSON.stringify(re));return T.default.isEqual(k(h),k(n.panels))?!T.default.isEqual(x,n.definition.sqlSnippets):!0},[n,h,x]),O=async()=>{const k=T.default.merge({},n,{panels:h},{definition:{sqlSnippets:x}});await i(k)},N=()=>{const k=z.randomId(),Y={id:k,layout:{x:0,y:1/0,w:3,h:4},title:`New Panel - ${k}`,description:"description goes here",sql:"",viz:{type:"table",conf:{}}};b.append(Y)},F=k=>{const Y=h.findIndex(re=>re.id===k);b.remove(Y)},Q=v===D.Edit,ie=d.default.useMemo(()=>({sqlSnippets:x,setSQLSnippets:g}),[x,g]);return e("div",{className:r,children:e(V.Provider,{value:ie,children:c(j.Provider,{value:{layoutFrozen:a,freezeLayout:l,mode:v,inEditMode:Q},children:[e(St,{mode:v,setMode:P,hasChanges:_,addPanel:N,saveChanges:O}),e(he,{panels:h,setPanels:b,isDraggable:Q&&!a,isResizable:Q&&!a,onRemoveItem:F,setLocalCols:f,setBreakpoint:s})]})})})}const wt=w.WidthProvider(w.Responsive);function Tt({panels:n,className:i="layout",cols:r={lg:12,md:10,sm:8,xs:6,xxs:4},rowHeight:a=10}){return e(wt,{className:i,cols:r,rowHeight:a,isDraggable:!1,isResizable:!1,children:n.map(s=>{var u=s,{id:l}=u,o=L(u,["id"]);return e("div",{"data-grid":o.layout,children:e(ne,m({id:l},o))},l)})})}function _t({dashboard:n,className:i="dashboard"}){const[r,a]=z.useListState(n.panels),[l,o]=d.default.useState(n.definition.sqlSnippets),s=d.default.useMemo(()=>({sqlSnippets:l,setSQLSnippets:o}),[l,o]);return e("div",{className:i,children:e(V.Provider,{value:s,children:e(j.Provider,{value:{layoutFrozen:!0,freezeLayout:()=>{},mode:D.Use,inEditMode:!1},children:e(Tt,{panels:r})})})})}p.ContextInfoContext=ee,p.Dashboard=Ct,p.DashboardLayout=he,p.DashboardMode=D,p.DefinitionContext=V,p.LayoutStateContext=j,p.Panel=ne,p.PanelContext=G,p.ReadOnlyDashboard=_t,p.initialContextInfoContext=De,Object.defineProperties(p,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -0,0 +1,16 @@
1
+ /// <reference types="react" />
2
+ import { IDashboardPanel } from "../types/dashboard";
3
+ interface IReadOnlyDashboardLayout {
4
+ panels: IDashboardPanel[];
5
+ className?: string;
6
+ cols?: {
7
+ lg: number;
8
+ md: number;
9
+ sm: number;
10
+ xs: number;
11
+ xxs: number;
12
+ };
13
+ rowHeight?: number;
14
+ }
15
+ export declare function ReadOnlyDashboardLayout({ panels, className, cols, rowHeight, }: IReadOnlyDashboardLayout): JSX.Element;
16
+ export {};
@@ -1,9 +1,2 @@
1
- /// <reference types="react" />
2
- import { IDashboard } from "../types/dashboard";
3
- interface IDashboardProps {
4
- dashboard: IDashboard;
5
- className?: string;
6
- update: (dashboard: IDashboard) => Promise<void>;
7
- }
8
- export declare function Dashboard({ dashboard, update, className, }: IDashboardProps): JSX.Element;
9
- export {};
1
+ export * from './main';
2
+ export * from './read-only';
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import { IDashboard } from "../types/dashboard";
3
+ interface IDashboardProps {
4
+ dashboard: IDashboard;
5
+ className?: string;
6
+ update: (dashboard: IDashboard) => Promise<void>;
7
+ }
8
+ export declare function Dashboard({ dashboard, update, className, }: IDashboardProps): JSX.Element;
9
+ export {};
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ import { IDashboard } from "../types/dashboard";
3
+ interface IReadOnlyDashboard {
4
+ dashboard: IDashboard;
5
+ className?: string;
6
+ }
7
+ export declare function ReadOnlyDashboard({ dashboard, className, }: IReadOnlyDashboard): JSX.Element;
8
+ export {};
@@ -1,8 +1,8 @@
1
1
  /// <reference types="react" />
2
2
  import { IDashboardPanel } from '../types/dashboard';
3
3
  interface IPanel extends IDashboardPanel {
4
- destroy: () => void;
5
- update: (panel: IDashboardPanel) => void;
4
+ destroy?: () => void;
5
+ update?: (panel: IDashboardPanel) => void;
6
6
  }
7
7
  export declare function Panel({ viz: initialViz, sql: initialSQL, title: initialTitle, description: initialDesc, update, layout, id, }: IPanel): JSX.Element;
8
8
  export {};
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ interface IMantineFontWeightSlider {
3
+ label: string;
4
+ value: string;
5
+ onChange: (value: string) => void;
6
+ }
7
+ export declare function MantineFontWeightSlider({ label, value, onChange }: IMantineFontWeightSlider): JSX.Element;
8
+ export {};
@@ -1,5 +1,7 @@
1
1
  /// <reference types="react" />
2
- interface IPanelSettings {
2
+ interface IPanelSettingsModal {
3
+ opened: boolean;
4
+ close: () => void;
3
5
  }
4
- export declare function PanelSettings({}: IPanelSettings): JSX.Element;
6
+ export declare function PanelSettingsModal({ opened, close }: IPanelSettingsModal): JSX.Element;
5
7
  export {};
@@ -1,3 +1,3 @@
1
1
  /// <reference types="react" />
2
2
  import { IVizPanelProps } from "../../../types/viz-panel";
3
- export declare function SunburstPanel({ conf: { columns, ...restConf }, setConf }: IVizPanelProps): JSX.Element;
3
+ export declare function SunburstPanel({ conf: { label_field, value_field }, setConf }: IVizPanelProps): JSX.Element;
@@ -11,6 +11,8 @@ export interface IDashboardPanel {
11
11
  y: number;
12
12
  w: number;
13
13
  h: number;
14
+ moved?: boolean;
15
+ static?: boolean;
14
16
  };
15
17
  sql: string;
16
18
  viz: IVizConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devtable/dashboard",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org/"
@@ -1,8 +0,0 @@
1
- /// <reference types="react" />
2
- interface IMantineSizeSlider {
3
- label: string;
4
- value: string;
5
- onChange: (value: string) => void;
6
- }
7
- export declare function MantineSizeSlider({ label, value, onChange }: IMantineSizeSlider): JSX.Element;
8
- export {};
@@ -1,8 +0,0 @@
1
- /// <reference types="react" />
2
- interface IMantineFontSizeSlider {
3
- label: string;
4
- value: string;
5
- onChange: (value: string) => void;
6
- }
7
- export declare function MantineFontSizeSlider({ label, value, onChange }: IMantineFontSizeSlider): JSX.Element;
8
- export {};