@devtable/dashboard 1.5.0 → 1.8.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.
- package/dist/contexts/layout-state-context.d.ts +2 -0
- package/dist/dashboard.es.js +268 -78
- package/dist/dashboard.umd.js +8 -7
- package/dist/definition-editor/data-source-editor/editor.d.ts +1 -1
- package/dist/panel/viz/pie/index.d.ts +9 -0
- package/dist/panel/viz/pie/panel.d.ts +3 -0
- package/dist/panel/viz/table/type.d.ts +1 -1
- package/dist/types/dashboard.d.ts +1 -0
- package/package.json +1 -1
|
@@ -5,5 +5,7 @@ export interface ILayoutStateContext {
|
|
|
5
5
|
freezeLayout: React.Dispatch<React.SetStateAction<boolean>>;
|
|
6
6
|
mode: DashboardMode;
|
|
7
7
|
inEditMode: boolean;
|
|
8
|
+
inLayoutMode: boolean;
|
|
9
|
+
inUseMode: boolean;
|
|
8
10
|
}
|
|
9
11
|
export declare const LayoutStateContext: React.Context<ILayoutStateContext>;
|
package/dist/dashboard.es.js
CHANGED
|
@@ -35,12 +35,12 @@ import { WidthProvider, Responsive } from "react-grid-layout";
|
|
|
35
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, Refresh, Trash, Settings, Paint, PlayerPlay, PlaylistAdd, ClipboardText, Database, Recycle, Share } from "tabler-icons-react";
|
|
38
|
+
import { InfoCircle, DeviceFloppy, Refresh, Trash, Settings, Resize, 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";
|
|
@@ -50,6 +50,7 @@ import { formList, useForm as useForm$1 } from "@mantine/form";
|
|
|
50
50
|
import { Prism } from "@mantine/prism";
|
|
51
51
|
var DashboardMode = /* @__PURE__ */ ((DashboardMode2) => {
|
|
52
52
|
DashboardMode2["Use"] = "use";
|
|
53
|
+
DashboardMode2["Layout"] = "layout";
|
|
53
54
|
DashboardMode2["Edit"] = "edit";
|
|
54
55
|
return DashboardMode2;
|
|
55
56
|
})(DashboardMode || {});
|
|
@@ -58,7 +59,9 @@ const initialContext$3 = {
|
|
|
58
59
|
freezeLayout: () => {
|
|
59
60
|
},
|
|
60
61
|
mode: DashboardMode.Edit,
|
|
61
|
-
inEditMode: false
|
|
62
|
+
inEditMode: false,
|
|
63
|
+
inLayoutMode: false,
|
|
64
|
+
inUseMode: true
|
|
62
65
|
};
|
|
63
66
|
const LayoutStateContext = React.createContext(initialContext$3);
|
|
64
67
|
const getRequest = (method) => {
|
|
@@ -216,7 +219,7 @@ function DescriptionPopover({
|
|
|
216
219
|
React.useEffect(() => {
|
|
217
220
|
freezeLayout(opened);
|
|
218
221
|
}, [opened]);
|
|
219
|
-
if (!description) {
|
|
222
|
+
if (!description || description === "<p><br></p>") {
|
|
220
223
|
return null;
|
|
221
224
|
}
|
|
222
225
|
const target = trigger === "click" ? /* @__PURE__ */ jsx(Tooltip, {
|
|
@@ -463,7 +466,8 @@ function DataPreview({
|
|
|
463
466
|
});
|
|
464
467
|
if (loading) {
|
|
465
468
|
return /* @__PURE__ */ jsx(LoadingOverlay, {
|
|
466
|
-
visible: loading
|
|
469
|
+
visible: loading,
|
|
470
|
+
exitTransitionDuration: 0
|
|
467
471
|
});
|
|
468
472
|
}
|
|
469
473
|
if (data.length === 0) {
|
|
@@ -578,7 +582,7 @@ function PickDataSource({}) {
|
|
|
578
582
|
});
|
|
579
583
|
}
|
|
580
584
|
echarts.use([SunburstChart, CanvasRenderer]);
|
|
581
|
-
const defaultOption$
|
|
585
|
+
const defaultOption$2 = {
|
|
582
586
|
tooltip: {
|
|
583
587
|
show: true
|
|
584
588
|
},
|
|
@@ -628,7 +632,7 @@ function Sunbrust({
|
|
|
628
632
|
}
|
|
629
633
|
}
|
|
630
634
|
}), [max]);
|
|
631
|
-
const option = _.merge({}, defaultOption$
|
|
635
|
+
const option = _.merge({}, defaultOption$2, labelOption, restConf, {
|
|
632
636
|
series: {
|
|
633
637
|
data: chartData
|
|
634
638
|
}
|
|
@@ -643,7 +647,7 @@ function Sunbrust({
|
|
|
643
647
|
});
|
|
644
648
|
}
|
|
645
649
|
echarts.use([BarChart, LineChart, GridComponent, LegendComponent, TooltipComponent, CanvasRenderer]);
|
|
646
|
-
const defaultOption = {
|
|
650
|
+
const defaultOption$1 = {
|
|
647
651
|
legend: {
|
|
648
652
|
show: true,
|
|
649
653
|
bottom: 0,
|
|
@@ -760,7 +764,7 @@ function VizLineBarChart({
|
|
|
760
764
|
}
|
|
761
765
|
}
|
|
762
766
|
};
|
|
763
|
-
return _.merge({}, defaultOption, customOptions);
|
|
767
|
+
return _.merge({}, defaultOption$1, customOptions);
|
|
764
768
|
}, [conf, data]);
|
|
765
769
|
if (!width || !height) {
|
|
766
770
|
return null;
|
|
@@ -845,7 +849,7 @@ function CellValue({
|
|
|
845
849
|
}
|
|
846
850
|
function VizTable({
|
|
847
851
|
conf,
|
|
848
|
-
data,
|
|
852
|
+
data = [],
|
|
849
853
|
width,
|
|
850
854
|
height
|
|
851
855
|
}) {
|
|
@@ -886,7 +890,7 @@ function VizTable({
|
|
|
886
890
|
}, label))
|
|
887
891
|
})
|
|
888
892
|
}), /* @__PURE__ */ jsx("tbody", {
|
|
889
|
-
children: data.map((row, index2) => /* @__PURE__ */ jsx("tr", {
|
|
893
|
+
children: data.slice(0, 30).map((row, index2) => /* @__PURE__ */ jsx("tr", {
|
|
890
894
|
children: finalColumns.map(({
|
|
891
895
|
value_field,
|
|
892
896
|
value_type
|
|
@@ -894,7 +898,8 @@ function VizTable({
|
|
|
894
898
|
children: /* @__PURE__ */ jsx(Group, {
|
|
895
899
|
sx: {
|
|
896
900
|
"&, .mantine-Text-root": {
|
|
897
|
-
fontFamily: "monospace"
|
|
901
|
+
fontFamily: "monospace",
|
|
902
|
+
fontSize: rest.fontSize
|
|
898
903
|
}
|
|
899
904
|
},
|
|
900
905
|
children: /* @__PURE__ */ jsx(CellValue, {
|
|
@@ -904,12 +909,26 @@ function VizTable({
|
|
|
904
909
|
})
|
|
905
910
|
}, row[value_field]))
|
|
906
911
|
}, id_field ? row[id_field] : `row-${index2}`))
|
|
912
|
+
}), data.length > 100 && /* @__PURE__ */ jsx("tfoot", {
|
|
913
|
+
children: /* @__PURE__ */ jsx("tr", {
|
|
914
|
+
children: /* @__PURE__ */ jsx("td", {
|
|
915
|
+
colSpan: labels.length,
|
|
916
|
+
children: /* @__PURE__ */ jsx(Text, {
|
|
917
|
+
color: "red",
|
|
918
|
+
size: "sm",
|
|
919
|
+
children: "Showing only the first 30 rows to avoid causing slow performance"
|
|
920
|
+
})
|
|
921
|
+
})
|
|
922
|
+
})
|
|
907
923
|
})]
|
|
908
924
|
}));
|
|
909
925
|
}
|
|
910
926
|
function interpolateString(template, params = {}) {
|
|
911
|
-
const
|
|
912
|
-
|
|
927
|
+
const extendedParams = __spreadProps(__spreadValues({}, params), {
|
|
928
|
+
numbro
|
|
929
|
+
});
|
|
930
|
+
const names = Object.keys(extendedParams);
|
|
931
|
+
const vals = Object.values(extendedParams);
|
|
913
932
|
try {
|
|
914
933
|
return new Function(...names, `return \`${template}\`;`)(...vals);
|
|
915
934
|
} catch (error) {
|
|
@@ -1013,6 +1032,87 @@ function VizBar3D({
|
|
|
1013
1032
|
});
|
|
1014
1033
|
}
|
|
1015
1034
|
var index$2 = "";
|
|
1035
|
+
echarts.use([PieChart, CanvasRenderer]);
|
|
1036
|
+
const defaultOption = {
|
|
1037
|
+
tooltip: {
|
|
1038
|
+
show: true
|
|
1039
|
+
},
|
|
1040
|
+
series: {
|
|
1041
|
+
type: "pie",
|
|
1042
|
+
radius: ["50%", "80%"],
|
|
1043
|
+
label: {
|
|
1044
|
+
position: "outer",
|
|
1045
|
+
alignTo: "edge",
|
|
1046
|
+
formatter: "{name|{b}}\n{percentage|{d}%}",
|
|
1047
|
+
minMargin: 5,
|
|
1048
|
+
edgeDistance: 10,
|
|
1049
|
+
lineHeight: 15,
|
|
1050
|
+
rich: {
|
|
1051
|
+
percentage: {
|
|
1052
|
+
color: "#999"
|
|
1053
|
+
}
|
|
1054
|
+
},
|
|
1055
|
+
margin: 20
|
|
1056
|
+
},
|
|
1057
|
+
labelLine: {
|
|
1058
|
+
length: 15,
|
|
1059
|
+
length2: 0,
|
|
1060
|
+
maxSurfaceAngle: 80,
|
|
1061
|
+
showAbove: true
|
|
1062
|
+
},
|
|
1063
|
+
top: 10,
|
|
1064
|
+
bottom: 10,
|
|
1065
|
+
left: 10,
|
|
1066
|
+
right: 10
|
|
1067
|
+
}
|
|
1068
|
+
};
|
|
1069
|
+
function VizPie({
|
|
1070
|
+
conf,
|
|
1071
|
+
data,
|
|
1072
|
+
width,
|
|
1073
|
+
height
|
|
1074
|
+
}) {
|
|
1075
|
+
const _a = conf, {
|
|
1076
|
+
label_field = "name",
|
|
1077
|
+
value_field = "value"
|
|
1078
|
+
} = _a, restConf = __objRest(_a, [
|
|
1079
|
+
"label_field",
|
|
1080
|
+
"value_field"
|
|
1081
|
+
]);
|
|
1082
|
+
const chartData = React.useMemo(() => {
|
|
1083
|
+
return data.map((d) => ({
|
|
1084
|
+
name: d[label_field],
|
|
1085
|
+
value: Number(d[value_field])
|
|
1086
|
+
}));
|
|
1087
|
+
}, [data, label_field, value_field]);
|
|
1088
|
+
const labelOptions = React.useMemo(() => {
|
|
1089
|
+
return {
|
|
1090
|
+
series: {
|
|
1091
|
+
labelLayout: function(params) {
|
|
1092
|
+
const isLeft = params.labelRect.x < width / 2;
|
|
1093
|
+
const points = params.labelLinePoints;
|
|
1094
|
+
points[2][0] = isLeft ? params.labelRect.x : params.labelRect.x + params.labelRect.width;
|
|
1095
|
+
return {
|
|
1096
|
+
labelLinePoints: points
|
|
1097
|
+
};
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
};
|
|
1101
|
+
}, [width]);
|
|
1102
|
+
const option = _.merge({}, defaultOption, labelOptions, restConf, {
|
|
1103
|
+
series: {
|
|
1104
|
+
data: chartData
|
|
1105
|
+
}
|
|
1106
|
+
});
|
|
1107
|
+
return /* @__PURE__ */ jsx(ReactEChartsCore, {
|
|
1108
|
+
echarts,
|
|
1109
|
+
option,
|
|
1110
|
+
style: {
|
|
1111
|
+
width,
|
|
1112
|
+
height
|
|
1113
|
+
}
|
|
1114
|
+
});
|
|
1115
|
+
}
|
|
1016
1116
|
function renderViz(width, height, data, viz) {
|
|
1017
1117
|
const props = {
|
|
1018
1118
|
width,
|
|
@@ -1031,6 +1131,8 @@ function renderViz(width, height, data, viz) {
|
|
|
1031
1131
|
return /* @__PURE__ */ jsx(VizText, __spreadValues({}, props));
|
|
1032
1132
|
case "bar-3d":
|
|
1033
1133
|
return /* @__PURE__ */ jsx(VizBar3D, __spreadValues({}, props));
|
|
1134
|
+
case "pie":
|
|
1135
|
+
return /* @__PURE__ */ jsx(VizPie, __spreadValues({}, props));
|
|
1034
1136
|
default:
|
|
1035
1137
|
return null;
|
|
1036
1138
|
}
|
|
@@ -1051,7 +1153,8 @@ function Viz({
|
|
|
1051
1153
|
className: "viz-root",
|
|
1052
1154
|
ref,
|
|
1053
1155
|
children: /* @__PURE__ */ jsx(LoadingOverlay, {
|
|
1054
|
-
visible: loading
|
|
1156
|
+
visible: loading,
|
|
1157
|
+
exitTransitionDuration: 0
|
|
1055
1158
|
})
|
|
1056
1159
|
});
|
|
1057
1160
|
}
|
|
@@ -1535,6 +1638,72 @@ function VizLineBarChartPanel({
|
|
|
1535
1638
|
})
|
|
1536
1639
|
});
|
|
1537
1640
|
}
|
|
1641
|
+
function VizPiePanel({
|
|
1642
|
+
conf: {
|
|
1643
|
+
label_field,
|
|
1644
|
+
value_field
|
|
1645
|
+
},
|
|
1646
|
+
setConf
|
|
1647
|
+
}) {
|
|
1648
|
+
const form = useForm$1({
|
|
1649
|
+
initialValues: {
|
|
1650
|
+
label_field,
|
|
1651
|
+
value_field
|
|
1652
|
+
}
|
|
1653
|
+
});
|
|
1654
|
+
return /* @__PURE__ */ jsx(Group, {
|
|
1655
|
+
direction: "column",
|
|
1656
|
+
mt: "md",
|
|
1657
|
+
spacing: "xs",
|
|
1658
|
+
grow: true,
|
|
1659
|
+
children: /* @__PURE__ */ jsxs("form", {
|
|
1660
|
+
onSubmit: form.onSubmit(setConf),
|
|
1661
|
+
children: [/* @__PURE__ */ jsxs(Group, {
|
|
1662
|
+
position: "apart",
|
|
1663
|
+
mb: "lg",
|
|
1664
|
+
sx: {
|
|
1665
|
+
position: "relative"
|
|
1666
|
+
},
|
|
1667
|
+
children: [/* @__PURE__ */ jsx(Text, {
|
|
1668
|
+
children: "Pie Config"
|
|
1669
|
+
}), /* @__PURE__ */ jsx(ActionIcon, {
|
|
1670
|
+
type: "submit",
|
|
1671
|
+
mr: 5,
|
|
1672
|
+
variant: "filled",
|
|
1673
|
+
color: "blue",
|
|
1674
|
+
children: /* @__PURE__ */ jsx(DeviceFloppy, {
|
|
1675
|
+
size: 20
|
|
1676
|
+
})
|
|
1677
|
+
})]
|
|
1678
|
+
}), /* @__PURE__ */ jsxs(Group, {
|
|
1679
|
+
direction: "column",
|
|
1680
|
+
mt: "md",
|
|
1681
|
+
spacing: "xs",
|
|
1682
|
+
grow: true,
|
|
1683
|
+
p: "md",
|
|
1684
|
+
mb: "sm",
|
|
1685
|
+
sx: {
|
|
1686
|
+
border: "1px solid #eee",
|
|
1687
|
+
borderRadius: "5px"
|
|
1688
|
+
},
|
|
1689
|
+
children: [/* @__PURE__ */ jsx(TextInput, __spreadValues({
|
|
1690
|
+
label: "Label Field",
|
|
1691
|
+
required: true,
|
|
1692
|
+
sx: {
|
|
1693
|
+
flex: 1
|
|
1694
|
+
}
|
|
1695
|
+
}, form.getInputProps("label_field"))), /* @__PURE__ */ jsx(TextInput, __spreadValues({
|
|
1696
|
+
label: "Value Field",
|
|
1697
|
+
placeholder: "get column value by this field",
|
|
1698
|
+
required: true,
|
|
1699
|
+
sx: {
|
|
1700
|
+
flex: 1
|
|
1701
|
+
}
|
|
1702
|
+
}, form.getInputProps("value_field")))]
|
|
1703
|
+
})]
|
|
1704
|
+
})
|
|
1705
|
+
});
|
|
1706
|
+
}
|
|
1538
1707
|
function SunburstPanel({
|
|
1539
1708
|
conf: {
|
|
1540
1709
|
label_field,
|
|
@@ -1634,7 +1803,7 @@ function VizTablePanel(_a) {
|
|
|
1634
1803
|
id_field: "id",
|
|
1635
1804
|
use_raw_columns: true,
|
|
1636
1805
|
columns: formList(columns != null ? columns : []),
|
|
1637
|
-
|
|
1806
|
+
fontSize: "sm",
|
|
1638
1807
|
horizontalSpacing: "sm",
|
|
1639
1808
|
verticalSpacing: "sm",
|
|
1640
1809
|
striped: false,
|
|
@@ -1725,7 +1894,7 @@ function VizTablePanel(_a) {
|
|
|
1725
1894
|
sx: {
|
|
1726
1895
|
flex: 1
|
|
1727
1896
|
}
|
|
1728
|
-
}, form.getInputProps("
|
|
1897
|
+
}, form.getInputProps("fontSize")))
|
|
1729
1898
|
}), /* @__PURE__ */ jsxs(Group, {
|
|
1730
1899
|
direction: "column",
|
|
1731
1900
|
grow: true,
|
|
@@ -2041,6 +2210,10 @@ const types = [{
|
|
|
2041
2210
|
value: "line-bar",
|
|
2042
2211
|
label: "Line-Bar Chart",
|
|
2043
2212
|
Panel: VizLineBarChartPanel
|
|
2213
|
+
}, {
|
|
2214
|
+
value: "pie",
|
|
2215
|
+
label: "Pie Chart",
|
|
2216
|
+
Panel: VizPiePanel
|
|
2044
2217
|
}];
|
|
2045
2218
|
function EditVizConf() {
|
|
2046
2219
|
const {
|
|
@@ -2170,7 +2343,8 @@ function PanelSettingsModal({
|
|
|
2170
2343
|
children: [/* @__PURE__ */ jsxs(Tabs.Tab, {
|
|
2171
2344
|
label: "Data Source",
|
|
2172
2345
|
children: [/* @__PURE__ */ jsx(LoadingOverlay, {
|
|
2173
|
-
visible: loading
|
|
2346
|
+
visible: loading,
|
|
2347
|
+
exitTransitionDuration: 0
|
|
2174
2348
|
}), /* @__PURE__ */ jsx(PickDataSource, {})]
|
|
2175
2349
|
}), /* @__PURE__ */ jsx(Tabs.Tab, {
|
|
2176
2350
|
label: "Panel",
|
|
@@ -2408,10 +2582,15 @@ function ModeToggler({
|
|
|
2408
2582
|
size: 20
|
|
2409
2583
|
}), "Use"),
|
|
2410
2584
|
value: DashboardMode.Use
|
|
2585
|
+
}, {
|
|
2586
|
+
label: renderLabel(/* @__PURE__ */ jsx(Resize, {
|
|
2587
|
+
size: 20
|
|
2588
|
+
}), "Layout"),
|
|
2589
|
+
value: DashboardMode.Layout
|
|
2411
2590
|
}, {
|
|
2412
2591
|
label: renderLabel(/* @__PURE__ */ jsx(Paint, {
|
|
2413
2592
|
size: 20
|
|
2414
|
-
}), "
|
|
2593
|
+
}), "Content"),
|
|
2415
2594
|
value: DashboardMode.Edit
|
|
2416
2595
|
}]
|
|
2417
2596
|
});
|
|
@@ -2631,7 +2810,7 @@ function DataSourceEditor({
|
|
|
2631
2810
|
}, [dataSources, id]);
|
|
2632
2811
|
const update = React.useCallback((value) => {
|
|
2633
2812
|
const index2 = dataSources.findIndex((d) => d.id === id);
|
|
2634
|
-
if (
|
|
2813
|
+
if (index2 === -1) {
|
|
2635
2814
|
console.error(new Error("Invalid data source id when updating by id"));
|
|
2636
2815
|
return;
|
|
2637
2816
|
}
|
|
@@ -2640,7 +2819,10 @@ function DataSourceEditor({
|
|
|
2640
2819
|
prevs.splice(index22, 1, value);
|
|
2641
2820
|
return [...prevs];
|
|
2642
2821
|
});
|
|
2643
|
-
}, [id, setDataSources]);
|
|
2822
|
+
}, [id, dataSources, setDataSources]);
|
|
2823
|
+
if (!id) {
|
|
2824
|
+
return null;
|
|
2825
|
+
}
|
|
2644
2826
|
if (!dataSource) {
|
|
2645
2827
|
return /* @__PURE__ */ jsx("span", {
|
|
2646
2828
|
children: "Invalid Data Source ID"
|
|
@@ -3020,13 +3202,17 @@ function DashboardActions({
|
|
|
3020
3202
|
addPanel,
|
|
3021
3203
|
saveChanges
|
|
3022
3204
|
}) {
|
|
3205
|
+
const {
|
|
3206
|
+
inLayoutMode,
|
|
3207
|
+
inEditMode,
|
|
3208
|
+
inUseMode
|
|
3209
|
+
} = React.useContext(LayoutStateContext);
|
|
3023
3210
|
const [dataSourcesOpened, setDataSourcesOpened] = React.useState(false);
|
|
3024
3211
|
const openDataSources = () => setDataSourcesOpened(true);
|
|
3025
3212
|
const closeDataSources = () => setDataSourcesOpened(false);
|
|
3026
3213
|
const [sqlSnippetsOpened, setSQLSnippetsOpened] = React.useState(false);
|
|
3027
3214
|
const openSQLSnippets = () => setSQLSnippetsOpened(true);
|
|
3028
3215
|
const closeSQLSnippets = () => setSQLSnippetsOpened(false);
|
|
3029
|
-
const inEditMode = mode === DashboardMode.Edit;
|
|
3030
3216
|
return /* @__PURE__ */ jsxs(Group, {
|
|
3031
3217
|
position: "apart",
|
|
3032
3218
|
pt: "sm",
|
|
@@ -3037,59 +3223,57 @@ function DashboardActions({
|
|
|
3037
3223
|
mode,
|
|
3038
3224
|
setMode
|
|
3039
3225
|
})
|
|
3040
|
-
}),
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
children: "Revert Changes"
|
|
3084
|
-
})]
|
|
3085
|
-
}), /* @__PURE__ */ jsx(EditDataSourcesModal, {
|
|
3086
|
-
opened: dataSourcesOpened,
|
|
3087
|
-
close: closeDataSources
|
|
3088
|
-
}), /* @__PURE__ */ jsx(EditSQLSnippetsModal, {
|
|
3089
|
-
opened: sqlSnippetsOpened,
|
|
3090
|
-
close: closeSQLSnippets
|
|
3226
|
+
}), /* @__PURE__ */ jsxs(Group, {
|
|
3227
|
+
position: "right",
|
|
3228
|
+
children: [inLayoutMode && /* @__PURE__ */ jsx(Button, {
|
|
3229
|
+
variant: "default",
|
|
3230
|
+
size: "sm",
|
|
3231
|
+
onClick: addPanel,
|
|
3232
|
+
leftIcon: /* @__PURE__ */ jsx(PlaylistAdd, {
|
|
3233
|
+
size: 20
|
|
3234
|
+
}),
|
|
3235
|
+
children: "Add a Panel"
|
|
3236
|
+
}), inEditMode && /* @__PURE__ */ jsx(Button, {
|
|
3237
|
+
variant: "default",
|
|
3238
|
+
size: "sm",
|
|
3239
|
+
onClick: openSQLSnippets,
|
|
3240
|
+
leftIcon: /* @__PURE__ */ jsx(ClipboardText, {
|
|
3241
|
+
size: 20
|
|
3242
|
+
}),
|
|
3243
|
+
children: "SQL Snippets"
|
|
3244
|
+
}), inEditMode && /* @__PURE__ */ jsx(Button, {
|
|
3245
|
+
variant: "default",
|
|
3246
|
+
size: "sm",
|
|
3247
|
+
onClick: openDataSources,
|
|
3248
|
+
leftIcon: /* @__PURE__ */ jsx(Database, {
|
|
3249
|
+
size: 20
|
|
3250
|
+
}),
|
|
3251
|
+
children: "Data Sources"
|
|
3252
|
+
}), !inUseMode && /* @__PURE__ */ jsx(Button, {
|
|
3253
|
+
variant: "default",
|
|
3254
|
+
size: "sm",
|
|
3255
|
+
onClick: saveChanges,
|
|
3256
|
+
disabled: !hasChanges,
|
|
3257
|
+
leftIcon: /* @__PURE__ */ jsx(DeviceFloppy, {
|
|
3258
|
+
size: 20
|
|
3259
|
+
}),
|
|
3260
|
+
children: "Save Changes"
|
|
3261
|
+
}), !inUseMode && /* @__PURE__ */ jsx(Button, {
|
|
3262
|
+
color: "red",
|
|
3263
|
+
size: "sm",
|
|
3264
|
+
disabled: !hasChanges,
|
|
3265
|
+
leftIcon: /* @__PURE__ */ jsx(Recycle, {
|
|
3266
|
+
size: 20
|
|
3267
|
+
}),
|
|
3268
|
+
children: "Revert Changes"
|
|
3091
3269
|
})]
|
|
3092
|
-
}),
|
|
3270
|
+
}), /* @__PURE__ */ jsx(EditDataSourcesModal, {
|
|
3271
|
+
opened: dataSourcesOpened,
|
|
3272
|
+
close: closeDataSources
|
|
3273
|
+
}), /* @__PURE__ */ jsx(EditSQLSnippetsModal, {
|
|
3274
|
+
opened: sqlSnippetsOpened,
|
|
3275
|
+
close: closeSQLSnippets
|
|
3276
|
+
}), inUseMode && /* @__PURE__ */ jsx(Button, {
|
|
3093
3277
|
variant: "default",
|
|
3094
3278
|
size: "sm",
|
|
3095
3279
|
disabled: true,
|
|
@@ -3163,6 +3347,8 @@ function Dashboard({
|
|
|
3163
3347
|
});
|
|
3164
3348
|
};
|
|
3165
3349
|
const inEditMode = mode === DashboardMode.Edit;
|
|
3350
|
+
const inLayoutMode = mode === DashboardMode.Layout;
|
|
3351
|
+
const inUseMode = mode === DashboardMode.Use;
|
|
3166
3352
|
const definitions = React.useMemo(() => ({
|
|
3167
3353
|
sqlSnippets,
|
|
3168
3354
|
setSQLSnippets,
|
|
@@ -3180,7 +3366,9 @@ function Dashboard({
|
|
|
3180
3366
|
layoutFrozen,
|
|
3181
3367
|
freezeLayout,
|
|
3182
3368
|
mode,
|
|
3183
|
-
inEditMode
|
|
3369
|
+
inEditMode,
|
|
3370
|
+
inLayoutMode,
|
|
3371
|
+
inUseMode
|
|
3184
3372
|
},
|
|
3185
3373
|
children: [/* @__PURE__ */ jsx(DashboardActions, {
|
|
3186
3374
|
mode,
|
|
@@ -3191,8 +3379,8 @@ function Dashboard({
|
|
|
3191
3379
|
}), /* @__PURE__ */ jsx(DashboardLayout, {
|
|
3192
3380
|
panels,
|
|
3193
3381
|
setPanels,
|
|
3194
|
-
isDraggable:
|
|
3195
|
-
isResizable:
|
|
3382
|
+
isDraggable: inLayoutMode,
|
|
3383
|
+
isResizable: inLayoutMode,
|
|
3196
3384
|
onRemoveItem: removePanelByID,
|
|
3197
3385
|
setLocalCols,
|
|
3198
3386
|
setBreakpoint
|
|
@@ -3259,7 +3447,9 @@ function ReadOnlyDashboard({
|
|
|
3259
3447
|
freezeLayout: () => {
|
|
3260
3448
|
},
|
|
3261
3449
|
mode: DashboardMode.Use,
|
|
3262
|
-
inEditMode: false
|
|
3450
|
+
inEditMode: false,
|
|
3451
|
+
inLayoutMode: false,
|
|
3452
|
+
inUseMode: true
|
|
3263
3453
|
},
|
|
3264
3454
|
children: /* @__PURE__ */ jsx(ReadOnlyDashboardLayout, {
|
|
3265
3455
|
panels: dashboard.panels
|
package/dist/dashboard.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
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,T,D,t,ie,ze,y,pe,M,Pe,Ie,J,U,N,Le,en,j,I,F){"use strict";var Yt=Object.defineProperty,Xt=Object.defineProperties;var Zt=Object.getOwnPropertyDescriptors;var ne=Object.getOwnPropertySymbols;var Ge=Object.prototype.hasOwnProperty,De=Object.prototype.propertyIsEnumerable;var _e=(x,w,T)=>w in x?Yt(x,w,{enumerable:!0,configurable:!0,writable:!0,value:T}):x[w]=T,m=(x,w)=>{for(var T in w||(w={}))Ge.call(w,T)&&_e(x,T,w[T]);if(ne)for(var T of ne(w))De.call(w,T)&&_e(x,T,w[T]);return x},E=(x,w)=>Xt(x,Zt(w));var z=(x,w)=>{var T={};for(var D in x)Ge.call(x,D)&&w.indexOf(D)<0&&(T[D]=x[D]);if(x!=null&&ne)for(var D of ne(x))w.indexOf(D)<0&&De.call(x,D)&&(T[D]=x[D]);return T};function Q(n){return n&&typeof n=="object"&&"default"in n?n:{default:n}}function ke(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),_=Q(T),Oe=Q(ze),Ee=Q(pe),H=Q(Pe),R=ke(Ie),K=Q(Le),L=(n=>(n.Use="use",n.Layout="layout",n.Edit="edit",n))(L||{});const Ae={layoutFrozen:!1,freezeLayout:()=>{},mode:L.Edit,inEditMode:!1,inLayoutMode:!1,inUseMode:!0},q=u.default.createContext(Ae),me=n=>(i,r,o={})=>{const a=m({"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),Oe.default(l).then(s=>s.data).catch(s=>Promise.reject(s))},Me=me("GET"),qe=me("POST");function fe(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 Be(n,i){const r=i.sqlSnippets.reduce((o,a)=>(o[a.key]=fe(a.value,n),o),{});return _.default.merge({},r,n)}const he=({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 h=Be(n,i),f=fe(s,h);return d&&(console.groupCollapsed(`Final SQL for: ${r}`),console.log(f),console.groupEnd()),await qe("/query",{type:a,key:l,sql:f})}catch(h){return console.error(h),[]}};async function Fe(){try{return await Me("/query/sources",{})}catch(n){return console.error(n),{}}}const xe={},Re=xe,W=u.default.createContext(xe),$e={data:[],loading:!1,title:"",setTitle:()=>{},description:"",setDescription:()=>{},dataSourceID:"",setDataSourceID:()=>{},viz:{type:"",conf:{}},setViz:()=>{},refreshData:()=>{}},k=u.default.createContext($e),Ve={sqlSnippets:[],setSQLSnippets:()=>{},dataSources:[],setDataSources:()=>{}},A=u.default.createContext(Ve);var Y={exports:{}},X={};/**
|
|
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,je=Symbol.for("react.element"),Ve=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={},l=null,s=null;i!==void 0&&(l=""+i),r.key!==void 0&&(l=""+r.key),r.ref!==void 0&&(s=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:je,type:n,key:l,ref:s,props:a,_owner:Qe.current}}K.Fragment=Ve,K.jsx=xe,K.jsxs=xe,U.exports=K;const e=U.exports.jsx,c=U.exports.jsxs,oe=U.exports.Fragment;function ge({position:n,trigger:r="click"}){const{freezeLayout:i}=u.default.useContext(F),[o,a]=u.default.useState(!1),{description:l}=u.default.useContext(P);if(u.default.useEffect(()=>{i(o)},[o]),!l)return null;const s=r==="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:_.default.noop,sx:{border:"none"}})})}function Ue(){const{description:n,setDescription:r}=u.default.useContext(P),[i,o]=u.default.useState(n),a=n!==i,l=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:l,children:e(v.DeviceFloppy,{size:20})})]}),e(ce.RichTextEditor,{value:i,onChange:o,sx:{flexGrow:1},sticky:!0,p:"0"})]})}class ae 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(P);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 Ye(){const{title:n,setTitle:r}=u.default.useContext(P),[i,o]=A.useInputState(n),a=n!==i,l=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:l,children:e(v.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(E),i=u.default.useContext(V),o=u.default.useMemo(()=>r.dataSources.find(d=>d.id===n),[r.dataSources,n]),{data:a=[],loading:l,refresh:s}=ee.useRequest(me({context:i,definitions:r,title:n,dataSource:o}),{refreshDeps:[i,r,o]});return l?e(t.LoadingOverlay,{visible:l}):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,x)=>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-${x}`))})]})]})}function Xe({}){const{dataSources:n}=u.default.useContext(E),{dataSourceID:r,setDataSourceID:i,data:o,loading:a}=u.default.useContext(P),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: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:l="value"}=b,s=I(b,["label_field","value_field"]),d=u.default.useMemo(()=>r.map(g=>({name:g[a],value:Number(g[l])})),[r,a,l]),x=u.default.useMemo(()=>{var g,S;return(S=(g=_.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/x<.2?" ":g}}}),[x]),p=_.default.merge({},Ze,m,s,{series:{data:d}});return e(re.default,{echarts:Q,option:p,style:{width:i,height:o}})}Q.use([te.BarChart,te.LineChart,N.GridComponent,N.LegendComponent,N.TooltipComponent,ne.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:r,width:i,height:o}){const a=u.default.useMemo(()=>{var x,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 ie.default(y).format(JSON.parse(g))}catch(T){return console.error(T),y}},p),{}),s=n.series.map(T=>{var D=T,{y_axis_data_key:p,y_axis_data_formatter:b,name:g,label_position:S="top"}=D,y=I(D,["y_axis_data_key","y_axis_data_formatter","name","label_position"]);const L=h({data:r.map(z=>z[p]),label:{show:!0,position:S},name:g},y);return b&&(L.label.formatter=l[g]),L}),d={xAxis:{data:r.map(p=>p[n.x_axis_data_key]),name:(x=n.x_axis_name)!=null?x:""},yAxis:{name:(m=n.y_axis_name)!=null?m:""},dataset:{source:r},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 _.default.merge({},tt,d)},[n,r]);return!i||!o?null:e(re.default,{echarts:Q,option:a,style:{width:i,height:o}})}var $=(n=>(n.string="string",n.number="number",n.eloc="eloc",n.percentage="percentage",n))($||{});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=ie.default(n).format({thousandSeparated:!0});return e(t.Text,{component:"span",children:r})}function at({value:n}){const r=ie.default(n).format({output:"percent",mantissa:3});return e(t.Text,{component:"span",children:r})}function lt({value:n,type:r}){switch(r){case $.string:return e(rt,{value:n});case $.eloc:return e(it,{value:n});case $.number:return e(ot,{value:n});case $.percentage:return e(at,{value:n})}}function st({conf:n,data:r,width:i,height:o}){const p=n,{id_field:a,use_raw_columns:l,columns:s}=p,d=I(p,["id_field","use_raw_columns","columns"]),x=u.default.useMemo(()=>l?Object.keys(r==null?void 0:r[0]):s.map(b=>b.label),[l,s,r]),m=u.default.useMemo(()=>l?Object.keys(r==null?void 0:r[0]).map(b=>({label:b,value_field:b,value_type:$.string})):s,[l,s,r]);return c(t.Table,O(h({sx:{maxHeight:o}},d),{children:[e("thead",{children:e("tr",{children:x.map(b=>e("th",{children:b},b))})}),e("tbody",{children:r.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"}},children:e(lt,{value:b[S],type:y})})},b[S]))},a?b[a]:`row-${g}`))})]}))}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(oe,{children:n.map((s,l)=>{var d=s,{template:i,size:o}=d,a=I(d,["template","size"]);return e(t.Text,O(h({},a),{sx:{fontSize:o},children:ut(i,r[0])}),`${i}---${l}`)})})}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:l,z_axis_data_key:s}=b,d=I(b,["x_axis_data_key","y_axis_data_key","z_axis_data_key"]),x=u.default.useMemo(()=>_.default.minBy(r,g=>g[s])[s],[r,s]),m=u.default.useMemo(()=>_.default.maxBy(r,g=>g[s])[s],[r,s]),p=O(h({tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:x,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:r.map(g=>[g[a],g[l],g[s]])}]});return e(re.default,{echarts:Q,option:p,style:{width:i,height:o}})}var Yt="";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:l}=A.useElementSize(),s=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:[s&&e(t.Text,{color:"gray",align:"center",children:"nothing to show"}),!s&&pt(a,l,r,n)]})}function ht({}){const{data:n,loading:r,viz:i}=u.default.useContext(P);return e(ae,{children:e(Se,{viz:i,data:n,loading:r})})}function mt({conf:n,setConf:r}){const i=_.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: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(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:r}){const i=t.useMantineTheme(),o=u.default.useMemo(()=>Object.entries(i.colors).map(([l,s])=>({label:l,value:s[6]})),[i]),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=>r(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: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}})]})}const ft=JSON.stringify({output:"percent",mantissa:2},null,2),xt=[{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 gt(n){function r({type:i,name:o,showSymbol:a,y_axis_data_key:l="value",y_axis_data_formatter:s="",label_position:d="top",stack:x="1",color:m="black"}){return{type:i,name:o,showSymbol:a,y_axis_data_key:l,y_axis_data_formatter:s,label_position:d,stack:x,color:m}}return n.map(r)}function bt({conf:n,setConf:r}){const x=n,{series:i}=x,o=I(x,["series"]),a=u.default.useMemo(()=>{const g=o,{x_axis_name:m="",y_axis_name:p=""}=g,b=I(g,["x_axis_name","y_axis_name"]);return h({series:k.formList(gt(i!=null?i:[])),x_axis_name:m,y_axis_name:p},b)},[i,o]),l=k.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(()=>!_.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(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",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:xt},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:ft,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 St({conf:{label_field:n,value_field:r},setConf:i}){const o=k.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(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 vt=Object.values($).map(n=>({label:n,value:n}));function yt({label:n,value:r,onChange:i,sx:o}){return e(t.Select,{label:n,data:vt,value:r,onChange:i,sx:o})}function wt(o){var a=o,{conf:l}=a,s=l,{columns:n}=s,r=I(s,["columns"]),{setConf:i}=a;const d=k.useForm({initialValues:h({id_field:"id",use_raw_columns:!0,columns:k.formList(n!=null?n:[]),size:"sm",horizontalSpacing:"sm",verticalSpacing:"sm",striped:!1,highlightOnHover:!1},r)}),x=()=>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(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(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("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((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(yt,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:x,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 Y=[{label:"initial",value:0},{label:"500",value:25},{label:"700",value:50},{label:"semibold",value:75},{label:"bold",value:100}];function Ct({label:n,value:r,onChange:i}){var l,s;const[o,a]=u.default.useState((s=(l=Y.find(d=>d.label===r))==null?void 0:l.value)!=null?s:Y[0].value);return u.default.useEffect(()=>{const d=Y.find(x=>x.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 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 Tt({conf:n,setConf:r}){var a;const i=k.useForm({initialValues:{paragraphs:k.formList((a=n.paragraphs)!=null?a:ye)}}),o=()=>i.addListItem("paragraphs",O(h({},ye[0]),{template:A.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(v.DeviceFloppy,{size:20})})]}),i.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}},i.getListInputProps("paragraphs",s,"template"))),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{children:"Color"}),e(ve,h({},i.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}},i.getListInputProps("paragraphs",s,"size")))}),e(t.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:e(Ct,h({label:"Font Weight"},i.getListInputProps("paragraphs",s,"weight")))}),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>i.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(i.values,null,2)})]})})}const le=[{value:"text",label:"Text",Panel:Tt},{value:"table",label:"Table",Panel:wt},{value:"sunburst",label:"Sunburst",Panel:St},{value:"bar-3d",label:"Bar Chart (3D)",Panel:mt},{value:"line-bar",label:"Line-Bar Chart",Panel:bt}];function _t(){const{viz:n,setViz:r}=u.default.useContext(P),[i,o]=A.useInputState(n.type),a=n.type!==i,l=u.default.useCallback(()=>{!a||r(m=>O(h({},m),{type:i}))},[a,i]),s=m=>{r(p=>O(h({},p),{conf:m}))},d=m=>{try{s(JSON.parse(m))}catch(p){console.error(p)}},x=u.default.useMemo(()=>{var m;return(m=le.find(p=>p.value===i))==null?void 0:m.Panel},[i,le]);return c(oe,{children:[e(t.Select,{label:"Visualization",value:i,onChange:o,data:le,rightSection:e(t.ActionIcon,{disabled:!a,onClick:l,children:e(v.DeviceFloppy,{size:20})})}),x&&e(x,{conf:n.conf,setConf:s}),!x&&e(t.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(n.conf,null,2),onChange:d})]})}function Gt({}){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(_t,{})}),e(t.Box,{sx:{height:"100%",flexGrow:1,maxWidth:"60%"},children:e(ht,{})})]})}function Dt({opened:n,close:r}){const{freezeLayout:i}=u.default.useContext(F),{data:o,loading:a,viz:l,title:s}=u.default.useContext(P);return u.default.useEffect(()=>{i(n)},[n]),e(t.Modal,{size:"96vw",overflow:"inside",opened:n,onClose:r,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}),e(Xe,{})]}),e(t.Tabs.Tab,{label:"Panel",children:e(He,{})}),e(t.Tabs.Tab,{label:"Visualization",children:e(Gt,{})})]})})})}function zt({}){const[n,r]=u.default.useState(!1),i=()=>r(!0),o=()=>r(!1),{title:a,refreshData:l}=u.default.useContext(P),{inEditMode:s}=u.default.useContext(F);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:i,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(Dt,{opened:n,close:o})]})}var Ht="";function se({viz:n,dataSourceID:r,title:i,description:o,update:a,layout:l,id:s}){const d=u.default.useContext(V),x=u.default.useContext(E),[m,p]=u.default.useState(i),[b,g]=u.default.useState(o),[S,y]=u.default.useState(r),[T,D]=u.default.useState(n),L=u.default.useMemo(()=>{if(!!S)return x.dataSources.find(J=>J.id===S)},[S,x.dataSources]);u.default.useEffect(()=>{a==null||a({id:s,layout:l,title:m,description:b,dataSourceID:S,viz:T})},[m,b,L,T,s,l,S]);const{data:z=[],loading:H,refresh:ue}=ee.useRequest(me({context:d,definitions:x,title:m,dataSource:L}),{refreshDeps:[d,x,L]}),de=ue;return e(P.Provider,{value:{data:z,loading:H,title:m,setTitle:p,description:b,setDescription:g,dataSourceID:S,setDataSourceID:y,viz:T,setViz:D,refreshData:de},children:c(t.Container,{className:"panel-root",children:[e(zt,{}),e(ae,{children:e(Se,{viz:T,data:z,loading:H})})]})})}var Xt="";const It=G.WidthProvider(G.Responsive);function we({panels:n,setPanels:r,className:i="layout",cols:o={lg:12,md:10,sm:8,xs:6,xxs:4},rowHeight:a=10,onRemoveItem:l,isDraggable:s,isResizable:d,setLocalCols:x,setBreakpoint:m}){const p=(g,S)=>{m(g),x(S)},b=u.default.useCallback(g=>{const S=new Map;g.forEach(L=>{var z=L,{i:T}=z,D=I(z,["i"]);S.set(T,D)});const y=n.map(T=>O(h({},T),{layout:S.get(T.id)}));r(y)},[n,r]);return e(It,{onBreakpointChange:p,onLayoutChange:b,className:i,cols:o,rowHeight:a,isDraggable:s,isResizable:d,children:n.map((T,y)=>{var D=T,{id:g}=D,S=I(D,["id"]);return e("div",{"data-grid":S.layout,children:e(se,O(h({id:g},S),{destroy:()=>l(g),update:L=>{r(z=>(z.splice(y,1,L),[...z]))}}))},g)})})}function Ce(n,r){return c(t.Text,{sx:{svg:{verticalAlign:"text-bottom"}},children:[n," ",r]})}function Pt({mode:n,setMode:r}){return e(t.SegmentedControl,{value:n,onChange:r,data:[{label:Ce(e(v.PlayerPlay,{size:20}),"Use"),value:q.Use},{label:Ce(e(v.Paint,{size:20}),"Edit"),value:q.Edit}]})}const Lt=`
|
|
9
|
+
*/var Ne=u.default,je=Symbol.for("react.element"),We=Symbol.for("react.fragment"),Qe=Object.prototype.hasOwnProperty,Je=Ne.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Ue={key:!0,ref:!0,__self:!0,__source:!0};function ge(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)Qe.call(i,o)&&!Ue.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:je,type:n,key:l,ref:s,props:a,_owner:Je.current}}X.Fragment=We,X.jsx=ge,X.jsxs=ge,Y.exports=X;const e=Y.exports.jsx,c=Y.exports.jsxs,be=Y.exports.Fragment;function Se({position:n,trigger:i="click"}){const{freezeLayout:r}=u.default.useContext(q),[o,a]=u.default.useState(!1),{description:l}=u.default.useContext(k);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(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:s,children:e(Ee.default,{readOnly:!0,value:l,onChange:_.default.noop,sx:{border:"none"}})})}function He(){const{description:n,setDescription:i}=u.default.useContext(k),[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(y.DeviceFloppy,{size:20})})]}),e(pe.RichTextEditor,{value:r,onChange:o,sx:{flexGrow:1},sticky:!0,p:"0"})]})}class re 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 Ke(){const{title:n}=u.default.useContext(k);return e(re,{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(Se,{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:i}=u.default.useContext(k),[r,o]=M.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(y.DeviceFloppy,{size:20})})]})})}function Xe({}){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(He,{})]}),e(t.Box,{sx:{height:"100%",flexGrow:1,maxWidth:"60%"},children:e(Ke,{})})]})}function ye({id:n}){const i=u.default.useContext(A),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}=ie.useRequest(he({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(y.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,h)=>e("tr",{children:Object.values(d).map((f,p)=>e("td",{children:e(t.Group,{sx:{"&, .mantine-Text-root":{fontFamily:"monospace"}},children:e(t.Text,{children:f})})},`${f}--${p}`))},`row-${h}`))})]})]})}function Ze({}){const{dataSources:n}=u.default.useContext(A),{dataSourceID:i,setDataSourceID:r,data:o,loading:a}=u.default.useContext(k),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(ye,{id:i})]})}R.use([J.SunburstChart,U.CanvasRenderer]);const et={tooltip:{show:!0},series:{type:"sunburst",radius:[0,"90%"],emphasis:{focus:"ancestor"}}};function tt({conf:n,data:i,width:r,height:o}){const b=n,{label_field:a="name",value_field:l="value"}=b,s=z(b,["label_field","value_field"]),d=u.default.useMemo(()=>i.map(g=>({name:g[a],value:Number(g[l])})),[i,a,l]),h=u.default.useMemo(()=>{var g,S;return(S=(g=_.default.maxBy(d,v=>v.value))==null?void 0:g.value)!=null?S:1},[d]),f=u.default.useMemo(()=>({series:{label:{formatter:({name:g,value:S})=>S/h<.2?" ":g}}}),[h]),p=_.default.merge({},et,f,s,{series:{data:d}});return e(H.default,{echarts:R,option:p,style:{width:r,height:o}})}R.use([J.BarChart,J.LineChart,N.GridComponent,N.LegendComponent,N.TooltipComponent,U.CanvasRenderer]);const nt={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 it({conf:n,data:i,width:r,height:o}){const a=u.default.useMemo(()=>{var h,f;const l=n.series.reduce((p,{name:b,y_axis_data_formatter:g})=>(p[b]=function({value:v}){if(!g)return v;try{return K.default(v).format(JSON.parse(g))}catch(C){return console.error(C),v}},p),{}),s=n.series.map(C=>{var G=C,{y_axis_data_key:p,y_axis_data_formatter:b,name:g,label_position:S="top"}=G,v=z(G,["y_axis_data_key","y_axis_data_formatter","name","label_position"]);const O=m({data:i.map(P=>P[p]),label:{show:!0,position:S},name:g},v);return b&&(O.label.formatter=l[g]),O}),d={xAxis:{data:i.map(p=>p[n.x_axis_data_key]),name:(h=n.x_axis_name)!=null?h:""},yAxis:{name:(f=n.y_axis_name)!=null?f:""},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:v})=>S?`${S}: ${l[S]({value:v})}`:v);return g.unshift(`<strong>${b[0].name}</strong>`),g.join("<br />")}}};return _.default.merge({},nt,d)},[n,i]);return!r||!o?null:e(H.default,{echarts:R,option:a,style:{width:r,height:o}})}var $=(n=>(n.string="string",n.number="number",n.eloc="eloc",n.percentage="percentage",n))($||{});function rt({value:n}){return e(t.Text,{component:"span",children:n})}function ot({value:n}){return e(t.Text,{component:"span",children:n})}function at({value:n}){const i=K.default(n).format({thousandSeparated:!0});return e(t.Text,{component:"span",children:i})}function lt({value:n}){const i=K.default(n).format({output:"percent",mantissa:3});return e(t.Text,{component:"span",children:i})}function st({value:n,type:i}){switch(i){case $.string:return e(rt,{value:n});case $.eloc:return e(ot,{value:n});case $.number:return e(at,{value:n});case $.percentage:return e(lt,{value:n})}}function ut({conf:n,data:i=[],width:r,height:o}){const p=n,{id_field:a,use_raw_columns:l,columns:s}=p,d=z(p,["id_field","use_raw_columns","columns"]),h=u.default.useMemo(()=>l?Object.keys(i==null?void 0:i[0]):s.map(b=>b.label),[l,s,i]),f=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(m({sx:{maxHeight:o}},d),{children:[e("thead",{children:e("tr",{children:h.map(b=>e("th",{children:b},b))})}),e("tbody",{children:i.slice(0,30).map((b,g)=>e("tr",{children:f.map(({value_field:S,value_type:v})=>e("td",{children:e(t.Group,{sx:{"&, .mantine-Text-root":{fontFamily:"monospace",fontSize:d.fontSize}},children:e(st,{value:b[S],type:v})})},b[S]))},a?b[a]:`row-${g}`))}),i.length>100&&e("tfoot",{children:e("tr",{children:e("td",{colSpan:h.length,children:e(t.Text,{color:"red",size:"sm",children:"Showing only the first 30 rows to avoid causing slow performance"})})})})]}))}function dt(n,i={}){const r=E(m({},i),{numbro:K.default}),o=Object.keys(r),a=Object.values(r);try{return new Function(...o,`return \`${n}\`;`)(...a)}catch(l){return l.message}}function ct({conf:{paragraphs:n},data:i}){return e(be,{children:n.map((s,l)=>{var d=s,{template:r,size:o}=d,a=z(d,["template","size"]);return e(t.Text,E(m({},a),{sx:{fontSize:o},children:dt(r,i[0])}),`${r}---${l}`)})})}R.use([N.GridComponent,N.VisualMapComponent,N.LegendComponent,N.TooltipComponent,U.CanvasRenderer]);function pt({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=z(b,["x_axis_data_key","y_axis_data_key","z_axis_data_key"]),h=u.default.useMemo(()=>_.default.minBy(i,g=>g[s])[s],[i,s]),f=u.default.useMemo(()=>_.default.maxBy(i,g=>g[s])[s],[i,s]),p=E(m({tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:h,max:f,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(H.default,{echarts:R,option:p,style:{width:r,height:o}})}var tn="";R.use([J.PieChart,U.CanvasRenderer]);const mt={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 ft({conf:n,data:i,width:r,height:o}){const p=n,{label_field:a="name",value_field:l="value"}=p,s=z(p,["label_field","value_field"]),d=u.default.useMemo(()=>i.map(b=>({name:b[a],value:Number(b[l])})),[i,a,l]),h=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]),f=_.default.merge({},mt,h,s,{series:{data:d}});return e(H.default,{echarts:R,option:f,style:{width:r,height:o}})}function ht(n,i,r,o){const a={width:n,height:i,data:r,conf:o.conf};switch(o.type){case"sunburst":return e(tt,m({},a));case"line-bar":return e(it,m({},a));case"table":return e(ut,m({},a));case"text":return e(ct,m({},a));case"bar-3d":return e(pt,m({},a));case"pie":return e(ft,m({},a));default:return null}}function ve({viz:n,data:i,loading:r}){const{ref:o,width:a,height:l}=M.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&&ht(a,l,i,n)]})}function xt({}){const{data:n,loading:i,viz:r}=u.default.useContext(k);return e(re,{children:e(ve,{viz:r,data:n,loading:i})})}function gt({conf:n,setConf:i}){const r=_.default.assign({},{x_axis_data_key:"x",y_axis_data_key:"y",z_axis_data_key:"z",xAxis3D:{type:"value",name:"X Axis Name"},yAxis3D:{type:"value",name:"Y Axis Name"},zAxis3D:{type:"value",name:"Z Axis Name"}},n),{control: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,m({sx:{flexGrow:1},size:"md",label:"Data Key"},s))}),e(j.Controller,{name:"xAxis3D.name",control:o,render:({field:s})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Name"},s))})]}),e(t.Text,{mt:"lg",children:"Y Axis"}),c(t.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[e(j.Controller,{name:"y_axis_data_key",control:o,render:({field:s})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Data Key"},s))}),e(j.Controller,{name:"yAxis3D.name",control:o,render:({field:s})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Name"},s))})]}),e(t.Text,{mt:"lg",children:"Z Axis"}),c(t.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[e(j.Controller,{name:"z_axis_data_key",control:o,render:({field:s})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Data Key"},s))}),e(j.Controller,{name:"zAxis3D.name",control:o,render:({field:s})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Name"},s))})]}),e(t.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:c(t.Button,{color:"blue",type:"submit",children:[e(y.DeviceFloppy,{size:20}),e(t.Text,{ml:"md",children:"Save"})]})})]})})}function we({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 bt=JSON.stringify({output:"percent",mantissa:2},null,2),St=[{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 yt(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:h="1",color:f="black"}){return{type:r,name:o,showSymbol:a,y_axis_data_key:l,y_axis_data_formatter:s,label_position:d,stack:h,color:f}}return n.map(i)}function vt({conf:n,setConf:i}){const h=n,{series:r}=h,o=z(h,["series"]),a=u.default.useMemo(()=>{const g=o,{x_axis_name:f="",y_axis_name:p=""}=g,b=z(g,["x_axis_name","y_axis_name"]);return m({series:I.formList(yt(r!=null?r:[])),x_axis_name:f,y_axis_name:p},b)},[r,o]),l=I.useForm({initialValues:a}),s=()=>l.addListItem("series",{type:"bar",name:M.randomId(),showSymbol:!1,y_axis_data_key:"value",y_axis_data_formatter:"",label_position:"top",stack:"",color:"#000"}),d=u.default.useMemo(()=>!_.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(y.DeviceFloppy,{size:20})})]}),e(t.TextInput,m({size:"md",mb:"lg",label:"X Axis Data Key"},l.getInputProps("x_axis_data_key"))),c(t.Group,{direction:"column",grow:!0,noWrap:!0,mb:"lg",children:[e(t.TextInput,m({size:"md",label:"X Axis Name"},l.getInputProps("x_axis_name"))),e(t.TextInput,m({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((f,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,m({label:"Name",required:!0,sx:{flex:1}},l.getListInputProps("series",p,"name"))),e(t.TextInput,m({label:"Stack",placeholder:"Stack bars by this ID"},l.getListInputProps("series",p,"stack"))),e(t.TextInput,m({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,m({label:"Label Position",data:St},l.getListInputProps("series",p,"label_position"))),e(t.JsonInput,m({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:bt,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(we,m({},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(y.Trash,{size:16})})]},p)),e(t.Group,{position:"center",mt:"xs",children:e(t.Button,{onClick:s,children:"Add a Series"})})]})]})})}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:"Pie Config"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",children:e(y.DeviceFloppy,{size:20})})]}),c(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,p:"md",mb:"sm",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[e(t.TextInput,m({label:"Label Field",required:!0,sx:{flex:1}},o.getInputProps("label_field"))),e(t.TextInput,m({label:"Value Field",placeholder:"get column value by this field",required:!0,sx:{flex:1}},o.getInputProps("value_field")))]})]})})}function Ct({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(y.DeviceFloppy,{size:20})})]}),c(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,p:"md",mb:"sm",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[e(t.TextInput,m({label:"Label Field",required:!0,sx:{flex:1}},o.getInputProps("label_field"))),e(t.TextInput,m({label:"Value Field",placeholder:"get column value by this field",required:!0,sx:{flex:1}},o.getInputProps("value_field")))]})]})})}const Tt=Object.values($).map(n=>({label:n,value:n}));function _t({label:n,value:i,onChange:r,sx:o}){return e(t.Select,{label:n,data:Tt,value:i,onChange:r,sx:o})}function Gt(o){var a=o,{conf:l}=a,s=l,{columns:n}=s,i=z(s,["columns"]),{setConf:r}=a;const d=I.useForm({initialValues:m({id_field:"id",use_raw_columns:!0,columns:I.formList(n!=null?n:[]),fontSize:"sm",horizontalSpacing:"sm",verticalSpacing:"sm",striped:!1,highlightOnHover:!1},i)}),h=()=>d.addListItem("columns",{label:M.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(y.DeviceFloppy,{size:20})})]}),c(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,p:"md",mb:"sm",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[e(t.TextInput,m({size:"md",mb:"lg",label:"ID Field"},d.getInputProps("id_field"))),c(t.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:[e(t.TextInput,m({label:"Horizontal Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1}},d.getInputProps("horizontalSpacing"))),e(t.TextInput,m({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,m({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,m({label:"Striped"},d.getInputProps("striped",{type:"checkbox"}))),e(t.Switch,m({label:"Highlight on hover"},d.getInputProps("highlightOnHover",{type:"checkbox"})))]})]})]}),c(t.Group,{direction:"column",mt:"xs",spacing:"xs",grow:!0,p:"md",mb:"xl",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[e(t.Switch,m({label:"Use Original Data Columns"},d.getInputProps("use_raw_columns",{type:"checkbox"}))),!d.values.use_raw_columns&&c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{mt:"xl",mb:0,children:"Custom Columns"}),d.values.columns.map((f,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,m({label:"Label",required:!0,sx:{flex:1}},d.getListInputProps("columns",p,"label"))),e(t.TextInput,m({label:"Value Field",placeholder:"get column value by this field",required:!0,sx:{flex:1}},d.getListInputProps("columns",p,"value_field"))),e(_t,m({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(y.Trash,{size:16})})]},p)),e(t.Group,{position:"center",mt:"xs",children:e(t.Button,{onClick:h,children:"Add a Column"})})]})]}),e(t.Text,{weight:500,mb:"md",children:"Current Configuration:"}),e(F.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(d.values,null,2)})]})})}const Z=[{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=Z.find(d=>d.label===i))==null?void 0:l.value)!=null?s:Z[0].value);return u.default.useEffect(()=>{const d=Z.find(h=>h.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:Z,value:o,onChange:a,step:25,placeholder:"Pick a font size"})]})}const Ce=[{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 zt({conf:n,setConf:i}){var a;const r=I.useForm({initialValues:{paragraphs:I.formList((a=n.paragraphs)!=null?a:Ce)}}),o=()=>r.addListItem("paragraphs",E(m({},Ce[0]),{template:M.randomId()}));return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:r.onSubmit(i),children:[r.values.paragraphs.length===0&&e(t.Text,{color:"dimmed",align:"center",children:"Empty"}),c(t.Group,{position:"apart",mb:"xs",sx:{" + .mantine-Group-root":{marginTop:0}},children:[e(t.Text,{children:"Paragraphs"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",children:e(y.DeviceFloppy,{size:20})})]}),r.values.paragraphs.map((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,m({placeholder:"Time: ${new Date().toISOString()}",label:"Content Template",required:!0,sx:{flex:1}},r.getListInputProps("paragraphs",s,"template"))),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{children:"Color"}),e(we,m({},r.getListInputProps("paragraphs",s,"color")))]}),e(t.Group,{direction:"column",grow:!0,children:e(t.TextInput,m({label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",sx:{flex:1}},r.getListInputProps("paragraphs",s,"size")))}),e(t.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:e(Dt,m({label:"Font Weight"},r.getListInputProps("paragraphs",s,"weight")))}),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>r.removeListItem("paragraphs",s),sx:{position:"absolute",top:15,right:5},children:e(y.Trash,{size:16})})]},s)),e(t.Group,{position:"center",mt:"md",children:e(t.Button,{onClick:o,children:"Add a Paragraph"})}),e(t.Text,{size:"sm",weight:500,mt:"md",children:"Current Configuration:"}),e(F.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(r.values,null,2)})]})})}const oe=[{value:"text",label:"Text",Panel:zt},{value:"table",label:"Table",Panel:Gt},{value:"sunburst",label:"Sunburst",Panel:Ct},{value:"bar-3d",label:"Bar Chart (3D)",Panel:gt},{value:"line-bar",label:"Line-Bar Chart",Panel:vt},{value:"pie",label:"Pie Chart",Panel:wt}];function Pt(){const{viz:n,setViz:i}=u.default.useContext(k),[r,o]=M.useInputState(n.type),a=n.type!==r,l=u.default.useCallback(()=>{!a||i(f=>E(m({},f),{type:r}))},[a,r]),s=f=>{i(p=>E(m({},p),{conf:f}))},d=f=>{try{s(JSON.parse(f))}catch(p){console.error(p)}},h=u.default.useMemo(()=>{var f;return(f=oe.find(p=>p.value===r))==null?void 0:f.Panel},[r,oe]);return c(be,{children:[e(t.Select,{label:"Visualization",value:r,onChange:o,data:oe,rightSection:e(t.ActionIcon,{disabled:!a,onClick:l,children:e(y.DeviceFloppy,{size:20})})}),h&&e(h,{conf:n.conf,setConf:s}),!h&&e(t.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(n.conf,null,2),onChange:d})]})}function It({}){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(xt,{})})]})}function Lt({opened:n,close:i}){const{freezeLayout:r}=u.default.useContext(q),{data:o,loading:a,viz:l,title:s}=u.default.useContext(k);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(Ze,{})]}),e(t.Tabs.Tab,{label:"Panel",children:e(Xe,{})}),e(t.Tabs.Tab,{label:"Visualization",children:e(It,{})})]})})})}function kt({}){const[n,i]=u.default.useState(!1),r=()=>i(!0),o=()=>i(!1),{title:a,refreshData:l}=u.default.useContext(k),{inEditMode:s}=u.default.useContext(q);return c(t.Group,{position:"apart",noWrap:!0,sx:{borderBottom:"1px solid #eee",paddingBottom:"5px"},children:[e(t.Group,{children:e(Se,{})}),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(y.Refresh,{size:14}),children:"Refresh"}),s&&e(t.Menu.Item,{onClick:r,icon:e(y.Settings,{size:14}),children:"Settings"}),e(t.Divider,{}),e(t.Menu.Item,{color:"red",disabled:!0,icon:e(y.Trash,{size:14}),children:"Delete"})]})}),s&&e(Lt,{opened:n,close:o})]})}var nn="";function ae({viz:n,dataSourceID:i,title:r,description:o,update:a,layout:l,id:s}){const d=u.default.useContext(W),h=u.default.useContext(A),[f,p]=u.default.useState(r),[b,g]=u.default.useState(o),[S,v]=u.default.useState(i),[C,G]=u.default.useState(n),O=u.default.useMemo(()=>{if(!!S)return h.dataSources.find(de=>de.id===S)},[S,h.dataSources]);u.default.useEffect(()=>{a==null||a({id:s,layout:l,title:f,description:b,dataSourceID:S,viz:C})},[f,b,O,C,s,l,S]);const{data:P=[],loading:ee,refresh:se}=ie.useRequest(he({context:d,definitions:h,title:f,dataSource:O}),{refreshDeps:[d,h,O]}),ue=se;return e(k.Provider,{value:{data:P,loading:ee,title:f,setTitle:p,description:b,setDescription:g,dataSourceID:S,setDataSourceID:v,viz:C,setViz:G,refreshData:ue},children:c(t.Container,{className:"panel-root",children:[e(kt,{}),e(re,{children:e(ve,{viz:C,data:P,loading:ee})})]})})}var rn="";const Ot=D.WidthProvider(D.Responsive);function Te({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:h,setBreakpoint:f}){const p=(g,S)=>{f(g),h(S)},b=u.default.useCallback(g=>{const S=new Map;g.forEach(O=>{var P=O,{i:C}=P,G=z(P,["i"]);S.set(C,G)});const v=n.map(C=>E(m({},C),{layout:S.get(C.id)}));i(v)},[n,i]);return e(Ot,{onBreakpointChange:p,onLayoutChange:b,className:r,cols:o,rowHeight:a,isDraggable:s,isResizable:d,children:n.map((C,v)=>{var G=C,{id:g}=G,S=z(G,["id"]);return e("div",{"data-grid":S.layout,children:e(ae,E(m({id:g},S),{destroy:()=>l(g),update:O=>{i(P=>(P.splice(v,1,O),[...P]))}}))},g)})})}function le(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:le(e(y.PlayerPlay,{size:20}),"Use"),value:L.Use},{label:le(e(y.Resize,{size:20}),"Layout"),value:L.Layout},{label:le(e(y.Paint,{size:20}),"Content"),value:L.Edit}]})}const At=`
|
|
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
|
|
21
|
+
`;function Mt({}){const n=u.default.useContext(W),{sqlSnippets:i}=u.default.useContext(A),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(F.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:At}),e(t.Text,{weight:500,sx:{flexGrow:0},children:"Avaiable context"}),e(F.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(F.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(f=>{i(f)},[i]),a=u.default.useMemo(()=>!_.default.isEqual(n,r.values),[n,r.values]);u.default.useEffect(()=>{r.reset()},[n]);const{data:l={},loading:s}=ie.useRequest(Fe,{refreshDeps:[]},[]),d=u.default.useMemo(()=>Object.keys(l).map(f=>({label:f,value:f})),[l]),h=u.default.useMemo(()=>{const f=l[r.values.type];return f?f.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(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,m({placeholder:"An ID unique in this dashboard",label:"ID",required:!0,sx:{flex:1},disabled:s},r.getInputProps("id"))),e(t.Select,m({label:"Data Source Type",data:d,sx:{flex:1},disabled:s},r.getInputProps("type"))),e(t.Select,m({label:"Data Source Key",data:h,sx:{flex:1},disabled:s},r.getInputProps("key")))]}),e(t.Textarea,m({autosize:!0,minRows:12,maxRows:24},r.getInputProps("sql")))]})]})})}function Bt({id:n}){const{dataSources:i,setDataSources:r}=u.default.useContext(A),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 h=d.findIndex(f=>f.id===n);return d.splice(h,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(Mt,{})]}):e("span",{children:"Invalid Data Source ID"}):null}function Ft({id:n,setID:i}){const{dataSources:r,setDataSources:o}=u.default.useContext(A),a=u.default.useCallback(()=>{var d,h;i((h=(d=r[0])==null?void 0:d.id)!=null?h:"")},[i,r]);u.default.useEffect(()=>{if(!n){a();return}r.findIndex(h=>h.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:M.randomId(),type:"postgresql",key:"",sql:""};o(h=>[...h,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 Rt({opened:n,close:i}){const[r,o]=u.default.useState(""),{freezeLayout:a}=u.default.useContext(q);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(Ft,{id:r,setID:o}),children:[e(Bt,{id:r}),e(ye,{id:r})]})})}function $t({}){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(F.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
|
-
${
|
|
24
|
+
${i}`}),e(t.Text,{weight:500,sx:{flexGrow:0},children:"Avaiable context entries"}),e(F.Prism,{language:"json",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:JSON.stringify(n,null,2)})]})]})}function Vt({}){const{sqlSnippets:n,setSQLSnippets:i}=u.default.useContext(A),r=`SELECT *
|
|
24
25
|
FROM commit
|
|
25
|
-
WHERE \${author_time_condition}`,o=u.default.useMemo(()=>({snippets:
|
|
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:M.randomId(),value:""}),s=u.default.useMemo(()=>!_.default.isEqual(a.values,o),[a.values,o]),d=({snippets:h})=>{i(h)};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(y.DeviceFloppy,{size:20})})]}),c(t.Group,{px:"md",pb:"md",children:[e(F.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
|
-
${
|
|
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((
|
|
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((h,f)=>c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[e(t.TextInput,m({label:"Key",required:!0},a.getListInputProps("snippets",f,"key"))),e(t.Textarea,m({minRows:3,label:"Value",required:!0},a.getListInputProps("snippets",f,"value"))),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>a.removeListItem("snippets",f),sx:{position:"absolute",top:15,right:5},children:e(y.Trash,{size:16})})]},f)),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 Nt({opened:n,close:i}){const{freezeLayout:r}=u.default.useContext(q);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(Vt,{}),e($t,{})]})})})}function jt({mode:n,setMode:i,hasChanges:r,addPanel:o,saveChanges:a}){const{inLayoutMode:l,inEditMode:s,inUseMode:d}=u.default.useContext(q),[h,f]=u.default.useState(!1),p=()=>f(!0),b=()=>f(!1),[g,S]=u.default.useState(!1),v=()=>S(!0),C=()=>S(!1);return c(t.Group,{position:"apart",pt:"sm",pb:"xs",children:[e(t.Group,{position:"left",children:e(Et,{mode:n,setMode:i})}),c(t.Group,{position:"right",children:[l&&e(t.Button,{variant:"default",size:"sm",onClick:o,leftIcon:e(y.PlaylistAdd,{size:20}),children:"Add a Panel"}),s&&e(t.Button,{variant:"default",size:"sm",onClick:v,leftIcon:e(y.ClipboardText,{size:20}),children:"SQL Snippets"}),s&&e(t.Button,{variant:"default",size:"sm",onClick:p,leftIcon:e(y.Database,{size:20}),children:"Data Sources"}),!d&&e(t.Button,{variant:"default",size:"sm",onClick:a,disabled:!r,leftIcon:e(y.DeviceFloppy,{size:20}),children:"Save Changes"}),!d&&e(t.Button,{color:"red",size:"sm",disabled:!r,leftIcon:e(y.Recycle,{size:20}),children:"Revert Changes"})]}),e(Rt,{opened:h,close:b}),e(Nt,{opened:g,close:C}),d&&e(t.Button,{variant:"default",size:"sm",disabled:!0,leftIcon:e(y.Share,{size:20}),children:"Share"})]})}function Wt({context:n,dashboard:i,update:r,className:o="dashboard"}){const[a,l]=u.default.useState(!1),[s,d]=u.default.useState(),[h,f]=u.default.useState(),[p,b]=u.default.useState(i.panels),[g,S]=u.default.useState(i.definition.sqlSnippets),[v,C]=u.default.useState(i.definition.dataSources),[G,O]=u.default.useState(L.Edit),P=u.default.useMemo(()=>{const B=V=>JSON.parse(JSON.stringify(V));return!_.default.isEqual(B(p),B(i.panels))||!_.default.isEqual(g,i.definition.sqlSnippets)?!0:!_.default.isEqual(v,i.definition.dataSources)},[i,p,g,v]),ee=async()=>{const B=_.default.merge({},i,{panels:p},{definition:{sqlSnippets:g,dataSources:v}});await r(B)},se=()=>{const B=M.randomId(),te={id:B,layout:{x:0,y:1/0,w:3,h:4},title:`New Panel - ${B}`,description:"description goes here",dataSourceID:"",viz:{type:"table",conf:{}}};b(V=>[...V,te])},ue=B=>{const te=p.findIndex(V=>V.id===B);b(V=>(V.splice(te,1),[...V]))},de=G===L.Edit,ce=G===L.Layout,Ht=G===L.Use,Kt=u.default.useMemo(()=>({sqlSnippets:g,setSQLSnippets:S,dataSources:v,setDataSources:C}),[g,S,v,C]);return e(W.Provider,{value:n,children:e("div",{className:o,children:e(A.Provider,{value:Kt,children:c(q.Provider,{value:{layoutFrozen:a,freezeLayout:l,mode:G,inEditMode:de,inLayoutMode:ce,inUseMode:Ht},children:[e(jt,{mode:G,setMode:O,hasChanges:P,addPanel:se,saveChanges:ee}),e(Te,{panels:p,setPanels:b,isDraggable:ce,isResizable:ce,onRemoveItem:ue,setLocalCols:f,setBreakpoint:d})]})})})})}const Qt=D.WidthProvider(D.Responsive);function Jt({panels:n,className:i="layout",cols:r={lg:12,md:10,sm:8,xs:6,xxs:4},rowHeight:o=10}){return e(Qt,{className:i,cols:r,rowHeight:o,isDraggable:!1,isResizable:!1,children:n.map(s=>{var d=s,{id:a}=d,l=z(d,["id"]);return e("div",{"data-grid":l.layout,children:e(ae,m({id:a},l))},a)})})}function Ut({context:n,dashboard:i,className:r="dashboard"}){const o=u.default.useMemo(()=>E(m({},i.definition),{setSQLSnippets:()=>{},setDataSources:()=>{}}),[i]);return e(W.Provider,{value:n,children:e("div",{className:r,children:e(A.Provider,{value:o,children:e(q.Provider,{value:{layoutFrozen:!0,freezeLayout:()=>{},mode:L.Use,inEditMode:!1,inLayoutMode:!1,inUseMode:!0},children:e(Jt,{panels:i.panels})})})})})}x.ContextInfoContext=W,x.Dashboard=Wt,x.DashboardLayout=Te,x.DashboardMode=L,x.DefinitionContext=A,x.LayoutStateContext=q,x.Panel=ae,x.PanelContext=k,x.ReadOnlyDashboard=Ut,x.initialContextInfoContext=Re,Object.defineProperties(x,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|