@devtable/dashboard 1.4.0 → 1.7.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,15 +32,15 @@ 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 { Popover, Tooltip, Group, Text, ActionIcon, TextInput, Box, LoadingOverlay, Table, Select, Button, useMantineTheme, ColorSwatch, Switch, Slider, JsonInput, Modal, AppShell, Tabs, Menu, Divider, Container, SegmentedControl, Textarea } from "@mantine/core";
35
+ import { Popover, Tooltip, Group, Text, ActionIcon, TextInput, Box, LoadingOverlay, Table, Select, Button, useMantineTheme, ColorSwatch, JsonInput, Anchor, Switch, Slider, Modal, AppShell, Tabs, Menu, Divider, Container, SegmentedControl, Textarea } from "@mantine/core";
36
36
  import { useRequest } from "ahooks";
37
37
  import axios from "axios";
38
- import { InfoCircle, DeviceFloppy, Trash, Refresh, Settings, Paint, PlayerPlay, PlaylistAdd, ClipboardText, Database, Recycle, Share } from "tabler-icons-react";
38
+ import { InfoCircle, DeviceFloppy, Refresh, Trash, Settings, Paint, PlayerPlay, PlaylistAdd, ClipboardText, Database, Recycle, Share } from "tabler-icons-react";
39
39
  import RichTextEditor, { RichTextEditor as RichTextEditor$1 } from "@mantine/rte";
40
40
  import { useInputState, useElementSize, randomId } from "@mantine/hooks";
41
41
  import ReactEChartsCore from "echarts-for-react/lib/core";
42
42
  import * as echarts from "echarts/core";
43
- import { SunburstChart, BarChart, LineChart } from "echarts/charts";
43
+ import { SunburstChart, BarChart, LineChart, PieChart } from "echarts/charts";
44
44
  import { CanvasRenderer } from "echarts/renderers";
45
45
  import { GridComponent, LegendComponent, TooltipComponent, VisualMapComponent } from "echarts/components";
46
46
  import numbro from "numbro";
@@ -216,7 +216,7 @@ function DescriptionPopover({
216
216
  React.useEffect(() => {
217
217
  freezeLayout(opened);
218
218
  }, [opened]);
219
- if (!description) {
219
+ if (!description || description === "<p><br></p>") {
220
220
  return null;
221
221
  }
222
222
  const target = trigger === "click" ? /* @__PURE__ */ jsx(Tooltip, {
@@ -451,7 +451,8 @@ function DataPreview({
451
451
  }, [definitions.dataSources, id]);
452
452
  const {
453
453
  data = [],
454
- loading
454
+ loading,
455
+ refresh
455
456
  } = useRequest(queryBySQL({
456
457
  context: contextInfo,
457
458
  definitions,
@@ -462,7 +463,8 @@ function DataPreview({
462
463
  });
463
464
  if (loading) {
464
465
  return /* @__PURE__ */ jsx(LoadingOverlay, {
465
- visible: loading
466
+ visible: loading,
467
+ exitTransitionDuration: 0
466
468
  });
467
469
  }
468
470
  if (data.length === 0) {
@@ -475,27 +477,47 @@ function DataPreview({
475
477
  sx: {
476
478
  border: "1px solid #eee"
477
479
  },
478
- children: [/* @__PURE__ */ jsx(Group, {
479
- position: "left",
480
+ children: [/* @__PURE__ */ jsxs(Group, {
481
+ position: "apart",
480
482
  py: "md",
481
483
  pl: "md",
482
484
  sx: {
483
485
  borderBottom: "1px solid #eee",
484
486
  background: "#efefef"
485
487
  },
486
- children: /* @__PURE__ */ jsx(Text, {
487
- weight: 500,
488
- children: "Preview Data"
489
- })
488
+ children: [/* @__PURE__ */ jsxs(Group, {
489
+ position: "left",
490
+ children: [/* @__PURE__ */ jsx(Text, {
491
+ weight: 500,
492
+ children: "Preview Data"
493
+ }), data.length > 10 && /* @__PURE__ */ jsxs(Text, {
494
+ size: "sm",
495
+ color: "gray",
496
+ children: ["Showing 10 rows of ", data.length]
497
+ })]
498
+ }), /* @__PURE__ */ jsx(ActionIcon, {
499
+ mr: 15,
500
+ variant: "hover",
501
+ color: "blue",
502
+ disabled: loading,
503
+ onClick: refresh,
504
+ children: /* @__PURE__ */ jsx(Refresh, {
505
+ size: 15
506
+ })
507
+ })]
490
508
  }), /* @__PURE__ */ jsxs(Table, {
491
509
  children: [/* @__PURE__ */ jsx("thead", {
492
510
  children: /* @__PURE__ */ jsx("tr", {
493
511
  children: Object.keys(data == null ? void 0 : data[0]).map((label) => /* @__PURE__ */ jsx("th", {
494
- children: label
512
+ children: /* @__PURE__ */ jsx(Text, {
513
+ weight: 700,
514
+ color: "#000",
515
+ children: label
516
+ })
495
517
  }, label))
496
518
  })
497
519
  }), /* @__PURE__ */ jsx("tbody", {
498
- children: data.map((row, index2) => /* @__PURE__ */ jsx("tr", {
520
+ children: data.slice(0, 10).map((row, index2) => /* @__PURE__ */ jsx("tr", {
499
521
  children: Object.values(row).map((v, i) => /* @__PURE__ */ jsx("td", {
500
522
  children: /* @__PURE__ */ jsx(Group, {
501
523
  sx: {
@@ -557,7 +579,7 @@ function PickDataSource({}) {
557
579
  });
558
580
  }
559
581
  echarts.use([SunburstChart, CanvasRenderer]);
560
- const defaultOption$1 = {
582
+ const defaultOption$2 = {
561
583
  tooltip: {
562
584
  show: true
563
585
  },
@@ -607,7 +629,7 @@ function Sunbrust({
607
629
  }
608
630
  }
609
631
  }), [max]);
610
- const option = _.merge({}, defaultOption$1, labelOption, restConf, {
632
+ const option = _.merge({}, defaultOption$2, labelOption, restConf, {
611
633
  series: {
612
634
  data: chartData
613
635
  }
@@ -622,22 +644,34 @@ function Sunbrust({
622
644
  });
623
645
  }
624
646
  echarts.use([BarChart, LineChart, GridComponent, LegendComponent, TooltipComponent, CanvasRenderer]);
625
- const defaultOption = {
647
+ const defaultOption$1 = {
626
648
  legend: {
627
- show: true
649
+ show: true,
650
+ bottom: 0,
651
+ left: 0
628
652
  },
629
653
  tooltip: {
630
654
  trigger: "axis"
631
655
  },
632
656
  xAxis: {
633
- type: "category"
657
+ type: "category",
658
+ nameGap: 25,
659
+ nameLocation: "center",
660
+ nameTextStyle: {
661
+ fontWeight: "bold"
662
+ }
663
+ },
664
+ yAxis: {
665
+ nameTextStyle: {
666
+ fontWeight: "bolder",
667
+ align: "left"
668
+ }
634
669
  },
635
- yAxis: {},
636
670
  grid: {
637
671
  top: 30,
638
- left: 10,
639
- right: 10,
640
- bottom: 10,
672
+ left: 15,
673
+ right: 15,
674
+ bottom: 30,
641
675
  containLabel: true
642
676
  }
643
677
  };
@@ -648,29 +682,86 @@ function VizLineBarChart({
648
682
  height
649
683
  }) {
650
684
  const option = React.useMemo(() => {
651
- const dataset = {
652
- dataset: {
653
- source: data
654
- }
655
- };
656
- const xAxisSource = {
657
- xAxis: {
658
- data: data.map((d) => d[conf.x_axis_data_key])
659
- }
660
- };
685
+ var _c, _d;
686
+ const valueFormatters = conf.series.reduce((ret, {
687
+ name,
688
+ y_axis_data_formatter
689
+ }) => {
690
+ ret[name] = function formatter({
691
+ value
692
+ }) {
693
+ if (!y_axis_data_formatter) {
694
+ return value;
695
+ }
696
+ try {
697
+ return numbro(value).format(JSON.parse(y_axis_data_formatter));
698
+ } catch (error) {
699
+ console.error(error);
700
+ return value;
701
+ }
702
+ };
703
+ return ret;
704
+ }, {});
661
705
  const series = conf.series.map((_a) => {
662
706
  var _b = _a, {
663
- y_axis_data_key
707
+ y_axis_data_key,
708
+ y_axis_data_formatter,
709
+ name,
710
+ label_position = "top"
664
711
  } = _b, rest = __objRest(_b, [
665
- "y_axis_data_key"
712
+ "y_axis_data_key",
713
+ "y_axis_data_formatter",
714
+ "name",
715
+ "label_position"
666
716
  ]);
667
- return __spreadValues({
668
- data: data.map((d) => d[y_axis_data_key])
717
+ const ret = __spreadValues({
718
+ data: data.map((d) => d[y_axis_data_key]),
719
+ label: {
720
+ show: true,
721
+ position: label_position
722
+ },
723
+ name
669
724
  }, rest);
725
+ if (y_axis_data_formatter) {
726
+ ret.label.formatter = valueFormatters[name];
727
+ }
728
+ return ret;
670
729
  });
671
- return _.assign({}, defaultOption, dataset, xAxisSource, {
672
- series
673
- });
730
+ const customOptions = {
731
+ xAxis: {
732
+ data: data.map((d) => d[conf.x_axis_data_key]),
733
+ name: (_c = conf.x_axis_name) != null ? _c : ""
734
+ },
735
+ yAxis: {
736
+ name: (_d = conf.y_axis_name) != null ? _d : ""
737
+ },
738
+ dataset: {
739
+ source: data
740
+ },
741
+ series,
742
+ tooltip: {
743
+ formatter: function(params) {
744
+ const arr = Array.isArray(params) ? params : [params];
745
+ if (arr.length === 0) {
746
+ return "";
747
+ }
748
+ const lines = arr.map(({
749
+ seriesName,
750
+ value
751
+ }) => {
752
+ if (!seriesName) {
753
+ return value;
754
+ }
755
+ return `${seriesName}: ${valueFormatters[seriesName]({
756
+ value
757
+ })}`;
758
+ });
759
+ lines.unshift(`<strong>${arr[0].name}</strong>`);
760
+ return lines.join("<br />");
761
+ }
762
+ }
763
+ };
764
+ return _.merge({}, defaultOption$1, customOptions);
674
765
  }, [conf, data]);
675
766
  if (!width || !height) {
676
767
  return null;
@@ -755,7 +846,7 @@ function CellValue({
755
846
  }
756
847
  function VizTable({
757
848
  conf,
758
- data,
849
+ data = [],
759
850
  width,
760
851
  height
761
852
  }) {
@@ -796,7 +887,7 @@ function VizTable({
796
887
  }, label))
797
888
  })
798
889
  }), /* @__PURE__ */ jsx("tbody", {
799
- children: data.map((row, index2) => /* @__PURE__ */ jsx("tr", {
890
+ children: data.slice(0, 30).map((row, index2) => /* @__PURE__ */ jsx("tr", {
800
891
  children: finalColumns.map(({
801
892
  value_field,
802
893
  value_type
@@ -804,7 +895,8 @@ function VizTable({
804
895
  children: /* @__PURE__ */ jsx(Group, {
805
896
  sx: {
806
897
  "&, .mantine-Text-root": {
807
- fontFamily: "monospace"
898
+ fontFamily: "monospace",
899
+ fontSize: rest.fontSize
808
900
  }
809
901
  },
810
902
  children: /* @__PURE__ */ jsx(CellValue, {
@@ -814,12 +906,26 @@ function VizTable({
814
906
  })
815
907
  }, row[value_field]))
816
908
  }, id_field ? row[id_field] : `row-${index2}`))
909
+ }), data.length > 100 && /* @__PURE__ */ jsx("tfoot", {
910
+ children: /* @__PURE__ */ jsx("tr", {
911
+ children: /* @__PURE__ */ jsx("td", {
912
+ colSpan: labels.length,
913
+ children: /* @__PURE__ */ jsx(Text, {
914
+ color: "red",
915
+ size: "sm",
916
+ children: "Showing only the first 30 rows to avoid causing slow performance"
917
+ })
918
+ })
919
+ })
817
920
  })]
818
921
  }));
819
922
  }
820
923
  function interpolateString(template, params = {}) {
821
- const names = Object.keys(params);
822
- const vals = Object.values(params);
924
+ const extendedParams = __spreadProps(__spreadValues({}, params), {
925
+ numbro
926
+ });
927
+ const names = Object.keys(extendedParams);
928
+ const vals = Object.values(extendedParams);
823
929
  try {
824
930
  return new Function(...names, `return \`${template}\`;`)(...vals);
825
931
  } catch (error) {
@@ -923,6 +1029,87 @@ function VizBar3D({
923
1029
  });
924
1030
  }
925
1031
  var index$2 = "";
1032
+ echarts.use([PieChart, CanvasRenderer]);
1033
+ const defaultOption = {
1034
+ tooltip: {
1035
+ show: true
1036
+ },
1037
+ series: {
1038
+ type: "pie",
1039
+ radius: ["50%", "80%"],
1040
+ label: {
1041
+ position: "outer",
1042
+ alignTo: "edge",
1043
+ formatter: "{name|{b}}\n{percentage|{d}%}",
1044
+ minMargin: 5,
1045
+ edgeDistance: 10,
1046
+ lineHeight: 15,
1047
+ rich: {
1048
+ percentage: {
1049
+ color: "#999"
1050
+ }
1051
+ },
1052
+ margin: 20
1053
+ },
1054
+ labelLine: {
1055
+ length: 15,
1056
+ length2: 0,
1057
+ maxSurfaceAngle: 80,
1058
+ showAbove: true
1059
+ },
1060
+ top: 10,
1061
+ bottom: 10,
1062
+ left: 10,
1063
+ right: 10
1064
+ }
1065
+ };
1066
+ function VizPie({
1067
+ conf,
1068
+ data,
1069
+ width,
1070
+ height
1071
+ }) {
1072
+ const _a = conf, {
1073
+ label_field = "name",
1074
+ value_field = "value"
1075
+ } = _a, restConf = __objRest(_a, [
1076
+ "label_field",
1077
+ "value_field"
1078
+ ]);
1079
+ const chartData = React.useMemo(() => {
1080
+ return data.map((d) => ({
1081
+ name: d[label_field],
1082
+ value: Number(d[value_field])
1083
+ }));
1084
+ }, [data, label_field, value_field]);
1085
+ const labelOptions = React.useMemo(() => {
1086
+ return {
1087
+ series: {
1088
+ labelLayout: function(params) {
1089
+ const isLeft = params.labelRect.x < width / 2;
1090
+ const points = params.labelLinePoints;
1091
+ points[2][0] = isLeft ? params.labelRect.x : params.labelRect.x + params.labelRect.width;
1092
+ return {
1093
+ labelLinePoints: points
1094
+ };
1095
+ }
1096
+ }
1097
+ };
1098
+ }, [width]);
1099
+ const option = _.merge({}, defaultOption, labelOptions, restConf, {
1100
+ series: {
1101
+ data: chartData
1102
+ }
1103
+ });
1104
+ return /* @__PURE__ */ jsx(ReactEChartsCore, {
1105
+ echarts,
1106
+ option,
1107
+ style: {
1108
+ width,
1109
+ height
1110
+ }
1111
+ });
1112
+ }
926
1113
  function renderViz(width, height, data, viz) {
927
1114
  const props = {
928
1115
  width,
@@ -941,6 +1128,8 @@ function renderViz(width, height, data, viz) {
941
1128
  return /* @__PURE__ */ jsx(VizText, __spreadValues({}, props));
942
1129
  case "bar-3d":
943
1130
  return /* @__PURE__ */ jsx(VizBar3D, __spreadValues({}, props));
1131
+ case "pie":
1132
+ return /* @__PURE__ */ jsx(VizPie, __spreadValues({}, props));
944
1133
  default:
945
1134
  return null;
946
1135
  }
@@ -961,7 +1150,8 @@ function Viz({
961
1150
  className: "viz-root",
962
1151
  ref,
963
1152
  children: /* @__PURE__ */ jsx(LoadingOverlay, {
964
- visible: loading
1153
+ visible: loading,
1154
+ exitTransitionDuration: 0
965
1155
  })
966
1156
  });
967
1157
  }
@@ -1205,6 +1395,74 @@ function MantineColorSelector({
1205
1395
  })]
1206
1396
  });
1207
1397
  }
1398
+ const numbroFormatExample = JSON.stringify({
1399
+ output: "percent",
1400
+ mantissa: 2
1401
+ }, null, 2);
1402
+ const labelPositions = [{
1403
+ label: "top",
1404
+ value: "top"
1405
+ }, {
1406
+ label: "left",
1407
+ value: "left"
1408
+ }, {
1409
+ label: "right",
1410
+ value: "right"
1411
+ }, {
1412
+ label: "bottom",
1413
+ value: "bottom"
1414
+ }, {
1415
+ label: "inside",
1416
+ value: "inside"
1417
+ }, {
1418
+ label: "insideLeft",
1419
+ value: "insideLeft"
1420
+ }, {
1421
+ label: "insideRight",
1422
+ value: "insideRight"
1423
+ }, {
1424
+ label: "insideTop",
1425
+ value: "insideTop"
1426
+ }, {
1427
+ label: "insideBottom",
1428
+ value: "insideBottom"
1429
+ }, {
1430
+ label: "insideTopLeft",
1431
+ value: "insideTopLeft"
1432
+ }, {
1433
+ label: "insideBottomLeft",
1434
+ value: "insideBottomLeft"
1435
+ }, {
1436
+ label: "insideTopRight",
1437
+ value: "insideTopRight"
1438
+ }, {
1439
+ label: "insideBottomRight",
1440
+ value: "insideBottomRight"
1441
+ }];
1442
+ function withDefaults(series) {
1443
+ function setDefaults({
1444
+ type,
1445
+ name,
1446
+ showSymbol,
1447
+ y_axis_data_key = "value",
1448
+ y_axis_data_formatter = "",
1449
+ label_position = "top",
1450
+ stack = "1",
1451
+ color = "black"
1452
+ }) {
1453
+ return {
1454
+ type,
1455
+ name,
1456
+ showSymbol,
1457
+ y_axis_data_key,
1458
+ y_axis_data_formatter,
1459
+ label_position,
1460
+ stack,
1461
+ color
1462
+ };
1463
+ }
1464
+ return series.map(setDefaults);
1465
+ }
1208
1466
  function VizLineBarChartPanel({
1209
1467
  conf,
1210
1468
  setConf
@@ -1214,9 +1472,20 @@ function VizLineBarChartPanel({
1214
1472
  } = _a, restConf = __objRest(_a, [
1215
1473
  "series"
1216
1474
  ]);
1217
- const initialValues = React.useMemo(() => __spreadValues({
1218
- series: formList(series != null ? series : [])
1219
- }, restConf), [series, restConf]);
1475
+ const initialValues = React.useMemo(() => {
1476
+ const _a2 = restConf, {
1477
+ x_axis_name = "",
1478
+ y_axis_name = ""
1479
+ } = _a2, rest = __objRest(_a2, [
1480
+ "x_axis_name",
1481
+ "y_axis_name"
1482
+ ]);
1483
+ return __spreadValues({
1484
+ series: formList(withDefaults(series != null ? series : [])),
1485
+ x_axis_name,
1486
+ y_axis_name
1487
+ }, rest);
1488
+ }, [series, restConf]);
1220
1489
  const form = useForm$1({
1221
1490
  initialValues
1222
1491
  });
@@ -1225,10 +1494,12 @@ function VizLineBarChartPanel({
1225
1494
  name: randomId(),
1226
1495
  showSymbol: false,
1227
1496
  y_axis_data_key: "value",
1497
+ y_axis_data_formatter: "",
1498
+ label_position: "top",
1228
1499
  stack: "",
1229
1500
  color: "#000"
1230
1501
  });
1231
- React.useMemo(() => !_.isEqual(form.values, initialValues), [form.values, initialValues]);
1502
+ const changed = React.useMemo(() => !_.isEqual(form.values, initialValues), [form.values, initialValues]);
1232
1503
  return /* @__PURE__ */ jsx(Group, {
1233
1504
  direction: "column",
1234
1505
  mt: "md",
@@ -1249,6 +1520,7 @@ function VizLineBarChartPanel({
1249
1520
  mr: 5,
1250
1521
  variant: "filled",
1251
1522
  color: "blue",
1523
+ disabled: !changed,
1252
1524
  children: /* @__PURE__ */ jsx(DeviceFloppy, {
1253
1525
  size: 20
1254
1526
  })
@@ -1258,6 +1530,18 @@ function VizLineBarChartPanel({
1258
1530
  mb: "lg",
1259
1531
  label: "X Axis Data Key"
1260
1532
  }, form.getInputProps("x_axis_data_key"))), /* @__PURE__ */ jsxs(Group, {
1533
+ direction: "column",
1534
+ grow: true,
1535
+ noWrap: true,
1536
+ mb: "lg",
1537
+ children: [/* @__PURE__ */ jsx(TextInput, __spreadValues({
1538
+ size: "md",
1539
+ label: "X Axis Name"
1540
+ }, form.getInputProps("x_axis_name"))), /* @__PURE__ */ jsx(TextInput, __spreadValues({
1541
+ size: "md",
1542
+ label: "Y Axis Name"
1543
+ }, form.getInputProps("y_axis_name")))]
1544
+ }), /* @__PURE__ */ jsxs(Group, {
1261
1545
  direction: "column",
1262
1546
  grow: true,
1263
1547
  children: [/* @__PURE__ */ jsx(Text, {
@@ -1274,23 +1558,52 @@ function VizLineBarChartPanel({
1274
1558
  border: "1px solid #eee",
1275
1559
  position: "relative"
1276
1560
  },
1277
- children: [/* @__PURE__ */ jsx(TextInput, __spreadValues({
1278
- label: "Label",
1279
- required: true,
1280
- sx: {
1281
- flex: 1
1282
- }
1283
- }, form.getListInputProps("series", index2, "name"))), /* @__PURE__ */ jsxs(Group, {
1561
+ children: [/* @__PURE__ */ jsxs(Group, {
1284
1562
  direction: "row",
1285
1563
  grow: true,
1286
1564
  noWrap: true,
1287
1565
  children: [/* @__PURE__ */ jsx(TextInput, __spreadValues({
1288
- label: "Y Axis Data key",
1289
- required: true
1290
- }, form.getListInputProps("series", index2, "y_axis_data_key"))), /* @__PURE__ */ jsx(TextInput, __spreadValues({
1291
- label: "Stack ID",
1566
+ label: "Name",
1567
+ required: true,
1568
+ sx: {
1569
+ flex: 1
1570
+ }
1571
+ }, form.getListInputProps("series", index2, "name"))), /* @__PURE__ */ jsx(TextInput, __spreadValues({
1572
+ label: "Stack",
1292
1573
  placeholder: "Stack bars by this ID"
1293
- }, form.getListInputProps("series", index2, "stack")))]
1574
+ }, form.getListInputProps("series", index2, "stack"))), /* @__PURE__ */ jsx(TextInput, __spreadValues({
1575
+ label: "Value key",
1576
+ required: true
1577
+ }, form.getListInputProps("series", index2, "y_axis_data_key")))]
1578
+ }), /* @__PURE__ */ jsxs(Group, {
1579
+ direction: "row",
1580
+ grow: true,
1581
+ noWrap: true,
1582
+ align: "top",
1583
+ children: [/* @__PURE__ */ jsx(Select, __spreadValues({
1584
+ label: "Label Position",
1585
+ data: labelPositions
1586
+ }, form.getListInputProps("series", index2, "label_position"))), /* @__PURE__ */ jsx(JsonInput, __spreadValues({
1587
+ sx: {
1588
+ label: {
1589
+ width: "100%"
1590
+ }
1591
+ },
1592
+ label: /* @__PURE__ */ jsxs(Group, {
1593
+ position: "apart",
1594
+ children: [/* @__PURE__ */ jsx(Text, {
1595
+ children: "Value Formatter"
1596
+ }), /* @__PURE__ */ jsx(Anchor, {
1597
+ href: "https://numbrojs.com/format.html",
1598
+ target: "_blank",
1599
+ children: "Formats"
1600
+ })]
1601
+ }),
1602
+ placeholder: numbroFormatExample,
1603
+ minRows: 4,
1604
+ maxRows: 12,
1605
+ autosize: true
1606
+ }, form.getListInputProps("series", index2, "y_axis_data_formatter")))]
1294
1607
  }), /* @__PURE__ */ jsxs(Group, {
1295
1608
  direction: "column",
1296
1609
  grow: true,
@@ -1322,6 +1635,72 @@ function VizLineBarChartPanel({
1322
1635
  })
1323
1636
  });
1324
1637
  }
1638
+ function VizPiePanel({
1639
+ conf: {
1640
+ label_field,
1641
+ value_field
1642
+ },
1643
+ setConf
1644
+ }) {
1645
+ const form = useForm$1({
1646
+ initialValues: {
1647
+ label_field,
1648
+ value_field
1649
+ }
1650
+ });
1651
+ return /* @__PURE__ */ jsx(Group, {
1652
+ direction: "column",
1653
+ mt: "md",
1654
+ spacing: "xs",
1655
+ grow: true,
1656
+ children: /* @__PURE__ */ jsxs("form", {
1657
+ onSubmit: form.onSubmit(setConf),
1658
+ children: [/* @__PURE__ */ jsxs(Group, {
1659
+ position: "apart",
1660
+ mb: "lg",
1661
+ sx: {
1662
+ position: "relative"
1663
+ },
1664
+ children: [/* @__PURE__ */ jsx(Text, {
1665
+ children: "Pie Config"
1666
+ }), /* @__PURE__ */ jsx(ActionIcon, {
1667
+ type: "submit",
1668
+ mr: 5,
1669
+ variant: "filled",
1670
+ color: "blue",
1671
+ children: /* @__PURE__ */ jsx(DeviceFloppy, {
1672
+ size: 20
1673
+ })
1674
+ })]
1675
+ }), /* @__PURE__ */ jsxs(Group, {
1676
+ direction: "column",
1677
+ mt: "md",
1678
+ spacing: "xs",
1679
+ grow: true,
1680
+ p: "md",
1681
+ mb: "sm",
1682
+ sx: {
1683
+ border: "1px solid #eee",
1684
+ borderRadius: "5px"
1685
+ },
1686
+ children: [/* @__PURE__ */ jsx(TextInput, __spreadValues({
1687
+ label: "Label Field",
1688
+ required: true,
1689
+ sx: {
1690
+ flex: 1
1691
+ }
1692
+ }, form.getInputProps("label_field"))), /* @__PURE__ */ jsx(TextInput, __spreadValues({
1693
+ label: "Value Field",
1694
+ placeholder: "get column value by this field",
1695
+ required: true,
1696
+ sx: {
1697
+ flex: 1
1698
+ }
1699
+ }, form.getInputProps("value_field")))]
1700
+ })]
1701
+ })
1702
+ });
1703
+ }
1325
1704
  function SunburstPanel({
1326
1705
  conf: {
1327
1706
  label_field,
@@ -1421,7 +1800,7 @@ function VizTablePanel(_a) {
1421
1800
  id_field: "id",
1422
1801
  use_raw_columns: true,
1423
1802
  columns: formList(columns != null ? columns : []),
1424
- size: "sm",
1803
+ fontSize: "sm",
1425
1804
  horizontalSpacing: "sm",
1426
1805
  verticalSpacing: "sm",
1427
1806
  striped: false,
@@ -1512,7 +1891,7 @@ function VizTablePanel(_a) {
1512
1891
  sx: {
1513
1892
  flex: 1
1514
1893
  }
1515
- }, form.getInputProps("size")))
1894
+ }, form.getInputProps("fontSize")))
1516
1895
  }), /* @__PURE__ */ jsxs(Group, {
1517
1896
  direction: "column",
1518
1897
  grow: true,
@@ -1828,6 +2207,10 @@ const types = [{
1828
2207
  value: "line-bar",
1829
2208
  label: "Line-Bar Chart",
1830
2209
  Panel: VizLineBarChartPanel
2210
+ }, {
2211
+ value: "pie",
2212
+ label: "Pie Chart",
2213
+ Panel: VizPiePanel
1831
2214
  }];
1832
2215
  function EditVizConf() {
1833
2216
  const {
@@ -1957,7 +2340,8 @@ function PanelSettingsModal({
1957
2340
  children: [/* @__PURE__ */ jsxs(Tabs.Tab, {
1958
2341
  label: "Data Source",
1959
2342
  children: [/* @__PURE__ */ jsx(LoadingOverlay, {
1960
- visible: loading
2343
+ visible: loading,
2344
+ exitTransitionDuration: 0
1961
2345
  }), /* @__PURE__ */ jsx(PickDataSource, {})]
1962
2346
  }), /* @__PURE__ */ jsx(Tabs.Tab, {
1963
2347
  label: "Panel",
@@ -2418,7 +2802,7 @@ function DataSourceEditor({
2418
2802
  }, [dataSources, id]);
2419
2803
  const update = React.useCallback((value) => {
2420
2804
  const index2 = dataSources.findIndex((d) => d.id === id);
2421
- if (!index2) {
2805
+ if (index2 === -1) {
2422
2806
  console.error(new Error("Invalid data source id when updating by id"));
2423
2807
  return;
2424
2808
  }
@@ -2427,7 +2811,10 @@ function DataSourceEditor({
2427
2811
  prevs.splice(index22, 1, value);
2428
2812
  return [...prevs];
2429
2813
  });
2430
- }, [id, setDataSources]);
2814
+ }, [id, dataSources, setDataSources]);
2815
+ if (!id) {
2816
+ return null;
2817
+ }
2431
2818
  if (!dataSource) {
2432
2819
  return /* @__PURE__ */ jsx("span", {
2433
2820
  children: "Invalid Data Source ID"
@@ -1,4 +1,4 @@
1
- (function(f,v){typeof exports=="object"&&typeof module!="undefined"?v(exports,require("react"),require("lodash"),require("react-grid-layout"),require("@mantine/core"),require("ahooks"),require("axios"),require("tabler-icons-react"),require("@mantine/rte"),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("react-hook-form"),require("@mantine/form"),require("@mantine/prism")):typeof define=="function"&&define.amd?define(["exports","react","lodash","react-grid-layout","@mantine/core","ahooks","axios","tabler-icons-react","@mantine/rte","@mantine/hooks","echarts-for-react/lib/core","echarts/core","echarts/charts","echarts/renderers","echarts/components","numbro","echarts-gl","react-hook-form","@mantine/form","@mantine/prism"],v):(f=typeof globalThis!="undefined"?globalThis:f||self,v(f.dashboard={},f.React,f._,f["react-grid-layout"],f["@mantine/core"],f.ahooks,f.axios,f["tabler-icons-react"],f["@mantine/rte"],f["@mantine/hooks"],f["echarts-for-react/lib/core"],f["echarts/core"],f["echarts/charts"],f["echarts/renderers"],f["echarts/components"],f.numbro,f["echarts-gl"],f["react-hook-form"],f["@mantine/form"],f["@mantine/prism"]))})(this,function(f,v,C,D,t,ee,_e,y,de,O,ze,Ie,te,ne,N,Pe,Qt,V,I,M){"use strict";var Vt=Object.defineProperty,Rt=Object.defineProperties;var Wt=Object.getOwnPropertyDescriptors;var Z=Object.getOwnPropertySymbols;var De=Object.prototype.hasOwnProperty,Ge=Object.prototype.propertyIsEnumerable;var Te=(f,v,C)=>v in f?Vt(f,v,{enumerable:!0,configurable:!0,writable:!0,value:C}):f[v]=C,h=(f,v)=>{for(var C in v||(v={}))De.call(v,C)&&Te(f,C,v[C]);if(Z)for(var C of Z(v))Ge.call(v,C)&&Te(f,C,v[C]);return f},E=(f,v)=>Rt(f,Wt(v));var z=(f,v)=>{var C={};for(var D in f)De.call(f,D)&&v.indexOf(D)<0&&(C[D]=f[D]);if(f!=null&&Z)for(var D of Z(f))v.indexOf(D)<0&&Ge.call(f,D)&&(C[D]=f[D]);return C};function W(n){return n&&typeof n=="object"&&"default"in n?n:{default:n}}function Le(n){if(n&&n.__esModule)return n;var r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});return n&&Object.keys(n).forEach(function(i){if(i!=="default"){var o=Object.getOwnPropertyDescriptor(n,i);Object.defineProperty(r,i,o.get?o:{enumerable:!0,get:function(){return n[i]}})}}),r.default=n,Object.freeze(r)}var u=W(v),w=W(C),ke=W(_e),Ee=W(de),re=W(ze),Q=Le(Ie),ce=W(Pe),q=(n=>(n.Use="use",n.Edit="edit",n))(q||{});const Oe={layoutFrozen:!1,freezeLayout:()=>{},mode:q.Edit,inEditMode:!1},B=u.default.createContext(Oe),pe=n=>(r,i,o={})=>{const a=h({"X-Requested-With":"XMLHttpRequest","Content-Type":o.string?"application/x-www-form-urlencoded":"application/json"},o.headers),s={baseURL:"http://localhost:31200",method:n,url:r,params:n==="GET"?i:o.params,headers:a};return n==="POST"&&(s.data=o.string?JSON.stringify(i):i),ke.default(s).then(l=>l.data).catch(l=>Promise.reject(l))},qe=pe("GET"),Ae=pe("POST");function he(n,r){const i=Object.keys(r),o=Object.values(r);try{return new Function(...i,`return \`${n}\`;`)(...o)}catch(a){throw i.length===0&&n.includes("$")?new Error("[formatSQL] insufficient params"):a}}function Me(n,r){const i=r.sqlSnippets.reduce((o,a)=>(o[a.key]=he(a.value,n),o),{});return w.default.merge({},i,n)}const fe=({context:n,definitions:r,title:i,dataSource:o})=>async()=>{if(!o||!o.sql)return[];const{type:a,key:s,sql:l}=o,d=l.includes("$");try{const m=Me(n,r),p=he(l,m);return d&&(console.groupCollapsed(`Final SQL for: ${i}`),console.log(p),console.groupEnd()),await Ae("/query",{type:a,key:s,sql:p})}catch(m){return console.error(m),[]}};async function Be(){try{return await qe("/query/sources",{})}catch(n){return console.error(n),{}}}const me={},Fe=me,R=u.default.createContext(me),$e={data:[],loading:!1,title:"",setTitle:()=>{},description:"",setDescription:()=>{},dataSourceID:"",setDataSourceID:()=>{},viz:{type:"",conf:{}},setViz:()=>{},refreshData:()=>{}},_=u.default.createContext($e),je={sqlSnippets:[],setSQLSnippets:()=>{},dataSources:[],setDataSources:()=>{}},P=u.default.createContext(je);var U={exports:{}},K={};/**
1
+ (function(x,w){typeof exports=="object"&&typeof module!="undefined"?w(exports,require("react"),require("lodash"),require("react-grid-layout"),require("@mantine/core"),require("ahooks"),require("axios"),require("tabler-icons-react"),require("@mantine/rte"),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("react-hook-form"),require("@mantine/form"),require("@mantine/prism")):typeof define=="function"&&define.amd?define(["exports","react","lodash","react-grid-layout","@mantine/core","ahooks","axios","tabler-icons-react","@mantine/rte","@mantine/hooks","echarts-for-react/lib/core","echarts/core","echarts/charts","echarts/renderers","echarts/components","numbro","echarts-gl","react-hook-form","@mantine/form","@mantine/prism"],w):(x=typeof globalThis!="undefined"?globalThis:x||self,w(x.dashboard={},x.React,x._,x["react-grid-layout"],x["@mantine/core"],x.ahooks,x.axios,x["tabler-icons-react"],x["@mantine/rte"],x["@mantine/hooks"],x["echarts-for-react/lib/core"],x["echarts/core"],x["echarts/charts"],x["echarts/renderers"],x["echarts/components"],x.numbro,x["echarts-gl"],x["react-hook-form"],x["@mantine/form"],x["@mantine/prism"]))})(this,function(x,w,C,D,t,re,Ge,v,ce,A,Pe,ze,U,H,N,Ie,Xt,j,I,B){"use strict";var Ht=Object.defineProperty,Kt=Object.defineProperties;var Yt=Object.getOwnPropertyDescriptors;var ie=Object.getOwnPropertySymbols;var _e=Object.prototype.hasOwnProperty,De=Object.prototype.propertyIsEnumerable;var Te=(x,w,C)=>w in x?Ht(x,w,{enumerable:!0,configurable:!0,writable:!0,value:C}):x[w]=C,h=(x,w)=>{for(var C in w||(w={}))_e.call(w,C)&&Te(x,C,w[C]);if(ie)for(var C of ie(w))De.call(w,C)&&Te(x,C,w[C]);return x},E=(x,w)=>Kt(x,Yt(w));var P=(x,w)=>{var C={};for(var D in x)_e.call(x,D)&&w.indexOf(D)<0&&(C[D]=x[D]);if(x!=null&&ie)for(var D of ie(x))w.indexOf(D)<0&&De.call(x,D)&&(C[D]=x[D]);return C};function Q(n){return n&&typeof n=="object"&&"default"in n?n:{default:n}}function Le(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 o=Object.getOwnPropertyDescriptor(n,r);Object.defineProperty(i,r,o.get?o:{enumerable:!0,get:function(){return n[r]}})}}),i.default=n,Object.freeze(i)}var u=Q(w),T=Q(C),ke=Q(Ge),Ee=Q(ce),K=Q(Pe),F=Le(ze),Y=Q(Ie),q=(n=>(n.Use="use",n.Edit="edit",n))(q||{});const Oe={layoutFrozen:!1,freezeLayout:()=>{},mode:q.Edit,inEditMode:!1},R=u.default.createContext(Oe),pe=n=>(i,r,o={})=>{const a=h({"X-Requested-With":"XMLHttpRequest","Content-Type":o.string?"application/x-www-form-urlencoded":"application/json"},o.headers),l={baseURL:"http://localhost:31200",method:n,url:i,params:n==="GET"?r:o.params,headers:a};return n==="POST"&&(l.data=o.string?JSON.stringify(r):r),ke.default(l).then(s=>s.data).catch(s=>Promise.reject(s))},Ae=pe("GET"),qe=pe("POST");function he(n,i){const r=Object.keys(i),o=Object.values(i);try{return new Function(...r,`return \`${n}\`;`)(...o)}catch(a){throw r.length===0&&n.includes("$")?new Error("[formatSQL] insufficient params"):a}}function Me(n,i){const r=i.sqlSnippets.reduce((o,a)=>(o[a.key]=he(a.value,n),o),{});return T.default.merge({},r,n)}const me=({context:n,definitions:i,title:r,dataSource:o})=>async()=>{if(!o||!o.sql)return[];const{type:a,key:l,sql:s}=o,d=s.includes("$");try{const f=Me(n,i),m=he(s,f);return d&&(console.groupCollapsed(`Final SQL for: ${r}`),console.log(m),console.groupEnd()),await qe("/query",{type:a,key:l,sql:m})}catch(f){return console.error(f),[]}};async function Be(){try{return await Ae("/query/sources",{})}catch(n){return console.error(n),{}}}const fe={},Fe=fe,W=u.default.createContext(fe),Re={data:[],loading:!1,title:"",setTitle:()=>{},description:"",setDescription:()=>{},dataSourceID:"",setDataSourceID:()=>{},viz:{type:"",conf:{}},setViz:()=>{},refreshData:()=>{}},L=u.default.createContext(Re),$e={sqlSnippets:[],setSQLSnippets:()=>{},dataSources:[],setDataSources:()=>{}},O=u.default.createContext($e);var X={exports:{}},Z={};/**
2
2
  * @license React
3
3
  * react-jsx-runtime.production.min.js
4
4
  *
@@ -6,7 +6,8 @@
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 Ne=u.default,Ve=Symbol.for("react.element"),Re=Symbol.for("react.fragment"),We=Object.prototype.hasOwnProperty,Qe=Ne.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Je={key:!0,ref:!0,__self:!0,__source:!0};function xe(n,r,i){var o,a={},s=null,l=null;i!==void 0&&(s=""+i),r.key!==void 0&&(s=""+r.key),r.ref!==void 0&&(l=r.ref);for(o in r)We.call(r,o)&&!Je.hasOwnProperty(o)&&(a[o]=r[o]);if(n&&n.defaultProps)for(o in r=n.defaultProps,r)a[o]===void 0&&(a[o]=r[o]);return{$$typeof:Ve,type:n,key:s,ref:l,props:a,_owner:Qe.current}}K.Fragment=Re,K.jsx=xe,K.jsxs=xe,U.exports=K;const e=U.exports.jsx,c=U.exports.jsxs,ie=U.exports.Fragment;function ge({position:n,trigger:r="click"}){const{freezeLayout:i}=u.default.useContext(B),[o,a]=u.default.useState(!1),{description:s}=u.default.useContext(_);if(u.default.useEffect(()=>{i(o)},[o]),!s)return null;const l=r==="click"?e(t.Tooltip,{label:"Click to see description",openDelay:500,children:e(y.InfoCircle,{size:20,onClick:()=>a(d=>!d),style:{verticalAlign:"baseline",cursor:"pointer"}})}):e(y.InfoCircle,{size:20,onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),style:{verticalAlign:"baseline",cursor:"pointer"}});return e(t.Popover,{opened:o,onClose:()=>a(!1),withCloseButton:!0,withArrow:!0,trapFocus:!0,closeOnEscape:!1,placement:"center",position:n,target:l,children:e(Ee.default,{readOnly:!0,value:s,onChange:w.default.noop,sx:{border:"none"}})})}function Ue(){const{description:n,setDescription:r}=u.default.useContext(_),[i,o]=u.default.useState(n),a=n!==i,s=u.default.useCallback(()=>{!a||r(i)},[a,i]);return c(t.Group,{direction:"column",sx:{flexGrow:1},children:[c(t.Group,{align:"end",children:[e(t.Text,{children:"Description"}),e(t.ActionIcon,{variant:"hover",color:"blue",disabled:!a,onClick:s,children:e(y.DeviceFloppy,{size:20})})]}),e(de.RichTextEditor,{value:i,onChange:o,sx:{flexGrow:1},sticky:!0,p:"0"})]})}class oe extends u.default.Component{constructor(r){super(r),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}render(){return this.state.hasError?e("h1",{children:"Something went wrong."}):this.props.children}}function Ke(){const{title:n}=u.default.useContext(_);return e(oe,{children:c(t.Group,{direction:"column",grow:!0,noWrap:!0,mx:"auto",mt:"xl",p:"5px",spacing:"xs",sx:{width:"600px",height:"450px",background:"transparent",borderRadius:"5px",boxShadow:"0px 0px 10px 0px rgba(0,0,0,.2)"},children:[c(t.Group,{position:"apart",noWrap:!0,sx:{borderBottom:"1px solid #eee",paddingBottom:"5px",flexGrow:0,flexShrink:0},children:[e(t.Group,{children:e(ge,{position:"bottom",trigger:"hover"})}),e(t.Group,{grow:!0,position:"center",children:e(t.Text,{lineClamp:1,weight:"bold",children:n})}),e(t.Group,{position:"right",spacing:0,sx:{height:"28px"}})]}),e(t.Group,{sx:{background:"#eee",flexGrow:1}})]})})}function Ye(){const{title:n,setTitle:r}=u.default.useContext(_),[i,o]=O.useInputState(n),a=n!==i,s=u.default.useCallback(()=>{!a||r(i)},[a,i]);return e(t.TextInput,{value:i,onChange:o,label:c(t.Group,{align:"end",children:[e(t.Text,{children:"Panel Title"}),e(t.ActionIcon,{variant:"hover",color:"blue",disabled:!a,onClick:s,children:e(y.DeviceFloppy,{size:20})})]})})}function He({}){return c(t.Group,{direction:"row",grow:!0,noWrap:!0,align:"stretch",sx:{height:"100%"},children:[c(t.Group,{grow:!0,direction:"column",sx:{width:"40%",flexShrink:0,flexGrow:0,height:"100%"},children:[e(Ye,{}),e(Ue,{})]}),e(t.Box,{sx:{height:"100%",flexGrow:1,maxWidth:"60%"},children:e(Ke,{})})]})}function be({id:n}){const r=u.default.useContext(P),i=u.default.useContext(R),o=u.default.useMemo(()=>r.dataSources.find(l=>l.id===n),[r.dataSources,n]),{data:a=[],loading:s}=ee.useRequest(fe({context:i,definitions:r,title:n,dataSource:o}),{refreshDeps:[i,r,o]});return s?e(t.LoadingOverlay,{visible:s}):a.length===0?e(t.Table,{}):c(t.Group,{my:"xl",direction:"column",grow:!0,sx:{border:"1px solid #eee"},children:[e(t.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:e(t.Text,{weight:500,children:"Preview Data"})}),c(t.Table,{children:[e("thead",{children:e("tr",{children:Object.keys(a==null?void 0:a[0]).map(l=>e("th",{children:l},l))})}),e("tbody",{children:a.map((l,d)=>e("tr",{children:Object.values(l).map((m,p)=>e("td",{children:e(t.Group,{sx:{"&, .mantine-Text-root":{fontFamily:"monospace"}},children:e(t.Text,{children:m})})},`${m}--${p}`))},`row-${d}`))})]})]})}function Xe({}){const{dataSources:n}=u.default.useContext(P),{dataSourceID:r,setDataSourceID:i,data:o,loading:a}=u.default.useContext(_),s=u.default.useMemo(()=>n.map(l=>({value:l.id,label:l.id})),[n]);return c(t.Group,{direction:"column",grow:!0,noWrap:!0,children:[c(t.Group,{position:"left",sx:{maxWidth:"600px",alignItems:"baseline"},children:[e(t.Text,{children:"Select a Data Source"}),e(t.Select,{data:s,value:r,onChange:i,allowDeselect:!1,clearable:!1,sx:{flexGrow:1}})]}),e(be,{id:r})]})}Q.use([te.SunburstChart,ne.CanvasRenderer]);const Ze={tooltip:{show:!0},series:{type:"sunburst",radius:[0,"90%"],emphasis:{focus:"ancestor"}}};function et({conf:n,data:r,width:i,height:o}){const b=n,{label_field:a="name",value_field:s="value"}=b,l=z(b,["label_field","value_field"]),d=u.default.useMemo(()=>r.map(x=>({name:x[a],value:Number(x[s])})),[r,a,s]),m=u.default.useMemo(()=>{var x,S;return(S=(x=w.default.maxBy(d,T=>T.value))==null?void 0:x.value)!=null?S:1},[d]),p=u.default.useMemo(()=>({series:{label:{formatter:({name:x,value:S})=>S/m<.2?" ":x}}}),[m]),g=w.default.merge({},Ze,p,l,{series:{data:d}});return e(re.default,{echarts:Q,option:g,style:{width:i,height:o}})}Q.use([te.BarChart,te.LineChart,N.GridComponent,N.LegendComponent,N.TooltipComponent,ne.CanvasRenderer]);const tt={legend:{show:!0},tooltip:{trigger:"axis"},xAxis:{type:"category"},yAxis:{},grid:{top:30,left:10,right:10,bottom:10,containLabel:!0}};function nt({conf:n,data:r,width:i,height:o}){const a=u.default.useMemo(()=>{const s={dataset:{source:r}},l={xAxis:{data:r.map(m=>m[n.x_axis_data_key])}},d=n.series.map(g=>{var b=g,{y_axis_data_key:m}=b,p=z(b,["y_axis_data_key"]);return h({data:r.map(x=>x[m])},p)});return w.default.assign({},tt,s,l,{series:d})},[n,r]);return!i||!o?null:e(re.default,{echarts:Q,option:a,style:{width:i,height:o}})}var F=(n=>(n.string="string",n.number="number",n.eloc="eloc",n.percentage="percentage",n))(F||{});function rt({value:n}){return e(t.Text,{component:"span",children:n})}function it({value:n}){return e(t.Text,{component:"span",children:n})}function ot({value:n}){const r=ce.default(n).format({thousandSeparated:!0});return e(t.Text,{component:"span",children:r})}function at({value:n}){const r=ce.default(n).format({output:"percent",mantissa:3});return e(t.Text,{component:"span",children:r})}function lt({value:n,type:r}){switch(r){case F.string:return e(rt,{value:n});case F.eloc:return e(it,{value:n});case F.number:return e(ot,{value:n});case F.percentage:return e(at,{value:n})}}function st({conf:n,data:r,width:i,height:o}){const g=n,{id_field:a,use_raw_columns:s,columns:l}=g,d=z(g,["id_field","use_raw_columns","columns"]),m=u.default.useMemo(()=>s?Object.keys(r==null?void 0:r[0]):l.map(b=>b.label),[s,l,r]),p=u.default.useMemo(()=>s?Object.keys(r==null?void 0:r[0]).map(b=>({label:b,value_field:b,value_type:F.string})):l,[s,l,r]);return c(t.Table,E(h({sx:{maxHeight:o}},d),{children:[e("thead",{children:e("tr",{children:m.map(b=>e("th",{children:b},b))})}),e("tbody",{children:r.map((b,x)=>e("tr",{children:p.map(({value_field:S,value_type:T})=>e("td",{children:e(t.Group,{sx:{"&, .mantine-Text-root":{fontFamily:"monospace"}},children:e(lt,{value:b[S],type:T})})},b[S]))},a?b[a]:`row-${x}`))})]}))}function ut(n,r={}){const i=Object.keys(r),o=Object.values(r);try{return new Function(...i,`return \`${n}\`;`)(...o)}catch(a){return a.message}}function dt({conf:{paragraphs:n},data:r}){return e(ie,{children:n.map((l,s)=>{var d=l,{template:i,size:o}=d,a=z(d,["template","size"]);return e(t.Text,E(h({},a),{sx:{fontSize:o},children:ut(i,r[0])}),`${i}---${s}`)})})}Q.use([N.GridComponent,N.VisualMapComponent,N.LegendComponent,N.TooltipComponent,ne.CanvasRenderer]);function ct({conf:n,data:r,width:i,height:o}){const b=n,{x_axis_data_key:a,y_axis_data_key:s,z_axis_data_key:l}=b,d=z(b,["x_axis_data_key","y_axis_data_key","z_axis_data_key"]),m=u.default.useMemo(()=>w.default.minBy(r,x=>x[l])[l],[r,l]),p=u.default.useMemo(()=>w.default.maxBy(r,x=>x[l])[l],[r,l]),g=E(h({tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:m,max:p,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:r.map(x=>[x[a],x[s],x[l]])}]});return e(re.default,{echarts:Q,option:g,style:{width:i,height:o}})}var Jt="";function pt(n,r,i,o){const a={width:n,height:r,data:i,conf:o.conf};switch(o.type){case"sunburst":return e(et,h({},a));case"line-bar":return e(nt,h({},a));case"table":return e(st,h({},a));case"text":return e(dt,h({},a));case"bar-3d":return e(ct,h({},a));default:return null}}function Se({viz:n,data:r,loading:i}){const{ref:o,width:a,height:s}=O.useElementSize(),l=u.default.useMemo(()=>!Array.isArray(r)||r.length===0,[r]);return i?e("div",{className:"viz-root",ref:o,children:e(t.LoadingOverlay,{visible:i})}):c("div",{className:"viz-root",ref:o,children:[l&&e(t.Text,{color:"gray",align:"center",children:"nothing to show"}),!l&&pt(a,s,r,n)]})}function ht({}){const{data:n,loading:r,viz:i}=u.default.useContext(_);return e(oe,{children:e(Se,{viz:i,data:n,loading:r})})}function ft({conf:n,setConf:r}){const i=w.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:o,handleSubmit:a,formState:s}=V.useForm({defaultValues:i});return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:a(r),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(V.Controller,{name:"x_axis_data_key",control:o,render:({field:l})=>e(t.TextInput,h({sx:{flexGrow:1},size:"md",label:"Data Key"},l))}),e(V.Controller,{name:"xAxis3D.name",control:o,render:({field:l})=>e(t.TextInput,h({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(V.Controller,{name:"y_axis_data_key",control:o,render:({field:l})=>e(t.TextInput,h({sx:{flexGrow:1},size:"md",label:"Data Key"},l))}),e(V.Controller,{name:"yAxis3D.name",control:o,render:({field:l})=>e(t.TextInput,h({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(V.Controller,{name:"z_axis_data_key",control:o,render:({field:l})=>e(t.TextInput,h({sx:{flexGrow:1},size:"md",label:"Data Key"},l))}),e(V.Controller,{name:"zAxis3D.name",control:o,render:({field:l})=>e(t.TextInput,h({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 ye({value:n,onChange:r}){const i=t.useMantineTheme(),o=u.default.useMemo(()=>Object.entries(i.colors).map(([s,l])=>({label:s,value:l[6]})),[i]),a=u.default.useMemo(()=>o.some(s=>s.value===n),[n,o]);return c(t.Group,{position:"apart",spacing:"xs",children:[e(t.TextInput,{placeholder:"Set any color",value:a?"":n,onChange:s=>r(s.currentTarget.value),rightSection:e(t.ColorSwatch,{color:a?"transparent":n,radius:4}),variant:a?"filled":"default",sx:{maxWidth:"100%",flexGrow:1}}),e(t.Text,{sx:{flexGrow:0},children:"or"}),e(t.Select,{data:o,value:n,onChange:r,variant:a?"default":"filled",placeholder:"Pick a theme color",icon:e(t.ColorSwatch,{color:a?n:"transparent",radius:4}),sx:{maxWidth:"100%",flexGrow:1}})]})}function mt({conf:n,setConf:r}){const d=n,{series:i}=d,o=z(d,["series"]),a=u.default.useMemo(()=>h({series:I.formList(i!=null?i:[])},o),[i,o]),s=I.useForm({initialValues:a}),l=()=>s.addListItem("series",{type:"bar",name:O.randomId(),showSymbol:!1,y_axis_data_key:"value",stack:"",color:"#000"});return u.default.useMemo(()=>!w.default.isEqual(s.values,a),[s.values,a]),e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:s.onSubmit(r),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,h({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((m,p)=>c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[e(t.TextInput,h({label:"Label",required:!0,sx:{flex:1}},s.getListInputProps("series",p,"name"))),c(t.Group,{direction:"row",grow:!0,noWrap:!0,children:[e(t.TextInput,h({label:"Y Axis Data key",required:!0},s.getListInputProps("series",p,"y_axis_data_key"))),e(t.TextInput,h({label:"Stack ID",placeholder:"Stack bars by this ID"},s.getListInputProps("series",p,"stack")))]}),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{children:"Color"}),e(ye,h({},s.getListInputProps("series",p,"color")))]}),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>s.removeListItem("series",p),sx:{position:"absolute",top:15,right:5},children:e(y.Trash,{size:16})})]},p)),e(t.Group,{position:"center",mt:"xs",children:e(t.Button,{onClick:l,children:"Add a Series"})})]})]})})}function xt({conf:{label_field:n,value_field:r},setConf:i}){const o=I.useForm({initialValues:{label_field:n,value_field:r}});return 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:"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,h({label:"Label Field",required:!0,sx:{flex:1}},o.getInputProps("label_field"))),e(t.TextInput,h({label:"Value Field",placeholder:"get column value by this field",required:!0,sx:{flex:1}},o.getInputProps("value_field")))]})]})})}const gt=Object.values(F).map(n=>({label:n,value:n}));function bt({label:n,value:r,onChange:i,sx:o}){return e(t.Select,{label:n,data:gt,value:r,onChange:i,sx:o})}function St(o){var a=o,{conf:s}=a,l=s,{columns:n}=l,r=z(l,["columns"]),{setConf:i}=a;const d=I.useForm({initialValues:h({id_field:"id",use_raw_columns:!0,columns:I.formList(n!=null?n:[]),size:"sm",horizontalSpacing:"sm",verticalSpacing:"sm",striped:!1,highlightOnHover:!1},r)}),m=()=>d.addListItem("columns",{label:O.randomId(),value_field:"value",value_type:F.string});return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:d.onSubmit(i),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,h({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(t.TextInput,h({label:"Horizontal Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1}},d.getInputProps("horizontalSpacing"))),e(t.TextInput,h({label:"Vertical Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1}},d.getInputProps("verticalSpacing")))]}),e(t.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:e(t.TextInput,h({label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1}},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,h({label:"Striped"},d.getInputProps("striped",{type:"checkbox"}))),e(t.Switch,h({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,h({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((p,g)=>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,h({label:"Label",required:!0,sx:{flex:1}},d.getListInputProps("columns",g,"label"))),e(t.TextInput,h({label:"Value Field",placeholder:"get column value by this field",required:!0,sx:{flex:1}},d.getListInputProps("columns",g,"value_field"))),e(bt,h({label:"Value Type",sx:{flex:1}},d.getListInputProps("columns",g,"value_type")))]}),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>d.removeListItem("columns",g),sx:{position:"absolute",top:15,right:5},children:e(y.Trash,{size:16})})]},g)),e(t.Group,{position:"center",mt:"xs",children:e(t.Button,{onClick:m,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 Y=[{label:"initial",value:0},{label:"500",value:25},{label:"700",value:50},{label:"semibold",value:75},{label:"bold",value:100}];function yt({label:n,value:r,onChange:i}){var s,l;const[o,a]=u.default.useState((l=(s=Y.find(d=>d.label===r))==null?void 0:s.value)!=null?l:Y[0].value);return u.default.useEffect(()=>{const d=Y.find(m=>m.value===o);d&&i(d.label)},[o]),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:o,onChange:a,step:25,placeholder:"Pick a font size"})]})}const ve=[{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 vt({conf:n,setConf:r}){var a;const i=I.useForm({initialValues:{paragraphs:I.formList((a=n.paragraphs)!=null?a:ve)}}),o=()=>i.addListItem("paragraphs",E(h({},ve[0]),{template:O.randomId()}));return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:i.onSubmit(r),children:[i.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})})]}),i.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,h({placeholder:"Time: ${new Date().toISOString()}",label:"Content Template",required:!0,sx:{flex:1}},i.getListInputProps("paragraphs",l,"template"))),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{children:"Color"}),e(ye,h({},i.getListInputProps("paragraphs",l,"color")))]}),e(t.Group,{direction:"column",grow:!0,children:e(t.TextInput,h({label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",sx:{flex:1}},i.getListInputProps("paragraphs",l,"size")))}),e(t.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:e(yt,h({label:"Font Weight"},i.getListInputProps("paragraphs",l,"weight")))}),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>i.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:o,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(i.values,null,2)})]})})}const ae=[{value:"text",label:"Text",Panel:vt},{value:"table",label:"Table",Panel:St},{value:"sunburst",label:"Sunburst",Panel:xt},{value:"bar-3d",label:"Bar Chart (3D)",Panel:ft},{value:"line-bar",label:"Line-Bar Chart",Panel:mt}];function Ct(){const{viz:n,setViz:r}=u.default.useContext(_),[i,o]=O.useInputState(n.type),a=n.type!==i,s=u.default.useCallback(()=>{!a||r(p=>E(h({},p),{type:i}))},[a,i]),l=p=>{r(g=>E(h({},g),{conf:p}))},d=p=>{try{l(JSON.parse(p))}catch(g){console.error(g)}},m=u.default.useMemo(()=>{var p;return(p=ae.find(g=>g.value===i))==null?void 0:p.Panel},[i,ae]);return c(ie,{children:[e(t.Select,{label:"Visualization",value:i,onChange:o,data:ae,rightSection:e(t.ActionIcon,{disabled:!a,onClick:s,children:e(y.DeviceFloppy,{size:20})})}),m&&e(m,{conf:n.conf,setConf:l}),!m&&e(t.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(n.conf,null,2),onChange:d})]})}function wt({}){return c(t.Group,{direction:"row",grow:!0,noWrap:!0,align:"stretch",sx:{height:"100%"},children:[e(t.Group,{grow:!0,direction:"column",noWrap:!0,sx:{width:"40%",flexShrink:0,flexGrow:0},children:e(Ct,{})}),e(t.Box,{sx:{height:"100%",flexGrow:1,maxWidth:"60%"},children:e(ht,{})})]})}function Tt({opened:n,close:r}){const{freezeLayout:i}=u.default.useContext(B),{data:o,loading:a,viz:s,title:l}=u.default.useContext(_);return u.default.useEffect(()=>{i(n)},[n]),e(t.Modal,{size:"96vw",overflow:"inside",opened:n,onClose:r,title:l,trapFocus:!0,onDragStart:d=>{d.stopPropagation()},children:e(t.AppShell,{sx:{height:"90vh",maxHeight:"calc(100vh - 185px)",".mantine-AppShell-body":{height:"100%"},main:{height:"100%",width:"100%"}},padding:"md",children:c(t.Tabs,{initialTab:2,children:[c(t.Tabs.Tab,{label:"Data Source",children:[e(t.LoadingOverlay,{visible:a}),e(Xe,{})]}),e(t.Tabs.Tab,{label:"Panel",children:e(He,{})}),e(t.Tabs.Tab,{label:"Visualization",children:e(wt,{})})]})})})}function Dt({}){const[n,r]=u.default.useState(!1),i=()=>r(!0),o=()=>r(!1),{title:a,refreshData:s}=u.default.useContext(_),{inEditMode:l}=u.default.useContext(B);return c(t.Group,{position:"apart",noWrap:!0,sx:{borderBottom:"1px solid #eee",paddingBottom:"5px"},children:[e(t.Group,{children:e(ge,{})}),e(t.Group,{grow:!0,position:"center",children:e(t.Text,{lineClamp:1,weight:"bold",children:a})}),e(t.Group,{position:"right",spacing:0,sx:{height:"28px"},children:c(t.Menu,{children:[e(t.Menu.Item,{onClick:s,icon:e(y.Refresh,{size:14}),children:"Refresh"}),l&&e(t.Menu.Item,{onClick:i,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"})]})}),l&&e(Tt,{opened:n,close:o})]})}var Ut="";function le({viz:n,dataSourceID:r,title:i,description:o,update:a,layout:s,id:l}){const d=u.default.useContext(R),m=u.default.useContext(P),[p,g]=u.default.useState(i),[b,x]=u.default.useState(o),[S,T]=u.default.useState(r),[G,L]=u.default.useState(n),$=u.default.useMemo(()=>{if(!!S)return m.dataSources.find(J=>J.id===S)},[S,m.dataSources]);u.default.useEffect(()=>{a==null||a({id:l,layout:s,title:p,description:b,dataSourceID:S,viz:G})},[p,b,$,G,l,s,S]);const{data:k=[],loading:H,refresh:se}=ee.useRequest(fe({context:d,definitions:m,title:p,dataSource:$}),{refreshDeps:[d,m,$]}),ue=se;return e(_.Provider,{value:{data:k,loading:H,title:p,setTitle:g,description:b,setDescription:x,dataSourceID:S,setDataSourceID:T,viz:G,setViz:L,refreshData:ue},children:c(t.Container,{className:"panel-root",children:[e(Dt,{}),e(oe,{children:e(Se,{viz:G,data:k,loading:H})})]})})}var Kt="";const Gt=D.WidthProvider(D.Responsive);function Ce({panels:n,setPanels:r,className:i="layout",cols:o={lg:12,md:10,sm:8,xs:6,xxs:4},rowHeight:a=10,onRemoveItem:s,isDraggable:l,isResizable:d,setLocalCols:m,setBreakpoint:p}){const g=(x,S)=>{p(x),m(S)},b=u.default.useCallback(x=>{const S=new Map;x.forEach($=>{var k=$,{i:G}=k,L=z(k,["i"]);S.set(G,L)});const T=n.map(G=>E(h({},G),{layout:S.get(G.id)}));r(T)},[n,r]);return e(Gt,{onBreakpointChange:g,onLayoutChange:b,className:i,cols:o,rowHeight:a,isDraggable:l,isResizable:d,children:n.map((G,T)=>{var L=G,{id:x}=L,S=z(L,["id"]);return e("div",{"data-grid":S.layout,children:e(le,E(h({id:x},S),{destroy:()=>s(x),update:$=>{r(k=>(k.splice(T,1,$),[...k]))}}))},x)})})}function we(n,r){return c(t.Text,{sx:{svg:{verticalAlign:"text-bottom"}},children:[n," ",r]})}function _t({mode:n,setMode:r}){return e(t.SegmentedControl,{value:n,onChange:r,data:[{label:we(e(y.PlayerPlay,{size:20}),"Use"),value:q.Use},{label:we(e(y.Paint,{size:20}),"Edit"),value:q.Edit}]})}const zt=`
9
+ */var Ve=u.default,Ne=Symbol.for("react.element"),je=Symbol.for("react.fragment"),We=Object.prototype.hasOwnProperty,Qe=Ve.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Je={key:!0,ref:!0,__self:!0,__source:!0};function xe(n,i,r){var o,a={},l=null,s=null;r!==void 0&&(l=""+r),i.key!==void 0&&(l=""+i.key),i.ref!==void 0&&(s=i.ref);for(o in i)We.call(i,o)&&!Je.hasOwnProperty(o)&&(a[o]=i[o]);if(n&&n.defaultProps)for(o in i=n.defaultProps,i)a[o]===void 0&&(a[o]=i[o]);return{$$typeof:Ne,type:n,key:l,ref:s,props:a,_owner:Qe.current}}Z.Fragment=je,Z.jsx=xe,Z.jsxs=xe,X.exports=Z;const e=X.exports.jsx,c=X.exports.jsxs,oe=X.exports.Fragment;function ge({position:n,trigger:i="click"}){const{freezeLayout:r}=u.default.useContext(R),[o,a]=u.default.useState(!1),{description:l}=u.default.useContext(L);if(u.default.useEffect(()=>{r(o)},[o]),!l||l==="<p><br></p>")return null;const s=i==="click"?e(t.Tooltip,{label:"Click to see description",openDelay:500,children:e(v.InfoCircle,{size:20,onClick:()=>a(d=>!d),style:{verticalAlign:"baseline",cursor:"pointer"}})}):e(v.InfoCircle,{size:20,onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),style:{verticalAlign:"baseline",cursor:"pointer"}});return e(t.Popover,{opened:o,onClose:()=>a(!1),withCloseButton:!0,withArrow:!0,trapFocus:!0,closeOnEscape:!1,placement:"center",position:n,target:s,children:e(Ee.default,{readOnly:!0,value:l,onChange:T.default.noop,sx:{border:"none"}})})}function Ue(){const{description:n,setDescription:i}=u.default.useContext(L),[r,o]=u.default.useState(n),a=n!==r,l=u.default.useCallback(()=>{!a||i(r)},[a,r]);return c(t.Group,{direction:"column",sx:{flexGrow:1},children:[c(t.Group,{align:"end",children:[e(t.Text,{children:"Description"}),e(t.ActionIcon,{variant:"hover",color:"blue",disabled:!a,onClick:l,children:e(v.DeviceFloppy,{size:20})})]}),e(ce.RichTextEditor,{value:r,onChange:o,sx:{flexGrow:1},sticky:!0,p:"0"})]})}class ae 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}}function He(){const{title:n}=u.default.useContext(L);return e(ae,{children:c(t.Group,{direction:"column",grow:!0,noWrap:!0,mx:"auto",mt:"xl",p:"5px",spacing:"xs",sx:{width:"600px",height:"450px",background:"transparent",borderRadius:"5px",boxShadow:"0px 0px 10px 0px rgba(0,0,0,.2)"},children:[c(t.Group,{position:"apart",noWrap:!0,sx:{borderBottom:"1px solid #eee",paddingBottom:"5px",flexGrow:0,flexShrink:0},children:[e(t.Group,{children:e(ge,{position:"bottom",trigger:"hover"})}),e(t.Group,{grow:!0,position:"center",children:e(t.Text,{lineClamp:1,weight:"bold",children:n})}),e(t.Group,{position:"right",spacing:0,sx:{height:"28px"}})]}),e(t.Group,{sx:{background:"#eee",flexGrow:1}})]})})}function Ke(){const{title:n,setTitle:i}=u.default.useContext(L),[r,o]=A.useInputState(n),a=n!==r,l=u.default.useCallback(()=>{!a||i(r)},[a,r]);return e(t.TextInput,{value:r,onChange:o,label:c(t.Group,{align:"end",children:[e(t.Text,{children:"Panel Title"}),e(t.ActionIcon,{variant:"hover",color:"blue",disabled:!a,onClick:l,children:e(v.DeviceFloppy,{size:20})})]})})}function Ye({}){return c(t.Group,{direction:"row",grow:!0,noWrap:!0,align:"stretch",sx:{height:"100%"},children:[c(t.Group,{grow:!0,direction:"column",sx:{width:"40%",flexShrink:0,flexGrow:0,height:"100%"},children:[e(Ke,{}),e(Ue,{})]}),e(t.Box,{sx:{height:"100%",flexGrow:1,maxWidth:"60%"},children:e(He,{})})]})}function be({id:n}){const i=u.default.useContext(O),r=u.default.useContext(W),o=u.default.useMemo(()=>i.dataSources.find(d=>d.id===n),[i.dataSources,n]),{data:a=[],loading:l,refresh:s}=re.useRequest(me({context:r,definitions:i,title:n,dataSource:o}),{refreshDeps:[r,i,o]});return l?e(t.LoadingOverlay,{visible:l,exitTransitionDuration:0}):a.length===0?e(t.Table,{}):c(t.Group,{my:"xl",direction:"column",grow:!0,sx:{border:"1px solid #eee"},children:[c(t.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[c(t.Group,{position:"left",children:[e(t.Text,{weight:500,children:"Preview Data"}),a.length>10&&c(t.Text,{size:"sm",color:"gray",children:["Showing 10 rows of ",a.length]})]}),e(t.ActionIcon,{mr:15,variant:"hover",color:"blue",disabled:l,onClick:s,children:e(v.Refresh,{size:15})})]}),c(t.Table,{children:[e("thead",{children:e("tr",{children:Object.keys(a==null?void 0:a[0]).map(d=>e("th",{children:e(t.Text,{weight:700,color:"#000",children:d})},d))})}),e("tbody",{children:a.slice(0,10).map((d,f)=>e("tr",{children:Object.values(d).map((m,p)=>e("td",{children:e(t.Group,{sx:{"&, .mantine-Text-root":{fontFamily:"monospace"}},children:e(t.Text,{children:m})})},`${m}--${p}`))},`row-${f}`))})]})]})}function Xe({}){const{dataSources:n}=u.default.useContext(O),{dataSourceID:i,setDataSourceID:r,data:o,loading:a}=u.default.useContext(L),l=u.default.useMemo(()=>n.map(s=>({value:s.id,label:s.id})),[n]);return c(t.Group,{direction:"column",grow:!0,noWrap:!0,children:[c(t.Group,{position:"left",sx:{maxWidth:"600px",alignItems:"baseline"},children:[e(t.Text,{children:"Select a Data Source"}),e(t.Select,{data:l,value:i,onChange:r,allowDeselect:!1,clearable:!1,sx:{flexGrow:1}})]}),e(be,{id:i})]})}F.use([U.SunburstChart,H.CanvasRenderer]);const Ze={tooltip:{show:!0},series:{type:"sunburst",radius:[0,"90%"],emphasis:{focus:"ancestor"}}};function et({conf:n,data:i,width:r,height:o}){const b=n,{label_field:a="name",value_field:l="value"}=b,s=P(b,["label_field","value_field"]),d=u.default.useMemo(()=>i.map(g=>({name:g[a],value:Number(g[l])})),[i,a,l]),f=u.default.useMemo(()=>{var g,S;return(S=(g=T.default.maxBy(d,y=>y.value))==null?void 0:g.value)!=null?S:1},[d]),m=u.default.useMemo(()=>({series:{label:{formatter:({name:g,value:S})=>S/f<.2?" ":g}}}),[f]),p=T.default.merge({},Ze,m,s,{series:{data:d}});return e(K.default,{echarts:F,option:p,style:{width:r,height:o}})}F.use([U.BarChart,U.LineChart,N.GridComponent,N.LegendComponent,N.TooltipComponent,H.CanvasRenderer]);const tt={legend:{show:!0,bottom:0,left:0},tooltip:{trigger:"axis"},xAxis:{type:"category",nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold"}},yAxis:{nameTextStyle:{fontWeight:"bolder",align:"left"}},grid:{top:30,left:15,right:15,bottom:30,containLabel:!0}};function nt({conf:n,data:i,width:r,height:o}){const a=u.default.useMemo(()=>{var f,m;const l=n.series.reduce((p,{name:b,y_axis_data_formatter:g})=>(p[b]=function({value:y}){if(!g)return y;try{return Y.default(y).format(JSON.parse(g))}catch(_){return console.error(_),y}},p),{}),s=n.series.map(_=>{var G=_,{y_axis_data_key:p,y_axis_data_formatter:b,name:g,label_position:S="top"}=G,y=P(G,["y_axis_data_key","y_axis_data_formatter","name","label_position"]);const k=h({data:i.map(z=>z[p]),label:{show:!0,position:S},name:g},y);return b&&(k.label.formatter=l[g]),k}),d={xAxis:{data:i.map(p=>p[n.x_axis_data_key]),name:(f=n.x_axis_name)!=null?f:""},yAxis:{name:(m=n.y_axis_name)!=null?m:""},dataset:{source:i},series:s,tooltip:{formatter:function(p){const b=Array.isArray(p)?p:[p];if(b.length===0)return"";const g=b.map(({seriesName:S,value:y})=>S?`${S}: ${l[S]({value:y})}`:y);return g.unshift(`<strong>${b[0].name}</strong>`),g.join("<br />")}}};return T.default.merge({},tt,d)},[n,i]);return!r||!o?null:e(K.default,{echarts:F,option:a,style:{width:r,height:o}})}var $=(n=>(n.string="string",n.number="number",n.eloc="eloc",n.percentage="percentage",n))($||{});function it({value:n}){return e(t.Text,{component:"span",children:n})}function rt({value:n}){return e(t.Text,{component:"span",children:n})}function ot({value:n}){const i=Y.default(n).format({thousandSeparated:!0});return e(t.Text,{component:"span",children:i})}function at({value:n}){const i=Y.default(n).format({output:"percent",mantissa:3});return e(t.Text,{component:"span",children:i})}function lt({value:n,type:i}){switch(i){case $.string:return e(it,{value:n});case $.eloc:return e(rt,{value:n});case $.number:return e(ot,{value:n});case $.percentage:return e(at,{value:n})}}function st({conf:n,data:i=[],width:r,height:o}){const p=n,{id_field:a,use_raw_columns:l,columns:s}=p,d=P(p,["id_field","use_raw_columns","columns"]),f=u.default.useMemo(()=>l?Object.keys(i==null?void 0:i[0]):s.map(b=>b.label),[l,s,i]),m=u.default.useMemo(()=>l?Object.keys(i==null?void 0:i[0]).map(b=>({label:b,value_field:b,value_type:$.string})):s,[l,s,i]);return c(t.Table,E(h({sx:{maxHeight:o}},d),{children:[e("thead",{children:e("tr",{children:f.map(b=>e("th",{children:b},b))})}),e("tbody",{children:i.slice(0,30).map((b,g)=>e("tr",{children:m.map(({value_field:S,value_type:y})=>e("td",{children:e(t.Group,{sx:{"&, .mantine-Text-root":{fontFamily:"monospace",fontSize:d.fontSize}},children:e(lt,{value:b[S],type:y})})},b[S]))},a?b[a]:`row-${g}`))}),i.length>100&&e("tfoot",{children:e("tr",{children:e("td",{colSpan:f.length,children:e(t.Text,{color:"red",size:"sm",children:"Showing only the first 30 rows to avoid causing slow performance"})})})})]}))}function ut(n,i={}){const r=E(h({},i),{numbro:Y.default}),o=Object.keys(r),a=Object.values(r);try{return new Function(...o,`return \`${n}\`;`)(...a)}catch(l){return l.message}}function dt({conf:{paragraphs:n},data:i}){return e(oe,{children:n.map((s,l)=>{var d=s,{template:r,size:o}=d,a=P(d,["template","size"]);return e(t.Text,E(h({},a),{sx:{fontSize:o},children:ut(r,i[0])}),`${r}---${l}`)})})}F.use([N.GridComponent,N.VisualMapComponent,N.LegendComponent,N.TooltipComponent,H.CanvasRenderer]);function ct({conf:n,data:i,width:r,height:o}){const b=n,{x_axis_data_key:a,y_axis_data_key:l,z_axis_data_key:s}=b,d=P(b,["x_axis_data_key","y_axis_data_key","z_axis_data_key"]),f=u.default.useMemo(()=>T.default.minBy(i,g=>g[s])[s],[i,s]),m=u.default.useMemo(()=>T.default.maxBy(i,g=>g[s])[s],[i,s]),p=E(h({tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:f,max:m,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[a],g[l],g[s]])}]});return e(K.default,{echarts:F,option:p,style:{width:r,height:o}})}var Zt="";F.use([U.PieChart,H.CanvasRenderer]);const pt={tooltip:{show:!0},series:{type:"pie",radius:["50%","80%"],label:{position:"outer",alignTo:"edge",formatter:`{name|{b}}
10
+ {percentage|{d}%}`,minMargin:5,edgeDistance:10,lineHeight:15,rich:{percentage:{color:"#999"}},margin:20},labelLine:{length:15,length2:0,maxSurfaceAngle:80,showAbove:!0},top:10,bottom:10,left:10,right:10}};function ht({conf:n,data:i,width:r,height:o}){const p=n,{label_field:a="name",value_field:l="value"}=p,s=P(p,["label_field","value_field"]),d=u.default.useMemo(()=>i.map(b=>({name:b[a],value:Number(b[l])})),[i,a,l]),f=u.default.useMemo(()=>({series:{labelLayout:function(b){const g=b.labelRect.x<r/2,S=b.labelLinePoints;return S[2][0]=g?b.labelRect.x:b.labelRect.x+b.labelRect.width,{labelLinePoints:S}}}}),[r]),m=T.default.merge({},pt,f,s,{series:{data:d}});return e(K.default,{echarts:F,option:m,style:{width:r,height:o}})}function mt(n,i,r,o){const a={width:n,height:i,data:r,conf:o.conf};switch(o.type){case"sunburst":return e(et,h({},a));case"line-bar":return e(nt,h({},a));case"table":return e(st,h({},a));case"text":return e(dt,h({},a));case"bar-3d":return e(ct,h({},a));case"pie":return e(ht,h({},a));default:return null}}function Se({viz:n,data:i,loading:r}){const{ref:o,width:a,height:l}=A.useElementSize(),s=u.default.useMemo(()=>!Array.isArray(i)||i.length===0,[i]);return r?e("div",{className:"viz-root",ref:o,children:e(t.LoadingOverlay,{visible:r,exitTransitionDuration:0})}):c("div",{className:"viz-root",ref:o,children:[s&&e(t.Text,{color:"gray",align:"center",children:"nothing to show"}),!s&&mt(a,l,i,n)]})}function ft({}){const{data:n,loading:i,viz:r}=u.default.useContext(L);return e(ae,{children:e(Se,{viz:r,data:n,loading:i})})}function xt({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:o,handleSubmit:a,formState:l}=j.useForm({defaultValues:r});return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:a(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(j.Controller,{name:"x_axis_data_key",control:o,render:({field:s})=>e(t.TextInput,h({sx:{flexGrow:1},size:"md",label:"Data Key"},s))}),e(j.Controller,{name:"xAxis3D.name",control:o,render:({field:s})=>e(t.TextInput,h({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(j.Controller,{name:"y_axis_data_key",control:o,render:({field:s})=>e(t.TextInput,h({sx:{flexGrow:1},size:"md",label:"Data Key"},s))}),e(j.Controller,{name:"yAxis3D.name",control:o,render:({field:s})=>e(t.TextInput,h({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(j.Controller,{name:"z_axis_data_key",control:o,render:({field:s})=>e(t.TextInput,h({sx:{flexGrow:1},size:"md",label:"Data Key"},s))}),e(j.Controller,{name:"zAxis3D.name",control:o,render:({field:s})=>e(t.TextInput,h({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(v.DeviceFloppy,{size:20}),e(t.Text,{ml:"md",children:"Save"})]})})]})})}function ve({value:n,onChange:i}){const r=t.useMantineTheme(),o=u.default.useMemo(()=>Object.entries(r.colors).map(([l,s])=>({label:l,value:s[6]})),[r]),a=u.default.useMemo(()=>o.some(l=>l.value===n),[n,o]);return c(t.Group,{position:"apart",spacing:"xs",children:[e(t.TextInput,{placeholder:"Set any color",value:a?"":n,onChange:l=>i(l.currentTarget.value),rightSection:e(t.ColorSwatch,{color:a?"transparent":n,radius:4}),variant:a?"filled":"default",sx:{maxWidth:"100%",flexGrow:1}}),e(t.Text,{sx:{flexGrow:0},children:"or"}),e(t.Select,{data:o,value:n,onChange:i,variant:a?"default":"filled",placeholder:"Pick a theme color",icon:e(t.ColorSwatch,{color:a?n:"transparent",radius:4}),sx:{maxWidth:"100%",flexGrow:1}})]})}const gt=JSON.stringify({output:"percent",mantissa:2},null,2),bt=[{label:"top",value:"top"},{label:"left",value:"left"},{label:"right",value:"right"},{label:"bottom",value:"bottom"},{label:"inside",value:"inside"},{label:"insideLeft",value:"insideLeft"},{label:"insideRight",value:"insideRight"},{label:"insideTop",value:"insideTop"},{label:"insideBottom",value:"insideBottom"},{label:"insideTopLeft",value:"insideTopLeft"},{label:"insideBottomLeft",value:"insideBottomLeft"},{label:"insideTopRight",value:"insideTopRight"},{label:"insideBottomRight",value:"insideBottomRight"}];function St(n){function i({type:r,name:o,showSymbol:a,y_axis_data_key:l="value",y_axis_data_formatter:s="",label_position:d="top",stack:f="1",color:m="black"}){return{type:r,name:o,showSymbol:a,y_axis_data_key:l,y_axis_data_formatter:s,label_position:d,stack:f,color:m}}return n.map(i)}function vt({conf:n,setConf:i}){const f=n,{series:r}=f,o=P(f,["series"]),a=u.default.useMemo(()=>{const g=o,{x_axis_name:m="",y_axis_name:p=""}=g,b=P(g,["x_axis_name","y_axis_name"]);return h({series:I.formList(St(r!=null?r:[])),x_axis_name:m,y_axis_name:p},b)},[r,o]),l=I.useForm({initialValues:a}),s=()=>l.addListItem("series",{type:"bar",name:A.randomId(),showSymbol:!1,y_axis_data_key:"value",y_axis_data_formatter:"",label_position:"top",stack:"",color:"#000"}),d=u.default.useMemo(()=>!T.default.isEqual(l.values,a),[l.values,a]);return 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(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!d,children:e(v.DeviceFloppy,{size:20})})]}),e(t.TextInput,h({size:"md",mb:"lg",label:"X Axis Data Key"},l.getInputProps("x_axis_data_key"))),c(t.Group,{direction:"column",grow:!0,noWrap:!0,mb:"lg",children:[e(t.TextInput,h({size:"md",label:"X Axis Name"},l.getInputProps("x_axis_name"))),e(t.TextInput,h({size:"md",label:"Y Axis Name"},l.getInputProps("y_axis_name")))]}),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{mt:"xl",mb:0,children:"Series"}),l.values.series.map((m,p)=>c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[c(t.Group,{direction:"row",grow:!0,noWrap:!0,children:[e(t.TextInput,h({label:"Name",required:!0,sx:{flex:1}},l.getListInputProps("series",p,"name"))),e(t.TextInput,h({label:"Stack",placeholder:"Stack bars by this ID"},l.getListInputProps("series",p,"stack"))),e(t.TextInput,h({label:"Value key",required:!0},l.getListInputProps("series",p,"y_axis_data_key")))]}),c(t.Group,{direction:"row",grow:!0,noWrap:!0,align:"top",children:[e(t.Select,h({label:"Label Position",data:bt},l.getListInputProps("series",p,"label_position"))),e(t.JsonInput,h({sx:{label:{width:"100%"}},label:c(t.Group,{position:"apart",children:[e(t.Text,{children:"Value Formatter"}),e(t.Anchor,{href:"https://numbrojs.com/format.html",target:"_blank",children:"Formats"})]}),placeholder:gt,minRows:4,maxRows:12,autosize:!0},l.getListInputProps("series",p,"y_axis_data_formatter")))]}),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{children:"Color"}),e(ve,h({},l.getListInputProps("series",p,"color")))]}),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>l.removeListItem("series",p),sx:{position:"absolute",top:15,right:5},children:e(v.Trash,{size:16})})]},p)),e(t.Group,{position:"center",mt:"xs",children:e(t.Button,{onClick:s,children:"Add a Series"})})]})]})})}function yt({conf:{label_field:n,value_field:i},setConf:r}){const o=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:o.onSubmit(r),children:[c(t.Group,{position:"apart",mb:"lg",sx:{position:"relative"},children:[e(t.Text,{children:"Pie Config"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",children:e(v.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,h({label:"Label Field",required:!0,sx:{flex:1}},o.getInputProps("label_field"))),e(t.TextInput,h({label:"Value Field",placeholder:"get column value by this field",required:!0,sx:{flex:1}},o.getInputProps("value_field")))]})]})})}function wt({conf:{label_field:n,value_field:i},setConf:r}){const o=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:o.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(v.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,h({label:"Label Field",required:!0,sx:{flex:1}},o.getInputProps("label_field"))),e(t.TextInput,h({label:"Value Field",placeholder:"get column value by this field",required:!0,sx:{flex:1}},o.getInputProps("value_field")))]})]})})}const Ct=Object.values($).map(n=>({label:n,value:n}));function Tt({label:n,value:i,onChange:r,sx:o}){return e(t.Select,{label:n,data:Ct,value:i,onChange:r,sx:o})}function _t(o){var a=o,{conf:l}=a,s=l,{columns:n}=s,i=P(s,["columns"]),{setConf:r}=a;const d=I.useForm({initialValues:h({id_field:"id",use_raw_columns:!0,columns:I.formList(n!=null?n:[]),fontSize:"sm",horizontalSpacing:"sm",verticalSpacing:"sm",striped:!1,highlightOnHover:!1},i)}),f=()=>d.addListItem("columns",{label:A.randomId(),value_field:"value",value_type:$.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(v.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,h({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(t.TextInput,h({label:"Horizontal Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1}},d.getInputProps("horizontalSpacing"))),e(t.TextInput,h({label:"Vertical Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1}},d.getInputProps("verticalSpacing")))]}),e(t.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:e(t.TextInput,h({label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1}},d.getInputProps("fontSize")))}),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{children:"Other"}),c(t.Group,{position:"apart",grow:!0,children:[e(t.Switch,h({label:"Striped"},d.getInputProps("striped",{type:"checkbox"}))),e(t.Switch,h({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,h({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((m,p)=>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,h({label:"Label",required:!0,sx:{flex:1}},d.getListInputProps("columns",p,"label"))),e(t.TextInput,h({label:"Value Field",placeholder:"get column value by this field",required:!0,sx:{flex:1}},d.getListInputProps("columns",p,"value_field"))),e(Tt,h({label:"Value Type",sx:{flex:1}},d.getListInputProps("columns",p,"value_type")))]}),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>d.removeListItem("columns",p),sx:{position:"absolute",top:15,right:5},children:e(v.Trash,{size:16})})]},p)),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(B.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(d.values,null,2)})]})})}const ee=[{label:"initial",value:0},{label:"500",value:25},{label:"700",value:50},{label:"semibold",value:75},{label:"bold",value:100}];function Dt({label:n,value:i,onChange:r}){var l,s;const[o,a]=u.default.useState((s=(l=ee.find(d=>d.label===i))==null?void 0:l.value)!=null?s:ee[0].value);return u.default.useEffect(()=>{const d=ee.find(f=>f.value===o);d&&r(d.label)},[o]),c(t.Group,{direction:"column",grow:!0,spacing:"xs",mb:"lg",children:[e(t.Text,{children:n}),e(t.Slider,{label:null,marks:ee,value:o,onChange:a,step:25,placeholder:"Pick a font size"})]})}const ye=[{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 a;const r=I.useForm({initialValues:{paragraphs:I.formList((a=n.paragraphs)!=null?a:ye)}}),o=()=>r.addListItem("paragraphs",E(h({},ye[0]),{template:A.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(v.DeviceFloppy,{size:20})})]}),r.values.paragraphs.map((l,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,h({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(ve,h({},r.getListInputProps("paragraphs",s,"color")))]}),e(t.Group,{direction:"column",grow:!0,children:e(t.TextInput,h({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(Dt,h({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(v.Trash,{size:16})})]},s)),e(t.Group,{position:"center",mt:"md",children:e(t.Button,{onClick:o,children:"Add a Paragraph"})}),e(t.Text,{size:"sm",weight:500,mt:"md",children:"Current Configuration:"}),e(B.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(r.values,null,2)})]})})}const le=[{value:"text",label:"Text",Panel:Gt},{value:"table",label:"Table",Panel:_t},{value:"sunburst",label:"Sunburst",Panel:wt},{value:"bar-3d",label:"Bar Chart (3D)",Panel:xt},{value:"line-bar",label:"Line-Bar Chart",Panel:vt},{value:"pie",label:"Pie Chart",Panel:yt}];function Pt(){const{viz:n,setViz:i}=u.default.useContext(L),[r,o]=A.useInputState(n.type),a=n.type!==r,l=u.default.useCallback(()=>{!a||i(m=>E(h({},m),{type:r}))},[a,r]),s=m=>{i(p=>E(h({},p),{conf:m}))},d=m=>{try{s(JSON.parse(m))}catch(p){console.error(p)}},f=u.default.useMemo(()=>{var m;return(m=le.find(p=>p.value===r))==null?void 0:m.Panel},[r,le]);return c(oe,{children:[e(t.Select,{label:"Visualization",value:r,onChange:o,data:le,rightSection:e(t.ActionIcon,{disabled:!a,onClick:l,children:e(v.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:d})]})}function zt({}){return c(t.Group,{direction:"row",grow:!0,noWrap:!0,align:"stretch",sx:{height:"100%"},children:[e(t.Group,{grow:!0,direction:"column",noWrap:!0,sx:{width:"40%",flexShrink:0,flexGrow:0},children:e(Pt,{})}),e(t.Box,{sx:{height:"100%",flexGrow:1,maxWidth:"60%"},children:e(ft,{})})]})}function It({opened:n,close:i}){const{freezeLayout:r}=u.default.useContext(R),{data:o,loading:a,viz:l,title:s}=u.default.useContext(L);return u.default.useEffect(()=>{r(n)},[n]),e(t.Modal,{size:"96vw",overflow:"inside",opened:n,onClose:i,title:s,trapFocus:!0,onDragStart:d=>{d.stopPropagation()},children:e(t.AppShell,{sx:{height:"90vh",maxHeight:"calc(100vh - 185px)",".mantine-AppShell-body":{height:"100%"},main:{height:"100%",width:"100%"}},padding:"md",children:c(t.Tabs,{initialTab:2,children:[c(t.Tabs.Tab,{label:"Data Source",children:[e(t.LoadingOverlay,{visible:a,exitTransitionDuration:0}),e(Xe,{})]}),e(t.Tabs.Tab,{label:"Panel",children:e(Ye,{})}),e(t.Tabs.Tab,{label:"Visualization",children:e(zt,{})})]})})})}function Lt({}){const[n,i]=u.default.useState(!1),r=()=>i(!0),o=()=>i(!1),{title:a,refreshData:l}=u.default.useContext(L),{inEditMode:s}=u.default.useContext(R);return c(t.Group,{position:"apart",noWrap:!0,sx:{borderBottom:"1px solid #eee",paddingBottom:"5px"},children:[e(t.Group,{children:e(ge,{})}),e(t.Group,{grow:!0,position:"center",children:e(t.Text,{lineClamp:1,weight:"bold",children:a})}),e(t.Group,{position:"right",spacing:0,sx:{height:"28px"},children:c(t.Menu,{children:[e(t.Menu.Item,{onClick:l,icon:e(v.Refresh,{size:14}),children:"Refresh"}),s&&e(t.Menu.Item,{onClick:r,icon:e(v.Settings,{size:14}),children:"Settings"}),e(t.Divider,{}),e(t.Menu.Item,{color:"red",disabled:!0,icon:e(v.Trash,{size:14}),children:"Delete"})]})}),s&&e(It,{opened:n,close:o})]})}var en="";function se({viz:n,dataSourceID:i,title:r,description:o,update:a,layout:l,id:s}){const d=u.default.useContext(W),f=u.default.useContext(O),[m,p]=u.default.useState(r),[b,g]=u.default.useState(o),[S,y]=u.default.useState(i),[_,G]=u.default.useState(n),k=u.default.useMemo(()=>{if(!!S)return f.dataSources.find(J=>J.id===S)},[S,f.dataSources]);u.default.useEffect(()=>{a==null||a({id:s,layout:l,title:m,description:b,dataSourceID:S,viz:_})},[m,b,k,_,s,l,S]);const{data:z=[],loading:te,refresh:ue}=re.useRequest(me({context:d,definitions:f,title:m,dataSource:k}),{refreshDeps:[d,f,k]}),de=ue;return e(L.Provider,{value:{data:z,loading:te,title:m,setTitle:p,description:b,setDescription:g,dataSourceID:S,setDataSourceID:y,viz:_,setViz:G,refreshData:de},children:c(t.Container,{className:"panel-root",children:[e(Lt,{}),e(ae,{children:e(Se,{viz:_,data:z,loading:te})})]})})}var tn="";const kt=D.WidthProvider(D.Responsive);function we({panels:n,setPanels:i,className:r="layout",cols:o={lg:12,md:10,sm:8,xs:6,xxs:4},rowHeight:a=10,onRemoveItem:l,isDraggable:s,isResizable:d,setLocalCols:f,setBreakpoint:m}){const p=(g,S)=>{m(g),f(S)},b=u.default.useCallback(g=>{const S=new Map;g.forEach(k=>{var z=k,{i:_}=z,G=P(z,["i"]);S.set(_,G)});const y=n.map(_=>E(h({},_),{layout:S.get(_.id)}));i(y)},[n,i]);return e(kt,{onBreakpointChange:p,onLayoutChange:b,className:r,cols:o,rowHeight:a,isDraggable:s,isResizable:d,children:n.map((_,y)=>{var G=_,{id:g}=G,S=P(G,["id"]);return e("div",{"data-grid":S.layout,children:e(se,E(h({id:g},S),{destroy:()=>l(g),update:k=>{i(z=>(z.splice(y,1,k),[...z]))}}))},g)})})}function Ce(n,i){return c(t.Text,{sx:{svg:{verticalAlign:"text-bottom"}},children:[n," ",i]})}function Et({mode:n,setMode:i}){return e(t.SegmentedControl,{value:n,onChange:i,data:[{label:Ce(e(v.PlayerPlay,{size:20}),"Use"),value:q.Use},{label:Ce(e(v.Paint,{size:20}),"Edit"),value:q.Edit}]})}const Ot=`
10
11
  -- You may reference context data or SQL snippets *by name*
11
12
  -- in SQL or VizConfig.
12
13
  SELECT *
@@ -17,16 +18,16 @@ WHERE
17
18
  -- SQL snippets
18
19
  AND \${author_email_condition}
19
20
  \${order_by_clause}
20
- `;function It({}){const n=u.default.useContext(R),{sqlSnippets:r}=u.default.useContext(P),i=u.default.useMemo(()=>{const a=r.reduce((s,l)=>(s[l.key]=l.value,s),{});return JSON.stringify(a,null,2)},[r]),o=u.default.useMemo(()=>JSON.stringify(n,null,2),[n]);return c(t.Group,{direction:"column",grow:!0,sx:{border:"1px solid #eee",maxWidth:"48%",overflow:"hidden"},children:[e(t.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:e(t.Text,{weight:500,children:"Context"})}),c(t.Group,{direction:"column",px:"md",pb:"md",sx:{width:"100%"},children:[e(M.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:zt}),e(t.Text,{weight:500,sx:{flexGrow:0},children:"Avaiable context"}),e(M.Prism,{language:"json",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:o}),e(t.Text,{weight:500,sx:{flexGrow:0},children:"Avaiable SQL Snippets"}),e(M.Prism,{language:"json",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:i})]})]})}function Pt({value:n,onChange:r}){const i=I.useForm({initialValues:n}),o=u.default.useCallback(p=>{r(p)},[r]),a=u.default.useMemo(()=>!w.default.isEqual(n,i.values),[n,i.values]);u.default.useEffect(()=>{i.reset()},[n]);const{data:s={},loading:l}=ee.useRequest(Be,{refreshDeps:[]},[]),d=u.default.useMemo(()=>Object.keys(s).map(p=>({label:p,value:p})),[s]),m=u.default.useMemo(()=>{const p=s[i.values.type];return p?p.map(g=>({label:g,value:g})):[]},[s,i.values.type]);return e(t.Group,{direction:"column",grow:!0,sx:{border:"1px solid #eee",flexGrow:1},children:c("form",{onSubmit:i.onSubmit(o),children:[c(t.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[e(t.Text,{weight:500,children:"Data Source Configuration"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!a||l,children:e(y.DeviceFloppy,{size:20})})]}),c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,children:[c(t.Group,{grow:!0,children:[e(t.TextInput,h({placeholder:"An ID unique in this dashboard",label:"ID",required:!0,sx:{flex:1},disabled:l},i.getInputProps("id"))),e(t.Select,h({label:"Data Source Type",data:d,sx:{flex:1},disabled:l},i.getInputProps("type"))),e(t.Select,h({label:"Data Source Key",data:m,sx:{flex:1},disabled:l},i.getInputProps("key")))]}),e(t.Textarea,h({autosize:!0,minRows:12,maxRows:24},i.getInputProps("sql")))]})]})})}function Lt({id:n}){const{dataSources:r,setDataSources:i}=u.default.useContext(P),o=u.default.useMemo(()=>r.find(s=>s.id===n),[r,n]),a=u.default.useCallback(s=>{if(!r.findIndex(d=>d.id===n)){console.error(new Error("Invalid data source id when updating by id"));return}i(d=>{const m=d.findIndex(p=>p.id===n);return d.splice(m,1,s),[...d]})},[n,i]);return o?c(t.Group,{direction:"row",position:"apart",grow:!0,align:"stretch",noWrap:!0,children:[e(Pt,{value:o,onChange:a}),e(It,{})]}):e("span",{children:"Invalid Data Source ID"})}function kt({id:n,setID:r}){const{dataSources:i,setDataSources:o}=u.default.useContext(P),a=u.default.useCallback(()=>{var d,m;r((m=(d=i[0])==null?void 0:d.id)!=null?m:"")},[r,i]);u.default.useEffect(()=>{if(!n){a();return}i.findIndex(m=>m.id===n)===-1&&a()},[n,i,a]);const s=u.default.useMemo(()=>i.map(d=>({value:d.id,label:d.id})),[i]),l=u.default.useCallback(()=>{const d={id:O.randomId(),type:"postgresql",key:"",sql:""};o(m=>[...m,d]),r(d.id)},[o,r]);return e(t.Group,{pb:"xl",children:c(t.Group,{position:"left",sx:{maxWidth:"600px",alignItems:"baseline"},children:[e(t.Text,{children:"Select a Data Source"}),e(t.Select,{data:s,value:n,onChange:r,allowDeselect:!1,clearable:!1,sx:{flexGrow:1}}),e(t.Text,{children:"or"}),e(t.Group,{position:"center",mt:"md",children:e(t.Button,{onClick:l,children:"Add a Data Source"})})]})})}function Et({opened:n,close:r}){const[i,o]=u.default.useState(""),{freezeLayout:a}=u.default.useContext(B);return u.default.useEffect(()=>{a(n)},[n]),e(t.Modal,{size:"96vw",overflow:"inside",opened:n,onClose:r,title:"Data Sources",trapFocus:!0,onDragStart:s=>{s.stopPropagation()},children:c(t.AppShell,{sx:{height:"90vh",maxHeight:"calc(100vh - 185px)",".mantine-AppShell-body":{height:"100%"},main:{height:"100%",width:"100%",padding:0,margin:0}},padding:"md",header:e(kt,{id:i,setID:o}),children:[e(Lt,{id:i}),e(be,{id:i})]})})}function Ot({}){const n=u.default.useContext(R),r="SELECT *\nFROM commit\nWHERE author_time BETWEEN '${timeRange?.[0].toISOString()}' AND '${timeRange?.[1].toISOString()}'";return c(t.Group,{direction:"column",grow:!0,sx:{border:"1px solid #eee",maxWidth:"48%",overflow:"hidden"},children:[e(t.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:e(t.Text,{weight:500,children:"Context"})}),c(t.Group,{direction:"column",px:"md",pb:"md",sx:{width:"100%"},children:[e(M.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:`-- You may refer context data *by name*
21
+ `;function At({}){const n=u.default.useContext(W),{sqlSnippets:i}=u.default.useContext(O),r=u.default.useMemo(()=>{const a=i.reduce((l,s)=>(l[s.key]=s.value,l),{});return JSON.stringify(a,null,2)},[i]),o=u.default.useMemo(()=>JSON.stringify(n,null,2),[n]);return c(t.Group,{direction:"column",grow:!0,sx:{border:"1px solid #eee",maxWidth:"48%",overflow:"hidden"},children:[e(t.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:e(t.Text,{weight:500,children:"Context"})}),c(t.Group,{direction:"column",px:"md",pb:"md",sx:{width:"100%"},children:[e(B.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:Ot}),e(t.Text,{weight:500,sx:{flexGrow:0},children:"Avaiable context"}),e(B.Prism,{language:"json",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:o}),e(t.Text,{weight:500,sx:{flexGrow:0},children:"Avaiable SQL Snippets"}),e(B.Prism,{language:"json",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:r})]})]})}function qt({value:n,onChange:i}){const r=I.useForm({initialValues:n}),o=u.default.useCallback(m=>{i(m)},[i]),a=u.default.useMemo(()=>!T.default.isEqual(n,r.values),[n,r.values]);u.default.useEffect(()=>{r.reset()},[n]);const{data:l={},loading:s}=re.useRequest(Be,{refreshDeps:[]},[]),d=u.default.useMemo(()=>Object.keys(l).map(m=>({label:m,value:m})),[l]),f=u.default.useMemo(()=>{const m=l[r.values.type];return m?m.map(p=>({label:p,value:p})):[]},[l,r.values.type]);return e(t.Group,{direction:"column",grow:!0,sx:{border:"1px solid #eee",flexGrow:1},children:c("form",{onSubmit:r.onSubmit(o),children:[c(t.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[e(t.Text,{weight:500,children:"Data Source Configuration"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!a||s,children:e(v.DeviceFloppy,{size:20})})]}),c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,children:[c(t.Group,{grow:!0,children:[e(t.TextInput,h({placeholder:"An ID unique in this dashboard",label:"ID",required:!0,sx:{flex:1},disabled:s},r.getInputProps("id"))),e(t.Select,h({label:"Data Source Type",data:d,sx:{flex:1},disabled:s},r.getInputProps("type"))),e(t.Select,h({label:"Data Source Key",data:f,sx:{flex:1},disabled:s},r.getInputProps("key")))]}),e(t.Textarea,h({autosize:!0,minRows:12,maxRows:24},r.getInputProps("sql")))]})]})})}function Mt({id:n}){const{dataSources:i,setDataSources:r}=u.default.useContext(O),o=u.default.useMemo(()=>i.find(l=>l.id===n),[i,n]),a=u.default.useCallback(l=>{if(i.findIndex(d=>d.id===n)===-1){console.error(new Error("Invalid data source id when updating by id"));return}r(d=>{const f=d.findIndex(m=>m.id===n);return d.splice(f,1,l),[...d]})},[n,i,r]);return n?o?c(t.Group,{direction:"row",position:"apart",grow:!0,align:"stretch",noWrap:!0,children:[e(qt,{value:o,onChange:a}),e(At,{})]}):e("span",{children:"Invalid Data Source ID"}):null}function Bt({id:n,setID:i}){const{dataSources:r,setDataSources:o}=u.default.useContext(O),a=u.default.useCallback(()=>{var d,f;i((f=(d=r[0])==null?void 0:d.id)!=null?f:"")},[i,r]);u.default.useEffect(()=>{if(!n){a();return}r.findIndex(f=>f.id===n)===-1&&a()},[n,r,a]);const l=u.default.useMemo(()=>r.map(d=>({value:d.id,label:d.id})),[r]),s=u.default.useCallback(()=>{const d={id:A.randomId(),type:"postgresql",key:"",sql:""};o(f=>[...f,d]),i(d.id)},[o,i]);return e(t.Group,{pb:"xl",children:c(t.Group,{position:"left",sx:{maxWidth:"600px",alignItems:"baseline"},children:[e(t.Text,{children:"Select a Data Source"}),e(t.Select,{data:l,value:n,onChange:i,allowDeselect:!1,clearable:!1,sx:{flexGrow:1}}),e(t.Text,{children:"or"}),e(t.Group,{position:"center",mt:"md",children:e(t.Button,{onClick:s,children:"Add a Data Source"})})]})})}function Ft({opened:n,close:i}){const[r,o]=u.default.useState(""),{freezeLayout:a}=u.default.useContext(R);return u.default.useEffect(()=>{a(n)},[n]),e(t.Modal,{size:"96vw",overflow:"inside",opened:n,onClose:i,title:"Data Sources",trapFocus:!0,onDragStart:l=>{l.stopPropagation()},children:c(t.AppShell,{sx:{height:"90vh",maxHeight:"calc(100vh - 185px)",".mantine-AppShell-body":{height:"100%"},main:{height:"100%",width:"100%",padding:0,margin:0}},padding:"md",header:e(Bt,{id:r,setID:o}),children:[e(Mt,{id:r}),e(be,{id:r})]})})}function Rt({}){const n=u.default.useContext(W),i="SELECT *\nFROM commit\nWHERE author_time BETWEEN '${timeRange?.[0].toISOString()}' AND '${timeRange?.[1].toISOString()}'";return c(t.Group,{direction:"column",grow:!0,sx:{border:"1px solid #eee",maxWidth:"48%",overflow:"hidden"},children:[e(t.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:e(t.Text,{weight:500,children:"Context"})}),c(t.Group,{direction:"column",px:"md",pb:"md",sx:{width:"100%"},children:[e(B.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:`-- You may refer context data *by name*
21
22
  -- in SQL or VizConfig.
22
23
 
23
- ${r}`}),e(t.Text,{weight:500,sx:{flexGrow:0},children:"Avaiable context entries"}),e(M.Prism,{language:"json",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:JSON.stringify(n,null,2)})]})]})}function qt({}){const{sqlSnippets:n,setSQLSnippets:r}=u.default.useContext(P),i=`SELECT *
24
+ ${i}`}),e(t.Text,{weight:500,sx:{flexGrow:0},children:"Avaiable context entries"}),e(B.Prism,{language:"json",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:JSON.stringify(n,null,2)})]})]})}function $t({}){const{sqlSnippets:n,setSQLSnippets:i}=u.default.useContext(O),r=`SELECT *
24
25
  FROM commit
25
- WHERE \${author_time_condition}`,o=u.default.useMemo(()=>({snippets:I.formList(n!=null?n:[])}),[n]),a=I.useForm({initialValues:o}),s=()=>a.addListItem("snippets",{key:O.randomId(),value:""}),l=u.default.useMemo(()=>!w.default.isEqual(a.values,o),[a.values,o]),d=({snippets:m})=>{r(m)};return c(t.Group,{direction:"column",grow:!0,sx:{border:"1px solid #eee"},children:[c(t.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:[e(t.Text,{weight:500,children:"SQL Snippets"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!l,children:e(y.DeviceFloppy,{size:20})})]}),c(t.Group,{px:"md",pb:"md",children:[e(M.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,trim:!1,colorScheme:"dark",children:`-- You may refer context data *by name*
26
+ WHERE \${author_time_condition}`,o=u.default.useMemo(()=>({snippets:I.formList(n!=null?n:[])}),[n]),a=I.useForm({initialValues:o}),l=()=>a.addListItem("snippets",{key:A.randomId(),value:""}),s=u.default.useMemo(()=>!T.default.isEqual(a.values,o),[a.values,o]),d=({snippets:f})=>{i(f)};return c(t.Group,{direction:"column",grow:!0,sx:{border:"1px solid #eee"},children:[c(t.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:[e(t.Text,{weight:500,children:"SQL Snippets"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!s,children:e(v.DeviceFloppy,{size:20})})]}),c(t.Group,{px:"md",pb:"md",children:[e(B.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,trim:!1,colorScheme:"dark",children:`-- You may refer context data *by name*
26
27
  -- in SQL or VizConfig.
27
28
 
28
- ${i}
29
+ ${r}
29
30
 
30
31
  -- where author_time_condition is:
31
32
  author_time BETWEEN '\${timeRange?.[0].toISOString()}' AND '\${timeRange?.[1].toISOString()}'
32
- `}),e(t.Group,{direction:"column",sx:{width:"100%",position:"relative"},grow:!0,children:c("form",{onSubmit:a.onSubmit(d),children:[a.values.snippets.map((m,p)=>c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[e(t.TextInput,h({label:"Key",required:!0},a.getListInputProps("snippets",p,"key"))),e(t.Textarea,h({minRows:3,label:"Value",required:!0},a.getListInputProps("snippets",p,"value"))),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>a.removeListItem("snippets",p),sx:{position:"absolute",top:15,right:5},children:e(y.Trash,{size:16})})]},p)),e(t.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"40%"},mx:"auto",children:e(t.Button,{variant:"default",onClick:s,children:"Add a snippet"})})]})})]})]})}function At({opened:n,close:r}){const{freezeLayout:i}=u.default.useContext(B);return u.default.useEffect(()=>{i(n)},[n]),e(t.Modal,{size:"96vw",overflow:"inside",opened:n,onClose:r,title:"SQL Snippets",trapFocus:!0,onDragStart:o=>{o.stopPropagation()},children:e(t.AppShell,{sx:{height:"90vh",maxHeight:"calc(100vh - 185px)",".mantine-AppShell-body":{height:"100%"},main:{height:"100%",width:"100%",padding:0,margin:0}},padding:"md",children:c(t.Group,{direction:"row",position:"apart",grow:!0,align:"stretch",noWrap:!0,children:[e(qt,{}),e(Ot,{})]})})})}function Mt({mode:n,setMode:r,hasChanges:i,addPanel:o,saveChanges:a}){const[s,l]=u.default.useState(!1),d=()=>l(!0),m=()=>l(!1),[p,g]=u.default.useState(!1),b=()=>g(!0),x=()=>g(!1),S=n===q.Edit;return c(t.Group,{position:"apart",pt:"sm",pb:"xs",children:[e(t.Group,{position:"left",children:e(_t,{mode:n,setMode:r})}),S&&c(ie,{children:[c(t.Group,{position:"right",children:[e(t.Button,{variant:"default",size:"sm",onClick:o,leftIcon:e(y.PlaylistAdd,{size:20}),children:"Add a Panel"}),e(t.Button,{variant:"default",size:"sm",onClick:b,leftIcon:e(y.ClipboardText,{size:20}),children:"SQL Snippets"}),e(t.Button,{variant:"default",size:"sm",onClick:d,leftIcon:e(y.Database,{size:20}),children:"Data Sources"}),e(t.Button,{variant:"default",size:"sm",onClick:a,disabled:!i,leftIcon:e(y.DeviceFloppy,{size:20}),children:"Save Changes"}),e(t.Button,{color:"red",size:"sm",disabled:!i,leftIcon:e(y.Recycle,{size:20}),children:"Revert Changes"})]}),e(Et,{opened:s,close:m}),e(At,{opened:p,close:x})]}),!S&&e(t.Button,{variant:"default",size:"sm",disabled:!0,leftIcon:e(y.Share,{size:20}),children:"Share"})]})}function Bt({context:n,dashboard:r,update:i,className:o="dashboard"}){const[a,s]=u.default.useState(!1),[l,d]=u.default.useState(),[m,p]=u.default.useState(),[g,b]=u.default.useState(r.panels),[x,S]=u.default.useState(r.definition.sqlSnippets),[T,G]=u.default.useState(r.definition.dataSources),[L,$]=u.default.useState(q.Edit),k=u.default.useMemo(()=>{const A=j=>JSON.parse(JSON.stringify(j));return!w.default.isEqual(A(g),A(r.panels))||!w.default.isEqual(x,r.definition.sqlSnippets)?!0:!w.default.isEqual(T,r.definition.dataSources)},[r,g,x,T]),H=async()=>{const A=w.default.merge({},r,{panels:g},{definition:{sqlSnippets:x,dataSources:T}});await i(A)},se=()=>{const A=O.randomId(),X={id:A,layout:{x:0,y:1/0,w:3,h:4},title:`New Panel - ${A}`,description:"description goes here",dataSourceID:"",viz:{type:"table",conf:{}}};b(j=>[...j,X])},ue=A=>{const X=g.findIndex(j=>j.id===A);b(j=>(j.splice(X,1),[...j]))},J=L===q.Edit,Nt=u.default.useMemo(()=>({sqlSnippets:x,setSQLSnippets:S,dataSources:T,setDataSources:G}),[x,S,T,G]);return e(R.Provider,{value:n,children:e("div",{className:o,children:e(P.Provider,{value:Nt,children:c(B.Provider,{value:{layoutFrozen:a,freezeLayout:s,mode:L,inEditMode:J},children:[e(Mt,{mode:L,setMode:$,hasChanges:k,addPanel:se,saveChanges:H}),e(Ce,{panels:g,setPanels:b,isDraggable:J&&!a,isResizable:J&&!a,onRemoveItem:ue,setLocalCols:p,setBreakpoint:d})]})})})})}const Ft=D.WidthProvider(D.Responsive);function $t({panels:n,className:r="layout",cols:i={lg:12,md:10,sm:8,xs:6,xxs:4},rowHeight:o=10}){return e(Ft,{className:r,cols:i,rowHeight:o,isDraggable:!1,isResizable:!1,children:n.map(l=>{var d=l,{id:a}=d,s=z(d,["id"]);return e("div",{"data-grid":s.layout,children:e(le,h({id:a},s))},a)})})}function jt({context:n,dashboard:r,className:i="dashboard"}){const o=u.default.useMemo(()=>E(h({},r.definition),{setSQLSnippets:()=>{},setDataSources:()=>{}}),[r]);return e(R.Provider,{value:n,children:e("div",{className:i,children:e(P.Provider,{value:o,children:e(B.Provider,{value:{layoutFrozen:!0,freezeLayout:()=>{},mode:q.Use,inEditMode:!1},children:e($t,{panels:r.panels})})})})})}f.ContextInfoContext=R,f.Dashboard=Bt,f.DashboardLayout=Ce,f.DashboardMode=q,f.DefinitionContext=P,f.LayoutStateContext=B,f.Panel=le,f.PanelContext=_,f.ReadOnlyDashboard=jt,f.initialContextInfoContext=Fe,Object.defineProperties(f,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
33
+ `}),e(t.Group,{direction:"column",sx:{width:"100%",position:"relative"},grow:!0,children:c("form",{onSubmit:a.onSubmit(d),children:[a.values.snippets.map((f,m)=>c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[e(t.TextInput,h({label:"Key",required:!0},a.getListInputProps("snippets",m,"key"))),e(t.Textarea,h({minRows:3,label:"Value",required:!0},a.getListInputProps("snippets",m,"value"))),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>a.removeListItem("snippets",m),sx:{position:"absolute",top:15,right:5},children:e(v.Trash,{size:16})})]},m)),e(t.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"40%"},mx:"auto",children:e(t.Button,{variant:"default",onClick:l,children:"Add a snippet"})})]})})]})]})}function Vt({opened:n,close:i}){const{freezeLayout:r}=u.default.useContext(R);return u.default.useEffect(()=>{r(n)},[n]),e(t.Modal,{size:"96vw",overflow:"inside",opened:n,onClose:i,title:"SQL Snippets",trapFocus:!0,onDragStart:o=>{o.stopPropagation()},children:e(t.AppShell,{sx:{height:"90vh",maxHeight:"calc(100vh - 185px)",".mantine-AppShell-body":{height:"100%"},main:{height:"100%",width:"100%",padding:0,margin:0}},padding:"md",children:c(t.Group,{direction:"row",position:"apart",grow:!0,align:"stretch",noWrap:!0,children:[e($t,{}),e(Rt,{})]})})})}function Nt({mode:n,setMode:i,hasChanges:r,addPanel:o,saveChanges:a}){const[l,s]=u.default.useState(!1),d=()=>s(!0),f=()=>s(!1),[m,p]=u.default.useState(!1),b=()=>p(!0),g=()=>p(!1),S=n===q.Edit;return c(t.Group,{position:"apart",pt:"sm",pb:"xs",children:[e(t.Group,{position:"left",children:e(Et,{mode:n,setMode:i})}),S&&c(oe,{children:[c(t.Group,{position:"right",children:[e(t.Button,{variant:"default",size:"sm",onClick:o,leftIcon:e(v.PlaylistAdd,{size:20}),children:"Add a Panel"}),e(t.Button,{variant:"default",size:"sm",onClick:b,leftIcon:e(v.ClipboardText,{size:20}),children:"SQL Snippets"}),e(t.Button,{variant:"default",size:"sm",onClick:d,leftIcon:e(v.Database,{size:20}),children:"Data Sources"}),e(t.Button,{variant:"default",size:"sm",onClick:a,disabled:!r,leftIcon:e(v.DeviceFloppy,{size:20}),children:"Save Changes"}),e(t.Button,{color:"red",size:"sm",disabled:!r,leftIcon:e(v.Recycle,{size:20}),children:"Revert Changes"})]}),e(Ft,{opened:l,close:f}),e(Vt,{opened:m,close:g})]}),!S&&e(t.Button,{variant:"default",size:"sm",disabled:!0,leftIcon:e(v.Share,{size:20}),children:"Share"})]})}function jt({context:n,dashboard:i,update:r,className:o="dashboard"}){const[a,l]=u.default.useState(!1),[s,d]=u.default.useState(),[f,m]=u.default.useState(),[p,b]=u.default.useState(i.panels),[g,S]=u.default.useState(i.definition.sqlSnippets),[y,_]=u.default.useState(i.definition.dataSources),[G,k]=u.default.useState(q.Edit),z=u.default.useMemo(()=>{const M=V=>JSON.parse(JSON.stringify(V));return!T.default.isEqual(M(p),M(i.panels))||!T.default.isEqual(g,i.definition.sqlSnippets)?!0:!T.default.isEqual(y,i.definition.dataSources)},[i,p,g,y]),te=async()=>{const M=T.default.merge({},i,{panels:p},{definition:{sqlSnippets:g,dataSources:y}});await r(M)},ue=()=>{const M=A.randomId(),ne={id:M,layout:{x:0,y:1/0,w:3,h:4},title:`New Panel - ${M}`,description:"description goes here",dataSourceID:"",viz:{type:"table",conf:{}}};b(V=>[...V,ne])},de=M=>{const ne=p.findIndex(V=>V.id===M);b(V=>(V.splice(ne,1),[...V]))},J=G===q.Edit,Ut=u.default.useMemo(()=>({sqlSnippets:g,setSQLSnippets:S,dataSources:y,setDataSources:_}),[g,S,y,_]);return e(W.Provider,{value:n,children:e("div",{className:o,children:e(O.Provider,{value:Ut,children:c(R.Provider,{value:{layoutFrozen:a,freezeLayout:l,mode:G,inEditMode:J},children:[e(Nt,{mode:G,setMode:k,hasChanges:z,addPanel:ue,saveChanges:te}),e(we,{panels:p,setPanels:b,isDraggable:J&&!a,isResizable:J&&!a,onRemoveItem:de,setLocalCols:m,setBreakpoint:d})]})})})})}const Wt=D.WidthProvider(D.Responsive);function Qt({panels:n,className:i="layout",cols:r={lg:12,md:10,sm:8,xs:6,xxs:4},rowHeight:o=10}){return e(Wt,{className:i,cols:r,rowHeight:o,isDraggable:!1,isResizable:!1,children:n.map(s=>{var d=s,{id:a}=d,l=P(d,["id"]);return e("div",{"data-grid":l.layout,children:e(se,h({id:a},l))},a)})})}function Jt({context:n,dashboard:i,className:r="dashboard"}){const o=u.default.useMemo(()=>E(h({},i.definition),{setSQLSnippets:()=>{},setDataSources:()=>{}}),[i]);return e(W.Provider,{value:n,children:e("div",{className:r,children:e(O.Provider,{value:o,children:e(R.Provider,{value:{layoutFrozen:!0,freezeLayout:()=>{},mode:q.Use,inEditMode:!1},children:e(Qt,{panels:i.panels})})})})})}x.ContextInfoContext=W,x.Dashboard=jt,x.DashboardLayout=we,x.DashboardMode=q,x.DefinitionContext=O,x.LayoutStateContext=R,x.Panel=se,x.PanelContext=L,x.ReadOnlyDashboard=Jt,x.initialContextInfoContext=Fe,Object.defineProperties(x,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -2,5 +2,5 @@
2
2
  interface IDataSourceEditor {
3
3
  id: string;
4
4
  }
5
- export declare function DataSourceEditor({ id }: IDataSourceEditor): JSX.Element;
5
+ export declare function DataSourceEditor({ id }: IDataSourceEditor): JSX.Element | null;
6
6
  export {};
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ interface IVizPie {
3
+ conf: any;
4
+ data: any[];
5
+ width: number;
6
+ height: number;
7
+ }
8
+ export declare function VizPie({ conf, data, width, height }: IVizPie): JSX.Element;
9
+ export {};
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ import { IVizPanelProps } from "../../../types/viz-panel";
3
+ export declare function VizPiePanel({ conf: { label_field, value_field }, setConf }: IVizPanelProps): JSX.Element;
@@ -13,7 +13,7 @@ export interface ITableConf {
13
13
  id_field: string;
14
14
  use_raw_columns: boolean;
15
15
  columns: IColumnConf[];
16
- size: string;
16
+ fontSize: string;
17
17
  horizontalSpacing: string;
18
18
  verticalSpacing: string;
19
19
  striped: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devtable/dashboard",
3
- "version": "1.4.0",
3
+ "version": "1.7.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org/"