@devtable/dashboard 1.5.0 → 1.6.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/dashboard.es.js
CHANGED
|
@@ -40,7 +40,7 @@ import RichTextEditor, { RichTextEditor as RichTextEditor$1 } from "@mantine/rte
|
|
|
40
40
|
import { useInputState, useElementSize, randomId } from "@mantine/hooks";
|
|
41
41
|
import ReactEChartsCore from "echarts-for-react/lib/core";
|
|
42
42
|
import * as echarts from "echarts/core";
|
|
43
|
-
import { SunburstChart, BarChart, LineChart } from "echarts/charts";
|
|
43
|
+
import { SunburstChart, BarChart, LineChart, PieChart } from "echarts/charts";
|
|
44
44
|
import { CanvasRenderer } from "echarts/renderers";
|
|
45
45
|
import { GridComponent, LegendComponent, TooltipComponent, VisualMapComponent } from "echarts/components";
|
|
46
46
|
import numbro from "numbro";
|
|
@@ -578,7 +578,7 @@ function PickDataSource({}) {
|
|
|
578
578
|
});
|
|
579
579
|
}
|
|
580
580
|
echarts.use([SunburstChart, CanvasRenderer]);
|
|
581
|
-
const defaultOption$
|
|
581
|
+
const defaultOption$2 = {
|
|
582
582
|
tooltip: {
|
|
583
583
|
show: true
|
|
584
584
|
},
|
|
@@ -628,7 +628,7 @@ function Sunbrust({
|
|
|
628
628
|
}
|
|
629
629
|
}
|
|
630
630
|
}), [max]);
|
|
631
|
-
const option = _.merge({}, defaultOption$
|
|
631
|
+
const option = _.merge({}, defaultOption$2, labelOption, restConf, {
|
|
632
632
|
series: {
|
|
633
633
|
data: chartData
|
|
634
634
|
}
|
|
@@ -643,7 +643,7 @@ function Sunbrust({
|
|
|
643
643
|
});
|
|
644
644
|
}
|
|
645
645
|
echarts.use([BarChart, LineChart, GridComponent, LegendComponent, TooltipComponent, CanvasRenderer]);
|
|
646
|
-
const defaultOption = {
|
|
646
|
+
const defaultOption$1 = {
|
|
647
647
|
legend: {
|
|
648
648
|
show: true,
|
|
649
649
|
bottom: 0,
|
|
@@ -760,7 +760,7 @@ function VizLineBarChart({
|
|
|
760
760
|
}
|
|
761
761
|
}
|
|
762
762
|
};
|
|
763
|
-
return _.merge({}, defaultOption, customOptions);
|
|
763
|
+
return _.merge({}, defaultOption$1, customOptions);
|
|
764
764
|
}, [conf, data]);
|
|
765
765
|
if (!width || !height) {
|
|
766
766
|
return null;
|
|
@@ -1013,6 +1013,87 @@ function VizBar3D({
|
|
|
1013
1013
|
});
|
|
1014
1014
|
}
|
|
1015
1015
|
var index$2 = "";
|
|
1016
|
+
echarts.use([PieChart, CanvasRenderer]);
|
|
1017
|
+
const defaultOption = {
|
|
1018
|
+
tooltip: {
|
|
1019
|
+
show: true
|
|
1020
|
+
},
|
|
1021
|
+
series: {
|
|
1022
|
+
type: "pie",
|
|
1023
|
+
radius: ["50%", "80%"],
|
|
1024
|
+
label: {
|
|
1025
|
+
position: "outer",
|
|
1026
|
+
alignTo: "edge",
|
|
1027
|
+
formatter: "{name|{b}}\n{percentage|{d}%}",
|
|
1028
|
+
minMargin: 5,
|
|
1029
|
+
edgeDistance: 10,
|
|
1030
|
+
lineHeight: 15,
|
|
1031
|
+
rich: {
|
|
1032
|
+
percentage: {
|
|
1033
|
+
color: "#999"
|
|
1034
|
+
}
|
|
1035
|
+
},
|
|
1036
|
+
margin: 20
|
|
1037
|
+
},
|
|
1038
|
+
labelLine: {
|
|
1039
|
+
length: 15,
|
|
1040
|
+
length2: 0,
|
|
1041
|
+
maxSurfaceAngle: 80,
|
|
1042
|
+
showAbove: true
|
|
1043
|
+
},
|
|
1044
|
+
top: 10,
|
|
1045
|
+
bottom: 10,
|
|
1046
|
+
left: 10,
|
|
1047
|
+
right: 10
|
|
1048
|
+
}
|
|
1049
|
+
};
|
|
1050
|
+
function VizPie({
|
|
1051
|
+
conf,
|
|
1052
|
+
data,
|
|
1053
|
+
width,
|
|
1054
|
+
height
|
|
1055
|
+
}) {
|
|
1056
|
+
const _a = conf, {
|
|
1057
|
+
label_field = "name",
|
|
1058
|
+
value_field = "value"
|
|
1059
|
+
} = _a, restConf = __objRest(_a, [
|
|
1060
|
+
"label_field",
|
|
1061
|
+
"value_field"
|
|
1062
|
+
]);
|
|
1063
|
+
const chartData = React.useMemo(() => {
|
|
1064
|
+
return data.map((d) => ({
|
|
1065
|
+
name: d[label_field],
|
|
1066
|
+
value: Number(d[value_field])
|
|
1067
|
+
}));
|
|
1068
|
+
}, [data, label_field, value_field]);
|
|
1069
|
+
const labelOptions = React.useMemo(() => {
|
|
1070
|
+
return {
|
|
1071
|
+
series: {
|
|
1072
|
+
labelLayout: function(params) {
|
|
1073
|
+
const isLeft = params.labelRect.x < width / 2;
|
|
1074
|
+
const points = params.labelLinePoints;
|
|
1075
|
+
points[2][0] = isLeft ? params.labelRect.x : params.labelRect.x + params.labelRect.width;
|
|
1076
|
+
return {
|
|
1077
|
+
labelLinePoints: points
|
|
1078
|
+
};
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
};
|
|
1082
|
+
}, [width]);
|
|
1083
|
+
const option = _.merge({}, defaultOption, labelOptions, restConf, {
|
|
1084
|
+
series: {
|
|
1085
|
+
data: chartData
|
|
1086
|
+
}
|
|
1087
|
+
});
|
|
1088
|
+
return /* @__PURE__ */ jsx(ReactEChartsCore, {
|
|
1089
|
+
echarts,
|
|
1090
|
+
option,
|
|
1091
|
+
style: {
|
|
1092
|
+
width,
|
|
1093
|
+
height
|
|
1094
|
+
}
|
|
1095
|
+
});
|
|
1096
|
+
}
|
|
1016
1097
|
function renderViz(width, height, data, viz) {
|
|
1017
1098
|
const props = {
|
|
1018
1099
|
width,
|
|
@@ -1031,6 +1112,8 @@ function renderViz(width, height, data, viz) {
|
|
|
1031
1112
|
return /* @__PURE__ */ jsx(VizText, __spreadValues({}, props));
|
|
1032
1113
|
case "bar-3d":
|
|
1033
1114
|
return /* @__PURE__ */ jsx(VizBar3D, __spreadValues({}, props));
|
|
1115
|
+
case "pie":
|
|
1116
|
+
return /* @__PURE__ */ jsx(VizPie, __spreadValues({}, props));
|
|
1034
1117
|
default:
|
|
1035
1118
|
return null;
|
|
1036
1119
|
}
|
|
@@ -1535,6 +1618,72 @@ function VizLineBarChartPanel({
|
|
|
1535
1618
|
})
|
|
1536
1619
|
});
|
|
1537
1620
|
}
|
|
1621
|
+
function VizPiePanel({
|
|
1622
|
+
conf: {
|
|
1623
|
+
label_field,
|
|
1624
|
+
value_field
|
|
1625
|
+
},
|
|
1626
|
+
setConf
|
|
1627
|
+
}) {
|
|
1628
|
+
const form = useForm$1({
|
|
1629
|
+
initialValues: {
|
|
1630
|
+
label_field,
|
|
1631
|
+
value_field
|
|
1632
|
+
}
|
|
1633
|
+
});
|
|
1634
|
+
return /* @__PURE__ */ jsx(Group, {
|
|
1635
|
+
direction: "column",
|
|
1636
|
+
mt: "md",
|
|
1637
|
+
spacing: "xs",
|
|
1638
|
+
grow: true,
|
|
1639
|
+
children: /* @__PURE__ */ jsxs("form", {
|
|
1640
|
+
onSubmit: form.onSubmit(setConf),
|
|
1641
|
+
children: [/* @__PURE__ */ jsxs(Group, {
|
|
1642
|
+
position: "apart",
|
|
1643
|
+
mb: "lg",
|
|
1644
|
+
sx: {
|
|
1645
|
+
position: "relative"
|
|
1646
|
+
},
|
|
1647
|
+
children: [/* @__PURE__ */ jsx(Text, {
|
|
1648
|
+
children: "Pie Config"
|
|
1649
|
+
}), /* @__PURE__ */ jsx(ActionIcon, {
|
|
1650
|
+
type: "submit",
|
|
1651
|
+
mr: 5,
|
|
1652
|
+
variant: "filled",
|
|
1653
|
+
color: "blue",
|
|
1654
|
+
children: /* @__PURE__ */ jsx(DeviceFloppy, {
|
|
1655
|
+
size: 20
|
|
1656
|
+
})
|
|
1657
|
+
})]
|
|
1658
|
+
}), /* @__PURE__ */ jsxs(Group, {
|
|
1659
|
+
direction: "column",
|
|
1660
|
+
mt: "md",
|
|
1661
|
+
spacing: "xs",
|
|
1662
|
+
grow: true,
|
|
1663
|
+
p: "md",
|
|
1664
|
+
mb: "sm",
|
|
1665
|
+
sx: {
|
|
1666
|
+
border: "1px solid #eee",
|
|
1667
|
+
borderRadius: "5px"
|
|
1668
|
+
},
|
|
1669
|
+
children: [/* @__PURE__ */ jsx(TextInput, __spreadValues({
|
|
1670
|
+
label: "Label Field",
|
|
1671
|
+
required: true,
|
|
1672
|
+
sx: {
|
|
1673
|
+
flex: 1
|
|
1674
|
+
}
|
|
1675
|
+
}, form.getInputProps("label_field"))), /* @__PURE__ */ jsx(TextInput, __spreadValues({
|
|
1676
|
+
label: "Value Field",
|
|
1677
|
+
placeholder: "get column value by this field",
|
|
1678
|
+
required: true,
|
|
1679
|
+
sx: {
|
|
1680
|
+
flex: 1
|
|
1681
|
+
}
|
|
1682
|
+
}, form.getInputProps("value_field")))]
|
|
1683
|
+
})]
|
|
1684
|
+
})
|
|
1685
|
+
});
|
|
1686
|
+
}
|
|
1538
1687
|
function SunburstPanel({
|
|
1539
1688
|
conf: {
|
|
1540
1689
|
label_field,
|
|
@@ -2041,6 +2190,10 @@ const types = [{
|
|
|
2041
2190
|
value: "line-bar",
|
|
2042
2191
|
label: "Line-Bar Chart",
|
|
2043
2192
|
Panel: VizLineBarChartPanel
|
|
2193
|
+
}, {
|
|
2194
|
+
value: "pie",
|
|
2195
|
+
label: "Pie Chart",
|
|
2196
|
+
Panel: VizPiePanel
|
|
2044
2197
|
}];
|
|
2045
2198
|
function EditVizConf() {
|
|
2046
2199
|
const {
|
package/dist/dashboard.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(x,w){typeof exports=="object"&&typeof module!="undefined"?w(exports,require("react"),require("lodash"),require("react-grid-layout"),require("@mantine/core"),require("ahooks"),require("axios"),require("tabler-icons-react"),require("@mantine/rte"),require("@mantine/hooks"),require("echarts-for-react/lib/core"),require("echarts/core"),require("echarts/charts"),require("echarts/renderers"),require("echarts/components"),require("numbro"),require("echarts-gl"),require("react-hook-form"),require("@mantine/form"),require("@mantine/prism")):typeof define=="function"&&define.amd?define(["exports","react","lodash","react-grid-layout","@mantine/core","ahooks","axios","tabler-icons-react","@mantine/rte","@mantine/hooks","echarts-for-react/lib/core","echarts/core","echarts/charts","echarts/renderers","echarts/components","numbro","echarts-gl","react-hook-form","@mantine/form","@mantine/prism"],w):(x=typeof globalThis!="undefined"?globalThis:x||self,w(x.dashboard={},x.React,x._,x["react-grid-layout"],x["@mantine/core"],x.ahooks,x.axios,x["tabler-icons-react"],x["@mantine/rte"],x["@mantine/hooks"],x["echarts-for-react/lib/core"],x["echarts/core"],x["echarts/charts"],x["echarts/renderers"],x["echarts/components"],x.numbro,x["echarts-gl"],x["react-hook-form"],x["@mantine/form"],x["@mantine/prism"]))})(this,function(x,w,C,G,t,ie,De,v,ce,A,Pe,Ie,U,H,N,ze,Xt,j,z,B){"use strict";var Ht=Object.defineProperty,Kt=Object.defineProperties;var Yt=Object.getOwnPropertyDescriptors;var ne=Object.getOwnPropertySymbols;var _e=Object.prototype.hasOwnProperty,Ge=Object.prototype.propertyIsEnumerable;var Te=(x,w,C)=>w in x?Ht(x,w,{enumerable:!0,configurable:!0,writable:!0,value:C}):x[w]=C,m=(x,w)=>{for(var C in w||(w={}))_e.call(w,C)&&Te(x,C,w[C]);if(ne)for(var C of ne(w))Ge.call(w,C)&&Te(x,C,w[C]);return x},O=(x,w)=>Kt(x,Yt(w));var P=(x,w)=>{var C={};for(var G in x)_e.call(x,G)&&w.indexOf(G)<0&&(C[G]=x[G]);if(x!=null&&ne)for(var G of ne(x))w.indexOf(G)<0&&Ge.call(x,G)&&(C[G]=x[G]);return C};function Q(n){return n&&typeof n=="object"&&"default"in n?n:{default:n}}function Le(n){if(n&&n.__esModule)return n;var i=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});return n&&Object.keys(n).forEach(function(r){if(r!=="default"){var o=Object.getOwnPropertyDescriptor(n,r);Object.defineProperty(i,r,o.get?o:{enumerable:!0,get:function(){return n[r]}})}}),i.default=n,Object.freeze(i)}var u=Q(w),T=Q(C),ke=Q(De),Ee=Q(ce),K=Q(Pe),F=Le(Ie),re=Q(ze),q=(n=>(n.Use="use",n.Edit="edit",n))(q||{});const Oe={layoutFrozen:!1,freezeLayout:()=>{},mode:q.Edit,inEditMode:!1},R=u.default.createContext(Oe),pe=n=>(i,r,o={})=>{const a=m({"X-Requested-With":"XMLHttpRequest","Content-Type":o.string?"application/x-www-form-urlencoded":"application/json"},o.headers),l={baseURL:"http://localhost:31200",method:n,url:i,params:n==="GET"?r:o.params,headers:a};return n==="POST"&&(l.data=o.string?JSON.stringify(r):r),ke.default(l).then(s=>s.data).catch(s=>Promise.reject(s))},Ae=pe("GET"),qe=pe("POST");function me(n,i){const r=Object.keys(i),o=Object.values(i);try{return new Function(...r,`return \`${n}\`;`)(...o)}catch(a){throw r.length===0&&n.includes("$")?new Error("[formatSQL] insufficient params"):a}}function Me(n,i){const r=i.sqlSnippets.reduce((o,a)=>(o[a.key]=me(a.value,n),o),{});return T.default.merge({},r,n)}const he=({context:n,definitions:i,title:r,dataSource:o})=>async()=>{if(!o||!o.sql)return[];const{type:a,key:l,sql:s}=o,d=s.includes("$");try{const f=Me(n,i),h=me(s,f);return d&&(console.groupCollapsed(`Final SQL for: ${r}`),console.log(h),console.groupEnd()),await qe("/query",{type:a,key:l,sql:h})}catch(f){return console.error(f),[]}};async function Be(){try{return await Ae("/query/sources",{})}catch(n){return console.error(n),{}}}const fe={},Fe=fe,W=u.default.createContext(fe),Re={data:[],loading:!1,title:"",setTitle:()=>{},description:"",setDescription:()=>{},dataSourceID:"",setDataSourceID:()=>{},viz:{type:"",conf:{}},setViz:()=>{},refreshData:()=>{}},L=u.default.createContext(Re),$e={sqlSnippets:[],setSQLSnippets:()=>{},dataSources:[],setDataSources:()=>{}},E=u.default.createContext($e);var Y={exports:{}},X={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var Ne=u.default,je=Symbol.for("react.element"),Ve=Symbol.for("react.fragment"),We=Object.prototype.hasOwnProperty,Qe=Ne.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Je={key:!0,ref:!0,__self:!0,__source:!0};function xe(n,r,i){var o,a={},l=null,s=null;i!==void 0&&(l=""+i),r.key!==void 0&&(l=""+r.key),r.ref!==void 0&&(s=r.ref);for(o in r)We.call(r,o)&&!Je.hasOwnProperty(o)&&(a[o]=r[o]);if(n&&n.defaultProps)for(o in r=n.defaultProps,r)a[o]===void 0&&(a[o]=r[o]);return{$$typeof:je,type:n,key:l,ref:s,props:a,_owner:Qe.current}}K.Fragment=Ve,K.jsx=xe,K.jsxs=xe,U.exports=K;const e=U.exports.jsx,c=U.exports.jsxs,oe=U.exports.Fragment;function ge({position:n,trigger:r="click"}){const{freezeLayout:i}=u.default.useContext(F),[o,a]=u.default.useState(!1),{description:l}=u.default.useContext(P);if(u.default.useEffect(()=>{i(o)},[o]),!l)return null;const s=r==="click"?e(t.Tooltip,{label:"Click to see description",openDelay:500,children:e(v.InfoCircle,{size:20,onClick:()=>a(d=>!d),style:{verticalAlign:"baseline",cursor:"pointer"}})}):e(v.InfoCircle,{size:20,onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),style:{verticalAlign:"baseline",cursor:"pointer"}});return e(t.Popover,{opened:o,onClose:()=>a(!1),withCloseButton:!0,withArrow:!0,trapFocus:!0,closeOnEscape:!1,placement:"center",position:n,target:s,children:e(Ee.default,{readOnly:!0,value:l,onChange:_.default.noop,sx:{border:"none"}})})}function Ue(){const{description:n,setDescription:r}=u.default.useContext(P),[i,o]=u.default.useState(n),a=n!==i,l=u.default.useCallback(()=>{!a||r(i)},[a,i]);return c(t.Group,{direction:"column",sx:{flexGrow:1},children:[c(t.Group,{align:"end",children:[e(t.Text,{children:"Description"}),e(t.ActionIcon,{variant:"hover",color:"blue",disabled:!a,onClick:l,children:e(v.DeviceFloppy,{size:20})})]}),e(ce.RichTextEditor,{value:i,onChange:o,sx:{flexGrow:1},sticky:!0,p:"0"})]})}class ae extends u.default.Component{constructor(r){super(r),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}render(){return this.state.hasError?e("h1",{children:"Something went wrong."}):this.props.children}}function Ke(){const{title:n}=u.default.useContext(P);return e(ae,{children:c(t.Group,{direction:"column",grow:!0,noWrap:!0,mx:"auto",mt:"xl",p:"5px",spacing:"xs",sx:{width:"600px",height:"450px",background:"transparent",borderRadius:"5px",boxShadow:"0px 0px 10px 0px rgba(0,0,0,.2)"},children:[c(t.Group,{position:"apart",noWrap:!0,sx:{borderBottom:"1px solid #eee",paddingBottom:"5px",flexGrow:0,flexShrink:0},children:[e(t.Group,{children:e(ge,{position:"bottom",trigger:"hover"})}),e(t.Group,{grow:!0,position:"center",children:e(t.Text,{lineClamp:1,weight:"bold",children:n})}),e(t.Group,{position:"right",spacing:0,sx:{height:"28px"}})]}),e(t.Group,{sx:{background:"#eee",flexGrow:1}})]})})}function Ye(){const{title:n,setTitle:r}=u.default.useContext(P),[i,o]=A.useInputState(n),a=n!==i,l=u.default.useCallback(()=>{!a||r(i)},[a,i]);return e(t.TextInput,{value:i,onChange:o,label:c(t.Group,{align:"end",children:[e(t.Text,{children:"Panel Title"}),e(t.ActionIcon,{variant:"hover",color:"blue",disabled:!a,onClick:l,children:e(v.DeviceFloppy,{size:20})})]})})}function He({}){return c(t.Group,{direction:"row",grow:!0,noWrap:!0,align:"stretch",sx:{height:"100%"},children:[c(t.Group,{grow:!0,direction:"column",sx:{width:"40%",flexShrink:0,flexGrow:0,height:"100%"},children:[e(Ye,{}),e(Ue,{})]}),e(t.Box,{sx:{height:"100%",flexGrow:1,maxWidth:"60%"},children:e(Ke,{})})]})}function be({id:n}){const r=u.default.useContext(E),i=u.default.useContext(V),o=u.default.useMemo(()=>r.dataSources.find(d=>d.id===n),[r.dataSources,n]),{data:a=[],loading:l,refresh:s}=ee.useRequest(me({context:i,definitions:r,title:n,dataSource:o}),{refreshDeps:[i,r,o]});return l?e(t.LoadingOverlay,{visible:l}):a.length===0?e(t.Table,{}):c(t.Group,{my:"xl",direction:"column",grow:!0,sx:{border:"1px solid #eee"},children:[c(t.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[c(t.Group,{position:"left",children:[e(t.Text,{weight:500,children:"Preview Data"}),a.length>10&&c(t.Text,{size:"sm",color:"gray",children:["Showing 10 rows of ",a.length]})]}),e(t.ActionIcon,{mr:15,variant:"hover",color:"blue",disabled:l,onClick:s,children:e(v.Refresh,{size:15})})]}),c(t.Table,{children:[e("thead",{children:e("tr",{children:Object.keys(a==null?void 0:a[0]).map(d=>e("th",{children:e(t.Text,{weight:700,color:"#000",children:d})},d))})}),e("tbody",{children:a.slice(0,10).map((d,x)=>e("tr",{children:Object.values(d).map((m,p)=>e("td",{children:e(t.Group,{sx:{"&, .mantine-Text-root":{fontFamily:"monospace"}},children:e(t.Text,{children:m})})},`${m}--${p}`))},`row-${x}`))})]})]})}function Xe({}){const{dataSources:n}=u.default.useContext(E),{dataSourceID:r,setDataSourceID:i,data:o,loading:a}=u.default.useContext(P),l=u.default.useMemo(()=>n.map(s=>({value:s.id,label:s.id})),[n]);return c(t.Group,{direction:"column",grow:!0,noWrap:!0,children:[c(t.Group,{position:"left",sx:{maxWidth:"600px",alignItems:"baseline"},children:[e(t.Text,{children:"Select a Data Source"}),e(t.Select,{data:l,value:r,onChange:i,allowDeselect:!1,clearable:!1,sx:{flexGrow:1}})]}),e(be,{id:r})]})}Q.use([te.SunburstChart,ne.CanvasRenderer]);const Ze={tooltip:{show:!0},series:{type:"sunburst",radius:[0,"90%"],emphasis:{focus:"ancestor"}}};function et({conf:n,data:r,width:i,height:o}){const b=n,{label_field:a="name",value_field:l="value"}=b,s=I(b,["label_field","value_field"]),d=u.default.useMemo(()=>r.map(g=>({name:g[a],value:Number(g[l])})),[r,a,l]),x=u.default.useMemo(()=>{var g,S;return(S=(g=_.default.maxBy(d,y=>y.value))==null?void 0:g.value)!=null?S:1},[d]),m=u.default.useMemo(()=>({series:{label:{formatter:({name:g,value:S})=>S/x<.2?" ":g}}}),[x]),p=_.default.merge({},Ze,m,s,{series:{data:d}});return e(re.default,{echarts:Q,option:p,style:{width:i,height:o}})}Q.use([te.BarChart,te.LineChart,N.GridComponent,N.LegendComponent,N.TooltipComponent,ne.CanvasRenderer]);const tt={legend:{show:!0,bottom:0,left:0},tooltip:{trigger:"axis"},xAxis:{type:"category",nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold"}},yAxis:{nameTextStyle:{fontWeight:"bolder",align:"left"}},grid:{top:30,left:15,right:15,bottom:30,containLabel:!0}};function nt({conf:n,data:r,width:i,height:o}){const a=u.default.useMemo(()=>{var x,m;const l=n.series.reduce((p,{name:b,y_axis_data_formatter:g})=>(p[b]=function({value:y}){if(!g)return y;try{return ie.default(y).format(JSON.parse(g))}catch(T){return console.error(T),y}},p),{}),s=n.series.map(T=>{var D=T,{y_axis_data_key:p,y_axis_data_formatter:b,name:g,label_position:S="top"}=D,y=I(D,["y_axis_data_key","y_axis_data_formatter","name","label_position"]);const L=h({data:r.map(z=>z[p]),label:{show:!0,position:S},name:g},y);return b&&(L.label.formatter=l[g]),L}),d={xAxis:{data:r.map(p=>p[n.x_axis_data_key]),name:(x=n.x_axis_name)!=null?x:""},yAxis:{name:(m=n.y_axis_name)!=null?m:""},dataset:{source:r},series:s,tooltip:{formatter:function(p){const b=Array.isArray(p)?p:[p];if(b.length===0)return"";const g=b.map(({seriesName:S,value:y})=>S?`${S}: ${l[S]({value:y})}`:y);return g.unshift(`<strong>${b[0].name}</strong>`),g.join("<br />")}}};return _.default.merge({},tt,d)},[n,r]);return!i||!o?null:e(re.default,{echarts:Q,option:a,style:{width:i,height:o}})}var $=(n=>(n.string="string",n.number="number",n.eloc="eloc",n.percentage="percentage",n))($||{});function rt({value:n}){return e(t.Text,{component:"span",children:n})}function it({value:n}){return e(t.Text,{component:"span",children:n})}function ot({value:n}){const r=ie.default(n).format({thousandSeparated:!0});return e(t.Text,{component:"span",children:r})}function at({value:n}){const r=ie.default(n).format({output:"percent",mantissa:3});return e(t.Text,{component:"span",children:r})}function lt({value:n,type:r}){switch(r){case $.string:return e(rt,{value:n});case $.eloc:return e(it,{value:n});case $.number:return e(ot,{value:n});case $.percentage:return e(at,{value:n})}}function st({conf:n,data:r,width:i,height:o}){const p=n,{id_field:a,use_raw_columns:l,columns:s}=p,d=I(p,["id_field","use_raw_columns","columns"]),x=u.default.useMemo(()=>l?Object.keys(r==null?void 0:r[0]):s.map(b=>b.label),[l,s,r]),m=u.default.useMemo(()=>l?Object.keys(r==null?void 0:r[0]).map(b=>({label:b,value_field:b,value_type:$.string})):s,[l,s,r]);return c(t.Table,O(h({sx:{maxHeight:o}},d),{children:[e("thead",{children:e("tr",{children:x.map(b=>e("th",{children:b},b))})}),e("tbody",{children:r.map((b,g)=>e("tr",{children:m.map(({value_field:S,value_type:y})=>e("td",{children:e(t.Group,{sx:{"&, .mantine-Text-root":{fontFamily:"monospace"}},children:e(lt,{value:b[S],type:y})})},b[S]))},a?b[a]:`row-${g}`))})]}))}function ut(n,r={}){const i=Object.keys(r),o=Object.values(r);try{return new Function(...i,`return \`${n}\`;`)(...o)}catch(a){return a.message}}function dt({conf:{paragraphs:n},data:r}){return e(oe,{children:n.map((s,l)=>{var d=s,{template:i,size:o}=d,a=I(d,["template","size"]);return e(t.Text,O(h({},a),{sx:{fontSize:o},children:ut(i,r[0])}),`${i}---${l}`)})})}Q.use([N.GridComponent,N.VisualMapComponent,N.LegendComponent,N.TooltipComponent,ne.CanvasRenderer]);function ct({conf:n,data:r,width:i,height:o}){const b=n,{x_axis_data_key:a,y_axis_data_key:l,z_axis_data_key:s}=b,d=I(b,["x_axis_data_key","y_axis_data_key","z_axis_data_key"]),x=u.default.useMemo(()=>_.default.minBy(r,g=>g[s])[s],[r,s]),m=u.default.useMemo(()=>_.default.maxBy(r,g=>g[s])[s],[r,s]),p=O(h({tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:x,max:m,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:{type:"value"},yAxis3D:{type:"value"},zAxis3D:{type:"value"},grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}}},d),{series:[{type:"bar3D",wireframe:{},data:r.map(g=>[g[a],g[l],g[s]])}]});return e(re.default,{echarts:Q,option:p,style:{width:i,height:o}})}var Yt="";function pt(n,r,i,o){const a={width:n,height:r,data:i,conf:o.conf};switch(o.type){case"sunburst":return e(et,h({},a));case"line-bar":return e(nt,h({},a));case"table":return e(st,h({},a));case"text":return e(dt,h({},a));case"bar-3d":return e(ct,h({},a));default:return null}}function Se({viz:n,data:r,loading:i}){const{ref:o,width:a,height:l}=A.useElementSize(),s=u.default.useMemo(()=>!Array.isArray(r)||r.length===0,[r]);return i?e("div",{className:"viz-root",ref:o,children:e(t.LoadingOverlay,{visible:i})}):c("div",{className:"viz-root",ref:o,children:[s&&e(t.Text,{color:"gray",align:"center",children:"nothing to show"}),!s&&pt(a,l,r,n)]})}function ht({}){const{data:n,loading:r,viz:i}=u.default.useContext(P);return e(ae,{children:e(Se,{viz:i,data:n,loading:r})})}function mt({conf:n,setConf:r}){const i=_.default.assign({},{x_axis_data_key:"x",y_axis_data_key:"y",z_axis_data_key:"z",xAxis3D:{type:"value",name:"X Axis Name"},yAxis3D:{type:"value",name:"Y Axis Name"},zAxis3D:{type:"value",name:"Z Axis Name"}},n),{control:o,handleSubmit:a,formState:l}=j.useForm({defaultValues:i});return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:a(r),children:[e(t.Text,{children:"X Axis"}),c(t.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[e(j.Controller,{name:"x_axis_data_key",control:o,render:({field:s})=>e(t.TextInput,h({sx:{flexGrow:1},size:"md",label:"Data Key"},s))}),e(j.Controller,{name:"xAxis3D.name",control:o,render:({field:s})=>e(t.TextInput,h({sx:{flexGrow:1},size:"md",label:"Name"},s))})]}),e(t.Text,{mt:"lg",children:"Y Axis"}),c(t.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[e(j.Controller,{name:"y_axis_data_key",control:o,render:({field:s})=>e(t.TextInput,h({sx:{flexGrow:1},size:"md",label:"Data Key"},s))}),e(j.Controller,{name:"yAxis3D.name",control:o,render:({field:s})=>e(t.TextInput,h({sx:{flexGrow:1},size:"md",label:"Name"},s))})]}),e(t.Text,{mt:"lg",children:"Z Axis"}),c(t.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[e(j.Controller,{name:"z_axis_data_key",control:o,render:({field:s})=>e(t.TextInput,h({sx:{flexGrow:1},size:"md",label:"Data Key"},s))}),e(j.Controller,{name:"zAxis3D.name",control:o,render:({field:s})=>e(t.TextInput,h({sx:{flexGrow:1},size:"md",label:"Name"},s))})]}),e(t.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:c(t.Button,{color:"blue",type:"submit",children:[e(v.DeviceFloppy,{size:20}),e(t.Text,{ml:"md",children:"Save"})]})})]})})}function ve({value:n,onChange:r}){const i=t.useMantineTheme(),o=u.default.useMemo(()=>Object.entries(i.colors).map(([l,s])=>({label:l,value:s[6]})),[i]),a=u.default.useMemo(()=>o.some(l=>l.value===n),[n,o]);return c(t.Group,{position:"apart",spacing:"xs",children:[e(t.TextInput,{placeholder:"Set any color",value:a?"":n,onChange:l=>r(l.currentTarget.value),rightSection:e(t.ColorSwatch,{color:a?"transparent":n,radius:4}),variant:a?"filled":"default",sx:{maxWidth:"100%",flexGrow:1}}),e(t.Text,{sx:{flexGrow:0},children:"or"}),e(t.Select,{data:o,value:n,onChange:r,variant:a?"default":"filled",placeholder:"Pick a theme color",icon:e(t.ColorSwatch,{color:a?n:"transparent",radius:4}),sx:{maxWidth:"100%",flexGrow:1}})]})}const ft=JSON.stringify({output:"percent",mantissa:2},null,2),xt=[{label:"top",value:"top"},{label:"left",value:"left"},{label:"right",value:"right"},{label:"bottom",value:"bottom"},{label:"inside",value:"inside"},{label:"insideLeft",value:"insideLeft"},{label:"insideRight",value:"insideRight"},{label:"insideTop",value:"insideTop"},{label:"insideBottom",value:"insideBottom"},{label:"insideTopLeft",value:"insideTopLeft"},{label:"insideBottomLeft",value:"insideBottomLeft"},{label:"insideTopRight",value:"insideTopRight"},{label:"insideBottomRight",value:"insideBottomRight"}];function gt(n){function r({type:i,name:o,showSymbol:a,y_axis_data_key:l="value",y_axis_data_formatter:s="",label_position:d="top",stack:x="1",color:m="black"}){return{type:i,name:o,showSymbol:a,y_axis_data_key:l,y_axis_data_formatter:s,label_position:d,stack:x,color:m}}return n.map(r)}function bt({conf:n,setConf:r}){const x=n,{series:i}=x,o=I(x,["series"]),a=u.default.useMemo(()=>{const g=o,{x_axis_name:m="",y_axis_name:p=""}=g,b=I(g,["x_axis_name","y_axis_name"]);return h({series:k.formList(gt(i!=null?i:[])),x_axis_name:m,y_axis_name:p},b)},[i,o]),l=k.useForm({initialValues:a}),s=()=>l.addListItem("series",{type:"bar",name:A.randomId(),showSymbol:!1,y_axis_data_key:"value",y_axis_data_formatter:"",label_position:"top",stack:"",color:"#000"}),d=u.default.useMemo(()=>!_.default.isEqual(l.values,a),[l.values,a]);return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:l.onSubmit(r),children:[c(t.Group,{position:"apart",mb:"lg",sx:{position:"relative"},children:[e(t.Text,{children:"Chart Config"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!d,children:e(v.DeviceFloppy,{size:20})})]}),e(t.TextInput,h({size:"md",mb:"lg",label:"X Axis Data Key"},l.getInputProps("x_axis_data_key"))),c(t.Group,{direction:"column",grow:!0,noWrap:!0,mb:"lg",children:[e(t.TextInput,h({size:"md",label:"X Axis Name"},l.getInputProps("x_axis_name"))),e(t.TextInput,h({size:"md",label:"Y Axis Name"},l.getInputProps("y_axis_name")))]}),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{mt:"xl",mb:0,children:"Series"}),l.values.series.map((m,p)=>c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[c(t.Group,{direction:"row",grow:!0,noWrap:!0,children:[e(t.TextInput,h({label:"Name",required:!0,sx:{flex:1}},l.getListInputProps("series",p,"name"))),e(t.TextInput,h({label:"Stack",placeholder:"Stack bars by this ID"},l.getListInputProps("series",p,"stack"))),e(t.TextInput,h({label:"Value key",required:!0},l.getListInputProps("series",p,"y_axis_data_key")))]}),c(t.Group,{direction:"row",grow:!0,noWrap:!0,align:"top",children:[e(t.Select,h({label:"Label Position",data:xt},l.getListInputProps("series",p,"label_position"))),e(t.JsonInput,h({sx:{label:{width:"100%"}},label:c(t.Group,{position:"apart",children:[e(t.Text,{children:"Value Formatter"}),e(t.Anchor,{href:"https://numbrojs.com/format.html",target:"_blank",children:"Formats"})]}),placeholder:ft,minRows:4,maxRows:12,autosize:!0},l.getListInputProps("series",p,"y_axis_data_formatter")))]}),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{children:"Color"}),e(ve,h({},l.getListInputProps("series",p,"color")))]}),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>l.removeListItem("series",p),sx:{position:"absolute",top:15,right:5},children:e(v.Trash,{size:16})})]},p)),e(t.Group,{position:"center",mt:"xs",children:e(t.Button,{onClick:s,children:"Add a Series"})})]})]})})}function St({conf:{label_field:n,value_field:r},setConf:i}){const o=k.useForm({initialValues:{label_field:n,value_field:r}});return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:o.onSubmit(i),children:[c(t.Group,{position:"apart",mb:"lg",sx:{position:"relative"},children:[e(t.Text,{children:"Sunburst Config"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",children:e(v.DeviceFloppy,{size:20})})]}),c(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,p:"md",mb:"sm",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[e(t.TextInput,h({label:"Label Field",required:!0,sx:{flex:1}},o.getInputProps("label_field"))),e(t.TextInput,h({label:"Value Field",placeholder:"get column value by this field",required:!0,sx:{flex:1}},o.getInputProps("value_field")))]})]})})}const vt=Object.values($).map(n=>({label:n,value:n}));function yt({label:n,value:r,onChange:i,sx:o}){return e(t.Select,{label:n,data:vt,value:r,onChange:i,sx:o})}function wt(o){var a=o,{conf:l}=a,s=l,{columns:n}=s,r=I(s,["columns"]),{setConf:i}=a;const d=k.useForm({initialValues:h({id_field:"id",use_raw_columns:!0,columns:k.formList(n!=null?n:[]),size:"sm",horizontalSpacing:"sm",verticalSpacing:"sm",striped:!1,highlightOnHover:!1},r)}),x=()=>d.addListItem("columns",{label:A.randomId(),value_field:"value",value_type:$.string});return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:d.onSubmit(i),children:[c(t.Group,{position:"apart",mb:"lg",sx:{position:"relative"},children:[e(t.Text,{children:"Table Config"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",children:e(v.DeviceFloppy,{size:20})})]}),c(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,p:"md",mb:"sm",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[e(t.TextInput,h({size:"md",mb:"lg",label:"ID Field"},d.getInputProps("id_field"))),c(t.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:[e(t.TextInput,h({label:"Horizontal Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1}},d.getInputProps("horizontalSpacing"))),e(t.TextInput,h({label:"Vertical Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1}},d.getInputProps("verticalSpacing")))]}),e(t.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:e(t.TextInput,h({label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1}},d.getInputProps("size")))}),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{children:"Other"}),c(t.Group,{position:"apart",grow:!0,children:[e(t.Switch,h({label:"Striped"},d.getInputProps("striped",{type:"checkbox"}))),e(t.Switch,h({label:"Highlight on hover"},d.getInputProps("highlightOnHover",{type:"checkbox"})))]})]})]}),c(t.Group,{direction:"column",mt:"xs",spacing:"xs",grow:!0,p:"md",mb:"xl",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[e(t.Switch,h({label:"Use Original Data Columns"},d.getInputProps("use_raw_columns",{type:"checkbox"}))),!d.values.use_raw_columns&&c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{mt:"xl",mb:0,children:"Custom Columns"}),d.values.columns.map((m,p)=>c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[c(t.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:[e(t.TextInput,h({label:"Label",required:!0,sx:{flex:1}},d.getListInputProps("columns",p,"label"))),e(t.TextInput,h({label:"Value Field",placeholder:"get column value by this field",required:!0,sx:{flex:1}},d.getListInputProps("columns",p,"value_field"))),e(yt,h({label:"Value Type",sx:{flex:1}},d.getListInputProps("columns",p,"value_type")))]}),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>d.removeListItem("columns",p),sx:{position:"absolute",top:15,right:5},children:e(v.Trash,{size:16})})]},p)),e(t.Group,{position:"center",mt:"xs",children:e(t.Button,{onClick:x,children:"Add a Column"})})]})]}),e(t.Text,{weight:500,mb:"md",children:"Current Configuration:"}),e(B.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(d.values,null,2)})]})})}const Y=[{label:"initial",value:0},{label:"500",value:25},{label:"700",value:50},{label:"semibold",value:75},{label:"bold",value:100}];function Ct({label:n,value:r,onChange:i}){var l,s;const[o,a]=u.default.useState((s=(l=Y.find(d=>d.label===r))==null?void 0:l.value)!=null?s:Y[0].value);return u.default.useEffect(()=>{const d=Y.find(x=>x.value===o);d&&i(d.label)},[o]),c(t.Group,{direction:"column",grow:!0,spacing:"xs",mb:"lg",children:[e(t.Text,{children:n}),e(t.Slider,{label:null,marks:Y,value:o,onChange:a,step:25,placeholder:"Pick a font size"})]})}const ye=[{align:"center",size:"xl",weight:"bold",color:"black",template:"Time: ${new Date().toISOString()}"},{align:"center",size:"md",weight:"bold",color:"red",template:"Platform: ${navigator.userAgentData.platform}."}];function Tt({conf:n,setConf:r}){var a;const i=k.useForm({initialValues:{paragraphs:k.formList((a=n.paragraphs)!=null?a:ye)}}),o=()=>i.addListItem("paragraphs",O(h({},ye[0]),{template:A.randomId()}));return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:i.onSubmit(r),children:[i.values.paragraphs.length===0&&e(t.Text,{color:"dimmed",align:"center",children:"Empty"}),c(t.Group,{position:"apart",mb:"xs",sx:{" + .mantine-Group-root":{marginTop:0}},children:[e(t.Text,{children:"Paragraphs"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",children:e(v.DeviceFloppy,{size:20})})]}),i.values.paragraphs.map((l,s)=>c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[e(t.TextInput,h({placeholder:"Time: ${new Date().toISOString()}",label:"Content Template",required:!0,sx:{flex:1}},i.getListInputProps("paragraphs",s,"template"))),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{children:"Color"}),e(ve,h({},i.getListInputProps("paragraphs",s,"color")))]}),e(t.Group,{direction:"column",grow:!0,children:e(t.TextInput,h({label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",sx:{flex:1}},i.getListInputProps("paragraphs",s,"size")))}),e(t.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:e(Ct,h({label:"Font Weight"},i.getListInputProps("paragraphs",s,"weight")))}),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>i.removeListItem("paragraphs",s),sx:{position:"absolute",top:15,right:5},children:e(v.Trash,{size:16})})]},s)),e(t.Group,{position:"center",mt:"md",children:e(t.Button,{onClick:o,children:"Add a Paragraph"})}),e(t.Text,{size:"sm",weight:500,mt:"md",children:"Current Configuration:"}),e(B.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(i.values,null,2)})]})})}const le=[{value:"text",label:"Text",Panel:Tt},{value:"table",label:"Table",Panel:wt},{value:"sunburst",label:"Sunburst",Panel:St},{value:"bar-3d",label:"Bar Chart (3D)",Panel:mt},{value:"line-bar",label:"Line-Bar Chart",Panel:bt}];function _t(){const{viz:n,setViz:r}=u.default.useContext(P),[i,o]=A.useInputState(n.type),a=n.type!==i,l=u.default.useCallback(()=>{!a||r(m=>O(h({},m),{type:i}))},[a,i]),s=m=>{r(p=>O(h({},p),{conf:m}))},d=m=>{try{s(JSON.parse(m))}catch(p){console.error(p)}},x=u.default.useMemo(()=>{var m;return(m=le.find(p=>p.value===i))==null?void 0:m.Panel},[i,le]);return c(oe,{children:[e(t.Select,{label:"Visualization",value:i,onChange:o,data:le,rightSection:e(t.ActionIcon,{disabled:!a,onClick:l,children:e(v.DeviceFloppy,{size:20})})}),x&&e(x,{conf:n.conf,setConf:s}),!x&&e(t.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(n.conf,null,2),onChange:d})]})}function Gt({}){return c(t.Group,{direction:"row",grow:!0,noWrap:!0,align:"stretch",sx:{height:"100%"},children:[e(t.Group,{grow:!0,direction:"column",noWrap:!0,sx:{width:"40%",flexShrink:0,flexGrow:0},children:e(_t,{})}),e(t.Box,{sx:{height:"100%",flexGrow:1,maxWidth:"60%"},children:e(ht,{})})]})}function Dt({opened:n,close:r}){const{freezeLayout:i}=u.default.useContext(F),{data:o,loading:a,viz:l,title:s}=u.default.useContext(P);return u.default.useEffect(()=>{i(n)},[n]),e(t.Modal,{size:"96vw",overflow:"inside",opened:n,onClose:r,title:s,trapFocus:!0,onDragStart:d=>{d.stopPropagation()},children:e(t.AppShell,{sx:{height:"90vh",maxHeight:"calc(100vh - 185px)",".mantine-AppShell-body":{height:"100%"},main:{height:"100%",width:"100%"}},padding:"md",children:c(t.Tabs,{initialTab:2,children:[c(t.Tabs.Tab,{label:"Data Source",children:[e(t.LoadingOverlay,{visible:a}),e(Xe,{})]}),e(t.Tabs.Tab,{label:"Panel",children:e(He,{})}),e(t.Tabs.Tab,{label:"Visualization",children:e(Gt,{})})]})})})}function zt({}){const[n,r]=u.default.useState(!1),i=()=>r(!0),o=()=>r(!1),{title:a,refreshData:l}=u.default.useContext(P),{inEditMode:s}=u.default.useContext(F);return c(t.Group,{position:"apart",noWrap:!0,sx:{borderBottom:"1px solid #eee",paddingBottom:"5px"},children:[e(t.Group,{children:e(ge,{})}),e(t.Group,{grow:!0,position:"center",children:e(t.Text,{lineClamp:1,weight:"bold",children:a})}),e(t.Group,{position:"right",spacing:0,sx:{height:"28px"},children:c(t.Menu,{children:[e(t.Menu.Item,{onClick:l,icon:e(v.Refresh,{size:14}),children:"Refresh"}),s&&e(t.Menu.Item,{onClick:i,icon:e(v.Settings,{size:14}),children:"Settings"}),e(t.Divider,{}),e(t.Menu.Item,{color:"red",disabled:!0,icon:e(v.Trash,{size:14}),children:"Delete"})]})}),s&&e(Dt,{opened:n,close:o})]})}var Ht="";function se({viz:n,dataSourceID:r,title:i,description:o,update:a,layout:l,id:s}){const d=u.default.useContext(V),x=u.default.useContext(E),[m,p]=u.default.useState(i),[b,g]=u.default.useState(o),[S,y]=u.default.useState(r),[T,D]=u.default.useState(n),L=u.default.useMemo(()=>{if(!!S)return x.dataSources.find(J=>J.id===S)},[S,x.dataSources]);u.default.useEffect(()=>{a==null||a({id:s,layout:l,title:m,description:b,dataSourceID:S,viz:T})},[m,b,L,T,s,l,S]);const{data:z=[],loading:H,refresh:ue}=ee.useRequest(me({context:d,definitions:x,title:m,dataSource:L}),{refreshDeps:[d,x,L]}),de=ue;return e(P.Provider,{value:{data:z,loading:H,title:m,setTitle:p,description:b,setDescription:g,dataSourceID:S,setDataSourceID:y,viz:T,setViz:D,refreshData:de},children:c(t.Container,{className:"panel-root",children:[e(zt,{}),e(ae,{children:e(Se,{viz:T,data:z,loading:H})})]})})}var Xt="";const It=G.WidthProvider(G.Responsive);function we({panels:n,setPanels:r,className:i="layout",cols:o={lg:12,md:10,sm:8,xs:6,xxs:4},rowHeight:a=10,onRemoveItem:l,isDraggable:s,isResizable:d,setLocalCols:x,setBreakpoint:m}){const p=(g,S)=>{m(g),x(S)},b=u.default.useCallback(g=>{const S=new Map;g.forEach(L=>{var z=L,{i:T}=z,D=I(z,["i"]);S.set(T,D)});const y=n.map(T=>O(h({},T),{layout:S.get(T.id)}));r(y)},[n,r]);return e(It,{onBreakpointChange:p,onLayoutChange:b,className:i,cols:o,rowHeight:a,isDraggable:s,isResizable:d,children:n.map((T,y)=>{var D=T,{id:g}=D,S=I(D,["id"]);return e("div",{"data-grid":S.layout,children:e(se,O(h({id:g},S),{destroy:()=>l(g),update:L=>{r(z=>(z.splice(y,1,L),[...z]))}}))},g)})})}function Ce(n,r){return c(t.Text,{sx:{svg:{verticalAlign:"text-bottom"}},children:[n," ",r]})}function Pt({mode:n,setMode:r}){return e(t.SegmentedControl,{value:n,onChange:r,data:[{label:Ce(e(v.PlayerPlay,{size:20}),"Use"),value:q.Use},{label:Ce(e(v.Paint,{size:20}),"Edit"),value:q.Edit}]})}const Lt=`
|
|
9
|
+
*/var Ve=u.default,Ne=Symbol.for("react.element"),je=Symbol.for("react.fragment"),We=Object.prototype.hasOwnProperty,Qe=Ve.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Je={key:!0,ref:!0,__self:!0,__source:!0};function xe(n,i,r){var o,a={},l=null,s=null;r!==void 0&&(l=""+r),i.key!==void 0&&(l=""+i.key),i.ref!==void 0&&(s=i.ref);for(o in i)We.call(i,o)&&!Je.hasOwnProperty(o)&&(a[o]=i[o]);if(n&&n.defaultProps)for(o in i=n.defaultProps,i)a[o]===void 0&&(a[o]=i[o]);return{$$typeof:Ne,type:n,key:l,ref:s,props:a,_owner:Qe.current}}X.Fragment=je,X.jsx=xe,X.jsxs=xe,Y.exports=X;const e=Y.exports.jsx,c=Y.exports.jsxs,oe=Y.exports.Fragment;function ge({position:n,trigger:i="click"}){const{freezeLayout:r}=u.default.useContext(R),[o,a]=u.default.useState(!1),{description:l}=u.default.useContext(L);if(u.default.useEffect(()=>{r(o)},[o]),!l)return null;const s=i==="click"?e(t.Tooltip,{label:"Click to see description",openDelay:500,children:e(v.InfoCircle,{size:20,onClick:()=>a(d=>!d),style:{verticalAlign:"baseline",cursor:"pointer"}})}):e(v.InfoCircle,{size:20,onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),style:{verticalAlign:"baseline",cursor:"pointer"}});return e(t.Popover,{opened:o,onClose:()=>a(!1),withCloseButton:!0,withArrow:!0,trapFocus:!0,closeOnEscape:!1,placement:"center",position:n,target:s,children:e(Ee.default,{readOnly:!0,value:l,onChange:T.default.noop,sx:{border:"none"}})})}function Ue(){const{description:n,setDescription:i}=u.default.useContext(L),[r,o]=u.default.useState(n),a=n!==r,l=u.default.useCallback(()=>{!a||i(r)},[a,r]);return c(t.Group,{direction:"column",sx:{flexGrow:1},children:[c(t.Group,{align:"end",children:[e(t.Text,{children:"Description"}),e(t.ActionIcon,{variant:"hover",color:"blue",disabled:!a,onClick:l,children:e(v.DeviceFloppy,{size:20})})]}),e(ce.RichTextEditor,{value:r,onChange:o,sx:{flexGrow:1},sticky:!0,p:"0"})]})}class ae extends u.default.Component{constructor(i){super(i),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}render(){return this.state.hasError?e("h1",{children:"Something went wrong."}):this.props.children}}function He(){const{title:n}=u.default.useContext(L);return e(ae,{children:c(t.Group,{direction:"column",grow:!0,noWrap:!0,mx:"auto",mt:"xl",p:"5px",spacing:"xs",sx:{width:"600px",height:"450px",background:"transparent",borderRadius:"5px",boxShadow:"0px 0px 10px 0px rgba(0,0,0,.2)"},children:[c(t.Group,{position:"apart",noWrap:!0,sx:{borderBottom:"1px solid #eee",paddingBottom:"5px",flexGrow:0,flexShrink:0},children:[e(t.Group,{children:e(ge,{position:"bottom",trigger:"hover"})}),e(t.Group,{grow:!0,position:"center",children:e(t.Text,{lineClamp:1,weight:"bold",children:n})}),e(t.Group,{position:"right",spacing:0,sx:{height:"28px"}})]}),e(t.Group,{sx:{background:"#eee",flexGrow:1}})]})})}function Ke(){const{title:n,setTitle:i}=u.default.useContext(L),[r,o]=A.useInputState(n),a=n!==r,l=u.default.useCallback(()=>{!a||i(r)},[a,r]);return e(t.TextInput,{value:r,onChange:o,label:c(t.Group,{align:"end",children:[e(t.Text,{children:"Panel Title"}),e(t.ActionIcon,{variant:"hover",color:"blue",disabled:!a,onClick:l,children:e(v.DeviceFloppy,{size:20})})]})})}function Ye({}){return c(t.Group,{direction:"row",grow:!0,noWrap:!0,align:"stretch",sx:{height:"100%"},children:[c(t.Group,{grow:!0,direction:"column",sx:{width:"40%",flexShrink:0,flexGrow:0,height:"100%"},children:[e(Ke,{}),e(Ue,{})]}),e(t.Box,{sx:{height:"100%",flexGrow:1,maxWidth:"60%"},children:e(He,{})})]})}function be({id:n}){const i=u.default.useContext(E),r=u.default.useContext(W),o=u.default.useMemo(()=>i.dataSources.find(d=>d.id===n),[i.dataSources,n]),{data:a=[],loading:l,refresh:s}=ie.useRequest(he({context:r,definitions:i,title:n,dataSource:o}),{refreshDeps:[r,i,o]});return l?e(t.LoadingOverlay,{visible:l}):a.length===0?e(t.Table,{}):c(t.Group,{my:"xl",direction:"column",grow:!0,sx:{border:"1px solid #eee"},children:[c(t.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[c(t.Group,{position:"left",children:[e(t.Text,{weight:500,children:"Preview Data"}),a.length>10&&c(t.Text,{size:"sm",color:"gray",children:["Showing 10 rows of ",a.length]})]}),e(t.ActionIcon,{mr:15,variant:"hover",color:"blue",disabled:l,onClick:s,children:e(v.Refresh,{size:15})})]}),c(t.Table,{children:[e("thead",{children:e("tr",{children:Object.keys(a==null?void 0:a[0]).map(d=>e("th",{children:e(t.Text,{weight:700,color:"#000",children:d})},d))})}),e("tbody",{children:a.slice(0,10).map((d,f)=>e("tr",{children:Object.values(d).map((h,p)=>e("td",{children:e(t.Group,{sx:{"&, .mantine-Text-root":{fontFamily:"monospace"}},children:e(t.Text,{children:h})})},`${h}--${p}`))},`row-${f}`))})]})]})}function Xe({}){const{dataSources:n}=u.default.useContext(E),{dataSourceID:i,setDataSourceID:r,data:o,loading:a}=u.default.useContext(L),l=u.default.useMemo(()=>n.map(s=>({value:s.id,label:s.id})),[n]);return c(t.Group,{direction:"column",grow:!0,noWrap:!0,children:[c(t.Group,{position:"left",sx:{maxWidth:"600px",alignItems:"baseline"},children:[e(t.Text,{children:"Select a Data Source"}),e(t.Select,{data:l,value:i,onChange:r,allowDeselect:!1,clearable:!1,sx:{flexGrow:1}})]}),e(be,{id:i})]})}F.use([U.SunburstChart,H.CanvasRenderer]);const Ze={tooltip:{show:!0},series:{type:"sunburst",radius:[0,"90%"],emphasis:{focus:"ancestor"}}};function et({conf:n,data:i,width:r,height:o}){const b=n,{label_field:a="name",value_field:l="value"}=b,s=P(b,["label_field","value_field"]),d=u.default.useMemo(()=>i.map(g=>({name:g[a],value:Number(g[l])})),[i,a,l]),f=u.default.useMemo(()=>{var g,S;return(S=(g=T.default.maxBy(d,y=>y.value))==null?void 0:g.value)!=null?S:1},[d]),h=u.default.useMemo(()=>({series:{label:{formatter:({name:g,value:S})=>S/f<.2?" ":g}}}),[f]),p=T.default.merge({},Ze,h,s,{series:{data:d}});return e(K.default,{echarts:F,option:p,style:{width:r,height:o}})}F.use([U.BarChart,U.LineChart,N.GridComponent,N.LegendComponent,N.TooltipComponent,H.CanvasRenderer]);const tt={legend:{show:!0,bottom:0,left:0},tooltip:{trigger:"axis"},xAxis:{type:"category",nameGap:25,nameLocation:"center",nameTextStyle:{fontWeight:"bold"}},yAxis:{nameTextStyle:{fontWeight:"bolder",align:"left"}},grid:{top:30,left:15,right:15,bottom:30,containLabel:!0}};function nt({conf:n,data:i,width:r,height:o}){const a=u.default.useMemo(()=>{var f,h;const l=n.series.reduce((p,{name:b,y_axis_data_formatter:g})=>(p[b]=function({value:y}){if(!g)return y;try{return re.default(y).format(JSON.parse(g))}catch(_){return console.error(_),y}},p),{}),s=n.series.map(_=>{var D=_,{y_axis_data_key:p,y_axis_data_formatter:b,name:g,label_position:S="top"}=D,y=P(D,["y_axis_data_key","y_axis_data_formatter","name","label_position"]);const k=m({data:i.map(I=>I[p]),label:{show:!0,position:S},name:g},y);return b&&(k.label.formatter=l[g]),k}),d={xAxis:{data:i.map(p=>p[n.x_axis_data_key]),name:(f=n.x_axis_name)!=null?f:""},yAxis:{name:(h=n.y_axis_name)!=null?h:""},dataset:{source:i},series:s,tooltip:{formatter:function(p){const b=Array.isArray(p)?p:[p];if(b.length===0)return"";const g=b.map(({seriesName:S,value:y})=>S?`${S}: ${l[S]({value:y})}`:y);return g.unshift(`<strong>${b[0].name}</strong>`),g.join("<br />")}}};return T.default.merge({},tt,d)},[n,i]);return!r||!o?null:e(K.default,{echarts:F,option:a,style:{width:r,height:o}})}var $=(n=>(n.string="string",n.number="number",n.eloc="eloc",n.percentage="percentage",n))($||{});function it({value:n}){return e(t.Text,{component:"span",children:n})}function rt({value:n}){return e(t.Text,{component:"span",children:n})}function ot({value:n}){const i=re.default(n).format({thousandSeparated:!0});return e(t.Text,{component:"span",children:i})}function at({value:n}){const i=re.default(n).format({output:"percent",mantissa:3});return e(t.Text,{component:"span",children:i})}function lt({value:n,type:i}){switch(i){case $.string:return e(it,{value:n});case $.eloc:return e(rt,{value:n});case $.number:return e(ot,{value:n});case $.percentage:return e(at,{value:n})}}function st({conf:n,data:i,width:r,height:o}){const p=n,{id_field:a,use_raw_columns:l,columns:s}=p,d=P(p,["id_field","use_raw_columns","columns"]),f=u.default.useMemo(()=>l?Object.keys(i==null?void 0:i[0]):s.map(b=>b.label),[l,s,i]),h=u.default.useMemo(()=>l?Object.keys(i==null?void 0:i[0]).map(b=>({label:b,value_field:b,value_type:$.string})):s,[l,s,i]);return c(t.Table,O(m({sx:{maxHeight:o}},d),{children:[e("thead",{children:e("tr",{children:f.map(b=>e("th",{children:b},b))})}),e("tbody",{children:i.map((b,g)=>e("tr",{children:h.map(({value_field:S,value_type:y})=>e("td",{children:e(t.Group,{sx:{"&, .mantine-Text-root":{fontFamily:"monospace"}},children:e(lt,{value:b[S],type:y})})},b[S]))},a?b[a]:`row-${g}`))})]}))}function ut(n,i={}){const r=Object.keys(i),o=Object.values(i);try{return new Function(...r,`return \`${n}\`;`)(...o)}catch(a){return a.message}}function dt({conf:{paragraphs:n},data:i}){return e(oe,{children:n.map((s,l)=>{var d=s,{template:r,size:o}=d,a=P(d,["template","size"]);return e(t.Text,O(m({},a),{sx:{fontSize:o},children:ut(r,i[0])}),`${r}---${l}`)})})}F.use([N.GridComponent,N.VisualMapComponent,N.LegendComponent,N.TooltipComponent,H.CanvasRenderer]);function ct({conf:n,data:i,width:r,height:o}){const b=n,{x_axis_data_key:a,y_axis_data_key:l,z_axis_data_key:s}=b,d=P(b,["x_axis_data_key","y_axis_data_key","z_axis_data_key"]),f=u.default.useMemo(()=>T.default.minBy(i,g=>g[s])[s],[i,s]),h=u.default.useMemo(()=>T.default.maxBy(i,g=>g[s])[s],[i,s]),p=O(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}}}},d),{series:[{type:"bar3D",wireframe:{},data:i.map(g=>[g[a],g[l],g[s]])}]});return e(K.default,{echarts:F,option:p,style:{width:r,height:o}})}var Zt="";F.use([U.PieChart,H.CanvasRenderer]);const pt={tooltip:{show:!0},series:{type:"pie",radius:["50%","80%"],label:{position:"outer",alignTo:"edge",formatter:`{name|{b}}
|
|
10
|
+
{percentage|{d}%}`,minMargin:5,edgeDistance:10,lineHeight:15,rich:{percentage:{color:"#999"}},margin:20},labelLine:{length:15,length2:0,maxSurfaceAngle:80,showAbove:!0},top:10,bottom:10,left:10,right:10}};function mt({conf:n,data:i,width:r,height:o}){const p=n,{label_field:a="name",value_field:l="value"}=p,s=P(p,["label_field","value_field"]),d=u.default.useMemo(()=>i.map(b=>({name:b[a],value:Number(b[l])})),[i,a,l]),f=u.default.useMemo(()=>({series:{labelLayout:function(b){const g=b.labelRect.x<r/2,S=b.labelLinePoints;return S[2][0]=g?b.labelRect.x:b.labelRect.x+b.labelRect.width,{labelLinePoints:S}}}}),[r]),h=T.default.merge({},pt,f,s,{series:{data:d}});return e(K.default,{echarts:F,option:h,style:{width:r,height:o}})}function ht(n,i,r,o){const a={width:n,height:i,data:r,conf:o.conf};switch(o.type){case"sunburst":return e(et,m({},a));case"line-bar":return e(nt,m({},a));case"table":return e(st,m({},a));case"text":return e(dt,m({},a));case"bar-3d":return e(ct,m({},a));case"pie":return e(mt,m({},a));default:return null}}function Se({viz:n,data:i,loading:r}){const{ref:o,width:a,height:l}=A.useElementSize(),s=u.default.useMemo(()=>!Array.isArray(i)||i.length===0,[i]);return r?e("div",{className:"viz-root",ref:o,children:e(t.LoadingOverlay,{visible:r})}):c("div",{className:"viz-root",ref:o,children:[s&&e(t.Text,{color:"gray",align:"center",children:"nothing to show"}),!s&&ht(a,l,i,n)]})}function ft({}){const{data:n,loading:i,viz:r}=u.default.useContext(L);return e(ae,{children:e(Se,{viz:r,data:n,loading:i})})}function xt({conf:n,setConf:i}){const r=T.default.assign({},{x_axis_data_key:"x",y_axis_data_key:"y",z_axis_data_key:"z",xAxis3D:{type:"value",name:"X Axis Name"},yAxis3D:{type:"value",name:"Y Axis Name"},zAxis3D:{type:"value",name:"Z Axis Name"}},n),{control:o,handleSubmit:a,formState:l}=j.useForm({defaultValues:r});return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:a(i),children:[e(t.Text,{children:"X Axis"}),c(t.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[e(j.Controller,{name:"x_axis_data_key",control:o,render:({field:s})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Data Key"},s))}),e(j.Controller,{name:"xAxis3D.name",control:o,render:({field:s})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Name"},s))})]}),e(t.Text,{mt:"lg",children:"Y Axis"}),c(t.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[e(j.Controller,{name:"y_axis_data_key",control:o,render:({field:s})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Data Key"},s))}),e(j.Controller,{name:"yAxis3D.name",control:o,render:({field:s})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Name"},s))})]}),e(t.Text,{mt:"lg",children:"Z Axis"}),c(t.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[e(j.Controller,{name:"z_axis_data_key",control:o,render:({field:s})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Data Key"},s))}),e(j.Controller,{name:"zAxis3D.name",control:o,render:({field:s})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Name"},s))})]}),e(t.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:c(t.Button,{color:"blue",type:"submit",children:[e(v.DeviceFloppy,{size:20}),e(t.Text,{ml:"md",children:"Save"})]})})]})})}function ve({value:n,onChange:i}){const r=t.useMantineTheme(),o=u.default.useMemo(()=>Object.entries(r.colors).map(([l,s])=>({label:l,value:s[6]})),[r]),a=u.default.useMemo(()=>o.some(l=>l.value===n),[n,o]);return c(t.Group,{position:"apart",spacing:"xs",children:[e(t.TextInput,{placeholder:"Set any color",value:a?"":n,onChange:l=>i(l.currentTarget.value),rightSection:e(t.ColorSwatch,{color:a?"transparent":n,radius:4}),variant:a?"filled":"default",sx:{maxWidth:"100%",flexGrow:1}}),e(t.Text,{sx:{flexGrow:0},children:"or"}),e(t.Select,{data:o,value:n,onChange:i,variant:a?"default":"filled",placeholder:"Pick a theme color",icon:e(t.ColorSwatch,{color:a?n:"transparent",radius:4}),sx:{maxWidth:"100%",flexGrow:1}})]})}const gt=JSON.stringify({output:"percent",mantissa:2},null,2),bt=[{label:"top",value:"top"},{label:"left",value:"left"},{label:"right",value:"right"},{label:"bottom",value:"bottom"},{label:"inside",value:"inside"},{label:"insideLeft",value:"insideLeft"},{label:"insideRight",value:"insideRight"},{label:"insideTop",value:"insideTop"},{label:"insideBottom",value:"insideBottom"},{label:"insideTopLeft",value:"insideTopLeft"},{label:"insideBottomLeft",value:"insideBottomLeft"},{label:"insideTopRight",value:"insideTopRight"},{label:"insideBottomRight",value:"insideBottomRight"}];function St(n){function i({type:r,name:o,showSymbol:a,y_axis_data_key:l="value",y_axis_data_formatter:s="",label_position:d="top",stack:f="1",color:h="black"}){return{type:r,name:o,showSymbol:a,y_axis_data_key:l,y_axis_data_formatter:s,label_position:d,stack:f,color:h}}return n.map(i)}function vt({conf:n,setConf:i}){const f=n,{series:r}=f,o=P(f,["series"]),a=u.default.useMemo(()=>{const g=o,{x_axis_name:h="",y_axis_name:p=""}=g,b=P(g,["x_axis_name","y_axis_name"]);return m({series:z.formList(St(r!=null?r:[])),x_axis_name:h,y_axis_name:p},b)},[r,o]),l=z.useForm({initialValues:a}),s=()=>l.addListItem("series",{type:"bar",name:A.randomId(),showSymbol:!1,y_axis_data_key:"value",y_axis_data_formatter:"",label_position:"top",stack:"",color:"#000"}),d=u.default.useMemo(()=>!T.default.isEqual(l.values,a),[l.values,a]);return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:l.onSubmit(i),children:[c(t.Group,{position:"apart",mb:"lg",sx:{position:"relative"},children:[e(t.Text,{children:"Chart Config"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!d,children:e(v.DeviceFloppy,{size:20})})]}),e(t.TextInput,m({size:"md",mb:"lg",label:"X Axis Data Key"},l.getInputProps("x_axis_data_key"))),c(t.Group,{direction:"column",grow:!0,noWrap:!0,mb:"lg",children:[e(t.TextInput,m({size:"md",label:"X Axis Name"},l.getInputProps("x_axis_name"))),e(t.TextInput,m({size:"md",label:"Y Axis Name"},l.getInputProps("y_axis_name")))]}),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{mt:"xl",mb:0,children:"Series"}),l.values.series.map((h,p)=>c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[c(t.Group,{direction:"row",grow:!0,noWrap:!0,children:[e(t.TextInput,m({label:"Name",required:!0,sx:{flex:1}},l.getListInputProps("series",p,"name"))),e(t.TextInput,m({label:"Stack",placeholder:"Stack bars by this ID"},l.getListInputProps("series",p,"stack"))),e(t.TextInput,m({label:"Value key",required:!0},l.getListInputProps("series",p,"y_axis_data_key")))]}),c(t.Group,{direction:"row",grow:!0,noWrap:!0,align:"top",children:[e(t.Select,m({label:"Label Position",data:bt},l.getListInputProps("series",p,"label_position"))),e(t.JsonInput,m({sx:{label:{width:"100%"}},label:c(t.Group,{position:"apart",children:[e(t.Text,{children:"Value Formatter"}),e(t.Anchor,{href:"https://numbrojs.com/format.html",target:"_blank",children:"Formats"})]}),placeholder:gt,minRows:4,maxRows:12,autosize:!0},l.getListInputProps("series",p,"y_axis_data_formatter")))]}),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{children:"Color"}),e(ve,m({},l.getListInputProps("series",p,"color")))]}),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>l.removeListItem("series",p),sx:{position:"absolute",top:15,right:5},children:e(v.Trash,{size:16})})]},p)),e(t.Group,{position:"center",mt:"xs",children:e(t.Button,{onClick:s,children:"Add a Series"})})]})]})})}function yt({conf:{label_field:n,value_field:i},setConf:r}){const o=z.useForm({initialValues:{label_field:n,value_field:i}});return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:o.onSubmit(r),children:[c(t.Group,{position:"apart",mb:"lg",sx:{position:"relative"},children:[e(t.Text,{children:"Pie Config"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",children:e(v.DeviceFloppy,{size:20})})]}),c(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,p:"md",mb:"sm",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[e(t.TextInput,m({label:"Label Field",required:!0,sx:{flex:1}},o.getInputProps("label_field"))),e(t.TextInput,m({label:"Value Field",placeholder:"get column value by this field",required:!0,sx:{flex:1}},o.getInputProps("value_field")))]})]})})}function wt({conf:{label_field:n,value_field:i},setConf:r}){const o=z.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,m({label:"Label Field",required:!0,sx:{flex:1}},o.getInputProps("label_field"))),e(t.TextInput,m({label:"Value Field",placeholder:"get column value by this field",required:!0,sx:{flex:1}},o.getInputProps("value_field")))]})]})})}const Ct=Object.values($).map(n=>({label:n,value:n}));function Tt({label:n,value:i,onChange:r,sx:o}){return e(t.Select,{label:n,data:Ct,value:i,onChange:r,sx:o})}function _t(o){var a=o,{conf:l}=a,s=l,{columns:n}=s,i=P(s,["columns"]),{setConf:r}=a;const d=z.useForm({initialValues:m({id_field:"id",use_raw_columns:!0,columns:z.formList(n!=null?n:[]),size:"sm",horizontalSpacing:"sm",verticalSpacing:"sm",striped:!1,highlightOnHover:!1},i)}),f=()=>d.addListItem("columns",{label:A.randomId(),value_field:"value",value_type:$.string});return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:d.onSubmit(r),children:[c(t.Group,{position:"apart",mb:"lg",sx:{position:"relative"},children:[e(t.Text,{children:"Table Config"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",children:e(v.DeviceFloppy,{size:20})})]}),c(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,p:"md",mb:"sm",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[e(t.TextInput,m({size:"md",mb:"lg",label:"ID Field"},d.getInputProps("id_field"))),c(t.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:[e(t.TextInput,m({label:"Horizontal Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1}},d.getInputProps("horizontalSpacing"))),e(t.TextInput,m({label:"Vertical Spacing",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1}},d.getInputProps("verticalSpacing")))]}),e(t.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:e(t.TextInput,m({label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",required:!0,sx:{flex:1}},d.getInputProps("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((h,p)=>c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[c(t.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:[e(t.TextInput,m({label:"Label",required:!0,sx:{flex:1}},d.getListInputProps("columns",p,"label"))),e(t.TextInput,m({label:"Value Field",placeholder:"get column value by this field",required:!0,sx:{flex:1}},d.getListInputProps("columns",p,"value_field"))),e(Tt,m({label:"Value Type",sx:{flex:1}},d.getListInputProps("columns",p,"value_type")))]}),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>d.removeListItem("columns",p),sx:{position:"absolute",top:15,right:5},children:e(v.Trash,{size:16})})]},p)),e(t.Group,{position:"center",mt:"xs",children:e(t.Button,{onClick:f,children:"Add a Column"})})]})]}),e(t.Text,{weight:500,mb:"md",children:"Current Configuration:"}),e(B.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(d.values,null,2)})]})})}const Z=[{label:"initial",value:0},{label:"500",value:25},{label:"700",value:50},{label:"semibold",value:75},{label:"bold",value:100}];function Gt({label:n,value:i,onChange:r}){var l,s;const[o,a]=u.default.useState((s=(l=Z.find(d=>d.label===i))==null?void 0:l.value)!=null?s:Z[0].value);return u.default.useEffect(()=>{const d=Z.find(f=>f.value===o);d&&r(d.label)},[o]),c(t.Group,{direction:"column",grow:!0,spacing:"xs",mb:"lg",children:[e(t.Text,{children:n}),e(t.Slider,{label:null,marks:Z,value:o,onChange:a,step:25,placeholder:"Pick a font size"})]})}const ye=[{align:"center",size:"xl",weight:"bold",color:"black",template:"Time: ${new Date().toISOString()}"},{align:"center",size:"md",weight:"bold",color:"red",template:"Platform: ${navigator.userAgentData.platform}."}];function Dt({conf:n,setConf:i}){var a;const r=z.useForm({initialValues:{paragraphs:z.formList((a=n.paragraphs)!=null?a:ye)}}),o=()=>r.addListItem("paragraphs",O(m({},ye[0]),{template:A.randomId()}));return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:r.onSubmit(i),children:[r.values.paragraphs.length===0&&e(t.Text,{color:"dimmed",align:"center",children:"Empty"}),c(t.Group,{position:"apart",mb:"xs",sx:{" + .mantine-Group-root":{marginTop:0}},children:[e(t.Text,{children:"Paragraphs"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",children:e(v.DeviceFloppy,{size:20})})]}),r.values.paragraphs.map((l,s)=>c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[e(t.TextInput,m({placeholder:"Time: ${new Date().toISOString()}",label:"Content Template",required:!0,sx:{flex:1}},r.getListInputProps("paragraphs",s,"template"))),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{children:"Color"}),e(ve,m({},r.getListInputProps("paragraphs",s,"color")))]}),e(t.Group,{direction:"column",grow:!0,children:e(t.TextInput,m({label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",sx:{flex:1}},r.getListInputProps("paragraphs",s,"size")))}),e(t.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:e(Gt,m({label:"Font Weight"},r.getListInputProps("paragraphs",s,"weight")))}),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>r.removeListItem("paragraphs",s),sx:{position:"absolute",top:15,right:5},children:e(v.Trash,{size:16})})]},s)),e(t.Group,{position:"center",mt:"md",children:e(t.Button,{onClick:o,children:"Add a Paragraph"})}),e(t.Text,{size:"sm",weight:500,mt:"md",children:"Current Configuration:"}),e(B.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(r.values,null,2)})]})})}const le=[{value:"text",label:"Text",Panel:Dt},{value:"table",label:"Table",Panel:_t},{value:"sunburst",label:"Sunburst",Panel:wt},{value:"bar-3d",label:"Bar Chart (3D)",Panel:xt},{value:"line-bar",label:"Line-Bar Chart",Panel:vt},{value:"pie",label:"Pie Chart",Panel:yt}];function Pt(){const{viz:n,setViz:i}=u.default.useContext(L),[r,o]=A.useInputState(n.type),a=n.type!==r,l=u.default.useCallback(()=>{!a||i(h=>O(m({},h),{type:r}))},[a,r]),s=h=>{i(p=>O(m({},p),{conf:h}))},d=h=>{try{s(JSON.parse(h))}catch(p){console.error(p)}},f=u.default.useMemo(()=>{var h;return(h=le.find(p=>p.value===r))==null?void 0:h.Panel},[r,le]);return c(oe,{children:[e(t.Select,{label:"Visualization",value:r,onChange:o,data:le,rightSection:e(t.ActionIcon,{disabled:!a,onClick:l,children:e(v.DeviceFloppy,{size:20})})}),f&&e(f,{conf:n.conf,setConf:s}),!f&&e(t.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(n.conf,null,2),onChange:d})]})}function It({}){return c(t.Group,{direction:"row",grow:!0,noWrap:!0,align:"stretch",sx:{height:"100%"},children:[e(t.Group,{grow:!0,direction:"column",noWrap:!0,sx:{width:"40%",flexShrink:0,flexGrow:0},children:e(Pt,{})}),e(t.Box,{sx:{height:"100%",flexGrow:1,maxWidth:"60%"},children:e(ft,{})})]})}function zt({opened:n,close:i}){const{freezeLayout:r}=u.default.useContext(R),{data:o,loading:a,viz:l,title:s}=u.default.useContext(L);return u.default.useEffect(()=>{r(n)},[n]),e(t.Modal,{size:"96vw",overflow:"inside",opened:n,onClose:i,title:s,trapFocus:!0,onDragStart:d=>{d.stopPropagation()},children:e(t.AppShell,{sx:{height:"90vh",maxHeight:"calc(100vh - 185px)",".mantine-AppShell-body":{height:"100%"},main:{height:"100%",width:"100%"}},padding:"md",children:c(t.Tabs,{initialTab:2,children:[c(t.Tabs.Tab,{label:"Data Source",children:[e(t.LoadingOverlay,{visible:a}),e(Xe,{})]}),e(t.Tabs.Tab,{label:"Panel",children:e(Ye,{})}),e(t.Tabs.Tab,{label:"Visualization",children:e(It,{})})]})})})}function Lt({}){const[n,i]=u.default.useState(!1),r=()=>i(!0),o=()=>i(!1),{title:a,refreshData:l}=u.default.useContext(L),{inEditMode:s}=u.default.useContext(R);return c(t.Group,{position:"apart",noWrap:!0,sx:{borderBottom:"1px solid #eee",paddingBottom:"5px"},children:[e(t.Group,{children:e(ge,{})}),e(t.Group,{grow:!0,position:"center",children:e(t.Text,{lineClamp:1,weight:"bold",children:a})}),e(t.Group,{position:"right",spacing:0,sx:{height:"28px"},children:c(t.Menu,{children:[e(t.Menu.Item,{onClick:l,icon:e(v.Refresh,{size:14}),children:"Refresh"}),s&&e(t.Menu.Item,{onClick:r,icon:e(v.Settings,{size:14}),children:"Settings"}),e(t.Divider,{}),e(t.Menu.Item,{color:"red",disabled:!0,icon:e(v.Trash,{size:14}),children:"Delete"})]})}),s&&e(zt,{opened:n,close:o})]})}var en="";function se({viz:n,dataSourceID:i,title:r,description:o,update:a,layout:l,id:s}){const d=u.default.useContext(W),f=u.default.useContext(E),[h,p]=u.default.useState(r),[b,g]=u.default.useState(o),[S,y]=u.default.useState(i),[_,D]=u.default.useState(n),k=u.default.useMemo(()=>{if(!!S)return f.dataSources.find(J=>J.id===S)},[S,f.dataSources]);u.default.useEffect(()=>{a==null||a({id:s,layout:l,title:h,description:b,dataSourceID:S,viz:_})},[h,b,k,_,s,l,S]);const{data:I=[],loading:ee,refresh:ue}=ie.useRequest(he({context:d,definitions:f,title:h,dataSource:k}),{refreshDeps:[d,f,k]}),de=ue;return e(L.Provider,{value:{data:I,loading:ee,title:h,setTitle:p,description:b,setDescription:g,dataSourceID:S,setDataSourceID:y,viz:_,setViz:D,refreshData:de},children:c(t.Container,{className:"panel-root",children:[e(Lt,{}),e(ae,{children:e(Se,{viz:_,data:I,loading:ee})})]})})}var tn="";const kt=G.WidthProvider(G.Responsive);function we({panels:n,setPanels:i,className:r="layout",cols:o={lg:12,md:10,sm:8,xs:6,xxs:4},rowHeight:a=10,onRemoveItem:l,isDraggable:s,isResizable:d,setLocalCols:f,setBreakpoint:h}){const p=(g,S)=>{h(g),f(S)},b=u.default.useCallback(g=>{const S=new Map;g.forEach(k=>{var I=k,{i:_}=I,D=P(I,["i"]);S.set(_,D)});const y=n.map(_=>O(m({},_),{layout:S.get(_.id)}));i(y)},[n,i]);return e(kt,{onBreakpointChange:p,onLayoutChange:b,className:r,cols:o,rowHeight:a,isDraggable:s,isResizable:d,children:n.map((_,y)=>{var D=_,{id:g}=D,S=P(D,["id"]);return e("div",{"data-grid":S.layout,children:e(se,O(m({id:g},S),{destroy:()=>l(g),update:k=>{i(I=>(I.splice(y,1,k),[...I]))}}))},g)})})}function Ce(n,i){return c(t.Text,{sx:{svg:{verticalAlign:"text-bottom"}},children:[n," ",i]})}function Et({mode:n,setMode:i}){return e(t.SegmentedControl,{value:n,onChange:i,data:[{label:Ce(e(v.PlayerPlay,{size:20}),"Use"),value:q.Use},{label:Ce(e(v.Paint,{size:20}),"Edit"),value:q.Edit}]})}const Ot=`
|
|
10
11
|
-- You may reference context data or SQL snippets *by name*
|
|
11
12
|
-- in SQL or VizConfig.
|
|
12
13
|
SELECT *
|
|
@@ -17,16 +18,16 @@ WHERE
|
|
|
17
18
|
-- SQL snippets
|
|
18
19
|
AND \${author_email_condition}
|
|
19
20
|
\${order_by_clause}
|
|
20
|
-
`;function
|
|
21
|
+
`;function At({}){const n=u.default.useContext(W),{sqlSnippets:i}=u.default.useContext(E),r=u.default.useMemo(()=>{const a=i.reduce((l,s)=>(l[s.key]=s.value,l),{});return JSON.stringify(a,null,2)},[i]),o=u.default.useMemo(()=>JSON.stringify(n,null,2),[n]);return c(t.Group,{direction:"column",grow:!0,sx:{border:"1px solid #eee",maxWidth:"48%",overflow:"hidden"},children:[e(t.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:e(t.Text,{weight:500,children:"Context"})}),c(t.Group,{direction:"column",px:"md",pb:"md",sx:{width:"100%"},children:[e(B.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:Ot}),e(t.Text,{weight:500,sx:{flexGrow:0},children:"Avaiable context"}),e(B.Prism,{language:"json",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:o}),e(t.Text,{weight:500,sx:{flexGrow:0},children:"Avaiable SQL Snippets"}),e(B.Prism,{language:"json",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:r})]})]})}function qt({value:n,onChange:i}){const r=z.useForm({initialValues:n}),o=u.default.useCallback(h=>{i(h)},[i]),a=u.default.useMemo(()=>!T.default.isEqual(n,r.values),[n,r.values]);u.default.useEffect(()=>{r.reset()},[n]);const{data:l={},loading:s}=ie.useRequest(Be,{refreshDeps:[]},[]),d=u.default.useMemo(()=>Object.keys(l).map(h=>({label:h,value:h})),[l]),f=u.default.useMemo(()=>{const h=l[r.values.type];return h?h.map(p=>({label:p,value:p})):[]},[l,r.values.type]);return e(t.Group,{direction:"column",grow:!0,sx:{border:"1px solid #eee",flexGrow:1},children:c("form",{onSubmit:r.onSubmit(o),children:[c(t.Group,{position:"left",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[e(t.Text,{weight:500,children:"Data Source Configuration"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!a||s,children:e(v.DeviceFloppy,{size:20})})]}),c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,children:[c(t.Group,{grow:!0,children:[e(t.TextInput,m({placeholder:"An ID unique in this dashboard",label:"ID",required:!0,sx:{flex:1},disabled:s},r.getInputProps("id"))),e(t.Select,m({label:"Data Source Type",data:d,sx:{flex:1},disabled:s},r.getInputProps("type"))),e(t.Select,m({label:"Data Source Key",data:f,sx:{flex:1},disabled:s},r.getInputProps("key")))]}),e(t.Textarea,m({autosize:!0,minRows:12,maxRows:24},r.getInputProps("sql")))]})]})})}function Mt({id:n}){const{dataSources:i,setDataSources:r}=u.default.useContext(E),o=u.default.useMemo(()=>i.find(l=>l.id===n),[i,n]),a=u.default.useCallback(l=>{if(!i.findIndex(d=>d.id===n)){console.error(new Error("Invalid data source id when updating by id"));return}r(d=>{const f=d.findIndex(h=>h.id===n);return d.splice(f,1,l),[...d]})},[n,r]);return o?c(t.Group,{direction:"row",position:"apart",grow:!0,align:"stretch",noWrap:!0,children:[e(qt,{value:o,onChange:a}),e(At,{})]}):e("span",{children:"Invalid Data Source ID"})}function Bt({id:n,setID:i}){const{dataSources:r,setDataSources:o}=u.default.useContext(E),a=u.default.useCallback(()=>{var d,f;i((f=(d=r[0])==null?void 0:d.id)!=null?f:"")},[i,r]);u.default.useEffect(()=>{if(!n){a();return}r.findIndex(f=>f.id===n)===-1&&a()},[n,r,a]);const l=u.default.useMemo(()=>r.map(d=>({value:d.id,label:d.id})),[r]),s=u.default.useCallback(()=>{const d={id:A.randomId(),type:"postgresql",key:"",sql:""};o(f=>[...f,d]),i(d.id)},[o,i]);return e(t.Group,{pb:"xl",children:c(t.Group,{position:"left",sx:{maxWidth:"600px",alignItems:"baseline"},children:[e(t.Text,{children:"Select a Data Source"}),e(t.Select,{data:l,value:n,onChange:i,allowDeselect:!1,clearable:!1,sx:{flexGrow:1}}),e(t.Text,{children:"or"}),e(t.Group,{position:"center",mt:"md",children:e(t.Button,{onClick:s,children:"Add a Data Source"})})]})})}function Ft({opened:n,close:i}){const[r,o]=u.default.useState(""),{freezeLayout:a}=u.default.useContext(R);return u.default.useEffect(()=>{a(n)},[n]),e(t.Modal,{size:"96vw",overflow:"inside",opened:n,onClose:i,title:"Data Sources",trapFocus:!0,onDragStart:l=>{l.stopPropagation()},children:c(t.AppShell,{sx:{height:"90vh",maxHeight:"calc(100vh - 185px)",".mantine-AppShell-body":{height:"100%"},main:{height:"100%",width:"100%",padding:0,margin:0}},padding:"md",header:e(Bt,{id:r,setID:o}),children:[e(Mt,{id:r}),e(be,{id:r})]})})}function Rt({}){const n=u.default.useContext(W),i="SELECT *\nFROM commit\nWHERE author_time BETWEEN '${timeRange?.[0].toISOString()}' AND '${timeRange?.[1].toISOString()}'";return c(t.Group,{direction:"column",grow:!0,sx:{border:"1px solid #eee",maxWidth:"48%",overflow:"hidden"},children:[e(t.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:e(t.Text,{weight:500,children:"Context"})}),c(t.Group,{direction:"column",px:"md",pb:"md",sx:{width:"100%"},children:[e(B.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:`-- You may refer context data *by name*
|
|
21
22
|
-- in SQL or VizConfig.
|
|
22
23
|
|
|
23
|
-
${
|
|
24
|
+
${i}`}),e(t.Text,{weight:500,sx:{flexGrow:0},children:"Avaiable context entries"}),e(B.Prism,{language:"json",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:JSON.stringify(n,null,2)})]})]})}function $t({}){const{sqlSnippets:n,setSQLSnippets:i}=u.default.useContext(E),r=`SELECT *
|
|
24
25
|
FROM commit
|
|
25
|
-
WHERE \${author_time_condition}`,o=u.default.useMemo(()=>({snippets:
|
|
26
|
+
WHERE \${author_time_condition}`,o=u.default.useMemo(()=>({snippets:z.formList(n!=null?n:[])}),[n]),a=z.useForm({initialValues:o}),l=()=>a.addListItem("snippets",{key:A.randomId(),value:""}),s=u.default.useMemo(()=>!T.default.isEqual(a.values,o),[a.values,o]),d=({snippets:f})=>{i(f)};return c(t.Group,{direction:"column",grow:!0,sx:{border:"1px solid #eee"},children:[c(t.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:[e(t.Text,{weight:500,children:"SQL Snippets"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",disabled:!s,children:e(v.DeviceFloppy,{size:20})})]}),c(t.Group,{px:"md",pb:"md",children:[e(B.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,trim:!1,colorScheme:"dark",children:`-- You may refer context data *by name*
|
|
26
27
|
-- in SQL or VizConfig.
|
|
27
28
|
|
|
28
|
-
${
|
|
29
|
+
${r}
|
|
29
30
|
|
|
30
31
|
-- where author_time_condition is:
|
|
31
32
|
author_time BETWEEN '\${timeRange?.[0].toISOString()}' AND '\${timeRange?.[1].toISOString()}'
|
|
32
|
-
`}),e(t.Group,{direction:"column",sx:{width:"100%",position:"relative"},grow:!0,children:c("form",{onSubmit:a.onSubmit(d),children:[a.values.snippets.map((
|
|
33
|
+
`}),e(t.Group,{direction:"column",sx:{width:"100%",position:"relative"},grow:!0,children:c("form",{onSubmit:a.onSubmit(d),children:[a.values.snippets.map((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:"Key",required:!0},a.getListInputProps("snippets",h,"key"))),e(t.Textarea,m({minRows:3,label:"Value",required:!0},a.getListInputProps("snippets",h,"value"))),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>a.removeListItem("snippets",h),sx:{position:"absolute",top:15,right:5},children:e(v.Trash,{size:16})})]},h)),e(t.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"40%"},mx:"auto",children:e(t.Button,{variant:"default",onClick:l,children:"Add a snippet"})})]})})]})]})}function Vt({opened:n,close:i}){const{freezeLayout:r}=u.default.useContext(R);return u.default.useEffect(()=>{r(n)},[n]),e(t.Modal,{size:"96vw",overflow:"inside",opened:n,onClose:i,title:"SQL Snippets",trapFocus:!0,onDragStart:o=>{o.stopPropagation()},children:e(t.AppShell,{sx:{height:"90vh",maxHeight:"calc(100vh - 185px)",".mantine-AppShell-body":{height:"100%"},main:{height:"100%",width:"100%",padding:0,margin:0}},padding:"md",children:c(t.Group,{direction:"row",position:"apart",grow:!0,align:"stretch",noWrap:!0,children:[e($t,{}),e(Rt,{})]})})})}function Nt({mode:n,setMode:i,hasChanges:r,addPanel:o,saveChanges:a}){const[l,s]=u.default.useState(!1),d=()=>s(!0),f=()=>s(!1),[h,p]=u.default.useState(!1),b=()=>p(!0),g=()=>p(!1),S=n===q.Edit;return c(t.Group,{position:"apart",pt:"sm",pb:"xs",children:[e(t.Group,{position:"left",children:e(Et,{mode:n,setMode:i})}),S&&c(oe,{children:[c(t.Group,{position:"right",children:[e(t.Button,{variant:"default",size:"sm",onClick:o,leftIcon:e(v.PlaylistAdd,{size:20}),children:"Add a Panel"}),e(t.Button,{variant:"default",size:"sm",onClick:b,leftIcon:e(v.ClipboardText,{size:20}),children:"SQL Snippets"}),e(t.Button,{variant:"default",size:"sm",onClick:d,leftIcon:e(v.Database,{size:20}),children:"Data Sources"}),e(t.Button,{variant:"default",size:"sm",onClick:a,disabled:!r,leftIcon:e(v.DeviceFloppy,{size:20}),children:"Save Changes"}),e(t.Button,{color:"red",size:"sm",disabled:!r,leftIcon:e(v.Recycle,{size:20}),children:"Revert Changes"})]}),e(Ft,{opened:l,close:f}),e(Vt,{opened:h,close:g})]}),!S&&e(t.Button,{variant:"default",size:"sm",disabled:!0,leftIcon:e(v.Share,{size:20}),children:"Share"})]})}function jt({context:n,dashboard:i,update:r,className:o="dashboard"}){const[a,l]=u.default.useState(!1),[s,d]=u.default.useState(),[f,h]=u.default.useState(),[p,b]=u.default.useState(i.panels),[g,S]=u.default.useState(i.definition.sqlSnippets),[y,_]=u.default.useState(i.definition.dataSources),[D,k]=u.default.useState(q.Edit),I=u.default.useMemo(()=>{const M=V=>JSON.parse(JSON.stringify(V));return!T.default.isEqual(M(p),M(i.panels))||!T.default.isEqual(g,i.definition.sqlSnippets)?!0:!T.default.isEqual(y,i.definition.dataSources)},[i,p,g,y]),ee=async()=>{const M=T.default.merge({},i,{panels:p},{definition:{sqlSnippets:g,dataSources:y}});await r(M)},ue=()=>{const M=A.randomId(),te={id:M,layout:{x:0,y:1/0,w:3,h:4},title:`New Panel - ${M}`,description:"description goes here",dataSourceID:"",viz:{type:"table",conf:{}}};b(V=>[...V,te])},de=M=>{const te=p.findIndex(V=>V.id===M);b(V=>(V.splice(te,1),[...V]))},J=D===q.Edit,Ut=u.default.useMemo(()=>({sqlSnippets:g,setSQLSnippets:S,dataSources:y,setDataSources:_}),[g,S,y,_]);return e(W.Provider,{value:n,children:e("div",{className:o,children:e(E.Provider,{value:Ut,children:c(R.Provider,{value:{layoutFrozen:a,freezeLayout:l,mode:D,inEditMode:J},children:[e(Nt,{mode:D,setMode:k,hasChanges:I,addPanel:ue,saveChanges:ee}),e(we,{panels:p,setPanels:b,isDraggable:J&&!a,isResizable:J&&!a,onRemoveItem:de,setLocalCols:h,setBreakpoint:d})]})})})})}const Wt=G.WidthProvider(G.Responsive);function Qt({panels:n,className:i="layout",cols:r={lg:12,md:10,sm:8,xs:6,xxs:4},rowHeight:o=10}){return e(Wt,{className:i,cols:r,rowHeight:o,isDraggable:!1,isResizable:!1,children:n.map(s=>{var d=s,{id:a}=d,l=P(d,["id"]);return e("div",{"data-grid":l.layout,children:e(se,m({id:a},l))},a)})})}function Jt({context:n,dashboard:i,className:r="dashboard"}){const o=u.default.useMemo(()=>O(m({},i.definition),{setSQLSnippets:()=>{},setDataSources:()=>{}}),[i]);return e(W.Provider,{value:n,children:e("div",{className:r,children:e(E.Provider,{value:o,children:e(R.Provider,{value:{layoutFrozen:!0,freezeLayout:()=>{},mode:q.Use,inEditMode:!1},children:e(Qt,{panels:i.panels})})})})})}x.ContextInfoContext=W,x.Dashboard=jt,x.DashboardLayout=we,x.DashboardMode=q,x.DefinitionContext=E,x.LayoutStateContext=R,x.Panel=se,x.PanelContext=L,x.ReadOnlyDashboard=Jt,x.initialContextInfoContext=Fe,Object.defineProperties(x,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|