@devtable/dashboard 10.58.1 → 10.58.2
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 +5 -2
- package/dist/dashboard.umd.js +2 -2
- package/dist/stats.html +1 -1
- package/package.json +1 -1
package/dist/dashboard.es.js
CHANGED
|
@@ -1317,7 +1317,7 @@ class Mi {
|
|
|
1317
1317
|
}), this.instanceRegistry.clear(), this.factoryRegistry.clear();
|
|
1318
1318
|
}
|
|
1319
1319
|
}
|
|
1320
|
-
const Jl = "10.58.
|
|
1320
|
+
const Jl = "10.58.2", am = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1321
1321
|
__proto__: null,
|
|
1322
1322
|
version: Jl
|
|
1323
1323
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
@@ -31354,7 +31354,10 @@ const nA = k(() => /* @__PURE__ */ r.jsx(w, { sx: {
|
|
|
31354
31354
|
lg: 300,
|
|
31355
31355
|
xl: 320
|
|
31356
31356
|
}, sx: {
|
|
31357
|
-
height: "100vh - 60px - 60px"
|
|
31357
|
+
height: "100vh - 60px - 60px",
|
|
31358
|
+
".mantine-NavLink-body": {
|
|
31359
|
+
wordWrap: "break-word"
|
|
31360
|
+
}
|
|
31358
31361
|
}, children: [
|
|
31359
31362
|
/* @__PURE__ */ r.jsx(Nt.Section, { pt: 9, pb: 8, sx: {
|
|
31360
31363
|
borderBottom: "1px solid #eee"
|
package/dist/dashboard.umd.js
CHANGED
|
@@ -51,7 +51,7 @@ Check the top-level render call using <`+A+">.")}return D}}function xc(v,D){{if(
|
|
|
51
51
|
${du.map(pu).join("")}
|
|
52
52
|
</tbody>
|
|
53
53
|
</table>
|
|
54
|
-
`;function os(e,t){const n=Object.keys(t),r=Object.values(t);try{return new Function(...n,`return \`${e}\`;`)(...r)}catch(i){throw n.length===0&&e.includes("$")?new Error("[formatSQL] insufficient payload"):i}}function ls(e,t){try{return os(e,t)}catch(n){return console.error(n),n.message}}function xu({sql:e,pre_process:t}){if(!t.trim())return e;try{return new Function(`return ${t}`)()({sql:e},gt)}catch(n){return console.error(n),e}}function fu(e,t,n){if(!e.trim())return t;try{return new Function(`return ${e}`)()(t,gt,n)}catch(r){return console.error(r),t}}function gu(e){e=e||{};const t=Object.keys(e).sort(),n=[];for(let r=0;r<t.length;r++){const i=t[r];if(i!="authentication"&&e[i])n.push(t[r]+"="+(typeof e[i]=="object"?JSON.stringify(e[i]):e[i]));else{const o=Object.keys(e[i]).sort();for(let l=0;l<o.length;l++){const c=o[l];c!="sign"&&e[i][c]&&n.push(o[l]+"="+(typeof e[i][c]=="object"?JSON.stringify(e[i][c]):e[i][c]))}}}return n.sort().join("&")}function mu(e,t){let n=gu(e);return n+="&key="+t,ou.MD5(n).toString().toUpperCase()}class ji{constructor(){this.type="default_api_client",this.baseURL="http://localhost:31200",this.app_id="",this.app_secret=""}getAuthentication(t){if(!this.app_id||!this.app_secret)return;const n=new Date().getTime().toString();return{app_id:this.app_id,nonce_str:n,sign:mu({app_id:this.app_id,nonce_str:n,...t},this.app_secret)}}getRequest(t,n){return(r,i,o,l)=>{const c=this.buildHeader(o),u=this.buildAxiosConfig(t,r,i,o,c,n);return tt(u).then(d=>l?d:d.data).catch(d=>Promise.reject(d))}}get(t){return this.getRequest("GET",t)}post(t){return this.getRequest("POST",t)}put(t){return this.getRequest("PUT",t)}buildAxiosConfig(t,n,r,i,o,l){const c={baseURL:this.baseURL,method:t,url:n,params:t==="GET"?r:i.params,headers:o,signal:l};return["POST","PUT"].includes(t)&&(c.data=i.string?JSON.stringify(r):r,c.data.authentication=this.getAuthentication(c.data)),c}buildHeader(t){const n=window.localStorage.getItem("token");return{"X-Requested-With":"XMLHttpRequest","Content-Type":t.string?"application/x-www-form-urlencoded":"application/json",authorization:n?`bearer ${n}`:"",...t.headers}}}class yu{constructor(t){this.implementation=t}getRequest(t,n){return this.implementation.getRequest(t,n)}get(t){return this.getRequest("GET",t)}post(t){return this.getRequest("POST",t)}put(t){return this.getRequest("PUT",t)}}class vi extends ji{constructor(){super(...arguments);E(this,"makeQueryENV",null)}query(n){return async(r,i={})=>{var o;return r.env||(r.env=((o=this.makeQueryENV)==null?void 0:o.call(this))??{error:"failed to run makeQueryENV"}),this.post(n)("/query",r,i)}}httpDataSourceQuery(n){return async(r,i={})=>{var o;return r.env||(r.env=((o=this.makeQueryENV)==null?void 0:o.call(this))??{error:"failed to run makeQueryENV"}),this.getRequest("POST",n)("/query",r,i,!0)}}structure(n){return async(r,i={})=>this.post(n)("/query/structure",r,i)}}class wi{constructor(t){this.implementation=t}query(t){return this.implementation.query(t)}httpDataSourceQuery(t){return this.implementation.httpDataSourceQuery(t)}structure(t){return this.implementation.structure(t)}getRequest(t,n){return this.implementation.getRequest(t,n)}get(t){return this.getRequest("GET",t)}post(t){return this.getRequest("POST",t)}put(t){return this.getRequest("PUT",t)}}const Dt=new vi;function cs(e){Dt.baseURL!==e.apiBaseURL&&(Dt.baseURL=e.apiBaseURL),e.app_id&&(Dt.app_id=e.app_id),e.app_secret&&(Dt.app_secret=e.app_secret),e.makeQueryENV&&(Dt.makeQueryENV=e.makeQueryENV)}const Ci=new wi(Dt),Xe=Ci;function Si(){return{filters:{},context:{}}}function us(e){const t=Si();if(!e)return Si();const{filters:n=t.filters,context:r=t.context}=e;return{filters:n,context:r}}function bu(e,t){const n=Hr.decode(t);n!==e&&(console.error("Inconsistent sql"),console.groupCollapsed("Inconsistent sql"),console.table({before:e,after:t,v:n}),console.groupEnd())}async function ju({query:e,name:t,payload:n,additionals:r},i){if(!e.sql)return[];const{type:o,key:l,sql:c,pre_process:u,post_process:d}=e,p=os(c,n),h=xu({sql:p,pre_process:u}),x=Hr.encode(h);bu(h,x);let m=await Xe.query(i)({type:o,key:l,query:x,...r},{params:{name:t}});return m=fu(d,m,us(n)),m}async function vu({type:e,key:t,configString:n,name:r,additionals:i},o){try{return await Xe.httpDataSourceQuery(o)({type:e,key:t,query:n,...i},{params:{name:r}})}catch(l){if(tt.isCancel(l))throw l;return console.error(l),l}}async function ds(){try{return(await Xe.post()("/datasource/list",{filter:{},sort:[{field:"create_time",order:"ASC"}],pagination:{page:1,pagesize:100}},{})).data}catch(e){return console.error(e),[]}}async function _i(){try{return(await Xe.post()("/sql_snippet/list",{filter:{},sort:[{field:"id",order:"ASC"}],pagination:{page:1,pagesize:1e3}},{})).data}catch(e){return console.error(e),[]}}class ki{constructor(t){E(this,"rootRef");this.rootRef=W.observable({current:t})}async deleteItem(t){W.runInAction(()=>{y.unset(this.rootRef.current,[t])})}getItem(t){const n=this.getValueFromRoot(t);return Promise.resolve(n)}getValueFromRoot(t){return t===null?W.toJS(this.rootRef.current):y.get(this.rootRef.current,[t])}setItem(t,n){if(t===null)if(y.isObject(n))W.runInAction(()=>{this.rootRef.current=n});else throw new Error("Cannot set root value to non-object");else W.runInAction(()=>{y.set(this.rootRef.current,[t],n)});return Promise.resolve(this.getItem(t))}watchItem(t,n,r){return W.reaction(()=>this.getValueFromRoot(t),(i,o)=>{n(i,o)},{requiresObservable:!0,fireImmediately:y.get(r,"fireImmediately",!1)})}}class wu{constructor(){E(this,"channels",new Map);E(this,"globalChannel",new ei)}getChannel(t){const n=this.channels.get(t);if(n)return n;const r=new ei;return this.channels.set(t,r),r}}class Cu{constructor(t){E(this,"instances",new Map);this.pluginManager=t}get availableVizList(){return this.pluginManager.installedPlugins.flatMap(t=>t.manifest.viz)}resolveComponent(t){return this.pluginManager.factory.viz(t)}getOrCreateInstance(t){const n=this.instances.get(t.id);if(n)return n;const r={id:t.id,name:t.viz.type,type:t.viz.type,messageChannels:new wu,instanceData:new ki(t.viz.conf)};return this.instances.set(t.id,r),r}}function Ti(e,t,n,r){return{vizManager:n,locale:"zh",msgChannels:e.messageChannels,instanceData:e.instanceData,pluginData:new ki({}),colorPalette:{getColor(){return()=>""}},data:t,variables:r}}const Su=e=>{const{panel:t,vizManager:n,data:r,variables:i}=e,o=n.resolveComponent(t.viz.type),l=n.getOrCreateInstance(t),c={...Ti(l,r,n,i),viewport:{width:t.layout.w,height:t.layout.h}},u=o.viewRender;return s.jsx(u,{context:c,instance:l,...y.omit(e,["panel","vizManager","data"])})},_u=e=>{const{vizManager:t,panel:n,data:r,variables:i}=e,o=t.resolveComponent(n.viz.type),l=t.getOrCreateInstance(n),c={...Ti(l,r,t,i)},u=o.configRender;return s.jsx(u,{context:c,instance:l,...y.omit(e,["panel","vizManager","data"])})},Di=(e,t)=>{const n=nt.bezier(e),r=nt.bezier(t);return function(i){return i<50?n(i*2/100).hex():r((i-50)*2/100).hex()}},un=e=>{const t=nt.bezier(e);return function(n){return t(n/100).hex()}},ku={type:"interpolation",displayName:"Red / Green",getColor:Di(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},Tu={type:"interpolation",displayName:"Yellow / Blue",getColor:Di(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},Du={type:"interpolation",displayName:"Red",getColor:un(["#fff7f1","darkred"]),name:"red",category:"sequential"},Iu={type:"interpolation",displayName:"Green",getColor:un(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},Mu={type:"interpolation",displayName:"Blue",getColor:un(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},zu={type:"interpolation",displayName:"Orange",getColor:un(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class Au{constructor(t){E(this,"symbol");this.symbol=Symbol(t)}}function st(e){return new Au(e)}class ps{constructor(){E(this,"parent");E(this,"factoryRegistry",new Map);E(this,"instanceRegistry",new Map)}createScoped(){const t=new ps;return t.parent=this,t}getRequired(t){return this.get(t)}get(t){if(this.instanceRegistry.has(t.symbol))return this.instanceRegistry.get(t.symbol);const n=this.factoryRegistry.get(t.symbol);if(n){const r=n(this);return this.instanceRegistry.set(t.symbol,r),r}if(this.parent)return this.parent.get(t)}provideFactory(t,n){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,n),this}provideValue(t,n){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,()=>n),this}dispose(){this.instanceRegistry.forEach(t=>{const n=y.get(t,"dispose");y.isFunction(n)&&n.bind(t)()}),this.instanceRegistry.clear(),this.factoryRegistry.clear()}}const Ii="10.58.1",Eu=Object.freeze(Object.defineProperty({__proto__:null,version:Ii},Symbol.toStringTag,{value:"Module"}));class Pu{constructor(t){E(this,"staticColors",new Map);E(this,"interpolations",new Map);t.installedPlugins.forEach(n=>{n.manifest.color.forEach(r=>{this.register(r)})})}getStaticColors(){return Array.from(this.staticColors.values())}register(t){const n=this.encodeColor(t);t.type==="single"?(this.staticColors.has(n)&&console.warn(`the color '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.staticColors.set(n,t)):t.type==="interpolation"&&(this.interpolations.has(n)&&console.warn(`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`,`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.interpolations.set(n,t))}decodeStaticColor(t){return this.staticColors.get(t)}encodeColor(t){return`\${${t.category}}.{${t.name}}`}decodeInterpolation(t){return this.interpolations.get(t)}getColorInterpolations(){return Array.from(this.interpolations.values())}}class Lu{constructor(){E(this,"plugins",new Map);E(this,"vizComponents",new Map);E(this,"factory",{viz:t=>{const n=this.vizComponents.get(t);if(n)return n;throw new Error(`Viz Component (${t}) not found`)}})}install(t){if(this.plugins.has(t.id))throw new Error(`Plugin (${t.id}) has been installed before`);this.plugins.set(t.id,t);for(const n of t.manifest.viz){if(this.vizComponents.has(n.name))throw new Error(`Viz Component (${n.name}) has been installed before`);this.vizComponents.set(n.name,n)}}get installedPlugins(){return Array.from(this.plugins.values())}}class Ou{constructor(){E(this,"migrations",[])}version(t,n){return this.migrations.push({version:t,handler:n}),this}run(t,n,r){var l;if(t.from===t.to)return n;if(t.from>t.to)throw new Error(`Can not downgrade from version '${t.from}' to (${t.to})`);const i=this.migrations.filter(c=>c.version>t.from&&c.version<=t.to),o=y.orderBy(i,"version","asc");if(((l=y.last(o))==null?void 0:l.version)!==t.to)throw new Error(`Migration to version ${t.to} not found`);return o.reduce((c,u)=>u.handler(c,r),n)}}class ie extends Ou{constructor(){super(),this.configVersions()}version(t,n){return super.version(t,(r,i)=>({version:t,...n(r,i)}))}async migrate({configData:t,panelModel:n}){const r=await t.getItem(null),i=y.get(r,"version",0),o=this.run({from:i,to:this.VERSION},r,{panelModel:n});await t.setItem(null,o)}async needMigration({configData:t}){const n=await t.getItem(null);return y.get(n,"version",0)<this.VERSION}}const $=(e,t)=>{const[n,{setFalse:r}]=V.useBoolean(!0),[i,o]=f.useState();f.useEffect(()=>(e.getItem(t).then(c=>{o(c),r()}),e.watchItem(t,c=>{o(c)})));const l=f.useCallback(async c=>{await e.setItem(t,c),o(c)},[e,t]);return{loading:n,value:i,set:l}},Te={top:16,right:16,bottom:16,left:16},We=e=>Math.max(0,e-Te.left-Te.right),Re=e=>Math.max(0,e-Te.top-Te.bottom),Wt=(e,t)=>({width:We(e),height:Re(t)}),De=({width:e,height:t,children:n})=>s.jsx(a.Box,{pt:Te.top,pr:Te.right,pb:Te.bottom,pl:Te.left,sx:{width:e,height:t,overflow:"hidden",position:"relative"},children:n});function z(e){const[t,n]=e.split(".");return{queryID:t,columnKey:n}}function Bu(e){return e.includes(".")?z(e):{queryID:"",columnKey:e}}function rt(e,t){var i;const{queryID:n,columnKey:r}=z(t);return n?r?((i=e[n])==null?void 0:i.map(o=>o[r]))??[]:e[n]:[]}function Rt(e,t){const{queryID:n}=z(t);return n?e[n]:[]}function $u(e){return Object.values(e)[0]}function dn(e,t){const{queryID:n,columnKey:r}=z(t);return e[r]}const hs={x_axis_data_key:"",y_axis_data_key:"",z_axis_data_key:"",xAxis3D:{type:"value",name:"X Axis Name"},yAxis3D:{type:"value",name:"Y Axis Name"},zAxis3D:{type:"value",name:"Z Axis Name"}};U.use([O.GridComponent,O.VisualMapComponent,O.LegendComponent,O.TooltipComponent,Ce.CanvasRenderer]);function Vu({context:e}){const{value:t}=$(e.instanceData,"config"),n=e.data,{width:r,height:i}=e.viewport,{x_axis_data_key:o,y_axis_data_key:l,z_axis_data_key:c,xAxis3D:u,yAxis3D:d,zAxis3D:p}=y.defaults({},t,hs),h=f.useMemo(()=>Rt(n,o),[n,o]),{x,y:m,z:j}=f.useMemo(()=>({x:z(o),y:z(l),z:z(c)}),[o,l,c]),{min:w,max:T}=f.useMemo(()=>{const P=y.minBy(h,re=>re[j.columnKey]),K=y.maxBy(h,re=>re[j.columnKey]);return{min:y.get(P,j.columnKey),max:y.get(K,j.columnKey)}},[h,j]),M={tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:w,max:T,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:u,yAxis3D:d,zAxis3D:p,grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}},series:[{type:"bar3D",wireframe:{},data:h.map(P=>[P[x.columnKey],P[m.columnKey],P[j.columnKey]])}]};return t?s.jsx(De,{width:r,height:i,children:s.jsx(we,{echarts:U,option:M,style:Wt(r,i),notMerge:!0,theme:"merico-light"})}):null}const Mi=f.createContext(null),xs=Mi.Provider;function fs(){const e=f.useContext(Mi);if(!e)throw new Error("Please use DashboardModelContextProvider");return e}const Y=()=>fs(),gs=()=>fs(),zi=f.createContext({searchButtonProps:{}}),ms=zi.Provider;function Ai(){return f.useContext(zi)}const Ei=f.createContext(null),ys=Ei.Provider;function Pi(){const e=f.useContext(Ei);if(!e)throw new Error("Please use ContentModelContextProvider");return e}const X=()=>Pi(),ce=()=>Pi(),qu={inEditMode:!1},pn=f.createContext(qu),Li=f.createContext({panel:null,data:{},loading:!1,errors:[],downloadPanelScreenshot:()=>{}}),bs=Li.Provider;function Oi(){const e=f.useContext(Li);if(!e.panel)throw new Error("Please use PanelContextProvider");return e}const dt=()=>Oi(),Le=()=>Oi(),Nu={fullScreenPanelID:"",setFullScreenPanelID:y.noop},js=f.createContext(Nu);function Bi(){const e=f.useContext(js);if(!e)throw new Error("Please use FullScreenPanelContext.Provider");return e}const B=S.observer(f.forwardRef(({label:e,required:t,value:n,onChange:r,clearable:i=!1,sx:o,...l},c)=>{const{panel:u}=Le(),d=f.useMemo(()=>u.dataFieldOptions(n,i),[n,i]);if(d.length===0){const p=u.explainDataKey(n);return s.jsxs(a.HoverCard,{shadow:"md",position:"bottom-start",withinPortal:!0,zIndex:320,children:[s.jsx(a.HoverCard.Target,{children:s.jsx(a.Box,{children:s.jsx(a.TextInput,{label:e,required:t,defaultValue:p.columnKey,readOnly:!0,disabled:!0})})}),s.jsx(a.HoverCard.Dropdown,{children:s.jsxs(a.Group,{position:"left",spacing:0,children:[s.jsx(a.Text,{size:"xs",color:p.queryName?"black":"red",sx:{fontFamily:"monospace"},children:p.queryName??p.queryID}),s.jsx(a.Text,{size:"xs",color:"black",sx:{fontFamily:"monospace"},children:"."}),s.jsx(a.Text,{size:"xs",color:"red",sx:{fontFamily:"monospace"},children:p.columnKey})]})})]})}return s.jsx(a.Select,{ref:c,label:e,data:d,value:n,onChange:r,required:t,sx:o,maxDropdownHeight:500,...l})}));function Fu({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=y.defaults({},t,hs),{control:i,handleSubmit:o,reset:l}=b.useForm({defaultValues:r});return f.useEffect(()=>{l(r)},[t]),t?s.jsx(a.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:o(n),children:[s.jsx(a.Text,{children:"X Axis"}),s.jsxs(a.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[s.jsx(b.Controller,{name:"x_axis_data_key",control:i,render:({field:c})=>s.jsx(B,{label:"Data Field",required:!0,...c})}),s.jsx(b.Controller,{name:"xAxis3D.name",control:i,render:({field:c})=>s.jsx(a.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...c})})]}),s.jsx(a.Text,{mt:"lg",children:"Y Axis"}),s.jsxs(a.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[s.jsx(b.Controller,{name:"y_axis_data_key",control:i,render:({field:c})=>s.jsx(B,{label:"Data Field",required:!0,...c})}),s.jsx(b.Controller,{name:"yAxis3D.name",control:i,render:({field:c})=>s.jsx(a.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...c})})]}),s.jsx(a.Text,{mt:"lg",children:"Z Axis"}),s.jsxs(a.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[s.jsx(b.Controller,{name:"z_axis_data_key",control:i,render:({field:c})=>s.jsx(B,{label:"Data Field",required:!0,...c})}),s.jsx(b.Controller,{name:"zAxis3D.name",control:i,render:({field:c})=>s.jsx(a.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...c})})]}),s.jsx(a.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:s.jsxs(a.Button,{color:"blue",type:"submit",children:[s.jsx(_.DeviceFloppy,{size:20}),s.jsx(a.Text,{ml:"md",children:"Save"})]})})]})}):null}function Gu(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis_data_key:i,y_axis_data_key:o,z_axis_data_key:l,...c}=e;return{...c,x_axis_data_key:r(i),y_axis_data_key:r(o),z_axis_data_key:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class Wu extends ie{constructor(){super(...arguments);E(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:i}=n;return{...n,version:2,config:Gu(i,r)}})}}const Ru={displayName:"Bar Chart (3D)",displayGroup:"ECharts-based charts",migrator:new Wu,name:"bar-3d",viewRender:Vu,configRender:Fu,createConfig(){return{version:2,config:y.cloneDeep(hs)}}};class Se extends f.Component{constructor(t){super(t),this.state={error:null}}componentDidCatch(t){this.setState({error:t})}render(){var t;if(this.state.error){const n=()=>{this.setState({error:null})};return s.jsxs(a.Box,{children:[s.jsx(a.Text,{size:"xs",children:(t=this.state.error)==null?void 0:t.message}),s.jsx(a.Button,{variant:"subtle",size:"xs",mx:"auto",compact:!0,sx:{display:"block"},onClick:n,children:"Retry"})]})}return this.props.children}}const be={mantissa:0,output:"number",trimMantissa:!1,average:!1},$i={root:{alignSelf:"flex-end"},body:{alignItems:"center"},label:{display:"block"}};function Qu({value:e,onChange:t},n){const r=c=>{t({...e,output:c})},i=c=>{const u=c===0?!1:e.trimMantissa;t({...e,mantissa:c,trimMantissa:u})},o=c=>{t({...e,trimMantissa:c.currentTarget.checked})},l=c=>{t({...e,average:c.currentTarget.checked})};return s.jsxs(a.Stack,{ref:n,children:[s.jsxs(a.Group,{grow:!0,children:[s.jsx(a.Select,{label:"Format",data:[{label:"1234",value:"number"},{label:"99%",value:"percent"}],value:e.output,onChange:r,sx:{flexGrow:1}}),s.jsx(a.Switch,{label:s.jsxs(a.Stack,{spacing:0,children:[s.jsx(a.Text,{children:"Average"}),s.jsx(a.Text,{size:12,color:"gray",children:"like 1.234k, 1.234m"})]}),checked:e.average,onChange:l,disabled:e.output!=="number",sx:{flexGrow:1},styles:$i})]}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(a.NumberInput,{label:"Mantissa",defaultValue:0,min:0,step:1,max:4,value:e.mantissa,onChange:i}),s.jsx(a.Switch,{label:s.jsxs(a.Stack,{spacing:0,children:[s.jsx(a.Text,{children:"Trim mantissa"}),s.jsx(a.Text,{size:12,color:"gray",children:"hide trailing zero(s)"})]}),checked:e.trimMantissa,onChange:o,disabled:e.mantissa===0,styles:$i})]}),s.jsxs(a.Stack,{spacing:0,children:[s.jsx(a.Text,{weight:"bold",children:"Preview"}),s.jsx(Se,{children:s.jsxs(a.Group,{position:"apart",children:[s.jsxs(a.Text,{size:12,color:"gray",children:["123456789 ",s.jsx(_.ArrowRight,{size:9})," ",F(123456789).format(e)]}),s.jsxs(a.Text,{size:12,color:"gray",children:["1234 ",s.jsx(_.ArrowRight,{size:9})," ",F(1234).format(e)]}),s.jsxs(a.Text,{size:12,color:"gray",children:["0.1234 ",s.jsx(_.ArrowRight,{size:9})," ",F(.1234).format(e)]})]})})]})]})}const Oe=f.forwardRef(Qu),Be={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
54
|
+
`;function os(e,t){const n=Object.keys(t),r=Object.values(t);try{return new Function(...n,`return \`${e}\`;`)(...r)}catch(i){throw n.length===0&&e.includes("$")?new Error("[formatSQL] insufficient payload"):i}}function ls(e,t){try{return os(e,t)}catch(n){return console.error(n),n.message}}function xu({sql:e,pre_process:t}){if(!t.trim())return e;try{return new Function(`return ${t}`)()({sql:e},gt)}catch(n){return console.error(n),e}}function fu(e,t,n){if(!e.trim())return t;try{return new Function(`return ${e}`)()(t,gt,n)}catch(r){return console.error(r),t}}function gu(e){e=e||{};const t=Object.keys(e).sort(),n=[];for(let r=0;r<t.length;r++){const i=t[r];if(i!="authentication"&&e[i])n.push(t[r]+"="+(typeof e[i]=="object"?JSON.stringify(e[i]):e[i]));else{const o=Object.keys(e[i]).sort();for(let l=0;l<o.length;l++){const c=o[l];c!="sign"&&e[i][c]&&n.push(o[l]+"="+(typeof e[i][c]=="object"?JSON.stringify(e[i][c]):e[i][c]))}}}return n.sort().join("&")}function mu(e,t){let n=gu(e);return n+="&key="+t,ou.MD5(n).toString().toUpperCase()}class ji{constructor(){this.type="default_api_client",this.baseURL="http://localhost:31200",this.app_id="",this.app_secret=""}getAuthentication(t){if(!this.app_id||!this.app_secret)return;const n=new Date().getTime().toString();return{app_id:this.app_id,nonce_str:n,sign:mu({app_id:this.app_id,nonce_str:n,...t},this.app_secret)}}getRequest(t,n){return(r,i,o,l)=>{const c=this.buildHeader(o),u=this.buildAxiosConfig(t,r,i,o,c,n);return tt(u).then(d=>l?d:d.data).catch(d=>Promise.reject(d))}}get(t){return this.getRequest("GET",t)}post(t){return this.getRequest("POST",t)}put(t){return this.getRequest("PUT",t)}buildAxiosConfig(t,n,r,i,o,l){const c={baseURL:this.baseURL,method:t,url:n,params:t==="GET"?r:i.params,headers:o,signal:l};return["POST","PUT"].includes(t)&&(c.data=i.string?JSON.stringify(r):r,c.data.authentication=this.getAuthentication(c.data)),c}buildHeader(t){const n=window.localStorage.getItem("token");return{"X-Requested-With":"XMLHttpRequest","Content-Type":t.string?"application/x-www-form-urlencoded":"application/json",authorization:n?`bearer ${n}`:"",...t.headers}}}class yu{constructor(t){this.implementation=t}getRequest(t,n){return this.implementation.getRequest(t,n)}get(t){return this.getRequest("GET",t)}post(t){return this.getRequest("POST",t)}put(t){return this.getRequest("PUT",t)}}class vi extends ji{constructor(){super(...arguments);E(this,"makeQueryENV",null)}query(n){return async(r,i={})=>{var o;return r.env||(r.env=((o=this.makeQueryENV)==null?void 0:o.call(this))??{error:"failed to run makeQueryENV"}),this.post(n)("/query",r,i)}}httpDataSourceQuery(n){return async(r,i={})=>{var o;return r.env||(r.env=((o=this.makeQueryENV)==null?void 0:o.call(this))??{error:"failed to run makeQueryENV"}),this.getRequest("POST",n)("/query",r,i,!0)}}structure(n){return async(r,i={})=>this.post(n)("/query/structure",r,i)}}class wi{constructor(t){this.implementation=t}query(t){return this.implementation.query(t)}httpDataSourceQuery(t){return this.implementation.httpDataSourceQuery(t)}structure(t){return this.implementation.structure(t)}getRequest(t,n){return this.implementation.getRequest(t,n)}get(t){return this.getRequest("GET",t)}post(t){return this.getRequest("POST",t)}put(t){return this.getRequest("PUT",t)}}const Dt=new vi;function cs(e){Dt.baseURL!==e.apiBaseURL&&(Dt.baseURL=e.apiBaseURL),e.app_id&&(Dt.app_id=e.app_id),e.app_secret&&(Dt.app_secret=e.app_secret),e.makeQueryENV&&(Dt.makeQueryENV=e.makeQueryENV)}const Ci=new wi(Dt),Xe=Ci;function Si(){return{filters:{},context:{}}}function us(e){const t=Si();if(!e)return Si();const{filters:n=t.filters,context:r=t.context}=e;return{filters:n,context:r}}function bu(e,t){const n=Hr.decode(t);n!==e&&(console.error("Inconsistent sql"),console.groupCollapsed("Inconsistent sql"),console.table({before:e,after:t,v:n}),console.groupEnd())}async function ju({query:e,name:t,payload:n,additionals:r},i){if(!e.sql)return[];const{type:o,key:l,sql:c,pre_process:u,post_process:d}=e,p=os(c,n),h=xu({sql:p,pre_process:u}),x=Hr.encode(h);bu(h,x);let m=await Xe.query(i)({type:o,key:l,query:x,...r},{params:{name:t}});return m=fu(d,m,us(n)),m}async function vu({type:e,key:t,configString:n,name:r,additionals:i},o){try{return await Xe.httpDataSourceQuery(o)({type:e,key:t,query:n,...i},{params:{name:r}})}catch(l){if(tt.isCancel(l))throw l;return console.error(l),l}}async function ds(){try{return(await Xe.post()("/datasource/list",{filter:{},sort:[{field:"create_time",order:"ASC"}],pagination:{page:1,pagesize:100}},{})).data}catch(e){return console.error(e),[]}}async function _i(){try{return(await Xe.post()("/sql_snippet/list",{filter:{},sort:[{field:"id",order:"ASC"}],pagination:{page:1,pagesize:1e3}},{})).data}catch(e){return console.error(e),[]}}class ki{constructor(t){E(this,"rootRef");this.rootRef=W.observable({current:t})}async deleteItem(t){W.runInAction(()=>{y.unset(this.rootRef.current,[t])})}getItem(t){const n=this.getValueFromRoot(t);return Promise.resolve(n)}getValueFromRoot(t){return t===null?W.toJS(this.rootRef.current):y.get(this.rootRef.current,[t])}setItem(t,n){if(t===null)if(y.isObject(n))W.runInAction(()=>{this.rootRef.current=n});else throw new Error("Cannot set root value to non-object");else W.runInAction(()=>{y.set(this.rootRef.current,[t],n)});return Promise.resolve(this.getItem(t))}watchItem(t,n,r){return W.reaction(()=>this.getValueFromRoot(t),(i,o)=>{n(i,o)},{requiresObservable:!0,fireImmediately:y.get(r,"fireImmediately",!1)})}}class wu{constructor(){E(this,"channels",new Map);E(this,"globalChannel",new ei)}getChannel(t){const n=this.channels.get(t);if(n)return n;const r=new ei;return this.channels.set(t,r),r}}class Cu{constructor(t){E(this,"instances",new Map);this.pluginManager=t}get availableVizList(){return this.pluginManager.installedPlugins.flatMap(t=>t.manifest.viz)}resolveComponent(t){return this.pluginManager.factory.viz(t)}getOrCreateInstance(t){const n=this.instances.get(t.id);if(n)return n;const r={id:t.id,name:t.viz.type,type:t.viz.type,messageChannels:new wu,instanceData:new ki(t.viz.conf)};return this.instances.set(t.id,r),r}}function Ti(e,t,n,r){return{vizManager:n,locale:"zh",msgChannels:e.messageChannels,instanceData:e.instanceData,pluginData:new ki({}),colorPalette:{getColor(){return()=>""}},data:t,variables:r}}const Su=e=>{const{panel:t,vizManager:n,data:r,variables:i}=e,o=n.resolveComponent(t.viz.type),l=n.getOrCreateInstance(t),c={...Ti(l,r,n,i),viewport:{width:t.layout.w,height:t.layout.h}},u=o.viewRender;return s.jsx(u,{context:c,instance:l,...y.omit(e,["panel","vizManager","data"])})},_u=e=>{const{vizManager:t,panel:n,data:r,variables:i}=e,o=t.resolveComponent(n.viz.type),l=t.getOrCreateInstance(n),c={...Ti(l,r,t,i)},u=o.configRender;return s.jsx(u,{context:c,instance:l,...y.omit(e,["panel","vizManager","data"])})},Di=(e,t)=>{const n=nt.bezier(e),r=nt.bezier(t);return function(i){return i<50?n(i*2/100).hex():r((i-50)*2/100).hex()}},un=e=>{const t=nt.bezier(e);return function(n){return t(n/100).hex()}},ku={type:"interpolation",displayName:"Red / Green",getColor:Di(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},Tu={type:"interpolation",displayName:"Yellow / Blue",getColor:Di(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},Du={type:"interpolation",displayName:"Red",getColor:un(["#fff7f1","darkred"]),name:"red",category:"sequential"},Iu={type:"interpolation",displayName:"Green",getColor:un(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},Mu={type:"interpolation",displayName:"Blue",getColor:un(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},zu={type:"interpolation",displayName:"Orange",getColor:un(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class Au{constructor(t){E(this,"symbol");this.symbol=Symbol(t)}}function st(e){return new Au(e)}class ps{constructor(){E(this,"parent");E(this,"factoryRegistry",new Map);E(this,"instanceRegistry",new Map)}createScoped(){const t=new ps;return t.parent=this,t}getRequired(t){return this.get(t)}get(t){if(this.instanceRegistry.has(t.symbol))return this.instanceRegistry.get(t.symbol);const n=this.factoryRegistry.get(t.symbol);if(n){const r=n(this);return this.instanceRegistry.set(t.symbol,r),r}if(this.parent)return this.parent.get(t)}provideFactory(t,n){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,n),this}provideValue(t,n){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,()=>n),this}dispose(){this.instanceRegistry.forEach(t=>{const n=y.get(t,"dispose");y.isFunction(n)&&n.bind(t)()}),this.instanceRegistry.clear(),this.factoryRegistry.clear()}}const Ii="10.58.2",Eu=Object.freeze(Object.defineProperty({__proto__:null,version:Ii},Symbol.toStringTag,{value:"Module"}));class Pu{constructor(t){E(this,"staticColors",new Map);E(this,"interpolations",new Map);t.installedPlugins.forEach(n=>{n.manifest.color.forEach(r=>{this.register(r)})})}getStaticColors(){return Array.from(this.staticColors.values())}register(t){const n=this.encodeColor(t);t.type==="single"?(this.staticColors.has(n)&&console.warn(`the color '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.staticColors.set(n,t)):t.type==="interpolation"&&(this.interpolations.has(n)&&console.warn(`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`,`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.interpolations.set(n,t))}decodeStaticColor(t){return this.staticColors.get(t)}encodeColor(t){return`\${${t.category}}.{${t.name}}`}decodeInterpolation(t){return this.interpolations.get(t)}getColorInterpolations(){return Array.from(this.interpolations.values())}}class Lu{constructor(){E(this,"plugins",new Map);E(this,"vizComponents",new Map);E(this,"factory",{viz:t=>{const n=this.vizComponents.get(t);if(n)return n;throw new Error(`Viz Component (${t}) not found`)}})}install(t){if(this.plugins.has(t.id))throw new Error(`Plugin (${t.id}) has been installed before`);this.plugins.set(t.id,t);for(const n of t.manifest.viz){if(this.vizComponents.has(n.name))throw new Error(`Viz Component (${n.name}) has been installed before`);this.vizComponents.set(n.name,n)}}get installedPlugins(){return Array.from(this.plugins.values())}}class Ou{constructor(){E(this,"migrations",[])}version(t,n){return this.migrations.push({version:t,handler:n}),this}run(t,n,r){var l;if(t.from===t.to)return n;if(t.from>t.to)throw new Error(`Can not downgrade from version '${t.from}' to (${t.to})`);const i=this.migrations.filter(c=>c.version>t.from&&c.version<=t.to),o=y.orderBy(i,"version","asc");if(((l=y.last(o))==null?void 0:l.version)!==t.to)throw new Error(`Migration to version ${t.to} not found`);return o.reduce((c,u)=>u.handler(c,r),n)}}class ie extends Ou{constructor(){super(),this.configVersions()}version(t,n){return super.version(t,(r,i)=>({version:t,...n(r,i)}))}async migrate({configData:t,panelModel:n}){const r=await t.getItem(null),i=y.get(r,"version",0),o=this.run({from:i,to:this.VERSION},r,{panelModel:n});await t.setItem(null,o)}async needMigration({configData:t}){const n=await t.getItem(null);return y.get(n,"version",0)<this.VERSION}}const $=(e,t)=>{const[n,{setFalse:r}]=V.useBoolean(!0),[i,o]=f.useState();f.useEffect(()=>(e.getItem(t).then(c=>{o(c),r()}),e.watchItem(t,c=>{o(c)})));const l=f.useCallback(async c=>{await e.setItem(t,c),o(c)},[e,t]);return{loading:n,value:i,set:l}},Te={top:16,right:16,bottom:16,left:16},We=e=>Math.max(0,e-Te.left-Te.right),Re=e=>Math.max(0,e-Te.top-Te.bottom),Wt=(e,t)=>({width:We(e),height:Re(t)}),De=({width:e,height:t,children:n})=>s.jsx(a.Box,{pt:Te.top,pr:Te.right,pb:Te.bottom,pl:Te.left,sx:{width:e,height:t,overflow:"hidden",position:"relative"},children:n});function z(e){const[t,n]=e.split(".");return{queryID:t,columnKey:n}}function Bu(e){return e.includes(".")?z(e):{queryID:"",columnKey:e}}function rt(e,t){var i;const{queryID:n,columnKey:r}=z(t);return n?r?((i=e[n])==null?void 0:i.map(o=>o[r]))??[]:e[n]:[]}function Rt(e,t){const{queryID:n}=z(t);return n?e[n]:[]}function $u(e){return Object.values(e)[0]}function dn(e,t){const{queryID:n,columnKey:r}=z(t);return e[r]}const hs={x_axis_data_key:"",y_axis_data_key:"",z_axis_data_key:"",xAxis3D:{type:"value",name:"X Axis Name"},yAxis3D:{type:"value",name:"Y Axis Name"},zAxis3D:{type:"value",name:"Z Axis Name"}};U.use([O.GridComponent,O.VisualMapComponent,O.LegendComponent,O.TooltipComponent,Ce.CanvasRenderer]);function Vu({context:e}){const{value:t}=$(e.instanceData,"config"),n=e.data,{width:r,height:i}=e.viewport,{x_axis_data_key:o,y_axis_data_key:l,z_axis_data_key:c,xAxis3D:u,yAxis3D:d,zAxis3D:p}=y.defaults({},t,hs),h=f.useMemo(()=>Rt(n,o),[n,o]),{x,y:m,z:j}=f.useMemo(()=>({x:z(o),y:z(l),z:z(c)}),[o,l,c]),{min:w,max:T}=f.useMemo(()=>{const P=y.minBy(h,re=>re[j.columnKey]),K=y.maxBy(h,re=>re[j.columnKey]);return{min:y.get(P,j.columnKey),max:y.get(K,j.columnKey)}},[h,j]),M={tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:w,max:T,inRange:{color:["#313695","#4575b4","#74add1","#abd9e9","#e0f3f8","#ffffbf","#fee090","#fdae61","#f46d43","#d73027","#a50026"]}},xAxis3D:u,yAxis3D:d,zAxis3D:p,grid3D:{viewControl:{projection:"orthographic",autoRotate:!1},light:{main:{shadow:!0,quality:"ultra",intensity:1.5}}},series:[{type:"bar3D",wireframe:{},data:h.map(P=>[P[x.columnKey],P[m.columnKey],P[j.columnKey]])}]};return t?s.jsx(De,{width:r,height:i,children:s.jsx(we,{echarts:U,option:M,style:Wt(r,i),notMerge:!0,theme:"merico-light"})}):null}const Mi=f.createContext(null),xs=Mi.Provider;function fs(){const e=f.useContext(Mi);if(!e)throw new Error("Please use DashboardModelContextProvider");return e}const Y=()=>fs(),gs=()=>fs(),zi=f.createContext({searchButtonProps:{}}),ms=zi.Provider;function Ai(){return f.useContext(zi)}const Ei=f.createContext(null),ys=Ei.Provider;function Pi(){const e=f.useContext(Ei);if(!e)throw new Error("Please use ContentModelContextProvider");return e}const X=()=>Pi(),ce=()=>Pi(),qu={inEditMode:!1},pn=f.createContext(qu),Li=f.createContext({panel:null,data:{},loading:!1,errors:[],downloadPanelScreenshot:()=>{}}),bs=Li.Provider;function Oi(){const e=f.useContext(Li);if(!e.panel)throw new Error("Please use PanelContextProvider");return e}const dt=()=>Oi(),Le=()=>Oi(),Nu={fullScreenPanelID:"",setFullScreenPanelID:y.noop},js=f.createContext(Nu);function Bi(){const e=f.useContext(js);if(!e)throw new Error("Please use FullScreenPanelContext.Provider");return e}const B=S.observer(f.forwardRef(({label:e,required:t,value:n,onChange:r,clearable:i=!1,sx:o,...l},c)=>{const{panel:u}=Le(),d=f.useMemo(()=>u.dataFieldOptions(n,i),[n,i]);if(d.length===0){const p=u.explainDataKey(n);return s.jsxs(a.HoverCard,{shadow:"md",position:"bottom-start",withinPortal:!0,zIndex:320,children:[s.jsx(a.HoverCard.Target,{children:s.jsx(a.Box,{children:s.jsx(a.TextInput,{label:e,required:t,defaultValue:p.columnKey,readOnly:!0,disabled:!0})})}),s.jsx(a.HoverCard.Dropdown,{children:s.jsxs(a.Group,{position:"left",spacing:0,children:[s.jsx(a.Text,{size:"xs",color:p.queryName?"black":"red",sx:{fontFamily:"monospace"},children:p.queryName??p.queryID}),s.jsx(a.Text,{size:"xs",color:"black",sx:{fontFamily:"monospace"},children:"."}),s.jsx(a.Text,{size:"xs",color:"red",sx:{fontFamily:"monospace"},children:p.columnKey})]})})]})}return s.jsx(a.Select,{ref:c,label:e,data:d,value:n,onChange:r,required:t,sx:o,maxDropdownHeight:500,...l})}));function Fu({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=y.defaults({},t,hs),{control:i,handleSubmit:o,reset:l}=b.useForm({defaultValues:r});return f.useEffect(()=>{l(r)},[t]),t?s.jsx(a.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:o(n),children:[s.jsx(a.Text,{children:"X Axis"}),s.jsxs(a.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[s.jsx(b.Controller,{name:"x_axis_data_key",control:i,render:({field:c})=>s.jsx(B,{label:"Data Field",required:!0,...c})}),s.jsx(b.Controller,{name:"xAxis3D.name",control:i,render:({field:c})=>s.jsx(a.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...c})})]}),s.jsx(a.Text,{mt:"lg",children:"Y Axis"}),s.jsxs(a.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[s.jsx(b.Controller,{name:"y_axis_data_key",control:i,render:({field:c})=>s.jsx(B,{label:"Data Field",required:!0,...c})}),s.jsx(b.Controller,{name:"yAxis3D.name",control:i,render:({field:c})=>s.jsx(a.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...c})})]}),s.jsx(a.Text,{mt:"lg",children:"Z Axis"}),s.jsxs(a.Group,{position:"apart",grow:!0,p:"md",sx:{position:"relative",border:"1px solid #eee"},children:[s.jsx(b.Controller,{name:"z_axis_data_key",control:i,render:({field:c})=>s.jsx(B,{label:"Data Field",required:!0,...c})}),s.jsx(b.Controller,{name:"zAxis3D.name",control:i,render:({field:c})=>s.jsx(a.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...c})})]}),s.jsx(a.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:s.jsxs(a.Button,{color:"blue",type:"submit",children:[s.jsx(_.DeviceFloppy,{size:20}),s.jsx(a.Text,{ml:"md",children:"Save"})]})})]})}):null}function Gu(e,{panelModel:t}){try{const n=t.queryIDs[0];if(!n)throw new Error("cannot migrate when queryID is empty");const r=u=>u&&`${n}.${u}`,{x_axis_data_key:i,y_axis_data_key:o,z_axis_data_key:l,...c}=e;return{...c,x_axis_data_key:r(i),y_axis_data_key:r(o),z_axis_data_key:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class Wu extends ie{constructor(){super(...arguments);E(this,"VERSION",2)}configVersions(){this.version(1,n=>({version:1,config:n})),this.version(2,(n,r)=>{const{config:i}=n;return{...n,version:2,config:Gu(i,r)}})}}const Ru={displayName:"Bar Chart (3D)",displayGroup:"ECharts-based charts",migrator:new Wu,name:"bar-3d",viewRender:Vu,configRender:Fu,createConfig(){return{version:2,config:y.cloneDeep(hs)}}};class Se extends f.Component{constructor(t){super(t),this.state={error:null}}componentDidCatch(t){this.setState({error:t})}render(){var t;if(this.state.error){const n=()=>{this.setState({error:null})};return s.jsxs(a.Box,{children:[s.jsx(a.Text,{size:"xs",children:(t=this.state.error)==null?void 0:t.message}),s.jsx(a.Button,{variant:"subtle",size:"xs",mx:"auto",compact:!0,sx:{display:"block"},onClick:n,children:"Retry"})]})}return this.props.children}}const be={mantissa:0,output:"number",trimMantissa:!1,average:!1},$i={root:{alignSelf:"flex-end"},body:{alignItems:"center"},label:{display:"block"}};function Qu({value:e,onChange:t},n){const r=c=>{t({...e,output:c})},i=c=>{const u=c===0?!1:e.trimMantissa;t({...e,mantissa:c,trimMantissa:u})},o=c=>{t({...e,trimMantissa:c.currentTarget.checked})},l=c=>{t({...e,average:c.currentTarget.checked})};return s.jsxs(a.Stack,{ref:n,children:[s.jsxs(a.Group,{grow:!0,children:[s.jsx(a.Select,{label:"Format",data:[{label:"1234",value:"number"},{label:"99%",value:"percent"}],value:e.output,onChange:r,sx:{flexGrow:1}}),s.jsx(a.Switch,{label:s.jsxs(a.Stack,{spacing:0,children:[s.jsx(a.Text,{children:"Average"}),s.jsx(a.Text,{size:12,color:"gray",children:"like 1.234k, 1.234m"})]}),checked:e.average,onChange:l,disabled:e.output!=="number",sx:{flexGrow:1},styles:$i})]}),s.jsxs(a.Group,{grow:!0,children:[s.jsx(a.NumberInput,{label:"Mantissa",defaultValue:0,min:0,step:1,max:4,value:e.mantissa,onChange:i}),s.jsx(a.Switch,{label:s.jsxs(a.Stack,{spacing:0,children:[s.jsx(a.Text,{children:"Trim mantissa"}),s.jsx(a.Text,{size:12,color:"gray",children:"hide trailing zero(s)"})]}),checked:e.trimMantissa,onChange:o,disabled:e.mantissa===0,styles:$i})]}),s.jsxs(a.Stack,{spacing:0,children:[s.jsx(a.Text,{weight:"bold",children:"Preview"}),s.jsx(Se,{children:s.jsxs(a.Group,{position:"apart",children:[s.jsxs(a.Text,{size:12,color:"gray",children:["123456789 ",s.jsx(_.ArrowRight,{size:9})," ",F(123456789).format(e)]}),s.jsxs(a.Text,{size:12,color:"gray",children:["1234 ",s.jsx(_.ArrowRight,{size:9})," ",F(1234).format(e)]}),s.jsxs(a.Text,{size:12,color:"gray",children:["0.1234 ",s.jsx(_.ArrowRight,{size:9})," ",F(.1234).format(e)]})]})})]})]})}const Oe=f.forwardRef(Qu),Be={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
55
55
|
`)},Vi={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:Uu,configRender:Ku,payload:[{name:"type",description:"Always 'click'",valueType:"string"},{name:"seriesType",description:"'boxplot'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"Record of 'name', 'min', 'q1', 'median', 'q3', 'max'",valueType:"object"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function Ku(e){return s.jsx(s.Fragment,{})}function Uu(e){return s.jsx(a.Text,{children:"Click chart's series"})}const Yu=[{label:"Truncate",value:"truncate"},{label:"Break Line",value:"break"},{label:"Break Word",value:"breakAll"}],hn=f.forwardRef(({sectionTitle:e,value:t,onChange:n},r)=>{const i=o=>l=>{const c=y.cloneDeep(t);y.set(c,o,l),n(c)};return s.jsxs(a.Stack,{spacing:0,children:[e&&s.jsx(a.Divider,{mb:-5,mt:5,variant:"dotted",label:e,labelPosition:"right",labelProps:{color:"dimmed"}}),s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(a.NumberInput,{label:"Max Width",hideControls:!0,value:t.width,onChange:i("width")}),s.jsx(a.Select,{label:"Overflow",data:Yu,value:t.overflow,onChange:i("overflow")}),s.jsx(a.TextInput,{label:"Ellipsis",value:t.ellipsis,disabled:!0})]})]})}),Je=f.forwardRef(({value:e,onChange:t},n)=>{const r=o=>{t({...e,on_axis:o})},i=o=>{t({...e,in_tooltip:o})};return s.jsxs(a.Stack,{ref:n,spacing:0,children:[s.jsx(hn,{sectionTitle:"Overflow on Axis",value:e.on_axis,onChange:r}),s.jsx(hn,{sectionTitle:"Overflow in Tooltip",value:e.in_tooltip,onChange:i})]})}),Ae={on_axis:{width:80,overflow:"truncate",ellipsis:"..."},in_tooltip:{width:200,overflow:"break",ellipsis:"..."}};function Qe({overflow:e,width:t}){const n={truncate:"initial",break:"break-all",breakAll:"break-word"}[e],r=e==="truncate"?"nowrap":"initial",i={truncate:"ellipsis",break:"clip",breakAll:"clip"}[e];return`
|
|
56
56
|
max-width: ${t}px;
|
|
57
57
|
word-break: ${n};
|
|
@@ -478,4 +478,4 @@ WHERE
|
|
|
478
478
|
`),post:["function process_result(res, utils, state) {"," // your code goes here"," return data","}"].join(`
|
|
479
479
|
`)},zT=S.observer(({queryModel:e})=>e.typedAsHTTP?s.jsxs(a.Tabs,{defaultValue:"pre_process",orientation:"vertical",sx:{flexGrow:1},children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"pre_process",children:"Build Request"}),s.jsx(a.Tabs.Tab,{value:"post_process",children:"Process Result"}),s.jsx(Nr,{})]}),s.jsx(a.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:s.jsx(en,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:Ql.pre})}),s.jsx(a.Tabs.Panel,{value:"post_process",p:"sm",children:s.jsx(en,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:Ql.post})})]}):null),AT=S.observer(({queryID:e,usage:t})=>{const n=Y().editor,r=o=>{if(o.type==="filter"){n.setPath(["_FILTERS_",o.id]);return}if(o.type==="panel"){const l=o.views[0].id;n.setPath(["_VIEWS_",l,"_PANELS_",o.id]);return}},i=o=>{n.setPath(["_VIEWS_",o])};return s.jsx(a.Stack,{py:"sm",px:"md",children:s.jsxs(a.Table,{highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{style:{width:100},children:"Type"}),s.jsx("th",{style:{width:"calc(50% - 50px)"},children:"Name"}),s.jsx("th",{children:"In View(s)"})]})}),s.jsx("tbody",{children:t.map(o=>s.jsxs("tr",{children:[s.jsx("td",{children:y.capitalize(o.type)}),s.jsx("td",{children:s.jsx(a.Anchor,{component:"button",type:"button",onClick:()=>r(o),children:o.label})}),s.jsx("td",{children:s.jsxs(a.Stack,{align:"flex-start",justify:"flex-start",spacing:2,children:[o.views.map(l=>s.jsx(a.Anchor,{component:"button",type:"button",onClick:()=>i(l.id),children:s.jsx(a.Box,{children:l.label})},l.id)),o.views.length===0&&s.jsx(a.Box,{children:"--"})]})})]},o.id))})]})})}),Fr=({value:e,onChange:t,height:n="200px",defaultLanguage:r="sql",theme:i="vs-dark"})=>{const o=c=>{t==null||t(c??"")},l=!t;return s.jsx(me,{className:"minimal-monaco-editor",height:n,defaultLanguage:r,value:e,onChange:l?void 0:o,theme:i,options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1},readOnly:l||!t,"semanticHighlighting.enabled":!0}})},ET=S.observer(({queryModel:e})=>{const t=f.useMemo(()=>y.groupBy(e.dependencies,"type"),[e.dependencies]),n=f.useMemo(()=>e.dependencies.some(i=>!i.valid),[e.dependencies]),r=e.dependencies.length>0;return r?s.jsxs(a.HoverCard,{withinPortal:!0,zIndex:340,shadow:"md",disabled:!r,children:[s.jsx(a.HoverCard.Target,{children:s.jsx(a.Button,{size:"xs",variant:"subtle",color:n?"red":"green",disabled:!r,leftIcon:n?s.jsx(k.IconAlertTriangle,{size:16}):s.jsx(k.IconDiscountCheckFilled,{size:16}),children:"Dependency"})}),s.jsx(a.HoverCard.Dropdown,{children:s.jsx(a.List,{spacing:"md",size:14,listStyleType:"none",children:Object.entries(t).map(([i,o])=>s.jsxs(a.List.Item,{children:[s.jsx(a.Text,{fw:"bold",ff:"monospace",children:i}),s.jsx(a.List,{withPadding:!0,size:14,sx:{fontFamily:"monospace",svg:{verticalAlign:"middle"}},children:o.map(l=>s.jsx(a.List.Item,{icon:s.jsx(a.Box,{sx:{path:{fill:l.valid?"rgb(18, 184, 134)":"rgb(250, 82, 82)"}},children:s.jsx(k.IconPointFilled,{size:12})}),children:l.key},l.key))})]},i))})})]}):s.jsx(a.Tooltip,{label:"This query has no dependency",children:s.jsx(a.Button,{size:"xs",variant:"subtle",color:"gray",leftIcon:s.jsx(k.IconHierarchy,{size:16,style:{transform:"rotate(180deg)"}}),sx:{transform:"none !important"},children:"Dependency"})})}),PT="SELECT 1",LT=S.observer(({queryModel:e})=>{const[t,n]=f.useState(e.sql),r=()=>{e.setSQL(t)},i=()=>{n(e.sql)},o=()=>{n(PT)};f.useEffect(()=>{n(e.sql)},[e.sql]);const l=t!==e.sql;return s.jsxs(a.Stack,{spacing:4,sx:{height:"100%"},children:[s.jsxs(a.Group,{mb:6,position:"apart",sx:{flexShrink:0,flexGrow:0},children:[s.jsx(a.Group,{position:"left",children:s.jsx(ET,{queryModel:e})}),s.jsxs(a.Group,{position:"right",children:[s.jsx(a.Button,{onClick:o,size:"xs",variant:"default",leftIcon:s.jsx(k.IconPlayerSkipBack,{size:16}),children:"Reset to default"}),s.jsx(a.Button,{onClick:i,color:"red",size:"xs",disabled:!l,leftIcon:s.jsx(k.IconRecycle,{size:16}),children:"Revert Changes"}),s.jsx(a.Button,{size:"xs",onClick:r,disabled:!l,leftIcon:s.jsx(k.IconDeviceFloppy,{size:16}),children:"Confirm Changes"})]})]}),s.jsx(Fr,{height:"100%",value:t,onChange:n,theme:"sql-dark",defaultLanguage:"sql"})]})}),OT=({value:e,height:t="200px",defaultLanguage:n="sql"})=>s.jsx(me,{className:"preview-sql-in-monaco-editor",height:t,defaultLanguage:n,value:e,onChange:void 0,theme:"vs-light",options:{lineNumbers:"on",folding:!0,lineDecorationsWidth:20,wordWrap:"on",minimap:{enabled:!1},readOnly:!0}}),BT=S.observer(({value:e})=>{const n=ce().payloadForSQL,r=f.useMemo(()=>ls(e,n),[e,n]);return s.jsx(OT,{height:"100%",value:r})}),Kl={pre:["function process_request({ context, filters, sql }, utils) {"," // modify and return sql"," return sql","}"].join(`
|
|
480
480
|
`),post:["function process_result(data, utils, state) {"," // process data and return the result"," return data","}"].join(`
|
|
481
|
-
`)},$T=S.observer(({queryModel:e})=>e.typedAsSQL?s.jsxs(a.Tabs,{defaultValue:"Edit",orientation:"vertical",sx:{flexGrow:1},styles:{tabLabel:{width:"100%",height:"28px",lineHeight:"28px"}},keepMounted:!1,children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"Edit",children:s.jsx(a.Group,{spacing:14,position:"apart",children:"Edit SQL"})}),s.jsx(a.Tabs.Tab,{value:"Preview",children:"Preview SQL"}),s.jsx(a.Tabs.Tab,{value:"pre_process",children:"Process Request"}),s.jsx(a.Tabs.Tab,{value:"post_process",children:"Process Result"}),s.jsx(Nr,{}),e.datasource&&s.jsx(Gl,{dataSource:e.datasource})]}),s.jsx(a.Tabs.Panel,{value:"Edit",sx:{position:"relative"},p:"sm",children:s.jsx(LT,{queryModel:e})}),s.jsx(a.Tabs.Panel,{value:"Preview",p:0,pl:4,children:s.jsx(BT,{value:e.sql})}),s.jsx(a.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:s.jsx(en,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:Kl.pre})}),s.jsx(a.Tabs.Panel,{value:"post_process",p:"sm",children:s.jsx(en,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:Kl.post})})]}):null),Jn={height:"calc(100% - 44px)",padding:0},VT=S.observer(({queryModel:e})=>{const t=X(),n=f.useMemo(()=>e.datasource?e.typedAsHTTP?"HTTP":"SQL":"Configurations",[e.datasource,e.typedAsHTTP]),[r,i]=f.useState(n);f.useEffect(()=>{i(c=>c!=="Configurations"&&n==="Configurations"?"Configurations":c)},[n]);const o=t.findQueryUsage(e.id),l=o.length===0;return s.jsxs(a.Tabs,{value:r,onTabChange:i,defaultValue:n,orientation:"horizontal",keepMounted:!1,sx:{height:"100vh"},children:[s.jsxs(a.Tabs.List,{grow:!0,children:[s.jsx(a.Tabs.Tab,{value:"Configurations",children:"Configurations"}),e.typedAsSQL&&s.jsx(a.Tabs.Tab,{value:"SQL",children:"Request"}),e.typedAsHTTP&&s.jsx(a.Tabs.Tab,{value:"HTTP",children:"Request"}),s.jsx(a.Tabs.Tab,{value:"Data",disabled:!e.datasource,children:s.jsx(a.Tooltip,{label:"Need to pick a Data Source first",disabled:e.datasource,withinPortal:!0,children:s.jsx(a.Text,{children:"Data"})})}),s.jsx(a.Tabs.Tab,{value:"Usage",disabled:l,children:s.jsx(a.Tooltip,{label:"This query is not used for any filter or panel",disabled:!l,withinPortal:!0,children:s.jsx(a.Text,{children:"Usage"})})})]}),s.jsx(a.Tabs.Panel,{value:"Configurations",pt:0,p:0,children:s.jsx(TT,{queryModel:e})}),e.typedAsSQL&&s.jsx(a.Tabs.Panel,{value:"SQL",sx:Jn,children:s.jsx(a.Stack,{sx:{height:"100%"},children:s.jsx($T,{queryModel:e})})}),e.typedAsHTTP&&s.jsx(a.Tabs.Panel,{value:"HTTP",sx:Jn,children:s.jsx(a.Stack,{sx:{height:"100%"},children:s.jsx(zT,{queryModel:e})})}),s.jsx(a.Tabs.Panel,{value:"Data",sx:{...Jn,overflow:"hidden"},children:s.jsx($r,{id:e.id,moreActions:null,refreshOnMount:!0})}),s.jsx(a.Tabs.Panel,{value:"Usage",sx:{...Jn,overflow:"hidden"},children:s.jsx(AT,{queryID:e.id,usage:o})})]})}),qT=S.observer(({id:e})=>{const n=X().queries.findByID(e);return e===""?null:n?s.jsx(VT,{queryModel:n}):s.jsx(a.Text,{size:14,color:"red",children:"Invalid Query ID"})}),NT=S.observer(({value:e})=>{const n=ce().payloadForSQL,r=f.useMemo(()=>ls(e,n),[e,n]);return s.jsx(Fr,{height:"100%",value:r})}),FT=S.observer(({item:e,remove:t,onKeyChanged:n})=>{const[r,i]=f.useState("SQL"),[o,l]=f.useState(e.key),c=()=>{e.setKey(o),n(o)},u=o!==e.key,d=e.isADuplicatedKey(o),[p,h]=f.useState(e.value),x=()=>{e.setValue(p)};f.useEffect(()=>{l(e.key),h(e.value)},[e]);const m=p!==e.value,j=ze.useModals(),w=()=>{j.openConfirmModal({title:"Delete this SQL snippet?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:t,confirmProps:{color:"red"},zIndex:320})};return s.jsxs(a.Stack,{p:20,sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",children:[s.jsxs(a.Group,{sx:{alignItems:"end"},spacing:40,children:[s.jsx(a.TextInput,{label:d?"This key is occupied by another snippet":"Key",value:o,onChange:T=>{l(T.currentTarget.value)},sx:{flexGrow:"1 !important"},rightSection:s.jsx(a.ActionIcon,{color:"blue",variant:"subtle",onClick:c,disabled:!u||d,children:s.jsx(_.DeviceFloppy,{size:16})}),error:d}),s.jsx(a.Button,{leftIcon:s.jsx(_.Trash,{size:16}),color:"red",variant:"light",onClick:w,children:"Delete this SQL Snippet"})]}),s.jsxs(a.Tabs,{value:r,onTabChange:i,sx:{flexGrow:1},styles:{panel:{height:"calc(100% - 50px)"}},children:[s.jsxs(a.Tabs.List,{sx:{position:"relative"},children:[s.jsx(a.Tabs.Tab,{value:"SQL",children:"SQL"}),s.jsx(a.Tabs.Tab,{value:"Preview",children:"Preview"}),s.jsx(Nr,{}),s.jsx(a.ActionIcon,{color:"blue",variant:"filled",onClick:x,disabled:!m,sx:{position:"absolute",top:0,right:10},children:s.jsx(_.DeviceFloppy,{size:18})})]}),s.jsx(a.Tabs.Panel,{value:"SQL",pt:"sm",children:s.jsx(Fr,{height:"100%",value:p,onChange:h,defaultLanguage:"sql",theme:"sql-dark"})}),s.jsx(a.Tabs.Panel,{value:"Preview",pt:"sm",children:s.jsx(NT,{value:p})})]})]})}),GT=S.observer(({id:e})=>{const t=Y(),n=X(),r=f.useMemo(()=>n.sqlSnippets.findByKey(e),[e]);if(!e)return null;if(!r)return s.jsxs(a.Text,{size:14,children:["SQL Snippet by key[",e,"] is not found"]});const i=()=>{t.editor.setPath(["_SQL_SNIPPETS_",""])},o=()=>{n.sqlSnippets.removeByKey(e),i()},l=c=>{t.editor.setPath(["_SQL_SNIPPETS_",c])};return s.jsx(FT,{item:r,remove:o,onKeyChanged:l})}),WT=S.observer(()=>{const[e,t]=f.useState([]),n=ze.useModals(),r=Y(),i=h=>{r.editor.setPath(["_SQL_SNIPPETS_",h])},o=()=>{n.openConfirmModal({title:"Delete ununsed SQL snippets?",children:s.jsx(a.Text,{size:"sm",children:"This action cannot be undone."}),labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>r.content.removeUnusedSQLSnippets(),confirmProps:{color:"red"},zIndex:320})},l=()=>{r.content.sqlSnippets.downloadSchema(e)},c=f.useMemo(()=>r.content.sqlSnippets.sortedList.map(h=>h.key),[r.content.sqlSnippets.sortedList]),u=()=>{t(c)},d=()=>{t([])},p=r.content.sqlSnippetsUsage;return s.jsxs(a.Stack,{sx:{height:"100%"},spacing:"sm",pb:"59px",children:[s.jsx(a.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:s.jsx(a.Text,{px:"md",align:"left",sx:{userSelect:"none",cursor:"default"},children:"Manage SQL Snippets"})}),s.jsxs(a.Flex,{justify:"space-between",align:"center",px:12,children:[s.jsxs(a.Group,{position:"left",children:[s.jsxs(a.Button.Group,{children:[s.jsx(a.Button,{variant:"default",size:"xs",onClick:u,children:"Select All"}),s.jsx(a.Button,{variant:"default",size:"xs",onClick:d,children:"Clear Selection"})]}),s.jsx(a.Button,{size:"xs",color:"blue",leftIcon:s.jsx(k.IconCode,{size:14}),disabled:e.length===0,onClick:l,children:"Download Schema"})]}),s.jsx(a.Button,{variant:"subtle",size:"xs",color:"red",leftIcon:s.jsx(k.IconTrash,{size:14}),disabled:!r.content.hasUnusedSQLSnippets,onClick:o,children:"Delete unused SQL snippets"})]}),s.jsx(a.Box,{sx:{flexGrow:1,overflow:"auto"},children:s.jsx(a.Checkbox.Group,{size:"xs",value:e,onChange:t,children:s.jsxs(a.Table,{fontSize:"sm",highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"40px"}}),s.jsx("th",{children:"Key"}),s.jsx("th",{style:{width:"100px",textAlign:"center"},children:"Usage"}),s.jsx("th",{style:{width:"300px",paddingLeft:"24px"},children:"Action"})]})}),s.jsx("tbody",{children:r.content.sqlSnippets.sortedList.map(h=>{var m;const x=((m=p[h.key])==null?void 0:m.length)??0;return s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx(a.Checkbox,{value:h.key,styles:{input:{cursor:"pointer"}}})}),s.jsx("td",{children:h.key}),s.jsx("td",{style:{color:x===0?"#ff0000":"#000",fontWeight:x===0?"bold":"normal",textAlign:"center"},children:x}),s.jsx("td",{children:s.jsx(a.Button,{variant:"subtle",size:"xs",onClick:()=>i(h.key),children:"Open"})})]},h.key)})})]})})})]})}),RT=S.observer(({id:e})=>{const t=ze.useModals(),n=Y(),r=X();if(e==="")return null;const i=r.views.findByID(e);if(!i)return s.jsxs(a.Text,{size:14,children:["View by ID[",e,"] is not found"]});const o=()=>{n.editor.setPath(["_VIEWS_",""])},l=()=>{t.openConfirmModal({title:"Delete this view?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.views.removeByID(e),o()},zIndex:320})};return s.jsxs(a.Stack,{sx:{maxWidth:"600px",height:"100%"},spacing:"sm",children:[s.jsx(a.Group,{position:"right",pt:10,children:s.jsx(a.Button,{size:"xs",color:"red",leftIcon:s.jsx(_.Trash,{size:16}),onClick:l,children:"Delete this view"})}),s.jsx(a.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:s.jsx(j_,{view:i})})]})});function QT(e){return e.length===1&&e[0]==="_QUERY_VARS_"}function KT(e){return e.length===1&&e[0]==="_MOCK_CONTEXT_"}function UT(e){return e.length===1&&e[0]==="_FILTERS_"}function YT(e){return e.length===2&&e[0]==="_FILTERS_"}function XT(e){return e.length===1&&e[0]==="_SQL_SNIPPETS_"}function JT(e){return e.length===2&&e[0]==="_SQL_SNIPPETS_"}function ZT(e){return e.length===2&&e[0]==="_QUERIES_"}function HT(e){return e.length===1&&e[0]==="_QUERIES_"}function eD(e){return e.length===2&&e[0]==="_VIEWS_"}function tD(e){return e.length===4&&e[0]==="_VIEWS_"&&e[2]==="_PANELS_"}const nD=S.observer(()=>s.jsx(a.Stack,{sx:{height:"100%"},p:"sm",children:s.jsx(Rl,{})})),sD=S.observer(()=>{const e=Y().editor,t=e.path;return QT(t)?s.jsx(nD,{}):KT(t)?s.jsx(Ck,{}):UT(t)?s.jsx(wk,{}):YT(t)?s.jsx(a.Box,{p:"xs",pl:20,children:s.jsx(vk,{id:t[1]})}):XT(t)?s.jsx(WT,{}):JT(t)?s.jsx(GT,{id:t[1]}):HT(t)?s.jsx(aT,{}):ZT(t)?s.jsx(qT,{id:t[1]}):eD(t)?s.jsx(a.Box,{p:"xs",pl:20,children:s.jsx(RT,{id:t[1]})}):tD(t)?s.jsx(iT,{viewID:t[1],panelID:t[3]}):s.jsx(a.Box,{children:e.path})}),rD=S.observer(()=>s.jsx(sD,{})),iD=S.observer(()=>{const e=Y(),t=()=>{const n=new Date().getTime().toString(),r={id:n,key:n,label:n,order:e.content.filters.current.length+1,type:de.TextInput,config:$o(),visibleInViewsIDs:["Main"],auto_submit:!1};e.content.filters.append(r),e.editor.setPath(["_FILTERS_",n])};return s.jsx(a.Button,{variant:"subtle",leftIcon:s.jsx(k.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Filter"})}),aD=S.observer(({parentID:e})=>{const t=X();if(!e)return null;const n=t.views.findByID(e);return!n||n.type===L.Tabs?null:s.jsx(a.Button,{variant:"subtle",leftIcon:s.jsx(k.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:()=>t.addANewPanel(n.id),sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Panel"})}),oD=S.observer(()=>{const e=Y(),t=()=>{const n=new Date().getTime().toString(),r={id:n,name:n,type:Me.Postgresql,key:"",sql:""};e.content.queries.append(r),e.editor.setPath(["_QUERIES_",n])};return s.jsx(a.Button,{variant:"subtle",leftIcon:s.jsx(k.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Query"})}),lD=S.observer(()=>{const e=Y(),t=()=>{const n=new Date().getTime().toString(),r={key:n,value:""};e.content.sqlSnippets.append(r),e.editor.setPath(["_SQL_SNIPPETS_",n])};return s.jsx(a.Button,{variant:"subtle",leftIcon:s.jsx(k.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a SQL Snippet"})}),cD=S.observer(()=>{const e=X();return s.jsx(a.Button,{variant:"subtle",leftIcon:s.jsx(k.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:e.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a View"})}),uD=S.observer(()=>{const e=Y();return s.jsx(a.Button,{variant:"subtle",rightIcon:s.jsx(k.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>e.editor.setPath(["_QUERIES_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:"Manage Queries"})}),dD=S.observer(()=>{const e=Y();return s.jsx(a.Button,{variant:"subtle",rightIcon:s.jsx(k.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>e.editor.setPath(["_SQL_SNIPPETS_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:"Manage SQL Snippets"})}),pD=S.observer(()=>{const e=Y();return s.jsx(a.Button,{variant:"subtle",rightIcon:s.jsx(k.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>e.editor.setPath(["_FILTERS_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:"Manage Filters"})}),hD=S.observer(({action_type:e,parentID:t})=>e==="_Add_A_Filter_"?s.jsx(iD,{}):e==="_Add_A_SQL_SNIPPET_"?s.jsx(lD,{}):e==="_Add_A_QUERY_"?s.jsx(oD,{}):e==="_Add_A_VIEW_"?s.jsx(cD,{}):e==="_Add_A_PANEL_"?s.jsx(aD,{parentID:t}):e==="_QUERIES_SETTINGS_"?s.jsx(uD,{}):e==="_SQL_SNIPPETS_SETTINGS_"?s.jsx(dD,{}):e==="_FILTERS_SETTINGS_"?s.jsx(pD,{}):null),Ul=S.observer(({option:e})=>{var d;const t=Y().editor,n=t.isOptionActive,r=n(t.path,e),i=t.isOptionOpened,o=t.navigate,l=i(e),[c,u]=f.useState(l);return f.useEffect(()=>{u(l)},[l]),s.jsx(a.NavLink,{active:r,defaultOpened:l,opened:c,onChange:u,label:e.label,onClick:()=>o(e),icon:e.Icon?s.jsx(e.Icon,{size:18}):null,children:(d=e.children)==null?void 0:d.map(p=>p._type==="ACTION"?s.jsx(hD,{action_type:p._action_type,parentID:p.parentID},`_ADD_${p.value}_`):s.jsx(Ul,{option:p},p.value))},e.label)}),xD=S.observer(()=>{const e=Y();return s.jsx(a.Box,{sx:{position:"relative"},children:e.editor.navOptions.map(t=>s.jsx(Ul,{option:t},t.value))})}),fD=S.observer(()=>{const e=Y();return s.jsxs(a.Navbar,{p:0,width:{base:220,xs:220,sm:240,md:260,lg:300,xl:320},sx:{height:"100vh - 60px - 60px"},children:[s.jsx(a.Navbar.Section,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:s.jsx(a.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Settings"})}),s.jsx(a.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:s.jsx(xD,{})}),s.jsx(a.Navbar.Section,{children:s.jsx(a.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:s.jsx(a.Button,{size:"xs",color:"red",leftIcon:s.jsx(k.IconX,{size:18}),onClick:()=>e.editor.close(),children:"Close"})})})]})}),gD={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden",minWidth:"calc(var(--mantine-navbar-width, 0px) + 1200px)"},body:{flexGrow:1,nav:{top:0,height:"100vh"}},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:0,height:"100vh"}},mD=S.observer(()=>{const e=Y().editor;return s.jsx(a.Modal,{onClose:()=>e.setSettingsOpen(!1),closeOnEscape:!1,closeOnClickOutside:!1,opened:e.settings_open,fullScreen:!0,title:null,transitionProps:{duration:0},withCloseButton:!1,withinPortal:!0,zIndex:300,styles:{body:{padding:"0 !important"},content:{overflowY:"hidden !important"}},children:s.jsx(a.AppShell,{padding:0,navbar:s.jsx(fD,{}),styles:gD,children:s.jsx(rD,{})})})}),yD=e=>e.replace(/([^:])(\/\/+)/g,"$1/");function bD(e){f.useEffect(()=>{if(me.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/dashboard");const n=yD(e);me.loader.config({paths:{vs:n}}),me.loader.init().then(r=>console.log("monaco instance:",r))},[])}Va();const jD={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden"},body:{flexGrow:1},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:60+30,height:"100vh"}},vD=({context:e,dashboard:t,content:n,update:r,className:i="dashboard",config:o,onChange:l,headerSlot:c},u)=>{bD(o.monacoPath),cs(o);const{data:d=[]}=V.useRequest(ds),{data:p=[]}=V.useRequest(_i),h=f.useMemo(()=>Dl(t,n,d,p,e),[t,n]);f.useImperativeHandle(u,()=>h,[h]),Il(h.content,!0),f.useEffect(()=>{h.context.replace(e)},[e]),f.useEffect(()=>{h.datasources.replace(d)},[d]),f.useEffect(()=>{h.globalSQLSnippets.replace(p)},[p]),f.useEffect(()=>W.reaction(()=>W.toJS(h.json),w=>{l==null||l(w)}),[h]);const x=async()=>{await r(h.json,h.content.json)},m=V.useCreation(wr,[]),j=Ml(m);return s.jsx(ze.ModalsProvider,{children:s.jsx(ms,{value:{searchButtonProps:o.searchButtonProps},children:s.jsx(xs,{value:h,children:s.jsx(ys,{value:h.content,children:s.jsx(pn.Provider,{value:{inEditMode:!0},children:s.jsx(et.Provider,{value:m,children:s.jsxs(qn,{configure:j,children:[s.jsx(a.AppShell,{padding:0,header:s.jsx(E_,{saveDashboardChanges:x,headerSlot:c}),navbar:s.jsx(ak,{}),styles:jD,children:s.jsx(a.Box,{className:`${i} dashboard-root`,sx:{position:"relative"},children:h.content.views.visibleViews.map(w=>s.jsx(ml,{view:w},w.id))})}),s.jsx(mD,{})]})})})})})})})},wD=S.observer(f.forwardRef(vD)),wI="",Yl=g.types.model({id:g.types.string,name:g.types.string,dashboard_id:g.types.string,create_time:g.types.string,update_time:g.types.string,version:g.types.string,filters:el,queries:nl,sqlSnippets:sl,views:Uo,panels:Zo,mock_context:Mo}).views(e=>({get json(){return{id:e.id,name:e.name,create_time:e.create_time,update_time:e.update_time,dashboard_id:e.dashboard_id,content:{views:e.views.json,panels:e.panels.json,filters:e.filters.json,version:e.version,definition:{queries:e.queries.json,sqlSnippets:e.sqlSnippets.json,mock_context:e.mock_context.current}}}},get contentJSON(){return this.json.content},get payloadForSQL(){const t=g.getParent(e).context.current,n=g.getParent(e).globalSQLSnippets,r={context:{...e.mock_context.current,...t},filters:e.filters.values};return{...r,sql_snippets:Wn(e.sqlSnippets.current,"key","value",r),global_sql_snippets:Wn(n.list,"id","content",r)}},get payloadForViz(){const t=g.getParent(e).context.current;return{context:{...e.mock_context.current,...t},filters:e.filters.values}},get dashboardState(){return us(this.payloadForSQL)},getAdditionalQueryInfo(t){return{content_id:e.id,query_id:t,params:this.dashboardState}},get data(){return e.queries.current.map(({id:n,data:r})=>({id:n,data:r})).reduce((n,r)=>(n[r.id]=r.data,n),{})},getDataStuffByID(t){const n=e.queries.findByID(t);return n?{data:n.data,len:n.data.length,state:n.state,error:n.error}:{data:[],len:0,state:"idle",error:void 0}}})).actions(e=>({}));function CD({id:e,name:t,dashboard_id:n,create_time:r,update_time:i,content:o}){if(!o)throw new Error("unexpected null content when creating a content model");const{version:l,filters:c,views:u,panels:d,definition:{queries:p,sqlSnippets:h,mock_context:x={}}}=o;return Yl.create({id:e,name:t,dashboard_id:n,create_time:r,update_time:i,version:l,filters:tl(c),queries:l1(p),sqlSnippets:u1(h),mock_context:zo(x),views:XS(u),panels:{list:d}})}const SD=g.types.model({id:g.types.identifier,name:g.types.string,group:g.types.string,content:Yl,content_id:g.types.string,datasources:US,globalSQLSnippets:Ro,context:Tr});function _D({id:e,name:t,group:n,content_id:r},i,o,l,c){return SD.create({id:e,name:t,group:n,content_id:r,content:CD(i),datasources:{list:o},globalSQLSnippets:{list:l},context:Qo(c)})}Va();const kD=S.observer(({context:e,dashboard:t,content:n,className:r="dashboard",config:i,fullScreenPanelID:o,setFullScreenPanelID:l})=>{cs(i);const{data:c=[]}=V.useRequest(ds),{data:u=[]}=V.useRequest(_i),d=f.useMemo(()=>_D(t,n,c,u,e),[t,n]);Il(d.content,!1),f.useEffect(()=>{d.context.replace(e)},[e]),f.useEffect(()=>{d.datasources.replace(c)},[c]),f.useEffect(()=>{d.globalSQLSnippets.replace(u)},[u]);const p=V.useCreation(wr,[]),h=Ml(p);return s.jsx(ze.ModalsProvider,{children:s.jsx(ms,{value:{searchButtonProps:i.searchButtonProps},children:s.jsx(xs,{value:d,children:s.jsx(ys,{value:d.content,children:s.jsx(js.Provider,{value:{fullScreenPanelID:o,setFullScreenPanelID:l},children:s.jsx(pn.Provider,{value:{inEditMode:!1},children:s.jsx(a.Box,{className:`${r} dashboard-root`,children:s.jsx(et.Provider,{value:p,children:s.jsx(qn,{configure:h,children:d.content.views.visibleViews.map(x=>s.jsx(Qn,{view:x},x.id))})})})})})})})})})});I.extend(Tc),I.extend(Dc),I.extend(Ic),I.extend(Mc),I.extend(zc),I.extend(Ac),I.extend(Ec),I.extend(Pc),I.extend(Lc),I.extend(Oc),I.extend(Vc),I.extend(qc),I.extend(Nc),I.extend(Fc),I.extend(Gc),I.extend(Bc),I.extend($c),I.extend(Wc),I.extend(Rc),I.extend(Qc),I.extend(Kc),I.extend(Uc),I.extend(Yc),I.extend(Xc),I.extend(Jc),I.extend(Zc),I.extend(Hc),I.extend(eu),I.extend(tu),I.extend(nu),I.extend(ru),I.extend(iu),I.extend(su),I.tz.setDefault("UTC"),I.updateLocale("en",{weekStart:1});const TD=()=>Promise.resolve().then(()=>Eu).then(({version:e})=>(console.log(`[@devtable/dashboard] version: ${e}`),e));C.APIClient=Xe,C.ContentModel=Er,C.ContentModelContextProvider=ys,C.DashboardApiClient=vi,C.DashboardApiFacadeClient=wi,C.DashboardEditor=wD,C.DashboardFilterType=de,C.DashboardMode=yl,C.DashboardModel=Tl,C.DashboardModelContextProvider=xs,C.DashboardThemeContextProvider=ms,C.DashboardViewEditor=ml,C.DashboardViewRender=Qn,C.DefaultApiClient=ji,C.DescriptionPopover=Dr,C.FacadeApiClient=yu,C.FiltersModel=jl,C.FullScreenPanel=pl,C.FullScreenPanelContext=js,C.LayoutStateContext=pn,C.Panel=dl,C.PanelContextProvider=bs,C.PanelErrorOrStateMessage=cl,C.PanelModel=Cl,C.PanelRender=Mr,C.PanelVizSection=Ir,C.PanelsModel=Sl,C.QueriesModel=vl,C.ReadOnlyDashboard=kD,C.SQLSnippetsModel=wl,C.ViewComponentTypeBackground=bl,C.ViewComponentTypeColor=Q1,C.ViewComponentTypeName=R1,C.ViewsModel=_l,C.Viz=ll,C.applyPartialDashboard=i_,C.configureAPIClient=cs,C.createContentModel=kl,C.createDashboardModel=Dl,C.facadeApiClient=Ci,C.getInitialDashboardViewsModel=Ar,C.getVersion=TD,C.initialDashboardContent=K1,C.useDashboardContext=fs,C.useDashboardThemeContext=Ai,C.useEditContentModelContext=X,C.useEditDashboardContext=Y,C.useEditPanelContext=Le,C.useFullScreenPanelContext=Bi,C.usePanelFullScreen=hl,C.useRenderContentModelContext=ce,C.useRenderDashboardContext=gs,C.useRenderPanelContext=dt,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})});
|
|
481
|
+
`)},$T=S.observer(({queryModel:e})=>e.typedAsSQL?s.jsxs(a.Tabs,{defaultValue:"Edit",orientation:"vertical",sx:{flexGrow:1},styles:{tabLabel:{width:"100%",height:"28px",lineHeight:"28px"}},keepMounted:!1,children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"Edit",children:s.jsx(a.Group,{spacing:14,position:"apart",children:"Edit SQL"})}),s.jsx(a.Tabs.Tab,{value:"Preview",children:"Preview SQL"}),s.jsx(a.Tabs.Tab,{value:"pre_process",children:"Process Request"}),s.jsx(a.Tabs.Tab,{value:"post_process",children:"Process Result"}),s.jsx(Nr,{}),e.datasource&&s.jsx(Gl,{dataSource:e.datasource})]}),s.jsx(a.Tabs.Panel,{value:"Edit",sx:{position:"relative"},p:"sm",children:s.jsx(LT,{queryModel:e})}),s.jsx(a.Tabs.Panel,{value:"Preview",p:0,pl:4,children:s.jsx(BT,{value:e.sql})}),s.jsx(a.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:s.jsx(en,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:Kl.pre})}),s.jsx(a.Tabs.Panel,{value:"post_process",p:"sm",children:s.jsx(en,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:Kl.post})})]}):null),Jn={height:"calc(100% - 44px)",padding:0},VT=S.observer(({queryModel:e})=>{const t=X(),n=f.useMemo(()=>e.datasource?e.typedAsHTTP?"HTTP":"SQL":"Configurations",[e.datasource,e.typedAsHTTP]),[r,i]=f.useState(n);f.useEffect(()=>{i(c=>c!=="Configurations"&&n==="Configurations"?"Configurations":c)},[n]);const o=t.findQueryUsage(e.id),l=o.length===0;return s.jsxs(a.Tabs,{value:r,onTabChange:i,defaultValue:n,orientation:"horizontal",keepMounted:!1,sx:{height:"100vh"},children:[s.jsxs(a.Tabs.List,{grow:!0,children:[s.jsx(a.Tabs.Tab,{value:"Configurations",children:"Configurations"}),e.typedAsSQL&&s.jsx(a.Tabs.Tab,{value:"SQL",children:"Request"}),e.typedAsHTTP&&s.jsx(a.Tabs.Tab,{value:"HTTP",children:"Request"}),s.jsx(a.Tabs.Tab,{value:"Data",disabled:!e.datasource,children:s.jsx(a.Tooltip,{label:"Need to pick a Data Source first",disabled:e.datasource,withinPortal:!0,children:s.jsx(a.Text,{children:"Data"})})}),s.jsx(a.Tabs.Tab,{value:"Usage",disabled:l,children:s.jsx(a.Tooltip,{label:"This query is not used for any filter or panel",disabled:!l,withinPortal:!0,children:s.jsx(a.Text,{children:"Usage"})})})]}),s.jsx(a.Tabs.Panel,{value:"Configurations",pt:0,p:0,children:s.jsx(TT,{queryModel:e})}),e.typedAsSQL&&s.jsx(a.Tabs.Panel,{value:"SQL",sx:Jn,children:s.jsx(a.Stack,{sx:{height:"100%"},children:s.jsx($T,{queryModel:e})})}),e.typedAsHTTP&&s.jsx(a.Tabs.Panel,{value:"HTTP",sx:Jn,children:s.jsx(a.Stack,{sx:{height:"100%"},children:s.jsx(zT,{queryModel:e})})}),s.jsx(a.Tabs.Panel,{value:"Data",sx:{...Jn,overflow:"hidden"},children:s.jsx($r,{id:e.id,moreActions:null,refreshOnMount:!0})}),s.jsx(a.Tabs.Panel,{value:"Usage",sx:{...Jn,overflow:"hidden"},children:s.jsx(AT,{queryID:e.id,usage:o})})]})}),qT=S.observer(({id:e})=>{const n=X().queries.findByID(e);return e===""?null:n?s.jsx(VT,{queryModel:n}):s.jsx(a.Text,{size:14,color:"red",children:"Invalid Query ID"})}),NT=S.observer(({value:e})=>{const n=ce().payloadForSQL,r=f.useMemo(()=>ls(e,n),[e,n]);return s.jsx(Fr,{height:"100%",value:r})}),FT=S.observer(({item:e,remove:t,onKeyChanged:n})=>{const[r,i]=f.useState("SQL"),[o,l]=f.useState(e.key),c=()=>{e.setKey(o),n(o)},u=o!==e.key,d=e.isADuplicatedKey(o),[p,h]=f.useState(e.value),x=()=>{e.setValue(p)};f.useEffect(()=>{l(e.key),h(e.value)},[e]);const m=p!==e.value,j=ze.useModals(),w=()=>{j.openConfirmModal({title:"Delete this SQL snippet?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:t,confirmProps:{color:"red"},zIndex:320})};return s.jsxs(a.Stack,{p:20,sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",children:[s.jsxs(a.Group,{sx:{alignItems:"end"},spacing:40,children:[s.jsx(a.TextInput,{label:d?"This key is occupied by another snippet":"Key",value:o,onChange:T=>{l(T.currentTarget.value)},sx:{flexGrow:"1 !important"},rightSection:s.jsx(a.ActionIcon,{color:"blue",variant:"subtle",onClick:c,disabled:!u||d,children:s.jsx(_.DeviceFloppy,{size:16})}),error:d}),s.jsx(a.Button,{leftIcon:s.jsx(_.Trash,{size:16}),color:"red",variant:"light",onClick:w,children:"Delete this SQL Snippet"})]}),s.jsxs(a.Tabs,{value:r,onTabChange:i,sx:{flexGrow:1},styles:{panel:{height:"calc(100% - 50px)"}},children:[s.jsxs(a.Tabs.List,{sx:{position:"relative"},children:[s.jsx(a.Tabs.Tab,{value:"SQL",children:"SQL"}),s.jsx(a.Tabs.Tab,{value:"Preview",children:"Preview"}),s.jsx(Nr,{}),s.jsx(a.ActionIcon,{color:"blue",variant:"filled",onClick:x,disabled:!m,sx:{position:"absolute",top:0,right:10},children:s.jsx(_.DeviceFloppy,{size:18})})]}),s.jsx(a.Tabs.Panel,{value:"SQL",pt:"sm",children:s.jsx(Fr,{height:"100%",value:p,onChange:h,defaultLanguage:"sql",theme:"sql-dark"})}),s.jsx(a.Tabs.Panel,{value:"Preview",pt:"sm",children:s.jsx(NT,{value:p})})]})]})}),GT=S.observer(({id:e})=>{const t=Y(),n=X(),r=f.useMemo(()=>n.sqlSnippets.findByKey(e),[e]);if(!e)return null;if(!r)return s.jsxs(a.Text,{size:14,children:["SQL Snippet by key[",e,"] is not found"]});const i=()=>{t.editor.setPath(["_SQL_SNIPPETS_",""])},o=()=>{n.sqlSnippets.removeByKey(e),i()},l=c=>{t.editor.setPath(["_SQL_SNIPPETS_",c])};return s.jsx(FT,{item:r,remove:o,onKeyChanged:l})}),WT=S.observer(()=>{const[e,t]=f.useState([]),n=ze.useModals(),r=Y(),i=h=>{r.editor.setPath(["_SQL_SNIPPETS_",h])},o=()=>{n.openConfirmModal({title:"Delete ununsed SQL snippets?",children:s.jsx(a.Text,{size:"sm",children:"This action cannot be undone."}),labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>r.content.removeUnusedSQLSnippets(),confirmProps:{color:"red"},zIndex:320})},l=()=>{r.content.sqlSnippets.downloadSchema(e)},c=f.useMemo(()=>r.content.sqlSnippets.sortedList.map(h=>h.key),[r.content.sqlSnippets.sortedList]),u=()=>{t(c)},d=()=>{t([])},p=r.content.sqlSnippetsUsage;return s.jsxs(a.Stack,{sx:{height:"100%"},spacing:"sm",pb:"59px",children:[s.jsx(a.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:s.jsx(a.Text,{px:"md",align:"left",sx:{userSelect:"none",cursor:"default"},children:"Manage SQL Snippets"})}),s.jsxs(a.Flex,{justify:"space-between",align:"center",px:12,children:[s.jsxs(a.Group,{position:"left",children:[s.jsxs(a.Button.Group,{children:[s.jsx(a.Button,{variant:"default",size:"xs",onClick:u,children:"Select All"}),s.jsx(a.Button,{variant:"default",size:"xs",onClick:d,children:"Clear Selection"})]}),s.jsx(a.Button,{size:"xs",color:"blue",leftIcon:s.jsx(k.IconCode,{size:14}),disabled:e.length===0,onClick:l,children:"Download Schema"})]}),s.jsx(a.Button,{variant:"subtle",size:"xs",color:"red",leftIcon:s.jsx(k.IconTrash,{size:14}),disabled:!r.content.hasUnusedSQLSnippets,onClick:o,children:"Delete unused SQL snippets"})]}),s.jsx(a.Box,{sx:{flexGrow:1,overflow:"auto"},children:s.jsx(a.Checkbox.Group,{size:"xs",value:e,onChange:t,children:s.jsxs(a.Table,{fontSize:"sm",highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"40px"}}),s.jsx("th",{children:"Key"}),s.jsx("th",{style:{width:"100px",textAlign:"center"},children:"Usage"}),s.jsx("th",{style:{width:"300px",paddingLeft:"24px"},children:"Action"})]})}),s.jsx("tbody",{children:r.content.sqlSnippets.sortedList.map(h=>{var m;const x=((m=p[h.key])==null?void 0:m.length)??0;return s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx(a.Checkbox,{value:h.key,styles:{input:{cursor:"pointer"}}})}),s.jsx("td",{children:h.key}),s.jsx("td",{style:{color:x===0?"#ff0000":"#000",fontWeight:x===0?"bold":"normal",textAlign:"center"},children:x}),s.jsx("td",{children:s.jsx(a.Button,{variant:"subtle",size:"xs",onClick:()=>i(h.key),children:"Open"})})]},h.key)})})]})})})]})}),RT=S.observer(({id:e})=>{const t=ze.useModals(),n=Y(),r=X();if(e==="")return null;const i=r.views.findByID(e);if(!i)return s.jsxs(a.Text,{size:14,children:["View by ID[",e,"] is not found"]});const o=()=>{n.editor.setPath(["_VIEWS_",""])},l=()=>{t.openConfirmModal({title:"Delete this view?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.views.removeByID(e),o()},zIndex:320})};return s.jsxs(a.Stack,{sx:{maxWidth:"600px",height:"100%"},spacing:"sm",children:[s.jsx(a.Group,{position:"right",pt:10,children:s.jsx(a.Button,{size:"xs",color:"red",leftIcon:s.jsx(_.Trash,{size:16}),onClick:l,children:"Delete this view"})}),s.jsx(a.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:s.jsx(j_,{view:i})})]})});function QT(e){return e.length===1&&e[0]==="_QUERY_VARS_"}function KT(e){return e.length===1&&e[0]==="_MOCK_CONTEXT_"}function UT(e){return e.length===1&&e[0]==="_FILTERS_"}function YT(e){return e.length===2&&e[0]==="_FILTERS_"}function XT(e){return e.length===1&&e[0]==="_SQL_SNIPPETS_"}function JT(e){return e.length===2&&e[0]==="_SQL_SNIPPETS_"}function ZT(e){return e.length===2&&e[0]==="_QUERIES_"}function HT(e){return e.length===1&&e[0]==="_QUERIES_"}function eD(e){return e.length===2&&e[0]==="_VIEWS_"}function tD(e){return e.length===4&&e[0]==="_VIEWS_"&&e[2]==="_PANELS_"}const nD=S.observer(()=>s.jsx(a.Stack,{sx:{height:"100%"},p:"sm",children:s.jsx(Rl,{})})),sD=S.observer(()=>{const e=Y().editor,t=e.path;return QT(t)?s.jsx(nD,{}):KT(t)?s.jsx(Ck,{}):UT(t)?s.jsx(wk,{}):YT(t)?s.jsx(a.Box,{p:"xs",pl:20,children:s.jsx(vk,{id:t[1]})}):XT(t)?s.jsx(WT,{}):JT(t)?s.jsx(GT,{id:t[1]}):HT(t)?s.jsx(aT,{}):ZT(t)?s.jsx(qT,{id:t[1]}):eD(t)?s.jsx(a.Box,{p:"xs",pl:20,children:s.jsx(RT,{id:t[1]})}):tD(t)?s.jsx(iT,{viewID:t[1],panelID:t[3]}):s.jsx(a.Box,{children:e.path})}),rD=S.observer(()=>s.jsx(sD,{})),iD=S.observer(()=>{const e=Y(),t=()=>{const n=new Date().getTime().toString(),r={id:n,key:n,label:n,order:e.content.filters.current.length+1,type:de.TextInput,config:$o(),visibleInViewsIDs:["Main"],auto_submit:!1};e.content.filters.append(r),e.editor.setPath(["_FILTERS_",n])};return s.jsx(a.Button,{variant:"subtle",leftIcon:s.jsx(k.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Filter"})}),aD=S.observer(({parentID:e})=>{const t=X();if(!e)return null;const n=t.views.findByID(e);return!n||n.type===L.Tabs?null:s.jsx(a.Button,{variant:"subtle",leftIcon:s.jsx(k.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:()=>t.addANewPanel(n.id),sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Panel"})}),oD=S.observer(()=>{const e=Y(),t=()=>{const n=new Date().getTime().toString(),r={id:n,name:n,type:Me.Postgresql,key:"",sql:""};e.content.queries.append(r),e.editor.setPath(["_QUERIES_",n])};return s.jsx(a.Button,{variant:"subtle",leftIcon:s.jsx(k.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a Query"})}),lD=S.observer(()=>{const e=Y(),t=()=>{const n=new Date().getTime().toString(),r={key:n,value:""};e.content.sqlSnippets.append(r),e.editor.setPath(["_SQL_SNIPPETS_",n])};return s.jsx(a.Button,{variant:"subtle",leftIcon:s.jsx(k.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a SQL Snippet"})}),cD=S.observer(()=>{const e=X();return s.jsx(a.Button,{variant:"subtle",leftIcon:s.jsx(k.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:e.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:"Add a View"})}),uD=S.observer(()=>{const e=Y();return s.jsx(a.Button,{variant:"subtle",rightIcon:s.jsx(k.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>e.editor.setPath(["_QUERIES_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:"Manage Queries"})}),dD=S.observer(()=>{const e=Y();return s.jsx(a.Button,{variant:"subtle",rightIcon:s.jsx(k.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>e.editor.setPath(["_SQL_SNIPPETS_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:"Manage SQL Snippets"})}),pD=S.observer(()=>{const e=Y();return s.jsx(a.Button,{variant:"subtle",rightIcon:s.jsx(k.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>e.editor.setPath(["_FILTERS_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:"Manage Filters"})}),hD=S.observer(({action_type:e,parentID:t})=>e==="_Add_A_Filter_"?s.jsx(iD,{}):e==="_Add_A_SQL_SNIPPET_"?s.jsx(lD,{}):e==="_Add_A_QUERY_"?s.jsx(oD,{}):e==="_Add_A_VIEW_"?s.jsx(cD,{}):e==="_Add_A_PANEL_"?s.jsx(aD,{parentID:t}):e==="_QUERIES_SETTINGS_"?s.jsx(uD,{}):e==="_SQL_SNIPPETS_SETTINGS_"?s.jsx(dD,{}):e==="_FILTERS_SETTINGS_"?s.jsx(pD,{}):null),Ul=S.observer(({option:e})=>{var d;const t=Y().editor,n=t.isOptionActive,r=n(t.path,e),i=t.isOptionOpened,o=t.navigate,l=i(e),[c,u]=f.useState(l);return f.useEffect(()=>{u(l)},[l]),s.jsx(a.NavLink,{active:r,defaultOpened:l,opened:c,onChange:u,label:e.label,onClick:()=>o(e),icon:e.Icon?s.jsx(e.Icon,{size:18}):null,children:(d=e.children)==null?void 0:d.map(p=>p._type==="ACTION"?s.jsx(hD,{action_type:p._action_type,parentID:p.parentID},`_ADD_${p.value}_`):s.jsx(Ul,{option:p},p.value))},e.label)}),xD=S.observer(()=>{const e=Y();return s.jsx(a.Box,{sx:{position:"relative"},children:e.editor.navOptions.map(t=>s.jsx(Ul,{option:t},t.value))})}),fD=S.observer(()=>{const e=Y();return s.jsxs(a.Navbar,{p:0,width:{base:220,xs:220,sm:240,md:260,lg:300,xl:320},sx:{height:"100vh - 60px - 60px",".mantine-NavLink-body":{wordWrap:"break-word"}},children:[s.jsx(a.Navbar.Section,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:s.jsx(a.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:"Settings"})}),s.jsx(a.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:s.jsx(xD,{})}),s.jsx(a.Navbar.Section,{children:s.jsx(a.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:s.jsx(a.Button,{size:"xs",color:"red",leftIcon:s.jsx(k.IconX,{size:18}),onClick:()=>e.editor.close(),children:"Close"})})})]})}),gD={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden",minWidth:"calc(var(--mantine-navbar-width, 0px) + 1200px)"},body:{flexGrow:1,nav:{top:0,height:"100vh"}},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:0,height:"100vh"}},mD=S.observer(()=>{const e=Y().editor;return s.jsx(a.Modal,{onClose:()=>e.setSettingsOpen(!1),closeOnEscape:!1,closeOnClickOutside:!1,opened:e.settings_open,fullScreen:!0,title:null,transitionProps:{duration:0},withCloseButton:!1,withinPortal:!0,zIndex:300,styles:{body:{padding:"0 !important"},content:{overflowY:"hidden !important"}},children:s.jsx(a.AppShell,{padding:0,navbar:s.jsx(fD,{}),styles:gD,children:s.jsx(rD,{})})})}),yD=e=>e.replace(/([^:])(\/\/+)/g,"$1/");function bD(e){f.useEffect(()=>{if(me.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/dashboard");const n=yD(e);me.loader.config({paths:{vs:n}}),me.loader.init().then(r=>console.log("monaco instance:",r))},[])}Va();const jD={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden"},body:{flexGrow:1},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:60+30,height:"100vh"}},vD=({context:e,dashboard:t,content:n,update:r,className:i="dashboard",config:o,onChange:l,headerSlot:c},u)=>{bD(o.monacoPath),cs(o);const{data:d=[]}=V.useRequest(ds),{data:p=[]}=V.useRequest(_i),h=f.useMemo(()=>Dl(t,n,d,p,e),[t,n]);f.useImperativeHandle(u,()=>h,[h]),Il(h.content,!0),f.useEffect(()=>{h.context.replace(e)},[e]),f.useEffect(()=>{h.datasources.replace(d)},[d]),f.useEffect(()=>{h.globalSQLSnippets.replace(p)},[p]),f.useEffect(()=>W.reaction(()=>W.toJS(h.json),w=>{l==null||l(w)}),[h]);const x=async()=>{await r(h.json,h.content.json)},m=V.useCreation(wr,[]),j=Ml(m);return s.jsx(ze.ModalsProvider,{children:s.jsx(ms,{value:{searchButtonProps:o.searchButtonProps},children:s.jsx(xs,{value:h,children:s.jsx(ys,{value:h.content,children:s.jsx(pn.Provider,{value:{inEditMode:!0},children:s.jsx(et.Provider,{value:m,children:s.jsxs(qn,{configure:j,children:[s.jsx(a.AppShell,{padding:0,header:s.jsx(E_,{saveDashboardChanges:x,headerSlot:c}),navbar:s.jsx(ak,{}),styles:jD,children:s.jsx(a.Box,{className:`${i} dashboard-root`,sx:{position:"relative"},children:h.content.views.visibleViews.map(w=>s.jsx(ml,{view:w},w.id))})}),s.jsx(mD,{})]})})})})})})})},wD=S.observer(f.forwardRef(vD)),wI="",Yl=g.types.model({id:g.types.string,name:g.types.string,dashboard_id:g.types.string,create_time:g.types.string,update_time:g.types.string,version:g.types.string,filters:el,queries:nl,sqlSnippets:sl,views:Uo,panels:Zo,mock_context:Mo}).views(e=>({get json(){return{id:e.id,name:e.name,create_time:e.create_time,update_time:e.update_time,dashboard_id:e.dashboard_id,content:{views:e.views.json,panels:e.panels.json,filters:e.filters.json,version:e.version,definition:{queries:e.queries.json,sqlSnippets:e.sqlSnippets.json,mock_context:e.mock_context.current}}}},get contentJSON(){return this.json.content},get payloadForSQL(){const t=g.getParent(e).context.current,n=g.getParent(e).globalSQLSnippets,r={context:{...e.mock_context.current,...t},filters:e.filters.values};return{...r,sql_snippets:Wn(e.sqlSnippets.current,"key","value",r),global_sql_snippets:Wn(n.list,"id","content",r)}},get payloadForViz(){const t=g.getParent(e).context.current;return{context:{...e.mock_context.current,...t},filters:e.filters.values}},get dashboardState(){return us(this.payloadForSQL)},getAdditionalQueryInfo(t){return{content_id:e.id,query_id:t,params:this.dashboardState}},get data(){return e.queries.current.map(({id:n,data:r})=>({id:n,data:r})).reduce((n,r)=>(n[r.id]=r.data,n),{})},getDataStuffByID(t){const n=e.queries.findByID(t);return n?{data:n.data,len:n.data.length,state:n.state,error:n.error}:{data:[],len:0,state:"idle",error:void 0}}})).actions(e=>({}));function CD({id:e,name:t,dashboard_id:n,create_time:r,update_time:i,content:o}){if(!o)throw new Error("unexpected null content when creating a content model");const{version:l,filters:c,views:u,panels:d,definition:{queries:p,sqlSnippets:h,mock_context:x={}}}=o;return Yl.create({id:e,name:t,dashboard_id:n,create_time:r,update_time:i,version:l,filters:tl(c),queries:l1(p),sqlSnippets:u1(h),mock_context:zo(x),views:XS(u),panels:{list:d}})}const SD=g.types.model({id:g.types.identifier,name:g.types.string,group:g.types.string,content:Yl,content_id:g.types.string,datasources:US,globalSQLSnippets:Ro,context:Tr});function _D({id:e,name:t,group:n,content_id:r},i,o,l,c){return SD.create({id:e,name:t,group:n,content_id:r,content:CD(i),datasources:{list:o},globalSQLSnippets:{list:l},context:Qo(c)})}Va();const kD=S.observer(({context:e,dashboard:t,content:n,className:r="dashboard",config:i,fullScreenPanelID:o,setFullScreenPanelID:l})=>{cs(i);const{data:c=[]}=V.useRequest(ds),{data:u=[]}=V.useRequest(_i),d=f.useMemo(()=>_D(t,n,c,u,e),[t,n]);Il(d.content,!1),f.useEffect(()=>{d.context.replace(e)},[e]),f.useEffect(()=>{d.datasources.replace(c)},[c]),f.useEffect(()=>{d.globalSQLSnippets.replace(u)},[u]);const p=V.useCreation(wr,[]),h=Ml(p);return s.jsx(ze.ModalsProvider,{children:s.jsx(ms,{value:{searchButtonProps:i.searchButtonProps},children:s.jsx(xs,{value:d,children:s.jsx(ys,{value:d.content,children:s.jsx(js.Provider,{value:{fullScreenPanelID:o,setFullScreenPanelID:l},children:s.jsx(pn.Provider,{value:{inEditMode:!1},children:s.jsx(a.Box,{className:`${r} dashboard-root`,children:s.jsx(et.Provider,{value:p,children:s.jsx(qn,{configure:h,children:d.content.views.visibleViews.map(x=>s.jsx(Qn,{view:x},x.id))})})})})})})})})})});I.extend(Tc),I.extend(Dc),I.extend(Ic),I.extend(Mc),I.extend(zc),I.extend(Ac),I.extend(Ec),I.extend(Pc),I.extend(Lc),I.extend(Oc),I.extend(Vc),I.extend(qc),I.extend(Nc),I.extend(Fc),I.extend(Gc),I.extend(Bc),I.extend($c),I.extend(Wc),I.extend(Rc),I.extend(Qc),I.extend(Kc),I.extend(Uc),I.extend(Yc),I.extend(Xc),I.extend(Jc),I.extend(Zc),I.extend(Hc),I.extend(eu),I.extend(tu),I.extend(nu),I.extend(ru),I.extend(iu),I.extend(su),I.tz.setDefault("UTC"),I.updateLocale("en",{weekStart:1});const TD=()=>Promise.resolve().then(()=>Eu).then(({version:e})=>(console.log(`[@devtable/dashboard] version: ${e}`),e));C.APIClient=Xe,C.ContentModel=Er,C.ContentModelContextProvider=ys,C.DashboardApiClient=vi,C.DashboardApiFacadeClient=wi,C.DashboardEditor=wD,C.DashboardFilterType=de,C.DashboardMode=yl,C.DashboardModel=Tl,C.DashboardModelContextProvider=xs,C.DashboardThemeContextProvider=ms,C.DashboardViewEditor=ml,C.DashboardViewRender=Qn,C.DefaultApiClient=ji,C.DescriptionPopover=Dr,C.FacadeApiClient=yu,C.FiltersModel=jl,C.FullScreenPanel=pl,C.FullScreenPanelContext=js,C.LayoutStateContext=pn,C.Panel=dl,C.PanelContextProvider=bs,C.PanelErrorOrStateMessage=cl,C.PanelModel=Cl,C.PanelRender=Mr,C.PanelVizSection=Ir,C.PanelsModel=Sl,C.QueriesModel=vl,C.ReadOnlyDashboard=kD,C.SQLSnippetsModel=wl,C.ViewComponentTypeBackground=bl,C.ViewComponentTypeColor=Q1,C.ViewComponentTypeName=R1,C.ViewsModel=_l,C.Viz=ll,C.applyPartialDashboard=i_,C.configureAPIClient=cs,C.createContentModel=kl,C.createDashboardModel=Dl,C.facadeApiClient=Ci,C.getInitialDashboardViewsModel=Ar,C.getVersion=TD,C.initialDashboardContent=K1,C.useDashboardContext=fs,C.useDashboardThemeContext=Ai,C.useEditContentModelContext=X,C.useEditDashboardContext=Y,C.useEditPanelContext=Le,C.useFullScreenPanelContext=Bi,C.usePanelFullScreen=hl,C.useRenderContentModelContext=ce,C.useRenderDashboardContext=gs,C.useRenderPanelContext=dt,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})});
|