@devtable/dashboard 0.0.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api-caller/index.d.ts +1 -1
- package/dist/dashboard.es.js +323 -270
- package/dist/dashboard.umd.js +5 -5
- package/dist/layout/index.d.ts +3 -1
- package/dist/main/actions.d.ts +3 -1
- package/dist/main/index.d.ts +2 -1
- package/dist/panel/error-boundary.d.ts +8 -0
- package/dist/panel/index.d.ts +4 -8
- package/dist/panel/settings/common/mantine-font-weight.d.ts +8 -0
- package/dist/panel/settings/index.d.ts +4 -2
- package/dist/panel/viz/sunburst/panel.d.ts +1 -1
- package/dist/types/dashboard.d.ts +2 -0
- package/package.json +1 -1
- package/dist/panel/settings/common/mantine-size.d.ts +0 -8
- package/dist/panel/settings/common/mantine-weight.d.ts +0 -8
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ContextInfoContextType } from "../contexts";
|
|
2
2
|
import { IDashboardDefinition } from "../types";
|
|
3
|
-
export declare const queryBySQL: (sql: string, context: ContextInfoContextType, definitions: IDashboardDefinition) => () => Promise<any>;
|
|
3
|
+
export declare const queryBySQL: (sql: string, context: ContextInfoContextType, definitions: IDashboardDefinition, title: string) => () => Promise<any>;
|
package/dist/dashboard.es.js
CHANGED
|
@@ -32,11 +32,11 @@ var __objRest = (source, exclude) => {
|
|
|
32
32
|
import React from "react";
|
|
33
33
|
import _ from "lodash";
|
|
34
34
|
import { WidthProvider, Responsive } from "react-grid-layout";
|
|
35
|
-
import { Text, Table, Group, LoadingOverlay, Box, Textarea, Button, TextInput, ActionIcon, useMantineTheme, ColorSwatch, Select,
|
|
35
|
+
import { Text, Table, Group, LoadingOverlay, Box, Textarea, Button, TextInput, ActionIcon, useMantineTheme, ColorSwatch, Select, Switch, Slider, JsonInput, Divider, Modal, AppShell, Navbar, Tabs, Tooltip, Menu, Container, SegmentedControl } from "@mantine/core";
|
|
36
36
|
import { useRequest } from "ahooks";
|
|
37
37
|
import axios from "axios";
|
|
38
|
-
import { Trash, DeviceFloppy,
|
|
39
|
-
import { useElementSize, randomId, useInputState } from "@mantine/hooks";
|
|
38
|
+
import { Trash, DeviceFloppy, InfoCircle, Refresh, Settings, Paint, PlayerPlay, PlaylistAdd, Recycle, Share } from "tabler-icons-react";
|
|
39
|
+
import { useElementSize, randomId, useInputState, useListState } from "@mantine/hooks";
|
|
40
40
|
import ReactEChartsCore from "echarts-for-react/lib/core";
|
|
41
41
|
import * as echarts from "echarts/core";
|
|
42
42
|
import { SunburstChart, BarChart, LineChart } from "echarts/charts";
|
|
@@ -87,7 +87,6 @@ const post = getRequest("POST");
|
|
|
87
87
|
function formatSQL(sql, params) {
|
|
88
88
|
const names = Object.keys(params);
|
|
89
89
|
const vals = Object.values(params);
|
|
90
|
-
console.log({ names, vals });
|
|
91
90
|
return new Function(...names, `return \`${sql}\`;`)(...vals);
|
|
92
91
|
}
|
|
93
92
|
function getSQLParams(context, definitions) {
|
|
@@ -95,16 +94,24 @@ function getSQLParams(context, definitions) {
|
|
|
95
94
|
ret[curr.key] = formatSQL(curr.value, context);
|
|
96
95
|
return ret;
|
|
97
96
|
}, {});
|
|
98
|
-
return _.
|
|
97
|
+
return _.merge({}, sqlSnippetRecord, context);
|
|
99
98
|
}
|
|
100
|
-
const queryBySQL = (sql, context, definitions) => async () => {
|
|
99
|
+
const queryBySQL = (sql, context, definitions, title) => async () => {
|
|
101
100
|
if (!sql) {
|
|
102
101
|
return [];
|
|
103
102
|
}
|
|
103
|
+
const needParams = sql.includes("$");
|
|
104
104
|
const params = getSQLParams(context, definitions);
|
|
105
|
+
console.log(needParams, params);
|
|
106
|
+
if (needParams && Object.keys(params).length === 0) {
|
|
107
|
+
console.error(`[queryBySQL] insufficient params for {${title}}'s SQL`);
|
|
108
|
+
return [];
|
|
109
|
+
}
|
|
105
110
|
const formattedSQL = formatSQL(sql, params);
|
|
106
|
-
if (
|
|
111
|
+
if (needParams) {
|
|
112
|
+
console.groupCollapsed(`Final SQL for: ${title}`);
|
|
107
113
|
console.log(formattedSQL);
|
|
114
|
+
console.groupEnd();
|
|
108
115
|
}
|
|
109
116
|
const res = await post("/query", { sql: formattedSQL });
|
|
110
117
|
return res;
|
|
@@ -167,6 +174,27 @@ reactJsxRuntime_production_min.jsxs = q;
|
|
|
167
174
|
const jsx = jsxRuntime.exports.jsx;
|
|
168
175
|
const jsxs = jsxRuntime.exports.jsxs;
|
|
169
176
|
const Fragment = jsxRuntime.exports.Fragment;
|
|
177
|
+
class ErrorBoundary extends React.Component {
|
|
178
|
+
constructor(props) {
|
|
179
|
+
super(props);
|
|
180
|
+
this.state = {
|
|
181
|
+
hasError: false
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
static getDerivedStateFromError() {
|
|
185
|
+
return {
|
|
186
|
+
hasError: true
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
render() {
|
|
190
|
+
if (this.state.hasError) {
|
|
191
|
+
return /* @__PURE__ */ jsx("h1", {
|
|
192
|
+
children: "Something went wrong."
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
return this.props.children;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
170
198
|
echarts.use([SunburstChart, CanvasRenderer]);
|
|
171
199
|
const defaultOption$1 = {
|
|
172
200
|
tooltip: {
|
|
@@ -196,7 +224,7 @@ function Sunbrust({
|
|
|
196
224
|
const chartData = React.useMemo(() => {
|
|
197
225
|
return data.map((d) => ({
|
|
198
226
|
name: d[label_field],
|
|
199
|
-
value: d[value_field]
|
|
227
|
+
value: Number(d[value_field])
|
|
200
228
|
}));
|
|
201
229
|
}, [data, label_field, value_field]);
|
|
202
230
|
const max = React.useMemo(() => {
|
|
@@ -218,7 +246,7 @@ function Sunbrust({
|
|
|
218
246
|
}
|
|
219
247
|
}
|
|
220
248
|
}), []);
|
|
221
|
-
const option = _.
|
|
249
|
+
const option = _.merge(defaultOption$1, labelOption, restConf, {
|
|
222
250
|
series: {
|
|
223
251
|
data: chartData
|
|
224
252
|
}
|
|
@@ -243,7 +271,14 @@ const defaultOption = {
|
|
|
243
271
|
xAxis: {
|
|
244
272
|
type: "category"
|
|
245
273
|
},
|
|
246
|
-
yAxis: {}
|
|
274
|
+
yAxis: {},
|
|
275
|
+
grid: {
|
|
276
|
+
top: 30,
|
|
277
|
+
left: 10,
|
|
278
|
+
right: 10,
|
|
279
|
+
bottom: 10,
|
|
280
|
+
containLabel: true
|
|
281
|
+
}
|
|
247
282
|
};
|
|
248
283
|
function VizLineBarChart({
|
|
249
284
|
conf,
|
|
@@ -439,11 +474,16 @@ function VizText({
|
|
|
439
474
|
return /* @__PURE__ */ jsx(Fragment, {
|
|
440
475
|
children: paragraphs.map((_a, index2) => {
|
|
441
476
|
var _b = _a, {
|
|
442
|
-
template
|
|
477
|
+
template,
|
|
478
|
+
size
|
|
443
479
|
} = _b, rest = __objRest(_b, [
|
|
444
|
-
"template"
|
|
480
|
+
"template",
|
|
481
|
+
"size"
|
|
445
482
|
]);
|
|
446
483
|
return /* @__PURE__ */ jsx(Text, __spreadProps(__spreadValues({}, rest), {
|
|
484
|
+
sx: {
|
|
485
|
+
fontSize: size
|
|
486
|
+
},
|
|
447
487
|
children: interpolateString(template, data[0])
|
|
448
488
|
}), `${template}---${index2}`);
|
|
449
489
|
})
|
|
@@ -683,7 +723,6 @@ function SQLSnippetsForm({
|
|
|
683
723
|
sqlSnippets,
|
|
684
724
|
setSQLSnippets
|
|
685
725
|
}) {
|
|
686
|
-
const submitButton = React.useRef(null);
|
|
687
726
|
const initialValues = React.useMemo(() => ({
|
|
688
727
|
snippets: formList(sqlSnippets != null ? sqlSnippets : [])
|
|
689
728
|
}), [sqlSnippets]);
|
|
@@ -695,12 +734,6 @@ function SQLSnippetsForm({
|
|
|
695
734
|
value: ""
|
|
696
735
|
});
|
|
697
736
|
const changed = React.useMemo(() => !_.isEqual(form.values, initialValues), [form.values, initialValues]);
|
|
698
|
-
React.useEffect(() => {
|
|
699
|
-
var _a;
|
|
700
|
-
if (changed) {
|
|
701
|
-
(_a = submitButton == null ? void 0 : submitButton.current) == null ? void 0 : _a.click();
|
|
702
|
-
}
|
|
703
|
-
}, [changed, submitButton.current]);
|
|
704
737
|
const submit = ({
|
|
705
738
|
snippets
|
|
706
739
|
}) => {
|
|
@@ -709,19 +742,13 @@ function SQLSnippetsForm({
|
|
|
709
742
|
return /* @__PURE__ */ jsx(Group, {
|
|
710
743
|
direction: "column",
|
|
711
744
|
sx: {
|
|
712
|
-
width: "100%"
|
|
745
|
+
width: "100%",
|
|
746
|
+
position: "relative"
|
|
713
747
|
},
|
|
714
748
|
grow: true,
|
|
715
749
|
children: /* @__PURE__ */ jsxs("form", {
|
|
716
750
|
onSubmit: form.onSubmit(submit),
|
|
717
|
-
children: [/* @__PURE__ */
|
|
718
|
-
ref: submitButton,
|
|
719
|
-
type: "submit",
|
|
720
|
-
style: {
|
|
721
|
-
display: "none"
|
|
722
|
-
},
|
|
723
|
-
children: "Ghost submit"
|
|
724
|
-
}), form.values.snippets.map((_item, index2) => /* @__PURE__ */ jsxs(Group, {
|
|
751
|
+
children: [form.values.snippets.map((_item, index2) => /* @__PURE__ */ jsxs(Group, {
|
|
725
752
|
direction: "column",
|
|
726
753
|
grow: true,
|
|
727
754
|
my: 0,
|
|
@@ -751,19 +778,24 @@ function SQLSnippetsForm({
|
|
|
751
778
|
size: 16
|
|
752
779
|
})
|
|
753
780
|
})]
|
|
754
|
-
}, index2)), /* @__PURE__ */
|
|
781
|
+
}, index2)), /* @__PURE__ */ jsxs(Group, {
|
|
755
782
|
position: "center",
|
|
756
783
|
mt: "xl",
|
|
757
784
|
grow: true,
|
|
758
785
|
sx: {
|
|
759
|
-
width: "
|
|
786
|
+
width: "80%"
|
|
760
787
|
},
|
|
761
788
|
mx: "auto",
|
|
762
|
-
children: /* @__PURE__ */ jsx(Button, {
|
|
763
|
-
|
|
789
|
+
children: [/* @__PURE__ */ jsx(Button, {
|
|
790
|
+
variant: "default",
|
|
764
791
|
onClick: addSnippet,
|
|
765
792
|
children: "Add a snippet"
|
|
766
|
-
})
|
|
793
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
794
|
+
color: "blue",
|
|
795
|
+
type: "submit",
|
|
796
|
+
disabled: !changed,
|
|
797
|
+
children: "Submit"
|
|
798
|
+
})]
|
|
767
799
|
})]
|
|
768
800
|
})
|
|
769
801
|
});
|
|
@@ -784,6 +816,7 @@ WHERE \${author_time_condition}`;
|
|
|
784
816
|
width: "100%"
|
|
785
817
|
},
|
|
786
818
|
noCopy: true,
|
|
819
|
+
trim: false,
|
|
787
820
|
colorScheme: "dark",
|
|
788
821
|
children: `-- You may refer context data *by name*
|
|
789
822
|
-- in SQL or VizConfig.
|
|
@@ -792,7 +825,7 @@ ${sampleSQL}
|
|
|
792
825
|
|
|
793
826
|
-- where author_time_condition is:
|
|
794
827
|
author_time BETWEEN '\${timeRange?.[0].toISOString()}' AND '\${timeRange?.[1].toISOString()}'
|
|
795
|
-
`
|
|
828
|
+
`
|
|
796
829
|
}), /* @__PURE__ */ jsx(Text, {
|
|
797
830
|
weight: 700,
|
|
798
831
|
children: "SQL Snippets"
|
|
@@ -1079,7 +1112,6 @@ function VizLineBarChartPanel({
|
|
|
1079
1112
|
conf,
|
|
1080
1113
|
setConf
|
|
1081
1114
|
}) {
|
|
1082
|
-
const submitButton = React.useRef(null);
|
|
1083
1115
|
const _a = conf, {
|
|
1084
1116
|
series
|
|
1085
1117
|
} = _a, restConf = __objRest(_a, [
|
|
@@ -1099,13 +1131,7 @@ function VizLineBarChartPanel({
|
|
|
1099
1131
|
stack: "",
|
|
1100
1132
|
color: "#000"
|
|
1101
1133
|
});
|
|
1102
|
-
|
|
1103
|
-
React.useEffect(() => {
|
|
1104
|
-
var _a2;
|
|
1105
|
-
if (changed) {
|
|
1106
|
-
(_a2 = submitButton == null ? void 0 : submitButton.current) == null ? void 0 : _a2.click();
|
|
1107
|
-
}
|
|
1108
|
-
}, [changed, submitButton.current]);
|
|
1134
|
+
React.useMemo(() => !_.isEqual(form.values, initialValues), [form.values, initialValues]);
|
|
1109
1135
|
return /* @__PURE__ */ jsx(Group, {
|
|
1110
1136
|
direction: "column",
|
|
1111
1137
|
mt: "md",
|
|
@@ -1121,13 +1147,14 @@ function VizLineBarChartPanel({
|
|
|
1121
1147
|
},
|
|
1122
1148
|
children: [/* @__PURE__ */ jsx(Text, {
|
|
1123
1149
|
children: "Chart Config"
|
|
1124
|
-
}), /* @__PURE__ */ jsx(
|
|
1125
|
-
ref: submitButton,
|
|
1150
|
+
}), /* @__PURE__ */ jsx(ActionIcon, {
|
|
1126
1151
|
type: "submit",
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
children:
|
|
1152
|
+
mr: 5,
|
|
1153
|
+
variant: "filled",
|
|
1154
|
+
color: "blue",
|
|
1155
|
+
children: /* @__PURE__ */ jsx(DeviceFloppy, {
|
|
1156
|
+
size: 20
|
|
1157
|
+
})
|
|
1131
1158
|
})]
|
|
1132
1159
|
}), /* @__PURE__ */ jsx(TextInput, __spreadValues({
|
|
1133
1160
|
size: "md",
|
|
@@ -1198,20 +1225,17 @@ function VizLineBarChartPanel({
|
|
|
1198
1225
|
})
|
|
1199
1226
|
});
|
|
1200
1227
|
}
|
|
1201
|
-
function SunburstPanel(
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
]), {
|
|
1209
|
-
setConf
|
|
1210
|
-
} = _b;
|
|
1228
|
+
function SunburstPanel({
|
|
1229
|
+
conf: {
|
|
1230
|
+
label_field,
|
|
1231
|
+
value_field
|
|
1232
|
+
},
|
|
1233
|
+
setConf
|
|
1234
|
+
}) {
|
|
1211
1235
|
const form = useForm({
|
|
1212
1236
|
initialValues: {
|
|
1213
|
-
label_field
|
|
1214
|
-
value_field
|
|
1237
|
+
label_field,
|
|
1238
|
+
value_field
|
|
1215
1239
|
}
|
|
1216
1240
|
});
|
|
1217
1241
|
return /* @__PURE__ */ jsx(Group, {
|
|
@@ -1267,52 +1291,6 @@ function SunburstPanel(_a) {
|
|
|
1267
1291
|
})
|
|
1268
1292
|
});
|
|
1269
1293
|
}
|
|
1270
|
-
const marks$1 = [{
|
|
1271
|
-
"value": 0,
|
|
1272
|
-
"label": "xs"
|
|
1273
|
-
}, {
|
|
1274
|
-
"value": 25,
|
|
1275
|
-
"label": "sm"
|
|
1276
|
-
}, {
|
|
1277
|
-
"value": 50,
|
|
1278
|
-
"label": "md"
|
|
1279
|
-
}, {
|
|
1280
|
-
"value": 75,
|
|
1281
|
-
"label": "lg"
|
|
1282
|
-
}, {
|
|
1283
|
-
"value": 100,
|
|
1284
|
-
"label": "xl"
|
|
1285
|
-
}];
|
|
1286
|
-
function MantineSizeSlider({
|
|
1287
|
-
label,
|
|
1288
|
-
value,
|
|
1289
|
-
onChange
|
|
1290
|
-
}) {
|
|
1291
|
-
var _a, _b;
|
|
1292
|
-
const [mark, setMark] = React.useState((_b = (_a = marks$1.find((m2) => m2.label === value)) == null ? void 0 : _a.value) != null ? _b : marks$1[0].value);
|
|
1293
|
-
React.useEffect(() => {
|
|
1294
|
-
const match = marks$1.find((s) => s.value === mark);
|
|
1295
|
-
if (match) {
|
|
1296
|
-
onChange(match.label);
|
|
1297
|
-
}
|
|
1298
|
-
}, [mark]);
|
|
1299
|
-
return /* @__PURE__ */ jsxs(Group, {
|
|
1300
|
-
direction: "column",
|
|
1301
|
-
grow: true,
|
|
1302
|
-
spacing: "xs",
|
|
1303
|
-
mb: "lg",
|
|
1304
|
-
children: [/* @__PURE__ */ jsx(Text, {
|
|
1305
|
-
children: label
|
|
1306
|
-
}), /* @__PURE__ */ jsx(Slider, {
|
|
1307
|
-
label: null,
|
|
1308
|
-
marks: marks$1,
|
|
1309
|
-
value: mark,
|
|
1310
|
-
onChange: setMark,
|
|
1311
|
-
step: 25,
|
|
1312
|
-
placeholder: "Pick a font size"
|
|
1313
|
-
})]
|
|
1314
|
-
});
|
|
1315
|
-
}
|
|
1316
1294
|
const valueTypes = Object.values(ValueType).map((v) => ({
|
|
1317
1295
|
label: v,
|
|
1318
1296
|
value: v
|
|
@@ -1331,16 +1309,16 @@ function ValueTypeSelector({
|
|
|
1331
1309
|
sx
|
|
1332
1310
|
});
|
|
1333
1311
|
}
|
|
1334
|
-
function VizTablePanel(
|
|
1335
|
-
var
|
|
1336
|
-
conf:
|
|
1337
|
-
} =
|
|
1312
|
+
function VizTablePanel(_a) {
|
|
1313
|
+
var _b = _a, {
|
|
1314
|
+
conf: _c
|
|
1315
|
+
} = _b, _d = _c, {
|
|
1338
1316
|
columns
|
|
1339
|
-
} =
|
|
1317
|
+
} = _d, restConf = __objRest(_d, [
|
|
1340
1318
|
"columns"
|
|
1341
1319
|
]), {
|
|
1342
1320
|
setConf
|
|
1343
|
-
} =
|
|
1321
|
+
} = _b;
|
|
1344
1322
|
const form = useForm({
|
|
1345
1323
|
initialValues: __spreadValues({
|
|
1346
1324
|
id_field: "id",
|
|
@@ -1406,10 +1384,20 @@ function VizTablePanel(_e) {
|
|
|
1406
1384
|
flexGrow: 1
|
|
1407
1385
|
}
|
|
1408
1386
|
},
|
|
1409
|
-
children: [/* @__PURE__ */ jsx(
|
|
1410
|
-
label: "Horizontal Spacing"
|
|
1411
|
-
|
|
1412
|
-
|
|
1387
|
+
children: [/* @__PURE__ */ jsx(TextInput, __spreadValues({
|
|
1388
|
+
label: "Horizontal Spacing",
|
|
1389
|
+
placeholder: "10px, 1em, 1rem, 100%...",
|
|
1390
|
+
required: true,
|
|
1391
|
+
sx: {
|
|
1392
|
+
flex: 1
|
|
1393
|
+
}
|
|
1394
|
+
}, form.getInputProps("horizontalSpacing"))), /* @__PURE__ */ jsx(TextInput, __spreadValues({
|
|
1395
|
+
label: "Vertical Spacing",
|
|
1396
|
+
placeholder: "10px, 1em, 1rem, 100%...",
|
|
1397
|
+
required: true,
|
|
1398
|
+
sx: {
|
|
1399
|
+
flex: 1
|
|
1400
|
+
}
|
|
1413
1401
|
}, form.getInputProps("verticalSpacing")))]
|
|
1414
1402
|
}), /* @__PURE__ */ jsx(Group, {
|
|
1415
1403
|
position: "apart",
|
|
@@ -1420,8 +1408,13 @@ function VizTablePanel(_e) {
|
|
|
1420
1408
|
flexGrow: 1
|
|
1421
1409
|
}
|
|
1422
1410
|
},
|
|
1423
|
-
children: /* @__PURE__ */ jsx(
|
|
1424
|
-
label: "Font Size"
|
|
1411
|
+
children: /* @__PURE__ */ jsx(TextInput, __spreadValues({
|
|
1412
|
+
label: "Font Size",
|
|
1413
|
+
placeholder: "10px, 1em, 1rem, 100%...",
|
|
1414
|
+
required: true,
|
|
1415
|
+
sx: {
|
|
1416
|
+
flex: 1
|
|
1417
|
+
}
|
|
1425
1418
|
}, form.getInputProps("size")))
|
|
1426
1419
|
}), /* @__PURE__ */ jsxs(Group, {
|
|
1427
1420
|
direction: "column",
|
|
@@ -1553,7 +1546,7 @@ const marks = [{
|
|
|
1553
1546
|
label: "bold",
|
|
1554
1547
|
value: 100
|
|
1555
1548
|
}];
|
|
1556
|
-
function
|
|
1549
|
+
function MantineFontWeightSlider({
|
|
1557
1550
|
label,
|
|
1558
1551
|
value,
|
|
1559
1552
|
onChange
|
|
@@ -1662,7 +1655,17 @@ function VizTextPanel({
|
|
|
1662
1655
|
children: [/* @__PURE__ */ jsx(Text, {
|
|
1663
1656
|
children: "Color"
|
|
1664
1657
|
}), /* @__PURE__ */ jsx(MantineColorSelector, __spreadValues({}, form.getListInputProps("paragraphs", index2, "color")))]
|
|
1665
|
-
}), /* @__PURE__ */
|
|
1658
|
+
}), /* @__PURE__ */ jsx(Group, {
|
|
1659
|
+
direction: "column",
|
|
1660
|
+
grow: true,
|
|
1661
|
+
children: /* @__PURE__ */ jsx(TextInput, __spreadValues({
|
|
1662
|
+
label: "Font Size",
|
|
1663
|
+
placeholder: "10px, 1em, 1rem, 100%...",
|
|
1664
|
+
sx: {
|
|
1665
|
+
flex: 1
|
|
1666
|
+
}
|
|
1667
|
+
}, form.getListInputProps("paragraphs", index2, "size")))
|
|
1668
|
+
}), /* @__PURE__ */ jsx(Group, {
|
|
1666
1669
|
position: "apart",
|
|
1667
1670
|
grow: true,
|
|
1668
1671
|
sx: {
|
|
@@ -1671,11 +1674,9 @@ function VizTextPanel({
|
|
|
1671
1674
|
maxWidth: "100%"
|
|
1672
1675
|
}
|
|
1673
1676
|
},
|
|
1674
|
-
children:
|
|
1675
|
-
label: "Font Size"
|
|
1676
|
-
}, form.getListInputProps("paragraphs", index2, "size"))), /* @__PURE__ */ jsx(MantineFontSizeSlider, __spreadValues({
|
|
1677
|
+
children: /* @__PURE__ */ jsx(MantineFontWeightSlider, __spreadValues({
|
|
1677
1678
|
label: "Font Weight"
|
|
1678
|
-
}, form.getListInputProps("paragraphs", index2, "weight")))
|
|
1679
|
+
}, form.getListInputProps("paragraphs", index2, "weight")))
|
|
1679
1680
|
}), /* @__PURE__ */ jsx(ActionIcon, {
|
|
1680
1681
|
color: "red",
|
|
1681
1682
|
variant: "hover",
|
|
@@ -1793,7 +1794,10 @@ function VizConfig({}) {
|
|
|
1793
1794
|
children: [/* @__PURE__ */ jsx(EditTitle, {}), /* @__PURE__ */ jsx(EditDescription, {}), /* @__PURE__ */ jsx(Divider, {}), /* @__PURE__ */ jsx(EditVizConf, {})]
|
|
1794
1795
|
});
|
|
1795
1796
|
}
|
|
1796
|
-
function
|
|
1797
|
+
function PanelSettingsModal({
|
|
1798
|
+
opened,
|
|
1799
|
+
close
|
|
1800
|
+
}) {
|
|
1797
1801
|
const {
|
|
1798
1802
|
freezeLayout
|
|
1799
1803
|
} = React.useContext(LayoutStateContext);
|
|
@@ -1803,151 +1807,141 @@ function PanelSettings({}) {
|
|
|
1803
1807
|
viz,
|
|
1804
1808
|
title
|
|
1805
1809
|
} = React.useContext(PanelContext);
|
|
1806
|
-
const [opened, setOpened] = React.useState(false);
|
|
1807
|
-
const open = () => setOpened(true);
|
|
1808
1810
|
React.useEffect(() => {
|
|
1809
1811
|
freezeLayout(opened);
|
|
1810
1812
|
}, [opened]);
|
|
1811
|
-
return /* @__PURE__ */
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
"
|
|
1827
|
-
height: "100%"
|
|
1828
|
-
},
|
|
1829
|
-
main: {
|
|
1830
|
-
height: "100%",
|
|
1831
|
-
width: "100%"
|
|
1832
|
-
}
|
|
1813
|
+
return /* @__PURE__ */ jsx(Modal, {
|
|
1814
|
+
size: "96vw",
|
|
1815
|
+
overflow: "inside",
|
|
1816
|
+
opened,
|
|
1817
|
+
onClose: close,
|
|
1818
|
+
title,
|
|
1819
|
+
trapFocus: true,
|
|
1820
|
+
onDragStart: (e) => {
|
|
1821
|
+
e.stopPropagation();
|
|
1822
|
+
},
|
|
1823
|
+
children: /* @__PURE__ */ jsx(AppShell, {
|
|
1824
|
+
sx: {
|
|
1825
|
+
height: "90vh",
|
|
1826
|
+
maxHeight: "calc(100vh - 185px)",
|
|
1827
|
+
".mantine-AppShell-body": {
|
|
1828
|
+
height: "100%"
|
|
1833
1829
|
},
|
|
1834
|
-
|
|
1835
|
-
navbar: /* @__PURE__ */ jsx(Navbar, {
|
|
1836
|
-
width: {
|
|
1837
|
-
base: "40%"
|
|
1838
|
-
},
|
|
1830
|
+
main: {
|
|
1839
1831
|
height: "100%",
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
})
|
|
1861
|
-
})
|
|
1862
|
-
|
|
1832
|
+
width: "100%"
|
|
1833
|
+
}
|
|
1834
|
+
},
|
|
1835
|
+
padding: "md",
|
|
1836
|
+
navbar: /* @__PURE__ */ jsx(Navbar, {
|
|
1837
|
+
width: {
|
|
1838
|
+
base: "40%"
|
|
1839
|
+
},
|
|
1840
|
+
height: "100%",
|
|
1841
|
+
p: "xs",
|
|
1842
|
+
children: /* @__PURE__ */ jsxs(Tabs, {
|
|
1843
|
+
initialTab: 1,
|
|
1844
|
+
children: [/* @__PURE__ */ jsx(Tabs.Tab, {
|
|
1845
|
+
label: "Context",
|
|
1846
|
+
children: /* @__PURE__ */ jsx(ContextInfo, {})
|
|
1847
|
+
}), /* @__PURE__ */ jsx(Tabs.Tab, {
|
|
1848
|
+
label: "SQL Snippets",
|
|
1849
|
+
children: /* @__PURE__ */ jsx(SQLSnippetsTab, {})
|
|
1850
|
+
}), /* @__PURE__ */ jsx(Tabs.Tab, {
|
|
1851
|
+
label: "SQL",
|
|
1852
|
+
children: /* @__PURE__ */ jsx(QueryEditor, {})
|
|
1853
|
+
}), /* @__PURE__ */ jsxs(Tabs.Tab, {
|
|
1854
|
+
label: "Data",
|
|
1855
|
+
children: [/* @__PURE__ */ jsx(LoadingOverlay, {
|
|
1856
|
+
visible: loading
|
|
1857
|
+
}), /* @__PURE__ */ jsx(QueryResult, {})]
|
|
1858
|
+
}), /* @__PURE__ */ jsx(Tabs.Tab, {
|
|
1859
|
+
label: "Viz Config",
|
|
1860
|
+
children: /* @__PURE__ */ jsx(VizConfig, {})
|
|
1861
|
+
})]
|
|
1862
|
+
})
|
|
1863
|
+
}),
|
|
1864
|
+
children: /* @__PURE__ */ jsx(ErrorBoundary, {
|
|
1863
1865
|
children: /* @__PURE__ */ jsx(Viz, {
|
|
1864
1866
|
viz,
|
|
1865
1867
|
data,
|
|
1866
1868
|
loading
|
|
1867
1869
|
})
|
|
1868
1870
|
})
|
|
1869
|
-
})
|
|
1870
|
-
variant: "hover",
|
|
1871
|
-
color: "blue",
|
|
1872
|
-
loading,
|
|
1873
|
-
onClick: open,
|
|
1874
|
-
children: /* @__PURE__ */ jsx(Settings, {
|
|
1875
|
-
size: 16
|
|
1876
|
-
})
|
|
1877
|
-
})]
|
|
1871
|
+
})
|
|
1878
1872
|
});
|
|
1879
1873
|
}
|
|
1880
|
-
function
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1874
|
+
function PanelTitleBar({}) {
|
|
1875
|
+
const [opened, setOpened] = React.useState(false);
|
|
1876
|
+
const open = () => setOpened(true);
|
|
1877
|
+
const close = () => setOpened(false);
|
|
1878
|
+
const {
|
|
1879
|
+
title,
|
|
1880
|
+
description,
|
|
1881
|
+
loading,
|
|
1882
|
+
refreshData
|
|
1883
|
+
} = React.useContext(PanelContext);
|
|
1884
|
+
const {
|
|
1885
|
+
inEditMode
|
|
1886
|
+
} = React.useContext(LayoutStateContext);
|
|
1884
1887
|
return /* @__PURE__ */ jsxs(Group, {
|
|
1885
|
-
position: "
|
|
1888
|
+
position: "apart",
|
|
1889
|
+
noWrap: true,
|
|
1886
1890
|
sx: {
|
|
1887
1891
|
borderBottom: "1px solid #eee",
|
|
1888
1892
|
paddingBottom: "5px"
|
|
1889
1893
|
},
|
|
1890
|
-
children: [
|
|
1891
|
-
|
|
1892
|
-
sx: {
|
|
1893
|
-
marginLeft: "5px",
|
|
1894
|
-
display: "inline"
|
|
1895
|
-
},
|
|
1896
|
-
children: title
|
|
1897
|
-
}), description && /* @__PURE__ */ jsx("div", {
|
|
1898
|
-
children: /* @__PURE__ */ jsxs(Tooltip, {
|
|
1894
|
+
children: [/* @__PURE__ */ jsx(Group, {
|
|
1895
|
+
children: description && /* @__PURE__ */ jsx(Tooltip, {
|
|
1899
1896
|
label: description,
|
|
1900
1897
|
withArrow: true,
|
|
1901
|
-
children:
|
|
1898
|
+
children: /* @__PURE__ */ jsx(InfoCircle, {
|
|
1902
1899
|
size: 12,
|
|
1903
1900
|
style: {
|
|
1904
1901
|
verticalAlign: "baseline",
|
|
1905
1902
|
cursor: "pointer"
|
|
1906
1903
|
}
|
|
1907
|
-
})
|
|
1908
|
-
weight: "bold",
|
|
1909
|
-
sx: {
|
|
1910
|
-
marginLeft: "5px",
|
|
1911
|
-
display: "inline"
|
|
1912
|
-
},
|
|
1913
|
-
children: title
|
|
1914
|
-
})]
|
|
1904
|
+
})
|
|
1915
1905
|
})
|
|
1916
|
-
})
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
} = React.useContext(PanelContext);
|
|
1926
|
-
const {
|
|
1927
|
-
inEditMode
|
|
1928
|
-
} = React.useContext(LayoutStateContext);
|
|
1929
|
-
return /* @__PURE__ */ jsxs(Fragment, {
|
|
1930
|
-
children: [/* @__PURE__ */ jsx(PanelTitle, {
|
|
1931
|
-
title,
|
|
1932
|
-
description
|
|
1933
|
-
}), /* @__PURE__ */ jsxs(Group, {
|
|
1906
|
+
}), /* @__PURE__ */ jsx(Group, {
|
|
1907
|
+
grow: true,
|
|
1908
|
+
position: "center",
|
|
1909
|
+
children: /* @__PURE__ */ jsx(Text, {
|
|
1910
|
+
lineClamp: 1,
|
|
1911
|
+
weight: "bold",
|
|
1912
|
+
children: title
|
|
1913
|
+
})
|
|
1914
|
+
}), /* @__PURE__ */ jsx(Group, {
|
|
1934
1915
|
position: "right",
|
|
1935
1916
|
spacing: 0,
|
|
1936
1917
|
sx: {
|
|
1937
|
-
position: "absolute",
|
|
1938
|
-
right: "15px",
|
|
1939
|
-
top: "4px",
|
|
1940
1918
|
height: "28px"
|
|
1941
1919
|
},
|
|
1942
|
-
children:
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
})
|
|
1950
|
-
|
|
1920
|
+
children: /* @__PURE__ */ jsxs(Menu, {
|
|
1921
|
+
children: [/* @__PURE__ */ jsx(Menu.Item, {
|
|
1922
|
+
onClick: refreshData,
|
|
1923
|
+
icon: /* @__PURE__ */ jsx(Refresh, {
|
|
1924
|
+
size: 14
|
|
1925
|
+
}),
|
|
1926
|
+
children: "Refresh"
|
|
1927
|
+
}), inEditMode && /* @__PURE__ */ jsx(Menu.Item, {
|
|
1928
|
+
onClick: open,
|
|
1929
|
+
icon: /* @__PURE__ */ jsx(Settings, {
|
|
1930
|
+
size: 14
|
|
1931
|
+
}),
|
|
1932
|
+
children: "Settings"
|
|
1933
|
+
}), /* @__PURE__ */ jsx(Divider, {}), /* @__PURE__ */ jsx(Menu.Item, {
|
|
1934
|
+
color: "red",
|
|
1935
|
+
disabled: true,
|
|
1936
|
+
icon: /* @__PURE__ */ jsx(Trash, {
|
|
1937
|
+
size: 14
|
|
1938
|
+
}),
|
|
1939
|
+
children: "Delete"
|
|
1940
|
+
})]
|
|
1941
|
+
})
|
|
1942
|
+
}), inEditMode && /* @__PURE__ */ jsx(PanelSettingsModal, {
|
|
1943
|
+
opened,
|
|
1944
|
+
close
|
|
1951
1945
|
})]
|
|
1952
1946
|
});
|
|
1953
1947
|
}
|
|
@@ -1956,7 +1950,10 @@ function Panel({
|
|
|
1956
1950
|
viz: initialViz,
|
|
1957
1951
|
sql: initialSQL,
|
|
1958
1952
|
title: initialTitle,
|
|
1959
|
-
description: initialDesc
|
|
1953
|
+
description: initialDesc,
|
|
1954
|
+
update,
|
|
1955
|
+
layout,
|
|
1956
|
+
id
|
|
1960
1957
|
}) {
|
|
1961
1958
|
const contextInfo = React.useContext(ContextInfoContext);
|
|
1962
1959
|
const definitions = React.useContext(DefinitionContext);
|
|
@@ -1964,12 +1961,22 @@ function Panel({
|
|
|
1964
1961
|
const [description, setDescription] = React.useState(initialDesc);
|
|
1965
1962
|
const [sql, setSQL] = React.useState(initialSQL);
|
|
1966
1963
|
const [viz, setViz] = React.useState(initialViz);
|
|
1964
|
+
React.useEffect(() => {
|
|
1965
|
+
update({
|
|
1966
|
+
id,
|
|
1967
|
+
layout,
|
|
1968
|
+
title,
|
|
1969
|
+
description,
|
|
1970
|
+
sql,
|
|
1971
|
+
viz
|
|
1972
|
+
});
|
|
1973
|
+
}, [title, description, sql, viz, id, layout]);
|
|
1967
1974
|
const {
|
|
1968
1975
|
data = [],
|
|
1969
1976
|
loading,
|
|
1970
1977
|
refresh
|
|
1971
|
-
} = useRequest(queryBySQL(sql, contextInfo, definitions), {
|
|
1972
|
-
refreshDeps: [contextInfo]
|
|
1978
|
+
} = useRequest(queryBySQL(sql, contextInfo, definitions, title), {
|
|
1979
|
+
refreshDeps: [contextInfo, definitions]
|
|
1973
1980
|
});
|
|
1974
1981
|
const refreshData = refresh;
|
|
1975
1982
|
return /* @__PURE__ */ jsx(PanelContext.Provider, {
|
|
@@ -1988,10 +1995,12 @@ function Panel({
|
|
|
1988
1995
|
},
|
|
1989
1996
|
children: /* @__PURE__ */ jsxs(Container, {
|
|
1990
1997
|
className: "panel-root",
|
|
1991
|
-
children: [/* @__PURE__ */ jsx(PanelTitleBar, {}), /* @__PURE__ */ jsx(
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1998
|
+
children: [/* @__PURE__ */ jsx(PanelTitleBar, {}), /* @__PURE__ */ jsx(ErrorBoundary, {
|
|
1999
|
+
children: /* @__PURE__ */ jsx(Viz, {
|
|
2000
|
+
viz,
|
|
2001
|
+
data,
|
|
2002
|
+
loading
|
|
2003
|
+
})
|
|
1995
2004
|
})]
|
|
1996
2005
|
})
|
|
1997
2006
|
});
|
|
@@ -2000,6 +2009,7 @@ var index = "";
|
|
|
2000
2009
|
const ResponsiveReactGridLayout = WidthProvider(Responsive);
|
|
2001
2010
|
function DashboardLayout({
|
|
2002
2011
|
panels,
|
|
2012
|
+
setPanels,
|
|
2003
2013
|
className = "layout",
|
|
2004
2014
|
cols = {
|
|
2005
2015
|
lg: 12,
|
|
@@ -2019,14 +2029,30 @@ function DashboardLayout({
|
|
|
2019
2029
|
setBreakpoint(breakpoint);
|
|
2020
2030
|
setLocalCols(localCols);
|
|
2021
2031
|
};
|
|
2032
|
+
const onLayoutChange = React.useCallback((currentLayout) => {
|
|
2033
|
+
const m2 = /* @__PURE__ */ new Map();
|
|
2034
|
+
currentLayout.forEach((_a) => {
|
|
2035
|
+
var _b = _a, {
|
|
2036
|
+
i
|
|
2037
|
+
} = _b, rest = __objRest(_b, [
|
|
2038
|
+
"i"
|
|
2039
|
+
]);
|
|
2040
|
+
m2.set(i, rest);
|
|
2041
|
+
});
|
|
2042
|
+
const newPanels = panels.map((p2) => __spreadProps(__spreadValues({}, p2), {
|
|
2043
|
+
layout: m2.get(p2.id)
|
|
2044
|
+
}));
|
|
2045
|
+
setPanels.setState(newPanels);
|
|
2046
|
+
}, [panels, setPanels]);
|
|
2022
2047
|
return /* @__PURE__ */ jsx(ResponsiveReactGridLayout, {
|
|
2023
2048
|
onBreakpointChange,
|
|
2049
|
+
onLayoutChange,
|
|
2024
2050
|
className,
|
|
2025
2051
|
cols,
|
|
2026
2052
|
rowHeight,
|
|
2027
2053
|
isDraggable,
|
|
2028
2054
|
isResizable,
|
|
2029
|
-
children: panels.map((_a) => {
|
|
2055
|
+
children: panels.map((_a, index2) => {
|
|
2030
2056
|
var _b = _a, {
|
|
2031
2057
|
id
|
|
2032
2058
|
} = _b, rest = __objRest(_b, [
|
|
@@ -2034,9 +2060,14 @@ function DashboardLayout({
|
|
|
2034
2060
|
]);
|
|
2035
2061
|
return /* @__PURE__ */ jsx("div", {
|
|
2036
2062
|
"data-grid": rest.layout,
|
|
2037
|
-
children: /* @__PURE__ */ jsx(Panel, __spreadValues({
|
|
2038
|
-
|
|
2039
|
-
}, rest)
|
|
2063
|
+
children: /* @__PURE__ */ jsx(Panel, __spreadProps(__spreadValues({
|
|
2064
|
+
id
|
|
2065
|
+
}, rest), {
|
|
2066
|
+
destroy: () => onRemoveItem(id),
|
|
2067
|
+
update: (panel) => {
|
|
2068
|
+
setPanels.setItem(index2, panel);
|
|
2069
|
+
}
|
|
2070
|
+
}))
|
|
2040
2071
|
}, id);
|
|
2041
2072
|
})
|
|
2042
2073
|
});
|
|
@@ -2074,7 +2105,9 @@ function ModeToggler({
|
|
|
2074
2105
|
function DashboardActions({
|
|
2075
2106
|
mode,
|
|
2076
2107
|
setMode,
|
|
2077
|
-
|
|
2108
|
+
hasChanges,
|
|
2109
|
+
addPanel,
|
|
2110
|
+
saveChanges
|
|
2078
2111
|
}) {
|
|
2079
2112
|
const inEditMode = mode === DashboardMode.Edit;
|
|
2080
2113
|
return /* @__PURE__ */ jsxs(Group, {
|
|
@@ -2100,15 +2133,16 @@ function DashboardActions({
|
|
|
2100
2133
|
}), /* @__PURE__ */ jsx(Button, {
|
|
2101
2134
|
variant: "default",
|
|
2102
2135
|
size: "sm",
|
|
2103
|
-
|
|
2136
|
+
onClick: saveChanges,
|
|
2137
|
+
disabled: !hasChanges,
|
|
2104
2138
|
leftIcon: /* @__PURE__ */ jsx(DeviceFloppy, {
|
|
2105
2139
|
size: 20
|
|
2106
2140
|
}),
|
|
2107
|
-
children: "Save
|
|
2141
|
+
children: "Save Changes"
|
|
2108
2142
|
}), /* @__PURE__ */ jsx(Button, {
|
|
2109
2143
|
color: "red",
|
|
2110
2144
|
size: "sm",
|
|
2111
|
-
disabled:
|
|
2145
|
+
disabled: !hasChanges,
|
|
2112
2146
|
leftIcon: /* @__PURE__ */ jsx(Recycle, {
|
|
2113
2147
|
size: 20
|
|
2114
2148
|
}),
|
|
@@ -2127,25 +2161,41 @@ function DashboardActions({
|
|
|
2127
2161
|
}
|
|
2128
2162
|
function Dashboard({
|
|
2129
2163
|
dashboard,
|
|
2164
|
+
update,
|
|
2130
2165
|
className = "dashboard"
|
|
2131
2166
|
}) {
|
|
2132
2167
|
const [layoutFrozen, freezeLayout] = React.useState(false);
|
|
2133
|
-
const [newCounter, setNewCounter] = React.useState(0);
|
|
2134
2168
|
const [breakpoint, setBreakpoint] = React.useState();
|
|
2135
2169
|
const [localCols, setLocalCols] = React.useState();
|
|
2136
|
-
const [panels, setPanels] =
|
|
2170
|
+
const [panels, setPanels] = useListState(dashboard.panels);
|
|
2137
2171
|
const [sqlSnippets, setSQLSnippets] = React.useState(dashboard.definition.sqlSnippets);
|
|
2138
2172
|
const [mode, setMode] = React.useState(DashboardMode.Edit);
|
|
2173
|
+
const hasChanges = React.useMemo(() => {
|
|
2174
|
+
const cleanJSON = (v) => JSON.parse(JSON.stringify(v));
|
|
2175
|
+
const panelsEqual = _.isEqual(cleanJSON(panels), cleanJSON(dashboard.panels));
|
|
2176
|
+
if (!panelsEqual) {
|
|
2177
|
+
return true;
|
|
2178
|
+
}
|
|
2179
|
+
return !_.isEqual(sqlSnippets, dashboard.definition.sqlSnippets);
|
|
2180
|
+
}, [dashboard, panels, sqlSnippets]);
|
|
2181
|
+
const saveDashboardChanges = async () => {
|
|
2182
|
+
const d = _.merge({}, dashboard, {
|
|
2183
|
+
panels
|
|
2184
|
+
}, {
|
|
2185
|
+
definition: {
|
|
2186
|
+
sqlSnippets
|
|
2187
|
+
}
|
|
2188
|
+
});
|
|
2189
|
+
await update(d);
|
|
2190
|
+
};
|
|
2139
2191
|
const addPanel = () => {
|
|
2140
|
-
|
|
2141
|
-
setNewCounter((v) => v + 1);
|
|
2142
|
-
const id = "n" + newCounter;
|
|
2192
|
+
const id = randomId();
|
|
2143
2193
|
const newItem = {
|
|
2144
2194
|
id,
|
|
2145
2195
|
layout: {
|
|
2146
|
-
x:
|
|
2196
|
+
x: 0,
|
|
2147
2197
|
y: Infinity,
|
|
2148
|
-
w:
|
|
2198
|
+
w: 3,
|
|
2149
2199
|
h: 4
|
|
2150
2200
|
},
|
|
2151
2201
|
title: `New Panel - ${id}`,
|
|
@@ -2156,21 +2206,21 @@ function Dashboard({
|
|
|
2156
2206
|
conf: {}
|
|
2157
2207
|
}
|
|
2158
2208
|
};
|
|
2159
|
-
setPanels(
|
|
2209
|
+
setPanels.append(newItem);
|
|
2160
2210
|
};
|
|
2161
2211
|
const removePanelByID = (id) => {
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
}));
|
|
2212
|
+
const index2 = panels.findIndex((p2) => p2.id === id);
|
|
2213
|
+
setPanels.remove(index2);
|
|
2165
2214
|
};
|
|
2166
2215
|
const inEditMode = mode === DashboardMode.Edit;
|
|
2216
|
+
const definitions = React.useMemo(() => ({
|
|
2217
|
+
sqlSnippets,
|
|
2218
|
+
setSQLSnippets
|
|
2219
|
+
}), [sqlSnippets, setSQLSnippets]);
|
|
2167
2220
|
return /* @__PURE__ */ jsx("div", {
|
|
2168
2221
|
className,
|
|
2169
2222
|
children: /* @__PURE__ */ jsx(DefinitionContext.Provider, {
|
|
2170
|
-
value:
|
|
2171
|
-
sqlSnippets,
|
|
2172
|
-
setSQLSnippets
|
|
2173
|
-
},
|
|
2223
|
+
value: definitions,
|
|
2174
2224
|
children: /* @__PURE__ */ jsxs(LayoutStateContext.Provider, {
|
|
2175
2225
|
value: {
|
|
2176
2226
|
layoutFrozen,
|
|
@@ -2181,9 +2231,12 @@ function Dashboard({
|
|
|
2181
2231
|
children: [/* @__PURE__ */ jsx(DashboardActions, {
|
|
2182
2232
|
mode,
|
|
2183
2233
|
setMode,
|
|
2184
|
-
|
|
2234
|
+
hasChanges,
|
|
2235
|
+
addPanel,
|
|
2236
|
+
saveChanges: saveDashboardChanges
|
|
2185
2237
|
}), /* @__PURE__ */ jsx(DashboardLayout, {
|
|
2186
2238
|
panels,
|
|
2239
|
+
setPanels,
|
|
2187
2240
|
isDraggable: inEditMode && !layoutFrozen,
|
|
2188
2241
|
isResizable: inEditMode && !layoutFrozen,
|
|
2189
2242
|
onRemoveItem: removePanelByID,
|
package/dist/dashboard.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(p,
|
|
1
|
+
(function(p,S){typeof exports=="object"&&typeof module!="undefined"?S(exports,require("react"),require("lodash"),require("react-grid-layout"),require("@mantine/core"),require("ahooks"),require("axios"),require("tabler-icons-react"),require("@mantine/hooks"),require("echarts-for-react/lib/core"),require("echarts/core"),require("echarts/charts"),require("echarts/renderers"),require("echarts/components"),require("numbro"),require("echarts-gl"),require("@mantine/prism"),require("@mantine/form"),require("react-hook-form")):typeof define=="function"&&define.amd?define(["exports","react","lodash","react-grid-layout","@mantine/core","ahooks","axios","tabler-icons-react","@mantine/hooks","echarts-for-react/lib/core","echarts/core","echarts/charts","echarts/renderers","echarts/components","numbro","echarts-gl","@mantine/prism","@mantine/form","react-hook-form"],S):(p=typeof globalThis!="undefined"?globalThis:p||self,S(p.dashboard={},p.React,p._,p["react-grid-layout"],p["@mantine/core"],p.ahooks,p.axios,p["tabler-icons-react"],p["@mantine/hooks"],p["echarts-for-react/lib/core"],p["echarts/core"],p["echarts/charts"],p["echarts/renderers"],p["echarts/components"],p.numbro,p["echarts-gl"],p["@mantine/prism"],p["@mantine/form"],p["react-hook-form"]))})(this,function(p,S,C,w,t,ve,ye,y,P,Se,Ce,X,H,A,we,zt,M,L,B){"use strict";var wt=Object.defineProperty,Tt=Object.defineProperties;var _t=Object.getOwnPropertyDescriptors;var K=Object.getOwnPropertySymbols;var ge=Object.prototype.hasOwnProperty,be=Object.prototype.propertyIsEnumerable;var xe=(p,S,C)=>S in p?wt(p,S,{enumerable:!0,configurable:!0,writable:!0,value:C}):p[S]=C,m=(p,S)=>{for(var C in S||(S={}))ge.call(S,C)&&xe(p,C,S[C]);if(K)for(var C of K(S))be.call(S,C)&&xe(p,C,S[C]);return p},k=(p,S)=>Tt(p,_t(S));var I=(p,S)=>{var C={};for(var w in p)ge.call(p,w)&&S.indexOf(w)<0&&(C[w]=p[w]);if(p!=null&&K)for(var w of K(p))S.indexOf(w)<0&&be.call(p,w)&&(C[w]=p[w]);return C};function j(n){return n&&typeof n=="object"&&"default"in n?n:{default:n}}function Te(n){if(n&&n.__esModule)return n;var i=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});return n&&Object.keys(n).forEach(function(r){if(r!=="default"){var a=Object.getOwnPropertyDescriptor(n,r);Object.defineProperty(i,r,a.get?a:{enumerable:!0,get:function(){return n[r]}})}}),i.default=n,Object.freeze(i)}var d=j(S),T=j(C),_e=j(ye),Z=j(Se),$=Te(Ce),re=j(we),q=(n=>(n.Use="use",n.Edit="edit",n))(q||{});const ze={layoutFrozen:!1,freezeLayout:()=>{},mode:q.Edit,inEditMode:!1},R=d.default.createContext(ze),Pe=(n=>(i,r,a={})=>{const o=m({"X-Requested-With":"XMLHttpRequest","Content-Type":a.string?"application/x-www-form-urlencoded":"application/json"},a.headers),s={baseURL:"http://localhost:31200",method:n,url:i,params:n==="GET"?r:a.params,headers:o};return n==="POST"&&(s.data=a.string?JSON.stringify(r):r),_e.default(s).then(l=>l.data).catch(l=>Promise.reject(l))})("POST");function ae(n,i){const r=Object.keys(i),a=Object.values(i);return new Function(...r,`return \`${n}\`;`)(...a)}function Ie(n,i){const r=i.sqlSnippets.reduce((a,o)=>(a[o.key]=ae(o.value,n),a),{});return T.default.merge({},r,n)}const Le=(n,i,r,a)=>async()=>{if(!n)return[];const o=n.includes("$"),s=Ie(i,r);if(console.log(o,s),o&&Object.keys(s).length===0)return console.error(`[queryBySQL] insufficient params for {${a}}'s SQL`),[];const l=ae(n,s);return o&&(console.groupCollapsed(`Final SQL for: ${a}`),console.log(l),console.groupEnd()),await Pe("/query",{sql:l})},oe={},De=oe,ee=d.default.createContext(oe),Ge={data:[],loading:!1,title:"",setTitle:()=>{},description:"",setDescription:()=>{},sql:"",setSQL:()=>{},viz:{type:"",conf:{}},setViz:()=>{},refreshData:()=>{}},D=d.default.createContext(Ge);var Q={exports:{}},W={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,16 +6,16 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var
|
|
9
|
+
*/var ke=d.default,qe=Symbol.for("react.element"),Ee=Symbol.for("react.fragment"),Oe=Object.prototype.hasOwnProperty,Ae=ke.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Me={key:!0,ref:!0,__self:!0,__source:!0};function le(n,i,r){var a,o={},s=null,l=null;r!==void 0&&(s=""+r),i.key!==void 0&&(s=""+i.key),i.ref!==void 0&&(l=i.ref);for(a in i)Oe.call(i,a)&&!Me.hasOwnProperty(a)&&(o[a]=i[a]);if(n&&n.defaultProps)for(a in i=n.defaultProps,i)o[a]===void 0&&(o[a]=i[a]);return{$$typeof:qe,type:n,key:s,ref:l,props:o,_owner:Ae.current}}W.Fragment=Ee,W.jsx=le,W.jsxs=le,Q.exports=W;const e=Q.exports.jsx,c=Q.exports.jsxs,se=Q.exports.Fragment;class ue extends d.default.Component{constructor(i){super(i),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}render(){return this.state.hasError?e("h1",{children:"Something went wrong."}):this.props.children}}$.use([X.SunburstChart,H.CanvasRenderer]);const Be={tooltip:{show:!0},series:{type:"sunburst",radius:[0,"90%"],emphasis:{focus:"ancestor"}}};function Ne({conf:n,data:i,width:r,height:a}){const x=n,{label_field:o="name",value_field:s="value"}=x,l=I(x,["label_field","value_field"]),u=d.default.useMemo(()=>i.map(g=>({name:g[o],value:Number(g[s])})),[i,o,s]),f=d.default.useMemo(()=>{var g,v;return(v=(g=T.default.maxBy(u,z=>z.value))==null?void 0:g.value)!=null?v:1},[u]),h=d.default.useMemo(()=>({series:{label:{formatter:({name:g,value:v})=>v/f<.2?" ":g}}}),[]),b=T.default.merge(Be,h,l,{series:{data:u}});return e(Z.default,{echarts:$,option:b,style:{width:r,height:a}})}$.use([X.BarChart,X.LineChart,A.GridComponent,A.LegendComponent,A.TooltipComponent,H.CanvasRenderer]);const Fe={legend:{show:!0},tooltip:{trigger:"axis"},xAxis:{type:"category"},yAxis:{},grid:{top:30,left:10,right:10,bottom:10,containLabel:!0}};function $e({conf:n,data:i,width:r,height:a}){const o=d.default.useMemo(()=>{const s={dataset:{source:i}},l={xAxis:{data:i.map(f=>f[n.x_axis_data_key])}},u=n.series.map(b=>{var x=b,{y_axis_data_key:f}=x,h=I(x,["y_axis_data_key"]);return m({data:i.map(g=>g[f])},h)});return T.default.assign({},Fe,s,l,{series:u})},[n,i]);return!r||!a?null:e(Z.default,{echarts:$,option:o,style:{width:r,height:a}})}var E=(n=>(n.string="string",n.number="number",n.eloc="eloc",n.percentage="percentage",n))(E||{});function je({value:n}){return e(t.Text,{component:"span",children:n})}function Ve({value:n}){return e(t.Text,{component:"span",children:n})}function Re({value:n}){const i=re.default(n).format({thousandSeparated:!0});return e(t.Text,{component:"span",children:i})}function Qe({value:n}){const i=re.default(n).format({output:"percent",mantissa:3});return e(t.Text,{component:"span",children:i})}function We({value:n,type:i}){switch(i){case E.string:return e(je,{value:n});case E.eloc:return e(Ve,{value:n});case E.number:return e(Re,{value:n});case E.percentage:return e(Qe,{value:n})}}function Je({conf:n,data:i,width:r,height:a}){const b=n,{id_field:o,use_raw_columns:s,columns:l}=b,u=I(b,["id_field","use_raw_columns","columns"]),f=d.default.useMemo(()=>s?Object.keys(i==null?void 0:i[0]):l.map(x=>x.label),[s,l,i]),h=d.default.useMemo(()=>s?Object.keys(i==null?void 0:i[0]).map(x=>({label:x,value_field:x,value_type:E.string})):l,[s,l,i]);return c(t.Table,k(m({sx:{maxHeight:a}},u),{children:[e("thead",{children:e("tr",{children:f.map(x=>e("th",{children:x},x))})}),e("tbody",{children:i.map((x,g)=>e("tr",{children:h.map(({value_field:v,value_type:z})=>e("td",{children:e(t.Group,{sx:{"&, .mantine-Text-root":{fontFamily:"monospace"}},children:e(We,{value:x[v],type:z})})},x[v]))},o?x[o]:`row-${g}`))})]}))}function Ue(n,i={}){const r=Object.keys(i),a=Object.values(i);try{return new Function(...r,`return \`${n}\`;`)(...a)}catch(o){return o.message}}function Ye({conf:{paragraphs:n},data:i}){return e(se,{children:n.map((l,s)=>{var u=l,{template:r,size:a}=u,o=I(u,["template","size"]);return e(t.Text,k(m({},o),{sx:{fontSize:a},children:Ue(r,i[0])}),`${r}---${s}`)})})}$.use([A.GridComponent,A.VisualMapComponent,A.LegendComponent,A.TooltipComponent,H.CanvasRenderer]);function Ke({conf:n,data:i,width:r,height:a}){const x=n,{x_axis_data_key:o,y_axis_data_key:s,z_axis_data_key:l}=x,u=I(x,["x_axis_data_key","y_axis_data_key","z_axis_data_key"]),f=d.default.useMemo(()=>T.default.minBy(i,g=>g[l])[l],[i,l]),h=d.default.useMemo(()=>T.default.maxBy(i,g=>g[l])[l],[i,l]),b=k(m({tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:f,max:h,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:{type:"value"},yAxis3D:{type:"value"},zAxis3D:{type:"value"},grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}}},u),{series:[{type:"bar3D",wireframe:{},data:i.map(g=>[g[o],g[s],g[l]])}]});return e(Z.default,{echarts:$,option:b,style:{width:r,height:a}})}var It="";function Xe(n,i,r,a){const o={width:n,height:i,data:r,conf:a.conf};switch(a.type){case"sunburst":return e(Ne,m({},o));case"line-bar":return e($e,m({},o));case"table":return e(Je,m({},o));case"text":return e(Ye,m({},o));case"bar-3d":return e(Ke,m({},o));default:return null}}function de({viz:n,data:i,loading:r}){const{ref:a,width:o,height:s}=P.useElementSize(),l=d.default.useMemo(()=>!Array.isArray(i)||i.length===0,[i]);return r?e("div",{className:"viz-root",ref:a,children:e(t.LoadingOverlay,{visible:r})}):c("div",{className:"viz-root",ref:a,children:[l&&e(t.Text,{color:"gray",align:"center",children:"nothing to show"}),!l&&Xe(o,s,i,n)]})}function He({}){const n=d.default.useContext(ee),i="SELECT *\nFROM commit\nWHERE author_time BETWEEN '${timeRange?.[0].toISOString()}' AND '${timeRange?.[1].toISOString()}'";return c(t.Group,{direction:"column",children:[e(M.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:`-- You may refer context data *by name*
|
|
10
10
|
-- in SQL or VizConfig.
|
|
11
11
|
|
|
12
|
-
${i}`}),e(t.Text,{weight:700,children:"Avaiable context entries"}),e(
|
|
12
|
+
${i}`}),e(t.Text,{weight:700,children:"Avaiable context entries"}),e(M.Prism,{language:"json",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:JSON.stringify(n,null,2)})]})}var Lt="";function Ze({}){const{sql:n,setSQL:i}=d.default.useContext(D),[r,a]=d.default.useState(!0),o=u=>{i(u.target.value)},s=d.default.useCallback(()=>{a(u=>!u)},[]),l=d.default.useCallback(()=>{i(u=>u.trim())},[i]);return c(t.Box,{className:"sql-query-editor-root",sx:{height:"100%"},children:[e(t.Textarea,{value:n,onChange:o,minRows:20,maxRows:20}),c(t.Group,{m:"md",position:"right",children:[e(t.Button,{color:"blue",onClick:l,children:"Format"}),e(t.Button,{variant:"default",onClick:s,children:"Toggle Preview"})]}),r&&e(M.Prism,{language:"sql",withLineNumbers:!0,noCopy:!0,colorScheme:"dark",children:n})]})}const et=Ze;function tt({}){const{data:n}=d.default.useContext(D);return c("div",{className:"query-result-root",children:[c(t.Group,{mb:"xs",children:[e(t.Text,{weight:"bold",children:"Data Length: "}),n.length]}),e(M.Prism,{language:"json",colorScheme:"dark",children:JSON.stringify(n,null,2)})]})}const nt={sqlSnippets:[],setSQLSnippets:()=>{}},J=d.default.createContext(nt);function it({sqlSnippets:n,setSQLSnippets:i}){const r=d.default.useMemo(()=>({snippets:L.formList(n!=null?n:[])}),[n]),a=L.useForm({initialValues:r}),o=()=>a.addListItem("snippets",{key:P.randomId(),value:""}),s=d.default.useMemo(()=>!T.default.isEqual(a.values,r),[a.values,r]),l=({snippets:u})=>{i(u)};return e(t.Group,{direction:"column",sx:{width:"100%",position:"relative"},grow:!0,children:c("form",{onSubmit:a.onSubmit(l),children:[a.values.snippets.map((u,f)=>c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[e(t.TextInput,m({label:"Key",required:!0},a.getListInputProps("snippets",f,"key"))),e(t.Textarea,m({minRows:3,label:"Value",required:!0},a.getListInputProps("snippets",f,"value"))),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>a.removeListItem("snippets",f),sx:{position:"absolute",top:15,right:5},children:e(y.Trash,{size:16})})]},f)),c(t.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"80%"},mx:"auto",children:[e(t.Button,{variant:"default",onClick:o,children:"Add a snippet"}),e(t.Button,{color:"blue",type:"submit",disabled:!s,children:"Submit"})]})]})})}function rt({}){const{sqlSnippets:n,setSQLSnippets:i}=d.default.useContext(J),r=`SELECT *
|
|
13
13
|
FROM commit
|
|
14
|
-
WHERE \${author_time_condition}`;return c(t.Group,{direction:"column",children:[e(
|
|
14
|
+
WHERE \${author_time_condition}`;return c(t.Group,{direction:"column",children:[e(M.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,trim:!1,colorScheme:"dark",children:`-- You may refer context data *by name*
|
|
15
15
|
-- in SQL or VizConfig.
|
|
16
16
|
|
|
17
17
|
${r}
|
|
18
18
|
|
|
19
19
|
-- where author_time_condition is:
|
|
20
20
|
author_time BETWEEN '\${timeRange?.[0].toISOString()}' AND '\${timeRange?.[1].toISOString()}'
|
|
21
|
-
`}),e(t.Text,{weight:700,children:"SQL Snippets"}),e(nt,{sqlSnippets:n,setSQLSnippets:i})]})}function rt(){const{description:n,setDescription:i}=u.default.useContext(L),[r,a]=I.useInputState(n),o=n!==r,s=u.default.useCallback(()=>{!o||i(r)},[o,r]);return e(t.Textarea,{label:"Panel Description",value:r,onChange:a,minRows:2,rightSection:e(t.ActionIcon,{disabled:!o,onClick:s,sx:{alignSelf:"flex-start",marginTop:"4px"},children:e(y.DeviceFloppy,{size:20})})})}function at(){const{title:n,setTitle:i}=u.default.useContext(L),[r,a]=I.useInputState(n),o=n!==r,s=u.default.useCallback(()=>{!o||i(r)},[o,r]);return e(t.TextInput,{label:"Panel Title",value:r,onChange:a,rightSection:e(t.ActionIcon,{disabled:!o,onClick:s,children:e(y.DeviceFloppy,{size:20})})})}function lt({conf:n,setConf:i}){const r=T.default.assign({},{x_axis_data_key:"x",y_axis_data_key:"y",z_axis_data_key:"z",xAxis3D:{type:"value",name:"X Axis Name"},yAxis3D:{type:"value",name:"Y Axis Name"},zAxis3D:{type:"value",name:"Z Axis Name"}},n),{control:a,handleSubmit:o,formState:s}=O.useForm({defaultValues:r});return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:o(i),children:[e(t.Text,{children:"X Axis"}),c(t.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[e(O.Controller,{name:"x_axis_data_key",control:a,render:({field:l})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Data Key"},l))}),e(O.Controller,{name:"xAxis3D.name",control:a,render:({field:l})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Name"},l))})]}),e(t.Text,{mt:"lg",children:"Y Axis"}),c(t.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[e(O.Controller,{name:"y_axis_data_key",control:a,render:({field:l})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Data Key"},l))}),e(O.Controller,{name:"yAxis3D.name",control:a,render:({field:l})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Name"},l))})]}),e(t.Text,{mt:"lg",children:"Z Axis"}),c(t.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[e(O.Controller,{name:"z_axis_data_key",control:a,render:({field:l})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Data Key"},l))}),e(O.Controller,{name:"zAxis3D.name",control:a,render:({field:l})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Name"},l))})]}),e(t.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:c(t.Button,{color:"blue",type:"submit",children:[e(y.DeviceFloppy,{size:20}),e(t.Text,{ml:"md",children:"Save"})]})})]})})}function de({value:n,onChange:i}){const r=t.useMantineTheme(),a=u.default.useMemo(()=>Object.entries(r.colors).map(([s,l])=>({label:s,value:l[6]})),[r]),o=u.default.useMemo(()=>a.some(s=>s.value===n),[n,a]);return c(t.Group,{position:"apart",spacing:"xs",children:[e(t.TextInput,{placeholder:"Set any color",value:o?"":n,onChange:s=>i(s.currentTarget.value),rightSection:e(t.ColorSwatch,{color:o?"transparent":n,radius:4}),variant:o?"filled":"default",sx:{maxWidth:"100%",flexGrow:1}}),e(t.Text,{sx:{flexGrow:0},children:"or"}),e(t.Select,{data:a,value:n,onChange:i,variant:o?"default":"filled",placeholder:"Pick a theme color",icon:e(t.ColorSwatch,{color:o?n:"transparent",radius:4}),sx:{maxWidth:"100%",flexGrow:1}})]})}function ot({conf:n,setConf:i}){const r=u.default.useRef(null),g=n,{series:a}=g,o=z(g,["series"]),s=u.default.useMemo(()=>m({series:P.formList(a!=null?a:[])},o),[a,o]),l=P.useForm({initialValues:s}),d=()=>l.addListItem("series",{type:"bar",name:I.randomId(),showSymbol:!1,y_axis_data_key:"value",stack:"",color:"#000"}),f=u.default.useMemo(()=>!T.default.isEqual(l.values,s),[l.values,s]);return u.default.useEffect(()=>{var x;f&&((x=r==null?void 0:r.current)==null||x.click())},[f,r.current]),e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:l.onSubmit(i),children:[c(t.Group,{position:"apart",mb:"lg",sx:{position:"relative"},children:[e(t.Text,{children:"Chart Config"}),e("button",{ref:r,type:"submit",style:{display:"none"},children:"Ghost submit"})]}),e(t.TextInput,m({size:"md",mb:"lg",label:"X Axis Data Key"},l.getInputProps("x_axis_data_key"))),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{mt:"xl",mb:0,children:"Series"}),l.values.series.map((x,h)=>c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[e(t.TextInput,m({label:"Label",required:!0,sx:{flex:1}},l.getListInputProps("series",h,"name"))),c(t.Group,{direction:"row",grow:!0,noWrap:!0,children:[e(t.TextInput,m({label:"Y Axis Data key",required:!0},l.getListInputProps("series",h,"y_axis_data_key"))),e(t.TextInput,m({label:"Stack ID",placeholder:"Stack bars by this ID"},l.getListInputProps("series",h,"stack")))]}),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{children:"Color"}),e(de,m({},l.getListInputProps("series",h,"color")))]}),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>l.removeListItem("series",h),sx:{position:"absolute",top:15,right:5},children:e(y.Trash,{size:16})})]},h)),e(t.Group,{position:"center",mt:"xs",children:e(t.Button,{onClick:d,children:"Add a Series"})})]})]})})}function st(a){var o=a,{conf:s}=o,l=s,{columns:n}=l,i=z(l,["columns"]),{setConf:r}=o;const d=P.useForm({initialValues:{label_field:"name",value_field:"value"}});return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:d.onSubmit(r),children:[c(t.Group,{position:"apart",mb:"lg",sx:{position:"relative"},children:[e(t.Text,{children:"Sunburst Config"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",children:e(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}},d.getInputProps("label_field"))),e(t.TextInput,m({label:"Value Field",placeholder:"get column value by this field",required:!0,sx:{flex:1}},d.getInputProps("value_field")))]})]})})}const F=[{value:0,label:"xs"},{value:25,label:"sm"},{value:50,label:"md"},{value:75,label:"lg"},{value:100,label:"xl"}];function R({label:n,value:i,onChange:r}){var s,l;const[a,o]=u.default.useState((l=(s=F.find(d=>d.label===i))==null?void 0:s.value)!=null?l:F[0].value);return u.default.useEffect(()=>{const d=F.find(f=>f.value===a);d&&r(d.label)},[a]),c(t.Group,{direction:"column",grow:!0,spacing:"xs",mb:"lg",children:[e(t.Text,{children:n}),e(t.Slider,{label:null,marks:F,value:a,onChange:o,step:25,placeholder:"Pick a font size"})]})}const ut=Object.values(G).map(n=>({label:n,value:n}));function dt({label:n,value:i,onChange:r,sx:a}){return e(t.Select,{label:n,data:ut,value:i,onChange:r,sx:a})}function ct(a){var o=a,{conf:s}=o,l=s,{columns:n}=l,i=z(l,["columns"]),{setConf:r}=o;const d=P.useForm({initialValues:m({id_field:"id",use_raw_columns:!0,columns:P.formList(n!=null?n:[]),size:"sm",horizontalSpacing:"sm",verticalSpacing:"sm",striped:!1,highlightOnHover:!1},i)}),f=()=>d.addListItem("columns",{label:I.randomId(),value_field:"value",value_type:G.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(R,m({label:"Horizontal Spacing"},d.getInputProps("horizontalSpacing"))),e(R,m({label:"Vertical Spacing"},d.getInputProps("verticalSpacing")))]}),e(t.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:e(R,m({label:"Font Size"},d.getInputProps("size")))}),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{children:"Other"}),c(t.Group,{position:"apart",grow:!0,children:[e(t.Switch,m({label:"Striped"},d.getInputProps("striped",{type:"checkbox"}))),e(t.Switch,m({label:"Highlight on hover"},d.getInputProps("highlightOnHover",{type:"checkbox"})))]})]})]}),c(t.Group,{direction:"column",mt:"xs",spacing:"xs",grow:!0,p:"md",mb:"xl",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[e(t.Switch,m({label:"Use Original Data Columns"},d.getInputProps("use_raw_columns",{type:"checkbox"}))),!d.values.use_raw_columns&&c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{mt:"xl",mb:0,children:"Custom Columns"}),d.values.columns.map((g,x)=>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",x,"label"))),e(t.TextInput,m({label:"Value Field",placeholder:"get column value by this field",required:!0,sx:{flex:1}},d.getListInputProps("columns",x,"value_field"))),e(dt,m({label:"Value Type",sx:{flex:1}},d.getListInputProps("columns",x,"value_type")))]}),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>d.removeListItem("columns",x),sx:{position:"absolute",top:15,right:5},children:e(y.Trash,{size:16})})]},x)),e(t.Group,{position:"center",mt:"xs",children:e(t.Button,{onClick:f,children:"Add a Column"})})]})]}),e(t.Text,{weight:500,mb:"md",children:"Current Configuration:"}),e(A.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(d.values,null,2)})]})})}const Q=[{label:"initial",value:0},{label:"500",value:25},{label:"700",value:50},{label:"semibold",value:75},{label:"bold",value:100}];function pt({label:n,value:i,onChange:r}){var s,l;const[a,o]=u.default.useState((l=(s=Q.find(d=>d.label===i))==null?void 0:s.value)!=null?l:Q[0].value);return u.default.useEffect(()=>{const d=Q.find(f=>f.value===a);d&&r(d.label)},[a]),c(t.Group,{direction:"column",grow:!0,spacing:"xs",mb:"lg",children:[e(t.Text,{children:n}),e(t.Slider,{label:null,marks:Q,value:a,onChange:o,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 mt({conf:n,setConf:i}){var o;const r=P.useForm({initialValues:{paragraphs:P.formList((o=n.paragraphs)!=null?o:ce)}}),a=()=>r.addListItem("paragraphs",q(m({},ce[0]),{template:I.randomId()}));return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:r.onSubmit(i),children:[r.values.paragraphs.length===0&&e(t.Text,{color:"dimmed",align:"center",children:"Empty"}),c(t.Group,{position:"apart",mb:"xs",sx:{" + .mantine-Group-root":{marginTop:0}},children:[e(t.Text,{children:"Paragraphs"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",children:e(y.DeviceFloppy,{size:20})})]}),r.values.paragraphs.map((s,l)=>c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[e(t.TextInput,m({placeholder:"Time: ${new Date().toISOString()}",label:"Content Template",required:!0,sx:{flex:1}},r.getListInputProps("paragraphs",l,"template"))),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{children:"Color"}),e(de,m({},r.getListInputProps("paragraphs",l,"color")))]}),c(t.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:[e(R,m({label:"Font Size"},r.getListInputProps("paragraphs",l,"size"))),e(pt,m({label:"Font Weight"},r.getListInputProps("paragraphs",l,"weight")))]}),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>r.removeListItem("paragraphs",l),sx:{position:"absolute",top:15,right:5},children:e(y.Trash,{size:16})})]},l)),e(t.Group,{position:"center",mt:"md",children:e(t.Button,{onClick:a,children:"Add a Paragraph"})}),e(t.Text,{size:"sm",weight:500,mt:"md",children:"Current Configuration:"}),e(A.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(r.values,null,2)})]})})}const Z=[{value:"text",label:"Text",Panel:mt},{value:"table",label:"Table",Panel:ct},{value:"sunburst",label:"Sunburst",Panel:st},{value:"bar-3d",label:"Bar Chart (3D)",Panel:lt},{value:"line-bar",label:"Line-Bar Chart",Panel:ot}];function ht(){const{viz:n,setViz:i}=u.default.useContext(L),[r,a]=I.useInputState(n.type),o=n.type!==r,s=u.default.useCallback(()=>{!o||i(g=>q(m({},g),{type:r}))},[o,r]),l=g=>{i(x=>q(m({},x),{conf:g}))},d=g=>{try{l(JSON.parse(g))}catch(x){console.error(x)}},f=u.default.useMemo(()=>{var g;return(g=Z.find(x=>x.value===r))==null?void 0:g.Panel},[r,Z]);return c(V,{children:[e(t.Select,{label:"Visualization",value:r,onChange:a,data:Z,rightSection:e(t.ActionIcon,{disabled:!o,onClick:s,children:e(y.DeviceFloppy,{size:20})})}),f&&e(f,{conf:n.conf,setConf:l}),!f&&e(t.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(n.conf,null,2),onChange:d})]})}function ft({}){return c(t.Group,{grow:!0,direction:"column",children:[e(at,{}),e(rt,{}),e(t.Divider,{}),e(ht,{})]})}function xt({}){const{freezeLayout:n}=u.default.useContext(j),{data:i,loading:r,viz:a,title:o}=u.default.useContext(L),[s,l]=u.default.useState(!1),d=()=>l(!0);return u.default.useEffect(()=>{n(s)},[s]),c(V,{children:[e(t.Modal,{size:"96vw",overflow:"inside",opened:s,onClose:()=>l(!1),title:o,trapFocus:!0,onDragStart:f=>{f.stopPropagation()},children:e(t.AppShell,{sx:{height:"90vh",maxHeight:"calc(100vh - 185px)",".mantine-AppShell-body":{height:"100%"},main:{height:"100%",width:"100%"}},padding:"md",navbar:e(t.Navbar,{width:{base:"40%"},height:"100%",p:"xs",children:c(t.Tabs,{initialTab:1,children:[e(t.Tabs.Tab,{label:"Context",children:e(Xe,{})}),e(t.Tabs.Tab,{label:"SQL Snippets",children:e(it,{})}),e(t.Tabs.Tab,{label:"SQL",children:e(Ze,{})}),c(t.Tabs.Tab,{label:"Data",children:[e(t.LoadingOverlay,{visible:r}),e(et,{})]}),e(t.Tabs.Tab,{label:"Viz Config",children:e(ft,{})})]})}),children:e(ue,{viz:a,data:i,loading:r})})}),e(t.ActionIcon,{variant:"hover",color:"blue",loading:r,onClick:d,children:e(y.Settings,{size:16})})]})}function gt({title:n,description:i}){return c(t.Group,{position:"center",sx:{borderBottom:"1px solid #eee",paddingBottom:"5px"},children:[!i&&e(t.Text,{weight:"bold",sx:{marginLeft:"5px",display:"inline"},children:n}),i&&e("div",{children:c(t.Tooltip,{label:i,withArrow:!0,children:[e(y.InfoCircle,{size:12,style:{verticalAlign:"baseline",cursor:"pointer"}}),e(t.Text,{weight:"bold",sx:{marginLeft:"5px",display:"inline"},children:n})]})})]})}function bt({}){const{title:n,description:i,loading:r,refreshData:a}=u.default.useContext(L),{inEditMode:o}=u.default.useContext(j);return c(V,{children:[e(gt,{title:n,description:i}),c(t.Group,{position:"right",spacing:0,sx:{position:"absolute",right:"15px",top:"4px",height:"28px"},children:[e(t.ActionIcon,{variant:"hover",color:"blue",loading:r,onClick:a,children:e(y.Refresh,{size:16})}),o&&e(xt,{})]})]})}var kt="";function pe({viz:n,sql:i,title:r,description:a}){const o=u.default.useContext(H),s=u.default.useContext($),[l,d]=u.default.useState(r),[f,g]=u.default.useState(a),[x,h]=u.default.useState(i),[b,C]=u.default.useState(n),{data:_=[],loading:W,refresh:ee}=be.useRequest(Le(x,o,s),{refreshDeps:[o]}),te=ee;return e(L.Provider,{value:{data:_,loading:W,title:l,setTitle:d,description:f,setDescription:g,sql:x,setSQL:h,viz:b,setViz:C,refreshData:te},children:c(t.Container,{className:"panel-root",children:[e(bt,{}),e(ue,{viz:b,data:_,loading:W})]})})}var Gt="";const vt=w.WidthProvider(w.Responsive);function me({panels:n,className:i="layout",cols:r={lg:12,md:10,sm:8,xs:6,xxs:4},rowHeight:a=10,onRemoveItem:o,isDraggable:s,isResizable:l,setLocalCols:d,setBreakpoint:f}){return e(vt,{onBreakpointChange:(x,h)=>{f(x),d(h)},className:i,cols:r,rowHeight:a,isDraggable:s,isResizable:l,children:n.map(b=>{var C=b,{id:x}=C,h=z(C,["id"]);return e("div",{"data-grid":h.layout,children:e(pe,m({destroy:()=>o(x)},h))},x)})})}function he(n,i){return c(t.Text,{sx:{svg:{verticalAlign:"text-bottom"}},children:[n," ",i]})}function yt({mode:n,setMode:i}){return e(t.SegmentedControl,{value:n,onChange:i,data:[{label:he(e(y.PlayerPlay,{size:20}),"Use"),value:k.Use},{label:he(e(y.Paint,{size:20}),"Edit"),value:k.Edit}]})}function St({mode:n,setMode:i,addPanel:r}){const a=n===k.Edit;return c(t.Group,{position:"apart",pt:"sm",pb:"xs",children:[e(t.Group,{position:"left",children:e(yt,{mode:n,setMode:i})}),a&&c(t.Group,{position:"right",children:[e(t.Button,{variant:"default",size:"sm",onClick:r,leftIcon:e(y.PlaylistAdd,{size:20}),children:"Add a Panel"}),e(t.Button,{variant:"default",size:"sm",disabled:!0,leftIcon:e(y.DeviceFloppy,{size:20}),children:"Save Dashboard"}),e(t.Button,{color:"red",size:"sm",disabled:!0,leftIcon:e(y.Recycle,{size:20}),children:"Revert Changes"})]}),!a&&e(t.Button,{variant:"default",size:"sm",disabled:!0,leftIcon:e(y.Share,{size:20}),children:"Share"})]})}function Ct({dashboard:n,className:i="dashboard"}){const[r,a]=u.default.useState(!1),[o,s]=u.default.useState(0),[l,d]=u.default.useState(),[f,g]=u.default.useState(),[x,h]=u.default.useState(n.panels),[b,C]=u.default.useState(n.definition.sqlSnippets),[_,W]=u.default.useState(k.Edit),ee=()=>{console.log("adding","n"+o),s(re=>re+1);const J="n"+o,ie={id:J,layout:{x:x.length*2%(f||12),y:1/0,w:4,h:4},title:`New Panel - ${J}`,description:"description goes here",sql:"",viz:{type:"table",conf:{}}};h(re=>[...re,ie])},te=J=>{h(ie=>T.default.reject(ie,{id:J}))},ne=_===k.Edit;return e("div",{className:i,children:e($.Provider,{value:{sqlSnippets:b,setSQLSnippets:C},children:c(j.Provider,{value:{layoutFrozen:r,freezeLayout:a,mode:_,inEditMode:ne},children:[e(St,{mode:_,setMode:W,addPanel:ee}),e(me,{panels:x,isDraggable:ne&&!r,isResizable:ne&&!r,onRemoveItem:te,setLocalCols:g,setBreakpoint:d})]})})})}p.ContextInfoContext=H,p.Dashboard=Ct,p.DashboardLayout=me,p.DashboardMode=k,p.DefinitionContext=$,p.LayoutStateContext=j,p.Panel=pe,p.PanelContext=L,p.initialContextInfoContext=Ie,Object.defineProperties(p,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
21
|
+
`}),e(t.Text,{weight:700,children:"SQL Snippets"}),e(it,{sqlSnippets:n,setSQLSnippets:i})]})}function at(){const{description:n,setDescription:i}=d.default.useContext(D),[r,a]=P.useInputState(n),o=n!==r,s=d.default.useCallback(()=>{!o||i(r)},[o,r]);return e(t.Textarea,{label:"Panel Description",value:r,onChange:a,minRows:2,rightSection:e(t.ActionIcon,{disabled:!o,onClick:s,sx:{alignSelf:"flex-start",marginTop:"4px"},children:e(y.DeviceFloppy,{size:20})})})}function ot(){const{title:n,setTitle:i}=d.default.useContext(D),[r,a]=P.useInputState(n),o=n!==r,s=d.default.useCallback(()=>{!o||i(r)},[o,r]);return e(t.TextInput,{label:"Panel Title",value:r,onChange:a,rightSection:e(t.ActionIcon,{disabled:!o,onClick:s,children:e(y.DeviceFloppy,{size:20})})})}function lt({conf:n,setConf:i}){const r=T.default.assign({},{x_axis_data_key:"x",y_axis_data_key:"y",z_axis_data_key:"z",xAxis3D:{type:"value",name:"X Axis Name"},yAxis3D:{type:"value",name:"Y Axis Name"},zAxis3D:{type:"value",name:"Z Axis Name"}},n),{control:a,handleSubmit:o,formState:s}=B.useForm({defaultValues:r});return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:o(i),children:[e(t.Text,{children:"X Axis"}),c(t.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[e(B.Controller,{name:"x_axis_data_key",control:a,render:({field:l})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Data Key"},l))}),e(B.Controller,{name:"xAxis3D.name",control:a,render:({field:l})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Name"},l))})]}),e(t.Text,{mt:"lg",children:"Y Axis"}),c(t.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[e(B.Controller,{name:"y_axis_data_key",control:a,render:({field:l})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Data Key"},l))}),e(B.Controller,{name:"yAxis3D.name",control:a,render:({field:l})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Name"},l))})]}),e(t.Text,{mt:"lg",children:"Z Axis"}),c(t.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[e(B.Controller,{name:"z_axis_data_key",control:a,render:({field:l})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Data Key"},l))}),e(B.Controller,{name:"zAxis3D.name",control:a,render:({field:l})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Name"},l))})]}),e(t.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:c(t.Button,{color:"blue",type:"submit",children:[e(y.DeviceFloppy,{size:20}),e(t.Text,{ml:"md",children:"Save"})]})})]})})}function ce({value:n,onChange:i}){const r=t.useMantineTheme(),a=d.default.useMemo(()=>Object.entries(r.colors).map(([s,l])=>({label:s,value:l[6]})),[r]),o=d.default.useMemo(()=>a.some(s=>s.value===n),[n,a]);return c(t.Group,{position:"apart",spacing:"xs",children:[e(t.TextInput,{placeholder:"Set any color",value:o?"":n,onChange:s=>i(s.currentTarget.value),rightSection:e(t.ColorSwatch,{color:o?"transparent":n,radius:4}),variant:o?"filled":"default",sx:{maxWidth:"100%",flexGrow:1}}),e(t.Text,{sx:{flexGrow:0},children:"or"}),e(t.Select,{data:a,value:n,onChange:i,variant:o?"default":"filled",placeholder:"Pick a theme color",icon:e(t.ColorSwatch,{color:o?n:"transparent",radius:4}),sx:{maxWidth:"100%",flexGrow:1}})]})}function st({conf:n,setConf:i}){const u=n,{series:r}=u,a=I(u,["series"]),o=d.default.useMemo(()=>m({series:L.formList(r!=null?r:[])},a),[r,a]),s=L.useForm({initialValues:o}),l=()=>s.addListItem("series",{type:"bar",name:P.randomId(),showSymbol:!1,y_axis_data_key:"value",stack:"",color:"#000"});return d.default.useMemo(()=>!T.default.isEqual(s.values,o),[s.values,o]),e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:s.onSubmit(i),children:[c(t.Group,{position:"apart",mb:"lg",sx:{position:"relative"},children:[e(t.Text,{children:"Chart Config"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",children:e(y.DeviceFloppy,{size:20})})]}),e(t.TextInput,m({size:"md",mb:"lg",label:"X Axis Data Key"},s.getInputProps("x_axis_data_key"))),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{mt:"xl",mb:0,children:"Series"}),s.values.series.map((f,h)=>c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[e(t.TextInput,m({label:"Label",required:!0,sx:{flex:1}},s.getListInputProps("series",h,"name"))),c(t.Group,{direction:"row",grow:!0,noWrap:!0,children:[e(t.TextInput,m({label:"Y Axis Data key",required:!0},s.getListInputProps("series",h,"y_axis_data_key"))),e(t.TextInput,m({label:"Stack ID",placeholder:"Stack bars by this ID"},s.getListInputProps("series",h,"stack")))]}),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{children:"Color"}),e(ce,m({},s.getListInputProps("series",h,"color")))]}),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>s.removeListItem("series",h),sx:{position:"absolute",top:15,right:5},children:e(y.Trash,{size:16})})]},h)),e(t.Group,{position:"center",mt:"xs",children:e(t.Button,{onClick:l,children:"Add a Series"})})]})]})})}function ut({conf:{label_field:n,value_field:i},setConf:r}){const a=L.useForm({initialValues:{label_field:n,value_field:i}});return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:a.onSubmit(r),children:[c(t.Group,{position:"apart",mb:"lg",sx:{position:"relative"},children:[e(t.Text,{children:"Sunburst Config"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",children:e(y.DeviceFloppy,{size:20})})]}),c(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,p:"md",mb:"sm",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[e(t.TextInput,m({label:"Label Field",required:!0,sx:{flex:1}},a.getInputProps("label_field"))),e(t.TextInput,m({label:"Value Field",placeholder:"get column value by this field",required:!0,sx:{flex:1}},a.getInputProps("value_field")))]})]})})}const dt=Object.values(E).map(n=>({label:n,value:n}));function ct({label:n,value:i,onChange:r,sx:a}){return e(t.Select,{label:n,data:dt,value:i,onChange:r,sx:a})}function pt(a){var o=a,{conf:s}=o,l=s,{columns:n}=l,i=I(l,["columns"]),{setConf:r}=o;const u=L.useForm({initialValues:m({id_field:"id",use_raw_columns:!0,columns:L.formList(n!=null?n:[]),size:"sm",horizontalSpacing:"sm",verticalSpacing:"sm",striped:!1,highlightOnHover:!1},i)}),f=()=>u.addListItem("columns",{label:P.randomId(),value_field:"value",value_type:E.string});return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:u.onSubmit(r),children:[c(t.Group,{position:"apart",mb:"lg",sx:{position:"relative"},children:[e(t.Text,{children:"Table Config"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",children:e(y.DeviceFloppy,{size:20})})]}),c(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,p:"md",mb:"sm",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[e(t.TextInput,m({size:"md",mb:"lg",label:"ID Field"},u.getInputProps("id_field"))),c(t.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:[e(t.TextInput,m({label:"Horizontal Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1}},u.getInputProps("horizontalSpacing"))),e(t.TextInput,m({label:"Vertical Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1}},u.getInputProps("verticalSpacing")))]}),e(t.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:e(t.TextInput,m({label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1}},u.getInputProps("size")))}),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{children:"Other"}),c(t.Group,{position:"apart",grow:!0,children:[e(t.Switch,m({label:"Striped"},u.getInputProps("striped",{type:"checkbox"}))),e(t.Switch,m({label:"Highlight on hover"},u.getInputProps("highlightOnHover",{type:"checkbox"})))]})]})]}),c(t.Group,{direction:"column",mt:"xs",spacing:"xs",grow:!0,p:"md",mb:"xl",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[e(t.Switch,m({label:"Use Original Data Columns"},u.getInputProps("use_raw_columns",{type:"checkbox"}))),!u.values.use_raw_columns&&c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{mt:"xl",mb:0,children:"Custom Columns"}),u.values.columns.map((h,b)=>c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[c(t.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:[e(t.TextInput,m({label:"Label",required:!0,sx:{flex:1}},u.getListInputProps("columns",b,"label"))),e(t.TextInput,m({label:"Value Field",placeholder:"get column value by this field",required:!0,sx:{flex:1}},u.getListInputProps("columns",b,"value_field"))),e(ct,m({label:"Value Type",sx:{flex:1}},u.getListInputProps("columns",b,"value_type")))]}),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>u.removeListItem("columns",b),sx:{position:"absolute",top:15,right:5},children:e(y.Trash,{size:16})})]},b)),e(t.Group,{position:"center",mt:"xs",children:e(t.Button,{onClick:f,children:"Add a Column"})})]})]}),e(t.Text,{weight:500,mb:"md",children:"Current Configuration:"}),e(M.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(u.values,null,2)})]})})}const U=[{label:"initial",value:0},{label:"500",value:25},{label:"700",value:50},{label:"semibold",value:75},{label:"bold",value:100}];function mt({label:n,value:i,onChange:r}){var s,l;const[a,o]=d.default.useState((l=(s=U.find(u=>u.label===i))==null?void 0:s.value)!=null?l:U[0].value);return d.default.useEffect(()=>{const u=U.find(f=>f.value===a);u&&r(u.label)},[a]),c(t.Group,{direction:"column",grow:!0,spacing:"xs",mb:"lg",children:[e(t.Text,{children:n}),e(t.Slider,{label:null,marks:U,value:a,onChange:o,step:25,placeholder:"Pick a font size"})]})}const pe=[{align:"center",size:"xl",weight:"bold",color:"black",template:"Time: ${new Date().toISOString()}"},{align:"center",size:"md",weight:"bold",color:"red",template:"Platform: ${navigator.userAgentData.platform}."}];function ht({conf:n,setConf:i}){var o;const r=L.useForm({initialValues:{paragraphs:L.formList((o=n.paragraphs)!=null?o:pe)}}),a=()=>r.addListItem("paragraphs",k(m({},pe[0]),{template:P.randomId()}));return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:r.onSubmit(i),children:[r.values.paragraphs.length===0&&e(t.Text,{color:"dimmed",align:"center",children:"Empty"}),c(t.Group,{position:"apart",mb:"xs",sx:{" + .mantine-Group-root":{marginTop:0}},children:[e(t.Text,{children:"Paragraphs"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",children:e(y.DeviceFloppy,{size:20})})]}),r.values.paragraphs.map((s,l)=>c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[e(t.TextInput,m({placeholder:"Time: ${new Date().toISOString()}",label:"Content Template",required:!0,sx:{flex:1}},r.getListInputProps("paragraphs",l,"template"))),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{children:"Color"}),e(ce,m({},r.getListInputProps("paragraphs",l,"color")))]}),e(t.Group,{direction:"column",grow:!0,children:e(t.TextInput,m({label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",sx:{flex:1}},r.getListInputProps("paragraphs",l,"size")))}),e(t.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:e(mt,m({label:"Font Weight"},r.getListInputProps("paragraphs",l,"weight")))}),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>r.removeListItem("paragraphs",l),sx:{position:"absolute",top:15,right:5},children:e(y.Trash,{size:16})})]},l)),e(t.Group,{position:"center",mt:"md",children:e(t.Button,{onClick:a,children:"Add a Paragraph"})}),e(t.Text,{size:"sm",weight:500,mt:"md",children:"Current Configuration:"}),e(M.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(r.values,null,2)})]})})}const te=[{value:"text",label:"Text",Panel:ht},{value:"table",label:"Table",Panel:pt},{value:"sunburst",label:"Sunburst",Panel:ut},{value:"bar-3d",label:"Bar Chart (3D)",Panel:lt},{value:"line-bar",label:"Line-Bar Chart",Panel:st}];function ft(){const{viz:n,setViz:i}=d.default.useContext(D),[r,a]=P.useInputState(n.type),o=n.type!==r,s=d.default.useCallback(()=>{!o||i(h=>k(m({},h),{type:r}))},[o,r]),l=h=>{i(b=>k(m({},b),{conf:h}))},u=h=>{try{l(JSON.parse(h))}catch(b){console.error(b)}},f=d.default.useMemo(()=>{var h;return(h=te.find(b=>b.value===r))==null?void 0:h.Panel},[r,te]);return c(se,{children:[e(t.Select,{label:"Visualization",value:r,onChange:a,data:te,rightSection:e(t.ActionIcon,{disabled:!o,onClick:s,children:e(y.DeviceFloppy,{size:20})})}),f&&e(f,{conf:n.conf,setConf:l}),!f&&e(t.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(n.conf,null,2),onChange:u})]})}function xt({}){return c(t.Group,{grow:!0,direction:"column",children:[e(ot,{}),e(at,{}),e(t.Divider,{}),e(ft,{})]})}function gt({opened:n,close:i}){const{freezeLayout:r}=d.default.useContext(R),{data:a,loading:o,viz:s,title:l}=d.default.useContext(D);return d.default.useEffect(()=>{r(n)},[n]),e(t.Modal,{size:"96vw",overflow:"inside",opened:n,onClose:i,title:l,trapFocus:!0,onDragStart:u=>{u.stopPropagation()},children:e(t.AppShell,{sx:{height:"90vh",maxHeight:"calc(100vh - 185px)",".mantine-AppShell-body":{height:"100%"},main:{height:"100%",width:"100%"}},padding:"md",navbar:e(t.Navbar,{width:{base:"40%"},height:"100%",p:"xs",children:c(t.Tabs,{initialTab:1,children:[e(t.Tabs.Tab,{label:"Context",children:e(He,{})}),e(t.Tabs.Tab,{label:"SQL Snippets",children:e(rt,{})}),e(t.Tabs.Tab,{label:"SQL",children:e(et,{})}),c(t.Tabs.Tab,{label:"Data",children:[e(t.LoadingOverlay,{visible:o}),e(tt,{})]}),e(t.Tabs.Tab,{label:"Viz Config",children:e(xt,{})})]})}),children:e(ue,{children:e(de,{viz:s,data:a,loading:o})})})})}function bt({}){const[n,i]=d.default.useState(!1),r=()=>i(!0),a=()=>i(!1),{title:o,description:s,loading:l,refreshData:u}=d.default.useContext(D),{inEditMode:f}=d.default.useContext(R);return c(t.Group,{position:"apart",noWrap:!0,sx:{borderBottom:"1px solid #eee",paddingBottom:"5px"},children:[e(t.Group,{children:s&&e(t.Tooltip,{label:s,withArrow:!0,children:e(y.InfoCircle,{size:12,style:{verticalAlign:"baseline",cursor:"pointer"}})})}),e(t.Group,{grow:!0,position:"center",children:e(t.Text,{lineClamp:1,weight:"bold",children:o})}),e(t.Group,{position:"right",spacing:0,sx:{height:"28px"},children:c(t.Menu,{children:[e(t.Menu.Item,{onClick:u,icon:e(y.Refresh,{size:14}),children:"Refresh"}),f&&e(t.Menu.Item,{onClick:r,icon:e(y.Settings,{size:14}),children:"Settings"}),e(t.Divider,{}),e(t.Menu.Item,{color:"red",disabled:!0,icon:e(y.Trash,{size:14}),children:"Delete"})]})}),f&&e(gt,{opened:n,close:a})]})}var Dt="";function me({viz:n,sql:i,title:r,description:a,update:o,layout:s,id:l}){const u=d.default.useContext(ee),f=d.default.useContext(J),[h,b]=d.default.useState(r),[x,g]=d.default.useState(a),[v,z]=d.default.useState(i),[_,O]=d.default.useState(n);d.default.useEffect(()=>{o({id:l,layout:s,title:h,description:x,sql:v,viz:_})},[h,x,v,_,l,s]);const{data:N=[],loading:F,refresh:V}=ve.useRequest(Le(v,u,f,h),{refreshDeps:[u,f]}),ne=V;return e(D.Provider,{value:{data:N,loading:F,title:h,setTitle:b,description:x,setDescription:g,sql:v,setSQL:z,viz:_,setViz:O,refreshData:ne},children:c(t.Container,{className:"panel-root",children:[e(bt,{}),e(ue,{children:e(de,{viz:_,data:N,loading:F})})]})})}var Gt="";const vt=w.WidthProvider(w.Responsive);function he({panels:n,setPanels:i,className:r="layout",cols:a={lg:12,md:10,sm:8,xs:6,xxs:4},rowHeight:o=10,onRemoveItem:s,isDraggable:l,isResizable:u,setLocalCols:f,setBreakpoint:h}){const b=(g,v)=>{h(g),f(v)},x=d.default.useCallback(g=>{const v=new Map;g.forEach(N=>{var F=N,{i:_}=F,O=I(F,["i"]);v.set(_,O)});const z=n.map(_=>k(m({},_),{layout:v.get(_.id)}));i.setState(z)},[n,i]);return e(vt,{onBreakpointChange:b,onLayoutChange:x,className:r,cols:a,rowHeight:o,isDraggable:l,isResizable:u,children:n.map((_,z)=>{var O=_,{id:g}=O,v=I(O,["id"]);return e("div",{"data-grid":v.layout,children:e(me,k(m({id:g},v),{destroy:()=>s(g),update:N=>{i.setItem(z,N)}}))},g)})})}function fe(n,i){return c(t.Text,{sx:{svg:{verticalAlign:"text-bottom"}},children:[n," ",i]})}function yt({mode:n,setMode:i}){return e(t.SegmentedControl,{value:n,onChange:i,data:[{label:fe(e(y.PlayerPlay,{size:20}),"Use"),value:q.Use},{label:fe(e(y.Paint,{size:20}),"Edit"),value:q.Edit}]})}function St({mode:n,setMode:i,hasChanges:r,addPanel:a,saveChanges:o}){const s=n===q.Edit;return c(t.Group,{position:"apart",pt:"sm",pb:"xs",children:[e(t.Group,{position:"left",children:e(yt,{mode:n,setMode:i})}),s&&c(t.Group,{position:"right",children:[e(t.Button,{variant:"default",size:"sm",onClick:a,leftIcon:e(y.PlaylistAdd,{size:20}),children:"Add a Panel"}),e(t.Button,{variant:"default",size:"sm",onClick:o,disabled:!r,leftIcon:e(y.DeviceFloppy,{size:20}),children:"Save Changes"}),e(t.Button,{color:"red",size:"sm",disabled:!r,leftIcon:e(y.Recycle,{size:20}),children:"Revert Changes"})]}),!s&&e(t.Button,{variant:"default",size:"sm",disabled:!0,leftIcon:e(y.Share,{size:20}),children:"Share"})]})}function Ct({dashboard:n,update:i,className:r="dashboard"}){const[a,o]=d.default.useState(!1),[s,l]=d.default.useState(),[u,f]=d.default.useState(),[h,b]=P.useListState(n.panels),[x,g]=d.default.useState(n.definition.sqlSnippets),[v,z]=d.default.useState(q.Edit),_=d.default.useMemo(()=>{const G=ie=>JSON.parse(JSON.stringify(ie));return T.default.isEqual(G(h),G(n.panels))?!T.default.isEqual(x,n.definition.sqlSnippets):!0},[n,h,x]),O=async()=>{const G=T.default.merge({},n,{panels:h},{definition:{sqlSnippets:x}});await i(G)},N=()=>{const G=P.randomId(),Y={id:G,layout:{x:0,y:1/0,w:3,h:4},title:`New Panel - ${G}`,description:"description goes here",sql:"",viz:{type:"table",conf:{}}};b.append(Y)},F=G=>{const Y=h.findIndex(ie=>ie.id===G);b.remove(Y)},V=v===q.Edit,ne=d.default.useMemo(()=>({sqlSnippets:x,setSQLSnippets:g}),[x,g]);return e("div",{className:r,children:e(J.Provider,{value:ne,children:c(R.Provider,{value:{layoutFrozen:a,freezeLayout:o,mode:v,inEditMode:V},children:[e(St,{mode:v,setMode:z,hasChanges:_,addPanel:N,saveChanges:O}),e(he,{panels:h,setPanels:b,isDraggable:V&&!a,isResizable:V&&!a,onRemoveItem:F,setLocalCols:f,setBreakpoint:l})]})})})}p.ContextInfoContext=ee,p.Dashboard=Ct,p.DashboardLayout=he,p.DashboardMode=q,p.DefinitionContext=J,p.LayoutStateContext=R,p.Panel=me,p.PanelContext=D,p.initialContextInfoContext=De,Object.defineProperties(p,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/dist/layout/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { IDashboardPanel } from "../types/dashboard";
|
|
3
|
+
import { UseListStateHandlers } from "@mantine/hooks";
|
|
3
4
|
interface IDashboardLayout {
|
|
4
5
|
panels: IDashboardPanel[];
|
|
6
|
+
setPanels: UseListStateHandlers<IDashboardPanel>;
|
|
5
7
|
className?: string;
|
|
6
8
|
cols?: {
|
|
7
9
|
lg: number;
|
|
@@ -17,5 +19,5 @@ interface IDashboardLayout {
|
|
|
17
19
|
setLocalCols: React.Dispatch<React.SetStateAction<any>>;
|
|
18
20
|
setBreakpoint: React.Dispatch<React.SetStateAction<any>>;
|
|
19
21
|
}
|
|
20
|
-
export declare function DashboardLayout({ panels, className, cols, rowHeight, onRemoveItem, isDraggable, isResizable, setLocalCols, setBreakpoint, }: IDashboardLayout): JSX.Element;
|
|
22
|
+
export declare function DashboardLayout({ panels, setPanels, className, cols, rowHeight, onRemoveItem, isDraggable, isResizable, setLocalCols, setBreakpoint, }: IDashboardLayout): JSX.Element;
|
|
21
23
|
export {};
|
package/dist/main/actions.d.ts
CHANGED
|
@@ -3,7 +3,9 @@ import { DashboardMode } from "../types";
|
|
|
3
3
|
interface IDashboardActions {
|
|
4
4
|
mode: DashboardMode;
|
|
5
5
|
setMode: React.Dispatch<React.SetStateAction<DashboardMode>>;
|
|
6
|
+
hasChanges: boolean;
|
|
6
7
|
addPanel: () => void;
|
|
8
|
+
saveChanges: () => void;
|
|
7
9
|
}
|
|
8
|
-
export declare function DashboardActions({ mode, setMode, addPanel, }: IDashboardActions): JSX.Element;
|
|
10
|
+
export declare function DashboardActions({ mode, setMode, hasChanges, addPanel, saveChanges, }: IDashboardActions): JSX.Element;
|
|
9
11
|
export {};
|
package/dist/main/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { IDashboard } from "../types/dashboard";
|
|
|
3
3
|
interface IDashboardProps {
|
|
4
4
|
dashboard: IDashboard;
|
|
5
5
|
className?: string;
|
|
6
|
+
update: (dashboard: IDashboard) => Promise<void>;
|
|
6
7
|
}
|
|
7
|
-
export declare function Dashboard({ dashboard, className, }: IDashboardProps): JSX.Element;
|
|
8
|
+
export declare function Dashboard({ dashboard, update, className, }: IDashboardProps): JSX.Element;
|
|
8
9
|
export {};
|
package/dist/panel/index.d.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import {
|
|
3
|
-
interface IPanel {
|
|
4
|
-
layout: any;
|
|
2
|
+
import { IDashboardPanel } from '../types/dashboard';
|
|
3
|
+
interface IPanel extends IDashboardPanel {
|
|
5
4
|
destroy: () => void;
|
|
6
|
-
|
|
7
|
-
viz: IVizConfig;
|
|
8
|
-
title: string;
|
|
9
|
-
description: string;
|
|
5
|
+
update: (panel: IDashboardPanel) => void;
|
|
10
6
|
}
|
|
11
|
-
export declare function Panel({ viz: initialViz, sql: initialSQL, title: initialTitle, description: initialDesc }: IPanel): JSX.Element;
|
|
7
|
+
export declare function Panel({ viz: initialViz, sql: initialSQL, title: initialTitle, description: initialDesc, update, layout, id, }: IPanel): JSX.Element;
|
|
12
8
|
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
interface IMantineFontWeightSlider {
|
|
3
|
+
label: string;
|
|
4
|
+
value: string;
|
|
5
|
+
onChange: (value: string) => void;
|
|
6
|
+
}
|
|
7
|
+
export declare function MantineFontWeightSlider({ label, value, onChange }: IMantineFontWeightSlider): JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
interface
|
|
2
|
+
interface IPanelSettingsModal {
|
|
3
|
+
opened: boolean;
|
|
4
|
+
close: () => void;
|
|
3
5
|
}
|
|
4
|
-
export declare function
|
|
6
|
+
export declare function PanelSettingsModal({ opened, close }: IPanelSettingsModal): JSX.Element;
|
|
5
7
|
export {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { IVizPanelProps } from "../../../types/viz-panel";
|
|
3
|
-
export declare function SunburstPanel({ conf: {
|
|
3
|
+
export declare function SunburstPanel({ conf: { label_field, value_field }, setConf }: IVizPanelProps): JSX.Element;
|
package/package.json
CHANGED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
interface IMantineFontSizeSlider {
|
|
3
|
-
label: string;
|
|
4
|
-
value: string;
|
|
5
|
-
onChange: (value: string) => void;
|
|
6
|
-
}
|
|
7
|
-
export declare function MantineFontSizeSlider({ label, value, onChange }: IMantineFontSizeSlider): JSX.Element;
|
|
8
|
-
export {};
|