@devtable/dashboard 0.2.0 → 0.3.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,21 @@ 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
+ console.log(needParams, params);
106
+ if (needParams && Object.keys(params).length === 0) {
107
+ console.error(`[queryBySQL] insufficient params for {${title}}'s SQL`);
108
+ return [];
109
+ }
104
110
  const formattedSQL = formatSQL(sql, params);
105
- if (sql.includes("$")) {
111
+ if (needParams) {
106
112
  console.groupCollapsed(`Final SQL for: ${title}`);
107
113
  console.log(formattedSQL);
108
114
  console.groupEnd();
@@ -218,7 +224,7 @@ function Sunbrust({
218
224
  const chartData = React.useMemo(() => {
219
225
  return data.map((d) => ({
220
226
  name: d[label_field],
221
- value: d[value_field]
227
+ value: Number(d[value_field])
222
228
  }));
223
229
  }, [data, label_field, value_field]);
224
230
  const max = React.useMemo(() => {
@@ -240,7 +246,7 @@ function Sunbrust({
240
246
  }
241
247
  }
242
248
  }), []);
243
- const option = _.defaultsDeep(defaultOption$1, labelOption, restConf, {
249
+ const option = _.merge(defaultOption$1, labelOption, restConf, {
244
250
  series: {
245
251
  data: chartData
246
252
  }
@@ -265,7 +271,14 @@ const defaultOption = {
265
271
  xAxis: {
266
272
  type: "category"
267
273
  },
268
- yAxis: {}
274
+ yAxis: {},
275
+ grid: {
276
+ top: 30,
277
+ left: 10,
278
+ right: 10,
279
+ bottom: 10,
280
+ containLabel: true
281
+ }
269
282
  };
270
283
  function VizLineBarChart({
271
284
  conf,
@@ -461,11 +474,16 @@ function VizText({
461
474
  return /* @__PURE__ */ jsx(Fragment, {
462
475
  children: paragraphs.map((_a, index2) => {
463
476
  var _b = _a, {
464
- template
477
+ template,
478
+ size
465
479
  } = _b, rest = __objRest(_b, [
466
- "template"
480
+ "template",
481
+ "size"
467
482
  ]);
468
483
  return /* @__PURE__ */ jsx(Text, __spreadProps(__spreadValues({}, rest), {
484
+ sx: {
485
+ fontSize: size
486
+ },
469
487
  children: interpolateString(template, data[0])
470
488
  }), `${template}---${index2}`);
471
489
  })
@@ -705,7 +723,6 @@ function SQLSnippetsForm({
705
723
  sqlSnippets,
706
724
  setSQLSnippets
707
725
  }) {
708
- const submitButton = React.useRef(null);
709
726
  const initialValues = React.useMemo(() => ({
710
727
  snippets: formList(sqlSnippets != null ? sqlSnippets : [])
711
728
  }), [sqlSnippets]);
@@ -717,12 +734,6 @@ function SQLSnippetsForm({
717
734
  value: ""
718
735
  });
719
736
  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
737
  const submit = ({
727
738
  snippets
728
739
  }) => {
@@ -731,19 +742,13 @@ function SQLSnippetsForm({
731
742
  return /* @__PURE__ */ jsx(Group, {
732
743
  direction: "column",
733
744
  sx: {
734
- width: "100%"
745
+ width: "100%",
746
+ position: "relative"
735
747
  },
736
748
  grow: true,
737
749
  children: /* @__PURE__ */ jsxs("form", {
738
750
  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, {
751
+ children: [form.values.snippets.map((_item, index2) => /* @__PURE__ */ jsxs(Group, {
747
752
  direction: "column",
748
753
  grow: true,
749
754
  my: 0,
@@ -773,19 +778,24 @@ function SQLSnippetsForm({
773
778
  size: 16
774
779
  })
775
780
  })]
776
- }, index2)), /* @__PURE__ */ jsx(Group, {
781
+ }, index2)), /* @__PURE__ */ jsxs(Group, {
777
782
  position: "center",
778
783
  mt: "xl",
779
784
  grow: true,
780
785
  sx: {
781
- width: "60%"
786
+ width: "80%"
782
787
  },
783
788
  mx: "auto",
784
- children: /* @__PURE__ */ jsx(Button, {
785
- color: "blue",
789
+ children: [/* @__PURE__ */ jsx(Button, {
790
+ variant: "default",
786
791
  onClick: addSnippet,
787
792
  children: "Add a snippet"
788
- })
793
+ }), /* @__PURE__ */ jsx(Button, {
794
+ color: "blue",
795
+ type: "submit",
796
+ disabled: !changed,
797
+ children: "Submit"
798
+ })]
789
799
  })]
790
800
  })
791
801
  });
@@ -806,6 +816,7 @@ WHERE \${author_time_condition}`;
806
816
  width: "100%"
807
817
  },
808
818
  noCopy: true,
819
+ trim: false,
809
820
  colorScheme: "dark",
810
821
  children: `-- You may refer context data *by name*
811
822
  -- in SQL or VizConfig.
@@ -814,7 +825,7 @@ ${sampleSQL}
814
825
 
815
826
  -- where author_time_condition is:
816
827
  author_time BETWEEN '\${timeRange?.[0].toISOString()}' AND '\${timeRange?.[1].toISOString()}'
817
- `
828
+ `
818
829
  }), /* @__PURE__ */ jsx(Text, {
819
830
  weight: 700,
820
831
  children: "SQL Snippets"
@@ -1101,7 +1112,6 @@ function VizLineBarChartPanel({
1101
1112
  conf,
1102
1113
  setConf
1103
1114
  }) {
1104
- const submitButton = React.useRef(null);
1105
1115
  const _a = conf, {
1106
1116
  series
1107
1117
  } = _a, restConf = __objRest(_a, [
@@ -1121,13 +1131,7 @@ function VizLineBarChartPanel({
1121
1131
  stack: "",
1122
1132
  color: "#000"
1123
1133
  });
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]);
1134
+ React.useMemo(() => !_.isEqual(form.values, initialValues), [form.values, initialValues]);
1131
1135
  return /* @__PURE__ */ jsx(Group, {
1132
1136
  direction: "column",
1133
1137
  mt: "md",
@@ -1143,13 +1147,14 @@ function VizLineBarChartPanel({
1143
1147
  },
1144
1148
  children: [/* @__PURE__ */ jsx(Text, {
1145
1149
  children: "Chart Config"
1146
- }), /* @__PURE__ */ jsx("button", {
1147
- ref: submitButton,
1150
+ }), /* @__PURE__ */ jsx(ActionIcon, {
1148
1151
  type: "submit",
1149
- style: {
1150
- display: "none"
1151
- },
1152
- children: "Ghost submit"
1152
+ mr: 5,
1153
+ variant: "filled",
1154
+ color: "blue",
1155
+ children: /* @__PURE__ */ jsx(DeviceFloppy, {
1156
+ size: 20
1157
+ })
1153
1158
  })]
1154
1159
  }), /* @__PURE__ */ jsx(TextInput, __spreadValues({
1155
1160
  size: "md",
@@ -1220,20 +1225,17 @@ function VizLineBarChartPanel({
1220
1225
  })
1221
1226
  });
1222
1227
  }
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;
1228
+ function SunburstPanel({
1229
+ conf: {
1230
+ label_field,
1231
+ value_field
1232
+ },
1233
+ setConf
1234
+ }) {
1233
1235
  const form = useForm({
1234
1236
  initialValues: {
1235
- label_field: "name",
1236
- value_field: "value"
1237
+ label_field,
1238
+ value_field
1237
1239
  }
1238
1240
  });
1239
1241
  return /* @__PURE__ */ jsx(Group, {
@@ -1289,52 +1291,6 @@ function SunburstPanel(_a) {
1289
1291
  })
1290
1292
  });
1291
1293
  }
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
1294
  const valueTypes = Object.values(ValueType).map((v) => ({
1339
1295
  label: v,
1340
1296
  value: v
@@ -1353,16 +1309,16 @@ function ValueTypeSelector({
1353
1309
  sx
1354
1310
  });
1355
1311
  }
1356
- function VizTablePanel(_e) {
1357
- var _f = _e, {
1358
- conf: _g
1359
- } = _f, _h = _g, {
1312
+ function VizTablePanel(_a) {
1313
+ var _b = _a, {
1314
+ conf: _c
1315
+ } = _b, _d = _c, {
1360
1316
  columns
1361
- } = _h, restConf = __objRest(_h, [
1317
+ } = _d, restConf = __objRest(_d, [
1362
1318
  "columns"
1363
1319
  ]), {
1364
1320
  setConf
1365
- } = _f;
1321
+ } = _b;
1366
1322
  const form = useForm({
1367
1323
  initialValues: __spreadValues({
1368
1324
  id_field: "id",
@@ -1428,10 +1384,20 @@ function VizTablePanel(_e) {
1428
1384
  flexGrow: 1
1429
1385
  }
1430
1386
  },
1431
- children: [/* @__PURE__ */ jsx(MantineSizeSlider, __spreadValues({
1432
- label: "Horizontal Spacing"
1433
- }, form.getInputProps("horizontalSpacing"))), /* @__PURE__ */ jsx(MantineSizeSlider, __spreadValues({
1434
- label: "Vertical Spacing"
1387
+ children: [/* @__PURE__ */ jsx(TextInput, __spreadValues({
1388
+ label: "Horizontal Spacing",
1389
+ placeholder: "10px, 1em, 1rem, 100%...",
1390
+ required: true,
1391
+ sx: {
1392
+ flex: 1
1393
+ }
1394
+ }, form.getInputProps("horizontalSpacing"))), /* @__PURE__ */ jsx(TextInput, __spreadValues({
1395
+ label: "Vertical Spacing",
1396
+ placeholder: "10px, 1em, 1rem, 100%...",
1397
+ required: true,
1398
+ sx: {
1399
+ flex: 1
1400
+ }
1435
1401
  }, form.getInputProps("verticalSpacing")))]
1436
1402
  }), /* @__PURE__ */ jsx(Group, {
1437
1403
  position: "apart",
@@ -1442,8 +1408,13 @@ function VizTablePanel(_e) {
1442
1408
  flexGrow: 1
1443
1409
  }
1444
1410
  },
1445
- children: /* @__PURE__ */ jsx(MantineSizeSlider, __spreadValues({
1446
- label: "Font Size"
1411
+ children: /* @__PURE__ */ jsx(TextInput, __spreadValues({
1412
+ label: "Font Size",
1413
+ placeholder: "10px, 1em, 1rem, 100%...",
1414
+ required: true,
1415
+ sx: {
1416
+ flex: 1
1417
+ }
1447
1418
  }, form.getInputProps("size")))
1448
1419
  }), /* @__PURE__ */ jsxs(Group, {
1449
1420
  direction: "column",
@@ -1575,7 +1546,7 @@ const marks = [{
1575
1546
  label: "bold",
1576
1547
  value: 100
1577
1548
  }];
1578
- function MantineFontSizeSlider({
1549
+ function MantineFontWeightSlider({
1579
1550
  label,
1580
1551
  value,
1581
1552
  onChange
@@ -1684,7 +1655,17 @@ function VizTextPanel({
1684
1655
  children: [/* @__PURE__ */ jsx(Text, {
1685
1656
  children: "Color"
1686
1657
  }), /* @__PURE__ */ jsx(MantineColorSelector, __spreadValues({}, form.getListInputProps("paragraphs", index2, "color")))]
1687
- }), /* @__PURE__ */ jsxs(Group, {
1658
+ }), /* @__PURE__ */ jsx(Group, {
1659
+ direction: "column",
1660
+ grow: true,
1661
+ children: /* @__PURE__ */ jsx(TextInput, __spreadValues({
1662
+ label: "Font Size",
1663
+ placeholder: "10px, 1em, 1rem, 100%...",
1664
+ sx: {
1665
+ flex: 1
1666
+ }
1667
+ }, form.getListInputProps("paragraphs", index2, "size")))
1668
+ }), /* @__PURE__ */ jsx(Group, {
1688
1669
  position: "apart",
1689
1670
  grow: true,
1690
1671
  sx: {
@@ -1693,11 +1674,9 @@ function VizTextPanel({
1693
1674
  maxWidth: "100%"
1694
1675
  }
1695
1676
  },
1696
- children: [/* @__PURE__ */ jsx(MantineSizeSlider, __spreadValues({
1697
- label: "Font Size"
1698
- }, form.getListInputProps("paragraphs", index2, "size"))), /* @__PURE__ */ jsx(MantineFontSizeSlider, __spreadValues({
1677
+ children: /* @__PURE__ */ jsx(MantineFontWeightSlider, __spreadValues({
1699
1678
  label: "Font Weight"
1700
- }, form.getListInputProps("paragraphs", index2, "weight")))]
1679
+ }, form.getListInputProps("paragraphs", index2, "weight")))
1701
1680
  }), /* @__PURE__ */ jsx(ActionIcon, {
1702
1681
  color: "red",
1703
1682
  variant: "hover",
@@ -1815,7 +1794,10 @@ function VizConfig({}) {
1815
1794
  children: [/* @__PURE__ */ jsx(EditTitle, {}), /* @__PURE__ */ jsx(EditDescription, {}), /* @__PURE__ */ jsx(Divider, {}), /* @__PURE__ */ jsx(EditVizConf, {})]
1816
1795
  });
1817
1796
  }
1818
- function PanelSettings({}) {
1797
+ function PanelSettingsModal({
1798
+ opened,
1799
+ close
1800
+ }) {
1819
1801
  const {
1820
1802
  freezeLayout
1821
1803
  } = React.useContext(LayoutStateContext);
@@ -1825,153 +1807,141 @@ function PanelSettings({}) {
1825
1807
  viz,
1826
1808
  title
1827
1809
  } = React.useContext(PanelContext);
1828
- const [opened, setOpened] = React.useState(false);
1829
- const open = () => setOpened(true);
1830
1810
  React.useEffect(() => {
1831
1811
  freezeLayout(opened);
1832
1812
  }, [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
- }
1813
+ return /* @__PURE__ */ jsx(Modal, {
1814
+ size: "96vw",
1815
+ overflow: "inside",
1816
+ opened,
1817
+ onClose: close,
1818
+ title,
1819
+ trapFocus: true,
1820
+ onDragStart: (e) => {
1821
+ e.stopPropagation();
1822
+ },
1823
+ children: /* @__PURE__ */ jsx(AppShell, {
1824
+ sx: {
1825
+ height: "90vh",
1826
+ maxHeight: "calc(100vh - 185px)",
1827
+ ".mantine-AppShell-body": {
1828
+ height: "100%"
1855
1829
  },
1856
- padding: "md",
1857
- navbar: /* @__PURE__ */ jsx(Navbar, {
1858
- width: {
1859
- base: "40%"
1860
- },
1830
+ main: {
1861
1831
  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
- })
1832
+ width: "100%"
1833
+ }
1834
+ },
1835
+ padding: "md",
1836
+ navbar: /* @__PURE__ */ jsx(Navbar, {
1837
+ width: {
1838
+ base: "40%"
1839
+ },
1840
+ height: "100%",
1841
+ p: "xs",
1842
+ children: /* @__PURE__ */ jsxs(Tabs, {
1843
+ initialTab: 1,
1844
+ children: [/* @__PURE__ */ jsx(Tabs.Tab, {
1845
+ label: "Context",
1846
+ children: /* @__PURE__ */ jsx(ContextInfo, {})
1847
+ }), /* @__PURE__ */ jsx(Tabs.Tab, {
1848
+ label: "SQL Snippets",
1849
+ children: /* @__PURE__ */ jsx(SQLSnippetsTab, {})
1850
+ }), /* @__PURE__ */ jsx(Tabs.Tab, {
1851
+ label: "SQL",
1852
+ children: /* @__PURE__ */ jsx(QueryEditor, {})
1853
+ }), /* @__PURE__ */ jsxs(Tabs.Tab, {
1854
+ label: "Data",
1855
+ children: [/* @__PURE__ */ jsx(LoadingOverlay, {
1856
+ visible: loading
1857
+ }), /* @__PURE__ */ jsx(QueryResult, {})]
1858
+ }), /* @__PURE__ */ jsx(Tabs.Tab, {
1859
+ label: "Viz Config",
1860
+ children: /* @__PURE__ */ jsx(VizConfig, {})
1861
+ })]
1862
+ })
1863
+ }),
1864
+ children: /* @__PURE__ */ jsx(ErrorBoundary, {
1865
+ children: /* @__PURE__ */ jsx(Viz, {
1866
+ viz,
1867
+ data,
1868
+ loading
1891
1869
  })
1892
1870
  })
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
- })]
1871
+ })
1902
1872
  });
1903
1873
  }
1904
- function PanelTitle({
1905
- title,
1906
- description
1907
- }) {
1874
+ function PanelTitleBar({}) {
1875
+ const [opened, setOpened] = React.useState(false);
1876
+ const open = () => setOpened(true);
1877
+ const close = () => setOpened(false);
1878
+ const {
1879
+ title,
1880
+ description,
1881
+ loading,
1882
+ refreshData
1883
+ } = React.useContext(PanelContext);
1884
+ const {
1885
+ inEditMode
1886
+ } = React.useContext(LayoutStateContext);
1908
1887
  return /* @__PURE__ */ jsxs(Group, {
1909
- position: "center",
1888
+ position: "apart",
1889
+ noWrap: true,
1910
1890
  sx: {
1911
1891
  borderBottom: "1px solid #eee",
1912
1892
  paddingBottom: "5px"
1913
1893
  },
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, {
1894
+ children: [/* @__PURE__ */ jsx(Group, {
1895
+ children: description && /* @__PURE__ */ jsx(Tooltip, {
1923
1896
  label: description,
1924
1897
  withArrow: true,
1925
- children: [/* @__PURE__ */ jsx(InfoCircle, {
1898
+ children: /* @__PURE__ */ jsx(InfoCircle, {
1926
1899
  size: 12,
1927
1900
  style: {
1928
1901
  verticalAlign: "baseline",
1929
1902
  cursor: "pointer"
1930
1903
  }
1931
- }), /* @__PURE__ */ jsx(Text, {
1932
- weight: "bold",
1933
- sx: {
1934
- marginLeft: "5px",
1935
- display: "inline"
1936
- },
1937
- children: title
1938
- })]
1904
+ })
1939
1905
  })
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, {
1906
+ }), /* @__PURE__ */ jsx(Group, {
1907
+ grow: true,
1908
+ position: "center",
1909
+ children: /* @__PURE__ */ jsx(Text, {
1910
+ lineClamp: 1,
1911
+ weight: "bold",
1912
+ children: title
1913
+ })
1914
+ }), /* @__PURE__ */ jsx(Group, {
1958
1915
  position: "right",
1959
1916
  spacing: 0,
1960
1917
  sx: {
1961
- position: "absolute",
1962
- right: "15px",
1963
- top: "4px",
1964
1918
  height: "28px"
1965
1919
  },
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, {})]
1920
+ children: /* @__PURE__ */ jsxs(Menu, {
1921
+ children: [/* @__PURE__ */ jsx(Menu.Item, {
1922
+ onClick: refreshData,
1923
+ icon: /* @__PURE__ */ jsx(Refresh, {
1924
+ size: 14
1925
+ }),
1926
+ children: "Refresh"
1927
+ }), inEditMode && /* @__PURE__ */ jsx(Menu.Item, {
1928
+ onClick: open,
1929
+ icon: /* @__PURE__ */ jsx(Settings, {
1930
+ size: 14
1931
+ }),
1932
+ children: "Settings"
1933
+ }), /* @__PURE__ */ jsx(Divider, {}), /* @__PURE__ */ jsx(Menu.Item, {
1934
+ color: "red",
1935
+ disabled: true,
1936
+ icon: /* @__PURE__ */ jsx(Trash, {
1937
+ size: 14
1938
+ }),
1939
+ children: "Delete"
1940
+ })]
1941
+ })
1942
+ }), inEditMode && /* @__PURE__ */ jsx(PanelSettingsModal, {
1943
+ opened,
1944
+ close
1975
1945
  })]
1976
1946
  });
1977
1947
  }
@@ -2195,7 +2165,6 @@ function Dashboard({
2195
2165
  className = "dashboard"
2196
2166
  }) {
2197
2167
  const [layoutFrozen, freezeLayout] = React.useState(false);
2198
- const [newCounter, setNewCounter] = React.useState(0);
2199
2168
  const [breakpoint, setBreakpoint] = React.useState();
2200
2169
  const [localCols, setLocalCols] = React.useState();
2201
2170
  const [panels, setPanels] = useListState(dashboard.panels);
@@ -2220,15 +2189,13 @@ function Dashboard({
2220
2189
  await update(d);
2221
2190
  };
2222
2191
  const addPanel = () => {
2223
- console.log("adding", "n" + newCounter);
2224
- setNewCounter((v) => v + 1);
2225
- const id = "n" + newCounter;
2192
+ const id = randomId();
2226
2193
  const newItem = {
2227
2194
  id,
2228
2195
  layout: {
2229
- x: panels.length * 2 % (localCols || 12),
2196
+ x: 0,
2230
2197
  y: Infinity,
2231
- w: 4,
2198
+ w: 3,
2232
2199
  h: 4
2233
2200
  },
2234
2201
  title: `New Panel - ${id}`,
@@ -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,P,Se,Ce,X,H,A,we,zt,M,L,B){"use strict";var wt=Object.defineProperty,Tt=Object.defineProperties;var _t=Object.getOwnPropertyDescriptors;var K=Object.getOwnPropertySymbols;var ge=Object.prototype.hasOwnProperty,be=Object.prototype.propertyIsEnumerable;var xe=(p,S,C)=>S in p?wt(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},k=(p,S)=>Tt(p,_t(S));var I=(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 j(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=j(S),T=j(C),_e=j(ye),Z=j(Se),$=Te(Ce),re=j(we),q=(n=>(n.Use="use",n.Edit="edit",n))(q||{});const ze={layoutFrozen:!1,freezeLayout:()=>{},mode:q.Edit,inEditMode:!1},R=d.default.createContext(ze),Pe=(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),_e.default(s).then(l=>l.data).catch(l=>Promise.reject(l))})("POST");function ae(n,i){const r=Object.keys(i),a=Object.values(i);return new Function(...r,`return \`${n}\`;`)(...a)}function Ie(n,i){const r=i.sqlSnippets.reduce((a,o)=>(a[o.key]=ae(o.value,n),a),{});return T.default.merge({},r,n)}const Le=(n,i,r,a)=>async()=>{if(!n)return[];const o=n.includes("$"),s=Ie(i,r);if(console.log(o,s),o&&Object.keys(s).length===0)return console.error(`[queryBySQL] insufficient params for {${a}}'s SQL`),[];const l=ae(n,s);return o&&(console.groupCollapsed(`Final SQL for: ${a}`),console.log(l),console.groupEnd()),await Pe("/query",{sql:l})},oe={},De=oe,ee=d.default.createContext(oe),Ge={data:[],loading:!1,title:"",setTitle:()=>{},description:"",setDescription:()=>{},sql:"",setSQL:()=>{},viz:{type:"",conf:{}},setViz:()=>{},refreshData:()=>{}},D=d.default.createContext(Ge);var Q={exports:{}},W={};/**
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 le(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)Oe.call(i,a)&&!Me.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:qe,type:n,key:s,ref:l,props:o,_owner:Ae.current}}W.Fragment=Ee,W.jsx=le,W.jsxs=le,Q.exports=W;const e=Q.exports.jsx,c=Q.exports.jsxs,se=Q.exports.Fragment;class ue 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}}$.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:o="name",value_field:s="value"}=x,l=I(x,["label_field","value_field"]),u=d.default.useMemo(()=>i.map(g=>({name:g[o],value:Number(g[s])})),[i,o,s]),f=d.default.useMemo(()=>{var g,v;return(v=(g=T.default.maxBy(u,z=>z.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,l,{series:{data:u}});return e(Z.default,{echarts:$,option:b,style:{width:r,height:a}})}$.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 $e({conf:n,data:i,width:r,height:a}){const o=d.default.useMemo(()=>{const s={dataset:{source:i}},l={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=I(x,["y_axis_data_key"]);return m({data:i.map(g=>g[f])},h)});return T.default.assign({},Fe,s,l,{series:u})},[n,i]);return!r||!a?null:e(Z.default,{echarts:$,option:o,style:{width:r,height:a}})}var E=(n=>(n.string="string",n.number="number",n.eloc="eloc",n.percentage="percentage",n))(E||{});function je({value:n}){return e(t.Text,{component:"span",children:n})}function Ve({value:n}){return e(t.Text,{component:"span",children:n})}function Re({value:n}){const i=re.default(n).format({thousandSeparated:!0});return e(t.Text,{component:"span",children:i})}function Qe({value:n}){const i=re.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(je,{value:n});case E.eloc:return e(Ve,{value:n});case E.number:return e(Re,{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:o,use_raw_columns:s,columns:l}=b,u=I(b,["id_field","use_raw_columns","columns"]),f=d.default.useMemo(()=>s?Object.keys(i==null?void 0:i[0]):l.map(x=>x.label),[s,l,i]),h=d.default.useMemo(()=>s?Object.keys(i==null?void 0:i[0]).map(x=>({label:x,value_field:x,value_type:E.string})):l,[s,l,i]);return c(t.Table,k(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:z})=>e("td",{children:e(t.Group,{sx:{"&, .mantine-Text-root":{fontFamily:"monospace"}},children:e(We,{value:x[v],type:z})})},x[v]))},o?x[o]:`row-${g}`))})]}))}function Ue(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 Ye({conf:{paragraphs:n},data:i}){return e(se,{children:n.map((l,s)=>{var u=l,{template:r,size:a}=u,o=I(u,["template","size"]);return e(t.Text,k(m({},o),{sx:{fontSize:a},children:Ue(r,i[0])}),`${r}---${s}`)})})}$.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:o,y_axis_data_key:s,z_axis_data_key:l}=x,u=I(x,["x_axis_data_key","y_axis_data_key","z_axis_data_key"]),f=d.default.useMemo(()=>T.default.minBy(i,g=>g[l])[l],[i,l]),h=d.default.useMemo(()=>T.default.maxBy(i,g=>g[l])[l],[i,l]),b=k(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[o],g[s],g[l]])}]});return e(Z.default,{echarts:$,option:b,style:{width:r,height:a}})}var It="";function Xe(n,i,r,a){const o={width:n,height:i,data:r,conf:a.conf};switch(a.type){case"sunburst":return e(Ne,m({},o));case"line-bar":return e($e,m({},o));case"table":return e(Je,m({},o));case"text":return e(Ye,m({},o));case"bar-3d":return e(Ke,m({},o));default:return null}}function de({viz:n,data:i,loading:r}){const{ref:a,width:o,height:s}=P.useElementSize(),l=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:[l&&e(t.Text,{color:"gray",align:"center",children:"nothing to show"}),!l&&Xe(o,s,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 Lt="";function Ze({}){const{sql:n,setSQL:i}=d.default.useContext(D),[r,a]=d.default.useState(!0),o=u=>{i(u.target.value)},s=d.default.useCallback(()=>{a(u=>!u)},[]),l=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: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 et=Ze;function tt({}){const{data:n}=d.default.useContext(D);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:()=>{}},J=d.default.createContext(nt);function it({sqlSnippets:n,setSQLSnippets:i}){const r=d.default.useMemo(()=>({snippets:L.formList(n!=null?n:[])}),[n]),a=L.useForm({initialValues:r}),o=()=>a.addListItem("snippets",{key:P.randomId(),value:""}),s=d.default.useMemo(()=>!T.default.isEqual(a.values,r),[a.values,r]),l=({snippets:u})=>{i(u)};return e(t.Group,{direction:"column",sx:{width:"100%",position:"relative"},grow:!0,children:c("form",{onSubmit:a.onSubmit(l),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:o,children:"Add a snippet"}),e(t.Button,{color:"blue",type:"submit",disabled:!s,children:"Submit"})]})]})})}function rt({}){const{sqlSnippets:n,setSQLSnippets:i}=d.default.useContext(J),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(D),[r,a]=P.useInputState(n),o=n!==r,s=d.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(y.DeviceFloppy,{size:20})})})}function ot(){const{title:n,setTitle:i}=d.default.useContext(D),[r,a]=P.useInputState(n),o=n!==r,s=d.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(y.DeviceFloppy,{size:20})})})}function lt({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:o,formState:s}=B.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(B.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(B.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(B.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(B.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(B.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(B.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(y.DeviceFloppy,{size:20}),e(t.Text,{ml:"md",children:"Save"})]})})]})})}function ce({value:n,onChange:i}){const r=t.useMantineTheme(),a=d.default.useMemo(()=>Object.entries(r.colors).map(([s,l])=>({label:s,value:l[6]})),[r]),o=d.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 st({conf:n,setConf:i}){const u=n,{series:r}=u,a=I(u,["series"]),o=d.default.useMemo(()=>m({series:L.formList(r!=null?r:[])},a),[r,a]),s=L.useForm({initialValues:o}),l=()=>s.addListItem("series",{type:"bar",name:P.randomId(),showSymbol:!1,y_axis_data_key:"value",stack:"",color:"#000"});return d.default.useMemo(()=>!T.default.isEqual(s.values,o),[s.values,o]),e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:s.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"},s.getInputProps("x_axis_data_key"))),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{mt:"xl",mb:0,children:"Series"}),s.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}},s.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},s.getListInputProps("series",h,"y_axis_data_key"))),e(t.TextInput,m({label:"Stack ID",placeholder:"Stack bars by this ID"},s.getListInputProps("series",h,"stack")))]}),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{children:"Color"}),e(ce,m({},s.getListInputProps("series",h,"color")))]}),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>s.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:l,children:"Add a Series"})})]})]})})}function ut({conf:{label_field:n,value_field:i},setConf:r}){const a=L.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 o=a,{conf:s}=o,l=s,{columns:n}=l,i=I(l,["columns"]),{setConf:r}=o;const u=L.useForm({initialValues:m({id_field:"id",use_raw_columns:!0,columns:L.formList(n!=null?n:[]),size:"sm",horizontalSpacing:"sm",verticalSpacing:"sm",striped:!1,highlightOnHover:!1},i)}),f=()=>u.addListItem("columns",{label:P.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 s,l;const[a,o]=d.default.useState((l=(s=U.find(u=>u.label===i))==null?void 0:s.value)!=null?l: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:o,step:25,placeholder:"Pick a font size"})]})}const pe=[{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 o;const r=L.useForm({initialValues:{paragraphs:L.formList((o=n.paragraphs)!=null?o:pe)}}),a=()=>r.addListItem("paragraphs",k(m({},pe[0]),{template:P.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((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(ce,m({},r.getListInputProps("paragraphs",l,"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",l,"size")))}),e(t.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:e(mt,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(y.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 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:lt},{value:"line-bar",label:"Line-Bar Chart",Panel:st}];function ft(){const{viz:n,setViz:i}=d.default.useContext(D),[r,a]=P.useInputState(n.type),o=n.type!==r,s=d.default.useCallback(()=>{!o||i(h=>k(m({},h),{type:r}))},[o,r]),l=h=>{i(b=>k(m({},b),{conf:h}))},u=h=>{try{l(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(se,{children:[e(t.Select,{label:"Visualization",value:r,onChange:a,data:te,rightSection:e(t.ActionIcon,{disabled:!o,onClick:s,children:e(y.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:u})]})}function xt({}){return c(t.Group,{grow:!0,direction:"column",children:[e(ot,{}),e(at,{}),e(t.Divider,{}),e(ft,{})]})}function gt({opened:n,close:i}){const{freezeLayout:r}=d.default.useContext(R),{data:a,loading:o,viz:s,title:l}=d.default.useContext(D);return d.default.useEffect(()=>{r(n)},[n]),e(t.Modal,{size:"96vw",overflow:"inside",opened:n,onClose:i,title:l,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:o}),e(tt,{})]}),e(t.Tabs.Tab,{label:"Viz Config",children:e(xt,{})})]})}),children:e(ue,{children:e(de,{viz:s,data:a,loading:o})})})})}function bt({}){const[n,i]=d.default.useState(!1),r=()=>i(!0),a=()=>i(!1),{title:o,description:s,loading:l,refreshData:u}=d.default.useContext(D),{inEditMode:f}=d.default.useContext(R);return c(t.Group,{position:"apart",noWrap:!0,sx:{borderBottom:"1px solid #eee",paddingBottom:"5px"},children:[e(t.Group,{children:s&&e(t.Tooltip,{label:s,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:o})}),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 Dt="";function me({viz:n,sql:i,title:r,description:a,update:o,layout:s,id:l}){const u=d.default.useContext(ee),f=d.default.useContext(J),[h,b]=d.default.useState(r),[x,g]=d.default.useState(a),[v,z]=d.default.useState(i),[_,O]=d.default.useState(n);d.default.useEffect(()=>{o({id:l,layout:s,title:h,description:x,sql:v,viz:_})},[h,x,v,_,l,s]);const{data:N=[],loading:F,refresh:V}=ve.useRequest(Le(v,u,f,h),{refreshDeps:[u,f]}),ne=V;return e(D.Provider,{value:{data:N,loading:F,title:h,setTitle:b,description:x,setDescription:g,sql:v,setSQL:z,viz:_,setViz:O,refreshData:ne},children:c(t.Container,{className:"panel-root",children:[e(bt,{}),e(ue,{children:e(de,{viz:_,data:N,loading:F})})]})})}var Gt="";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:o=10,onRemoveItem:s,isDraggable:l,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=I(F,["i"]);v.set(_,O)});const z=n.map(_=>k(m({},_),{layout:v.get(_.id)}));i.setState(z)},[n,i]);return e(vt,{onBreakpointChange:b,onLayoutChange:x,className:r,cols:a,rowHeight:o,isDraggable:l,isResizable:u,children:n.map((_,z)=>{var O=_,{id:g}=O,v=I(O,["id"]);return e("div",{"data-grid":v.layout,children:e(me,k(m({id:g},v),{destroy:()=>s(g),update:N=>{i.setItem(z,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:q.Use},{label:fe(e(y.Paint,{size:20}),"Edit"),value:q.Edit}]})}function St({mode:n,setMode:i,hasChanges:r,addPanel:a,saveChanges:o}){const s=n===q.Edit;return c(t.Group,{position:"apart",pt:"sm",pb:"xs",children:[e(t.Group,{position:"left",children:e(yt,{mode:n,setMode:i})}),s&&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:o,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"})]}),!s&&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,o]=d.default.useState(!1),[s,l]=d.default.useState(),[u,f]=d.default.useState(),[h,b]=P.useListState(n.panels),[x,g]=d.default.useState(n.definition.sqlSnippets),[v,z]=d.default.useState(q.Edit),_=d.default.useMemo(()=>{const G=ie=>JSON.parse(JSON.stringify(ie));return T.default.isEqual(G(h),G(n.panels))?!T.default.isEqual(x,n.definition.sqlSnippets):!0},[n,h,x]),O=async()=>{const G=T.default.merge({},n,{panels:h},{definition:{sqlSnippets:x}});await i(G)},N=()=>{const G=P.randomId(),Y={id:G,layout:{x:0,y:1/0,w:3,h:4},title:`New Panel - ${G}`,description:"description goes here",sql:"",viz:{type:"table",conf:{}}};b.append(Y)},F=G=>{const Y=h.findIndex(ie=>ie.id===G);b.remove(Y)},V=v===q.Edit,ne=d.default.useMemo(()=>({sqlSnippets:x,setSQLSnippets:g}),[x,g]);return e("div",{className:r,children:e(J.Provider,{value:ne,children:c(R.Provider,{value:{layoutFrozen:a,freezeLayout:o,mode:v,inEditMode:V},children:[e(St,{mode:v,setMode:z,hasChanges:_,addPanel:N,saveChanges:O}),e(he,{panels:h,setPanels:b,isDraggable:V&&!a,isResizable:V&&!a,onRemoveItem:F,setLocalCols:f,setBreakpoint:l})]})})})}p.ContextInfoContext=ee,p.Dashboard=Ct,p.DashboardLayout=he,p.DashboardMode=q,p.DefinitionContext=J,p.LayoutStateContext=R,p.Panel=me,p.PanelContext=D,p.initialContextInfoContext=De,Object.defineProperties(p,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -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.3.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 {};