@devtable/dashboard 0.0.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api-caller/index.d.ts +1 -1
- package/dist/dashboard.es.js +118 -34
- package/dist/dashboard.umd.js +5 -5
- package/dist/layout/index.d.ts +3 -1
- package/dist/main/actions.d.ts +3 -1
- package/dist/main/index.d.ts +2 -1
- package/dist/panel/error-boundary.d.ts +8 -0
- package/dist/panel/index.d.ts +4 -8
- package/dist/style.css +1 -1
- package/package.json +2 -5
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ContextInfoContextType } from "../contexts";
|
|
2
2
|
import { IDashboardDefinition } from "../types";
|
|
3
|
-
export declare const queryBySQL: (sql: string, context: ContextInfoContextType, definitions: IDashboardDefinition) => () => Promise<any>;
|
|
3
|
+
export declare const queryBySQL: (sql: string, context: ContextInfoContextType, definitions: IDashboardDefinition, title: string) => () => Promise<any>;
|
package/dist/dashboard.es.js
CHANGED
|
@@ -36,7 +36,7 @@ import { Text, Table, Group, LoadingOverlay, Box, Textarea, Button, TextInput, A
|
|
|
36
36
|
import { useRequest } from "ahooks";
|
|
37
37
|
import axios from "axios";
|
|
38
38
|
import { Trash, DeviceFloppy, Settings, Refresh, InfoCircle, Paint, PlayerPlay, PlaylistAdd, Recycle, Share } from "tabler-icons-react";
|
|
39
|
-
import { useElementSize, randomId, useInputState } from "@mantine/hooks";
|
|
39
|
+
import { useElementSize, randomId, useInputState, useListState } from "@mantine/hooks";
|
|
40
40
|
import ReactEChartsCore from "echarts-for-react/lib/core";
|
|
41
41
|
import * as echarts from "echarts/core";
|
|
42
42
|
import { SunburstChart, BarChart, LineChart } from "echarts/charts";
|
|
@@ -87,7 +87,6 @@ const post = getRequest("POST");
|
|
|
87
87
|
function formatSQL(sql, params) {
|
|
88
88
|
const names = Object.keys(params);
|
|
89
89
|
const vals = Object.values(params);
|
|
90
|
-
console.log({ names, vals });
|
|
91
90
|
return new Function(...names, `return \`${sql}\`;`)(...vals);
|
|
92
91
|
}
|
|
93
92
|
function getSQLParams(context, definitions) {
|
|
@@ -97,14 +96,16 @@ function getSQLParams(context, definitions) {
|
|
|
97
96
|
}, {});
|
|
98
97
|
return _.defaultsDeep(context, sqlSnippetRecord);
|
|
99
98
|
}
|
|
100
|
-
const queryBySQL = (sql, context, definitions) => async () => {
|
|
99
|
+
const queryBySQL = (sql, context, definitions, title) => async () => {
|
|
101
100
|
if (!sql) {
|
|
102
101
|
return [];
|
|
103
102
|
}
|
|
104
103
|
const params = getSQLParams(context, definitions);
|
|
105
104
|
const formattedSQL = formatSQL(sql, params);
|
|
106
105
|
if (sql.includes("$")) {
|
|
106
|
+
console.groupCollapsed(`Final SQL for: ${title}`);
|
|
107
107
|
console.log(formattedSQL);
|
|
108
|
+
console.groupEnd();
|
|
108
109
|
}
|
|
109
110
|
const res = await post("/query", { sql: formattedSQL });
|
|
110
111
|
return res;
|
|
@@ -167,6 +168,27 @@ reactJsxRuntime_production_min.jsxs = q;
|
|
|
167
168
|
const jsx = jsxRuntime.exports.jsx;
|
|
168
169
|
const jsxs = jsxRuntime.exports.jsxs;
|
|
169
170
|
const Fragment = jsxRuntime.exports.Fragment;
|
|
171
|
+
class ErrorBoundary extends React.Component {
|
|
172
|
+
constructor(props) {
|
|
173
|
+
super(props);
|
|
174
|
+
this.state = {
|
|
175
|
+
hasError: false
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
static getDerivedStateFromError() {
|
|
179
|
+
return {
|
|
180
|
+
hasError: true
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
render() {
|
|
184
|
+
if (this.state.hasError) {
|
|
185
|
+
return /* @__PURE__ */ jsx("h1", {
|
|
186
|
+
children: "Something went wrong."
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
return this.props.children;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
170
192
|
echarts.use([SunburstChart, CanvasRenderer]);
|
|
171
193
|
const defaultOption$1 = {
|
|
172
194
|
tooltip: {
|
|
@@ -1860,10 +1882,12 @@ function PanelSettings({}) {
|
|
|
1860
1882
|
})]
|
|
1861
1883
|
})
|
|
1862
1884
|
}),
|
|
1863
|
-
children: /* @__PURE__ */ jsx(
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1885
|
+
children: /* @__PURE__ */ jsx(ErrorBoundary, {
|
|
1886
|
+
children: /* @__PURE__ */ jsx(Viz, {
|
|
1887
|
+
viz,
|
|
1888
|
+
data,
|
|
1889
|
+
loading
|
|
1890
|
+
})
|
|
1867
1891
|
})
|
|
1868
1892
|
})
|
|
1869
1893
|
}), /* @__PURE__ */ jsx(ActionIcon, {
|
|
@@ -1956,7 +1980,10 @@ function Panel({
|
|
|
1956
1980
|
viz: initialViz,
|
|
1957
1981
|
sql: initialSQL,
|
|
1958
1982
|
title: initialTitle,
|
|
1959
|
-
description: initialDesc
|
|
1983
|
+
description: initialDesc,
|
|
1984
|
+
update,
|
|
1985
|
+
layout,
|
|
1986
|
+
id
|
|
1960
1987
|
}) {
|
|
1961
1988
|
const contextInfo = React.useContext(ContextInfoContext);
|
|
1962
1989
|
const definitions = React.useContext(DefinitionContext);
|
|
@@ -1964,12 +1991,22 @@ function Panel({
|
|
|
1964
1991
|
const [description, setDescription] = React.useState(initialDesc);
|
|
1965
1992
|
const [sql, setSQL] = React.useState(initialSQL);
|
|
1966
1993
|
const [viz, setViz] = React.useState(initialViz);
|
|
1994
|
+
React.useEffect(() => {
|
|
1995
|
+
update({
|
|
1996
|
+
id,
|
|
1997
|
+
layout,
|
|
1998
|
+
title,
|
|
1999
|
+
description,
|
|
2000
|
+
sql,
|
|
2001
|
+
viz
|
|
2002
|
+
});
|
|
2003
|
+
}, [title, description, sql, viz, id, layout]);
|
|
1967
2004
|
const {
|
|
1968
2005
|
data = [],
|
|
1969
2006
|
loading,
|
|
1970
2007
|
refresh
|
|
1971
|
-
} = useRequest(queryBySQL(sql, contextInfo, definitions), {
|
|
1972
|
-
refreshDeps: [contextInfo]
|
|
2008
|
+
} = useRequest(queryBySQL(sql, contextInfo, definitions, title), {
|
|
2009
|
+
refreshDeps: [contextInfo, definitions]
|
|
1973
2010
|
});
|
|
1974
2011
|
const refreshData = refresh;
|
|
1975
2012
|
return /* @__PURE__ */ jsx(PanelContext.Provider, {
|
|
@@ -1988,20 +2025,21 @@ function Panel({
|
|
|
1988
2025
|
},
|
|
1989
2026
|
children: /* @__PURE__ */ jsxs(Container, {
|
|
1990
2027
|
className: "panel-root",
|
|
1991
|
-
children: [/* @__PURE__ */ jsx(PanelTitleBar, {}), /* @__PURE__ */ jsx(
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
2028
|
+
children: [/* @__PURE__ */ jsx(PanelTitleBar, {}), /* @__PURE__ */ jsx(ErrorBoundary, {
|
|
2029
|
+
children: /* @__PURE__ */ jsx(Viz, {
|
|
2030
|
+
viz,
|
|
2031
|
+
data,
|
|
2032
|
+
loading
|
|
2033
|
+
})
|
|
1995
2034
|
})]
|
|
1996
2035
|
})
|
|
1997
2036
|
});
|
|
1998
2037
|
}
|
|
1999
|
-
var styles$1 = "";
|
|
2000
|
-
var styles = "";
|
|
2001
2038
|
var index = "";
|
|
2002
2039
|
const ResponsiveReactGridLayout = WidthProvider(Responsive);
|
|
2003
2040
|
function DashboardLayout({
|
|
2004
2041
|
panels,
|
|
2042
|
+
setPanels,
|
|
2005
2043
|
className = "layout",
|
|
2006
2044
|
cols = {
|
|
2007
2045
|
lg: 12,
|
|
@@ -2021,14 +2059,30 @@ function DashboardLayout({
|
|
|
2021
2059
|
setBreakpoint(breakpoint);
|
|
2022
2060
|
setLocalCols(localCols);
|
|
2023
2061
|
};
|
|
2062
|
+
const onLayoutChange = React.useCallback((currentLayout) => {
|
|
2063
|
+
const m2 = /* @__PURE__ */ new Map();
|
|
2064
|
+
currentLayout.forEach((_a) => {
|
|
2065
|
+
var _b = _a, {
|
|
2066
|
+
i
|
|
2067
|
+
} = _b, rest = __objRest(_b, [
|
|
2068
|
+
"i"
|
|
2069
|
+
]);
|
|
2070
|
+
m2.set(i, rest);
|
|
2071
|
+
});
|
|
2072
|
+
const newPanels = panels.map((p2) => __spreadProps(__spreadValues({}, p2), {
|
|
2073
|
+
layout: m2.get(p2.id)
|
|
2074
|
+
}));
|
|
2075
|
+
setPanels.setState(newPanels);
|
|
2076
|
+
}, [panels, setPanels]);
|
|
2024
2077
|
return /* @__PURE__ */ jsx(ResponsiveReactGridLayout, {
|
|
2025
2078
|
onBreakpointChange,
|
|
2079
|
+
onLayoutChange,
|
|
2026
2080
|
className,
|
|
2027
2081
|
cols,
|
|
2028
2082
|
rowHeight,
|
|
2029
2083
|
isDraggable,
|
|
2030
2084
|
isResizable,
|
|
2031
|
-
children: panels.map((_a) => {
|
|
2085
|
+
children: panels.map((_a, index2) => {
|
|
2032
2086
|
var _b = _a, {
|
|
2033
2087
|
id
|
|
2034
2088
|
} = _b, rest = __objRest(_b, [
|
|
@@ -2036,9 +2090,14 @@ function DashboardLayout({
|
|
|
2036
2090
|
]);
|
|
2037
2091
|
return /* @__PURE__ */ jsx("div", {
|
|
2038
2092
|
"data-grid": rest.layout,
|
|
2039
|
-
children: /* @__PURE__ */ jsx(Panel, __spreadValues({
|
|
2040
|
-
|
|
2041
|
-
}, rest)
|
|
2093
|
+
children: /* @__PURE__ */ jsx(Panel, __spreadProps(__spreadValues({
|
|
2094
|
+
id
|
|
2095
|
+
}, rest), {
|
|
2096
|
+
destroy: () => onRemoveItem(id),
|
|
2097
|
+
update: (panel) => {
|
|
2098
|
+
setPanels.setItem(index2, panel);
|
|
2099
|
+
}
|
|
2100
|
+
}))
|
|
2042
2101
|
}, id);
|
|
2043
2102
|
})
|
|
2044
2103
|
});
|
|
@@ -2076,7 +2135,9 @@ function ModeToggler({
|
|
|
2076
2135
|
function DashboardActions({
|
|
2077
2136
|
mode,
|
|
2078
2137
|
setMode,
|
|
2079
|
-
|
|
2138
|
+
hasChanges,
|
|
2139
|
+
addPanel,
|
|
2140
|
+
saveChanges
|
|
2080
2141
|
}) {
|
|
2081
2142
|
const inEditMode = mode === DashboardMode.Edit;
|
|
2082
2143
|
return /* @__PURE__ */ jsxs(Group, {
|
|
@@ -2102,15 +2163,16 @@ function DashboardActions({
|
|
|
2102
2163
|
}), /* @__PURE__ */ jsx(Button, {
|
|
2103
2164
|
variant: "default",
|
|
2104
2165
|
size: "sm",
|
|
2105
|
-
|
|
2166
|
+
onClick: saveChanges,
|
|
2167
|
+
disabled: !hasChanges,
|
|
2106
2168
|
leftIcon: /* @__PURE__ */ jsx(DeviceFloppy, {
|
|
2107
2169
|
size: 20
|
|
2108
2170
|
}),
|
|
2109
|
-
children: "Save
|
|
2171
|
+
children: "Save Changes"
|
|
2110
2172
|
}), /* @__PURE__ */ jsx(Button, {
|
|
2111
2173
|
color: "red",
|
|
2112
2174
|
size: "sm",
|
|
2113
|
-
disabled:
|
|
2175
|
+
disabled: !hasChanges,
|
|
2114
2176
|
leftIcon: /* @__PURE__ */ jsx(Recycle, {
|
|
2115
2177
|
size: 20
|
|
2116
2178
|
}),
|
|
@@ -2129,15 +2191,34 @@ function DashboardActions({
|
|
|
2129
2191
|
}
|
|
2130
2192
|
function Dashboard({
|
|
2131
2193
|
dashboard,
|
|
2194
|
+
update,
|
|
2132
2195
|
className = "dashboard"
|
|
2133
2196
|
}) {
|
|
2134
2197
|
const [layoutFrozen, freezeLayout] = React.useState(false);
|
|
2135
2198
|
const [newCounter, setNewCounter] = React.useState(0);
|
|
2136
2199
|
const [breakpoint, setBreakpoint] = React.useState();
|
|
2137
2200
|
const [localCols, setLocalCols] = React.useState();
|
|
2138
|
-
const [panels, setPanels] =
|
|
2201
|
+
const [panels, setPanels] = useListState(dashboard.panels);
|
|
2139
2202
|
const [sqlSnippets, setSQLSnippets] = React.useState(dashboard.definition.sqlSnippets);
|
|
2140
2203
|
const [mode, setMode] = React.useState(DashboardMode.Edit);
|
|
2204
|
+
const hasChanges = React.useMemo(() => {
|
|
2205
|
+
const cleanJSON = (v) => JSON.parse(JSON.stringify(v));
|
|
2206
|
+
const panelsEqual = _.isEqual(cleanJSON(panels), cleanJSON(dashboard.panels));
|
|
2207
|
+
if (!panelsEqual) {
|
|
2208
|
+
return true;
|
|
2209
|
+
}
|
|
2210
|
+
return !_.isEqual(sqlSnippets, dashboard.definition.sqlSnippets);
|
|
2211
|
+
}, [dashboard, panels, sqlSnippets]);
|
|
2212
|
+
const saveDashboardChanges = async () => {
|
|
2213
|
+
const d = _.merge({}, dashboard, {
|
|
2214
|
+
panels
|
|
2215
|
+
}, {
|
|
2216
|
+
definition: {
|
|
2217
|
+
sqlSnippets
|
|
2218
|
+
}
|
|
2219
|
+
});
|
|
2220
|
+
await update(d);
|
|
2221
|
+
};
|
|
2141
2222
|
const addPanel = () => {
|
|
2142
2223
|
console.log("adding", "n" + newCounter);
|
|
2143
2224
|
setNewCounter((v) => v + 1);
|
|
@@ -2158,21 +2239,21 @@ function Dashboard({
|
|
|
2158
2239
|
conf: {}
|
|
2159
2240
|
}
|
|
2160
2241
|
};
|
|
2161
|
-
setPanels(
|
|
2242
|
+
setPanels.append(newItem);
|
|
2162
2243
|
};
|
|
2163
2244
|
const removePanelByID = (id) => {
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
}));
|
|
2245
|
+
const index2 = panels.findIndex((p2) => p2.id === id);
|
|
2246
|
+
setPanels.remove(index2);
|
|
2167
2247
|
};
|
|
2168
2248
|
const inEditMode = mode === DashboardMode.Edit;
|
|
2249
|
+
const definitions = React.useMemo(() => ({
|
|
2250
|
+
sqlSnippets,
|
|
2251
|
+
setSQLSnippets
|
|
2252
|
+
}), [sqlSnippets, setSQLSnippets]);
|
|
2169
2253
|
return /* @__PURE__ */ jsx("div", {
|
|
2170
2254
|
className,
|
|
2171
2255
|
children: /* @__PURE__ */ jsx(DefinitionContext.Provider, {
|
|
2172
|
-
value:
|
|
2173
|
-
sqlSnippets,
|
|
2174
|
-
setSQLSnippets
|
|
2175
|
-
},
|
|
2256
|
+
value: definitions,
|
|
2176
2257
|
children: /* @__PURE__ */ jsxs(LayoutStateContext.Provider, {
|
|
2177
2258
|
value: {
|
|
2178
2259
|
layoutFrozen,
|
|
@@ -2183,9 +2264,12 @@ function Dashboard({
|
|
|
2183
2264
|
children: [/* @__PURE__ */ jsx(DashboardActions, {
|
|
2184
2265
|
mode,
|
|
2185
2266
|
setMode,
|
|
2186
|
-
|
|
2267
|
+
hasChanges,
|
|
2268
|
+
addPanel,
|
|
2269
|
+
saveChanges: saveDashboardChanges
|
|
2187
2270
|
}), /* @__PURE__ */ jsx(DashboardLayout, {
|
|
2188
2271
|
panels,
|
|
2272
|
+
setPanels,
|
|
2189
2273
|
isDraggable: inEditMode && !layoutFrozen,
|
|
2190
2274
|
isResizable: inEditMode && !layoutFrozen,
|
|
2191
2275
|
onRemoveItem: removePanelByID,
|
package/dist/dashboard.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(p,
|
|
1
|
+
(function(p,y){typeof exports=="object"&&typeof module!="undefined"?y(exports,require("react"),require("lodash"),require("react-grid-layout"),require("@mantine/core"),require("ahooks"),require("axios"),require("tabler-icons-react"),require("@mantine/hooks"),require("echarts-for-react/lib/core"),require("echarts/core"),require("echarts/charts"),require("echarts/renderers"),require("echarts/components"),require("numbro"),require("echarts-gl"),require("@mantine/prism"),require("@mantine/form"),require("react-hook-form")):typeof define=="function"&&define.amd?define(["exports","react","lodash","react-grid-layout","@mantine/core","ahooks","axios","tabler-icons-react","@mantine/hooks","echarts-for-react/lib/core","echarts/core","echarts/charts","echarts/renderers","echarts/components","numbro","echarts-gl","@mantine/prism","@mantine/form","react-hook-form"],y):(p=typeof globalThis!="undefined"?globalThis:p||self,y(p.dashboard={},p.React,p._,p["react-grid-layout"],p["@mantine/core"],p.ahooks,p.axios,p["tabler-icons-react"],p["@mantine/hooks"],p["echarts-for-react/lib/core"],p["echarts/core"],p["echarts/charts"],p["echarts/renderers"],p["echarts/components"],p.numbro,p["echarts-gl"],p["@mantine/prism"],p["@mantine/form"],p["react-hook-form"]))})(this,function(p,y,C,T,t,Ce,we,S,L,Te,_e,ee,te,A,ze,Gt,M,I,N){"use strict";var Lt=Object.defineProperty,It=Object.defineProperties;var kt=Object.getOwnPropertyDescriptors;var Z=Object.getOwnPropertySymbols;var ye=Object.prototype.hasOwnProperty,Se=Object.prototype.propertyIsEnumerable;var ve=(p,y,C)=>y in p?Lt(p,y,{enumerable:!0,configurable:!0,writable:!0,value:C}):p[y]=C,m=(p,y)=>{for(var C in y||(y={}))ye.call(y,C)&&ve(p,C,y[C]);if(Z)for(var C of Z(y))Se.call(y,C)&&ve(p,C,y[C]);return p},D=(p,y)=>It(p,kt(y));var P=(p,y)=>{var C={};for(var T in p)ye.call(p,T)&&y.indexOf(T)<0&&(C[T]=p[T]);if(p!=null&&Z)for(var T of Z(p))y.indexOf(T)<0&&Se.call(p,T)&&(C[T]=p[T]);return C};function V(n){return n&&typeof n=="object"&&"default"in n?n:{default:n}}function Pe(n){if(n&&n.__esModule)return n;var i=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});return n&&Object.keys(n).forEach(function(r){if(r!=="default"){var a=Object.getOwnPropertyDescriptor(n,r);Object.defineProperty(i,r,a.get?a:{enumerable:!0,get:function(){return n[r]}})}}),i.default=n,Object.freeze(i)}var u=V(y),_=V(C),Le=V(we),ne=V(Te),F=Pe(_e),se=V(ze),E=(n=>(n.Use="use",n.Edit="edit",n))(E||{});const Ie={layoutFrozen:!1,freezeLayout:()=>{},mode:E.Edit,inEditMode:!1},R=u.default.createContext(Ie),ke=(n=>(i,r,a={})=>{const o=m({"X-Requested-With":"XMLHttpRequest","Content-Type":a.string?"application/x-www-form-urlencoded":"application/json"},a.headers),s={baseURL:"http://localhost:31200",method:n,url:i,params:n==="GET"?r:a.params,headers:o};return n==="POST"&&(s.data=a.string?JSON.stringify(r):r),Le.default(s).then(l=>l.data).catch(l=>Promise.reject(l))})("POST");function ue(n,i){const r=Object.keys(i),a=Object.values(i);return new Function(...r,`return \`${n}\`;`)(...a)}function Ge(n,i){const r=i.sqlSnippets.reduce((a,o)=>(a[o.key]=ue(o.value,n),a),{});return _.default.defaultsDeep(n,r)}const De=(n,i,r,a)=>async()=>{if(!n)return[];const o=Ge(i,r),s=ue(n,o);return n.includes("$")&&(console.groupCollapsed(`Final SQL for: ${a}`),console.log(s),console.groupEnd()),await ke("/query",{sql:s})},de={},Ee=de,ie=u.default.createContext(de),Oe={data:[],loading:!1,title:"",setTitle:()=>{},description:"",setDescription:()=>{},sql:"",setSQL:()=>{},viz:{type:"",conf:{}},setViz:()=>{},refreshData:()=>{}},k=u.default.createContext(Oe);var Q={exports:{}},J={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,16 +6,16 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var
|
|
9
|
+
*/var qe=u.default,Ae=Symbol.for("react.element"),Me=Symbol.for("react.fragment"),Ne=Object.prototype.hasOwnProperty,$e=qe.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Be={key:!0,ref:!0,__self:!0,__source:!0};function ce(n,i,r){var a,o={},s=null,l=null;r!==void 0&&(s=""+r),i.key!==void 0&&(s=""+i.key),i.ref!==void 0&&(l=i.ref);for(a in i)Ne.call(i,a)&&!Be.hasOwnProperty(a)&&(o[a]=i[a]);if(n&&n.defaultProps)for(a in i=n.defaultProps,i)o[a]===void 0&&(o[a]=i[a]);return{$$typeof:Ae,type:n,key:s,ref:l,props:o,_owner:$e.current}}J.Fragment=Me,J.jsx=ce,J.jsxs=ce,Q.exports=J;const e=Q.exports.jsx,c=Q.exports.jsxs,W=Q.exports.Fragment;class pe 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}}F.use([ee.SunburstChart,te.CanvasRenderer]);const Fe={tooltip:{show:!0},series:{type:"sunburst",radius:[0,"90%"],emphasis:{focus:"ancestor"}}};function Ve({conf:n,data:i,width:r,height:a}){const h=n,{label_field:o="name",value_field:s="value"}=h,l=P(h,["label_field","value_field"]),d=u.default.useMemo(()=>i.map(g=>({name:g[o],value:g[s]})),[i,o,s]),f=u.default.useMemo(()=>{var g,v;return(v=(g=_.default.maxBy(d,z=>z.value))==null?void 0:g.value)!=null?v:1},[d]),x=u.default.useMemo(()=>({series:{label:{formatter:({name:g,value:v})=>v/f<.2?" ":g}}}),[]),b=_.default.defaultsDeep(Fe,x,l,{series:{data:d}});return e(ne.default,{echarts:F,option:b,style:{width:r,height:a}})}F.use([ee.BarChart,ee.LineChart,A.GridComponent,A.LegendComponent,A.TooltipComponent,te.CanvasRenderer]);const je={legend:{show:!0},tooltip:{trigger:"axis"},xAxis:{type:"category"},yAxis:{}};function Re({conf:n,data:i,width:r,height:a}){const o=u.default.useMemo(()=>{const s={dataset:{source:i}},l={xAxis:{data:i.map(f=>f[n.x_axis_data_key])}},d=n.series.map(b=>{var h=b,{y_axis_data_key:f}=h,x=P(h,["y_axis_data_key"]);return m({data:i.map(g=>g[f])},x)});return _.default.assign({},je,s,l,{series:d})},[n,i]);return!r||!a?null:e(ne.default,{echarts:F,option:o,style:{width:r,height:a}})}var O=(n=>(n.string="string",n.number="number",n.eloc="eloc",n.percentage="percentage",n))(O||{});function Qe({value:n}){return e(t.Text,{component:"span",children:n})}function Je({value:n}){return e(t.Text,{component:"span",children:n})}function We({value:n}){const i=se.default(n).format({thousandSeparated:!0});return e(t.Text,{component:"span",children:i})}function Ue({value:n}){const i=se.default(n).format({output:"percent",mantissa:3});return e(t.Text,{component:"span",children:i})}function Ye({value:n,type:i}){switch(i){case O.string:return e(Qe,{value:n});case O.eloc:return e(Je,{value:n});case O.number:return e(We,{value:n});case O.percentage:return e(Ue,{value:n})}}function Ke({conf:n,data:i,width:r,height:a}){const b=n,{id_field:o,use_raw_columns:s,columns:l}=b,d=P(b,["id_field","use_raw_columns","columns"]),f=u.default.useMemo(()=>s?Object.keys(i==null?void 0:i[0]):l.map(h=>h.label),[s,l,i]),x=u.default.useMemo(()=>s?Object.keys(i==null?void 0:i[0]).map(h=>({label:h,value_field:h,value_type:O.string})):l,[s,l,i]);return c(t.Table,D(m({sx:{maxHeight:a}},d),{children:[e("thead",{children:e("tr",{children:f.map(h=>e("th",{children:h},h))})}),e("tbody",{children:i.map((h,g)=>e("tr",{children:x.map(({value_field:v,value_type:z})=>e("td",{children:e(t.Group,{sx:{"&, .mantine-Text-root":{fontFamily:"monospace"}},children:e(Ye,{value:h[v],type:z})})},h[v]))},o?h[o]:`row-${g}`))})]}))}function Xe(n,i={}){const r=Object.keys(i),a=Object.values(i);try{return new Function(...r,`return \`${n}\`;`)(...a)}catch(o){return o.message}}function He({conf:{paragraphs:n},data:i}){return e(W,{children:n.map((s,o)=>{var l=s,{template:r}=l,a=P(l,["template"]);return e(t.Text,D(m({},a),{children:Xe(r,i[0])}),`${r}---${o}`)})})}F.use([A.GridComponent,A.VisualMapComponent,A.LegendComponent,A.TooltipComponent,te.CanvasRenderer]);function Ze({conf:n,data:i,width:r,height:a}){const h=n,{x_axis_data_key:o,y_axis_data_key:s,z_axis_data_key:l}=h,d=P(h,["x_axis_data_key","y_axis_data_key","z_axis_data_key"]),f=u.default.useMemo(()=>_.default.minBy(i,g=>g[l])[l],[i,l]),x=u.default.useMemo(()=>_.default.maxBy(i,g=>g[l])[l],[i,l]),b=D(m({tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:f,max:x,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[o],g[s],g[l]])}]});return e(ne.default,{echarts:F,option:b,style:{width:r,height:a}})}var Et="";function et(n,i,r,a){const o={width:n,height:i,data:r,conf:a.conf};switch(a.type){case"sunburst":return e(Ve,m({},o));case"line-bar":return e(Re,m({},o));case"table":return e(Ke,m({},o));case"text":return e(He,m({},o));case"bar-3d":return e(Ze,m({},o));default:return null}}function me({viz:n,data:i,loading:r}){const{ref:a,width:o,height:s}=L.useElementSize(),l=u.default.useMemo(()=>!Array.isArray(i)||i.length===0,[i]);return r?e("div",{className:"viz-root",ref:a,children:e(t.LoadingOverlay,{visible:r})}):c("div",{className:"viz-root",ref:a,children:[l&&e(t.Text,{color:"gray",align:"center",children:"nothing to show"}),!l&&et(o,s,i,n)]})}function tt({}){const n=u.default.useContext(ie),i="SELECT *\nFROM commit\nWHERE author_time BETWEEN '${timeRange?.[0].toISOString()}' AND '${timeRange?.[1].toISOString()}'";return c(t.Group,{direction:"column",children:[e(M.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:`-- You may refer context data *by name*
|
|
10
10
|
-- in SQL or VizConfig.
|
|
11
11
|
|
|
12
|
-
${i}`}),e(t.Text,{weight:700,children:"Avaiable context entries"}),e(
|
|
12
|
+
${i}`}),e(t.Text,{weight:700,children:"Avaiable context entries"}),e(M.Prism,{language:"json",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:JSON.stringify(n,null,2)})]})}var Ot="";function nt({}){const{sql:n,setSQL:i}=u.default.useContext(k),[r,a]=u.default.useState(!0),o=d=>{i(d.target.value)},s=u.default.useCallback(()=>{a(d=>!d)},[]),l=u.default.useCallback(()=>{i(d=>d.trim())},[i]);return c(t.Box,{className:"sql-query-editor-root",sx:{height:"100%"},children:[e(t.Textarea,{value:n,onChange:o,minRows:20,maxRows:20}),c(t.Group,{m:"md",position:"right",children:[e(t.Button,{color:"blue",onClick:l,children:"Format"}),e(t.Button,{variant:"default",onClick:s,children:"Toggle Preview"})]}),r&&e(M.Prism,{language:"sql",withLineNumbers:!0,noCopy:!0,colorScheme:"dark",children:n})]})}const it=nt;function rt({}){const{data:n}=u.default.useContext(k);return c("div",{className:"query-result-root",children:[c(t.Group,{mb:"xs",children:[e(t.Text,{weight:"bold",children:"Data Length: "}),n.length]}),e(M.Prism,{language:"json",colorScheme:"dark",children:JSON.stringify(n,null,2)})]})}const at={sqlSnippets:[],setSQLSnippets:()=>{}},U=u.default.createContext(at);function lt({sqlSnippets:n,setSQLSnippets:i}){const r=u.default.useRef(null),a=u.default.useMemo(()=>({snippets:I.formList(n!=null?n:[])}),[n]),o=I.useForm({initialValues:a}),s=()=>o.addListItem("snippets",{key:L.randomId(),value:""}),l=u.default.useMemo(()=>!_.default.isEqual(o.values,a),[o.values,a]);u.default.useEffect(()=>{var f;l&&((f=r==null?void 0:r.current)==null||f.click())},[l,r.current]);const d=({snippets:f})=>{i(f)};return e(t.Group,{direction:"column",sx:{width:"100%"},grow:!0,children:c("form",{onSubmit:o.onSubmit(d),children:[e("button",{ref:r,type:"submit",style:{display:"none"},children:"Ghost submit"}),o.values.snippets.map((f,x)=>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},o.getListInputProps("snippets",x,"key"))),e(t.Textarea,m({minRows:3,label:"Value",required:!0},o.getListInputProps("snippets",x,"value"))),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>o.removeListItem("snippets",x),sx:{position:"absolute",top:15,right:5},children:e(S.Trash,{size:16})})]},x)),e(t.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:e(t.Button,{color:"blue",onClick:s,children:"Add a snippet"})})]})})}function ot({}){const{sqlSnippets:n,setSQLSnippets:i}=u.default.useContext(U),r=`SELECT *
|
|
13
13
|
FROM commit
|
|
14
|
-
WHERE \${author_time_condition}`;return c(t.Group,{direction:"column",children:[e(
|
|
14
|
+
WHERE \${author_time_condition}`;return c(t.Group,{direction:"column",children:[e(M.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:`-- You may refer context data *by name*
|
|
15
15
|
-- in SQL or VizConfig.
|
|
16
16
|
|
|
17
17
|
${r}
|
|
18
18
|
|
|
19
19
|
-- where author_time_condition is:
|
|
20
20
|
author_time BETWEEN '\${timeRange?.[0].toISOString()}' AND '\${timeRange?.[1].toISOString()}'
|
|
21
|
-
`}),e(t.Text,{weight:700,children:"SQL Snippets"}),e(nt,{sqlSnippets:n,setSQLSnippets:i})]})}function rt(){const{description:n,setDescription:i}=u.default.useContext(L),[r,a]=I.useInputState(n),o=n!==r,s=u.default.useCallback(()=>{!o||i(r)},[o,r]);return e(t.Textarea,{label:"Panel Description",value:r,onChange:a,minRows:2,rightSection:e(t.ActionIcon,{disabled:!o,onClick:s,sx:{alignSelf:"flex-start",marginTop:"4px"},children:e(y.DeviceFloppy,{size:20})})})}function at(){const{title:n,setTitle:i}=u.default.useContext(L),[r,a]=I.useInputState(n),o=n!==r,s=u.default.useCallback(()=>{!o||i(r)},[o,r]);return e(t.TextInput,{label:"Panel Title",value:r,onChange:a,rightSection:e(t.ActionIcon,{disabled:!o,onClick:s,children:e(y.DeviceFloppy,{size:20})})})}function lt({conf:n,setConf:i}){const r=T.default.assign({},{x_axis_data_key:"x",y_axis_data_key:"y",z_axis_data_key:"z",xAxis3D:{type:"value",name:"X Axis Name"},yAxis3D:{type:"value",name:"Y Axis Name"},zAxis3D:{type:"value",name:"Z Axis Name"}},n),{control:a,handleSubmit:o,formState:s}=O.useForm({defaultValues:r});return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:o(i),children:[e(t.Text,{children:"X Axis"}),c(t.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[e(O.Controller,{name:"x_axis_data_key",control:a,render:({field:l})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Data Key"},l))}),e(O.Controller,{name:"xAxis3D.name",control:a,render:({field:l})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Name"},l))})]}),e(t.Text,{mt:"lg",children:"Y Axis"}),c(t.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[e(O.Controller,{name:"y_axis_data_key",control:a,render:({field:l})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Data Key"},l))}),e(O.Controller,{name:"yAxis3D.name",control:a,render:({field:l})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Name"},l))})]}),e(t.Text,{mt:"lg",children:"Z Axis"}),c(t.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[e(O.Controller,{name:"z_axis_data_key",control:a,render:({field:l})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Data Key"},l))}),e(O.Controller,{name:"zAxis3D.name",control:a,render:({field:l})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Name"},l))})]}),e(t.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:c(t.Button,{color:"blue",type:"submit",children:[e(y.DeviceFloppy,{size:20}),e(t.Text,{ml:"md",children:"Save"})]})})]})})}function de({value:n,onChange:i}){const r=t.useMantineTheme(),a=u.default.useMemo(()=>Object.entries(r.colors).map(([s,l])=>({label:s,value:l[6]})),[r]),o=u.default.useMemo(()=>a.some(s=>s.value===n),[n,a]);return c(t.Group,{position:"apart",spacing:"xs",children:[e(t.TextInput,{placeholder:"Set any color",value:o?"":n,onChange:s=>i(s.currentTarget.value),rightSection:e(t.ColorSwatch,{color:o?"transparent":n,radius:4}),variant:o?"filled":"default",sx:{maxWidth:"100%",flexGrow:1}}),e(t.Text,{sx:{flexGrow:0},children:"or"}),e(t.Select,{data:a,value:n,onChange:i,variant:o?"default":"filled",placeholder:"Pick a theme color",icon:e(t.ColorSwatch,{color:o?n:"transparent",radius:4}),sx:{maxWidth:"100%",flexGrow:1}})]})}function ot({conf:n,setConf:i}){const r=u.default.useRef(null),g=n,{series:a}=g,o=z(g,["series"]),s=u.default.useMemo(()=>m({series:P.formList(a!=null?a:[])},o),[a,o]),l=P.useForm({initialValues:s}),d=()=>l.addListItem("series",{type:"bar",name:I.randomId(),showSymbol:!1,y_axis_data_key:"value",stack:"",color:"#000"}),f=u.default.useMemo(()=>!T.default.isEqual(l.values,s),[l.values,s]);return u.default.useEffect(()=>{var x;f&&((x=r==null?void 0:r.current)==null||x.click())},[f,r.current]),e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:l.onSubmit(i),children:[c(t.Group,{position:"apart",mb:"lg",sx:{position:"relative"},children:[e(t.Text,{children:"Chart Config"}),e("button",{ref:r,type:"submit",style:{display:"none"},children:"Ghost submit"})]}),e(t.TextInput,m({size:"md",mb:"lg",label:"X Axis Data Key"},l.getInputProps("x_axis_data_key"))),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{mt:"xl",mb:0,children:"Series"}),l.values.series.map((x,h)=>c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[e(t.TextInput,m({label:"Label",required:!0,sx:{flex:1}},l.getListInputProps("series",h,"name"))),c(t.Group,{direction:"row",grow:!0,noWrap:!0,children:[e(t.TextInput,m({label:"Y Axis Data key",required:!0},l.getListInputProps("series",h,"y_axis_data_key"))),e(t.TextInput,m({label:"Stack ID",placeholder:"Stack bars by this ID"},l.getListInputProps("series",h,"stack")))]}),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{children:"Color"}),e(de,m({},l.getListInputProps("series",h,"color")))]}),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>l.removeListItem("series",h),sx:{position:"absolute",top:15,right:5},children:e(y.Trash,{size:16})})]},h)),e(t.Group,{position:"center",mt:"xs",children:e(t.Button,{onClick:d,children:"Add a Series"})})]})]})})}function st(a){var o=a,{conf:s}=o,l=s,{columns:n}=l,i=z(l,["columns"]),{setConf:r}=o;const d=P.useForm({initialValues:{label_field:"name",value_field:"value"}});return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:d.onSubmit(r),children:[c(t.Group,{position:"apart",mb:"lg",sx:{position:"relative"},children:[e(t.Text,{children:"Sunburst Config"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",children:e(y.DeviceFloppy,{size:20})})]}),c(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,p:"md",mb:"sm",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[e(t.TextInput,m({label:"Label Field",required:!0,sx:{flex:1}},d.getInputProps("label_field"))),e(t.TextInput,m({label:"Value Field",placeholder:"get column value by this field",required:!0,sx:{flex:1}},d.getInputProps("value_field")))]})]})})}const F=[{value:0,label:"xs"},{value:25,label:"sm"},{value:50,label:"md"},{value:75,label:"lg"},{value:100,label:"xl"}];function R({label:n,value:i,onChange:r}){var s,l;const[a,o]=u.default.useState((l=(s=F.find(d=>d.label===i))==null?void 0:s.value)!=null?l:F[0].value);return u.default.useEffect(()=>{const d=F.find(f=>f.value===a);d&&r(d.label)},[a]),c(t.Group,{direction:"column",grow:!0,spacing:"xs",mb:"lg",children:[e(t.Text,{children:n}),e(t.Slider,{label:null,marks:F,value:a,onChange:o,step:25,placeholder:"Pick a font size"})]})}const ut=Object.values(G).map(n=>({label:n,value:n}));function dt({label:n,value:i,onChange:r,sx:a}){return e(t.Select,{label:n,data:ut,value:i,onChange:r,sx:a})}function ct(a){var o=a,{conf:s}=o,l=s,{columns:n}=l,i=z(l,["columns"]),{setConf:r}=o;const d=P.useForm({initialValues:m({id_field:"id",use_raw_columns:!0,columns:P.formList(n!=null?n:[]),size:"sm",horizontalSpacing:"sm",verticalSpacing:"sm",striped:!1,highlightOnHover:!1},i)}),f=()=>d.addListItem("columns",{label:I.randomId(),value_field:"value",value_type:G.string});return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:d.onSubmit(r),children:[c(t.Group,{position:"apart",mb:"lg",sx:{position:"relative"},children:[e(t.Text,{children:"Table Config"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",children:e(y.DeviceFloppy,{size:20})})]}),c(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,p:"md",mb:"sm",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[e(t.TextInput,m({size:"md",mb:"lg",label:"ID Field"},d.getInputProps("id_field"))),c(t.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:[e(R,m({label:"Horizontal Spacing"},d.getInputProps("horizontalSpacing"))),e(R,m({label:"Vertical Spacing"},d.getInputProps("verticalSpacing")))]}),e(t.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:e(R,m({label:"Font Size"},d.getInputProps("size")))}),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{children:"Other"}),c(t.Group,{position:"apart",grow:!0,children:[e(t.Switch,m({label:"Striped"},d.getInputProps("striped",{type:"checkbox"}))),e(t.Switch,m({label:"Highlight on hover"},d.getInputProps("highlightOnHover",{type:"checkbox"})))]})]})]}),c(t.Group,{direction:"column",mt:"xs",spacing:"xs",grow:!0,p:"md",mb:"xl",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[e(t.Switch,m({label:"Use Original Data Columns"},d.getInputProps("use_raw_columns",{type:"checkbox"}))),!d.values.use_raw_columns&&c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{mt:"xl",mb:0,children:"Custom Columns"}),d.values.columns.map((g,x)=>c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[c(t.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:[e(t.TextInput,m({label:"Label",required:!0,sx:{flex:1}},d.getListInputProps("columns",x,"label"))),e(t.TextInput,m({label:"Value Field",placeholder:"get column value by this field",required:!0,sx:{flex:1}},d.getListInputProps("columns",x,"value_field"))),e(dt,m({label:"Value Type",sx:{flex:1}},d.getListInputProps("columns",x,"value_type")))]}),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>d.removeListItem("columns",x),sx:{position:"absolute",top:15,right:5},children:e(y.Trash,{size:16})})]},x)),e(t.Group,{position:"center",mt:"xs",children:e(t.Button,{onClick:f,children:"Add a Column"})})]})]}),e(t.Text,{weight:500,mb:"md",children:"Current Configuration:"}),e(A.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(d.values,null,2)})]})})}const Q=[{label:"initial",value:0},{label:"500",value:25},{label:"700",value:50},{label:"semibold",value:75},{label:"bold",value:100}];function pt({label:n,value:i,onChange:r}){var s,l;const[a,o]=u.default.useState((l=(s=Q.find(d=>d.label===i))==null?void 0:s.value)!=null?l:Q[0].value);return u.default.useEffect(()=>{const d=Q.find(f=>f.value===a);d&&r(d.label)},[a]),c(t.Group,{direction:"column",grow:!0,spacing:"xs",mb:"lg",children:[e(t.Text,{children:n}),e(t.Slider,{label:null,marks:Q,value:a,onChange:o,step:25,placeholder:"Pick a font size"})]})}const ce=[{align:"center",size:"xl",weight:"bold",color:"black",template:"Time: ${new Date().toISOString()}"},{align:"center",size:"md",weight:"bold",color:"red",template:"Platform: ${navigator.userAgentData.platform}."}];function mt({conf:n,setConf:i}){var o;const r=P.useForm({initialValues:{paragraphs:P.formList((o=n.paragraphs)!=null?o:ce)}}),a=()=>r.addListItem("paragraphs",q(m({},ce[0]),{template:I.randomId()}));return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:r.onSubmit(i),children:[r.values.paragraphs.length===0&&e(t.Text,{color:"dimmed",align:"center",children:"Empty"}),c(t.Group,{position:"apart",mb:"xs",sx:{" + .mantine-Group-root":{marginTop:0}},children:[e(t.Text,{children:"Paragraphs"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",children:e(y.DeviceFloppy,{size:20})})]}),r.values.paragraphs.map((s,l)=>c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[e(t.TextInput,m({placeholder:"Time: ${new Date().toISOString()}",label:"Content Template",required:!0,sx:{flex:1}},r.getListInputProps("paragraphs",l,"template"))),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{children:"Color"}),e(de,m({},r.getListInputProps("paragraphs",l,"color")))]}),c(t.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:[e(R,m({label:"Font Size"},r.getListInputProps("paragraphs",l,"size"))),e(pt,m({label:"Font Weight"},r.getListInputProps("paragraphs",l,"weight")))]}),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>r.removeListItem("paragraphs",l),sx:{position:"absolute",top:15,right:5},children:e(y.Trash,{size:16})})]},l)),e(t.Group,{position:"center",mt:"md",children:e(t.Button,{onClick:a,children:"Add a Paragraph"})}),e(t.Text,{size:"sm",weight:500,mt:"md",children:"Current Configuration:"}),e(A.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(r.values,null,2)})]})})}const Z=[{value:"text",label:"Text",Panel:mt},{value:"table",label:"Table",Panel:ct},{value:"sunburst",label:"Sunburst",Panel:st},{value:"bar-3d",label:"Bar Chart (3D)",Panel:lt},{value:"line-bar",label:"Line-Bar Chart",Panel:ot}];function ht(){const{viz:n,setViz:i}=u.default.useContext(L),[r,a]=I.useInputState(n.type),o=n.type!==r,s=u.default.useCallback(()=>{!o||i(g=>q(m({},g),{type:r}))},[o,r]),l=g=>{i(x=>q(m({},x),{conf:g}))},d=g=>{try{l(JSON.parse(g))}catch(x){console.error(x)}},f=u.default.useMemo(()=>{var g;return(g=Z.find(x=>x.value===r))==null?void 0:g.Panel},[r,Z]);return c(N,{children:[e(t.Select,{label:"Visualization",value:r,onChange:a,data:Z,rightSection:e(t.ActionIcon,{disabled:!o,onClick:s,children:e(y.DeviceFloppy,{size:20})})}),f&&e(f,{conf:n.conf,setConf:l}),!f&&e(t.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(n.conf,null,2),onChange:d})]})}function ft({}){return c(t.Group,{grow:!0,direction:"column",children:[e(at,{}),e(rt,{}),e(t.Divider,{}),e(ht,{})]})}function xt({}){const{freezeLayout:n}=u.default.useContext($),{data:i,loading:r,viz:a,title:o}=u.default.useContext(L),[s,l]=u.default.useState(!1),d=()=>l(!0);return u.default.useEffect(()=>{n(s)},[s]),c(N,{children:[e(t.Modal,{size:"96vw",overflow:"inside",opened:s,onClose:()=>l(!1),title:o,trapFocus:!0,onDragStart:f=>{f.stopPropagation()},children:e(t.AppShell,{sx:{height:"90vh",maxHeight:"calc(100vh - 185px)",".mantine-AppShell-body":{height:"100%"},main:{height:"100%",width:"100%"}},padding:"md",navbar:e(t.Navbar,{width:{base:"40%"},height:"100%",p:"xs",children:c(t.Tabs,{initialTab:1,children:[e(t.Tabs.Tab,{label:"Context",children:e(Xe,{})}),e(t.Tabs.Tab,{label:"SQL Snippets",children:e(it,{})}),e(t.Tabs.Tab,{label:"SQL",children:e(Ze,{})}),c(t.Tabs.Tab,{label:"Data",children:[e(t.LoadingOverlay,{visible:r}),e(et,{})]}),e(t.Tabs.Tab,{label:"Viz Config",children:e(ft,{})})]})}),children:e(ue,{viz:a,data:i,loading:r})})}),e(t.ActionIcon,{variant:"hover",color:"blue",loading:r,onClick:d,children:e(y.Settings,{size:16})})]})}function gt({title:n,description:i}){return c(t.Group,{position:"center",sx:{borderBottom:"1px solid #eee",paddingBottom:"5px"},children:[!i&&e(t.Text,{weight:"bold",sx:{marginLeft:"5px",display:"inline"},children:n}),i&&e("div",{children:c(t.Tooltip,{label:i,withArrow:!0,children:[e(y.InfoCircle,{size:12,style:{verticalAlign:"baseline",cursor:"pointer"}}),e(t.Text,{weight:"bold",sx:{marginLeft:"5px",display:"inline"},children:n})]})})]})}function bt({}){const{title:n,description:i,loading:r,refreshData:a}=u.default.useContext(L),{inEditMode:o}=u.default.useContext($);return c(N,{children:[e(gt,{title:n,description:i}),c(t.Group,{position:"right",spacing:0,sx:{position:"absolute",right:"15px",top:"4px",height:"28px"},children:[e(t.ActionIcon,{variant:"hover",color:"blue",loading:r,onClick:a,children:e(y.Refresh,{size:16})}),o&&e(xt,{})]})]})}var kt="";function pe({viz:n,sql:i,title:r,description:a}){const o=u.default.useContext(H),s=u.default.useContext(V),[l,d]=u.default.useState(r),[f,g]=u.default.useState(a),[x,h]=u.default.useState(i),[b,C]=u.default.useState(n),{data:_=[],loading:W,refresh:ee}=be.useRequest(Le(x,o,s),{refreshDeps:[o]}),te=ee;return e(L.Provider,{value:{data:_,loading:W,title:l,setTitle:d,description:f,setDescription:g,sql:x,setSQL:h,viz:b,setViz:C,refreshData:te},children:c(t.Container,{className:"panel-root",children:[e(bt,{}),e(ue,{viz:b,data:_,loading:W})]})})}var Gt="",Dt="",At="";const vt=w.WidthProvider(w.Responsive);function me({panels:n,className:i="layout",cols:r={lg:12,md:10,sm:8,xs:6,xxs:4},rowHeight:a=10,onRemoveItem:o,isDraggable:s,isResizable:l,setLocalCols:d,setBreakpoint:f}){return e(vt,{onBreakpointChange:(x,h)=>{f(x),d(h)},className:i,cols:r,rowHeight:a,isDraggable:s,isResizable:l,children:n.map(b=>{var C=b,{id:x}=C,h=z(C,["id"]);return e("div",{"data-grid":h.layout,children:e(pe,m({destroy:()=>o(x)},h))},x)})})}function he(n,i){return c(t.Text,{sx:{svg:{verticalAlign:"text-bottom"}},children:[n," ",i]})}function yt({mode:n,setMode:i}){return e(t.SegmentedControl,{value:n,onChange:i,data:[{label:he(e(y.PlayerPlay,{size:20}),"Use"),value:k.Use},{label:he(e(y.Paint,{size:20}),"Edit"),value:k.Edit}]})}function St({mode:n,setMode:i,addPanel:r}){const a=n===k.Edit;return c(t.Group,{position:"apart",pt:"sm",pb:"xs",children:[e(t.Group,{position:"left",children:e(yt,{mode:n,setMode:i})}),a&&c(t.Group,{position:"right",children:[e(t.Button,{variant:"default",size:"sm",onClick:r,leftIcon:e(y.PlaylistAdd,{size:20}),children:"Add a Panel"}),e(t.Button,{variant:"default",size:"sm",disabled:!0,leftIcon:e(y.DeviceFloppy,{size:20}),children:"Save Dashboard"}),e(t.Button,{color:"red",size:"sm",disabled:!0,leftIcon:e(y.Recycle,{size:20}),children:"Revert Changes"})]}),!a&&e(t.Button,{variant:"default",size:"sm",disabled:!0,leftIcon:e(y.Share,{size:20}),children:"Share"})]})}function Ct({dashboard:n,className:i="dashboard"}){const[r,a]=u.default.useState(!1),[o,s]=u.default.useState(0),[l,d]=u.default.useState(),[f,g]=u.default.useState(),[x,h]=u.default.useState(n.panels),[b,C]=u.default.useState(n.definition.sqlSnippets),[_,W]=u.default.useState(k.Edit),ee=()=>{console.log("adding","n"+o),s(re=>re+1);const J="n"+o,ie={id:J,layout:{x:x.length*2%(f||12),y:1/0,w:4,h:4},title:`New Panel - ${J}`,description:"description goes here",sql:"",viz:{type:"table",conf:{}}};h(re=>[...re,ie])},te=J=>{h(ie=>T.default.reject(ie,{id:J}))},ne=_===k.Edit;return e("div",{className:i,children:e(V.Provider,{value:{sqlSnippets:b,setSQLSnippets:C},children:c($.Provider,{value:{layoutFrozen:r,freezeLayout:a,mode:_,inEditMode:ne},children:[e(St,{mode:_,setMode:W,addPanel:ee}),e(me,{panels:x,isDraggable:ne&&!r,isResizable:ne&&!r,onRemoveItem:te,setLocalCols:g,setBreakpoint:d})]})})})}p.ContextInfoContext=H,p.Dashboard=Ct,p.DashboardLayout=me,p.DashboardMode=k,p.DefinitionContext=V,p.LayoutStateContext=$,p.Panel=pe,p.PanelContext=L,p.initialContextInfoContext=Ie,Object.defineProperties(p,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
21
|
+
`}),e(t.Text,{weight:700,children:"SQL Snippets"}),e(lt,{sqlSnippets:n,setSQLSnippets:i})]})}function st(){const{description:n,setDescription:i}=u.default.useContext(k),[r,a]=L.useInputState(n),o=n!==r,s=u.default.useCallback(()=>{!o||i(r)},[o,r]);return e(t.Textarea,{label:"Panel Description",value:r,onChange:a,minRows:2,rightSection:e(t.ActionIcon,{disabled:!o,onClick:s,sx:{alignSelf:"flex-start",marginTop:"4px"},children:e(S.DeviceFloppy,{size:20})})})}function ut(){const{title:n,setTitle:i}=u.default.useContext(k),[r,a]=L.useInputState(n),o=n!==r,s=u.default.useCallback(()=>{!o||i(r)},[o,r]);return e(t.TextInput,{label:"Panel Title",value:r,onChange:a,rightSection:e(t.ActionIcon,{disabled:!o,onClick:s,children:e(S.DeviceFloppy,{size:20})})})}function dt({conf:n,setConf:i}){const r=_.default.assign({},{x_axis_data_key:"x",y_axis_data_key:"y",z_axis_data_key:"z",xAxis3D:{type:"value",name:"X Axis Name"},yAxis3D:{type:"value",name:"Y Axis Name"},zAxis3D:{type:"value",name:"Z Axis Name"}},n),{control:a,handleSubmit:o,formState:s}=N.useForm({defaultValues:r});return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:o(i),children:[e(t.Text,{children:"X Axis"}),c(t.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[e(N.Controller,{name:"x_axis_data_key",control:a,render:({field:l})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Data Key"},l))}),e(N.Controller,{name:"xAxis3D.name",control:a,render:({field:l})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Name"},l))})]}),e(t.Text,{mt:"lg",children:"Y Axis"}),c(t.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[e(N.Controller,{name:"y_axis_data_key",control:a,render:({field:l})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Data Key"},l))}),e(N.Controller,{name:"yAxis3D.name",control:a,render:({field:l})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Name"},l))})]}),e(t.Text,{mt:"lg",children:"Z Axis"}),c(t.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[e(N.Controller,{name:"z_axis_data_key",control:a,render:({field:l})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Data Key"},l))}),e(N.Controller,{name:"zAxis3D.name",control:a,render:({field:l})=>e(t.TextInput,m({sx:{flexGrow:1},size:"md",label:"Name"},l))})]}),e(t.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:c(t.Button,{color:"blue",type:"submit",children:[e(S.DeviceFloppy,{size:20}),e(t.Text,{ml:"md",children:"Save"})]})})]})})}function he({value:n,onChange:i}){const r=t.useMantineTheme(),a=u.default.useMemo(()=>Object.entries(r.colors).map(([s,l])=>({label:s,value:l[6]})),[r]),o=u.default.useMemo(()=>a.some(s=>s.value===n),[n,a]);return c(t.Group,{position:"apart",spacing:"xs",children:[e(t.TextInput,{placeholder:"Set any color",value:o?"":n,onChange:s=>i(s.currentTarget.value),rightSection:e(t.ColorSwatch,{color:o?"transparent":n,radius:4}),variant:o?"filled":"default",sx:{maxWidth:"100%",flexGrow:1}}),e(t.Text,{sx:{flexGrow:0},children:"or"}),e(t.Select,{data:a,value:n,onChange:i,variant:o?"default":"filled",placeholder:"Pick a theme color",icon:e(t.ColorSwatch,{color:o?n:"transparent",radius:4}),sx:{maxWidth:"100%",flexGrow:1}})]})}function ct({conf:n,setConf:i}){const r=u.default.useRef(null),x=n,{series:a}=x,o=P(x,["series"]),s=u.default.useMemo(()=>m({series:I.formList(a!=null?a:[])},o),[a,o]),l=I.useForm({initialValues:s}),d=()=>l.addListItem("series",{type:"bar",name:L.randomId(),showSymbol:!1,y_axis_data_key:"value",stack:"",color:"#000"}),f=u.default.useMemo(()=>!_.default.isEqual(l.values,s),[l.values,s]);return u.default.useEffect(()=>{var b;f&&((b=r==null?void 0:r.current)==null||b.click())},[f,r.current]),e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:l.onSubmit(i),children:[c(t.Group,{position:"apart",mb:"lg",sx:{position:"relative"},children:[e(t.Text,{children:"Chart Config"}),e("button",{ref:r,type:"submit",style:{display:"none"},children:"Ghost submit"})]}),e(t.TextInput,m({size:"md",mb:"lg",label:"X Axis Data Key"},l.getInputProps("x_axis_data_key"))),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{mt:"xl",mb:0,children:"Series"}),l.values.series.map((b,h)=>c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[e(t.TextInput,m({label:"Label",required:!0,sx:{flex:1}},l.getListInputProps("series",h,"name"))),c(t.Group,{direction:"row",grow:!0,noWrap:!0,children:[e(t.TextInput,m({label:"Y Axis Data key",required:!0},l.getListInputProps("series",h,"y_axis_data_key"))),e(t.TextInput,m({label:"Stack ID",placeholder:"Stack bars by this ID"},l.getListInputProps("series",h,"stack")))]}),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{children:"Color"}),e(he,m({},l.getListInputProps("series",h,"color")))]}),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>l.removeListItem("series",h),sx:{position:"absolute",top:15,right:5},children:e(S.Trash,{size:16})})]},h)),e(t.Group,{position:"center",mt:"xs",children:e(t.Button,{onClick:d,children:"Add a Series"})})]})]})})}function pt(a){var o=a,{conf:s}=o,l=s,{columns:n}=l,i=P(l,["columns"]),{setConf:r}=o;const d=I.useForm({initialValues:{label_field:"name",value_field:"value"}});return e(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,children:c("form",{onSubmit:d.onSubmit(r),children:[c(t.Group,{position:"apart",mb:"lg",sx:{position:"relative"},children:[e(t.Text,{children:"Sunburst Config"}),e(t.ActionIcon,{type:"submit",mr:5,variant:"filled",color:"blue",children:e(S.DeviceFloppy,{size:20})})]}),c(t.Group,{direction:"column",mt:"md",spacing:"xs",grow:!0,p:"md",mb:"sm",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[e(t.TextInput,m({label:"Label Field",required:!0,sx:{flex:1}},d.getInputProps("label_field"))),e(t.TextInput,m({label:"Value Field",placeholder:"get column value by this field",required:!0,sx:{flex:1}},d.getInputProps("value_field")))]})]})})}const Y=[{value:0,label:"xs"},{value:25,label:"sm"},{value:50,label:"md"},{value:75,label:"lg"},{value:100,label:"xl"}];function K({label:n,value:i,onChange:r}){var s,l;const[a,o]=u.default.useState((l=(s=Y.find(d=>d.label===i))==null?void 0:s.value)!=null?l:Y[0].value);return u.default.useEffect(()=>{const d=Y.find(f=>f.value===a);d&&r(d.label)},[a]),c(t.Group,{direction:"column",grow:!0,spacing:"xs",mb:"lg",children:[e(t.Text,{children:n}),e(t.Slider,{label:null,marks:Y,value:a,onChange:o,step:25,placeholder:"Pick a font size"})]})}const mt=Object.values(O).map(n=>({label:n,value:n}));function ht({label:n,value:i,onChange:r,sx:a}){return e(t.Select,{label:n,data:mt,value:i,onChange:r,sx:a})}function ft(a){var o=a,{conf:s}=o,l=s,{columns:n}=l,i=P(l,["columns"]),{setConf:r}=o;const d=I.useForm({initialValues:m({id_field:"id",use_raw_columns:!0,columns:I.formList(n!=null?n:[]),size:"sm",horizontalSpacing:"sm",verticalSpacing:"sm",striped:!1,highlightOnHover:!1},i)}),f=()=>d.addListItem("columns",{label:L.randomId(),value_field:"value",value_type:O.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(S.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(K,m({label:"Horizontal Spacing"},d.getInputProps("horizontalSpacing"))),e(K,m({label:"Vertical Spacing"},d.getInputProps("verticalSpacing")))]}),e(t.Group,{position:"apart",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:e(K,m({label:"Font Size"},d.getInputProps("size")))}),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{children:"Other"}),c(t.Group,{position:"apart",grow:!0,children:[e(t.Switch,m({label:"Striped"},d.getInputProps("striped",{type:"checkbox"}))),e(t.Switch,m({label:"Highlight on hover"},d.getInputProps("highlightOnHover",{type:"checkbox"})))]})]})]}),c(t.Group,{direction:"column",mt:"xs",spacing:"xs",grow:!0,p:"md",mb:"xl",sx:{border:"1px solid #eee",borderRadius:"5px"},children:[e(t.Switch,m({label:"Use Original Data Columns"},d.getInputProps("use_raw_columns",{type:"checkbox"}))),!d.values.use_raw_columns&&c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{mt:"xl",mb:0,children:"Custom Columns"}),d.values.columns.map((x,b)=>c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[c(t.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:[e(t.TextInput,m({label:"Label",required:!0,sx:{flex:1}},d.getListInputProps("columns",b,"label"))),e(t.TextInput,m({label:"Value Field",placeholder:"get column value by this field",required:!0,sx:{flex:1}},d.getListInputProps("columns",b,"value_field"))),e(ht,m({label:"Value Type",sx:{flex:1}},d.getListInputProps("columns",b,"value_type")))]}),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>d.removeListItem("columns",b),sx:{position:"absolute",top:15,right:5},children:e(S.Trash,{size:16})})]},b)),e(t.Group,{position:"center",mt:"xs",children:e(t.Button,{onClick:f,children:"Add a Column"})})]})]}),e(t.Text,{weight:500,mb:"md",children:"Current Configuration:"}),e(M.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(d.values,null,2)})]})})}const X=[{label:"initial",value:0},{label:"500",value:25},{label:"700",value:50},{label:"semibold",value:75},{label:"bold",value:100}];function xt({label:n,value:i,onChange:r}){var s,l;const[a,o]=u.default.useState((l=(s=X.find(d=>d.label===i))==null?void 0:s.value)!=null?l:X[0].value);return u.default.useEffect(()=>{const d=X.find(f=>f.value===a);d&&r(d.label)},[a]),c(t.Group,{direction:"column",grow:!0,spacing:"xs",mb:"lg",children:[e(t.Text,{children:n}),e(t.Slider,{label:null,marks:X,value:a,onChange:o,step:25,placeholder:"Pick a font size"})]})}const fe=[{align:"center",size:"xl",weight:"bold",color:"black",template:"Time: ${new Date().toISOString()}"},{align:"center",size:"md",weight:"bold",color:"red",template:"Platform: ${navigator.userAgentData.platform}."}];function gt({conf:n,setConf:i}){var o;const r=I.useForm({initialValues:{paragraphs:I.formList((o=n.paragraphs)!=null?o:fe)}}),a=()=>r.addListItem("paragraphs",D(m({},fe[0]),{template:L.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(S.DeviceFloppy,{size:20})})]}),r.values.paragraphs.map((s,l)=>c(t.Group,{direction:"column",grow:!0,my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[e(t.TextInput,m({placeholder:"Time: ${new Date().toISOString()}",label:"Content Template",required:!0,sx:{flex:1}},r.getListInputProps("paragraphs",l,"template"))),c(t.Group,{direction:"column",grow:!0,children:[e(t.Text,{children:"Color"}),e(he,m({},r.getListInputProps("paragraphs",l,"color")))]}),c(t.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:[e(K,m({label:"Font Size"},r.getListInputProps("paragraphs",l,"size"))),e(xt,m({label:"Font Weight"},r.getListInputProps("paragraphs",l,"weight")))]}),e(t.ActionIcon,{color:"red",variant:"hover",onClick:()=>r.removeListItem("paragraphs",l),sx:{position:"absolute",top:15,right:5},children:e(S.Trash,{size:16})})]},l)),e(t.Group,{position:"center",mt:"md",children:e(t.Button,{onClick:a,children:"Add a Paragraph"})}),e(t.Text,{size:"sm",weight:500,mt:"md",children:"Current Configuration:"}),e(M.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(r.values,null,2)})]})})}const re=[{value:"text",label:"Text",Panel:gt},{value:"table",label:"Table",Panel:ft},{value:"sunburst",label:"Sunburst",Panel:pt},{value:"bar-3d",label:"Bar Chart (3D)",Panel:dt},{value:"line-bar",label:"Line-Bar Chart",Panel:ct}];function bt(){const{viz:n,setViz:i}=u.default.useContext(k),[r,a]=L.useInputState(n.type),o=n.type!==r,s=u.default.useCallback(()=>{!o||i(x=>D(m({},x),{type:r}))},[o,r]),l=x=>{i(b=>D(m({},b),{conf:x}))},d=x=>{try{l(JSON.parse(x))}catch(b){console.error(b)}},f=u.default.useMemo(()=>{var x;return(x=re.find(b=>b.value===r))==null?void 0:x.Panel},[r,re]);return c(W,{children:[e(t.Select,{label:"Visualization",value:r,onChange:a,data:re,rightSection:e(t.ActionIcon,{disabled:!o,onClick:s,children:e(S.DeviceFloppy,{size:20})})}),f&&e(f,{conf:n.conf,setConf:l}),!f&&e(t.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(n.conf,null,2),onChange:d})]})}function vt({}){return c(t.Group,{grow:!0,direction:"column",children:[e(ut,{}),e(st,{}),e(t.Divider,{}),e(bt,{})]})}function yt({}){const{freezeLayout:n}=u.default.useContext(R),{data:i,loading:r,viz:a,title:o}=u.default.useContext(k),[s,l]=u.default.useState(!1),d=()=>l(!0);return u.default.useEffect(()=>{n(s)},[s]),c(W,{children:[e(t.Modal,{size:"96vw",overflow:"inside",opened:s,onClose:()=>l(!1),title:o,trapFocus:!0,onDragStart:f=>{f.stopPropagation()},children:e(t.AppShell,{sx:{height:"90vh",maxHeight:"calc(100vh - 185px)",".mantine-AppShell-body":{height:"100%"},main:{height:"100%",width:"100%"}},padding:"md",navbar:e(t.Navbar,{width:{base:"40%"},height:"100%",p:"xs",children:c(t.Tabs,{initialTab:1,children:[e(t.Tabs.Tab,{label:"Context",children:e(tt,{})}),e(t.Tabs.Tab,{label:"SQL Snippets",children:e(ot,{})}),e(t.Tabs.Tab,{label:"SQL",children:e(it,{})}),c(t.Tabs.Tab,{label:"Data",children:[e(t.LoadingOverlay,{visible:r}),e(rt,{})]}),e(t.Tabs.Tab,{label:"Viz Config",children:e(vt,{})})]})}),children:e(pe,{children:e(me,{viz:a,data:i,loading:r})})})}),e(t.ActionIcon,{variant:"hover",color:"blue",loading:r,onClick:d,children:e(S.Settings,{size:16})})]})}function St({title:n,description:i}){return c(t.Group,{position:"center",sx:{borderBottom:"1px solid #eee",paddingBottom:"5px"},children:[!i&&e(t.Text,{weight:"bold",sx:{marginLeft:"5px",display:"inline"},children:n}),i&&e("div",{children:c(t.Tooltip,{label:i,withArrow:!0,children:[e(S.InfoCircle,{size:12,style:{verticalAlign:"baseline",cursor:"pointer"}}),e(t.Text,{weight:"bold",sx:{marginLeft:"5px",display:"inline"},children:n})]})})]})}function Ct({}){const{title:n,description:i,loading:r,refreshData:a}=u.default.useContext(k),{inEditMode:o}=u.default.useContext(R);return c(W,{children:[e(St,{title:n,description:i}),c(t.Group,{position:"right",spacing:0,sx:{position:"absolute",right:"15px",top:"4px",height:"28px"},children:[e(t.ActionIcon,{variant:"hover",color:"blue",loading:r,onClick:a,children:e(S.Refresh,{size:16})}),o&&e(yt,{})]})]})}var qt="";function xe({viz:n,sql:i,title:r,description:a,update:o,layout:s,id:l}){const d=u.default.useContext(ie),f=u.default.useContext(U),[x,b]=u.default.useState(r),[h,g]=u.default.useState(a),[v,z]=u.default.useState(i),[w,q]=u.default.useState(n);u.default.useEffect(()=>{o({id:l,layout:s,title:x,description:h,sql:v,viz:w})},[x,h,v,w,l,s]);const{data:$=[],loading:B,refresh:ae}=Ce.useRequest(De(v,d,f,x),{refreshDeps:[d,f]}),le=ae;return e(k.Provider,{value:{data:$,loading:B,title:x,setTitle:b,description:h,setDescription:g,sql:v,setSQL:z,viz:w,setViz:q,refreshData:le},children:c(t.Container,{className:"panel-root",children:[e(Ct,{}),e(pe,{children:e(me,{viz:w,data:$,loading:B})})]})})}var At="";const wt=T.WidthProvider(T.Responsive);function ge({panels:n,setPanels:i,className:r="layout",cols:a={lg:12,md:10,sm:8,xs:6,xxs:4},rowHeight:o=10,onRemoveItem:s,isDraggable:l,isResizable:d,setLocalCols:f,setBreakpoint:x}){const b=(g,v)=>{x(g),f(v)},h=u.default.useCallback(g=>{const v=new Map;g.forEach($=>{var B=$,{i:w}=B,q=P(B,["i"]);v.set(w,q)});const z=n.map(w=>D(m({},w),{layout:v.get(w.id)}));i.setState(z)},[n,i]);return e(wt,{onBreakpointChange:b,onLayoutChange:h,className:r,cols:a,rowHeight:o,isDraggable:l,isResizable:d,children:n.map((w,z)=>{var q=w,{id:g}=q,v=P(q,["id"]);return e("div",{"data-grid":v.layout,children:e(xe,D(m({id:g},v),{destroy:()=>s(g),update:$=>{i.setItem(z,$)}}))},g)})})}function be(n,i){return c(t.Text,{sx:{svg:{verticalAlign:"text-bottom"}},children:[n," ",i]})}function Tt({mode:n,setMode:i}){return e(t.SegmentedControl,{value:n,onChange:i,data:[{label:be(e(S.PlayerPlay,{size:20}),"Use"),value:E.Use},{label:be(e(S.Paint,{size:20}),"Edit"),value:E.Edit}]})}function _t({mode:n,setMode:i,hasChanges:r,addPanel:a,saveChanges:o}){const s=n===E.Edit;return c(t.Group,{position:"apart",pt:"sm",pb:"xs",children:[e(t.Group,{position:"left",children:e(Tt,{mode:n,setMode:i})}),s&&c(t.Group,{position:"right",children:[e(t.Button,{variant:"default",size:"sm",onClick:a,leftIcon:e(S.PlaylistAdd,{size:20}),children:"Add a Panel"}),e(t.Button,{variant:"default",size:"sm",onClick:o,disabled:!r,leftIcon:e(S.DeviceFloppy,{size:20}),children:"Save Changes"}),e(t.Button,{color:"red",size:"sm",disabled:!r,leftIcon:e(S.Recycle,{size:20}),children:"Revert Changes"})]}),!s&&e(t.Button,{variant:"default",size:"sm",disabled:!0,leftIcon:e(S.Share,{size:20}),children:"Share"})]})}function zt({dashboard:n,update:i,className:r="dashboard"}){const[a,o]=u.default.useState(!1),[s,l]=u.default.useState(0),[d,f]=u.default.useState(),[x,b]=u.default.useState(),[h,g]=L.useListState(n.panels),[v,z]=u.default.useState(n.definition.sqlSnippets),[w,q]=u.default.useState(E.Edit),$=u.default.useMemo(()=>{const G=j=>JSON.parse(JSON.stringify(j));return _.default.isEqual(G(h),G(n.panels))?!_.default.isEqual(v,n.definition.sqlSnippets):!0},[n,h,v]),B=async()=>{const G=_.default.merge({},n,{panels:h},{definition:{sqlSnippets:v}});await i(G)},ae=()=>{console.log("adding","n"+s),l(j=>j+1);const G="n"+s,H={id:G,layout:{x:h.length*2%(x||12),y:1/0,w:4,h:4},title:`New Panel - ${G}`,description:"description goes here",sql:"",viz:{type:"table",conf:{}}};g.append(H)},le=G=>{const H=h.findIndex(j=>j.id===G);g.remove(H)},oe=w===E.Edit,Pt=u.default.useMemo(()=>({sqlSnippets:v,setSQLSnippets:z}),[v,z]);return e("div",{className:r,children:e(U.Provider,{value:Pt,children:c(R.Provider,{value:{layoutFrozen:a,freezeLayout:o,mode:w,inEditMode:oe},children:[e(_t,{mode:w,setMode:q,hasChanges:$,addPanel:ae,saveChanges:B}),e(ge,{panels:h,setPanels:g,isDraggable:oe&&!a,isResizable:oe&&!a,onRemoveItem:le,setLocalCols:b,setBreakpoint:f})]})})})}p.ContextInfoContext=ie,p.Dashboard=zt,p.DashboardLayout=ge,p.DashboardMode=E,p.DefinitionContext=U,p.LayoutStateContext=R,p.Panel=xe,p.PanelContext=k,p.initialContextInfoContext=Ee,Object.defineProperties(p,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/dist/layout/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { IDashboardPanel } from "../types/dashboard";
|
|
3
|
+
import { UseListStateHandlers } from "@mantine/hooks";
|
|
3
4
|
interface IDashboardLayout {
|
|
4
5
|
panels: IDashboardPanel[];
|
|
6
|
+
setPanels: UseListStateHandlers<IDashboardPanel>;
|
|
5
7
|
className?: string;
|
|
6
8
|
cols?: {
|
|
7
9
|
lg: number;
|
|
@@ -17,5 +19,5 @@ interface IDashboardLayout {
|
|
|
17
19
|
setLocalCols: React.Dispatch<React.SetStateAction<any>>;
|
|
18
20
|
setBreakpoint: React.Dispatch<React.SetStateAction<any>>;
|
|
19
21
|
}
|
|
20
|
-
export declare function DashboardLayout({ panels, className, cols, rowHeight, onRemoveItem, isDraggable, isResizable, setLocalCols, setBreakpoint, }: IDashboardLayout): JSX.Element;
|
|
22
|
+
export declare function DashboardLayout({ panels, setPanels, className, cols, rowHeight, onRemoveItem, isDraggable, isResizable, setLocalCols, setBreakpoint, }: IDashboardLayout): JSX.Element;
|
|
21
23
|
export {};
|
package/dist/main/actions.d.ts
CHANGED
|
@@ -3,7 +3,9 @@ import { DashboardMode } from "../types";
|
|
|
3
3
|
interface IDashboardActions {
|
|
4
4
|
mode: DashboardMode;
|
|
5
5
|
setMode: React.Dispatch<React.SetStateAction<DashboardMode>>;
|
|
6
|
+
hasChanges: boolean;
|
|
6
7
|
addPanel: () => void;
|
|
8
|
+
saveChanges: () => void;
|
|
7
9
|
}
|
|
8
|
-
export declare function DashboardActions({ mode, setMode, addPanel, }: IDashboardActions): JSX.Element;
|
|
10
|
+
export declare function DashboardActions({ mode, setMode, hasChanges, addPanel, saveChanges, }: IDashboardActions): JSX.Element;
|
|
9
11
|
export {};
|
package/dist/main/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { IDashboard } from "../types/dashboard";
|
|
|
3
3
|
interface IDashboardProps {
|
|
4
4
|
dashboard: IDashboard;
|
|
5
5
|
className?: string;
|
|
6
|
+
update: (dashboard: IDashboard) => Promise<void>;
|
|
6
7
|
}
|
|
7
|
-
export declare function Dashboard({ dashboard, className, }: IDashboardProps): JSX.Element;
|
|
8
|
+
export declare function Dashboard({ dashboard, update, className, }: IDashboardProps): JSX.Element;
|
|
8
9
|
export {};
|
package/dist/panel/index.d.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import {
|
|
3
|
-
interface IPanel {
|
|
4
|
-
layout: any;
|
|
2
|
+
import { IDashboardPanel } from '../types/dashboard';
|
|
3
|
+
interface IPanel extends IDashboardPanel {
|
|
5
4
|
destroy: () => void;
|
|
6
|
-
|
|
7
|
-
viz: IVizConfig;
|
|
8
|
-
title: string;
|
|
9
|
-
description: string;
|
|
5
|
+
update: (panel: IDashboardPanel) => void;
|
|
10
6
|
}
|
|
11
|
-
export declare function Panel({ viz: initialViz, sql: initialSQL, title: initialTitle, description: initialDesc }: IPanel): JSX.Element;
|
|
7
|
+
export declare function Panel({ viz: initialViz, sql: initialSQL, title: initialTitle, description: initialDesc, update, layout, id, }: IPanel): JSX.Element;
|
|
12
8
|
export {};
|
package/dist/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.viz-root{width:100%;overflow:scroll;padding-top:10px;height:calc(100% - 30px);background-color:#fff}.sql-query-editor-root textarea{font-family:monospace}.panel-root{padding:5px;height:100%;width:100%;max-width:100%}.mantine-Tabs-root{width:100%;height:calc(100% - 25px);overflow:hidden;display:flex;justify-content:flex-start;flex-direction:column;flex-wrap:nowrap}.mantine-Tabs-tabsListWrapper{flex:0}.mantine-Tabs-body{flex:1;overflow:scroll}.react-grid-
|
|
1
|
+
.viz-root{width:100%;overflow:scroll;padding-top:10px;height:calc(100% - 30px);background-color:#fff}.sql-query-editor-root textarea{font-family:monospace}.panel-root{padding:5px;height:100%;width:100%;max-width:100%}.mantine-Tabs-root{width:100%;height:calc(100% - 25px);overflow:hidden;display:flex;justify-content:flex-start;flex-direction:column;flex-wrap:nowrap}.mantine-Tabs-tabsListWrapper{flex:0}.mantine-Tabs-body{flex:1;overflow:scroll}.react-grid-item{padding:0}.react-grid-item:not(.react-grid-placeholder){background:transparent;border-radius:5px;box-shadow:0 0 10px #0003}.remove-panel{position:absolute;right:2px;top:0;cursor:pointer}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devtable/dashboard",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -26,10 +26,7 @@
|
|
|
26
26
|
"build": "tsc && vite build",
|
|
27
27
|
"preview": "vite preview"
|
|
28
28
|
},
|
|
29
|
-
"dependencies": {
|
|
30
|
-
"react": "^18.0.0",
|
|
31
|
-
"react-dom": "^18.0.0"
|
|
32
|
-
},
|
|
29
|
+
"dependencies": {},
|
|
33
30
|
"devDependencies": {
|
|
34
31
|
"@mantine/core": "^4.2.5",
|
|
35
32
|
"@mantine/dates": "^4.2.5",
|