@devtable/dashboard 11.0.0 → 11.0.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 +347 -338
- package/dist/dashboard.umd.js +2 -2
- package/dist/stats.html +1 -1
- package/package.json +1 -1
package/dist/dashboard.umd.js
CHANGED
|
@@ -53,7 +53,7 @@ Check the top-level render call using <`+A+">.")}return D}}function Hc(w,D){{if(
|
|
|
53
53
|
</table>
|
|
54
54
|
`;function ps(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 hs(e,t){try{return ps(e,t)}catch(n){return console.error(n),n.message}}function Hu({sql:e,pre_process:t}){if(!t.trim())return e;try{return new Function(`return ${t}`)()({sql:e},st)}catch(n){return console.error(n),e}}function ed(e,t,n){if(!e.trim())return t;try{return new Function(`return ${e}`)()(t,st,n)}catch(r){return console.error(r),t}}function td(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 nd(e,t){let n=td(e);return n+="&key="+t,Qu.MD5(n).toString().toUpperCase()}class Xi{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:nd({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 sd{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 Ji extends Xi{constructor(){super(...arguments);P(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 Zi{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 It=new Ji;function xs(e){It.baseURL!==e.apiBaseURL&&(It.baseURL=e.apiBaseURL),e.app_id&&(It.app_id=e.app_id),e.app_secret&&(It.app_secret=e.app_secret),e.makeQueryENV&&(It.makeQueryENV=e.makeQueryENV)}const Hi=new Zi(It),Je=Hi,Ut=f.forwardRef(function({value:t,onChange:n,...r},i){return s.jsx(a.TextInput,{ref:i,value:t,onChange:n,...r})});function z(e){const[t,n]=e.split(".");return{queryID:t,columnKey:n}}function rd(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 Kt(e,t){const{queryID:n}=z(t);return n?e[n]:[]}function id(e){return Object.values(e)[0]}function xn(e,t){const{queryID:n,columnKey:r}=z(t);return e[r]}const ea=["function aggregation({ queryData }, utils) {",' return "Aggregation Result";',"}"].join(`
|
|
55
55
|
`),Mt={type:"none",config:{},fallback:"0"};function ad(e){const t=Array.from(e).sort((r,i)=>r-i),n=Math.floor(t.length/2);return t.length%2===0?(t[n-1]+t[n])/2:t[n]}function od(e,t){switch(t.type){case"sum":return y.sum(e);case"mean":return y.mean(e);case"median":return ad(e);case"max":return y.max(e);case"min":return y.min(e);case"quantile":return Gt.quantile(e,t.config.p);case"CV":const n=hn.std(...e),r=hn.mean(...e);return r?n/r:Number.NaN;case"std":return hn.std(...e);default:return e}}function fs(e,t){const n=e.map(Number),r=od(n,t);return typeof r=="number"?Number.isFinite(r)?r:t.fallback:r??t.fallback}function ld(e,t,n){try{const r=Kt(e,t);return new Function(`return ${n.config.func}`)()({queryData:r},st)}catch(r){return console.error(r),r.message}}function fn(e,t,n){try{return n.type==="custom"?ld(e,t,n):fs(rt(e,t),n)}catch(r){return console.error(r),null}}class cd{constructor({valueRange:t,colorRange:n}){P(this,"mapper");this.mapper=mt.interpolate(t,n)}getColor(t){return this.mapper(t)}}const je={mantissa:0,output:"number",trimMantissa:!1,average:!1,absolute:!1};function W(e,{absolute:t,...n}){if(e===null)return String(e);try{let r=os(e).value();if(r===void 0)throw new Error(`[formatNumber]Not a number: ${e}`);return t&&(r=Math.abs(r)),os(r).format(n)}catch(r){return console.debug(r),String(e)}}function ud(e){return e===null?"null":e===void 0?"undefined":Array.isArray(e)?`Array(${e.length})`:e.toString()}function it({data_field:e,aggregation:t},n){return fn(n,e,t)}function Le({formatter:e,aggregation:t},n){if(typeof n!="string"&&typeof n!="number")return ud(n);if(t.type==="custom")return n;try{return W(n,e)}catch(r){return console.error(r),n}}function dd(e,t){if(e.type==="static")return e.staticColor;if(e.type==="continuous")try{if(typeof t!="number")throw new Error(`[getColorByColorConf] Invalid type of aggregated value: ${t}`);return new cd(e).getColor(t)}catch(n){return console.error(n),"black"}return"black"}function pd(e,t){const{color:n,data_field:r,aggregation:i,size:o,weight:l}=e,c=fn(t,r,i),u=Le(e,c);return s.jsx(a.Text,{sx:{fontSize:o,display:"inline"},color:dd(n,c),weight:l,children:u})}function hd(e,t){const n={};return e.forEach(r=>{const i=r.name;n[i]=pd(r,t)}),n}function xd(e){return e.split(" ").map((t,n)=>s.jsxs(f.Fragment,{children:[t," "]},n))}function fd(e){const n=e.replaceAll("<br />","<br/>").replaceAll(`
|
|
56
|
-
`,"<br/>").split("<br/>");return n.map((i,o)=>{const l=[xd(i)];return o!==n.length-1&&l.push(s.jsx("br",{},`br-${o}`)),l}).flat().filter(i=>i!==void 0)}function gs(e){return fd(e)}function Yt(e,t,n){const r=hd(t,n),i=/^\{(.+)\}(.*)$/;return e.split("$").map((o,l)=>{const c=i.exec(o);if(!c)return gs(o);const u=r[c[1]];if(!u)return gs(o);const d=c[2]??"";return s.jsxs(f.Fragment,{children:[u,gs(d)]},`${o}-${l}`)})}function gd(e,t){const{data_field:n,aggregation:r}=e,i=fn(t,n,r);return Le(e,i)}function ta(e,t){const n={};return e.forEach(r=>{n[r.name]=gd(r,t)}),n}function gn(e,t,n){const r=ta(t,n),i=/^\{(.+)\}(.*)$/;return e.split("$").map(o=>{const l=i.exec(o);if(!l)return o;const c=r[l[1]];if(!c)return o;const u=l[2]??"";return`${c}${u}`}).join("")}const ms={grid:{axis:"#97999D",scope:"rgba(47,140,192,0.1)",boundary:"#789AB4",reference:"#CFCFD8"},graphics:{compared:{blueDark:"#3E7CAB",blue:"#6398C7",blueLight:"#7CB0DF",blue10:"#6398C71a",redDark:"#AF5F6B",red:"#CD7C88",redLight:"#E794A0",red10:"#CD7C881a"},gradient:{distributed:"linear-gradient(90deg, #1babe6 0%, #2fc8c8 28.63%, #98d44b 48.86%, #ffd057 67.53%, #f5ae53 80.6%, #e76441 91.18%, #b90000 100%)",protrude:"linear-gradient(180deg, #ec73734d 0%, #ec737300 100%)"},level:{lv0:"#6398C7",lv1:"#61B5BF",lv2:"#54D4BB",lv3:"#F5D277",lv4:"#E8BB7F",lv5:"#DB9E84",lv6:"#CB8089"},depth:{dp0:"#FFF7F8",dp1:"#FFE1E1",dp2:"#FDBCBC",dp3:"#F39494",dp4:"#FA4242",dp5:"#E21212"},multiple:{c1:"#66B4DB",c2:"#E46464",c3:"#EEBA00",c4:"#33A678",c5:"#9D88CB",c6:"#939943",c7:"#E49792",c8:"#09A2B8",c9:"#AF5F6B",c10:"#6CA157",c11:"#3E7CAB",c12:"#6398C7",c13:"#E692BA",c14:"#97B566",c15:"#8CACE2",c16:"#CA79AC",c17:"#6DBC80",c18:"#B08F4B",c19:"#39BFA2",c20:"#826BAF"}}};function md(){Y.registerTheme("merico-light",{color:Object.values(ms.graphics.multiple),visualMap:{color:Object.values(ms.graphics.depth).reverse()},axes:[{type:"all",name:"通用坐标轴",axisLineColor:"#97999D",axisTickColor:"#97999D",axisLabelShow:!0,axisLabelColor:"#818388",splitLineShow:!0,splitLineColor:["#E0E6F1"]}]})}function na(){md()}function*yd(e){const t=ms.graphics[e];if(!t)throw new Error("Invalid palette key provided");const n=Object.values(t);let r=0;for(;;)yield n[r%n.length],r++}function sa(){return{filters:{},context:{}}}function ys(e){const t=sa();if(!e)return sa();const{filters:n=t.filters,context:r=t.context}=e;return{filters:n,context:r}}class we 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}}function bd(e,t={handleError:!0}){return n=>s.jsx(we,{...t,children:s.jsx(e,{...n})})}function jd(e,t){return new Function(`return ${e}`)()(t,st)}function vd(e,t,n){return jd(e,{context:t,filters:n})}function wd(e,t){try{return new Function(`return ${e.config.processing.pre}`)()(t,st)}catch(n){return console.error(n),t}}function Cd(e,t){return new Function(`return ${e.config.processing.post}`)()(t,st)}function Sd(e,t,n){return e?new Function(`return ${e}`)()(t,st,n):t}const mn=e=>y.cloneDeepWith(e,(t,n)=>{if(n!==void 0&&t)return R.toJS(t)}),yn={sqlSnippet:new RegExp("(?<=sql_snippets\\.)([^\\?}.]+)","gm"),context:new RegExp("(?<=context\\.)([^\\?}.]+)","gm"),filter:new RegExp("(?<=filters\\.)([^\\?}.]+)","gm")};function _d(e,t){const n=Ii.decode(t);n!==e&&(console.error("Inconsistent sql"),console.groupCollapsed("Inconsistent sql"),console.table({before:e,after:t,v:n}),console.groupEnd())}async function kd({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=ps(c,n),h=Hu({sql:p,pre_process:u}),x=Ii.encode(h);_d(h,x);let m=await Je.query(i)({type:o,key:l,query:x,...r},{params:{name:t}});return m=ed(d,m,ys(n)),m}async function Td({type:e,key:t,configString:n,name:r,additionals:i},o){try{return await Je.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 bs(){try{return(await Je.post()("/datasource/list",{filter:{},sort:[{field:"create_time",order:"ASC"}],pagination:{page:1,pagesize:100}},{})).data}catch(e){return console.error(e),[]}}async function ra(){try{return(await Je.post()("/sql_snippet/list",{filter:{},sort:[{field:"id",order:"ASC"}],pagination:{page:1,pagesize:1e3}},{})).data}catch(e){return console.error(e),[]}}class ia{constructor(t){P(this,"rootRef");this.rootRef=R.observable({current:t})}async deleteItem(t){R.runInAction(()=>{y.unset(this.rootRef.current,[t])})}getItem(t){const n=this.getValueFromRoot(t);return Promise.resolve(n)}getValueFromRoot(t){return t===null?R.toJS(this.rootRef.current):y.get(this.rootRef.current,[t])}setItem(t,n){if(t===null)if(y.isObject(n))R.runInAction(()=>{this.rootRef.current=n});else throw new Error("Cannot set root value to non-object");else R.runInAction(()=>{y.set(this.rootRef.current,[t],n)});return Promise.resolve(this.getItem(t))}watchItem(t,n,r){return R.reaction(()=>this.getValueFromRoot(t),(i,o)=>{n(i,o)},{requiresObservable:!0,fireImmediately:y.get(r,"fireImmediately",!1)})}}class Dd{constructor(){P(this,"channels",new Map);P(this,"globalChannel",new Mi)}getChannel(t){const n=this.channels.get(t);if(n)return n;const r=new Mi;return this.channels.set(t,r),r}}class Id{constructor(t){P(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 Dd,instanceData:new ia(t.viz.conf)};return this.instances.set(t.id,r),r}}function aa(e,t,n,r){return{vizManager:n,locale:"zh",msgChannels:e.messageChannels,instanceData:e.instanceData,pluginData:new ia({}),colorPalette:{getColor(){return()=>""}},data:t,variables:r}}const Md=e=>{const{panel:t,vizManager:n,data:r,variables:i}=e,o=n.resolveComponent(t.viz.type),l=n.getOrCreateInstance(t),c={...aa(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"])})},zd=e=>{const{vizManager:t,panel:n,data:r,variables:i}=e,o=t.resolveComponent(n.viz.type),l=t.getOrCreateInstance(n),c={...aa(l,r,t,i)},u=o.configRender;return s.jsx(u,{context:c,instance:l,...y.omit(e,["panel","vizManager","data"])})},oa=(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()}},bn=e=>{const t=nt.bezier(e);return function(n){return t(n/100).hex()}},Ad={type:"interpolation",displayName:"Red / Green",getColor:oa(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},Ed={type:"interpolation",displayName:"Yellow / Blue",getColor:oa(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},Pd={type:"interpolation",displayName:"Red",getColor:bn(["#fff7f1","darkred"]),name:"red",category:"sequential"},Ld={type:"interpolation",displayName:"Green",getColor:bn(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},Od={type:"interpolation",displayName:"Blue",getColor:bn(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},Bd={type:"interpolation",displayName:"Orange",getColor:bn(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class $d{constructor(t){P(this,"symbol");this.symbol=Symbol(t)}}function at(e){return new $d(e)}class js{constructor(){P(this,"parent");P(this,"factoryRegistry",new Map);P(this,"instanceRegistry",new Map)}createScoped(){const t=new js;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 la="11.0.0",Vd=Object.freeze(Object.defineProperty({__proto__:null,version:la},Symbol.toStringTag,{value:"Module"}));class qd{constructor(t){P(this,"staticColors",new Map);P(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 Nd{constructor(){P(this,"plugins",new Map);P(this,"vizComponents",new Map);P(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 Fd{constructor(){P(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 Fd{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}},De={top:16,right:16,bottom:16,left:16},Qe=e=>Math.max(0,e-De.left-De.right),Ue=e=>Math.max(0,e-De.top-De.bottom),Xt=(e,t)=>({width:Qe(e),height:Ue(t)}),Ie=({width:e,height:t,children:n})=>s.jsx(a.Box,{pt:De.top,pr:De.right,pb:De.bottom,pl:De.left,sx:{width:e,height:t,overflow:"hidden",position:"relative"},children:n}),vs={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"}};Y.use([O.GridComponent,O.VisualMapComponent,O.LegendComponent,O.TooltipComponent,_e.CanvasRenderer]);function Gd({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,vs),h=f.useMemo(()=>Kt(n,o),[n,o]),{x,y:m,z:j}=f.useMemo(()=>({x:z(o),y:z(l),z:z(c)}),[o,l,c]),{min:C,max:T}=f.useMemo(()=>{const E=y.minBy(h,H=>H[j.columnKey]),F=y.maxBy(h,H=>H[j.columnKey]);return{min:y.get(E,j.columnKey),max:y.get(F,j.columnKey)}},[h,j]),M={tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:C,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(E=>[E[x.columnKey],E[m.columnKey],E[j.columnKey]])}]};return t?s.jsx(Ie,{width:r,height:i,children:s.jsx(Se,{echarts:Y,option:M,style:Xt(r,i),notMerge:!0,theme:"merico-light"})}):null}const ca=f.createContext(null),ws=ca.Provider;function Cs(){const e=f.useContext(ca);if(!e)throw new Error("Please use DashboardModelContextProvider");return e}const X=()=>Cs(),Ss=()=>Cs(),ua=f.createContext({searchButtonProps:{}}),_s=ua.Provider;function da(){return f.useContext(ua)}const pa=f.createContext(null),ks=pa.Provider;function ha(){const e=f.useContext(pa);if(!e)throw new Error("Please use ContentModelContextProvider");return e}const K=()=>ha(),ue=()=>ha(),Wd={inEditMode:!1},jn=f.createContext(Wd),xa=f.createContext({panel:null,data:{},loading:!1,errors:[],downloadPanelScreenshot:()=>{}}),Ts=xa.Provider;function fa(){const e=f.useContext(xa);if(!e.panel)throw new Error("Please use PanelContextProvider");return e}const ht=()=>fa(),Oe=()=>fa(),Rd={fullScreenPanelID:"",setFullScreenPanelID:y.noop},Ds=f.createContext(Rd);function ga(){const e=f.useContext(Ds);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}=Oe(),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 Qd({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=y.defaults({},t,vs),{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(k.DeviceFloppy,{size:20}),s.jsx(a.Text,{ml:"md",children:"Save"})]})})]})}):null}function Ud(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 Kd extends ie{constructor(){super(...arguments);P(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:Ud(i,r)}})}}const Yd={displayName:"Bar Chart (3D)",displayGroup:"ECharts-based charts",migrator:new Kd,name:"bar-3d",viewRender:Gd,configRender:Qd,createConfig(){return{version:2,config:y.cloneDeep(vs)}}},Be={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
56
|
+
`,"<br/>").split("<br/>");return n.map((i,o)=>{const l=[xd(i)];return o!==n.length-1&&l.push(s.jsx("br",{},`br-${o}`)),l}).flat().filter(i=>i!==void 0)}function gs(e){return fd(e)}function Yt(e,t,n){const r=hd(t,n),i=/^\{(.+)\}(.*)$/;return e.split("$").map((o,l)=>{const c=i.exec(o);if(!c)return gs(o);const u=r[c[1]];if(!u)return gs(o);const d=c[2]??"";return s.jsxs(f.Fragment,{children:[u,gs(d)]},`${o}-${l}`)})}function gd(e,t){const{data_field:n,aggregation:r}=e,i=fn(t,n,r);return Le(e,i)}function ta(e,t){const n={};return e.forEach(r=>{n[r.name]=gd(r,t)}),n}function gn(e,t,n){const r=ta(t,n),i=/^\{(.+)\}(.*)$/;return e.split("$").map(o=>{const l=i.exec(o);if(!l)return o;const c=r[l[1]];if(!c)return o;const u=l[2]??"";return`${c}${u}`}).join("")}const ms={grid:{axis:"#97999D",scope:"rgba(47,140,192,0.1)",boundary:"#789AB4",reference:"#CFCFD8"},graphics:{compared:{blueDark:"#3E7CAB",blue:"#6398C7",blueLight:"#7CB0DF",blue10:"#6398C71a",redDark:"#AF5F6B",red:"#CD7C88",redLight:"#E794A0",red10:"#CD7C881a"},gradient:{distributed:"linear-gradient(90deg, #1babe6 0%, #2fc8c8 28.63%, #98d44b 48.86%, #ffd057 67.53%, #f5ae53 80.6%, #e76441 91.18%, #b90000 100%)",protrude:"linear-gradient(180deg, #ec73734d 0%, #ec737300 100%)"},level:{lv0:"#6398C7",lv1:"#61B5BF",lv2:"#54D4BB",lv3:"#F5D277",lv4:"#E8BB7F",lv5:"#DB9E84",lv6:"#CB8089"},depth:{dp0:"#FFF7F8",dp1:"#FFE1E1",dp2:"#FDBCBC",dp3:"#F39494",dp4:"#FA4242",dp5:"#E21212"},multiple:{c1:"#66B4DB",c2:"#E46464",c3:"#EEBA00",c4:"#33A678",c5:"#9D88CB",c6:"#939943",c7:"#E49792",c8:"#09A2B8",c9:"#AF5F6B",c10:"#6CA157",c11:"#3E7CAB",c12:"#6398C7",c13:"#E692BA",c14:"#97B566",c15:"#8CACE2",c16:"#CA79AC",c17:"#6DBC80",c18:"#B08F4B",c19:"#39BFA2",c20:"#826BAF"}}};function md(){Y.registerTheme("merico-light",{color:Object.values(ms.graphics.multiple),visualMap:{color:Object.values(ms.graphics.depth).reverse()},axes:[{type:"all",name:"通用坐标轴",axisLineColor:"#97999D",axisTickColor:"#97999D",axisLabelShow:!0,axisLabelColor:"#818388",splitLineShow:!0,splitLineColor:["#E0E6F1"]}]})}function na(){md()}function*yd(e){const t=ms.graphics[e];if(!t)throw new Error("Invalid palette key provided");const n=Object.values(t);let r=0;for(;;)yield n[r%n.length],r++}function sa(){return{filters:{},context:{}}}function ys(e){const t=sa();if(!e)return sa();const{filters:n=t.filters,context:r=t.context}=e;return{filters:n,context:r}}class we 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}}function bd(e,t={handleError:!0}){return n=>s.jsx(we,{...t,children:s.jsx(e,{...n})})}function jd(e,t){return new Function(`return ${e}`)()(t,st)}function vd(e,t,n){return jd(e,{context:t,filters:n})}function wd(e,t){try{return new Function(`return ${e.config.processing.pre}`)()(t,st)}catch(n){return console.error(n),t}}function Cd(e,t){return new Function(`return ${e.config.processing.post}`)()(t,st)}function Sd(e,t,n){return e?new Function(`return ${e}`)()(t,st,n):t}const mn=e=>y.cloneDeepWith(e,(t,n)=>{if(n!==void 0&&t)return R.toJS(t)}),yn={sqlSnippet:new RegExp("(?<=sql_snippets\\.)([^\\?}.]+)","gm"),context:new RegExp("(?<=context\\.)([^\\?}.]+)","gm"),filter:new RegExp("(?<=filters\\.)([^\\?}.]+)","gm")};function _d(e,t){const n=Ii.decode(t);n!==e&&(console.error("Inconsistent sql"),console.groupCollapsed("Inconsistent sql"),console.table({before:e,after:t,v:n}),console.groupEnd())}async function kd({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=ps(c,n),h=Hu({sql:p,pre_process:u}),x=Ii.encode(h);_d(h,x);let m=await Je.query(i)({type:o,key:l,query:x,...r},{params:{name:t}});return m=ed(d,m,ys(n)),m}async function Td({type:e,key:t,configString:n,name:r,additionals:i},o){try{return await Je.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 bs(){try{return(await Je.post()("/datasource/list",{filter:{},sort:[{field:"create_time",order:"ASC"}],pagination:{page:1,pagesize:100}},{})).data}catch(e){return console.error(e),[]}}async function ra(){try{return(await Je.post()("/sql_snippet/list",{filter:{},sort:[{field:"id",order:"ASC"}],pagination:{page:1,pagesize:1e3}},{})).data}catch(e){return console.error(e),[]}}class ia{constructor(t){P(this,"rootRef");this.rootRef=R.observable({current:t})}async deleteItem(t){R.runInAction(()=>{y.unset(this.rootRef.current,[t])})}getItem(t){const n=this.getValueFromRoot(t);return Promise.resolve(n)}getValueFromRoot(t){return t===null?R.toJS(this.rootRef.current):y.get(this.rootRef.current,[t])}setItem(t,n){if(t===null)if(y.isObject(n))R.runInAction(()=>{this.rootRef.current=n});else throw new Error("Cannot set root value to non-object");else R.runInAction(()=>{y.set(this.rootRef.current,[t],n)});return Promise.resolve(this.getItem(t))}watchItem(t,n,r){return R.reaction(()=>this.getValueFromRoot(t),(i,o)=>{n(i,o)},{requiresObservable:!0,fireImmediately:y.get(r,"fireImmediately",!1)})}}class Dd{constructor(){P(this,"channels",new Map);P(this,"globalChannel",new Mi)}getChannel(t){const n=this.channels.get(t);if(n)return n;const r=new Mi;return this.channels.set(t,r),r}}class Id{constructor(t){P(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 Dd,instanceData:new ia(t.viz.conf)};return this.instances.set(t.id,r),r}}function aa(e,t,n,r){return{vizManager:n,locale:"zh",msgChannels:e.messageChannels,instanceData:e.instanceData,pluginData:new ia({}),colorPalette:{getColor(){return()=>""}},data:t,variables:r}}const Md=e=>{const{panel:t,vizManager:n,data:r,variables:i}=e,o=n.resolveComponent(t.viz.type),l=n.getOrCreateInstance(t),c={...aa(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"])})},zd=e=>{const{vizManager:t,panel:n,data:r,variables:i}=e,o=t.resolveComponent(n.viz.type),l=t.getOrCreateInstance(n),c={...aa(l,r,t,i)},u=o.configRender;return s.jsx(u,{context:c,instance:l,...y.omit(e,["panel","vizManager","data"])})},oa=(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()}},bn=e=>{const t=nt.bezier(e);return function(n){return t(n/100).hex()}},Ad={type:"interpolation",displayName:"Red / Green",getColor:oa(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},Ed={type:"interpolation",displayName:"Yellow / Blue",getColor:oa(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},Pd={type:"interpolation",displayName:"Red",getColor:bn(["#fff7f1","darkred"]),name:"red",category:"sequential"},Ld={type:"interpolation",displayName:"Green",getColor:bn(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},Od={type:"interpolation",displayName:"Blue",getColor:bn(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},Bd={type:"interpolation",displayName:"Orange",getColor:bn(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class $d{constructor(t){P(this,"symbol");this.symbol=Symbol(t)}}function at(e){return new $d(e)}class js{constructor(){P(this,"parent");P(this,"factoryRegistry",new Map);P(this,"instanceRegistry",new Map)}createScoped(){const t=new js;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 la="11.0.2",Vd=Object.freeze(Object.defineProperty({__proto__:null,version:la},Symbol.toStringTag,{value:"Module"}));class qd{constructor(t){P(this,"staticColors",new Map);P(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 Nd{constructor(){P(this,"plugins",new Map);P(this,"vizComponents",new Map);P(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 Fd{constructor(){P(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 Fd{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}},De={top:16,right:16,bottom:16,left:16},Qe=e=>Math.max(0,e-De.left-De.right),Ue=e=>Math.max(0,e-De.top-De.bottom),Xt=(e,t)=>({width:Qe(e),height:Ue(t)}),Ie=({width:e,height:t,children:n})=>s.jsx(a.Box,{pt:De.top,pr:De.right,pb:De.bottom,pl:De.left,sx:{width:e,height:t,overflow:"hidden",position:"relative"},children:n}),vs={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"}};Y.use([O.GridComponent,O.VisualMapComponent,O.LegendComponent,O.TooltipComponent,_e.CanvasRenderer]);function Gd({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,vs),h=f.useMemo(()=>Kt(n,o),[n,o]),{x,y:m,z:j}=f.useMemo(()=>({x:z(o),y:z(l),z:z(c)}),[o,l,c]),{min:C,max:T}=f.useMemo(()=>{const E=y.minBy(h,H=>H[j.columnKey]),F=y.maxBy(h,H=>H[j.columnKey]);return{min:y.get(E,j.columnKey),max:y.get(F,j.columnKey)}},[h,j]),M={tooltip:{},backgroundColor:"#fff",visualMap:{show:!0,dimension:2,min:C,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(E=>[E[x.columnKey],E[m.columnKey],E[j.columnKey]])}]};return t?s.jsx(Ie,{width:r,height:i,children:s.jsx(Se,{echarts:Y,option:M,style:Xt(r,i),notMerge:!0,theme:"merico-light"})}):null}const ca=f.createContext(null),ws=ca.Provider;function Cs(){const e=f.useContext(ca);if(!e)throw new Error("Please use DashboardModelContextProvider");return e}const X=()=>Cs(),Ss=()=>Cs(),ua=f.createContext({searchButtonProps:{}}),_s=ua.Provider;function da(){return f.useContext(ua)}const pa=f.createContext(null),ks=pa.Provider;function ha(){const e=f.useContext(pa);if(!e)throw new Error("Please use ContentModelContextProvider");return e}const K=()=>ha(),ue=()=>ha(),Wd={inEditMode:!1},jn=f.createContext(Wd),xa=f.createContext({panel:null,data:{},loading:!1,errors:[],downloadPanelScreenshot:()=>{}}),Ts=xa.Provider;function fa(){const e=f.useContext(xa);if(!e.panel)throw new Error("Please use PanelContextProvider");return e}const ht=()=>fa(),Oe=()=>fa(),Rd={fullScreenPanelID:"",setFullScreenPanelID:y.noop},Ds=f.createContext(Rd);function ga(){const e=f.useContext(Ds);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}=Oe(),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 Qd({context:e}){const{value:t,set:n}=$(e.instanceData,"config"),r=y.defaults({},t,vs),{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(k.DeviceFloppy,{size:20}),s.jsx(a.Text,{ml:"md",children:"Save"})]})})]})}):null}function Ud(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 Kd extends ie{constructor(){super(...arguments);P(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:Ud(i,r)}})}}const Yd={displayName:"Bar Chart (3D)",displayGroup:"ECharts-based charts",migrator:new Kd,name:"bar-3d",viewRender:Gd,configRender:Qd,createConfig(){return{version:2,config:y.cloneDeep(vs)}}},Be={enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
|
|
57
57
|
`)},ma={id:"builtin:echarts:click-echart:series",displayName:"Click Chart Series",nameRender:Jd,configRender:Xd,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 Xd(e){return s.jsx(s.Fragment,{})}function Jd(e){return s.jsx(a.Text,{children:"Click chart's series"})}const Zd=[{label:"Truncate",value:"truncate"},{label:"Break Line",value:"break"},{label:"Break Word",value:"breakAll"}],vn=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:Zd,value:t.overflow,onChange:i("overflow")}),s.jsx(a.TextInput,{label:"Ellipsis",value:t.ellipsis,disabled:!0})]})]})}),Ke=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(vn,{sectionTitle:"Overflow on Axis",value:e.on_axis,onChange:r}),s.jsx(vn,{sectionTitle:"Overflow in Tooltip",value:e.in_tooltip,onChange:i})]})});function Me(){return{on_axis:{width:80,overflow:"truncate",ellipsis:"..."},in_tooltip:{width:200,overflow:"break",ellipsis:"..."}}}function $e({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`
|
|
58
58
|
max-width: ${t}px;
|
|
59
59
|
word-break: ${n};
|
|
@@ -462,7 +462,7 @@ Check the top-level render call using <`+A+">.")}return D}}function Hc(w,D){{if(
|
|
|
462
462
|
parent_value: string;
|
|
463
463
|
description?: string;
|
|
464
464
|
}
|
|
465
|
-
`,Mk=()=>{const[e,t]=f.useState(!1);return s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"subtle",compact:!0,onClick:()=>t(n=>!n),children:e?"Close":"Click to see expected data structure"}),s.jsx(a.Collapse,{in:e,children:s.jsx(dt.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:Ik})})]})},zk=S.observer(function({filter:t}){const n=t.config;return s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Checkbox,{checked:n.required,onChange:r=>n.setRequired(r.currentTarget.checked),label:"Required"}),s.jsx(qt,{filter:t})]}),s.jsx(a.TextInput,{label:"Min-width",value:n.min_width,onChange:r=>n.setMinWidth(r.currentTarget.value),placeholder:"200px"}),s.jsx(a.Divider,{label:"Fetch options from database",labelPosition:"center"}),s.jsx(a.Checkbox,{checked:n.treeCheckStrictly,onChange:r=>n.setTreeCheckStrictly(r.currentTarget.checked),label:"Parent and children nodes are not associated"}),s.jsx(a.NumberInput,{value:n.default_selection_count,onChange:n.setDefaultSelectionCount,label:"Select first N options by default"}),s.jsx(pi,{value:n.options_query_id,onChange:n.setOptionsQueryID}),s.jsx(Mk,{})]})}),Ak=S.observer(function({filter:t}){return s.jsxs(a.Box,{sx:{maxWidth:"480px"},children:[s.jsx(a.Text,{pt:"0",pb:"md",color:"gray",children:"Config"}),s.jsx(dt.Prism,{mt:22,language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(t,null,4)})]})}),Ek={select:Tk,"multi-select":kk,"tree-select":zk,"text-input":Dk,checkbox:wk,"date-range":Sk},gt={select:"Select","multi-select":"Multi Select","tree-select":"Tree Select","text-input":"Text Input",checkbox:"Checkbox","date-range":"Date Range"},Pk=[{label:gt.select,value:"select"},{label:gt["multi-select"],value:"multi-select"},{label:gt["tree-select"],value:"tree-select"},{label:gt["text-input"],value:"text-input"},{label:gt.checkbox,value:"checkbox"},{label:gt["date-range"],value:"date-range"}],Lk=S.observer(function({filter:t}){const n=K(),r=f.useMemo(()=>Ek[t.type],[t.type]);return s.jsxs(a.Group,{grow:!0,spacing:20,align:"top",children:[s.jsxs(a.Box,{sx:{maxWidth:"600px"},children:[s.jsx(a.Text,{pb:"md",color:"gray",children:"Edit"}),s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{noWrap:!0,children:[s.jsx(a.NumberInput,{label:"Placement Order",required:!0,value:t.order,onChange:t.setOrder,hideControls:!0,sx:{flexGrow:"1 !important"}}),t.auto_submit_supported&&s.jsx(a.Checkbox,{label:"Submit automatically",checked:t.auto_submit,onChange:i=>t.setAutoSubmit(i.currentTarget.checked),mt:22})]}),s.jsx(a.MultiSelect,{label:"Visible in...",data:n.views.options,value:[...t.visibleInViewsIDs],onChange:t.setVisibleInViewsIDs}),s.jsx(a.TextInput,{label:"Key",placeholder:"A unique key to refer",required:!0,value:t.key,onChange:i=>{t.setKey(i.currentTarget.value)}}),s.jsx(a.TextInput,{label:"Label",placeholder:"Label for this field",required:!0,value:t.label,onChange:i=>{t.setLabel(i.currentTarget.value)}}),s.jsx(a.Select,{label:"Widget",data:Pk,required:!0,value:t.type,onChange:t.setType,maxDropdownHeight:500}),s.jsx(a.Divider,{mb:0,mt:10,variant:"dashed",label:`${gt[t.type]} Settings`,labelPosition:"center"}),s.jsx(r,{filter:t})]})]}),s.jsx(Ak,{filter:t})]})}),Ok=S.observer(({id:e})=>{const t=Ae.useModals(),n=X(),r=K();if(e==="")return null;const i=r.filters.findByID(e);if(!i)return s.jsxs(a.Text,{size:14,children:["Filter by ID[",e,"] is not found"]});const o=()=>{n.editor.setPath(["_FILTERS_",""])},l=()=>{t.openConfirmModal({title:"Delete this filter?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.filters.removeByID(e),o()},confirmProps:{color:"red"},zIndex:320})};return s.jsxs(a.Stack,{sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",pb:30,children:[s.jsx(a.Group,{position:"right",pt:10,children:s.jsx(a.Button,{size:"xs",color:"red",leftIcon:s.jsx(k.Trash,{size:16}),onClick:l,children:"Delete this filter"})}),s.jsx(a.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:s.jsx(Lk,{filter:i})})]})}),Bk=S.observer(()=>{const[e,t]=f.useState([]),n=X(),r=u=>{n.editor.setPath(["_FILTERS_",u])},i=()=>{n.content.filters.downloadSchema(e)},o=f.useMemo(()=>n.content.filters.sortedList.map(u=>u.id),[n.content.filters.sortedList]),l=()=>{t(o)},c=()=>{t([])};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 Filters"})}),s.jsx(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:l,children:"Select All"}),s.jsx(a.Button,{variant:"default",size:"xs",onClick:c,children:"Clear Selection"})]}),s.jsx(a.Button,{size:"xs",color:"blue",leftIcon:s.jsx(_.IconCode,{size:14}),disabled:e.length===0,onClick:i,children:"Download Schema"})]})}),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",{style:{width:"300px"},children:"Label"}),s.jsx("th",{children:"Key"}),s.jsx("th",{style:{width:"100px"},children:"Widget"}),s.jsx("th",{style:{width:"300px",paddingLeft:"24px"},children:"Action"})]})}),s.jsx("tbody",{children:n.content.filters.sortedList.map(u=>s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx(a.Checkbox,{value:u.id,styles:{input:{cursor:"pointer"}}})}),s.jsx("td",{children:u.label}),s.jsx("td",{children:u.key}),s.jsx("td",{children:gt[u.type]}),s.jsx("td",{children:s.jsx(a.Button,{variant:"subtle",size:"xs",onClick:()=>r(u.id),children:"Open"})})]},u.id))})]})})})]})}),$k=S.observer(()=>{const e=K(),[t,n]=f.useState(()=>JSON.stringify(e.mock_context.current,null,4)),r=()=>{try{e.mock_context.replace(JSON.parse(t))}catch(o){yt.showNotification({title:"Failed",message:o.message,color:"red"})}},i=f.useMemo(()=>{try{return JSON.stringify(JSON.parse(t))!==JSON.stringify(e.mock_context.current)}catch{return!1}},[t,e.mock_context.current]);return s.jsxs(a.Stack,{sx:{border:"1px solid #eee",borderLeft:"none",borderRight:"none",flexGrow:1,maxWidth:"unset"},children:[s.jsx(a.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:s.jsx(a.Text,{weight:500,children:"Mock Context"})}),s.jsxs(a.Group,{grow:!0,px:"md",pb:"md",pt:0,sx:{flexGrow:1,position:"relative",alignItems:"flex-start"},children:[s.jsxs(a.Stack,{spacing:10,sx:{maxWidth:"unset !important"},children:[s.jsx(a.Text,{children:"A valid json string is required"}),s.jsx(a.JsonInput,{validationError:"Invalid json",formatOnBlur:!0,autosize:!0,minRows:30,value:t,onChange:n,sx:{flexGrow:1}})]}),s.jsx(a.ActionIcon,{mr:5,variant:"filled",color:"blue",sx:{position:"absolute",right:12,top:0},disabled:!i,onClick:r,children:s.jsx(k.DeviceFloppy,{size:20})})]})]})}),Vk=S.observer(()=>{const{panel:e}=Oe();return s.jsx(pr,{label:"Description",value:e.description,onChange:e.setDescription,styles:{root:{flexGrow:1}}})}),qk=S.observer(()=>{const{panel:e}=Oe(),{style:t}=e;return s.jsxs(s.Fragment,{children:[s.jsx(a.Divider,{mb:-10,label:"Style",labelPosition:"center",variant:"dashed"}),s.jsxs(a.Stack,{spacing:20,children:[s.jsxs(a.Group,{grow:!0,align:"top",children:[s.jsx(a.NumberInput,{label:"Width",min:1,max:36,step:1,precision:0,rightSection:s.jsx(a.Text,{size:12,children:"of 36 columns"}),styles:{rightSection:{width:"110px"}},value:e.layout.w,onChange:n=>{n&&e.layout.setWidth(n)}}),s.jsx(a.NumberInput,{label:"Height",rightSection:s.jsx(a.Text,{size:12,children:"px"}),styles:{rightSection:{width:"40px"}},value:e.layout.h,onChange:n=>{n&&e.layout.setHeight(n)}})]}),s.jsx(a.Checkbox,{ml:6,label:"Border",checked:t.border.enabled,onChange:n=>t.border.setEnabled(n.currentTarget.checked)})]})]})}),Nk=()=>s.jsxs("span",{className:"mantine-103svbs mantine-InputWrapper-required mantine-Select-required","aria-hidden":"true",children:[" ","*"]}),Fk=S.observer(()=>{const{panel:e}=Oe(),{name:t}=e,[n,r]=ae.useInputState(t),i=t!==n,o=f.useCallback(()=>{i&&e.setName(n)},[i,n]);f.useEffect(()=>{r(t)},[t]);const l=!n.trim();return s.jsxs(a.Stack,{spacing:4,children:[s.jsxs(a.Group,{align:"center",children:[s.jsxs(a.Text,{size:14,fw:500,children:["Panel Name",s.jsx(Nk,{})]}),s.jsx(a.ActionIcon,{variant:"subtle",color:"blue",disabled:!i||l,onClick:o,children:s.jsx(_.IconDeviceFloppy,{size:18})})]}),s.jsx(a.TextInput,{value:n,onChange:r,required:!0})]})}),Gk=S.observer(()=>{const{panel:e}=Oe();return s.jsx(a.Stack,{spacing:6,mb:10,children:s.jsxs(a.Group,{pl:6,position:"left",spacing:20,children:[s.jsx(a.Checkbox,{size:"sm",checked:e.title.show,onChange:t=>e.title.setShow(t.currentTarget.checked),label:"Show Title",sx:{userSelect:"none"}}),s.jsx(a.Checkbox,{size:"sm",checked:!0,disabled:!0,label:"Use name as title"})]})})});function Wk(){return s.jsxs(a.Stack,{sx:{height:"100%"},children:[s.jsx(qk,{}),s.jsx(a.Divider,{label:"Info",labelPosition:"center",variant:"dashed"}),s.jsx(Fk,{}),s.jsx(Gk,{}),s.jsx(Vk,{})]})}const Rk={width:"fit-content",minWidth:"100%",tableLayout:"fixed",tr:{width:"fit-content"},th:{position:"relative"},"th, td":{wordBreak:"break-word"},".resizer":{position:"absolute",right:0,top:"50%",transform:"translateY(-50%)",cursor:"col-resize",userSelect:"none",touchAction:"none"},".resizer.isResizing":{color:"#228be6",opacity:"1"},"@media (hover: hover)":{".resizer":{opacity:"0"},"*:hover > .resizer":{color:"#228be6",opacity:"1"}}};function Cc({data:e}){const t=f.useMemo(()=>{if(!Array.isArray(e)||e.length===0)return[];const r=Re.createColumnHelper();return Object.keys(e[0]).map(i=>r.accessor(i,{cell:o=>o.getValue()}))},[e]),n=Re.useReactTable({data:e,columns:t,columnResizeMode:"onChange",getCoreRowModel:Re.getCoreRowModel()});return e.length===0?s.jsx(a.Box,{sx:{height:"5em"}}):s.jsx(we,{children:s.jsxs(a.Table,{sx:Rk,children:[s.jsx("thead",{children:n.getHeaderGroups().map(r=>s.jsx("tr",{children:r.headers.map(i=>s.jsxs("th",{style:{width:i.getSize()},children:[i.isPlaceholder?null:Re.flexRender(i.column.columnDef.header,i.getContext()),s.jsx(a.ActionIcon,{onMouseDown:i.getResizeHandler(),onTouchStart:i.getResizeHandler(),className:`resizer ${i.column.getIsResizing()?"isResizing":""}`,children:s.jsx(k.ArrowBarToRight,{})})]},i.id))},r.id))}),s.jsx("tbody",{children:n.getRowModel().rows.map(r=>s.jsx("tr",{children:r.getVisibleCells().map(i=>s.jsx("td",{children:s.jsx(we,{children:Re.flexRender(i.column.columnDef.cell,i.getContext())})},i.id))},r.id))})]})})}const Qk=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],Uk={icon:{width:"80px",textAlign:"center"},input:{"&[data-with-icon]":{paddingLeft:"80px"}}},Kk=({data:e,page:t,setPage:n,limit:r,setLimit:i})=>{const o=e.length,l=Math.ceil(o/r),c=d=>{n(1),i(Number(d))};if(o===0)return null;const u=l===1&&o<=10;return s.jsxs(a.Group,{pt:10,px:10,position:"apart",children:[s.jsxs(a.Group,{position:"left",children:[l>1&&s.jsx(a.Pagination,{size:"sm",value:t,onChange:n,total:l,withEdges:l>7,styles:{control:{height:"30px"}}}),!u&&s.jsx(a.Select,{icon:s.jsx(a.Text,{ta:"center",color:"dimmed",size:14,children:"Page Size"}),size:"xs",styles:Uk,data:Qk,value:String(r),onChange:c})]}),s.jsx(a.Group,{position:"right",children:s.jsxs(a.Text,{color:"dimmed",my:0,size:14,children:["Total ",o," rows"]})})]})},Yk=bd(({data:e,loading:t})=>{const[n,r]=f.useState(1),[i,o]=f.useState(20),l=f.useMemo(()=>{const c=(n-1)*i,u=c+i;return e.slice(c,u)},[e,n,i]);return s.jsxs(we,{children:[s.jsx(Kk,{data:e,page:n,setPage:r,limit:i,setLimit:o}),s.jsxs(a.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[s.jsx(a.LoadingOverlay,{visible:t,overlayBlur:2}),s.jsx(Cc,{data:l})]})]})}),Xk=({queryID:e})=>{const t=ue(),{state:n,error:r}=t.getDataStuffByID(e),i=f.useMemo(()=>t.queries.findByID(e),[t,e]);return n==="loading"?null:r?s.jsx(a.Text,{mt:10,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:r}):i!=null&&i.stateMessage?s.jsx(a.Text,{mt:10,color:"gray",align:"center",children:i.stateMessage}):null},hi=S.observer(({id:e,moreActions:t,refreshOnMount:n})=>{const r=ue(),{data:i,state:o}=r.getDataStuffByID(e),l=o==="loading",c=f.useCallback(()=>{r.queries.refetchDataByQueryID(e)},[e,r]),u=()=>{r.queries.downloadDataByQueryID(e)};f.useEffect(()=>{n&&c()},[c,n]);const d=!Array.isArray(i)||i.length===0;return s.jsxs(a.Stack,{spacing:0,sx:{height:"100%",border:"1px solid #eee"},children:[s.jsxs(a.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Group,{position:"left",children:s.jsx(a.Text,{weight:500,children:"Preview Data"})}),s.jsxs(a.Group,{pr:15,children:[t,s.jsx(a.ActionIcon,{variant:"subtle",color:"blue",disabled:l,onClick:c,children:s.jsx(k.Refresh,{size:16})}),s.jsx(a.ActionIcon,{variant:"subtle",color:"blue",disabled:l||d,onClick:u,children:s.jsx(k.Download,{size:16})})]})]}),s.jsxs(a.Box,{pb:20,sx:{position:"relative",flexGrow:1,overflow:"auto"},children:[s.jsx(Xk,{queryID:e}),s.jsx(Yk,{data:i,loading:l})]})]})}),Jk=S.observer(function(){const t=X(),n=K(),{panel:r}=Oe(),[i,o]=f.useState(!1),l=c=>{t.editor.setPath(["_QUERIES_",c])};return s.jsxs(s.Fragment,{children:[s.jsx(a.Drawer,{opened:i,onClose:()=>o(!1),title:"Choose queries",padding:"xl",size:500,zIndex:320,children:s.jsx(a.Checkbox.Group,{value:[...r.queryIDs],onChange:r.setQueryIDs,children:s.jsx(a.Stack,{spacing:"lg",children:n.queries.options.map(c=>s.jsx(a.Checkbox,{label:c.label,value:c.value},c.value))})})}),s.jsxs(a.Stack,{spacing:6,children:[s.jsx(a.Group,{position:"right",children:s.jsx(a.Button,{variant:"light",size:"sm",leftIcon:s.jsx(_.IconLine,{size:16}),onClick:()=>o(!0),children:"Click me to choose queries for this panel"})}),r.queryIDs.length===1&&s.jsx(hi,{id:r.queryIDs[0],moreActions:s.jsx(a.Tooltip,{label:"Open this query",children:s.jsx(a.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>l(r.queryIDs[0]),children:s.jsx(_.IconArrowCurveRight,{size:16})})})}),r.queryIDs.length>1&&s.jsxs(a.Tabs,{defaultValue:r.queryIDs[0],children:[s.jsx(a.Tabs.List,{children:r.queries.map(c=>s.jsx(a.Tabs.Tab,{value:c.id,children:c.name},c.id))}),r.queries.map(c=>s.jsx(a.Tabs.Panel,{value:c.id,children:s.jsx(hi,{id:c.id,moreActions:s.jsx(a.Tooltip,{label:"Open this query",children:s.jsx(a.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>l(c.id),children:s.jsx(_.IconArrowCurveRight,{size:16})})})})},c.id))]})]})]})}),Zk=S.observer(()=>{const{panel:e}=ht();return s.jsx(we,{children:s.jsx(a.Box,{sx:{height:"100%",flexGrow:0,flexShrink:0,width:"600px"},children:s.jsxs(a.Stack,{mt:24,spacing:5,sx:{width:"600px",height:"450px",background:"transparent",borderRadius:"5px",border:"1px solid #e9ecef",borderWidth:e.style.border.enabled?"1px":"0px"},children:[s.jsxs(a.Group,{position:"apart",noWrap:!0,sx:{flexGrow:0,flexShrink:0},children:[s.jsx(a.Group,{children:s.jsx(si,{})}),s.jsx(a.Group,{grow:!0,position:"center",children:s.jsx(a.Text,{lineClamp:1,weight:"bold",children:e.title.show?e.name:""})}),s.jsx(a.Group,{position:"right",spacing:0,sx:{height:"28px"}})]}),s.jsx(a.Group,{px:5,pb:5,sx:{flexGrow:1,".panel-viz-section":{height:"calc(100% - 28px)"}},children:s.jsx(ri,{panel:e})})]})})})}),xi={name:"new_var",size:"1rem",weight:"initial",color:{type:"static",staticColor:"Red"},data_field:"",aggregation:{type:"sum",config:{},fallback:"0"},formatter:{output:"number",mantissa:0,trimMantissa:!1,average:!1}};class Hk{constructor(t){P(this,"panel");P(this,"selected");this.panel=t,t.variables.length>0&&(this.selected=t.variables[0]),R.makeAutoObservable(this,{},{deep:!1,autoBind:!0})}get variables(){return this.panel.variables}get variableOptions(){return this.panel.variables.map(t=>({label:t.name,value:t.name,description:t.aggregation.type}))}addNew(){const t=this.panel.variables.filter(n=>n.name.startsWith(xi.name)).length;this.panel.addVariable(y.cloneDeep({...xi,name:`${xi.name}${t||""}`})),this.selected=y.last(this.panel.variables)}select(t){this.selected=t}selectByName(t){if(!t){console.warn("Unexpected null name when calling selectByName");return}const n=this.variables.find(r=>r.name===t);if(!n){console.error(`Variable by name[${t}] not found`);return}this.selected=n}remove(t){this.selected===t&&(this.selected=void 0);const n=this.panel.variables.indexOf(t);if(this.panel.removeVariable(t),!this.selected&&!y.isEmpty(this.panel.variables)){const r=Math.min(this.panel.variables.length-1,n);this.selected=this.panel.variables[r]}}}function eT(){const{panel:e}=Oe();return V.useCreation(()=>new Hk(e),[e])}function tT({label:e,value:t,onChange:n},r){const[i,o]=f.useState(Array.isArray(t)?[...t]:[]),l=f.useCallback(()=>{o(x=>[...x,""])},[o]),c=f.useCallback(x=>{o(m=>(m.splice(x,1),[...m]))},[o]),u=f.useMemo(()=>!y.isEqual(i,t),[i,t]),d=()=>{n(i.map(x=>x.toString()))},p=a.useMantineTheme(),h=f.useMemo(()=>Object.entries(p.colors).map(([x,m])=>m[6]),[p]);return s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{position:"left",ref:r,children:[s.jsx(a.Text,{children:e}),s.jsx(a.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!u,onClick:d,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Group,{children:[i.map((x,m)=>s.jsx(a.ColorInput,{value:x,onChange:j=>{o(C=>(C.splice(m,1,j),[...C]))},swatches:h,rightSection:s.jsx(a.ActionIcon,{onClick:()=>c(m),color:"red",children:s.jsx(k.Trash,{size:14})}),sx:{width:"45%"}})),s.jsx(a.ActionIcon,{onClick:l,color:"blue",variant:"outline",children:s.jsx(k.PlaylistAdd,{size:20})})]})]})}const nT=f.forwardRef(tT);function sT({label:e,value:t,onChange:n,type:r},i){const[o,l]=f.useState(Array.isArray(t)?[...t]:[]),c=f.useCallback(()=>{l(h=>[...h,""])},[l]),u=f.useCallback(h=>{l(x=>(x.splice(h,1),[...x]))},[l]),d=f.useMemo(()=>!y.isEqual(o.map(String),t.map(String)),[o,t]),p=()=>{n(o.map(h=>r==="number"?Number(h):h.toString()))};return s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{position:"left",ref:i,children:[s.jsx(a.Text,{children:e}),s.jsx(a.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!d,onClick:p,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Group,{children:[o.map((h,x)=>s.jsx(a.TextInput,{type:r,value:h,onChange:m=>{const j=m.currentTarget.value;l(C=>(C.splice(x,1,j),[...C]))},rightSection:s.jsx(a.ActionIcon,{onClick:()=>u(x),color:"red",children:s.jsx(k.Trash,{size:14})}),sx:{width:"45%"}})),s.jsx(a.ActionIcon,{onClick:c,color:"blue",variant:"outline",children:s.jsx(k.PlaylistAdd,{size:20})})]})]})}const rT=f.forwardRef(sT),iT=f.forwardRef(function({value:t,onChange:n},r){const i=t.color.type,o=(c,u)=>{const d=y.cloneDeep(t);y.set(d,c,u),n(d)},l=c=>{if(c==="static"){n({...t,color:{type:"static",staticColor:"#25262B"}});return}n({...t,color:{type:"continuous",colorRange:[],valueRange:[]}})};return s.jsxs(s.Fragment,{children:[s.jsx(a.Stack,{children:s.jsx(a.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",sx:{flex:1},value:t.size,onChange:c=>o("size",c.currentTarget.value)})}),s.jsx(a.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:s.jsx(Go,{label:"Font Weight",value:t.weight,onChange:c=>o("weight",c)})}),s.jsx(a.Divider,{mt:"lg",mb:0,variant:"dashed",label:"Style",labelPosition:"center"}),s.jsxs(a.Stack,{children:[s.jsx(a.Select,{label:"Color Type",data:[{label:"Static Color",value:"static"},{label:"Continuous Color",value:"continuous"}],value:t.color.type,onChange:l}),i==="static"&&s.jsx(ke,{value:t.color.staticColor,onChange:c=>o("color.staticColor",c)}),i==="continuous"&&s.jsxs(s.Fragment,{children:[s.jsx(rT,{label:"Value Range",value:t.color.valueRange,type:"number",onChange:c=>o("color.valueRange",c)}),s.jsx(nT,{label:"Color Range",value:t.color.colorRange,onChange:c=>o("color.colorRange",c)})]})]})]})}),aT=f.forwardRef(function({value:t,onChange:n,withStyle:r=!0,remove:i},o){const l=(c,u)=>{const d=y.cloneDeep(t);y.set(d,c,u),n(d)};return s.jsxs(a.Stack,{ref:o,children:[s.jsxs(a.Stack,{spacing:"xs",px:"sm",py:"md",sx:{border:"1px solid #e9ecef"},children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(a.TextInput,{label:"Name",required:!0,value:t.name,onChange:c=>l("name",c.currentTarget.value)}),s.jsx(B,{label:"Data Field",required:!0,value:t.data_field,onChange:c=>l("data_field",c)})]}),s.jsx(ir,{label:"Aggregation",pt:0,value:t.aggregation,onChange:c=>l("aggregation",c),withFallback:!0}),t.aggregation.type!=="custom"&&s.jsxs(s.Fragment,{children:[s.jsx(a.Divider,{mt:"xl",mb:0,label:"Format",labelPosition:"center",variant:"dashed"}),s.jsx(Fe,{value:t.formatter,onChange:c=>l("formatter",c)})]})]}),r&&s.jsx(a.Accordion,{variant:"contained",children:s.jsxs(a.Accordion.Item,{value:"Styles",children:[s.jsx(a.Accordion.Control,{icon:s.jsx(a.Text,{size:"xl",children:"🖼️"}),children:"Styles"}),s.jsx(a.Accordion.Panel,{children:s.jsx(iT,{value:t,onChange:n})})]})}),s.jsx(a.Button,{mt:20,leftIcon:s.jsx(_.IconTrash,{size:16}),color:"red",variant:"light",onClick:i,children:"Delete this Variable"})]})}),oT=S.observer(e=>{const t=V.useCreation(()=>Vl(e.variable),[e.variable]),n=()=>e.uiModel.remove(e.variable);return s.jsxs(a.Stack,{"data-testid":"variable-editor",align:"stretch",children:[s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{variant:"subtle",size:"xs",disabled:!t.changed,color:"red",onClick:t.reset,leftIcon:s.jsx(_.IconRecycle,{size:18}),children:"Revert Changes"}),s.jsx(a.Button,{variant:"filled",size:"xs",disabled:!t.changed,color:"green",onClick:t.commit,leftIcon:s.jsx(_.IconDeviceFloppy,{size:18}),children:"Save Changes"})]}),s.jsx(aT,{value:g.getSnapshot(t.copy),onChange:t.update,remove:n})]})});S.observer(e=>{const{uiModel:t}=e;return s.jsx(a.Stack,{className:"var-list",children:t.variables.map(n=>s.jsx(a.Button,{variant:t.selected===n?"filled":"subtle",color:"gray",onClick:()=>t.select(n),children:n.name},n.name))})});const lT=S.observer(({model:e})=>s.jsx(a.Overlay,{color:"#fff",opacity:1,sx:{position:"absolute"},children:s.jsx(a.Button,{variant:"light",size:"xs",leftIcon:s.jsx(_.IconPlus,{size:16}),onClick:e.addNew,sx:{flexGrow:0,flexShrink:0,alignSelf:"flex-end",height:"38px"},children:"Add a Variable"})})),cT=S.observer(()=>{var t;const e=eT();return e.variableOptions.length===0?s.jsx(lT,{model:e}):s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{position:"left",children:[s.jsx(a.Select,{label:"Variables",data:e.variableOptions,value:(t=e.selected)==null?void 0:t.name,onChange:e.selectByName,maxDropdownHeight:600,sx:{flexGrow:1}}),s.jsx(a.Button,{variant:"light",size:"xs",leftIcon:s.jsx(_.IconPlus,{size:16}),onClick:e.addNew,sx:{flexGrow:0,flexShrink:0,alignSelf:"flex-end",height:"38px"},children:"Add a Variable"})]}),s.jsx(a.Divider,{variant:"dashed"}),e.selected?s.jsx(oT,{uiModel:e,variable:e.selected}):s.jsx("span",{children:"Select or create a new variable on right side"})]})}),uT=S.observer(()=>{const{panel:e}=Oe();return Object.keys(e.variableStrings).length===0?null:s.jsxs(a.Stack,{mt:22,spacing:4,children:[s.jsx(a.Text,{size:"sm",fw:500,color:"dimmed",children:"Variables"}),s.jsx(dt.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(e.variableStrings,null,4)})]})});function dT(){const{vizManager:e}=f.useContext(et);return f.useMemo(()=>{const t=e.availableVizList.map(n=>({value:n.name,label:n.displayName??n.name,group:n.displayGroup??""}));return y.orderBy(t,[n=>n.group,n=>n.label],["asc","asc"])},[e])}const pT=S.observer(({value:e,submit:t})=>{const[n,r]=ae.useInputState(e);f.useEffect(()=>{r(e)},[e]);const i=dT(),o=e!==n;return s.jsx(a.Select,{label:"Visualization",value:n,searchable:!0,onChange:r,data:i,rightSection:s.jsx(a.ActionIcon,{disabled:!o,onClick:()=>t(n),children:s.jsx(k.DeviceFloppy,{size:20})}),maxDropdownHeight:600})}),Sc=[];function hT(e,t){try{return e.resolveComponent(t).createConfig()}catch{return null}}function xT(){const{data:e,panel:{variables:t,viz:n,title:r,name:i,queryIDs:o,description:l,id:c}}=Oe(),{vizManager:u}=f.useContext(et),d={name:i,title:r,description:l,viz:n,queryIDs:o,id:c},p=Nl(d);try{return u.resolveComponent(d.viz.type),s.jsx(Qn,{configure:p,children:s.jsx(E1,{variables:t,setVizConf:n.setConf,panel:d,vizManager:u,data:e})})}catch(h){return console.info(y.get(h,"message")),null}}const fT=S.observer(()=>{const{data:e,panel:{viz:t}}=Oe(),{vizManager:n}=f.useContext(et),r=f.useCallback(d=>{if(d===t.type)return;const p=hT(n,d);t.setType(d),t.setConf(p||{})},[t.type]),i=d=>{try{t.setConf(JSON.parse(d))}catch(p){console.error(p)}},o=f.useMemo(()=>{var d;return(d=Sc.find(p=>p.value===t.type))==null?void 0:d.Panel},[t.type,Sc]),l=xT(),c=o?f.createElement(o,{data:e,conf:t.conf,setConf:t.setConf}):null,u=l||c;return s.jsxs(a.Stack,{align:"stretch",sx:{height:"100%",overflow:"hidden"},children:[s.jsx(pT,{submit:r,value:t.type}),s.jsxs(we,{children:[s.jsx(a.Stack,{pb:10,sx:{flexGrow:1,maxHeight:"100%",overflow:"auto"},children:u}),!u&&s.jsx(a.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(t.conf,null,2),onChange:i})]})]})}),gT=S.observer(({panel:e,sourceViewID:t})=>{const n=K(),[r,i]=f.useState(t);f.useEffect(()=>{i(t)},[t]);const[o,{open:l,close:c}]=ae.useDisclosure(!1),u=()=>{e.moveToView(t,r),c()};return s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{size:"xs",variant:"subtle",color:"blue",onClick:l,leftIcon:s.jsx(_.IconBoxMultiple,{size:14}),children:"Move into Another View"}),s.jsx(a.Modal,{opened:o,onClose:c,title:"Move panel into another view",zIndex:320,children:s.jsxs(a.Stack,{sx:{maxHeight:"calc(100vh - 185px)",overflow:"hidden"},children:[s.jsx(a.Radio.Group,{value:r,onChange:i,pb:10,sx:{flexGrow:1,maxHeight:"calc(100vh - 185px - 30px)",overflow:"auto"},children:s.jsx(a.Stack,{spacing:"xs",children:n.views.options.map(d=>s.jsx(a.Radio,{value:d.value,label:d.label},d.value))})}),s.jsxs(a.Group,{noWrap:!0,position:"apart",sx:{flexGrow:0,flexShrink:0},children:[s.jsx(a.Button,{size:"xs",color:"red",leftIcon:s.jsx(_.IconX,{size:14}),onClick:c,children:"Cancel"}),s.jsx(a.Button,{size:"xs",color:"blue",leftIcon:s.jsx(_.IconDeviceFloppy,{size:14}),onClick:u,disabled:r===t,children:"Confirm"})]})]})})]})}),mT={root:{flexGrow:1,width:"100%",minWidth:"1200px",overflow:"hidden"},panel:{width:"100%",minWidth:"1200px",height:"calc(100% - 44px)",padding:10,overflow:"auto"}},fi=({children:e})=>s.jsxs(a.Group,{noWrap:!0,grow:!0,position:"left",spacing:20,sx:{width:"100%",height:"100%",position:"relative"},children:[s.jsx(a.Box,{sx:{maxWidth:"calc(100% - 610px - 10px)",height:"100%",overflow:"auto"},children:e}),s.jsxs(a.Stack,{justify:"flex-start",sx:{alignSelf:"flex-start",width:"600px",flexGrow:0,flexShrink:0},children:[s.jsx(Zk,{}),s.jsx(a.Box,{sx:{flexGrow:1},children:s.jsx(uT,{})})]})]});function yT(e){return!["richText","button"].includes(e)}const bT=S.observer(({panel:e})=>{const t=Ae.useModals(),n=X(),r=K(),[i,o]=f.useState("Data"),l=e.queries,u=yT(e.viz.type)&&e.dataLoading,d=u||e.queryErrors.length>0||e.queryStateMessages!==""||l.length===0,p=n.editor.path[1];f.useEffect(()=>{o(m=>d&&m==="Visualization"?"Data":m)},[e.id,d]);const h=()=>{n.editor.setPath(["_VIEWS_",p])},x=()=>t.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.removePanelByID(e.id,p),h()},confirmProps:{color:"red"},zIndex:320});return s.jsxs(Ts,{value:{panel:e,data:e.data,loading:u,errors:e.queryErrors,downloadPanelScreenshot:()=>{}},children:[s.jsxs(a.Group,{px:16,position:"apart",sx:{borderBottom:"1px solid #eee"},children:[s.jsx(a.Text,{pt:9,pb:8,children:e.name}),s.jsxs(a.Group,{position:"right",noWrap:!0,children:[s.jsx(gT,{panel:e,sourceViewID:p}),s.jsx(a.Button,{size:"xs",variant:"subtle",color:"red",onClick:x,leftIcon:s.jsx(_.IconTrash,{size:14}),children:"Delete This Panel"})]})]}),s.jsxs(a.Tabs,{value:i,onTabChange:o,keepMounted:!1,styles:mT,children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"Data",disabled:u,children:"Data"}),s.jsx(a.Tabs.Tab,{value:"Panel",children:"Panel"}),s.jsx(a.Tabs.Tab,{value:"Variables",disabled:d,children:s.jsx(a.Tooltip,{label:"Requires data",disabled:!d,withinPortal:!0,zIndex:310,children:s.jsx(a.Text,{children:"Variables"})})}),s.jsx(a.Tabs.Tab,{value:"Visualization",disabled:d,children:s.jsx(a.Tooltip,{label:"Requires data",disabled:!d,withinPortal:!0,zIndex:310,children:s.jsx(a.Text,{children:"Visualization"})})}),s.jsx(a.Tabs.Tab,{value:"Interactions",children:"Interactions"})]}),s.jsxs(a.Tabs.Panel,{value:"Data",children:[s.jsx(a.LoadingOverlay,{visible:u,exitTransitionDuration:0}),s.jsx(Jk,{})]}),s.jsx(a.Tabs.Panel,{value:"Panel",children:s.jsx(fi,{children:s.jsx(Wk,{})})}),s.jsx(a.Tabs.Panel,{value:"Variables",children:s.jsx(fi,{children:s.jsx(cT,{})})}),s.jsx(a.Tabs.Panel,{value:"Visualization",children:s.jsx(we,{children:s.jsx(fi,{children:s.jsx(fT,{})})})}),s.jsx(a.Tabs.Panel,{value:"Interactions",children:s.jsx(we,{children:s.jsx(Vp,{})})})]})]})}),jT=S.observer(({viewID:e,panelID:t})=>{const n=K();if(!n.views.findByID(e))return s.jsxs(a.Text,{size:14,children:["View by ID[",e,"] is not found"]});const i=n.panels.findByID(t);return i?s.jsx(bT,{panel:i}):s.jsxs(a.Text,{size:14,children:["Panel by ID[",t,"] is not found"]})}),vT=S.observer(()=>{const[e,t]=f.useState([]),n=Ae.useModals(),r=X(),i=h=>{r.editor.setPath(["_QUERIES_",h])},o=()=>{n.openConfirmModal({title:"Delete ununsed queries?",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.removeUnusedQueries(),confirmProps:{color:"red"},zIndex:320})},l=()=>{r.content.queries.downloadSchema(e)},c=f.useMemo(()=>r.content.queries.sortedList.map(h=>h.id),[r.content.queries.sortedList]),u=()=>{t(c)},d=()=>{t([])},p=r.content.queriesUsage;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 Queries"})}),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(_.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(_.IconTrash,{size:14}),disabled:!r.content.hasUnusedQueries,onClick:o,children:"Delete unused queries"})]}),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:"Name"}),s.jsx("th",{style:{width:"200px"},children:"Data Source"}),s.jsx("th",{style:{width:"100px",textAlign:"right"},children:"Type"}),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.queries.sortedList.map(h=>{var m;const x=((m=p[h.id])==null?void 0:m.length)??0;return s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx(a.Checkbox,{value:h.id,styles:{input:{cursor:"pointer"}}})}),s.jsx("td",{children:h.name}),s.jsx("td",{children:h.key}),s.jsx("td",{style:{textAlign:"right"},children:h.type}),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.id),children:"Open"})})]},h.id)})})]})})})]})}),wT=e=>{const{queryModel:t}=e,n=X(),r=K(),o=r.findQueryUsage(t.id).length>0,l=Ae.useModals(),c=()=>{l.openConfirmModal({title:"Delete this query?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.queries.removeQuery(t.id),n.editor.setPath(["_QUERIES_",""])},confirmProps:{color:"red"},zIndex:320})};return o?s.jsx(a.Tooltip,{label:"Can't delete this query for it's being used, check out Usage tab for details",withArrow:!0,events:{hover:!0,focus:!1,touch:!1},withinPortal:!0,children:s.jsx(a.Button,{color:"gray",size:"xs",leftIcon:s.jsx(_.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})}):s.jsx(a.Button,{color:"red",size:"xs",onClick:c,leftIcon:s.jsx(_.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})},CT=S.observer(wT),_c=({width:e="calc(100% - 32px)",lastWidth:t="50%",height:n,count:r,spacing:i=16,pl:o=0})=>s.jsxs(a.Stack,{spacing:i,mt:6,pl:o,children:[Array.from(new Array(r-1),(l,c)=>s.jsx(a.Skeleton,{width:e,height:n,radius:"xs"},c)),s.jsx(a.Skeleton,{width:t,height:n,radius:"xs"})]}),on=({value:e})=>e===null||e===""?null:s.jsx(a.Tooltip,{label:e,disabled:!e,multiline:!0,children:s.jsx(a.ActionIcon,{children:s.jsx(_.IconInfoCircle,{size:14})})}),ST=({column:e})=>{const{column_key:t,column_key_text:n}=e;return t?s.jsx(a.Tooltip,{label:n,disabled:!n,children:s.jsx(a.Badge,{children:t})}):null},_T=S.observer(({dataSource:e})=>{const{columns:t}=e;return t.loading?s.jsx(_c,{height:"24px",width:"100%",lastWidth:"100%",count:20,pl:6}):t.empty?null:s.jsxs(a.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"1000px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[s.jsxs("colgroup",{children:[s.jsx("col",{style:{width:50}}),s.jsx("col",{style:{minWidth:300}}),s.jsx("col",{style:{width:30}}),s.jsx("col",{style:{width:70}}),s.jsx("col",{style:{minWidth:300}}),s.jsx("col",{style:{minWidth:80,width:80}}),s.jsx("col",{style:{minWidth:120,width:120}})]}),s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"#"}),s.jsx("th",{children:"Column Name"}),s.jsx("th",{}),s.jsx("th",{}),s.jsx("th",{children:"Type"}),s.jsx("th",{children:"Nullable"}),s.jsx("th",{children:"Default Value"})]})}),s.jsx("tbody",{children:t.data.map(n=>s.jsxs("tr",{children:[s.jsx("td",{children:n.ordinal_position}),s.jsx("td",{children:n.column_name}),s.jsx("td",{children:s.jsx(on,{value:n.column_comment})}),s.jsx("td",{children:s.jsx(ST,{column:n})}),s.jsx("td",{children:n.column_type}),s.jsx("td",{children:n.is_nullable}),s.jsx("td",{children:s.jsx(on,{value:n.column_default})})]},n.column_name))})]})}),kT=S.observer(({dataSource:e})=>{const{indexes:t}=e,n=t.data;return s.jsxs(a.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"950px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[s.jsxs("colgroup",{children:[s.jsx("col",{style:{width:100}}),s.jsx("col",{style:{minWidth:300}}),s.jsx("col",{style:{width:150}}),s.jsx("col",{style:{width:150}}),s.jsx("col",{style:{width:250}})]}),s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Index Length"}),s.jsx("th",{children:"Index Name"}),s.jsx("th",{children:"Index Algorithm"}),s.jsx("th",{children:"Unique"}),s.jsx("th",{children:"Column Name"})]})}),s.jsx("tbody",{children:n.map(r=>s.jsxs("tr",{children:[s.jsx("td",{children:r.index_length}),s.jsx("td",{children:r.index_name}),s.jsx("td",{children:r.index_algorithm}),s.jsx("td",{children:r.is_unique?"YES":"NO"}),s.jsx("td",{children:r.column_name})]},r.index_name))})]})}),TT=S.observer(({dataSource:e})=>{const{indexes:t}=e,n=t.data;return s.jsxs(a.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"850px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[s.jsxs("colgroup",{children:[s.jsx("col",{style:{minWidth:300}}),s.jsx("col",{style:{width:150}}),s.jsx("col",{style:{width:100}}),s.jsx("col",{style:{width:100}}),s.jsx("col",{style:{width:100}}),s.jsx("col",{style:{width:100}})]}),s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Index Name"}),s.jsx("th",{children:"Index Algorithm"}),s.jsx("th",{children:"Unique"}),s.jsx("th",{children:"Definition"}),s.jsx("th",{children:"Condition"}),s.jsx("th",{children:"Comment"})]})}),s.jsx("tbody",{children:n.map(r=>s.jsxs("tr",{children:[s.jsx("td",{children:r.index_name}),s.jsx("td",{children:r.index_algorithm}),s.jsx("td",{children:r.is_unique?"YES":"NO"}),s.jsx("td",{children:s.jsx(on,{value:r.index_definition})}),s.jsx("td",{children:s.jsx(on,{value:r.condition})}),s.jsx("td",{children:s.jsx(on,{value:r.comment})})]},r.index_name))})]})}),DT=S.observer(({dataSource:e})=>{const{indexes:t}=e;return t.loading||t.empty?null:e.type===le.MySQL?s.jsx(kT,{dataSource:e}):e.type===le.Postgresql?s.jsx(TT,{dataSource:e}):null}),IT=S.observer(({dataSource:e})=>s.jsxs(a.Stack,{spacing:40,pt:10,sx:{flexGrow:1,overflow:"auto",position:"relative"},children:[s.jsx(we,{children:s.jsx(_T,{dataSource:e})}),s.jsx(we,{children:s.jsx(DT,{dataSource:e})})]}));function MT({table_type:e}){return e==="VIEW"?s.jsx(_.IconEye,{size:14}):e==="BASE TABLE"?s.jsx(_.IconTable,{size:14}):null}const zT=S.observer(({dataSource:e})=>{const{tables:t}=e;return t.loading?s.jsx(_c,{height:"24px",lastWidth:"50%",count:15}):s.jsx(a.Box,{h:"100%",sx:{overflow:"auto",".mantine-NavLink-label":{fontFamily:"monospace"}},children:Object.entries(t.data).map(([n,r])=>s.jsx(a.NavLink,{label:n,icon:s.jsx(_.IconDatabase,{size:14}),defaultOpened:e.table_schema===n,pl:0,childrenOffset:14,children:r.map(i=>s.jsx(a.NavLink,{label:i.table_name,icon:s.jsx(MT,{table_type:i.table_type}),onClick:()=>{e.setKeywords(n,i.table_name)},active:e.table_name===i.table_name},i.table_name))},n))})}),AT=({visible:e})=>s.jsx(a.Box,{py:10,sx:{width:"100%",height:"100%",overflow:"hidden",position:"relative"},children:s.jsx(a.LoadingOverlay,{visible:e})}),ET=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],PT={icon:{width:"50px",textAlign:"center"},input:{"&[data-with-icon]":{paddingLeft:"50px"}}},LT=S.observer(({dataSource:e})=>{const{tableData:t}=e;return s.jsxs(a.Group,{pt:10,px:10,position:"apart",children:[s.jsxs(a.Group,{position:"left",children:[t.maxPage>1&&s.jsx(a.Pagination,{size:"sm",value:t.page,onChange:t.setPage,total:t.maxPage,withEdges:t.maxPage>7,styles:{control:{height:"30px"}}}),s.jsx(a.Select,{icon:s.jsx(a.Text,{ta:"center",color:"dimmed",size:14,children:"Limit"}),size:"xs",styles:PT,data:ET,value:String(t.limit),onChange:n=>t.setLimit(Number(n))})]}),s.jsx(a.Group,{position:"right",children:s.jsxs(a.Text,{color:"dimmed",my:0,size:14,children:["Total ",t.total," rows"]})})]})}),OT=S.observer(({dataSource:e})=>{const t=e.tableData;return t.maxPage===0?s.jsx(a.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:"This table is empty"}):t.error?s.jsx(a.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:t.error}):t.page===1&&t.loading?s.jsx(AT,{visible:!0}):s.jsxs(we,{children:[s.jsx(LT,{dataSource:e}),s.jsxs(a.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[s.jsx(a.LoadingOverlay,{visible:t.loading,overlayBlur:2}),s.jsx(Cc,{data:t.data})]})]})}),BT={root:{flexGrow:1,overflow:"auto",borderLeft:"1px solid #efefef"},tabsList:{borderBottom:"1px solid #efefef"},tab:{minWidth:120}},$T=S.observer(({dataSource:e})=>(f.useEffect(()=>{e.loadTablesIfEmpty()},[e]),e.tables.error?s.jsx(a.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:e.tables.error}):s.jsxs(a.Flex,{sx:{height:"100%"},children:[s.jsx(a.Box,{w:300,sx:{flexGrow:0,flexShrink:0,position:"relative"},children:s.jsx(we,{children:s.jsx(zT,{dataSource:e})})}),s.jsxs(a.Tabs,{defaultValue:"structure",styles:BT,children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"structure",icon:s.jsx(_.IconColumns,{size:14}),children:"Structure"}),s.jsx(a.Tabs.Tab,{value:"data",icon:s.jsx(_.IconDatabase,{size:14}),children:"Data"})]}),s.jsx(a.Tabs.Panel,{value:"structure",children:s.jsx(IT,{dataSource:e})}),s.jsx(a.Tabs.Panel,{value:"data",sx:{width:"100%",height:"calc(100% - 36px)",overflow:"hidden"},children:s.jsx(OT,{dataSource:e})})]})]}))),VT={modal:{paddingLeft:"0px !important",paddingRight:"0px !important"},header:{marginBottom:0,padding:"20px 20px 10px",borderBottom:"1px solid #efefef",gap:"20px"},title:{flexGrow:1},body:{padding:"0 0 0 20px"}},kc=S.observer(({dataSource:e,triggerButtonProps:t={}})=>{const[n,r]=f.useState(!1);return e.type==="http"?null:s.jsxs(s.Fragment,{children:[s.jsx(a.Modal,{opened:n,onClose:()=>r(!1),title:s.jsxs(a.Group,{position:"apart",sx:{flexGrow:1},children:[s.jsx(a.Text,{fw:500,children:"Explorer Data Source"}),s.jsxs(a.Group,{spacing:7,children:[s.jsx(a.Badge,{variant:"gradient",gradient:{from:"indigo",to:"cyan"},children:e.key}),s.jsx(a.Badge,{variant:"gradient",gradient:{from:"orange",to:"red"},children:e.type})]})]}),zIndex:320,size:"96vw",styles:VT,children:s.jsx(a.Box,{sx:{height:"calc(100vh - 220px)"},children:s.jsx($T,{dataSource:e})})}),s.jsx(a.Button,{variant:"subtle",onClick:()=>r(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},...t,children:"See Table Structure"})]})}),qT=f.forwardRef(({label:e,type:t,...n},r)=>t===le.Transform?s.jsxs(a.Group,{position:"left",ref:r,...n,children:[s.jsx(_.IconVectorTriangle,{size:14,color:"#228be6"}),s.jsx(a.Text,{color:"blue",children:e})]}):s.jsxs(a.Group,{position:"apart",ref:r,...n,children:[s.jsx(a.Text,{children:e}),s.jsx(a.Text,{children:t})]})),NT=S.observer(({value:e,onChange:t})=>{const n=X(),{data:r=[],loading:i}=V.useRequest(bs,{refreshDeps:[]},[]),o=f.useMemo(()=>{const d=r.map(p=>({label:p.key,value:p.key,type:p.type}));return d.push({label:"Use other queries' data",value:le.Transform,type:le.Transform}),d},[r]),l=f.useMemo(()=>o.reduce((d,p)=>(d[p.value]=p.type,d),{}),[o]),c=d=>{d!==null&&t({key:d,type:l[d]})},u=f.useMemo(()=>n.datasources.find(e),[n,e]);return s.jsx(a.Select,{data:o,label:s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Box,{children:"Data Source"}),u&&s.jsx(kc,{dataSource:u,triggerButtonProps:{compact:!0,size:"xs",px:10}})]}),itemComponent:qT,rightSection:u?s.jsx(a.Text,{size:"xs",color:"dimmed",children:u.type}):void 0,rightSectionWidth:85,maxDropdownHeight:500,styles:{root:{flex:1},label:{display:"block"},rightSection:{pointerEvents:"none",justifyContent:"flex-end",paddingRight:"10px",".mantine-Text-root":{userSelect:"none"}}},disabled:i,value:e.key,onChange:c})}),Tc=f.forwardRef((e,t)=>{const{label:n,description:r,...i}=e;return s.jsx("div",{ref:t,...i,children:s.jsxs(a.Group,{position:"apart",noWrap:!0,children:[s.jsx(a.Text,{children:n}),s.jsx(a.Text,{size:"xs",color:"dimmed",children:r})]})})}),FT=S.observer(({queryModel:e})=>{const[t,n]=f.useState(e.name);return f.useEffect(()=>{n(e.name)},[e.name]),s.jsx(a.Center,{ml:20,mt:20,sx:{maxWidth:"600px"},children:s.jsxs(a.Stack,{spacing:10,sx:{width:"100%"},children:[s.jsx(a.Divider,{mb:-10,variant:"dashed",label:"Basics",labelPosition:"center"}),s.jsx(a.TextInput,{placeholder:"A unique name",label:"Name",required:!0,sx:{flex:1},value:t,onChange:r=>{n(r.currentTarget.value)},rightSection:s.jsx(a.ActionIcon,{variant:"filled",color:"blue",size:"sm",onClick:()=>e.setName(t),disabled:t===e.name,children:s.jsx(_.IconDeviceFloppy,{size:16})}),onBlur:()=>{e.setName(t)}}),s.jsx(NT,{value:{type:e.type,key:e.key},onChange:({type:r,key:i})=>{e.setKey(i),e.setType(r)}}),s.jsx(a.Divider,{mt:10,mb:-10,variant:"dashed",label:"Conditions",labelPosition:"center"}),s.jsx(a.MultiSelect,{label:"Run query when these are truthy",placeholder:"Always run this query on load",data:e.conditionOptions,value:[...e.run_by],onChange:e.setRunBy,itemComponent:Tc,maxDropdownHeight:500}),e.typedAsHTTP&&s.jsx(a.MultiSelect,{label:"Re-run query when these changed",placeholder:"Leave it empty to never re-run this query",data:e.conditionOptions,value:[...e.react_to],onChange:e.setReactTo,itemComponent:Tc,maxDropdownHeight:500}),s.jsx(a.Divider,{mt:20,mb:10,variant:"dashed"}),s.jsx(CT,{queryModel:e})]})})});function GT({content:e}){return s.jsxs(a.HoverCard,{width:"60vw",shadow:"md",children:[s.jsx(a.HoverCard.Target,{children:s.jsx(a.ActionIcon,{size:16,color:"blue",children:s.jsx(_.IconEye,{})})}),s.jsx(a.HoverCard.Dropdown,{children:s.jsx(dt.Prism,{language:"sql",noCopy:!0,withLineNumbers:!0,children:e})})]})}const WT=S.observer(()=>{const t=[...X().globalSQLSnippets.list];return t.length===0?null:s.jsxs(a.Table,{horizontalSpacing:"xs",verticalSpacing:"xs",fontSize:"sm",highlightOnHover:!0,children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Key"}),s.jsx("th",{children:"Value"})]})}),s.jsx("tbody",{children:t.map(n=>{const{id:r,content:i}=n;return s.jsxs("tr",{children:[s.jsx("td",{children:r}),s.jsx("td",{width:200,children:s.jsx(GT,{content:i})})]},r)})})]})}),RT=`
|
|
465
|
+
`,Mk=()=>{const[e,t]=f.useState(!1);return s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{variant:"subtle",compact:!0,onClick:()=>t(n=>!n),children:e?"Close":"Click to see expected data structure"}),s.jsx(a.Collapse,{in:e,children:s.jsx(dt.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:Ik})})]})},zk=S.observer(function({filter:t}){const n=t.config;return s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Checkbox,{checked:n.required,onChange:r=>n.setRequired(r.currentTarget.checked),label:"Required"}),s.jsx(qt,{filter:t})]}),s.jsx(a.TextInput,{label:"Min-width",value:n.min_width,onChange:r=>n.setMinWidth(r.currentTarget.value),placeholder:"200px"}),s.jsx(a.Divider,{label:"Fetch options from database",labelPosition:"center"}),s.jsx(a.Checkbox,{checked:n.treeCheckStrictly,onChange:r=>n.setTreeCheckStrictly(r.currentTarget.checked),label:"Parent and children nodes are not associated"}),s.jsx(a.NumberInput,{value:n.default_selection_count,onChange:n.setDefaultSelectionCount,label:"Select first N options by default"}),s.jsx(pi,{value:n.options_query_id,onChange:n.setOptionsQueryID}),s.jsx(Mk,{})]})}),Ak=S.observer(function({filter:t}){return s.jsxs(a.Box,{sx:{maxWidth:"480px"},children:[s.jsx(a.Text,{pt:"0",pb:"md",color:"gray",children:"Config"}),s.jsx(dt.Prism,{mt:22,language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(t,null,4)})]})}),Ek={select:Tk,"multi-select":kk,"tree-select":zk,"text-input":Dk,checkbox:wk,"date-range":Sk},gt={select:"Select","multi-select":"Multi Select","tree-select":"Tree Select","text-input":"Text Input",checkbox:"Checkbox","date-range":"Date Range"},Pk=[{label:gt.select,value:"select"},{label:gt["multi-select"],value:"multi-select"},{label:gt["tree-select"],value:"tree-select"},{label:gt["text-input"],value:"text-input"},{label:gt.checkbox,value:"checkbox"},{label:gt["date-range"],value:"date-range"}],Lk=S.observer(function({filter:t}){const n=K(),r=f.useMemo(()=>Ek[t.type],[t.type]);return s.jsxs(a.Group,{grow:!0,spacing:20,align:"top",children:[s.jsxs(a.Box,{sx:{maxWidth:"600px"},children:[s.jsx(a.Text,{pb:"md",color:"gray",children:"Edit"}),s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{noWrap:!0,children:[s.jsx(a.NumberInput,{label:"Placement Order",required:!0,value:t.order,onChange:t.setOrder,hideControls:!0,sx:{flexGrow:"1 !important"}}),t.auto_submit_supported&&s.jsx(a.Checkbox,{label:"Submit automatically",checked:t.auto_submit,onChange:i=>t.setAutoSubmit(i.currentTarget.checked),mt:22})]}),s.jsx(a.MultiSelect,{label:"Visible in...",data:n.views.options,value:[...t.visibleInViewsIDs],onChange:t.setVisibleInViewsIDs}),s.jsx(a.TextInput,{label:"Key",placeholder:"A unique key to refer",required:!0,value:t.key,onChange:i=>{t.setKey(i.currentTarget.value)}}),s.jsx(a.TextInput,{label:"Label",placeholder:"Label for this field",required:!0,value:t.label,onChange:i=>{t.setLabel(i.currentTarget.value)}}),s.jsx(a.Select,{label:"Widget",data:Pk,required:!0,value:t.type,onChange:t.setType,maxDropdownHeight:500}),s.jsx(a.Divider,{mb:0,mt:10,variant:"dashed",label:`${gt[t.type]} Settings`,labelPosition:"center"}),s.jsx(r,{filter:t})]})]}),s.jsx(Ak,{filter:t})]})}),Ok=S.observer(({id:e})=>{const t=Ae.useModals(),n=X(),r=K();if(e==="")return null;const i=r.filters.findByID(e);if(!i)return s.jsxs(a.Text,{size:14,children:["Filter by ID[",e,"] is not found"]});const o=()=>{n.editor.setPath(["_FILTERS_",""])},l=()=>{t.openConfirmModal({title:"Delete this filter?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.filters.removeByID(e),o()},confirmProps:{color:"red"},zIndex:320})};return s.jsxs(a.Stack,{sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",pb:30,children:[s.jsx(a.Group,{position:"right",pt:10,children:s.jsx(a.Button,{size:"xs",color:"red",leftIcon:s.jsx(k.Trash,{size:16}),onClick:l,children:"Delete this filter"})}),s.jsx(a.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:s.jsx(Lk,{filter:i})})]})}),Bk=S.observer(()=>{const[e,t]=f.useState([]),n=X(),r=u=>{n.editor.setPath(["_FILTERS_",u])},i=()=>{n.content.filters.downloadSchema(e)},o=f.useMemo(()=>n.content.filters.sortedList.map(u=>u.id),[n.content.filters.sortedList]),l=()=>{t(o)},c=()=>{t([])};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 Filters"})}),s.jsx(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:l,children:"Select All"}),s.jsx(a.Button,{variant:"default",size:"xs",onClick:c,children:"Clear Selection"})]}),s.jsx(a.Button,{size:"xs",color:"blue",leftIcon:s.jsx(_.IconCode,{size:14}),disabled:e.length===0,onClick:i,children:"Download Schema"})]})}),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",{style:{width:"300px"},children:"Label"}),s.jsx("th",{children:"Key"}),s.jsx("th",{style:{width:"100px"},children:"Widget"}),s.jsx("th",{style:{width:"300px",paddingLeft:"24px"},children:"Action"})]})}),s.jsx("tbody",{children:n.content.filters.sortedList.map(u=>s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx(a.Checkbox,{value:u.id,styles:{input:{cursor:"pointer"}}})}),s.jsx("td",{children:u.label}),s.jsx("td",{children:u.key}),s.jsx("td",{children:gt[u.type]}),s.jsx("td",{children:s.jsx(a.Button,{variant:"subtle",size:"xs",onClick:()=>r(u.id),children:"Open"})})]},u.id))})]})})})]})}),$k=S.observer(()=>{const e=K(),[t,n]=f.useState(()=>JSON.stringify(e.mock_context.current,null,4)),r=()=>{try{e.mock_context.replace(JSON.parse(t))}catch(o){yt.showNotification({title:"Failed",message:o.message,color:"red"})}},i=f.useMemo(()=>{try{return JSON.stringify(JSON.parse(t))!==JSON.stringify(e.mock_context.current)}catch{return!1}},[t,e.mock_context.current]);return s.jsxs(a.Stack,{sx:{border:"1px solid #eee",borderLeft:"none",borderRight:"none",flexGrow:1,maxWidth:"unset"},children:[s.jsx(a.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:s.jsx(a.Text,{weight:500,children:"Mock Context"})}),s.jsxs(a.Group,{grow:!0,px:"md",pb:"md",pt:0,sx:{flexGrow:1,position:"relative",alignItems:"flex-start"},children:[s.jsxs(a.Stack,{spacing:10,sx:{maxWidth:"unset !important"},children:[s.jsx(a.Text,{children:"A valid json string is required"}),s.jsx(a.JsonInput,{validationError:"Invalid json",formatOnBlur:!0,autosize:!0,minRows:30,value:t,onChange:n,sx:{flexGrow:1}})]}),s.jsx(a.ActionIcon,{mr:5,variant:"filled",color:"blue",sx:{position:"absolute",right:12,top:0},disabled:!i,onClick:r,children:s.jsx(k.DeviceFloppy,{size:20})})]})]})}),Vk=S.observer(()=>{const{panel:e}=Oe();return s.jsx(pr,{label:"Description",value:e.description,onChange:e.setDescription,styles:{root:{flexGrow:1}}})}),qk=S.observer(()=>{const{panel:e}=Oe(),{style:t}=e;return s.jsxs(s.Fragment,{children:[s.jsx(a.Divider,{mb:-10,label:"Style",labelPosition:"center",variant:"dashed"}),s.jsxs(a.Stack,{spacing:20,children:[s.jsxs(a.Group,{grow:!0,align:"top",children:[s.jsx(a.NumberInput,{label:"Width",min:1,max:36,step:1,precision:0,rightSection:s.jsx(a.Text,{size:12,children:"of 36 columns"}),styles:{rightSection:{width:"110px"}},value:e.layout.w,onChange:n=>{n&&e.layout.setWidth(n)}}),s.jsx(a.NumberInput,{label:"Height",rightSection:s.jsx(a.Text,{size:12,children:"px"}),styles:{rightSection:{width:"40px"}},value:e.layout.h,onChange:n=>{n&&e.layout.setHeight(n)}})]}),s.jsx(a.Checkbox,{ml:6,label:"Border",checked:t.border.enabled,onChange:n=>t.border.setEnabled(n.currentTarget.checked)})]})]})}),Nk=()=>s.jsxs("span",{className:"mantine-103svbs mantine-InputWrapper-required mantine-Select-required","aria-hidden":"true",children:[" ","*"]}),Fk=S.observer(()=>{const{panel:e}=Oe(),{name:t}=e,[n,r]=ae.useInputState(t),i=t!==n,o=f.useCallback(()=>{i&&e.setName(n)},[i,n]);f.useEffect(()=>{r(t)},[t]);const l=!n.trim();return s.jsxs(a.Stack,{spacing:4,children:[s.jsxs(a.Group,{align:"center",children:[s.jsxs(a.Text,{size:14,fw:500,children:["Panel Name",s.jsx(Nk,{})]}),s.jsx(a.ActionIcon,{variant:"subtle",color:"blue",disabled:!i||l,onClick:o,children:s.jsx(_.IconDeviceFloppy,{size:18})})]}),s.jsx(a.TextInput,{value:n,onChange:r,required:!0})]})}),Gk=S.observer(()=>{const{panel:e}=Oe();return s.jsx(a.Stack,{spacing:6,mb:10,children:s.jsxs(a.Group,{pl:6,position:"left",spacing:20,children:[s.jsx(a.Checkbox,{size:"sm",checked:e.title.show,onChange:t=>e.title.setShow(t.currentTarget.checked),label:"Show Title",sx:{userSelect:"none"}}),s.jsx(a.Checkbox,{size:"sm",checked:!0,disabled:!0,label:"Use name as title"})]})})});function Wk(){return s.jsxs(a.Stack,{sx:{height:"100%"},children:[s.jsx(qk,{}),s.jsx(a.Divider,{label:"Info",labelPosition:"center",variant:"dashed"}),s.jsx(Fk,{}),s.jsx(Gk,{}),s.jsx(Vk,{})]})}const Rk={width:"fit-content",minWidth:"100%",tableLayout:"fixed",tr:{width:"fit-content"},th:{position:"relative"},"th, td":{wordBreak:"break-word"},".resizer":{position:"absolute",right:0,top:"50%",transform:"translateY(-50%)",cursor:"col-resize",userSelect:"none",touchAction:"none"},".resizer.isResizing":{color:"#228be6",opacity:"1"},"@media (hover: hover)":{".resizer":{opacity:"0"},"*:hover > .resizer":{color:"#228be6",opacity:"1"}}};function Cc({data:e}){const t=f.useMemo(()=>{if(!Array.isArray(e)||e.length===0)return[];const r=Re.createColumnHelper();return Object.keys(e[0]).map(i=>r.accessor(i,{cell:o=>o.getValue()}))},[e]),n=Re.useReactTable({data:e,columns:t,columnResizeMode:"onChange",getCoreRowModel:Re.getCoreRowModel()});return e.length===0?s.jsx(a.Box,{sx:{height:"5em"}}):s.jsx(we,{children:s.jsxs(a.Table,{sx:Rk,children:[s.jsx("thead",{children:n.getHeaderGroups().map(r=>s.jsx("tr",{children:r.headers.map(i=>s.jsxs("th",{style:{width:i.getSize()},children:[i.isPlaceholder?null:Re.flexRender(i.column.columnDef.header,i.getContext()),s.jsx(a.ActionIcon,{onMouseDown:i.getResizeHandler(),onTouchStart:i.getResizeHandler(),className:`resizer ${i.column.getIsResizing()?"isResizing":""}`,children:s.jsx(k.ArrowBarToRight,{})})]},i.id))},r.id))}),s.jsx("tbody",{children:n.getRowModel().rows.map(r=>s.jsx("tr",{children:r.getVisibleCells().map(i=>s.jsx("td",{children:s.jsx(we,{children:Re.flexRender(i.column.columnDef.cell,i.getContext())})},i.id))},r.id))})]})})}const Qk=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],Uk={icon:{width:"80px",textAlign:"center"},input:{"&[data-with-icon]":{paddingLeft:"80px"}}},Kk=({data:e,page:t,setPage:n,limit:r,setLimit:i})=>{const o=e.length,l=Math.ceil(o/r),c=d=>{n(1),i(Number(d))};if(o===0)return null;const u=l===1&&o<=10;return s.jsxs(a.Group,{pt:10,px:10,position:"apart",children:[s.jsxs(a.Group,{position:"left",children:[l>1&&s.jsx(a.Pagination,{size:"sm",value:t,onChange:n,total:l,withEdges:l>7,styles:{control:{height:"30px"}}}),!u&&s.jsx(a.Select,{icon:s.jsx(a.Text,{ta:"center",color:"dimmed",size:14,children:"Page Size"}),size:"xs",styles:Uk,data:Qk,value:String(r),onChange:c})]}),s.jsx(a.Group,{position:"right",children:s.jsxs(a.Text,{color:"dimmed",my:0,size:14,children:["Total ",o," rows"]})})]})},Yk=bd(({data:e,loading:t})=>{const[n,r]=f.useState(1),[i,o]=f.useState(20),l=f.useMemo(()=>{const c=(n-1)*i,u=c+i;return e.slice(c,u)},[e,n,i]);return s.jsxs(we,{children:[s.jsx(Kk,{data:e,page:n,setPage:r,limit:i,setLimit:o}),s.jsxs(a.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[s.jsx(a.LoadingOverlay,{visible:t,overlayBlur:2}),s.jsx(Cc,{data:l})]})]})}),Xk=({queryID:e})=>{const t=ue(),{state:n,error:r}=t.getDataStuffByID(e),i=f.useMemo(()=>t.queries.findByID(e),[t,e]);return n==="loading"?null:r?s.jsx(a.Text,{mt:10,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:r}):i!=null&&i.stateMessage?s.jsx(a.Text,{mt:10,color:"gray",align:"center",children:i.stateMessage}):null},hi=S.observer(({id:e,moreActions:t,refreshOnMount:n})=>{const r=ue(),{data:i,state:o}=r.getDataStuffByID(e),l=o==="loading",c=f.useCallback(()=>{r.queries.refetchDataByQueryID(e)},[e,r]),u=()=>{r.queries.downloadDataByQueryID(e)};f.useEffect(()=>{n&&c()},[c,n]);const d=!Array.isArray(i)||i.length===0;return s.jsxs(a.Stack,{spacing:0,sx:{height:"100%",border:"1px solid #eee"},children:[s.jsxs(a.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(a.Group,{position:"left",children:s.jsx(a.Text,{weight:500,children:"Preview Data"})}),s.jsxs(a.Group,{pr:15,children:[t,s.jsx(a.ActionIcon,{variant:"subtle",color:"blue",disabled:l,onClick:c,children:s.jsx(k.Refresh,{size:16})}),s.jsx(a.ActionIcon,{variant:"subtle",color:"blue",disabled:l||d,onClick:u,children:s.jsx(k.Download,{size:16})})]})]}),s.jsxs(a.Box,{pb:20,sx:{position:"relative",flexGrow:1,overflow:"auto"},children:[s.jsx(Xk,{queryID:e}),s.jsx(Yk,{data:i,loading:l})]})]})}),Jk=S.observer(function(){const t=X(),n=K(),{panel:r}=Oe(),[i,o]=f.useState(!1),l=c=>{t.editor.setPath(["_QUERIES_",c])};return s.jsxs(s.Fragment,{children:[s.jsx(a.Drawer,{opened:i,onClose:()=>o(!1),title:"Choose queries",padding:"xl",size:500,zIndex:320,children:s.jsx(a.Checkbox.Group,{value:[...r.queryIDs],onChange:r.setQueryIDs,children:s.jsx(a.Stack,{spacing:"lg",children:n.queries.options.map(c=>s.jsx(a.Checkbox,{label:c.label,value:c.value},c.value))})})}),s.jsxs(a.Stack,{spacing:6,children:[s.jsx(a.Group,{position:"right",children:s.jsx(a.Button,{variant:"light",size:"sm",leftIcon:s.jsx(_.IconLine,{size:16}),onClick:()=>o(!0),children:"Click me to choose queries for this panel"})}),r.queryIDs.length===1&&s.jsx(hi,{id:r.queryIDs[0],moreActions:s.jsx(a.Tooltip,{label:"Open this query",children:s.jsx(a.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>l(r.queryIDs[0]),children:s.jsx(_.IconArrowCurveRight,{size:16})})})}),r.queryIDs.length>1&&s.jsxs(a.Tabs,{defaultValue:r.queryIDs[0],children:[s.jsx(a.Tabs.List,{children:r.queries.map(c=>s.jsx(a.Tabs.Tab,{value:c.id,children:c.name},c.id))}),r.queries.map(c=>s.jsx(a.Tabs.Panel,{value:c.id,children:s.jsx(hi,{id:c.id,moreActions:s.jsx(a.Tooltip,{label:"Open this query",children:s.jsx(a.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>l(c.id),children:s.jsx(_.IconArrowCurveRight,{size:16})})})})},c.id))]})]})]})}),Zk=S.observer(()=>{const{panel:e}=ht();return s.jsx(we,{children:s.jsx(a.Box,{sx:{height:"100%",flexGrow:0,flexShrink:0,width:"600px"},children:s.jsxs(a.Stack,{mt:24,spacing:5,sx:{width:"600px",height:"450px",background:"transparent",borderRadius:"5px",border:"1px solid #e9ecef",borderWidth:e.style.border.enabled?"1px":"0px"},children:[s.jsxs(a.Group,{position:"apart",noWrap:!0,sx:{flexGrow:0,flexShrink:0},children:[s.jsx(a.Group,{children:s.jsx(si,{})}),s.jsx(a.Group,{grow:!0,position:"center",children:s.jsx(a.Text,{lineClamp:1,weight:"bold",children:e.title.show?e.name:""})}),s.jsx(a.Group,{position:"right",spacing:0,sx:{height:"28px"}})]}),s.jsx(a.Group,{px:5,pb:5,sx:{flexGrow:1,".panel-viz-section":{height:"calc(100% - 28px)"}},children:s.jsx(ri,{panel:e})})]})})})}),xi={name:"new_var",size:"1rem",weight:"initial",color:{type:"static",staticColor:"Red"},data_field:"",aggregation:{type:"sum",config:{},fallback:"0"},formatter:{output:"number",mantissa:0,trimMantissa:!1,average:!1}};class Hk{constructor(t){P(this,"panel");P(this,"selected");this.panel=t,t.variables.length>0&&(this.selected=t.variables[0]),R.makeAutoObservable(this,{},{deep:!1,autoBind:!0})}get variables(){return this.panel.variables}get variableOptions(){return this.panel.variables.map(t=>({label:t.name,value:t.name,description:t.aggregation.type}))}addNew(){const t=this.panel.variables.filter(n=>n.name.startsWith(xi.name)).length;this.panel.addVariable(y.cloneDeep({...xi,name:`${xi.name}${t||""}`})),this.selected=y.last(this.panel.variables)}select(t){this.selected=t}selectByName(t){if(!t){console.warn("Unexpected null name when calling selectByName");return}const n=this.variables.find(r=>r.name===t);if(!n){console.error(`Variable by name[${t}] not found`);return}this.selected=n}remove(t){this.selected===t&&(this.selected=void 0);const n=this.panel.variables.indexOf(t);if(this.panel.removeVariable(t),!this.selected&&!y.isEmpty(this.panel.variables)){const r=Math.min(this.panel.variables.length-1,n);this.selected=this.panel.variables[r]}}}function eT(){const{panel:e}=Oe();return V.useCreation(()=>new Hk(e),[e])}function tT({label:e,value:t,onChange:n},r){const[i,o]=f.useState(Array.isArray(t)?[...t]:[]),l=f.useCallback(()=>{o(x=>[...x,""])},[o]),c=f.useCallback(x=>{o(m=>(m.splice(x,1),[...m]))},[o]),u=f.useMemo(()=>!y.isEqual(i,t),[i,t]),d=()=>{n(i.map(x=>x.toString()))},p=a.useMantineTheme(),h=f.useMemo(()=>Object.entries(p.colors).map(([x,m])=>m[6]),[p]);return s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{position:"left",ref:r,children:[s.jsx(a.Text,{children:e}),s.jsx(a.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!u,onClick:d,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Group,{children:[i.map((x,m)=>s.jsx(a.ColorInput,{value:x,onChange:j=>{o(C=>(C.splice(m,1,j),[...C]))},swatches:h,rightSection:s.jsx(a.ActionIcon,{onClick:()=>c(m),color:"red",children:s.jsx(k.Trash,{size:14})}),sx:{width:"45%"}})),s.jsx(a.ActionIcon,{onClick:l,color:"blue",variant:"outline",children:s.jsx(k.PlaylistAdd,{size:20})})]})]})}const nT=f.forwardRef(tT);function sT({label:e,value:t,onChange:n,type:r},i){const[o,l]=f.useState(Array.isArray(t)?[...t]:[]),c=f.useCallback(()=>{l(h=>[...h,""])},[l]),u=f.useCallback(h=>{l(x=>(x.splice(h,1),[...x]))},[l]),d=f.useMemo(()=>!y.isEqual(o.map(String),t.map(String)),[o,t]),p=()=>{n(o.map(h=>r==="number"?Number(h):h.toString()))};return s.jsxs(s.Fragment,{children:[s.jsxs(a.Group,{position:"left",ref:i,children:[s.jsx(a.Text,{children:e}),s.jsx(a.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!d,onClick:p,children:s.jsx(k.DeviceFloppy,{size:20})})]}),s.jsxs(a.Group,{children:[o.map((h,x)=>s.jsx(a.TextInput,{type:r,value:h,onChange:m=>{const j=m.currentTarget.value;l(C=>(C.splice(x,1,j),[...C]))},rightSection:s.jsx(a.ActionIcon,{onClick:()=>u(x),color:"red",children:s.jsx(k.Trash,{size:14})}),sx:{width:"45%"}})),s.jsx(a.ActionIcon,{onClick:c,color:"blue",variant:"outline",children:s.jsx(k.PlaylistAdd,{size:20})})]})]})}const rT=f.forwardRef(sT),iT=f.forwardRef(function({value:t,onChange:n},r){const i=t.color.type,o=(c,u)=>{const d=y.cloneDeep(t);y.set(d,c,u),n(d)},l=c=>{if(c==="static"){n({...t,color:{type:"static",staticColor:"#25262B"}});return}n({...t,color:{type:"continuous",colorRange:[],valueRange:[]}})};return s.jsxs(s.Fragment,{children:[s.jsx(a.Stack,{children:s.jsx(a.TextInput,{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%...",sx:{flex:1},value:t.size,onChange:c=>o("size",c.currentTarget.value)})}),s.jsx(a.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:s.jsx(Go,{label:"Font Weight",value:t.weight,onChange:c=>o("weight",c)})}),s.jsx(a.Divider,{mt:"lg",mb:0,variant:"dashed",label:"Style",labelPosition:"center"}),s.jsxs(a.Stack,{children:[s.jsx(a.Select,{label:"Color Type",data:[{label:"Static Color",value:"static"},{label:"Continuous Color",value:"continuous"}],value:t.color.type,onChange:l}),i==="static"&&s.jsx(ke,{value:t.color.staticColor,onChange:c=>o("color.staticColor",c)}),i==="continuous"&&s.jsxs(s.Fragment,{children:[s.jsx(rT,{label:"Value Range",value:t.color.valueRange,type:"number",onChange:c=>o("color.valueRange",c)}),s.jsx(nT,{label:"Color Range",value:t.color.colorRange,onChange:c=>o("color.colorRange",c)})]})]})]})}),aT=f.forwardRef(function({value:t,onChange:n,withStyle:r=!0,remove:i},o){const l=(c,u)=>{const d=y.cloneDeep(t);y.set(d,c,u),n(d)};return s.jsxs(a.Stack,{ref:o,children:[s.jsxs(a.Stack,{spacing:"xs",px:"sm",py:"md",sx:{border:"1px solid #e9ecef"},children:[s.jsxs(a.Group,{grow:!0,noWrap:!0,children:[s.jsx(a.TextInput,{label:"Name",required:!0,value:t.name,onChange:c=>l("name",c.currentTarget.value)}),s.jsx(B,{label:"Data Field",required:!0,value:t.data_field,onChange:c=>l("data_field",c)})]}),s.jsx(ir,{label:"Aggregation",pt:0,value:t.aggregation,onChange:c=>l("aggregation",c),withFallback:!0}),t.aggregation.type!=="custom"&&s.jsxs(s.Fragment,{children:[s.jsx(a.Divider,{mt:"xl",mb:0,label:"Format",labelPosition:"center",variant:"dashed"}),s.jsx(Fe,{value:t.formatter,onChange:c=>l("formatter",c)})]})]}),r&&s.jsx(a.Accordion,{variant:"contained",children:s.jsxs(a.Accordion.Item,{value:"Styles",children:[s.jsx(a.Accordion.Control,{icon:s.jsx(a.Text,{size:"xl",children:"🖼️"}),children:"Styles"}),s.jsx(a.Accordion.Panel,{children:s.jsx(iT,{value:t,onChange:n})})]})}),s.jsx(a.Button,{mt:20,leftIcon:s.jsx(_.IconTrash,{size:16}),color:"red",variant:"light",onClick:i,children:"Delete this Variable"})]})}),oT=S.observer(e=>{const t=V.useCreation(()=>Vl(e.variable),[e.variable]),n=()=>e.uiModel.remove(e.variable);return s.jsxs(a.Stack,{"data-testid":"variable-editor",align:"stretch",children:[s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Button,{variant:"subtle",size:"xs",disabled:!t.changed,color:"red",onClick:t.reset,leftIcon:s.jsx(_.IconRecycle,{size:18}),children:"Revert Changes"}),s.jsx(a.Button,{variant:"filled",size:"xs",disabled:!t.changed,color:"green",onClick:t.commit,leftIcon:s.jsx(_.IconDeviceFloppy,{size:18}),children:"Save Changes"})]}),s.jsx(aT,{value:g.getSnapshot(t.copy),onChange:t.update,remove:n})]})});S.observer(e=>{const{uiModel:t}=e;return s.jsx(a.Stack,{className:"var-list",children:t.variables.map(n=>s.jsx(a.Button,{variant:t.selected===n?"filled":"subtle",color:"gray",onClick:()=>t.select(n),children:n.name},n.name))})});const lT=S.observer(({model:e})=>s.jsx(a.Overlay,{color:"#fff",opacity:1,sx:{position:"absolute"},children:s.jsx(a.Button,{variant:"light",size:"xs",leftIcon:s.jsx(_.IconPlus,{size:16}),onClick:e.addNew,sx:{flexGrow:0,flexShrink:0,alignSelf:"flex-end",height:"38px"},children:"Add a Variable"})})),cT=S.observer(()=>{var t;const e=eT();return e.variableOptions.length===0?s.jsx(lT,{model:e}):s.jsxs(a.Stack,{children:[s.jsxs(a.Group,{position:"left",children:[s.jsx(a.Select,{label:"Variables",data:e.variableOptions,value:(t=e.selected)==null?void 0:t.name,onChange:e.selectByName,maxDropdownHeight:600,sx:{flexGrow:1}}),s.jsx(a.Button,{variant:"light",size:"xs",leftIcon:s.jsx(_.IconPlus,{size:16}),onClick:e.addNew,sx:{flexGrow:0,flexShrink:0,alignSelf:"flex-end",height:"38px"},children:"Add a Variable"})]}),s.jsx(a.Divider,{variant:"dashed"}),e.selected?s.jsx(oT,{uiModel:e,variable:e.selected}):s.jsx("span",{children:"Select or create a new variable on right side"})]})}),uT=S.observer(()=>{const{panel:e}=Oe();return Object.keys(e.variableStrings).length===0?null:s.jsxs(a.Stack,{mt:22,spacing:4,children:[s.jsx(a.Text,{size:"sm",fw:500,color:"dimmed",children:"Variables"}),s.jsx(dt.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(e.variableStrings,null,4)})]})});function dT(){const{vizManager:e}=f.useContext(et);return f.useMemo(()=>{const t=e.availableVizList.map(n=>({value:n.name,label:n.displayName??n.name,group:n.displayGroup??""}));return y.orderBy(t,[n=>n.group,n=>n.label],["asc","asc"])},[e])}const pT=S.observer(({value:e,submit:t})=>{const[n,r]=ae.useInputState(e);f.useEffect(()=>{r(e)},[e]);const i=dT(),o=e!==n;return s.jsx(a.Select,{label:"Visualization",value:n,searchable:!0,onChange:r,data:i,rightSection:s.jsx(a.ActionIcon,{disabled:!o,onClick:()=>t(n),children:s.jsx(k.DeviceFloppy,{size:20})}),maxDropdownHeight:600})}),Sc=[];function hT(e,t){try{return e.resolveComponent(t).createConfig()}catch{return null}}function xT(){const{data:e,panel:{variables:t,viz:n,title:r,name:i,queryIDs:o,description:l,id:c}}=Oe(),{vizManager:u}=f.useContext(et),d={name:i,title:r,description:l,viz:n,queryIDs:o,id:c},p=Nl(d);try{return u.resolveComponent(d.viz.type),s.jsx(Qn,{configure:p,children:s.jsx(E1,{variables:t,setVizConf:n.setConf,panel:d,vizManager:u,data:e})})}catch(h){return console.info(y.get(h,"message")),null}}const fT=S.observer(()=>{const{data:e,panel:{viz:t}}=Oe(),{vizManager:n}=f.useContext(et),r=f.useCallback(d=>{if(d===t.type)return;const p=hT(n,d);t.setType(d),t.setConf(p||{})},[t.type]),i=d=>{try{t.setConf(JSON.parse(d))}catch(p){console.error(p)}},o=f.useMemo(()=>{var d;return(d=Sc.find(p=>p.value===t.type))==null?void 0:d.Panel},[t.type,Sc]),l=xT(),c=o?f.createElement(o,{data:e,conf:t.conf,setConf:t.setConf}):null,u=l||c;return s.jsxs(a.Stack,{align:"stretch",sx:{height:"100%",overflow:"hidden"},children:[s.jsx(pT,{submit:r,value:t.type}),s.jsxs(we,{children:[s.jsx(a.Stack,{pb:10,sx:{flexGrow:1,maxHeight:"100%",overflow:"auto"},children:u}),!u&&s.jsx(a.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(t.conf,null,2),onChange:i})]})]})}),gT=S.observer(({panel:e,sourceViewID:t})=>{const n=K(),[r,i]=f.useState(t);f.useEffect(()=>{i(t)},[t]);const[o,{open:l,close:c}]=ae.useDisclosure(!1),u=()=>{e.moveToView(t,r),c()};return s.jsxs(s.Fragment,{children:[s.jsx(a.Button,{size:"xs",variant:"subtle",color:"blue",onClick:l,leftIcon:s.jsx(_.IconBoxMultiple,{size:14}),children:"Move into Another View"}),s.jsx(a.Modal,{opened:o,onClose:c,title:"Move panel into another view",zIndex:320,children:s.jsxs(a.Stack,{sx:{maxHeight:"calc(100vh - 185px)",overflow:"hidden"},children:[s.jsx(a.Radio.Group,{value:r,onChange:i,pb:10,sx:{flexGrow:1,maxHeight:"calc(100vh - 185px - 30px)",overflow:"auto"},children:s.jsx(a.Stack,{spacing:"xs",children:n.views.options.map(d=>s.jsx(a.Radio,{value:d.value,label:d.label},d.value))})}),s.jsxs(a.Group,{noWrap:!0,position:"apart",sx:{flexGrow:0,flexShrink:0},children:[s.jsx(a.Button,{size:"xs",color:"red",leftIcon:s.jsx(_.IconX,{size:14}),onClick:c,children:"Cancel"}),s.jsx(a.Button,{size:"xs",color:"blue",leftIcon:s.jsx(_.IconDeviceFloppy,{size:14}),onClick:u,disabled:r===t,children:"Confirm"})]})]})})]})}),mT={root:{flexGrow:1,width:"100%",minWidth:"1200px",overflow:"hidden"},panel:{width:"100%",minWidth:"1200px",height:"calc(100% - 44px)",padding:10,overflow:"auto"}},fi=({children:e})=>s.jsxs(a.Group,{noWrap:!0,grow:!0,position:"left",spacing:20,sx:{width:"100%",height:"100%",position:"relative"},children:[s.jsx(a.Box,{sx:{maxWidth:"calc(100% - 610px - 10px)",height:"100%",overflow:"auto"},children:e}),s.jsxs(a.Stack,{justify:"flex-start",sx:{alignSelf:"flex-start",width:"600px",flexGrow:0,flexShrink:0},children:[s.jsx(Zk,{}),s.jsx(a.Box,{sx:{flexGrow:1},children:s.jsx(uT,{})})]})]});function yT(e){return!["richText","button"].includes(e)}const bT=S.observer(({panel:e})=>{const t=Ae.useModals(),n=X(),r=K(),[i,o]=f.useState("Data"),l=e.queries,u=yT(e.viz.type)&&e.dataLoading,d=u||e.queryErrors.length>0||e.queryStateMessages!==""||l.length===0,p=n.editor.path[1];f.useEffect(()=>{o(m=>d&&m==="Visualization"?"Data":m)},[e.id,d]);const h=()=>{n.editor.setPath(["_VIEWS_",p])},x=()=>t.openConfirmModal({title:"Delete this panel?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.removePanelByID(e.id,p),h()},confirmProps:{color:"red"},zIndex:320});return s.jsxs(Ts,{value:{panel:e,data:e.data,loading:u,errors:e.queryErrors,downloadPanelScreenshot:()=>{}},children:[s.jsxs(a.Group,{px:16,position:"apart",sx:{borderBottom:"1px solid #eee"},children:[s.jsx(a.Text,{pt:9,pb:8,children:e.name}),s.jsxs(a.Group,{position:"right",noWrap:!0,children:[s.jsx(gT,{panel:e,sourceViewID:p}),s.jsx(a.Button,{size:"xs",variant:"subtle",color:"red",onClick:x,leftIcon:s.jsx(_.IconTrash,{size:14}),children:"Delete This Panel"})]})]}),s.jsxs(a.Tabs,{value:i,onTabChange:o,keepMounted:!1,styles:mT,children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"Data",disabled:u,children:"Data"}),s.jsx(a.Tabs.Tab,{value:"Panel",children:"Panel"}),s.jsx(a.Tabs.Tab,{value:"Variables",disabled:d,children:s.jsx(a.Tooltip,{label:"Requires data",disabled:!d,withinPortal:!0,zIndex:310,children:s.jsx(a.Text,{children:"Variables"})})}),s.jsx(a.Tabs.Tab,{value:"Visualization",disabled:d,children:s.jsx(a.Tooltip,{label:"Requires data",disabled:!d,withinPortal:!0,zIndex:310,children:s.jsx(a.Text,{children:"Visualization"})})}),s.jsx(a.Tabs.Tab,{value:"Interactions",children:"Interactions"})]}),s.jsxs(a.Tabs.Panel,{value:"Data",children:[s.jsx(a.LoadingOverlay,{visible:u,exitTransitionDuration:0}),s.jsx(Jk,{})]}),s.jsx(a.Tabs.Panel,{value:"Panel",children:s.jsx(fi,{children:s.jsx(Wk,{})})}),s.jsx(a.Tabs.Panel,{value:"Variables",children:s.jsx(fi,{children:s.jsx(cT,{})})}),s.jsx(a.Tabs.Panel,{value:"Visualization",children:s.jsx(we,{children:s.jsx(fi,{children:s.jsx(fT,{})})})}),s.jsx(a.Tabs.Panel,{value:"Interactions",children:s.jsx(we,{children:s.jsx(Vp,{})})})]})]})}),jT=S.observer(({viewID:e,panelID:t})=>{const n=K();if(!n.views.findByID(e))return s.jsxs(a.Text,{size:14,children:["View by ID[",e,"] is not found"]});const i=n.panels.findByID(t);return i?s.jsx(bT,{panel:i}):s.jsxs(a.Text,{size:14,children:["Panel by ID[",t,"] is not found"]})}),vT=S.observer(()=>{const[e,t]=f.useState([]),n=Ae.useModals(),r=X(),i=h=>{r.editor.setPath(["_QUERIES_",h])},o=()=>{n.openConfirmModal({title:"Delete ununsed queries?",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.removeUnusedQueries(),confirmProps:{color:"red"},zIndex:320})},l=()=>{r.content.queries.downloadSchema(e)},c=f.useMemo(()=>r.content.queries.sortedList.map(h=>h.id),[r.content.queries.sortedList]),u=()=>{t(c)},d=()=>{t([])},p=r.content.queriesUsage;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 Queries"})}),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(_.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(_.IconTrash,{size:14}),disabled:!r.content.hasUnusedQueries,onClick:o,children:"Delete unused queries"})]}),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:"Name"}),s.jsx("th",{style:{width:"200px"},children:"Data Source"}),s.jsx("th",{style:{width:"100px",textAlign:"right"},children:"Type"}),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.queries.sortedList.map(h=>{var m;const x=((m=p[h.id])==null?void 0:m.length)??0;return s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx(a.Checkbox,{value:h.id,styles:{input:{cursor:"pointer"}}})}),s.jsx("td",{children:h.name}),s.jsx("td",{children:h.key}),s.jsx("td",{style:{textAlign:"right"},children:h.type}),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.id),children:"Open"})})]},h.id)})})]})})})]})}),wT=e=>{const{queryModel:t}=e,n=X(),r=K(),o=r.findQueryUsage(t.id).length>0,l=Ae.useModals(),c=()=>{l.openConfirmModal({title:"Delete this query?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:()=>{r.queries.removeQuery(t.id),n.editor.setPath(["_QUERIES_",""])},confirmProps:{color:"red"},zIndex:320})};return o?s.jsx(a.Tooltip,{label:"Can't delete this query for it's being used, check out Usage tab for details",withArrow:!0,events:{hover:!0,focus:!1,touch:!1},withinPortal:!0,children:s.jsx(a.Button,{color:"gray",size:"xs",leftIcon:s.jsx(_.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})}):s.jsx(a.Button,{color:"red",size:"xs",onClick:c,leftIcon:s.jsx(_.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:"Delete this Query"})},CT=S.observer(wT),_c=({width:e="calc(100% - 32px)",lastWidth:t="50%",height:n,count:r,spacing:i=16,pl:o=0})=>s.jsxs(a.Stack,{spacing:i,mt:6,pl:o,children:[Array.from(new Array(r-1),(l,c)=>s.jsx(a.Skeleton,{width:e,height:n,radius:"xs"},c)),s.jsx(a.Skeleton,{width:t,height:n,radius:"xs"})]}),on=({value:e})=>e===null||e===""?null:s.jsx(a.Tooltip,{label:e,disabled:!e,multiline:!0,children:s.jsx(a.ActionIcon,{children:s.jsx(_.IconInfoCircle,{size:14})})}),ST=({column:e})=>{const{column_key:t,column_key_text:n}=e;return t?s.jsx(a.Tooltip,{label:n,disabled:!n,children:s.jsx(a.Badge,{children:t})}):null},_T=S.observer(({dataSource:e})=>{const{columns:t}=e;return t.loading?s.jsx(_c,{height:"24px",width:"100%",lastWidth:"100%",count:20,pl:6}):t.empty?null:s.jsxs(a.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"1000px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[s.jsxs("colgroup",{children:[s.jsx("col",{style:{width:50}}),s.jsx("col",{style:{minWidth:300}}),s.jsx("col",{style:{width:30}}),s.jsx("col",{style:{width:70}}),s.jsx("col",{style:{minWidth:300}}),s.jsx("col",{style:{minWidth:80,width:80}}),s.jsx("col",{style:{minWidth:120,width:120}})]}),s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"#"}),s.jsx("th",{children:"Column Name"}),s.jsx("th",{}),s.jsx("th",{}),s.jsx("th",{children:"Type"}),s.jsx("th",{children:"Nullable"}),s.jsx("th",{children:"Default Value"})]})}),s.jsx("tbody",{children:t.data.map(n=>s.jsxs("tr",{children:[s.jsx("td",{children:n.ordinal_position}),s.jsx("td",{children:n.column_name}),s.jsx("td",{children:s.jsx(on,{value:n.column_comment})}),s.jsx("td",{children:s.jsx(ST,{column:n})}),s.jsx("td",{children:n.column_type}),s.jsx("td",{children:n.is_nullable}),s.jsx("td",{children:s.jsx(on,{value:n.column_default})})]},n.column_name))})]})}),kT=S.observer(({dataSource:e})=>{const{indexes:t}=e,n=t.data;return s.jsxs(a.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"950px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[s.jsxs("colgroup",{children:[s.jsx("col",{style:{width:100}}),s.jsx("col",{style:{minWidth:300}}),s.jsx("col",{style:{width:150}}),s.jsx("col",{style:{width:150}}),s.jsx("col",{style:{width:250}})]}),s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Index Length"}),s.jsx("th",{children:"Index Name"}),s.jsx("th",{children:"Index Algorithm"}),s.jsx("th",{children:"Unique"}),s.jsx("th",{children:"Column Name"})]})}),s.jsx("tbody",{children:n.map(r=>s.jsxs("tr",{children:[s.jsx("td",{children:r.index_length}),s.jsx("td",{children:r.index_name}),s.jsx("td",{children:r.index_algorithm}),s.jsx("td",{children:r.is_unique?"YES":"NO"}),s.jsx("td",{children:r.column_name})]},r.index_name))})]})}),TT=S.observer(({dataSource:e})=>{const{indexes:t}=e,n=t.data;return s.jsxs(a.Table,{highlightOnHover:!0,fontSize:14,sx:{width:"auto",minWidth:"850px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[s.jsxs("colgroup",{children:[s.jsx("col",{style:{minWidth:300}}),s.jsx("col",{style:{width:150}}),s.jsx("col",{style:{width:100}}),s.jsx("col",{style:{width:100}}),s.jsx("col",{style:{width:100}}),s.jsx("col",{style:{width:100}})]}),s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Index Name"}),s.jsx("th",{children:"Index Algorithm"}),s.jsx("th",{children:"Unique"}),s.jsx("th",{children:"Definition"}),s.jsx("th",{children:"Condition"}),s.jsx("th",{children:"Comment"})]})}),s.jsx("tbody",{children:n.map(r=>s.jsxs("tr",{children:[s.jsx("td",{children:r.index_name}),s.jsx("td",{children:r.index_algorithm}),s.jsx("td",{children:r.is_unique?"YES":"NO"}),s.jsx("td",{children:s.jsx(on,{value:r.index_definition})}),s.jsx("td",{children:s.jsx(on,{value:r.condition})}),s.jsx("td",{children:s.jsx(on,{value:r.comment})})]},r.index_name))})]})}),DT=S.observer(({dataSource:e})=>{const{indexes:t}=e;return t.loading||t.empty?null:e.type===le.MySQL?s.jsx(kT,{dataSource:e}):e.type===le.Postgresql?s.jsx(TT,{dataSource:e}):null}),IT=S.observer(({dataSource:e})=>s.jsxs(a.Stack,{spacing:40,pt:10,sx:{flexGrow:1,overflow:"auto",position:"relative"},children:[s.jsx(we,{children:s.jsx(_T,{dataSource:e})}),s.jsx(we,{children:s.jsx(DT,{dataSource:e})})]}));function MT({table_type:e}){return e==="VIEW"?s.jsx(_.IconEye,{size:14}):e==="BASE TABLE"?s.jsx(_.IconTable,{size:14}):null}const zT=S.observer(({dataSource:e})=>{const{tables:t}=e;return t.loading?s.jsx(_c,{height:"24px",lastWidth:"50%",count:15}):s.jsx(a.Box,{h:"100%",sx:{overflow:"auto",".mantine-NavLink-label":{fontFamily:"monospace"}},children:Object.entries(t.data).map(([n,r])=>s.jsx(a.NavLink,{label:n,icon:s.jsx(_.IconDatabase,{size:14}),defaultOpened:e.table_schema===n,pl:0,childrenOffset:14,children:r.map(i=>s.jsx(a.NavLink,{label:i.table_name,icon:s.jsx(MT,{table_type:i.table_type}),onClick:()=>{e.setKeywords(n,i.table_name)},active:e.table_name===i.table_name},i.table_name))},n))})}),AT=({visible:e})=>s.jsx(a.Box,{py:10,sx:{width:"100%",height:"100%",overflow:"hidden",position:"relative"},children:s.jsx(a.LoadingOverlay,{visible:e})}),ET=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],PT={icon:{width:"50px",textAlign:"center"},input:{"&[data-with-icon]":{paddingLeft:"50px"}}},LT=S.observer(({dataSource:e})=>{const{tableData:t}=e;return s.jsxs(a.Group,{pt:10,px:10,position:"apart",children:[s.jsxs(a.Group,{position:"left",children:[t.maxPage>1&&s.jsx(a.Pagination,{size:"sm",value:t.page,onChange:t.setPage,total:t.maxPage,withEdges:t.maxPage>7,styles:{control:{height:"30px"}}}),s.jsx(a.Select,{icon:s.jsx(a.Text,{ta:"center",color:"dimmed",size:14,children:"Limit"}),size:"xs",styles:PT,data:ET,value:String(t.limit),onChange:n=>t.setLimit(Number(n))})]}),s.jsx(a.Group,{position:"right",children:s.jsxs(a.Text,{color:"dimmed",my:0,size:14,children:["Total ",t.total," rows"]})})]})}),OT=S.observer(({dataSource:e})=>{const t=e.tableData;return t.maxPage===0?s.jsx(a.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:"This table is empty"}):t.error?s.jsx(a.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:t.error}):t.page===1&&t.loading?s.jsx(AT,{visible:!0}):s.jsxs(we,{children:[s.jsx(LT,{dataSource:e}),s.jsxs(a.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[s.jsx(a.LoadingOverlay,{visible:t.loading,overlayBlur:2}),s.jsx(Cc,{data:t.data})]})]})}),BT={root:{flexGrow:1,overflow:"auto",borderLeft:"1px solid #efefef"},tabsList:{borderBottom:"1px solid #efefef"},tab:{minWidth:120}},$T=S.observer(({dataSource:e})=>(f.useEffect(()=>{e.loadTablesIfEmpty()},[e]),e.tables.error?s.jsx(a.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:e.tables.error}):s.jsxs(a.Flex,{sx:{height:"100%"},children:[s.jsx(a.Box,{w:300,sx:{flexGrow:0,flexShrink:0,position:"relative"},children:s.jsx(we,{children:s.jsx(zT,{dataSource:e})})}),s.jsxs(a.Tabs,{defaultValue:"structure",styles:BT,children:[s.jsxs(a.Tabs.List,{children:[s.jsx(a.Tabs.Tab,{value:"structure",icon:s.jsx(_.IconColumns,{size:14}),children:"Structure"}),s.jsx(a.Tabs.Tab,{value:"data",icon:s.jsx(_.IconDatabase,{size:14}),children:"Data"})]}),s.jsx(a.Tabs.Panel,{value:"structure",children:s.jsx(IT,{dataSource:e})}),s.jsx(a.Tabs.Panel,{value:"data",sx:{width:"100%",height:"calc(100% - 36px)",overflow:"hidden"},children:s.jsx(OT,{dataSource:e})})]})]}))),VT={modal:{paddingLeft:"0px !important",paddingRight:"0px !important"},header:{marginBottom:0,padding:"20px 20px 10px",borderBottom:"1px solid #efefef",gap:"20px"},title:{flexGrow:1},body:{padding:"0 0 0 20px"}},kc=S.observer(({dataSource:e,triggerButtonProps:t={}})=>{const[n,r]=f.useState(!1);return e.type==="http"?null:s.jsxs(s.Fragment,{children:[s.jsx(a.Modal,{opened:n,onClose:()=>r(!1),title:s.jsxs(a.Group,{position:"apart",sx:{flexGrow:1},children:[s.jsx(a.Text,{fw:500,children:"Explorer Data Source"}),s.jsxs(a.Group,{spacing:7,children:[s.jsx(a.Badge,{variant:"gradient",gradient:{from:"indigo",to:"cyan"},children:e.key}),s.jsx(a.Badge,{variant:"gradient",gradient:{from:"orange",to:"red"},children:e.type})]})]}),zIndex:320,size:"96vw",styles:VT,children:s.jsx(a.Box,{sx:{height:"calc(100vh - 220px)"},children:s.jsx($T,{dataSource:e})})}),s.jsx(a.Button,{variant:"subtle",onClick:()=>r(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},...t,children:"See Table Structure"})]})}),qT=f.forwardRef(({label:e,type:t,...n},r)=>t===le.Transform?s.jsxs(a.Group,{className:"transform-query-option",position:"left",ref:r,...n,sx:{'&[data-selected="true"]':{".mantine-Text-root":{color:"white"},svg:{stroke:"white"}}},children:[s.jsx(_.IconVectorTriangle,{size:14,color:"#228be6"}),s.jsx(a.Text,{color:"blue",children:e})]}):s.jsxs(a.Group,{position:"apart",ref:r,...n,children:[s.jsx(a.Text,{children:e}),s.jsx(a.Text,{children:t})]})),NT=S.observer(({value:e,onChange:t})=>{const n=X(),{data:r=[],loading:i}=V.useRequest(bs,{refreshDeps:[]},[]),o=f.useMemo(()=>{const d=r.map(p=>({label:p.key,value:p.key,type:p.type}));return d.push({label:"Use other queries' data",value:le.Transform,type:le.Transform}),d},[r]),l=f.useMemo(()=>o.reduce((d,p)=>(d[p.value]=p.type,d),{}),[o]),c=d=>{d!==null&&t({key:d,type:l[d]})},u=f.useMemo(()=>n.datasources.find(e),[n,e]);return s.jsx(a.Select,{data:o,label:s.jsxs(a.Group,{position:"apart",children:[s.jsx(a.Box,{children:"Data Source"}),u&&s.jsx(kc,{dataSource:u,triggerButtonProps:{compact:!0,size:"xs",px:10}})]}),itemComponent:qT,rightSection:u?s.jsx(a.Text,{size:"xs",color:"dimmed",children:u.type}):void 0,rightSectionWidth:85,maxDropdownHeight:500,styles:{root:{flex:1},label:{display:"block"},rightSection:{pointerEvents:"none",justifyContent:"flex-end",paddingRight:"10px",".mantine-Text-root":{userSelect:"none"}}},disabled:i,value:e.key,onChange:c})}),Tc=f.forwardRef((e,t)=>{const{label:n,description:r,...i}=e;return s.jsx("div",{ref:t,...i,children:s.jsxs(a.Group,{position:"apart",noWrap:!0,children:[s.jsx(a.Text,{children:n}),s.jsx(a.Text,{size:"xs",color:"dimmed",children:r})]})})}),FT=S.observer(({queryModel:e})=>{const[t,n]=f.useState(e.name);return f.useEffect(()=>{n(e.name)},[e.name]),s.jsx(a.Center,{ml:20,mt:20,sx:{maxWidth:"600px"},children:s.jsxs(a.Stack,{spacing:10,sx:{width:"100%"},children:[s.jsx(a.Divider,{mb:-10,variant:"dashed",label:"Basics",labelPosition:"center"}),s.jsx(a.TextInput,{placeholder:"A unique name",label:"Name",required:!0,sx:{flex:1},value:t,onChange:r=>{n(r.currentTarget.value)},rightSection:s.jsx(a.ActionIcon,{variant:"filled",color:"blue",size:"sm",onClick:()=>e.setName(t),disabled:t===e.name,children:s.jsx(_.IconDeviceFloppy,{size:16})}),onBlur:()=>{e.setName(t)}}),s.jsx(NT,{value:{type:e.type,key:e.key},onChange:({type:r,key:i})=>{e.setKey(i),e.setType(r)}}),s.jsx(a.Divider,{mt:10,mb:-10,variant:"dashed",label:"Conditions",labelPosition:"center"}),s.jsx(a.MultiSelect,{label:"Run query when these are truthy",placeholder:"Always run this query on load",data:e.conditionOptions,value:[...e.run_by],onChange:e.setRunBy,itemComponent:Tc,maxDropdownHeight:500}),e.typedAsHTTP&&s.jsx(a.MultiSelect,{label:"Re-run query when these changed",placeholder:"Leave it empty to never re-run this query",data:e.conditionOptions,value:[...e.react_to],onChange:e.setReactTo,itemComponent:Tc,maxDropdownHeight:500}),s.jsx(a.Divider,{mt:20,mb:10,variant:"dashed"}),s.jsx(CT,{queryModel:e})]})})});function GT({content:e}){return s.jsxs(a.HoverCard,{width:"60vw",shadow:"md",children:[s.jsx(a.HoverCard.Target,{children:s.jsx(a.ActionIcon,{size:16,color:"blue",children:s.jsx(_.IconEye,{})})}),s.jsx(a.HoverCard.Dropdown,{children:s.jsx(dt.Prism,{language:"sql",noCopy:!0,withLineNumbers:!0,children:e})})]})}const WT=S.observer(()=>{const t=[...X().globalSQLSnippets.list];return t.length===0?null:s.jsxs(a.Table,{horizontalSpacing:"xs",verticalSpacing:"xs",fontSize:"sm",highlightOnHover:!0,children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Key"}),s.jsx("th",{children:"Value"})]})}),s.jsx("tbody",{children:t.map(n=>{const{id:r,content:i}=n;return s.jsxs("tr",{children:[s.jsx("td",{children:r}),s.jsx("td",{width:200,children:s.jsx(GT,{content:i})})]},r)})})]})}),RT=`
|
|
466
466
|
-- You may reference query variables in SQL or VizConfig.
|
|
467
467
|
SELECT *
|
|
468
468
|
FROM commit
|