@devtable/dashboard 13.3.0 → 13.4.1

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.
@@ -53,7 +53,7 @@ Check the top-level render call using <`+A+">.")}return z}}function mu(w,z){{if(
53
53
  </table>
54
54
  `;function ws(t,e){const n=Object.keys(e),r=Object.values(e);try{return new Function(...n,`return \`${t}\`;`)(...r)}catch(i){throw n.length===0&&t.includes("$")?new Error("[formatSQL] insufficient payload"):i}}function Cs(t,e){try{return ws(t,e)}catch(n){return console.error(n),n.message}}function hd({sql:t,pre_process:e}){if(!e.trim())return t;try{return new Function(`return ${e}`)()({sql:t},ct)}catch(n){return console.error(n),t}}function md(t,e,n){if(!t.trim())return e;try{return new Function(`return ${t}`)()(e,ct,n)}catch(r){return console.error(r),e}}function fd(t){t=t||{};const e=Object.keys(t).sort(),n=[];for(let r=0;r<e.length;r++){const i=e[r];if(i!="authentication"&&t[i])n.push(e[r]+"="+(typeof t[i]=="object"?JSON.stringify(t[i]):t[i]));else{const a=Object.keys(t[i]).sort();for(let l=0;l<a.length;l++){const c=a[l];c!="sign"&&t[i][c]&&n.push(a[l]+"="+(typeof t[i][c]=="object"?JSON.stringify(t[i][c]):t[i][c]))}}}return n.sort().join("&")}function gd(t,e){let n=fd(t);return n+="&key="+e,ad.MD5(n).toString().toUpperCase()}class da{constructor(){this.type="default_api_client",this.baseURL="http://localhost:31200",this.app_id="",this.app_secret=""}getAuthentication(e){if(!this.app_id||!this.app_secret)return;const n=new Date().getTime().toString();return{app_id:this.app_id,nonce_str:n,sign:gd({app_id:this.app_id,nonce_str:n,...e},this.app_secret)}}getRequest(e,n){return(r,i,a,l)=>{const c=this.buildHeader(a),u=this.buildAxiosConfig(e,r,i,a,c,n);return at(u).then(d=>l?d:d.data).catch(d=>{const p=x.get(d,"response.data.detail.message",d.message);return Promise.reject(new Error(p))})}}get(e){return this.getRequest("GET",e)}post(e){return this.getRequest("POST",e)}put(e){return this.getRequest("PUT",e)}buildAxiosConfig(e,n,r,i,a,l){const c={baseURL:this.baseURL,method:e,url:n,params:e==="GET"?r:i.params,headers:a,signal:l};return["POST","PUT"].includes(e)&&(c.data=i.string?JSON.stringify(r):r,c.data.authentication=this.getAuthentication(c.data)),c}buildHeader(e){const n=window.localStorage.getItem("token");return{"X-Requested-With":"XMLHttpRequest","Content-Type":e.string?"application/x-www-form-urlencoded":"application/json",authorization:n?`bearer ${n}`:"",...e.headers}}}class xd{constructor(e){this.implementation=e}getRequest(e,n){return this.implementation.getRequest(e,n)}get(e){return this.getRequest("GET",e)}post(e){return this.getRequest("POST",e)}put(e){return this.getRequest("PUT",e)}}class pa extends da{constructor(){super(...arguments);$(this,"makeQueryENV",null)}query(n){return async(r,i={})=>{var a;return r.env||(r.env=((a=this.makeQueryENV)==null?void 0:a.call(this))??{error:"failed to run makeQueryENV"}),this.post(n)("/query",r,i)}}httpDataSourceQuery(n){return async(r,i={})=>{var a;return r.env||(r.env=((a=this.makeQueryENV)==null?void 0:a.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 ha{constructor(e){this.implementation=e}query(e){return this.implementation.query(e)}httpDataSourceQuery(e){return this.implementation.httpDataSourceQuery(e)}structure(e){return this.implementation.structure(e)}getRequest(e,n){return this.implementation.getRequest(e,n)}get(e){return this.getRequest("GET",e)}post(e){return this.getRequest("POST",e)}put(e){return this.getRequest("PUT",e)}}const Lt=new pa;function Ss(t){Lt.baseURL!==t.apiBaseURL&&(Lt.baseURL=t.apiBaseURL),t.app_id&&(Lt.app_id=t.app_id),t.app_secret&&(Lt.app_secret=t.app_secret),t.makeQueryENV&&(Lt.makeQueryENV=t.makeQueryENV)}const ma=new ha(Lt),et=ma,rn=m.forwardRef(function({value:e,onChange:n,...r},i){return s.jsx(o.TextInput,{ref:i,value:e,onChange:n,...r})});function E(t){const[e,n]=t.split(".");return{queryID:e,columnKey:n}}function yd(t){return t.includes(".")?E(t):{queryID:"",columnKey:t}}function tt(t,e){var i;const{queryID:n,columnKey:r}=E(e);return n?r?((i=t[n])==null?void 0:i.map(a=>a[r]))??[]:t[n]:[]}function kn(t,e){const{queryID:n}=E(e);return n?t[n]:[]}function bd(t){return Object.values(t)[0]}function Tn(t,e){const{queryID:n,columnKey:r}=E(e);return t[r]}const fa=["function aggregation({ queryData }, utils) {",' return "Aggregation Result";',"}"].join(`
55
55
  `),Ot={type:"none",config:{},fallback:"0"};function vd(t){const e=Array.from(t).sort((r,i)=>r-i),n=Math.floor(e.length/2);return e.length%2===0?(e[n-1]+e[n])/2:e[n]}function _d(t,e){switch(e.type){case"sum":return x.sum(t);case"mean":return x.mean(t);case"median":return vd(t);case"max":return x.max(t);case"min":return x.min(t);case"quantile":return en.quantile(t,e.config.p);case"CV":const n=qt.std(...t),r=qt.mean(...t);return r?n/r:Number.NaN;case"std":return qt.std(...t);default:return t}}function ks(t,e){const n=t.map(Number),r=_d(n,e);return typeof r=="number"?Number.isFinite(r)?r:e.fallback:r??e.fallback}function jd(t,e,n){try{const r=kn(t,e);return new Function(`return ${n.config.func}`)()({queryData:r},ct)}catch(r){return console.error(r),r.message}}function Dn(t,e,n){try{return n.type==="custom"?jd(t,e,n):ks(tt(t,e),n)}catch(r){return console.error(r),null}}class wd{constructor({valueRange:e,colorRange:n}){$(this,"mapper");this.mapper=St.interpolate(e,n)}getColor(e){return this.mapper(e)}}const be={mantissa:0,output:"number",trimMantissa:!1,average:!1,absolute:!1};function R(t,{absolute:e,...n}){if(t===null)return String(t);try{let r=wn(t).value();if(r===void 0||Number.isNaN(r))throw new Error(`[formatNumber]Not a number: ${t}`);return e&&(r=Math.abs(r)),wn(r).format(n)}catch(r){return console.debug(r),String(t)}}function Cd(t){return t===null?"null":t===void 0?"undefined":Array.isArray(t)?`Array(${t.length})`:t.toString()}function ut({data_field:t,aggregation:e},n){return Dn(n,t,e)}function Oe({formatter:t,aggregation:e},n){if(typeof n!="string"&&typeof n!="number")return Cd(n);if(e.type==="custom")return n;try{return R(n,t)}catch(r){return console.error(r),n}}function Sd(t,e){if(t.type==="static")return t.staticColor;if(t.type==="continuous")try{if(typeof e!="number")throw new Error(`[getColorByColorConf] Invalid type of aggregated value: ${e}`);return new wd(t).getColor(e)}catch(n){return console.error(n),"black"}return"black"}function kd(t,e){const{color:n,data_field:r,aggregation:i,size:a,weight:l}=t,c=Dn(e,r,i),u=Oe(t,c);return s.jsx(o.Text,{sx:{fontSize:a,display:"inline"},color:Sd(n,c),weight:l,children:u})}function Td(t,e){const n={};return t.forEach(r=>{const i=r.name;n[i]=kd(r,e)}),n}function Dd(t){return t.split(" ").map((e,n)=>s.jsxs(m.Fragment,{children:[e," "]},n))}function zd(t){const n=t.replaceAll("<br />","<br/>").replaceAll(`
56
- `,"<br/>").split("<br/>");return n.map((i,a)=>{const l=[Dd(i)];return a!==n.length-1&&l.push(s.jsx("br",{},`br-${a}`)),l}).flat().filter(i=>i!==void 0)}function Ts(t){return zd(t)}function an(t,e,n){const r=Td(e,n),i=/^\{(.+)\}(.*)$/;return t.split("$").map((a,l)=>{const c=i.exec(a);if(!c)return Ts(a);const u=r[c[1]];if(!u)return Ts(a);const d=c[2]??"";return s.jsxs(m.Fragment,{children:[u,Ts(d)]},`${a}-${l}`)})}function Md(t,e){const{data_field:n,aggregation:r}=t,i=Dn(e,n,r);return Oe(t,i)}function ga(t,e){const n={};return t.forEach(r=>{n[r.name]=Md(r,e)}),n}function zn(t,e,n){const r=ga(e,n),i=/^\{(.+)\}(.*)$/;return t.split("$").map(a=>{const l=i.exec(a);if(!l)return a;const c=r[l[1]];if(!c)return a;const u=l[2]??"";return`${c}${u}`}).join("")}const kt={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 Id(){je.registerTheme("merico-light",{color:Object.values(kt.graphics.multiple),visualMap:{color:Object.values(kt.graphics.depth).reverse()},axes:[{type:"all",name:"通用坐标轴",axisLineColor:"#97999D",axisTickColor:"#97999D",axisLabelShow:!0,axisLabelColor:"#818388",splitLineShow:!0,splitLineColor:["#E0E6F1"]}]})}function xa(){Id()}function*Ed(t){const e=kt.graphics[t];if(!e)throw new Error("Invalid palette key provided");const n=Object.values(e);let r=0;for(;;)yield n[r%n.length],r++}function ya(){return{filters:{},context:{}}}function Ds(t){const e=ya();if(!t)return ya();const{filters:n=e.filters,context:r=e.context}=t;return{filters:n,context:r}}class we extends m.Component{constructor(e){super(e),this.state={error:null}}componentDidCatch(e){this.setState({error:e})}render(){var e;if(this.state.error){const n=()=>{this.setState({error:null})};return s.jsxs(o.Box,{children:[s.jsx(o.Text,{size:"xs",children:(e=this.state.error)==null?void 0:e.message}),s.jsx(o.Button,{variant:"subtle",size:"xs",mx:"auto",compact:!0,sx:{display:"block"},onClick:n,children:"Retry"})]})}return this.props.children}}function Ad(t,e={handleError:!0}){return n=>s.jsx(we,{...e,children:s.jsx(t,{...n})})}function Pd(t,e){return new Function(`return ${t}`)()(e,ct)}function $d(t,e,n){return Pd(t,{context:e,filters:n})}function Bd(t,e){try{return new Function(`return ${t.config.processing.pre}`)()(e,ct)}catch(n){return console.error(n),e}}function qd(t,e){return new Function(`return ${t.config.processing.post}`)()(e,ct)}function Ld(t,e,n){return t?new Function(`return ${t}`)()(e,ct,n):e}function ba(){Ni.use([vu.CanvasRenderer,He.BarChart,He.BoxplotChart,He.CustomChart,He.FunnelChart,He.HeatmapChart,He.LineChart,He.PieChart,He.RadarChart,He.ScatterChart,He.SunburstChart,yt.CalendarComponent,yt.DataZoomComponent,yt.GridComponent,yt.LegendComponent,yt.TooltipComponent,yt.MarkLineComponent,yt.MarkAreaComponent,yt.VisualMapComponent])}const Vt=t=>x.cloneDeepWith(t,(e,n)=>{if(n!==void 0&&e)return K.toJS(e)}),Mn={sqlSnippet:new RegExp("(?<=sql_snippets\\.)([^\\?}.]+)","gm"),context:new RegExp("(?<=context\\.)([^\\?}.]+)","gm"),filter:new RegExp("(?<=filters\\.)([^\\?}.]+)","gm")};function Od(t,e){const n=Gi.decode(e);n!==t&&(console.error("Inconsistent sql"),console.groupCollapsed("Inconsistent sql"),console.table({before:t,after:e,v:n}),console.groupEnd())}async function Vd({query:t,name:e,payload:n,additionals:r},i){if(!t.sql)return[];const{type:a,key:l,sql:c,pre_process:u,post_process:d}=t,p=ws(c,n),h=hd({sql:p,pre_process:u}),g=Gi.encode(h);Od(h,g);let y=await et.query(i)({type:a,key:l,query:g,...r},{params:{name:e}});return y=md(d,y,Ds(n)),y}async function Nd({type:t,key:e,configString:n,name:r,additionals:i},a){try{return await et.httpDataSourceQuery(a)({type:t,key:e,query:n,...i},{params:{name:r}})}catch(l){if(at.isCancel(l))throw l;return console.error(l),l}}async function zs(){try{return(await et.post()("/datasource/list",{filter:{},sort:[{field:"create_time",order:"ASC"}],pagination:{page:1,pagesize:100}},{})).data}catch(t){return console.error(t),[]}}async function va(){try{return(await et.post()("/sql_snippet/list",{filter:{},sort:[{field:"id",order:"ASC"}],pagination:{page:1,pagesize:1e3}},{})).data}catch(t){return console.error(t),[]}}class _a{constructor(e){$(this,"rootRef");this.rootRef=K.observable({current:e})}async deleteItem(e){K.runInAction(()=>{x.unset(this.rootRef.current,[e])})}getItem(e){const n=this.getValueFromRoot(e);return Promise.resolve(n)}getValueFromRoot(e){return e===null?K.toJS(this.rootRef.current):x.get(this.rootRef.current,[e])}setItem(e,n){if(e===null)if(x.isObject(n))K.runInAction(()=>{this.rootRef.current=n});else throw new Error("Cannot set root value to non-object");else K.runInAction(()=>{x.set(this.rootRef.current,[e],n)});return Promise.resolve(this.getItem(e))}watchItem(e,n,r){return K.reaction(()=>this.getValueFromRoot(e),(i,a)=>{n(i,a)},{requiresObservable:!0,fireImmediately:x.get(r,"fireImmediately",!1)})}}class Gd{constructor(){$(this,"channels",new Map);$(this,"globalChannel",new Fi)}getChannel(e){const n=this.channels.get(e);if(n)return n;const r=new Fi;return this.channels.set(e,r),r}}class Fd{constructor(e){$(this,"instances",new Map);this.pluginManager=e}get availableVizList(){return this.pluginManager.installedPlugins.flatMap(e=>e.manifest.viz)}resolveComponent(e){return this.pluginManager.factory.viz(e)}getOrCreateInstance(e){const n=this.instances.get(e.id);if(n)return n;const r={id:e.id,name:e.viz.type,type:e.viz.type,messageChannels:new Gd,instanceData:new _a(e.viz.conf)};return this.instances.set(e.id,r),r}}function ja(t,e,n,r){return{vizManager:n,locale:"zh",msgChannels:t.messageChannels,instanceData:t.instanceData,pluginData:new _a({}),colorPalette:{getColor(){return()=>""}},data:e,variables:r}}const Wd=t=>{const{panel:e,measure:n,vizManager:r,data:i,variables:a}=t,l=r.resolveComponent(e.viz.type),c=r.getOrCreateInstance(e),u={...ja(c,i,r,a),viewport:{width:n.w,height:n.h}},d=l.viewRender;return s.jsx(d,{context:u,instance:c,...x.omit(t,["panel","vizManager","data"])})},Qd=t=>{const{vizManager:e,panel:n,data:r,variables:i}=t,a=e.resolveComponent(n.viz.type),l=e.getOrCreateInstance(n),c={...ja(l,r,e,i)},u=a.configRender;return s.jsx(u,{context:c,instance:l,...x.omit(t,["panel","vizManager","data"])})},wa=(t,e)=>{const n=ot.bezier(t),r=ot.bezier(e);return function(i){return i<50?n(i*2/100).hex():r((i-50)*2/100).hex()}},In=t=>{const e=ot.bezier(t);return function(n){return e(n/100).hex()}},Rd={type:"interpolation",displayName:"style.color.interpolation.palette.red_green",getColor:wa(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},Ud={type:"interpolation",displayName:"style.color.interpolation.palette.yellow_blue",getColor:wa(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},Yd={type:"interpolation",displayName:"style.color.interpolation.palette.red",getColor:In(["#fff7f1","darkred"]),name:"red",category:"sequential"},Kd={type:"interpolation",displayName:"style.color.interpolation.palette.green",getColor:In(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},Jd={type:"interpolation",displayName:"style.color.interpolation.palette.blue",getColor:In(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},Xd={type:"interpolation",displayName:"style.color.interpolation.palette.orange",getColor:In(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class Zd{constructor(e){$(this,"symbol");this.symbol=Symbol(e)}}function dt(t){return new Zd(t)}class Ms{constructor(){$(this,"parent");$(this,"factoryRegistry",new Map);$(this,"instanceRegistry",new Map)}createScoped(){const e=new Ms;return e.parent=this,e}getRequired(e){return this.get(e)}get(e){if(this.instanceRegistry.has(e.symbol))return this.instanceRegistry.get(e.symbol);const n=this.factoryRegistry.get(e.symbol);if(n){const r=n(this);return this.instanceRegistry.set(e.symbol,r),r}if(this.parent)return this.parent.get(e)}provideFactory(e,n){return this.factoryRegistry.has(e.symbol)?console.warn(`Token ${e.symbol.toString()} is already registered`):this.factoryRegistry.set(e.symbol,n),this}provideValue(e,n){return this.factoryRegistry.has(e.symbol)?console.warn(`Token ${e.symbol.toString()} is already registered`):this.factoryRegistry.set(e.symbol,()=>n),this}dispose(){this.instanceRegistry.forEach(e=>{const n=x.get(e,"dispose");x.isFunction(n)&&n.bind(e)()}),this.instanceRegistry.clear(),this.factoryRegistry.clear()}}const Ca="13.3.0",Hd=Object.freeze(Object.defineProperty({__proto__:null,version:Ca},Symbol.toStringTag,{value:"Module"}));class ep{constructor(e){$(this,"staticColors",new Map);$(this,"interpolations",new Map);e.installedPlugins.forEach(n=>{n.manifest.color.forEach(r=>{this.register(r)})})}getStaticColors(){return Array.from(this.staticColors.values())}register(e){const n=this.encodeColor(e);e.type==="single"?(this.staticColors.has(n)&&console.warn(`the color '${e.name}' has been registered under '${e.category}', previous registered value will be overridden`),this.staticColors.set(n,e)):e.type==="interpolation"&&(this.interpolations.has(n)&&console.warn(`the interpolation '${e.name}' has been registered under '${e.category}', previous registered value will be overridden`,`the interpolation '${e.name}' has been registered under '${e.category}', previous registered value will be overridden`),this.interpolations.set(n,e))}decodeStaticColor(e){return this.staticColors.get(e)}encodeColor(e){return`\${${e.category}}.{${e.name}}`}decodeInterpolation(e){return this.interpolations.get(e)}getColorInterpolations(){return Array.from(this.interpolations.values())}}class tp{constructor(){$(this,"plugins",new Map);$(this,"vizComponents",new Map);$(this,"factory",{viz:e=>{const n=this.vizComponents.get(e);if(n)return n;throw new Error(`Viz Component (${e}) not found`)}})}install(e){if(this.plugins.has(e.id))throw new Error(`Plugin (${e.id}) has been installed before`);this.plugins.set(e.id,e);for(const n of e.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 np{constructor(){$(this,"migrations",[])}version(e,n){return this.migrations.push({version:e,handler:n}),this}run(e,n,r){var l;if(e.from===e.to)return n;if(e.from>e.to)throw new Error(`Can not downgrade from version '${e.from}' to (${e.to})`);const i=this.migrations.filter(c=>c.version>e.from&&c.version<=e.to),a=x.orderBy(i,"version","asc");if(((l=x.last(a))==null?void 0:l.version)!==e.to)throw new Error(`Migration to version ${e.to} not found`);return a.reduce((c,u)=>u.handler(c,r),n)}}class oe extends np{constructor(){super(),this.configVersions()}version(e,n){return super.version(e,(r,i)=>({version:e,...n(r,i)}))}async migrate({configData:e,panelModel:n}){const r=await e.getItem(null),i=x.get(r,"version",0),a=this.run({from:i,to:this.VERSION},r,{panelModel:n});await e.setItem(null,a)}async needMigration({configData:e}){const n=await e.getItem(null);return x.get(n,"version",0)<this.VERSION}}const O=(t,e)=>{const[n,{setFalse:r}]=N.useBoolean(!0),[i,a]=m.useState();m.useEffect(()=>(t.getItem(e).then(c=>{a(c),r()}),t.watchItem(e,c=>{a(c)})));const l=m.useCallback(async c=>{await t.setItem(e,c),a(c)},[t,e]);return{loading:n,value:i,set:l}},ze={top:16,right:16,bottom:16,left:16},Ye=t=>Math.max(0,t-ze.left-ze.right),Ke=t=>Math.max(0,t-ze.top-ze.bottom),on=(t,e)=>({width:Ye(t),height:Ke(e)}),Me=({width:t,height:e,children:n})=>s.jsx(o.Box,{pt:ze.top,pr:ze.right,pb:ze.bottom,pl:ze.left,sx:{width:t,height:e,overflow:"hidden",position:"relative"},children:n}),Is={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"}};function sp({context:t}){const{value:e}=O(t.instanceData,"config"),n=t.data,{width:r,height:i}=t.viewport,{x_axis_data_key:a,y_axis_data_key:l,z_axis_data_key:c,xAxis3D:u,yAxis3D:d,zAxis3D:p}=x.defaults({},e,Is),h=m.useMemo(()=>kn(n,a),[n,a]),{x:g,y,z:v}=m.useMemo(()=>({x:E(a),y:E(l),z:E(c)}),[a,l,c]),{min:C,max:T}=m.useMemo(()=>{const I=x.minBy(h,W=>W[v.columnKey]),P=x.maxBy(h,W=>W[v.columnKey]);return{min:x.get(I,v.columnKey),max:x.get(P,v.columnKey)}},[h,v]),D={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(I=>[I[g.columnKey],I[y.columnKey],I[v.columnKey]])}]};return e?s.jsx(Me,{width:r,height:i,children:s.jsx(ke,{echarts:je,option:D,style:on(r,i),notMerge:!0,theme:"merico-light"})}):null}const Sa=m.createContext(null),Es=Sa.Provider;function As(){const t=m.useContext(Sa);if(!t)throw new Error("Please use DashboardModelContextProvider");return t}const H=()=>As(),ka=()=>As(),Ta=m.createContext({searchButtonProps:{}}),Ps=Ta.Provider;function Da(){return m.useContext(Ta)}const za=m.createContext(null),$s=za.Provider;function Ma(){const t=m.useContext(za);if(!t)throw new Error("Please use ContentModelContextProvider");return t}const U=()=>Ma(),de=()=>Ma(),rp={inEditMode:!1},En=m.createContext(rp),Ia=m.createContext({panel:null,data:{},loading:!1,errors:[],downloadPanelScreenshot:()=>{}}),Bs=Ia.Provider;function Ea(){const t=m.useContext(Ia);if(!t.panel)throw new Error("Please use PanelContextProvider");return t}const pt=()=>Ea(),$e=()=>Ea(),ip={fullScreenPanelID:"",setFullScreenPanelID:x.noop},qs=m.createContext(ip);function Aa(){const t=m.useContext(qs);if(!t)throw new Error("Please use FullScreenPanelContext.Provider");return t}const ap={en:"en",zh:"zh-cn"};function Ls({children:t}){const{i18n:e}=_.useTranslation(),n=m.useMemo(()=>{const r=e.language;return ap[r]??"en"},[e.language]);return s.jsx(Wi.DatesProvider,{settings:{locale:n,firstDayOfWeek:1},children:t})}const L=S.observer(m.forwardRef(({label:t,required:e,description:n,value:r,onChange:i,queryID:a,clearable:l=!1,sx:c,...u},d)=>{const{panel:p}=$e(),h=m.useMemo(()=>p.dataFieldOptions(r,l,a),[r,l,a]);if(h.length===0){const g=p.explainDataKey(r);return s.jsxs(o.HoverCard,{shadow:"md",position:"bottom-start",withinPortal:!0,zIndex:320,children:[s.jsx(o.HoverCard.Target,{children:s.jsx(o.Box,{children:s.jsx(o.TextInput,{label:t,required:e,defaultValue:g.columnKey,readOnly:!0,disabled:!0})})}),s.jsx(o.HoverCard.Dropdown,{children:s.jsxs(o.Group,{position:"left",spacing:0,children:[s.jsx(o.Text,{size:"xs",color:g.queryName?"black":"red",sx:{fontFamily:"monospace"},children:g.queryName??g.queryID}),s.jsx(o.Text,{size:"xs",color:"black",sx:{fontFamily:"monospace"},children:"."}),s.jsx(o.Text,{size:"xs",color:"red",sx:{fontFamily:"monospace"},children:g.columnKey})]})})]})}return s.jsx(o.Select,{ref:d,label:t,description:n,data:h,value:r,onChange:i,required:e,sx:c,maxDropdownHeight:500,...u})}));function op({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),r=x.defaults({},e,Is),{control:i,handleSubmit:a,reset:l}=b.useForm({defaultValues:r});return m.useEffect(()=>{l(r)},[e]),e?s.jsx(o.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:a(n),children:[s.jsx(o.Text,{children:"X Axis"}),s.jsxs(o.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(L,{label:"Data Field",required:!0,...c})}),s.jsx(b.Controller,{name:"xAxis3D.name",control:i,render:({field:c})=>s.jsx(o.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...c})})]}),s.jsx(o.Text,{mt:"lg",children:"Y Axis"}),s.jsxs(o.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(L,{label:"Data Field",required:!0,...c})}),s.jsx(b.Controller,{name:"yAxis3D.name",control:i,render:({field:c})=>s.jsx(o.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...c})})]}),s.jsx(o.Text,{mt:"lg",children:"Z Axis"}),s.jsxs(o.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(L,{label:"Data Field",required:!0,...c})}),s.jsx(b.Controller,{name:"zAxis3D.name",control:i,render:({field:c})=>s.jsx(o.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...c})})]}),s.jsx(o.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:s.jsxs(o.Button,{color:"blue",type:"submit",children:[s.jsx(B.DeviceFloppy,{size:20}),s.jsx(o.Text,{ml:"md",children:"Save"})]})})]})}):null}const lp=[{lang:"en",resources:{bar_chart_3d:{viz_name:"Bar Chart(3D)"}}},{lang:"zh",resources:{bar_chart_3d:{viz_name:"柱图(3D)"}}}];function cp(t,{panelModel:e}){try{const n=e.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:a,z_axis_data_key:l,...c}=t;return{...c,x_axis_data_key:r(i),y_axis_data_key:r(a),z_axis_data_key:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class up extends oe{constructor(){super(...arguments);$(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:cp(i,r)}})}}const dp={displayName:"viz.bar_chart_3d.viz_name",displayGroup:"chart.groups.echarts_based_charts",migrator:new up,name:"bar-3d",viewRender:sp,configRender:op,createConfig(){return{version:2,config:x.cloneDeep(Is)}},translation:lp},pp=({disabled:t,value:e,onChange:n})=>{const r=i=>{i&&n(i)};return s.jsxs(o.Box,{sx:{position:"relative"},children:[t&&s.jsx(o.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),s.jsx(Pe,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})};function Ie({enabled:t,func_content:e}){return(n,r)=>{if(!t)return n;try{return new Function(`return ${e}`)()(n,r)}catch(i){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${i.message}`),n}}}function Ce(){return{enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
56
+ `,"<br/>").split("<br/>");return n.map((i,a)=>{const l=[Dd(i)];return a!==n.length-1&&l.push(s.jsx("br",{},`br-${a}`)),l}).flat().filter(i=>i!==void 0)}function Ts(t){return zd(t)}function an(t,e,n){const r=Td(e,n),i=/^\{(.+)\}(.*)$/;return t.split("$").map((a,l)=>{const c=i.exec(a);if(!c)return Ts(a);const u=r[c[1]];if(!u)return Ts(a);const d=c[2]??"";return s.jsxs(m.Fragment,{children:[u,Ts(d)]},`${a}-${l}`)})}function Md(t,e){const{data_field:n,aggregation:r}=t,i=Dn(e,n,r);return Oe(t,i)}function ga(t,e){const n={};return t.forEach(r=>{n[r.name]=Md(r,e)}),n}function zn(t,e,n){const r=ga(e,n),i=/^\{(.+)\}(.*)$/;return t.split("$").map(a=>{const l=i.exec(a);if(!l)return a;const c=r[l[1]];if(!c)return a;const u=l[2]??"";return`${c}${u}`}).join("")}const kt={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 Id(){je.registerTheme("merico-light",{color:Object.values(kt.graphics.multiple),visualMap:{color:Object.values(kt.graphics.depth).reverse()},axes:[{type:"all",name:"通用坐标轴",axisLineColor:"#97999D",axisTickColor:"#97999D",axisLabelShow:!0,axisLabelColor:"#818388",splitLineShow:!0,splitLineColor:["#E0E6F1"]}]})}function xa(){Id()}function*Ed(t){const e=kt.graphics[t];if(!e)throw new Error("Invalid palette key provided");const n=Object.values(e);let r=0;for(;;)yield n[r%n.length],r++}function ya(){return{filters:{},context:{}}}function Ds(t){const e=ya();if(!t)return ya();const{filters:n=e.filters,context:r=e.context}=t;return{filters:n,context:r}}class we extends m.Component{constructor(e){super(e),this.state={error:null}}componentDidCatch(e){this.setState({error:e})}render(){var e;if(this.state.error){const n=()=>{this.setState({error:null})};return s.jsxs(o.Box,{children:[s.jsx(o.Text,{size:"xs",children:(e=this.state.error)==null?void 0:e.message}),s.jsx(o.Button,{variant:"subtle",size:"xs",mx:"auto",compact:!0,sx:{display:"block"},onClick:n,children:"Retry"})]})}return this.props.children}}function Ad(t,e={handleError:!0}){return n=>s.jsx(we,{...e,children:s.jsx(t,{...n})})}function Pd(t,e){return new Function(`return ${t}`)()(e,ct)}function $d(t,e,n){return Pd(t,{context:e,filters:n})}function Bd(t,e){try{return new Function(`return ${t.config.processing.pre}`)()(e,ct)}catch(n){return console.error(n),e}}function qd(t,e){return new Function(`return ${t.config.processing.post}`)()(e,ct)}function Ld(t,e,n){return t?new Function(`return ${t}`)()(e,ct,n):e}function ba(){Ni.use([vu.CanvasRenderer,He.BarChart,He.BoxplotChart,He.CustomChart,He.FunnelChart,He.HeatmapChart,He.LineChart,He.PieChart,He.RadarChart,He.ScatterChart,He.SunburstChart,yt.CalendarComponent,yt.DataZoomComponent,yt.GridComponent,yt.LegendComponent,yt.TooltipComponent,yt.MarkLineComponent,yt.MarkAreaComponent,yt.VisualMapComponent])}const Vt=t=>x.cloneDeepWith(t,(e,n)=>{if(n!==void 0&&e)return K.toJS(e)}),Mn={sqlSnippet:new RegExp("(?<=sql_snippets\\.)([^\\?}.]+)","gm"),context:new RegExp("(?<=context\\.)([^\\?}.]+)","gm"),filter:new RegExp("(?<=filters\\.)([^\\?}.]+)","gm")};function Od(t,e){const n=Gi.decode(e);n!==t&&(console.error("Inconsistent sql"),console.groupCollapsed("Inconsistent sql"),console.table({before:t,after:e,v:n}),console.groupEnd())}async function Vd({query:t,name:e,payload:n,additionals:r},i){if(!t.sql)return[];const{type:a,key:l,sql:c,pre_process:u,post_process:d}=t,p=ws(c,n),h=hd({sql:p,pre_process:u}),g=Gi.encode(h);Od(h,g);let y=await et.query(i)({type:a,key:l,query:g,...r},{params:{name:e}});return y=md(d,y,Ds(n)),y}async function Nd({type:t,key:e,configString:n,name:r,additionals:i},a){try{return await et.httpDataSourceQuery(a)({type:t,key:e,query:n,...i},{params:{name:r}})}catch(l){if(at.isCancel(l))throw l;return console.error(l),l}}async function zs(){try{return(await et.post()("/datasource/list",{filter:{},sort:[{field:"create_time",order:"ASC"}],pagination:{page:1,pagesize:100}},{})).data}catch(t){return console.error(t),[]}}async function va(){try{return(await et.post()("/sql_snippet/list",{filter:{},sort:[{field:"id",order:"ASC"}],pagination:{page:1,pagesize:1e3}},{})).data}catch(t){return console.error(t),[]}}class _a{constructor(e){$(this,"rootRef");this.rootRef=K.observable({current:e})}async deleteItem(e){K.runInAction(()=>{x.unset(this.rootRef.current,[e])})}getItem(e){const n=this.getValueFromRoot(e);return Promise.resolve(n)}getValueFromRoot(e){return e===null?K.toJS(this.rootRef.current):x.get(this.rootRef.current,[e])}setItem(e,n){if(e===null)if(x.isObject(n))K.runInAction(()=>{this.rootRef.current=n});else throw new Error("Cannot set root value to non-object");else K.runInAction(()=>{x.set(this.rootRef.current,[e],n)});return Promise.resolve(this.getItem(e))}watchItem(e,n,r){return K.reaction(()=>this.getValueFromRoot(e),(i,a)=>{n(i,a)},{requiresObservable:!0,fireImmediately:x.get(r,"fireImmediately",!1)})}}class Gd{constructor(){$(this,"channels",new Map);$(this,"globalChannel",new Fi)}getChannel(e){const n=this.channels.get(e);if(n)return n;const r=new Fi;return this.channels.set(e,r),r}}class Fd{constructor(e){$(this,"instances",new Map);this.pluginManager=e}get availableVizList(){return this.pluginManager.installedPlugins.flatMap(e=>e.manifest.viz)}resolveComponent(e){return this.pluginManager.factory.viz(e)}getOrCreateInstance(e){const n=this.instances.get(e.id);if(n)return n;const r={id:e.id,name:e.viz.type,type:e.viz.type,messageChannels:new Gd,instanceData:new _a(e.viz.conf)};return this.instances.set(e.id,r),r}}function ja(t,e,n,r){return{vizManager:n,locale:"zh",msgChannels:t.messageChannels,instanceData:t.instanceData,pluginData:new _a({}),colorPalette:{getColor(){return()=>""}},data:e,variables:r}}const Wd=t=>{const{panel:e,measure:n,vizManager:r,data:i,variables:a}=t,l=r.resolveComponent(e.viz.type),c=r.getOrCreateInstance(e),u={...ja(c,i,r,a),viewport:{width:n.w,height:n.h}},d=l.viewRender;return s.jsx(d,{context:u,instance:c,...x.omit(t,["panel","vizManager","data"])})},Qd=t=>{const{vizManager:e,panel:n,data:r,variables:i}=t,a=e.resolveComponent(n.viz.type),l=e.getOrCreateInstance(n),c={...ja(l,r,e,i)},u=a.configRender;return s.jsx(u,{context:c,instance:l,...x.omit(t,["panel","vizManager","data"])})},wa=(t,e)=>{const n=ot.bezier(t),r=ot.bezier(e);return function(i){return i<50?n(i*2/100).hex():r((i-50)*2/100).hex()}},In=t=>{const e=ot.bezier(t);return function(n){return e(n/100).hex()}},Rd={type:"interpolation",displayName:"style.color.interpolation.palette.red_green",getColor:wa(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},Ud={type:"interpolation",displayName:"style.color.interpolation.palette.yellow_blue",getColor:wa(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},Yd={type:"interpolation",displayName:"style.color.interpolation.palette.red",getColor:In(["#fff7f1","darkred"]),name:"red",category:"sequential"},Kd={type:"interpolation",displayName:"style.color.interpolation.palette.green",getColor:In(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},Jd={type:"interpolation",displayName:"style.color.interpolation.palette.blue",getColor:In(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},Xd={type:"interpolation",displayName:"style.color.interpolation.palette.orange",getColor:In(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class Zd{constructor(e){$(this,"symbol");this.symbol=Symbol(e)}}function dt(t){return new Zd(t)}class Ms{constructor(){$(this,"parent");$(this,"factoryRegistry",new Map);$(this,"instanceRegistry",new Map)}createScoped(){const e=new Ms;return e.parent=this,e}getRequired(e){return this.get(e)}get(e){if(this.instanceRegistry.has(e.symbol))return this.instanceRegistry.get(e.symbol);const n=this.factoryRegistry.get(e.symbol);if(n){const r=n(this);return this.instanceRegistry.set(e.symbol,r),r}if(this.parent)return this.parent.get(e)}provideFactory(e,n){return this.factoryRegistry.has(e.symbol)?console.warn(`Token ${e.symbol.toString()} is already registered`):this.factoryRegistry.set(e.symbol,n),this}provideValue(e,n){return this.factoryRegistry.has(e.symbol)?console.warn(`Token ${e.symbol.toString()} is already registered`):this.factoryRegistry.set(e.symbol,()=>n),this}dispose(){this.instanceRegistry.forEach(e=>{const n=x.get(e,"dispose");x.isFunction(n)&&n.bind(e)()}),this.instanceRegistry.clear(),this.factoryRegistry.clear()}}const Ca="13.4.1",Hd=Object.freeze(Object.defineProperty({__proto__:null,version:Ca},Symbol.toStringTag,{value:"Module"}));class ep{constructor(e){$(this,"staticColors",new Map);$(this,"interpolations",new Map);e.installedPlugins.forEach(n=>{n.manifest.color.forEach(r=>{this.register(r)})})}getStaticColors(){return Array.from(this.staticColors.values())}register(e){const n=this.encodeColor(e);e.type==="single"?(this.staticColors.has(n)&&console.warn(`the color '${e.name}' has been registered under '${e.category}', previous registered value will be overridden`),this.staticColors.set(n,e)):e.type==="interpolation"&&(this.interpolations.has(n)&&console.warn(`the interpolation '${e.name}' has been registered under '${e.category}', previous registered value will be overridden`,`the interpolation '${e.name}' has been registered under '${e.category}', previous registered value will be overridden`),this.interpolations.set(n,e))}decodeStaticColor(e){return this.staticColors.get(e)}encodeColor(e){return`\${${e.category}}.{${e.name}}`}decodeInterpolation(e){return this.interpolations.get(e)}getColorInterpolations(){return Array.from(this.interpolations.values())}}class tp{constructor(){$(this,"plugins",new Map);$(this,"vizComponents",new Map);$(this,"factory",{viz:e=>{const n=this.vizComponents.get(e);if(n)return n;throw new Error(`Viz Component (${e}) not found`)}})}install(e){if(this.plugins.has(e.id))throw new Error(`Plugin (${e.id}) has been installed before`);this.plugins.set(e.id,e);for(const n of e.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 np{constructor(){$(this,"migrations",[])}version(e,n){return this.migrations.push({version:e,handler:n}),this}run(e,n,r){var l;if(e.from===e.to)return n;if(e.from>e.to)throw new Error(`Can not downgrade from version '${e.from}' to (${e.to})`);const i=this.migrations.filter(c=>c.version>e.from&&c.version<=e.to),a=x.orderBy(i,"version","asc");if(((l=x.last(a))==null?void 0:l.version)!==e.to)throw new Error(`Migration to version ${e.to} not found`);return a.reduce((c,u)=>u.handler(c,r),n)}}class oe extends np{constructor(){super(),this.configVersions()}version(e,n){return super.version(e,(r,i)=>({version:e,...n(r,i)}))}async migrate({configData:e,panelModel:n}){const r=await e.getItem(null),i=x.get(r,"version",0),a=this.run({from:i,to:this.VERSION},r,{panelModel:n});await e.setItem(null,a)}async needMigration({configData:e}){const n=await e.getItem(null);return x.get(n,"version",0)<this.VERSION}}const O=(t,e)=>{const[n,{setFalse:r}]=N.useBoolean(!0),[i,a]=m.useState();m.useEffect(()=>(t.getItem(e).then(c=>{a(c),r()}),t.watchItem(e,c=>{a(c)})));const l=m.useCallback(async c=>{await t.setItem(e,c),a(c)},[t,e]);return{loading:n,value:i,set:l}},ze={top:16,right:16,bottom:16,left:16},Ye=t=>Math.max(0,t-ze.left-ze.right),Ke=t=>Math.max(0,t-ze.top-ze.bottom),on=(t,e)=>({width:Ye(t),height:Ke(e)}),Me=({width:t,height:e,children:n})=>s.jsx(o.Box,{pt:ze.top,pr:ze.right,pb:ze.bottom,pl:ze.left,sx:{width:t,height:e,overflow:"hidden",position:"relative"},children:n}),Is={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"}};function sp({context:t}){const{value:e}=O(t.instanceData,"config"),n=t.data,{width:r,height:i}=t.viewport,{x_axis_data_key:a,y_axis_data_key:l,z_axis_data_key:c,xAxis3D:u,yAxis3D:d,zAxis3D:p}=x.defaults({},e,Is),h=m.useMemo(()=>kn(n,a),[n,a]),{x:g,y,z:v}=m.useMemo(()=>({x:E(a),y:E(l),z:E(c)}),[a,l,c]),{min:C,max:T}=m.useMemo(()=>{const I=x.minBy(h,W=>W[v.columnKey]),P=x.maxBy(h,W=>W[v.columnKey]);return{min:x.get(I,v.columnKey),max:x.get(P,v.columnKey)}},[h,v]),D={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(I=>[I[g.columnKey],I[y.columnKey],I[v.columnKey]])}]};return e?s.jsx(Me,{width:r,height:i,children:s.jsx(ke,{echarts:je,option:D,style:on(r,i),notMerge:!0,theme:"merico-light"})}):null}const Sa=m.createContext(null),Es=Sa.Provider;function As(){const t=m.useContext(Sa);if(!t)throw new Error("Please use DashboardModelContextProvider");return t}const H=()=>As(),ka=()=>As(),Ta=m.createContext({searchButtonProps:{}}),Ps=Ta.Provider;function Da(){return m.useContext(Ta)}const za=m.createContext(null),$s=za.Provider;function Ma(){const t=m.useContext(za);if(!t)throw new Error("Please use ContentModelContextProvider");return t}const U=()=>Ma(),de=()=>Ma(),rp={inEditMode:!1},En=m.createContext(rp),Ia=m.createContext({panel:null,data:{},loading:!1,errors:[],downloadPanelScreenshot:()=>{}}),Bs=Ia.Provider;function Ea(){const t=m.useContext(Ia);if(!t.panel)throw new Error("Please use PanelContextProvider");return t}const pt=()=>Ea(),$e=()=>Ea(),ip={fullScreenPanelID:"",setFullScreenPanelID:x.noop},qs=m.createContext(ip);function Aa(){const t=m.useContext(qs);if(!t)throw new Error("Please use FullScreenPanelContext.Provider");return t}const ap={en:"en",zh:"zh-cn"};function Ls({children:t}){const{i18n:e}=_.useTranslation(),n=m.useMemo(()=>{const r=e.language;return ap[r]??"en"},[e.language]);return s.jsx(Wi.DatesProvider,{settings:{locale:n,firstDayOfWeek:1},children:t})}const L=S.observer(m.forwardRef(({label:t,required:e,description:n,value:r,onChange:i,queryID:a,clearable:l=!1,sx:c,...u},d)=>{const{panel:p}=$e(),h=m.useMemo(()=>p.dataFieldOptions(r,l,a),[r,l,a]);if(h.length===0){const g=p.explainDataKey(r);return s.jsxs(o.HoverCard,{shadow:"md",position:"bottom-start",withinPortal:!0,zIndex:320,children:[s.jsx(o.HoverCard.Target,{children:s.jsx(o.Box,{children:s.jsx(o.TextInput,{label:t,required:e,defaultValue:g.columnKey,readOnly:!0,disabled:!0})})}),s.jsx(o.HoverCard.Dropdown,{children:s.jsxs(o.Group,{position:"left",spacing:0,children:[s.jsx(o.Text,{size:"xs",color:g.queryName?"black":"red",sx:{fontFamily:"monospace"},children:g.queryName??g.queryID}),s.jsx(o.Text,{size:"xs",color:"black",sx:{fontFamily:"monospace"},children:"."}),s.jsx(o.Text,{size:"xs",color:"red",sx:{fontFamily:"monospace"},children:g.columnKey})]})})]})}return s.jsx(o.Select,{ref:d,label:t,description:n,data:h,value:r,onChange:i,required:e,sx:c,maxDropdownHeight:500,...u})}));function op({context:t}){const{value:e,set:n}=O(t.instanceData,"config"),r=x.defaults({},e,Is),{control:i,handleSubmit:a,reset:l}=b.useForm({defaultValues:r});return m.useEffect(()=>{l(r)},[e]),e?s.jsx(o.Stack,{spacing:"xs",children:s.jsxs("form",{onSubmit:a(n),children:[s.jsx(o.Text,{children:"X Axis"}),s.jsxs(o.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(L,{label:"Data Field",required:!0,...c})}),s.jsx(b.Controller,{name:"xAxis3D.name",control:i,render:({field:c})=>s.jsx(o.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...c})})]}),s.jsx(o.Text,{mt:"lg",children:"Y Axis"}),s.jsxs(o.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(L,{label:"Data Field",required:!0,...c})}),s.jsx(b.Controller,{name:"yAxis3D.name",control:i,render:({field:c})=>s.jsx(o.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...c})})]}),s.jsx(o.Text,{mt:"lg",children:"Z Axis"}),s.jsxs(o.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(L,{label:"Data Field",required:!0,...c})}),s.jsx(b.Controller,{name:"zAxis3D.name",control:i,render:({field:c})=>s.jsx(o.TextInput,{sx:{flexGrow:1},size:"md",label:"Name",...c})})]}),s.jsx(o.Group,{position:"center",mt:"xl",grow:!0,sx:{width:"60%"},mx:"auto",children:s.jsxs(o.Button,{color:"blue",type:"submit",children:[s.jsx(B.DeviceFloppy,{size:20}),s.jsx(o.Text,{ml:"md",children:"Save"})]})})]})}):null}const lp=[{lang:"en",resources:{bar_chart_3d:{viz_name:"Bar Chart(3D)"}}},{lang:"zh",resources:{bar_chart_3d:{viz_name:"柱图(3D)"}}}];function cp(t,{panelModel:e}){try{const n=e.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:a,z_axis_data_key:l,...c}=t;return{...c,x_axis_data_key:r(i),y_axis_data_key:r(a),z_axis_data_key:r(l)}}catch(n){throw console.error("[Migration failed]",n),n}}class up extends oe{constructor(){super(...arguments);$(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:cp(i,r)}})}}const dp={displayName:"viz.bar_chart_3d.viz_name",displayGroup:"chart.groups.echarts_based_charts",migrator:new up,name:"bar-3d",viewRender:sp,configRender:op,createConfig(){return{version:2,config:x.cloneDeep(Is)}},translation:lp},pp=({disabled:t,value:e,onChange:n})=>{const r=i=>{i&&n(i)};return s.jsxs(o.Box,{sx:{position:"relative"},children:[t&&s.jsx(o.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),s.jsx(Pe,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})};function Ie({enabled:t,func_content:e}){return(n,r)=>{if(!t)return n;try{return new Function(`return ${e}`)()(n,r)}catch(i){return console.error(`[getEchartsXAxisLabel] failed parsing custom function, error: ${i.message}`),n}}}function Ce(){return{enabled:!1,func_content:["function label(value, index) {"," // your code goes here"," // return value","}"].join(`
57
57
  `)}}const Je=m.forwardRef(({value:t,onChange:e,triggerButtonText:n},r)=>{const{t:i}=_.useTranslation(),[a,{setTrue:l,setFalse:c}]=N.useBoolean(),[u,d]=m.useState(t);m.useEffect(()=>{d(t)},[t]);const p=T=>{d({...u,enabled:T})},h=()=>{c();const{enabled:T,func_content:D}=u,I={enabled:T,func_content:D};d(I),e(I)},g=()=>{c(),d(t)},y=T=>{d(D=>({...D,func_content:T}))},v=()=>{y(Ce().func_content)},C=n??i("chart.axis.customize_label");return s.jsxs(s.Fragment,{children:[s.jsx(o.Button,{variant:"filled",color:"grape",leftIcon:s.jsx(k.IconMathFunction,{size:16}),mt:24,onClick:l,sx:{flexGrow:0},children:C}),s.jsx(o.Modal,{size:800,title:C,opened:a,onClose:c,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:a&&s.jsxs(o.Stack,{children:[s.jsx(o.Checkbox,{mt:10,label:i("common.enabled"),checked:u.enabled,onChange:T=>p(T.currentTarget.checked)}),s.jsx(pp,{value:u.func_content,onChange:y,disabled:!u.enabled}),s.jsxs(o.Group,{position:"apart",children:[s.jsx(o.Button,{onClick:v,color:"red",leftIcon:s.jsx(B.Recycle,{size:20}),children:i("common.actions.reset_to_default")}),s.jsxs(o.Group,{position:"right",children:[s.jsx(o.Button,{onClick:g,variant:"subtle",children:i("common.actions.cancel")}),s.jsx(o.Button,{color:"green",leftIcon:s.jsx(k.IconDeviceFloppy,{size:16}),onClick:h,children:i("common.actions.save")})]})]})]})})]})}),Tt={x_axis_scroll:!1,y_axis_scroll:!1,x_axis_slider:!1,y_axis_slider:!1};function Pa(){return x.cloneDeep(Tt)}const hp=[{lang:"en",resources:{boxplot:{viz_name:"Boxplot Chart",box:"Box",outlier:"Outlier",scatter:"Scatter",click_series:{label:"Click box, scatter or outlier"}}}},{lang:"zh",resources:{boxplot:{viz_name:"箱线图",box:"箱体",outlier:"异常点",scatter:"散点",click_series:{label:"点击箱体、散点或异常点"}}}}],$a={id:"builtin:echarts:click-echart:series",displayName:"viz.boxplot.click_series.label",nameRender:fp,configRender:mp,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 mp(t){return s.jsx(s.Fragment,{})}function fp(t){const{t:e}=_.useTranslation();return s.jsx(o.Text,{children:e("viz.boxplot.click_series.label")})}const An=m.forwardRef(({sectionTitle:t,value:e,onChange:n},r)=>{const{t:i,i18n:a}=_.useTranslation(),l=u=>d=>{const p=x.cloneDeep(e);x.set(p,u,d),n(p)},c=m.useMemo(()=>[{label:i("chart.axis.overflow.truncate"),value:"truncate"},{label:i("chart.axis.overflow.break_line"),value:"break"},{label:i("chart.axis.overflow.break_word"),value:"breakAll"}],[a.language]);return s.jsxs(o.Stack,{spacing:0,children:[t&&s.jsx(o.Divider,{mb:-5,mt:5,variant:"dotted",label:t,labelPosition:"right",labelProps:{color:"dimmed"}}),s.jsxs(o.Group,{grow:!0,noWrap:!0,children:[s.jsx(o.NumberInput,{label:i("chart.axis.overflow.max_width"),hideControls:!0,value:e.width,onChange:l("width")}),s.jsx(o.Select,{label:i("chart.axis.overflow.label"),data:c,value:e.overflow,onChange:l("overflow")}),s.jsx(o.TextInput,{label:i("chart.axis.overflow.ellipsis"),value:e.ellipsis,disabled:!0})]})]})}),Xe=m.forwardRef(({value:t,onChange:e},n)=>{const{t:r}=_.useTranslation(),i=l=>{e({...t,on_axis:l})},a=l=>{e({...t,in_tooltip:l})};return s.jsxs(o.Stack,{ref:n,spacing:0,children:[s.jsx(An,{sectionTitle:r("chart.axis.overflow.section_title.on_axis"),value:t.on_axis,onChange:i}),s.jsx(An,{sectionTitle:r("chart.axis.overflow.section_title.in_tooltip"),value:t.in_tooltip,onChange:a})]})});function Ee(){return{on_axis:{width:80,overflow:"truncate",ellipsis:"..."},in_tooltip:{width:200,overflow:"break",ellipsis:"..."}}}function Ve({overflow:t,width:e}){const n={truncate:"initial",break:"break-all",breakAll:"break-word"}[t],r=t==="truncate"?"nowrap":"initial",i={truncate:"ellipsis",break:"clip",breakAll:"clip"}[t];return`
58
58
  max-width: ${e}px;
59
59
  word-break: ${n};
@@ -445,15 +445,15 @@ Check the top-level render call using <`+A+">.")}return z}}function mu(w,z){{if(
445
445
  `)},ei=f.types.model("ViewModalConfig",{_name:f.types.literal(q.Modal),width:f.types.string,height:f.types.string,custom_modal_title:f.types.optional(pS,ls)}).views(t=>({get json(){const{_name:e,width:n,height:r,custom_modal_title:i}=t;return{_name:e,width:n,height:r,custom_modal_title:i.json}}})).actions(t=>({setWidth(e){t.width=e},setHeight(e){t.height=e}})),$l=()=>ei.create({_name:q.Modal,width:"90vw",height:"90vh"}),hS=f.types.model("ViewTabsTabModel",{id:f.types.identifier,name:f.types.string,view_id:f.types.string,color:f.types.optional(f.types.string,""),order:f.types.optional(f.types.number,0)}).views(t=>({get json(){const{id:e,name:n,view_id:r,color:i,order:a}=t;return{id:e,name:n,color:i,order:a,view_id:r}}})).actions(t=>({setName(e){t.name=e},setViewID(e){t.view_id=e},setColor(e){t.color=e},setOrder(e){t.order=e}})),ti=f.types.model("ViewTabsConfig",{_name:f.types.literal(q.Modal),tabs:f.types.optional(f.types.array(hS),[]),variant:f.types.optional(f.types.enumeration("variant",["default","outline","pills"]),"default"),orientation:f.types.optional(f.types.enumeration("orientation",["horizontal","vertical"]),"horizontal"),grow:f.types.optional(f.types.boolean,!1)}).views(t=>({get json(){const{_name:e,variant:n,orientation:r,tabs:i,grow:a}=t;return{grow:a,tabs:i.map(l=>l.json),_name:e,variant:n,orientation:r}},get tabsInOrder(){return x.sortBy(t.tabs,"order")}})).actions(t=>({setVariant(e){t.variant=e},setOrientation(e){t.orientation=e},setGrow(e){t.grow=e},setTabs(e){t.tabs.length=0,t.tabs=f.cast(e)},addTab(){const e=ie.randomId(),n={id:e,name:e,view_id:""};t.tabs.push(n)},removeTab(e){t.tabs.splice(e,1)}})),Bl=()=>ti.create({_name:q.Modal,tabs:[]}),ql=f.types.model({id:f.types.identifier,name:f.types.string,type:f.types.enumeration("EViewComponentType",[q.Division,q.Modal,q.Tabs]),config:f.types.union(Hr,ei,ti),panelIDs:f.types.optional(f.types.array(f.types.string),[])}).views(t=>({get json(){const{id:e,name:n,type:r,config:i}=t;return{id:e,name:n,type:r,config:i.json,panelIDs:t.panelIDs.map(a=>a)}}})).actions(t=>({setName(e){t.name=e},setType(e){if(t.type!==e){switch(e){case q.Division:t.config=Pl();break;case q.Modal:t.config=$l();break;case q.Tabs:t.config=Bl();break}t.type=e}},appendPanelID(e){t.panelIDs.push(e)},appendPanelIDs(e){t.panelIDs.push(...e)},removePanelID(e){const n=t.panelIDs.filter(r=>r!==e);t.panelIDs.length=0,t.panelIDs.push(...n)}})),ft="11.10.0",mS={definition:{sqlSnippets:[],queries:[],mock_context:{}},views:[{id:"Main",name:"Main",type:q.Division,config:{},panelIDs:[]}],panels:[],filters:[],version:ft,layouts:[{id:"basis",name:"basis",list:[],breakpoint:0}]},ni=f.types.model("DataSourceMetaModel",{id:f.types.string,type:f.types.enumeration("DataSourceType",[ce.HTTP,ce.MySQL,ce.Postgresql]),key:f.types.string,config:f.types.frozen()}),Ll=f.types.model("DataSourcesMetaModel",{list:f.types.optional(f.types.array(ni),[])}).views(t=>({find({type:e,key:n}){return t.list.find(r=>r.key===n&&r.type===e)},get options(){return t.list.map(e=>({value:e.key,label:e.key}))}})).actions(t=>({replace(e){t.list.length=0,t.list.push(...e)}})),Ol=f.types.model({id:f.types.string,content:f.types.string,create_time:f.types.string,update_time:f.types.string,is_preset:f.types.boolean}),si=f.types.model("GlobalSQLSnippetsMeta",{list:f.types.optional(f.types.array(Ol),[])}).views(t=>({find(e){return t.list.find(n=>n.id===e)},get options(){return t.list.map(e=>({value:e.id,label:e.id}))}})).actions(t=>({replace(e){t.list.length=0,t.list.push(...e)}})),cs=f.types.model("ContextMeta",{current:f.types.optional(f.types.frozen(),{})}).views(t=>({get keys(){return Object.keys(t.current)},get entries(){return Object.entries(t.current)}})).actions(t=>({replace(e){t.current=e},get(e){return t.current[e]},set(e,n){t.current[e]=n}}));function ri(t){return cs.create({current:t})}const ii=f.types.compose("ViewRenderModel",ql,f.types.model({tab:f.types.optional(f.types.string,"")})).views(t=>({get defaultTab(){if(t.type!==q.Tabs)return"";const e=t.config;return e.tabs.length>0?e.tabs[0].id:""},get tabViewID(){var n;return t.type!==q.Tabs?"":((n=t.config.tabs.find(r=>r.id===t.tab))==null?void 0:n.view_id)??""},get contentModel(){return f.getParent(t,3)},get panels(){if(t.type!==q.Tabs)return this.contentModel.panels.panelsByIDs(t.panelIDs);const e=this.tabViewID,n=this.contentModel.views.findByID(e);return(n==null?void 0:n.panels)??[]},get renderViewIDs(){const e=[t.id];return t.type===q.Tabs&&e.push(this.tabViewID),e},async downloadScreenshot(e){const n=e.offsetWidth*2+10,r=e.offsetHeight*2+10,i=new la,a=new Date().getTime(),l=await oa.toBlob(e,{bgcolor:"white",width:n,height:r,style:{transformOrigin:"0 0",transform:"scale(2)"}});i.file(`${t.name}_${a}.png`,l),i.file(`dashboard_state_${a}.json`,JSON.stringify(this.contentModel.dashboardState,null,4)),i.generateAsync({type:"blob"}).then(c=>{Sn.saveAs(c,`${t.name}_${a}.zip`)}).catch(c=>{console.error(c),bt.notifications.show({color:"red",title:"Failed to download screenshot with dashboard state",message:c.message})})}})).actions(t=>({setTab(e){t.tab=e??""},afterCreate(){f.addDisposer(t,K.reaction(()=>t.defaultTab,e=>this.setTab(e),{fireImmediately:!0,delay:0}))}})),ai=f.types.model("ViewsRenderModel",{current:f.types.optional(f.types.array(ii),[]),visibleViewIDs:f.types.array(f.types.string)}).views(t=>({get json(){return t.current.map(e=>Vt(e.json))},get idMap(){const e=new Map;return t.current.forEach(n=>{e.set(n.id,n)}),e},findByID(e){return t.current.find(n=>n.id===e)},get firstVisibleView(){const[e]=t.visibleViewIDs;return t.current.find(({id:n})=>n===e)},get visibleViews(){const e=new Set(t.visibleViewIDs);return t.current.filter(({id:n})=>e.has(n))}})).actions(t=>({appendToVisibles(e){new Set(t.visibleViewIDs.map(r=>r)).has(e)||t.visibleViewIDs.push(e)},rmVisibleViewID(e){const n=t.visibleViewIDs.findIndex(r=>r===e);n!==-1&&t.visibleViewIDs.splice(n,1)}}));function Vl(t){const e=t.length>0?[t[0].id]:[];return{current:t.map(r=>{const{_name:i=r.type}=r.config;return{...r,config:{...r.config,_name:i},panelIDs:r.panelIDs}}),visibleViewIDs:e}}const fS=new Cu.AsyncParser({withBOM:!0});async function Nl(t){return!Array.isArray(t)||t.length===0?"":await fS.parse(t).promise()}async function gS(t,e){const n=await Nl(e),r=new Blob([n],{type:"text/csv"});Sn.saveAs(r,`${t}.csv`)}function Gl(t){const e=new la,n=t.map(async({id:r,data:i})=>{const a=await Nl(i);e.file(`${r}.csv`,a)});Promise.all(n).then(()=>{e.generateAsync({type:"blob"}).then(r=>{Sn.saveAs(r,"dashboard_data.zip")})}).catch(r=>{console.error(r),bt.notifications.show({color:"red",title:"Failed to download data",message:r.message})})}function Jt(t,e){const n=new Blob([e],{type:"application/json"});Sn.saveAs(n,`${t}.json`)}const oi=wl.views(t=>({get contentModel(){return f.getRoot(t).content}})).views(t=>({get queries(){return t.contentModel.queries.findByIDSet(t.queryIDSet)},get firstQuery(){return this.queries.length>0?this.queries[0]:null},get firstQueryData(){return this.firstQuery?this.firstQuery.data:[]},queryByID(e){return this.queries.find(n=>n.id===e)},get data(){return this.queries.reduce((e,n)=>(e[n.id]=n.data,e),{})},get variableStrings(){return ga(t.variables,this.data)},get dataLoading(){return this.queries.some(e=>e.state==="loading")},get queryStateMessages(){const e=this.queries.filter(a=>!a.runByConditionsMet);if(e.length===0)return"";const n=new Set,r=new Set;e.forEach(a=>{const l=a.conditionNames;l.context.forEach(c=>n.add(c)),l.filters.forEach(c=>r.add(c))});const i=[];return n.size>0&&(console.log(n),i.push(`context: ${Array.from(n).join(", ")}`)),r.size>0&&i.push(`filter${r.size>1?"s":""}: ${Array.from(r).join(", ")}`),i.length===2&&i.splice(1,0,"and"),i.unshift("Waiting for"),i.join(" ")},get queryErrors(){return this.queries.map(e=>e.error).filter(e=>!!e)},get canRenderViz(){return this.queryErrors.length===0&&this.queryStateMessages===""&&!this.dataLoading}})).actions(t=>({refreshData(){t.queries.forEach(e=>e.fetchData(!0))},downloadData(){t.contentModel.queries.downloadDataByQueryIDs(t.queryIDs)},getSchema(){const e=t.json;return e.viz.conf={...e.viz.conf,__INTERACTIONS:{},__OPERATIONS:{},__TRIGGERS:{}},{panel:e,queries:t.queries.map(n=>n.json),layouts:t.contentModel.layouts.jsonByPanelIDSet(new Set([t.id]))}},downloadSchema(){const{panel:e,queries:n,layouts:r}=this.getSchema(),a=JSON.stringify({panels:[e],definition:{queries:n},layouts:r,version:ft},null,2),l=t.name;Jt(l,a)}}));function Fl(t){return{id:t,name:"Panel",title:{show:!0},description:"<p></p>",queryIDs:[],viz:{type:Dr.name,conf:Dr.createConfig()},style:{border:{enabled:!0}}}}const li=f.types.model("PanelsRenderModel",{list:f.types.optional(f.types.array(oi),[])}).views(t=>({get json(){return t.list.map(e=>e.json)},findByID(e){return t.list.find(n=>n.id===e)},get idMap(){const e=new Map;return t.list.forEach(n=>{e.set(n.id,n)}),e}})).views(t=>({panelsByIDs(e){const n=[];return e.forEach(r=>{const i=t.idMap.get(r);i?n.push(i):console.warn(`Panel is not found, id:${r}`)}),n}}));function Wl(t){const e=t.config,n=e.default_value;if(n===void 0)return n;if(e._name==="date-range")try{if(e.default_shortcut){const i=fl(e.default_shortcut);if(i)return i.map(a=>M(a).format(e.inputFormat))}const[...r]=n;return r.map(i=>i===null?i:M.tz(i,"UTC").format(e.inputFormat)??i)}catch(r){return console.error(r),n}return n}function xS(t,e){const n=t.default_value_func;try{return new Function(`return ${n}`)()(t,ct,e)}catch(r){return console.error(r),Wl(t)}}function Ql(t,e){var n;return(n=t.default_value_func)!=null&&n.trim()?xS(t,e):Wl(t)}function Rl(t,e){return t.reduce((n,r)=>(n[r.key]=Ql(r,e),n),{})}const ci=f.types.model("FiltersRenderModel",{current:f.types.optional(f.types.array(Zr),[]),values:f.types.optional(f.types.frozen(),{})}).views(t=>({get json(){return t.current.map(e=>e.json)},get contentModel(){return f.getRoot(t).content},get context(){return this.contentModel.payloadForSQL.context},get initialValuesDep(){return JSON.stringify({filters:t.current.map(({default_value_func:e,config:n})=>({default_value_func:e,config:n})),context:this.contentModel.payloadForSQL.context})},get formattedDefaultValues(){return Rl(this.json,this.contentModel.context)},get firstID(){if(t.current.length!==0)return t.current[0].id},findByID(e){return t.current.find(n=>n.id===e)},findByIDSet(e){return t.current.filter(n=>e.has(n.id))},get inOrder(){return x.sortBy(t.current,"order")},get empty(){return t.current.length===0},visibleInView(e){return x.sortBy(t.current.filter(n=>n.visibleInViewsIDSet.has(e)),"order")},get firstFilterValueKey(){return Object.keys(t.values)[0]??""},get keySet(){return new Set(t.current.map(e=>e.key))},get keyLabelMap(){return t.current.reduce((e,n)=>(e[n.key]=n.label,e),{})},getSelectOption(e){const n=this.findByID(e);if(!n||!("getSelectOption"in n.config))return null;const r=t.values[n.key];return n.config.getSelectOption(r)}})).actions(t=>({setValues(e){t.values=e},patchValues(e){t.values=x.defaults({},e,t.values)},setValueByKey(e,n){t.values={...t.values,[e]:n}},getValueByKey(e){return t.values[e]},getSchema(e,n){return{filters:t.findByIDSet(new Set(e)).map(a=>({...a.json,visibleInViewsIDs:n?a.json.visibleInViewsIDs:[]})),version:ft}},downloadSchema(e){const n=JSON.stringify(this.getSchema(e,!1),null,2);Jt("Filters",n)}}));function ui(t,e,n,r){const i=x.defaults({},r,Rl(t,{...n,...e}));return{current:t,values:i}}const Ul=Cl.views(t=>({get rootModel(){return f.getRoot(t)},get contentModel(){return this.rootModel.content},get conditionOptions(){if(!f.isAlive(t))return[];const{context:e}=this.contentModel.payloadForSQL,n=Object.keys(e).map(l=>({group:"Context",label:l,value:`context.${l}`,description:void 0})),r=this.contentModel.filters.keyLabelOptions.map(l=>({group:"Filters",label:l.label,value:`filters.${l.value}`,description:l.value})),i=[...n,...r],a=new Set(i.map(l=>l.value));return t.run_by.forEach(l=>{a.has(l)||i.push({group:"Invalid",label:l,value:l})}),i},get unmetRunByConditions(){if(!f.isAlive(t))return[];const{run_by:e}=t;if(e.length===0)return[];const n=this.contentModel.payloadForSQL;return e.filter(r=>{const i=x.get(n,r);return Array.isArray(i)?i.length===0:typeof i=="number"?Number.isNaN(i):!i})}})).views(t=>({get payload(){return t.contentModel.payloadForSQL},get formattedSQL(){return Cs(t.sql,this.payload)},get httpConfigString(){const{context:e,filters:n}=this.payload,{name:r,pre_process:i}=t.json,a=$d(i,e,n);return console.groupCollapsed(`Request config for: ${r}`),console.log(a),console.groupEnd(),JSON.stringify(a)},get typedAsSQL(){return[ce.Postgresql,ce.MySQL].includes(t.type)},get typedAsHTTP(){return[ce.HTTP].includes(t.type)},get isTransform(){return t.type===ce.Transform},get reQueryKey(){const{react_to:e=[]}=t;if(e.length===0)return"";const n=t.contentModel.payloadForSQL,r=[...e].reduce((i,a)=>(i[a]=x.get(n,a),i),{});return JSON.stringify(r)},get runByConditionsMet(){return t.unmetRunByConditions.length===0},get conditionNames(){if(t.unmetRunByConditions.length===0)return{context:[],filters:[]};const{keyLabelMap:e}=t.contentModel.filters,n=t.unmetRunByConditions.filter(i=>i.startsWith("context.")).map(i=>i.replace("context.","")),r=t.unmetRunByConditions.filter(i=>i.startsWith("filters.")).map(i=>x.get({filters:e},i,i.replace("filters.",""))).filter(i=>!!i);return{context:n,filters:r}},get queries(){return f.getParent(t,2)},get inUse(){return this.queries.isQueryInUse(t.id)},get dependencies(){if(!this.typedAsSQL)return[];const e=x.uniq(t.sql.match(Mn.sqlSnippet)),n=x.uniq(t.sql.match(Mn.filter)),r=x.uniq(t.sql.match(Mn.context)),i=[];return e.forEach(a=>{i.push({type:"sql_snippet",key:a,valid:t.contentModel.sqlSnippets.keySet.has(a)})}),n.forEach(a=>{i.push({type:"filter",key:a,valid:t.contentModel.filters.keySet.has(a)})}),r.forEach(a=>{i.push({type:"context",key:a,valid:t.contentModel.mock_context.keySet.has(a)})}),i}})),di=f.types.compose("QueryRenderModel",Ul,f.types.model({state:f.types.optional(f.types.enumeration(["idle","loading","error"]),"idle"),data:f.types.optional(f.types.frozen([]),[]),error:f.types.frozen()})).views(t=>({get datasource(){const{key:e,type:n}=t;return t.rootModel.datasources.find({type:n,key:e})},get additionalQueryInfo(){return t.contentModel.getAdditionalQueryInfo(t.id)},get depQueryModels(){return t.contentModel.queries.findByIDSet(new Set(t.dep_query_ids))},get depQueryModelStates(){return this.depQueryModels.map(e=>e.state)},get depQueryModelStatesString(){return this.depQueryModelStates.toString()}})).views(t=>({get stateMessage(){if(t.state!=="idle")return"";if(!t.runByConditionsMet){const{context:e,filters:n}=t.conditionNames;if(e.length===0&&n.length===0)return"Waiting";const r=[];return e.length>0&&r.push(`context: ${e.join(", ")}`),n.length>0&&r.push(`filter${n.length>1?"s":""}: ${n.join(", ")}`),r.length===2&&r.splice(1,0,"and"),r.unshift("Waiting for"),r.join(" ")}return t.data.length>0?"":"Empty Data"}})).volatile(()=>({controller:new AbortController})).actions(t=>({runSQL:f.flow(function*(){var e;if(t.valid&&((e=t.controller)==null||e.abort(),!!t.runByConditionsMet)){t.controller=new AbortController,t.state="loading";try{const n=t.payload;t.data=yield*f.toGenerator(Vd({payload:n,name:t.name,query:t.json,additionals:t.additionalQueryInfo},t.controller.signal)),t.state="idle",t.error=null}catch(n){if(!at.isCancel(n)){t.data=[];const r=x.get(n,"message","unkown error");t.error=x.get(n,"response.data.detail.message",r),t.state="error"}}}}),runHTTP:f.flow(function*(){var e;if(!(!t.valid||!t.datasource)&&((e=t.controller)==null||e.abort(),!!t.runByConditionsMet)){t.controller=new AbortController,t.state="loading";try{const{type:n,key:r,post_process:i}=t.json;let a=JSON.parse(t.httpConfigString);a=Bd(t.datasource,a);const l=yield*f.toGenerator(Nd({type:n,key:r,configString:JSON.stringify(a),name:t.name,additionals:t.additionalQueryInfo},t.controller.signal)),c=qd(t.datasource,l),u=Ld(i,c,t.contentModel.dashboardState);t.data=u,t.state="idle",t.error=null}catch(n){if(console.error(n),!at.isCancel(n)){t.data=[];const r=x.get(n,"message","unkown error");t.error=x.get(n,"response.data.detail.message",r),t.state="error"}}}}),runTransformation(){t.state="loading";try{const n=t.contentModel.queries.findByIDSet(new Set(t.dep_query_ids)).map(l=>({id:l.id,name:l.name,data:x.cloneDeep(l.data)})),r=t.contentModel.dashboardState,i=t.pre_process,a=new Function(`return ${i}`)()(n,r,ct);t.data=a,t.state="idle",t.error=null}catch(e){t.data=[],t.error=e.message,t.state="error"}}})).actions(t=>({fetchData:e=>{if(!t.inUse&&!e){console.debug(`🟡 Skipping query[${t.name}]`);return}return console.debug(`🔵 Running query[${t.name}]`),t.isTransform?t.runTransformation():t.typedAsHTTP?t.runHTTP():t.runSQL()},beforeDestroy(){var e;(e=t.controller)==null||e.abort()}})).actions(t=>({afterCreate(){f.addDisposer(t,K.reaction(()=>{var n;return t.isTransform?[t.inUse,t.id,t.key,t.dep_query_ids.toString(),t.pre_process,t.depQueryModelStatesString].join("--"):t.typedAsHTTP?`${t.inUse}--${t.id}--${t.key}--${t.reQueryKey}--${(n=t.datasource)==null?void 0:n.id}`:[t.inUse,t.id,t.key,t.formattedSQL,t.pre_process,t.post_process].join("--")},()=>t.fetchData(!1),{fireImmediately:!0,delay:0}))}})),pi=f.types.model("QueriesRenderModel",{current:f.types.optional(f.types.array(di),[])}).views(t=>({get idSet(){return new Set(t.current.map(e=>e.id))},get firstID(){if(t.current.length!==0)return t.current[0].id},findByID(e){return t.current.find(n=>n.id===e)},findByIDSet(e){return t.current.filter(n=>e.has(n.id))},get json(){return t.current.filter(e=>e.id&&e.key).map(e=>e.json)},get contentModel(){return f.getParent(t,1)},get visibleQueryIDSet(){const{views:e,filters:n,queries:r}=this.contentModel,i=[];e.visibleViews.forEach(c=>{c.panels.forEach(u=>{i.push(...u.queryIDs)})});const a=x.uniq(e.visibleViews.map(c=>c.renderViewIDs).flat());n.current.forEach(c=>{const u=x.get(c,"config.options_query_id");if(!u)return;a.some(p=>c.visibleInViewsIDSet.has(p))&&i.push(u)}),r.findByIDSet(new Set(i)).forEach(c=>{!c.isTransform||c.dep_query_ids.length===0||i.push(...c.dep_query_ids)});const l=new Set(i);return console.debug("QueryIDs:",l),l},isQueryInUse(e){return this.visibleQueryIDSet.has(e)}})).actions(t=>({downloadAllData(){const e=t.current.map(({name:n,data:r})=>({id:n,data:r}));Gl(e)},downloadDataByQueryIDs(e){const n=new Set(e),r=t.current.filter(i=>n.has(i.id)).map(({name:i,data:a})=>({id:i,data:a}));Gl(r)},downloadDataByQueryID(e){const n=t.findByID(e);if(!n){console.log("[downloadDataByQueryID] query not found");return}const{name:r,data:i}=n;gS(r,i)},refetchDataByQueryID(e){const n=t.findByID(e);if(!n){console.error(new Error(`[downloadDataByQueryID] query by ID[${e}] not found`));return}return n.fetchData(!0)},getSchema(e){return{definition:{queries:t.findByIDSet(new Set(e)).map(i=>i.json)},version:ft}},downloadSchema(e){const n=JSON.stringify(this.getSchema(e),null,2);Jt("Queries",n)}}));function Yl(t){return{current:t}}function Kl({min:t,max:e}){const n=`${t}px`,r=Number.isFinite(e)?`${e}px`:"∞";return`[${n}, ${r})`}const hi=f.types.model("LayoutsRenderModel",{list:f.types.array(kl),currentBreakpoint:f.types.string}).views(t=>({get json(){return t.list.map(e=>e.json)},jsonByPanelIDSet(e){return t.list.map(n=>n.jsonByPanelIDSet(e))},get root(){return f.getRoot(t)},get contentModel(){return this.root.content},get basisLayoutSet(){return t.list.find(e=>e.id==="basis")},get currentLayoutSet(){return t.list.find(e=>e.id===t.currentBreakpoint)},get currentLayoutRange(){return this.breakpointRanges.find(e=>e.id===t.currentBreakpoint)},get currentRangeText(){const e=this.currentLayoutRange;return Kl(e)},get cols(){const e={};return t.list.forEach(n=>{e[n.id]=36}),e},get breakpoints(){const e={};return t.list.forEach(n=>{e[n.id]=n.breakpoint}),e},get breakpointNameRecord(){const e={};return t.list.forEach(n=>{e[n.name]=n.breakpoint}),e},get breakpointRanges(){const e=t.list.map(n=>({id:n.id,name:n.name,min:n.breakpoint,max:1/0,text:""}));return e.sort((n,r)=>n.min-r.min).forEach((n,r)=>{r!==e.length-1&&(n.max=e[r+1].min)}),e.forEach(n=>{n.text=Kl(n)}),e},get breakpointsInfo(){return t.list.map(e=>({id:e.id,name:e.name,breakpoint:e.breakpoint})).sort((e,n)=>e.breakpoint-n.breakpoint)},get currentBreakpointRange(){return this.breakpointRanges.find(e=>e.id===t.currentBreakpoint)},get currentLayoutPreviewWidth(){const e=this.currentBreakpointRange;if(e)return e.max===1/0?e.min===0?void 0:e.min+1:e.max},items(e){const n=new Set(e);return this.currentLayoutSet.list.filter(i=>n.has(i.panelID))},gridLayouts(e){const n=new Set(e),r={};return t.list.forEach(i=>{r[i.id]=i.list.filter(a=>n.has(a.panelID)).map(a=>a.layoutProperies)}),r},findItemByPanelID(e){return this.currentLayoutSet.findByPanelID(e)}})).actions(t=>({setCurrentBreakpoint(e){console.log("🔴 onBreakpointChange:",e),t.currentBreakpoint=e},afterCreate(){f.addDisposer(t,K.reaction(()=>t.currentBreakpoint,()=>{setTimeout(()=>{window.dispatchEvent(new Event("resize"))},32)},{fireImmediately:!1,delay:0}))}})),Jl=Tl.views(t=>({isADuplicatedKey(e){return!e||e===t.key?!1:!!f.getParent(t,2).findByKey(e)}})),mi=f.types.model("SQLSnippetsRenderModel",{current:f.types.optional(f.types.array(Jl),[])}).views(t=>({get json(){return t.current.map(e=>e.json)},get record(){return t.current.reduce((e,n)=>(e[n.key]=n.value,e),{})},get keySet(){return new Set(t.current.map(e=>e.key))},get firstKey(){if(t.current.length!==0)return t.current[0].key},findByKey(e){return t.current.find(n=>n.key===e)},findByKeySet(e){return t.current.filter(n=>e.has(n.key))}})).actions(t=>({getSchema(e){return{definition:{sqlSnippets:t.findByKeySet(new Set(e)).map(i=>i.json)},version:ft}},downloadSchema(e){const n=JSON.stringify(this.getSchema(e),null,2);Jt("SQL Snippets",n)}}));function Xl(t){return{current:t}}function xn(t,e,n,r){return t.reduce((i,a)=>{try{i[a[e]]=ws(a[n],r)}catch(l){i[a[e]]=l.message}return i},{})}class Zl{constructor(e){$(this,"origin");$(this,"copy");this.origin=e,this.copy=f.clone(e),K.makeAutoObservable(this,{},{autoBind:!0,deep:!1})}get changed(){return!x.isEqual(f.getSnapshot(this.origin),f.getSnapshot(this.copy))}commit(){f.applySnapshot(this.origin,f.getSnapshot(this.copy))}reset(){f.applySnapshot(this.copy,f.getSnapshot(this.origin))}update(e){f.applySnapshot(this.copy,e)}}const Hl=t=>new Zl(t),yS=S.observer(({view:t})=>{const{t:e}=_.useTranslation(),n=H(),r=U(),i=Le.useModals(),{panel:a,downloadPanelScreenshot:l}=$e(),{id:c}=a,{viewPanelInFullScreen:u,inFullScreen:d}=m.useContext(os),p=()=>{r.duplicatePanelByID(c,t.id)},h=()=>{n.editor.open(["_VIEWS_",t.id,"_PANELS_",c])},g=()=>i.openConfirmModal({title:`${e("panel.delete")}?`,labels:{confirm:e("common.actions.confirm"),cancel:e("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>r.removePanelByID(c,t.id),confirmProps:{color:"red"},zIndex:320}),y=m.useCallback(()=>{u(c)},[c,u]),v=!d&&t.type!==q.Modal;return s.jsx(s.Fragment,{children:s.jsx(o.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},children:s.jsxs(o.Menu,{withinPortal:!0,children:[s.jsx(o.Menu.Target,{children:s.jsx(o.Box,{className:"panel-dropdown-target",sx:{width:"100%"}})}),s.jsxs(o.Menu.Dropdown,{children:[s.jsx(o.Menu.Item,{onClick:a.refreshData,icon:s.jsx(B.Refresh,{size:14}),children:e("common.actions.refresh")}),s.jsx(o.Menu.Item,{onClick:a.downloadData,icon:s.jsx(B.Download,{size:14}),children:e("common.actions.download_data")}),s.jsx(o.Menu.Item,{onClick:a.downloadSchema,icon:s.jsx(k.IconCode,{size:14}),children:e("common.actions.download_schema")}),s.jsx(o.Menu.Item,{onClick:l,icon:s.jsx(k.IconCamera,{size:14}),children:e("common.actions.download_screenshot")}),v&&s.jsx(o.Menu.Item,{onClick:y,icon:s.jsx(B.ArrowsMaximize,{size:14}),disabled:!0,children:e("common.actions.enter_fullscreen")}),s.jsx(o.Divider,{label:e("common.actions.edit"),labelPosition:"center"}),s.jsx(o.Menu.Item,{onClick:h,icon:s.jsx(B.Settings,{size:14}),children:e("common.titles.settings")}),s.jsx(o.Menu.Item,{onClick:p,icon:s.jsx(B.Copy,{size:14}),children:e("common.actions.duplicate")}),s.jsx(o.Menu.Item,{color:"red",onClick:g,icon:s.jsx(B.Trash,{size:14}),children:e("common.actions.delete")})]})]})})})});function bS(t){return t?["<p><br></p>","<p></p>"].includes(t):!0}const fi=S.observer(()=>{const{t}=_.useTranslation(),[e,n]=m.useState(!1),{panel:r}=pt();return bS(r.description)?null:s.jsxs(s.Fragment,{children:[s.jsx(o.Modal,{opened:e,onClose:()=>n(!1),title:r.title.show?r.name:"",withCloseButton:!1,withinPortal:!0,zIndex:310,children:s.jsx(Xn,{value:r.description,styles:{root:{border:"none"},content:{padding:0}},sx:{".mantine-RichTextEditor-content .ProseMirror":{padding:"0 !important"}}})}),s.jsx(o.Tooltip,{label:t("panel.panel_description_click"),position:"top-start",withinPortal:!0,children:s.jsx(o.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>n(i=>!i),sx:{verticalAlign:"baseline",cursor:"pointer"},children:s.jsx(B.InfoCircle,{size:20})})})]})}),dM="",vS=S.observer(function(){const{panel:e}=pt(),{name:n,title:r}=e;return r.show?s.jsx(o.Group,{grow:!0,position:"center",className:"panel-title-wrapper",sx:{flexGrow:1},children:s.jsx(o.Text,{align:"center",lineClamp:1,className:"panel-title-text",children:n})}):null});function _S(t){const e=m.useRef(null);return{ref:e,downloadPanelScreenshot:()=>{const r=e.current;if(!r)return;const i=r.offsetWidth*2,a=r.offsetHeight*2;oa.toBlob(e.current,{bgcolor:"white",width:i,height:a,style:{border:"none",borderRadius:0,transformOrigin:"0 0",transform:"scale(2)"}}).then(l=>{window.saveAs(l,`${t.name?t.name:t.viz.type}.png`)})}}}var ec=(t=>(t.migrated="migrated",t.nothingToMigrate="nothingToMigrate",t.checkFailed="checkFailed",t.migrationFailed="migrationFailed",t))(ec||{}),us=(t=>(t.notStarted="notStarted",t.inProgress="inProgress",t.done="done",t))(us||{});class jS{constructor(e){$(this,"vizInstance");$(this,"operationManager");$(this,"triggerManager");$(this,"vizManager");$(this,"runningMigration");$(this,"panelModel");$(this,"status","notStarted");this.panelModel=e.getRequired(pe.instanceScope.panelModel),this.vizInstance=e.getRequired(pe.instanceScope.vizInstance),this.operationManager=e.getRequired(pe.instanceScope.operationManager),this.triggerManager=e.getRequired(pe.instanceScope.triggerManager),this.vizManager=e.getRequired(pe.vizManager)}async createMigrationTask(){const e=[];try{await this.instanceNeedMigration()&&e.push(()=>this.runInstanceMigration()),await this.interactionNeedMigration()&&e.push(()=>this.runInteractionMigration())}catch(n){return console.warn("check migration failed",n),"checkFailed"}if(e.length===0)return"nothingToMigrate";try{return await Promise.all(e.map(n=>n())),"migrated"}catch(n){return console.warn("migration failed",n),"migrationFailed"}}async runMigration(){return this.runningMigration||(this.status="inProgress",this.runningMigration=this.createMigrationTask().then(e=>(this.status="done",e))),this.runningMigration}async runInteractionMigration(){await this.operationManager.runMigration(),await this.triggerManager.runMigration()}async runInstanceMigration(){const e=this.vizManager.resolveComponent(this.vizInstance.type),n={configData:this.vizInstance.instanceData,panelModel:this.panelModel};await e.migrator.migrate(n)}async instanceNeedMigration(){const e=this.vizManager.resolveComponent(this.vizInstance.type),n={configData:this.vizInstance.instanceData};return e.migrator.needMigration(n)}async interactionNeedMigration(){return await this.operationManager.needMigration()||await this.triggerManager.needMigration()}}function tc(t){const{panel:e}=pt();return m.useCallback(n=>{const r=n.getRequired(pe.vizManager),i=r.resolveComponent(t.viz.type);return n.createScoped().provideFactory(pe.instanceScope.vizInstance,()=>r.getOrCreateInstance(t)).provideFactory(pe.instanceScope.interactionManager,a=>{const l=a.getRequired(pe.instanceScope.vizInstance);return new Ns(l,i,Pn)}).provideFactory(pe.instanceScope.operationManager,a=>a.getRequired(pe.instanceScope.interactionManager).operationManager).provideFactory(pe.instanceScope.triggerManager,a=>a.getRequired(pe.instanceScope.interactionManager).triggerManager).provideValue(pe.instanceScope.panelModel,e).provideFactory(pe.instanceScope.migrator,a=>new jS(a))},[t.viz.type,t.viz.conf])}function nc(t){const[e,n]=m.useState(!1),r=ml().getRequired(pe.instanceScope.migrator);return N.useAsyncEffect(async()=>{const i=r.status===us.notStarted;n(r.status===us.done),r.status===us.notStarted&&r.runMigration().then(a=>{a===ec.migrated&&i&&(t==null||t())}).finally(()=>{n(!0)})},[r]),e}function sc(t,e){const n=ml().getRequired(pe.instanceScope.vizInstance);return m.useEffect(()=>(n.instanceData.setItem(null,e.viz.conf),n.instanceData.watchItem(null,r=>{t(r)})),[t,e.viz.type]),n}function wS({setVizConf:t,...e}){const{panel:n}=e,r=sc(t,n),i=nc(()=>{bt.showNotification({title:`${n.name} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})});return N.useAsyncEffect(async()=>{await r.instanceData.setItem(null,n.viz.conf)},[r,n.viz.type]),i?s.jsx(Qd,{...e}):s.jsx(o.Text,{children:"Checking update..."})}function CS(t){const{panel:e,setVizConf:n}=t;sc(n,e);const{inEditMode:r}=m.useContext(En);return nc(()=>{r&&bt.showNotification({title:`${e.name} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})})?s.jsx(Wd,{...t}):s.jsx(o.Text,{children:"Checking update"})}const pM="";function SS(t,e){const{vizManager:n}=m.useContext(it),{panel:{viz:r,title:i,id:a,name:l,description:c,queryIDs:u,variables:d}}=pt(),p={id:a,name:l,title:i,description:c,queryIDs:u,viz:r},h=tc(p);try{return n.resolveComponent(r.type),s.jsx(as,{configure:h,children:s.jsx(CS,{setVizConf:r.setConf,panel:p,measure:e,data:t,variables:d,vizManager:n})})}catch(g){return console.info(x.get(g,"message")),null}}const rc=S.observer(function({data:e}){const{ref:n,width:r,height:i}=ie.useElementSize(),a=SS(e,{w:r,h:i}),l=r>0&&i>0;return s.jsx("div",{className:"viz-root",ref:n,children:s.jsx(o.Box,{sx:{width:r,height:i,overflow:"hidden"},children:l&&s.jsx(we,{children:a})})})}),ic=S.observer(({panel:t})=>s.jsxs(o.Stack,{children:[t.queryErrors.map((e,n)=>s.jsx(o.Text,{color:"red",size:"sm",align:"center",sx:{fontFamily:"monospace"},children:e},`${n}-${e}`)),s.jsx(o.Text,{color:"gray",align:"center",size:"sm",children:t.queryStateMessages})]})),gi=S.observer(({panel:t})=>s.jsxs(o.Flex,{className:"panel-viz-section",direction:"column",sx:{position:"relative",width:"100%"},children:[s.jsx(o.LoadingOverlay,{visible:t.dataLoading,exitTransitionDuration:0}),!t.canRenderViz&&s.jsx(ic,{panel:t}),t.canRenderViz&&s.jsx(rc,{data:t.data})]})),kS={border:"1px solid #e9ecef"},ac=S.observer(({panel:t,panelStyle:e,dropdownContent:n})=>{const{ref:r,downloadPanelScreenshot:i}=_S(t);return t.title.show,s.jsx(Bs,{value:{panel:t,data:t.data,loading:t.dataLoading,errors:t.queryErrors,downloadPanelScreenshot:i},children:s.jsxs(o.Box,{className:`panel-root ${t.title.show?"panel-root--show-title":""}`,ref:r,p:0,sx:{...kS,...e},children:[s.jsx(o.Box,{className:"panel-description-popover-wrapper",children:s.jsx(fi,{})}),n,s.jsx(vS,{}),s.jsx(gi,{panel:t})]})})}),TS={border:"1px dashed transparent",transition:"border-color 300ms ease","&:hover":{borderColor:"#e9ecef"}};function DS(t){return t.style.border.enabled?{}:TS}const oc=S.observer(function({panel:e,view:n}){const r=DS(e);return s.jsx(ac,{panel:e,panelStyle:r,dropdownContent:s.jsx(yS,{view:n})})});function zS(t){return!["richText","button"].includes(t)}const MS=S.observer(({view:t})=>{const{t:e}=_.useTranslation(),{panel:n,downloadPanelScreenshot:r}=pt(),{id:i}=n,{viewPanelInFullScreen:a,inFullScreen:l}=m.useContext(os),c=m.useCallback(()=>{a(i)},[i,a]),u=!l&&t.type!==q.Modal;return zS(n.viz.type)?s.jsx(o.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},children:s.jsxs(o.Menu,{withinPortal:!0,children:[s.jsx(o.Menu.Target,{children:s.jsx(o.Box,{className:"panel-dropdown-target"})}),s.jsxs(o.Menu.Dropdown,{children:[s.jsx(o.Menu.Item,{onClick:n.refreshData,icon:s.jsx(B.Refresh,{size:14}),children:e("common.actions.refresh")}),s.jsx(o.Menu.Item,{onClick:n.downloadData,icon:s.jsx(B.Download,{size:14}),children:e("common.actions.download_data")}),s.jsx(o.Menu.Item,{onClick:r,icon:s.jsx(k.IconCamera,{size:14}),children:e("common.actions.download_screenshot")}),u&&s.jsx(o.Menu.Item,{onClick:c,icon:s.jsx(B.ArrowsMaximize,{size:14}),children:e("common.actions.enter_fullscreen")})]})]})}):null});function IS(t){return t.style.border.enabled?{}:{border:"1px dashed transparent"}}const xi=S.observer(({panel:t,view:e})=>{const n=IS(t);return s.jsx(ac,{panel:t,panelStyle:n,dropdownContent:s.jsx(MS,{view:e})})}),ES={modal:{display:"flex",flexDirection:"column",flexWrap:"nowrap"},body:{display:"flex",height:"calc(100vh - 88px)"}},lc=S.observer(function({view:e,panel:n,exitFullScreen:r}){return s.jsx(o.Modal,{opened:!0,fullScreen:!0,onClose:r,title:s.jsx(o.Button,{color:"blue",size:"xs",onClick:r,leftIcon:s.jsx(B.ArrowLeft,{size:20}),children:"Exit fullscreen"}),styles:ES,children:s.jsx(o.Group,{grow:!0,sx:{flexGrow:1,flexShrink:0},children:s.jsx(xi,{view:e,panel:n})})})});function cc(t,e,n){const{panels:r}=de(),i=t.id==="Main",[a,l]=m.useState(()=>i&&r.findByID(e)?e:null),c=m.useCallback(h=>{l(h),i&&n(h)},[i,n]),u=m.useCallback(()=>{l(null),i&&n("")},[i,n]),d=a?r.findByID(a):null;return{viewPanelInFullScreen:c,exitFullScreen:u,inFullScreen:!!d,fullScreenPanel:d}}const hM="",AS=m.forwardRef(({h:t},e)=>s.jsx(o.ActionIcon,{ref:e,className:"react-grid-customDragHandle",sx:{userSelect:"none",cursor:"grab",position:"absolute",top:5,right:t>38?5:20,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",children:s.jsx(B.ArrowsMove,{size:16})})),PS=m.forwardRef(({handleAxis:t,...e},n)=>s.jsx(o.ActionIcon,{ref:n,className:"react-grid-customResizeHandle",sx:{userSelect:"none",cursor:"nwse-resize",position:"absolute",bottom:0,right:0,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",...e,children:s.jsx(B.ChevronDownRight,{size:16})})),$S=Cn.WidthProvider(Cn.Responsive),BS=S.observer(({view:t,className:e="layout"})=>{const r=U().layouts,i=r.items(t.panelIDs),a=r.gridLayouts(t.panelIDs),l=(d,p,h,g)=>{console.log("🔴 onResize",d),h.h<30&&(h.h=30,g.h=30),h.w<4&&(h.w=4,g.w=4)},c=(d,p,h)=>{console.log("🔴 onResizeStop",{layouts:d,oldItem:p,newItem:h}),r.updateCurrentLayoutItem(h)},u=(d,p,h)=>{console.log("🔴 onDragStop",{layouts:d,oldItem:p,newItem:h}),r.updateCurrentLayoutItem(h)};return s.jsx($S,{className:`dashboard-layout ${e}`,rowHeight:1,margin:[0,0],isBounded:!0,isDraggable:!0,isResizable:!0,cols:r.cols,layouts:a,draggableHandle:".react-grid-customDragHandle",resizeHandle:s.jsx(PS,{}),onResize:l,breakpoints:r.breakpoints,onBreakpointChange:r.setCurrentBreakpoint,onResizeStop:c,onDragStop:u,width:r.currentLayoutPreviewWidth,children:i.map(d=>s.jsxs("div",{"data-grid":d.layoutProperies,className:"panel-grid-item",children:[s.jsx(AS,{h:d.h}),s.jsx(oc,{view:t,panel:d.panel})]},d.id))})}),qS=Cn.WidthProvider(Cn.Responsive),LS=S.observer(({view:t,className:e="layout"})=>{const n=de(),r=n.layouts.items(t.panelIDs),i=n.layouts.gridLayouts(t.panelIDs);return s.jsx(qS,{className:`dashboard-layout ${e}`,rowHeight:1,margin:[0,0],isDraggable:!1,isResizable:!1,cols:n.layouts.cols,layouts:i,breakpoints:n.layouts.breakpoints,onBreakpointChange:n.layouts.setCurrentBreakpoint,children:r.map(a=>s.jsx("div",{"data-grid":a.layoutProperies,className:"panel-grid-item",children:s.jsx(xi,{view:t,panel:a.panel})},a.id))})});function yi(t){const e=m.useRef(null);return{ref:e,downloadScreenshot:()=>{var i;const r=(i=e.current)==null?void 0:i.querySelector(".react-grid-layout");r&&t.downloadScreenshot(r)}}}const OS=S.observer(({downloadScreenshot:t})=>{const{t:e}=_.useTranslation(),[n,{setTrue:r,setFalse:i}]=N.useBoolean(!1),a=ka(),l=de(),c=()=>{const u=JSON.stringify(l.contentJSON,null,2),d=`${a.name}__${l.name}`;Jt(d,u)};return s.jsxs(o.Menu,{shadow:"md",width:200,trigger:"hover",openDelay:200,closeDelay:400,withinPortal:!0,position:"bottom-end",children:[s.jsx(o.Menu.Target,{children:s.jsx(o.Affix,{position:{bottom:"20px",right:"10px"},zIndex:1,children:s.jsx(o.ActionIcon,{size:"md",variant:"gradient",gradient:{from:"indigo",to:"cyan"},onMouseEnter:r,onMouseLeave:i,sx:{opacity:n?1:.6,transform:`translateX(${n?0:"2px"})`,transition:"all ease 300ms",borderRadius:"50%"},children:s.jsx(k.IconShare3,{size:"1rem"})})})}),s.jsxs(o.Menu.Dropdown,{children:[s.jsx(o.Menu.Item,{icon:s.jsx(k.IconCamera,{size:14}),onClick:t,children:e("common.actions.download_screenshot")}),s.jsx(o.Menu.Divider,{}),s.jsx(o.Menu.Item,{icon:s.jsx(k.IconDownload,{size:14}),onClick:l.queries.downloadAllData,children:e("common.actions.download_data")}),s.jsx(o.Menu.Item,{icon:s.jsx(k.IconCode,{size:14}),onClick:c,children:e("common.actions.download_schema")})]})]})}),uc=S.observer(({children:t,view:e,sx:n={}})=>{const{ref:r,downloadScreenshot:i}=yi(e);return s.jsxs(s.Fragment,{children:[s.jsx(o.Box,{ref:r,pt:10,pb:10,sx:n,children:t}),s.jsx(OS,{downloadScreenshot:i})]})}),dc=S.observer(({downloadScreenshot:t})=>s.jsx(o.ActionIcon,{className:"download-screenshot-button",color:"blue",onClick:t,children:s.jsx(k.IconCamera,{size:14})})),VS=S.observer(({children:t,view:e})=>{const n=de(),r=e.config,i=n.views.visibleViewIDs.includes(e.id),a=()=>n.views.rmVisibleViewID(e.id),{ref:l,downloadScreenshot:c}=yi(e);return s.jsx(o.Modal,{size:r.width,centered:!0,opened:i,onClose:a,withCloseButton:!1,title:s.jsxs(o.Group,{position:"apart",px:"1rem",h:"48px",children:[s.jsx(o.Box,{children:r.custom_modal_title.value}),s.jsx(dc,{downloadScreenshot:c})]}),trapFocus:!0,onDragStart:u=>{u.stopPropagation()},styles:{root:{position:"fixed",zIndex:200,inset:0},overlay:{zIndex:"unset"},inner:{zIndex:"unset",padding:"0 !important"},content:{border:"1px solid #efefef",maxHeight:"unset !important",overflow:"hidden"},body:{maxHeight:r.height,overflow:"auto",position:"relative",paddingBottom:10},header:{padding:0},title:{flexGrow:1}},transitionProps:{duration:0},children:s.jsx(o.Box,{ref:l,children:t})})}),NS=t=>t.color?{"&[data-active], &[data-active]:hover":{borderColor:t.color?t.color:"..."}}:{},GS=S.observer(({view:t})=>{const e=de(),n=t.config;return s.jsxs(o.Tabs,{className:"render-view-tabs",variant:n.variant,orientation:n.orientation,value:t.tab,onTabChange:t.setTab,styles:{root:{height:"100%",overflow:n.orientation==="horizontal"?"hidden":"auto"},panel:{padding:n.orientation==="horizontal"?"0px 0px 36px":"0",height:"100%",overflow:"auto"}},keepMounted:!1,children:[s.jsx(o.Tabs.List,{grow:n.grow,children:n.tabsInOrder.map(r=>s.jsx(o.Tabs.Tab,{value:r.id,sx:NS(r),disabled:!r.view_id,children:r.name??r.id},r.id))}),n.tabsInOrder.map(r=>{const i=e.views.findByID(r.view_id);return i?s.jsx(o.Tabs.Panel,{value:r.id,children:s.jsx(ds,{view:i})},r.id):null})]})}),FS=S.observer(({view:t,children:e})=>{switch(t.type){case q.Modal:return s.jsx(VS,{view:t,children:e});case q.Tabs:return s.jsx(GS,{view:t});case q.Division:default:return s.jsx(uc,{view:t,children:e})}}),WS=S.observer(({children:t,view:e})=>{const r=U().layouts,[i,a]=ie.useResizeObserver();return m.useEffect(()=>{r.setCurrentLayoutWrapperWidth(a.width)},[a.width]),s.jsx(o.Box,{sx:{height:"100%"},ref:i,children:s.jsx(o.Box,{sx:{paddingBottom:"100px",background:"white",margin:"0 auto",width:r.currentLayoutPreviewWidth??"100%",transform:`scale(${r.divisionPreviewScale})`,transformOrigin:"0 0"},children:s.jsx(uc,{view:e,sx:{paddingTop:"0px !important",".dashboard-sticky-area > form":{paddingBottom:"5px"},".dashboard-layout":{marginTop:0,marginBottom:0}},children:t})})})});function pc(t){return t.replace(/(vw|vh)/,"%")}const QS=S.observer(({children:t,view:e})=>{const n=e.config,{width:r,height:i}=m.useMemo(()=>({width:pc(n.width),height:pc(n.height)}),[n.width,n.height]),{ref:a,downloadScreenshot:l}=yi(e);return s.jsx(o.Box,{sx:{height:"100%","> div:not(.mantine-Modal-root)":{height:"100%"}},children:s.jsx(o.Modal,{size:n.width,opened:!0,onClose:x.noop,withCloseButton:!1,title:s.jsxs(o.Group,{position:"apart",px:"1rem",h:"48px",children:[s.jsx(o.Box,{children:n.custom_modal_title.value}),s.jsx(dc,{downloadScreenshot:l})]}),trapFocus:!0,onDragStart:c=>{c.stopPropagation()},styles:{root:{position:"relative",height:"100%"},overlay:{position:"absolute !important"},inner:{position:"relative",top:"50%",left:"50%",right:"unset",bottom:"unset",transform:"translate(-50%, -50%)",padding:"0 !important",width:r,height:i,maxHeight:i},content:{border:"1px solid #efefef",height:"100%"},body:{maxHeight:"calc(100% - 48px)",overflow:"auto"},header:{padding:0},title:{flexGrow:1}},withinPortal:!1,transitionProps:{duration:0},children:s.jsx(o.Box,{ref:a,children:t})})})}),RS=({variant:t,orientation:e})=>{const n={root:{height:"100%",overflow:"hidden"},tabsList:{backgroundColor:"white"},tab:{},panel:{padding:"16px"}};return t==="pills"&&e==="horizontal"&&(n.tab.paddingTop="6px",n.tab.paddingBottom="6px"),e==="vertical"&&(n.tab["&.add-a-tab"]={paddingTop:"1px",paddingBottom:"1px"},n.tab["&.add-a-tab .mantine-Tabs-tabLabel"]={marginLeft:"auto",marginRight:"auto"}),n},US=t=>t.color?{"&[data-active], &[data-active]:hover":{borderColor:t.color?t.color:"..."}}:{},YS=S.observer(({view:t})=>{const{t:e}=_.useTranslation(),n=Le.useModals(),r=U(),i=m.useMemo(()=>r.views.options.filter(u=>u.type===q.Division),[t.id,r.views.options]),a=t.config,l=u=>n.openConfirmModal({title:`${e("view.component.tabs.tab.delete")}?`,labels:{confirm:e("common.actions.confirm"),cancel:e("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{a.removeTab(u)},confirmProps:{color:"red"},zIndex:320}),c=a.tabs.length===0;return s.jsxs(o.Tabs,{className:"preview-view-tabs",variant:a.variant,orientation:a.orientation,value:t.tab,onTabChange:t.setTab,styles:RS(a),children:[s.jsxs(o.Tabs.List,{grow:a.grow,children:[a.tabsInOrder.map(u=>s.jsx(o.Tabs.Tab,{value:u.id,sx:US(u),children:u.name??u.id},u.id)),s.jsx(o.Tabs.Tab,{onClick:a.addTab,value:"add",className:"add-a-tab",children:s.jsx(B.Plus,{size:18,color:"#228be6"})})]}),a.tabsInOrder.map((u,d)=>{const p=r.views.findByID(u.view_id);return s.jsxs(o.Tabs.Panel,{value:u.id,sx:{position:"relative"},children:[s.jsxs(o.Box,{sx:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:200},children:[s.jsx(o.Overlay,{opacity:.8,color:"#FFF",blur:10,zIndex:100}),s.jsxs(o.Stack,{mx:"auto",mt:100,sx:{width:"300px",position:"relative",zIndex:200},children:[s.jsx(o.TextInput,{label:e("view.component.tabs.tab.name"),required:!0,value:u.name,onChange:h=>u.setName(h.currentTarget.value)}),s.jsx(o.Select,{label:"View",value:u.view_id,onChange:u.setViewID,data:i}),s.jsx(o.NumberInput,{label:e("view.component.tabs.tab.order"),required:!0,value:u.order,onChange:h=>u.setOrder(h||0),min:0,max:1e3,step:1}),s.jsx(o.ColorInput,{label:e("view.component.tabs.tab.color"),value:u.color,onChange:u.setColor,disabled:a.variant!=="default"}),p&&s.jsx(o.Button,{mt:20,variant:"gradient",leftIcon:s.jsx(k.IconArrowsLeftRight,{size:18}),gradient:{from:"cyan",to:"indigo"},onClick:()=>r.views.setIDOfVIE(p.id),children:e("view.component.tabs.tab.switch_to_view",{name:p.name})}),s.jsx(o.Button,{mt:20,variant:"subtle",color:"red",onClick:()=>l(d),disabled:c,leftIcon:s.jsx(k.IconTrash,{size:14}),children:e("view.component.tabs.tab.delete")})]})]}),p&&s.jsx(ds,{view:p})]},u.id)})]})}),KS=S.observer(({view:t,children:e})=>{switch(t.type){case q.Modal:return s.jsx(QS,{view:t,children:e});case q.Tabs:return s.jsx(YS,{view:t});case q.Division:default:return s.jsx(WS,{view:t,children:e})}}),hc=S.observer(function({view:e}){const r=U().layouts.divisionPreviewScale!==1;return s.jsx(os.Provider,{value:{viewPanelInFullScreen:x.noop,inFullScreen:!1},children:s.jsx(o.Box,{className:"dashboard-view","data-enable-scrollbar":!0,sx:{background:r?"transparent":"#efefef"},children:s.jsx(KS,{view:e,children:s.jsxs(o.Box,{sx:{position:"relative"},children:[s.jsx(o.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:s.jsx(yl,{view:e})}),s.jsx(BS,{view:e})]})})})})}),ds=S.observer(function({view:e}){const{fullScreenPanelID:n,setFullScreenPanelID:r}=Aa(),{viewPanelInFullScreen:i,exitFullScreen:a,inFullScreen:l,fullScreenPanel:c}=cc(e,n,r);return s.jsx(os.Provider,{value:{viewPanelInFullScreen:i,inFullScreen:l},children:s.jsxs(o.Box,{className:"dashboard-view","data-enable-scrollbar":!0,sx:{height:e.type===q.Modal?"0 !important":"100%"},children:[l&&s.jsx(lc,{view:e,panel:c,exitFullScreen:a}),s.jsx(FS,{view:e,children:s.jsxs(o.Box,{sx:{position:"relative"},children:[!l&&s.jsx(o.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:s.jsx(yl,{view:e})}),!l&&s.jsx(LS,{view:e})]})})]})})});var mc=(t=>(t.Use="use",t.Edit="edit",t))(mc||{});const JS={[q.Division]:"Division",[q.Tabs]:"Tabs",[q.Modal]:"Modal"},fc={[q.Division]:"rgba(255, 0, 0, 0.2)",[q.Modal]:"rgba(0, 0, 0, 0.2)",[q.Tabs]:"rgba(255, 200, 100, 0.4)"},XS={[q.Division]:"#ff4000",[q.Modal]:"#000",[q.Tabs]:"#ffad18"};function ZS(t,e,n){f.addDisposer(t,f.addMiddleware(t,(r,i)=>{i(r,()=>{f.getType(r.context)===e&&r.type==="action"&&n(r.name,r.context)})}))}const gc=f.types.compose("FiltersModel",ci,f.types.model("FiltersModel",{previewValues:f.types.optional(f.types.frozen(),{})})).views(t=>({get idSet(){return new Set(t.current.map(e=>e.id))},get keySet(){return new Set(t.current.map(e=>e.key))},get options(){return t.current.map(e=>({label:e.label??e.id,value:e.id,_type:"filter"}))},get selects(){return t.current.filter(e=>e.type===he.Select).map(e=>({label:e.label??e.id,value:e.id}))},get keyLabelOptions(){return t.current.map(e=>({label:e.label??e.key,value:e.key}))},get sortedList(){return x.sortBy(t.current,e=>e.label.toLowerCase())}})).actions(t=>({replace(e){t.current=f.cast(e)},append(e){t.current.push(e)},appendMultiple(e){if(e.length===0)return;const n=e.filter(r=>!t.idSet.has(r.id));t.current.push(...n)},remove(e){t.current.splice(e,1)},removeByID(e){const n=t.current.findIndex(r=>r.id===e);n>=0&&t.current.splice(n,1)},updatePreviewValues(e){t.previewValues=e}})).actions(t=>{function e(){ZS(t.current,Zr,(n,r)=>{if(n==="setType"){const i=Ql(r.config.default_value,r.config);t.setValueByKey(r.key,i),t.updatePreviewValues({...t.previewValues,[r.key]:i})}})}return{afterCreate(){e()}}}),xc=di.views(t=>({get canPreviewData(){return t.isTransform?t.dep_query_ids.length>0&&!!t.pre_process:!!t.datasource},get guideToPreviewData(){return t.isTransform?"Need to complete settings in Transform tab":"Need to pick a Data Source first"}})),yc=f.types.compose("QueriesModel",pi,f.types.model({current:f.types.optional(f.types.array(xc),[])})).views(t=>({get options(){const e=t.current.map(n=>({value:n.id,label:n.name,_type:"query"}));return x.sortBy(e,n=>n.label.toLowerCase())},get optionsWithoutTransform(){const e=t.current.filter(n=>n.type!==ce.Transform).map(n=>({value:n.id,label:n.name,_type:"query"}));return x.sortBy(e,n=>n.label.toLowerCase())},get sortedList(){return x.sortBy(t.current,e=>e.name.toLowerCase())}})).actions(t=>({replace(e){t.current=f.cast(e)},append(e){t.current.push(e)},appendMultiple(e){if(e.length===0)return;const n=e.filter(r=>!t.idSet.has(r.id));t.current.push(...n)},remove(e){t.current.splice(e,1)},replaceByIndex(e,n){t.current.splice(e,1,n)},removeQuery(e){const n=t.current.find(r=>r.id===e);n&&(f.detach(n),t.current.remove(n))},removeQueries(e){const n=new Set(e);t.current.forEach(i=>{n.has(i.id)&&f.detach(i)});const r=[...t.current];x.remove(r,i=>n.has(i.id)),t.current=f.cast(r)}})),bc=mi.views(t=>({get sortedList(){return x.sortBy(t.current,e=>e.key.toLowerCase())},get options(){const e=t.current.map(n=>({label:n.key,value:n.key,_type:"sql_snippet"}));return x.sortBy(e,n=>n.label.toLowerCase())}})).actions(t=>({replace(e){t.current=f.cast(e)},append(e){t.current.push(e)},appendMultiple(e){if(e.length===0)return;const n=e.filter(r=>!t.keySet.has(r.key));t.current.push(...n)},remove(e){t.current.splice(e,1)},removeByKey(e){const n=t.current.findIndex(r=>r.key===e);n>=0&&t.current.splice(n,1)},removeByKeys(e){const n=new Set(e);t.current.forEach(i=>{n.has(i.key)&&f.detach(i)});const r=[...t.current];x.remove(r,i=>n.has(i.key)),t.current=f.cast(r)},replaceByIndex(e,n){t.current.splice(e,1,n)}})),HS=f.types.model({data:f.types.optional(f.types.frozen(),[]),state:f.types.optional(f.types.enumeration(["idle","loading","error"]),"idle"),error:f.types.frozen()}).views(t=>({get loading(){return t.state==="loading"},get empty(){return t.data.length===0}})),ek=f.types.model({data:f.types.optional(f.types.frozen(),[]),state:f.types.optional(f.types.enumeration(["idle","loading","error"]),"idle"),error:f.types.frozen()}).views(t=>({get loading(){return t.state==="loading"},get empty(){return t.data.length===0}})),tk=f.types.model({page:f.types.optional(f.types.number,1),limit:f.types.optional(f.types.number,20),data:f.types.optional(f.types.frozen(),[]),total:f.types.optional(f.types.number,0),state:f.types.optional(f.types.enumeration(["idle","loading","error"]),"idle"),error:f.types.frozen()}).views(t=>({get keywords(){return f.getParent(t,1)},get keywordString(){const{table_name:e,table_schema:n}=f.getParent(t,1);return`${n}||${e}`}})).views(t=>({get loading(){return t.state==="loading"},get empty(){return t.data.length===0},get maxPage(){return Math.ceil(t.total/t.limit)},get offset(){return(t.page-1)*t.limit},get countSql(){const{table_name:e,table_schema:n}=t.keywords;return`
446
446
  SELECT count(*) AS total
447
447
  FROM ${n}.${e}
448
- `}})).actions(t=>({setPage(e){t.page=e},resetPage(){t.page=1},setLimit(e){t.limit=e}})).actions(t=>({afterCreate(){f.addDisposer(t,K.reaction(()=>t.keywordString,t.resetPage,{fireImmediately:!1,delay:0})),f.addDisposer(t,K.reaction(()=>t.limit,t.resetPage,{fireImmediately:!1,delay:0}))}})),nk=f.types.model({data:f.types.optional(f.types.frozen(),{}),state:f.types.optional(f.types.enumeration(["idle","loading","error"]),"idle"),error:f.types.frozen()}).views(t=>({get loading(){return t.state==="loading"},get empty(){return Object.keys(t.data).length===0}})),sk=f.types.compose("DataSourceModel",ni,f.types.model({tables:f.types.optional(nk,{}),columns:f.types.optional(HS,{}),tableData:f.types.optional(tk,{}),indexes:f.types.optional(ek,{}),table_schema:f.types.optional(f.types.string,""),table_name:f.types.optional(f.types.string,"")})).views(t=>({get sqlDataSourceType(){return t.type},get reloadConditionString(){const{type:e,table_name:n,table_schema:r}=t;return`${e};${n};${r}`}})).volatile(()=>({controllers:{tables:new AbortController,columns:new AbortController,indexes:new AbortController,tableData:new AbortController}})).actions(t=>({setKeywords(e,n){t.table_schema=e,t.table_name=n}})).actions(t=>({initKeywords(){if(t.tables.empty)return;const e=Object.keys(t.tables.data)[0],n=t.tables.data[e][0].table_name;t.setKeywords(e,n)}})).actions(t=>{const e=f.flow(function*(){var n;(n=t.controllers.tables)==null||n.abort(),t.controllers.tables=new AbortController,t.tables.state="loading";try{const r=yield*f.toGenerator(et.structure(t.controllers.tables.signal)({query_type:"TABLES",type:t.sqlDataSourceType,key:t.key,table_schema:"",table_name:""},{params:{query_type:"TABLES"}}));t.tables.data=x.groupBy(r,"table_schema"),t.tables.state="idle",t.tables.error=null,t.initKeywords()}catch(r){if(!at.isCancel(r)){t.tables.data={};const i=x.get(r,"message","unkown error");t.tables.error=x.get(r,"response.data.detail.message",i),t.tables.state="error"}}});return{loadTables:e,loadTablesIfEmpty(){t.tables.empty&&e()},loadColumns:f.flow(function*(){var n;(n=t.controllers.columns)==null||n.abort(),t.controllers.columns=new AbortController,t.columns.state="loading";try{t.columns.data=yield*f.toGenerator(et.structure(t.controllers.columns.signal)({query_type:"COLUMNS",type:t.sqlDataSourceType,key:t.key,table_schema:t.table_schema,table_name:t.table_name},{params:{query_type:"COLUMNS"}})),t.columns.state="idle",t.columns.error=null}catch(r){if(at.isCancel(r))t.columns.state="idle",t.columns.error=null;else{t.columns.data=[];const i=x.get(r,"message","unkown error");t.columns.error=x.get(r,"response.data.detail.message",i),t.columns.state="error"}}}),loadIndexes:f.flow(function*(){var n;(n=t.controllers.indexes)==null||n.abort(),t.controllers.indexes=new AbortController,t.indexes.state="loading";try{t.indexes.data=yield*f.toGenerator(et.structure(t.controllers.indexes.signal)({query_type:"INDEXES",type:t.sqlDataSourceType,key:t.key,table_schema:t.table_schema,table_name:t.table_name},{params:{query_type:"INDEXES"}})),t.indexes.state="idle",t.indexes.error=null}catch(r){if(at.isCancel(r))t.indexes.state="idle",t.indexes.error=null;else{t.indexes.data=[];const i=x.get(r,"message","unkown error");t.indexes.error=x.get(r,"response.data.detail.message",i),t.indexes.state="error"}}}),loadTableData:f.flow(function*(){var r;(r=t.controllers.tableData)==null||r.abort(),t.controllers.tableData=new AbortController;const n=t.tableData;n.state="loading";try{n.data=yield*f.toGenerator(et.structure(t.controllers.tableData.signal)({query_type:"DATA",type:t.sqlDataSourceType,key:t.key,table_schema:t.table_schema,table_name:t.table_name,limit:n.limit,offset:n.offset},{params:{query_type:"DATA"}}));const[{total:i}]=yield*f.toGenerator(et.structure(t.controllers.tableData.signal)({query_type:"COUNT",type:t.sqlDataSourceType,key:t.key,table_schema:t.table_schema,table_name:t.table_name},{params:{query_type:"COUNT"}}));n.total=Number(i),n.state="idle",n.error=null}catch(i){if(at.isCancel(i))n.state="idle",n.error=null;else{n.data=[];const a=x.get(i,"message","unkown error");n.error=x.get(i,"response.data.detail.message",a),n.state="error"}}})}}).actions(t=>({afterCreate(){f.addDisposer(t,K.reaction(()=>t.reloadConditionString,t.loadColumns,{fireImmediately:!1,delay:500}))}})).actions(t=>({afterCreate(){f.addDisposer(t,K.reaction(()=>t.reloadConditionString,t.loadIndexes,{fireImmediately:!1,delay:500})),f.addDisposer(t,K.reaction(()=>`${t.reloadConditionString};limit:${t.tableData.limit};offset:${t.tableData.offset}`,t.loadTableData,{fireImmediately:!1,delay:0}))}})),rk=f.types.model("DataSourcesModel",{list:f.types.optional(f.types.array(sk),[])}).views(t=>({find({type:e,key:n}){return t.list.find(r=>r.key===n&&r.type===e)},get options(){return t.list.map(e=>({value:e.key,label:e.key}))}})).actions(t=>({replace(e){t.list.length=0,t.list.push(...e)}}));function Pt(t){return{label:t,value:t,_type:"ACTION",_action_type:t,Icon:null,children:null}}function ik(t){switch(t._type){case"GROUP":case"ACTION":return null;case"query_variables":return["_QUERY_VARS_"];case"mock_context":return["_MOCK_CONTEXT_"];case"filter":return["_FILTERS_",t.value];case"sql_snippet":return["_SQL_SNIPPETS_",t.value];case"query":return["_QUERIES_",t.value];case"view":return["_VIEWS_",t.value];case"panel":return t.parentID?["_VIEWS_",t.parentID,"_PANELS_",t.value]:(console.error("[getPathFromOption] parentID is required"),null)}}const ak=f.types.model("EditorModel",{path:f.types.optional(f.types.frozen(),[]),settings_open:f.types.optional(f.types.boolean,!1)}).views(t=>({get navOptions(){const{content:e}=f.getRoot(t),{filters:n,views:r,sqlSnippets:i,queries:a}=e;return[{label:"query_variable.labels",value:"_QUERY_VARS_",_type:"query_variables",Icon:k.IconVariable},{label:"mock_context.label",value:"_MOCK_CONTEXT_",Icon:k.IconCodeDots,_type:"mock_context"},{label:"filter.labels",value:"_FILTERS_",Icon:k.IconFilter,children:[Pt("_FILTERS_SETTINGS_"),...n.options,Pt("_Add_A_Filter_")],_type:"GROUP"},{label:"sql_snippet.labels",value:"_SQL_SNIPPETS_",Icon:k.IconCopy,children:[Pt("_SQL_SNIPPETS_SETTINGS_"),...i.options,Pt("_Add_A_SQL_SNIPPET_")],_type:"GROUP"},{label:"query.labels",value:"_QUERIES_",Icon:k.IconDatabase,children:[Pt("_QUERIES_SETTINGS_"),...a.options,Pt("_Add_A_QUERY_")],_type:"GROUP"},{label:"view.labels",value:"_VIEWS_",Icon:k.IconBoxMultiple,children:[...r.editorOptions,Pt("_Add_A_VIEW_")],_type:"GROUP"}]},isOptionActive(e,n){return e.length===0?!1:e[e.length-1]===n.value},isOptionOpened(e){const{path:n}=t;return n.length===0||!e.children||e.children.length===0?!1:n.includes(e.value)}})).actions(t=>({setPath(e){t.path=e},setSettingsOpen(e){t.settings_open=e}})).actions(t=>({open(e){t.setPath(e),t.setSettingsOpen(!0)},close(){t.setSettingsOpen(!1)},navigate(e){const n=ik(e);n&&t.setPath(n)}})),ok=f.types.compose("LayoutsModel",hi,f.types.model({currentLayoutWrapperWidth:f.types.optional(f.types.number,0)})).views(t=>({get divisionPreviewScale(){const e=t.currentLayoutPreviewWidth,n=t.currentLayoutWrapperWidth;return!e||!n||e<=n?1:n/e}})).actions(t=>({addALayoutItem(e){t.list.forEach(n=>{n.addNewLayout(e)})},duplicateLayoutItemsByPanelID(e,n){t.list.forEach(r=>{const i=r.findByPanelID(e);if(!i){console.error(`Can't find a layout item by panelID[${e}] in layoutSet[${r.name}]`);return}r.list.push({...i,id:lt.v4(),panelID:n,y:1/0})})},removeByPanelID(e){t.list.forEach(n=>{n.removeByPanelID(e)})},setCurrentLayoutWrapperWidth(e){t.currentLayoutWrapperWidth=e},addALayoutSet(e,n,r){const i=t.basisLayoutSet,a={id:e,name:n,breakpoint:r,list:i.json.list.map(l=>({...l,id:lt.v4()}))};t.list.push(a)},updateLayoutSetsInfo(e){const n=x.keyBy(t.list,"id");e.forEach(a=>{const l=n[a.id];if(l){l.setName(a.name),l.setBreakpoint(a.breakpoint),delete n[a.id];return}this.addALayoutSet(a.id,a.name,a.breakpoint)});const r=new Set(Object.keys(n)),i=r.size>0;r.forEach(a=>{const l=t.list.findIndex(c=>c.id===a);t.list.splice(l,1)}),i&&t.setCurrentBreakpoint("basis")},updateCurrentLayoutItem(e){t.currentLayoutSet.updateLayoutItem(e)},append(e){t.list.push(e)},appendMultiple(e){e.length!==0&&t.list.push(...e)},remove(e){t.list.splice(e,1)},removeByID(e){const n=t.list.findIndex(r=>r.id===e);n!==-1&&t.list.splice(n,1)},removeByIDs(e){e.forEach(n=>{this.removeByID(n)})}})),vc=oi.views(t=>({get realDataFieldOptions(){return t.queryIDs.length===0?[]:t.queries.map(e=>{const n=e.data;return n.length===0?[]:Object.keys(n[0]).map(i=>({label:i,value:`${e.id}.${i}`,group:e.name,disabled:!1}))}).flat()},get realQueryOptions(){return t.queryIDs.length===0?[]:t.queries.map(e=>({label:e.name,value:e.id,disabled:!1}))},queryOptions(e,n){const r=[...this.realQueryOptions];return e&&!r.find(i=>i.value===e)&&r.unshift({label:e,value:e,disabled:!0}),n&&r.unshift({label:"unset",value:"",disabled:!1}),r},dataFieldOptions(e,n,r){let i=[...this.realDataFieldOptions];if(r&&(i=i.filter(a=>a.group===r)),e&&!i.find(a=>a.value===e)){const a=E(e),l=t.queryByID(a.queryID);i.unshift({label:a.columnKey,value:e,group:l?l.name:a.queryID,disabled:!0})}return n&&i.unshift({label:"unset",value:"",group:"",disabled:!1}),i},explainDataKey(e){const{queryID:n,columnKey:r}=E(e),i=t.queries.find(a=>a.id===n);return i?{queryID:n,queryName:i.name,columnKey:r}:{queryID:n,queryName:null,columnKey:r}}})).actions(t=>({removeSelf(){f.getParent(t,2).removeByID(t.id)}})).actions(t=>({moveToView(e,n){f.getRoot(t).content.views.findByID(e).removePanelID(t.id),f.getRoot(t).content.views.findByID(n).appendPanelID(t.id),f.getRoot(t).editor.setPath(["_VIEWS_",n,"_PANELS_",t.id])}})),_c=f.types.compose("PanelsModel",li,f.types.model({list:f.types.optional(f.types.array(vc),[])})).views(t=>({get contentModel(){return f.getRoot(t).content},editorOptions(e,n){const r=t.panelsByIDs(n);r.length!==n.length&&console.warn(`Unfulfilled panels for View[${e}]`);const i=r.map(l=>({label:l.name,value:l.id,_type:"panel",parentID:e})),a="_Add_A_PANEL_";return i.push({label:a,value:a,_type:"ACTION",_action_type:a,parentID:e,Icon:null,children:null}),i}})).actions(t=>({replace(e){t.list=f.castToSnapshot(e)},append(e){t.list.push(e)},appendMultiple(e){e.length!==0&&t.list.push(...e)},remove(e){t.list.splice(e,1)},removeByID(e){const n=t.list.findIndex(r=>r.id===e);n!==-1&&t.list.splice(n,1)},removeByIDs(e){e.forEach(n=>{this.removeByID(n)})},duplicateByID(e){const n=t.list.find(i=>i.id===e);if(!n){console.error(new Error(`[duplicate panel] Can't find a panel by id[${e}]`));return}const r=new Date().getTime().toString();return t.list.push({...n.json,id:r,title:{...n.json.title}}),t.contentModel.layouts.duplicateLayoutItemsByPanelID(n.id,r),r},replaceByIndex(e,n){t.list.splice(e,1,n)}})),lk=ii.actions(t=>({getSchema(){const e=t.json,n=[],r=[];t.panels.forEach(l=>{const c=l.getSchema();n.push(c.panel),c.queries.length>0&&r.push(...c.queries)});const i=t.contentModel.layouts.jsonByPanelIDSet(new Set(t.panelIDs));return{views:[e],panels:n,definition:{queries:x.uniqBy(r,l=>l.id)},layouts:i,version:ft}},downloadSchema(){if(t.type===q.Tabs){console.error(new Error("Please choose a tab first"));return}const e=JSON.stringify(this.getSchema(),null,2),n=t.name;Jt(n,e)}})),jc=f.types.compose("ViewsModel",ai,f.types.model({current:f.types.optional(f.types.array(lk),[]),idOfVIE:f.types.string})).views(t=>({get isVIETheFirstView(){return t.current.length===0||!t.idOfVIE?!1:t.current[0].id===t.idOfVIE},get VIE(){return t.current.find(({id:e})=>e===t.idOfVIE)},get options(){return t.current.map(e=>({label:e.name,value:e.id,type:e.type}))},get editorOptions(){const e=f.getRoot(t).content.panels;return t.current.map(n=>({label:n.name,value:n.id,_type:"view",children:e.editorOptions(n.id,n.panelIDs)}))}})).actions(t=>({setIDOfVIE(e){t.idOfVIE=e,t.visibleViewIDs.length=0,t.visibleViewIDs.push(e)},replace(e){t.current.replace(e)},addANewView(e,n,r,i){t.current.push({id:e,name:n,type:r,config:i,panelIDs:[]})},append(e){t.current.push(e)},appendMultiple(e){e.length!==0&&t.current.push(...e)},remove(e){t.current.splice(e,1)},removeByID(e){const n=t.current.findIndex(a=>a.id===e);if(n===-1)return;const r=t.current[n];f.getRoot(t).content.panels.removeByIDs(r.panelIDs),t.current.splice(n,1)},replaceByIndex(e,n){t.current.splice(e,1,n)},addARandomNewView(){const e=new Date().getTime().toString();this.addANewView(e,q.Division,q.Division,{_name:q.Division}),this.setIDOfVIE(e)},removeVIE(){t.current.length!==1&&(this.removeByID(t.idOfVIE),this.setIDOfVIE(t.current[0].id))}}));function bi(t){const e=t.length>0?[t[0].id]:[],n=t.length>0?t[0].id:"";return{current:t.map(i=>{const{_name:a=i.type}=i.config;return{...i,config:{...i.config,_name:a},panelIDs:i.panelIDs}}),visibleViewIDs:e,idOfVIE:n}}const ck=f.types.model({id:f.types.string,name:f.types.string,dashboard_id:f.types.string,create_time:f.types.string,update_time:f.types.string,version:f.types.string,filters:gc,queries:yc,sqlSnippets:bc,views:jc,panels:_c,layouts:ok,mock_context:Gr,origin:f.types.maybe(f.types.frozen())}).views(t=>({get json(){return{id:t.id,name:t.name,create_time:t.create_time,update_time:t.update_time,dashboard_id:t.dashboard_id,content:{views:t.views.json,panels:t.panels.json,filters:t.filters.json,version:t.version,layouts:t.layouts.json,definition:{queries:t.queries.json,sqlSnippets:t.sqlSnippets.json,mock_context:t.mock_context.current}}}},get contentJSON(){return this.json.content},get filtersChanged(){const e="filters.current";return!x.isEqual(f.getSnapshot(x.get(t,e)),x.get(t.origin,e))},get queriesChanged(){const e="queries.current",n=f.getSnapshot(x.get(t,e)).map(r=>x.pick(r,["id","name","key","type","sql","run_by","react_to","pre_process","post_process","dep_query_ids"]));return!x.isEqual(n,x.get(t.origin,e))},get sqlSnippetsChanged(){const e="sqlSnippets.current";return!x.isEqual(f.getSnapshot(x.get(t,e)),x.get(t.origin,e))},get viewsChanged(){const e="views.current";return!x.isEqual(t.views.json,x.get(t.origin,e))},get panelsChanged(){const e="panels.list";return!x.isEqual(f.getSnapshot(x.get(t,e)),x.get(t.origin,e))},get layoutsChanged(){const e="layouts.list";return!x.isEqual(f.getSnapshot(x.get(t,e)),x.get(t.origin,e))},get mockContextChanged(){const e="mock_context.current";return!x.isEqual(x.get(t,e),x.get(t.origin,e))},get context(){const e=f.getParent(t).context.current;return{...t.mock_context.current,...e}},get payloadForSQL(){const e=f.getParent(t).globalSQLSnippets,n={context:this.context,filters:t.filters.values};return{...n,sql_snippets:xn(t.sqlSnippets.current,"key","value",n),global_sql_snippets:xn(e.list,"id","content",n)}},get payloadForViz(){const e=f.getParent(t).context.current;return{context:{...t.mock_context.current,...e},filters:t.filters.values}},get dashboardState(){return Ds(this.payloadForSQL)},getAdditionalQueryInfo(e){return{content_id:t.id,query_id:e,params:this.dashboardState}},get changed(){return this.filtersChanged||this.queriesChanged||this.sqlSnippetsChanged||this.viewsChanged||this.panelsChanged||this.layoutsChanged||this.mockContextChanged},get data(){return t.queries.current.map(({id:n,data:r})=>({id:n,data:r})).reduce((n,r)=>(n[r.id]=r.data,n),{})},getDataStuffByID(e){const n=t.queries.findByID(e);return n?{data:n.data,len:n.data.length,state:n.state,error:n.error}:{data:[],len:0,state:"idle",error:void 0}}})).views(t=>({get queriesUsage(){const e=t.panels.idMap,n=[];t.views.current.forEach(i=>{i.panelIDs.forEach(a=>{const l=e.get(a);if(!l)return;const c="panel",u=l.name,d=[{id:i.id,label:i.name}];l.queryIDs.forEach(p=>{n.push({id:a,queryID:p,type:c,type_label:"panel.label",label:u,views:d})})})});const r=t.views.idMap;return t.filters.current.filter(i=>!!x.get(i,"config.options_query_id")).forEach(i=>{n.push({type:"filter",type_label:"filter.label",id:i.id,queryID:x.get(i,"config.options_query_id"),label:i.label,views:i.visibleInViewsIDs.map(a=>{var l;return{id:a,label:((l=r.get(a))==null?void 0:l.name)??a}})})}),t.queries.current.forEach(i=>{i.isTransform&&i.dep_query_ids.forEach(a=>{n.push({type:"transform-query",type_label:"query.transform.full_label",id:i.id,queryID:a,label:i.name,views:[]})})}),x.groupBy(n,"queryID")},get hasUnusedQueries(){return t.queries.current.length>Object.keys(this.queriesUsage).length},findQueryUsage(e){return this.queriesUsage[e]??[]},get sqlSnippetsUsage(){const e=[];return t.queries.current.forEach(n=>{if(!n.typedAsSQL)return;x.uniq(n.sql.match(Mn.sqlSnippet)).forEach(i=>{e.push({queryID:n.id,sqlSnippetKey:i,queryName:n.name})})}),x.groupBy(e,"sqlSnippetKey")},get hasUnusedSQLSnippets(){return t.sqlSnippets.current.length>Object.keys(this.sqlSnippetsUsage).length},findSQLSnippetUsage(e){return this.sqlSnippetsUsage[e]??[]}})).actions(t=>({removeUnusedQueries(){const e=new Set(Object.keys(t.queriesUsage)),n=t.queries.current.filter(r=>!e.has(r.id)).map(r=>r.id);t.queries.removeQueries(n)},removeUnusedSQLSnippets(){const e=new Set(Object.keys(t.sqlSnippetsUsage)),n=t.sqlSnippets.current.filter(r=>!e.has(r.key)).map(r=>r.key);t.sqlSnippets.removeByKeys(n)},duplicatePanelByID(e,n){var i;const r=t.panels.duplicateByID(e);r&&((i=t.views.findByID(n))==null||i.appendPanelID(r))},removePanelByID(e,n){var r;t.panels.removeByID(e),t.layouts.removeByPanelID(e),(r=t.views.findByID(n))==null||r.removePanelID(e)},addANewPanel(e){var r;const n=lt.v4();t.panels.append(Fl(n)),(r=t.views.findByID(e))==null||r.appendPanelID(n),t.layouts.addALayoutItem(n)},applyJSONSchema(e){var h;const{views:n,panels:r,filters:i,definition:a={},layouts:l}=e,{queries:c,sqlSnippets:u,mock_context:d}=a,p=new Map;if(Array.isArray(r)){const g=r.map(y=>{const v=lt.v4();return p.set(y.id,v),{...y,id:v}});if(t.panels.appendMultiple(g),!Array.isArray(n)||n.length===0){const y=g.map(v=>v.id);(h=t.views.VIE)==null||h.appendPanelIDs(y)}}if(Array.isArray(n)){const g=n.map(y=>{const v=y.panelIDs.map(C=>p.get(C)??C);return{...y,id:lt.v4(),panelIDs:v}});t.views.appendMultiple(g)}if(Array.isArray(l)){const g=(C,T)=>t.layouts.breakpointNameRecord[C]===T;let y=[];const v=l.filter(C=>g(C.name,C.breakpoint));v.forEach(C=>{C.id==="basis"&&(y=C.list),C.list.forEach(T=>{const D=p.get(T.panelID);T.id=lt.v4(),T.panelID=D})}),t.layouts.list.forEach(C=>{const T=v.find(D=>D.name===C.name&&D.breakpoint===C.breakpoint);if(!T){y.forEach(D=>{C.addLayout(D)});return}T.list.forEach(D=>{C.addLayout(D)})})}Array.isArray(i)&&t.filters.appendMultiple(i),Array.isArray(c)&&t.queries.appendMultiple(c),Array.isArray(u)&&t.sqlSnippets.appendMultiple(u),d&&Object.keys(d).length>0&&t.mock_context.defaults(d)}})).actions(t=>({reset(){f.applySnapshot(t.filters.current,t.origin.filters.current),f.applySnapshot(t.queries.current,t.origin.queries.current),f.applySnapshot(t.sqlSnippets.current,t.origin.sqlSnippets.current),f.applySnapshot(t.views.current,t.origin.views.current),f.applySnapshot(t.panels.list,t.origin.panels.list),f.applySnapshot(t.layouts.list,t.origin.layouts.list),t.mock_context.current=t.origin.mock_context.current},resetFilters(){f.applySnapshot(t.filters.current,t.origin.filters.current)},updateCurrent(e){const{id:n,name:r,content:i}=e;if(!i)throw new Error("unexpected null content when updating a content model");const{version:a,filters:l,views:c,panels:u,definition:{queries:d,sqlSnippets:p,mock_context:h={}}}=i;t.id=n,t.name=r,t.version=a,f.applySnapshot(t.filters.current,l),f.applySnapshot(t.views.current,bi(c).current),f.applySnapshot(t.panels.list,u),f.applySnapshot(t.queries.current,d),f.applySnapshot(t.sqlSnippets.current,p),t.mock_context.current=h}})),vi=f.types.snapshotProcessor(ck,{preProcessor(t){return{...t,origin:t}},postProcessor(t){delete t.origin;const e=f.castToSnapshot(t.queries.current.map(n=>x.pick(n,["id","key","type","sql"])));return x.defaults({},{queries:{current:e}},t)}});function uk(t,e){e.filters&&f.applySnapshot(t.filters.current,e.filters)}function wc({id:t,name:e,dashboard_id:n,create_time:r,update_time:i,content:a},l,c){if(!a)throw new Error("unexpected null content when creating a content model");const{version:u,filters:d,views:p,panels:h,layouts:g,definition:{queries:y,sqlSnippets:v,mock_context:C={}}}=a;return vi.create({id:t,name:e,dashboard_id:n,create_time:r,update_time:i,version:u,filters:ui(d,l,C,c),queries:{current:y},sqlSnippets:{current:v},mock_context:Fr(C),views:bi(p),panels:{list:h},layouts:{list:g,currentBreakpoint:g[0].id}})}const Cc=f.types.model({id:f.types.identifier,name:f.types.string,group:f.types.string,content:vi,content_id:f.types.string,datasources:rk,globalSQLSnippets:si,context:cs,editor:ak}).views(t=>({get json(){return{id:t.id,name:t.name,group:t.group,content_id:t.content_id}}})).actions(t=>({updateCurrentContent(e){t.content.updateCurrent(e)},updateCurrent(e,n){const{id:r,name:i,group:a,content_id:l}=e;t.id=r,t.name=i,t.group=a,t.content_id=l,this.updateCurrentContent(n)}}));function Sc({id:t,name:e,group:n,content_id:r},i,a,l,c,u){return Cc.create({id:t,name:e,group:n,content_id:r,content:wc(i,c,u),datasources:{list:a},globalSQLSnippets:{list:l},context:ri(c),editor:{}})}const dk={translation:{filter:{label:"Filter",labels:"Filters",add:"Add a Filter",manage:"Manage Filters",show_filters:"Show Filters",hide_filters:"Hide Filters",field:{widget:"Widget",visible_in:"Visible in...",key_placeholder:"A unique key to refer",label_placeholder:"Label for this field",auto_submit:"Submit automatically",order:"Placement Order",custom_default_value:{trigger:"Custom",title:"Custom default value",tips:"Tips",tip_1:"Function has the highest priority of getting filter's default value",tip_2:"Leave this editor empty to disable this feature"}},widget:{names:{select:"Select",multi_select:"Multi Select",tree_select:"Tree Select",text_input:"Text Input",checkbox:"Checkbox",date_range:"Date Range"},common:{use_query_data_as_options:"Use query data as options",fetch_options_from_datasource:"Fetch options from datasource",or_fetch_options_from_datasource:"Or fetch options from datasource",selector_option_empty:"Not found",see_data_structure:"Click to see expected data structure",using_query:"Using query",default_selection_count:"Select first N options by default",min_width:"Min width",x_selected:"{{count}} selected"},text_input:{default_value:"Default Value",required:"Required"},select:{width:"Width",required:"Required",clearable:"Clearable",configure_options:"Configure options",default_selection:"Default Selection",no_default_selection:"none",select_first_option_by_default:"Select the first option by default"},multi_select:{width_description:"At least 160px"},tree_select:{strictly:"Parent and children nodes are not associated"},checkbox:{description:"Description",default_checked:"Default checked"},date_range:{required:"Required",allow_single_date:"Allow choosing 1 day",display_format:"Display format",max_days:"Max days",one_day:"1 day",x_days:"{{count}} days",x_max_days:"{{max_days}} days max",default_value:"Default value",default_by_shortcut:"Default by shortcut",defualt_by_shortcut_placeholder:"Priors default value",start_date:"Start date",end_date:"End date",shortcut:{last:{label:"last",d:"yesterday",w:"week",m:"month",m2:"2 months",m3:"3 months",y:"year",full:{d:"yesterday",w:"last week",m:"last month",m2:"last 2 months",m3:"last 3 months",y:"last year"}},recent:{label:"recent",d7:"7 days",d30:"30 days",d60:"60 days",d90:"90 days",d180:"180 days",d365:"365 days",full:{d7:"recent 7 days",d30:"recent 30 days",d60:"recent 60 days",d90:"recent 90 days",d180:"recent 180 days",d365:"recent 365 days"}},this:{label:"this",d:"today",w:"week",m:"month",y:"year",full:{d:"today",w:"this week",m:"this month",y:"this year"}},this_so_far:{label:"this...so far",w:"week",m:"month",y:"year",full:{w:"this week so far",m:"this month so far",y:"this year so far"}}}}}},view:{label:"View",labels:"Views",add:"Add a View",delete:"Delete this View",download_schema:"Download this View",component:{div:{label:"Division"},tabs:{label:"Tabs",tabs_settings:"Tabs Settings",tab:{name:"Tab Name",view:"View",order:"Placement Order",color:"Color",delete:"Delete this tab",switch_to_view:"Swith to View: {{name}}"}},modal:{label:"Modal",modal_settings:"Modal settings",title:"Modal Title",custom_title:"Customize modal title",width:"Width",height:"Height"}}},interactions:{label:"Interactions",add:"Add an interaction",interactions_viewer:"Interactions Viewer",unavailable:"Unavailable",unavailable_reason:"This visualization does not have available interactions to choose from",trigger:{setup:"Setup Trigger",label:"Trigger",payload:"Payload"},operation:{setup:"Operation Settings",label:"Operation",settings:"Settings",variables:"Variables",console_log:{label:"console.log | debug",log_content:"log content"},open_link:{label:"Open Link",url:"URL",open_in_new_tab:"Open in new tab"},open_view:{label:"Open View",view:"View"},set_filter_values:{label:"Set Filter Values",set_filter:"Set filter",with:"with"},clear_filter_values:{label:"Clear Filter Values",select_filter:"Select filters to clear"}}},query_variable:{label:"Query Variable",labels:"Query Variables",add:"Add a Variable",guide:{tabs:{guide:"Guide",variables_in_this_dashboard:"Variables in this dashboard",global_sql_snippets:"Global SQL Snippets"}},open:"See Query Variables"},sql_snippet:{label:"SQL Snippet",labels:"SQL Snippets",add:"Add a SQL Snippet",delete:"Delete this SQL Snippet",delete_unused:"Delete unused SQL Snippets",manage:"Manage SQL Snippets",key:"Key",key_occupied:"This key is occupied by another snippet",edit_snippet:"Edit SQL Snippet",preview_snippet:"Preview SQL Snippet",usage:{label:"Usage"}},global_sql_snippet:{label:"Global SQL Snippet",labels:"Global SQL Snippets",description:"SQL snippets worth sharing between dashboards are managed in System Settings by admins."},common:{titles:{settings:"Settings",edit:"Edit",config:"Config"},pagination:{page_size:"Page Size",total:"Total",total_rows:"Total {{total}} row(s)"},align:{horizontal:{label:"Horizontal Align",left:"left",center:"center",right:"right"},vertical:{label:"Vertical Align",left:"top",center:"center",right:"bottom"}},id:"ID",name:"Name",key:"Key",label:"Label",value:"Value",type:"Type",info:"Info",min:"Min",max:"Max",data_field:"Data Field",name_data_field:"Name Data Field",value_data_field:"Value Data Field",color_data_field:"Color Data Field",enabled:"Enabled",copied:"Copied to clipboard",action:"Action",actions:{open:"Open",close:"Close",save:"Save",save_changes:"Save Changes",revert:"Revert",revert_changes:"Revert Changes",reset_to_default:"Reset to default",select_all:"Select All",clear_selection:"Clear Selection",refresh:"Refresh",download_data:"Download Data",download_schema:"Download Schema",download_screenshot:"Screenshot",enter_fullscreen:"Full Screen",duplicate:"Duplicate",delete:"Delete",cancel:"Cancel",confirm:"Confirm",add_an_option:"Add an Option",edit:"Edit",end_editing:"End editing <1>{{name}}</1>"},tabs:{variant:{label:"Variant",default:"Default",outline:"Outline",pills:"Pills"},orientation:{label:"Orientation",horizontal:"Horizontal",vertical:"Vertical"},grow_tabs:"Grow Tabs"},choose_a_tab_first:"Please choose a tab first"},breakpoint:{label_one:"Screen size",label_other:"Screen sizes",add:"Add a screen size",manage:"Manage screen sizes",breakpoint:"Min Width"},context:{label:"Context"},mock_context:{label:"Mock Context",hint:"A valid json string is required"},panel:{label:"Panel",labels:"Panels",add:"Add a Panel",delete:"Delete This Panel",panel_name:"Panel Name",panel_description:"Description",panel_description_click:"Click to see description",show_title:"Show title",use_name_as_title:"Use name as title",settings:{change_view:"Move into Another View",change_view_title:"Move panel into another view",choose_queries:"Choose queries",need_to_choose_queries:"Choose at least 1 query for its data"},style:{label:"Style",width:"Width",width_postfix:"of 36 columns",height:"Height",height_postfix:"px",border:"Border"},variable:{label:"Variable",labels:"Variables",add:"Add a Variable",delete:"Delete this Variable",aggregation:{label:"Aggregation",fallback_value:"Fallback Value",fallback_value_description:"Used when data is empty or the aggregation yields NaN"}}},style:{label:"Style",font_size:{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%..."},font_weight:{label:"Font Weight"},size:{xs:"xs",sm:"sm",md:"md",lg:"lg",xl:"xl"},flex:{justify_content:{label:"Justify Content",left:"Left",center:"Center",right:"Right",space_between:"Space Between",space_around:"Space Around",space_evenly:"Space Evenly"},align_items:{label:"Align Items",start:"Start",center:"Center",end:"End",stretch:"Stretch"}},color:{type:{label:"Color Type",static:"Static",interpolation:"Interpolation",none:"None"},interpolation:{setup:"Setup color interpolation",palette:{label:"Palette",category:{sequential:"Sequential",diverging:"Diverging"},red_green:"Red / Green",yellow_blue:"Yellow / Blue",red:"Red",green:"Green",blue:"Blue",orange:"Orange",mapping:{value_input_label:"Map a value to this color"}}}}},query:{label:"Query",labels:"Queries",add:"Add a Query",delete:"Delete this Query",cant_delete:"Can't delete this query for it's being used, check out Usage tab for details",delete_unused:"Delete unused queries",name:"Name",name_description:"A unique name",manage:"Manage Queries",open:"Open this query",configurations:"Configurations",basics:"Basics",conditions:"Conditions",run_by_condition:{label:"Run query when these are truthy",unset:"Always run this query on load"},re_run_condition:{label:"Re-run query when these changed",unset:"Leave it empty to never re-run this query"},dependency:{label:"Dependency",has_none:"This query has no dependency"},edit_sql:"Edit SQL",preview_sql:"Preview SQL",request:"Request",build_request:"Build Request",process_request:"Process Request",process_result:"Process Result",usage:{label:"Usage",in_views:"In View(s)",unused_description:"This query is not used by any filter or panel"},transform:{label:"Transform",full_label:"Transform Query",data_source:"Use other queries' data",guide:{pick_queries:"Pick queries for data input",write_function:"Write a function for making new data"}}},data:{label:"Data",preview_data:"Preview Data",empty_data:"Empty Data",requires_data:"Requires data"},data_source:{label:"Data Source",explore:"Explore Data Source",explorer:"Data Source Explorer",table_structure:"Table Structure",table_structure_short:"Structure",see_table_structure:"See Table Structure"},visualization:{label:"Visualization",component:"Visualization",label_short:"Viz"},numbro:{format:{label:"Format",absolute:"Absolute",absolute_description:"Non-negative",abbreviation:"Abbreviation",abbreviation_description:"like 1.23k, 1.23m",mantissa:"Mantissa",trim_mantissa:"Trim mantissa",trim_mantissa_description:"hide trailing zero(s)",preview:{open:"Open Preview",close:"Close Preview",input:"In",output:"Out"}}},import:{label:"Import...",title:"Import content with schema json",json_file:"JSON File",this_dashboard:"This dashboard",this_file:"This file"},function_utils:{trigger_text:"About parameter 'utils'",modal_title:"About FunctionUtils",description:"Parameter <code>utils</code> is <code>FunctionUtils</code>, which contains:",document:"Document"},aggregation:{option:{none:"None",sum:"Sum",mean:"Mean",median:"Median",min:"Min",max:"Max",cov:"Coefficient of Variation",std:"Standard Variation",quantile:{label:"Quantile",label_with_hint:"Quantile(99%, 95%, ...)"},custom:{label:"Custom",label_trigger:"Edit Function",title:"Custom Aggregation"}}},chart:{chart_config:"Chart Config",data_field:"Data Field",groups:{merico_suite:"Merico suite",echarts_based_charts:"ECharts-based charts",others:"Others"},label:{label:"Label",label_full:"Label",label_style:"Label Style",label_format:"Label Format"},label_position:{label:"Label Position",off:"Off",top:"Top",left:"Left",right:"Right",bottom:"Bottom",inside:"Inside",inside_top:"Inside Top",inside_left:"Inside Left",inside_center:"Inside Center",inside_right:"Inside Right",inside_bottom:"Inside Bottom",inside_top_left:"Inside Top Left",inside_top_right:"Inside Top Right",inside_bottom_left:"Inside Bottom Left",inside_bottom_right:"Inside Bottom Right",outside:"Outside"},visual_map:{label:"Visual Map",item_width:"Bar Width",item_height:"Bar Height",calculable:"Show drag handle",min_value:"Min Value",max_value:"Max Value",min_text:"Min Text",max_text:"Max Text",use_palette_x:'Use palette "{{x}}"',built_in_palettes:"Built-in Palettes",skip_range:{lt_min:"Color for smaller values than min value",min:"Color for min value",max:"Color for max value",gt_max:"Color for greater values than max value",follow_visual_map:"follow gradient rule"}},number_or_dynamic_value:{type:{static:"Static",dynamic:"Dynamic"},dynamic:{setup:"Setup",setup_title:"Setup dynamic value",guide:"Dyanmic by a custom function"}},orientation:{label:"Orientation",horizontal:"Horizontal",vertical:"Vertical"},symbol_size:{label:"Symbol Size",static:"Static",dynamic:"Dynamic",setup:{label:"Setup",title:"Setup dynamic size",description:"Dynamic by a custom function"}},series:{label:"Series",name:"Name",y_axis:"Y Axis",data_field:"Data Field",add:"Add a series",delete:"Delete this series",line:{label:"Line",line_settings:"Line Settings",line_style:"Line Style",type:{label:"Line Type",solid:"Solid",dashed:"Dashed",dotted:"Dotted"},line_width:"Line Width",step:{label:"Step",off:"Off",start:"Start",middle:"Middle",end:"End"},smooth_line:"Smooth Line",show_name_on_line:"Display Name on Line",show_symbol_on_line:"Show Symbol on Line"},bar:{label:"Bar",stack:"Stack",stack_hint:"Stack bars by this ID",bar_gap:{label:"Bar Gap",no_gap:"No gap between bars",overlap:"Bars overlapping on each other"},bar_width:{min:"Bar Width(min)",exact:"Bar Width",max:"Bar Width(max)"}},scatter:{label:"Scatter"},group_by:{label:"Split into multiple seires by this field...",label_line:"Split into multiple lines by this field..."}},axis:{tick_label:"Tick Label",customize_label:"Customize Label",overflow:{label:"Overflow",max_width:"Max Width",truncate:"Truncate",break_line:"Break Line",break_word:"Break Word",ellipsis:"Ellipsis",section_title:{on_axis:"Overflow on Axis",in_tooltip:"Overflow in Tooltip"}},section_title:{label_format:"Label Format"},type:{value:"Value",category:"Category",time:"Time",log:"Log",click_to_learn_more:"Click <1>here</1> to learn more about these options"}},name_text:{align:{label:"Name Anchor",left:"Left",center:"Center",right:"Right"}},rotate:"Rotate",degree:"degree",padding:"Padding",content_template:{label:"Content Template",hint:"Average: ${avg}"},x_axis:{label:"X Axis",labels:"X Axes",label_format:"Label Format",add:"Add an X Axis",delete:"Delete this X Axis",x_axis_name:"X Axis Name",x_axis_data_field:"X Axis Data Field",x_axis_type:"X Axis Type",layout:"Layout",position:{label:"Position",top:"Top",bottom:"Bottom"},value_range:"Value Range",value_min:"Min",value_max:"Max",behavior:"Behavior",visible:"Visible"},y_axis:{label:"Y Axis",labels:"Y Axes",label_format:"Label Format",add:"Add a Y Axis",delete:"Delete this Y Axis",y_axis_name:"Y Axis Name",y_axis_name_anchor:"Name Anchor",y_axis_data_field:"Y Axis Data Field",layout:"Layout",position:{label:"Position",left:"Left",right:"Right"},value_range:"Value Range",value_min:"Min",value_max:"Max",behavior:"Behavior",visible:"Visible"},stats:{label:"Stats",template:{above_chart:"Template for stats above the chart",under_chart:"Template for stats under the chart"}},legend:{label:"Legend",show_legend:"Show Legend",show_in_legend:"Show in legend",hide_in_legend:"Hide in legend",orientation:{label:"Orientation",horizontal:"Horizontal",vertical:"Vertical"}},tooltip:{label:"Tooltip",additional_metrics:{description:"Set additional metrics to show in scatter's tooltip",add:"Add a metic",delete:"Delete this Metric"},trigger:{label:"Trigger",scatter_point:"Scatter Point",x_axis:"X Axis"}},style:{label:"Style"},color:{label:"Color",or:"or",set_any_color:"Set any color",pick_a_theme_color:"Pick a theme color",background_color:"Background Color",text_color:"Text Color",click_to_add_a_color:"Click to add a color",color_gradient:"Color Gradient"},behavior:{label:"Behavior",invisible:"Invisible"},heatmap:{heatblock:{label:"Heat Block",show_label:"Show Label"}},reference_line:{label:"Reference Line",labels:"Reference Lines",add:"Add a reference line",name_placeholder:"Average Reference Line",delete:"Remove this Reference Line",orientation:{vertical_hint:"Works only when xAxis values are numbers"}},regression_line:{label:"Regression Line",labels:"Regression Lines",add:"Add a line",delete:"Delete this line",method:{label:"Method",linear:"Linear",exponential:"Exponential",logistic:"Logistic",polynomial:"Polynomial",polynomial_order:"Order"}},reference_area:{label:"Reference Area",labels:"Reference Areas",add:"Add a reference area",delete:"Remove this reference area",type:{label:"Type",rectangle:"Rectangle"},direction:{label:"Direction",horizontal:"Horizontal"},boundary:{upper:"Upper Boundary",lower:"Lower Boundary"},content:{label:"Content",content_text:"Content Text",text_position:"Text Position"},endpoint:{labels:"Endpoints",left_bottom_point:"Left-Bottom Point",right_top_point:"Right-Top Point"}},zooming:{label:"Zooming",scroll:{label:"Scroll to zoom",x_axis:"Enable on X Axis",y_axis:"Enable on Y Axis"},slider:{label:"Slider for zooming",x_axis:"Slider for X Axis",y_axis:"Slider for Y Axis",y_axis_disabled:"Not available for now, will overlap y-axis's label"}}},viz:{viz_config_banner:"Visualization Settings"},validation:{number:{require_a_number:"A number is required"}}}},pk={translation:{filter:{label:"筛选器",labels:"筛选器",add:"新增筛选器",manage:"管理筛选器",show_filters:"展开筛选器",hide_filters:"收起筛选器",field:{widget:"控件",visible_in:"在...视图中可见",key_placeholder:"用于引用此筛选器,需保持唯一",label_placeholder:"用于展示的标签文案",auto_submit:"自动提交",order:"排列次序",custom_default_value:{trigger:"自定义",title:"自定义默认值",tips:"提示",tip_1:"在指定筛选器默认值这事上,自定义函数具备最高优先级",tip_2:"清空下方编辑器来禁用本功能"}},widget:{names:{select:"单选",multi_select:"多选",tree_select:"树形选择器",text_input:"文本框",checkbox:"勾选框",date_range:"日期范围"},common:{use_query_data_as_options:"使用所查数据为选项",fetch_options_from_datasource:"从数据源查选项",or_fetch_options_from_datasource:"或从数据源查选项",selector_option_empty:"无选项可用",see_data_structure:"点击查看期望的数据格式",using_query:"在用查询获取选项",default_selection_count:"默认选中前N项",min_width:"控件最小宽度",x_selected:"已选数:{{count}}"},text_input:{default_value:"默认值",required:"必填"},select:{width:"控件宽度",required:"必选",clearable:"可取消选择",configure_options:"配置选项",default_selection:"默认选项",no_default_selection:"无",select_first_option_by_default:"默认选中第一个选项"},multi_select:{width_description:"至少160px"},tree_select:{strictly:"枝叶节点不相关,各选各的"},checkbox:{description:"描述信息",default_checked:"默认勾选"},date_range:{required:"必选",allow_single_date:"允许选一天作为范围",display_format:"展示格式",max_days:"最大选择天数",one_day:"1天",x_days:"{{count}}天",x_max_days:"最多可选{{max_days}}天",default_value:"默认日期范围(具体)",default_by_shortcut:"默认日期范围(快捷方式)",defualt_by_shortcut_placeholder:"优先于左侧",start_date:"开始日期",end_date:"结束日期",shortcut:{last:{label:"过往整周期",d:"昨天",w:"周",m:"月",m2:"两个月",m3:"三个月",y:"年",full:{d:"昨天",w:"上周",m:"上个月",m2:"上两月",m3:"上三月",y:"去年"}},recent:{label:"最近",d7:"7天",d30:"30天",d60:"60天",d90:"90天",d180:"180天",d365:"365天",full:{d7:"近7天",d30:"近30天",d60:"近60天",d90:"近90天",d180:"近180天",d365:"近365天"}},this:{label:"当前整周期",d:"今天",w:"周",m:"月",y:"年",full:{d:"今天",w:"本周",m:"本月",y:"今年"}},this_so_far:{label:"至今",w:"周",m:"月",y:"年",full:{w:"本周至今",m:"本月至今",y:"本年至今"}}}}}},view:{label:"视图",labels:"视图",add:"新增视图",delete:"删除此视图",download_schema:"下载此视图描述文件",component:{div:{label:"内容"},tabs:{label:"标签页",tabs_settings:"标签页设置",tab:{name:"名称",view:"内容视图",order:"排列次序",color:"颜色",delete:"删除这个标签页",switch_to_view:"打开视图: {{name}}"}},modal:{label:"弹窗",modal_settings:"弹窗设置",title:"弹窗标题",custom_title:"自定义弹窗标题",width:"宽度",height:"高度"}}},interactions:{label:"交互",add:"新增交互",interactions_viewer:"纵览交互",unavailable:"不可用",unavailable_reason:"此可视化组件没有交互功能",trigger:{setup:"设置触发动作",label:"触发动作",payload:"触发时的参数"},operation:{setup:"操作设置",label:"操作",settings:"设置",variables:"变量",console_log:{label:"console.log | 调试用",log_content:"打印内容"},open_link:{label:"打开链接",url:"URL",open_in_new_tab:"在新标签页中打开"},open_view:{label:"唤出视图",view:"视图"},set_filter_values:{label:"设置筛选器值",set_filter:"将筛选器的值",with:"设为"},clear_filter_values:{label:"清除筛选器值",select_filter:"选择筛选器以清除其值"}}},query_variable:{label:"查询变量",labels:"查询变量",add:"新增变量",guide:{tabs:{guide:"使用指南",variables_in_this_dashboard:"本看板中的查询变量",global_sql_snippets:"全局SQL片段"}},open:"查看查询变量"},sql_snippet:{label:"SQL片段",labels:"SQL片段",add:"新增SQL片段",delete:"删除这个SQL片段",delete_unused:"删除未用到的SQL片段",manage:"管理SQL片段",key:"键",key_occupied:"此键已被其他SQL片段占用",edit_snippet:"编辑SQL片段",preview_snippet:"预览SQL片段",usage:{label:"使用情况"}},global_sql_snippet:{label:"全局SQL片段",labels:"全局SQL片段",description:"管理员负责在系统设置中维护全局SQL片段"},common:{titles:{settings:"设置",edit:"编辑",config:"配置"},pagination:{page_size:"页容量",total:"共",total_rows:"共 {{total}} 行"},align:{horizontal:{label:"水平对齐",left:"居左",center:"居中",right:"居右"},vertical:{label:"垂直对齐",left:"居上",center:"居中",right:"居下"}},id:"ID",name:"名称",key:"键",label:"标签",value:"值",type:"类型",info:"信息",min:"最小值",max:"最大值",data_field:"数据字段",name_data_field:"名称字段",value_data_field:"值字段",color_data_field:"颜色字段",enabled:"启用",copied:"已复制到剪切板",action:"操作",actions:{open:"打开",close:"关闭",save:"保存",save_changes:"保存改动",revert:"还原",revert_changes:"还原改动",reset_to_default:"重置为初始值",select_all:"全选",clear_selection:"撤销选择",refresh:"刷新",download_data:"下载数据",download_schema:"下载描述文件",download_screenshot:"下载截图",enter_fullscreen:"全屏",duplicate:"复制",delete:"删除",cancel:"取消",confirm:"确认",add_an_option:"新增选项",edit:"编辑",end_editing:"结束编辑 <1>{{name}}</1>"},tabs:{variant:{label:"风格",default:"默认",outline:"轮廓",pills:"胶囊"},orientation:{label:"朝向",horizontal:"水平",vertical:"垂直"},grow_tabs:"拉伸标签卡宽度"},choose_a_tab_first:"请先选择一个标签页"},breakpoint:{label_one:"屏幕尺寸",label_other:"屏幕尺寸",add:"新增屏幕尺寸",manage:"管理屏幕尺寸",breakpoint:"最小宽度"},context:{label:"上下文"},mock_context:{label:"模拟上下文",hint:"内容格式为JSON"},panel:{label:"卡片",labels:"卡片",add:"新增卡片",delete:"删除这个卡片",panel_name:"卡片名",panel_description:"卡片描述",panel_description_click:"点击查看卡片描述",show_title:"展示卡片标题",use_name_as_title:"使用卡片名作为标题",settings:{change_view:"移至另一个视图下",change_view_title:"移动此卡片至另一个视图下",choose_queries:"关联查询",need_to_choose_queries:"请关联至少一个查询以使用其数据"},style:{label:"样式",width:"宽",width_postfix:"之 36 栏",height:"高",height_postfix:"px",border:"边框"},variable:{label:"变量",labels:"变量",add:"新增变量",delete:"删除此变量",aggregation:{label:"聚合",fallback_value:"兜底值",fallback_value_description:"当数据为空或聚合结果非数字时,使用此兜底值"}}},style:{label:"样式",font_size:{label:"字号",placeholder:"10px, 1em, 1rem, 100%..."},font_weight:{label:"字重"},size:{xs:"特小",sm:"小",md:"中",lg:"大",xl:"特大"},flex:{justify_content:{label:"内容分布",left:"从左起",center:"居中",right:"从右起",space_between:"均匀分布,首尾顶格",space_around:"均匀分布,首尾留空一半",space_evenly:"均匀分布,首尾留空"},align_items:{label:"对齐位置",start:"起点对齐",center:"居中对齐",end:"末端对齐",stretch:"拉伸对齐"}},color:{type:{label:"颜色类型",static:"单色",interpolation:"插值取色",none:"无"},interpolation:{setup:"设置取色方案",palette:{label:"色板",category:{sequential:"单色渐变",diverging:"双色渐变"},red_green:"红 / 绿",yellow_blue:"黄 / 蓝",red:"红",green:"绿",blue:"蓝",orange:"橙",mapping:{value_input_label:"映射一个值到此颜色"}}}}},query:{label:"查询",labels:"查询",add:"新增查询",delete:"删除这个查询",cant_delete:"此查询在使用中,不能删除。请查看“使用情况”标签页以了解详情",delete_unused:"删除未用到的查询",name:"名称",name_description:"唯一名称",manage:"管理查询",open:"打开此查询",configurations:"配置",basics:"基本信息",conditions:"条件",run_by_condition:{label:"以下条件满足时,才运行本查询",unset:"看板加载时便运行本查询"},re_run_condition:{label:"当以下条件改变时,重新运行此查询",unset:"留空则永不重新运行此查询"},dependency:{label:"依赖",has_none:"此查询无依赖"},edit_sql:"编辑SQL",preview_sql:"预览SQL",request:"请求",build_request:"构造请求",process_request:"加工请求",process_result:"加工结果",usage:{label:"使用情况",in_views:"所在视图",unused_description:"此查询未被任何筛选器或卡片用到"},transform:{label:"查询变形",full_label:"查询变形",data_source:"基于其他查询的数据,加工出新数据",guide:{pick_queries:"选择一至多个查询作为数据输入",write_function:"编写函数,返回新数据"}}},data:{label:"数据",preview_data:"预览数据",empty_data:"无数据",requires_data:"请先关联查询"},data_source:{label:"数据源",explore:"查看数据源",explorer:"数据源查看器",table_structure:"数据表结构",table_structure_short:"表结构",see_table_structure:"查看数据表结构"},visualization:{label:"可视化",component:"可视化组件",label_short:"可视化"},numbro:{format:{label:"格式",absolute:"绝对值",absolute_description:"非负",abbreviation:"缩写",abbreviation_description:"如1.23k、1.23m",mantissa:"小数",trim_mantissa:"抹零",trim_mantissa_description:"省略末尾的零",preview:{open:"展开预览",close:"收起预览",input:"输入",output:"输出"}}},import:{label:"导入...",title:"自描述文件导入看板内容",json_file:"描述文件(JSON格式)",this_dashboard:"此看板",this_file:"此文件"},function_utils:{trigger_text:"关于utils参数",modal_title:"关于utils参数",description:"参数 <code>utils</code> 是 <code>FunctionUtils</code>,包含以下内容:",document:"文档"},aggregation:{option:{none:"无",sum:"和",mean:"平均值",median:"中位数",min:"最小值",max:"最大值",cov:"变异系数",std:"标准差",quantile:{label:"分位",label_with_hint:"分位(99%, 95%, ...)"},custom:{label:"自定义",label_trigger:"编写函数",title:"自定义聚合方式"}}},chart:{chart_config:"图表设置",data_field:"数据字段",groups:{merico_suite:"思码逸套件",echarts_based_charts:"基于ECharts的图表",others:"其他"},label:{label:"文案",label_full:"标签文案",label_style:"标签文案样式",label_format:"标签文案格式"},label_position:{label:"文案位置",off:"不显示文案",top:"上",left:"左",right:"右",bottom:"下",inside:"内",inside_top:"内-上",inside_left:"内-左",inside_center:"内-中",inside_right:"内-右",inside_bottom:"内-下",inside_top_left:"内-上-左",inside_top_right:"内-上-右",inside_bottom_left:"内-下-左",inside_bottom_right:"内-下-右",outside:"外"},visual_map:{label:"视觉映射",item_width:"长条的宽度",item_height:"长条的高度",calculable:"显示拖拽手柄",min_value:"最小值",max_value:"最大值",min_text:"最小值文案",max_text:"最大值文案",use_palette_x:'使用配色方案"{{x}}"',built_in_palettes:"内置配色方案",skip_range:{lt_min:"小于最小值时的颜色",min:"最小值的颜色",max:"最大值的颜色",gt_max:"大于最大值时的颜色",follow_visual_map:"颜色跟随渐变规则"}},number_or_dynamic_value:{type:{static:"具体值",dynamic:"动态值"},dynamic:{setup:"设置",setup_title:"设置动态值",guide:"由函数确定动态值"}},orientation:{label:"朝向",horizontal:"水平",vertical:"垂直"},symbol_size:{label:"标记点大小",static:"固定值",dynamic:"动态值",setup:{label:"设置",title:"设置动态值",description:"由函数确定动态值"}},series:{label:"系列",name:"名称",y_axis:"Y轴",data_field:"数据字段",add:"增加一个系列",delete:"删除这个系列",line:{label:"线",line_settings:"线段设置",line_style:"线条样式",type:{label:"类型",solid:"实线",dashed:"方虚线",dotted:"圆点虚线"},line_width:"线宽",step:{label:"阶梯状",off:"不启用",start:"在当前点拐弯",middle:"在当前点与下个点中间拐弯",end:"在下个点拐弯"},smooth_line:"平滑曲线",show_name_on_line:"显示标签文案",show_symbol_on_line:"显示标记点"},bar:{label:"柱",stack:"堆放",stack_hint:"此值相同的柱系列会堆叠在一起",bar_gap:{label:"柱间隔",no_gap:"柱子之间无间隔",overlap:"柱子可互相重叠"},bar_width:{min:"最大柱宽",exact:"柱宽",max:"最大柱宽"}},scatter:{label:"散点"},group_by:{label:"按此字段拆分为多个系列",label_line:"按此字段拆分为多条线"}},axis:{tick_label:"刻度文案",customize_label:"自定义文案",overflow:{label:"溢出",max_width:"最大宽度",truncate:"截断",break_line:"换行",break_word:"断词换行",ellipsis:"省略符",section_title:{on_axis:"轴刻度上文案的溢出",in_tooltip:"提示框中的文案溢出"}},section_title:{label_format:"文案格式"},type:{value:"数值轴",category:"类目轴",time:"时间轴",log:"对数轴",click_to_learn_more:"点击 <1>这里</1> 以进一步了解这些选项"}},name_text:{align:{label:"名称贴靠侧",left:"左",center:"中",right:"右"}},rotate:"旋转",degree:"度",padding:"内间距",content_template:{label:"内容模板",hint:"均值: ${avg}"},x_axis:{label:"X轴",labels:"X轴",label_format:"刻度文案格式",add:"增加一条X轴",delete:"删除这条X轴",x_axis_name:"X轴名称",x_axis_data_field:"X轴数据字段",x_axis_type:"X轴类型",layout:"布局",position:{label:"位置",top:"上",bottom:"下"},value_range:"值范围",value_min:"最小值",value_max:"最大值",behavior:"表现",visible:"可见"},y_axis:{label:"Y轴",labels:"Y轴",label_format:"刻度文案格式",add:"增加一条Y轴",delete:"删除这条Y轴",y_axis_name:"Y轴名称",y_axis_name_anchor:"名称贴靠侧",y_axis_data_field:"Y轴数据字段",layout:"布局",position:{label:"位置",left:"左",right:"右"},value_range:"值范围",value_min:"最小值",value_max:"最大值",behavior:"表现",visible:"可见"},stats:{label:"统计内容",template:{above_chart:"统计内容模板(图表上方)",under_chart:"统计内容模板(图表下方)"}},legend:{label:"图例",show_legend:"显示图例",show_in_legend:"显示在图例中",hide_in_legend:"不显示在图例中",orientation:{label:"布局朝向",horizontal:"横向",vertical:"纵向"}},tooltip:{label:"提示框",additional_metrics:{description:"在此设置更多指标,来展示在散点的提示框",add:"增加一个指标",delete:"删除这个指标"},trigger:{label:"触发者",scatter_point:"散点",x_axis:"X轴"}},style:{label:"样式"},color:{label:"颜色",or:"或",set_any_color:"输入色号",pick_a_theme_color:"选择一个主题色",background_color:"背景色",text_color:"文字颜色",click_to_add_a_color:"点击增加一个颜色",color_gradient:"颜色渐变"},behavior:{label:"表现",invisible:"隐藏不可见"},heatmap:{heatblock:{label:"热力块",show_label:"展示值文案"}},reference_line:{label:"参考线",labels:"参考线",add:"增加一条参考线",name_placeholder:"均值参考线",delete:"删除这条参考线",orientation:{vertical_hint:"仅当X轴值为数字时可绘制"}},regression_line:{label:"回归线",labels:"回归线",add:"增加一条回归线",delete:"删除这条回归线",method:{label:"方法",linear:"线性回归",exponential:"指数回归",logistic:"指数回归",polynomial:"多项式回归",polynomial_order:"次"}},reference_area:{label:"参考区域",labels:"参考区域",add:"增加一面参考区域",delete:"删除这面参考区域",type:{label:"形状",rectangle:"矩形"},direction:{label:"方向",horizontal:"水平"},boundary:{upper:"上边界",lower:"下边界"},content:{label:"内容",content_text:"内容文字",text_position:"文字位置"},endpoint:{labels:"端点",left_bottom_point:"左下点",right_top_point:"右上点"}},zooming:{label:"缩放",scroll:{label:"滚轮缩放",x_axis:"对X轴启用",y_axis:"对Y轴启用"},slider:{label:"滚动条缩放",x_axis:"对X轴启用",y_axis:"对Y轴启用",y_axis_disabled:"暂不可用,会与Y轴刻度文字重叠"}}},viz:{viz_config_banner:"可视化参数配置"},validation:{number:{require_a_number:"请填写一个数字"}}}},ps=rd.createInstance({debug:!1,fallbackLng:"en",interpolation:{escapeValue:!1},resources:{en:dk,zh:pk}}).use(id).use(_.initReactI18next);ps.init(),pl.forEach(t=>{var e;(e=t.translation)==null||e.forEach(n=>{ps.addResourceBundle(n.lang,"translation",{viz:n.resources},!0,!0)})});function kc({lang:t,children:e}){return m.useEffect(()=>{ps.changeLanguage(t)},[t]),s.jsx(_.I18nextProvider,{i18n:ps,children:e})}function Tc(t,e){m.useEffect(()=>{const n=r=>{console.log(r);const{viewID:i}=r.detail;if(!i){console.error(new Error("[Open View] Needs to pick a view first"));return}t.views.appendToVisibles(i),e&&t.views.setIDOfVIE(i)};return window.addEventListener("open-view",n),()=>{window.removeEventListener("open-view",n)}},[t,e]),m.useEffect(()=>{const n=r=>{console.log(r);const{dictionary:i,payload:a}=r.detail;if(!a||Object.keys(a).length===0){console.error(new Error("[Set Filter Values] payload is empty"));return}Object.entries(i).forEach(([l,c])=>{t.filters.setValueByKey(l,x.get(a,c))})};return window.addEventListener("set-filter-values",n),()=>{window.removeEventListener("set-filter-values",n)}},[t]),m.useEffect(()=>{function n(i){return Array.isArray(i)?[]:typeof i=="object"?{}:typeof i=="boolean"?!1:typeof i=="string"?"":typeof i=="number"?0:i}const r=i=>{console.log(i);const{filter_keys:a}=i.detail;a.forEach(l=>{const c=x.get(t.filters.values,l),u=n(c);console.log(`${l}: ${u}`),t.filters.setValueByKey(l,u)})};return window.addEventListener("clear-filter-values",r),()=>{window.removeEventListener("clear-filter-values",r)}},[t]),m.useEffect(()=>{const n=r=>{console.log(r);const{urlTemplate:i,openInNewTab:a,enableEncoding:l=!1,payload:c}=r.detail;if(!i){console.error(new Error("[Open Link] URL is empty"));return}function u(h){return x.cloneDeepWith(h,y=>{if(l&&typeof y=="string")return encodeURIComponent(y)})}const p=x.template(i||"")(u({...c,filters:t.payloadForSQL.filters,context:t.payloadForSQL.context}));window.open(p,a?"_blank":"_self","noopener")};return window.addEventListener("open-link",n),()=>{window.removeEventListener("open-link",n)}},[t])}function Dc(t){return m.useCallback(e=>e.provideValue(pe.pluginManager,t.pluginManager).provideValue(pe.vizManager,t.vizManager).provideValue(pe.colorManager,t.colorManager),[])}const mM="",hk=S.observer(({saveDashboardChanges:t})=>{const{t:e}=_.useTranslation(),n=Le.useModals(),r=U(),i=()=>{n.openConfirmModal({title:s.jsxs(o.Group,{position:"left",children:[s.jsx(k.IconAlertTriangle,{size:18,color:"red"}),s.jsx(o.Text,{children:"You are reverting changes"})]}),labels:{confirm:e("common.actions.confirm"),cancel:e("common.actions.cancel")},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:()=>r.reset(),zIndex:320,withCloseButton:!1})},a=r.changed;return s.jsxs(o.Group,{spacing:0,children:[s.jsx(o.Button,{color:"green",variant:"filled",size:"xs",leftIcon:s.jsx(k.IconDeviceFloppy,{size:18}),onClick:t,disabled:!a,sx:{borderTopRightRadius:0,borderBottomRightRadius:0},children:e("common.actions.save_changes")}),s.jsxs(o.Menu,{width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:320,disabled:!a,children:[s.jsx(o.Menu.Target,{children:s.jsx(o.ActionIcon,{variant:"default",disabled:!a,sx:{height:"30px",borderTopLeftRadius:0,borderBottomLeftRadius:0,svg:{fill:"rgb(173, 181, 189)",stroke:"none"}},children:s.jsx(k.IconCaretDown,{size:18})})}),s.jsx(o.Menu.Dropdown,{children:s.jsx(o.Menu.Item,{icon:s.jsx(k.IconRecycle,{size:14,color:"red"}),disabled:!a,onClick:i,children:e("common.actions.revert_changes")})})]})]})}),mk=S.observer(({saveDashboardChanges:t,onExit:e,headerSlot:n=null})=>{_.useTranslation();const r=H(),i=r.content.changed,a=()=>{e({hasChanges:i,dashboardId:r.id})};return s.jsx(o.Header,{height:60,px:"md",py:0,sx:{zIndex:299},children:s.jsxs(o.Group,{position:"apart",sx:{height:60,minWidth:"1000px",position:"relative"},children:[s.jsxs(o.Group,{children:[s.jsx(o.Button,{size:"xs",color:i?"red":"green",leftIcon:s.jsx(k.IconArrowLeft,{size:20}),onClick:a,children:s.jsx(o.Group,{spacing:4,children:s.jsxs(_.Trans,{i18nKey:"common.actions.end_editing",values:{name:r.name},children:["End Editing ",s.jsx(o.Text,{td:"underline",children:r.name})]})})}),s.jsx(hk,{saveDashboardChanges:t})]}),s.jsx(o.Group,{position:"right",sx:{flexGrow:1},children:n})]})})}),zc={height:"30px",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},fk=S.observer(()=>{var i;const{t}=_.useTranslation(),e=U(),n=((i=e.views.VIE)==null?void 0:i.type)===q.Tabs,r=()=>e.addANewPanel(e.views.idOfVIE);return n?s.jsx(o.Tooltip,{label:t("common.choose_a_tab_first"),children:s.jsx(o.Button,{variant:"outline",color:"gray",radius:0,size:"xs",leftIcon:s.jsx(k.IconPlaylistAdd,{size:20}),sx:{...zc,transform:"none !important"},children:t("panel.add")})}):s.jsx(o.Button,{variant:"outline",color:"blue",radius:0,size:"xs",onClick:r,leftIcon:s.jsx(k.IconPlaylistAdd,{size:20}),sx:{...zc,background:"rgb(231, 245, 255)"},children:t("panel.add")})}),gk=S.observer(({done:t})=>{var J,Q;const{t:e}=_.useTranslation(),r=U().layouts,i=m.useMemo(()=>({list:r.breakpointsInfo}),[r.breakpointsInfo]),{control:a,handleSubmit:l,watch:c,getValues:u,reset:d,formState:p}=b.useForm({defaultValues:i}),{fields:h,append:g,remove:y}=b.useFieldArray({control:a,name:"list",rules:{validate:F=>{if(console.log({values:F}),x.uniqBy(F,"breakpoint").length!==F.length)return"Screen sizes should be unique by min width"}}}),v=c("list"),C=h.map((F,Z)=>({...F,...v[Z]})),T=()=>{g({id:lt.v4(),name:"",breakpoint:""})},D=({list:F})=>{const Z=F.filter(ve=>Number.isFinite(ve.breakpoint));r.updateLayoutSetsInfo(Z),t()},I=u(),P=m.useMemo(()=>{const F={list:I.list.filter(Z=>!!Z.name&&Number.isFinite(Z.breakpoint))};return!x.isEqual(F,i)},[I,i]),W=(Q=(J=p.errors.list)==null?void 0:J.root)==null?void 0:Q.message;return s.jsx(s.Fragment,{children:s.jsxs("form",{onSubmit:l(D),children:[s.jsxs(o.Table,{fontSize:"sm",highlightOnHover:!0,withBorder:!0,sx:{tableLayout:"fixed"},children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"340px"},children:e("common.name")}),s.jsx("th",{style:{width:"160px"},children:e("breakpoint.breakpoint")}),s.jsx("th",{})]})}),s.jsxs("tbody",{children:[C.map((F,Z)=>s.jsxs("tr",{children:[s.jsx("th",{children:F.id==="basis"?F.name:s.jsx(b.Controller,{name:`list.${Z}.name`,control:a,render:({field:ve})=>s.jsx(o.TextInput,{size:"xs",label:"",required:!0,sx:{flex:1},...ve})})}),s.jsx("td",{children:F.id==="basis"?s.jsxs(o.Text,{ff:"monospace",children:[F.breakpoint,"px"]}):s.jsx(b.Controller,{name:`list.${Z}.breakpoint`,control:a,render:({field:ve})=>s.jsx(o.NumberInput,{size:"xs",label:"",required:!0,max:1e4,hideControls:!0,rightSection:s.jsx(o.Text,{color:"dimmed",children:"px"}),rightSectionProps:{style:{width:"30px"}},sx:{flex:1,fontFamily:"monospace"},styles:{input:{paddingRight:"30px"}},...ve})})}),s.jsx("td",{children:F.id!=="basis"&&s.jsx(o.ActionIcon,{mx:"auto",size:"xs",variant:"subtle",color:"red",onClick:()=>y(Z),children:s.jsx(k.IconTrash,{})})})]},F.id)),s.jsx("tr",{style:{backgroundColor:"transparent"},children:s.jsx("td",{colSpan:3,style:{padding:"0"},children:s.jsx(o.Tooltip,{label:e("breakpoint.add"),children:s.jsx(o.ActionIcon,{variant:"subtle",size:"md",color:"blue",onClick:T,sx:{width:"100%"},children:s.jsx(k.IconPlus,{size:18})})})})})]})]}),s.jsx(o.Text,{mt:6,ta:"right",size:"xs",color:"red",children:W??" "}),s.jsxs(o.Group,{mt:6,position:"apart",children:[s.jsx(o.Button,{color:"orange",size:"xs",onClick:()=>d(),leftIcon:s.jsx(k.IconRecycle,{size:18}),disabled:!P,children:e("common.actions.revert")}),s.jsx(o.Button,{color:"green",size:"xs",type:"submit",leftIcon:s.jsx(k.IconDeviceFloppy,{size:18}),disabled:!P,children:e("common.actions.save_changes")})]})]})})}),xk=S.observer(()=>{const{t}=_.useTranslation(),[e,{open:n,close:r}]=ie.useDisclosure(!1),i=U(),a=i.layouts.currentBreakpoint,l=i.layouts.currentLayoutRange,c=()=>{setTimeout(()=>{window.dispatchEvent(new Event("resize"))},32)},u=()=>{r(),c()};return s.jsxs(s.Fragment,{children:[s.jsxs(o.Group,{children:[s.jsxs(o.Menu,{withArrow:!0,withinPortal:!0,zIndex:320,trigger:"hover",children:[s.jsx(o.Menu.Target,{children:s.jsx(o.Button,{size:"xs",variant:"subtle",leftIcon:s.jsx(k.IconDevices,{size:16}),sx:{borderRadius:0},children:s.jsxs(o.Group,{spacing:6,children:[s.jsx(o.Text,{size:"xs",fw:"normal",children:l.name}),s.jsx(o.Text,{size:"xs",color:"#777",children:i.layouts.currentRangeText})]})})}),s.jsxs(o.Menu.Dropdown,{children:[i.layouts.breakpointRanges.map(d=>s.jsx(o.Menu.Item,{onClick:()=>i.layouts.setCurrentBreakpoint(d.id),disabled:a===d.id,children:s.jsxs(o.Group,{position:"apart",children:[s.jsx(o.Text,{size:"sm",children:d.name}),s.jsx(o.Text,{size:"xs",color:"dimmed",children:d.text})]})},d.id)),s.jsx(o.Menu.Divider,{}),s.jsx(o.Menu.Item,{color:"blue",icon:s.jsx(k.IconSettings,{size:14}),onClick:n,children:s.jsx(o.Text,{size:"sm",children:t("breakpoint.manage")})})]})]}),i.layouts.divisionPreviewScale<1&&s.jsx(o.Text,{size:"xs",color:"dimmed",children:wn(i.layouts.divisionPreviewScale).format({output:"percent",mantissa:0})})]}),s.jsx(o.Modal,{opened:e,onClose:u,title:t("breakpoint.label",{count:2}),withinPortal:!0,zIndex:320,size:600,closeOnClickOutside:!1,children:s.jsx(gk,{done:u})})]})}),Mc={height:"30px",borderRight:"none",borderTop:"none",borderLeft:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},yk=S.observer(()=>{var i;const{t}=_.useTranslation(),e=U(),n=((i=e.views.VIE)==null?void 0:i.type)===q.Tabs,r=()=>{var a;return(a=e.views.VIE)==null?void 0:a.downloadSchema()};return n?s.jsx(o.Tooltip,{label:t("common.choose_a_tab_first"),children:s.jsx(o.Button,{variant:"outline",color:"gray",radius:0,size:"xs",leftIcon:s.jsx(k.IconCode,{size:16}),sx:{...Mc,transform:"none !important"},children:t("view.download_schema")})}):s.jsx(o.Button,{variant:"outline",color:"blue",radius:0,size:"xs",onClick:r,leftIcon:s.jsx(k.IconCode,{size:16}),sx:{...Mc},children:t("view.download_schema")})}),hs=({headers:t,rows:e})=>s.jsxs(o.Table,{fontSize:"xs",highlightOnHover:!0,sx:{tableLayout:"fixed",fontFamily:"monospace"},children:[s.jsx("thead",{children:t}),s.jsx("tbody",{children:e})]}),bk=({content:t})=>{const{t:e}=_.useTranslation(),n=t.views;return!Array.isArray(n)||n.length===0?null:s.jsxs(o.Box,{children:[s.jsx(o.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:e("view.labels")}),s.jsx(hs,{headers:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"160px"},children:e("common.id")}),s.jsx("th",{children:e("common.name")}),s.jsx("th",{children:e("common.type")})]}),rows:n.map(r=>s.jsxs("tr",{children:[s.jsx("td",{children:r.id}),s.jsx("td",{children:r.name}),s.jsx("td",{children:e(`view.component.${r.type}.label`)})]},r.id))})]})},vk=({content:t})=>{const{t:e}=_.useTranslation(),n=t.filters;return!Array.isArray(n)||n.length===0?null:s.jsxs(o.Box,{children:[s.jsx(o.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:e("filter.labels")}),s.jsx(hs,{headers:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"160px"},children:e("common.id")}),s.jsx("th",{children:e("common.key")}),s.jsx("th",{children:e("common.label")})]}),rows:n.map(r=>s.jsxs("tr",{children:[s.jsx("td",{children:r.id}),s.jsx("td",{children:r.key}),s.jsx("td",{children:r.label})]},r.id))})]})},_k=({content:t})=>{const{t:e}=_.useTranslation(),n=t.panels;return!Array.isArray(n)||n.length===0?null:s.jsxs(o.Box,{children:[s.jsx(o.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:e("panel.labels")}),s.jsx(hs,{headers:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"160px"},children:e("common.id")}),s.jsx("th",{children:e("common.name")}),s.jsx("th",{children:e("visualization.component")})]}),rows:n.map(r=>s.jsxs("tr",{children:[s.jsx("td",{children:r.id}),s.jsx("td",{children:r.name}),s.jsx("td",{children:r.viz.type})]},r.id))})]})},jk=({content:t})=>{var r;const{t:e}=_.useTranslation(),n=(r=t.definition)==null?void 0:r.queries;return!Array.isArray(n)||n.length===0?null:s.jsxs(o.Box,{children:[s.jsx(o.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:e("query.labels")}),s.jsx(hs,{headers:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"160px"},children:e("common.id")}),s.jsx("th",{children:e("common.name")}),s.jsx("th",{style:{width:"140px"},children:e("common.type")}),s.jsx("th",{style:{width:"260px"},children:e("data_source.label")})]}),rows:n.map(i=>s.jsxs("tr",{children:[s.jsx("td",{children:i.id}),s.jsx("td",{children:i.name}),s.jsx("td",{children:i.type}),s.jsx("td",{children:i.key})]},i.id))})]})},wk=({content:t})=>{var r;const{t:e}=_.useTranslation(),n=(r=t.definition)==null?void 0:r.sqlSnippets;return!Array.isArray(n)||n.length===0?null:s.jsxs(o.Box,{children:[s.jsx(o.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:e("sql_snippet.labels")}),s.jsx(o.List,{size:"sm",pl:10,ff:"monospace",icon:s.jsx(k.IconPointFilled,{size:10}),children:n.map(i=>s.jsx(o.List.Item,{children:i.key},i.key))})]})},Ck=({content:t})=>{var r;const{t:e}=_.useTranslation(),n=Object.keys(((r=t.definition)==null?void 0:r.mock_context)??{});return n.length===0?null:s.jsxs(o.Box,{children:[s.jsx(o.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:e("mock_context.label")}),s.jsx(o.List,{size:"sm",pl:10,ff:"monospace",icon:s.jsx(k.IconPointFilled,{size:10}),children:n.map(i=>s.jsx(o.List.Item,{children:i},i))})]})},Sk=({content:t})=>t?s.jsxs(o.Box,{children:[s.jsx(o.Divider,{mt:20,mb:10,variant:"dashed"}),s.jsx(o.Text,{ta:"left",c:"dimmed",children:"Preview"}),s.jsxs(o.Stack,{children:[s.jsx(bk,{content:t}),s.jsx(vk,{content:t}),s.jsx(_k,{content:t}),s.jsx(jk,{content:t}),s.jsx(wk,{content:t}),s.jsx(Ck,{content:t})]})]}):null;function kk(t){if(t.target===null)throw new Error("FileReader failed with null result");if(typeof t.target.result!="string")throw new Error(`Unparsable file content of type: ${typeof t.target.result}`);let e=JSON.parse(t.target.result);if("content"in e&&(e=e.content),e.version!==ft)throw new Error("Schema version mismatch");return e}const Tk=S.observer(({onSuccess:t,stretchModal:e,shrinkModal:n})=>{var D,I;const{t:r}=_.useTranslation(),i=U(),{handleSubmit:a,formState:{errors:l},setValue:c,watch:u,setError:d,clearErrors:p}=b.useForm({defaultValues:{content:null}}),h=({content:P})=>{try{if(!P)throw new Error("please use a valid json file");i.applyJSONSchema(P),bt.showNotification({title:"Successful",message:"",color:"green"}),t()}catch(W){console.error(W),bt.showNotification({title:"Failed",message:W.message,color:"red"})}},[g,y]=m.useState(null);m.useEffect(()=>{if(!g)return;const P=new FileReader;P.readAsText(g,"UTF-8"),P.onload=W=>{try{const J=kk(W);c("content",J),p("content")}catch(J){console.error(J),d("content",{type:"custom",message:J.message})}},P.onabort=()=>console.log("🟨 abort"),P.onerror=()=>{P.error&&(console.error(P.error),d("content",{type:"custom",message:P.error.message}))}},[g]);const[v]=u(["content"]),C=!v,T=(D=l==null?void 0:l.content)==null?void 0:D.message;return m.useEffect(()=>{!v||T?n():e()},[v,T]),s.jsx(o.Box,{mx:"auto",sx:{position:"relative"},children:s.jsxs("form",{onSubmit:a(h),children:[s.jsx(o.FileInput,{label:r("import.json_file"),required:!0,value:g,onChange:y,error:(I=l==null?void 0:l.content)==null?void 0:I.message,sx:{maxWidth:500}}),T?s.jsx(o.Table,{fontSize:12,mt:10,children:s.jsxs("tbody",{children:[s.jsxs("tr",{children:[s.jsx("th",{children:r("import.this_dashboard")}),s.jsx("td",{children:ft})]}),s.jsxs("tr",{children:[s.jsx("th",{children:r("import.this_file")}),s.jsx("td",{style:{color:"red"},children:v==null?void 0:v.version})]})]})}):s.jsxs(s.Fragment,{children:[s.jsx(Sk,{content:v}),s.jsx(o.Group,{position:"right",my:"md",children:s.jsx(o.Button,{type:"submit",color:"green",disabled:C,children:r("common.actions.confirm")})})]})]})})}),Ic={height:"30px",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},Dk=S.observer(()=>{var d;const{t}=_.useTranslation(),[e,{open:n,close:r}]=ie.useDisclosure(!1),[i,{setTrue:a,setFalse:l}]=N.useBoolean(!1),u=((d=H().content.views.VIE)==null?void 0:d.type)===q.Tabs;return u?s.jsx(o.Tooltip,{label:t("common.choose_a_tab_first"),children:s.jsx(o.Button,{variant:"outline",color:"gray",radius:0,size:"xs",leftIcon:s.jsx(k.IconFileImport,{size:16}),sx:{...Ic,transform:"none !important"},children:t("import.label")})}):s.jsxs(s.Fragment,{children:[s.jsx(o.Button,{variant:"subtle",color:"blue",radius:0,size:"xs",disabled:u||e,onClick:n,leftIcon:s.jsx(k.IconFileImport,{size:16}),sx:{...Ic},children:t("import.label")}),s.jsx(o.Modal,{opened:e,onClose:r,title:t("import.title"),trapFocus:!0,onDragStart:p=>{p.stopPropagation()},withinPortal:!0,zIndex:320,size:i?"90vw":500,children:s.jsx(Tk,{onSuccess:r,stretchModal:a,shrinkModal:l})})]})}),zk={position:"fixed",top:60,left:0,right:0,height:30,zIndex:299,borderBottom:"1px solid #e9ecef",background:"rgba(233,236,239, 0.15)"},Mk=S.observer(()=>s.jsx(o.Box,{sx:zk,pl:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},children:s.jsxs(o.Group,{position:"apart",align:"center",sx:{height:"30px"},children:[s.jsxs(o.Group,{position:"left",spacing:0,children:[s.jsx(fk,{}),s.jsx(Dk,{})]}),s.jsx(xk,{}),s.jsx(o.Group,{position:"right",spacing:0,children:s.jsx(yk,{})})]})})),Ik=S.observer(t=>s.jsxs(s.Fragment,{children:[s.jsx(mk,{...t}),s.jsx(Mk,{})]})),fM="";function Ek(t,e,n){const r=[];return t.filter(i=>"__INTERACTIONS"in i.viz.conf).forEach((i,a)=>{const l=e[i.id];l.data.interactions=x.get(l,"data.interactions",[]);const{__INTERACTIONS:c,__OPERATIONS:u,__TRIGGERS:d}=i.viz.conf;Object.entries(u).forEach(([p,h])=>{const{schemaRef:g,data:y}=h,{config:v}=y;switch(g){case"builtin:op:open-link":let C=v.urlTemplate.substring(0,100);v.urlTemplate.length>=20&&(C+="..."),l.type="interaction",l.data.interactions.push({schemaRef:g,urlTemplate:v.urlTemplate,shortURLTemplate:C});return;case"builtin:op:open_view":r.push({id:`OPERATION--${p}`,source:i.id,target:v.viewID,label:"Open View",style:{stroke:"rgba(0,0,0,0.8)"},type:"default"});return;case"builtin:op:set_filter_values":l.type="interaction",l.data.interactions.push({schemaRef:g,filters:Object.keys(v.dictionary).map(T=>({key:T,label:n[T]}))});return;case"builtin:op:clear_filter_values":l.type="interaction",l.data.interactions.push({schemaRef:g,filters:v.filter_keys.map(T=>({key:T,label:n[T]}))});return;default:return}})}),r}function Ak(t,e){const n=t.filters.keyLabelMap;return{edges:Ek(t.panels.list,e,n),edgeNodes:[]}}function Ec(t,e,n){return t*e+t*n}function Pk(t,e,n){return t*e+(t-1)*n}const ms=25,_i=40,Ac=25,ji=350,$k=150,Bk=150,Pc=150,$c=300,fs=40,Bc=25,qk=300;function Lk(t,e){const n=x.keyBy(e,i=>i.id),r=[];return t.current.forEach((i,a)=>{i.panelIDs.forEach((l,c)=>{const u=Ec(c,fs,Bc)+_i,d=n[l];if(!d){r.push({id:l,_node_type:"panel",parentNode:i.id,data:{label:`!: ${l}`},position:{x:ms,y:u},sourcePosition:_e.Position.Right,targetPosition:_e.Position.Left,style:{width:$c,height:fs}});return}const p=d.name;r.push({id:d.id,_node_type:"panel",parentNode:i.id,data:{label:p},position:{x:ms,y:u},sourcePosition:_e.Position.Right,targetPosition:_e.Position.Left,style:{width:$c,height:fs}})})}),r}const Ok={[q.Division]:"Div",[q.Modal]:"Modal",[q.Tabs]:"Tabs"},Vk=fc;function Nk(t){return t.current.map((n,r)=>{const i=Pk(n.panelIDs.length,fs,Bc)+_i+Ac;let a=[];return n.type===q.Tabs&&(a=n.config.tabsInOrder.map(c=>c.view_id)),{id:n.id,_node_type:"view-root",_view_type:n.type,_view_level:0,_sub_view_ids:[],_tab_view_ids:a,data:{label:`${Ok[n.type]}:${n.name}`},position:{x:0,y:0},sourcePosition:_e.Position.Right,targetPosition:_e.Position.Left,className:"light",style:{backgroundColor:Vk[n.type],width:ji,height:i}}})}function Gk(t){const e=x.keyBy(t,n=>n.id);t.forEach(n=>{n._node_type!=="view-root"||n._view_type!==q.Tabs||n._tab_view_ids.forEach(r=>{e[r].parentNode=n.id})})}function Fk(t){const e=Nk(t.views);Gk(e);const n=Lk(t.views,t.panels.list);return[...e,...n]}function Wk({nodeMap:t,nodes:e,edges:n}){e.forEach(r=>{r._node_type!=="view-root"||r._view_type!==q.Tabs||(r.sourcePosition=_e.Position.Bottom,r.style.width=ji+ms*2,r.style.height=Ac+r._tab_view_ids.reduce((i,a)=>{const l=t[a];l.position.y=i,l.position.x=ms;const c=l.style.height;return i+c+20},_i))})}function Qk({nodeMap:t,nodes:e,edges:n}){n.filter(r=>r.label==="Open View").forEach(r=>{const i=t[r.source],a=t[r.target];if(!i||!a||!i.parentNode)return;const l=t[i.parentNode];l._node_type!=="view-root"||a._node_type!=="view-root"||(a._view_level+=1+l._view_level,l._sub_view_ids.push(a.id))}),e.sort((r,i)=>r._node_type==="view-root"&&i._node_type==="view-root"?r._view_level-i._view_level:r._node_type!=="view-root"&&i._node_type!=="view-root"?0:r._node_type==="view-root"?-1:1)}function Rk({nodeMap:t,nodes:e,edges:n}){const r={};n.forEach(i=>{if(i.label!=="Open View")return;const a=t[i.source],l=t[i.target];if(a&&l&&a.parentNode){const c=t[a.parentNode],u=c.position.x,d=Number(x.get(l,"style.height",0)),p=Number(c.style.width);l.position.x=u+p+qk,c._view_level===0&&l._sub_view_ids.length===0&&(a.sourcePosition=_e.Position.Left,l.targetPosition=_e.Position.Right,l.position.x*=-1);const g=l.position.x,y=x.get(r,g,0);l.position.y=y,r[g]=y+d+Pc}})}function Uk({nodeMap:t,nodes:e,edges:n}){const r=new Set,i=new Set;n.forEach(l=>{r.add(l.source),i.add(l.target)}),e.filter(l=>l._node_type!=="view-root"||l.id==="Main"||l.parentNode?!1:!r.has(l.id)&&!i.has(l.id)).forEach((l,c)=>{l.position.x=Ec(c,ji,Bk),l.position.y=0-$k-Pc})}function Yk({nodeMap:t,nodes:e,edges:n}){const r={nodeMap:t,nodes:e,edges:n};return Uk(r),Qk(r),Wk(r),Rk(r),{nodes:e,edges:n}}function Kk(t){const e=Fk(t),n=x.keyBy(e,u=>u.id),{edges:r,edgeNodes:i}=Ak(t,n),a=[...e,...i],l=x.keyBy(a,u=>u.id),c={edges:x.uniqBy(r,u=>u.id),nodes:a,nodeMap:l};return Yk(c)}const gM="",wi={"builtin:op:open-link":s.jsx(o.ThemeIcon,{color:"blue",size:20,radius:"xl",children:s.jsx(k.IconCircleDashed,{size:14})}),"builtin:op:set_filter_values":s.jsx(o.ThemeIcon,{color:"orange",size:20,radius:"xl",children:s.jsx(k.IconCircleDot,{size:14})}),"builtin:op:clear_filter_values":s.jsx(o.ThemeIcon,{color:"orange",size:20,radius:"xl",children:s.jsx(k.IconCircleOff,{size:14})})};function Jk(t){const e=[];return t.forEach(n=>{switch(n.schemaRef){case"builtin:op:open-link":e.push({key:n.urlTemplate,icon:wi[n.schemaRef],text:s.jsxs(o.Group,{spacing:4,children:[s.jsx(o.Text,{children:"Open: "}),s.jsx(o.Text,{color:"dimmed",children:n.shortURLTemplate})]})});return;case"builtin:op:set_filter_values":n.filters.forEach(({key:r,label:i})=>{e.push({key:n.schemaRef+r,icon:wi[n.schemaRef],text:s.jsx(o.Group,{spacing:4,children:s.jsxs(o.Text,{children:["Set Filter: ",i]})})})});return;case"builtin:op:clear_filter_values":n.filters.forEach(({key:r,label:i})=>{e.push({key:n.schemaRef+r,icon:wi[n.schemaRef],text:s.jsx(o.Group,{spacing:4,children:s.jsxs(o.Text,{children:["Clear Filter: ",i]})})})});return}}),e}const Xk=m.memo(({data:t,isConnectable:e,sourcePosition:n=_e.Position.Right,targetPosition:r=_e.Position.Left,...i})=>{const a=m.useMemo(()=>Jk(t.interactions),[t.interactions]);return s.jsxs(s.Fragment,{children:[s.jsx(_e.Handle,{type:"target",position:r,isConnectable:e}),s.jsx(o.Box,{sx:{position:"absolute",top:0,right:0},children:s.jsx(B.ChevronsUpRight,{size:12})}),s.jsxs(o.HoverCard,{shadow:"xl",withinPortal:!0,children:[s.jsx(o.HoverCard.Target,{children:s.jsx(o.Text,{children:t.label})}),s.jsx(o.HoverCard.Dropdown,{children:s.jsx(o.List,{spacing:"xs",size:"sm",center:!0,children:a.map(l=>s.jsx(o.List.Item,{icon:l.icon,children:l.text},l.key))})})]}),s.jsx(_e.Handle,{type:"source",position:n,isConnectable:e})]})}),xM="",Zk={interaction:Xk},Hk=S.observer(()=>{const t=de(),{edges:e,nodes:n}=Kk(t);return s.jsxs(_e,{nodes:n,edges:e,onNodesChange:x.noop,onEdgesChange:x.noop,onConnect:x.noop,className:"interactions-viewer",fitView:!0,nodeTypes:Zk,children:[s.jsx(_e.MiniMap,{}),s.jsx(_e.Controls,{}),s.jsx(_e.Background,{})]})}),eT=S.observer(({opened:t,close:e})=>{const{t:n}=_.useTranslation();return s.jsx(o.Modal,{size:"96vw",opened:t,onClose:e,title:n("interactions.interactions_viewer"),trapFocus:!0,onDragStart:r=>{r.stopPropagation()},styles:{body:{height:"calc(90vh - 54px)"},content:{transform:"none !important"}},zIndex:300,children:s.jsx(Hk,{})})}),tT={"> button":{"&:first-of-type":{borderTopRightRadius:0,borderBottomRightRadius:0,borderRightWidth:.5},":not(:first-of-type):not(:last-of-type)":{borderTopRightRadius:0,borderBottomRightRadius:0,borderTopLeftRadius:0,borderBottomLeftRadius:0,borderLeftWidth:.5,borderRightWidth:.5},"&:last-of-type":{borderTopLeftRadius:0,borderBottomLeftRadius:0,borderLeftWidth:.5}}};function nT({onClick:t,name:e,active:n,openSettings:r}){return s.jsxs(o.Box,{sx:{position:"relative"},children:[s.jsx(o.UnstyledButton,{sx:i=>({display:"block",width:"100%",padding:i.spacing.xs,borderRadius:0,position:"relative",color:i.black,"&:hover":{backgroundColor:i.colors.gray[0]},backgroundColor:n?i.colors.gray[2]:"transparent"}),children:s.jsx(o.Group,{sx:{width:"calc(100% - 28px)"},onClick:t,children:s.jsx(o.Text,{size:"sm",children:e})})}),n&&s.jsx(o.Tooltip,{label:"Edit",position:"right",withinPortal:!0,children:s.jsx(o.ActionIcon,{onClick:r,variant:"light",color:"blue",sx:{position:"absolute",top:0,bottom:0,height:"100%",right:0,zIndex:0,borderRadius:0},children:s.jsx(k.IconAdjustments,{size:16})})})]})}const sT=S.observer(()=>{const{t}=_.useTranslation(),e=H(),n=U(),r=m.useCallback(a=>()=>n.views.setIDOfVIE(a),[n]),i=a=>{e.editor.open(["_VIEWS_",a])};return s.jsxs(o.Box,{sx:{position:"relative"},children:[n.views.options.map(a=>s.jsx(nT,{active:n.views.idOfVIE===a.value,name:a.label,onClick:r(a.value),openSettings:()=>i(a.value)},a.value)),s.jsx(o.Divider,{variant:"dashed"}),s.jsx(o.Button,{variant:"subtle",rightIcon:s.jsx(k.IconPlus,{size:14}),size:"sm",px:"xs",color:"blue",onClick:n.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"space-between"}},children:t("view.add")})]})}),rT=S.observer(()=>{const{t}=_.useTranslation(),e=H(),n=U(),r=()=>{if(!n.queries.firstID){e.editor.open(["_QUERIES_",""]);return}e.editor.open(["_QUERIES_",n.queries.firstID])},i=()=>{if(!n.filters.firstID){e.editor.open(["_FILTERS_",""]);return}e.editor.open(["_FILTERS_",n.filters.firstID])},[a,l]=m.useState(!1),c=()=>l(!0),u=()=>l(!1);return s.jsxs(o.Navbar,{p:0,width:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},zIndex:299,children:[s.jsxs(o.Navbar.Section,{children:[s.jsxs(o.Group,{grow:!0,spacing:0,sx:{...tT,button:{borderWidth:0,borderBottomWidth:1,borderColor:"#e9ecef"}},children:[s.jsx(o.Tooltip,{label:t("filter.labels"),withinPortal:!0,children:s.jsx(o.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:i,children:s.jsx(k.IconFilter,{size:18})})}),s.jsx(o.Tooltip,{label:t("query.labels"),withinPortal:!0,children:s.jsx(o.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:r,children:s.jsx(k.IconDatabase,{size:18})})}),s.jsx(o.Tooltip,{label:t("interactions.interactions_viewer"),withinPortal:!0,children:s.jsx(o.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:c,children:s.jsx(k.IconLink,{size:18})})})]}),s.jsx(eT,{opened:a,close:u})]}),s.jsx(o.Navbar.Section,{py:5,sx:{borderBottom:"1px solid #eee"},children:s.jsx(o.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:t("view.labels")})}),s.jsx(o.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:s.jsx(sT,{})}),s.jsx(o.Navbar.Section,{children:s.jsx(o.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:s.jsx(o.Button,{size:"xs",leftIcon:s.jsx(k.IconSettings,{size:20}),onClick:()=>e.editor.open([]),children:t("common.titles.settings")})})})]})}),iT=["function getDefaultValue(filter, utils, context) {",' return "";',"}"].join(`
449
- `),Xt=S.observer(({filter:t})=>{const{t:e}=_.useTranslation();return s.jsx(zo,{label:"",title:e("filter.field.custom_default_value.title"),triggerLabel:e("filter.field.custom_default_value.trigger"),value:t.default_value_func,onChange:t.setDefaultValueFunc,defaultValue:iT,triggerButtonProps:{size:"xs",color:"grape",sx:{flexGrow:0,alignSelf:"flex-start"},leftIcon:s.jsx(k.IconMathFunction,{size:16})},description:s.jsx(o.Alert,{title:e("filter.field.custom_default_value.tips"),color:"gray",mb:16,children:s.jsxs(o.List,{size:13,type:"ordered",children:[s.jsx(o.List.Item,{children:e("filter.field.custom_default_value.tip_1")}),s.jsx(o.List.Item,{children:e("filter.field.custom_default_value.tip_2")})]})})})}),aT=S.observer(function({filter:e}){const{t:n}=_.useTranslation(),r=e.config;return s.jsxs(s.Fragment,{children:[s.jsxs(o.Group,{position:"apart",children:[s.jsx(o.Checkbox,{checked:r.default_value,onChange:i=>r.setDefaultValue(i.currentTarget.checked),label:n("filter.widget.checkbox.default_checked")}),s.jsx(Xt,{filter:e})]}),s.jsx(jr,{label:n("filter.widget.checkbox.description"),value:r.description,onChange:r.setDescription,styles:{root:{flexGrow:1,minHeight:"400px"}}})]})}),oT=[{label:"2022",value:"YYYY"},{label:"202201",value:"YYYYMM"},{label:"20220101",value:"YYYYMMDD"},{label:"2022-01",value:"YYYY-MM"},{label:"2022-01-01",value:"YYYY-MM-DD"}],lT=S.observer(function({filter:e}){const{t:n}=_.useTranslation(),r=e.config,i=m.useMemo(()=>Vr().map(({key:a,value:l,group:c})=>({label:n(`filter.widget.date_range.shortcut.${c}.full.${a}`),value:l,group:n(`filter.widget.date_range.shortcut.${c}.label`)})),[]);return s.jsxs(s.Fragment,{children:[s.jsxs(o.Group,{children:[s.jsx(o.Checkbox,{checked:r.required,onChange:a=>r.setRequired(a.currentTarget.checked),label:n("filter.widget.date_range.required")}),s.jsx(o.Checkbox,{checked:r.allowSingleDateInRange,onChange:a=>r.setAllowSingleDateInRange(a.currentTarget.checked),label:n("filter.widget.date_range.allow_single_date")})]}),s.jsxs(o.Group,{grow:!0,children:[s.jsx(o.Select,{data:oT,label:n("filter.widget.date_range.display_format"),value:r.inputFormat,onChange:r.setInputFormat}),s.jsx(o.NumberInput,{label:n("filter.widget.date_range.max_days"),min:0,value:r.max_days,onChange:r.setMaxDays,hideControls:!0})]}),s.jsxs(o.Group,{children:[s.jsx(xl,{label:n("filter.widget.date_range.default_value"),config:r,value:r.default_value,onChange:r.setDefaultValue,disabled:!!r.default_shortcut}),s.jsx(o.Select,{data:i,label:n("filter.widget.date_range.default_by_shortcut"),value:r.default_shortcut,onChange:r.setDefaultShortcut,placeholder:n("filter.widget.date_range.default_by_shortcut_placeholder"),clearable:!0,sx:{flexGrow:1},maxDropdownHeight:500})]}),s.jsx(Xt,{filter:e})]})}),Ci=S.observer(({value:t,onChange:e})=>{const{t:n}=_.useTranslation(),r=H(),i=U(),a=m.useMemo(()=>i.queries.options,[i.queries.current]),l=a.length===0,c=u=>{r.editor.setPath(["_QUERIES_",u])};return s.jsx(o.Select,{label:s.jsxs(o.Group,{position:"apart",children:[s.jsx(o.Text,{children:n("filter.widget.common.use_query_data_as_options")}),t&&s.jsx(o.Button,{size:"xs",leftIcon:s.jsx(k.IconArrowCurveRight,{size:16}),variant:"subtle",color:"blue",onClick:()=>c(t),children:n("query.open")})]}),data:a,value:t,onChange:e,allowDeselect:!1,clearable:!0,sx:{flexGrow:1},disabled:l,error:l?"You need to add a query in Data Settings":void 0,styles:{label:{display:"block"}}})}),cT=`
448
+ `}})).actions(t=>({setPage(e){t.page=e},resetPage(){t.page=1},setLimit(e){t.limit=e}})).actions(t=>({afterCreate(){f.addDisposer(t,K.reaction(()=>t.keywordString,t.resetPage,{fireImmediately:!1,delay:0})),f.addDisposer(t,K.reaction(()=>t.limit,t.resetPage,{fireImmediately:!1,delay:0}))}})),nk=f.types.model({data:f.types.optional(f.types.frozen(),{}),state:f.types.optional(f.types.enumeration(["idle","loading","error"]),"idle"),error:f.types.frozen()}).views(t=>({get loading(){return t.state==="loading"},get empty(){return Object.keys(t.data).length===0}})),sk=f.types.compose("DataSourceModel",ni,f.types.model({tables:f.types.optional(nk,{}),columns:f.types.optional(HS,{}),tableData:f.types.optional(tk,{}),indexes:f.types.optional(ek,{}),table_schema:f.types.optional(f.types.string,""),table_name:f.types.optional(f.types.string,"")})).views(t=>({get sqlDataSourceType(){return t.type},get reloadConditionString(){const{type:e,table_name:n,table_schema:r}=t;return`${e};${n};${r}`}})).volatile(()=>({controllers:{tables:new AbortController,columns:new AbortController,indexes:new AbortController,tableData:new AbortController}})).actions(t=>({setKeywords(e,n){t.table_schema=e,t.table_name=n}})).actions(t=>({initKeywords(){if(t.tables.empty)return;const e=Object.keys(t.tables.data)[0],n=t.tables.data[e][0].table_name;t.setKeywords(e,n)}})).actions(t=>{const e=f.flow(function*(){var n;(n=t.controllers.tables)==null||n.abort(),t.controllers.tables=new AbortController,t.tables.state="loading";try{const r=yield*f.toGenerator(et.structure(t.controllers.tables.signal)({query_type:"TABLES",type:t.sqlDataSourceType,key:t.key,table_schema:"",table_name:""},{params:{query_type:"TABLES"}}));t.tables.data=x.groupBy(r,"table_schema"),t.tables.state="idle",t.tables.error=null,t.initKeywords()}catch(r){if(!at.isCancel(r)){t.tables.data={};const i=x.get(r,"message","unkown error");t.tables.error=x.get(r,"response.data.detail.message",i),t.tables.state="error"}}});return{loadTables:e,loadTablesIfEmpty(){t.tables.empty&&e()},loadColumns:f.flow(function*(){var n;(n=t.controllers.columns)==null||n.abort(),t.controllers.columns=new AbortController,t.columns.state="loading";try{t.columns.data=yield*f.toGenerator(et.structure(t.controllers.columns.signal)({query_type:"COLUMNS",type:t.sqlDataSourceType,key:t.key,table_schema:t.table_schema,table_name:t.table_name},{params:{query_type:"COLUMNS"}})),t.columns.state="idle",t.columns.error=null}catch(r){if(at.isCancel(r))t.columns.state="idle",t.columns.error=null;else{t.columns.data=[];const i=x.get(r,"message","unkown error");t.columns.error=x.get(r,"response.data.detail.message",i),t.columns.state="error"}}}),loadIndexes:f.flow(function*(){var n;(n=t.controllers.indexes)==null||n.abort(),t.controllers.indexes=new AbortController,t.indexes.state="loading";try{t.indexes.data=yield*f.toGenerator(et.structure(t.controllers.indexes.signal)({query_type:"INDEXES",type:t.sqlDataSourceType,key:t.key,table_schema:t.table_schema,table_name:t.table_name},{params:{query_type:"INDEXES"}})),t.indexes.state="idle",t.indexes.error=null}catch(r){if(at.isCancel(r))t.indexes.state="idle",t.indexes.error=null;else{t.indexes.data=[];const i=x.get(r,"message","unkown error");t.indexes.error=x.get(r,"response.data.detail.message",i),t.indexes.state="error"}}}),loadTableData:f.flow(function*(){var r;(r=t.controllers.tableData)==null||r.abort(),t.controllers.tableData=new AbortController;const n=t.tableData;n.state="loading";try{n.data=yield*f.toGenerator(et.structure(t.controllers.tableData.signal)({query_type:"DATA",type:t.sqlDataSourceType,key:t.key,table_schema:t.table_schema,table_name:t.table_name,limit:n.limit,offset:n.offset},{params:{query_type:"DATA"}}));const[{total:i}]=yield*f.toGenerator(et.structure(t.controllers.tableData.signal)({query_type:"COUNT",type:t.sqlDataSourceType,key:t.key,table_schema:t.table_schema,table_name:t.table_name},{params:{query_type:"COUNT"}}));n.total=Number(i),n.state="idle",n.error=null}catch(i){if(at.isCancel(i))n.state="idle",n.error=null;else{n.data=[];const a=x.get(i,"message","unkown error");n.error=x.get(i,"response.data.detail.message",a),n.state="error"}}})}}).actions(t=>({afterCreate(){f.addDisposer(t,K.reaction(()=>t.reloadConditionString,t.loadColumns,{fireImmediately:!1,delay:500}))}})).actions(t=>({afterCreate(){f.addDisposer(t,K.reaction(()=>t.reloadConditionString,t.loadIndexes,{fireImmediately:!1,delay:500})),f.addDisposer(t,K.reaction(()=>`${t.reloadConditionString};limit:${t.tableData.limit};offset:${t.tableData.offset}`,t.loadTableData,{fireImmediately:!1,delay:0}))}})),rk=f.types.model("DataSourcesModel",{list:f.types.optional(f.types.array(sk),[])}).views(t=>({find({type:e,key:n}){return t.list.find(r=>r.key===n&&r.type===e)},get options(){return t.list.map(e=>({value:e.key,label:e.key}))}})).actions(t=>({replace(e){t.list.length=0,t.list.push(...e)}}));function Pt(t){return{label:t,value:t,_type:"ACTION",_action_type:t,Icon:null,children:null}}function ik(t){switch(t._type){case"GROUP":case"ACTION":return null;case"query_variables":return["_QUERY_VARS_"];case"mock_context":return["_MOCK_CONTEXT_"];case"filter":return["_FILTERS_",t.value];case"sql_snippet":return["_SQL_SNIPPETS_",t.value];case"query":return["_QUERIES_",t.value];case"view":return["_VIEWS_",t.value];case"panel":return t.parentID?["_VIEWS_",t.parentID,"_PANELS_",t.value]:(console.error("[getPathFromOption] parentID is required"),null)}}const ak=f.types.model("EditorModel",{path:f.types.optional(f.types.frozen(),[]),settings_open:f.types.optional(f.types.boolean,!1)}).views(t=>({get navOptions(){const{content:e}=f.getRoot(t),{filters:n,views:r,sqlSnippets:i,queries:a}=e;return[{label:"query_variable.labels",value:"_QUERY_VARS_",_type:"query_variables",Icon:k.IconVariable},{label:"mock_context.label",value:"_MOCK_CONTEXT_",Icon:k.IconCodeDots,_type:"mock_context"},{label:"filter.labels",value:"_FILTERS_",Icon:k.IconFilter,children:[Pt("_FILTERS_SETTINGS_"),...n.options,Pt("_Add_A_Filter_")],_type:"GROUP"},{label:"sql_snippet.labels",value:"_SQL_SNIPPETS_",Icon:k.IconCopy,children:[Pt("_SQL_SNIPPETS_SETTINGS_"),...i.options,Pt("_Add_A_SQL_SNIPPET_")],_type:"GROUP"},{label:"query.labels",value:"_QUERIES_",Icon:k.IconDatabase,children:[Pt("_QUERIES_SETTINGS_"),...a.options,Pt("_Add_A_QUERY_")],_type:"GROUP"},{label:"view.labels",value:"_VIEWS_",Icon:k.IconBoxMultiple,children:[...r.editorOptions,Pt("_Add_A_VIEW_")],_type:"GROUP"}]},isOptionActive(e,n){return e.length===0?!1:e[e.length-1]===n.value},isOptionOpened(e){const{path:n}=t;return n.length===0||!e.children||e.children.length===0?!1:n.includes(e.value)}})).actions(t=>({setPath(e){t.path=e},setSettingsOpen(e){t.settings_open=e}})).actions(t=>({open(e){t.setPath(e),t.setSettingsOpen(!0)},close(){t.setSettingsOpen(!1)},navigate(e){const n=ik(e);n&&t.setPath(n)}})),ok=f.types.compose("LayoutsModel",hi,f.types.model({currentLayoutWrapperWidth:f.types.optional(f.types.number,0)})).views(t=>({get divisionPreviewScale(){const e=t.currentLayoutPreviewWidth,n=t.currentLayoutWrapperWidth;return!e||!n||e<=n?1:n/e}})).actions(t=>({addALayoutItem(e){t.list.forEach(n=>{n.addNewLayout(e)})},duplicateLayoutItemsByPanelID(e,n){t.list.forEach(r=>{const i=r.findByPanelID(e);if(!i){console.error(`Can't find a layout item by panelID[${e}] in layoutSet[${r.name}]`);return}r.list.push({...i,id:lt.v4(),panelID:n,y:1/0})})},removeByPanelID(e){t.list.forEach(n=>{n.removeByPanelID(e)})},setCurrentLayoutWrapperWidth(e){t.currentLayoutWrapperWidth=e},addALayoutSet(e,n,r){const i=t.basisLayoutSet,a={id:e,name:n,breakpoint:r,list:i.json.list.map(l=>({...l,id:lt.v4()}))};t.list.push(a)},updateLayoutSetsInfo(e){const n=x.keyBy(t.list,"id");e.forEach(a=>{const l=n[a.id];if(l){l.setName(a.name),l.setBreakpoint(a.breakpoint),delete n[a.id];return}this.addALayoutSet(a.id,a.name,a.breakpoint)});const r=new Set(Object.keys(n)),i=r.size>0;r.forEach(a=>{const l=t.list.findIndex(c=>c.id===a);t.list.splice(l,1)}),i&&t.setCurrentBreakpoint("basis")},updateCurrentLayoutItem(e){t.currentLayoutSet.updateLayoutItem(e)},append(e){t.list.push(e)},appendMultiple(e){e.length!==0&&t.list.push(...e)},remove(e){t.list.splice(e,1)},removeByID(e){const n=t.list.findIndex(r=>r.id===e);n!==-1&&t.list.splice(n,1)},removeByIDs(e){e.forEach(n=>{this.removeByID(n)})}})),vc=oi.views(t=>({get realDataFieldOptions(){return t.queryIDs.length===0?[]:t.queries.map(e=>{const n=e.data;return n.length===0?[]:Object.keys(n[0]).map(i=>({label:i,value:`${e.id}.${i}`,group:e.name,group_id:e.id,disabled:!1}))}).flat()},get realQueryOptions(){return t.queryIDs.length===0?[]:t.queries.map(e=>({label:e.name,value:e.id,disabled:!1}))},queryOptions(e,n){const r=[...this.realQueryOptions];return e&&!r.find(i=>i.value===e)&&r.unshift({label:e,value:e,disabled:!0}),n&&r.unshift({label:"unset",value:"",disabled:!1}),r},dataFieldOptions(e,n,r){let i=[...this.realDataFieldOptions];if(r&&(i=i.filter(a=>a.group_id===r)),e&&!i.find(a=>a.value===e)){const a=E(e),l=t.queryByID(a.queryID);i.unshift({label:a.columnKey,value:e,group:l?l.name:a.queryID,group_id:l?l.id:"",disabled:!0})}return n&&i.unshift({label:"unset",value:"",group:"",group_id:"",disabled:!1}),i},explainDataKey(e){const{queryID:n,columnKey:r}=E(e),i=t.queries.find(a=>a.id===n);return i?{queryID:n,queryName:i.name,columnKey:r}:{queryID:n,queryName:null,columnKey:r}}})).actions(t=>({removeSelf(){f.getParent(t,2).removeByID(t.id)}})).actions(t=>({moveToView(e,n){f.getRoot(t).content.views.findByID(e).removePanelID(t.id),f.getRoot(t).content.views.findByID(n).appendPanelID(t.id),f.getRoot(t).editor.setPath(["_VIEWS_",n,"_PANELS_",t.id])}})),_c=f.types.compose("PanelsModel",li,f.types.model({list:f.types.optional(f.types.array(vc),[])})).views(t=>({get contentModel(){return f.getRoot(t).content},editorOptions(e,n){const r=t.panelsByIDs(n);r.length!==n.length&&console.warn(`Unfulfilled panels for View[${e}]`);const i=r.map(l=>({label:l.name,value:l.id,_type:"panel",parentID:e})),a="_Add_A_PANEL_";return i.push({label:a,value:a,_type:"ACTION",_action_type:a,parentID:e,Icon:null,children:null}),i}})).actions(t=>({replace(e){t.list=f.castToSnapshot(e)},append(e){t.list.push(e)},appendMultiple(e){e.length!==0&&t.list.push(...e)},remove(e){t.list.splice(e,1)},removeByID(e){const n=t.list.findIndex(r=>r.id===e);n!==-1&&t.list.splice(n,1)},removeByIDs(e){e.forEach(n=>{this.removeByID(n)})},duplicateByID(e){const n=t.list.find(i=>i.id===e);if(!n){console.error(new Error(`[duplicate panel] Can't find a panel by id[${e}]`));return}const r=new Date().getTime().toString();return t.list.push({...n.json,id:r,title:{...n.json.title}}),t.contentModel.layouts.duplicateLayoutItemsByPanelID(n.id,r),r},replaceByIndex(e,n){t.list.splice(e,1,n)}})),lk=ii.actions(t=>({getSchema(){const e=t.json,n=[],r=[];t.panels.forEach(l=>{const c=l.getSchema();n.push(c.panel),c.queries.length>0&&r.push(...c.queries)});const i=t.contentModel.layouts.jsonByPanelIDSet(new Set(t.panelIDs));return{views:[e],panels:n,definition:{queries:x.uniqBy(r,l=>l.id)},layouts:i,version:ft}},downloadSchema(){if(t.type===q.Tabs){console.error(new Error("Please choose a tab first"));return}const e=JSON.stringify(this.getSchema(),null,2),n=t.name;Jt(n,e)}})),jc=f.types.compose("ViewsModel",ai,f.types.model({current:f.types.optional(f.types.array(lk),[]),idOfVIE:f.types.string})).views(t=>({get isVIETheFirstView(){return t.current.length===0||!t.idOfVIE?!1:t.current[0].id===t.idOfVIE},get VIE(){return t.current.find(({id:e})=>e===t.idOfVIE)},get options(){return t.current.map(e=>({label:e.name,value:e.id,type:e.type}))},get editorOptions(){const e=f.getRoot(t).content.panels;return t.current.map(n=>({label:n.name,value:n.id,_type:"view",children:e.editorOptions(n.id,n.panelIDs)}))}})).actions(t=>({setIDOfVIE(e){t.idOfVIE=e,t.visibleViewIDs.length=0,t.visibleViewIDs.push(e)},replace(e){t.current.replace(e)},addANewView(e,n,r,i){t.current.push({id:e,name:n,type:r,config:i,panelIDs:[]})},append(e){t.current.push(e)},appendMultiple(e){e.length!==0&&t.current.push(...e)},remove(e){t.current.splice(e,1)},removeByID(e){const n=t.current.findIndex(a=>a.id===e);if(n===-1)return;const r=t.current[n];f.getRoot(t).content.panels.removeByIDs(r.panelIDs),t.current.splice(n,1)},replaceByIndex(e,n){t.current.splice(e,1,n)},addARandomNewView(){const e=new Date().getTime().toString();this.addANewView(e,q.Division,q.Division,{_name:q.Division}),this.setIDOfVIE(e)},removeVIE(){t.current.length!==1&&(this.removeByID(t.idOfVIE),this.setIDOfVIE(t.current[0].id))}}));function bi(t){const e=t.length>0?[t[0].id]:[],n=t.length>0?t[0].id:"";return{current:t.map(i=>{const{_name:a=i.type}=i.config;return{...i,config:{...i.config,_name:a},panelIDs:i.panelIDs}}),visibleViewIDs:e,idOfVIE:n}}const ck=f.types.model({id:f.types.string,name:f.types.string,dashboard_id:f.types.string,create_time:f.types.string,update_time:f.types.string,version:f.types.string,filters:gc,queries:yc,sqlSnippets:bc,views:jc,panels:_c,layouts:ok,mock_context:Gr,origin:f.types.maybe(f.types.frozen())}).views(t=>({get json(){return{id:t.id,name:t.name,create_time:t.create_time,update_time:t.update_time,dashboard_id:t.dashboard_id,content:{views:t.views.json,panels:t.panels.json,filters:t.filters.json,version:t.version,layouts:t.layouts.json,definition:{queries:t.queries.json,sqlSnippets:t.sqlSnippets.json,mock_context:t.mock_context.current}}}},get contentJSON(){return this.json.content},get filtersChanged(){const e="filters.current";return!x.isEqual(f.getSnapshot(x.get(t,e)),x.get(t.origin,e))},get queriesChanged(){const e="queries.current",n=f.getSnapshot(x.get(t,e)).map(r=>x.pick(r,["id","name","key","type","sql","run_by","react_to","pre_process","post_process","dep_query_ids"]));return!x.isEqual(n,x.get(t.origin,e))},get sqlSnippetsChanged(){const e="sqlSnippets.current";return!x.isEqual(f.getSnapshot(x.get(t,e)),x.get(t.origin,e))},get viewsChanged(){const e="views.current";return!x.isEqual(t.views.json,x.get(t.origin,e))},get panelsChanged(){const e="panels.list";return!x.isEqual(f.getSnapshot(x.get(t,e)),x.get(t.origin,e))},get layoutsChanged(){const e="layouts.list";return!x.isEqual(f.getSnapshot(x.get(t,e)),x.get(t.origin,e))},get mockContextChanged(){const e="mock_context.current";return!x.isEqual(x.get(t,e),x.get(t.origin,e))},get context(){const e=f.getParent(t).context.current;return{...t.mock_context.current,...e}},get payloadForSQL(){const e=f.getParent(t).globalSQLSnippets,n={context:this.context,filters:t.filters.values};return{...n,sql_snippets:xn(t.sqlSnippets.current,"key","value",n),global_sql_snippets:xn(e.list,"id","content",n)}},get payloadForViz(){const e=f.getParent(t).context.current;return{context:{...t.mock_context.current,...e},filters:t.filters.values}},get dashboardState(){return Ds(this.payloadForSQL)},getAdditionalQueryInfo(e){return{content_id:t.id,query_id:e,params:this.dashboardState}},get changed(){return this.filtersChanged||this.queriesChanged||this.sqlSnippetsChanged||this.viewsChanged||this.panelsChanged||this.layoutsChanged||this.mockContextChanged},get data(){return t.queries.current.map(({id:n,data:r})=>({id:n,data:r})).reduce((n,r)=>(n[r.id]=r.data,n),{})},getDataStuffByID(e){const n=t.queries.findByID(e);return n?{data:n.data,len:n.data.length,state:n.state,error:n.error}:{data:[],len:0,state:"idle",error:void 0}}})).views(t=>({get queriesUsage(){const e=t.panels.idMap,n=[];t.views.current.forEach(i=>{i.panelIDs.forEach(a=>{const l=e.get(a);if(!l)return;const c="panel",u=l.name,d=[{id:i.id,label:i.name}];l.queryIDs.forEach(p=>{n.push({id:a,queryID:p,type:c,type_label:"panel.label",label:u,views:d})})})});const r=t.views.idMap;return t.filters.current.filter(i=>!!x.get(i,"config.options_query_id")).forEach(i=>{n.push({type:"filter",type_label:"filter.label",id:i.id,queryID:x.get(i,"config.options_query_id"),label:i.label,views:i.visibleInViewsIDs.map(a=>{var l;return{id:a,label:((l=r.get(a))==null?void 0:l.name)??a}})})}),t.queries.current.forEach(i=>{i.isTransform&&i.dep_query_ids.forEach(a=>{n.push({type:"transform-query",type_label:"query.transform.full_label",id:i.id,queryID:a,label:i.name,views:[]})})}),x.groupBy(n,"queryID")},get hasUnusedQueries(){return t.queries.current.length>Object.keys(this.queriesUsage).length},findQueryUsage(e){return this.queriesUsage[e]??[]},get sqlSnippetsUsage(){const e=[];return t.queries.current.forEach(n=>{if(!n.typedAsSQL)return;x.uniq(n.sql.match(Mn.sqlSnippet)).forEach(i=>{e.push({queryID:n.id,sqlSnippetKey:i,queryName:n.name})})}),x.groupBy(e,"sqlSnippetKey")},get hasUnusedSQLSnippets(){return t.sqlSnippets.current.length>Object.keys(this.sqlSnippetsUsage).length},findSQLSnippetUsage(e){return this.sqlSnippetsUsage[e]??[]}})).actions(t=>({removeUnusedQueries(){const e=new Set(Object.keys(t.queriesUsage)),n=t.queries.current.filter(r=>!e.has(r.id)).map(r=>r.id);t.queries.removeQueries(n)},removeUnusedSQLSnippets(){const e=new Set(Object.keys(t.sqlSnippetsUsage)),n=t.sqlSnippets.current.filter(r=>!e.has(r.key)).map(r=>r.key);t.sqlSnippets.removeByKeys(n)},duplicatePanelByID(e,n){var i;const r=t.panels.duplicateByID(e);r&&((i=t.views.findByID(n))==null||i.appendPanelID(r))},removePanelByID(e,n){var r;t.panels.removeByID(e),t.layouts.removeByPanelID(e),(r=t.views.findByID(n))==null||r.removePanelID(e)},addANewPanel(e){var r;const n=lt.v4();t.panels.append(Fl(n)),(r=t.views.findByID(e))==null||r.appendPanelID(n),t.layouts.addALayoutItem(n)},applyJSONSchema(e){var h;const{views:n,panels:r,filters:i,definition:a={},layouts:l}=e,{queries:c,sqlSnippets:u,mock_context:d}=a,p=new Map;if(Array.isArray(r)){const g=r.map(y=>{const v=lt.v4();return p.set(y.id,v),{...y,id:v}});if(t.panels.appendMultiple(g),!Array.isArray(n)||n.length===0){const y=g.map(v=>v.id);(h=t.views.VIE)==null||h.appendPanelIDs(y)}}if(Array.isArray(n)){const g=n.map(y=>{const v=y.panelIDs.map(C=>p.get(C)??C);return{...y,id:lt.v4(),panelIDs:v}});t.views.appendMultiple(g)}if(Array.isArray(l)){const g=(C,T)=>t.layouts.breakpointNameRecord[C]===T;let y=[];const v=l.filter(C=>g(C.name,C.breakpoint));v.forEach(C=>{C.id==="basis"&&(y=C.list),C.list.forEach(T=>{const D=p.get(T.panelID);T.id=lt.v4(),T.panelID=D})}),t.layouts.list.forEach(C=>{const T=v.find(D=>D.name===C.name&&D.breakpoint===C.breakpoint);if(!T){y.forEach(D=>{C.addLayout(D)});return}T.list.forEach(D=>{C.addLayout(D)})})}Array.isArray(i)&&t.filters.appendMultiple(i),Array.isArray(c)&&t.queries.appendMultiple(c),Array.isArray(u)&&t.sqlSnippets.appendMultiple(u),d&&Object.keys(d).length>0&&t.mock_context.defaults(d)}})).actions(t=>({reset(){f.applySnapshot(t.filters.current,t.origin.filters.current),f.applySnapshot(t.queries.current,t.origin.queries.current),f.applySnapshot(t.sqlSnippets.current,t.origin.sqlSnippets.current),f.applySnapshot(t.views.current,t.origin.views.current),f.applySnapshot(t.panels.list,t.origin.panels.list),f.applySnapshot(t.layouts.list,t.origin.layouts.list),t.mock_context.current=t.origin.mock_context.current},resetFilters(){f.applySnapshot(t.filters.current,t.origin.filters.current)},updateCurrent(e){const{id:n,name:r,content:i}=e;if(!i)throw new Error("unexpected null content when updating a content model");const{version:a,filters:l,views:c,panels:u,definition:{queries:d,sqlSnippets:p,mock_context:h={}}}=i;t.id=n,t.name=r,t.version=a,f.applySnapshot(t.filters.current,l),f.applySnapshot(t.views.current,bi(c).current),f.applySnapshot(t.panels.list,u),f.applySnapshot(t.queries.current,d),f.applySnapshot(t.sqlSnippets.current,p),t.mock_context.current=h}})),vi=f.types.snapshotProcessor(ck,{preProcessor(t){return{...t,origin:t}},postProcessor(t){delete t.origin;const e=f.castToSnapshot(t.queries.current.map(n=>x.pick(n,["id","key","type","sql"])));return x.defaults({},{queries:{current:e}},t)}});function uk(t,e){e.filters&&f.applySnapshot(t.filters.current,e.filters)}function wc({id:t,name:e,dashboard_id:n,create_time:r,update_time:i,content:a},l,c){if(!a)throw new Error("unexpected null content when creating a content model");const{version:u,filters:d,views:p,panels:h,layouts:g,definition:{queries:y,sqlSnippets:v,mock_context:C={}}}=a;return vi.create({id:t,name:e,dashboard_id:n,create_time:r,update_time:i,version:u,filters:ui(d,l,C,c),queries:{current:y},sqlSnippets:{current:v},mock_context:Fr(C),views:bi(p),panels:{list:h},layouts:{list:g,currentBreakpoint:g[0].id}})}const Cc=f.types.model({id:f.types.identifier,name:f.types.string,group:f.types.string,content:vi,content_id:f.types.string,datasources:rk,globalSQLSnippets:si,context:cs,editor:ak}).views(t=>({get json(){return{id:t.id,name:t.name,group:t.group,content_id:t.content_id}}})).actions(t=>({updateCurrentContent(e){t.content.updateCurrent(e)},updateCurrent(e,n){const{id:r,name:i,group:a,content_id:l}=e;t.id=r,t.name=i,t.group=a,t.content_id=l,this.updateCurrentContent(n)}}));function Sc({id:t,name:e,group:n,content_id:r},i,a,l,c,u){return Cc.create({id:t,name:e,group:n,content_id:r,content:wc(i,c,u),datasources:{list:a},globalSQLSnippets:{list:l},context:ri(c),editor:{}})}const dk={translation:{filter:{label:"Filter",labels:"Filters",add:"Add a Filter",manage:"Manage Filters",show_filters:"Show Filters",hide_filters:"Hide Filters",field:{widget:"Widget",visible_in:"Visible in...",key_placeholder:"A unique key to refer",label_placeholder:"Label for this field",auto_submit:"Submit automatically",order:"Placement Order",custom_default_value:{trigger:"Custom",title:"Custom default value",tips:"Tips",tip_1:"Function has the highest priority of getting filter's default value",tip_2:"Leave this editor empty to disable this feature"}},widget:{names:{select:"Select",multi_select:"Multi Select",tree_select:"Tree Select",text_input:"Text Input",checkbox:"Checkbox",date_range:"Date Range"},common:{use_query_data_as_options:"Use query data as options",fetch_options_from_datasource:"Fetch options from datasource",or_fetch_options_from_datasource:"Or fetch options from datasource",selector_option_empty:"Not found",see_data_structure:"Click to see expected data structure",using_query:"Using query",default_selection_count:"Select first N options by default",min_width:"Min width",x_selected:"{{count}} selected"},text_input:{default_value:"Default Value",required:"Required"},select:{width:"Width",required:"Required",clearable:"Clearable",configure_options:"Configure options",default_selection:"Default Selection",no_default_selection:"none",select_first_option_by_default:"Select the first option by default"},multi_select:{width_description:"At least 160px"},tree_select:{strictly:"Parent and children nodes are not associated"},checkbox:{description:"Description",default_checked:"Default checked"},date_range:{required:"Required",allow_single_date:"Allow choosing 1 day",display_format:"Display format",max_days:"Max days",one_day:"1 day",x_days:"{{count}} days",x_max_days:"{{max_days}} days max",default_value:"Default value",default_by_shortcut:"Default by shortcut",defualt_by_shortcut_placeholder:"Priors default value",start_date:"Start date",end_date:"End date",shortcut:{last:{label:"last",d:"yesterday",w:"week",m:"month",m2:"2 months",m3:"3 months",y:"year",full:{d:"yesterday",w:"last week",m:"last month",m2:"last 2 months",m3:"last 3 months",y:"last year"}},recent:{label:"recent",d7:"7 days",d30:"30 days",d60:"60 days",d90:"90 days",d180:"180 days",d365:"365 days",full:{d7:"recent 7 days",d30:"recent 30 days",d60:"recent 60 days",d90:"recent 90 days",d180:"recent 180 days",d365:"recent 365 days"}},this:{label:"this",d:"today",w:"week",m:"month",y:"year",full:{d:"today",w:"this week",m:"this month",y:"this year"}},this_so_far:{label:"this...so far",w:"week",m:"month",y:"year",full:{w:"this week so far",m:"this month so far",y:"this year so far"}}}}}},view:{label:"View",labels:"Views",add:"Add a View",delete:"Delete this View",download_schema:"Download this View",component:{div:{label:"Division"},tabs:{label:"Tabs",tabs_settings:"Tabs Settings",tab:{name:"Tab Name",view:"View",order:"Placement Order",color:"Color",delete:"Delete this tab",switch_to_view:"Swith to View: {{name}}"}},modal:{label:"Modal",modal_settings:"Modal settings",title:"Modal Title",custom_title:"Customize modal title",width:"Width",height:"Height"}}},interactions:{label:"Interactions",add:"Add an interaction",interactions_viewer:"Interactions Viewer",unavailable:"Unavailable",unavailable_reason:"This visualization does not have available interactions to choose from",trigger:{setup:"Setup Trigger",label:"Trigger",payload:"Payload"},operation:{setup:"Operation Settings",label:"Operation",settings:"Settings",variables:"Variables",console_log:{label:"console.log | debug",log_content:"log content"},open_link:{label:"Open Link",url:"URL",open_in_new_tab:"Open in new tab"},open_view:{label:"Open View",view:"View"},set_filter_values:{label:"Set Filter Values",set_filter:"Set filter",with:"with"},clear_filter_values:{label:"Clear Filter Values",select_filter:"Select filters to clear"}}},query_variable:{label:"Query Variable",labels:"Query Variables",add:"Add a Variable",guide:{tabs:{guide:"Guide",variables_in_this_dashboard:"Variables in this dashboard",global_sql_snippets:"Global SQL Snippets"}},open:"See Query Variables"},sql_snippet:{label:"SQL Snippet",labels:"SQL Snippets",add:"Add a SQL Snippet",delete:"Delete this SQL Snippet",delete_unused:"Delete unused SQL Snippets",manage:"Manage SQL Snippets",key:"Key",key_occupied:"This key is occupied by another snippet",edit_snippet:"Edit SQL Snippet",preview_snippet:"Preview SQL Snippet",usage:{label:"Usage"}},global_sql_snippet:{label:"Global SQL Snippet",labels:"Global SQL Snippets",description:"SQL snippets worth sharing between dashboards are managed in System Settings by admins."},common:{titles:{settings:"Settings",edit:"Edit",config:"Config"},pagination:{page_size:"Page Size",total:"Total",total_rows:"Total {{total}} row(s)"},align:{horizontal:{label:"Horizontal Align",left:"left",center:"center",right:"right"},vertical:{label:"Vertical Align",left:"top",center:"center",right:"bottom"}},id:"ID",name:"Name",key:"Key",label:"Label",value:"Value",type:"Type",info:"Info",min:"Min",max:"Max",data_field:"Data Field",name_data_field:"Name Data Field",value_data_field:"Value Data Field",color_data_field:"Color Data Field",enabled:"Enabled",copied:"Copied to clipboard",action:"Action",actions:{open:"Open",close:"Close",save:"Save",save_changes:"Save Changes",revert:"Revert",revert_changes:"Revert Changes",reset_to_default:"Reset to default",select_all:"Select All",clear_selection:"Clear Selection",refresh:"Refresh",download_data:"Download Data",download_schema:"Download Schema",download_screenshot:"Screenshot",enter_fullscreen:"Full Screen",duplicate:"Duplicate",delete:"Delete",cancel:"Cancel",confirm:"Confirm",add_an_option:"Add an Option",edit:"Edit",end_editing:"End editing <1>{{name}}</1>"},tabs:{variant:{label:"Variant",default:"Default",outline:"Outline",pills:"Pills"},orientation:{label:"Orientation",horizontal:"Horizontal",vertical:"Vertical"},grow_tabs:"Grow Tabs"},choose_a_tab_first:"Please choose a tab first"},breakpoint:{label_one:"Screen size",label_other:"Screen sizes",add:"Add a screen size",manage:"Manage screen sizes",breakpoint:"Min Width"},context:{label:"Context"},mock_context:{label:"Mock Context",hint:"A valid json string is required"},panel:{label:"Panel",labels:"Panels",add:"Add a Panel",delete:"Delete This Panel",panel_name:"Panel Name",panel_description:"Description",panel_description_click:"Click to see description",show_title:"Show title",use_name_as_title:"Use name as title",settings:{change_view:"Move into Another View",change_view_title:"Move panel into another view",choose_queries:"Choose queries",need_to_choose_queries:"Choose at least 1 query for its data"},style:{label:"Style",width:"Width",width_postfix:"of 36 columns",height:"Height",height_postfix:"px",border:"Border"},variable:{label:"Variable",labels:"Variables",add:"Add a Variable",delete:"Delete this Variable",aggregation:{label:"Aggregation",fallback_value:"Fallback Value",fallback_value_description:"Used when data is empty or the aggregation yields NaN"}}},style:{label:"Style",font_size:{label:"Font Size",placeholder:"10px, 1em, 1rem, 100%..."},font_weight:{label:"Font Weight"},size:{xs:"xs",sm:"sm",md:"md",lg:"lg",xl:"xl"},flex:{justify_content:{label:"Justify Content",left:"Left",center:"Center",right:"Right",space_between:"Space Between",space_around:"Space Around",space_evenly:"Space Evenly"},align_items:{label:"Align Items",start:"Start",center:"Center",end:"End",stretch:"Stretch"}},color:{type:{label:"Color Type",static:"Static",interpolation:"Interpolation",none:"None"},interpolation:{setup:"Setup color interpolation",palette:{label:"Palette",category:{sequential:"Sequential",diverging:"Diverging"},red_green:"Red / Green",yellow_blue:"Yellow / Blue",red:"Red",green:"Green",blue:"Blue",orange:"Orange",mapping:{value_input_label:"Map a value to this color"}}}}},query:{label:"Query",labels:"Queries",add:"Add a Query",delete:"Delete this Query",cant_delete:"Can't delete this query for it's being used, check out Usage tab for details",delete_unused:"Delete unused queries",name:"Name",name_description:"A unique name",manage:"Manage Queries",open:"Open this query",configurations:"Configurations",basics:"Basics",conditions:"Conditions",run_by_condition:{label:"Run query when these are truthy",unset:"Always run this query on load"},re_run_condition:{label:"Re-run query when these changed",unset:"Leave it empty to never re-run this query"},dependency:{label:"Dependency",has_none:"This query has no dependency"},edit_sql:"Edit SQL",preview_sql:"Preview SQL",request:"Request",build_request:"Build Request",process_request:"Process Request",process_result:"Process Result",usage:{label:"Usage",in_views:"In View(s)",unused_description:"This query is not used by any filter or panel"},transform:{label:"Transform",full_label:"Transform Query",data_source:"Use other queries' data",guide:{pick_queries:"Pick queries for data input",write_function:"Write a function for making new data"}}},data:{label:"Data",preview_data:"Preview Data",empty_data:"Empty Data",requires_data:"Requires data"},data_source:{label:"Data Source",explore:"Explore Data Source",explorer:"Data Source Explorer",table_structure:"Table Structure",table_structure_short:"Structure",see_table_structure:"See Table Structure"},visualization:{label:"Visualization",component:"Visualization",label_short:"Viz"},numbro:{format:{label:"Format",absolute:"Absolute",absolute_description:"Non-negative",abbreviation:"Abbreviation",abbreviation_description:"like 1.23k, 1.23m",mantissa:"Mantissa",trim_mantissa:"Trim mantissa",trim_mantissa_description:"hide trailing zero(s)",preview:{open:"Open Preview",close:"Close Preview",input:"In",output:"Out"}}},import:{label:"Import...",title:"Import content with schema json",json_file:"JSON File",this_dashboard:"This dashboard",this_file:"This file"},function_utils:{trigger_text:"About parameter 'utils'",modal_title:"About FunctionUtils",description:"Parameter <code>utils</code> is <code>FunctionUtils</code>, which contains:",document:"Document"},aggregation:{option:{none:"None",sum:"Sum",mean:"Mean",median:"Median",min:"Min",max:"Max",cov:"Coefficient of Variation",std:"Standard Variation",quantile:{label:"Quantile",label_with_hint:"Quantile(99%, 95%, ...)"},custom:{label:"Custom",label_trigger:"Edit Function",title:"Custom Aggregation"}}},chart:{chart_config:"Chart Config",data_field:"Data Field",groups:{merico_suite:"Merico suite",echarts_based_charts:"ECharts-based charts",others:"Others"},label:{label:"Label",label_full:"Label",label_style:"Label Style",label_format:"Label Format"},label_position:{label:"Label Position",off:"Off",top:"Top",left:"Left",right:"Right",bottom:"Bottom",inside:"Inside",inside_top:"Inside Top",inside_left:"Inside Left",inside_center:"Inside Center",inside_right:"Inside Right",inside_bottom:"Inside Bottom",inside_top_left:"Inside Top Left",inside_top_right:"Inside Top Right",inside_bottom_left:"Inside Bottom Left",inside_bottom_right:"Inside Bottom Right",outside:"Outside"},visual_map:{label:"Visual Map",item_width:"Bar Width",item_height:"Bar Height",calculable:"Show drag handle",min_value:"Min Value",max_value:"Max Value",min_text:"Min Text",max_text:"Max Text",use_palette_x:'Use palette "{{x}}"',built_in_palettes:"Built-in Palettes",skip_range:{lt_min:"Color for smaller values than min value",min:"Color for min value",max:"Color for max value",gt_max:"Color for greater values than max value",follow_visual_map:"follow gradient rule"}},number_or_dynamic_value:{type:{static:"Static",dynamic:"Dynamic"},dynamic:{setup:"Setup",setup_title:"Setup dynamic value",guide:"Dyanmic by a custom function"}},orientation:{label:"Orientation",horizontal:"Horizontal",vertical:"Vertical"},symbol_size:{label:"Symbol Size",static:"Static",dynamic:"Dynamic",setup:{label:"Setup",title:"Setup dynamic size",description:"Dynamic by a custom function"}},series:{label:"Series",name:"Name",y_axis:"Y Axis",data_field:"Data Field",add:"Add a series",delete:"Delete this series",line:{label:"Line",line_settings:"Line Settings",line_style:"Line Style",type:{label:"Line Type",solid:"Solid",dashed:"Dashed",dotted:"Dotted"},line_width:"Line Width",step:{label:"Step",off:"Off",start:"Start",middle:"Middle",end:"End"},smooth_line:"Smooth Line",show_name_on_line:"Display Name on Line",show_symbol_on_line:"Show Symbol on Line"},bar:{label:"Bar",stack:"Stack",stack_hint:"Stack bars by this ID",bar_gap:{label:"Bar Gap",no_gap:"No gap between bars",overlap:"Bars overlapping on each other"},bar_width:{min:"Bar Width(min)",exact:"Bar Width",max:"Bar Width(max)"}},scatter:{label:"Scatter"},group_by:{label:"Split into multiple seires by this field...",label_line:"Split into multiple lines by this field..."}},axis:{tick_label:"Tick Label",customize_label:"Customize Label",overflow:{label:"Overflow",max_width:"Max Width",truncate:"Truncate",break_line:"Break Line",break_word:"Break Word",ellipsis:"Ellipsis",section_title:{on_axis:"Overflow on Axis",in_tooltip:"Overflow in Tooltip"}},section_title:{label_format:"Label Format"},type:{value:"Value",category:"Category",time:"Time",log:"Log",click_to_learn_more:"Click <1>here</1> to learn more about these options"}},name_text:{align:{label:"Name Anchor",left:"Left",center:"Center",right:"Right"}},rotate:"Rotate",degree:"degree",padding:"Padding",content_template:{label:"Content Template",hint:"Average: ${avg}"},x_axis:{label:"X Axis",labels:"X Axes",label_format:"Label Format",add:"Add an X Axis",delete:"Delete this X Axis",x_axis_name:"X Axis Name",x_axis_data_field:"X Axis Data Field",x_axis_type:"X Axis Type",layout:"Layout",position:{label:"Position",top:"Top",bottom:"Bottom"},value_range:"Value Range",value_min:"Min",value_max:"Max",behavior:"Behavior",visible:"Visible"},y_axis:{label:"Y Axis",labels:"Y Axes",label_format:"Label Format",add:"Add a Y Axis",delete:"Delete this Y Axis",y_axis_name:"Y Axis Name",y_axis_name_anchor:"Name Anchor",y_axis_data_field:"Y Axis Data Field",layout:"Layout",position:{label:"Position",left:"Left",right:"Right"},value_range:"Value Range",value_min:"Min",value_max:"Max",behavior:"Behavior",visible:"Visible"},stats:{label:"Stats",template:{above_chart:"Template for stats above the chart",under_chart:"Template for stats under the chart"}},legend:{label:"Legend",show_legend:"Show Legend",show_in_legend:"Show in legend",hide_in_legend:"Hide in legend",orientation:{label:"Orientation",horizontal:"Horizontal",vertical:"Vertical"}},tooltip:{label:"Tooltip",additional_metrics:{description:"Set additional metrics to show in scatter's tooltip",add:"Add a metic",delete:"Delete this Metric"},trigger:{label:"Trigger",scatter_point:"Scatter Point",x_axis:"X Axis"}},style:{label:"Style"},color:{label:"Color",or:"or",set_any_color:"Set any color",pick_a_theme_color:"Pick a theme color",background_color:"Background Color",text_color:"Text Color",click_to_add_a_color:"Click to add a color",color_gradient:"Color Gradient"},behavior:{label:"Behavior",invisible:"Invisible"},heatmap:{heatblock:{label:"Heat Block",show_label:"Show Label"}},reference_line:{label:"Reference Line",labels:"Reference Lines",add:"Add a reference line",name_placeholder:"Average Reference Line",delete:"Remove this Reference Line",orientation:{vertical_hint:"Works only when xAxis values are numbers"}},regression_line:{label:"Regression Line",labels:"Regression Lines",add:"Add a line",delete:"Delete this line",method:{label:"Method",linear:"Linear",exponential:"Exponential",logistic:"Logistic",polynomial:"Polynomial",polynomial_order:"Order"}},reference_area:{label:"Reference Area",labels:"Reference Areas",add:"Add a reference area",delete:"Remove this reference area",type:{label:"Type",rectangle:"Rectangle"},direction:{label:"Direction",horizontal:"Horizontal"},boundary:{upper:"Upper Boundary",lower:"Lower Boundary"},content:{label:"Content",content_text:"Content Text",text_position:"Text Position"},endpoint:{labels:"Endpoints",left_bottom_point:"Left-Bottom Point",right_top_point:"Right-Top Point"}},zooming:{label:"Zooming",scroll:{label:"Scroll to zoom",x_axis:"Enable on X Axis",y_axis:"Enable on Y Axis"},slider:{label:"Slider for zooming",x_axis:"Slider for X Axis",y_axis:"Slider for Y Axis",y_axis_disabled:"Not available for now, will overlap y-axis's label"}}},viz:{viz_config_banner:"Visualization Settings"},validation:{number:{require_a_number:"A number is required"}}}},pk={translation:{filter:{label:"筛选器",labels:"筛选器",add:"新增筛选器",manage:"管理筛选器",show_filters:"展开筛选器",hide_filters:"收起筛选器",field:{widget:"控件",visible_in:"在...视图中可见",key_placeholder:"用于引用此筛选器,需保持唯一",label_placeholder:"用于展示的标签文案",auto_submit:"自动提交",order:"排列次序",custom_default_value:{trigger:"自定义",title:"自定义默认值",tips:"提示",tip_1:"在指定筛选器默认值这事上,自定义函数具备最高优先级",tip_2:"清空下方编辑器来禁用本功能"}},widget:{names:{select:"单选",multi_select:"多选",tree_select:"树形选择器",text_input:"文本框",checkbox:"勾选框",date_range:"日期范围"},common:{use_query_data_as_options:"使用所查数据为选项",fetch_options_from_datasource:"从数据源查选项",or_fetch_options_from_datasource:"或从数据源查选项",selector_option_empty:"无选项可用",see_data_structure:"点击查看期望的数据格式",using_query:"在用查询获取选项",default_selection_count:"默认选中前N项",min_width:"控件最小宽度",x_selected:"已选数:{{count}}"},text_input:{default_value:"默认值",required:"必填"},select:{width:"控件宽度",required:"必选",clearable:"可取消选择",configure_options:"配置选项",default_selection:"默认选项",no_default_selection:"无",select_first_option_by_default:"默认选中第一个选项"},multi_select:{width_description:"至少160px"},tree_select:{strictly:"枝叶节点不相关,各选各的"},checkbox:{description:"描述信息",default_checked:"默认勾选"},date_range:{required:"必选",allow_single_date:"允许选一天作为范围",display_format:"展示格式",max_days:"最大选择天数",one_day:"1天",x_days:"{{count}}天",x_max_days:"最多可选{{max_days}}天",default_value:"默认日期范围(具体)",default_by_shortcut:"默认日期范围(快捷方式)",defualt_by_shortcut_placeholder:"优先于左侧",start_date:"开始日期",end_date:"结束日期",shortcut:{last:{label:"过往整周期",d:"昨天",w:"周",m:"月",m2:"两个月",m3:"三个月",y:"年",full:{d:"昨天",w:"上周",m:"上个月",m2:"上两月",m3:"上三月",y:"去年"}},recent:{label:"最近",d7:"7天",d30:"30天",d60:"60天",d90:"90天",d180:"180天",d365:"365天",full:{d7:"近7天",d30:"近30天",d60:"近60天",d90:"近90天",d180:"近180天",d365:"近365天"}},this:{label:"当前整周期",d:"今天",w:"周",m:"月",y:"年",full:{d:"今天",w:"本周",m:"本月",y:"今年"}},this_so_far:{label:"至今",w:"周",m:"月",y:"年",full:{w:"本周至今",m:"本月至今",y:"本年至今"}}}}}},view:{label:"视图",labels:"视图",add:"新增视图",delete:"删除此视图",download_schema:"下载此视图描述文件",component:{div:{label:"内容"},tabs:{label:"标签页",tabs_settings:"标签页设置",tab:{name:"名称",view:"内容视图",order:"排列次序",color:"颜色",delete:"删除这个标签页",switch_to_view:"打开视图: {{name}}"}},modal:{label:"弹窗",modal_settings:"弹窗设置",title:"弹窗标题",custom_title:"自定义弹窗标题",width:"宽度",height:"高度"}}},interactions:{label:"交互",add:"新增交互",interactions_viewer:"纵览交互",unavailable:"不可用",unavailable_reason:"此可视化组件没有交互功能",trigger:{setup:"设置触发动作",label:"触发动作",payload:"触发时的参数"},operation:{setup:"操作设置",label:"操作",settings:"设置",variables:"变量",console_log:{label:"console.log | 调试用",log_content:"打印内容"},open_link:{label:"打开链接",url:"URL",open_in_new_tab:"在新标签页中打开"},open_view:{label:"唤出视图",view:"视图"},set_filter_values:{label:"设置筛选器值",set_filter:"将筛选器的值",with:"设为"},clear_filter_values:{label:"清除筛选器值",select_filter:"选择筛选器以清除其值"}}},query_variable:{label:"查询变量",labels:"查询变量",add:"新增变量",guide:{tabs:{guide:"使用指南",variables_in_this_dashboard:"本看板中的查询变量",global_sql_snippets:"全局SQL片段"}},open:"查看查询变量"},sql_snippet:{label:"SQL片段",labels:"SQL片段",add:"新增SQL片段",delete:"删除这个SQL片段",delete_unused:"删除未用到的SQL片段",manage:"管理SQL片段",key:"键",key_occupied:"此键已被其他SQL片段占用",edit_snippet:"编辑SQL片段",preview_snippet:"预览SQL片段",usage:{label:"使用情况"}},global_sql_snippet:{label:"全局SQL片段",labels:"全局SQL片段",description:"管理员负责在系统设置中维护全局SQL片段"},common:{titles:{settings:"设置",edit:"编辑",config:"配置"},pagination:{page_size:"页容量",total:"共",total_rows:"共 {{total}} 行"},align:{horizontal:{label:"水平对齐",left:"居左",center:"居中",right:"居右"},vertical:{label:"垂直对齐",left:"居上",center:"居中",right:"居下"}},id:"ID",name:"名称",key:"键",label:"标签",value:"值",type:"类型",info:"信息",min:"最小值",max:"最大值",data_field:"数据字段",name_data_field:"名称字段",value_data_field:"值字段",color_data_field:"颜色字段",enabled:"启用",copied:"已复制到剪切板",action:"操作",actions:{open:"打开",close:"关闭",save:"保存",save_changes:"保存改动",revert:"还原",revert_changes:"还原改动",reset_to_default:"重置为初始值",select_all:"全选",clear_selection:"撤销选择",refresh:"刷新",download_data:"下载数据",download_schema:"下载描述文件",download_screenshot:"下载截图",enter_fullscreen:"全屏",duplicate:"复制",delete:"删除",cancel:"取消",confirm:"确认",add_an_option:"新增选项",edit:"编辑",end_editing:"结束编辑 <1>{{name}}</1>"},tabs:{variant:{label:"风格",default:"默认",outline:"轮廓",pills:"胶囊"},orientation:{label:"朝向",horizontal:"水平",vertical:"垂直"},grow_tabs:"拉伸标签卡宽度"},choose_a_tab_first:"请先选择一个标签页"},breakpoint:{label_one:"屏幕尺寸",label_other:"屏幕尺寸",add:"新增屏幕尺寸",manage:"管理屏幕尺寸",breakpoint:"最小宽度"},context:{label:"上下文"},mock_context:{label:"模拟上下文",hint:"内容格式为JSON"},panel:{label:"卡片",labels:"卡片",add:"新增卡片",delete:"删除这个卡片",panel_name:"卡片名",panel_description:"卡片描述",panel_description_click:"点击查看卡片描述",show_title:"展示卡片标题",use_name_as_title:"使用卡片名作为标题",settings:{change_view:"移至另一个视图下",change_view_title:"移动此卡片至另一个视图下",choose_queries:"关联查询",need_to_choose_queries:"请关联至少一个查询以使用其数据"},style:{label:"样式",width:"宽",width_postfix:"之 36 栏",height:"高",height_postfix:"px",border:"边框"},variable:{label:"变量",labels:"变量",add:"新增变量",delete:"删除此变量",aggregation:{label:"聚合",fallback_value:"兜底值",fallback_value_description:"当数据为空或聚合结果非数字时,使用此兜底值"}}},style:{label:"样式",font_size:{label:"字号",placeholder:"10px, 1em, 1rem, 100%..."},font_weight:{label:"字重"},size:{xs:"特小",sm:"小",md:"中",lg:"大",xl:"特大"},flex:{justify_content:{label:"内容分布",left:"从左起",center:"居中",right:"从右起",space_between:"均匀分布,首尾顶格",space_around:"均匀分布,首尾留空一半",space_evenly:"均匀分布,首尾留空"},align_items:{label:"对齐位置",start:"起点对齐",center:"居中对齐",end:"末端对齐",stretch:"拉伸对齐"}},color:{type:{label:"颜色类型",static:"单色",interpolation:"插值取色",none:"无"},interpolation:{setup:"设置取色方案",palette:{label:"色板",category:{sequential:"单色渐变",diverging:"双色渐变"},red_green:"红 / 绿",yellow_blue:"黄 / 蓝",red:"红",green:"绿",blue:"蓝",orange:"橙",mapping:{value_input_label:"映射一个值到此颜色"}}}}},query:{label:"查询",labels:"查询",add:"新增查询",delete:"删除这个查询",cant_delete:"此查询在使用中,不能删除。请查看“使用情况”标签页以了解详情",delete_unused:"删除未用到的查询",name:"名称",name_description:"唯一名称",manage:"管理查询",open:"打开此查询",configurations:"配置",basics:"基本信息",conditions:"条件",run_by_condition:{label:"以下条件满足时,才运行本查询",unset:"看板加载时便运行本查询"},re_run_condition:{label:"当以下条件改变时,重新运行此查询",unset:"留空则永不重新运行此查询"},dependency:{label:"依赖",has_none:"此查询无依赖"},edit_sql:"编辑SQL",preview_sql:"预览SQL",request:"请求",build_request:"构造请求",process_request:"加工请求",process_result:"加工结果",usage:{label:"使用情况",in_views:"所在视图",unused_description:"此查询未被任何筛选器或卡片用到"},transform:{label:"查询变形",full_label:"查询变形",data_source:"基于其他查询的数据,加工出新数据",guide:{pick_queries:"选择一至多个查询作为数据输入",write_function:"编写函数,返回新数据"}}},data:{label:"数据",preview_data:"预览数据",empty_data:"无数据",requires_data:"请先关联查询"},data_source:{label:"数据源",explore:"查看数据源",explorer:"数据源查看器",table_structure:"数据表结构",table_structure_short:"表结构",see_table_structure:"查看数据表结构"},visualization:{label:"可视化",component:"可视化组件",label_short:"可视化"},numbro:{format:{label:"格式",absolute:"绝对值",absolute_description:"非负",abbreviation:"缩写",abbreviation_description:"如1.23k、1.23m",mantissa:"小数",trim_mantissa:"抹零",trim_mantissa_description:"省略末尾的零",preview:{open:"展开预览",close:"收起预览",input:"输入",output:"输出"}}},import:{label:"导入...",title:"自描述文件导入看板内容",json_file:"描述文件(JSON格式)",this_dashboard:"此看板",this_file:"此文件"},function_utils:{trigger_text:"关于utils参数",modal_title:"关于utils参数",description:"参数 <code>utils</code> 是 <code>FunctionUtils</code>,包含以下内容:",document:"文档"},aggregation:{option:{none:"无",sum:"和",mean:"平均值",median:"中位数",min:"最小值",max:"最大值",cov:"变异系数",std:"标准差",quantile:{label:"分位",label_with_hint:"分位(99%, 95%, ...)"},custom:{label:"自定义",label_trigger:"编写函数",title:"自定义聚合方式"}}},chart:{chart_config:"图表设置",data_field:"数据字段",groups:{merico_suite:"思码逸套件",echarts_based_charts:"基于ECharts的图表",others:"其他"},label:{label:"文案",label_full:"标签文案",label_style:"标签文案样式",label_format:"标签文案格式"},label_position:{label:"文案位置",off:"不显示文案",top:"上",left:"左",right:"右",bottom:"下",inside:"内",inside_top:"内-上",inside_left:"内-左",inside_center:"内-中",inside_right:"内-右",inside_bottom:"内-下",inside_top_left:"内-上-左",inside_top_right:"内-上-右",inside_bottom_left:"内-下-左",inside_bottom_right:"内-下-右",outside:"外"},visual_map:{label:"视觉映射",item_width:"长条的宽度",item_height:"长条的高度",calculable:"显示拖拽手柄",min_value:"最小值",max_value:"最大值",min_text:"最小值文案",max_text:"最大值文案",use_palette_x:'使用配色方案"{{x}}"',built_in_palettes:"内置配色方案",skip_range:{lt_min:"小于最小值时的颜色",min:"最小值的颜色",max:"最大值的颜色",gt_max:"大于最大值时的颜色",follow_visual_map:"颜色跟随渐变规则"}},number_or_dynamic_value:{type:{static:"具体值",dynamic:"动态值"},dynamic:{setup:"设置",setup_title:"设置动态值",guide:"由函数确定动态值"}},orientation:{label:"朝向",horizontal:"水平",vertical:"垂直"},symbol_size:{label:"标记点大小",static:"固定值",dynamic:"动态值",setup:{label:"设置",title:"设置动态值",description:"由函数确定动态值"}},series:{label:"系列",name:"名称",y_axis:"Y轴",data_field:"数据字段",add:"增加一个系列",delete:"删除这个系列",line:{label:"线",line_settings:"线段设置",line_style:"线条样式",type:{label:"类型",solid:"实线",dashed:"方虚线",dotted:"圆点虚线"},line_width:"线宽",step:{label:"阶梯状",off:"不启用",start:"在当前点拐弯",middle:"在当前点与下个点中间拐弯",end:"在下个点拐弯"},smooth_line:"平滑曲线",show_name_on_line:"显示标签文案",show_symbol_on_line:"显示标记点"},bar:{label:"柱",stack:"堆放",stack_hint:"此值相同的柱系列会堆叠在一起",bar_gap:{label:"柱间隔",no_gap:"柱子之间无间隔",overlap:"柱子可互相重叠"},bar_width:{min:"最大柱宽",exact:"柱宽",max:"最大柱宽"}},scatter:{label:"散点"},group_by:{label:"按此字段拆分为多个系列",label_line:"按此字段拆分为多条线"}},axis:{tick_label:"刻度文案",customize_label:"自定义文案",overflow:{label:"溢出",max_width:"最大宽度",truncate:"截断",break_line:"换行",break_word:"断词换行",ellipsis:"省略符",section_title:{on_axis:"轴刻度上文案的溢出",in_tooltip:"提示框中的文案溢出"}},section_title:{label_format:"文案格式"},type:{value:"数值轴",category:"类目轴",time:"时间轴",log:"对数轴",click_to_learn_more:"点击 <1>这里</1> 以进一步了解这些选项"}},name_text:{align:{label:"名称贴靠侧",left:"左",center:"中",right:"右"}},rotate:"旋转",degree:"度",padding:"内间距",content_template:{label:"内容模板",hint:"均值: ${avg}"},x_axis:{label:"X轴",labels:"X轴",label_format:"刻度文案格式",add:"增加一条X轴",delete:"删除这条X轴",x_axis_name:"X轴名称",x_axis_data_field:"X轴数据字段",x_axis_type:"X轴类型",layout:"布局",position:{label:"位置",top:"上",bottom:"下"},value_range:"值范围",value_min:"最小值",value_max:"最大值",behavior:"表现",visible:"可见"},y_axis:{label:"Y轴",labels:"Y轴",label_format:"刻度文案格式",add:"增加一条Y轴",delete:"删除这条Y轴",y_axis_name:"Y轴名称",y_axis_name_anchor:"名称贴靠侧",y_axis_data_field:"Y轴数据字段",layout:"布局",position:{label:"位置",left:"左",right:"右"},value_range:"值范围",value_min:"最小值",value_max:"最大值",behavior:"表现",visible:"可见"},stats:{label:"统计内容",template:{above_chart:"统计内容模板(图表上方)",under_chart:"统计内容模板(图表下方)"}},legend:{label:"图例",show_legend:"显示图例",show_in_legend:"显示在图例中",hide_in_legend:"不显示在图例中",orientation:{label:"布局朝向",horizontal:"横向",vertical:"纵向"}},tooltip:{label:"提示框",additional_metrics:{description:"在此设置更多指标,来展示在散点的提示框",add:"增加一个指标",delete:"删除这个指标"},trigger:{label:"触发者",scatter_point:"散点",x_axis:"X轴"}},style:{label:"样式"},color:{label:"颜色",or:"或",set_any_color:"输入色号",pick_a_theme_color:"选择一个主题色",background_color:"背景色",text_color:"文字颜色",click_to_add_a_color:"点击增加一个颜色",color_gradient:"颜色渐变"},behavior:{label:"表现",invisible:"隐藏不可见"},heatmap:{heatblock:{label:"热力块",show_label:"展示值文案"}},reference_line:{label:"参考线",labels:"参考线",add:"增加一条参考线",name_placeholder:"均值参考线",delete:"删除这条参考线",orientation:{vertical_hint:"仅当X轴值为数字时可绘制"}},regression_line:{label:"回归线",labels:"回归线",add:"增加一条回归线",delete:"删除这条回归线",method:{label:"方法",linear:"线性回归",exponential:"指数回归",logistic:"指数回归",polynomial:"多项式回归",polynomial_order:"次"}},reference_area:{label:"参考区域",labels:"参考区域",add:"增加一面参考区域",delete:"删除这面参考区域",type:{label:"形状",rectangle:"矩形"},direction:{label:"方向",horizontal:"水平"},boundary:{upper:"上边界",lower:"下边界"},content:{label:"内容",content_text:"内容文字",text_position:"文字位置"},endpoint:{labels:"端点",left_bottom_point:"左下点",right_top_point:"右上点"}},zooming:{label:"缩放",scroll:{label:"滚轮缩放",x_axis:"对X轴启用",y_axis:"对Y轴启用"},slider:{label:"滚动条缩放",x_axis:"对X轴启用",y_axis:"对Y轴启用",y_axis_disabled:"暂不可用,会与Y轴刻度文字重叠"}}},viz:{viz_config_banner:"可视化参数配置"},validation:{number:{require_a_number:"请填写一个数字"}}}},ps=rd.createInstance({debug:!1,fallbackLng:"en",interpolation:{escapeValue:!1},resources:{en:dk,zh:pk}}).use(id).use(_.initReactI18next);ps.init(),pl.forEach(t=>{var e;(e=t.translation)==null||e.forEach(n=>{ps.addResourceBundle(n.lang,"translation",{viz:n.resources},!0,!0)})});function kc({lang:t,children:e}){return m.useEffect(()=>{ps.changeLanguage(t)},[t]),s.jsx(_.I18nextProvider,{i18n:ps,children:e})}function Tc(t,e){m.useEffect(()=>{const n=r=>{console.log(r);const{viewID:i}=r.detail;if(!i){console.error(new Error("[Open View] Needs to pick a view first"));return}t.views.appendToVisibles(i),e&&t.views.setIDOfVIE(i)};return window.addEventListener("open-view",n),()=>{window.removeEventListener("open-view",n)}},[t,e]),m.useEffect(()=>{const n=r=>{console.log(r);const{dictionary:i,payload:a}=r.detail;if(!a||Object.keys(a).length===0){console.error(new Error("[Set Filter Values] payload is empty"));return}Object.entries(i).forEach(([l,c])=>{t.filters.setValueByKey(l,x.get(a,c))})};return window.addEventListener("set-filter-values",n),()=>{window.removeEventListener("set-filter-values",n)}},[t]),m.useEffect(()=>{function n(i){return Array.isArray(i)?[]:typeof i=="object"?{}:typeof i=="boolean"?!1:typeof i=="string"?"":typeof i=="number"?0:i}const r=i=>{console.log(i);const{filter_keys:a}=i.detail;a.forEach(l=>{const c=x.get(t.filters.values,l),u=n(c);console.log(`${l}: ${u}`),t.filters.setValueByKey(l,u)})};return window.addEventListener("clear-filter-values",r),()=>{window.removeEventListener("clear-filter-values",r)}},[t]),m.useEffect(()=>{const n=r=>{console.log(r);const{urlTemplate:i,openInNewTab:a,enableEncoding:l=!1,payload:c}=r.detail;if(!i){console.error(new Error("[Open Link] URL is empty"));return}function u(h){return x.cloneDeepWith(h,y=>{if(l&&typeof y=="string")return encodeURIComponent(y)})}const p=x.template(i||"")(u({...c,filters:t.payloadForSQL.filters,context:t.payloadForSQL.context}));window.open(p,a?"_blank":"_self","noopener")};return window.addEventListener("open-link",n),()=>{window.removeEventListener("open-link",n)}},[t])}function Dc(t){return m.useCallback(e=>e.provideValue(pe.pluginManager,t.pluginManager).provideValue(pe.vizManager,t.vizManager).provideValue(pe.colorManager,t.colorManager),[])}const mM="",hk=S.observer(({saveDashboardChanges:t})=>{const{t:e}=_.useTranslation(),n=Le.useModals(),r=U(),i=()=>{n.openConfirmModal({title:s.jsxs(o.Group,{position:"left",children:[s.jsx(k.IconAlertTriangle,{size:18,color:"red"}),s.jsx(o.Text,{children:"You are reverting changes"})]}),labels:{confirm:e("common.actions.confirm"),cancel:e("common.actions.cancel")},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:()=>r.reset(),zIndex:320,withCloseButton:!1})},a=r.changed;return s.jsxs(o.Group,{spacing:0,children:[s.jsx(o.Button,{color:"green",variant:"filled",size:"xs",leftIcon:s.jsx(k.IconDeviceFloppy,{size:18}),onClick:t,disabled:!a,sx:{borderTopRightRadius:0,borderBottomRightRadius:0},children:e("common.actions.save_changes")}),s.jsxs(o.Menu,{width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:320,disabled:!a,children:[s.jsx(o.Menu.Target,{children:s.jsx(o.ActionIcon,{variant:"default",disabled:!a,sx:{height:"30px",borderTopLeftRadius:0,borderBottomLeftRadius:0,svg:{fill:"rgb(173, 181, 189)",stroke:"none"}},children:s.jsx(k.IconCaretDown,{size:18})})}),s.jsx(o.Menu.Dropdown,{children:s.jsx(o.Menu.Item,{icon:s.jsx(k.IconRecycle,{size:14,color:"red"}),disabled:!a,onClick:i,children:e("common.actions.revert_changes")})})]})]})}),mk=S.observer(({saveDashboardChanges:t,onExit:e,headerSlot:n=null})=>{_.useTranslation();const r=H(),i=r.content.changed,a=()=>{e({hasChanges:i,dashboardId:r.id})};return s.jsx(o.Header,{height:60,px:"md",py:0,sx:{zIndex:299},children:s.jsxs(o.Group,{position:"apart",sx:{height:60,minWidth:"1000px",position:"relative"},children:[s.jsxs(o.Group,{children:[s.jsx(o.Button,{size:"xs",color:i?"red":"green",leftIcon:s.jsx(k.IconArrowLeft,{size:20}),onClick:a,children:s.jsx(o.Group,{spacing:4,children:s.jsxs(_.Trans,{i18nKey:"common.actions.end_editing",values:{name:r.name},children:["End Editing ",s.jsx(o.Text,{td:"underline",children:r.name})]})})}),s.jsx(hk,{saveDashboardChanges:t})]}),s.jsx(o.Group,{position:"right",sx:{flexGrow:1},children:n})]})})}),zc={height:"30px",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},fk=S.observer(()=>{var i;const{t}=_.useTranslation(),e=U(),n=((i=e.views.VIE)==null?void 0:i.type)===q.Tabs,r=()=>e.addANewPanel(e.views.idOfVIE);return n?s.jsx(o.Tooltip,{label:t("common.choose_a_tab_first"),children:s.jsx(o.Button,{variant:"outline",color:"gray",radius:0,size:"xs",leftIcon:s.jsx(k.IconPlaylistAdd,{size:20}),sx:{...zc,transform:"none !important"},children:t("panel.add")})}):s.jsx(o.Button,{variant:"outline",color:"blue",radius:0,size:"xs",onClick:r,leftIcon:s.jsx(k.IconPlaylistAdd,{size:20}),sx:{...zc,background:"rgb(231, 245, 255)"},children:t("panel.add")})}),gk=S.observer(({done:t})=>{var J,Q;const{t:e}=_.useTranslation(),r=U().layouts,i=m.useMemo(()=>({list:r.breakpointsInfo}),[r.breakpointsInfo]),{control:a,handleSubmit:l,watch:c,getValues:u,reset:d,formState:p}=b.useForm({defaultValues:i}),{fields:h,append:g,remove:y}=b.useFieldArray({control:a,name:"list",rules:{validate:F=>{if(console.log({values:F}),x.uniqBy(F,"breakpoint").length!==F.length)return"Screen sizes should be unique by min width"}}}),v=c("list"),C=h.map((F,Z)=>({...F,...v[Z]})),T=()=>{g({id:lt.v4(),name:"",breakpoint:""})},D=({list:F})=>{const Z=F.filter(ve=>Number.isFinite(ve.breakpoint));r.updateLayoutSetsInfo(Z),t()},I=u(),P=m.useMemo(()=>{const F={list:I.list.filter(Z=>!!Z.name&&Number.isFinite(Z.breakpoint))};return!x.isEqual(F,i)},[I,i]),W=(Q=(J=p.errors.list)==null?void 0:J.root)==null?void 0:Q.message;return s.jsx(s.Fragment,{children:s.jsxs("form",{onSubmit:l(D),children:[s.jsxs(o.Table,{fontSize:"sm",highlightOnHover:!0,withBorder:!0,sx:{tableLayout:"fixed"},children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"340px"},children:e("common.name")}),s.jsx("th",{style:{width:"160px"},children:e("breakpoint.breakpoint")}),s.jsx("th",{})]})}),s.jsxs("tbody",{children:[C.map((F,Z)=>s.jsxs("tr",{children:[s.jsx("th",{children:F.id==="basis"?F.name:s.jsx(b.Controller,{name:`list.${Z}.name`,control:a,render:({field:ve})=>s.jsx(o.TextInput,{size:"xs",label:"",required:!0,sx:{flex:1},...ve})})}),s.jsx("td",{children:F.id==="basis"?s.jsxs(o.Text,{ff:"monospace",children:[F.breakpoint,"px"]}):s.jsx(b.Controller,{name:`list.${Z}.breakpoint`,control:a,render:({field:ve})=>s.jsx(o.NumberInput,{size:"xs",label:"",required:!0,max:1e4,hideControls:!0,rightSection:s.jsx(o.Text,{color:"dimmed",children:"px"}),rightSectionProps:{style:{width:"30px"}},sx:{flex:1,fontFamily:"monospace"},styles:{input:{paddingRight:"30px"}},...ve})})}),s.jsx("td",{children:F.id!=="basis"&&s.jsx(o.ActionIcon,{mx:"auto",size:"xs",variant:"subtle",color:"red",onClick:()=>y(Z),children:s.jsx(k.IconTrash,{})})})]},F.id)),s.jsx("tr",{style:{backgroundColor:"transparent"},children:s.jsx("td",{colSpan:3,style:{padding:"0"},children:s.jsx(o.Tooltip,{label:e("breakpoint.add"),children:s.jsx(o.ActionIcon,{variant:"subtle",size:"md",color:"blue",onClick:T,sx:{width:"100%"},children:s.jsx(k.IconPlus,{size:18})})})})})]})]}),s.jsx(o.Text,{mt:6,ta:"right",size:"xs",color:"red",children:W??" "}),s.jsxs(o.Group,{mt:6,position:"apart",children:[s.jsx(o.Button,{color:"orange",size:"xs",onClick:()=>d(),leftIcon:s.jsx(k.IconRecycle,{size:18}),disabled:!P,children:e("common.actions.revert")}),s.jsx(o.Button,{color:"green",size:"xs",type:"submit",leftIcon:s.jsx(k.IconDeviceFloppy,{size:18}),disabled:!P,children:e("common.actions.save_changes")})]})]})})}),xk=S.observer(()=>{const{t}=_.useTranslation(),[e,{open:n,close:r}]=ie.useDisclosure(!1),i=U(),a=i.layouts.currentBreakpoint,l=i.layouts.currentLayoutRange,c=()=>{setTimeout(()=>{window.dispatchEvent(new Event("resize"))},32)},u=()=>{r(),c()};return s.jsxs(s.Fragment,{children:[s.jsxs(o.Group,{children:[s.jsxs(o.Menu,{withArrow:!0,withinPortal:!0,zIndex:320,trigger:"hover",children:[s.jsx(o.Menu.Target,{children:s.jsx(o.Button,{size:"xs",variant:"subtle",leftIcon:s.jsx(k.IconDevices,{size:16}),sx:{borderRadius:0},children:s.jsxs(o.Group,{spacing:6,children:[s.jsx(o.Text,{size:"xs",fw:"normal",children:l.name}),s.jsx(o.Text,{size:"xs",color:"#777",children:i.layouts.currentRangeText})]})})}),s.jsxs(o.Menu.Dropdown,{children:[i.layouts.breakpointRanges.map(d=>s.jsx(o.Menu.Item,{onClick:()=>i.layouts.setCurrentBreakpoint(d.id),disabled:a===d.id,children:s.jsxs(o.Group,{position:"apart",children:[s.jsx(o.Text,{size:"sm",children:d.name}),s.jsx(o.Text,{size:"xs",color:"dimmed",children:d.text})]})},d.id)),s.jsx(o.Menu.Divider,{}),s.jsx(o.Menu.Item,{color:"blue",icon:s.jsx(k.IconSettings,{size:14}),onClick:n,children:s.jsx(o.Text,{size:"sm",children:t("breakpoint.manage")})})]})]}),i.layouts.divisionPreviewScale<1&&s.jsx(o.Text,{size:"xs",color:"dimmed",children:wn(i.layouts.divisionPreviewScale).format({output:"percent",mantissa:0})})]}),s.jsx(o.Modal,{opened:e,onClose:u,title:t("breakpoint.label",{count:2}),withinPortal:!0,zIndex:320,size:600,closeOnClickOutside:!1,children:s.jsx(gk,{done:u})})]})}),Mc={height:"30px",borderRight:"none",borderTop:"none",borderLeft:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},yk=S.observer(()=>{var i;const{t}=_.useTranslation(),e=U(),n=((i=e.views.VIE)==null?void 0:i.type)===q.Tabs,r=()=>{var a;return(a=e.views.VIE)==null?void 0:a.downloadSchema()};return n?s.jsx(o.Tooltip,{label:t("common.choose_a_tab_first"),children:s.jsx(o.Button,{variant:"outline",color:"gray",radius:0,size:"xs",leftIcon:s.jsx(k.IconCode,{size:16}),sx:{...Mc,transform:"none !important"},children:t("view.download_schema")})}):s.jsx(o.Button,{variant:"outline",color:"blue",radius:0,size:"xs",onClick:r,leftIcon:s.jsx(k.IconCode,{size:16}),sx:{...Mc},children:t("view.download_schema")})}),hs=({headers:t,rows:e})=>s.jsxs(o.Table,{fontSize:"xs",highlightOnHover:!0,sx:{tableLayout:"fixed",fontFamily:"monospace"},children:[s.jsx("thead",{children:t}),s.jsx("tbody",{children:e})]}),bk=({content:t})=>{const{t:e}=_.useTranslation(),n=t.views;return!Array.isArray(n)||n.length===0?null:s.jsxs(o.Box,{children:[s.jsx(o.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:e("view.labels")}),s.jsx(hs,{headers:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"160px"},children:e("common.id")}),s.jsx("th",{children:e("common.name")}),s.jsx("th",{children:e("common.type")})]}),rows:n.map(r=>s.jsxs("tr",{children:[s.jsx("td",{children:r.id}),s.jsx("td",{children:r.name}),s.jsx("td",{children:e(`view.component.${r.type}.label`)})]},r.id))})]})},vk=({content:t})=>{const{t:e}=_.useTranslation(),n=t.filters;return!Array.isArray(n)||n.length===0?null:s.jsxs(o.Box,{children:[s.jsx(o.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:e("filter.labels")}),s.jsx(hs,{headers:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"160px"},children:e("common.id")}),s.jsx("th",{children:e("common.key")}),s.jsx("th",{children:e("common.label")})]}),rows:n.map(r=>s.jsxs("tr",{children:[s.jsx("td",{children:r.id}),s.jsx("td",{children:r.key}),s.jsx("td",{children:r.label})]},r.id))})]})},_k=({content:t})=>{const{t:e}=_.useTranslation(),n=t.panels;return!Array.isArray(n)||n.length===0?null:s.jsxs(o.Box,{children:[s.jsx(o.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:e("panel.labels")}),s.jsx(hs,{headers:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"160px"},children:e("common.id")}),s.jsx("th",{children:e("common.name")}),s.jsx("th",{children:e("visualization.component")})]}),rows:n.map(r=>s.jsxs("tr",{children:[s.jsx("td",{children:r.id}),s.jsx("td",{children:r.name}),s.jsx("td",{children:r.viz.type})]},r.id))})]})},jk=({content:t})=>{var r;const{t:e}=_.useTranslation(),n=(r=t.definition)==null?void 0:r.queries;return!Array.isArray(n)||n.length===0?null:s.jsxs(o.Box,{children:[s.jsx(o.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:e("query.labels")}),s.jsx(hs,{headers:s.jsxs("tr",{children:[s.jsx("th",{style:{width:"160px"},children:e("common.id")}),s.jsx("th",{children:e("common.name")}),s.jsx("th",{style:{width:"140px"},children:e("common.type")}),s.jsx("th",{style:{width:"260px"},children:e("data_source.label")})]}),rows:n.map(i=>s.jsxs("tr",{children:[s.jsx("td",{children:i.id}),s.jsx("td",{children:i.name}),s.jsx("td",{children:i.type}),s.jsx("td",{children:i.key})]},i.id))})]})},wk=({content:t})=>{var r;const{t:e}=_.useTranslation(),n=(r=t.definition)==null?void 0:r.sqlSnippets;return!Array.isArray(n)||n.length===0?null:s.jsxs(o.Box,{children:[s.jsx(o.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:e("sql_snippet.labels")}),s.jsx(o.List,{size:"sm",pl:10,ff:"monospace",icon:s.jsx(k.IconPointFilled,{size:10}),children:n.map(i=>s.jsx(o.List.Item,{children:i.key},i.key))})]})},Ck=({content:t})=>{var r;const{t:e}=_.useTranslation(),n=Object.keys(((r=t.definition)==null?void 0:r.mock_context)??{});return n.length===0?null:s.jsxs(o.Box,{children:[s.jsx(o.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:e("mock_context.label")}),s.jsx(o.List,{size:"sm",pl:10,ff:"monospace",icon:s.jsx(k.IconPointFilled,{size:10}),children:n.map(i=>s.jsx(o.List.Item,{children:i},i))})]})},Sk=({content:t})=>t?s.jsxs(o.Box,{children:[s.jsx(o.Divider,{mt:20,mb:10,variant:"dashed"}),s.jsx(o.Text,{ta:"left",c:"dimmed",children:"Preview"}),s.jsxs(o.Stack,{children:[s.jsx(bk,{content:t}),s.jsx(vk,{content:t}),s.jsx(_k,{content:t}),s.jsx(jk,{content:t}),s.jsx(wk,{content:t}),s.jsx(Ck,{content:t})]})]}):null;function kk(t){if(t.target===null)throw new Error("FileReader failed with null result");if(typeof t.target.result!="string")throw new Error(`Unparsable file content of type: ${typeof t.target.result}`);let e=JSON.parse(t.target.result);if("content"in e&&(e=e.content),e.version!==ft)throw new Error("Schema version mismatch");return e}const Tk=S.observer(({onSuccess:t,stretchModal:e,shrinkModal:n})=>{var D,I;const{t:r}=_.useTranslation(),i=U(),{handleSubmit:a,formState:{errors:l},setValue:c,watch:u,setError:d,clearErrors:p}=b.useForm({defaultValues:{content:null}}),h=({content:P})=>{try{if(!P)throw new Error("please use a valid json file");i.applyJSONSchema(P),bt.showNotification({title:"Successful",message:"",color:"green"}),t()}catch(W){console.error(W),bt.showNotification({title:"Failed",message:W.message,color:"red"})}},[g,y]=m.useState(null);m.useEffect(()=>{if(!g)return;const P=new FileReader;P.readAsText(g,"UTF-8"),P.onload=W=>{try{const J=kk(W);c("content",J),p("content")}catch(J){console.error(J),d("content",{type:"custom",message:J.message})}},P.onabort=()=>console.log("🟨 abort"),P.onerror=()=>{P.error&&(console.error(P.error),d("content",{type:"custom",message:P.error.message}))}},[g]);const[v]=u(["content"]),C=!v,T=(D=l==null?void 0:l.content)==null?void 0:D.message;return m.useEffect(()=>{!v||T?n():e()},[v,T]),s.jsx(o.Box,{mx:"auto",sx:{position:"relative"},children:s.jsxs("form",{onSubmit:a(h),children:[s.jsx(o.FileInput,{label:r("import.json_file"),required:!0,value:g,onChange:y,error:(I=l==null?void 0:l.content)==null?void 0:I.message,sx:{maxWidth:500}}),T?s.jsx(o.Table,{fontSize:12,mt:10,children:s.jsxs("tbody",{children:[s.jsxs("tr",{children:[s.jsx("th",{children:r("import.this_dashboard")}),s.jsx("td",{children:ft})]}),s.jsxs("tr",{children:[s.jsx("th",{children:r("import.this_file")}),s.jsx("td",{style:{color:"red"},children:v==null?void 0:v.version})]})]})}):s.jsxs(s.Fragment,{children:[s.jsx(Sk,{content:v}),s.jsx(o.Group,{position:"right",my:"md",children:s.jsx(o.Button,{type:"submit",color:"green",disabled:C,children:r("common.actions.confirm")})})]})]})})}),Ic={height:"30px",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},Dk=S.observer(()=>{var d;const{t}=_.useTranslation(),[e,{open:n,close:r}]=ie.useDisclosure(!1),[i,{setTrue:a,setFalse:l}]=N.useBoolean(!1),u=((d=H().content.views.VIE)==null?void 0:d.type)===q.Tabs;return u?s.jsx(o.Tooltip,{label:t("common.choose_a_tab_first"),children:s.jsx(o.Button,{variant:"outline",color:"gray",radius:0,size:"xs",leftIcon:s.jsx(k.IconFileImport,{size:16}),sx:{...Ic,transform:"none !important"},children:t("import.label")})}):s.jsxs(s.Fragment,{children:[s.jsx(o.Button,{variant:"subtle",color:"blue",radius:0,size:"xs",disabled:u||e,onClick:n,leftIcon:s.jsx(k.IconFileImport,{size:16}),sx:{...Ic},children:t("import.label")}),s.jsx(o.Modal,{opened:e,onClose:r,title:t("import.title"),trapFocus:!0,onDragStart:p=>{p.stopPropagation()},withinPortal:!0,zIndex:320,size:i?"90vw":500,children:s.jsx(Tk,{onSuccess:r,stretchModal:a,shrinkModal:l})})]})}),zk={position:"fixed",top:60,left:0,right:0,height:30,zIndex:299,borderBottom:"1px solid #e9ecef",background:"rgba(233,236,239, 0.15)"},Mk=S.observer(()=>s.jsx(o.Box,{sx:zk,pl:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},children:s.jsxs(o.Group,{position:"apart",align:"center",sx:{height:"30px"},children:[s.jsxs(o.Group,{position:"left",spacing:0,children:[s.jsx(fk,{}),s.jsx(Dk,{})]}),s.jsx(xk,{}),s.jsx(o.Group,{position:"right",spacing:0,children:s.jsx(yk,{})})]})})),Ik=S.observer(t=>s.jsxs(s.Fragment,{children:[s.jsx(mk,{...t}),s.jsx(Mk,{})]})),fM="";function Ek(t,e,n){const r=[];return t.filter(i=>"__INTERACTIONS"in i.viz.conf).forEach((i,a)=>{const l=e[i.id];l.data.interactions=x.get(l,"data.interactions",[]);const{__INTERACTIONS:c,__OPERATIONS:u,__TRIGGERS:d}=i.viz.conf;Object.entries(u).forEach(([p,h])=>{const{schemaRef:g,data:y}=h,{config:v}=y;switch(g){case"builtin:op:open-link":let C=v.urlTemplate.substring(0,100);v.urlTemplate.length>=20&&(C+="..."),l.type="interaction",l.data.interactions.push({schemaRef:g,urlTemplate:v.urlTemplate,shortURLTemplate:C});return;case"builtin:op:open_view":r.push({id:`OPERATION--${p}`,source:i.id,target:v.viewID,label:"Open View",style:{stroke:"rgba(0,0,0,0.8)"},type:"default"});return;case"builtin:op:set_filter_values":l.type="interaction",l.data.interactions.push({schemaRef:g,filters:Object.keys(v.dictionary).map(T=>({key:T,label:n[T]}))});return;case"builtin:op:clear_filter_values":l.type="interaction",l.data.interactions.push({schemaRef:g,filters:v.filter_keys.map(T=>({key:T,label:n[T]}))});return;default:return}})}),r}function Ak(t,e){const n=t.filters.keyLabelMap;return{edges:Ek(t.panels.list,e,n),edgeNodes:[]}}function Ec(t,e,n){return t*e+t*n}function Pk(t,e,n){return t*e+(t-1)*n}const ms=25,_i=40,Ac=25,ji=350,$k=150,Bk=150,Pc=150,$c=300,fs=40,Bc=25,qk=300;function Lk(t,e){const n=x.keyBy(e,i=>i.id),r=[];return t.current.forEach((i,a)=>{i.panelIDs.forEach((l,c)=>{const u=Ec(c,fs,Bc)+_i,d=n[l];if(!d){r.push({id:l,_node_type:"panel",parentNode:i.id,data:{label:`!: ${l}`},position:{x:ms,y:u},sourcePosition:_e.Position.Right,targetPosition:_e.Position.Left,style:{width:$c,height:fs}});return}const p=d.name;r.push({id:d.id,_node_type:"panel",parentNode:i.id,data:{label:p},position:{x:ms,y:u},sourcePosition:_e.Position.Right,targetPosition:_e.Position.Left,style:{width:$c,height:fs}})})}),r}const Ok={[q.Division]:"Div",[q.Modal]:"Modal",[q.Tabs]:"Tabs"},Vk=fc;function Nk(t){return t.current.map((n,r)=>{const i=Pk(n.panelIDs.length,fs,Bc)+_i+Ac;let a=[];return n.type===q.Tabs&&(a=n.config.tabsInOrder.map(c=>c.view_id)),{id:n.id,_node_type:"view-root",_view_type:n.type,_view_level:0,_sub_view_ids:[],_tab_view_ids:a,data:{label:`${Ok[n.type]}:${n.name}`},position:{x:0,y:0},sourcePosition:_e.Position.Right,targetPosition:_e.Position.Left,className:"light",style:{backgroundColor:Vk[n.type],width:ji,height:i}}})}function Gk(t){const e=x.keyBy(t,n=>n.id);t.forEach(n=>{n._node_type!=="view-root"||n._view_type!==q.Tabs||n._tab_view_ids.forEach(r=>{e[r].parentNode=n.id})})}function Fk(t){const e=Nk(t.views);Gk(e);const n=Lk(t.views,t.panels.list);return[...e,...n]}function Wk({nodeMap:t,nodes:e,edges:n}){e.forEach(r=>{r._node_type!=="view-root"||r._view_type!==q.Tabs||(r.sourcePosition=_e.Position.Bottom,r.style.width=ji+ms*2,r.style.height=Ac+r._tab_view_ids.reduce((i,a)=>{const l=t[a];l.position.y=i,l.position.x=ms;const c=l.style.height;return i+c+20},_i))})}function Qk({nodeMap:t,nodes:e,edges:n}){n.filter(r=>r.label==="Open View").forEach(r=>{const i=t[r.source],a=t[r.target];if(!i||!a||!i.parentNode)return;const l=t[i.parentNode];l._node_type!=="view-root"||a._node_type!=="view-root"||(a._view_level+=1+l._view_level,l._sub_view_ids.push(a.id))}),e.sort((r,i)=>r._node_type==="view-root"&&i._node_type==="view-root"?r._view_level-i._view_level:r._node_type!=="view-root"&&i._node_type!=="view-root"?0:r._node_type==="view-root"?-1:1)}function Rk({nodeMap:t,nodes:e,edges:n}){const r={};n.forEach(i=>{if(i.label!=="Open View")return;const a=t[i.source],l=t[i.target];if(a&&l&&a.parentNode){const c=t[a.parentNode],u=c.position.x,d=Number(x.get(l,"style.height",0)),p=Number(c.style.width);l.position.x=u+p+qk,c._view_level===0&&l._sub_view_ids.length===0&&(a.sourcePosition=_e.Position.Left,l.targetPosition=_e.Position.Right,l.position.x*=-1);const g=l.position.x,y=x.get(r,g,0);l.position.y=y,r[g]=y+d+Pc}})}function Uk({nodeMap:t,nodes:e,edges:n}){const r=new Set,i=new Set;n.forEach(l=>{r.add(l.source),i.add(l.target)}),e.filter(l=>l._node_type!=="view-root"||l.id==="Main"||l.parentNode?!1:!r.has(l.id)&&!i.has(l.id)).forEach((l,c)=>{l.position.x=Ec(c,ji,Bk),l.position.y=0-$k-Pc})}function Yk({nodeMap:t,nodes:e,edges:n}){const r={nodeMap:t,nodes:e,edges:n};return Uk(r),Qk(r),Wk(r),Rk(r),{nodes:e,edges:n}}function Kk(t){const e=Fk(t),n=x.keyBy(e,u=>u.id),{edges:r,edgeNodes:i}=Ak(t,n),a=[...e,...i],l=x.keyBy(a,u=>u.id),c={edges:x.uniqBy(r,u=>u.id),nodes:a,nodeMap:l};return Yk(c)}const gM="",wi={"builtin:op:open-link":s.jsx(o.ThemeIcon,{color:"blue",size:20,radius:"xl",children:s.jsx(k.IconCircleDashed,{size:14})}),"builtin:op:set_filter_values":s.jsx(o.ThemeIcon,{color:"orange",size:20,radius:"xl",children:s.jsx(k.IconCircleDot,{size:14})}),"builtin:op:clear_filter_values":s.jsx(o.ThemeIcon,{color:"orange",size:20,radius:"xl",children:s.jsx(k.IconCircleOff,{size:14})})};function Jk(t){const e=[];return t.forEach(n=>{switch(n.schemaRef){case"builtin:op:open-link":e.push({key:n.urlTemplate,icon:wi[n.schemaRef],text:s.jsxs(o.Group,{spacing:4,children:[s.jsx(o.Text,{children:"Open: "}),s.jsx(o.Text,{color:"dimmed",children:n.shortURLTemplate})]})});return;case"builtin:op:set_filter_values":n.filters.forEach(({key:r,label:i})=>{e.push({key:n.schemaRef+r,icon:wi[n.schemaRef],text:s.jsx(o.Group,{spacing:4,children:s.jsxs(o.Text,{children:["Set Filter: ",i]})})})});return;case"builtin:op:clear_filter_values":n.filters.forEach(({key:r,label:i})=>{e.push({key:n.schemaRef+r,icon:wi[n.schemaRef],text:s.jsx(o.Group,{spacing:4,children:s.jsxs(o.Text,{children:["Clear Filter: ",i]})})})});return}}),e}const Xk=m.memo(({data:t,isConnectable:e,sourcePosition:n=_e.Position.Right,targetPosition:r=_e.Position.Left,...i})=>{const a=m.useMemo(()=>Jk(t.interactions),[t.interactions]);return s.jsxs(s.Fragment,{children:[s.jsx(_e.Handle,{type:"target",position:r,isConnectable:e}),s.jsx(o.Box,{sx:{position:"absolute",top:0,right:0},children:s.jsx(B.ChevronsUpRight,{size:12})}),s.jsxs(o.HoverCard,{shadow:"xl",withinPortal:!0,children:[s.jsx(o.HoverCard.Target,{children:s.jsx(o.Text,{children:t.label})}),s.jsx(o.HoverCard.Dropdown,{children:s.jsx(o.List,{spacing:"xs",size:"sm",center:!0,children:a.map(l=>s.jsx(o.List.Item,{icon:l.icon,children:l.text},l.key))})})]}),s.jsx(_e.Handle,{type:"source",position:n,isConnectable:e})]})}),xM="",Zk={interaction:Xk},Hk=S.observer(()=>{const t=de(),{edges:e,nodes:n}=Kk(t);return s.jsxs(_e,{nodes:n,edges:e,onNodesChange:x.noop,onEdgesChange:x.noop,onConnect:x.noop,className:"interactions-viewer",fitView:!0,nodeTypes:Zk,children:[s.jsx(_e.MiniMap,{}),s.jsx(_e.Controls,{}),s.jsx(_e.Background,{})]})}),e1=S.observer(({opened:t,close:e})=>{const{t:n}=_.useTranslation();return s.jsx(o.Modal,{size:"96vw",opened:t,onClose:e,title:n("interactions.interactions_viewer"),trapFocus:!0,onDragStart:r=>{r.stopPropagation()},styles:{body:{height:"calc(90vh - 54px)"},content:{transform:"none !important"}},zIndex:300,children:s.jsx(Hk,{})})}),t1={"> button":{"&:first-of-type":{borderTopRightRadius:0,borderBottomRightRadius:0,borderRightWidth:.5},":not(:first-of-type):not(:last-of-type)":{borderTopRightRadius:0,borderBottomRightRadius:0,borderTopLeftRadius:0,borderBottomLeftRadius:0,borderLeftWidth:.5,borderRightWidth:.5},"&:last-of-type":{borderTopLeftRadius:0,borderBottomLeftRadius:0,borderLeftWidth:.5}}};function n1({onClick:t,name:e,active:n,openSettings:r}){return s.jsxs(o.Box,{sx:{position:"relative"},children:[s.jsx(o.UnstyledButton,{sx:i=>({display:"block",width:"100%",padding:i.spacing.xs,borderRadius:0,position:"relative",color:i.black,"&:hover":{backgroundColor:i.colors.gray[0]},backgroundColor:n?i.colors.gray[2]:"transparent"}),children:s.jsx(o.Group,{sx:{width:"calc(100% - 28px)"},onClick:t,children:s.jsx(o.Text,{size:"sm",children:e})})}),n&&s.jsx(o.Tooltip,{label:"Edit",position:"right",withinPortal:!0,children:s.jsx(o.ActionIcon,{onClick:r,variant:"light",color:"blue",sx:{position:"absolute",top:0,bottom:0,height:"100%",right:0,zIndex:0,borderRadius:0},children:s.jsx(k.IconAdjustments,{size:16})})})]})}const s1=S.observer(()=>{const{t}=_.useTranslation(),e=H(),n=U(),r=m.useCallback(a=>()=>n.views.setIDOfVIE(a),[n]),i=a=>{e.editor.open(["_VIEWS_",a])};return s.jsxs(o.Box,{sx:{position:"relative"},children:[n.views.options.map(a=>s.jsx(n1,{active:n.views.idOfVIE===a.value,name:a.label,onClick:r(a.value),openSettings:()=>i(a.value)},a.value)),s.jsx(o.Divider,{variant:"dashed"}),s.jsx(o.Button,{variant:"subtle",rightIcon:s.jsx(k.IconPlus,{size:14}),size:"sm",px:"xs",color:"blue",onClick:n.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"space-between"}},children:t("view.add")})]})}),r1=S.observer(()=>{const{t}=_.useTranslation(),e=H(),n=U(),r=()=>{if(!n.queries.firstID){e.editor.open(["_QUERIES_",""]);return}e.editor.open(["_QUERIES_",n.queries.firstID])},i=()=>{if(!n.filters.firstID){e.editor.open(["_FILTERS_",""]);return}e.editor.open(["_FILTERS_",n.filters.firstID])},[a,l]=m.useState(!1),c=()=>l(!0),u=()=>l(!1);return s.jsxs(o.Navbar,{p:0,width:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},zIndex:299,children:[s.jsxs(o.Navbar.Section,{children:[s.jsxs(o.Group,{grow:!0,spacing:0,sx:{...t1,button:{borderWidth:0,borderBottomWidth:1,borderColor:"#e9ecef"}},children:[s.jsx(o.Tooltip,{label:t("filter.labels"),withinPortal:!0,children:s.jsx(o.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:i,children:s.jsx(k.IconFilter,{size:18})})}),s.jsx(o.Tooltip,{label:t("query.labels"),withinPortal:!0,children:s.jsx(o.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:r,children:s.jsx(k.IconDatabase,{size:18})})}),s.jsx(o.Tooltip,{label:t("interactions.interactions_viewer"),withinPortal:!0,children:s.jsx(o.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:c,children:s.jsx(k.IconLink,{size:18})})})]}),s.jsx(e1,{opened:a,close:u})]}),s.jsx(o.Navbar.Section,{py:5,sx:{borderBottom:"1px solid #eee"},children:s.jsx(o.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:t("view.labels")})}),s.jsx(o.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:s.jsx(s1,{})}),s.jsx(o.Navbar.Section,{children:s.jsx(o.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:s.jsx(o.Button,{size:"xs",leftIcon:s.jsx(k.IconSettings,{size:20}),onClick:()=>e.editor.open([]),children:t("common.titles.settings")})})})]})}),i1=["function getDefaultValue(filter, utils, context) {",' return "";',"}"].join(`
449
+ `),Xt=S.observer(({filter:t})=>{const{t:e}=_.useTranslation();return s.jsx(zo,{label:"",title:e("filter.field.custom_default_value.title"),triggerLabel:e("filter.field.custom_default_value.trigger"),value:t.default_value_func,onChange:t.setDefaultValueFunc,defaultValue:i1,triggerButtonProps:{size:"xs",color:"grape",sx:{flexGrow:0,alignSelf:"flex-start"},leftIcon:s.jsx(k.IconMathFunction,{size:16})},description:s.jsx(o.Alert,{title:e("filter.field.custom_default_value.tips"),color:"gray",mb:16,children:s.jsxs(o.List,{size:13,type:"ordered",children:[s.jsx(o.List.Item,{children:e("filter.field.custom_default_value.tip_1")}),s.jsx(o.List.Item,{children:e("filter.field.custom_default_value.tip_2")})]})})})}),a1=S.observer(function({filter:e}){const{t:n}=_.useTranslation(),r=e.config;return s.jsxs(s.Fragment,{children:[s.jsxs(o.Group,{position:"apart",children:[s.jsx(o.Checkbox,{checked:r.default_value,onChange:i=>r.setDefaultValue(i.currentTarget.checked),label:n("filter.widget.checkbox.default_checked")}),s.jsx(Xt,{filter:e})]}),s.jsx(jr,{label:n("filter.widget.checkbox.description"),value:r.description,onChange:r.setDescription,styles:{root:{flexGrow:1,minHeight:"400px"}}})]})}),o1=[{label:"2022",value:"YYYY"},{label:"202201",value:"YYYYMM"},{label:"20220101",value:"YYYYMMDD"},{label:"2022-01",value:"YYYY-MM"},{label:"2022-01-01",value:"YYYY-MM-DD"}],l1=S.observer(function({filter:e}){const{t:n}=_.useTranslation(),r=e.config,i=m.useMemo(()=>Vr().map(({key:a,value:l,group:c})=>({label:n(`filter.widget.date_range.shortcut.${c}.full.${a}`),value:l,group:n(`filter.widget.date_range.shortcut.${c}.label`)})),[]);return s.jsxs(s.Fragment,{children:[s.jsxs(o.Group,{children:[s.jsx(o.Checkbox,{checked:r.required,onChange:a=>r.setRequired(a.currentTarget.checked),label:n("filter.widget.date_range.required")}),s.jsx(o.Checkbox,{checked:r.allowSingleDateInRange,onChange:a=>r.setAllowSingleDateInRange(a.currentTarget.checked),label:n("filter.widget.date_range.allow_single_date")})]}),s.jsxs(o.Group,{grow:!0,children:[s.jsx(o.Select,{data:o1,label:n("filter.widget.date_range.display_format"),value:r.inputFormat,onChange:r.setInputFormat}),s.jsx(o.NumberInput,{label:n("filter.widget.date_range.max_days"),min:0,value:r.max_days,onChange:r.setMaxDays,hideControls:!0})]}),s.jsxs(o.Group,{children:[s.jsx(xl,{label:n("filter.widget.date_range.default_value"),config:r,value:r.default_value,onChange:r.setDefaultValue,disabled:!!r.default_shortcut}),s.jsx(o.Select,{data:i,label:n("filter.widget.date_range.default_by_shortcut"),value:r.default_shortcut,onChange:r.setDefaultShortcut,placeholder:n("filter.widget.date_range.default_by_shortcut_placeholder"),clearable:!0,sx:{flexGrow:1},maxDropdownHeight:500})]}),s.jsx(Xt,{filter:e})]})}),Ci=S.observer(({value:t,onChange:e})=>{const{t:n}=_.useTranslation(),r=H(),i=U(),a=m.useMemo(()=>i.queries.options,[i.queries.current]),l=a.length===0,c=u=>{r.editor.setPath(["_QUERIES_",u])};return s.jsx(o.Select,{label:s.jsxs(o.Group,{position:"apart",children:[s.jsx(o.Text,{children:n("filter.widget.common.use_query_data_as_options")}),t&&s.jsx(o.Button,{size:"xs",leftIcon:s.jsx(k.IconArrowCurveRight,{size:16}),variant:"subtle",color:"blue",onClick:()=>c(t),children:n("query.open")})]}),data:a,value:t,onChange:e,allowDeselect:!1,clearable:!0,sx:{flexGrow:1},disabled:l,error:l?"You need to add a query in Data Settings":void 0,styles:{label:{display:"block"}}})}),c1=`
450
450
  // row
451
451
  {
452
452
  label: string;
453
453
  value: string;
454
454
  description?: string; // optional
455
455
  }
456
- `,qc=()=>{const{t}=_.useTranslation(),[e,n]=m.useState(!1);return s.jsxs(s.Fragment,{children:[s.jsx(o.Button,{variant:"subtle",compact:!0,onClick:()=>n(r=>!r),children:t(e?"common.actions.close":"filter.widget.common.see_data_structure")}),s.jsx(o.Collapse,{in:e,children:s.jsx(vt.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:cT})})]})},uT=S.observer(function({filter:e}){const{t:n}=_.useTranslation(),r=e.config,i=()=>{r.addStaticOption({label:"",value:""})},a=r.static_options,l=[...a];return s.jsxs(s.Fragment,{children:[s.jsxs(o.Group,{position:"apart",children:[s.jsx(o.Checkbox,{checked:r.required,onChange:c=>r.setRequired(c.currentTarget.checked),label:n("filter.widget.select.required")}),s.jsx(Xt,{filter:e})]}),s.jsx(o.TextInput,{label:n("filter.widget.select.width"),description:n("filter.widget.multi_select.width_description"),value:r.min_width,onChange:c=>r.setMinWidth(c.currentTarget.value),placeholder:"200px"}),s.jsx(o.Divider,{label:n("filter.widget.select.configure_options"),labelPosition:"center"}),s.jsxs(o.Stack,{spacing:10,sx:{position:"relative",minHeight:"50px"},children:[r.usingQuery&&s.jsxs(s.Fragment,{children:[s.jsx(o.Overlay,{opacity:.8,color:"#000",sx:{left:"-5px",right:"-5px",top:"-5px",bottom:"-5px"}}),s.jsx(o.Center,{sx:{position:"absolute",top:0,left:0,zIndex:200,height:"100%",width:"100%"},children:s.jsx(o.Text,{color:"white",size:16,children:n("filter.widget.common.using_query")})})]}),a.length>0&&s.jsx(o.MultiSelect,{label:n("filter.widget.select.default_selection"),data:l,value:[...r.default_value],onChange:r.setDefaultValue}),a.map((c,u)=>s.jsxs(o.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[s.jsx(o.TextInput,{label:n("common.label"),required:!0,value:r.static_options[u].label,onChange:d=>{r.static_options[u].setLabel(d.currentTarget.value)},sx:{flexGrow:1}}),s.jsx(o.TextInput,{label:n("common.value"),required:!0,value:r.static_options[u].value,onChange:d=>{r.static_options[u].setValue(d.currentTarget.value)},sx:{flexGrow:1}}),s.jsx(o.ActionIcon,{color:"red",variant:"subtle",onClick:()=>r.removeStaticOption(u),sx:{position:"absolute",top:28,right:5},children:s.jsx(B.Trash,{size:16})})]},u)),s.jsx(o.Button,{mt:10,size:"xs",color:"blue",leftIcon:s.jsx(B.PlaylistAdd,{size:20}),onClick:i,sx:{width:"50%"},mx:"auto",children:n("common.actions.add_an_option")})]}),s.jsx(o.Divider,{label:n("filter.widget.common.or_fetch_options_from_datasource"),labelPosition:"center"}),s.jsx(o.NumberInput,{value:r.default_selection_count,onChange:r.setDefaultSelectionCount,label:n("filter.widget.common.default_selection_count")}),s.jsx(Ci,{value:r.options_query_id,onChange:r.setOptionsQueryID}),s.jsx(qc,{})]})}),dT=S.observer(function({filter:e}){const{t:n,i18n:r}=_.useTranslation(),i=e.config,a=()=>{i.addStaticOption({label:"",value:""})},l=i.static_options,c=m.useMemo(()=>[{label:n("filter.widget.select.no_default_selection"),value:""},...l],[r.language,l]);return s.jsxs(s.Fragment,{children:[s.jsxs(o.Group,{position:"apart",children:[s.jsx(o.Checkbox,{checked:i.required,onChange:u=>i.setRequired(u.currentTarget.checked),label:n("filter.widget.select.required")}),s.jsx(o.Checkbox,{checked:i.clearable,onChange:u=>i.setClearable(u.currentTarget.checked),label:n("filter.widget.select.clearable")}),s.jsx(Xt,{filter:e})]}),s.jsx(o.TextInput,{label:n("filter.widget.select.width"),value:i.width,onChange:u=>i.setWidth(u.currentTarget.value),placeholder:"200px"}),s.jsx(o.Divider,{label:n("filter.widget.select.configure_options"),labelPosition:"center"}),s.jsxs(o.Stack,{spacing:10,sx:{position:"relative",minHeight:"50px"},children:[i.usingQuery&&s.jsxs(s.Fragment,{children:[s.jsx(o.Overlay,{opacity:.8,color:"#000",sx:{left:"-5px",right:"-5px",top:"-5px",bottom:"-5px"}}),s.jsx(o.Center,{sx:{position:"absolute",top:0,left:0,zIndex:200,height:"100%",width:"100%"},children:s.jsx(o.Text,{color:"white",size:16,children:n("filter.widget.common.using_query")})})]}),l.length>0&&s.jsx(o.Select,{label:n("filter.widget.select.default_selection"),data:c,value:i.default_value,onChange:i.setDefaultValue}),l.map((u,d)=>s.jsxs(o.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[s.jsx(o.TextInput,{label:n("common.label"),required:!0,value:i.static_options[d].label,onChange:p=>{i.static_options[d].setLabel(p.currentTarget.value)},sx:{flexGrow:1}}),s.jsx(o.TextInput,{label:n("common.value"),required:!0,value:i.static_options[d].value,onChange:p=>{i.static_options[d].setValue(p.currentTarget.value)},sx:{flexGrow:1}}),s.jsx(o.ActionIcon,{color:"red",variant:"subtle",onClick:()=>i.removeStaticOption(d),sx:{position:"absolute",top:28,right:5},children:s.jsx(B.Trash,{size:16})})]},d)),s.jsx(o.Button,{size:"xs",color:"blue",leftIcon:s.jsx(B.PlaylistAdd,{size:20}),onClick:a,sx:{width:"50%"},mx:"auto",children:n("common.actions.add_an_option")})]}),s.jsx(o.Divider,{label:n("filter.widget.common.or_fetch_options_from_datasource"),labelPosition:"center"}),s.jsx(o.Checkbox,{checked:i.default_selection_count===1,onChange:u=>i.setDefaultSelectionCount(u.currentTarget.checked?1:0),label:n("filter.widget.select.select_first_option_by_default")}),s.jsx(Ci,{value:i.options_query_id,onChange:i.setOptionsQueryID}),s.jsx(qc,{})]})}),pT=S.observer(function({filter:e}){const{t:n}=_.useTranslation(),r=e.config;return s.jsxs(s.Fragment,{children:[s.jsxs(o.Group,{children:[s.jsx(o.TextInput,{label:n("filter.widget.text_input.default_value"),value:r.default_value,onChange:i=>{r.setDefaultValue(i.currentTarget.value)},sx:{flexGrow:1}}),s.jsx(o.Box,{mt:22,children:s.jsx(Xt,{filter:e})})]}),s.jsx(o.Checkbox,{checked:r.required,onChange:i=>r.setRequired(i.currentTarget.checked),label:n("filter.widget.text_input.required")})]})}),hT=`
456
+ `,qc=()=>{const{t}=_.useTranslation(),[e,n]=m.useState(!1);return s.jsxs(s.Fragment,{children:[s.jsx(o.Button,{variant:"subtle",compact:!0,onClick:()=>n(r=>!r),children:t(e?"common.actions.close":"filter.widget.common.see_data_structure")}),s.jsx(o.Collapse,{in:e,children:s.jsx(vt.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:c1})})]})},u1=S.observer(function({filter:e}){const{t:n}=_.useTranslation(),r=e.config,i=()=>{r.addStaticOption({label:"",value:""})},a=r.static_options,l=[...a];return s.jsxs(s.Fragment,{children:[s.jsxs(o.Group,{position:"apart",children:[s.jsx(o.Checkbox,{checked:r.required,onChange:c=>r.setRequired(c.currentTarget.checked),label:n("filter.widget.select.required")}),s.jsx(Xt,{filter:e})]}),s.jsx(o.TextInput,{label:n("filter.widget.select.width"),description:n("filter.widget.multi_select.width_description"),value:r.min_width,onChange:c=>r.setMinWidth(c.currentTarget.value),placeholder:"200px"}),s.jsx(o.Divider,{label:n("filter.widget.select.configure_options"),labelPosition:"center"}),s.jsxs(o.Stack,{spacing:10,sx:{position:"relative",minHeight:"50px"},children:[r.usingQuery&&s.jsxs(s.Fragment,{children:[s.jsx(o.Overlay,{opacity:.8,color:"#000",sx:{left:"-5px",right:"-5px",top:"-5px",bottom:"-5px"}}),s.jsx(o.Center,{sx:{position:"absolute",top:0,left:0,zIndex:200,height:"100%",width:"100%"},children:s.jsx(o.Text,{color:"white",size:16,children:n("filter.widget.common.using_query")})})]}),a.length>0&&s.jsx(o.MultiSelect,{label:n("filter.widget.select.default_selection"),data:l,value:[...r.default_value],onChange:r.setDefaultValue}),a.map((c,u)=>s.jsxs(o.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[s.jsx(o.TextInput,{label:n("common.label"),required:!0,value:r.static_options[u].label,onChange:d=>{r.static_options[u].setLabel(d.currentTarget.value)},sx:{flexGrow:1}}),s.jsx(o.TextInput,{label:n("common.value"),required:!0,value:r.static_options[u].value,onChange:d=>{r.static_options[u].setValue(d.currentTarget.value)},sx:{flexGrow:1}}),s.jsx(o.ActionIcon,{color:"red",variant:"subtle",onClick:()=>r.removeStaticOption(u),sx:{position:"absolute",top:28,right:5},children:s.jsx(B.Trash,{size:16})})]},u)),s.jsx(o.Button,{mt:10,size:"xs",color:"blue",leftIcon:s.jsx(B.PlaylistAdd,{size:20}),onClick:i,sx:{width:"50%"},mx:"auto",children:n("common.actions.add_an_option")})]}),s.jsx(o.Divider,{label:n("filter.widget.common.or_fetch_options_from_datasource"),labelPosition:"center"}),s.jsx(o.NumberInput,{value:r.default_selection_count,onChange:r.setDefaultSelectionCount,label:n("filter.widget.common.default_selection_count")}),s.jsx(Ci,{value:r.options_query_id,onChange:r.setOptionsQueryID}),s.jsx(qc,{})]})}),d1=S.observer(function({filter:e}){const{t:n,i18n:r}=_.useTranslation(),i=e.config,a=()=>{i.addStaticOption({label:"",value:""})},l=i.static_options,c=m.useMemo(()=>[{label:n("filter.widget.select.no_default_selection"),value:""},...l],[r.language,l]);return s.jsxs(s.Fragment,{children:[s.jsxs(o.Group,{position:"apart",children:[s.jsx(o.Checkbox,{checked:i.required,onChange:u=>i.setRequired(u.currentTarget.checked),label:n("filter.widget.select.required")}),s.jsx(o.Checkbox,{checked:i.clearable,onChange:u=>i.setClearable(u.currentTarget.checked),label:n("filter.widget.select.clearable")}),s.jsx(Xt,{filter:e})]}),s.jsx(o.TextInput,{label:n("filter.widget.select.width"),value:i.width,onChange:u=>i.setWidth(u.currentTarget.value),placeholder:"200px"}),s.jsx(o.Divider,{label:n("filter.widget.select.configure_options"),labelPosition:"center"}),s.jsxs(o.Stack,{spacing:10,sx:{position:"relative",minHeight:"50px"},children:[i.usingQuery&&s.jsxs(s.Fragment,{children:[s.jsx(o.Overlay,{opacity:.8,color:"#000",sx:{left:"-5px",right:"-5px",top:"-5px",bottom:"-5px"}}),s.jsx(o.Center,{sx:{position:"absolute",top:0,left:0,zIndex:200,height:"100%",width:"100%"},children:s.jsx(o.Text,{color:"white",size:16,children:n("filter.widget.common.using_query")})})]}),l.length>0&&s.jsx(o.Select,{label:n("filter.widget.select.default_selection"),data:c,value:i.default_value,onChange:i.setDefaultValue}),l.map((u,d)=>s.jsxs(o.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[s.jsx(o.TextInput,{label:n("common.label"),required:!0,value:i.static_options[d].label,onChange:p=>{i.static_options[d].setLabel(p.currentTarget.value)},sx:{flexGrow:1}}),s.jsx(o.TextInput,{label:n("common.value"),required:!0,value:i.static_options[d].value,onChange:p=>{i.static_options[d].setValue(p.currentTarget.value)},sx:{flexGrow:1}}),s.jsx(o.ActionIcon,{color:"red",variant:"subtle",onClick:()=>i.removeStaticOption(d),sx:{position:"absolute",top:28,right:5},children:s.jsx(B.Trash,{size:16})})]},d)),s.jsx(o.Button,{size:"xs",color:"blue",leftIcon:s.jsx(B.PlaylistAdd,{size:20}),onClick:a,sx:{width:"50%"},mx:"auto",children:n("common.actions.add_an_option")})]}),s.jsx(o.Divider,{label:n("filter.widget.common.or_fetch_options_from_datasource"),labelPosition:"center"}),s.jsx(o.Checkbox,{checked:i.default_selection_count===1,onChange:u=>i.setDefaultSelectionCount(u.currentTarget.checked?1:0),label:n("filter.widget.select.select_first_option_by_default")}),s.jsx(Ci,{value:i.options_query_id,onChange:i.setOptionsQueryID}),s.jsx(qc,{})]})}),p1=S.observer(function({filter:e}){const{t:n}=_.useTranslation(),r=e.config;return s.jsxs(s.Fragment,{children:[s.jsxs(o.Group,{children:[s.jsx(o.TextInput,{label:n("filter.widget.text_input.default_value"),value:r.default_value,onChange:i=>{r.setDefaultValue(i.currentTarget.value)},sx:{flexGrow:1}}),s.jsx(o.Box,{mt:22,children:s.jsx(Xt,{filter:e})})]}),s.jsx(o.Checkbox,{checked:r.required,onChange:i=>r.setRequired(i.currentTarget.checked),label:n("filter.widget.text_input.required")})]})}),h1=`
457
457
  // row
458
458
  {
459
459
  label: string;
@@ -461,7 +461,7 @@ Check the top-level render call using <`+A+">.")}return z}}function mu(w,z){{if(
461
461
  parent_value: string;
462
462
  description?: string;
463
463
  }
464
- `,mT=()=>{const{t}=_.useTranslation(),[e,n]=m.useState(!1);return s.jsxs(s.Fragment,{children:[s.jsx(o.Button,{variant:"subtle",compact:!0,onClick:()=>n(r=>!r),children:t(e?"common.actions.close":"filter.widget.common.see_data_structure")}),s.jsx(o.Collapse,{in:e,children:s.jsx(vt.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:hT})})]})},fT=S.observer(function({filter:e}){const{t:n}=_.useTranslation(),r=e.config;return s.jsxs(s.Fragment,{children:[s.jsxs(o.Group,{position:"apart",children:[s.jsx(o.Checkbox,{checked:r.required,onChange:i=>r.setRequired(i.currentTarget.checked),label:n("filter.widget.select.required")}),s.jsx(Xt,{filter:e})]}),s.jsx(o.TextInput,{label:n("filter.widget.common.min_width"),value:r.min_width,onChange:i=>r.setMinWidth(i.currentTarget.value),placeholder:"200px"}),s.jsx(o.Divider,{label:n("filter.widget.common.fetch_options_from_datasource"),labelPosition:"center"}),s.jsx(o.Checkbox,{checked:r.treeCheckStrictly,onChange:i=>r.setTreeCheckStrictly(i.currentTarget.checked),label:n("filter.widget.tree_select.strictly")}),s.jsx(o.NumberInput,{value:r.default_selection_count,onChange:r.setDefaultSelectionCount,label:n("filter.widget.common.default_selection_count")}),s.jsx(Ci,{value:r.options_query_id,onChange:r.setOptionsQueryID}),s.jsx(mT,{})]})}),gT=S.observer(function({filter:e}){const{t:n}=_.useTranslation();return s.jsxs(o.Box,{sx:{maxWidth:"480px"},children:[s.jsx(o.Text,{pt:"0",pb:"md",color:"gray",children:n("common.titles.config")}),s.jsx(vt.Prism,{mt:22,language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(e,null,4)})]})}),xT={select:dT,"multi-select":uT,"tree-select":fT,"text-input":pT,checkbox:aT,"date-range":lT},$t={select:"filter.widget.names.select","multi-select":"filter.widget.names.multi_select","tree-select":"filter.widget.names.tree_select","text-input":"filter.widget.names.text_input",checkbox:"filter.widget.names.checkbox","date-range":"filter.widget.names.date_range"},yT=S.observer(function({filter:e}){const{t:n,i18n:r}=_.useTranslation(),i=U(),a=m.useMemo(()=>xT[e.type],[e.type]),l=m.useMemo(()=>[{label:n($t.select),value:"select"},{label:n($t["multi-select"]),value:"multi-select"},{label:n($t["tree-select"]),value:"tree-select"},{label:n($t["text-input"]),value:"text-input"},{label:n($t.checkbox),value:"checkbox"},{label:n($t["date-range"]),value:"date-range"}],[r.language]);return s.jsxs(o.Group,{grow:!0,spacing:20,align:"top",children:[s.jsxs(o.Box,{sx:{maxWidth:"600px"},children:[s.jsx(o.Text,{pb:"md",color:"gray",children:n("common.titles.edit")}),s.jsxs(o.Stack,{children:[s.jsxs(o.Group,{noWrap:!0,children:[s.jsx(o.NumberInput,{label:n("filter.field.order"),required:!0,value:e.order,onChange:e.setOrder,hideControls:!0,sx:{flexGrow:"1 !important"}}),e.auto_submit_supported&&s.jsx(o.Checkbox,{label:n("filter.field.auto_submit"),checked:e.auto_submit,onChange:c=>e.setAutoSubmit(c.currentTarget.checked),mt:22})]}),s.jsx(o.MultiSelect,{label:n("filter.field.visible_in"),data:i.views.options,value:[...e.visibleInViewsIDs],onChange:e.setVisibleInViewsIDs}),s.jsx(o.TextInput,{label:n("common.key"),placeholder:n("filter.field.key_placeholder"),required:!0,value:e.key,onChange:c=>{e.setKey(c.currentTarget.value)}}),s.jsx(o.TextInput,{label:n("common.label"),placeholder:n("filter.field.label_placeholder"),required:!0,value:e.label,onChange:c=>{e.setLabel(c.currentTarget.value)}}),s.jsx(o.Select,{label:n("filter.field.widget"),data:l,required:!0,value:e.type,onChange:e.setType,maxDropdownHeight:500}),s.jsx(o.Divider,{mb:0,mt:10,variant:"dashed",labelPosition:"center"}),s.jsx(a,{filter:e})]})]}),s.jsx(gT,{filter:e})]})}),bT=S.observer(({id:t})=>{const{t:e}=_.useTranslation(),n=Le.useModals(),r=H(),i=U();if(t==="")return null;const a=i.filters.findByID(t);if(!a)return s.jsxs(o.Text,{size:14,children:["Filter by ID[",t,"] is not found"]});const l=()=>{r.editor.setPath(["_FILTERS_",""])},c=()=>{n.openConfirmModal({title:`${e("filter.delete")}?`,labels:{confirm:e("common.actions.confirm"),cancel:e("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.filters.removeByID(t),l()},confirmProps:{color:"red"},zIndex:320})};return s.jsxs(o.Stack,{sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",pb:30,children:[s.jsx(o.Group,{position:"right",pt:10,children:s.jsx(o.Button,{size:"xs",color:"red",leftIcon:s.jsx(B.Trash,{size:16}),onClick:c,children:e("filter.delete")})}),s.jsx(o.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:s.jsx(yT,{filter:a})})]})}),vT=S.observer(()=>{const{t}=_.useTranslation(),[e,n]=m.useState([]),r=H(),i=d=>{r.editor.setPath(["_FILTERS_",d])},a=()=>{r.content.filters.downloadSchema(e)},l=m.useMemo(()=>r.content.filters.sortedList.map(d=>d.id),[r.content.filters.sortedList]),c=()=>{n(l)},u=()=>{n([])};return s.jsxs(o.Stack,{sx:{height:"100%"},spacing:"sm",pb:"59px",children:[s.jsx(o.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:s.jsx(o.Text,{px:"md",align:"left",sx:{userSelect:"none",cursor:"default"},children:t("filter.manage")})}),s.jsx(o.Flex,{justify:"space-between",align:"center",px:12,children:s.jsxs(o.Group,{position:"left",children:[s.jsxs(o.Button.Group,{children:[s.jsx(o.Button,{variant:"default",size:"xs",onClick:c,children:t("common.actions.select_all")}),s.jsx(o.Button,{variant:"default",size:"xs",onClick:u,children:t("common.actions.clear_selection")})]}),s.jsx(o.Button,{size:"xs",color:"blue",leftIcon:s.jsx(k.IconCode,{size:14}),disabled:e.length===0,onClick:a,children:t("common.actions.download_schema")})]})}),s.jsx(o.Box,{sx:{flexGrow:1,overflow:"auto"},children:s.jsx(o.Checkbox.Group,{size:"xs",value:e,onChange:n,children:s.jsxs(o.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:t("common.label")}),s.jsx("th",{children:t("common.key")}),s.jsx("th",{style:{width:"100px"},children:t("filter.field.widget")}),s.jsx("th",{style:{width:"300px",paddingLeft:"24px"},children:t("common.action")})]})}),s.jsx("tbody",{children:r.content.filters.sortedList.map(d=>s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx(o.Checkbox,{value:d.id,styles:{input:{cursor:"pointer"}}})}),s.jsx("td",{children:d.label}),s.jsx("td",{children:d.key}),s.jsx("td",{children:t($t[d.type])}),s.jsx("td",{children:s.jsx(o.Button,{variant:"subtle",size:"xs",onClick:()=>i(d.id),children:t("common.actions.open")})})]},d.id))})]})})})]})}),_T=S.observer(()=>{const{t}=_.useTranslation(),e=U(),[n,r]=m.useState(()=>JSON.stringify(e.mock_context.current,null,4)),i=()=>{try{e.mock_context.replace(JSON.parse(n))}catch(l){bt.showNotification({title:"Failed",message:l.message,color:"red"})}},a=m.useMemo(()=>{try{return JSON.stringify(JSON.parse(n))!==JSON.stringify(e.mock_context.current)}catch{return!1}},[n,e.mock_context.current]);return s.jsxs(o.Stack,{sx:{border:"1px solid #eee",borderLeft:"none",borderRight:"none",flexGrow:1,maxWidth:"unset"},children:[s.jsx(o.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:s.jsx(o.Text,{weight:500,children:t("mock_context.label")})}),s.jsxs(o.Group,{grow:!0,px:"md",pb:"md",pt:0,sx:{flexGrow:1,position:"relative",alignItems:"flex-start"},children:[s.jsxs(o.Stack,{spacing:10,sx:{maxWidth:"unset !important"},children:[s.jsx(o.Text,{children:t("mock_context.hint")}),s.jsx(o.JsonInput,{validationError:"Invalid json",formatOnBlur:!0,autosize:!0,minRows:30,value:n,onChange:r,sx:{flexGrow:1}})]}),s.jsx(o.ActionIcon,{mr:5,variant:"filled",color:"blue",sx:{position:"absolute",right:12,top:0},disabled:!a,onClick:i,children:s.jsx(B.DeviceFloppy,{size:20})})]})]})}),jT=S.observer(()=>{const{t}=_.useTranslation(),{panel:e}=$e();return s.jsx(jr,{label:t("panel.panel_description"),value:e.description,onChange:e.setDescription,styles:{root:{flexGrow:1}}})}),wT=S.observer(()=>{const{t}=_.useTranslation(),{panel:e}=$e(),n=de().layouts.findItemByPanelID(e.id),{style:r}=e;return s.jsxs(s.Fragment,{children:[s.jsx(o.Divider,{mb:-10,label:t("panel.style.label"),labelPosition:"center",variant:"dashed"}),s.jsxs(o.Stack,{spacing:20,children:[s.jsxs(o.Group,{grow:!0,align:"top",children:[s.jsx(o.NumberInput,{label:t("panel.style.width"),min:1,max:36,step:1,precision:0,rightSection:s.jsx(o.Text,{size:12,children:t("panel.style.width_postfix")}),styles:{rightSection:{width:"auto",maxWidth:"100px",paddingRight:"14px",justifyContent:"flex-end"}},value:n.w,onChange:i=>{i&&n.setWidth(i)}}),s.jsx(o.NumberInput,{label:t("panel.style.height"),rightSection:s.jsx(o.Text,{size:12,children:t("panel.style.height_postfix")}),styles:{rightSection:{width:"40px"}},value:n.h,onChange:i=>{i&&n.setHeight(i)}})]}),s.jsx(o.Checkbox,{ml:6,label:t("panel.style.border"),checked:r.border.enabled,onChange:i=>r.border.setEnabled(i.currentTarget.checked)})]})]})}),CT=()=>s.jsxs("span",{className:"mantine-103svbs mantine-InputWrapper-required mantine-Select-required","aria-hidden":"true",children:[" ","*"]}),ST=S.observer(()=>{const{t}=_.useTranslation(),{panel:e}=$e(),{name:n}=e,[r,i]=ie.useInputState(n),a=n!==r,l=m.useCallback(()=>{a&&e.setName(r)},[a,r]);m.useEffect(()=>{i(n)},[n]);const c=!r.trim();return s.jsxs(o.Stack,{spacing:4,children:[s.jsxs(o.Group,{align:"center",children:[s.jsxs(o.Text,{size:14,fw:500,children:[t("panel.panel_name"),s.jsx(CT,{})]}),s.jsx(o.ActionIcon,{variant:"subtle",color:"blue",disabled:!a||c,onClick:l,children:s.jsx(k.IconDeviceFloppy,{size:18})})]}),s.jsx(o.TextInput,{value:r,onChange:i,required:!0})]})}),kT=S.observer(()=>{const{t}=_.useTranslation(),{panel:e}=$e();return s.jsx(o.Stack,{spacing:6,mb:10,children:s.jsxs(o.Group,{pl:6,position:"left",spacing:20,children:[s.jsx(o.Checkbox,{size:"sm",checked:e.title.show,onChange:n=>e.title.setShow(n.currentTarget.checked),label:t("panel.show_title"),sx:{userSelect:"none"}}),s.jsx(o.Checkbox,{size:"sm",checked:!0,disabled:!0,label:t("panel.use_name_as_title")})]})})});function TT(){const{t}=_.useTranslation();return s.jsxs(o.Stack,{sx:{height:"100%"},children:[s.jsx(wT,{}),s.jsx(o.Divider,{label:t("common.info"),labelPosition:"center",variant:"dashed"}),s.jsx(ST,{}),s.jsx(kT,{}),s.jsx(jT,{})]})}const DT={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 Lc({data:t}){const e=m.useMemo(()=>{if(!Array.isArray(t)||t.length===0)return[];const r=Ue.createColumnHelper();return Object.keys(t[0]).map(i=>r.accessor(i,{cell:a=>a.getValue()}))},[t]),n=Ue.useReactTable({data:t,columns:e,columnResizeMode:"onChange",getCoreRowModel:Ue.getCoreRowModel()});return t.length===0?s.jsx(o.Box,{sx:{height:"5em"}}):s.jsx(we,{children:s.jsxs(o.Table,{sx:DT,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:Ue.flexRender(i.column.columnDef.header,i.getContext()),s.jsx(o.ActionIcon,{onMouseDown:i.getResizeHandler(),onTouchStart:i.getResizeHandler(),className:`resizer ${i.column.getIsResizing()?"isResizing":""}`,children:s.jsx(B.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:typeof i.getValue()=="object"?s.jsx("pre",{children:JSON.stringify(i.getValue(),null,2)}):Ue.flexRender(i.column.columnDef.cell,i.getContext())})},i.id))},r.id))})]})})}const zT=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],MT={icon:{width:"80px",textAlign:"center"},input:{"&[data-with-icon]":{paddingLeft:"80px"}}},IT=({data:t,page:e,setPage:n,limit:r,setLimit:i})=>{const{t:a}=_.useTranslation(),l=t.length,c=Math.ceil(l/r),u=p=>{n(1),i(Number(p))};if(l===0)return null;const d=c===1&&l<=10;return s.jsxs(o.Group,{pt:10,px:10,position:"apart",children:[s.jsxs(o.Group,{position:"left",children:[c>1&&s.jsx(o.Pagination,{size:"sm",value:e,onChange:n,total:c,withEdges:c>7,styles:{control:{height:"30px"}}}),!d&&s.jsx(o.Select,{icon:s.jsx(o.Text,{ta:"center",color:"dimmed",size:14,children:a("common.pagination.page_size")}),size:"xs",styles:MT,data:zT,value:String(r),onChange:u})]}),s.jsx(o.Group,{position:"right",children:s.jsx(o.Text,{color:"dimmed",my:0,size:14,children:a("common.pagination.total_rows",{total:l})})})]})},ET=Ad(({data:t,loading:e})=>{const[n,r]=m.useState(1),[i,a]=m.useState(20),l=m.useMemo(()=>{const c=(n-1)*i,u=c+i;return t.slice(c,u)},[t,n,i]);return s.jsxs(we,{children:[s.jsx(IT,{data:t,page:n,setPage:r,limit:i,setLimit:a}),s.jsxs(o.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[s.jsx(o.LoadingOverlay,{visible:e,overlayBlur:2}),s.jsx(Lc,{data:l})]})]})}),AT=({queryID:t})=>{const e=de(),{state:n,error:r}=e.getDataStuffByID(t),i=m.useMemo(()=>e.queries.findByID(t),[e,t]);return n==="loading"?null:r?s.jsx(o.Text,{mt:10,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:r}):i!=null&&i.stateMessage?s.jsx(o.Text,{mt:10,color:"gray",align:"center",children:i.stateMessage}):null},Si=S.observer(({id:t,moreActions:e,refreshOnMount:n})=>{const{t:r}=_.useTranslation(),i=de(),{data:a,state:l}=i.getDataStuffByID(t),c=l==="loading",u=m.useCallback(()=>{i.queries.refetchDataByQueryID(t)},[t,i]),d=()=>{i.queries.downloadDataByQueryID(t)};m.useEffect(()=>{n&&u()},[u,n]);const p=!Array.isArray(a)||a.length===0;return s.jsxs(o.Stack,{spacing:0,sx:{height:"100%",border:"1px solid #eee"},children:[s.jsxs(o.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(o.Group,{position:"left",children:s.jsx(o.Text,{weight:500,children:r("data.preview_data")})}),s.jsxs(o.Group,{pr:15,children:[e,s.jsx(o.ActionIcon,{variant:"subtle",color:"blue",disabled:c,onClick:u,children:s.jsx(B.Refresh,{size:16})}),s.jsx(o.ActionIcon,{variant:"subtle",color:"blue",disabled:c||p,onClick:d,children:s.jsx(B.Download,{size:16})})]})]}),s.jsxs(o.Box,{pb:20,sx:{position:"relative",flexGrow:1,overflow:"auto"},children:[s.jsx(AT,{queryID:t}),s.jsx(ET,{data:a,loading:c})]})]})}),PT=S.observer(function(){const{t:e}=_.useTranslation(),n=H(),r=U(),{panel:i}=$e(),[a,l]=m.useState(!1),c=d=>{n.editor.setPath(["_QUERIES_",d])},u=i.queryIDs.length;return s.jsxs(s.Fragment,{children:[s.jsx(o.Drawer,{opened:a,onClose:()=>l(!1),title:e("panel.settings.choose_queries"),padding:"xl",size:500,zIndex:320,children:s.jsx(o.Checkbox.Group,{value:[...i.queryIDs],onChange:i.setQueryIDs,children:s.jsx(o.Stack,{spacing:"lg",children:r.queries.options.map(d=>s.jsx(o.Checkbox,{label:d.label,value:d.value},d.value))})})}),s.jsxs(o.Stack,{spacing:6,children:[s.jsx(o.Group,{position:"left",children:s.jsx(o.Button,{variant:"light",size:"sm",leftIcon:s.jsx(k.IconLine,{size:16}),onClick:()=>l(!0),children:e(u===0?"panel.settings.need_to_choose_queries":"panel.settings.choose_queries")})}),u===1&&s.jsx(Si,{id:i.queryIDs[0],moreActions:s.jsx(o.Tooltip,{label:e("query.open"),children:s.jsx(o.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>c(i.queryIDs[0]),children:s.jsx(k.IconArrowCurveRight,{size:16})})})}),u>1&&s.jsxs(o.Tabs,{defaultValue:i.queryIDs[0],children:[s.jsx(o.Tabs.List,{children:i.queries.map(d=>s.jsx(o.Tabs.Tab,{value:d.id,children:d.name},d.id))}),i.queries.map(d=>s.jsx(o.Tabs.Panel,{value:d.id,children:s.jsx(Si,{id:d.id,moreActions:s.jsx(o.Tooltip,{label:e("query.open"),children:s.jsx(o.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>c(d.id),children:s.jsx(k.IconArrowCurveRight,{size:16})})})})},d.id))]})]})]})}),$T=S.observer(()=>{const{panel:t}=pt();return s.jsx(we,{children:s.jsx(o.Box,{sx:{height:"100%",flexGrow:0,flexShrink:0,width:"600px"},children:s.jsxs(o.Stack,{mt:24,spacing:5,sx:{width:"600px",height:"450px",background:"transparent",borderRadius:"5px",border:"1px solid #e9ecef",borderWidth:t.style.border.enabled?"1px":"0px"},children:[s.jsxs(o.Group,{position:"apart",noWrap:!0,sx:{flexGrow:0,flexShrink:0},children:[s.jsx(o.Group,{children:s.jsx(fi,{})}),s.jsx(o.Group,{grow:!0,position:"center",children:s.jsx(o.Text,{lineClamp:1,weight:"bold",children:t.title.show?t.name:""})}),s.jsx(o.Group,{position:"right",spacing:0,sx:{height:"28px"}})]}),s.jsx(o.Group,{px:5,pb:5,sx:{flexGrow:1,".panel-viz-section":{height:"calc(100% - 28px)"}},children:s.jsx(gi,{panel:t})})]})})})}),ki={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 BT{constructor(e){$(this,"panel");$(this,"selected");this.panel=e,e.variables.length>0&&(this.selected=e.variables[0]),K.makeAutoObservable(this,{},{deep:!1,autoBind:!0})}get variables(){return this.panel.variables}get variableOptions(){return this.panel.variables.map(e=>({label:e.name,value:e.name,description:e.aggregation.type}))}addNew(){const e=this.panel.variables.filter(n=>n.name.startsWith(ki.name)).length;this.panel.addVariable(x.cloneDeep({...ki,name:`${ki.name}${e||""}`})),this.selected=x.last(this.panel.variables)}select(e){this.selected=e}selectByName(e){if(!e){console.warn("Unexpected null name when calling selectByName");return}const n=this.variables.find(r=>r.name===e);if(!n){console.error(`Variable by name[${e}] not found`);return}this.selected=n}remove(e){this.selected===e&&(this.selected=void 0);const n=this.panel.variables.indexOf(e);if(this.panel.removeVariable(e),!this.selected&&!x.isEmpty(this.panel.variables)){const r=Math.min(this.panel.variables.length-1,n);this.selected=this.panel.variables[r]}}}function qT(){const{panel:t}=$e();return N.useCreation(()=>new BT(t),[t])}function LT({label:t,value:e,onChange:n},r){const[i,a]=m.useState(Array.isArray(e)?[...e]:[]),l=m.useCallback(()=>{a(g=>[...g,""])},[a]),c=m.useCallback(g=>{a(y=>(y.splice(g,1),[...y]))},[a]),u=m.useMemo(()=>!x.isEqual(i,e),[i,e]),d=()=>{n(i.map(g=>g.toString()))},p=o.useMantineTheme(),h=m.useMemo(()=>Object.entries(p.colors).map(([g,y])=>y[6]),[p]);return s.jsxs(s.Fragment,{children:[s.jsxs(o.Group,{position:"left",ref:r,children:[s.jsx(o.Text,{children:t}),s.jsx(o.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!u,onClick:d,children:s.jsx(B.DeviceFloppy,{size:20})})]}),s.jsxs(o.Group,{children:[i.map((g,y)=>s.jsx(o.ColorInput,{value:g,onChange:v=>{a(C=>(C.splice(y,1,v),[...C]))},swatches:h,rightSection:s.jsx(o.ActionIcon,{onClick:()=>c(y),color:"red",children:s.jsx(B.Trash,{size:14})}),sx:{width:"45%"}})),s.jsx(o.ActionIcon,{onClick:l,color:"blue",variant:"outline",children:s.jsx(B.PlaylistAdd,{size:20})})]})]})}const OT=m.forwardRef(LT);function VT({label:t,value:e,onChange:n,type:r},i){const[a,l]=m.useState(Array.isArray(e)?[...e]:[]),c=m.useCallback(()=>{l(h=>[...h,""])},[l]),u=m.useCallback(h=>{l(g=>(g.splice(h,1),[...g]))},[l]),d=m.useMemo(()=>!x.isEqual(a.map(String),e.map(String)),[a,e]),p=()=>{n(a.map(h=>r==="number"?Number(h):h.toString()))};return s.jsxs(s.Fragment,{children:[s.jsxs(o.Group,{position:"left",ref:i,children:[s.jsx(o.Text,{children:t}),s.jsx(o.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!d,onClick:p,children:s.jsx(B.DeviceFloppy,{size:20})})]}),s.jsxs(o.Group,{children:[a.map((h,g)=>s.jsx(o.TextInput,{type:r,value:h,onChange:y=>{const v=y.currentTarget.value;l(C=>(C.splice(g,1,v),[...C]))},rightSection:s.jsx(o.ActionIcon,{onClick:()=>u(g),color:"red",children:s.jsx(B.Trash,{size:14})}),sx:{width:"45%"}})),s.jsx(o.ActionIcon,{onClick:c,color:"blue",variant:"outline",children:s.jsx(B.PlaylistAdd,{size:20})})]})]})}const NT=m.forwardRef(VT),GT=m.forwardRef(function({value:e,onChange:n},r){const{t:i}=_.useTranslation(),a=e.color.type,l=(u,d)=>{const p=x.cloneDeep(e);x.set(p,u,d),n(p)},c=u=>{if(u==="static"){n({...e,color:{type:"static",staticColor:"#25262B"}});return}n({...e,color:{type:"continuous",colorRange:[],valueRange:[]}})};return s.jsxs(s.Fragment,{children:[s.jsx(o.Stack,{children:s.jsx(o.TextInput,{label:i("style.font_size.label"),placeholder:i("styles.font_size.placeholder"),sx:{flex:1},value:e.size,onChange:u=>l("size",u.currentTarget.value)})}),s.jsx(o.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:s.jsx(sl,{label:i("style.font_weight.label"),value:e.weight,onChange:u=>l("weight",u)})}),s.jsx(o.Divider,{mt:"lg",mb:0,variant:"dashed",label:i("style.label"),labelPosition:"center"}),s.jsxs(o.Stack,{children:[s.jsx(o.Select,{label:"Color Type",data:[{label:"Static Color",value:"static"},{label:"Continuous Color",value:"continuous"}],value:e.color.type,onChange:c}),a==="static"&&s.jsx(Te,{value:e.color.staticColor,onChange:u=>l("color.staticColor",u)}),a==="continuous"&&s.jsxs(s.Fragment,{children:[s.jsx(NT,{label:"Value Range",value:e.color.valueRange,type:"number",onChange:u=>l("color.valueRange",u)}),s.jsx(OT,{label:"Color Range",value:e.color.colorRange,onChange:u=>l("color.colorRange",u)})]})]})]})}),FT=m.forwardRef(function({value:e,onChange:n,withStyle:r=!0,remove:i},a){const{t:l}=_.useTranslation(),c=(u,d)=>{const p=x.cloneDeep(e);x.set(p,u,d),n(p)};return s.jsxs(o.Stack,{ref:a,children:[s.jsxs(o.Stack,{spacing:"xs",px:"sm",py:"md",sx:{border:"1px solid #e9ecef"},children:[s.jsxs(o.Group,{grow:!0,noWrap:!0,children:[s.jsx(o.TextInput,{label:l("common.name"),required:!0,value:e.name,onChange:u=>c("name",u.currentTarget.value)}),s.jsx(L,{label:l("common.data_field"),required:!0,value:e.data_field,onChange:u=>c("data_field",u)})]}),s.jsx(fr,{label:l("panel.variable.aggregation.label"),pt:0,value:e.aggregation,onChange:u=>c("aggregation",u),withFallback:!0}),e.aggregation.type!=="custom"&&s.jsxs(s.Fragment,{children:[s.jsx(o.Divider,{mt:"xl",mb:0,label:l("numbro.format.label"),labelPosition:"center",variant:"dashed"}),s.jsx(We,{value:e.formatter,onChange:u=>c("formatter",u)})]})]}),r&&s.jsx(o.Accordion,{variant:"contained",children:s.jsxs(o.Accordion.Item,{value:"Styles",children:[s.jsx(o.Accordion.Control,{icon:s.jsx(o.Text,{size:"xl",children:"🖼️"}),children:l("style.label")}),s.jsx(o.Accordion.Panel,{children:s.jsx(GT,{value:e,onChange:n})})]})}),s.jsx(o.Button,{mt:20,leftIcon:s.jsx(k.IconTrash,{size:16}),color:"red",variant:"light",onClick:i,children:l("panel.variable.delete")})]})}),WT=S.observer(t=>{const{t:e}=_.useTranslation(),n=N.useCreation(()=>Hl(t.variable),[t.variable]),r=()=>t.uiModel.remove(t.variable);return s.jsxs(o.Stack,{"data-testid":"variable-editor",align:"stretch",children:[s.jsxs(o.Group,{position:"apart",children:[s.jsx(o.Button,{variant:"subtle",size:"xs",disabled:!n.changed,color:"red",onClick:n.reset,leftIcon:s.jsx(k.IconRecycle,{size:18}),children:e("common.actions.revert_changes")}),s.jsx(o.Button,{variant:"filled",size:"xs",disabled:!n.changed,color:"green",onClick:n.commit,leftIcon:s.jsx(k.IconDeviceFloppy,{size:18}),children:e("common.actions.save_changes")})]}),s.jsx(FT,{value:f.getSnapshot(n.copy),onChange:n.update,remove:r})]})});S.observer(t=>{const{uiModel:e}=t;return s.jsx(o.Stack,{className:"var-list",children:e.variables.map(n=>s.jsx(o.Button,{variant:e.selected===n?"filled":"subtle",color:"gray",onClick:()=>e.select(n),children:n.name},n.name))})});const QT=S.observer(({model:t})=>{const{t:e}=_.useTranslation();return s.jsx(o.Overlay,{color:"#fff",opacity:1,sx:{position:"absolute"},children:s.jsx(o.Button,{variant:"light",size:"xs",leftIcon:s.jsx(k.IconPlus,{size:16}),onClick:t.addNew,sx:{flexGrow:0,flexShrink:0,alignSelf:"flex-end",height:"38px"},children:e("panel.variable.add")})})}),RT=S.observer(()=>{var n;const{t}=_.useTranslation(),e=qT();return e.variableOptions.length===0?s.jsx(QT,{model:e}):s.jsxs(o.Stack,{pb:20,children:[s.jsxs(o.Group,{position:"left",children:[s.jsx(o.Select,{label:t("panel.variable.labels"),data:e.variableOptions,value:(n=e.selected)==null?void 0:n.name,onChange:e.selectByName,maxDropdownHeight:600,sx:{flexGrow:1}}),s.jsx(o.Button,{variant:"light",size:"xs",leftIcon:s.jsx(k.IconPlus,{size:16}),onClick:e.addNew,sx:{flexGrow:0,flexShrink:0,alignSelf:"flex-end",height:"38px"},children:t("panel.variable.add")})]}),s.jsx(o.Divider,{variant:"dashed"}),e.selected?s.jsx(WT,{uiModel:e,variable:e.selected}):s.jsx("span",{children:"Select or create a new variable on right side"})]})}),UT=S.observer(()=>{const{t}=_.useTranslation(),{panel:e}=$e();return Object.keys(e.variableStrings).length===0?null:s.jsxs(o.Stack,{mt:22,spacing:4,children:[s.jsx(o.Text,{size:"sm",fw:500,color:"dimmed",children:t("panel.variable.labels")}),s.jsx(vt.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(e.variableStrings,null,4)})]})});function YT(){const{t}=_.useTranslation(),{vizManager:e}=m.useContext(it);return m.useMemo(()=>{const n=e.availableVizList.map(r=>({value:r.name,label:t(r.displayName??r.name),group:t(r.displayGroup??"")}));return x.orderBy(n,[r=>r.group,r=>r.label],["asc","asc"])},[e])}const KT=S.observer(({value:t,submit:e})=>{const{t:n}=_.useTranslation(),[r,i]=ie.useInputState(t);m.useEffect(()=>{i(t)},[t]);const a=YT(),l=t!==r;return s.jsx(o.Select,{label:n("visualization.component"),value:r,searchable:!0,onChange:i,data:a,rightSection:s.jsx(o.ActionIcon,{variant:"filled",color:"green",disabled:!l,onClick:()=>e(r),children:s.jsx(B.DeviceFloppy,{size:20})}),maxDropdownHeight:600})}),Oc=[];function JT(t,e){try{return t.resolveComponent(e).createConfig()}catch{return null}}function XT(){const{data:t,panel:{variables:e,viz:n,title:r,name:i,queryIDs:a,description:l,id:c}}=$e(),{vizManager:u}=m.useContext(it),d={name:i,title:r,description:l,viz:n,queryIDs:a,id:c},p=tc(d);try{return u.resolveComponent(d.viz.type),s.jsx(as,{configure:p,children:s.jsx(wS,{variables:e,setVizConf:n.setConf,panel:d,vizManager:u,data:t})})}catch(h){return console.info(x.get(h,"message")),null}}const ZT=S.observer(()=>{const{data:t,panel:{viz:e}}=$e(),{vizManager:n}=m.useContext(it),r=m.useCallback(d=>{if(d===e.type)return;const p=JT(n,d);e.setType(d),e.setConf(p||{})},[e.type]),i=d=>{try{e.setConf(JSON.parse(d))}catch(p){console.error(p)}},a=m.useMemo(()=>{var d;return(d=Oc.find(p=>p.value===e.type))==null?void 0:d.Panel},[e.type,Oc]),l=XT(),c=a?m.createElement(a,{data:t,conf:e.conf,setConf:e.setConf}):null,u=l||c;return s.jsxs(o.Stack,{align:"stretch",sx:{height:"100%",overflow:"hidden"},children:[s.jsx(KT,{submit:r,value:e.type}),s.jsxs(we,{children:[s.jsx(o.Stack,{pb:10,sx:{flexGrow:1,maxHeight:"100%",overflow:"auto"},children:u}),!u&&s.jsx(o.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(e.conf,null,2),onChange:i})]})]})}),HT=S.observer(({panel:t,sourceViewID:e})=>{const{t:n}=_.useTranslation(),r=U(),[i,a]=m.useState(e);m.useEffect(()=>{a(e)},[e]);const[l,{open:c,close:u}]=ie.useDisclosure(!1),d=()=>{t.moveToView(e,i),u()};return s.jsxs(s.Fragment,{children:[s.jsx(o.Button,{size:"xs",variant:"subtle",color:"blue",onClick:c,leftIcon:s.jsx(k.IconBoxMultiple,{size:14}),children:n("panel.settings.change_view")}),s.jsx(o.Modal,{opened:l,onClose:u,title:n("panel.settings.change_view_title"),zIndex:320,children:s.jsxs(o.Stack,{sx:{maxHeight:"calc(100vh - 185px)",overflow:"hidden"},children:[s.jsx(o.Radio.Group,{value:i,onChange:a,pb:10,sx:{flexGrow:1,maxHeight:"calc(100vh - 185px - 30px)",overflow:"auto"},children:s.jsx(o.Stack,{spacing:"xs",children:r.views.options.map(p=>s.jsx(o.Radio,{value:p.value,label:p.label},p.value))})}),s.jsxs(o.Group,{noWrap:!0,position:"apart",sx:{flexGrow:0,flexShrink:0},children:[s.jsx(o.Button,{size:"xs",color:"red",leftIcon:s.jsx(k.IconX,{size:14}),onClick:u,children:n("common.actions.cancel")}),s.jsx(o.Button,{size:"xs",color:"blue",leftIcon:s.jsx(k.IconDeviceFloppy,{size:14}),onClick:d,disabled:i===e,children:n("common.actions.confirm")})]})]})})]})}),e1={root:{flexGrow:1,width:"100%",minWidth:"1200px",overflow:"hidden"},panel:{width:"100%",minWidth:"1200px",height:"calc(100% - 44px)",padding:10,overflow:"auto"}},Ti=({children:t})=>s.jsxs(o.Group,{noWrap:!0,grow:!0,position:"left",spacing:20,sx:{width:"100%",height:"100%",position:"relative"},children:[s.jsx(o.Box,{sx:{maxWidth:"calc(100% - 610px - 10px)",height:"100%",overflow:"auto"},children:t}),s.jsxs(o.Stack,{justify:"flex-start",sx:{alignSelf:"flex-start",width:"600px",flexGrow:0,flexShrink:0},children:[s.jsx($T,{}),s.jsx(o.Box,{sx:{flexGrow:1},children:s.jsx(UT,{})})]})]});function t1(t){return!["richText","button"].includes(t)}const n1=S.observer(({panel:t})=>{const{t:e}=_.useTranslation(),n=Le.useModals(),r=H(),i=U(),[a,l]=m.useState("Data"),c=t.queries,d=t1(t.viz.type)&&t.dataLoading,p=d||t.queryErrors.length>0||t.queryStateMessages!==""||c.length===0,h=r.editor.path[1];m.useEffect(()=>{l(v=>p&&v==="Visualization"?"Data":v)},[t.id,p]);const g=()=>{r.editor.setPath(["_VIEWS_",h])},y=()=>n.openConfirmModal({title:`${e("panel.delete")}?`,labels:{confirm:e("common.actions.confirm"),cancel:e("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.removePanelByID(t.id,h),g()},confirmProps:{color:"red"},zIndex:320});return s.jsxs(Bs,{value:{panel:t,data:t.data,loading:d,errors:t.queryErrors,downloadPanelScreenshot:()=>{}},children:[s.jsxs(o.Group,{px:16,position:"apart",sx:{borderBottom:"1px solid #eee"},children:[s.jsx(o.Text,{pt:9,pb:8,children:t.name}),s.jsxs(o.Group,{position:"right",noWrap:!0,children:[s.jsx(HT,{panel:t,sourceViewID:h}),s.jsx(o.Button,{size:"xs",variant:"subtle",color:"red",onClick:y,leftIcon:s.jsx(k.IconTrash,{size:14}),children:e("panel.delete")})]})]}),s.jsxs(o.Tabs,{value:a,onTabChange:l,keepMounted:!1,styles:e1,children:[s.jsxs(o.Tabs.List,{children:[s.jsx(o.Tabs.Tab,{value:"Data",disabled:d,children:e("data.label")}),s.jsx(o.Tabs.Tab,{value:"Panel",children:e("panel.label")}),s.jsx(o.Tabs.Tab,{value:"Variables",disabled:p,children:s.jsx(o.Tooltip,{label:e("data.requires_data"),disabled:!p,withinPortal:!0,zIndex:310,children:s.jsx(o.Text,{children:e("panel.variable.labels")})})}),s.jsx(o.Tabs.Tab,{value:"Visualization",disabled:p,children:s.jsx(o.Tooltip,{label:e("data.requires_data"),disabled:!p,withinPortal:!0,zIndex:310,children:s.jsx(o.Text,{children:e("visualization.label")})})}),s.jsx(o.Tabs.Tab,{value:"Interactions",children:e("interactions.label")})]}),s.jsxs(o.Tabs.Panel,{value:"Data",children:[s.jsx(o.LoadingOverlay,{visible:d,exitTransitionDuration:0}),s.jsx(PT,{})]}),s.jsx(o.Tabs.Panel,{value:"Panel",children:s.jsx(Ti,{children:s.jsx(TT,{})})}),s.jsx(o.Tabs.Panel,{value:"Variables",children:s.jsx(Ti,{children:s.jsx(RT,{})})}),s.jsx(o.Tabs.Panel,{value:"Visualization",children:s.jsx(we,{children:s.jsx(Ti,{children:s.jsx(ZT,{})})})}),s.jsx(o.Tabs.Panel,{value:"Interactions",children:s.jsx(we,{children:s.jsx(nh,{})})})]})]})}),s1=S.observer(({viewID:t,panelID:e})=>{const n=U();if(!n.views.findByID(t))return s.jsxs(o.Text,{size:14,children:["View by ID[",t,"] is not found"]});const i=n.panels.findByID(e);return i?s.jsx(n1,{panel:i}):s.jsxs(o.Text,{size:14,children:["Panel by ID[",e,"] is not found"]})}),r1=S.observer(()=>{const{t}=_.useTranslation(),[e,n]=m.useState([]),r=Le.useModals(),i=H(),a=g=>{i.editor.setPath(["_QUERIES_",g])},l=()=>{r.openConfirmModal({title:"Delete ununsed queries?",children:s.jsx(o.Text,{size:"sm",children:"This action cannot be undone."}),labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>i.content.removeUnusedQueries(),confirmProps:{color:"red"},zIndex:320})},c=()=>{i.content.queries.downloadSchema(e)},u=m.useMemo(()=>i.content.queries.sortedList.map(g=>g.id),[i.content.queries.sortedList]),d=()=>{n(u)},p=()=>{n([])},h=i.content.queriesUsage;return s.jsxs(o.Stack,{sx:{height:"100%"},spacing:"sm",pb:"59px",children:[s.jsx(o.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:s.jsx(o.Text,{px:"md",align:"left",sx:{userSelect:"none",cursor:"default"},children:t("query.manage")})}),s.jsxs(o.Flex,{justify:"space-between",align:"center",px:12,children:[s.jsxs(o.Group,{position:"left",children:[s.jsxs(o.Button.Group,{children:[s.jsx(o.Button,{variant:"default",size:"xs",onClick:d,children:t("common.actions.select_all")}),s.jsx(o.Button,{variant:"default",size:"xs",onClick:p,children:t("common.actions.clear_selection")})]}),s.jsx(o.Button,{size:"xs",color:"blue",leftIcon:s.jsx(k.IconCode,{size:14}),disabled:e.length===0,onClick:c,children:t("common.actions.download_schema")})]}),s.jsx(o.Button,{variant:"subtle",size:"xs",color:"red",leftIcon:s.jsx(k.IconTrash,{size:14}),disabled:!i.content.hasUnusedQueries,onClick:l,children:t("query.delete_unused")})]}),s.jsx(o.Box,{sx:{flexGrow:1,overflow:"auto"},children:s.jsx(o.Checkbox.Group,{size:"xs",value:e,onChange:n,children:s.jsxs(o.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:t("common.name")}),s.jsx("th",{style:{width:"200px"},children:t("data_source.label")}),s.jsx("th",{style:{width:"100px",textAlign:"right"},children:t("common.type")}),s.jsx("th",{style:{width:"100px",textAlign:"center"},children:t("query.usage.label")}),s.jsx("th",{style:{width:"300px",paddingLeft:"24px"},children:t("common.action")})]})}),s.jsx("tbody",{children:i.content.queries.sortedList.map(g=>{var v;const y=((v=h[g.id])==null?void 0:v.length)??0;return s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx(o.Checkbox,{value:g.id,styles:{input:{cursor:"pointer"}}})}),s.jsx("td",{children:g.name}),s.jsx("td",{children:g.key}),s.jsx("td",{style:{textAlign:"right"},children:g.type}),s.jsx("td",{style:{color:y===0?"#ff0000":"#000",fontWeight:y===0?"bold":"normal",textAlign:"center"},children:y}),s.jsx("td",{children:s.jsx(o.Button,{variant:"subtle",size:"xs",onClick:()=>a(g.id),children:t("common.actions.open")})})]},g.id)})})]})})})]})}),i1=t=>{const{t:e}=_.useTranslation(),{queryModel:n}=t,r=H(),i=U(),l=i.findQueryUsage(n.id).length>0,c=Le.useModals(),u=()=>{c.openConfirmModal({title:`${e("query.delete")}?`,labels:{confirm:e("common.actions.confirm"),cancel:e("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.queries.removeQuery(n.id),r.editor.setPath(["_QUERIES_",""])},confirmProps:{color:"red"},zIndex:320})};return l?s.jsx(o.Tooltip,{label:e("query.cant_delete"),withArrow:!0,events:{hover:!0,focus:!1,touch:!1},withinPortal:!0,zIndex:320,position:"top-end",children:s.jsx(o.Box,{sx:{alignSelf:"flex-end"},children:s.jsx(o.Button,{disabled:!0,size:"xs",leftIcon:s.jsx(k.IconTrash,{size:16}),children:e("query.delete")})})}):s.jsx(o.Button,{color:"red",size:"xs",onClick:u,leftIcon:s.jsx(k.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:e("query.delete")})},a1=S.observer(i1),Vc=({width:t="calc(100% - 32px)",lastWidth:e="50%",height:n,count:r,spacing:i=16,pl:a=0})=>s.jsxs(o.Stack,{spacing:i,mt:6,pl:a,children:[Array.from(new Array(r-1),(l,c)=>s.jsx(o.Skeleton,{width:t,height:n,radius:"xs"},c)),s.jsx(o.Skeleton,{width:e,height:n,radius:"xs"})]}),yn=({value:t})=>t===null||t===""?null:s.jsx(o.Tooltip,{label:t,disabled:!t,multiline:!0,children:s.jsx(o.ActionIcon,{children:s.jsx(k.IconInfoCircle,{size:14})})}),o1=({column:t})=>{const{column_key:e,column_key_text:n}=t;return e?s.jsx(o.Tooltip,{label:n,disabled:!n,children:s.jsx(o.Badge,{children:e})}):null},l1=S.observer(({dataSource:t})=>{const{columns:e}=t;return e.loading?s.jsx(Vc,{height:"24px",width:"100%",lastWidth:"100%",count:20,pl:6}):e.empty?null:s.jsxs(o.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:e.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(yn,{value:n.column_comment})}),s.jsx("td",{children:s.jsx(o1,{column:n})}),s.jsx("td",{children:n.column_type}),s.jsx("td",{children:n.is_nullable}),s.jsx("td",{children:s.jsx(yn,{value:n.column_default})})]},n.column_name))})]})}),c1=S.observer(({dataSource:t})=>{const{indexes:e}=t,n=e.data;return s.jsxs(o.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))})]})}),u1=S.observer(({dataSource:t})=>{const{indexes:e}=t,n=e.data;return s.jsxs(o.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(yn,{value:r.index_definition})}),s.jsx("td",{children:s.jsx(yn,{value:r.condition})}),s.jsx("td",{children:s.jsx(yn,{value:r.comment})})]},r.index_name))})]})}),d1=S.observer(({dataSource:t})=>{const{indexes:e}=t;return e.loading||e.empty?null:t.type===ce.MySQL?s.jsx(c1,{dataSource:t}):t.type===ce.Postgresql?s.jsx(u1,{dataSource:t}):null}),p1=S.observer(({dataSource:t})=>s.jsxs(o.Stack,{spacing:40,pt:10,sx:{flexGrow:1,overflow:"auto",position:"relative"},children:[s.jsx(we,{children:s.jsx(l1,{dataSource:t})}),s.jsx(we,{children:s.jsx(d1,{dataSource:t})})]}));function h1({table_type:t}){return t==="VIEW"?s.jsx(k.IconEye,{size:14}):t==="BASE TABLE"?s.jsx(k.IconTable,{size:14}):null}const m1=S.observer(({dataSource:t})=>{const{tables:e}=t;return e.loading?s.jsx(Vc,{height:"24px",lastWidth:"50%",count:15}):s.jsx(o.Box,{h:"100%",sx:{overflow:"auto",".mantine-NavLink-label":{fontFamily:"monospace"}},children:Object.entries(e.data).map(([n,r])=>s.jsx(o.NavLink,{label:n,icon:s.jsx(k.IconDatabase,{size:14}),defaultOpened:t.table_schema===n,pl:0,childrenOffset:14,children:r.map(i=>s.jsx(o.NavLink,{label:i.table_name,icon:s.jsx(h1,{table_type:i.table_type}),onClick:()=>{t.setKeywords(n,i.table_name)},active:t.table_name===i.table_name},i.table_name))},n))})}),f1=({visible:t})=>s.jsx(o.Box,{py:10,sx:{width:"100%",height:"100%",overflow:"hidden",position:"relative"},children:s.jsx(o.LoadingOverlay,{visible:t})}),g1=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],x1={icon:{width:"50px",textAlign:"center"},input:{"&[data-with-icon]":{paddingLeft:"50px"}}},y1=S.observer(({dataSource:t})=>{const{t:e}=_.useTranslation(),{tableData:n}=t;return s.jsxs(o.Group,{pt:10,px:10,position:"apart",children:[s.jsxs(o.Group,{position:"left",children:[n.maxPage>1&&s.jsx(o.Pagination,{size:"sm",value:n.page,onChange:n.setPage,total:n.maxPage,withEdges:n.maxPage>7,styles:{control:{height:"30px"}}}),s.jsx(o.Select,{icon:s.jsx(o.Text,{ta:"center",color:"dimmed",size:14,children:e("common.pagination.page_size")}),size:"xs",styles:x1,data:g1,value:String(n.limit),onChange:r=>n.setLimit(Number(r))})]}),s.jsx(o.Group,{position:"right",children:s.jsx(o.Text,{color:"dimmed",my:0,size:14,children:e("common.pagination.total_rows",{total:n.total})})})]})}),b1=S.observer(({dataSource:t})=>{const e=t.tableData;return e.maxPage===0?s.jsx(o.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:"This table is empty"}):e.error?s.jsx(o.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:e.error}):e.page===1&&e.loading?s.jsx(f1,{visible:!0}):s.jsxs(we,{children:[s.jsx(y1,{dataSource:t}),s.jsxs(o.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[s.jsx(o.LoadingOverlay,{visible:e.loading,overlayBlur:2}),s.jsx(Lc,{data:e.data})]})]})}),v1={root:{flexGrow:1,overflow:"auto",borderLeft:"1px solid #efefef"},tabsList:{borderBottom:"1px solid #efefef"},tab:{minWidth:120}},_1=S.observer(({dataSource:t})=>{const{t:e}=_.useTranslation();return m.useEffect(()=>{t.loadTablesIfEmpty()},[t]),t.tables.error?s.jsx(o.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:t.tables.error}):s.jsxs(o.Flex,{sx:{height:"100%"},children:[s.jsx(o.Box,{w:300,sx:{flexGrow:0,flexShrink:0,position:"relative"},children:s.jsx(we,{children:s.jsx(m1,{dataSource:t})})}),s.jsxs(o.Tabs,{defaultValue:"structure",styles:v1,children:[s.jsxs(o.Tabs.List,{children:[s.jsx(o.Tabs.Tab,{value:"structure",icon:s.jsx(k.IconColumns,{size:14}),children:e("data_source.table_structure_short")}),s.jsx(o.Tabs.Tab,{value:"data",icon:s.jsx(k.IconDatabase,{size:14}),children:e("data.label")})]}),s.jsx(o.Tabs.Panel,{value:"structure",children:s.jsx(p1,{dataSource:t})}),s.jsx(o.Tabs.Panel,{value:"data",sx:{width:"100%",height:"calc(100% - 36px)",overflow:"hidden"},children:s.jsx(b1,{dataSource:t})})]})]})}),j1={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"}},Nc=S.observer(({dataSource:t,triggerButtonProps:e={}})=>{const{t:n}=_.useTranslation(),[r,i]=m.useState(!1);return t.type==="http"?null:s.jsxs(s.Fragment,{children:[s.jsx(o.Modal,{opened:r,onClose:()=>i(!1),title:s.jsxs(o.Group,{position:"apart",sx:{flexGrow:1},children:[s.jsx(o.Text,{fw:500,children:n("data_source.explorer")}),s.jsxs(o.Group,{spacing:7,children:[s.jsx(o.Badge,{variant:"gradient",gradient:{from:"indigo",to:"cyan"},children:t.key}),s.jsx(o.Badge,{variant:"gradient",gradient:{from:"orange",to:"red"},children:t.type})]})]}),zIndex:320,size:"96vw",styles:j1,children:s.jsx(o.Box,{sx:{height:"calc(100vh - 220px)"},children:s.jsx(_1,{dataSource:t})})}),s.jsx(o.Button,{variant:"subtle",onClick:()=>i(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},...e,children:n("data_source.see_table_structure")})]})}),w1=m.forwardRef(({label:t,type:e,...n},r)=>e===ce.Transform?s.jsxs(o.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(k.IconVectorTriangle,{size:14,color:"#228be6"}),s.jsx(o.Text,{color:"blue",children:t})]}):s.jsxs(o.Group,{position:"apart",ref:r,...n,children:[s.jsx(o.Text,{children:t}),s.jsx(o.Text,{children:e})]})),C1=S.observer(({value:t,onChange:e})=>{const{t:n}=_.useTranslation(),r=H(),{data:i=[],loading:a}=N.useRequest(zs,{refreshDeps:[]},[]),l=m.useMemo(()=>{const p=i.map(h=>({label:h.key,value:h.key,type:h.type}));return p.push({label:n("query.transform.data_source"),value:ce.Transform,type:ce.Transform}),p},[i]),c=m.useMemo(()=>l.reduce((p,h)=>(p[h.value]=h.type,p),{}),[l]),u=p=>{p!==null&&e({key:p,type:c[p]})},d=m.useMemo(()=>r.datasources.find(t),[r,t]);return s.jsx(o.Select,{data:l,label:s.jsxs(o.Group,{position:"apart",children:[s.jsx(o.Box,{children:n("data_source.label")}),d&&s.jsx(Nc,{dataSource:d,triggerButtonProps:{compact:!0,size:"xs",px:10}})]}),itemComponent:w1,rightSection:d?s.jsx(o.Text,{size:"xs",color:"dimmed",children:d.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:a,value:t.key,onChange:u})}),Gc=m.forwardRef((t,e)=>{const{label:n,description:r,...i}=t;return s.jsx("div",{ref:e,...i,children:s.jsxs(o.Group,{position:"apart",noWrap:!0,children:[s.jsx(o.Text,{children:n}),s.jsx(o.Text,{size:"xs",color:"dimmed",children:r})]})})}),S1=S.observer(({queryModel:t})=>{const{t:e}=_.useTranslation(),[n,r]=m.useState(t.name);return m.useEffect(()=>{r(t.name)},[t.name]),s.jsx(o.Center,{ml:20,mt:20,sx:{maxWidth:"600px"},children:s.jsxs(o.Stack,{spacing:10,sx:{width:"100%"},children:[s.jsx(o.Divider,{mb:-10,variant:"dashed",label:e("query.basics"),labelPosition:"center"}),s.jsx(o.TextInput,{placeholder:e("query.name_description"),label:e("query.name"),required:!0,sx:{flex:1},value:n,onChange:i=>{r(i.currentTarget.value)},rightSection:s.jsx(o.ActionIcon,{variant:"filled",color:"blue",size:"sm",onClick:()=>t.setName(n),disabled:n===t.name,children:s.jsx(k.IconDeviceFloppy,{size:16})}),onBlur:()=>{t.setName(n)}}),s.jsx(C1,{value:{type:t.type,key:t.key},onChange:({type:i,key:a})=>{t.setKey(a),t.setType(i)}}),s.jsx(o.Divider,{mt:10,mb:-10,variant:"dashed",label:e("query.conditions"),labelPosition:"center"}),s.jsx(o.MultiSelect,{label:e("query.run_by_condition.label"),placeholder:e("query.run_by_condition.unset"),data:t.conditionOptions,value:[...t.run_by],onChange:t.setRunBy,itemComponent:Gc,maxDropdownHeight:500}),t.typedAsHTTP&&s.jsx(o.MultiSelect,{label:e("query.re_run_condition.label"),placeholder:e("query.re_run_condition.label"),data:t.conditionOptions,value:[...t.react_to],onChange:t.setReactTo,itemComponent:Gc,maxDropdownHeight:500}),s.jsx(o.Divider,{mt:20,mb:10,variant:"dashed"}),s.jsx(a1,{queryModel:t})]})})});function k1({content:t}){return s.jsxs(o.HoverCard,{width:"60vw",shadow:"md",children:[s.jsx(o.HoverCard.Target,{children:s.jsx(o.ActionIcon,{size:16,color:"blue",children:s.jsx(k.IconEye,{})})}),s.jsx(o.HoverCard.Dropdown,{children:s.jsx(vt.Prism,{language:"sql",noCopy:!0,withLineNumbers:!0,children:t})})]})}const T1=S.observer(()=>{const e=[...H().globalSQLSnippets.list];return e.length===0?null:s.jsxs(o.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:e.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(k1,{content:i})})]},r)})})]})}),D1=`
464
+ `,m1=()=>{const{t}=_.useTranslation(),[e,n]=m.useState(!1);return s.jsxs(s.Fragment,{children:[s.jsx(o.Button,{variant:"subtle",compact:!0,onClick:()=>n(r=>!r),children:t(e?"common.actions.close":"filter.widget.common.see_data_structure")}),s.jsx(o.Collapse,{in:e,children:s.jsx(vt.Prism,{language:"typescript",noCopy:!0,colorScheme:"dark",children:h1})})]})},f1=S.observer(function({filter:e}){const{t:n}=_.useTranslation(),r=e.config;return s.jsxs(s.Fragment,{children:[s.jsxs(o.Group,{position:"apart",children:[s.jsx(o.Checkbox,{checked:r.required,onChange:i=>r.setRequired(i.currentTarget.checked),label:n("filter.widget.select.required")}),s.jsx(Xt,{filter:e})]}),s.jsx(o.TextInput,{label:n("filter.widget.common.min_width"),value:r.min_width,onChange:i=>r.setMinWidth(i.currentTarget.value),placeholder:"200px"}),s.jsx(o.Divider,{label:n("filter.widget.common.fetch_options_from_datasource"),labelPosition:"center"}),s.jsx(o.Checkbox,{checked:r.treeCheckStrictly,onChange:i=>r.setTreeCheckStrictly(i.currentTarget.checked),label:n("filter.widget.tree_select.strictly")}),s.jsx(o.NumberInput,{value:r.default_selection_count,onChange:r.setDefaultSelectionCount,label:n("filter.widget.common.default_selection_count")}),s.jsx(Ci,{value:r.options_query_id,onChange:r.setOptionsQueryID}),s.jsx(m1,{})]})}),g1=S.observer(function({filter:e}){const{t:n}=_.useTranslation();return s.jsxs(o.Box,{sx:{maxWidth:"480px"},children:[s.jsx(o.Text,{pt:"0",pb:"md",color:"gray",children:n("common.titles.config")}),s.jsx(vt.Prism,{mt:22,language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(e,null,4)})]})}),x1={select:d1,"multi-select":u1,"tree-select":f1,"text-input":p1,checkbox:a1,"date-range":l1},$t={select:"filter.widget.names.select","multi-select":"filter.widget.names.multi_select","tree-select":"filter.widget.names.tree_select","text-input":"filter.widget.names.text_input",checkbox:"filter.widget.names.checkbox","date-range":"filter.widget.names.date_range"},y1=S.observer(function({filter:e}){const{t:n,i18n:r}=_.useTranslation(),i=U(),a=m.useMemo(()=>x1[e.type],[e.type]),l=m.useMemo(()=>[{label:n($t.select),value:"select"},{label:n($t["multi-select"]),value:"multi-select"},{label:n($t["tree-select"]),value:"tree-select"},{label:n($t["text-input"]),value:"text-input"},{label:n($t.checkbox),value:"checkbox"},{label:n($t["date-range"]),value:"date-range"}],[r.language]);return s.jsxs(o.Group,{grow:!0,spacing:20,align:"top",children:[s.jsxs(o.Box,{sx:{maxWidth:"600px"},children:[s.jsx(o.Text,{pb:"md",color:"gray",children:n("common.titles.edit")}),s.jsxs(o.Stack,{children:[s.jsxs(o.Group,{noWrap:!0,children:[s.jsx(o.NumberInput,{label:n("filter.field.order"),required:!0,value:e.order,onChange:e.setOrder,hideControls:!0,sx:{flexGrow:"1 !important"}}),e.auto_submit_supported&&s.jsx(o.Checkbox,{label:n("filter.field.auto_submit"),checked:e.auto_submit,onChange:c=>e.setAutoSubmit(c.currentTarget.checked),mt:22})]}),s.jsx(o.MultiSelect,{label:n("filter.field.visible_in"),data:i.views.options,value:[...e.visibleInViewsIDs],onChange:e.setVisibleInViewsIDs}),s.jsx(o.TextInput,{label:n("common.key"),placeholder:n("filter.field.key_placeholder"),required:!0,value:e.key,onChange:c=>{e.setKey(c.currentTarget.value)}}),s.jsx(o.TextInput,{label:n("common.label"),placeholder:n("filter.field.label_placeholder"),required:!0,value:e.label,onChange:c=>{e.setLabel(c.currentTarget.value)}}),s.jsx(o.Select,{label:n("filter.field.widget"),data:l,required:!0,value:e.type,onChange:e.setType,maxDropdownHeight:500}),s.jsx(o.Divider,{mb:0,mt:10,variant:"dashed",labelPosition:"center"}),s.jsx(a,{filter:e})]})]}),s.jsx(g1,{filter:e})]})}),b1=S.observer(({id:t})=>{const{t:e}=_.useTranslation(),n=Le.useModals(),r=H(),i=U();if(t==="")return null;const a=i.filters.findByID(t);if(!a)return s.jsxs(o.Text,{size:14,children:["Filter by ID[",t,"] is not found"]});const l=()=>{r.editor.setPath(["_FILTERS_",""])},c=()=>{n.openConfirmModal({title:`${e("filter.delete")}?`,labels:{confirm:e("common.actions.confirm"),cancel:e("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.filters.removeByID(t),l()},confirmProps:{color:"red"},zIndex:320})};return s.jsxs(o.Stack,{sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",pb:30,children:[s.jsx(o.Group,{position:"right",pt:10,children:s.jsx(o.Button,{size:"xs",color:"red",leftIcon:s.jsx(B.Trash,{size:16}),onClick:c,children:e("filter.delete")})}),s.jsx(o.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:s.jsx(y1,{filter:a})})]})}),v1=S.observer(()=>{const{t}=_.useTranslation(),[e,n]=m.useState([]),r=H(),i=d=>{r.editor.setPath(["_FILTERS_",d])},a=()=>{r.content.filters.downloadSchema(e)},l=m.useMemo(()=>r.content.filters.sortedList.map(d=>d.id),[r.content.filters.sortedList]),c=()=>{n(l)},u=()=>{n([])};return s.jsxs(o.Stack,{sx:{height:"100%"},spacing:"sm",pb:"59px",children:[s.jsx(o.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:s.jsx(o.Text,{px:"md",align:"left",sx:{userSelect:"none",cursor:"default"},children:t("filter.manage")})}),s.jsx(o.Flex,{justify:"space-between",align:"center",px:12,children:s.jsxs(o.Group,{position:"left",children:[s.jsxs(o.Button.Group,{children:[s.jsx(o.Button,{variant:"default",size:"xs",onClick:c,children:t("common.actions.select_all")}),s.jsx(o.Button,{variant:"default",size:"xs",onClick:u,children:t("common.actions.clear_selection")})]}),s.jsx(o.Button,{size:"xs",color:"blue",leftIcon:s.jsx(k.IconCode,{size:14}),disabled:e.length===0,onClick:a,children:t("common.actions.download_schema")})]})}),s.jsx(o.Box,{sx:{flexGrow:1,overflow:"auto"},children:s.jsx(o.Checkbox.Group,{size:"xs",value:e,onChange:n,children:s.jsxs(o.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:t("common.label")}),s.jsx("th",{children:t("common.key")}),s.jsx("th",{style:{width:"100px"},children:t("filter.field.widget")}),s.jsx("th",{style:{width:"300px",paddingLeft:"24px"},children:t("common.action")})]})}),s.jsx("tbody",{children:r.content.filters.sortedList.map(d=>s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx(o.Checkbox,{value:d.id,styles:{input:{cursor:"pointer"}}})}),s.jsx("td",{children:d.label}),s.jsx("td",{children:d.key}),s.jsx("td",{children:t($t[d.type])}),s.jsx("td",{children:s.jsx(o.Button,{variant:"subtle",size:"xs",onClick:()=>i(d.id),children:t("common.actions.open")})})]},d.id))})]})})})]})}),_1=S.observer(()=>{const{t}=_.useTranslation(),e=U(),[n,r]=m.useState(()=>JSON.stringify(e.mock_context.current,null,4)),i=()=>{try{e.mock_context.replace(JSON.parse(n))}catch(l){bt.showNotification({title:"Failed",message:l.message,color:"red"})}},a=m.useMemo(()=>{try{return JSON.stringify(JSON.parse(n))!==JSON.stringify(e.mock_context.current)}catch{return!1}},[n,e.mock_context.current]);return s.jsxs(o.Stack,{sx:{border:"1px solid #eee",borderLeft:"none",borderRight:"none",flexGrow:1,maxWidth:"unset"},children:[s.jsx(o.Group,{position:"left",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:s.jsx(o.Text,{weight:500,children:t("mock_context.label")})}),s.jsxs(o.Group,{grow:!0,px:"md",pb:"md",pt:0,sx:{flexGrow:1,position:"relative",alignItems:"flex-start"},children:[s.jsxs(o.Stack,{spacing:10,sx:{maxWidth:"unset !important"},children:[s.jsx(o.Text,{children:t("mock_context.hint")}),s.jsx(o.JsonInput,{validationError:"Invalid json",formatOnBlur:!0,autosize:!0,minRows:30,value:n,onChange:r,sx:{flexGrow:1}})]}),s.jsx(o.ActionIcon,{mr:5,variant:"filled",color:"blue",sx:{position:"absolute",right:12,top:0},disabled:!a,onClick:i,children:s.jsx(B.DeviceFloppy,{size:20})})]})]})}),j1=S.observer(()=>{const{t}=_.useTranslation(),{panel:e}=$e();return s.jsx(jr,{label:t("panel.panel_description"),value:e.description,onChange:e.setDescription,styles:{root:{flexGrow:1}}})}),w1=S.observer(()=>{const{t}=_.useTranslation(),{panel:e}=$e(),n=de().layouts.findItemByPanelID(e.id),{style:r}=e;return s.jsxs(s.Fragment,{children:[s.jsx(o.Divider,{mb:-10,label:t("panel.style.label"),labelPosition:"center",variant:"dashed"}),s.jsxs(o.Stack,{spacing:20,children:[s.jsxs(o.Group,{grow:!0,align:"top",children:[s.jsx(o.NumberInput,{label:t("panel.style.width"),min:1,max:36,step:1,precision:0,rightSection:s.jsx(o.Text,{size:12,children:t("panel.style.width_postfix")}),styles:{rightSection:{width:"auto",maxWidth:"100px",paddingRight:"14px",justifyContent:"flex-end"}},value:n.w,onChange:i=>{i&&n.setWidth(i)}}),s.jsx(o.NumberInput,{label:t("panel.style.height"),rightSection:s.jsx(o.Text,{size:12,children:t("panel.style.height_postfix")}),styles:{rightSection:{width:"40px"}},value:n.h,onChange:i=>{i&&n.setHeight(i)}})]}),s.jsx(o.Checkbox,{ml:6,label:t("panel.style.border"),checked:r.border.enabled,onChange:i=>r.border.setEnabled(i.currentTarget.checked)})]})]})}),C1=()=>s.jsxs("span",{className:"mantine-103svbs mantine-InputWrapper-required mantine-Select-required","aria-hidden":"true",children:[" ","*"]}),S1=S.observer(()=>{const{t}=_.useTranslation(),{panel:e}=$e(),{name:n}=e,[r,i]=ie.useInputState(n),a=n!==r,l=m.useCallback(()=>{a&&e.setName(r)},[a,r]);m.useEffect(()=>{i(n)},[n]);const c=!r.trim();return s.jsxs(o.Stack,{spacing:4,children:[s.jsxs(o.Group,{align:"center",children:[s.jsxs(o.Text,{size:14,fw:500,children:[t("panel.panel_name"),s.jsx(C1,{})]}),s.jsx(o.ActionIcon,{variant:"subtle",color:"blue",disabled:!a||c,onClick:l,children:s.jsx(k.IconDeviceFloppy,{size:18})})]}),s.jsx(o.TextInput,{value:r,onChange:i,required:!0})]})}),k1=S.observer(()=>{const{t}=_.useTranslation(),{panel:e}=$e();return s.jsx(o.Stack,{spacing:6,mb:10,children:s.jsxs(o.Group,{pl:6,position:"left",spacing:20,children:[s.jsx(o.Checkbox,{size:"sm",checked:e.title.show,onChange:n=>e.title.setShow(n.currentTarget.checked),label:t("panel.show_title"),sx:{userSelect:"none"}}),s.jsx(o.Checkbox,{size:"sm",checked:!0,disabled:!0,label:t("panel.use_name_as_title")})]})})});function T1(){const{t}=_.useTranslation();return s.jsxs(o.Stack,{sx:{height:"100%"},children:[s.jsx(w1,{}),s.jsx(o.Divider,{label:t("common.info"),labelPosition:"center",variant:"dashed"}),s.jsx(S1,{}),s.jsx(k1,{}),s.jsx(j1,{})]})}const D1={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 Lc({data:t}){const e=m.useMemo(()=>{if(!Array.isArray(t)||t.length===0)return[];const r=Ue.createColumnHelper();return Object.keys(t[0]).map(i=>r.accessor(i,{cell:a=>a.getValue()}))},[t]),n=Ue.useReactTable({data:t,columns:e,columnResizeMode:"onChange",getCoreRowModel:Ue.getCoreRowModel()});return t.length===0?s.jsx(o.Box,{sx:{height:"5em"}}):s.jsx(we,{children:s.jsxs(o.Table,{sx:D1,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:Ue.flexRender(i.column.columnDef.header,i.getContext()),s.jsx(o.ActionIcon,{onMouseDown:i.getResizeHandler(),onTouchStart:i.getResizeHandler(),className:`resizer ${i.column.getIsResizing()?"isResizing":""}`,children:s.jsx(B.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:typeof i.getValue()=="object"?s.jsx("pre",{children:JSON.stringify(i.getValue(),null,2)}):Ue.flexRender(i.column.columnDef.cell,i.getContext())})},i.id))},r.id))})]})})}const z1=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],M1={icon:{width:"80px",textAlign:"center"},input:{"&[data-with-icon]":{paddingLeft:"80px"}}},I1=({data:t,page:e,setPage:n,limit:r,setLimit:i})=>{const{t:a}=_.useTranslation(),l=t.length,c=Math.ceil(l/r),u=p=>{n(1),i(Number(p))};if(l===0)return null;const d=c===1&&l<=10;return s.jsxs(o.Group,{pt:10,px:10,position:"apart",children:[s.jsxs(o.Group,{position:"left",children:[c>1&&s.jsx(o.Pagination,{size:"sm",value:e,onChange:n,total:c,withEdges:c>7,styles:{control:{height:"30px"}}}),!d&&s.jsx(o.Select,{icon:s.jsx(o.Text,{ta:"center",color:"dimmed",size:14,children:a("common.pagination.page_size")}),size:"xs",styles:M1,data:z1,value:String(r),onChange:u})]}),s.jsx(o.Group,{position:"right",children:s.jsx(o.Text,{color:"dimmed",my:0,size:14,children:a("common.pagination.total_rows",{total:l})})})]})},E1=Ad(({data:t,loading:e})=>{const[n,r]=m.useState(1),[i,a]=m.useState(20),l=m.useMemo(()=>{const c=(n-1)*i,u=c+i;return t.slice(c,u)},[t,n,i]);return s.jsxs(we,{children:[s.jsx(I1,{data:t,page:n,setPage:r,limit:i,setLimit:a}),s.jsxs(o.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[s.jsx(o.LoadingOverlay,{visible:e,overlayBlur:2}),s.jsx(Lc,{data:l})]})]})}),A1=({queryID:t})=>{const e=de(),{state:n,error:r}=e.getDataStuffByID(t),i=m.useMemo(()=>e.queries.findByID(t),[e,t]);return n==="loading"?null:r?s.jsx(o.Text,{mt:10,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:r}):i!=null&&i.stateMessage?s.jsx(o.Text,{mt:10,color:"gray",align:"center",children:i.stateMessage}):null},Si=S.observer(({id:t,moreActions:e,refreshOnMount:n})=>{const{t:r}=_.useTranslation(),i=de(),{data:a,state:l}=i.getDataStuffByID(t),c=l==="loading",u=m.useCallback(()=>{i.queries.refetchDataByQueryID(t)},[t,i]),d=()=>{i.queries.downloadDataByQueryID(t)};m.useEffect(()=>{n&&u()},[u,n]);const p=!Array.isArray(a)||a.length===0;return s.jsxs(o.Stack,{spacing:0,sx:{height:"100%",border:"1px solid #eee"},children:[s.jsxs(o.Group,{position:"apart",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[s.jsx(o.Group,{position:"left",children:s.jsx(o.Text,{weight:500,children:r("data.preview_data")})}),s.jsxs(o.Group,{pr:15,children:[e,s.jsx(o.ActionIcon,{variant:"subtle",color:"blue",disabled:c,onClick:u,children:s.jsx(B.Refresh,{size:16})}),s.jsx(o.ActionIcon,{variant:"subtle",color:"blue",disabled:c||p,onClick:d,children:s.jsx(B.Download,{size:16})})]})]}),s.jsxs(o.Box,{pb:20,sx:{position:"relative",flexGrow:1,overflow:"auto"},children:[s.jsx(A1,{queryID:t}),s.jsx(E1,{data:a,loading:c})]})]})}),P1=S.observer(function(){const{t:e}=_.useTranslation(),n=H(),r=U(),{panel:i}=$e(),[a,l]=m.useState(!1),c=d=>{n.editor.setPath(["_QUERIES_",d])},u=i.queryIDs.length;return s.jsxs(s.Fragment,{children:[s.jsx(o.Drawer,{opened:a,onClose:()=>l(!1),title:e("panel.settings.choose_queries"),padding:"xl",size:500,zIndex:320,children:s.jsx(o.Checkbox.Group,{value:[...i.queryIDs],onChange:i.setQueryIDs,children:s.jsx(o.Stack,{spacing:"lg",children:r.queries.options.map(d=>s.jsx(o.Checkbox,{label:d.label,value:d.value},d.value))})})}),s.jsxs(o.Stack,{spacing:6,children:[s.jsx(o.Group,{position:"left",children:s.jsx(o.Button,{variant:"light",size:"sm",leftIcon:s.jsx(k.IconLine,{size:16}),onClick:()=>l(!0),children:e(u===0?"panel.settings.need_to_choose_queries":"panel.settings.choose_queries")})}),u===1&&s.jsx(Si,{id:i.queryIDs[0],moreActions:s.jsx(o.Tooltip,{label:e("query.open"),children:s.jsx(o.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>c(i.queryIDs[0]),children:s.jsx(k.IconArrowCurveRight,{size:16})})})}),u>1&&s.jsxs(o.Tabs,{defaultValue:i.queryIDs[0],children:[s.jsx(o.Tabs.List,{children:i.queries.map(d=>s.jsx(o.Tabs.Tab,{value:d.id,children:d.name},d.id))}),i.queries.map(d=>s.jsx(o.Tabs.Panel,{value:d.id,children:s.jsx(Si,{id:d.id,moreActions:s.jsx(o.Tooltip,{label:e("query.open"),children:s.jsx(o.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>c(d.id),children:s.jsx(k.IconArrowCurveRight,{size:16})})})})},d.id))]})]})]})}),$1=S.observer(()=>{const{panel:t}=pt();return s.jsx(we,{children:s.jsx(o.Box,{sx:{height:"100%",flexGrow:0,flexShrink:0,width:"600px"},children:s.jsxs(o.Stack,{mt:24,spacing:5,sx:{width:"600px",height:"450px",background:"transparent",borderRadius:"5px",border:"1px solid #e9ecef",borderWidth:t.style.border.enabled?"1px":"0px"},children:[s.jsxs(o.Group,{position:"apart",noWrap:!0,sx:{flexGrow:0,flexShrink:0},children:[s.jsx(o.Group,{children:s.jsx(fi,{})}),s.jsx(o.Group,{grow:!0,position:"center",children:s.jsx(o.Text,{lineClamp:1,weight:"bold",children:t.title.show?t.name:""})}),s.jsx(o.Group,{position:"right",spacing:0,sx:{height:"28px"}})]}),s.jsx(o.Group,{px:5,pb:5,sx:{flexGrow:1,".panel-viz-section":{height:"calc(100% - 28px)"}},children:s.jsx(gi,{panel:t})})]})})})}),ki={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 B1{constructor(e){$(this,"panel");$(this,"selected");this.panel=e,e.variables.length>0&&(this.selected=e.variables[0]),K.makeAutoObservable(this,{},{deep:!1,autoBind:!0})}get variables(){return this.panel.variables}get variableOptions(){return this.panel.variables.map(e=>({label:e.name,value:e.name,description:e.aggregation.type}))}addNew(){const e=this.panel.variables.filter(n=>n.name.startsWith(ki.name)).length;this.panel.addVariable(x.cloneDeep({...ki,name:`${ki.name}${e||""}`})),this.selected=x.last(this.panel.variables)}select(e){this.selected=e}selectByName(e){if(!e){console.warn("Unexpected null name when calling selectByName");return}const n=this.variables.find(r=>r.name===e);if(!n){console.error(`Variable by name[${e}] not found`);return}this.selected=n}remove(e){this.selected===e&&(this.selected=void 0);const n=this.panel.variables.indexOf(e);if(this.panel.removeVariable(e),!this.selected&&!x.isEmpty(this.panel.variables)){const r=Math.min(this.panel.variables.length-1,n);this.selected=this.panel.variables[r]}}}function q1(){const{panel:t}=$e();return N.useCreation(()=>new B1(t),[t])}function L1({label:t,value:e,onChange:n},r){const[i,a]=m.useState(Array.isArray(e)?[...e]:[]),l=m.useCallback(()=>{a(g=>[...g,""])},[a]),c=m.useCallback(g=>{a(y=>(y.splice(g,1),[...y]))},[a]),u=m.useMemo(()=>!x.isEqual(i,e),[i,e]),d=()=>{n(i.map(g=>g.toString()))},p=o.useMantineTheme(),h=m.useMemo(()=>Object.entries(p.colors).map(([g,y])=>y[6]),[p]);return s.jsxs(s.Fragment,{children:[s.jsxs(o.Group,{position:"left",ref:r,children:[s.jsx(o.Text,{children:t}),s.jsx(o.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!u,onClick:d,children:s.jsx(B.DeviceFloppy,{size:20})})]}),s.jsxs(o.Group,{children:[i.map((g,y)=>s.jsx(o.ColorInput,{value:g,onChange:v=>{a(C=>(C.splice(y,1,v),[...C]))},swatches:h,rightSection:s.jsx(o.ActionIcon,{onClick:()=>c(y),color:"red",children:s.jsx(B.Trash,{size:14})}),sx:{width:"45%"}})),s.jsx(o.ActionIcon,{onClick:l,color:"blue",variant:"outline",children:s.jsx(B.PlaylistAdd,{size:20})})]})]})}const O1=m.forwardRef(L1);function V1({label:t,value:e,onChange:n,type:r},i){const[a,l]=m.useState(Array.isArray(e)?[...e]:[]),c=m.useCallback(()=>{l(h=>[...h,""])},[l]),u=m.useCallback(h=>{l(g=>(g.splice(h,1),[...g]))},[l]),d=m.useMemo(()=>!x.isEqual(a.map(String),e.map(String)),[a,e]),p=()=>{n(a.map(h=>r==="number"?Number(h):h.toString()))};return s.jsxs(s.Fragment,{children:[s.jsxs(o.Group,{position:"left",ref:i,children:[s.jsx(o.Text,{children:t}),s.jsx(o.ActionIcon,{mr:5,variant:"filled",color:"blue",disabled:!d,onClick:p,children:s.jsx(B.DeviceFloppy,{size:20})})]}),s.jsxs(o.Group,{children:[a.map((h,g)=>s.jsx(o.TextInput,{type:r,value:h,onChange:y=>{const v=y.currentTarget.value;l(C=>(C.splice(g,1,v),[...C]))},rightSection:s.jsx(o.ActionIcon,{onClick:()=>u(g),color:"red",children:s.jsx(B.Trash,{size:14})}),sx:{width:"45%"}})),s.jsx(o.ActionIcon,{onClick:c,color:"blue",variant:"outline",children:s.jsx(B.PlaylistAdd,{size:20})})]})]})}const N1=m.forwardRef(V1),G1=m.forwardRef(function({value:e,onChange:n},r){const{t:i}=_.useTranslation(),a=e.color.type,l=(u,d)=>{const p=x.cloneDeep(e);x.set(p,u,d),n(p)},c=u=>{if(u==="static"){n({...e,color:{type:"static",staticColor:"#25262B"}});return}n({...e,color:{type:"continuous",colorRange:[],valueRange:[]}})};return s.jsxs(s.Fragment,{children:[s.jsx(o.Stack,{children:s.jsx(o.TextInput,{label:i("style.font_size.label"),placeholder:i("styles.font_size.placeholder"),sx:{flex:1},value:e.size,onChange:u=>l("size",u.currentTarget.value)})}),s.jsx(o.Group,{position:"apart",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:s.jsx(sl,{label:i("style.font_weight.label"),value:e.weight,onChange:u=>l("weight",u)})}),s.jsx(o.Divider,{mt:"lg",mb:0,variant:"dashed",label:i("style.label"),labelPosition:"center"}),s.jsxs(o.Stack,{children:[s.jsx(o.Select,{label:"Color Type",data:[{label:"Static Color",value:"static"},{label:"Continuous Color",value:"continuous"}],value:e.color.type,onChange:c}),a==="static"&&s.jsx(Te,{value:e.color.staticColor,onChange:u=>l("color.staticColor",u)}),a==="continuous"&&s.jsxs(s.Fragment,{children:[s.jsx(N1,{label:"Value Range",value:e.color.valueRange,type:"number",onChange:u=>l("color.valueRange",u)}),s.jsx(O1,{label:"Color Range",value:e.color.colorRange,onChange:u=>l("color.colorRange",u)})]})]})]})}),F1=m.forwardRef(function({value:e,onChange:n,withStyle:r=!0,remove:i},a){const{t:l}=_.useTranslation(),c=(u,d)=>{const p=x.cloneDeep(e);x.set(p,u,d),n(p)};return s.jsxs(o.Stack,{ref:a,children:[s.jsxs(o.Stack,{spacing:"xs",px:"sm",py:"md",sx:{border:"1px solid #e9ecef"},children:[s.jsxs(o.Group,{grow:!0,noWrap:!0,children:[s.jsx(o.TextInput,{label:l("common.name"),required:!0,value:e.name,onChange:u=>c("name",u.currentTarget.value)}),s.jsx(L,{label:l("common.data_field"),required:!0,value:e.data_field,onChange:u=>c("data_field",u)})]}),s.jsx(fr,{label:l("panel.variable.aggregation.label"),pt:0,value:e.aggregation,onChange:u=>c("aggregation",u),withFallback:!0}),e.aggregation.type!=="custom"&&s.jsxs(s.Fragment,{children:[s.jsx(o.Divider,{mt:"xl",mb:0,label:l("numbro.format.label"),labelPosition:"center",variant:"dashed"}),s.jsx(We,{value:e.formatter,onChange:u=>c("formatter",u)})]})]}),r&&s.jsx(o.Accordion,{variant:"contained",children:s.jsxs(o.Accordion.Item,{value:"Styles",children:[s.jsx(o.Accordion.Control,{icon:s.jsx(o.Text,{size:"xl",children:"🖼️"}),children:l("style.label")}),s.jsx(o.Accordion.Panel,{children:s.jsx(G1,{value:e,onChange:n})})]})}),s.jsx(o.Button,{mt:20,leftIcon:s.jsx(k.IconTrash,{size:16}),color:"red",variant:"light",onClick:i,children:l("panel.variable.delete")})]})}),W1=S.observer(t=>{const{t:e}=_.useTranslation(),n=N.useCreation(()=>Hl(t.variable),[t.variable]),r=()=>t.uiModel.remove(t.variable);return s.jsxs(o.Stack,{"data-testid":"variable-editor",align:"stretch",children:[s.jsxs(o.Group,{position:"apart",children:[s.jsx(o.Button,{variant:"subtle",size:"xs",disabled:!n.changed,color:"red",onClick:n.reset,leftIcon:s.jsx(k.IconRecycle,{size:18}),children:e("common.actions.revert_changes")}),s.jsx(o.Button,{variant:"filled",size:"xs",disabled:!n.changed,color:"green",onClick:n.commit,leftIcon:s.jsx(k.IconDeviceFloppy,{size:18}),children:e("common.actions.save_changes")})]}),s.jsx(F1,{value:f.getSnapshot(n.copy),onChange:n.update,remove:r})]})});S.observer(t=>{const{uiModel:e}=t;return s.jsx(o.Stack,{className:"var-list",children:e.variables.map(n=>s.jsx(o.Button,{variant:e.selected===n?"filled":"subtle",color:"gray",onClick:()=>e.select(n),children:n.name},n.name))})});const Q1=S.observer(({model:t})=>{const{t:e}=_.useTranslation();return s.jsx(o.Overlay,{color:"#fff",opacity:1,sx:{position:"absolute"},children:s.jsx(o.Button,{variant:"light",size:"xs",leftIcon:s.jsx(k.IconPlus,{size:16}),onClick:t.addNew,sx:{flexGrow:0,flexShrink:0,alignSelf:"flex-end",height:"38px"},children:e("panel.variable.add")})})}),R1=S.observer(()=>{var n;const{t}=_.useTranslation(),e=q1();return e.variableOptions.length===0?s.jsx(Q1,{model:e}):s.jsxs(o.Stack,{pb:20,children:[s.jsxs(o.Group,{position:"left",children:[s.jsx(o.Select,{label:t("panel.variable.labels"),data:e.variableOptions,value:(n=e.selected)==null?void 0:n.name,onChange:e.selectByName,maxDropdownHeight:600,sx:{flexGrow:1}}),s.jsx(o.Button,{variant:"light",size:"xs",leftIcon:s.jsx(k.IconPlus,{size:16}),onClick:e.addNew,sx:{flexGrow:0,flexShrink:0,alignSelf:"flex-end",height:"38px"},children:t("panel.variable.add")})]}),s.jsx(o.Divider,{variant:"dashed"}),e.selected?s.jsx(W1,{uiModel:e,variable:e.selected}):s.jsx("span",{children:"Select or create a new variable on right side"})]})}),U1=S.observer(()=>{const{t}=_.useTranslation(),{panel:e}=$e();return Object.keys(e.variableStrings).length===0?null:s.jsxs(o.Stack,{mt:22,spacing:4,children:[s.jsx(o.Text,{size:"sm",fw:500,color:"dimmed",children:t("panel.variable.labels")}),s.jsx(vt.Prism,{language:"json",colorScheme:"dark",noCopy:!0,children:JSON.stringify(e.variableStrings,null,4)})]})});function Y1(){const{t}=_.useTranslation(),{vizManager:e}=m.useContext(it);return m.useMemo(()=>{const n=e.availableVizList.map(r=>({value:r.name,label:t(r.displayName??r.name),group:t(r.displayGroup??"")}));return x.orderBy(n,[r=>r.group,r=>r.label],["asc","asc"])},[e])}const K1=S.observer(({value:t,submit:e})=>{const{t:n}=_.useTranslation(),[r,i]=ie.useInputState(t);m.useEffect(()=>{i(t)},[t]);const a=Y1(),l=t!==r;return s.jsx(o.Select,{label:n("visualization.component"),value:r,searchable:!0,onChange:i,data:a,rightSection:s.jsx(o.ActionIcon,{variant:"filled",color:"green",disabled:!l,onClick:()=>e(r),children:s.jsx(B.DeviceFloppy,{size:20})}),maxDropdownHeight:600})}),Oc=[];function J1(t,e){try{return t.resolveComponent(e).createConfig()}catch{return null}}function X1(){const{data:t,panel:{variables:e,viz:n,title:r,name:i,queryIDs:a,description:l,id:c}}=$e(),{vizManager:u}=m.useContext(it),d={name:i,title:r,description:l,viz:n,queryIDs:a,id:c},p=tc(d);try{return u.resolveComponent(d.viz.type),s.jsx(as,{configure:p,children:s.jsx(wS,{variables:e,setVizConf:n.setConf,panel:d,vizManager:u,data:t})})}catch(h){return console.info(x.get(h,"message")),null}}const Z1=S.observer(()=>{const{data:t,panel:{viz:e}}=$e(),{vizManager:n}=m.useContext(it),r=m.useCallback(d=>{if(d===e.type)return;const p=J1(n,d);e.setType(d),e.setConf(p||{})},[e.type]),i=d=>{try{e.setConf(JSON.parse(d))}catch(p){console.error(p)}},a=m.useMemo(()=>{var d;return(d=Oc.find(p=>p.value===e.type))==null?void 0:d.Panel},[e.type,Oc]),l=X1(),c=a?m.createElement(a,{data:t,conf:e.conf,setConf:e.setConf}):null,u=l||c;return s.jsxs(o.Stack,{align:"stretch",sx:{height:"100%",overflow:"hidden"},children:[s.jsx(K1,{submit:r,value:e.type}),s.jsxs(we,{children:[s.jsx(o.Stack,{pb:10,sx:{flexGrow:1,maxHeight:"100%",overflow:"auto"},children:u}),!u&&s.jsx(o.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(e.conf,null,2),onChange:i})]})]})}),H1=S.observer(({panel:t,sourceViewID:e})=>{const{t:n}=_.useTranslation(),r=U(),[i,a]=m.useState(e);m.useEffect(()=>{a(e)},[e]);const[l,{open:c,close:u}]=ie.useDisclosure(!1),d=()=>{t.moveToView(e,i),u()};return s.jsxs(s.Fragment,{children:[s.jsx(o.Button,{size:"xs",variant:"subtle",color:"blue",onClick:c,leftIcon:s.jsx(k.IconBoxMultiple,{size:14}),children:n("panel.settings.change_view")}),s.jsx(o.Modal,{opened:l,onClose:u,title:n("panel.settings.change_view_title"),zIndex:320,children:s.jsxs(o.Stack,{sx:{maxHeight:"calc(100vh - 185px)",overflow:"hidden"},children:[s.jsx(o.Radio.Group,{value:i,onChange:a,pb:10,sx:{flexGrow:1,maxHeight:"calc(100vh - 185px - 30px)",overflow:"auto"},children:s.jsx(o.Stack,{spacing:"xs",children:r.views.options.map(p=>s.jsx(o.Radio,{value:p.value,label:p.label},p.value))})}),s.jsxs(o.Group,{noWrap:!0,position:"apart",sx:{flexGrow:0,flexShrink:0},children:[s.jsx(o.Button,{size:"xs",color:"red",leftIcon:s.jsx(k.IconX,{size:14}),onClick:u,children:n("common.actions.cancel")}),s.jsx(o.Button,{size:"xs",color:"blue",leftIcon:s.jsx(k.IconDeviceFloppy,{size:14}),onClick:d,disabled:i===e,children:n("common.actions.confirm")})]})]})})]})}),eT={root:{flexGrow:1,width:"100%",minWidth:"1200px",overflow:"hidden"},panel:{width:"100%",minWidth:"1200px",height:"calc(100% - 44px)",padding:10,overflow:"auto"}},Ti=({children:t})=>s.jsxs(o.Group,{noWrap:!0,grow:!0,position:"left",spacing:20,sx:{width:"100%",height:"100%",position:"relative"},children:[s.jsx(o.Box,{sx:{maxWidth:"calc(100% - 610px - 10px)",height:"100%",overflow:"auto"},children:t}),s.jsxs(o.Stack,{justify:"flex-start",sx:{alignSelf:"flex-start",width:"600px",flexGrow:0,flexShrink:0},children:[s.jsx($1,{}),s.jsx(o.Box,{sx:{flexGrow:1},children:s.jsx(U1,{})})]})]});function tT(t){return!["richText","button"].includes(t)}const nT=S.observer(({panel:t})=>{const{t:e}=_.useTranslation(),n=Le.useModals(),r=H(),i=U(),[a,l]=m.useState("Data"),c=t.queries,d=tT(t.viz.type)&&t.dataLoading,p=d||t.queryErrors.length>0||t.queryStateMessages!==""||c.length===0,h=r.editor.path[1];m.useEffect(()=>{l(v=>p&&v==="Visualization"?"Data":v)},[t.id,p]);const g=()=>{r.editor.setPath(["_VIEWS_",h])},y=()=>n.openConfirmModal({title:`${e("panel.delete")}?`,labels:{confirm:e("common.actions.confirm"),cancel:e("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.removePanelByID(t.id,h),g()},confirmProps:{color:"red"},zIndex:320});return s.jsxs(Bs,{value:{panel:t,data:t.data,loading:d,errors:t.queryErrors,downloadPanelScreenshot:()=>{}},children:[s.jsxs(o.Group,{px:16,position:"apart",sx:{borderBottom:"1px solid #eee"},children:[s.jsx(o.Text,{pt:9,pb:8,children:t.name}),s.jsxs(o.Group,{position:"right",noWrap:!0,children:[s.jsx(H1,{panel:t,sourceViewID:h}),s.jsx(o.Button,{size:"xs",variant:"subtle",color:"red",onClick:y,leftIcon:s.jsx(k.IconTrash,{size:14}),children:e("panel.delete")})]})]}),s.jsxs(o.Tabs,{value:a,onTabChange:l,keepMounted:!1,styles:eT,children:[s.jsxs(o.Tabs.List,{children:[s.jsx(o.Tabs.Tab,{value:"Data",disabled:d,children:e("data.label")}),s.jsx(o.Tabs.Tab,{value:"Panel",children:e("panel.label")}),s.jsx(o.Tabs.Tab,{value:"Variables",disabled:p,children:s.jsx(o.Tooltip,{label:e("data.requires_data"),disabled:!p,withinPortal:!0,zIndex:310,children:s.jsx(o.Text,{children:e("panel.variable.labels")})})}),s.jsx(o.Tabs.Tab,{value:"Visualization",disabled:p,children:s.jsx(o.Tooltip,{label:e("data.requires_data"),disabled:!p,withinPortal:!0,zIndex:310,children:s.jsx(o.Text,{children:e("visualization.label")})})}),s.jsx(o.Tabs.Tab,{value:"Interactions",children:e("interactions.label")})]}),s.jsxs(o.Tabs.Panel,{value:"Data",children:[s.jsx(o.LoadingOverlay,{visible:d,exitTransitionDuration:0}),s.jsx(P1,{})]}),s.jsx(o.Tabs.Panel,{value:"Panel",children:s.jsx(Ti,{children:s.jsx(T1,{})})}),s.jsx(o.Tabs.Panel,{value:"Variables",children:s.jsx(Ti,{children:s.jsx(R1,{})})}),s.jsx(o.Tabs.Panel,{value:"Visualization",children:s.jsx(we,{children:s.jsx(Ti,{children:s.jsx(Z1,{})})})}),s.jsx(o.Tabs.Panel,{value:"Interactions",children:s.jsx(we,{children:s.jsx(nh,{})})})]})]})}),sT=S.observer(({viewID:t,panelID:e})=>{const n=U();if(!n.views.findByID(t))return s.jsxs(o.Text,{size:14,children:["View by ID[",t,"] is not found"]});const i=n.panels.findByID(e);return i?s.jsx(nT,{panel:i}):s.jsxs(o.Text,{size:14,children:["Panel by ID[",e,"] is not found"]})}),rT=S.observer(()=>{const{t}=_.useTranslation(),[e,n]=m.useState([]),r=Le.useModals(),i=H(),a=g=>{i.editor.setPath(["_QUERIES_",g])},l=()=>{r.openConfirmModal({title:"Delete ununsed queries?",children:s.jsx(o.Text,{size:"sm",children:"This action cannot be undone."}),labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>i.content.removeUnusedQueries(),confirmProps:{color:"red"},zIndex:320})},c=()=>{i.content.queries.downloadSchema(e)},u=m.useMemo(()=>i.content.queries.sortedList.map(g=>g.id),[i.content.queries.sortedList]),d=()=>{n(u)},p=()=>{n([])},h=i.content.queriesUsage;return s.jsxs(o.Stack,{sx:{height:"100%"},spacing:"sm",pb:"59px",children:[s.jsx(o.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:s.jsx(o.Text,{px:"md",align:"left",sx:{userSelect:"none",cursor:"default"},children:t("query.manage")})}),s.jsxs(o.Flex,{justify:"space-between",align:"center",px:12,children:[s.jsxs(o.Group,{position:"left",children:[s.jsxs(o.Button.Group,{children:[s.jsx(o.Button,{variant:"default",size:"xs",onClick:d,children:t("common.actions.select_all")}),s.jsx(o.Button,{variant:"default",size:"xs",onClick:p,children:t("common.actions.clear_selection")})]}),s.jsx(o.Button,{size:"xs",color:"blue",leftIcon:s.jsx(k.IconCode,{size:14}),disabled:e.length===0,onClick:c,children:t("common.actions.download_schema")})]}),s.jsx(o.Button,{variant:"subtle",size:"xs",color:"red",leftIcon:s.jsx(k.IconTrash,{size:14}),disabled:!i.content.hasUnusedQueries,onClick:l,children:t("query.delete_unused")})]}),s.jsx(o.Box,{sx:{flexGrow:1,overflow:"auto"},children:s.jsx(o.Checkbox.Group,{size:"xs",value:e,onChange:n,children:s.jsxs(o.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:t("common.name")}),s.jsx("th",{style:{width:"200px"},children:t("data_source.label")}),s.jsx("th",{style:{width:"100px",textAlign:"right"},children:t("common.type")}),s.jsx("th",{style:{width:"100px",textAlign:"center"},children:t("query.usage.label")}),s.jsx("th",{style:{width:"300px",paddingLeft:"24px"},children:t("common.action")})]})}),s.jsx("tbody",{children:i.content.queries.sortedList.map(g=>{var v;const y=((v=h[g.id])==null?void 0:v.length)??0;return s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx(o.Checkbox,{value:g.id,styles:{input:{cursor:"pointer"}}})}),s.jsx("td",{children:g.name}),s.jsx("td",{children:g.key}),s.jsx("td",{style:{textAlign:"right"},children:g.type}),s.jsx("td",{style:{color:y===0?"#ff0000":"#000",fontWeight:y===0?"bold":"normal",textAlign:"center"},children:y}),s.jsx("td",{children:s.jsx(o.Button,{variant:"subtle",size:"xs",onClick:()=>a(g.id),children:t("common.actions.open")})})]},g.id)})})]})})})]})}),iT=t=>{const{t:e}=_.useTranslation(),{queryModel:n}=t,r=H(),i=U(),l=i.findQueryUsage(n.id).length>0,c=Le.useModals(),u=()=>{c.openConfirmModal({title:`${e("query.delete")}?`,labels:{confirm:e("common.actions.confirm"),cancel:e("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.queries.removeQuery(n.id),r.editor.setPath(["_QUERIES_",""])},confirmProps:{color:"red"},zIndex:320})};return l?s.jsx(o.Tooltip,{label:e("query.cant_delete"),withArrow:!0,events:{hover:!0,focus:!1,touch:!1},withinPortal:!0,zIndex:320,position:"top-end",children:s.jsx(o.Box,{sx:{alignSelf:"flex-end"},children:s.jsx(o.Button,{disabled:!0,size:"xs",leftIcon:s.jsx(k.IconTrash,{size:16}),children:e("query.delete")})})}):s.jsx(o.Button,{color:"red",size:"xs",onClick:u,leftIcon:s.jsx(k.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:e("query.delete")})},aT=S.observer(iT),Vc=({width:t="calc(100% - 32px)",lastWidth:e="50%",height:n,count:r,spacing:i=16,pl:a=0})=>s.jsxs(o.Stack,{spacing:i,mt:6,pl:a,children:[Array.from(new Array(r-1),(l,c)=>s.jsx(o.Skeleton,{width:t,height:n,radius:"xs"},c)),s.jsx(o.Skeleton,{width:e,height:n,radius:"xs"})]}),yn=({value:t})=>t===null||t===""?null:s.jsx(o.Tooltip,{label:t,disabled:!t,multiline:!0,children:s.jsx(o.ActionIcon,{children:s.jsx(k.IconInfoCircle,{size:14})})}),oT=({column:t})=>{const{column_key:e,column_key_text:n}=t;return e?s.jsx(o.Tooltip,{label:n,disabled:!n,children:s.jsx(o.Badge,{children:e})}):null},lT=S.observer(({dataSource:t})=>{const{columns:e}=t;return e.loading?s.jsx(Vc,{height:"24px",width:"100%",lastWidth:"100%",count:20,pl:6}):e.empty?null:s.jsxs(o.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:e.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(yn,{value:n.column_comment})}),s.jsx("td",{children:s.jsx(oT,{column:n})}),s.jsx("td",{children:n.column_type}),s.jsx("td",{children:n.is_nullable}),s.jsx("td",{children:s.jsx(yn,{value:n.column_default})})]},n.column_name))})]})}),cT=S.observer(({dataSource:t})=>{const{indexes:e}=t,n=e.data;return s.jsxs(o.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))})]})}),uT=S.observer(({dataSource:t})=>{const{indexes:e}=t,n=e.data;return s.jsxs(o.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(yn,{value:r.index_definition})}),s.jsx("td",{children:s.jsx(yn,{value:r.condition})}),s.jsx("td",{children:s.jsx(yn,{value:r.comment})})]},r.index_name))})]})}),dT=S.observer(({dataSource:t})=>{const{indexes:e}=t;return e.loading||e.empty?null:t.type===ce.MySQL?s.jsx(cT,{dataSource:t}):t.type===ce.Postgresql?s.jsx(uT,{dataSource:t}):null}),pT=S.observer(({dataSource:t})=>s.jsxs(o.Stack,{spacing:40,pt:10,sx:{flexGrow:1,overflow:"auto",position:"relative"},children:[s.jsx(we,{children:s.jsx(lT,{dataSource:t})}),s.jsx(we,{children:s.jsx(dT,{dataSource:t})})]}));function hT({table_type:t}){return t==="VIEW"?s.jsx(k.IconEye,{size:14}):t==="BASE TABLE"?s.jsx(k.IconTable,{size:14}):null}const mT=S.observer(({dataSource:t})=>{const{tables:e}=t;return e.loading?s.jsx(Vc,{height:"24px",lastWidth:"50%",count:15}):s.jsx(o.Box,{h:"100%",sx:{overflow:"auto",".mantine-NavLink-label":{fontFamily:"monospace"}},children:Object.entries(e.data).map(([n,r])=>s.jsx(o.NavLink,{label:n,icon:s.jsx(k.IconDatabase,{size:14}),defaultOpened:t.table_schema===n,pl:0,childrenOffset:14,children:r.map(i=>s.jsx(o.NavLink,{label:i.table_name,icon:s.jsx(hT,{table_type:i.table_type}),onClick:()=>{t.setKeywords(n,i.table_name)},active:t.table_name===i.table_name},i.table_name))},n))})}),fT=({visible:t})=>s.jsx(o.Box,{py:10,sx:{width:"100%",height:"100%",overflow:"hidden",position:"relative"},children:s.jsx(o.LoadingOverlay,{visible:t})}),gT=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],xT={icon:{width:"50px",textAlign:"center"},input:{"&[data-with-icon]":{paddingLeft:"50px"}}},yT=S.observer(({dataSource:t})=>{const{t:e}=_.useTranslation(),{tableData:n}=t;return s.jsxs(o.Group,{pt:10,px:10,position:"apart",children:[s.jsxs(o.Group,{position:"left",children:[n.maxPage>1&&s.jsx(o.Pagination,{size:"sm",value:n.page,onChange:n.setPage,total:n.maxPage,withEdges:n.maxPage>7,styles:{control:{height:"30px"}}}),s.jsx(o.Select,{icon:s.jsx(o.Text,{ta:"center",color:"dimmed",size:14,children:e("common.pagination.page_size")}),size:"xs",styles:xT,data:gT,value:String(n.limit),onChange:r=>n.setLimit(Number(r))})]}),s.jsx(o.Group,{position:"right",children:s.jsx(o.Text,{color:"dimmed",my:0,size:14,children:e("common.pagination.total_rows",{total:n.total})})})]})}),bT=S.observer(({dataSource:t})=>{const e=t.tableData;return e.maxPage===0?s.jsx(o.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:"This table is empty"}):e.error?s.jsx(o.Text,{mt:20,color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:e.error}):e.page===1&&e.loading?s.jsx(fT,{visible:!0}):s.jsxs(we,{children:[s.jsx(yT,{dataSource:t}),s.jsxs(o.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[s.jsx(o.LoadingOverlay,{visible:e.loading,overlayBlur:2}),s.jsx(Lc,{data:e.data})]})]})}),vT={root:{flexGrow:1,overflow:"auto",borderLeft:"1px solid #efefef"},tabsList:{borderBottom:"1px solid #efefef"},tab:{minWidth:120}},_T=S.observer(({dataSource:t})=>{const{t:e}=_.useTranslation();return m.useEffect(()=>{t.loadTablesIfEmpty()},[t]),t.tables.error?s.jsx(o.Text,{color:"red",size:"md",align:"center",sx:{fontFamily:"monospace"},children:t.tables.error}):s.jsxs(o.Flex,{sx:{height:"100%"},children:[s.jsx(o.Box,{w:300,sx:{flexGrow:0,flexShrink:0,position:"relative"},children:s.jsx(we,{children:s.jsx(mT,{dataSource:t})})}),s.jsxs(o.Tabs,{defaultValue:"structure",styles:vT,children:[s.jsxs(o.Tabs.List,{children:[s.jsx(o.Tabs.Tab,{value:"structure",icon:s.jsx(k.IconColumns,{size:14}),children:e("data_source.table_structure_short")}),s.jsx(o.Tabs.Tab,{value:"data",icon:s.jsx(k.IconDatabase,{size:14}),children:e("data.label")})]}),s.jsx(o.Tabs.Panel,{value:"structure",children:s.jsx(pT,{dataSource:t})}),s.jsx(o.Tabs.Panel,{value:"data",sx:{width:"100%",height:"calc(100% - 36px)",overflow:"hidden"},children:s.jsx(bT,{dataSource:t})})]})]})}),jT={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"}},Nc=S.observer(({dataSource:t,triggerButtonProps:e={}})=>{const{t:n}=_.useTranslation(),[r,i]=m.useState(!1);return t.type==="http"?null:s.jsxs(s.Fragment,{children:[s.jsx(o.Modal,{opened:r,onClose:()=>i(!1),title:s.jsxs(o.Group,{position:"apart",sx:{flexGrow:1},children:[s.jsx(o.Text,{fw:500,children:n("data_source.explorer")}),s.jsxs(o.Group,{spacing:7,children:[s.jsx(o.Badge,{variant:"gradient",gradient:{from:"indigo",to:"cyan"},children:t.key}),s.jsx(o.Badge,{variant:"gradient",gradient:{from:"orange",to:"red"},children:t.type})]})]}),zIndex:320,size:"96vw",styles:jT,children:s.jsx(o.Box,{sx:{height:"calc(100vh - 220px)"},children:s.jsx(_T,{dataSource:t})})}),s.jsx(o.Button,{variant:"subtle",onClick:()=>i(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},...e,children:n("data_source.see_table_structure")})]})}),wT=m.forwardRef(({label:t,type:e,...n},r)=>e===ce.Transform?s.jsxs(o.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(k.IconVectorTriangle,{size:14,color:"#228be6"}),s.jsx(o.Text,{color:"blue",children:t})]}):s.jsxs(o.Group,{position:"apart",ref:r,...n,children:[s.jsx(o.Text,{children:t}),s.jsx(o.Text,{children:e})]})),CT=S.observer(({value:t,onChange:e})=>{const{t:n}=_.useTranslation(),r=H(),{data:i=[],loading:a}=N.useRequest(zs,{refreshDeps:[]},[]),l=m.useMemo(()=>{const p=i.map(h=>({label:h.key,value:h.key,type:h.type}));return p.push({label:n("query.transform.data_source"),value:ce.Transform,type:ce.Transform}),p},[i]),c=m.useMemo(()=>l.reduce((p,h)=>(p[h.value]=h.type,p),{}),[l]),u=p=>{p!==null&&e({key:p,type:c[p]})},d=m.useMemo(()=>r.datasources.find(t),[r,t]);return s.jsx(o.Select,{data:l,label:s.jsxs(o.Group,{position:"apart",children:[s.jsx(o.Box,{children:n("data_source.label")}),d&&s.jsx(Nc,{dataSource:d,triggerButtonProps:{compact:!0,size:"xs",px:10}})]}),itemComponent:wT,rightSection:d?s.jsx(o.Text,{size:"xs",color:"dimmed",children:d.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:a,value:t.key,onChange:u})}),Gc=m.forwardRef((t,e)=>{const{label:n,description:r,...i}=t;return s.jsx("div",{ref:e,...i,children:s.jsxs(o.Group,{position:"apart",noWrap:!0,children:[s.jsx(o.Text,{children:n}),s.jsx(o.Text,{size:"xs",color:"dimmed",children:r})]})})}),ST=S.observer(({queryModel:t})=>{const{t:e}=_.useTranslation(),[n,r]=m.useState(t.name);return m.useEffect(()=>{r(t.name)},[t.name]),s.jsx(o.Center,{ml:20,mt:20,sx:{maxWidth:"600px"},children:s.jsxs(o.Stack,{spacing:10,sx:{width:"100%"},children:[s.jsx(o.Divider,{mb:-10,variant:"dashed",label:e("query.basics"),labelPosition:"center"}),s.jsx(o.TextInput,{placeholder:e("query.name_description"),label:e("query.name"),required:!0,sx:{flex:1},value:n,onChange:i=>{r(i.currentTarget.value)},rightSection:s.jsx(o.ActionIcon,{variant:"filled",color:"blue",size:"sm",onClick:()=>t.setName(n),disabled:n===t.name,children:s.jsx(k.IconDeviceFloppy,{size:16})}),onBlur:()=>{t.setName(n)}}),s.jsx(CT,{value:{type:t.type,key:t.key},onChange:({type:i,key:a})=>{t.setKey(a),t.setType(i)}}),s.jsx(o.Divider,{mt:10,mb:-10,variant:"dashed",label:e("query.conditions"),labelPosition:"center"}),s.jsx(o.MultiSelect,{label:e("query.run_by_condition.label"),placeholder:e("query.run_by_condition.unset"),data:t.conditionOptions,value:[...t.run_by],onChange:t.setRunBy,itemComponent:Gc,maxDropdownHeight:500}),t.typedAsHTTP&&s.jsx(o.MultiSelect,{label:e("query.re_run_condition.label"),placeholder:e("query.re_run_condition.label"),data:t.conditionOptions,value:[...t.react_to],onChange:t.setReactTo,itemComponent:Gc,maxDropdownHeight:500}),s.jsx(o.Divider,{mt:20,mb:10,variant:"dashed"}),s.jsx(aT,{queryModel:t})]})})});function kT({content:t}){return s.jsxs(o.HoverCard,{width:"60vw",shadow:"md",children:[s.jsx(o.HoverCard.Target,{children:s.jsx(o.ActionIcon,{size:16,color:"blue",children:s.jsx(k.IconEye,{})})}),s.jsx(o.HoverCard.Dropdown,{children:s.jsx(vt.Prism,{language:"sql",noCopy:!0,withLineNumbers:!0,children:t})})]})}const TT=S.observer(()=>{const e=[...H().globalSQLSnippets.list];return e.length===0?null:s.jsxs(o.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:e.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(kT,{content:i})})]},r)})})]})}),DT=`
465
465
  -- You may reference query variables in SQL or VizConfig.
466
466
  SELECT *
467
467
  FROM commit
@@ -474,9 +474,9 @@ WHERE
474
474
  AND \${sql_snippets.author_email_condition}
475
475
  -- Global SQL snippets (shared between dashboards)
476
476
  AND \${global_sql_snippets.account_condition}
477
- `,Fc=S.observer(function({showSQLSnippets:e=!0,sx:n={}}){const{t:r}=_.useTranslation(),i=H(),a=U(),l=i.context.current,c=(()=>{const u={context:{...a.mock_context.current,...l},filters:a.filters.previewValues};return e&&(u.sql_snippets=a.sqlSnippets.record),JSON.stringify(u,null,2)})();return s.jsx(o.Stack,{sx:{overflow:"hidden",...n},children:s.jsxs(o.Tabs,{defaultValue:"guide",keepMounted:!1,children:[s.jsxs(o.Tabs.List,{grow:!0,children:[s.jsx(o.Tabs.Tab,{value:"guide",icon:s.jsx(k.IconAlertCircle,{size:14}),children:r("query_variable.guide.tabs.guide")}),s.jsx(o.Tabs.Tab,{value:"local_query_vars",icon:s.jsx(k.IconVariable,{size:14}),children:r("query_variable.guide.tabs.variables_in_this_dashboard")}),s.jsx(o.Tabs.Tab,{value:"global_sql_snippets",icon:s.jsx(k.IconVariablePlus,{size:14}),children:r("query_variable.guide.tabs.global_sql_snippets")})]}),s.jsx(o.Tabs.Panel,{value:"guide",pt:"xs",children:s.jsx(vt.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:D1})}),s.jsx(o.Tabs.Panel,{value:"local_query_vars",pt:"xs",children:s.jsx(vt.Prism,{language:"json",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:c})}),s.jsx(o.Tabs.Panel,{value:"global_sql_snippets",pt:"xs",children:s.jsxs(o.Stack,{spacing:10,children:[s.jsx(o.Alert,{icon:s.jsx(k.IconAlertCircle,{size:16}),title:r("global_sql_snippet.labels"),children:r("global_sql_snippet.description")}),s.jsx(T1,{})]})})]})})}),Di=S.observer(()=>{const{t}=_.useTranslation(),[e,n]=m.useState(!1);return s.jsxs(s.Fragment,{children:[s.jsx(o.Modal,{opened:e,onClose:()=>n(!1),title:t("query_variable.labels"),zIndex:320,size:"800px",children:s.jsx(Fc,{})}),s.jsx(o.Button,{variant:"subtle",onClick:()=>n(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},children:t("query_variable.open")})]})}),Wc={pre:["function build_request({ context, filters }, utils) {"," // build the quest"," return { method: 'POST', url: '/', params: {}, headers: {}, data: {} }","}"].join(`
477
+ `,Fc=S.observer(function({showSQLSnippets:e=!0,sx:n={}}){const{t:r}=_.useTranslation(),i=H(),a=U(),l=i.context.current,c=(()=>{const u={context:{...a.mock_context.current,...l},filters:a.filters.previewValues};return e&&(u.sql_snippets=a.sqlSnippets.record),JSON.stringify(u,null,2)})();return s.jsx(o.Stack,{sx:{overflow:"hidden",...n},children:s.jsxs(o.Tabs,{defaultValue:"guide",keepMounted:!1,children:[s.jsxs(o.Tabs.List,{grow:!0,children:[s.jsx(o.Tabs.Tab,{value:"guide",icon:s.jsx(k.IconAlertCircle,{size:14}),children:r("query_variable.guide.tabs.guide")}),s.jsx(o.Tabs.Tab,{value:"local_query_vars",icon:s.jsx(k.IconVariable,{size:14}),children:r("query_variable.guide.tabs.variables_in_this_dashboard")}),s.jsx(o.Tabs.Tab,{value:"global_sql_snippets",icon:s.jsx(k.IconVariablePlus,{size:14}),children:r("query_variable.guide.tabs.global_sql_snippets")})]}),s.jsx(o.Tabs.Panel,{value:"guide",pt:"xs",children:s.jsx(vt.Prism,{language:"sql",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:DT})}),s.jsx(o.Tabs.Panel,{value:"local_query_vars",pt:"xs",children:s.jsx(vt.Prism,{language:"json",sx:{width:"100%"},noCopy:!0,colorScheme:"dark",children:c})}),s.jsx(o.Tabs.Panel,{value:"global_sql_snippets",pt:"xs",children:s.jsxs(o.Stack,{spacing:10,children:[s.jsx(o.Alert,{icon:s.jsx(k.IconAlertCircle,{size:16}),title:r("global_sql_snippet.labels"),children:r("global_sql_snippet.description")}),s.jsx(TT,{})]})})]})})}),Di=S.observer(()=>{const{t}=_.useTranslation(),[e,n]=m.useState(!1);return s.jsxs(s.Fragment,{children:[s.jsx(o.Modal,{opened:e,onClose:()=>n(!1),title:t("query_variable.labels"),zIndex:320,size:"800px",children:s.jsx(Fc,{})}),s.jsx(o.Button,{variant:"subtle",onClick:()=>n(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},children:t("query_variable.open")})]})}),Wc={pre:["function build_request({ context, filters }, utils) {"," // build the quest"," return { method: 'POST', url: '/', params: {}, headers: {}, data: {} }","}"].join(`
478
478
  `),post:["function process_result(res, utils, state) {"," // your code goes here"," return data","}"].join(`
479
- `)},z1=S.observer(({queryModel:t})=>{const{t:e}=_.useTranslation();return t.typedAsHTTP?s.jsxs(o.Tabs,{defaultValue:"pre_process",orientation:"vertical",sx:{flexGrow:1},children:[s.jsxs(o.Tabs.List,{children:[s.jsx(o.Tabs.Tab,{value:"pre_process",children:e("query.build_request")}),s.jsx(o.Tabs.Tab,{value:"post_process",children:e("query.process_result")}),s.jsx(Di,{})]}),s.jsx(o.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:s.jsx(Qt,{label:"",value:t.pre_process,onChange:t.setPreProcess,defaultValue:Wc.pre})}),s.jsx(o.Tabs.Panel,{value:"post_process",p:"sm",children:s.jsx(Qt,{label:"",value:t.post_process,onChange:t.setPostProcess,defaultValue:Wc.post})})]}):null}),M1=S.observer(({queryID:t,usage:e})=>{const{t:n}=_.useTranslation(),r=H().editor,i=l=>{if(l.type==="filter"){r.setPath(["_FILTERS_",l.id]);return}if(l.type==="panel"){const c=l.views[0].id;r.setPath(["_VIEWS_",c,"_PANELS_",l.id]);return}},a=l=>{r.setPath(["_VIEWS_",l])};return s.jsx(o.Stack,{py:"sm",px:"md",children:s.jsxs(o.Table,{highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{style:{width:100},children:n("common.type")}),s.jsx("th",{style:{width:"calc(50% - 50px)"},children:n("common.name")}),s.jsx("th",{children:n("query.usage.in_views")})]})}),s.jsx("tbody",{children:e.map(l=>s.jsxs("tr",{children:[s.jsx("td",{children:n(l.type_label)}),s.jsx("td",{children:s.jsx(o.Anchor,{component:"button",type:"button",onClick:()=>i(l),children:l.label})}),s.jsx("td",{children:s.jsxs(o.Stack,{align:"flex-start",justify:"flex-start",spacing:2,children:[l.views.map(c=>s.jsx(o.Anchor,{component:"button",type:"button",onClick:()=>a(c.id),children:s.jsx(o.Box,{children:c.label})},c.id)),l.views.length===0&&s.jsx(o.Box,{children:"--"})]})})]},l.id))})]})})}),zi=({value:t,onChange:e,height:n="200px",defaultLanguage:r="sql",theme:i="vs-dark"})=>{const a=c=>{e==null||e(c??"")},l=!e;return s.jsx(Pe,{className:"minimal-monaco-editor",height:n,defaultLanguage:r,value:t,onChange:l?void 0:a,theme:i,options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1},readOnly:l||!e,"semanticHighlighting.enabled":!0}})},I1=S.observer(({queryModel:t})=>{const{t:e}=_.useTranslation(),n=m.useMemo(()=>x.groupBy(t.dependencies,"type"),[t.dependencies]),r=m.useMemo(()=>t.dependencies.some(a=>!a.valid),[t.dependencies]),i=t.dependencies.length>0;return i?s.jsxs(o.HoverCard,{withinPortal:!0,zIndex:340,shadow:"md",disabled:!i,children:[s.jsx(o.HoverCard.Target,{children:s.jsx(o.Button,{size:"xs",variant:"subtle",color:r?"red":"green",disabled:!i,leftIcon:r?s.jsx(k.IconAlertTriangle,{size:16}):s.jsx(k.IconDiscountCheckFilled,{size:16}),children:e("query.dependency.label")})}),s.jsx(o.HoverCard.Dropdown,{children:s.jsx(o.List,{spacing:"md",size:14,listStyleType:"none",children:Object.entries(n).map(([a,l])=>s.jsxs(o.List.Item,{children:[s.jsx(o.Text,{fw:"bold",ff:"monospace",children:e(`${a}.label`)}),s.jsx(o.List,{withPadding:!0,size:14,sx:{fontFamily:"monospace",svg:{verticalAlign:"middle"}},children:l.map(c=>s.jsx(o.List.Item,{icon:s.jsx(o.Box,{sx:{path:{fill:c.valid?"rgb(18, 184, 134)":"rgb(250, 82, 82)"}},children:s.jsx(k.IconPointFilled,{size:12})}),children:c.key},c.key))})]},a))})})]}):s.jsx(o.Tooltip,{label:e("query.dependency.has_none"),children:s.jsx(o.Button,{size:"xs",variant:"subtle",color:"gray",leftIcon:s.jsx(k.IconHierarchy,{size:16,style:{transform:"rotate(180deg)"}}),sx:{transform:"none !important"},children:e("query.dependency.label")})})}),E1="SELECT 1",A1=S.observer(({queryModel:t})=>{const{t:e}=_.useTranslation(),[n,r]=m.useState(t.sql),i=()=>{t.setSQL(n)},a=()=>{r(t.sql)},l=()=>{r(E1)};m.useEffect(()=>{r(t.sql)},[t.sql]);const c=n!==t.sql;return s.jsxs(o.Stack,{spacing:4,sx:{height:"100%"},children:[s.jsxs(o.Group,{mb:6,position:"apart",sx:{flexShrink:0,flexGrow:0},children:[s.jsx(o.Group,{position:"left",children:s.jsx(I1,{queryModel:t})}),s.jsxs(o.Group,{position:"right",children:[s.jsx(o.Button,{onClick:l,size:"xs",variant:"default",leftIcon:s.jsx(k.IconPlayerSkipBack,{size:16}),children:e("common.actions.reset_to_default")}),s.jsx(o.Button,{onClick:a,color:"red",size:"xs",disabled:!c,leftIcon:s.jsx(k.IconRecycle,{size:16}),children:e("common.actions.revert_changes")}),s.jsx(o.Button,{color:"green",size:"xs",onClick:i,disabled:!c,leftIcon:s.jsx(k.IconDeviceFloppy,{size:16}),children:e("common.actions.save_changes")})]})]}),s.jsx(zi,{height:"100%",value:n,onChange:r,theme:"sql-dark",defaultLanguage:"sql"})]})}),P1=({value:t,height:e="200px",defaultLanguage:n="sql"})=>s.jsx(Pe,{className:"preview-sql-in-monaco-editor",height:e,defaultLanguage:n,value:t,onChange:void 0,theme:"vs-light",options:{lineNumbers:"on",folding:!0,lineDecorationsWidth:20,wordWrap:"on",minimap:{enabled:!1},readOnly:!0}}),$1=S.observer(({value:t})=>{const n=de().payloadForSQL,r=m.useMemo(()=>Cs(t,n),[t,n]);return s.jsx(P1,{height:"100%",value:r})}),Qc={pre:["function process_request({ context, filters, sql }, utils) {"," // modify and return sql"," return sql","}"].join(`
479
+ `)},zT=S.observer(({queryModel:t})=>{const{t:e}=_.useTranslation();return t.typedAsHTTP?s.jsxs(o.Tabs,{defaultValue:"pre_process",orientation:"vertical",sx:{flexGrow:1},children:[s.jsxs(o.Tabs.List,{children:[s.jsx(o.Tabs.Tab,{value:"pre_process",children:e("query.build_request")}),s.jsx(o.Tabs.Tab,{value:"post_process",children:e("query.process_result")}),s.jsx(Di,{})]}),s.jsx(o.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:s.jsx(Qt,{label:"",value:t.pre_process,onChange:t.setPreProcess,defaultValue:Wc.pre})}),s.jsx(o.Tabs.Panel,{value:"post_process",p:"sm",children:s.jsx(Qt,{label:"",value:t.post_process,onChange:t.setPostProcess,defaultValue:Wc.post})})]}):null}),MT=S.observer(({queryID:t,usage:e})=>{const{t:n}=_.useTranslation(),r=H().editor,i=l=>{if(l.type==="filter"){r.setPath(["_FILTERS_",l.id]);return}if(l.type==="panel"){const c=l.views[0].id;r.setPath(["_VIEWS_",c,"_PANELS_",l.id]);return}},a=l=>{r.setPath(["_VIEWS_",l])};return s.jsx(o.Stack,{py:"sm",px:"md",children:s.jsxs(o.Table,{highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{style:{width:100},children:n("common.type")}),s.jsx("th",{style:{width:"calc(50% - 50px)"},children:n("common.name")}),s.jsx("th",{children:n("query.usage.in_views")})]})}),s.jsx("tbody",{children:e.map(l=>s.jsxs("tr",{children:[s.jsx("td",{children:n(l.type_label)}),s.jsx("td",{children:s.jsx(o.Anchor,{component:"button",type:"button",onClick:()=>i(l),children:l.label})}),s.jsx("td",{children:s.jsxs(o.Stack,{align:"flex-start",justify:"flex-start",spacing:2,children:[l.views.map(c=>s.jsx(o.Anchor,{component:"button",type:"button",onClick:()=>a(c.id),children:s.jsx(o.Box,{children:c.label})},c.id)),l.views.length===0&&s.jsx(o.Box,{children:"--"})]})})]},l.id))})]})})}),zi=({value:t,onChange:e,height:n="200px",defaultLanguage:r="sql",theme:i="vs-dark"})=>{const a=c=>{e==null||e(c??"")},l=!e;return s.jsx(Pe,{className:"minimal-monaco-editor",height:n,defaultLanguage:r,value:t,onChange:l?void 0:a,theme:i,options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1},readOnly:l||!e,"semanticHighlighting.enabled":!0}})},IT=S.observer(({queryModel:t})=>{const{t:e}=_.useTranslation(),n=m.useMemo(()=>x.groupBy(t.dependencies,"type"),[t.dependencies]),r=m.useMemo(()=>t.dependencies.some(a=>!a.valid),[t.dependencies]),i=t.dependencies.length>0;return i?s.jsxs(o.HoverCard,{withinPortal:!0,zIndex:340,shadow:"md",disabled:!i,children:[s.jsx(o.HoverCard.Target,{children:s.jsx(o.Button,{size:"xs",variant:"subtle",color:r?"red":"green",disabled:!i,leftIcon:r?s.jsx(k.IconAlertTriangle,{size:16}):s.jsx(k.IconDiscountCheckFilled,{size:16}),children:e("query.dependency.label")})}),s.jsx(o.HoverCard.Dropdown,{children:s.jsx(o.List,{spacing:"md",size:14,listStyleType:"none",children:Object.entries(n).map(([a,l])=>s.jsxs(o.List.Item,{children:[s.jsx(o.Text,{fw:"bold",ff:"monospace",children:e(`${a}.label`)}),s.jsx(o.List,{withPadding:!0,size:14,sx:{fontFamily:"monospace",svg:{verticalAlign:"middle"}},children:l.map(c=>s.jsx(o.List.Item,{icon:s.jsx(o.Box,{sx:{path:{fill:c.valid?"rgb(18, 184, 134)":"rgb(250, 82, 82)"}},children:s.jsx(k.IconPointFilled,{size:12})}),children:c.key},c.key))})]},a))})})]}):s.jsx(o.Tooltip,{label:e("query.dependency.has_none"),children:s.jsx(o.Button,{size:"xs",variant:"subtle",color:"gray",leftIcon:s.jsx(k.IconHierarchy,{size:16,style:{transform:"rotate(180deg)"}}),sx:{transform:"none !important"},children:e("query.dependency.label")})})}),ET="SELECT 1",AT=S.observer(({queryModel:t})=>{const{t:e}=_.useTranslation(),[n,r]=m.useState(t.sql),i=()=>{t.setSQL(n)},a=()=>{r(t.sql)},l=()=>{r(ET)};m.useEffect(()=>{r(t.sql)},[t.sql]);const c=n!==t.sql;return s.jsxs(o.Stack,{spacing:4,sx:{height:"100%"},children:[s.jsxs(o.Group,{mb:6,position:"apart",sx:{flexShrink:0,flexGrow:0},children:[s.jsx(o.Group,{position:"left",children:s.jsx(IT,{queryModel:t})}),s.jsxs(o.Group,{position:"right",children:[s.jsx(o.Button,{onClick:l,size:"xs",variant:"default",leftIcon:s.jsx(k.IconPlayerSkipBack,{size:16}),children:e("common.actions.reset_to_default")}),s.jsx(o.Button,{onClick:a,color:"red",size:"xs",disabled:!c,leftIcon:s.jsx(k.IconRecycle,{size:16}),children:e("common.actions.revert_changes")}),s.jsx(o.Button,{color:"green",size:"xs",onClick:i,disabled:!c,leftIcon:s.jsx(k.IconDeviceFloppy,{size:16}),children:e("common.actions.save_changes")})]})]}),s.jsx(zi,{height:"100%",value:n,onChange:r,theme:"sql-dark",defaultLanguage:"sql"})]})}),PT=({value:t,height:e="200px",defaultLanguage:n="sql"})=>s.jsx(Pe,{className:"preview-sql-in-monaco-editor",height:e,defaultLanguage:n,value:t,onChange:void 0,theme:"vs-light",options:{lineNumbers:"on",folding:!0,lineDecorationsWidth:20,wordWrap:"on",minimap:{enabled:!1},readOnly:!0}}),$T=S.observer(({value:t})=>{const n=de().payloadForSQL,r=m.useMemo(()=>Cs(t,n),[t,n]);return s.jsx(PT,{height:"100%",value:r})}),Qc={pre:["function process_request({ context, filters, sql }, utils) {"," // modify and return sql"," return sql","}"].join(`
480
480
  `),post:["function process_result(data, utils, state) {"," // process data and return the result"," return data","}"].join(`
481
- `)},B1=S.observer(({queryModel:t})=>{const{t:e}=_.useTranslation();return t.typedAsSQL?s.jsxs(o.Tabs,{defaultValue:"Edit",orientation:"vertical",sx:{flexGrow:1},styles:{tabLabel:{width:"100%",height:"28px",lineHeight:"28px"}},keepMounted:!1,children:[s.jsxs(o.Tabs.List,{children:[s.jsx(o.Tabs.Tab,{value:"Edit",children:s.jsx(o.Group,{spacing:14,position:"apart",children:e("query.edit_sql")})}),s.jsx(o.Tabs.Tab,{value:"Preview",children:e("query.preview_sql")}),s.jsx(o.Tabs.Tab,{value:"pre_process",children:e("query.process_request")}),s.jsx(o.Tabs.Tab,{value:"post_process",children:e("query.process_result")}),s.jsx(Di,{}),t.datasource&&s.jsx(Nc,{dataSource:t.datasource})]}),s.jsx(o.Tabs.Panel,{value:"Edit",sx:{position:"relative"},p:"sm",children:s.jsx(A1,{queryModel:t})}),s.jsx(o.Tabs.Panel,{value:"Preview",p:0,pl:4,children:s.jsx($1,{value:t.sql})}),s.jsx(o.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:s.jsx(Qt,{label:"",value:t.pre_process,onChange:t.setPreProcess,defaultValue:Qc.pre})}),s.jsx(o.Tabs.Panel,{value:"post_process",p:"sm",children:s.jsx(Qt,{label:"",value:t.post_process,onChange:t.setPostProcess,defaultValue:Qc.post})})]}):null}),q1={pre:["function transform(queries, state, utils) {"," // use queries & dashboar state to build new data"," const data = []"," return data","}"].join(`
482
- `),post:""},L1=S.observer(({queryModel:t})=>{const{t:e}=_.useTranslation(),n=U();return t.isTransform?s.jsxs(o.Stack,{py:20,px:20,sx:{height:"100%"},children:[s.jsx(o.Text,{size:"sm",children:e("query.transform.guide.pick_queries")}),s.jsx(o.MultiSelect,{data:n.queries.optionsWithoutTransform,value:[...t.dep_query_ids],onChange:t.setDependantQueryIDs,maxDropdownHeight:800}),s.jsx(o.Text,{size:"sm",children:e("query.transform.guide.write_function")}),s.jsx(o.Box,{sx:{flexGrow:1},children:s.jsx(Qt,{label:"",value:t.pre_process,onChange:t.setPreProcess,defaultValue:q1.pre})})]}):null}),bn={height:"calc(100% - 44px)",padding:0},O1=S.observer(({queryModel:t})=>{const{t:e}=_.useTranslation(),n=U(),r=m.useMemo(()=>t.datasource?t.typedAsHTTP?"HTTP":"SQL":"Configurations",[t.datasource,t.typedAsHTTP]),[i,a]=m.useState(r);m.useEffect(()=>{a(u=>u!=="Configurations"&&r==="Configurations"?"Configurations":u)},[r]);const l=n.findQueryUsage(t.id),c=l.length===0;return s.jsxs(o.Tabs,{value:i,onTabChange:a,defaultValue:r,orientation:"horizontal",keepMounted:!1,sx:{height:"100vh"},children:[s.jsxs(o.Tabs.List,{grow:!0,children:[s.jsx(o.Tabs.Tab,{value:"Configurations",children:e("query.configurations")}),t.typedAsSQL&&s.jsx(o.Tabs.Tab,{value:"SQL",children:e("query.request")}),t.typedAsHTTP&&s.jsx(o.Tabs.Tab,{value:"HTTP",children:e("query.request")}),t.isTransform&&s.jsx(o.Tabs.Tab,{value:"Transform",children:e("query.transform.label")}),s.jsx(o.Tabs.Tab,{value:"Data",disabled:!t.canPreviewData,children:s.jsx(o.Tooltip,{label:t.guideToPreviewData,disabled:t.canPreviewData,withinPortal:!0,children:s.jsx(o.Text,{children:e("data.preview_data")})})}),s.jsx(o.Tabs.Tab,{value:"Usage",disabled:c,children:s.jsx(o.Tooltip,{label:e("query.usage.unused_description"),disabled:!c,withinPortal:!0,children:s.jsx(o.Text,{children:e("query.usage.label")})})})]}),s.jsx(o.Tabs.Panel,{value:"Configurations",pt:0,p:0,children:s.jsx(S1,{queryModel:t})}),t.typedAsSQL&&s.jsx(o.Tabs.Panel,{value:"SQL",sx:bn,children:s.jsx(o.Stack,{sx:{height:"100%"},children:s.jsx(B1,{queryModel:t})})}),t.typedAsHTTP&&s.jsx(o.Tabs.Panel,{value:"HTTP",sx:bn,children:s.jsx(o.Stack,{sx:{height:"100%"},children:s.jsx(z1,{queryModel:t})})}),t.isTransform&&s.jsx(o.Tabs.Panel,{value:"Transform",sx:bn,children:s.jsx(o.Stack,{sx:{height:"100%"},children:s.jsx(L1,{queryModel:t})})}),s.jsx(o.Tabs.Panel,{value:"Data",sx:{...bn,overflow:"hidden"},children:s.jsx(Si,{id:t.id,moreActions:null,refreshOnMount:!0})}),s.jsx(o.Tabs.Panel,{value:"Usage",sx:{...bn,overflow:"hidden"},children:s.jsx(M1,{queryID:t.id,usage:l})})]})}),V1=S.observer(({id:t})=>{const n=U().queries.findByID(t);return t===""?null:n?s.jsx(O1,{queryModel:n}):s.jsx(o.Text,{size:14,color:"red",children:"Invalid Query ID"})}),N1=S.observer(({value:t})=>{const n=de().payloadForSQL,r=m.useMemo(()=>Cs(t,n),[t,n]);return s.jsx(zi,{height:"100%",value:r})}),G1=S.observer(({item:t,remove:e,onKeyChanged:n})=>{const{t:r}=_.useTranslation(),[i,a]=m.useState("SQL"),[l,c]=m.useState(t.key),u=()=>{t.setKey(l),n(l)},d=l!==t.key,p=t.isADuplicatedKey(l),[h,g]=m.useState(t.value),y=()=>{t.setValue(h)};m.useEffect(()=>{c(t.key),g(t.value)},[t]);const v=h!==t.value,C=Le.useModals(),T=()=>{C.openConfirmModal({title:`${r("sql_snippet.delete")}?`,labels:{confirm:r("common.actions.confirm"),cancel:r("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:e,confirmProps:{color:"red"},zIndex:320})};return s.jsxs(o.Stack,{p:20,sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",children:[s.jsxs(o.Group,{sx:{alignItems:"end"},spacing:40,children:[s.jsx(o.TextInput,{label:r(p?"sql_snippet.key_occupied":"sql_snippet.key"),value:l,onChange:D=>{c(D.currentTarget.value)},sx:{flexGrow:"1 !important"},rightSection:s.jsx(o.ActionIcon,{color:"blue",variant:"subtle",onClick:u,disabled:!d||p,children:s.jsx(B.DeviceFloppy,{size:16})}),error:p}),s.jsx(o.Button,{leftIcon:s.jsx(B.Trash,{size:16}),color:"red",variant:"light",onClick:T,children:r("sql_snippet.delete")})]}),s.jsxs(o.Tabs,{value:i,onTabChange:a,sx:{flexGrow:1},styles:{panel:{height:"calc(100% - 50px)"}},children:[s.jsxs(o.Tabs.List,{sx:{position:"relative"},children:[s.jsx(o.Tabs.Tab,{value:"SQL",children:r("sql_snippet.edit_snippet")}),s.jsx(o.Tabs.Tab,{value:"Preview",children:r("sql_snippet.preview_snippet")}),s.jsx(Di,{}),s.jsx(o.ActionIcon,{color:"blue",variant:"filled",onClick:y,disabled:!v,sx:{position:"absolute",top:0,right:10},children:s.jsx(B.DeviceFloppy,{size:18})})]}),s.jsx(o.Tabs.Panel,{value:"SQL",pt:"sm",children:s.jsx(zi,{height:"100%",value:h,onChange:g,defaultLanguage:"sql",theme:"sql-dark"})}),s.jsx(o.Tabs.Panel,{value:"Preview",pt:"sm",children:s.jsx(N1,{value:h})})]})]})}),F1=S.observer(({id:t})=>{const e=H(),n=U(),r=m.useMemo(()=>n.sqlSnippets.findByKey(t),[t]);if(!t)return null;if(!r)return s.jsxs(o.Text,{size:14,children:["SQL Snippet by key[",t,"] is not found"]});const i=()=>{e.editor.setPath(["_SQL_SNIPPETS_",""])},a=()=>{n.sqlSnippets.removeByKey(t),i()},l=c=>{e.editor.setPath(["_SQL_SNIPPETS_",c])};return s.jsx(G1,{item:r,remove:a,onKeyChanged:l})}),W1=S.observer(()=>{const{t}=_.useTranslation(),[e,n]=m.useState([]),r=Le.useModals(),i=H(),a=g=>{i.editor.setPath(["_SQL_SNIPPETS_",g])},l=()=>{r.openConfirmModal({title:"Delete ununsed SQL snippets?",children:s.jsx(o.Text,{size:"sm",children:"This action cannot be undone."}),labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>i.content.removeUnusedSQLSnippets(),confirmProps:{color:"red"},zIndex:320})},c=()=>{i.content.sqlSnippets.downloadSchema(e)},u=m.useMemo(()=>i.content.sqlSnippets.sortedList.map(g=>g.key),[i.content.sqlSnippets.sortedList]),d=()=>{n(u)},p=()=>{n([])},h=i.content.sqlSnippetsUsage;return s.jsxs(o.Stack,{sx:{height:"100%"},spacing:"sm",pb:"59px",children:[s.jsx(o.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:s.jsx(o.Text,{px:"md",align:"left",sx:{userSelect:"none",cursor:"default"},children:t("sql_snippet.manage")})}),s.jsxs(o.Flex,{justify:"space-between",align:"center",px:12,children:[s.jsxs(o.Group,{position:"left",children:[s.jsxs(o.Button.Group,{children:[s.jsx(o.Button,{variant:"default",size:"xs",onClick:d,children:t("common.actions.select_all")}),s.jsx(o.Button,{variant:"default",size:"xs",onClick:p,children:t("common.actions.clear_selection")})]}),s.jsx(o.Button,{size:"xs",color:"blue",leftIcon:s.jsx(k.IconCode,{size:14}),disabled:e.length===0,onClick:c,children:t("common.actions.download_schema")})]}),s.jsx(o.Button,{variant:"subtle",size:"xs",color:"red",leftIcon:s.jsx(k.IconTrash,{size:14}),disabled:!i.content.hasUnusedSQLSnippets,onClick:l,children:t("sql_snippet.delete_unused")})]}),s.jsx(o.Box,{sx:{flexGrow:1,overflow:"auto"},children:s.jsx(o.Checkbox.Group,{size:"xs",value:e,onChange:n,children:s.jsxs(o.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:t("common.key")}),s.jsx("th",{style:{width:"100px",textAlign:"center"},children:t("sql_snippet.usage.label")}),s.jsx("th",{style:{width:"300px",paddingLeft:"24px"},children:t("common.action")})]})}),s.jsx("tbody",{children:i.content.sqlSnippets.sortedList.map(g=>{var v;const y=((v=h[g.key])==null?void 0:v.length)??0;return s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx(o.Checkbox,{value:g.key,styles:{input:{cursor:"pointer"}}})}),s.jsx("td",{children:g.key}),s.jsx("td",{style:{color:y===0?"#ff0000":"#000",fontWeight:y===0?"bold":"normal",textAlign:"center"},children:y}),s.jsx("td",{children:s.jsx(o.Button,{variant:"subtle",size:"xs",onClick:()=>a(g.key),children:t("common.actions.open")})})]},g.key)})})]})})})]})}),Q1=S.observer(({view:t})=>!t||t.type!==q.Division?null:s.jsx(o.Stack,{})),R1=S.observer(({view:t})=>{const{t:e,i18n:n}=_.useTranslation(),r=m.useMemo(()=>[{value:"default",label:e("common.tabs.variant.default")},{value:"outline",label:e("common.tabs.variant.outline")},{value:"pills",label:e("common.tabs.variant.pills")}],[n.language]),i=m.useMemo(()=>[{value:"horizontal",label:e("common.tabs.orientation.horizontal")},{value:"vertical",label:e("common.tabs.orientation.vertical")}],[n.language]);if(!t||t.type!==q.Tabs)return null;const a=t.config;return s.jsxs(o.Stack,{children:[s.jsx(o.Divider,{mt:8,mb:0,label:e("view.component.tabs.tabs_settings"),labelPosition:"center"}),s.jsx(o.Select,{label:e("common.tabs.variant.label"),value:a.variant,onChange:a.setVariant,data:r}),s.jsx(o.Select,{label:e("common.tabs.orientation.label"),value:a.orientation,onChange:a.setOrientation,data:i}),s.jsx(o.Switch,{label:e("common.tabs.grow_tabs"),checked:a.grow,onChange:l=>a.setGrow(l.currentTarget.checked)})]})}),U1=({disabled:t,value:e,onChange:n})=>{const r=i=>{i&&n(i)};return s.jsxs(o.Box,{sx:{position:"relative"},children:[t&&s.jsx(o.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),s.jsx(Pe,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},Y1=({value:t,onChange:e})=>{const{t:n}=_.useTranslation(),[r,{setTrue:i,setFalse:a}]=N.useBoolean(),[l,c]=m.useState(t??ls),u=y=>{c({...l,enabled:y})},d=()=>{a();const{enabled:y,func_content:v}=l,C={enabled:y,func_content:v};c(C),e(C)},p=()=>{a(),c(t)},h=y=>{c(v=>({...v,func_content:y}))},g=()=>{h(ls.func_content)};return s.jsxs(s.Fragment,{children:[s.jsx(o.ActionIcon,{size:"lg",color:"blue",variant:"filled",mt:26,onClick:i,sx:{flexGrow:0},children:s.jsx(B.Settings,{size:14})}),s.jsx(o.Modal,{size:800,title:n("view.component.modal.custom_title"),opened:r,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&s.jsxs(o.Stack,{children:[s.jsx(o.Checkbox,{mt:10,label:n("common.enabled"),checked:l.enabled,onChange:y=>u(y.currentTarget.checked)}),s.jsx(U1,{value:l.func_content,onChange:h,disabled:!l.enabled}),s.jsxs(o.Group,{position:"apart",children:[s.jsx(o.Button,{onClick:g,color:"red",leftIcon:s.jsx(B.Recycle,{size:20}),children:n("common.actions.revert")}),s.jsxs(o.Group,{position:"right",children:[s.jsx(o.Button,{onClick:p,variant:"subtle",children:n("common.actions.cancel")}),s.jsx(o.Button,{onClick:d,children:n("common.actions.save")})]})]})]})})]})},K1=S.observer(({view:t})=>{const{t:e}=_.useTranslation();if(!t||t.type!==q.Modal)return null;const n=t.config,r=n.custom_modal_title.value;return s.jsxs(o.Stack,{children:[s.jsx(o.Divider,{mt:8,label:e("view.component.modal.modal_settings"),labelPosition:"center"}),s.jsxs(o.Flex,{gap:10,children:[s.jsx(o.TextInput,{label:e("view.component.modal.title"),value:r,onChange:x.noop,disabled:!0,sx:{flexGrow:1}}),s.jsx(Y1,{value:n.custom_modal_title,onChange:n.custom_modal_title.replace})]}),s.jsxs(o.Group,{grow:!0,children:[s.jsx(o.TextInput,{label:e("view.component.modal.width"),value:n.width,onChange:i=>n.setWidth(i.currentTarget.value),placeholder:"600px / 50vw"}),s.jsx(o.TextInput,{label:e("view.component.modal.height"),value:n.height,onChange:i=>n.setHeight(i.currentTarget.value),placeholder:"600px / 50vw"})]})]})}),J1=S.observer(({view:t})=>s.jsxs(s.Fragment,{children:[s.jsx(Q1,{view:t}),s.jsx(K1,{view:t}),s.jsx(R1,{view:t})]})),X1=S.observer(({view:t})=>{const{t:e,i18n:n}=_.useTranslation(),r=m.useMemo(()=>[{label:e("view.component.div.label"),value:q.Division},{label:e("view.component.modal.label"),value:q.Modal},{label:e("view.component.tabs.label"),value:q.Tabs}],[n.language]);return t?s.jsxs(o.Stack,{sx:{position:"relative"},children:[s.jsx(o.TextInput,{label:e("common.name"),value:t.name,onChange:i=>{t.setName(i.currentTarget.value)}}),s.jsx(o.Select,{label:e("common.type"),withinPortal:!0,zIndex:320,value:t.type,onChange:t.setType,data:r}),s.jsx(J1,{view:t})]}):null}),Z1=S.observer(({id:t})=>{const{t:e}=_.useTranslation(),n=Le.useModals(),r=H(),i=U();if(t==="")return null;const a=i.views.findByID(t);if(!a)return s.jsxs(o.Text,{size:14,children:["View by ID[",t,"] is not found"]});const l=()=>{r.editor.setPath(["_VIEWS_",""])},c=()=>{n.openConfirmModal({title:`${e("view.delete")}?`,labels:{confirm:e("common.actions.confirm"),cancel:e("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.views.removeByID(t),l()},zIndex:320})};return s.jsxs(o.Stack,{sx:{maxWidth:"600px",height:"100%"},spacing:"sm",children:[s.jsx(o.Group,{position:"right",pt:10,children:s.jsx(o.Button,{size:"xs",color:"red",leftIcon:s.jsx(B.Trash,{size:16}),onClick:c,children:e("view.delete")})}),s.jsx(o.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:s.jsx(X1,{view:a})})]})});function H1(t){return t.length===1&&t[0]==="_QUERY_VARS_"}function eD(t){return t.length===1&&t[0]==="_MOCK_CONTEXT_"}function tD(t){return t.length===1&&t[0]==="_FILTERS_"}function nD(t){return t.length===2&&t[0]==="_FILTERS_"}function sD(t){return t.length===1&&t[0]==="_SQL_SNIPPETS_"}function rD(t){return t.length===2&&t[0]==="_SQL_SNIPPETS_"}function iD(t){return t.length===2&&t[0]==="_QUERIES_"}function aD(t){return t.length===1&&t[0]==="_QUERIES_"}function oD(t){return t.length===2&&t[0]==="_VIEWS_"}function lD(t){return t.length===4&&t[0]==="_VIEWS_"&&t[2]==="_PANELS_"}const cD=S.observer(()=>s.jsx(o.Stack,{sx:{height:"100%"},p:"sm",children:s.jsx(Fc,{})})),uD=S.observer(()=>{const t=H().editor,e=t.path;return H1(e)?s.jsx(cD,{}):eD(e)?s.jsx(_T,{}):tD(e)?s.jsx(vT,{}):nD(e)?s.jsx(o.Box,{p:"xs",pl:20,children:s.jsx(bT,{id:e[1]})}):sD(e)?s.jsx(W1,{}):rD(e)?s.jsx(F1,{id:e[1]}):aD(e)?s.jsx(r1,{}):iD(e)?s.jsx(V1,{id:e[1]}):oD(e)?s.jsx(o.Box,{p:"xs",pl:20,children:s.jsx(Z1,{id:e[1]})}):lD(e)?s.jsx(s1,{viewID:e[1],panelID:e[3]}):s.jsx(o.Box,{children:t.path})}),dD=S.observer(()=>s.jsx(uD,{})),pD=S.observer(()=>{const{t}=_.useTranslation(),e=H(),n=()=>{const r=new Date().getTime().toString(),i={id:r,key:r,label:r,order:e.content.filters.current.length+1,type:he.TextInput,config:Jr(),visibleInViewsIDs:["Main"],auto_submit:!1};e.content.filters.append(i),e.editor.setPath(["_FILTERS_",r])};return s.jsx(o.Button,{variant:"subtle",leftIcon:s.jsx(k.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:n,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:t("filter.add")})}),hD=S.observer(({parentID:t})=>{const{t:e}=_.useTranslation(),n=U();if(!t)return null;const r=n.views.findByID(t);return!r||r.type===q.Tabs?null:s.jsx(o.Button,{variant:"subtle",leftIcon:s.jsx(k.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:()=>n.addANewPanel(r.id),sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:e("panel.add")})}),mD=S.observer(()=>{const{t}=_.useTranslation(),e=H(),n=()=>{const r=new Date().getTime().toString(),i={id:r,name:r,type:ce.Postgresql,key:"",sql:""};e.content.queries.append(i),e.editor.setPath(["_QUERIES_",r])};return s.jsx(o.Button,{variant:"subtle",leftIcon:s.jsx(k.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:n,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:t("query.add")})}),fD=S.observer(()=>{const{t}=_.useTranslation(),e=H(),n=()=>{const r=new Date().getTime().toString(),i={key:r,value:""};e.content.sqlSnippets.append(i),e.editor.setPath(["_SQL_SNIPPETS_",r])};return s.jsx(o.Button,{variant:"subtle",leftIcon:s.jsx(k.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:n,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:t("sql_snippet.add")})}),gD=S.observer(()=>{const{t}=_.useTranslation(),e=U();return s.jsx(o.Button,{variant:"subtle",leftIcon:s.jsx(k.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:e.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:t("view.add")})}),xD=S.observer(()=>{const{t}=_.useTranslation(),e=H();return s.jsx(o.Button,{variant:"subtle",rightIcon:s.jsx(k.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>e.editor.setPath(["_QUERIES_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:t("query.manage")})}),yD=S.observer(()=>{const{t}=_.useTranslation(),e=H();return s.jsx(o.Button,{variant:"subtle",rightIcon:s.jsx(k.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>e.editor.setPath(["_SQL_SNIPPETS_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:t("sql_snippet.manage")})}),bD=S.observer(()=>{const{t}=_.useTranslation(),e=H();return s.jsx(o.Button,{variant:"subtle",rightIcon:s.jsx(k.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>e.editor.setPath(["_FILTERS_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:t("filter.manage")})}),vD=S.observer(({action_type:t,parentID:e})=>t==="_Add_A_Filter_"?s.jsx(pD,{}):t==="_Add_A_SQL_SNIPPET_"?s.jsx(fD,{}):t==="_Add_A_QUERY_"?s.jsx(mD,{}):t==="_Add_A_VIEW_"?s.jsx(gD,{}):t==="_Add_A_PANEL_"?s.jsx(hD,{parentID:e}):t==="_QUERIES_SETTINGS_"?s.jsx(xD,{}):t==="_SQL_SNIPPETS_SETTINGS_"?s.jsx(yD,{}):t==="_FILTERS_SETTINGS_"?s.jsx(bD,{}):null),Rc=S.observer(({option:t})=>{var p;const{t:e}=_.useTranslation(),n=H().editor,r=n.isOptionActive,i=r(n.path,t),a=n.isOptionOpened,l=n.navigate,c=a(t),[u,d]=m.useState(c);return m.useEffect(()=>{d(c)},[c]),s.jsx(o.NavLink,{active:i,defaultOpened:c,opened:u,onChange:d,label:e(t.label),onClick:()=>l(t),icon:t.Icon?s.jsx(t.Icon,{size:18}):null,children:(p=t.children)==null?void 0:p.map(h=>h._type==="ACTION"?s.jsx(vD,{action_type:h._action_type,parentID:h.parentID},`_ADD_${h.value}_`):s.jsx(Rc,{option:h},h.value))},t.label)}),_D=S.observer(()=>{const t=H();return s.jsx(o.Box,{sx:{position:"relative"},children:t.editor.navOptions.map(e=>s.jsx(Rc,{option:e},e.value))})}),jD=S.observer(()=>{const{t}=_.useTranslation(),e=H();return s.jsxs(o.Navbar,{p:0,width:{base:220,xs:220,sm:240,md:260,lg:300,xl:320},sx:{height:"100vh - 60px - 60px",".mantine-NavLink-body":{wordWrap:"break-word"}},children:[s.jsx(o.Navbar.Section,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:s.jsx(o.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:t("common.titles.settings")})}),s.jsx(o.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:s.jsx(_D,{})}),s.jsx(o.Navbar.Section,{children:s.jsx(o.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:s.jsx(o.Button,{size:"xs",color:"red",leftIcon:s.jsx(k.IconX,{size:18}),onClick:()=>e.editor.close(),children:t("common.actions.close")})})})]})}),wD={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden",minWidth:"calc(var(--mantine-navbar-width, 0px) + 1200px)"},body:{flexGrow:1,nav:{top:0,height:"100vh"}},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:0,height:"100vh"}},CD=S.observer(()=>{const t=H().editor;return s.jsx(o.Modal,{onClose:()=>t.setSettingsOpen(!1),closeOnEscape:!1,closeOnClickOutside:!1,opened:t.settings_open,fullScreen:!0,title:null,transitionProps:{duration:0},withCloseButton:!1,withinPortal:!0,zIndex:300,styles:{body:{padding:"0 !important"},content:{overflowY:"hidden !important"}},children:s.jsx(o.AppShell,{padding:0,navbar:s.jsx(jD,{}),styles:wD,children:s.jsx(dD,{})})})}),SD=t=>t.replace(/([^:])(\/\/+)/g,"$1/");function kD(t){m.useEffect(()=>{if(Pe.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/dashboard");const n=SD(t);Pe.loader.config({paths:{vs:n}}),Pe.loader.init().then(r=>console.log("monaco instance:",r))},[])}xa(),ba();const TD={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden"},body:{flexGrow:1},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:60+30,height:"100vh"}},DD=({context:t,dashboard:e,content:n,update:r,className:i="dashboard",config:a,onChange:l,headerSlot:c,filterValues:u,onFilterValuesChange:d,onExit:p,lang:h},g)=>{kD(a.monacoPath),Ss(a);const{data:y=[]}=N.useRequest(zs),{data:v=[]}=N.useRequest(va),C=m.useMemo(()=>Sc(e,n,y,v,t,u??{}),[e,n]);m.useImperativeHandle(g,()=>C,[C]),Tc(C.content,!0),m.useEffect(()=>{C.context.replace(t)},[t]),m.useEffect(()=>{C.datasources.replace(y)},[y]),m.useEffect(()=>{C.globalSQLSnippets.replace(v)},[v]),m.useEffect(()=>{d==null||d(C.content.filters.values)},[d,C.content.filters.values]),m.useEffect(()=>{u&&C.content.filters.patchValues(u)},[u,C.content.filters.patchValues]),m.useEffect(()=>K.reaction(()=>K.toJS(C.json),P=>{l==null||l(P)}),[C]);const T=async()=>{await r(C.json,C.content.json)},D=N.useCreation(Lr,[]),I=Dc(D);return s.jsx(kc,{lang:h,children:s.jsx(Le.ModalsProvider,{children:s.jsx(Ls,{children:s.jsx(Ps,{value:{searchButtonProps:a.searchButtonProps},children:s.jsx(Es,{value:C,children:s.jsx($s,{value:C.content,children:s.jsx(En.Provider,{value:{inEditMode:!0},children:s.jsx(it.Provider,{value:D,children:s.jsxs(as,{configure:I,children:[s.jsx(o.AppShell,{padding:0,header:s.jsx(Ik,{onExit:p,saveDashboardChanges:T,headerSlot:c}),navbar:s.jsx(rT,{}),styles:TD,children:s.jsx(o.Box,{className:`${i} dashboard-root`,sx:{position:"relative"},children:C.content.views.visibleViews.map(P=>s.jsx(hc,{view:P},P.id))})}),s.jsx(CD,{})]})})})})})})})})})},zD=S.observer(m.forwardRef(DD)),yM="",Mi=f.types.model({id:f.types.string,name:f.types.string,dashboard_id:f.types.string,create_time:f.types.string,update_time:f.types.string,version:f.types.string,filters:ci,queries:pi,sqlSnippets:mi,views:ai,panels:li,layouts:hi,mock_context:Gr}).views(t=>({get json(){return{id:t.id,name:t.name,create_time:t.create_time,update_time:t.update_time,dashboard_id:t.dashboard_id,content:{views:t.views.json,panels:t.panels.json,filters:t.filters.json,version:t.version,layouts:t.layouts.json,definition:{queries:t.queries.json,sqlSnippets:t.sqlSnippets.json,mock_context:t.mock_context.current}}}},get contentJSON(){return this.json.content},get payloadForSQL(){const e=f.getParent(t).context.current,n=f.getParent(t).globalSQLSnippets,r={context:{...t.mock_context.current,...e},filters:t.filters.values};return{...r,sql_snippets:xn(t.sqlSnippets.current,"key","value",r),global_sql_snippets:xn(n.list,"id","content",r)}},get payloadForViz(){const e=f.getParent(t).context.current;return{context:{...t.mock_context.current,...e},filters:t.filters.values}},get dashboardState(){return Ds(this.payloadForSQL)},getAdditionalQueryInfo(e){return{content_id:t.id,query_id:e,params:this.dashboardState}},get data(){return t.queries.current.map(({id:n,data:r})=>({id:n,data:r})).reduce((n,r)=>(n[r.id]=r.data,n),{})},getDataStuffByID(e){const n=t.queries.findByID(e);return n?{data:n.data,len:n.data.length,state:n.state,error:n.error}:{data:[],len:0,state:"idle",error:void 0}}})).actions(t=>({}));function Uc({id:t,name:e,dashboard_id:n,create_time:r,update_time:i,content:a},l,c){if(!a)throw new Error("unexpected null content when creating a content model");const{version:u,filters:d,views:p,panels:h,layouts:g,definition:{queries:y,sqlSnippets:v,mock_context:C={}}}=a;return Mi.create({id:t,name:e,dashboard_id:n,create_time:r,update_time:i,version:u,filters:ui(d,l,C,c),queries:Yl(y),sqlSnippets:Xl(v),mock_context:Fr(C),views:Vl(p),panels:{list:h},layouts:{list:g,currentBreakpoint:g[0].id}})}const Yc=f.types.model({id:f.types.identifier,name:f.types.string,group:f.types.string,content:Mi,content_id:f.types.string,datasources:Ll,globalSQLSnippets:si,context:cs});function Kc({id:t,name:e,group:n,content_id:r},i,a,l,c,u){return Yc.create({id:t,name:e,group:n,content_id:r,content:Uc(i,c,u),datasources:{list:a},globalSQLSnippets:{list:l},context:ri(c)})}xa(),ba();const MD=({context:t,dashboard:e,content:n,className:r="dashboard",config:i,fullScreenPanelID:a,setFullScreenPanelID:l,filterValues:c,onFilterValuesChange:u,lang:d})=>{Ss(i);const{data:p=[]}=N.useRequest(zs),{data:h=[]}=N.useRequest(va),g=m.useMemo(()=>Kc(e,n,p,h,t,c??{}),[e,n]);Tc(g.content,!1),m.useEffect(()=>{g.context.replace(t)},[t]),m.useEffect(()=>{g.datasources.replace(p)},[p]),m.useEffect(()=>{g.globalSQLSnippets.replace(h)},[h]),m.useEffect(()=>{u==null||u(g.content.filters.values)},[u,g.content.filters.values]),m.useEffect(()=>{c&&g.content.filters.patchValues(c)},[c,g.content.filters.patchValues]);const y=N.useCreation(Lr,[]),v=Dc(y);return s.jsx(kc,{lang:d,children:s.jsx(Le.ModalsProvider,{children:s.jsx(Ls,{children:s.jsx(Ps,{value:{searchButtonProps:i.searchButtonProps},children:s.jsx(Es,{value:g,children:s.jsx($s,{value:g.content,children:s.jsx(qs.Provider,{value:{fullScreenPanelID:a,setFullScreenPanelID:l},children:s.jsx(En.Provider,{value:{inEditMode:!1},children:s.jsx(o.Box,{className:`${r} dashboard-root`,children:s.jsx(it.Provider,{value:y,children:s.jsx(as,{configure:v,children:g.content.views.visibleViews.map(C=>s.jsx(ds,{view:C},C.id))})})})})})})})})})})})},ID=S.observer(MD);M.extend(Su),M.extend(ku),M.extend(Tu),M.extend(Du),M.extend(zu),M.extend(Mu),M.extend(Iu),M.extend(Eu),M.extend(Au),M.extend(Pu),M.extend(qu),M.extend(Lu),M.extend(Ou),M.extend(Vu),M.extend(Nu),M.extend($u),M.extend(Bu),M.extend(Gu),M.extend(Fu),M.extend(Wu),M.extend(Qu),M.extend(Ru),M.extend(Uu),M.extend(Yu),M.extend(Ku),M.extend(Ju),M.extend(Xu),M.extend(Zu),M.extend(Hu),M.extend(ed),M.extend(nd),M.extend(sd),M.extend(td),M.tz.setDefault("UTC"),M.updateLocale("en",{weekStart:1});const ED=()=>Promise.resolve().then(()=>Hd).then(({version:t})=>(console.log(`[@devtable/dashboard] version: ${t}`),t));j.APIClient=et,j.CURRENT_SCHEMA_VERSION=ft,j.ContentModel=vi,j.ContentModelContextProvider=$s,j.ContentRenderModel=Mi,j.ContextMeta=cs,j.DEFAULT_CUSTOM_MODAL_TITLE=ls,j.DashboardApiClient=pa,j.DashboardApiFacadeClient=ha,j.DashboardEditor=zD,j.DashboardFilterType=he,j.DashboardMode=mc,j.DashboardModel=Cc,j.DashboardModelContextProvider=Es,j.DashboardRenderModel=Yc,j.DashboardThemeContextProvider=Ps,j.DashboardViewEditor=hc,j.DashboardViewRender=ds,j.DataSourceMetaModel=ni,j.DataSourceType=ce,j.DataSourcesMetaModel=Ll,j.DatesProvider=Ls,j.DefaultApiClient=da,j.DescriptionPopover=fi,j.DraftModel=Zl,j.EViewComponentType=q,j.FacadeApiClient=xd,j.FilterCheckboxConfigMeta=Wr,j.FilterDateRangeConfigMeta=Qr,j.FilterMeta=Zr,j.FilterMultiSelectConfigMeta=Ur,j.FilterSelectConfigMeta=Yr,j.FilterTextInputConfigMeta=Kr,j.FilterTreeSelectConfigMeta=Xr,j.FiltersModel=gc,j.FiltersRenderModel=ci,j.FullScreenPanel=lc,j.FullScreenPanelContext=qs,j.GlobalSQLSnippetMeta=Ol,j.GlobalSQLSnippetsMeta=si,j.LayoutItemMeta=Sl,j.LayoutSetMeta=kl,j.LayoutStateContext=En,j.LayoutsRenderModel=hi,j.MockContextMeta=Gr,j.MuteQueryModel=Ul,j.Panel=oc,j.PanelContextProvider=Bs,j.PanelErrorOrStateMessage=ic,j.PanelMeta=wl,j.PanelModel=vc,j.PanelRender=xi,j.PanelRenderModel=oi,j.PanelStyleMeta=bl,j.PanelTitleMeta=vl,j.PanelVizMeta=jl,j.PanelVizSection=gi,j.PanelsModel=_c,j.PanelsRenderModel=li,j.QueriesModel=yc,j.QueriesRenderModel=pi,j.QueryMeta=Cl,j.QueryModel=xc,j.QueryRenderModel=di,j.ReadOnlyDashboard=ID,j.SQLSnippetMeta=Tl,j.SQLSnippetRenderModel=Jl,j.SQLSnippetsModel=bc,j.SQLSnippetsRenderModel=mi,j.VariableMeta=_l,j.ViewComponentTypeBackground=fc,j.ViewComponentTypeColor=XS,j.ViewComponentTypeName=JS,j.ViewDivisionConfig=Hr,j.ViewMeta=ql,j.ViewModalConfig=ei,j.ViewRenderModel=ii,j.ViewTabsConfig=ti,j.ViewsModel=jc,j.ViewsRenderModel=ai,j.Viz=rc,j.applyPartialDashboard=uk,j.configureAPIClient=Ss,j.createContentModel=wc,j.createContentRenderModel=Uc,j.createContextMeta=ri,j.createDashboardModel=Sc,j.createDashboardRenderModel=Kc,j.createDraft=Hl,j.createFilterCheckboxConfig=Dl,j.createFilterDateRangeConfig=Ml,j.createFilterMultiSelectConfig=Il,j.createFilterSelectConfig=El,j.createFilterTextInputConfig=Jr,j.createFilterTreeSelectConfig=Al,j.createViewDivisionConfig=Pl,j.createViewModalConfig=$l,j.createViewTabsConfig=Bl,j.facadeApiClient=ma,j.formatSQLSnippet=xn,j.getInitialDashboardViewsModel=bi,j.getInitialFiltersConfig=ui,j.getInitialMockContextMeta=Fr,j.getInitialQueriesRenderModel=Yl,j.getInitialSQLSnippetsRenderModel=Xl,j.getInitialViewsRenderModel=Vl,j.getNewPanel=Fl,j.getVersion=ED,j.initialDashboardContent=mS,j.useDashboardContext=As,j.useDashboardThemeContext=Da,j.useEditContentModelContext=U,j.useEditDashboardContext=H,j.useEditPanelContext=$e,j.useFullScreenPanelContext=Aa,j.usePanelFullScreen=cc,j.useRenderContentModelContext=de,j.useRenderDashboardContext=ka,j.useRenderPanelContext=pt,Object.defineProperty(j,Symbol.toStringTag,{value:"Module"})});
481
+ `)},BT=S.observer(({queryModel:t})=>{const{t:e}=_.useTranslation();return t.typedAsSQL?s.jsxs(o.Tabs,{defaultValue:"Edit",orientation:"vertical",sx:{flexGrow:1},styles:{tabLabel:{width:"100%",height:"28px",lineHeight:"28px"}},keepMounted:!1,children:[s.jsxs(o.Tabs.List,{children:[s.jsx(o.Tabs.Tab,{value:"Edit",children:s.jsx(o.Group,{spacing:14,position:"apart",children:e("query.edit_sql")})}),s.jsx(o.Tabs.Tab,{value:"Preview",children:e("query.preview_sql")}),s.jsx(o.Tabs.Tab,{value:"pre_process",children:e("query.process_request")}),s.jsx(o.Tabs.Tab,{value:"post_process",children:e("query.process_result")}),s.jsx(Di,{}),t.datasource&&s.jsx(Nc,{dataSource:t.datasource})]}),s.jsx(o.Tabs.Panel,{value:"Edit",sx:{position:"relative"},p:"sm",children:s.jsx(AT,{queryModel:t})}),s.jsx(o.Tabs.Panel,{value:"Preview",p:0,pl:4,children:s.jsx($T,{value:t.sql})}),s.jsx(o.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:s.jsx(Qt,{label:"",value:t.pre_process,onChange:t.setPreProcess,defaultValue:Qc.pre})}),s.jsx(o.Tabs.Panel,{value:"post_process",p:"sm",children:s.jsx(Qt,{label:"",value:t.post_process,onChange:t.setPostProcess,defaultValue:Qc.post})})]}):null}),qT={pre:["function transform(queries, state, utils) {"," // use queries & dashboar state to build new data"," const data = []"," return data","}"].join(`
482
+ `),post:""},LT=S.observer(({queryModel:t})=>{const{t:e}=_.useTranslation(),n=U();return t.isTransform?s.jsxs(o.Stack,{py:20,px:20,sx:{height:"100%"},children:[s.jsx(o.Text,{size:"sm",children:e("query.transform.guide.pick_queries")}),s.jsx(o.MultiSelect,{data:n.queries.optionsWithoutTransform,value:[...t.dep_query_ids],onChange:t.setDependantQueryIDs,maxDropdownHeight:800}),s.jsx(o.Text,{size:"sm",children:e("query.transform.guide.write_function")}),s.jsx(o.Box,{sx:{flexGrow:1},children:s.jsx(Qt,{label:"",value:t.pre_process,onChange:t.setPreProcess,defaultValue:qT.pre})})]}):null}),bn={height:"calc(100% - 44px)",padding:0},OT=S.observer(({queryModel:t})=>{const{t:e}=_.useTranslation(),n=U(),r=m.useMemo(()=>t.datasource?t.typedAsHTTP?"HTTP":"SQL":"Configurations",[t.datasource,t.typedAsHTTP]),[i,a]=m.useState(r);m.useEffect(()=>{a(u=>u!=="Configurations"&&r==="Configurations"?"Configurations":u)},[r]);const l=n.findQueryUsage(t.id),c=l.length===0;return s.jsxs(o.Tabs,{value:i,onTabChange:a,defaultValue:r,orientation:"horizontal",keepMounted:!1,sx:{height:"100vh"},children:[s.jsxs(o.Tabs.List,{grow:!0,children:[s.jsx(o.Tabs.Tab,{value:"Configurations",children:e("query.configurations")}),t.typedAsSQL&&s.jsx(o.Tabs.Tab,{value:"SQL",children:e("query.request")}),t.typedAsHTTP&&s.jsx(o.Tabs.Tab,{value:"HTTP",children:e("query.request")}),t.isTransform&&s.jsx(o.Tabs.Tab,{value:"Transform",children:e("query.transform.label")}),s.jsx(o.Tabs.Tab,{value:"Data",disabled:!t.canPreviewData,children:s.jsx(o.Tooltip,{label:t.guideToPreviewData,disabled:t.canPreviewData,withinPortal:!0,children:s.jsx(o.Text,{children:e("data.preview_data")})})}),s.jsx(o.Tabs.Tab,{value:"Usage",disabled:c,children:s.jsx(o.Tooltip,{label:e("query.usage.unused_description"),disabled:!c,withinPortal:!0,children:s.jsx(o.Text,{children:e("query.usage.label")})})})]}),s.jsx(o.Tabs.Panel,{value:"Configurations",pt:0,p:0,children:s.jsx(ST,{queryModel:t})}),t.typedAsSQL&&s.jsx(o.Tabs.Panel,{value:"SQL",sx:bn,children:s.jsx(o.Stack,{sx:{height:"100%"},children:s.jsx(BT,{queryModel:t})})}),t.typedAsHTTP&&s.jsx(o.Tabs.Panel,{value:"HTTP",sx:bn,children:s.jsx(o.Stack,{sx:{height:"100%"},children:s.jsx(zT,{queryModel:t})})}),t.isTransform&&s.jsx(o.Tabs.Panel,{value:"Transform",sx:bn,children:s.jsx(o.Stack,{sx:{height:"100%"},children:s.jsx(LT,{queryModel:t})})}),s.jsx(o.Tabs.Panel,{value:"Data",sx:{...bn,overflow:"hidden"},children:s.jsx(Si,{id:t.id,moreActions:null,refreshOnMount:!0})}),s.jsx(o.Tabs.Panel,{value:"Usage",sx:{...bn,overflow:"hidden"},children:s.jsx(MT,{queryID:t.id,usage:l})})]})}),VT=S.observer(({id:t})=>{const n=U().queries.findByID(t);return t===""?null:n?s.jsx(OT,{queryModel:n}):s.jsx(o.Text,{size:14,color:"red",children:"Invalid Query ID"})}),NT=S.observer(({value:t})=>{const n=de().payloadForSQL,r=m.useMemo(()=>Cs(t,n),[t,n]);return s.jsx(zi,{height:"100%",value:r})}),GT=S.observer(({item:t,remove:e,onKeyChanged:n})=>{const{t:r}=_.useTranslation(),[i,a]=m.useState("SQL"),[l,c]=m.useState(t.key),u=()=>{t.setKey(l),n(l)},d=l!==t.key,p=t.isADuplicatedKey(l),[h,g]=m.useState(t.value),y=()=>{t.setValue(h)};m.useEffect(()=>{c(t.key),g(t.value)},[t]);const v=h!==t.value,C=Le.useModals(),T=()=>{C.openConfirmModal({title:`${r("sql_snippet.delete")}?`,labels:{confirm:r("common.actions.confirm"),cancel:r("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:e,confirmProps:{color:"red"},zIndex:320})};return s.jsxs(o.Stack,{p:20,sx:{maxWidth:"1100px",height:"100vh"},spacing:"sm",children:[s.jsxs(o.Group,{sx:{alignItems:"end"},spacing:40,children:[s.jsx(o.TextInput,{label:r(p?"sql_snippet.key_occupied":"sql_snippet.key"),value:l,onChange:D=>{c(D.currentTarget.value)},sx:{flexGrow:"1 !important"},rightSection:s.jsx(o.ActionIcon,{color:"blue",variant:"subtle",onClick:u,disabled:!d||p,children:s.jsx(B.DeviceFloppy,{size:16})}),error:p}),s.jsx(o.Button,{leftIcon:s.jsx(B.Trash,{size:16}),color:"red",variant:"light",onClick:T,children:r("sql_snippet.delete")})]}),s.jsxs(o.Tabs,{value:i,onTabChange:a,sx:{flexGrow:1},styles:{panel:{height:"calc(100% - 50px)"}},children:[s.jsxs(o.Tabs.List,{sx:{position:"relative"},children:[s.jsx(o.Tabs.Tab,{value:"SQL",children:r("sql_snippet.edit_snippet")}),s.jsx(o.Tabs.Tab,{value:"Preview",children:r("sql_snippet.preview_snippet")}),s.jsx(Di,{}),s.jsx(o.ActionIcon,{color:"blue",variant:"filled",onClick:y,disabled:!v,sx:{position:"absolute",top:0,right:10},children:s.jsx(B.DeviceFloppy,{size:18})})]}),s.jsx(o.Tabs.Panel,{value:"SQL",pt:"sm",children:s.jsx(zi,{height:"100%",value:h,onChange:g,defaultLanguage:"sql",theme:"sql-dark"})}),s.jsx(o.Tabs.Panel,{value:"Preview",pt:"sm",children:s.jsx(NT,{value:h})})]})]})}),FT=S.observer(({id:t})=>{const e=H(),n=U(),r=m.useMemo(()=>n.sqlSnippets.findByKey(t),[t]);if(!t)return null;if(!r)return s.jsxs(o.Text,{size:14,children:["SQL Snippet by key[",t,"] is not found"]});const i=()=>{e.editor.setPath(["_SQL_SNIPPETS_",""])},a=()=>{n.sqlSnippets.removeByKey(t),i()},l=c=>{e.editor.setPath(["_SQL_SNIPPETS_",c])};return s.jsx(GT,{item:r,remove:a,onKeyChanged:l})}),WT=S.observer(()=>{const{t}=_.useTranslation(),[e,n]=m.useState([]),r=Le.useModals(),i=H(),a=g=>{i.editor.setPath(["_SQL_SNIPPETS_",g])},l=()=>{r.openConfirmModal({title:"Delete ununsed SQL snippets?",children:s.jsx(o.Text,{size:"sm",children:"This action cannot be undone."}),labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>i.content.removeUnusedSQLSnippets(),confirmProps:{color:"red"},zIndex:320})},c=()=>{i.content.sqlSnippets.downloadSchema(e)},u=m.useMemo(()=>i.content.sqlSnippets.sortedList.map(g=>g.key),[i.content.sqlSnippets.sortedList]),d=()=>{n(u)},p=()=>{n([])},h=i.content.sqlSnippetsUsage;return s.jsxs(o.Stack,{sx:{height:"100%"},spacing:"sm",pb:"59px",children:[s.jsx(o.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:s.jsx(o.Text,{px:"md",align:"left",sx:{userSelect:"none",cursor:"default"},children:t("sql_snippet.manage")})}),s.jsxs(o.Flex,{justify:"space-between",align:"center",px:12,children:[s.jsxs(o.Group,{position:"left",children:[s.jsxs(o.Button.Group,{children:[s.jsx(o.Button,{variant:"default",size:"xs",onClick:d,children:t("common.actions.select_all")}),s.jsx(o.Button,{variant:"default",size:"xs",onClick:p,children:t("common.actions.clear_selection")})]}),s.jsx(o.Button,{size:"xs",color:"blue",leftIcon:s.jsx(k.IconCode,{size:14}),disabled:e.length===0,onClick:c,children:t("common.actions.download_schema")})]}),s.jsx(o.Button,{variant:"subtle",size:"xs",color:"red",leftIcon:s.jsx(k.IconTrash,{size:14}),disabled:!i.content.hasUnusedSQLSnippets,onClick:l,children:t("sql_snippet.delete_unused")})]}),s.jsx(o.Box,{sx:{flexGrow:1,overflow:"auto"},children:s.jsx(o.Checkbox.Group,{size:"xs",value:e,onChange:n,children:s.jsxs(o.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:t("common.key")}),s.jsx("th",{style:{width:"100px",textAlign:"center"},children:t("sql_snippet.usage.label")}),s.jsx("th",{style:{width:"300px",paddingLeft:"24px"},children:t("common.action")})]})}),s.jsx("tbody",{children:i.content.sqlSnippets.sortedList.map(g=>{var v;const y=((v=h[g.key])==null?void 0:v.length)??0;return s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx(o.Checkbox,{value:g.key,styles:{input:{cursor:"pointer"}}})}),s.jsx("td",{children:g.key}),s.jsx("td",{style:{color:y===0?"#ff0000":"#000",fontWeight:y===0?"bold":"normal",textAlign:"center"},children:y}),s.jsx("td",{children:s.jsx(o.Button,{variant:"subtle",size:"xs",onClick:()=>a(g.key),children:t("common.actions.open")})})]},g.key)})})]})})})]})}),QT=S.observer(({view:t})=>!t||t.type!==q.Division?null:s.jsx(o.Stack,{})),RT=S.observer(({view:t})=>{const{t:e,i18n:n}=_.useTranslation(),r=m.useMemo(()=>[{value:"default",label:e("common.tabs.variant.default")},{value:"outline",label:e("common.tabs.variant.outline")},{value:"pills",label:e("common.tabs.variant.pills")}],[n.language]),i=m.useMemo(()=>[{value:"horizontal",label:e("common.tabs.orientation.horizontal")},{value:"vertical",label:e("common.tabs.orientation.vertical")}],[n.language]);if(!t||t.type!==q.Tabs)return null;const a=t.config;return s.jsxs(o.Stack,{children:[s.jsx(o.Divider,{mt:8,mb:0,label:e("view.component.tabs.tabs_settings"),labelPosition:"center"}),s.jsx(o.Select,{label:e("common.tabs.variant.label"),value:a.variant,onChange:a.setVariant,data:r}),s.jsx(o.Select,{label:e("common.tabs.orientation.label"),value:a.orientation,onChange:a.setOrientation,data:i}),s.jsx(o.Switch,{label:e("common.tabs.grow_tabs"),checked:a.grow,onChange:l=>a.setGrow(l.currentTarget.checked)})]})}),UT=({disabled:t,value:e,onChange:n})=>{const r=i=>{i&&n(i)};return s.jsxs(o.Box,{sx:{position:"relative"},children:[t&&s.jsx(o.Overlay,{opacity:.6,color:"#fff",zIndex:5,blur:2}),s.jsx(Pe,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:t}})]})},YT=({value:t,onChange:e})=>{const{t:n}=_.useTranslation(),[r,{setTrue:i,setFalse:a}]=N.useBoolean(),[l,c]=m.useState(t??ls),u=y=>{c({...l,enabled:y})},d=()=>{a();const{enabled:y,func_content:v}=l,C={enabled:y,func_content:v};c(C),e(C)},p=()=>{a(),c(t)},h=y=>{c(v=>({...v,func_content:y}))},g=()=>{h(ls.func_content)};return s.jsxs(s.Fragment,{children:[s.jsx(o.ActionIcon,{size:"lg",color:"blue",variant:"filled",mt:26,onClick:i,sx:{flexGrow:0},children:s.jsx(B.Settings,{size:14})}),s.jsx(o.Modal,{size:800,title:n("view.component.modal.custom_title"),opened:r,onClose:a,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:r&&s.jsxs(o.Stack,{children:[s.jsx(o.Checkbox,{mt:10,label:n("common.enabled"),checked:l.enabled,onChange:y=>u(y.currentTarget.checked)}),s.jsx(UT,{value:l.func_content,onChange:h,disabled:!l.enabled}),s.jsxs(o.Group,{position:"apart",children:[s.jsx(o.Button,{onClick:g,color:"red",leftIcon:s.jsx(B.Recycle,{size:20}),children:n("common.actions.revert")}),s.jsxs(o.Group,{position:"right",children:[s.jsx(o.Button,{onClick:p,variant:"subtle",children:n("common.actions.cancel")}),s.jsx(o.Button,{onClick:d,children:n("common.actions.save")})]})]})]})})]})},KT=S.observer(({view:t})=>{const{t:e}=_.useTranslation();if(!t||t.type!==q.Modal)return null;const n=t.config,r=n.custom_modal_title.value;return s.jsxs(o.Stack,{children:[s.jsx(o.Divider,{mt:8,label:e("view.component.modal.modal_settings"),labelPosition:"center"}),s.jsxs(o.Flex,{gap:10,children:[s.jsx(o.TextInput,{label:e("view.component.modal.title"),value:r,onChange:x.noop,disabled:!0,sx:{flexGrow:1}}),s.jsx(YT,{value:n.custom_modal_title,onChange:n.custom_modal_title.replace})]}),s.jsxs(o.Group,{grow:!0,children:[s.jsx(o.TextInput,{label:e("view.component.modal.width"),value:n.width,onChange:i=>n.setWidth(i.currentTarget.value),placeholder:"600px / 50vw"}),s.jsx(o.TextInput,{label:e("view.component.modal.height"),value:n.height,onChange:i=>n.setHeight(i.currentTarget.value),placeholder:"600px / 50vw"})]})]})}),JT=S.observer(({view:t})=>s.jsxs(s.Fragment,{children:[s.jsx(QT,{view:t}),s.jsx(KT,{view:t}),s.jsx(RT,{view:t})]})),XT=S.observer(({view:t})=>{const{t:e,i18n:n}=_.useTranslation(),r=m.useMemo(()=>[{label:e("view.component.div.label"),value:q.Division},{label:e("view.component.modal.label"),value:q.Modal},{label:e("view.component.tabs.label"),value:q.Tabs}],[n.language]);return t?s.jsxs(o.Stack,{sx:{position:"relative"},children:[s.jsx(o.TextInput,{label:e("common.name"),value:t.name,onChange:i=>{t.setName(i.currentTarget.value)}}),s.jsx(o.Select,{label:e("common.type"),withinPortal:!0,zIndex:320,value:t.type,onChange:t.setType,data:r}),s.jsx(JT,{view:t})]}):null}),ZT=S.observer(({id:t})=>{const{t:e}=_.useTranslation(),n=Le.useModals(),r=H(),i=U();if(t==="")return null;const a=i.views.findByID(t);if(!a)return s.jsxs(o.Text,{size:14,children:["View by ID[",t,"] is not found"]});const l=()=>{r.editor.setPath(["_VIEWS_",""])},c=()=>{n.openConfirmModal({title:`${e("view.delete")}?`,labels:{confirm:e("common.actions.confirm"),cancel:e("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{i.views.removeByID(t),l()},zIndex:320})};return s.jsxs(o.Stack,{sx:{maxWidth:"600px",height:"100%"},spacing:"sm",children:[s.jsx(o.Group,{position:"right",pt:10,children:s.jsx(o.Button,{size:"xs",color:"red",leftIcon:s.jsx(B.Trash,{size:16}),onClick:c,children:e("view.delete")})}),s.jsx(o.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:s.jsx(XT,{view:a})})]})});function HT(t){return t.length===1&&t[0]==="_QUERY_VARS_"}function eD(t){return t.length===1&&t[0]==="_MOCK_CONTEXT_"}function tD(t){return t.length===1&&t[0]==="_FILTERS_"}function nD(t){return t.length===2&&t[0]==="_FILTERS_"}function sD(t){return t.length===1&&t[0]==="_SQL_SNIPPETS_"}function rD(t){return t.length===2&&t[0]==="_SQL_SNIPPETS_"}function iD(t){return t.length===2&&t[0]==="_QUERIES_"}function aD(t){return t.length===1&&t[0]==="_QUERIES_"}function oD(t){return t.length===2&&t[0]==="_VIEWS_"}function lD(t){return t.length===4&&t[0]==="_VIEWS_"&&t[2]==="_PANELS_"}const cD=S.observer(()=>s.jsx(o.Stack,{sx:{height:"100%"},p:"sm",children:s.jsx(Fc,{})})),uD=S.observer(()=>{const t=H().editor,e=t.path;return HT(e)?s.jsx(cD,{}):eD(e)?s.jsx(_1,{}):tD(e)?s.jsx(v1,{}):nD(e)?s.jsx(o.Box,{p:"xs",pl:20,children:s.jsx(b1,{id:e[1]})}):sD(e)?s.jsx(WT,{}):rD(e)?s.jsx(FT,{id:e[1]}):aD(e)?s.jsx(rT,{}):iD(e)?s.jsx(VT,{id:e[1]}):oD(e)?s.jsx(o.Box,{p:"xs",pl:20,children:s.jsx(ZT,{id:e[1]})}):lD(e)?s.jsx(sT,{viewID:e[1],panelID:e[3]}):s.jsx(o.Box,{children:t.path})}),dD=S.observer(()=>s.jsx(uD,{})),pD=S.observer(()=>{const{t}=_.useTranslation(),e=H(),n=()=>{const r=new Date().getTime().toString(),i={id:r,key:r,label:r,order:e.content.filters.current.length+1,type:he.TextInput,config:Jr(),visibleInViewsIDs:["Main"],auto_submit:!1};e.content.filters.append(i),e.editor.setPath(["_FILTERS_",r])};return s.jsx(o.Button,{variant:"subtle",leftIcon:s.jsx(k.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:n,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:t("filter.add")})}),hD=S.observer(({parentID:t})=>{const{t:e}=_.useTranslation(),n=U();if(!t)return null;const r=n.views.findByID(t);return!r||r.type===q.Tabs?null:s.jsx(o.Button,{variant:"subtle",leftIcon:s.jsx(k.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:()=>n.addANewPanel(r.id),sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:e("panel.add")})}),mD=S.observer(()=>{const{t}=_.useTranslation(),e=H(),n=()=>{const r=new Date().getTime().toString(),i={id:r,name:r,type:ce.Postgresql,key:"",sql:""};e.content.queries.append(i),e.editor.setPath(["_QUERIES_",r])};return s.jsx(o.Button,{variant:"subtle",leftIcon:s.jsx(k.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:n,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:t("query.add")})}),fD=S.observer(()=>{const{t}=_.useTranslation(),e=H(),n=()=>{const r=new Date().getTime().toString(),i={key:r,value:""};e.content.sqlSnippets.append(i),e.editor.setPath(["_SQL_SNIPPETS_",r])};return s.jsx(o.Button,{variant:"subtle",leftIcon:s.jsx(k.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:n,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:t("sql_snippet.add")})}),gD=S.observer(()=>{const{t}=_.useTranslation(),e=U();return s.jsx(o.Button,{variant:"subtle",leftIcon:s.jsx(k.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:e.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:t("view.add")})}),xD=S.observer(()=>{const{t}=_.useTranslation(),e=H();return s.jsx(o.Button,{variant:"subtle",rightIcon:s.jsx(k.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>e.editor.setPath(["_QUERIES_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:t("query.manage")})}),yD=S.observer(()=>{const{t}=_.useTranslation(),e=H();return s.jsx(o.Button,{variant:"subtle",rightIcon:s.jsx(k.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>e.editor.setPath(["_SQL_SNIPPETS_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:t("sql_snippet.manage")})}),bD=S.observer(()=>{const{t}=_.useTranslation(),e=H();return s.jsx(o.Button,{variant:"subtle",rightIcon:s.jsx(k.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>e.editor.setPath(["_FILTERS_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:t("filter.manage")})}),vD=S.observer(({action_type:t,parentID:e})=>t==="_Add_A_Filter_"?s.jsx(pD,{}):t==="_Add_A_SQL_SNIPPET_"?s.jsx(fD,{}):t==="_Add_A_QUERY_"?s.jsx(mD,{}):t==="_Add_A_VIEW_"?s.jsx(gD,{}):t==="_Add_A_PANEL_"?s.jsx(hD,{parentID:e}):t==="_QUERIES_SETTINGS_"?s.jsx(xD,{}):t==="_SQL_SNIPPETS_SETTINGS_"?s.jsx(yD,{}):t==="_FILTERS_SETTINGS_"?s.jsx(bD,{}):null),Rc=S.observer(({option:t})=>{var p;const{t:e}=_.useTranslation(),n=H().editor,r=n.isOptionActive,i=r(n.path,t),a=n.isOptionOpened,l=n.navigate,c=a(t),[u,d]=m.useState(c);return m.useEffect(()=>{d(c)},[c]),s.jsx(o.NavLink,{active:i,defaultOpened:c,opened:u,onChange:d,label:e(t.label),onClick:()=>l(t),icon:t.Icon?s.jsx(t.Icon,{size:18}):null,children:(p=t.children)==null?void 0:p.map(h=>h._type==="ACTION"?s.jsx(vD,{action_type:h._action_type,parentID:h.parentID},`_ADD_${h.value}_`):s.jsx(Rc,{option:h},h.value))},t.label)}),_D=S.observer(()=>{const t=H();return s.jsx(o.Box,{sx:{position:"relative"},children:t.editor.navOptions.map(e=>s.jsx(Rc,{option:e},e.value))})}),jD=S.observer(()=>{const{t}=_.useTranslation(),e=H();return s.jsxs(o.Navbar,{p:0,width:{base:220,xs:220,sm:240,md:260,lg:300,xl:320},sx:{height:"100vh - 60px - 60px",".mantine-NavLink-body":{wordWrap:"break-word"}},children:[s.jsx(o.Navbar.Section,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:s.jsx(o.Text,{align:"center",sx:{userSelect:"none",cursor:"default"},children:t("common.titles.settings")})}),s.jsx(o.Navbar.Section,{grow:!0,sx:{overflow:"auto"},children:s.jsx(_D,{})}),s.jsx(o.Navbar.Section,{children:s.jsx(o.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:s.jsx(o.Button,{size:"xs",color:"red",leftIcon:s.jsx(k.IconX,{size:18}),onClick:()=>e.editor.close(),children:t("common.actions.close")})})})]})}),wD={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden",minWidth:"calc(var(--mantine-navbar-width, 0px) + 1200px)"},body:{flexGrow:1,nav:{top:0,height:"100vh"}},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:0,height:"100vh"}},CD=S.observer(()=>{const t=H().editor;return s.jsx(o.Modal,{onClose:()=>t.setSettingsOpen(!1),closeOnEscape:!1,closeOnClickOutside:!1,opened:t.settings_open,fullScreen:!0,title:null,transitionProps:{duration:0},withCloseButton:!1,withinPortal:!0,zIndex:300,styles:{body:{padding:"0 !important"},content:{overflowY:"hidden !important"}},children:s.jsx(o.AppShell,{padding:0,navbar:s.jsx(jD,{}),styles:wD,children:s.jsx(dD,{})})})}),SD=t=>t.replace(/([^:])(\/\/+)/g,"$1/");function kD(t){m.useEffect(()=>{if(Pe.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/dashboard");const n=SD(t);Pe.loader.config({paths:{vs:n}}),Pe.loader.init().then(r=>console.log("monaco instance:",r))},[])}xa(),ba();const TD={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden"},body:{flexGrow:1},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:60+30,height:"100vh"}},DD=({context:t,dashboard:e,content:n,update:r,className:i="dashboard",config:a,onChange:l,headerSlot:c,filterValues:u,onFilterValuesChange:d,onExit:p,lang:h},g)=>{kD(a.monacoPath),Ss(a);const{data:y=[]}=N.useRequest(zs),{data:v=[]}=N.useRequest(va),C=m.useMemo(()=>Sc(e,n,y,v,t,u??{}),[e,n]);m.useImperativeHandle(g,()=>C,[C]),Tc(C.content,!0),m.useEffect(()=>{C.context.replace(t)},[t]),m.useEffect(()=>{C.datasources.replace(y)},[y]),m.useEffect(()=>{C.globalSQLSnippets.replace(v)},[v]),m.useEffect(()=>{d==null||d(C.content.filters.values)},[d,C.content.filters.values]),m.useEffect(()=>{u&&C.content.filters.patchValues(u)},[u,C.content.filters.patchValues]),m.useEffect(()=>K.reaction(()=>K.toJS(C.json),P=>{l==null||l(P)}),[C]);const T=async()=>{await r(C.json,C.content.json)},D=N.useCreation(Lr,[]),I=Dc(D);return s.jsx(kc,{lang:h,children:s.jsx(Le.ModalsProvider,{children:s.jsx(Ls,{children:s.jsx(Ps,{value:{searchButtonProps:a.searchButtonProps},children:s.jsx(Es,{value:C,children:s.jsx($s,{value:C.content,children:s.jsx(En.Provider,{value:{inEditMode:!0},children:s.jsx(it.Provider,{value:D,children:s.jsxs(as,{configure:I,children:[s.jsx(o.AppShell,{padding:0,header:s.jsx(Ik,{onExit:p,saveDashboardChanges:T,headerSlot:c}),navbar:s.jsx(r1,{}),styles:TD,children:s.jsx(o.Box,{className:`${i} dashboard-root`,sx:{position:"relative"},children:C.content.views.visibleViews.map(P=>s.jsx(hc,{view:P},P.id))})}),s.jsx(CD,{})]})})})})})})})})})},zD=S.observer(m.forwardRef(DD)),yM="",Mi=f.types.model({id:f.types.string,name:f.types.string,dashboard_id:f.types.string,create_time:f.types.string,update_time:f.types.string,version:f.types.string,filters:ci,queries:pi,sqlSnippets:mi,views:ai,panels:li,layouts:hi,mock_context:Gr}).views(t=>({get json(){return{id:t.id,name:t.name,create_time:t.create_time,update_time:t.update_time,dashboard_id:t.dashboard_id,content:{views:t.views.json,panels:t.panels.json,filters:t.filters.json,version:t.version,layouts:t.layouts.json,definition:{queries:t.queries.json,sqlSnippets:t.sqlSnippets.json,mock_context:t.mock_context.current}}}},get contentJSON(){return this.json.content},get payloadForSQL(){const e=f.getParent(t).context.current,n=f.getParent(t).globalSQLSnippets,r={context:{...t.mock_context.current,...e},filters:t.filters.values};return{...r,sql_snippets:xn(t.sqlSnippets.current,"key","value",r),global_sql_snippets:xn(n.list,"id","content",r)}},get payloadForViz(){const e=f.getParent(t).context.current;return{context:{...t.mock_context.current,...e},filters:t.filters.values}},get dashboardState(){return Ds(this.payloadForSQL)},getAdditionalQueryInfo(e){return{content_id:t.id,query_id:e,params:this.dashboardState}},get data(){return t.queries.current.map(({id:n,data:r})=>({id:n,data:r})).reduce((n,r)=>(n[r.id]=r.data,n),{})},getDataStuffByID(e){const n=t.queries.findByID(e);return n?{data:n.data,len:n.data.length,state:n.state,error:n.error}:{data:[],len:0,state:"idle",error:void 0}}})).actions(t=>({}));function Uc({id:t,name:e,dashboard_id:n,create_time:r,update_time:i,content:a},l,c){if(!a)throw new Error("unexpected null content when creating a content model");const{version:u,filters:d,views:p,panels:h,layouts:g,definition:{queries:y,sqlSnippets:v,mock_context:C={}}}=a;return Mi.create({id:t,name:e,dashboard_id:n,create_time:r,update_time:i,version:u,filters:ui(d,l,C,c),queries:Yl(y),sqlSnippets:Xl(v),mock_context:Fr(C),views:Vl(p),panels:{list:h},layouts:{list:g,currentBreakpoint:g[0].id}})}const Yc=f.types.model({id:f.types.identifier,name:f.types.string,group:f.types.string,content:Mi,content_id:f.types.string,datasources:Ll,globalSQLSnippets:si,context:cs});function Kc({id:t,name:e,group:n,content_id:r},i,a,l,c,u){return Yc.create({id:t,name:e,group:n,content_id:r,content:Uc(i,c,u),datasources:{list:a},globalSQLSnippets:{list:l},context:ri(c)})}xa(),ba();const MD=({context:t,dashboard:e,content:n,className:r="dashboard",config:i,fullScreenPanelID:a,setFullScreenPanelID:l,filterValues:c,onFilterValuesChange:u,lang:d})=>{Ss(i);const{data:p=[]}=N.useRequest(zs),{data:h=[]}=N.useRequest(va),g=m.useMemo(()=>Kc(e,n,p,h,t,c??{}),[e,n]);Tc(g.content,!1),m.useEffect(()=>{g.context.replace(t)},[t]),m.useEffect(()=>{g.datasources.replace(p)},[p]),m.useEffect(()=>{g.globalSQLSnippets.replace(h)},[h]),m.useEffect(()=>{u==null||u(g.content.filters.values)},[u,g.content.filters.values]),m.useEffect(()=>{c&&g.content.filters.patchValues(c)},[c,g.content.filters.patchValues]);const y=N.useCreation(Lr,[]),v=Dc(y);return s.jsx(kc,{lang:d,children:s.jsx(Le.ModalsProvider,{children:s.jsx(Ls,{children:s.jsx(Ps,{value:{searchButtonProps:i.searchButtonProps},children:s.jsx(Es,{value:g,children:s.jsx($s,{value:g.content,children:s.jsx(qs.Provider,{value:{fullScreenPanelID:a,setFullScreenPanelID:l},children:s.jsx(En.Provider,{value:{inEditMode:!1},children:s.jsx(o.Box,{className:`${r} dashboard-root`,children:s.jsx(it.Provider,{value:y,children:s.jsx(as,{configure:v,children:g.content.views.visibleViews.map(C=>s.jsx(ds,{view:C},C.id))})})})})})})})})})})})},ID=S.observer(MD);M.extend(Su),M.extend(ku),M.extend(Tu),M.extend(Du),M.extend(zu),M.extend(Mu),M.extend(Iu),M.extend(Eu),M.extend(Au),M.extend(Pu),M.extend(qu),M.extend(Lu),M.extend(Ou),M.extend(Vu),M.extend(Nu),M.extend($u),M.extend(Bu),M.extend(Gu),M.extend(Fu),M.extend(Wu),M.extend(Qu),M.extend(Ru),M.extend(Uu),M.extend(Yu),M.extend(Ku),M.extend(Ju),M.extend(Xu),M.extend(Zu),M.extend(Hu),M.extend(ed),M.extend(nd),M.extend(sd),M.extend(td),M.tz.setDefault("UTC"),M.updateLocale("en",{weekStart:1});const ED=()=>Promise.resolve().then(()=>Hd).then(({version:t})=>(console.log(`[@devtable/dashboard] version: ${t}`),t));j.APIClient=et,j.CURRENT_SCHEMA_VERSION=ft,j.ContentModel=vi,j.ContentModelContextProvider=$s,j.ContentRenderModel=Mi,j.ContextMeta=cs,j.DEFAULT_CUSTOM_MODAL_TITLE=ls,j.DashboardApiClient=pa,j.DashboardApiFacadeClient=ha,j.DashboardEditor=zD,j.DashboardFilterType=he,j.DashboardMode=mc,j.DashboardModel=Cc,j.DashboardModelContextProvider=Es,j.DashboardRenderModel=Yc,j.DashboardThemeContextProvider=Ps,j.DashboardViewEditor=hc,j.DashboardViewRender=ds,j.DataSourceMetaModel=ni,j.DataSourceType=ce,j.DataSourcesMetaModel=Ll,j.DatesProvider=Ls,j.DefaultApiClient=da,j.DescriptionPopover=fi,j.DraftModel=Zl,j.EViewComponentType=q,j.FacadeApiClient=xd,j.FilterCheckboxConfigMeta=Wr,j.FilterDateRangeConfigMeta=Qr,j.FilterMeta=Zr,j.FilterMultiSelectConfigMeta=Ur,j.FilterSelectConfigMeta=Yr,j.FilterTextInputConfigMeta=Kr,j.FilterTreeSelectConfigMeta=Xr,j.FiltersModel=gc,j.FiltersRenderModel=ci,j.FullScreenPanel=lc,j.FullScreenPanelContext=qs,j.GlobalSQLSnippetMeta=Ol,j.GlobalSQLSnippetsMeta=si,j.LayoutItemMeta=Sl,j.LayoutSetMeta=kl,j.LayoutStateContext=En,j.LayoutsRenderModel=hi,j.MockContextMeta=Gr,j.MuteQueryModel=Ul,j.Panel=oc,j.PanelContextProvider=Bs,j.PanelErrorOrStateMessage=ic,j.PanelMeta=wl,j.PanelModel=vc,j.PanelRender=xi,j.PanelRenderModel=oi,j.PanelStyleMeta=bl,j.PanelTitleMeta=vl,j.PanelVizMeta=jl,j.PanelVizSection=gi,j.PanelsModel=_c,j.PanelsRenderModel=li,j.QueriesModel=yc,j.QueriesRenderModel=pi,j.QueryMeta=Cl,j.QueryModel=xc,j.QueryRenderModel=di,j.ReadOnlyDashboard=ID,j.SQLSnippetMeta=Tl,j.SQLSnippetRenderModel=Jl,j.SQLSnippetsModel=bc,j.SQLSnippetsRenderModel=mi,j.VariableMeta=_l,j.ViewComponentTypeBackground=fc,j.ViewComponentTypeColor=XS,j.ViewComponentTypeName=JS,j.ViewDivisionConfig=Hr,j.ViewMeta=ql,j.ViewModalConfig=ei,j.ViewRenderModel=ii,j.ViewTabsConfig=ti,j.ViewsModel=jc,j.ViewsRenderModel=ai,j.Viz=rc,j.applyPartialDashboard=uk,j.configureAPIClient=Ss,j.createContentModel=wc,j.createContentRenderModel=Uc,j.createContextMeta=ri,j.createDashboardModel=Sc,j.createDashboardRenderModel=Kc,j.createDraft=Hl,j.createFilterCheckboxConfig=Dl,j.createFilterDateRangeConfig=Ml,j.createFilterMultiSelectConfig=Il,j.createFilterSelectConfig=El,j.createFilterTextInputConfig=Jr,j.createFilterTreeSelectConfig=Al,j.createViewDivisionConfig=Pl,j.createViewModalConfig=$l,j.createViewTabsConfig=Bl,j.facadeApiClient=ma,j.formatSQLSnippet=xn,j.getInitialDashboardViewsModel=bi,j.getInitialFiltersConfig=ui,j.getInitialMockContextMeta=Fr,j.getInitialQueriesRenderModel=Yl,j.getInitialSQLSnippetsRenderModel=Xl,j.getInitialViewsRenderModel=Vl,j.getNewPanel=Fl,j.getVersion=ED,j.initialDashboardContent=mS,j.useDashboardContext=As,j.useDashboardThemeContext=Da,j.useEditContentModelContext=U,j.useEditDashboardContext=H,j.useEditPanelContext=$e,j.useFullScreenPanelContext=Aa,j.usePanelFullScreen=cc,j.useRenderContentModelContext=de,j.useRenderDashboardContext=ka,j.useRenderPanelContext=pt,Object.defineProperty(j,Symbol.toStringTag,{value:"Module"})});