@devtable/dashboard 1.0.0 → 1.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 +2 -0
- package/dist/dashboard.es.js +312 -124
- package/dist/dashboard.umd.js +7 -7
- package/dist/panel/panel-description.d.ts +7 -0
- package/dist/panel/settings/{viz-config → panel-config}/description.d.ts +0 -0
- package/dist/panel/settings/panel-config/index.d.ts +5 -0
- package/dist/panel/settings/panel-config/preview-panel.d.ts +2 -0
- package/dist/panel/settings/{viz-config → panel-config}/title.d.ts +0 -0
- package/package.json +3 -1
|
@@ -7,4 +7,6 @@ interface IQueryBySQL {
|
|
|
7
7
|
dataSource?: IDataSource;
|
|
8
8
|
}
|
|
9
9
|
export declare const queryBySQL: ({ context, definitions, title, dataSource }: IQueryBySQL) => () => Promise<any>;
|
|
10
|
+
export declare type TQuerySources = Record<string, string[]>;
|
|
11
|
+
export declare function getQuerySources(): Promise<TQuerySources>;
|
|
10
12
|
export {};
|
package/dist/dashboard.es.js
CHANGED
|
@@ -32,10 +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 {
|
|
35
|
+
import { Popover, Tooltip, Group, Text, ActionIcon, TextInput, Box, LoadingOverlay, Table, Select, Button, useMantineTheme, ColorSwatch, Switch, Slider, JsonInput, Modal, AppShell, Tabs, Menu, Divider, Container, SegmentedControl, Textarea } from "@mantine/core";
|
|
36
36
|
import { useRequest } from "ahooks";
|
|
37
37
|
import axios from "axios";
|
|
38
|
-
import { DeviceFloppy, Trash,
|
|
38
|
+
import { InfoCircle, DeviceFloppy, Trash, Refresh, Settings, Paint, PlayerPlay, PlaylistAdd, ClipboardText, Database, Recycle, Share } from "tabler-icons-react";
|
|
39
|
+
import RichTextEditor, { RichTextEditor as RichTextEditor$1 } from "@mantine/rte";
|
|
39
40
|
import { useInputState, useElementSize, randomId } from "@mantine/hooks";
|
|
40
41
|
import ReactEChartsCore from "echarts-for-react/lib/core";
|
|
41
42
|
import * as echarts from "echarts/core";
|
|
@@ -83,6 +84,7 @@ const getRequest = (method) => {
|
|
|
83
84
|
});
|
|
84
85
|
};
|
|
85
86
|
};
|
|
87
|
+
const get = getRequest("GET");
|
|
86
88
|
const post = getRequest("POST");
|
|
87
89
|
function formatSQL(sql, params) {
|
|
88
90
|
const names = Object.keys(params);
|
|
@@ -124,6 +126,15 @@ const queryBySQL = ({ context, definitions, title, dataSource }) => async () =>
|
|
|
124
126
|
return [];
|
|
125
127
|
}
|
|
126
128
|
};
|
|
129
|
+
async function getQuerySources() {
|
|
130
|
+
try {
|
|
131
|
+
const res = await get("/query/sources", {});
|
|
132
|
+
return res;
|
|
133
|
+
} catch (error) {
|
|
134
|
+
console.error(error);
|
|
135
|
+
return {};
|
|
136
|
+
}
|
|
137
|
+
}
|
|
127
138
|
const initialContext$2 = {};
|
|
128
139
|
const initialContextInfoContext = initialContext$2;
|
|
129
140
|
const ContextInfoContext = React.createContext(initialContext$2);
|
|
@@ -191,6 +202,245 @@ reactJsxRuntime_production_min.jsxs = q;
|
|
|
191
202
|
const jsx = jsxRuntime.exports.jsx;
|
|
192
203
|
const jsxs = jsxRuntime.exports.jsxs;
|
|
193
204
|
const Fragment = jsxRuntime.exports.Fragment;
|
|
205
|
+
function DescriptionPopover({
|
|
206
|
+
position,
|
|
207
|
+
trigger = "click"
|
|
208
|
+
}) {
|
|
209
|
+
const {
|
|
210
|
+
freezeLayout
|
|
211
|
+
} = React.useContext(LayoutStateContext);
|
|
212
|
+
const [opened, setOpened] = React.useState(false);
|
|
213
|
+
const {
|
|
214
|
+
description
|
|
215
|
+
} = React.useContext(PanelContext);
|
|
216
|
+
React.useEffect(() => {
|
|
217
|
+
freezeLayout(opened);
|
|
218
|
+
}, [opened]);
|
|
219
|
+
if (!description) {
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
const target = trigger === "click" ? /* @__PURE__ */ jsx(Tooltip, {
|
|
223
|
+
label: "Click to see description",
|
|
224
|
+
openDelay: 500,
|
|
225
|
+
children: /* @__PURE__ */ jsx(InfoCircle, {
|
|
226
|
+
size: 20,
|
|
227
|
+
onClick: () => setOpened((v) => !v),
|
|
228
|
+
style: {
|
|
229
|
+
verticalAlign: "baseline",
|
|
230
|
+
cursor: "pointer"
|
|
231
|
+
}
|
|
232
|
+
})
|
|
233
|
+
}) : /* @__PURE__ */ jsx(InfoCircle, {
|
|
234
|
+
size: 20,
|
|
235
|
+
onMouseEnter: () => setOpened(true),
|
|
236
|
+
onMouseLeave: () => setOpened(false),
|
|
237
|
+
style: {
|
|
238
|
+
verticalAlign: "baseline",
|
|
239
|
+
cursor: "pointer"
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
return /* @__PURE__ */ jsx(Popover, {
|
|
243
|
+
opened,
|
|
244
|
+
onClose: () => setOpened(false),
|
|
245
|
+
withCloseButton: true,
|
|
246
|
+
withArrow: true,
|
|
247
|
+
trapFocus: true,
|
|
248
|
+
closeOnEscape: false,
|
|
249
|
+
placement: "center",
|
|
250
|
+
position,
|
|
251
|
+
target,
|
|
252
|
+
children: /* @__PURE__ */ jsx(RichTextEditor, {
|
|
253
|
+
readOnly: true,
|
|
254
|
+
value: description,
|
|
255
|
+
onChange: _.noop,
|
|
256
|
+
sx: {
|
|
257
|
+
border: "none"
|
|
258
|
+
}
|
|
259
|
+
})
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
function EditDescription() {
|
|
263
|
+
const {
|
|
264
|
+
description,
|
|
265
|
+
setDescription
|
|
266
|
+
} = React.useContext(PanelContext);
|
|
267
|
+
const [value, onChange] = React.useState(description);
|
|
268
|
+
const changed = description !== value;
|
|
269
|
+
const submit = React.useCallback(() => {
|
|
270
|
+
if (!changed) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
setDescription(value);
|
|
274
|
+
}, [changed, value]);
|
|
275
|
+
return /* @__PURE__ */ jsxs(Group, {
|
|
276
|
+
direction: "column",
|
|
277
|
+
sx: {
|
|
278
|
+
flexGrow: 1
|
|
279
|
+
},
|
|
280
|
+
children: [/* @__PURE__ */ jsxs(Group, {
|
|
281
|
+
align: "end",
|
|
282
|
+
children: [/* @__PURE__ */ jsx(Text, {
|
|
283
|
+
children: "Description"
|
|
284
|
+
}), /* @__PURE__ */ jsx(ActionIcon, {
|
|
285
|
+
variant: "hover",
|
|
286
|
+
color: "blue",
|
|
287
|
+
disabled: !changed,
|
|
288
|
+
onClick: submit,
|
|
289
|
+
children: /* @__PURE__ */ jsx(DeviceFloppy, {
|
|
290
|
+
size: 20
|
|
291
|
+
})
|
|
292
|
+
})]
|
|
293
|
+
}), /* @__PURE__ */ jsx(RichTextEditor$1, {
|
|
294
|
+
value,
|
|
295
|
+
onChange,
|
|
296
|
+
sx: {
|
|
297
|
+
flexGrow: 1
|
|
298
|
+
},
|
|
299
|
+
sticky: true,
|
|
300
|
+
p: "0"
|
|
301
|
+
})]
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
class ErrorBoundary extends React.Component {
|
|
305
|
+
constructor(props) {
|
|
306
|
+
super(props);
|
|
307
|
+
this.state = {
|
|
308
|
+
hasError: false
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
static getDerivedStateFromError() {
|
|
312
|
+
return {
|
|
313
|
+
hasError: true
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
render() {
|
|
317
|
+
if (this.state.hasError) {
|
|
318
|
+
return /* @__PURE__ */ jsx("h1", {
|
|
319
|
+
children: "Something went wrong."
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
return this.props.children;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
function PreviewPanel() {
|
|
326
|
+
const {
|
|
327
|
+
title
|
|
328
|
+
} = React.useContext(PanelContext);
|
|
329
|
+
return /* @__PURE__ */ jsx(ErrorBoundary, {
|
|
330
|
+
children: /* @__PURE__ */ jsxs(Group, {
|
|
331
|
+
direction: "column",
|
|
332
|
+
grow: true,
|
|
333
|
+
noWrap: true,
|
|
334
|
+
mx: "auto",
|
|
335
|
+
mt: "xl",
|
|
336
|
+
p: "5px",
|
|
337
|
+
spacing: "xs",
|
|
338
|
+
sx: {
|
|
339
|
+
width: "600px",
|
|
340
|
+
height: "450px",
|
|
341
|
+
background: "transparent",
|
|
342
|
+
borderRadius: "5px",
|
|
343
|
+
boxShadow: "0px 0px 10px 0px rgba(0,0,0,.2)"
|
|
344
|
+
},
|
|
345
|
+
children: [/* @__PURE__ */ jsxs(Group, {
|
|
346
|
+
position: "apart",
|
|
347
|
+
noWrap: true,
|
|
348
|
+
sx: {
|
|
349
|
+
borderBottom: "1px solid #eee",
|
|
350
|
+
paddingBottom: "5px",
|
|
351
|
+
flexGrow: 0,
|
|
352
|
+
flexShrink: 0
|
|
353
|
+
},
|
|
354
|
+
children: [/* @__PURE__ */ jsx(Group, {
|
|
355
|
+
children: /* @__PURE__ */ jsx(DescriptionPopover, {
|
|
356
|
+
position: "bottom",
|
|
357
|
+
trigger: "hover"
|
|
358
|
+
})
|
|
359
|
+
}), /* @__PURE__ */ jsx(Group, {
|
|
360
|
+
grow: true,
|
|
361
|
+
position: "center",
|
|
362
|
+
children: /* @__PURE__ */ jsx(Text, {
|
|
363
|
+
lineClamp: 1,
|
|
364
|
+
weight: "bold",
|
|
365
|
+
children: title
|
|
366
|
+
})
|
|
367
|
+
}), /* @__PURE__ */ jsx(Group, {
|
|
368
|
+
position: "right",
|
|
369
|
+
spacing: 0,
|
|
370
|
+
sx: {
|
|
371
|
+
height: "28px"
|
|
372
|
+
}
|
|
373
|
+
})]
|
|
374
|
+
}), /* @__PURE__ */ jsx(Group, {
|
|
375
|
+
sx: {
|
|
376
|
+
background: "#eee",
|
|
377
|
+
flexGrow: 1
|
|
378
|
+
}
|
|
379
|
+
})]
|
|
380
|
+
})
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
function EditTitle() {
|
|
384
|
+
const {
|
|
385
|
+
title,
|
|
386
|
+
setTitle
|
|
387
|
+
} = React.useContext(PanelContext);
|
|
388
|
+
const [localTitle, setLocalTitle] = useInputState(title);
|
|
389
|
+
const changed = title !== localTitle;
|
|
390
|
+
const submit = React.useCallback(() => {
|
|
391
|
+
if (!changed) {
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
setTitle(localTitle);
|
|
395
|
+
}, [changed, localTitle]);
|
|
396
|
+
return /* @__PURE__ */ jsx(TextInput, {
|
|
397
|
+
value: localTitle,
|
|
398
|
+
onChange: setLocalTitle,
|
|
399
|
+
label: /* @__PURE__ */ jsxs(Group, {
|
|
400
|
+
align: "end",
|
|
401
|
+
children: [/* @__PURE__ */ jsx(Text, {
|
|
402
|
+
children: "Panel Title"
|
|
403
|
+
}), /* @__PURE__ */ jsx(ActionIcon, {
|
|
404
|
+
variant: "hover",
|
|
405
|
+
color: "blue",
|
|
406
|
+
disabled: !changed,
|
|
407
|
+
onClick: submit,
|
|
408
|
+
children: /* @__PURE__ */ jsx(DeviceFloppy, {
|
|
409
|
+
size: 20
|
|
410
|
+
})
|
|
411
|
+
})]
|
|
412
|
+
})
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
function PanelConfig({}) {
|
|
416
|
+
return /* @__PURE__ */ jsxs(Group, {
|
|
417
|
+
direction: "row",
|
|
418
|
+
grow: true,
|
|
419
|
+
noWrap: true,
|
|
420
|
+
align: "stretch",
|
|
421
|
+
sx: {
|
|
422
|
+
height: "100%"
|
|
423
|
+
},
|
|
424
|
+
children: [/* @__PURE__ */ jsxs(Group, {
|
|
425
|
+
grow: true,
|
|
426
|
+
direction: "column",
|
|
427
|
+
sx: {
|
|
428
|
+
width: "40%",
|
|
429
|
+
flexShrink: 0,
|
|
430
|
+
flexGrow: 0,
|
|
431
|
+
height: "100%"
|
|
432
|
+
},
|
|
433
|
+
children: [/* @__PURE__ */ jsx(EditTitle, {}), /* @__PURE__ */ jsx(EditDescription, {})]
|
|
434
|
+
}), /* @__PURE__ */ jsx(Box, {
|
|
435
|
+
sx: {
|
|
436
|
+
height: "100%",
|
|
437
|
+
flexGrow: 1,
|
|
438
|
+
maxWidth: "60%"
|
|
439
|
+
},
|
|
440
|
+
children: /* @__PURE__ */ jsx(PreviewPanel, {})
|
|
441
|
+
})]
|
|
442
|
+
});
|
|
443
|
+
}
|
|
194
444
|
function DataPreview({
|
|
195
445
|
id
|
|
196
446
|
}) {
|
|
@@ -306,58 +556,6 @@ function PickDataSource({}) {
|
|
|
306
556
|
})]
|
|
307
557
|
});
|
|
308
558
|
}
|
|
309
|
-
function EditDescription() {
|
|
310
|
-
const {
|
|
311
|
-
description,
|
|
312
|
-
setDescription
|
|
313
|
-
} = React.useContext(PanelContext);
|
|
314
|
-
const [localDesc, setLocalDesc] = useInputState(description);
|
|
315
|
-
const changed = description !== localDesc;
|
|
316
|
-
const submit = React.useCallback(() => {
|
|
317
|
-
if (!changed) {
|
|
318
|
-
return;
|
|
319
|
-
}
|
|
320
|
-
setDescription(localDesc);
|
|
321
|
-
}, [changed, localDesc]);
|
|
322
|
-
return /* @__PURE__ */ jsx(Textarea, {
|
|
323
|
-
label: "Panel Description",
|
|
324
|
-
value: localDesc,
|
|
325
|
-
onChange: setLocalDesc,
|
|
326
|
-
minRows: 2,
|
|
327
|
-
rightSection: /* @__PURE__ */ jsx(ActionIcon, {
|
|
328
|
-
disabled: !changed,
|
|
329
|
-
onClick: submit,
|
|
330
|
-
sx: {
|
|
331
|
-
alignSelf: "flex-start",
|
|
332
|
-
marginTop: "4px"
|
|
333
|
-
},
|
|
334
|
-
children: /* @__PURE__ */ jsx(DeviceFloppy, {
|
|
335
|
-
size: 20
|
|
336
|
-
})
|
|
337
|
-
})
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
class ErrorBoundary extends React.Component {
|
|
341
|
-
constructor(props) {
|
|
342
|
-
super(props);
|
|
343
|
-
this.state = {
|
|
344
|
-
hasError: false
|
|
345
|
-
};
|
|
346
|
-
}
|
|
347
|
-
static getDerivedStateFromError() {
|
|
348
|
-
return {
|
|
349
|
-
hasError: true
|
|
350
|
-
};
|
|
351
|
-
}
|
|
352
|
-
render() {
|
|
353
|
-
if (this.state.hasError) {
|
|
354
|
-
return /* @__PURE__ */ jsx("h1", {
|
|
355
|
-
children: "Something went wrong."
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
return this.props.children;
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
559
|
echarts.use([SunburstChart, CanvasRenderer]);
|
|
362
560
|
const defaultOption$1 = {
|
|
363
561
|
tooltip: {
|
|
@@ -791,32 +989,6 @@ function PreviewViz({}) {
|
|
|
791
989
|
})
|
|
792
990
|
});
|
|
793
991
|
}
|
|
794
|
-
function EditTitle() {
|
|
795
|
-
const {
|
|
796
|
-
title,
|
|
797
|
-
setTitle
|
|
798
|
-
} = React.useContext(PanelContext);
|
|
799
|
-
const [localTitle, setLocalTitle] = useInputState(title);
|
|
800
|
-
const changed = title !== localTitle;
|
|
801
|
-
const submit = React.useCallback(() => {
|
|
802
|
-
if (!changed) {
|
|
803
|
-
return;
|
|
804
|
-
}
|
|
805
|
-
setTitle(localTitle);
|
|
806
|
-
}, [changed, localTitle]);
|
|
807
|
-
return /* @__PURE__ */ jsx(TextInput, {
|
|
808
|
-
label: "Panel Title",
|
|
809
|
-
value: localTitle,
|
|
810
|
-
onChange: setLocalTitle,
|
|
811
|
-
rightSection: /* @__PURE__ */ jsx(ActionIcon, {
|
|
812
|
-
disabled: !changed,
|
|
813
|
-
onClick: submit,
|
|
814
|
-
children: /* @__PURE__ */ jsx(DeviceFloppy, {
|
|
815
|
-
size: 20
|
|
816
|
-
})
|
|
817
|
-
})
|
|
818
|
-
});
|
|
819
|
-
}
|
|
820
992
|
function VizBar3DPanel({
|
|
821
993
|
conf,
|
|
822
994
|
setConf
|
|
@@ -1721,19 +1893,16 @@ function VizConfig({}) {
|
|
|
1721
1893
|
sx: {
|
|
1722
1894
|
height: "100%"
|
|
1723
1895
|
},
|
|
1724
|
-
children: [/* @__PURE__ */
|
|
1896
|
+
children: [/* @__PURE__ */ jsx(Group, {
|
|
1725
1897
|
grow: true,
|
|
1726
1898
|
direction: "column",
|
|
1899
|
+
noWrap: true,
|
|
1727
1900
|
sx: {
|
|
1728
1901
|
width: "40%",
|
|
1729
1902
|
flexShrink: 0,
|
|
1730
1903
|
flexGrow: 0
|
|
1731
1904
|
},
|
|
1732
|
-
children:
|
|
1733
|
-
sx: {
|
|
1734
|
-
flexGrow: 0
|
|
1735
|
-
}
|
|
1736
|
-
}), /* @__PURE__ */ jsx(EditVizConf, {})]
|
|
1905
|
+
children: /* @__PURE__ */ jsx(EditVizConf, {})
|
|
1737
1906
|
}), /* @__PURE__ */ jsx(Box, {
|
|
1738
1907
|
sx: {
|
|
1739
1908
|
height: "100%",
|
|
@@ -1791,7 +1960,10 @@ function PanelSettingsModal({
|
|
|
1791
1960
|
visible: loading
|
|
1792
1961
|
}), /* @__PURE__ */ jsx(PickDataSource, {})]
|
|
1793
1962
|
}), /* @__PURE__ */ jsx(Tabs.Tab, {
|
|
1794
|
-
label: "
|
|
1963
|
+
label: "Panel",
|
|
1964
|
+
children: /* @__PURE__ */ jsx(PanelConfig, {})
|
|
1965
|
+
}), /* @__PURE__ */ jsx(Tabs.Tab, {
|
|
1966
|
+
label: "Visualization",
|
|
1795
1967
|
children: /* @__PURE__ */ jsx(VizConfig, {})
|
|
1796
1968
|
})]
|
|
1797
1969
|
})
|
|
@@ -1804,8 +1976,6 @@ function PanelTitleBar({}) {
|
|
|
1804
1976
|
const close = () => setOpened(false);
|
|
1805
1977
|
const {
|
|
1806
1978
|
title,
|
|
1807
|
-
description,
|
|
1808
|
-
loading,
|
|
1809
1979
|
refreshData
|
|
1810
1980
|
} = React.useContext(PanelContext);
|
|
1811
1981
|
const {
|
|
@@ -1819,17 +1989,7 @@ function PanelTitleBar({}) {
|
|
|
1819
1989
|
paddingBottom: "5px"
|
|
1820
1990
|
},
|
|
1821
1991
|
children: [/* @__PURE__ */ jsx(Group, {
|
|
1822
|
-
children:
|
|
1823
|
-
label: description,
|
|
1824
|
-
withArrow: true,
|
|
1825
|
-
children: /* @__PURE__ */ jsx(InfoCircle, {
|
|
1826
|
-
size: 12,
|
|
1827
|
-
style: {
|
|
1828
|
-
verticalAlign: "baseline",
|
|
1829
|
-
cursor: "pointer"
|
|
1830
|
-
}
|
|
1831
|
-
})
|
|
1832
|
-
})
|
|
1992
|
+
children: /* @__PURE__ */ jsx(DescriptionPopover, {})
|
|
1833
1993
|
}), /* @__PURE__ */ jsx(Group, {
|
|
1834
1994
|
grow: true,
|
|
1835
1995
|
position: "center",
|
|
@@ -2005,7 +2165,7 @@ function DashboardLayout({
|
|
|
2005
2165
|
update: (panel) => {
|
|
2006
2166
|
setPanels((prevs) => {
|
|
2007
2167
|
prevs.splice(index2, 1, panel);
|
|
2008
|
-
return prevs;
|
|
2168
|
+
return [...prevs];
|
|
2009
2169
|
});
|
|
2010
2170
|
}
|
|
2011
2171
|
}))
|
|
@@ -2154,6 +2314,28 @@ function DataSourceForm({
|
|
|
2154
2314
|
React.useEffect(() => {
|
|
2155
2315
|
form.reset();
|
|
2156
2316
|
}, [value]);
|
|
2317
|
+
const {
|
|
2318
|
+
data: querySources = {},
|
|
2319
|
+
loading
|
|
2320
|
+
} = useRequest(getQuerySources, {
|
|
2321
|
+
refreshDeps: []
|
|
2322
|
+
}, []);
|
|
2323
|
+
const querySourceTypeOptions = React.useMemo(() => {
|
|
2324
|
+
return Object.keys(querySources).map((k2) => ({
|
|
2325
|
+
label: k2,
|
|
2326
|
+
value: k2
|
|
2327
|
+
}));
|
|
2328
|
+
}, [querySources]);
|
|
2329
|
+
const querySourceKeyOptions = React.useMemo(() => {
|
|
2330
|
+
const sources = querySources[form.values.type];
|
|
2331
|
+
if (!sources) {
|
|
2332
|
+
return [];
|
|
2333
|
+
}
|
|
2334
|
+
return sources.map((k2) => ({
|
|
2335
|
+
label: k2,
|
|
2336
|
+
value: k2
|
|
2337
|
+
}));
|
|
2338
|
+
}, [querySources, form.values.type]);
|
|
2157
2339
|
return /* @__PURE__ */ jsx(Group, {
|
|
2158
2340
|
direction: "column",
|
|
2159
2341
|
grow: true,
|
|
@@ -2179,7 +2361,7 @@ function DataSourceForm({
|
|
|
2179
2361
|
mr: 5,
|
|
2180
2362
|
variant: "filled",
|
|
2181
2363
|
color: "blue",
|
|
2182
|
-
disabled: !changed,
|
|
2364
|
+
disabled: !changed || loading,
|
|
2183
2365
|
children: /* @__PURE__ */ jsx(DeviceFloppy, {
|
|
2184
2366
|
size: 20
|
|
2185
2367
|
})
|
|
@@ -2198,22 +2380,23 @@ function DataSourceForm({
|
|
|
2198
2380
|
required: true,
|
|
2199
2381
|
sx: {
|
|
2200
2382
|
flex: 1
|
|
2201
|
-
}
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
label: "Data Source
|
|
2205
|
-
|
|
2383
|
+
},
|
|
2384
|
+
disabled: loading
|
|
2385
|
+
}, form.getInputProps("id"))), /* @__PURE__ */ jsx(Select, __spreadValues({
|
|
2386
|
+
label: "Data Source Type",
|
|
2387
|
+
data: querySourceTypeOptions,
|
|
2206
2388
|
sx: {
|
|
2207
2389
|
flex: 1
|
|
2208
|
-
}
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
label: "
|
|
2212
|
-
|
|
2390
|
+
},
|
|
2391
|
+
disabled: loading
|
|
2392
|
+
}, form.getInputProps("type"))), /* @__PURE__ */ jsx(Select, __spreadValues({
|
|
2393
|
+
label: "Data Source Key",
|
|
2394
|
+
data: querySourceKeyOptions,
|
|
2213
2395
|
sx: {
|
|
2214
2396
|
flex: 1
|
|
2215
|
-
}
|
|
2216
|
-
|
|
2397
|
+
},
|
|
2398
|
+
disabled: loading
|
|
2399
|
+
}, form.getInputProps("key")))]
|
|
2217
2400
|
}), /* @__PURE__ */ jsx(Textarea, __spreadValues({
|
|
2218
2401
|
autosize: true,
|
|
2219
2402
|
minRows: 12,
|
|
@@ -2240,12 +2423,9 @@ function DataSourceEditor({
|
|
|
2240
2423
|
return;
|
|
2241
2424
|
}
|
|
2242
2425
|
setDataSources((prevs) => {
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
}
|
|
2247
|
-
return p2;
|
|
2248
|
-
});
|
|
2426
|
+
const index22 = prevs.findIndex((p2) => p2.id === id);
|
|
2427
|
+
prevs.splice(index22, 1, value);
|
|
2428
|
+
return [...prevs];
|
|
2249
2429
|
});
|
|
2250
2430
|
}, [setDataSources]);
|
|
2251
2431
|
if (!dataSource) {
|
|
@@ -2273,12 +2453,20 @@ function SelectOrAddDataSource({
|
|
|
2273
2453
|
dataSources,
|
|
2274
2454
|
setDataSources
|
|
2275
2455
|
} = React.useContext(DefinitionContext);
|
|
2276
|
-
React.
|
|
2456
|
+
const chooseDefault = React.useCallback(() => {
|
|
2277
2457
|
var _a, _b;
|
|
2458
|
+
setID((_b = (_a = dataSources[0]) == null ? void 0 : _a.id) != null ? _b : "");
|
|
2459
|
+
}, [setID, dataSources]);
|
|
2460
|
+
React.useEffect(() => {
|
|
2278
2461
|
if (!id) {
|
|
2279
|
-
|
|
2462
|
+
chooseDefault();
|
|
2463
|
+
return;
|
|
2464
|
+
}
|
|
2465
|
+
const index2 = dataSources.findIndex((d) => d.id === id);
|
|
2466
|
+
if (index2 === -1) {
|
|
2467
|
+
chooseDefault();
|
|
2280
2468
|
}
|
|
2281
|
-
}, [id,
|
|
2469
|
+
}, [id, dataSources, chooseDefault]);
|
|
2282
2470
|
const options = React.useMemo(() => {
|
|
2283
2471
|
return dataSources.map((d) => ({
|
|
2284
2472
|
value: d.id,
|
|
@@ -2756,7 +2944,7 @@ function Dashboard({
|
|
|
2756
2944
|
const index2 = panels.findIndex((p2) => p2.id === id);
|
|
2757
2945
|
setPanels((prevs) => {
|
|
2758
2946
|
prevs.splice(index2, 1);
|
|
2759
|
-
return prevs;
|
|
2947
|
+
return [...prevs];
|
|
2760
2948
|
});
|
|
2761
2949
|
};
|
|
2762
2950
|
const inEditMode = mode === DashboardMode.Edit;
|
package/dist/dashboard.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(f,v){typeof exports=="object"&&typeof module!="undefined"?v(exports,require("react"),require("lodash"),require("react-grid-layout"),require("@mantine/core"),require("ahooks"),require("axios"),require("tabler-icons-react"),require("@mantine/rte"),require("@mantine/hooks"),require("echarts-for-react/lib/core"),require("echarts/core"),require("echarts/charts"),require("echarts/renderers"),require("echarts/components"),require("numbro"),require("echarts-gl"),require("react-hook-form"),require("@mantine/form"),require("@mantine/prism")):typeof define=="function"&&define.amd?define(["exports","react","lodash","react-grid-layout","@mantine/core","ahooks","axios","tabler-icons-react","@mantine/rte","@mantine/hooks","echarts-for-react/lib/core","echarts/core","echarts/charts","echarts/renderers","echarts/components","numbro","echarts-gl","react-hook-form","@mantine/form","@mantine/prism"],v):(f=typeof globalThis!="undefined"?globalThis:f||self,v(f.dashboard={},f.React,f._,f["react-grid-layout"],f["@mantine/core"],f.ahooks,f.axios,f["tabler-icons-react"],f["@mantine/rte"],f["@mantine/hooks"],f["echarts-for-react/lib/core"],f["echarts/core"],f["echarts/charts"],f["echarts/renderers"],f["echarts/components"],f.numbro,f["echarts-gl"],f["react-hook-form"],f["@mantine/form"],f["@mantine/prism"]))})(this,function(f,v,C,T,t,ee,Ie,y,de,O,_e,ze,te,ne,N,Pe,Qt,V,z,M){"use strict";var Vt=Object.defineProperty,Rt=Object.defineProperties;var Wt=Object.getOwnPropertyDescriptors;var Z=Object.getOwnPropertySymbols;var De=Object.prototype.hasOwnProperty,Ge=Object.prototype.propertyIsEnumerable;var Te=(f,v,C)=>v in f?Vt(f,v,{enumerable:!0,configurable:!0,writable:!0,value:C}):f[v]=C,h=(f,v)=>{for(var C in v||(v={}))De.call(v,C)&&Te(f,C,v[C]);if(Z)for(var C of Z(v))Ge.call(v,C)&&Te(f,C,v[C]);return f},E=(f,v)=>Rt(f,Wt(v));var _=(f,v)=>{var C={};for(var T in f)De.call(f,T)&&v.indexOf(T)<0&&(C[T]=f[T]);if(f!=null&&Z)for(var T of Z(f))v.indexOf(T)<0&&Ge.call(f,T)&&(C[T]=f[T]);return C};function W(n){return n&&typeof n=="object"&&"default"in n?n:{default:n}}function Le(n){if(n&&n.__esModule)return n;var r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});return n&&Object.keys(n).forEach(function(i){if(i!=="default"){var o=Object.getOwnPropertyDescriptor(n,i);Object.defineProperty(r,i,o.get?o:{enumerable:!0,get:function(){return n[i]}})}}),r.default=n,Object.freeze(r)}var u=W(v),w=W(C),ke=W(Ie),Ee=W(de),re=W(_e),Q=Le(ze),ce=W(Pe),q=(n=>(n.Use="use",n.Edit="edit",n))(q||{});const Oe={layoutFrozen:!1,freezeLayout:()=>{},mode:q.Edit,inEditMode:!1},B=u.default.createContext(Oe),pe=n=>(r,i,o={})=>{const a=h({"X-Requested-With":"XMLHttpRequest","Content-Type":o.string?"application/x-www-form-urlencoded":"application/json"},o.headers),s={baseURL:"http://localhost:31200",method:n,url:r,params:n==="GET"?i:o.params,headers:a};return n==="POST"&&(s.data=o.string?JSON.stringify(i):i),ke.default(s).then(l=>l.data).catch(l=>Promise.reject(l))},qe=pe("GET"),Ae=pe("POST");function he(n,r){const i=Object.keys(r),o=Object.values(r);try{return new Function(...i,`return \`${n}\`;`)(...o)}catch(a){throw i.length===0&&n.includes("$")?new Error("[formatSQL] insufficient params"):a}}function Me(n,r){const i=r.sqlSnippets.reduce((o,a)=>(o[a.key]=he(a.value,n),o),{});return w.default.merge({},i,n)}const fe=({context:n,definitions:r,title:i,dataSource:o})=>async()=>{if(!o||!o.sql)return[];const{type:a,key:s,sql:l}=o,d=l.includes("$");try{const m=Me(n,r),p=he(l,m);return d&&(console.groupCollapsed(`Final SQL for: ${i}`),console.log(p),console.groupEnd()),await Ae("/query",{type:a,key:s,sql:p})}catch(m){return console.error(m),[]}};async function Be(){try{return await qe("/query/sources",{})}catch(n){return console.error(n),{}}}const me={},Fe=me,R=u.default.createContext(me),$e={data:[],loading:!1,title:"",setTitle:()=>{},description:"",setDescription:()=>{},dataSourceID:"",setDataSourceID:()=>{},viz:{type:"",conf:{}},setViz:()=>{},refreshData:()=>{}},I=u.default.createContext($e),je={sqlSnippets:[],setSQLSnippets:()=>{},dataSources:[],setDataSources:()=>{}},P=u.default.createContext(je);var U={exports:{}},K={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,7 +6,7 @@
|
|
|
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 Ae=u.default,Me=Symbol.for("react.element"),Be=Symbol.for("react.fragment"),$e=Object.prototype.hasOwnProperty,Fe=Ae.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Ne={key:!0,ref:!0,__self:!0,__source:!0};function me(n,i,r){var o,a={},s=null,l=null;r!==void 0&&(s=""+r),i.key!==void 0&&(s=""+i.key),i.ref!==void 0&&(l=i.ref);for(o in i)$e.call(i,o)&&!Ne.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:Me,type:n,key:s,ref:l,props:a,_owner:Fe.current}}Y.Fragment=Be,Y.jsx=me,Y.jsxs=me,U.exports=Y;const e=U.exports.jsx,c=U.exports.jsxs,ie=U.exports.Fragment;function he({id:n}){const i=u.default.useContext(P),r=u.default.useContext(R),o=u.default.useMemo(()=>i.dataSources.find(l=>l.id===n),[i.dataSources,n]),{data:a=[],loading:s}=se.useRequest(ce({context:r,definitions:i,title:n,dataSource:o}),{refreshDeps:[r,i,o]});return s?e(t.LoadingOverlay,{visible:s}):a.length===0?e(t.Table,{}):c(t.Group,{my:"xl",direction:"column",grow:!0,sx:{border:"1px solid #eee"},children:[e(t.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:e(t.Text,{weight:500,children:"Preview Data"})}),c(t.Table,{children:[e("thead",{children:e("tr",{children:Object.keys(a==null?void 0:a[0]).map(l=>e("th",{children:l},l))})}),e("tbody",{children:a.map((l,d)=>e("tr",{children:Object.values(l).map((h,f)=>e("td",{children:e(t.Group,{sx:{"&, .mantine-Text-root":{fontFamily:"monospace"}},children:e(t.Text,{children:h})})},`${h}--${f}`))},`row-${d}`))})]})]})}function Ve({}){const{dataSources:n}=u.default.useContext(P),{dataSourceID:i,setDataSourceID:r,data:o,loading:a}=u.default.useContext(q),s=u.default.useMemo(()=>n.map(l=>({value:l.id,label:l.id})),[n]);return c(t.Group,{direction:"column",grow:!0,noWrap:!0,children:[c(t.Group,{position:"left",sx:{maxWidth:"600px",alignItems:"baseline"},children:[e(t.Text,{children:"Select a Data Source"}),e(t.Select,{data:s,value:i,onChange:r,allowDeselect:!1,clearable:!1,sx:{flexGrow:1}})]}),e(he,{id:i})]})}function je(){const{description:n,setDescription:i}=u.default.useContext(q),[r,o]=z.useInputState(n),a=n!==r,s=u.default.useCallback(()=>{!a||i(r)},[a,r]);return e(t.Textarea,{label:"Panel Description",value:r,onChange:o,minRows:2,rightSection:e(t.ActionIcon,{disabled:!a,onClick:s,sx:{alignSelf:"flex-start",marginTop:"4px"},children:e(v.DeviceFloppy,{size:20})})})}class fe 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}}W.use([ee.SunburstChart,te.CanvasRenderer]);const Re={tooltip:{show:!0},series:{type:"sunburst",radius:[0,"90%"],emphasis:{focus:"ancestor"}}};function We({conf:n,data:i,width:r,height:o}){const b=n,{label_field:a="name",value_field:s="value"}=b,l=_(b,["label_field","value_field"]),d=u.default.useMemo(()=>i.map(x=>({name:x[a],value:Number(x[s])})),[i,a,s]),h=u.default.useMemo(()=>{var x,S;return(S=(x=T.default.maxBy(d,D=>D.value))==null?void 0:x.value)!=null?S:1},[d]),f=u.default.useMemo(()=>({series:{label:{formatter:({name:x,value:S})=>S/h<.2?" ":x}}}),[h]),g=T.default.merge({},Re,f,l,{series:{data:d}});return e(ne.default,{echarts:W,option:g,style:{width:r,height:o}})}W.use([ee.BarChart,ee.LineChart,N.GridComponent,N.LegendComponent,N.TooltipComponent,te.CanvasRenderer]);const Qe={legend:{show:!0},tooltip:{trigger:"axis"},xAxis:{type:"category"},yAxis:{},grid:{top:30,left:10,right:10,bottom:10,containLabel:!0}};function Je({conf:n,data:i,width:r,height:o}){const a=u.default.useMemo(()=>{const s={dataset:{source:i}},l={xAxis:{data:i.map(h=>h[n.x_axis_data_key])}},d=n.series.map(g=>{var b=g,{y_axis_data_key:h}=b,f=_(b,["y_axis_data_key"]);return p({data:i.map(x=>x[h])},f)});return T.default.assign({},Qe,s,l,{series:d})},[n,i]);return!r||!o?null:e(ne.default,{echarts:W,option:a,style:{width:r,height:o}})}var B=(n=>(n.string="string",n.number="number",n.eloc="eloc",n.percentage="percentage",n))(B||{});function Ue({value:n}){return e(t.Text,{component:"span",children:n})}function Ye({value:n}){return e(t.Text,{component:"span",children:n})}function He({value:n}){const i=ue.default(n).format({thousandSeparated:!0});return e(t.Text,{component:"span",children:i})}function Ke({value:n}){const i=ue.default(n).format({output:"percent",mantissa:3});return e(t.Text,{component:"span",children:i})}function Xe({value:n,type:i}){switch(i){case B.string:return e(Ue,{value:n});case B.eloc:return e(Ye,{value:n});case B.number:return e(He,{value:n});case B.percentage:return e(Ke,{value:n})}}function Ze({conf:n,data:i,width:r,height:o}){const g=n,{id_field:a,use_raw_columns:s,columns:l}=g,d=_(g,["id_field","use_raw_columns","columns"]),h=u.default.useMemo(()=>s?Object.keys(i==null?void 0:i[0]):l.map(b=>b.label),[s,l,i]),f=u.default.useMemo(()=>s?Object.keys(i==null?void 0:i[0]).map(b=>({label:b,value_field:b,value_type:B.string})):l,[s,l,i]);return c(t.Table,E(p({sx:{maxHeight:o}},d),{children:[e("thead",{children:e("tr",{children:h.map(b=>e("th",{children:b},b))})}),e("tbody",{children:i.map((b,x)=>e("tr",{children:f.map(({value_field:S,value_type:D})=>e("td",{children:e(t.Group,{sx:{"&, .mantine-Text-root":{fontFamily:"monospace"}},children:e(Xe,{value:b[S],type:D})})},b[S]))},a?b[a]:`row-${x}`))})]}))}function et(n,i={}){const r=Object.keys(i),o=Object.values(i);try{return new Function(...r,`return \`${n}\`;`)(...o)}catch(a){return a.message}}function tt({conf:{paragraphs:n},data:i}){return e(ie,{children:n.map((l,s)=>{var d=l,{template:r,size:o}=d,a=_(d,["template","size"]);return e(t.Text,E(p({},a),{sx:{fontSize:o},children:et(r,i[0])}),`${r}---${s}`)})})}W.use([N.GridComponent,N.VisualMapComponent,N.LegendComponent,N.TooltipComponent,te.CanvasRenderer]);function nt({conf:n,data:i,width:r,height:o}){const b=n,{x_axis_data_key:a,y_axis_data_key:s,z_axis_data_key:l}=b,d=_(b,["x_axis_data_key","y_axis_data_key","z_axis_data_key"]),h=u.default.useMemo(()=>T.default.minBy(i,x=>x[l])[l],[i,l]),f=u.default.useMemo(()=>T.default.maxBy(i,x=>x[l])[l],[i,l]),g=E(p({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(x=>[x[a],x[s],x[l]])}]});return e(ne.default,{echarts:W,option:g,style:{width:r,height:o}})}var Ft="";function it(n,i,r,o){const a={width:n,height:i,data:r,conf:o.conf};switch(o.type){case"sunburst":return e(We,p({},a));case"line-bar":return e(Je,p({},a));case"table":return e(Ze,p({},a));case"text":return e(tt,p({},a));case"bar-3d":return e(nt,p({},a));default:return null}}function xe({viz:n,data:i,loading:r}){const{ref:o,width:a,height:s}=z.useElementSize(),l=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})}):c("div",{className:"viz-root",ref:o,children:[l&&e(t.Text,{color:"gray",align:"center",children:"nothing to show"}),!l&&it(a,s,i,n)]})}function rt({}){const{data:n,loading:i,viz:r}=u.default.useContext(q);return e(fe,{children:e(xe,{viz:r,data:n,loading:i})})}function ot(){const{title:n,setTitle:i}=u.default.useContext(q),[r,o]=z.useInputState(n),a=n!==r,s=u.default.useCallback(()=>{!a||i(r)},[a,r]);return e(t.TextInput,{label:"Panel Title",value:r,onChange:o,rightSection:e(t.ActionIcon,{disabled:!a,onClick:s,children:e(v.DeviceFloppy,{size:20})})})}function at({conf:n,setConf:i}){const r=T.default.assign({},{x_axis_data_key:"x",y_axis_data_key:"y",z_axis_data_key:"z",xAxis3D:{type:"value",name:"X Axis Name"},yAxis3D:{type:"value",name:"Y Axis Name"},zAxis3D:{type:"value",name:"Z Axis Name"}},n),{control:o,handleSubmit:a,formState:s}=V.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(V.Controller,{name:"x_axis_data_key",control:o,render:({field:l})=>e(t.TextInput,p({sx:{flexGrow:1},size:"md",label:"Data Key"},l))}),e(V.Controller,{name:"xAxis3D.name",control:o,render:({field:l})=>e(t.TextInput,p({sx:{flexGrow:1},size:"md",label:"Name"},l))})]}),e(t.Text,{mt:"lg",children:"Y Axis"}),c(t.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[e(V.Controller,{name:"y_axis_data_key",control:o,render:({field:l})=>e(t.TextInput,p({sx:{flexGrow:1},size:"md",label:"Data Key"},l))}),e(V.Controller,{name:"yAxis3D.name",control:o,render:({field:l})=>e(t.TextInput,p({sx:{flexGrow:1},size:"md",label:"Name"},l))})]}),e(t.Text,{mt:"lg",children:"Z Axis"}),c(t.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[e(V.Controller,{name:"z_axis_data_key",control:o,render:({field:l})=>e(t.TextInput,p({sx:{flexGrow:1},size:"md",label:"Data Key"},l))}),e(V.Controller,{name:"zAxis3D.name",control:o,render:({field:l})=>e(t.TextInput,p({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(v.DeviceFloppy,{size:20}),e(t.Text,{ml:"md",children:"Save"})]})})]})})}function ge({value:n,onChange:i}){const r=t.useMantineTheme(),o=u.default.useMemo(()=>Object.entries(r.colors).map(([s,l])=>({label:s,value:l[6]})),[r]),a=u.default.useMemo(()=>o.some(s=>s.value===n),[n,o]);return c(t.Group,{position:"apart",spacing:"xs",children:[e(t.TextInput,{placeholder:"Set any color",value:a?"":n,onChange:s=>i(s.currentTarget.value),rightSection:e(t.ColorSwatch,{color:a?"transparent":n,radius:4}),variant:a?"filled":"default",sx:{maxWidth:"100%",flexGrow:1}}),e(t.Text,{sx:{flexGrow:0},children:"or"}),e(t.Select,{data:o,value:n,onChange: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}})]})}function lt({conf:n,setConf:i}){const d=n,{series:r}=d,o=_(d,["series"]),a=u.default.useMemo(()=>p({series:G.formList(r!=null?r:[])},o),[r,o]),s=G.useForm({initialValues:a}),l=()=>s.addListItem("series",{type:"bar",name:z.randomId(),showSymbol:!1,y_axis_data_key:"value",stack:"",color:"#000"});return u.default.useMemo(()=>!T.default.isEqual(s.values,a),[s.values,a]),e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:s.onSubmit(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(v.DeviceFloppy,{size:20})})]}),e(t.TextInput,p({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((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,p({label:"Label",required:!0,sx:{flex:1}},s.getListInputProps("series",f,"name"))),c(t.Group,{direction:"row",grow:!0,noWrap:!0,children:[e(t.TextInput,p({label:"Y Axis Data key",required:!0},s.getListInputProps("series",f,"y_axis_data_key"))),e(t.TextInput,p({label:"Stack ID",placeholder:"Stack bars by this ID"},s.getListInputProps("series",f,"stack")))]}),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{children:"Color"}),e(ge,p({},s.getListInputProps("series",f,"color")))]}),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>s.removeListItem("series",f),sx:{position:"absolute",top:15,right:5},children:e(v.Trash,{size:16})})]},f)),e(t.Group,{position:"center",mt:"xs",children:e(t.Button,{onClick:l,children:"Add a Series"})})]})]})})}function st({conf:{label_field:n,value_field:i},setConf:r}){const o=G.useForm({initialValues:{label_field:n,value_field:i}});return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:o.onSubmit(r),children:[c(t.Group,{position:"apart",mb:"lg",sx:{position:"relative"},children:[e(t.Text,{children:"Sunburst Config"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",children:e(v.DeviceFloppy,{size:20})})]}),c(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,p:"md",mb:"sm",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[e(t.TextInput,p({label:"Label Field",required:!0,sx:{flex:1}},o.getInputProps("label_field"))),e(t.TextInput,p({label:"Value Field",placeholder:"get column value by this field",required:!0,sx:{flex:1}},o.getInputProps("value_field")))]})]})})}const ut=Object.values(B).map(n=>({label:n,value:n}));function dt({label:n,value:i,onChange:r,sx:o}){return e(t.Select,{label:n,data:ut,value:i,onChange:r,sx:o})}function ct(o){var a=o,{conf:s}=a,l=s,{columns:n}=l,i=_(l,["columns"]),{setConf:r}=a;const d=G.useForm({initialValues:p({id_field:"id",use_raw_columns:!0,columns:G.formList(n!=null?n:[]),size:"sm",horizontalSpacing:"sm",verticalSpacing:"sm",striped:!1,highlightOnHover:!1},i)}),h=()=>d.addListItem("columns",{label:z.randomId(),value_field:"value",value_type:B.string});return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:d.onSubmit(r),children:[c(t.Group,{position:"apart",mb:"lg",sx:{position:"relative"},children:[e(t.Text,{children:"Table Config"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",children:e(v.DeviceFloppy,{size:20})})]}),c(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,p:"md",mb:"sm",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[e(t.TextInput,p({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,p({label:"Horizontal Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1}},d.getInputProps("horizontalSpacing"))),e(t.TextInput,p({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,p({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,p({label:"Striped"},d.getInputProps("striped",{type:"checkbox"}))),e(t.Switch,p({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,p({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,g)=>c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[c(t.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:[e(t.TextInput,p({label:"Label",required:!0,sx:{flex:1}},d.getListInputProps("columns",g,"label"))),e(t.TextInput,p({label:"Value Field",placeholder:"get column value by this field",required:!0,sx:{flex:1}},d.getListInputProps("columns",g,"value_field"))),e(dt,p({label:"Value Type",sx:{flex:1}},d.getListInputProps("columns",g,"value_type")))]}),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>d.removeListItem("columns",g),sx:{position:"absolute",top:15,right:5},children:e(v.Trash,{size:16})})]},g)),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(M.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(d.values,null,2)})]})})}const H=[{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[o,a]=u.default.useState((l=(s=H.find(d=>d.label===i))==null?void 0:s.value)!=null?l:H[0].value);return u.default.useEffect(()=>{const d=H.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:H,value:o,onChange:a,step:25,placeholder:"Pick a font size"})]})}const be=[{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 a;const r=G.useForm({initialValues:{paragraphs:G.formList((a=n.paragraphs)!=null?a:be)}}),o=()=>r.addListItem("paragraphs",E(p({},be[0]),{template:z.randomId()}));return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:r.onSubmit(i),children:[r.values.paragraphs.length===0&&e(t.Text,{color:"dimmed",align:"center",children:"Empty"}),c(t.Group,{position:"apart",mb:"xs",sx:{" + .mantine-Group-root":{marginTop:0}},children:[e(t.Text,{children:"Paragraphs"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",children:e(v.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,p({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(ge,p({},r.getListInputProps("paragraphs",l,"color")))]}),e(t.Group,{direction:"column",grow:!0,children:e(t.TextInput,p({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(pt,p({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(v.Trash,{size:16})})]},l)),e(t.Group,{position:"center",mt:"md",children:e(t.Button,{onClick:o,children:"Add a Paragraph"})}),e(t.Text,{size:"sm",weight:500,mt:"md",children:"Current Configuration:"}),e(M.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(r.values,null,2)})]})})}const re=[{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:at},{value:"line-bar",label:"Line-Bar Chart",Panel:lt}];function ht(){const{viz:n,setViz:i}=u.default.useContext(q),[r,o]=z.useInputState(n.type),a=n.type!==r,s=u.default.useCallback(()=>{!a||i(f=>E(p({},f),{type:r}))},[a,r]),l=f=>{i(g=>E(p({},g),{conf:f}))},d=f=>{try{l(JSON.parse(f))}catch(g){console.error(g)}},h=u.default.useMemo(()=>{var f;return(f=re.find(g=>g.value===r))==null?void 0:f.Panel},[r,re]);return c(ie,{children:[e(t.Select,{label:"Visualization",value:r,onChange:o,data:re,rightSection:e(t.ActionIcon,{disabled:!a,onClick:s,children:e(v.DeviceFloppy,{size:20})})}),h&&e(h,{conf:n.conf,setConf:l}),!h&&e(t.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(n.conf,null,2),onChange:d})]})}function ft({}){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},children:[e(ot,{}),e(je,{}),e(t.Divider,{sx:{flexGrow:0}}),e(ht,{})]}),e(t.Box,{sx:{height:"100%",flexGrow:1,maxWidth:"60%"},children:e(rt,{})})]})}function xt({opened:n,close:i}){const{freezeLayout:r}=u.default.useContext(j),{data:o,loading:a,viz:s,title:l}=u.default.useContext(q);return u.default.useEffect(()=>{r(n)},[n]),e(t.Modal,{size:"96vw",overflow:"inside",opened:n,onClose:i,title:l,trapFocus:!0,onDragStart:d=>{d.stopPropagation()},children:e(t.AppShell,{sx:{height:"90vh",maxHeight:"calc(100vh - 185px)",".mantine-AppShell-body":{height:"100%"},main:{height:"100%",width:"100%"}},padding:"md",children:c(t.Tabs,{initialTab:2,children:[c(t.Tabs.Tab,{label:"Data Source",children:[e(t.LoadingOverlay,{visible:a}),e(Ve,{})]}),e(t.Tabs.Tab,{label:"Viz Config",children:e(ft,{})})]})})})}function gt({}){const[n,i]=u.default.useState(!1),r=()=>i(!0),o=()=>i(!1),{title:a,description:s,loading:l,refreshData:d}=u.default.useContext(q),{inEditMode:h}=u.default.useContext(j);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(v.InfoCircle,{size:12,style:{verticalAlign:"baseline",cursor:"pointer"}})})}),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:d,icon:e(v.Refresh,{size:14}),children:"Refresh"}),h&&e(t.Menu.Item,{onClick:r,icon:e(v.Settings,{size:14}),children:"Settings"}),e(t.Divider,{}),e(t.Menu.Item,{color:"red",disabled:!0,icon:e(v.Trash,{size:14}),children:"Delete"})]})}),h&&e(xt,{opened:n,close:o})]})}var Nt="";function oe({viz:n,dataSourceID:i,title:r,description:o,update:a,layout:s,id:l}){const d=u.default.useContext(R),h=u.default.useContext(P),[f,g]=u.default.useState(r),[b,x]=u.default.useState(o),[S,D]=u.default.useState(i),[I,L]=u.default.useState(n),$=u.default.useMemo(()=>{if(!!S)return h.dataSources.find(J=>J.id===S)},[S,h.dataSources]);u.default.useEffect(()=>{a==null||a({id:l,layout:s,title:f,description:b,dataSourceID:S,viz:I})},[f,b,$,I,l,s,S]);const{data:k=[],loading:K,refresh:ae}=se.useRequest(ce({context:d,definitions:h,title:f,dataSource:$}),{refreshDeps:[d,h,$]}),le=ae;return e(q.Provider,{value:{data:k,loading:K,title:f,setTitle:g,description:b,setDescription:x,dataSourceID:S,setDataSourceID:D,viz:I,setViz:L,refreshData:le},children:c(t.Container,{className:"panel-root",children:[e(gt,{}),e(fe,{children:e(xe,{viz:I,data:k,loading:K})})]})})}var Vt="";const bt=w.WidthProvider(w.Responsive);function Se({panels:n,setPanels:i,className:r="layout",cols:o={lg:12,md:10,sm:8,xs:6,xxs:4},rowHeight:a=10,onRemoveItem:s,isDraggable:l,isResizable:d,setLocalCols:h,setBreakpoint:f}){const g=(x,S)=>{f(x),h(S)},b=u.default.useCallback(x=>{const S=new Map;x.forEach($=>{var k=$,{i:I}=k,L=_(k,["i"]);S.set(I,L)});const D=n.map(I=>E(p({},I),{layout:S.get(I.id)}));i(D)},[n,i]);return e(bt,{onBreakpointChange:g,onLayoutChange:b,className:r,cols:o,rowHeight:a,isDraggable:l,isResizable:d,children:n.map((I,D)=>{var L=I,{id:x}=L,S=_(L,["id"]);return e("div",{"data-grid":S.layout,children:e(oe,E(p({id:x},S),{destroy:()=>s(x),update:$=>{i(k=>(k.splice(D,1,$),k))}}))},x)})})}function ve(n,i){return c(t.Text,{sx:{svg:{verticalAlign:"text-bottom"}},children:[n," ",i]})}function St({mode:n,setMode:i}){return e(t.SegmentedControl,{value:n,onChange:i,data:[{label:ve(e(v.PlayerPlay,{size:20}),"Use"),value:O.Use},{label:ve(e(v.Paint,{size:20}),"Edit"),value:O.Edit}]})}const vt=`
|
|
9
|
+
*/var Ne=u.default,Ve=Symbol.for("react.element"),Re=Symbol.for("react.fragment"),We=Object.prototype.hasOwnProperty,Qe=Ne.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Je={key:!0,ref:!0,__self:!0,__source:!0};function xe(n,r,i){var o,a={},s=null,l=null;i!==void 0&&(s=""+i),r.key!==void 0&&(s=""+r.key),r.ref!==void 0&&(l=r.ref);for(o in r)We.call(r,o)&&!Je.hasOwnProperty(o)&&(a[o]=r[o]);if(n&&n.defaultProps)for(o in r=n.defaultProps,r)a[o]===void 0&&(a[o]=r[o]);return{$$typeof:Ve,type:n,key:s,ref:l,props:a,_owner:Qe.current}}K.Fragment=Re,K.jsx=xe,K.jsxs=xe,U.exports=K;const e=U.exports.jsx,c=U.exports.jsxs,ie=U.exports.Fragment;function ge({position:n,trigger:r="click"}){const{freezeLayout:i}=u.default.useContext(B),[o,a]=u.default.useState(!1),{description:s}=u.default.useContext(I);if(u.default.useEffect(()=>{i(o)},[o]),!s)return null;const l=r==="click"?e(t.Tooltip,{label:"Click to see description",openDelay:500,children:e(y.InfoCircle,{size:20,onClick:()=>a(d=>!d),style:{verticalAlign:"baseline",cursor:"pointer"}})}):e(y.InfoCircle,{size:20,onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),style:{verticalAlign:"baseline",cursor:"pointer"}});return e(t.Popover,{opened:o,onClose:()=>a(!1),withCloseButton:!0,withArrow:!0,trapFocus:!0,closeOnEscape:!1,placement:"center",position:n,target:l,children:e(Ee.default,{readOnly:!0,value:s,onChange:w.default.noop,sx:{border:"none"}})})}function Ue(){const{description:n,setDescription:r}=u.default.useContext(I),[i,o]=u.default.useState(n),a=n!==i,s=u.default.useCallback(()=>{!a||r(i)},[a,i]);return c(t.Group,{direction:"column",sx:{flexGrow:1},children:[c(t.Group,{align:"end",children:[e(t.Text,{children:"Description"}),e(t.ActionIcon,{variant:"hover",color:"blue",disabled:!a,onClick:s,children:e(y.DeviceFloppy,{size:20})})]}),e(de.RichTextEditor,{value:i,onChange:o,sx:{flexGrow:1},sticky:!0,p:"0"})]})}class oe extends u.default.Component{constructor(r){super(r),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}render(){return this.state.hasError?e("h1",{children:"Something went wrong."}):this.props.children}}function Ke(){const{title:n}=u.default.useContext(I);return e(oe,{children:c(t.Group,{direction:"column",grow:!0,noWrap:!0,mx:"auto",mt:"xl",p:"5px",spacing:"xs",sx:{width:"600px",height:"450px",background:"transparent",borderRadius:"5px",boxShadow:"0px 0px 10px 0px rgba(0,0,0,.2)"},children:[c(t.Group,{position:"apart",noWrap:!0,sx:{borderBottom:"1px solid #eee",paddingBottom:"5px",flexGrow:0,flexShrink:0},children:[e(t.Group,{children:e(ge,{position:"bottom",trigger:"hover"})}),e(t.Group,{grow:!0,position:"center",children:e(t.Text,{lineClamp:1,weight:"bold",children:n})}),e(t.Group,{position:"right",spacing:0,sx:{height:"28px"}})]}),e(t.Group,{sx:{background:"#eee",flexGrow:1}})]})})}function Ye(){const{title:n,setTitle:r}=u.default.useContext(I),[i,o]=O.useInputState(n),a=n!==i,s=u.default.useCallback(()=>{!a||r(i)},[a,i]);return e(t.TextInput,{value:i,onChange:o,label:c(t.Group,{align:"end",children:[e(t.Text,{children:"Panel Title"}),e(t.ActionIcon,{variant:"hover",color:"blue",disabled:!a,onClick:s,children:e(y.DeviceFloppy,{size:20})})]})})}function He({}){return c(t.Group,{direction:"row",grow:!0,noWrap:!0,align:"stretch",sx:{height:"100%"},children:[c(t.Group,{grow:!0,direction:"column",sx:{width:"40%",flexShrink:0,flexGrow:0,height:"100%"},children:[e(Ye,{}),e(Ue,{})]}),e(t.Box,{sx:{height:"100%",flexGrow:1,maxWidth:"60%"},children:e(Ke,{})})]})}function be({id:n}){const r=u.default.useContext(P),i=u.default.useContext(R),o=u.default.useMemo(()=>r.dataSources.find(l=>l.id===n),[r.dataSources,n]),{data:a=[],loading:s}=ee.useRequest(fe({context:i,definitions:r,title:n,dataSource:o}),{refreshDeps:[i,r,o]});return s?e(t.LoadingOverlay,{visible:s}):a.length===0?e(t.Table,{}):c(t.Group,{my:"xl",direction:"column",grow:!0,sx:{border:"1px solid #eee"},children:[e(t.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:e(t.Text,{weight:500,children:"Preview Data"})}),c(t.Table,{children:[e("thead",{children:e("tr",{children:Object.keys(a==null?void 0:a[0]).map(l=>e("th",{children:l},l))})}),e("tbody",{children:a.map((l,d)=>e("tr",{children:Object.values(l).map((m,p)=>e("td",{children:e(t.Group,{sx:{"&, .mantine-Text-root":{fontFamily:"monospace"}},children:e(t.Text,{children:m})})},`${m}--${p}`))},`row-${d}`))})]})]})}function Xe({}){const{dataSources:n}=u.default.useContext(P),{dataSourceID:r,setDataSourceID:i,data:o,loading:a}=u.default.useContext(I),s=u.default.useMemo(()=>n.map(l=>({value:l.id,label:l.id})),[n]);return c(t.Group,{direction:"column",grow:!0,noWrap:!0,children:[c(t.Group,{position:"left",sx:{maxWidth:"600px",alignItems:"baseline"},children:[e(t.Text,{children:"Select a Data Source"}),e(t.Select,{data:s,value:r,onChange:i,allowDeselect:!1,clearable:!1,sx:{flexGrow:1}})]}),e(be,{id:r})]})}Q.use([te.SunburstChart,ne.CanvasRenderer]);const Ze={tooltip:{show:!0},series:{type:"sunburst",radius:[0,"90%"],emphasis:{focus:"ancestor"}}};function et({conf:n,data:r,width:i,height:o}){const b=n,{label_field:a="name",value_field:s="value"}=b,l=_(b,["label_field","value_field"]),d=u.default.useMemo(()=>r.map(x=>({name:x[a],value:Number(x[s])})),[r,a,s]),m=u.default.useMemo(()=>{var x,S;return(S=(x=w.default.maxBy(d,D=>D.value))==null?void 0:x.value)!=null?S:1},[d]),p=u.default.useMemo(()=>({series:{label:{formatter:({name:x,value:S})=>S/m<.2?" ":x}}}),[m]),g=w.default.merge({},Ze,p,l,{series:{data:d}});return e(re.default,{echarts:Q,option:g,style:{width:i,height:o}})}Q.use([te.BarChart,te.LineChart,N.GridComponent,N.LegendComponent,N.TooltipComponent,ne.CanvasRenderer]);const tt={legend:{show:!0},tooltip:{trigger:"axis"},xAxis:{type:"category"},yAxis:{},grid:{top:30,left:10,right:10,bottom:10,containLabel:!0}};function nt({conf:n,data:r,width:i,height:o}){const a=u.default.useMemo(()=>{const s={dataset:{source:r}},l={xAxis:{data:r.map(m=>m[n.x_axis_data_key])}},d=n.series.map(g=>{var b=g,{y_axis_data_key:m}=b,p=_(b,["y_axis_data_key"]);return h({data:r.map(x=>x[m])},p)});return w.default.assign({},tt,s,l,{series:d})},[n,r]);return!i||!o?null:e(re.default,{echarts:Q,option:a,style:{width:i,height:o}})}var F=(n=>(n.string="string",n.number="number",n.eloc="eloc",n.percentage="percentage",n))(F||{});function rt({value:n}){return e(t.Text,{component:"span",children:n})}function it({value:n}){return e(t.Text,{component:"span",children:n})}function ot({value:n}){const r=ce.default(n).format({thousandSeparated:!0});return e(t.Text,{component:"span",children:r})}function at({value:n}){const r=ce.default(n).format({output:"percent",mantissa:3});return e(t.Text,{component:"span",children:r})}function lt({value:n,type:r}){switch(r){case F.string:return e(rt,{value:n});case F.eloc:return e(it,{value:n});case F.number:return e(ot,{value:n});case F.percentage:return e(at,{value:n})}}function st({conf:n,data:r,width:i,height:o}){const g=n,{id_field:a,use_raw_columns:s,columns:l}=g,d=_(g,["id_field","use_raw_columns","columns"]),m=u.default.useMemo(()=>s?Object.keys(r==null?void 0:r[0]):l.map(b=>b.label),[s,l,r]),p=u.default.useMemo(()=>s?Object.keys(r==null?void 0:r[0]).map(b=>({label:b,value_field:b,value_type:F.string})):l,[s,l,r]);return c(t.Table,E(h({sx:{maxHeight:o}},d),{children:[e("thead",{children:e("tr",{children:m.map(b=>e("th",{children:b},b))})}),e("tbody",{children:r.map((b,x)=>e("tr",{children:p.map(({value_field:S,value_type:D})=>e("td",{children:e(t.Group,{sx:{"&, .mantine-Text-root":{fontFamily:"monospace"}},children:e(lt,{value:b[S],type:D})})},b[S]))},a?b[a]:`row-${x}`))})]}))}function ut(n,r={}){const i=Object.keys(r),o=Object.values(r);try{return new Function(...i,`return \`${n}\`;`)(...o)}catch(a){return a.message}}function dt({conf:{paragraphs:n},data:r}){return e(ie,{children:n.map((l,s)=>{var d=l,{template:i,size:o}=d,a=_(d,["template","size"]);return e(t.Text,E(h({},a),{sx:{fontSize:o},children:ut(i,r[0])}),`${i}---${s}`)})})}Q.use([N.GridComponent,N.VisualMapComponent,N.LegendComponent,N.TooltipComponent,ne.CanvasRenderer]);function ct({conf:n,data:r,width:i,height:o}){const b=n,{x_axis_data_key:a,y_axis_data_key:s,z_axis_data_key:l}=b,d=_(b,["x_axis_data_key","y_axis_data_key","z_axis_data_key"]),m=u.default.useMemo(()=>w.default.minBy(r,x=>x[l])[l],[r,l]),p=u.default.useMemo(()=>w.default.maxBy(r,x=>x[l])[l],[r,l]),g=E(h({tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:m,max:p,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:{type:"value"},yAxis3D:{type:"value"},zAxis3D:{type:"value"},grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}}},d),{series:[{type:"bar3D",wireframe:{},data:r.map(x=>[x[a],x[s],x[l]])}]});return e(re.default,{echarts:Q,option:g,style:{width:i,height:o}})}var Jt="";function pt(n,r,i,o){const a={width:n,height:r,data:i,conf:o.conf};switch(o.type){case"sunburst":return e(et,h({},a));case"line-bar":return e(nt,h({},a));case"table":return e(st,h({},a));case"text":return e(dt,h({},a));case"bar-3d":return e(ct,h({},a));default:return null}}function Se({viz:n,data:r,loading:i}){const{ref:o,width:a,height:s}=O.useElementSize(),l=u.default.useMemo(()=>!Array.isArray(r)||r.length===0,[r]);return i?e("div",{className:"viz-root",ref:o,children:e(t.LoadingOverlay,{visible:i})}):c("div",{className:"viz-root",ref:o,children:[l&&e(t.Text,{color:"gray",align:"center",children:"nothing to show"}),!l&&pt(a,s,r,n)]})}function ht({}){const{data:n,loading:r,viz:i}=u.default.useContext(I);return e(oe,{children:e(Se,{viz:i,data:n,loading:r})})}function ft({conf:n,setConf:r}){const i=w.default.assign({},{x_axis_data_key:"x",y_axis_data_key:"y",z_axis_data_key:"z",xAxis3D:{type:"value",name:"X Axis Name"},yAxis3D:{type:"value",name:"Y Axis Name"},zAxis3D:{type:"value",name:"Z Axis Name"}},n),{control:o,handleSubmit:a,formState:s}=V.useForm({defaultValues:i});return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:a(r),children:[e(t.Text,{children:"X Axis"}),c(t.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[e(V.Controller,{name:"x_axis_data_key",control:o,render:({field:l})=>e(t.TextInput,h({sx:{flexGrow:1},size:"md",label:"Data Key"},l))}),e(V.Controller,{name:"xAxis3D.name",control:o,render:({field:l})=>e(t.TextInput,h({sx:{flexGrow:1},size:"md",label:"Name"},l))})]}),e(t.Text,{mt:"lg",children:"Y Axis"}),c(t.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[e(V.Controller,{name:"y_axis_data_key",control:o,render:({field:l})=>e(t.TextInput,h({sx:{flexGrow:1},size:"md",label:"Data Key"},l))}),e(V.Controller,{name:"yAxis3D.name",control:o,render:({field:l})=>e(t.TextInput,h({sx:{flexGrow:1},size:"md",label:"Name"},l))})]}),e(t.Text,{mt:"lg",children:"Z Axis"}),c(t.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[e(V.Controller,{name:"z_axis_data_key",control:o,render:({field:l})=>e(t.TextInput,h({sx:{flexGrow:1},size:"md",label:"Data Key"},l))}),e(V.Controller,{name:"zAxis3D.name",control:o,render:({field:l})=>e(t.TextInput,h({sx:{flexGrow:1},size:"md",label:"Name"},l))})]}),e(t.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:c(t.Button,{color:"blue",type:"submit",children:[e(y.DeviceFloppy,{size:20}),e(t.Text,{ml:"md",children:"Save"})]})})]})})}function ye({value:n,onChange:r}){const i=t.useMantineTheme(),o=u.default.useMemo(()=>Object.entries(i.colors).map(([s,l])=>({label:s,value:l[6]})),[i]),a=u.default.useMemo(()=>o.some(s=>s.value===n),[n,o]);return c(t.Group,{position:"apart",spacing:"xs",children:[e(t.TextInput,{placeholder:"Set any color",value:a?"":n,onChange:s=>r(s.currentTarget.value),rightSection:e(t.ColorSwatch,{color:a?"transparent":n,radius:4}),variant:a?"filled":"default",sx:{maxWidth:"100%",flexGrow:1}}),e(t.Text,{sx:{flexGrow:0},children:"or"}),e(t.Select,{data:o,value:n,onChange:r,variant:a?"default":"filled",placeholder:"Pick a theme color",icon:e(t.ColorSwatch,{color:a?n:"transparent",radius:4}),sx:{maxWidth:"100%",flexGrow:1}})]})}function mt({conf:n,setConf:r}){const d=n,{series:i}=d,o=_(d,["series"]),a=u.default.useMemo(()=>h({series:z.formList(i!=null?i:[])},o),[i,o]),s=z.useForm({initialValues:a}),l=()=>s.addListItem("series",{type:"bar",name:O.randomId(),showSymbol:!1,y_axis_data_key:"value",stack:"",color:"#000"});return u.default.useMemo(()=>!w.default.isEqual(s.values,a),[s.values,a]),e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:s.onSubmit(r),children:[c(t.Group,{position:"apart",mb:"lg",sx:{position:"relative"},children:[e(t.Text,{children:"Chart Config"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",children:e(y.DeviceFloppy,{size:20})})]}),e(t.TextInput,h({size:"md",mb:"lg",label:"X Axis Data Key"},s.getInputProps("x_axis_data_key"))),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{mt:"xl",mb:0,children:"Series"}),s.values.series.map((m,p)=>c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[e(t.TextInput,h({label:"Label",required:!0,sx:{flex:1}},s.getListInputProps("series",p,"name"))),c(t.Group,{direction:"row",grow:!0,noWrap:!0,children:[e(t.TextInput,h({label:"Y Axis Data key",required:!0},s.getListInputProps("series",p,"y_axis_data_key"))),e(t.TextInput,h({label:"Stack ID",placeholder:"Stack bars by this ID"},s.getListInputProps("series",p,"stack")))]}),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{children:"Color"}),e(ye,h({},s.getListInputProps("series",p,"color")))]}),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>s.removeListItem("series",p),sx:{position:"absolute",top:15,right:5},children:e(y.Trash,{size:16})})]},p)),e(t.Group,{position:"center",mt:"xs",children:e(t.Button,{onClick:l,children:"Add a Series"})})]})]})})}function xt({conf:{label_field:n,value_field:r},setConf:i}){const o=z.useForm({initialValues:{label_field:n,value_field:r}});return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:o.onSubmit(i),children:[c(t.Group,{position:"apart",mb:"lg",sx:{position:"relative"},children:[e(t.Text,{children:"Sunburst Config"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",children:e(y.DeviceFloppy,{size:20})})]}),c(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,p:"md",mb:"sm",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[e(t.TextInput,h({label:"Label Field",required:!0,sx:{flex:1}},o.getInputProps("label_field"))),e(t.TextInput,h({label:"Value Field",placeholder:"get column value by this field",required:!0,sx:{flex:1}},o.getInputProps("value_field")))]})]})})}const gt=Object.values(F).map(n=>({label:n,value:n}));function bt({label:n,value:r,onChange:i,sx:o}){return e(t.Select,{label:n,data:gt,value:r,onChange:i,sx:o})}function St(o){var a=o,{conf:s}=a,l=s,{columns:n}=l,r=_(l,["columns"]),{setConf:i}=a;const d=z.useForm({initialValues:h({id_field:"id",use_raw_columns:!0,columns:z.formList(n!=null?n:[]),size:"sm",horizontalSpacing:"sm",verticalSpacing:"sm",striped:!1,highlightOnHover:!1},r)}),m=()=>d.addListItem("columns",{label:O.randomId(),value_field:"value",value_type:F.string});return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:d.onSubmit(i),children:[c(t.Group,{position:"apart",mb:"lg",sx:{position:"relative"},children:[e(t.Text,{children:"Table Config"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",children:e(y.DeviceFloppy,{size:20})})]}),c(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,p:"md",mb:"sm",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[e(t.TextInput,h({size:"md",mb:"lg",label:"ID Field"},d.getInputProps("id_field"))),c(t.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:[e(t.TextInput,h({label:"Horizontal Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1}},d.getInputProps("horizontalSpacing"))),e(t.TextInput,h({label:"Vertical Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1}},d.getInputProps("verticalSpacing")))]}),e(t.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:e(t.TextInput,h({label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1}},d.getInputProps("size")))}),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{children:"Other"}),c(t.Group,{position:"apart",grow:!0,children:[e(t.Switch,h({label:"Striped"},d.getInputProps("striped",{type:"checkbox"}))),e(t.Switch,h({label:"Highlight on hover"},d.getInputProps("highlightOnHover",{type:"checkbox"})))]})]})]}),c(t.Group,{direction:"column",mt:"xs",spacing:"xs",grow:!0,p:"md",mb:"xl",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[e(t.Switch,h({label:"Use Original Data Columns"},d.getInputProps("use_raw_columns",{type:"checkbox"}))),!d.values.use_raw_columns&&c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{mt:"xl",mb:0,children:"Custom Columns"}),d.values.columns.map((p,g)=>c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[c(t.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:[e(t.TextInput,h({label:"Label",required:!0,sx:{flex:1}},d.getListInputProps("columns",g,"label"))),e(t.TextInput,h({label:"Value Field",placeholder:"get column value by this field",required:!0,sx:{flex:1}},d.getListInputProps("columns",g,"value_field"))),e(bt,h({label:"Value Type",sx:{flex:1}},d.getListInputProps("columns",g,"value_type")))]}),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>d.removeListItem("columns",g),sx:{position:"absolute",top:15,right:5},children:e(y.Trash,{size:16})})]},g)),e(t.Group,{position:"center",mt:"xs",children:e(t.Button,{onClick:m,children:"Add a Column"})})]})]}),e(t.Text,{weight:500,mb:"md",children:"Current Configuration:"}),e(M.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(d.values,null,2)})]})})}const Y=[{label:"initial",value:0},{label:"500",value:25},{label:"700",value:50},{label:"semibold",value:75},{label:"bold",value:100}];function yt({label:n,value:r,onChange:i}){var s,l;const[o,a]=u.default.useState((l=(s=Y.find(d=>d.label===r))==null?void 0:s.value)!=null?l:Y[0].value);return u.default.useEffect(()=>{const d=Y.find(m=>m.value===o);d&&i(d.label)},[o]),c(t.Group,{direction:"column",grow:!0,spacing:"xs",mb:"lg",children:[e(t.Text,{children:n}),e(t.Slider,{label:null,marks:Y,value:o,onChange:a,step:25,placeholder:"Pick a font size"})]})}const ve=[{align:"center",size:"xl",weight:"bold",color:"black",template:"Time: ${new Date().toISOString()}"},{align:"center",size:"md",weight:"bold",color:"red",template:"Platform: ${navigator.userAgentData.platform}."}];function vt({conf:n,setConf:r}){var a;const i=z.useForm({initialValues:{paragraphs:z.formList((a=n.paragraphs)!=null?a:ve)}}),o=()=>i.addListItem("paragraphs",E(h({},ve[0]),{template:O.randomId()}));return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:i.onSubmit(r),children:[i.values.paragraphs.length===0&&e(t.Text,{color:"dimmed",align:"center",children:"Empty"}),c(t.Group,{position:"apart",mb:"xs",sx:{" + .mantine-Group-root":{marginTop:0}},children:[e(t.Text,{children:"Paragraphs"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",children:e(y.DeviceFloppy,{size:20})})]}),i.values.paragraphs.map((s,l)=>c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[e(t.TextInput,h({placeholder:"Time: ${new Date().toISOString()}",label:"Content Template",required:!0,sx:{flex:1}},i.getListInputProps("paragraphs",l,"template"))),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{children:"Color"}),e(ye,h({},i.getListInputProps("paragraphs",l,"color")))]}),e(t.Group,{direction:"column",grow:!0,children:e(t.TextInput,h({label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",sx:{flex:1}},i.getListInputProps("paragraphs",l,"size")))}),e(t.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:e(yt,h({label:"Font Weight"},i.getListInputProps("paragraphs",l,"weight")))}),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>i.removeListItem("paragraphs",l),sx:{position:"absolute",top:15,right:5},children:e(y.Trash,{size:16})})]},l)),e(t.Group,{position:"center",mt:"md",children:e(t.Button,{onClick:o,children:"Add a Paragraph"})}),e(t.Text,{size:"sm",weight:500,mt:"md",children:"Current Configuration:"}),e(M.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(i.values,null,2)})]})})}const ae=[{value:"text",label:"Text",Panel:vt},{value:"table",label:"Table",Panel:St},{value:"sunburst",label:"Sunburst",Panel:xt},{value:"bar-3d",label:"Bar Chart (3D)",Panel:ft},{value:"line-bar",label:"Line-Bar Chart",Panel:mt}];function Ct(){const{viz:n,setViz:r}=u.default.useContext(I),[i,o]=O.useInputState(n.type),a=n.type!==i,s=u.default.useCallback(()=>{!a||r(p=>E(h({},p),{type:i}))},[a,i]),l=p=>{r(g=>E(h({},g),{conf:p}))},d=p=>{try{l(JSON.parse(p))}catch(g){console.error(g)}},m=u.default.useMemo(()=>{var p;return(p=ae.find(g=>g.value===i))==null?void 0:p.Panel},[i,ae]);return c(ie,{children:[e(t.Select,{label:"Visualization",value:i,onChange:o,data:ae,rightSection:e(t.ActionIcon,{disabled:!a,onClick:s,children:e(y.DeviceFloppy,{size:20})})}),m&&e(m,{conf:n.conf,setConf:l}),!m&&e(t.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(n.conf,null,2),onChange:d})]})}function wt({}){return c(t.Group,{direction:"row",grow:!0,noWrap:!0,align:"stretch",sx:{height:"100%"},children:[e(t.Group,{grow:!0,direction:"column",noWrap:!0,sx:{width:"40%",flexShrink:0,flexGrow:0},children:e(Ct,{})}),e(t.Box,{sx:{height:"100%",flexGrow:1,maxWidth:"60%"},children:e(ht,{})})]})}function Tt({opened:n,close:r}){const{freezeLayout:i}=u.default.useContext(B),{data:o,loading:a,viz:s,title:l}=u.default.useContext(I);return u.default.useEffect(()=>{i(n)},[n]),e(t.Modal,{size:"96vw",overflow:"inside",opened:n,onClose:r,title:l,trapFocus:!0,onDragStart:d=>{d.stopPropagation()},children:e(t.AppShell,{sx:{height:"90vh",maxHeight:"calc(100vh - 185px)",".mantine-AppShell-body":{height:"100%"},main:{height:"100%",width:"100%"}},padding:"md",children:c(t.Tabs,{initialTab:2,children:[c(t.Tabs.Tab,{label:"Data Source",children:[e(t.LoadingOverlay,{visible:a}),e(Xe,{})]}),e(t.Tabs.Tab,{label:"Panel",children:e(He,{})}),e(t.Tabs.Tab,{label:"Visualization",children:e(wt,{})})]})})})}function Dt({}){const[n,r]=u.default.useState(!1),i=()=>r(!0),o=()=>r(!1),{title:a,refreshData:s}=u.default.useContext(I),{inEditMode:l}=u.default.useContext(B);return c(t.Group,{position:"apart",noWrap:!0,sx:{borderBottom:"1px solid #eee",paddingBottom:"5px"},children:[e(t.Group,{children:e(ge,{})}),e(t.Group,{grow:!0,position:"center",children:e(t.Text,{lineClamp:1,weight:"bold",children:a})}),e(t.Group,{position:"right",spacing:0,sx:{height:"28px"},children:c(t.Menu,{children:[e(t.Menu.Item,{onClick:s,icon:e(y.Refresh,{size:14}),children:"Refresh"}),l&&e(t.Menu.Item,{onClick:i,icon:e(y.Settings,{size:14}),children:"Settings"}),e(t.Divider,{}),e(t.Menu.Item,{color:"red",disabled:!0,icon:e(y.Trash,{size:14}),children:"Delete"})]})}),l&&e(Tt,{opened:n,close:o})]})}var Ut="";function le({viz:n,dataSourceID:r,title:i,description:o,update:a,layout:s,id:l}){const d=u.default.useContext(R),m=u.default.useContext(P),[p,g]=u.default.useState(i),[b,x]=u.default.useState(o),[S,D]=u.default.useState(r),[G,L]=u.default.useState(n),$=u.default.useMemo(()=>{if(!!S)return m.dataSources.find(J=>J.id===S)},[S,m.dataSources]);u.default.useEffect(()=>{a==null||a({id:l,layout:s,title:p,description:b,dataSourceID:S,viz:G})},[p,b,$,G,l,s,S]);const{data:k=[],loading:H,refresh:se}=ee.useRequest(fe({context:d,definitions:m,title:p,dataSource:$}),{refreshDeps:[d,m,$]}),ue=se;return e(I.Provider,{value:{data:k,loading:H,title:p,setTitle:g,description:b,setDescription:x,dataSourceID:S,setDataSourceID:D,viz:G,setViz:L,refreshData:ue},children:c(t.Container,{className:"panel-root",children:[e(Dt,{}),e(oe,{children:e(Se,{viz:G,data:k,loading:H})})]})})}var Kt="";const Gt=T.WidthProvider(T.Responsive);function Ce({panels:n,setPanels:r,className:i="layout",cols:o={lg:12,md:10,sm:8,xs:6,xxs:4},rowHeight:a=10,onRemoveItem:s,isDraggable:l,isResizable:d,setLocalCols:m,setBreakpoint:p}){const g=(x,S)=>{p(x),m(S)},b=u.default.useCallback(x=>{const S=new Map;x.forEach($=>{var k=$,{i:G}=k,L=_(k,["i"]);S.set(G,L)});const D=n.map(G=>E(h({},G),{layout:S.get(G.id)}));r(D)},[n,r]);return e(Gt,{onBreakpointChange:g,onLayoutChange:b,className:i,cols:o,rowHeight:a,isDraggable:l,isResizable:d,children:n.map((G,D)=>{var L=G,{id:x}=L,S=_(L,["id"]);return e("div",{"data-grid":S.layout,children:e(le,E(h({id:x},S),{destroy:()=>s(x),update:$=>{r(k=>(k.splice(D,1,$),[...k]))}}))},x)})})}function we(n,r){return c(t.Text,{sx:{svg:{verticalAlign:"text-bottom"}},children:[n," ",r]})}function It({mode:n,setMode:r}){return e(t.SegmentedControl,{value:n,onChange:r,data:[{label:we(e(y.PlayerPlay,{size:20}),"Use"),value:q.Use},{label:we(e(y.Paint,{size:20}),"Edit"),value:q.Edit}]})}const _t=`
|
|
10
10
|
-- You may reference context data or SQL snippets *by name*
|
|
11
11
|
-- in SQL or VizConfig.
|
|
12
12
|
SELECT *
|
|
@@ -17,16 +17,16 @@ WHERE
|
|
|
17
17
|
-- SQL snippets
|
|
18
18
|
AND \${author_email_condition}
|
|
19
19
|
\${order_by_clause}
|
|
20
|
-
`;function
|
|
20
|
+
`;function zt({}){const n=u.default.useContext(R),{sqlSnippets:r}=u.default.useContext(P),i=u.default.useMemo(()=>{const a=r.reduce((s,l)=>(s[l.key]=l.value,s),{});return JSON.stringify(a,null,2)},[r]),o=u.default.useMemo(()=>JSON.stringify(n,null,2),[n]);return c(t.Group,{direction:"column",grow:!0,sx:{border:"1px solid #eee",maxWidth:"48%",overflow:"hidden"},children:[e(t.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:e(t.Text,{weight:500,children:"Context"})}),c(t.Group,{direction:"column",px:"md",pb:"md",sx:{width:"100%"},children:[e(M.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:_t}),e(t.Text,{weight:500,sx:{flexGrow:0},children:"Avaiable context"}),e(M.Prism,{language:"json",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:o}),e(t.Text,{weight:500,sx:{flexGrow:0},children:"Avaiable SQL Snippets"}),e(M.Prism,{language:"json",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:i})]})]})}function Pt({value:n,onChange:r}){const i=z.useForm({initialValues:n}),o=u.default.useCallback(p=>{r(p)},[r]),a=u.default.useMemo(()=>!w.default.isEqual(n,i.values),[n,i.values]);u.default.useEffect(()=>{i.reset()},[n]);const{data:s={},loading:l}=ee.useRequest(Be,{refreshDeps:[]},[]),d=u.default.useMemo(()=>Object.keys(s).map(p=>({label:p,value:p})),[s]),m=u.default.useMemo(()=>{const p=s[i.values.type];return p?p.map(g=>({label:g,value:g})):[]},[s,i.values.type]);return e(t.Group,{direction:"column",grow:!0,sx:{border:"1px solid #eee",flexGrow:1},children:c("form",{onSubmit:i.onSubmit(o),children:[c(t.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[e(t.Text,{weight:500,children:"Data Source Configuration"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!a||l,children:e(y.DeviceFloppy,{size:20})})]}),c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,children:[c(t.Group,{grow:!0,children:[e(t.TextInput,h({placeholder:"An ID unique in this dashboard",label:"ID",required:!0,sx:{flex:1},disabled:l},i.getInputProps("id"))),e(t.Select,h({label:"Data Source Type",data:d,sx:{flex:1},disabled:l},i.getInputProps("type"))),e(t.Select,h({label:"Data Source Key",data:m,sx:{flex:1},disabled:l},i.getInputProps("key")))]}),e(t.Textarea,h({autosize:!0,minRows:12,maxRows:24},i.getInputProps("sql")))]})]})})}function Lt({id:n}){const{dataSources:r,setDataSources:i}=u.default.useContext(P),o=u.default.useMemo(()=>r.find(s=>s.id===n),[r,n]),a=u.default.useCallback(s=>{if(!r.findIndex(d=>d.id===s.id)){console.error(new Error("Invalid data source id when updating by id"));return}i(d=>{const m=d.findIndex(p=>p.id===n);return d.splice(m,1,s),[...d]})},[i]);return o?c(t.Group,{direction:"row",position:"apart",grow:!0,align:"stretch",noWrap:!0,children:[e(Pt,{value:o,onChange:a}),e(zt,{})]}):e("span",{children:"Invalid Data Source ID"})}function kt({id:n,setID:r}){const{dataSources:i,setDataSources:o}=u.default.useContext(P),a=u.default.useCallback(()=>{var d,m;r((m=(d=i[0])==null?void 0:d.id)!=null?m:"")},[r,i]);u.default.useEffect(()=>{if(!n){a();return}i.findIndex(m=>m.id===n)===-1&&a()},[n,i,a]);const s=u.default.useMemo(()=>i.map(d=>({value:d.id,label:d.id})),[i]),l=u.default.useCallback(()=>{const d={id:O.randomId(),type:"postgresql",key:"",sql:""};o(m=>[...m,d])},[o]);return e(t.Group,{pb:"xl",children:c(t.Group,{position:"left",sx:{maxWidth:"600px",alignItems:"baseline"},children:[e(t.Text,{children:"Select a Data Source"}),e(t.Select,{data:s,value:n,onChange:r,allowDeselect:!1,clearable:!1,sx:{flexGrow:1}}),e(t.Text,{children:"or"}),e(t.Group,{position:"center",mt:"md",children:e(t.Button,{onClick:l,children:"Add a Data Source"})})]})})}function Et({opened:n,close:r}){const[i,o]=u.default.useState(""),{freezeLayout:a}=u.default.useContext(B);return u.default.useEffect(()=>{a(n)},[n]),e(t.Modal,{size:"96vw",overflow:"inside",opened:n,onClose:r,title:"Data Sources",trapFocus:!0,onDragStart:s=>{s.stopPropagation()},children:c(t.AppShell,{sx:{height:"90vh",maxHeight:"calc(100vh - 185px)",".mantine-AppShell-body":{height:"100%"},main:{height:"100%",width:"100%",padding:0,margin:0}},padding:"md",header:e(kt,{id:i,setID:o}),children:[e(Lt,{id:i}),e(be,{id:i})]})})}function Ot({}){const n=u.default.useContext(R),r="SELECT *\nFROM commit\nWHERE author_time BETWEEN '${timeRange?.[0].toISOString()}' AND '${timeRange?.[1].toISOString()}'";return c(t.Group,{direction:"column",grow:!0,sx:{border:"1px solid #eee",maxWidth:"48%",overflow:"hidden"},children:[e(t.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:e(t.Text,{weight:500,children:"Context"})}),c(t.Group,{direction:"column",px:"md",pb:"md",sx:{width:"100%"},children:[e(M.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:`-- You may refer context data *by name*
|
|
21
21
|
-- in SQL or VizConfig.
|
|
22
22
|
|
|
23
|
-
${
|
|
23
|
+
${r}`}),e(t.Text,{weight:500,sx:{flexGrow:0},children:"Avaiable context entries"}),e(M.Prism,{language:"json",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:JSON.stringify(n,null,2)})]})]})}function qt({}){const{sqlSnippets:n,setSQLSnippets:r}=u.default.useContext(P),i=`SELECT *
|
|
24
24
|
FROM commit
|
|
25
|
-
WHERE \${author_time_condition}`,o=u.default.useMemo(()=>({snippets:
|
|
25
|
+
WHERE \${author_time_condition}`,o=u.default.useMemo(()=>({snippets:z.formList(n!=null?n:[])}),[n]),a=z.useForm({initialValues:o}),s=()=>a.addListItem("snippets",{key:O.randomId(),value:""}),l=u.default.useMemo(()=>!w.default.isEqual(a.values,o),[a.values,o]),d=({snippets:m})=>{r(m)};return c(t.Group,{direction:"column",grow:!0,sx:{border:"1px solid #eee"},children:[c(t.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:[e(t.Text,{weight:500,children:"SQL Snippets"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!l,children:e(y.DeviceFloppy,{size:20})})]}),c(t.Group,{px:"md",pb:"md",children:[e(M.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,trim:!1,colorScheme:"dark",children:`-- You may refer context data *by name*
|
|
26
26
|
-- in SQL or VizConfig.
|
|
27
27
|
|
|
28
|
-
${
|
|
28
|
+
${i}
|
|
29
29
|
|
|
30
30
|
-- where author_time_condition is:
|
|
31
31
|
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((
|
|
32
|
+
`}),e(t.Group,{direction:"column",sx:{width:"100%",position:"relative"},grow:!0,children:c("form",{onSubmit:a.onSubmit(d),children:[a.values.snippets.map((m,p)=>c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[e(t.TextInput,h({label:"Key",required:!0},a.getListInputProps("snippets",p,"key"))),e(t.Textarea,h({minRows:3,label:"Value",required:!0},a.getListInputProps("snippets",p,"value"))),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>a.removeListItem("snippets",p),sx:{position:"absolute",top:15,right:5},children:e(y.Trash,{size:16})})]},p)),e(t.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"40%"},mx:"auto",children:e(t.Button,{variant:"default",onClick:s,children:"Add a snippet"})})]})})]})]})}function At({opened:n,close:r}){const{freezeLayout:i}=u.default.useContext(B);return u.default.useEffect(()=>{i(n)},[n]),e(t.Modal,{size:"96vw",overflow:"inside",opened:n,onClose:r,title:"SQL Snippets",trapFocus:!0,onDragStart:o=>{o.stopPropagation()},children:e(t.AppShell,{sx:{height:"90vh",maxHeight:"calc(100vh - 185px)",".mantine-AppShell-body":{height:"100%"},main:{height:"100%",width:"100%",padding:0,margin:0}},padding:"md",children:c(t.Group,{direction:"row",position:"apart",grow:!0,align:"stretch",noWrap:!0,children:[e(qt,{}),e(Ot,{})]})})})}function Mt({mode:n,setMode:r,hasChanges:i,addPanel:o,saveChanges:a}){const[s,l]=u.default.useState(!1),d=()=>l(!0),m=()=>l(!1),[p,g]=u.default.useState(!1),b=()=>g(!0),x=()=>g(!1),S=n===q.Edit;return c(t.Group,{position:"apart",pt:"sm",pb:"xs",children:[e(t.Group,{position:"left",children:e(It,{mode:n,setMode:r})}),S&&c(ie,{children:[c(t.Group,{position:"right",children:[e(t.Button,{variant:"default",size:"sm",onClick:o,leftIcon:e(y.PlaylistAdd,{size:20}),children:"Add a Panel"}),e(t.Button,{variant:"default",size:"sm",onClick:b,leftIcon:e(y.ClipboardText,{size:20}),children:"SQL Snippets"}),e(t.Button,{variant:"default",size:"sm",onClick:d,leftIcon:e(y.Database,{size:20}),children:"Data Sources"}),e(t.Button,{variant:"default",size:"sm",onClick:a,disabled:!i,leftIcon:e(y.DeviceFloppy,{size:20}),children:"Save Changes"}),e(t.Button,{color:"red",size:"sm",disabled:!i,leftIcon:e(y.Recycle,{size:20}),children:"Revert Changes"})]}),e(Et,{opened:s,close:m}),e(At,{opened:p,close:x})]}),!S&&e(t.Button,{variant:"default",size:"sm",disabled:!0,leftIcon:e(y.Share,{size:20}),children:"Share"})]})}function Bt({context:n,dashboard:r,update:i,className:o="dashboard"}){const[a,s]=u.default.useState(!1),[l,d]=u.default.useState(),[m,p]=u.default.useState(),[g,b]=u.default.useState(r.panels),[x,S]=u.default.useState(r.definition.sqlSnippets),[D,G]=u.default.useState(r.definition.dataSources),[L,$]=u.default.useState(q.Edit),k=u.default.useMemo(()=>{const A=j=>JSON.parse(JSON.stringify(j));return!w.default.isEqual(A(g),A(r.panels))||!w.default.isEqual(x,r.definition.sqlSnippets)?!0:!w.default.isEqual(D,r.definition.dataSources)},[r,g,x,D]),H=async()=>{const A=w.default.merge({},r,{panels:g},{definition:{sqlSnippets:x}});await i(A)},se=()=>{const A=O.randomId(),X={id:A,layout:{x:0,y:1/0,w:3,h:4},title:`New Panel - ${A}`,description:"description goes here",dataSourceID:"",viz:{type:"table",conf:{}}};b(j=>[...j,X])},ue=A=>{const X=g.findIndex(j=>j.id===A);b(j=>(j.splice(X,1),[...j]))},J=L===q.Edit,Nt=u.default.useMemo(()=>({sqlSnippets:x,setSQLSnippets:S,dataSources:D,setDataSources:G}),[x,S,D,G]);return e(R.Provider,{value:n,children:e("div",{className:o,children:e(P.Provider,{value:Nt,children:c(B.Provider,{value:{layoutFrozen:a,freezeLayout:s,mode:L,inEditMode:J},children:[e(Mt,{mode:L,setMode:$,hasChanges:k,addPanel:se,saveChanges:H}),e(Ce,{panels:g,setPanels:b,isDraggable:J&&!a,isResizable:J&&!a,onRemoveItem:ue,setLocalCols:p,setBreakpoint:d})]})})})})}const Ft=T.WidthProvider(T.Responsive);function $t({panels:n,className:r="layout",cols:i={lg:12,md:10,sm:8,xs:6,xxs:4},rowHeight:o=10}){return e(Ft,{className:r,cols:i,rowHeight:o,isDraggable:!1,isResizable:!1,children:n.map(l=>{var d=l,{id:a}=d,s=_(d,["id"]);return e("div",{"data-grid":s.layout,children:e(le,h({id:a},s))},a)})})}function jt({context:n,dashboard:r,className:i="dashboard"}){const o=u.default.useMemo(()=>E(h({},r.definition),{setSQLSnippets:()=>{},setDataSources:()=>{}}),[r]);return e(R.Provider,{value:n,children:e("div",{className:i,children:e(P.Provider,{value:o,children:e(B.Provider,{value:{layoutFrozen:!0,freezeLayout:()=>{},mode:q.Use,inEditMode:!1},children:e($t,{panels:r.panels})})})})})}f.ContextInfoContext=R,f.Dashboard=Bt,f.DashboardLayout=Ce,f.DashboardMode=q,f.DefinitionContext=P,f.LayoutStateContext=B,f.Panel=le,f.PanelContext=I,f.ReadOnlyDashboard=jt,f.initialContextInfoContext=Fe,Object.defineProperties(f,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
interface IDescriptionPopover {
|
|
3
|
+
position?: 'top' | 'left' | 'bottom' | 'right';
|
|
4
|
+
trigger?: 'hover' | 'click';
|
|
5
|
+
}
|
|
6
|
+
export declare function DescriptionPopover({ position, trigger }: IDescriptionPopover): JSX.Element | null;
|
|
7
|
+
export {};
|
|
File without changes
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devtable/dashboard",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"@mantine/hooks": "^4.2.5",
|
|
35
35
|
"@mantine/notifications": "^4.2.5",
|
|
36
36
|
"@mantine/prism": "^4.2.5",
|
|
37
|
+
"@mantine/rte": "^4.2.5",
|
|
37
38
|
"@types/lodash": "^4.14.182",
|
|
38
39
|
"@types/react": "^18.0.0",
|
|
39
40
|
"@types/react-dom": "^18.0.0",
|
|
@@ -61,6 +62,7 @@
|
|
|
61
62
|
"@mantine/hooks": "^4.2.5",
|
|
62
63
|
"@mantine/notifications": "^4.2.5",
|
|
63
64
|
"@mantine/prism": "^4.2.5",
|
|
65
|
+
"@mantine/rte": "^4.2.5",
|
|
64
66
|
"ahooks": "^3.3.11",
|
|
65
67
|
"axios": "^0.27.2",
|
|
66
68
|
"echarts": "^5.3.2",
|