@devtable/dashboard 14.43.4 → 14.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/plugins/plugin-context.d.ts +144 -0
- package/dist/contexts/panel-context.d.ts +288 -0
- package/dist/dashboard-editor/model/panels/panel.d.ts +72 -0
- package/dist/dashboard-editor/model/queries/queries.d.ts +135 -0
- package/dist/dashboard-editor/model/queries/query.d.ts +5 -0
- package/dist/dashboard.es.js +528 -520
- package/dist/dashboard.umd.js +5 -5
- package/dist/model/meta-model/dashboard/content/query/merico-metric-query.d.ts +8 -0
- package/dist/model/meta-model/dashboard/content/query/query.d.ts +4 -0
- package/dist/model/render-model/dashboard/content/panels/panel.d.ts +48 -0
- package/dist/model/render-model/dashboard/content/queries/mute-query.d.ts +5 -0
- package/dist/model/render-model/dashboard/content/queries/queries.d.ts +101 -0
- package/dist/model/render-model/dashboard/content/queries/query.d.ts +5 -0
- package/dist/stats.html +1 -1
- package/dist/version.json +2 -2
- package/package.json +20 -20
package/dist/dashboard.umd.js
CHANGED
|
@@ -6,7 +6,7 @@ Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel vari
|
|
|
6
6
|
-- 在富文本中,要使用双重花括号来包裹代码。
|
|
7
7
|
项目ID:{{ context.project_id }}
|
|
8
8
|
搜索关键字:{{ filters.keyword }}
|
|
9
|
-
我的卡片变量: {{ your_var }}`,tabs:{guide:"使用指南",vars:"看板信息与卡片的变量"}}}},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:"以下条件为真时,才运行本查询",description:"为假的情况: 空数组 / NaN / false / 空字符串 / undefined / null",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:"自定义聚合方式"},pick_record:{label:"直接选择数据",method:{label:"数据记录",first:"第一条",last:"最后一条"}}}},rich_text:{label:"富文本",content:{label:"内容"},dynamic_color:{label:"动态颜色",edit:"编辑动态颜色",clear:"清除动态颜色"},color_mapping:{label:"颜色映射",edit:"编辑颜色映射",clear:"清除颜色映射",choose_value_var:"选择用于映射颜色的变量",min:{val:"固定最小值",var:"动态最小值(优先)"},max:{val:"固定最大值",var:"动态最大值(优先)"}}},chart:{chart_config:"图表设置",data_field:"数据字段",groups:{merico_suite:"思码逸套件",echarts_based_charts:"基于ECharts的图表",others:"其他"},unit:{title:"单位",text:{placeholder:"单位文案"},show_in_tooltip:"在提示框中显示单位",show_in_legend:"在图例中显示单位"},series_order:{label:"排序依据",name:"名称",value:"值",raw:"不排序,保持数据本身的顺序",asc:"升序",desc:"降序"},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:"视觉映射",continuous:{label:"连续型"},piecewise:{label:"分段型",mode:{pieces:"连续数据",categories:"离散数据"},add_a_piece:"加一个分段",interval:"值区间",piece_label:"文案"},bar_width:"长条的宽度",bar_height:"长条的高度",item_width:"小块的宽度",item_height:"小块的高度",calculable:"显示拖拽手柄",min_value:"最小值",max_value:"最大值",min_text:"最小值文案",max_text:"最大值文案",use_palette_x:'使用配色方案"{{x}}"',built_in_palettes:"内置配色方案",precision:"数据精度",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:"显示标记点",area_style:{label:"区域填充样式",enabled:"启用区域填充",color:"填充颜色",use_series_color:"沿用系列本色",origin:{label:"图形区域的起始位置",auto:{label:"自动",description:"填充坐标轴线到数据间的区域(默认)"},start:{label:"自下而上",description:"填充坐标轴底部到数据间的区域"},end:{label:"自上而下",description:"填充坐标轴顶部到数据间的区域"}},shadow_blur:"图形阴影的模糊大小",shadow_color:"图形阴影的颜色",shadow_offset_x:"阴影水平方向上的偏移距离",shadow_offset_y:"阴影垂直方向上的偏移距离",opacity:"图形透明度"}},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轴数据字段",inverse:"反向坐标轴",layout:"布局",position:{label:"位置",left:"左",right:"右"},value_range:"值范围",value_min:"最小值",value_max:"最大值",behavior:"表现",visible:"可见",mirror:{label:"上下镜像"}},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:"颜色",background_color:"背景色",text_color:"文字颜色",click_to_add_a_color:"点击增加一个颜色",color_gradient:"颜色渐变",not_set:"未设置"},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:"请填写一个数字"}},spotlight:{trigger_text:"搜索",main_group:"主要项",placeholder:"打开…",not_found:"无匹配项"}}};class Jt{constructor(t){P(this,"rootRef");this.rootRef=Q.observable({current:t})}async deleteItem(t){Q.runInAction(()=>{y.unset(this.rootRef.current,[t])})}getItem(t){const r=this.getValueFromRoot(t);return Promise.resolve(r)}getValueFromRoot(t){return t===null?Q.toJS(this.rootRef.current):y.get(this.rootRef.current,[t])}setItem(t,r){if(t===null)if(y.isObject(r))Q.runInAction(()=>{this.rootRef.current=r});else throw new Error("Cannot set root value to non-object");else Q.runInAction(()=>{y.set(this.rootRef.current,[t],r)});return Promise.resolve(this.getItem(t))}watchItem(t,r,a){return Q.reaction(()=>this.getValueFromRoot(t),(l,o)=>{r(l,o)},{requiresObservable:!0,fireImmediately:y.get(a,"fireImmediately",!1)})}}class Zd{constructor(){P(this,"channels",new Map);P(this,"globalChannel",new Xa)}getChannel(t){const r=this.channels.get(t);if(r)return r;const a=new Xa;return this.channels.set(t,a),a}}class Jd{constructor(t){P(this,"instances",new Map);this.pluginManager=t}get availableVizList(){return this.pluginManager.installedPlugins.flatMap(t=>t.manifest.viz)}resolveComponent(t){return this.pluginManager.factory.viz(t)}getOrCreateInstance(t){const r=this.instances.get(t.id);if(r)return r;const a={id:t.id,name:t.viz.type,type:t.viz.type,messageChannels:new Zd,instanceData:new Jt(t.viz.conf)};return this.instances.set(t.id,a),a}}function _s(e,t,r,a){return{vizManager:r,locale:"zh",msgChannels:e.messageChannels,instanceData:e.instanceData,pluginData:new Jt({}),colorPalette:{getColor(){return()=>""}},data:t,variables:a}}const Hd=e=>{const{panel:t,measure:r,vizManager:a,data:l,variables:o}=e,i=a.resolveComponent(t.viz.type),c=a.getOrCreateInstance(t),d={..._s(c,l,a,o),viewport:{width:r.w,height:r.h}},u=i.viewRender;return n.jsx(u,{context:d,instance:c,...y.omit(e,["panel","vizManager","data"])})},Rd=e=>{const{vizManager:t,panel:r,data:a,variables:l}=e,o=t.resolveComponent(r.viz.type),i=t.getOrCreateInstance(r),c={..._s(i,a,t,l)},d=o.configRender;return n.jsx(d,{context:c,instance:i,...y.omit(e,["panel","vizManager","data"])})},xs=(e,t)=>{const r=qe.bezier(e),a=qe.bezier(t);return function(l){return l<50?r(l*2/100).hex():a((l-50)*2/100).hex()}},Ht=e=>{const t=qe.bezier(e);return function(r){return t(r/100).hex()}},eu={type:"interpolation",displayName:"style.color.interpolation.palette.red_green",getColor:xs(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},tu={type:"interpolation",displayName:"style.color.interpolation.palette.yellow_blue",getColor:xs(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},nu={type:"interpolation",displayName:"style.color.interpolation.palette.red",getColor:Ht(["#fff7f1","darkred"]),name:"red",category:"sequential"},ru={type:"interpolation",displayName:"style.color.interpolation.palette.green",getColor:Ht(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},au={type:"interpolation",displayName:"style.color.interpolation.palette.blue",getColor:Ht(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},su={type:"interpolation",displayName:"style.color.interpolation.palette.orange",getColor:Ht(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class lu{constructor(t){P(this,"symbol");this.symbol=Symbol(t)}}function Je(e){return new lu(e)}class qn{constructor(){P(this,"parent");P(this,"factoryRegistry",new Map);P(this,"instanceRegistry",new Map)}createScoped(){const t=new qn;return t.parent=this,t}getRequired(t){return this.get(t)}get(t){if(this.instanceRegistry.has(t.symbol))return this.instanceRegistry.get(t.symbol);const r=this.factoryRegistry.get(t.symbol);if(r){const a=r(this);return this.instanceRegistry.set(t.symbol,a),a}if(this.parent)return this.parent.get(t)}provideFactory(t,r){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,r),this}provideValue(t,r){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,()=>r),this}dispose(){this.instanceRegistry.forEach(t=>{const r=y.get(t,"dispose");y.isFunction(r)&&r.bind(t)()}),this.instanceRegistry.clear(),this.factoryRegistry.clear()}}class ou{constructor(t){this.pluginManager=t}createPanelAddonNode(t){const a=this.pluginManager.installedPlugins.flatMap(l=>l.manifest.panelAddon).filter(l=>!!l).map(l=>h.createElement(l.addonRender,{...t,key:l.name}));return n.jsx(n.Fragment,{children:a})}}const ws=h.createContext({addonSlotId:null});function ms({children:e}){const t=`panel-addon-slot-${h.useId()}`;return n.jsxs(ws.Provider,{value:{addonSlotId:t},children:[n.jsx("div",{style:{position:"static",top:0,left:0},id:t}),e]})}function iu(){const{addonSlotId:e}=h.useContext(ws);return e?document.getElementById(e):null}const Cs="14.43.4",cu=Object.freeze(Object.defineProperty({__proto__:null,version:Cs},Symbol.toStringTag,{value:"Module"}));class du{constructor(t){P(this,"staticColors",new Map);P(this,"interpolations",new Map);t.installedPlugins.forEach(r=>{r.manifest.color.forEach(a=>{this.register(a)})})}getStaticColors(){return Array.from(this.staticColors.values())}register(t){const r=this.encodeColor(t);t.type==="single"?(this.staticColors.has(r)&&console.warn(`the color '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.staticColors.set(r,t)):t.type==="interpolation"&&(this.interpolations.has(r)&&console.warn(`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`,`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.interpolations.set(r,t))}decodeStaticColor(t){return this.staticColors.get(t)}encodeColor(t){return`\${${t.category}}.{${t.name}}`}decodeInterpolation(t){return this.interpolations.get(t)}getColorInterpolations(){return Array.from(this.interpolations.values())}}class uu{constructor(){P(this,"plugins",new Map);P(this,"vizComponents",new Map);P(this,"factory",{viz:t=>{const r=this.vizComponents.get(t);if(r)return r;throw new Error(`Viz Component (${t}) not found`)}})}install(t){if(this.plugins.has(t.id))throw new Error(`Plugin (${t.id}) has been installed before`);this.plugins.set(t.id,t);for(const r of t.manifest.viz){if(this.vizComponents.has(r.name))throw new Error(`Viz Component (${r.name}) has been installed before`);this.vizComponents.set(r.name,r)}}get installedPlugins(){return Array.from(this.plugins.values())}}class pu{constructor(){P(this,"migrations",[])}version(t,r){return this.migrations.push({version:t,handler:r}),this}run(t,r,a){var i;if(t.from===t.to)return r;if(t.from>t.to)throw new Error(`Can not downgrade from version '${t.from}' to (${t.to})`);const l=this.migrations.filter(c=>c.version>t.from&&c.version<=t.to),o=y.orderBy(l,"version","asc");if(((i=y.last(o))==null?void 0:i.version)!==t.to)throw new Error(`Migration to version ${t.to} not found`);return o.reduce((c,d)=>d.handler(c,a),r)}}class ee extends pu{constructor(){super(),this.configVersions()}version(t,r){return super.version(t,(a,l)=>({version:t,...r(a,l)}))}async migrate({configData:t,panelModel:r}){const a=await t.getItem(null),l=y.get(a,"version",0),o=this.run({from:l,to:this.VERSION},a,{panelModel:r});await t.setItem(null,o)}async needMigration({configData:t}){const r=await t.getItem(null);return y.get(r,"version",0)<this.VERSION}}const B=(e,t)=>{const[r,{setFalse:a}]=O.useBoolean(!0),[l,o]=h.useState();h.useEffect(()=>(e.getItem(t).then(c=>{o(c),a()}),e.watchItem(t,c=>{o(c)})));const i=h.useCallback(async c=>{await e.setItem(t,c),o(c)},[e,t]);return{loading:r,value:l,set:i}},ve={top:16,right:16,bottom:16,left:16},Ge=e=>Math.max(0,e-ve.left-ve.right),Fe=e=>Math.max(0,e-ve.top-ve.bottom),Ot=(e,t)=>({width:Ge(e),height:Fe(t)}),_e=({width:e,height:t,children:r})=>n.jsx(s.Box,{pt:ve.top,pr:ve.right,pb:ve.bottom,pl:ve.left,sx:{width:e,height:t,overflow:"hidden",position:"relative"},children:r});h.forwardRef(function({value:t,onChange:r,...a},l){return n.jsx(s.TextInput,{ref:l,value:t,onChange:r,...a})});class hu{constructor({valueRange:t,colorRange:r}){P(this,"mapper");this.mapper=ot.interpolate(t,r)}getColor(t){return this.mapper(t)}}function gu(e,t){if(e.type==="static")return e.staticColor;if(e.type==="continuous")try{const r=Number(t);if(Number.isNaN(r))throw new Error(`[getColorByColorConf] Invalid type of aggregated value: ${t}, parsed: ${r}`);return new hu(e).getColor(r)}catch(r){return console.error(r),"black"}return"black"}const fu=gu;function A(e){const[t,r]=e.split(".");return{queryID:t,columnKey:r}}function bu(e){return e.includes(".")?A(e):{queryID:"",columnKey:e}}function Ve(e,t){var l;const{queryID:r,columnKey:a}=A(t);return r?a?((l=e[r])==null?void 0:l.map(o=>o[a]))??[]:e[r]:[]}function Rt(e,t){const{queryID:r}=A(t);return r?e[r]:[]}function yu(e){return Object.values(e)[0]}function en(e,t){const{queryID:r,columnKey:a}=A(t);return e[a]}const je={CryptoJS:Ja,d3Array:vs,dayjs:M,lodash:y,numbro:Ye,mathjs:Ne,faker:nd.faker,popmotion:Wd},vu=[{name:"CryptoJS",url:"https://github.com/brix/crypto-js",version:"4.1.1"},{name:"d3Array",url:"https://github.com/d3/d3-array",version:"3.2.4"},{name:"dayjs",url:"https://day.js.org/",version:"1.11.6"},{name:"lodash",url:"https://lodash.com/docs/4.17.15",version:"4.17.21"},{name:"mathjs",url:"https://mathjs.org/",version:"11.12.0"},{name:"numbro",url:"https://numbrojs.com/",version:"2.3.6"},{name:"faker",url:"https://fakerjs.dev/",version:"7.6.0"},{name:"popmotion",url:"https://popmotion.io/",version:"11.0.3"}],_u=e=>`
|
|
9
|
+
我的卡片变量: {{ your_var }}`,tabs:{guide:"使用指南",vars:"看板信息与卡片的变量"}}}},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:"以下条件为真时,才运行本查询",description:"为假的情况: 空数组 / NaN / false / 空字符串 / undefined / null",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:"自定义聚合方式"},pick_record:{label:"直接选择数据",method:{label:"数据记录",first:"第一条",last:"最后一条"}}}},rich_text:{label:"富文本",content:{label:"内容"},dynamic_color:{label:"动态颜色",edit:"编辑动态颜色",clear:"清除动态颜色"},color_mapping:{label:"颜色映射",edit:"编辑颜色映射",clear:"清除颜色映射",choose_value_var:"选择用于映射颜色的变量",min:{val:"固定最小值",var:"动态最小值(优先)"},max:{val:"固定最大值",var:"动态最大值(优先)"}}},chart:{chart_config:"图表设置",data_field:"数据字段",groups:{merico_suite:"思码逸套件",echarts_based_charts:"基于ECharts的图表",others:"其他"},unit:{title:"单位",text:{placeholder:"单位文案"},show_in_tooltip:"在提示框中显示单位",show_in_legend:"在图例中显示单位"},series_order:{label:"排序依据",name:"名称",value:"值",raw:"不排序,保持数据本身的顺序",asc:"升序",desc:"降序"},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:"视觉映射",continuous:{label:"连续型"},piecewise:{label:"分段型",mode:{pieces:"连续数据",categories:"离散数据"},add_a_piece:"加一个分段",interval:"值区间",piece_label:"文案"},bar_width:"长条的宽度",bar_height:"长条的高度",item_width:"小块的宽度",item_height:"小块的高度",calculable:"显示拖拽手柄",min_value:"最小值",max_value:"最大值",min_text:"最小值文案",max_text:"最大值文案",use_palette_x:'使用配色方案"{{x}}"',built_in_palettes:"内置配色方案",precision:"数据精度",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:"显示标记点",area_style:{label:"区域填充样式",enabled:"启用区域填充",color:"填充颜色",use_series_color:"沿用系列本色",origin:{label:"图形区域的起始位置",auto:{label:"自动",description:"填充坐标轴线到数据间的区域(默认)"},start:{label:"自下而上",description:"填充坐标轴底部到数据间的区域"},end:{label:"自上而下",description:"填充坐标轴顶部到数据间的区域"}},shadow_blur:"图形阴影的模糊大小",shadow_color:"图形阴影的颜色",shadow_offset_x:"阴影水平方向上的偏移距离",shadow_offset_y:"阴影垂直方向上的偏移距离",opacity:"图形透明度"}},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轴数据字段",inverse:"反向坐标轴",layout:"布局",position:{label:"位置",left:"左",right:"右"},value_range:"值范围",value_min:"最小值",value_max:"最大值",behavior:"表现",visible:"可见",mirror:{label:"上下镜像"}},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:"颜色",background_color:"背景色",text_color:"文字颜色",click_to_add_a_color:"点击增加一个颜色",color_gradient:"颜色渐变",not_set:"未设置"},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:"请填写一个数字"}},spotlight:{trigger_text:"搜索",main_group:"主要项",placeholder:"打开…",not_found:"无匹配项"}}};class Jt{constructor(t){P(this,"rootRef");this.rootRef=Q.observable({current:t})}async deleteItem(t){Q.runInAction(()=>{y.unset(this.rootRef.current,[t])})}getItem(t){const r=this.getValueFromRoot(t);return Promise.resolve(r)}getValueFromRoot(t){return t===null?Q.toJS(this.rootRef.current):y.get(this.rootRef.current,[t])}setItem(t,r){if(t===null)if(y.isObject(r))Q.runInAction(()=>{this.rootRef.current=r});else throw new Error("Cannot set root value to non-object");else Q.runInAction(()=>{y.set(this.rootRef.current,[t],r)});return Promise.resolve(this.getItem(t))}watchItem(t,r,a){return Q.reaction(()=>this.getValueFromRoot(t),(l,o)=>{r(l,o)},{requiresObservable:!0,fireImmediately:y.get(a,"fireImmediately",!1)})}}class Zd{constructor(){P(this,"channels",new Map);P(this,"globalChannel",new Xa)}getChannel(t){const r=this.channels.get(t);if(r)return r;const a=new Xa;return this.channels.set(t,a),a}}class Jd{constructor(t){P(this,"instances",new Map);this.pluginManager=t}get availableVizList(){return this.pluginManager.installedPlugins.flatMap(t=>t.manifest.viz)}resolveComponent(t){return this.pluginManager.factory.viz(t)}getOrCreateInstance(t){const r=this.instances.get(t.id);if(r)return r;const a={id:t.id,name:t.viz.type,type:t.viz.type,messageChannels:new Zd,instanceData:new Jt(t.viz.conf)};return this.instances.set(t.id,a),a}}function _s(e,t,r,a){return{vizManager:r,locale:"zh",msgChannels:e.messageChannels,instanceData:e.instanceData,pluginData:new Jt({}),colorPalette:{getColor(){return()=>""}},data:t,variables:a}}const Hd=e=>{const{panel:t,measure:r,vizManager:a,data:l,variables:o}=e,i=a.resolveComponent(t.viz.type),c=a.getOrCreateInstance(t),d={..._s(c,l,a,o),viewport:{width:r.w,height:r.h}},u=i.viewRender;return n.jsx(u,{context:d,instance:c,...y.omit(e,["panel","vizManager","data"])})},Rd=e=>{const{vizManager:t,panel:r,data:a,variables:l}=e,o=t.resolveComponent(r.viz.type),i=t.getOrCreateInstance(r),c={..._s(i,a,t,l)},d=o.configRender;return n.jsx(d,{context:c,instance:i,...y.omit(e,["panel","vizManager","data"])})},xs=(e,t)=>{const r=qe.bezier(e),a=qe.bezier(t);return function(l){return l<50?r(l*2/100).hex():a((l-50)*2/100).hex()}},Ht=e=>{const t=qe.bezier(e);return function(r){return t(r/100).hex()}},eu={type:"interpolation",displayName:"style.color.interpolation.palette.red_green",getColor:xs(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},tu={type:"interpolation",displayName:"style.color.interpolation.palette.yellow_blue",getColor:xs(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},nu={type:"interpolation",displayName:"style.color.interpolation.palette.red",getColor:Ht(["#fff7f1","darkred"]),name:"red",category:"sequential"},ru={type:"interpolation",displayName:"style.color.interpolation.palette.green",getColor:Ht(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},au={type:"interpolation",displayName:"style.color.interpolation.palette.blue",getColor:Ht(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},su={type:"interpolation",displayName:"style.color.interpolation.palette.orange",getColor:Ht(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class lu{constructor(t){P(this,"symbol");this.symbol=Symbol(t)}}function Je(e){return new lu(e)}class qn{constructor(){P(this,"parent");P(this,"factoryRegistry",new Map);P(this,"instanceRegistry",new Map)}createScoped(){const t=new qn;return t.parent=this,t}getRequired(t){return this.get(t)}get(t){if(this.instanceRegistry.has(t.symbol))return this.instanceRegistry.get(t.symbol);const r=this.factoryRegistry.get(t.symbol);if(r){const a=r(this);return this.instanceRegistry.set(t.symbol,a),a}if(this.parent)return this.parent.get(t)}provideFactory(t,r){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,r),this}provideValue(t,r){return this.factoryRegistry.has(t.symbol)?console.warn(`Token ${t.symbol.toString()} is already registered`):this.factoryRegistry.set(t.symbol,()=>r),this}dispose(){this.instanceRegistry.forEach(t=>{const r=y.get(t,"dispose");y.isFunction(r)&&r.bind(t)()}),this.instanceRegistry.clear(),this.factoryRegistry.clear()}}class ou{constructor(t){this.pluginManager=t}createPanelAddonNode(t){const a=this.pluginManager.installedPlugins.flatMap(l=>l.manifest.panelAddon).filter(l=>!!l).map(l=>h.createElement(l.addonRender,{...t,key:l.name}));return n.jsx(n.Fragment,{children:a})}}const ws=h.createContext({addonSlotId:null});function ms({children:e}){const t=`panel-addon-slot-${h.useId()}`;return n.jsxs(ws.Provider,{value:{addonSlotId:t},children:[n.jsx("div",{style:{position:"static",top:0,left:0},id:t}),e]})}function iu(){const{addonSlotId:e}=h.useContext(ws);return e?document.getElementById(e):null}const Cs="14.44.0",cu=Object.freeze(Object.defineProperty({__proto__:null,version:Cs},Symbol.toStringTag,{value:"Module"}));class du{constructor(t){P(this,"staticColors",new Map);P(this,"interpolations",new Map);t.installedPlugins.forEach(r=>{r.manifest.color.forEach(a=>{this.register(a)})})}getStaticColors(){return Array.from(this.staticColors.values())}register(t){const r=this.encodeColor(t);t.type==="single"?(this.staticColors.has(r)&&console.warn(`the color '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.staticColors.set(r,t)):t.type==="interpolation"&&(this.interpolations.has(r)&&console.warn(`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`,`the interpolation '${t.name}' has been registered under '${t.category}', previous registered value will be overridden`),this.interpolations.set(r,t))}decodeStaticColor(t){return this.staticColors.get(t)}encodeColor(t){return`\${${t.category}}.{${t.name}}`}decodeInterpolation(t){return this.interpolations.get(t)}getColorInterpolations(){return Array.from(this.interpolations.values())}}class uu{constructor(){P(this,"plugins",new Map);P(this,"vizComponents",new Map);P(this,"factory",{viz:t=>{const r=this.vizComponents.get(t);if(r)return r;throw new Error(`Viz Component (${t}) not found`)}})}install(t){if(this.plugins.has(t.id))throw new Error(`Plugin (${t.id}) has been installed before`);this.plugins.set(t.id,t);for(const r of t.manifest.viz){if(this.vizComponents.has(r.name))throw new Error(`Viz Component (${r.name}) has been installed before`);this.vizComponents.set(r.name,r)}}get installedPlugins(){return Array.from(this.plugins.values())}}class pu{constructor(){P(this,"migrations",[])}version(t,r){return this.migrations.push({version:t,handler:r}),this}run(t,r,a){var i;if(t.from===t.to)return r;if(t.from>t.to)throw new Error(`Can not downgrade from version '${t.from}' to (${t.to})`);const l=this.migrations.filter(c=>c.version>t.from&&c.version<=t.to),o=y.orderBy(l,"version","asc");if(((i=y.last(o))==null?void 0:i.version)!==t.to)throw new Error(`Migration to version ${t.to} not found`);return o.reduce((c,d)=>d.handler(c,a),r)}}class ee extends pu{constructor(){super(),this.configVersions()}version(t,r){return super.version(t,(a,l)=>({version:t,...r(a,l)}))}async migrate({configData:t,panelModel:r}){const a=await t.getItem(null),l=y.get(a,"version",0),o=this.run({from:l,to:this.VERSION},a,{panelModel:r});await t.setItem(null,o)}async needMigration({configData:t}){const r=await t.getItem(null);return y.get(r,"version",0)<this.VERSION}}const B=(e,t)=>{const[r,{setFalse:a}]=O.useBoolean(!0),[l,o]=h.useState();h.useEffect(()=>(e.getItem(t).then(c=>{o(c),a()}),e.watchItem(t,c=>{o(c)})));const i=h.useCallback(async c=>{await e.setItem(t,c),o(c)},[e,t]);return{loading:r,value:l,set:i}},ve={top:16,right:16,bottom:16,left:16},Ge=e=>Math.max(0,e-ve.left-ve.right),Fe=e=>Math.max(0,e-ve.top-ve.bottom),Ot=(e,t)=>({width:Ge(e),height:Fe(t)}),_e=({width:e,height:t,children:r})=>n.jsx(s.Box,{pt:ve.top,pr:ve.right,pb:ve.bottom,pl:ve.left,sx:{width:e,height:t,overflow:"hidden",position:"relative"},children:r});h.forwardRef(function({value:t,onChange:r,...a},l){return n.jsx(s.TextInput,{ref:l,value:t,onChange:r,...a})});class hu{constructor({valueRange:t,colorRange:r}){P(this,"mapper");this.mapper=ot.interpolate(t,r)}getColor(t){return this.mapper(t)}}function gu(e,t){if(e.type==="static")return e.staticColor;if(e.type==="continuous")try{const r=Number(t);if(Number.isNaN(r))throw new Error(`[getColorByColorConf] Invalid type of aggregated value: ${t}, parsed: ${r}`);return new hu(e).getColor(r)}catch(r){return console.error(r),"black"}return"black"}const fu=gu;function A(e){const[t,r]=e.split(".");return{queryID:t,columnKey:r}}function bu(e){return e.includes(".")?A(e):{queryID:"",columnKey:e}}function Ve(e,t){var l;const{queryID:r,columnKey:a}=A(t);return r?a?((l=e[r])==null?void 0:l.map(o=>o[a]))??[]:e[r]:[]}function Rt(e,t){const{queryID:r}=A(t);return r?e[r]:[]}function yu(e){return Object.values(e)[0]}function en(e,t){const{queryID:r,columnKey:a}=A(t);return e[a]}const je={CryptoJS:Ja,d3Array:vs,dayjs:M,lodash:y,numbro:Ye,mathjs:Ne,faker:nd.faker,popmotion:Wd},vu=[{name:"CryptoJS",url:"https://github.com/brix/crypto-js",version:"4.1.1"},{name:"d3Array",url:"https://github.com/d3/d3-array",version:"3.2.4"},{name:"dayjs",url:"https://day.js.org/",version:"1.11.6"},{name:"lodash",url:"https://lodash.com/docs/4.17.15",version:"4.17.21"},{name:"mathjs",url:"https://mathjs.org/",version:"11.12.0"},{name:"numbro",url:"https://numbrojs.com/",version:"2.3.6"},{name:"faker",url:"https://fakerjs.dev/",version:"7.6.0"},{name:"popmotion",url:"https://popmotion.io/",version:"11.0.3"}],_u=e=>`
|
|
10
10
|
<tr>
|
|
11
11
|
<td><code>${e.name}</code></td>
|
|
12
12
|
<td>
|
|
@@ -48,7 +48,7 @@ Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel vari
|
|
|
48
48
|
rgba(0,0,0,0) 100%)`}}}),Ku=({editor:e})=>{const{t}=x.useTranslation(),[r,{set:a,setTrue:l,setFalse:o,toggle:i}]=O.useBoolean(),c=e.getAttributes(Bs),{empty:d,...u}=h.useMemo(()=>Pu(c),[c]),p=h.useCallback(v=>{e.chain().focus().setColorMapping(v).run(),o()},[e]),f=h.useCallback(()=>{e.chain().focus().unsetColorMapping().run()},[e]);return n.jsxs(n.Fragment,{children:[n.jsx(s.Modal,{size:500,opened:r,onClose:o,shadow:"md",withinPortal:!0,zIndex:330,closeOnClickOutside:!1,closeOnEscape:!1,title:t("rich_text.color_mapping.edit"),styles:{header:{paddingBottom:0,minHeight:"unset"},body:{padding:0}},children:n.jsx(Qu,{defaultValues:u,unset:f,onSubmit:p})}),n.jsxs(G.RichTextEditor.ControlsGroup,{children:[n.jsx(s.Tooltip,{label:t("rich_text.color_mapping.label"),children:n.jsx(s.ActionIcon,{variant:"default","data-rich-text-editor-control":"true",sx:{height:"26px",minHeight:"26px",lineHeight:"26px",borderColor:"#ced4da !important",color:"#000"},onClick:l,children:n.jsx(Uu,{})})}),n.jsx(s.Tooltip,{label:t("rich_text.color_mapping.clear"),children:n.jsx(s.ActionIcon,{variant:"default","data-rich-text-editor-control":"true",sx:{height:"26px",minHeight:"26px",lineHeight:"26px",borderColor:"#ced4da !important"},disabled:d,onClick:f,children:n.jsx(Yu,{disabled:d})})})]})]})},nn="function color({ variables }, { filters, context }, utils) {",Us="}",Xu=[nn,' return "red";',Us].join(`
|
|
49
49
|
`);function Zu(e){if(!e)return[];const t=e.split(`
|
|
50
50
|
`),r=t.length+1;let a=1;const l=t[t.length-1];return l&&(a=l.length+1),[{range:[2,1,r,a],label:"body",allowMultiline:!0}]}const Ju=e=>e&&e.replace(nn,"").replace(/(.*)\}$/,"$1"),Ys=e=>!e||e.startsWith(nn)?e:[nn,e,Us].join(`
|
|
51
|
-
`),er="dyn_color_",Hu=new RegExp(`^(?!${er})(.+)$`);function Ks(e){return e&&e.replace(Hu,`${er}$1`)}const Xs=e=>{const r="abcdefghijklmnopqrstuvwxyz",l=`1234567890${r}${r.toUpperCase()}`.split(""),o=new Uint8Array(e);crypto.getRandomValues(o);const i=o.reduce((c,d)=>`${c}${l[d&61]}`,"");return`${er}${i}`};function Ru(e,t,r){const a={},l=i=>new Function(`return ${Ys(i)}`)()({variables:r},t,je);return e.querySelectorAll("dynamic-color").forEach(i=>{const c=i.getAttribute("data-value");c&&(a[`#${Ks(i.id)}`]={color:l(c)})}),a}const Ft="data-value",ep=Ft,Zs="dynamicColor",Js=$n.Mark.create({name:Zs,addAttributes(){return{id:{default:Xs(6),parseHTML:e=>{const t=e.getAttribute("id");return Ks(t)}},[Ft]:{default:null,parseHTML:e=>e.getAttribute(Ft)}}},parseHTML(){return[{tag:"dynamic-color",getAttrs:e=>typeof e=="string"?(console.debug(e),!1):[e.getAttribute(Ft)]}]},renderHTML({HTMLAttributes:e}){return["dynamic-color",e,0]},addCommands(){return{setDynamicColor:e=>({commands:t})=>{const r=Ju(e);return t.setMark(this.name,{[Ft]:r})},unsetDynamicColor:()=>({commands:e})=>e.unsetMark(this.name)}}}),tp=({value:e,onChange:t,onMount:r})=>{const a=h.useRef(null),l=h.useRef(null),o=c=>{if(!c){t("");return}t(c)};h.useEffect(()=>{var d;const c=(d=a.current)==null?void 0:d.getModel();c&&(c.getValue()||c.setValue(e))},[e]);const i=(c,d)=>{a.current=c,l.current=d,r==null||r(c,d)};return n.jsx(Te,{className:"function-editor",height:"100%",defaultLanguage:"javascript",defaultValue:e,onChange:o,theme:"vs-dark",options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1}},onMount:i})},xt=h.forwardRef(({value:e,onChange:t,label:r,defaultValue:a,restrictions:l=[]},o)=>{const{t:i}=x.useTranslation(),[c,d]=h.useState(e),u=()=>{t(c)},p=()=>{d(e)},f=()=>{d(a)};h.useEffect(()=>{d(e)},[e]);const v=h.useCallback((m,k)=>{if(l.length===0)return;const z=sd.constrainedEditor(k),D=m.getModel();if(z.initializeIn(m),z.addRestrictionsTo(D,l),!!D&&!D._hasHighlight){z.toggleDevMode(),D.toggleHighlightOfEditableAreas();const I=D.getCurrentEditableRanges(),L=D.getValueInEditableRanges();console.debug({model:D,currentRanges:I,currentValue:L})}},[l]),_=c!==e,w=typeof c=="string"&&c.length===0;return n.jsxs(s.Stack,{gap:4,sx:{height:"100%",".editableArea--multi-line":{backgroundColor:"rgba(255,183,78, 0.1)"},".editableArea--single-line":{backgroundColor:"rgba(255,183,78, 0.1)"}},children:[n.jsxs(s.Group,{mb:6,justify:"space-between",sx:{flexShrink:0,flexGrow:0},children:[n.jsx(s.Group,{justify:"flex-start",children:n.jsx(Rs,{})}),n.jsxs(s.Group,{justify:"flex-end",children:[n.jsx(s.Button,{onClick:f,size:"xs",variant:"default",leftSection:n.jsx(S.IconPlayerSkipBack,{size:16}),children:i("common.actions.reset_to_default")}),n.jsx(s.Button,{onClick:p,color:"red",size:"xs",disabled:!_,leftSection:n.jsx(S.IconRecycle,{size:16}),children:i("common.actions.revert_changes")}),n.jsx(s.Button,{color:"green",size:"xs",onClick:u,disabled:!_,leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),children:i("common.actions.save_changes")})]})]}),n.jsx(s.Text,{size:"14px",children:r}),n.jsxs(s.Box,{sx:{position:"relative",flexGrow:1},children:[w&&n.jsx(s.Overlay,{center:!0,color:"#fff",backgroundOpacity:.5,children:n.jsx(s.Button,{color:"blue",radius:"xl",onClick:f,children:i("common.actions.init_with_default")})}),n.jsx(tp,{value:c,onChange:d,onMount:v})]})]})}),tr=h.forwardRef(({title:e,value:t,onChange:r,label:a,description:l=null,triggerLabel:o="Edit",triggerButtonProps:i={},renderTriggerButton:c,defaultValue:d,zIndex:u=320,restrictions:p},f)=>{const[v,{open:_,close:w}]=te.useDisclosure(!1);return n.jsxs(n.Fragment,{children:[n.jsxs(s.Modal,{opened:v,onClose:w,title:e,withinPortal:!0,zIndex:u,size:"900px",children:[l,n.jsx(s.Box,{h:600,children:n.jsx(xt,{value:t,onChange:r,defaultValue:d,label:a,restrictions:p})})]}),c==null?void 0:c({onClick:_}),!c&&n.jsx(s.Button,{onClick:_,...i,children:o})]})}),np=({onClick:e})=>{const{t}=x.useTranslation();return n.jsx(s.Tooltip,{label:t("rich_text.dynamic_color.label"),children:n.jsx(s.ActionIcon,{variant:"default","data-rich-text-editor-control":"true",sx:{height:"26px",minHeight:"26px",lineHeight:"26px",borderColor:"#ced4da !important",color:"rgb(190, 75, 219)"},onClick:e,children:n.jsx(S.IconMathFunction,{stroke:2,size:16})})})},rp=({editor:e})=>{const{t}=x.useTranslation(),r=e.getAttributes(Zs)[ep]??"",a=Ys(r),l=Zu(r);return n.jsxs(n.Fragment,{children:[n.jsx(tr,{title:t("rich_text.dynamic_color.edit"),label:"",triggerLabel:"",value:a,onChange:o=>{o?e.chain().focus().setDynamicColor(o).run():e.chain().focus().unsetDynamicColor().run()},defaultValue:Xu,renderTriggerButton:np,restrictions:l,zIndex:340}),n.jsx(s.Tooltip,{label:t("rich_text.dynamic_color.clear"),children:n.jsx(s.ActionIcon,{variant:"default","data-rich-text-editor-control":"true",sx:{height:"26px",minHeight:"26px",lineHeight:"26px",borderColor:"#ced4da !important",color:"#000"},disabled:!r,onClick:()=>e.chain().focus().unsetDynamicColor().run(),children:n.jsx(S.IconMathFunctionOff,{stroke:1.5,size:16})})})]})},Hs=$n.Extension.create({name:"fontSize",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{fontSize:{default:null,parseHTML:e=>e.style.fontSize.replace(/['"]+/g,""),renderHTML:e=>e.fontSize?{style:`font-size: ${e.fontSize}; line-height: 1.2; overflow: auto`}:{}}}}]},addCommands(){return{setFontSize:e=>({chain:t})=>t().setMark("textStyle",{fontSize:e}).run(),unsetFontSize:()=>({chain:e})=>e().setMark("textStyle",{fontSize:null}).removeEmptyTextStyle().run()}}}),ap=["8","10","12","14","16","18","20","24","30","36","48","60","72"].map(e=>`${e}px`),sp=[{label:"auto",value:""}].concat(ap.map(e=>({label:e,value:e}))),lp={input:{height:"26px",minHeight:"26px",lineHeight:"26px",borderColor:"#ced4da !important"}},op=({editor:e})=>{const t=e.getAttributes("textStyle").fontSize;return n.jsx(G.RichTextEditor.ControlsGroup,{children:n.jsx(s.NativeSelect,{size:"xs",leftSection:n.jsx(S.IconTextSize,{stroke:1.5,size:16}),data:sp,styles:lp,value:t||"",onChange:r=>{const a=r.currentTarget.value;a?e.chain().focus().setFontSize(a).run():e.chain().focus().unsetFontSize().run()}})})},Dt=h.forwardRef(({value:e,styles:t={},sx:r={},dashboardStateValues:a=ar(),variableAggValueMap:l={}},o)=>{const i=As(),c=h.useMemo(()=>{const _=[us,cs,G.Link,ns,ts,Ra,rs.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),ls,ss,as,os.configure({types:["heading","paragraph"]}),es.configure({placeholder:"This is placeholder"}),is,Ha.Color,Hs,Js];return i&&_.push(Ls),_},[i]),d=ds.useEditor({extensions:c,content:e,editable:!1});h.useEffect(()=>{d==null||d.commands.setContent(e)},[e,d]);const u=h.useMemo(()=>new DOMParser().parseFromString(e,"text/html"),[e]),p=h.useMemo(()=>Ru(u,a,l),[u,a,l]),f=h.useMemo(()=>Au(u,l),[u,l]),v=h.useMemo(()=>y.defaultsDeep({},{content:{...Zn,...p,...f}},t),[t,p,f]);return n.jsx(G.RichTextEditor,{editor:d,styles:v,sx:r,children:n.jsx(G.RichTextEditor.Content,{ref:o})})});function Rs(){const{t:e}=x.useTranslation(),[t,{open:r,close:a}]=te.useDisclosure(!1);return n.jsxs(n.Fragment,{children:[n.jsx(s.Modal,{opened:t,onClose:a,title:e("function_utils.modal_title"),zIndex:330,withinPortal:!0,children:n.jsx(Dt,{value:xu(e),styles:{root:{border:"none"},content:{padding:0,table:{marginBottom:0}}}})}),n.jsx(s.Button,{variant:"light",color:"violet",size:"xs",onClick:r,leftSection:n.jsx(S.IconInfoCircle,{size:16}),children:e("function_utils.trigger_text")})]})}const nr=({option:e,checked:t,...r})=>{const{label:a,description:l}=e;return n.jsx("div",{...r,style:{flexGrow:1},children:n.jsxs(s.Group,{justify:"space-between",wrap:"nowrap",children:[n.jsxs(s.Group,{justify:"flex-start",gap:"0.5em",children:[t&&n.jsx(S.IconCheck,{size:16,color:"green"}),n.jsx(s.Text,{size:"sm",sx:{flexGrow:1},children:a})]}),n.jsx(s.Text,{size:"xs",c:"dimmed",children:l})]})})},rr=({value:e,onChange:t,height:r="200px",defaultLanguage:a="sql",theme:l="vs-dark"})=>{const o=c=>{t==null||t(c??"")},i=!t;return n.jsx(Te,{className:"minimal-monaco-editor",height:r,defaultLanguage:a,value:e,onChange:i?void 0:o,theme:l,options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1},readOnly:i||!t,"semanticHighlighting.enabled":!0}})},ip=({color:e})=>h.forwardRef(({onClick:t},r)=>n.jsx(G.RichTextEditor.Control,{ref:r,onClick:t,children:n.jsx(s.ColorSwatch,{color:e,size:14})})),cp=({editor:e})=>{const t=s.useMantineTheme(),r=e.getAttributes("textStyle").color||t.black,a=h.useMemo(()=>nl(r),[r]),l=h.useCallback(i=>{e.chain().setColor(i).run()},[e]),o=h.useCallback(()=>{e.chain().focus().unsetColor().run()},[e]);return n.jsx(al,{value:a,onChange:l,clear:o,Trigger:ip({color:a})})},dp={"dynamic-color":{position:"relative"},"dynamic-color:after":{content:'""',position:"absolute",bottom:"-2px",left:0,width:"100%",height:"1px",border:"double 1px purple"},"color-mapping":{position:"relative"},"color-mapping:after":{content:'""',position:"absolute",bottom:"-2px",left:0,width:"100%",height:"4px",opacity:.8,background:"linear-gradient(90deg, rgb(255, 225, 225) 0%, rgb(253, 188, 188) 40%, rgb(243, 148, 148) 60%, rgb(250, 66, 66) 80%, rgb(226, 18, 18) 100%)"}};function up(){const{editor:e}=G.useRichTextEditorContext();return n.jsx(G.RichTextEditor.Control,{onClick:()=>e==null?void 0:e.commands.insertTable({rows:3,cols:3,withHeaderRow:!0}),"aria-label":"Insert table",title:"Insert table",children:n.jsx(S.IconBorderAll,{stroke:1.5,size:16})})}const pt=h.forwardRef(({value:e,onChange:t,styles:r={},label:a,autoSubmit:l,onSubmit:o},i)=>{const{t:c}=x.useTranslation(),d=Ps(),u=h.useMemo(()=>{const I=[us,cs,G.Link,ns,ts,Ra,rs.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),ls,ss,as,os.configure({types:["heading","paragraph"]}),es.configure({placeholder:"This is placeholder"}),is,Ha.Color,Hs,Js];return d&&I.push(Ls),I},[d]),[p,{setTrue:f,setFalse:v}]=O.useBoolean(!1),[_,w]=h.useState(e),m=ds.useEditor({extensions:u,content:_,onUpdate:({editor:I})=>{const L=I.getHTML();w(L)},onCreate:({editor:I})=>{I.view.dom.setAttribute("spellcheck","false"),I.view.dom.setAttribute("autocomplete","off"),I.view.dom.setAttribute("autocapitalize","off")},onFocus:f,onBlur:v});h.useEffect(()=>{w(I=>e===I?I:(m==null||m.commands.setContent(e),e))},[e]);const k=()=>{t(_),o==null||o()},z=e!==_;h.useEffect(()=>{!l||!p||k()},[l,z,p]);const D=h.useMemo(()=>y.defaultsDeep({},{content:{...Zn,...dp}},r),[r]);return m?n.jsxs(s.Stack,{gap:4,sx:{flexGrow:1,position:"relative"},children:[n.jsxs(s.Group,{align:"center",children:[n.jsx(s.Text,{size:"14px",fw:500,children:a}),!l&&n.jsx(s.Button,{variant:"filled",color:"blue",size:"compact-xs",disabled:!z,onClick:k,leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),children:c("common.actions.save_changes")})]}),n.jsxs(G.RichTextEditor,{editor:m,styles:D,children:[n.jsxs(G.RichTextEditor.Toolbar,{sticky:!0,stickyOffset:0,children:[n.jsx(cp,{editor:m}),d&&n.jsx(Ku,{editor:m}),n.jsx(G.RichTextEditor.ControlsGroup,{children:n.jsx(rp,{editor:m})}),n.jsxs(G.RichTextEditor.ControlsGroup,{children:[n.jsx(G.RichTextEditor.Bold,{}),n.jsx(G.RichTextEditor.Italic,{}),n.jsx(G.RichTextEditor.Underline,{}),n.jsx(G.RichTextEditor.ClearFormatting,{}),n.jsx(G.RichTextEditor.Highlight,{}),n.jsx(G.RichTextEditor.Code,{})]}),n.jsxs(G.RichTextEditor.ControlsGroup,{children:[n.jsx(G.RichTextEditor.H1,{}),n.jsx(G.RichTextEditor.H2,{}),n.jsx(G.RichTextEditor.H3,{}),n.jsx(G.RichTextEditor.H4,{})]}),n.jsxs(G.RichTextEditor.ControlsGroup,{children:[n.jsx(G.RichTextEditor.Blockquote,{}),n.jsx(G.RichTextEditor.Hr,{}),n.jsx(G.RichTextEditor.BulletList,{}),n.jsx(G.RichTextEditor.OrderedList,{}),n.jsx(G.RichTextEditor.Subscript,{}),n.jsx(G.RichTextEditor.Superscript,{})]}),n.jsxs(G.RichTextEditor.ControlsGroup,{children:[n.jsx(G.RichTextEditor.Link,{}),n.jsx(G.RichTextEditor.Unlink,{})]}),n.jsxs(G.RichTextEditor.ControlsGroup,{children:[n.jsx(G.RichTextEditor.AlignLeft,{}),n.jsx(G.RichTextEditor.AlignCenter,{}),n.jsx(G.RichTextEditor.AlignJustify,{}),n.jsx(G.RichTextEditor.AlignRight,{})]}),n.jsx(G.RichTextEditor.ControlsGroup,{children:n.jsx(up,{})}),n.jsx(op,{editor:m})]}),n.jsx(G.RichTextEditor.Content,{})]})]}):null}),el={hex:/^#?([0-9A-F]{3}){1,2}$/i,fullHex:/^#?([0-9A-F]{6})$/i,hexa:/^#?([0-9A-F]{4}){1,2}$/i,rgb:/^rgb\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/i,rgba:/^rgba\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/i,hsl:/hsl\(\s*(\d+)\s*,\s*(\d+(?:\.\d+)?%)\s*,\s*(\d+(?:\.\d+)?%)\)/i,hsla:/^hsla\((\d+),\s*([\d.]+)%,\s*([\d.]+)%,\s*(\d*(?:\.\d+)?)\)$/i},pp=y.pick(el,"fullHex","rgb","rgba","hsl","hsla"),hp=y.pick(el,"fullHex","rgb","rgba","hsl","hsla");function gp(e){return Object.values(pp).some(t=>t.test(e))}function tl(e){return Object.values(hp).some(t=>t.test(e))}function nl(e){return tl(e)?e:qe.valid(e)?qe(e).css():e}const rl=({value:e})=>tl(e)?n.jsx(s.ColorSwatch,{ml:8,size:16,color:e}):n.jsx(s.ColorSwatch,{ml:8,size:16,color:""}),fp=({value:e,onChange:t,shouldPatch:r})=>{const{t:a}=x.useTranslation(),[l,o]=h.useState(e);h.useEffect(()=>{r&&o(e)},[e,r]);const i=h.useCallback(c=>{const d=c.currentTarget.value;o(d),gp(d)&&t(d)},[t]);return n.jsx(s.TextInput,{value:l,onChange:i,leftSection:n.jsx(rl,{value:l}),size:"xs",placeholder:a("chart.color.not_set"),styles:{root:{flexGrow:1},input:{fontFamily:"monospace",letterSpacing:2,textAlign:"center",textTransform:"uppercase"}}})},bp=["gray","red","grape","blue","cyan","green","yellow"],al=({Trigger:e,value:t,onChange:r,clear:a})=>{const{t:l}=x.useTranslation(),o=s.useMantineTheme(),[i,{set:c,setFalse:d,toggle:u}]=O.useBoolean(),[p,f]=h.useState(!1),v=h.useMemo(()=>{const z=[];return bp.forEach(D=>{const I=o.colors[D];I&&I.forEach(L=>{z.push(L)})}),z},[o.colors]),_=(z,D=!0)=>{r(z),D&&d()},w=h.useCallback(z=>{_(z,!1),f(!1)},[]),m=h.useCallback(z=>{_(z,!1),f(!0)},[]),k=()=>{a(),d()};return n.jsxs(s.Popover,{opened:i,onChange:c,shadow:"md",withinPortal:!0,zIndex:340,withArrow:!0,children:[n.jsx(s.Popover.Target,{children:n.jsx(e,{onClick:u})}),n.jsx(s.Popover.Dropdown,{children:n.jsxs(s.Stack,{gap:"xs",children:[n.jsxs(s.Group,{justify:"flex-end",children:[n.jsx(fp,{value:t,onChange:w,shouldPatch:p}),n.jsx(s.ActionIcon,{variant:"default",onClick:k,title:l("common.actions.clear"),children:n.jsx(S.IconCircleOff,{stroke:1.5,size:"1rem"})}),n.jsx(s.ActionIcon,{variant:"default",onClick:d,title:l("common.actions.close"),children:n.jsx(S.IconX,{stroke:1.5,size:"1rem"})})]}),n.jsxs(s.SimpleGrid,{cols:2,children:[n.jsx(s.ColorPicker,{format:"hex",swatches:v,value:t,onChange:m,size:"sm",withPicker:!1,styles:{swatches:{marginTop:"0 !important"}}}),n.jsx(s.ColorPicker,{format:"hex",fullWidth:!0,value:t,onChange:m})]})]})})]})},yp=({color:e,label:t})=>h.forwardRef(({onClick:r},a)=>n.jsx(s.Button,{ref:a,size:"sm",variant:"default",leftSection:n.jsx(rl,{value:e}),onClick:r,children:t})),ye=h.forwardRef(({value:e="",onChange:t,label:r},a)=>{const l=h.useCallback(()=>{t("")},[t]),o=h.useMemo(()=>nl(e),[e]);return n.jsx(al,{value:o,onChange:t,clear:l,Trigger:yp({color:o,label:r})})}),le={mantissa:0,output:"number",trimMantissa:!1,average:!1,absolute:!1};function Y(e,{absolute:t,...r}){if(e===null)return String(e);try{let a=Ye(e).value();if(a===void 0||Number.isNaN(a))throw new Error(`[formatNumber]Not a number: ${e}`);return t&&(a=Math.abs(a)),Ye(a).format(r)}catch(a){return console.debug(a),String(e)}}function vp(e){return e===null?"null":e===void 0?"undefined":Array.isArray(e)?`Array(${e.length})`:e.toString()}function Re({data_field:e,aggregation:t},r){return Nn(r,e,t)}function $e({formatter:e,aggregation:t},r){if(typeof r!="string"&&typeof r!="number")return vp(r);if(t.type==="custom")return r;try{return Y(r,e)}catch(a){return console.error(a),r}}function It(e,t){return e.replaceAll(/(\$\{([^{\}]+(?=}))\})/g,(...a)=>{const l=a[2],o=t.variableStyleMap[l];if(!o)return`{{${l}}}`;const{variable:i,...c}=o,d=Object.entries(c).map(([v,_])=>`${v}:${_}`).join(";"),u=i.color;if(u.type!=="continuous")return`<span style="${d}">{{${l}}}</span>`;const p=Xs(6),f=`try {
|
|
51
|
+
`),er="dyn_color_",Hu=new RegExp(`^(?!${er})(.+)$`);function Ks(e){return e&&e.replace(Hu,`${er}$1`)}const Xs=e=>{const r="abcdefghijklmnopqrstuvwxyz",l=`1234567890${r}${r.toUpperCase()}`.split(""),o=new Uint8Array(e);crypto.getRandomValues(o);const i=o.reduce((c,d)=>`${c}${l[d&61]}`,"");return`${er}${i}`};function Ru(e,t,r){const a={},l=i=>new Function(`return ${Ys(i)}`)()({variables:r},t,je);return e.querySelectorAll("dynamic-color").forEach(i=>{const c=i.getAttribute("data-value");c&&(a[`#${Ks(i.id)}`]={color:l(c)})}),a}const Ft="data-value",ep=Ft,Zs="dynamicColor",Js=$n.Mark.create({name:Zs,addAttributes(){return{id:{default:Xs(6),parseHTML:e=>{const t=e.getAttribute("id");return Ks(t)}},[Ft]:{default:null,parseHTML:e=>e.getAttribute(Ft)}}},parseHTML(){return[{tag:"dynamic-color",getAttrs:e=>typeof e=="string"?(console.debug(e),!1):[e.getAttribute(Ft)]}]},renderHTML({HTMLAttributes:e}){return["dynamic-color",e,0]},addCommands(){return{setDynamicColor:e=>({commands:t})=>{const r=Ju(e);return t.setMark(this.name,{[Ft]:r})},unsetDynamicColor:()=>({commands:e})=>e.unsetMark(this.name)}}}),tp=({value:e,onChange:t,onMount:r})=>{const a=h.useRef(null),l=h.useRef(null),o=c=>{if(!c){t("");return}t(c)};h.useEffect(()=>{var d;const c=(d=a.current)==null?void 0:d.getModel();c&&(c.getValue()||c.setValue(e))},[e]);const i=(c,d)=>{a.current=c,l.current=d,r==null||r(c,d)};return n.jsx(Te,{className:"function-editor",height:"100%",defaultLanguage:"javascript",defaultValue:e,onChange:o,theme:"vs-dark",options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1}},onMount:i})},xt=h.forwardRef(({value:e,onChange:t,label:r,defaultValue:a,restrictions:l=[]},o)=>{const{t:i}=x.useTranslation(),[c,d]=h.useState(e),u=()=>{t(c)},p=()=>{d(e)},f=()=>{d(a)};h.useEffect(()=>{d(e)},[e]);const v=h.useCallback((m,k)=>{if(l.length===0)return;const z=sd.constrainedEditor(k),D=m.getModel();if(z.initializeIn(m),z.addRestrictionsTo(D,l),!!D&&!D._hasHighlight){z.toggleDevMode(),D.toggleHighlightOfEditableAreas();const I=D.getCurrentEditableRanges(),L=D.getValueInEditableRanges();console.debug({model:D,currentRanges:I,currentValue:L})}},[l]),_=c!==e,w=typeof c=="string"&&c.length===0;return n.jsxs(s.Stack,{gap:4,sx:{height:"100%",".editableArea--multi-line":{backgroundColor:"rgba(255,183,78, 0.1)"},".editableArea--single-line":{backgroundColor:"rgba(255,183,78, 0.1)"}},children:[n.jsxs(s.Group,{mb:6,justify:"space-between",sx:{flexShrink:0,flexGrow:0},children:[n.jsx(s.Group,{justify:"flex-start",children:n.jsx(Rs,{})}),n.jsxs(s.Group,{justify:"flex-end",children:[n.jsx(s.Button,{onClick:f,size:"xs",variant:"default",leftSection:n.jsx(S.IconPlayerSkipBack,{size:16}),children:i("common.actions.reset_to_default")}),n.jsx(s.Button,{onClick:p,color:"red",size:"xs",disabled:!_,leftSection:n.jsx(S.IconRecycle,{size:16}),children:i("common.actions.revert_changes")}),n.jsx(s.Button,{color:"green",size:"xs",onClick:u,disabled:!_,leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),children:i("common.actions.save_changes")})]})]}),n.jsx(s.Text,{size:"14px",children:r}),n.jsxs(s.Box,{sx:{position:"relative",flexGrow:1},children:[w&&n.jsx(s.Overlay,{center:!0,color:"#fff",backgroundOpacity:.5,children:n.jsx(s.Button,{color:"blue",radius:"xl",onClick:f,children:i("common.actions.init_with_default")})}),n.jsx(tp,{value:c,onChange:d,onMount:v})]})]})}),tr=h.forwardRef(({title:e,value:t,onChange:r,label:a,description:l=null,triggerLabel:o="Edit",triggerButtonProps:i={},renderTriggerButton:c,defaultValue:d,zIndex:u=320,restrictions:p},f)=>{const[v,{open:_,close:w}]=te.useDisclosure(!1);return n.jsxs(n.Fragment,{children:[n.jsxs(s.Modal,{opened:v,onClose:w,title:e,withinPortal:!0,zIndex:u,size:"900px",children:[l,n.jsx(s.Box,{h:600,children:n.jsx(xt,{value:t,onChange:r,defaultValue:d,label:a,restrictions:p})})]}),c==null?void 0:c({onClick:_}),!c&&n.jsx(s.Button,{onClick:_,...i,children:o})]})}),np=({onClick:e})=>{const{t}=x.useTranslation();return n.jsx(s.Tooltip,{label:t("rich_text.dynamic_color.label"),children:n.jsx(s.ActionIcon,{variant:"default","data-rich-text-editor-control":"true",sx:{height:"26px",minHeight:"26px",lineHeight:"26px",borderColor:"#ced4da !important",color:"rgb(190, 75, 219)"},onClick:e,children:n.jsx(S.IconMathFunction,{stroke:2,size:16})})})},rp=({editor:e})=>{const{t}=x.useTranslation(),r=e.getAttributes(Zs)[ep]??"",a=Ys(r),l=Zu(r);return n.jsxs(n.Fragment,{children:[n.jsx(tr,{title:t("rich_text.dynamic_color.edit"),label:"",triggerLabel:"",value:a,onChange:o=>{o?e.chain().focus().setDynamicColor(o).run():e.chain().focus().unsetDynamicColor().run()},defaultValue:Xu,renderTriggerButton:np,restrictions:l,zIndex:340}),n.jsx(s.Tooltip,{label:t("rich_text.dynamic_color.clear"),children:n.jsx(s.ActionIcon,{variant:"default","data-rich-text-editor-control":"true",sx:{height:"26px",minHeight:"26px",lineHeight:"26px",borderColor:"#ced4da !important",color:"#000"},disabled:!r,onClick:()=>e.chain().focus().unsetDynamicColor().run(),children:n.jsx(S.IconMathFunctionOff,{stroke:1.5,size:16})})})]})},Hs=$n.Extension.create({name:"fontSize",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{fontSize:{default:null,parseHTML:e=>e.style.fontSize.replace(/['"]+/g,""),renderHTML:e=>e.fontSize?{style:`font-size: ${e.fontSize}; line-height: 1.2; overflow: auto`}:{}}}}]},addCommands(){return{setFontSize:e=>({chain:t})=>t().setMark("textStyle",{fontSize:e}).run(),unsetFontSize:()=>({chain:e})=>e().setMark("textStyle",{fontSize:null}).removeEmptyTextStyle().run()}}}),ap=["8","10","12","14","16","18","20","24","30","36","48","60","72"].map(e=>`${e}px`),sp=[{label:"auto",value:""}].concat(ap.map(e=>({label:e,value:e}))),lp={input:{height:"26px",minHeight:"26px",lineHeight:"26px",borderColor:"#ced4da !important"}},op=({editor:e})=>{const t=e.getAttributes("textStyle").fontSize;return n.jsx(G.RichTextEditor.ControlsGroup,{children:n.jsx(s.NativeSelect,{size:"xs",leftSection:n.jsx(S.IconTextSize,{stroke:1.5,size:16}),data:sp,styles:lp,value:t||"",onChange:r=>{const a=r.currentTarget.value;a?e.chain().focus().setFontSize(a).run():e.chain().focus().unsetFontSize().run()}})})},Dt=h.forwardRef(({value:e,styles:t={},sx:r={},dashboardStateValues:a=ar(),variableAggValueMap:l={}},o)=>{const i=As(),c=h.useMemo(()=>{const _=[us,cs,G.Link,ns,ts,Ra,rs.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),ls,ss,as,os.configure({types:["heading","paragraph"]}),es.configure({placeholder:"This is placeholder"}),is,Ha.Color,Hs,Js];return i&&_.push(Ls),_},[i]),d=ds.useEditor({extensions:c,content:e,editable:!1});h.useEffect(()=>{d==null||d.commands.setContent(e)},[e,d]);const u=h.useMemo(()=>new DOMParser().parseFromString(e,"text/html"),[e]),p=h.useMemo(()=>Ru(u,a,l),[u,a,l]),f=h.useMemo(()=>Au(u,l),[u,l]),v=h.useMemo(()=>y.defaultsDeep({},{content:{...Zn,...p,...f}},t),[t,p,f]);return n.jsx(G.RichTextEditor,{editor:d,styles:v,sx:r,children:n.jsx(G.RichTextEditor.Content,{ref:o})})});function Rs(){const{t:e}=x.useTranslation(),[t,{open:r,close:a}]=te.useDisclosure(!1);return n.jsxs(n.Fragment,{children:[n.jsx(s.Modal,{opened:t,onClose:a,title:e("function_utils.modal_title"),zIndex:330,withinPortal:!0,children:n.jsx(Dt,{value:xu(e),styles:{root:{border:"none"},content:{padding:0,table:{marginBottom:0}}}})}),n.jsx(s.Button,{variant:"light",color:"violet",size:"xs",onClick:r,leftSection:n.jsx(S.IconInfoCircle,{size:16}),children:e("function_utils.trigger_text")})]})}const nr=({option:e,checked:t,...r})=>{const{label:a,description:l}=e;return n.jsx("div",{...r,style:{flexGrow:1},children:n.jsxs(s.Group,{justify:"space-between",wrap:"nowrap",children:[n.jsxs(s.Group,{justify:"flex-start",gap:"0.5em",children:[t&&n.jsx(S.IconCheck,{size:16,color:"green"}),n.jsx(s.Text,{size:"sm",sx:{flexGrow:1},children:a})]}),n.jsx(s.Text,{size:"xs",c:"dimmed",children:l})]})})},rr=({value:e,onChange:t,height:r="200px",defaultLanguage:a="sql",theme:l="vs-dark"})=>{const o=c=>{t==null||t(c??"")},i=!t;return n.jsx(Te,{className:"minimal-monaco-editor",height:r,defaultLanguage:a,value:e,onChange:i?void 0:o,theme:l,options:{lineNumbers:"off",folding:!1,lineDecorationsWidth:20,lineNumbersMinChars:0,wordWrap:"on",minimap:{enabled:!1},readOnly:i||!t,"semanticHighlighting.enabled":!0}})},ip=({color:e})=>h.forwardRef(({onClick:t},r)=>n.jsx(G.RichTextEditor.Control,{ref:r,onClick:t,children:n.jsx(s.ColorSwatch,{color:e,size:14})})),cp=({editor:e})=>{const t=s.useMantineTheme(),r=e.getAttributes("textStyle").color||t.black,a=h.useMemo(()=>nl(r),[r]),l=h.useCallback(i=>{e.chain().setColor(i).run()},[e]),o=h.useCallback(()=>{e.chain().focus().unsetColor().run()},[e]);return n.jsx(al,{value:a,onChange:l,clear:o,Trigger:ip({color:a})})},dp={"dynamic-color":{position:"relative"},"dynamic-color:after":{content:'""',position:"absolute",bottom:"-2px",left:0,width:"100%",height:"1px",border:"double 1px purple"},"color-mapping":{position:"relative"},"color-mapping:after":{content:'""',position:"absolute",bottom:"-2px",left:0,width:"100%",height:"4px",opacity:.8,background:"linear-gradient(90deg, rgb(255, 225, 225) 0%, rgb(253, 188, 188) 40%, rgb(243, 148, 148) 60%, rgb(250, 66, 66) 80%, rgb(226, 18, 18) 100%)"}};function up(){const{editor:e}=G.useRichTextEditorContext();return n.jsx(G.RichTextEditor.Control,{onClick:()=>e==null?void 0:e.commands.insertTable({rows:3,cols:3,withHeaderRow:!0}),"aria-label":"Insert table",title:"Insert table",children:n.jsx(S.IconBorderAll,{stroke:1.5,size:16})})}const pt=h.forwardRef(({value:e,onChange:t,styles:r={},label:a,autoSubmit:l,onSubmit:o},i)=>{const{t:c}=x.useTranslation(),d=Ps(),u=h.useMemo(()=>{const I=[us,cs,G.Link,ns,ts,Ra,rs.configure({resizable:!1,HTMLAttributes:{class:"rich-text-table-render"}}),ls,ss,as,os.configure({types:["heading","paragraph"]}),es.configure({placeholder:"This is placeholder"}),is,Ha.Color,Hs,Js];return d&&I.push(Ls),I},[d]),[p,{setTrue:f,setFalse:v}]=O.useBoolean(!1),[_,w]=h.useState(e),m=ds.useEditor({extensions:u,content:e,onUpdate:({editor:I})=>{const L=I.getHTML();w(L)},onCreate:({editor:I})=>{I.view.dom.setAttribute("spellcheck","false"),I.view.dom.setAttribute("autocomplete","off"),I.view.dom.setAttribute("autocapitalize","off")},onFocus:f,onBlur:v});h.useEffect(()=>{w(e),m==null||m.commands.setContent(e)},[e]);const k=()=>{t(_),o==null||o()},z=e!==_;h.useEffect(()=>{!l||!p||k()},[l,z,p]);const D=h.useMemo(()=>y.defaultsDeep({},{content:{...Zn,...dp}},r),[r]);return m?n.jsxs(s.Stack,{gap:4,sx:{flexGrow:1,position:"relative"},children:[n.jsxs(s.Group,{align:"center",children:[n.jsx(s.Text,{size:"14px",fw:500,children:a}),!l&&n.jsx(s.Button,{variant:"filled",color:"blue",size:"compact-xs",disabled:!z,onClick:k,leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),children:c("common.actions.save_changes")})]}),n.jsxs(G.RichTextEditor,{editor:m,styles:D,children:[n.jsxs(G.RichTextEditor.Toolbar,{sticky:!0,stickyOffset:0,children:[n.jsx(cp,{editor:m}),d&&n.jsx(Ku,{editor:m}),n.jsx(G.RichTextEditor.ControlsGroup,{children:n.jsx(rp,{editor:m})}),n.jsxs(G.RichTextEditor.ControlsGroup,{children:[n.jsx(G.RichTextEditor.Bold,{}),n.jsx(G.RichTextEditor.Italic,{}),n.jsx(G.RichTextEditor.Underline,{}),n.jsx(G.RichTextEditor.ClearFormatting,{}),n.jsx(G.RichTextEditor.Highlight,{}),n.jsx(G.RichTextEditor.Code,{})]}),n.jsxs(G.RichTextEditor.ControlsGroup,{children:[n.jsx(G.RichTextEditor.H1,{}),n.jsx(G.RichTextEditor.H2,{}),n.jsx(G.RichTextEditor.H3,{}),n.jsx(G.RichTextEditor.H4,{})]}),n.jsxs(G.RichTextEditor.ControlsGroup,{children:[n.jsx(G.RichTextEditor.Blockquote,{}),n.jsx(G.RichTextEditor.Hr,{}),n.jsx(G.RichTextEditor.BulletList,{}),n.jsx(G.RichTextEditor.OrderedList,{}),n.jsx(G.RichTextEditor.Subscript,{}),n.jsx(G.RichTextEditor.Superscript,{})]}),n.jsxs(G.RichTextEditor.ControlsGroup,{children:[n.jsx(G.RichTextEditor.Link,{}),n.jsx(G.RichTextEditor.Unlink,{})]}),n.jsxs(G.RichTextEditor.ControlsGroup,{children:[n.jsx(G.RichTextEditor.AlignLeft,{}),n.jsx(G.RichTextEditor.AlignCenter,{}),n.jsx(G.RichTextEditor.AlignJustify,{}),n.jsx(G.RichTextEditor.AlignRight,{})]}),n.jsx(G.RichTextEditor.ControlsGroup,{children:n.jsx(up,{})}),n.jsx(op,{editor:m})]}),n.jsx(G.RichTextEditor.Content,{})]})]}):null}),el={hex:/^#?([0-9A-F]{3}){1,2}$/i,fullHex:/^#?([0-9A-F]{6})$/i,hexa:/^#?([0-9A-F]{4}){1,2}$/i,rgb:/^rgb\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/i,rgba:/^rgba\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/i,hsl:/hsl\(\s*(\d+)\s*,\s*(\d+(?:\.\d+)?%)\s*,\s*(\d+(?:\.\d+)?%)\)/i,hsla:/^hsla\((\d+),\s*([\d.]+)%,\s*([\d.]+)%,\s*(\d*(?:\.\d+)?)\)$/i},pp=y.pick(el,"fullHex","rgb","rgba","hsl","hsla"),hp=y.pick(el,"fullHex","rgb","rgba","hsl","hsla");function gp(e){return Object.values(pp).some(t=>t.test(e))}function tl(e){return Object.values(hp).some(t=>t.test(e))}function nl(e){return tl(e)?e:qe.valid(e)?qe(e).css():e}const rl=({value:e})=>tl(e)?n.jsx(s.ColorSwatch,{ml:8,size:16,color:e}):n.jsx(s.ColorSwatch,{ml:8,size:16,color:""}),fp=({value:e,onChange:t,shouldPatch:r})=>{const{t:a}=x.useTranslation(),[l,o]=h.useState(e);h.useEffect(()=>{r&&o(e)},[e,r]);const i=h.useCallback(c=>{const d=c.currentTarget.value;o(d),gp(d)&&t(d)},[t]);return n.jsx(s.TextInput,{value:l,onChange:i,leftSection:n.jsx(rl,{value:l}),size:"xs",placeholder:a("chart.color.not_set"),styles:{root:{flexGrow:1},input:{fontFamily:"monospace",letterSpacing:2,textAlign:"center",textTransform:"uppercase"}}})},bp=["gray","red","grape","blue","cyan","green","yellow"],al=({Trigger:e,value:t,onChange:r,clear:a})=>{const{t:l}=x.useTranslation(),o=s.useMantineTheme(),[i,{set:c,setFalse:d,toggle:u}]=O.useBoolean(),[p,f]=h.useState(!1),v=h.useMemo(()=>{const z=[];return bp.forEach(D=>{const I=o.colors[D];I&&I.forEach(L=>{z.push(L)})}),z},[o.colors]),_=(z,D=!0)=>{r(z),D&&d()},w=h.useCallback(z=>{_(z,!1),f(!1)},[]),m=h.useCallback(z=>{_(z,!1),f(!0)},[]),k=()=>{a(),d()};return n.jsxs(s.Popover,{opened:i,onChange:c,shadow:"md",withinPortal:!0,zIndex:340,withArrow:!0,children:[n.jsx(s.Popover.Target,{children:n.jsx(e,{onClick:u})}),n.jsx(s.Popover.Dropdown,{children:n.jsxs(s.Stack,{gap:"xs",children:[n.jsxs(s.Group,{justify:"flex-end",children:[n.jsx(fp,{value:t,onChange:w,shouldPatch:p}),n.jsx(s.ActionIcon,{variant:"default",onClick:k,title:l("common.actions.clear"),children:n.jsx(S.IconCircleOff,{stroke:1.5,size:"1rem"})}),n.jsx(s.ActionIcon,{variant:"default",onClick:d,title:l("common.actions.close"),children:n.jsx(S.IconX,{stroke:1.5,size:"1rem"})})]}),n.jsxs(s.SimpleGrid,{cols:2,children:[n.jsx(s.ColorPicker,{format:"hex",swatches:v,value:t,onChange:m,size:"sm",withPicker:!1,styles:{swatches:{marginTop:"0 !important"}}}),n.jsx(s.ColorPicker,{format:"hex",fullWidth:!0,value:t,onChange:m})]})]})})]})},yp=({color:e,label:t})=>h.forwardRef(({onClick:r},a)=>n.jsx(s.Button,{ref:a,size:"sm",variant:"default",leftSection:n.jsx(rl,{value:e}),onClick:r,children:t})),ye=h.forwardRef(({value:e="",onChange:t,label:r},a)=>{const l=h.useCallback(()=>{t("")},[t]),o=h.useMemo(()=>nl(e),[e]);return n.jsx(al,{value:o,onChange:t,clear:l,Trigger:yp({color:o,label:r})})}),le={mantissa:0,output:"number",trimMantissa:!1,average:!1,absolute:!1};function Y(e,{absolute:t,...r}){if(e===null)return String(e);try{let a=Ye(e).value();if(a===void 0||Number.isNaN(a))throw new Error(`[formatNumber]Not a number: ${e}`);return t&&(a=Math.abs(a)),Ye(a).format(r)}catch(a){return console.debug(a),String(e)}}function vp(e){return e===null?"null":e===void 0?"undefined":Array.isArray(e)?`Array(${e.length})`:e.toString()}function Re({data_field:e,aggregation:t},r){return Nn(r,e,t)}function $e({formatter:e,aggregation:t},r){if(typeof r!="string"&&typeof r!="number")return vp(r);if(t.type==="custom")return r;try{return Y(r,e)}catch(a){return console.error(a),r}}function It(e,t){return e.replaceAll(/(\$\{([^{\}]+(?=}))\})/g,(...a)=>{const l=a[2],o=t.variableStyleMap[l];if(!o)return`{{${l}}}`;const{variable:i,...c}=o,d=Object.entries(c).map(([v,_])=>`${v}:${_}`).join(";"),u=i.color;if(u.type!=="continuous")return`<span style="${d}">{{${l}}}</span>`;const p=Xs(6),f=`try {
|
|
52
52
|
return utils.popmotion.interpolate(${JSON.stringify(u.valueRange)}, ${JSON.stringify(u.colorRange)})(variables["${l}"]);
|
|
53
53
|
} catch (error) {
|
|
54
54
|
console.error(error);
|
|
@@ -527,7 +527,7 @@ Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel vari
|
|
|
527
527
|
</thead>
|
|
528
528
|
<tbody>${_.join("")}</tbody>
|
|
529
529
|
</table>
|
|
530
|
-
`}})}function PC(e,t,r){const{overflow:a,rotate:l}=e.x_axis.axisLabel,o=Be(a.on_axis);return X.getXAxis({id:"main-x-axis",type:"category",data:t,name:e.x_axis.name??"",align:"center",axisTick:{show:!0,alignWithLabel:!0},axisLabel:{rotate:l,...o,formatter:r},splitArea:{show:!1,areaStyle:{color:"#E7E7E9"}},splitLine:{show:!1},nameLocation:"center",nameGap:25,nameTextStyle:{fontWeight:"bold",align:"center"},z:3})}function VC(e,t){const{nameAlignment:r,data_key:a,...l}=e.y_axis,{overflow:o,rotate:i}=e.y_axis.axisLabel,c=Be(o.on_axis);return X.getYAxis({...l,type:"category",axisLabel:{rotate:i,...c,formatter:t},axisLine:{show:!0,lineStyle:{width:3}},axisTick:{show:!0,alignWithLabel:!0},splitArea:{show:!1,areaStyle:{color:"#E7E7E9"}},splitLine:{show:!1},nameTextStyle:{fontWeight:"bold",align:r},nameLocation:"end",nameGap:15,z:3})}function $C(e,t,r){if(!e.x_axis.data_key||!e.y_axis.data_key||!e.heat_block.data_key)return{};const a=r.reduce((m,k)=>{const z=Re(k,t);return m[k.name]=$e(k,z),m},{}),l=TC(e),o=kC(e),i=tn(e.visualMap,a),{min:c,max:d}=i,u=A(e.x_axis.data_key),p=A(e.y_axis.data_key),f=A(e.heat_block.data_key),v=y.uniq(t[u.queryID].map(m=>m[u.columnKey])),_=t[u.queryID].map(m=>{const k=y.get(m,u.columnKey),z=y.get(m,p.columnKey),D=y.get(m,f.columnKey),I={value:[k,z,D]},{followVisualMap:L,color:E}=Rn(D,c,d,e.visualMap);return L||(I.visualMap=!1,I.itemStyle={color:E}),I});return{xAxis:PC(e,v,l.x_axis),yAxis:VC(e,l.y_axis),series:DC(e,_),tooltip:AC(e,t,l,o),grid:zC(e),visualMap:i}}function EC({conf:e,data:t,width:r,height:a,interactionManager:l,variables:o,instance:i}){const c=h.useMemo(()=>{const w=A(e.x_axis.data_key),m=A(e.y_axis.data_key);return y.keyBy(t[w.queryID],k=>`${k[w.columnKey]}---${k[m.columnKey]}`)},[t,e.x_axis.data_key,e.y_axis.data_key]),d=Ie(l.triggerManager,mo.id),u=h.useCallback(w=>{const[m,k]=w.value,z=y.get(c,`${m}---${k}`,{error:"rowData is not found"});d.forEach(D=>{l.runInteraction(D.id,{...w,rowData:z})})},[c,d,l]),p=h.useRef(null),f=h.useCallback(()=>{var m;const w=(m=p.current)==null?void 0:m.getEchartsInstance();w&&de(i,w.getOption())},[i]),v=h.useMemo(()=>({click:u,finished:f}),[u,f]),_=h.useMemo(()=>$C(e,t,o),[e,t]);return n.jsx(he,{echarts:ce,option:_,ref:p,style:{width:r,height:a},onEvents:v,notMerge:!0,theme:"merico-light"})}function BC({context:e,instance:t}){const r=Me({vizManager:e.vizManager,instance:t}),{value:a}=B(e.instanceData,"config"),{variables:l}=e,o=h.useMemo(()=>y.defaults({},a,jr),[a]),i=e.data,{width:c,height:d}=e.viewport;return!c||!d?null:n.jsx(_e,{width:c,height:d,children:n.jsx(EC,{instance:t,variables:l,width:Ge(c),height:Fe(d),data:i,conf:o,interactionManager:r})})}const LC=[{lang:"en",resources:{merico_heatmap:{viz_name:"Merico Heatmap",click_heatmap:{heatblock:{label:"Click heat block"}}}}},{lang:"zh",resources:{merico_heatmap:{viz_name:"思码逸热力图",click_heatmap:{heatblock:{label:"点击热力块"}}}}}];function qC(e){const{visualMap:t=et(),heat_block:{min:r,max:a,...l},...o}=e;return{...o,heat_block:l,visualMap:{...et(),min:r,max:a}}}function OC(e){const t=e.tooltip.metrics;return{...e,tooltip:{...e.tooltip,metrics:t.map(r=>({...r,unit:r.unit??U()}))}}}function NC(e){const{heat_block:t}=e;return{...e,heat_block:{...t,unit:t.unit??U()}}}class GC extends ee{constructor(){super(...arguments);P(this,"VERSION",4)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,r=>({...r,version:2,config:qC(r.config)})),this.version(3,r=>({...r,version:3,config:OC(r.config)})),this.version(4,r=>({...r,version:4,config:NC(r.config)}))}}const FC={displayName:"viz.merico_heatmap.viz_name",displayGroup:"chart.groups.merico_suite",migrator:new GC,name:"merico-heatmap",viewRender:BC,configRender:mC,createConfig:()=>({version:4,config:jr}),triggers:[mo],translation:LC},Qr={item_badge:"_item_badge_l2t3l_1",label:"_label_l2t3l_8",value:"_value_l2t3l_20"},jC=({children:e})=>["string","number"].includes(typeof e)?n.jsx(s.Text,{size:"xs",ff:"monospace",children:e}):e,bt=h.forwardRef(({label:e,value:t,label_description:r,value_description:a},l)=>n.jsxs("div",{ref:l,className:Qr.item_badge,children:[n.jsx("div",{className:Qr.label,children:e}),n.jsxs(s.HoverCard,{shadow:"md",disabled:!a,children:[n.jsx(s.HoverCard.Target,{children:n.jsx("div",{className:Qr.value,"data-with-tooltip":!!a,children:t})}),n.jsx(s.HoverCard.Dropdown,{p:"xs",children:n.jsx(jC,{children:a})})]})]})),QC=({item:e})=>e.type!=="checkbox"?null:n.jsx(bt,{label:e.label,value:n.jsx(s.ThemeIcon,{variant:"white",radius:"xs",color:e.value?"teal":"red",w:12,h:12,miw:12,mih:12,children:e.value?n.jsx(S.IconCheck,{size:12,strokeWidth:3}):n.jsx(S.IconX,{strokeWidth:3})}),label_description:`filters.${e.key}`}),WC=({item:e})=>e.type!=="context"?null:n.jsx(bt,{label:e.key,value:e.value,label_description:`context.${e.key}`}),UC=T.observer(({item:e})=>{const{t}=x.useTranslation(),a=e.model.value,[l,o]=a.value,i=h.useMemo(()=>!o&&!l?Number.NaN:M(o).diff(M(l),"days")+1,[l,o]);if(Number.isNaN(i))return n.jsx("span",{style:{userSelect:"none",opacity:0,visibility:"hidden"},children:"."});const c=i===1?t("filter.widget.date_range.one_day"):t("filter.widget.date_range.x_days",{count:i});return n.jsx(bt,{label:e.label,value:e.value.join(" ~ "),label_description:`filters.${e.key}`,value_description:c})}),YC=({item:e})=>e.type!=="date-range"?null:n.jsx(UC,{item:e}),Co=({selection:e})=>(x.useTranslation(),e.length===0?null:n.jsx(s.Group,{justify:"flex-start",gap:"xs",maw:"80vw",children:e.map(t=>n.jsx(s.Pill,{size:"xs",ff:"monospace",children:t.label},t.value))})),KC=T.observer(({item:e})=>{x.useTranslation();const r=e.model.config,a=h.useMemo(()=>r.optionsByValues(e.value),[e.value,r.options]);return n.jsx(bt,{label:e.label,value:a.length,label_description:`filters.${e.key}`,value_description:n.jsx(Co,{selection:a})})}),XC=({item:e})=>e.type!=="multi-select"?null:n.jsx(KC,{item:e}),ZC=T.observer(({item:e})=>{x.useTranslation();const r=e.model.config,a=h.useMemo(()=>{var l;return((l=r.options.find(o=>o.value===e.value))==null?void 0:l.label)??e.value},[e.value,r.options]);return n.jsx(bt,{label:e.label,value:a,label_description:`filters.${e.key}`})}),JC=({item:e})=>e.type!=="select"?null:n.jsx(ZC,{item:e}),HC=({item:e})=>e.type!=="text-input"?null:n.jsx(bt,{label:e.label,value:n.jsx(s.Text,{maw:200,size:"xs",truncate:"end",ff:"monospace",children:e.value}),value_description:e.value}),RC=T.observer(({item:e})=>{x.useTranslation();const r=e.model.config,a=h.useMemo(()=>r.optionsByValues(e.value),[e.value,r.options]);return n.jsx(bt,{label:e.label,value:a.length,label_description:`filters.${e.key}`,value_description:n.jsx(Co,{selection:a})})}),eS=({item:e})=>e.type!=="tree-select"?null:n.jsx(RC,{item:e}),tS=T.observer(({item:e})=>{x.useTranslation();const r=e.model.config,a=h.useMemo(()=>{var l;return((l=r.options.find(o=>o.value===e.value))==null?void 0:l.label)??e.value},[e.value,r.options]);return n.jsx(bt,{label:e.label,value:a,label_description:`filters.${e.key}`,value_description:e.value})}),nS=({item:e})=>e.type!=="tree-single-select"?null:n.jsx(tS,{item:e}),Wr=({item:e})=>{switch(e.type){case"date-range":return n.jsx(YC,{item:e});case"select":return n.jsx(JC,{item:e});case"tree-single-select":return n.jsx(nS,{item:e});case"multi-select":return n.jsx(XC,{item:e});case"tree-select":return n.jsx(eS,{item:e});case"text-input":return n.jsx(HC,{item:e});case"checkbox":return n.jsx(QC,{item:e});case"context":return n.jsx(WC,{item:e});default:return null}},rS=T.observer(({conf:e})=>{const r=J().dashboardState,{all:a,keys:l}=e;return a?n.jsxs(n.Fragment,{children:[Object.entries(r.context).map(([o,i])=>n.jsx(Wr,{item:i},o)),Object.entries(r.filters).map(([o,i])=>n.jsx(Wr,{item:i},o))]}):n.jsx(n.Fragment,{children:l.map(o=>{const i=y.get(r,o);return i?n.jsx(Wr,{item:i},o):null})})}),aS=T.observer(({context:e})=>{const{value:t}=B(e.instanceData,"config"),{width:r,height:a}=e.viewport;return t?n.jsx(s.Group,{justify:"flex-start",align:"flex-start",wrap:"wrap",px:0,py:0,gap:"xs",w:r,mah:a,style:{overflow:"auto"},"data-enable-scrollbar":!0,children:n.jsx(rS,{conf:t})}):null}),So={all:!0,keys:[]},sS={select:"filter.widget.names.select","multi-select":"filter.widget.names.multi_select","tree-select":"filter.widget.names.tree_select","tree-single-select":"filter.widget.names.tree_single_select","text-input":"filter.widget.names.text_input",checkbox:"filter.widget.names.checkbox","date-range":"filter.widget.names.date_range"},lS=({option:e,checked:t,...r})=>{const{t:a}=x.useTranslation(),l=e,o=l.type==="filter";return n.jsxs(s.Group,{gap:4,flex:1,children:[n.jsx(S.IconCheck,{size:14,opacity:t?1:0,color:"black"}),n.jsx(s.Stack,{gap:0,py:4,px:8,flex:1,styles:{root:{flexGrow:1,borderRadius:"4px"}},...r,children:n.jsxs(s.Group,{justify:"space-between",wrap:"nowrap",children:[n.jsx(s.Text,{size:"xs",children:e.label}),o&&n.jsx(s.Text,{size:"xs",c:t?"rgba(0,0,0,.8)":"dimmed",style:{flexShrink:0,flexGrow:0},children:a(sS[l.widget])})]})})]})},oS=T.observer(({value:e,onChange:t,disabled:r})=>{const{t:a}=x.useTranslation(),o=F().dashboardStateVariableOptions,i=h.useMemo(()=>{const{optionGroups:c,validValues:d}=o,u=c.map(f=>({group:a(f.group),items:f.items.map(v=>({...v,label:v.label,value:v.value,widget_label:v.label}))})),p=e.filter(f=>!d.has(f)).map(f=>({label:f,value:f,disabled:!0}));return p.length>0&&u.push({group:a("common.invalid"),items:p}),u},[o,a,e]);return n.jsx(s.MultiSelect,{size:"xs",label:a("viz.vizDashboardState.variable_selector.label"),placeholder:e.length===0?a("viz.vizDashboardState.variable_selector.placeholder"):void 0,data:i,renderOption:lS,maxDropdownHeight:600,value:e,onChange:t,disabled:r,clearable:!0})}),iS=({form:e})=>{const{t}=x.useTranslation(),r=e.watch("all");return n.jsxs(s.Stack,{gap:"xs",p:"xs",children:[n.jsx(b.Controller,{name:"all",control:e.control,render:({field:a})=>n.jsx(s.Checkbox,{size:"xs",label:t("viz.vizDashboardState.show_all"),checked:a.value,onChange:l=>a.onChange(l.currentTarget.checked)})}),n.jsx(b.Controller,{name:"keys",control:e.control,render:({field:a})=>n.jsx(oS,{disabled:r,...a})})]})};function cS({context:e}){const{value:t,set:r}=B(e.instanceData,"config"),a=h.useMemo(()=>y.defaultsDeep({},t,So),[t]),l=b.useForm({defaultValues:a}),{handleSubmit:o,formState:i,reset:c}=l;return h.useEffect(()=>{c(a)},[a]),n.jsxs("form",{onSubmit:o(r),children:[n.jsx(ae,{canSubmit:i.isDirty}),n.jsx(iS,{form:l})]})}const dS=[{lang:"en",resources:{vizDashboardState:{viz_name:"Dashboard State",show_all:"Show all filters and context entries",variable_selector:{label:"Select filters and context entries to show",placeholder:""}}}},{lang:"zh",resources:{vizDashboardState:{viz_name:"看板状态",show_all:"显示所有筛选器和上下文条目",variable_selector:{label:"选择要展示的筛选器和上下文",placeholder:""}}}}];class uS extends ee{constructor(){super(...arguments);P(this,"VERSION",1)}configVersions(){this.version(1,r=>({version:1,config:r}))}}const pS={displayName:"viz.vizDashboardState.viz_name",displayGroup:"chart.groups.others",migrator:new uS,name:"vizDashboardState",viewRender:aS,configRender:cS,createConfig:()=>({version:1,config:So}),translation:dS},hS=[{value:"#25262B",name:"Dark"},{value:"#868E96",name:"Gray"},{value:"#FA5252",name:"Red"},{value:"#E64980",name:"Pink"},{value:"#BE4BDB",name:"Grape"},{value:"#7950F2",name:"Violet"},{value:"#4C6EF5",name:"Indigo"},{value:"#228BE6",name:"Blue"},{value:"#15AABF",name:"Cyan"},{value:"#12B886",name:"Teal"},{value:"#40C057",name:"Green"},{value:"#82C91E",name:"Lime"},{value:"#FAB005",name:"Yellow"},{value:"#FD7E14",name:"Orange"}].map(e=>({name:e.name,value:e.value,type:"single",category:"basic"})),gS=[eu,tu,au,ru,nu,su],Ur=[$r,Mw,Jm,ux,Hw,l_,C1,$p,Fg,Jb,Gy,L0,kv,Pb,uw,P_,lx,l0,rC,FC,fC,ef,pS],To=Ur.reduce((e,t)=>(e[t.name]={displayName:t.displayName,displayGroup:t.displayGroup},e),{}),ko=()=>({id:"dashboard",version:Cs,manifest:{viz:Ur,color:[...hS,...gS]}}),Ct=new uu,R={pluginManager:Je("pluginManager"),vizManager:Je("vizManager"),colorManager:Je("colorManager"),panelAddonManager:Je("panelAddonManager"),instanceScope:{panelModel:Je("panelModel"),vizInstance:Je("vizInstance"),interactionManager:Je("interactionManager"),migrator:Je("migrator"),operationManager:Je("operationManager"),triggerManager:Je("triggerManager")}},Yr=()=>{try{Ct.install(ko())}catch{}const e=new Jd(Ct),t=new du(Ct),r=new ou(Ct);return{pluginManager:Ct,vizManager:e,colorManager:t,panelAddonManager:r}},rt=h.createContext(Yr());try{Ct.install(ko())}catch{}const wn=Se.createInstance({debug:!1,fallbackLng:"en",interpolation:{escapeValue:!1},resources:{en:Kd,zh:Xd}}).use(ed).use(x.initReactI18next);wn.init(),Ur.forEach(e=>{var t;(t=e.translation)==null||t.forEach(r=>{wn.addResourceBundle(r.lang,"translation",{viz:r.resources},!0,!0)})});function zo({lang:e,children:t}){return h.useEffect(()=>{wn.changeLanguage(e)},[e]),n.jsx(x.I18nextProvider,{i18n:wn,children:t})}M.extend(id),M.extend(cd),M.extend(dd),M.extend(ud),M.extend(pd),M.extend(hd),M.extend(gd),M.extend(fd),M.extend(bd),M.extend(yd),M.extend(xd),M.extend(wd),M.extend(md),M.extend(Cd),M.extend(Sd),M.extend(vd),M.extend(_d),M.extend(Td),M.extend(kd),M.extend(zd),M.extend(Dd),M.extend(Id),M.extend(Md),M.extend(Ad),M.extend(Pd),M.extend(Vd),M.extend($d),M.extend(Ed),M.extend(Bd),M.extend(Ld),M.extend(Od),M.extend(Nd),M.extend(qd),M.tz.setDefault("UTC"),M.updateLocale("en",{weekStart:1});function fS(e){e=e||{};const t=Object.keys(e).sort(),r=[];for(let a=0;a<t.length;a++){const l=t[a];if(l!="authentication"&&e[l])r.push(t[a]+"="+(typeof e[l]=="object"?JSON.stringify(e[l]):e[l]));else{const o=Object.keys(e[l]).sort();for(let i=0;i<o.length;i++){const c=o[i];c!="sign"&&e[l][c]&&r.push(o[i]+"="+(typeof e[l][c]=="object"?JSON.stringify(e[l][c]):e[l][c]))}}}return r.sort().join("&")}function bS(e,t){let r=fS(e);return r+="&key="+t,Ud.MD5(r).toString().toUpperCase()}class Do{constructor(){this.type="default_api_client",this.baseURL="http://localhost:31200",this.app_id="",this.app_secret=""}getAuthentication(t){if(!this.app_id||!this.app_secret)return;const r=new Date().getTime().toString();return{app_id:this.app_id,nonce_str:r,sign:bS({app_id:this.app_id,nonce_str:r,...t},this.app_secret)}}getRequest(t,r){return(a,l,o,i)=>{const c=this.buildHeader(o),d=this.buildAxiosConfig(t,a,l,o,c,r);return ke(d).then(u=>i?u:u.data).catch(u=>{if(ke.isCancel(u))return Promise.reject(u);const p=u,f=y.get(p,"response.data.detail.message",p.message);return Promise.reject(new Error(f))})}}get(t){return this.getRequest("GET",t)}post(t){return this.getRequest("POST",t)}put(t){return this.getRequest("PUT",t)}buildAxiosConfig(t,r,a,l,o,i){const c={baseURL:this.baseURL,method:t,url:r,params:t==="GET"?a:l.params,headers:o,signal:i};return["POST","PUT"].includes(t)&&(c.data=l.string?JSON.stringify(a):a,c.data.authentication=this.getAuthentication(c.data)),c}buildHeader(t){const r=window.localStorage.getItem("token");return{"X-Requested-With":"XMLHttpRequest","Content-Type":t.string?"application/x-www-form-urlencoded":"application/json",authorization:r?`bearer ${r}`:"",...t.headers}}}class yS{constructor(t){this.implementation=t}getRequest(t,r){return this.implementation.getRequest(t,r)}get(t){return this.getRequest("GET",t)}post(t){return this.getRequest("POST",t)}put(t){return this.getRequest("PUT",t)}}class Io extends Do{constructor(){super(...arguments);P(this,"makeQueryENV",null)}query(r){return async(a,l={})=>{var o;return a.env||(a.env=((o=this.makeQueryENV)==null?void 0:o.call(this))??{error:"failed to run makeQueryENV"}),this.post(r)("/query",a,l)}}httpDataSourceQuery(r){return async(a,l={})=>{var o;return a.env||(a.env=((o=this.makeQueryENV)==null?void 0:o.call(this))??{error:"failed to run makeQueryENV"}),this.getRequest("POST",r)("/query",a,l,!0)}}structure(r){return async(a,l={})=>this.post(r)("/query/structure",a,l)}mericoMetricInfo(r){return async(a,l={})=>this.post(r)("/query/merico_metric_info",a,l,!0)}mericoMetricQuery(r){return async(a,l={})=>this.post(r)("/query",a,l,!0)}}class Mo{constructor(t){this.implementation=t}query(t){return this.implementation.query(t)}httpDataSourceQuery(t){return this.implementation.httpDataSourceQuery(t)}structure(t){return this.implementation.structure(t)}mericoMetricInfo(t){return this.implementation.mericoMetricInfo(t)}mericoMetricQuery(t){return this.implementation.mericoMetricQuery(t)}getRequest(t,r){return this.implementation.getRequest(t,r)}get(t){return this.getRequest("GET",t)}post(t){return this.getRequest("POST",t)}put(t){return this.getRequest("PUT",t)}}const Et=new Io;function Kr(e){Et.baseURL!==e.apiBaseURL&&(Et.baseURL=e.apiBaseURL),e.app_id&&(Et.app_id=e.app_id),e.app_secret&&(Et.app_secret=e.app_secret),e.makeQueryENV&&(Et.makeQueryENV=e.makeQueryENV)}const Ao=new Mo(Et),Ae=Ao,Xr=g.types.model("MockContextMeta",{current:g.types.optional(g.types.frozen(),{})}).views(e=>({get keys(){return Object.keys(e.current)},get keySet(){return new Set(this.keys)},get entries(){return Object.entries(e.current)}})).actions(e=>({replace(t){e.current=t},defaults(t){e.current={...t,...e.current}},get(t){return e.current[t]},set(t,r){e.current[t]=r}}));function Zr(e){return{current:e}}const vS=g.types.model("PanelStyleBorderMeta",{enabled:g.types.boolean}).views(e=>({get json(){const{enabled:t}=e;return{enabled:t}}})).actions(e=>({setEnabled(t){e.enabled=t}})),Po=g.types.model("PanelStyleMeta",{border:vS}).views(e=>({get json(){const{border:t}=e;return{border:t.json}}})).actions(e=>({})),Vo=g.types.model("PanelTitleMeta",{show:g.types.optional(g.types.boolean,!0)}).views(e=>({get json(){const{show:t}=e;return{show:t}}})).actions(e=>({setShow(t){e.show=t}})),$o=g.types.model("VariableMeta",{name:g.types.string,size:g.types.string,weight:g.types.string,color:g.types.union(g.types.model({type:g.types.literal("static"),staticColor:g.types.string}),g.types.model({type:g.types.literal("continuous"),valueRange:g.types.array(g.types.number),colorRange:g.types.array(g.types.string)}),g.types.model({type:g.types.literal("piecewise")})),formatter:g.types.model({output:g.types.enumeration("Output",["number","percent"]),average:g.types.optional(g.types.boolean,!1),mantissa:g.types.number,trimMantissa:g.types.optional(g.types.boolean,!1),absolute:g.types.optional(g.types.boolean,!1)}),data_field:g.types.string,aggregation:g.types.union(g.types.model({type:g.types.enumeration(["none","sum","mean","median","min","max","CV","std"]),config:g.types.frozen(),fallback:g.types.optional(g.types.string,"0")}),g.types.model({type:g.types.literal("quantile"),config:g.types.model({p:g.types.number}),fallback:g.types.optional(g.types.string,"0")}),g.types.model({type:g.types.literal("pick_record"),config:g.types.model({method:g.types.enumeration("Pick Record Method",["first","last"])}),fallback:g.types.optional(g.types.string,"0")}),g.types.model({type:g.types.literal("custom"),config:g.types.model({func:g.types.string}),fallback:g.types.optional(g.types.string,"0")}))}).views(e=>({get json(){const{name:t,size:r,weight:a,color:l,formatter:o,data_field:i,aggregation:c}=e;return y.cloneDeep({name:t,size:r,color:l,weight:a,formatter:o,data_field:i,aggregation:c})}})),Eo=g.types.model("PanelVizMeta",{type:g.types.string,conf:g.types.frozen()}).views(e=>({get json(){return{conf:e.conf,type:e.type}}})).actions(e=>({setType(t){e.type=t},setConf(t){y.isEqual(e.conf,t)||(e.conf=t)}})),Bo=g.types.model({id:g.types.string,name:g.types.optional(g.types.string,""),title:Vo,description:g.types.string,queryIDs:g.types.array(g.types.string),viz:Eo,style:Po,variables:g.types.optional(g.types.array($o),[])}).views(e=>({get json(){const{id:t,name:r,title:a,description:l,queryIDs:o}=e;return{id:t,viz:e.viz.json,name:r,style:e.style.json,title:a.json,queryIDs:[...o],variables:e.variables.map(i=>i.json),description:l}},get queryIDSet(){return new Set(e.queryIDs)}})).actions(e=>({setID(t){e.id=t},setName(t){e.name=t},setDescription(t){e.description=t},addQueryID(t){e.queryIDSet.has(t)||e.queryIDs.push(t)},removeQueryID(t){if(!e.queryIDSet.has(t))return;const r=new Set(e.queryIDSet);r.delete(t),e.queryIDs=g.cast(Array.from(r))},setQueryIDs(t){e.queryIDs=g.cast(t)},addVariable(t){e.variables.push(t)},removeVariable(t){e.variables.remove(t)}}));var j=(e=>(e.Postgresql="postgresql",e.MySQL="mysql",e.HTTP="http",e.Transform="transform",e.MericoMetricSystem="merico_metric_system",e))(j||{});const Lo=g.types.model("DBQueryMeta",{_type:g.types.enumeration([j.MySQL,j.Postgresql]),sql:g.types.string}).views(e=>({get base(){return g.getParent(e)},get valid(){return!!e.sql},get json(){const{sql:t,_type:r}=e;return{sql:t,_type:r}}})).actions(e=>({setSQL(t){e.sql=t}})),_S=e=>Lo.create({_type:e,sql:""}),qo=g.types.model("HTTPQueryMeta",{_type:g.types.literal(j.HTTP),react_to:g.types.optional(g.types.array(g.types.string),[])}).views(e=>({get valid(){return!0},get json(){const{react_to:t,_type:r}=e;return tt({react_to:t,_type:r})}})).actions(e=>({setReactTo(t){e.react_to.length=0,e.react_to.push(...t)}})),xS=()=>qo.create({_type:j.HTTP,react_to:[]}),Oo=g.types.model("TransformQueryMeta",{_type:g.types.literal(j.Transform),dep_query_ids:g.types.optional(g.types.array(g.types.string),[]),react_to:g.types.optional(g.types.array(g.types.string),[])}).views(e=>({get valid(){return e.dep_query_ids.length>0},get json(){const{dep_query_ids:t,_type:r,react_to:a}=e;return tt({dep_query_ids:t,_type:r,react_to:a})}})).actions(e=>({setDependantQueryIDs(t){e.dep_query_ids.length=0,e.dep_query_ids.push(...t)},setReactTo(t){e.react_to.length=0,e.react_to.push(...t)}})),wS=()=>Oo.create({_type:j.Transform,dep_query_ids:[]}),No=g.types.model("MetricFilterColMeta",{dimension:g.types.optional(g.types.string,""),variable:g.types.optional(g.types.string,"")}).views(e=>({get allEmpty(){return!e.dimension&&!e.variable},get json(){const{dimension:t,variable:r}=e;return{dimension:t,variable:r}}})).actions(e=>({removeSelf(){g.getParent(e,2).removeFilter(e)},setDimension(t){e.dimension=t??"",e.allEmpty&&this.removeSelf()},setVariable(t){e.variable=t??"",e.allEmpty&&this.removeSelf()}})),Jr=g.types.model("MericoMetricQueryMeta",{_type:g.types.literal(j.MericoMetricSystem),id:g.types.optional(g.types.string,""),type:g.types.optional(g.types.enumeration("MetricType",["derived","combined"]),"derived"),filters:g.types.optional(g.types.array(No),[]),groupBys:g.types.optional(g.types.array(g.types.string),[]),timeQuery:g.types.model({enabled:g.types.optional(g.types.boolean,!1),range_variable:g.types.optional(g.types.string,""),unit_variable:g.types.optional(g.types.string,""),timezone:g.types.optional(g.types.string,"PRC"),stepKeyFormat:g.types.optional(g.types.string,"YYYY-MM-DD")})}).views(e=>({get query(){return g.getParent(e)},get valid(){return!!e.id},get json(){const{id:t,type:r,filters:a,groupBys:l,timeQuery:o,_type:i}=e;return tt({id:t,type:r,filters:a.map(c=>c.json),groupBys:l,timeQuery:o,_type:i})},get usedFilterDimensionKeys(){const t=e.filters.map(r=>r.dimension).filter(r=>!!r);return new Set(t)},get usedFilterVariableSet(){const t=[...e.filters.map(r=>r.variable)].filter(r=>!!r);return new Set(t)},get usedTimeQueryVariableSet(){const t=[e.timeQuery.range_variable,e.timeQuery.unit_variable].filter(r=>!!r);return new Set(t)},get groupByValues(){const t=e.groupBys.map(r=>r.replace(/^(.+)\s->\s(.*)/,"$1"));return Array.from(new Set(t))}})).actions(e=>({reset(){e.filters.length=0,e.groupBys.length=0,e.timeQuery.enabled=!1,e.timeQuery.range_variable="",e.timeQuery.unit_variable="","data"in e.query&&(e.query.setData([]),e.query.setError(null))},setID(t){t!==e.id&&this.reset(),e.id=t},setType(t){t!=="derived"&&t!=="combined"||(e.type=t)},addFilter(t,r){t&&e.usedFilterDimensionKeys.has(t)||e.filters.push(No.create({dimension:t,variable:r}))},removeFilter(t){g.destroy(t)},setGroupBys(t){e.groupBys.length=0,e.groupBys.push(...t)},setRangeVariable(t){e.timeQuery.range_variable=t??""},setUnitVariable(t){e.timeQuery.unit_variable=t??""},setTimeQueryEnabled(t){e.timeQuery.enabled=t,t?e.groupBys.length>1&&(e.groupBys.length=0):(e.timeQuery.range_variable="",e.timeQuery.unit_variable="")}})),Go=()=>Jr.create({_type:j.MericoMetricSystem,id:"",type:"derived",filters:[],groupBys:[],timeQuery:{range_variable:"",unit_variable:"",timezone:"PRC",stepKeyFormat:"YYYY-MM-DD"}}),Fo=g.types.model("QueryMeta",{id:g.types.string,name:g.types.string,key:g.types.string,type:g.types.enumeration("DataSourceType",[j.Postgresql,j.MySQL,j.HTTP,j.Transform,j.MericoMetricSystem]),config:g.types.union(Lo,qo,Oo,Jr),pre_process:g.types.optional(g.types.string,""),post_process:g.types.optional(g.types.string,""),run_by:g.types.optional(g.types.array(g.types.string),[])}).views(e=>({get valid(){const{id:t,name:r,key:a,type:l,config:o}=e;return o.valid&&!!t&&!!r&&!!a&&!!l},get json(){const{id:t,name:r,key:a,type:l,config:o,pre_process:i,post_process:c,run_by:d}=e;return tt({id:t,name:r,key:a,type:l,config:o.json,pre_process:i,post_process:c,run_by:d})}})).actions(e=>({setName(t){e.name=t},setKey(t){e.key=t},setType(t){switch(e.type=t,t){case j.HTTP:e.config=xS();break;case j.MySQL:case j.Postgresql:e.config=_S(t);break;case j.Transform:e.config=wS();break;case j.MericoMetricSystem:e.config=Go();break;default:throw new Error(`Unexpected query type[${t}]`)}},setRunBy(t){e.run_by.length=0,e.run_by.push(...t)},setPreProcess(t){e.pre_process=t},setPostProcess(t){e.post_process=t}})),jo=g.types.model("LayoutItemMeta",{id:g.types.identifier,panelID:g.types.string,x:g.types.number,y:g.types.maybeNull(g.types.number),w:g.types.number,h:g.types.number,moved:g.types.optional(g.types.boolean,!1),static:g.types.optional(g.types.boolean,!1)}).views(e=>({get json(){const{id:t,panelID:r,x:a,y:l,w:o,h:i,moved:c}=e;return{h:i,w:o,x:a,y:l===null?0:l,id:t,moved:c,static:e.static,panelID:r}},get contentModel(){return g.getRoot(e).content},get panel(){const{panelID:t}=e;return this.contentModel.panels.findByID(t)},get layoutProperies(){const{id:t,x:r,y:a,w:l,h:o,moved:i}=e;return{id:t,i:t,x:r,y:a===null?1/0:a,w:l,h:o,moved:i,static:e.static}}})).actions(e=>({set(t){const{isDraggable:r,x:a,y:l,w:o,h:i,moved:c}=t;e.x=a,e.y=l,e.w=o,e.h=i,e.moved=!!c,e.static=!!t.static},setWidth(t){e.w=t},setHeight(t){e.h=t}})),Qo=g.types.model("LayoutSetMeta",{id:g.types.identifier,name:g.types.string,breakpoint:g.types.number,list:g.types.optional(g.types.array(jo),[])}).views(e=>({get contentModel(){return g.getRoot(e).content},get json(){const{id:t,name:r,breakpoint:a,list:l}=e;return{id:t,name:r,breakpoint:a,list:l.map(o=>tt(o.json))}},jsonByPanelIDSet(t){const{id:r,name:a,breakpoint:l,list:o}=e;return{id:r,name:a,breakpoint:l,list:o.filter(i=>t.has(i.panelID)).map(i=>tt(i.json))}},findByID(t){return e.list.find(r=>r.id===t)},findByPanelID(t){return e.list.find(r=>r.panelID===t)}})).actions(e=>({setName(t){e.name=t},setBreakpoint(t){e.breakpoint=t},addLayout(t){e.list.push(t)},addNewLayout(t){e.list.push({id:Ke.v4(),panelID:t,x:0,y:1/0,w:18,h:300,static:!1,moved:!1})},removeByPanelID(t){const r=e.list.findIndex(a=>a.panelID===t);r>=0&&e.list.splice(r,1)},removeByPanelIDs(t){for(;t.length>0;){const r=t.pop();r&&this.removeByPanelID(r)}},updateLayoutItem(t){const r=e.list.find(a=>a.id===t.i);if(!r){console.error("Trying to update a layout that doesn't exist"),console.log({strangeLayoutItem:t});return}r.set(t)}})).actions(e=>({afterCreate(){g.addDisposer(e,Q.reaction(()=>{const t=e.list.length,r=e.contentModel.panels.list.length;return{match:t===r,layoutCount:t,panelCount:r}},({match:t,panelCount:r,layoutCount:a})=>{if(t)return;const l={id:"layout panel count mismatch",title:"Error detected, please don't save changes.",message:`${a} layout items against and ${r} panels.`,color:"red",autoClose:!1};Ze.showNotification(l),Ze.updateNotification(l)},{fireImmediately:!0,delay:0}))}})),Wo=g.types.model("SQLSnippetMeta",{key:g.types.string,value:g.types.string}).views(e=>({get json(){const{key:t,value:r}=e;return{key:t,value:r}}})).actions(e=>({setKey(t){e.key=t},setValue(t){e.value=t}}));var V=(e=>(e.Select="select",e.MultiSelect="multi-select",e.TreeSelect="tree-select",e.TreeSingleSelect="tree-single-select",e.TextInput="text-input",e.Checkbox="checkbox",e.DateRange="date-range",e))(V||{});const Hr=g.types.optional(g.types.enumeration(["intersect","reset"]),"intersect"),Rr=g.types.model("FilterCheckboxConfigMeta",{_name:g.types.literal("checkbox"),description:g.types.optional(g.types.string,""),default_value:g.types.boolean}).views(e=>({get json(){const{_name:t,description:r,default_value:a}=e;return{_name:t,description:r,default_value:a}},get isDescriptionEmpty(){const{description:t}=e;return t===""||t==="<p></p>"}})).actions(e=>({setDefaultValue(t){e.default_value=t},setDescription(t){e.description=t}})),Uo=()=>Rr.create({_name:"checkbox",description:"",default_value:!1}),Yo=()=>[{key:"d",value:"yesterday",group:"last",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(1,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()],shortcut:"yesterday"}}},{key:"w",value:"last week",group:"last",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(1,"week").startOf("week").toDate(),M(e).subtract(1,"week").endOf("week").toDate()],shortcut:"last week"}}},{key:"m",value:"last month",group:"last",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(1,"month").startOf("month").toDate(),M(e).subtract(1,"month").endOf("month").toDate()],shortcut:"last month"}}},{key:"m2",value:"last 2 months",group:"last",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(2,"month").startOf("month").toDate(),M(e).subtract(1,"month").endOf("month").toDate()],shortcut:"last 2 months"}}},{key:"m3",value:"last 3 months",group:"last",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(3,"month").startOf("month").toDate(),M(e).subtract(1,"month").endOf("month").toDate()],shortcut:"last 3 months"}}},{key:"y",value:"last year",group:"last",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(1,"year").startOf("year").toDate(),M(e).subtract(1,"year").endOf("year").toDate()],shortcut:"last year"}}},{key:"d7",value:"recent 7 days",group:"recent",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(7,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()],shortcut:"recent 7 days"}}},{key:"d30",value:"recent 30 days",group:"recent",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(30,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()],shortcut:"recent 30 days"}}},{key:"d60",value:"recent 60 days",group:"recent",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(60,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()],shortcut:"recent 60 days"}}},{key:"d90",value:"recent 90 days",group:"recent",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(90,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()],shortcut:"recent 90 days"}}},{key:"d180",value:"recent 180 days",group:"recent",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(180,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()],shortcut:"recent 180 days"}}},{key:"d365",value:"recent 365 days",group:"recent",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(365,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()],shortcut:"recent 365 days"}}},{key:"d",value:"today",group:"this",getRange:()=>{const e=Date.now();return{value:[M(e).startOf("day").toDate(),M(e).endOf("day").toDate()],shortcut:"today"}}},{key:"w",value:"this week",group:"this",getRange:()=>{const e=Date.now();return{value:[M(e).startOf("week").toDate(),M(e).endOf("week").toDate()],shortcut:"this week"}}},{key:"m",value:"this month",group:"this",getRange:()=>{const e=Date.now();return{value:[M(e).startOf("month").toDate(),M(e).endOf("month").toDate()],shortcut:"this month"}}},{key:"y",value:"this year",group:"this",getRange:()=>{const e=Date.now();return{value:[M(e).startOf("year").toDate(),M(e).endOf("year").toDate()],shortcut:"this year"}}},{key:"w",value:"this week so far",group:"this_so_far",getRange:()=>{const e=Date.now();return{value:[M(e).startOf("week").toDate(),M(e).toDate()],shortcut:"this week so far"}}},{key:"m",value:"this month so far",group:"this_so_far",getRange:()=>{const e=Date.now();return{value:[M(e).startOf("month").toDate(),M(e).toDate()],shortcut:"this month so far"}}},{key:"y",value:"this year so far",group:"this_so_far",getRange:()=>{const e=Date.now();return{value:[M(e).startOf("year").toDate(),M(e).toDate()],shortcut:"this year so far"}}}];function ea(e){if(!e)return null;const r=Yo().find(a=>a.value===e);return r?r.getRange():null}function Ko(){return y.groupBy(Yo(),"group")}function Xo(e){try{if(e.default_shortcut){const r=ea(e.default_shortcut);if(r)return{value:r.value.map(a=>M(a).toDate()),shortcut:e.default_shortcut}}return{value:e.default_value.map(r=>r===null?r:M.tz(r,"UTC").toDate()??r),shortcut:null}}catch(t){return console.error(t),{value:[null,null],shortcut:null}}}function Zo(e,t){return e.map(r=>{try{return r?M.tz(r,"UTC").toISOString():null}catch{return console.log(`[date-range] failed parsing ${r}`),null}})}const mS=g.types.model("FilterDateRangeConfigMeta",{_name:g.types.literal("date-range"),required:g.types.boolean,inputFormat:g.types.enumeration("DateRangeInputFormat",["YYYY","YYYYMM","YYYYMMDD","YYYY-MM","YYYY-MM-DD"]),default_value:g.types.optional(g.types.array(g.types.union(g.types.Date,g.types.null)),[null,null]),default_shortcut:g.types.optional(g.types.string,""),clearable:g.types.boolean,max_days:g.types.optional(g.types.number,0),allowSingleDateInRange:g.types.optional(g.types.boolean,!1)}).views(e=>({get json(){const{_name:t,max_days:r,required:a,clearable:l,inputFormat:o,default_value:i,default_shortcut:c,allowSingleDateInRange:d}=e;return{_name:t,max_days:r,required:a,clearable:l,inputFormat:o,default_value:Zo(i),default_shortcut:c,allowSingleDateInRange:d}},truthy(t){try{const{value:r}=t;return Array.isArray(r)&&r.length===2&&r.every(a=>!!a)}catch(r){return console.error(r),!1}},get filter(){return g.getParent(e)},get dateStringsValue(){try{const t=this.filter.value,[r,a]=t.value,l=r?M(r).format(e.inputFormat):"",o=a?M(a).format(e.inputFormat):"";return[l,o]}catch(t){return console.error(t),["",""]}}})).actions(e=>({setFilterValue(t){try{e.filter.setValue(t)}catch(r){console.error(r)}}})).actions(e=>({setRequired(t){e.required=t},setClearable(t){e.clearable=t},setInputFormat(t){t&&(e.inputFormat=t)},setDefaultValue(t){e.default_value.length=0,e.default_value.push(...t.value),e.setFilterValue(t)},setDefaultShortcut(t){if(e.default_shortcut=t??"",!t)return;const r=ea(e.default_shortcut);r&&e.setFilterValue(r)},setMaxDays(t){const r=Number(t);Number.isFinite(r)&&(e.max_days=r,r>0&&(e.clearable=!0))},setAllowSingleDateInRange(t){e.allowSingleDateInRange=t}})),ta=g.types.snapshotProcessor(mS,{preProcessor({default_value:e,...t}){return{...t,default_value:e.map(r=>r===null?null:M.tz(r,"UTC").toDate())}},postProcessor(e){const{default_value:t,...r}=e;return{...r,default_value:Zo(t,r.inputFormat)}}}),Jo=()=>ta.create({_name:"date-range",required:!1,inputFormat:"YYYY-MM-DD",clearable:!1,default_value:[null,null]}),Ho=g.types.model({label:g.types.string,value:g.types.string}).actions(e=>({setLabel(t){e.label=t},setValue(t){e.value=t}})),na=g.types.model("FilterConfigModel_BaseSelect",{static_options:g.types.optional(g.types.array(Ho),[]),options_query_id:g.types.optional(g.types.string,""),default_selection_count:g.types.optional(g.types.number,0),required:g.types.optional(g.types.boolean,!1)}).views(e=>({get contentModel(){return g.getRoot(e).content},get filter(){return g.getParent(e)},get usingQuery(){return!!e.options_query_id}})).views(e=>({get optionsLoading(){if(!e.usingQuery)return!1;const{state:t}=e.contentModel.getDataStuffByID(e.options_query_id);return t==="loading"},get options(){if(!e.usingQuery)return e.static_options;const{data:t,state:r}=e.contentModel.getDataStuffByID(e.options_query_id);return r==="error"?[]:Array.isArray(t)?t.filter(a=>"label"in a&&"value"in a):[]},get optionValuesSet(){return new Set(this.options.map(t=>t.value))}})).actions(e=>({setRequired(t){e.required=t},addStaticOption(t){e.static_options.push(t)},removeStaticOption(t){e.static_options.splice(t,1)},replaceStaticOptions(t){e.static_options.forEach(a=>g.detach(a));const r=t.map(a=>Ho.create(a));e.static_options.replace(r)},setDefaultSelectionCount(t){const r=Number(t);Number.isFinite(r)&&(e.default_selection_count=r)},setOptionsQueryID(t){e.options_query_id=t??""}})),ra=g.types.compose("FilterMultiSelectConfigMeta",g.types.model({_name:g.types.literal("multi-select"),min_width:g.types.optional(g.types.string,""),default_value:g.types.optional(g.types.array(g.types.string),[]),default_value_mode:Hr}),na).views(e=>({get json(){const{_name:t,default_value:r,default_value_mode:a,required:l,min_width:o,static_options:i,options_query_id:c,default_selection_count:d}=e;return tt({_name:t,required:!!l,min_width:o,default_value:r,static_options:i,options_query_id:c,default_value_mode:a,default_selection_count:d})},get defaultSelection(){const t=e.filter.formattedDefaultValue;return Array.isArray(t)&&t.length>0||!e.usingQuery?t:e.options.slice(0,e.default_selection_count).map(r=>r.value)},optionsByValues(t){if(!Array.isArray(t)||t.length===0)return[];const r=new Set(t);return e.options.filter(a=>r.has(a.value))},initialSelection(t){return t||this.defaultSelection},truthy(t){return Array.isArray(t)&&t.length>0}})).actions(e=>({setDefaultValue(t){e.default_value=g.cast(t)},setDefaultValueMode(t){t!=="intersect"&&t!=="reset"||(e.default_value_mode=t)},setMinWidth(t){e.min_width=t},applyDefaultSelection(){if(e.optionsLoading)return;if(e.default_value_mode==="reset"){e.filter.setValue(e.defaultSelection);return}const t=new Set(e.options.map(l=>l.value)),a=(e.filter.value??[]).filter(l=>t.has(l));a.length>0?e.filter.setValue(a):e.filter.setValue(e.defaultSelection)}})).actions(e=>({afterCreate(){g.addDisposer(e,Q.reaction(()=>Q.toJS(e.defaultSelection),e.applyDefaultSelection,{fireImmediately:!1,delay:0}))}})),Ro=()=>ra.create({_name:"multi-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),aa=g.types.compose("FilterConfigModel_Select",g.types.model({_name:g.types.literal("select"),default_value:g.types.string,width:g.types.optional(g.types.string,""),clearable:g.types.optional(g.types.boolean,!1)}),na).views(e=>({get json(){const{_name:t,clearable:r,default_value:a,required:l,width:o,static_options:i,options_query_id:c,default_selection_count:d}=e;return tt({_name:t,width:o,required:l,clearable:r,default_value:a,static_options:i,options_query_id:c,default_selection_count:d})},truthy(t){return!!t},getSelectOption(t){return e.options.find(r=>r.value===t)},get default_selection(){return e.usingQuery?e.default_selection_count>0&&e.options.length>0?e.options[0].value:"":e.filter.formattedDefaultValue}})).actions(e=>({setDefaultValue(t){t!==null&&(e.default_value=t)},setWidth(t){e.width=t},setClearable(t){e.clearable=t},setDefaultSelection(){var a;const t=e.filter.value,r=(a=e.options.find(l=>l.value===t))==null?void 0:a.value;r?e.filter.setValue(r):e.filter.setValue(e.default_selection)}})).actions(e=>({afterCreate(){g.addDisposer(e,Q.reaction(()=>Q.toJS(e.default_selection),e.setDefaultSelection,{fireImmediately:!1,delay:0}))}})),ei=()=>aa.create({_name:"select",required:!1,default_value:"",static_options:[],options_query_id:"",default_selection_count:0}),sa=g.types.model("FilterTextInputConfigMeta",{_name:g.types.literal("text-input"),required:g.types.boolean,default_value:g.types.string}).views(e=>({get json(){const{_name:t,required:r,default_value:a}=e;return{_name:t,required:r,default_value:a}},truthy(t){return typeof t!="string"?!1:!!t.trim()}})).actions(e=>({setRequired(t){e.required=t},setDefaultValue(t){e.default_value=t}})),la=()=>sa.create({_name:"text-input",required:!1,default_value:""}),CS=`
|
|
530
|
+
`}})}function PC(e,t,r){const{overflow:a,rotate:l}=e.x_axis.axisLabel,o=Be(a.on_axis);return X.getXAxis({id:"main-x-axis",type:"category",data:t,name:e.x_axis.name??"",align:"center",axisTick:{show:!0,alignWithLabel:!0},axisLabel:{rotate:l,...o,formatter:r},splitArea:{show:!1,areaStyle:{color:"#E7E7E9"}},splitLine:{show:!1},nameLocation:"center",nameGap:25,nameTextStyle:{fontWeight:"bold",align:"center"},z:3})}function VC(e,t){const{nameAlignment:r,data_key:a,...l}=e.y_axis,{overflow:o,rotate:i}=e.y_axis.axisLabel,c=Be(o.on_axis);return X.getYAxis({...l,type:"category",axisLabel:{rotate:i,...c,formatter:t},axisLine:{show:!0,lineStyle:{width:3}},axisTick:{show:!0,alignWithLabel:!0},splitArea:{show:!1,areaStyle:{color:"#E7E7E9"}},splitLine:{show:!1},nameTextStyle:{fontWeight:"bold",align:r},nameLocation:"end",nameGap:15,z:3})}function $C(e,t,r){if(!e.x_axis.data_key||!e.y_axis.data_key||!e.heat_block.data_key)return{};const a=r.reduce((m,k)=>{const z=Re(k,t);return m[k.name]=$e(k,z),m},{}),l=TC(e),o=kC(e),i=tn(e.visualMap,a),{min:c,max:d}=i,u=A(e.x_axis.data_key),p=A(e.y_axis.data_key),f=A(e.heat_block.data_key),v=y.uniq(t[u.queryID].map(m=>m[u.columnKey])),_=t[u.queryID].map(m=>{const k=y.get(m,u.columnKey),z=y.get(m,p.columnKey),D=y.get(m,f.columnKey),I={value:[k,z,D]},{followVisualMap:L,color:E}=Rn(D,c,d,e.visualMap);return L||(I.visualMap=!1,I.itemStyle={color:E}),I});return{xAxis:PC(e,v,l.x_axis),yAxis:VC(e,l.y_axis),series:DC(e,_),tooltip:AC(e,t,l,o),grid:zC(e),visualMap:i}}function EC({conf:e,data:t,width:r,height:a,interactionManager:l,variables:o,instance:i}){const c=h.useMemo(()=>{const w=A(e.x_axis.data_key),m=A(e.y_axis.data_key);return y.keyBy(t[w.queryID],k=>`${k[w.columnKey]}---${k[m.columnKey]}`)},[t,e.x_axis.data_key,e.y_axis.data_key]),d=Ie(l.triggerManager,mo.id),u=h.useCallback(w=>{const[m,k]=w.value,z=y.get(c,`${m}---${k}`,{error:"rowData is not found"});d.forEach(D=>{l.runInteraction(D.id,{...w,rowData:z})})},[c,d,l]),p=h.useRef(null),f=h.useCallback(()=>{var m;const w=(m=p.current)==null?void 0:m.getEchartsInstance();w&&de(i,w.getOption())},[i]),v=h.useMemo(()=>({click:u,finished:f}),[u,f]),_=h.useMemo(()=>$C(e,t,o),[e,t]);return n.jsx(he,{echarts:ce,option:_,ref:p,style:{width:r,height:a},onEvents:v,notMerge:!0,theme:"merico-light"})}function BC({context:e,instance:t}){const r=Me({vizManager:e.vizManager,instance:t}),{value:a}=B(e.instanceData,"config"),{variables:l}=e,o=h.useMemo(()=>y.defaults({},a,jr),[a]),i=e.data,{width:c,height:d}=e.viewport;return!c||!d?null:n.jsx(_e,{width:c,height:d,children:n.jsx(EC,{instance:t,variables:l,width:Ge(c),height:Fe(d),data:i,conf:o,interactionManager:r})})}const LC=[{lang:"en",resources:{merico_heatmap:{viz_name:"Merico Heatmap",click_heatmap:{heatblock:{label:"Click heat block"}}}}},{lang:"zh",resources:{merico_heatmap:{viz_name:"思码逸热力图",click_heatmap:{heatblock:{label:"点击热力块"}}}}}];function qC(e){const{visualMap:t=et(),heat_block:{min:r,max:a,...l},...o}=e;return{...o,heat_block:l,visualMap:{...et(),min:r,max:a}}}function OC(e){const t=e.tooltip.metrics;return{...e,tooltip:{...e.tooltip,metrics:t.map(r=>({...r,unit:r.unit??U()}))}}}function NC(e){const{heat_block:t}=e;return{...e,heat_block:{...t,unit:t.unit??U()}}}class GC extends ee{constructor(){super(...arguments);P(this,"VERSION",4)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,r=>({...r,version:2,config:qC(r.config)})),this.version(3,r=>({...r,version:3,config:OC(r.config)})),this.version(4,r=>({...r,version:4,config:NC(r.config)}))}}const FC={displayName:"viz.merico_heatmap.viz_name",displayGroup:"chart.groups.merico_suite",migrator:new GC,name:"merico-heatmap",viewRender:BC,configRender:mC,createConfig:()=>({version:4,config:jr}),triggers:[mo],translation:LC},Qr={item_badge:"_item_badge_l2t3l_1",label:"_label_l2t3l_8",value:"_value_l2t3l_20"},jC=({children:e})=>["string","number"].includes(typeof e)?n.jsx(s.Text,{size:"xs",ff:"monospace",children:e}):e,bt=h.forwardRef(({label:e,value:t,label_description:r,value_description:a},l)=>n.jsxs("div",{ref:l,className:Qr.item_badge,children:[n.jsx("div",{className:Qr.label,children:e}),n.jsxs(s.HoverCard,{shadow:"md",disabled:!a,children:[n.jsx(s.HoverCard.Target,{children:n.jsx("div",{className:Qr.value,"data-with-tooltip":!!a,children:t})}),n.jsx(s.HoverCard.Dropdown,{p:"xs",children:n.jsx(jC,{children:a})})]})]})),QC=({item:e})=>e.type!=="checkbox"?null:n.jsx(bt,{label:e.label,value:n.jsx(s.ThemeIcon,{variant:"white",radius:"xs",color:e.value?"teal":"red",w:12,h:12,miw:12,mih:12,children:e.value?n.jsx(S.IconCheck,{size:12,strokeWidth:3}):n.jsx(S.IconX,{strokeWidth:3})}),label_description:`filters.${e.key}`}),WC=({item:e})=>e.type!=="context"?null:n.jsx(bt,{label:e.key,value:e.value,label_description:`context.${e.key}`}),UC=T.observer(({item:e})=>{const{t}=x.useTranslation(),a=e.model.value,[l,o]=a.value,i=h.useMemo(()=>!o&&!l?Number.NaN:M(o).diff(M(l),"days")+1,[l,o]);if(Number.isNaN(i))return n.jsx("span",{style:{userSelect:"none",opacity:0,visibility:"hidden"},children:"."});const c=i===1?t("filter.widget.date_range.one_day"):t("filter.widget.date_range.x_days",{count:i});return n.jsx(bt,{label:e.label,value:e.value.join(" ~ "),label_description:`filters.${e.key}`,value_description:c})}),YC=({item:e})=>e.type!=="date-range"?null:n.jsx(UC,{item:e}),Co=({selection:e})=>(x.useTranslation(),e.length===0?null:n.jsx(s.Group,{justify:"flex-start",gap:"xs",maw:"80vw",children:e.map(t=>n.jsx(s.Pill,{size:"xs",ff:"monospace",children:t.label},t.value))})),KC=T.observer(({item:e})=>{x.useTranslation();const r=e.model.config,a=h.useMemo(()=>r.optionsByValues(e.value),[e.value,r.options]);return n.jsx(bt,{label:e.label,value:a.length,label_description:`filters.${e.key}`,value_description:n.jsx(Co,{selection:a})})}),XC=({item:e})=>e.type!=="multi-select"?null:n.jsx(KC,{item:e}),ZC=T.observer(({item:e})=>{x.useTranslation();const r=e.model.config,a=h.useMemo(()=>{var l;return((l=r.options.find(o=>o.value===e.value))==null?void 0:l.label)??e.value},[e.value,r.options]);return n.jsx(bt,{label:e.label,value:a,label_description:`filters.${e.key}`})}),JC=({item:e})=>e.type!=="select"?null:n.jsx(ZC,{item:e}),HC=({item:e})=>e.type!=="text-input"?null:n.jsx(bt,{label:e.label,value:n.jsx(s.Text,{maw:200,size:"xs",truncate:"end",ff:"monospace",children:e.value}),value_description:e.value}),RC=T.observer(({item:e})=>{x.useTranslation();const r=e.model.config,a=h.useMemo(()=>r.optionsByValues(e.value),[e.value,r.options]);return n.jsx(bt,{label:e.label,value:a.length,label_description:`filters.${e.key}`,value_description:n.jsx(Co,{selection:a})})}),eS=({item:e})=>e.type!=="tree-select"?null:n.jsx(RC,{item:e}),tS=T.observer(({item:e})=>{x.useTranslation();const r=e.model.config,a=h.useMemo(()=>{var l;return((l=r.options.find(o=>o.value===e.value))==null?void 0:l.label)??e.value},[e.value,r.options]);return n.jsx(bt,{label:e.label,value:a,label_description:`filters.${e.key}`,value_description:e.value})}),nS=({item:e})=>e.type!=="tree-single-select"?null:n.jsx(tS,{item:e}),Wr=({item:e})=>{switch(e.type){case"date-range":return n.jsx(YC,{item:e});case"select":return n.jsx(JC,{item:e});case"tree-single-select":return n.jsx(nS,{item:e});case"multi-select":return n.jsx(XC,{item:e});case"tree-select":return n.jsx(eS,{item:e});case"text-input":return n.jsx(HC,{item:e});case"checkbox":return n.jsx(QC,{item:e});case"context":return n.jsx(WC,{item:e});default:return null}},rS=T.observer(({conf:e})=>{const r=J().dashboardState,{all:a,keys:l}=e;return a?n.jsxs(n.Fragment,{children:[Object.entries(r.context).map(([o,i])=>n.jsx(Wr,{item:i},o)),Object.entries(r.filters).map(([o,i])=>n.jsx(Wr,{item:i},o))]}):n.jsx(n.Fragment,{children:l.map(o=>{const i=y.get(r,o);return i?n.jsx(Wr,{item:i},o):null})})}),aS=T.observer(({context:e})=>{const{value:t}=B(e.instanceData,"config"),{width:r,height:a}=e.viewport;return t?n.jsx(s.Group,{justify:"flex-start",align:"flex-start",wrap:"wrap",px:0,py:0,gap:"xs",w:r,mah:a,style:{overflow:"auto"},"data-enable-scrollbar":!0,children:n.jsx(rS,{conf:t})}):null}),So={all:!0,keys:[]},sS={select:"filter.widget.names.select","multi-select":"filter.widget.names.multi_select","tree-select":"filter.widget.names.tree_select","tree-single-select":"filter.widget.names.tree_single_select","text-input":"filter.widget.names.text_input",checkbox:"filter.widget.names.checkbox","date-range":"filter.widget.names.date_range"},lS=({option:e,checked:t,...r})=>{const{t:a}=x.useTranslation(),l=e,o=l.type==="filter";return n.jsxs(s.Group,{gap:4,flex:1,children:[n.jsx(S.IconCheck,{size:14,opacity:t?1:0,color:"black"}),n.jsx(s.Stack,{gap:0,py:4,px:8,flex:1,styles:{root:{flexGrow:1,borderRadius:"4px"}},...r,children:n.jsxs(s.Group,{justify:"space-between",wrap:"nowrap",children:[n.jsx(s.Text,{size:"xs",children:e.label}),o&&n.jsx(s.Text,{size:"xs",c:t?"rgba(0,0,0,.8)":"dimmed",style:{flexShrink:0,flexGrow:0},children:a(sS[l.widget])})]})})]})},oS=T.observer(({value:e,onChange:t,disabled:r})=>{const{t:a}=x.useTranslation(),o=F().dashboardStateVariableOptions,i=h.useMemo(()=>{const{optionGroups:c,validValues:d}=o,u=c.map(f=>({group:a(f.group),items:f.items.map(v=>({...v,label:v.label,value:v.value,widget_label:v.label}))})),p=e.filter(f=>!d.has(f)).map(f=>({label:f,value:f,disabled:!0}));return p.length>0&&u.push({group:a("common.invalid"),items:p}),u},[o,a,e]);return n.jsx(s.MultiSelect,{size:"xs",label:a("viz.vizDashboardState.variable_selector.label"),placeholder:e.length===0?a("viz.vizDashboardState.variable_selector.placeholder"):void 0,data:i,renderOption:lS,maxDropdownHeight:600,value:e,onChange:t,disabled:r,clearable:!0})}),iS=({form:e})=>{const{t}=x.useTranslation(),r=e.watch("all");return n.jsxs(s.Stack,{gap:"xs",p:"xs",children:[n.jsx(b.Controller,{name:"all",control:e.control,render:({field:a})=>n.jsx(s.Checkbox,{size:"xs",label:t("viz.vizDashboardState.show_all"),checked:a.value,onChange:l=>a.onChange(l.currentTarget.checked)})}),n.jsx(b.Controller,{name:"keys",control:e.control,render:({field:a})=>n.jsx(oS,{disabled:r,...a})})]})};function cS({context:e}){const{value:t,set:r}=B(e.instanceData,"config"),a=h.useMemo(()=>y.defaultsDeep({},t,So),[t]),l=b.useForm({defaultValues:a}),{handleSubmit:o,formState:i,reset:c}=l;return h.useEffect(()=>{c(a)},[a]),n.jsxs("form",{onSubmit:o(r),children:[n.jsx(ae,{canSubmit:i.isDirty}),n.jsx(iS,{form:l})]})}const dS=[{lang:"en",resources:{vizDashboardState:{viz_name:"Dashboard State",show_all:"Show all filters and context entries",variable_selector:{label:"Select filters and context entries to show",placeholder:""}}}},{lang:"zh",resources:{vizDashboardState:{viz_name:"看板状态",show_all:"显示所有筛选器和上下文条目",variable_selector:{label:"选择要展示的筛选器和上下文",placeholder:""}}}}];class uS extends ee{constructor(){super(...arguments);P(this,"VERSION",1)}configVersions(){this.version(1,r=>({version:1,config:r}))}}const pS={displayName:"viz.vizDashboardState.viz_name",displayGroup:"chart.groups.others",migrator:new uS,name:"vizDashboardState",viewRender:aS,configRender:cS,createConfig:()=>({version:1,config:So}),translation:dS},hS=[{value:"#25262B",name:"Dark"},{value:"#868E96",name:"Gray"},{value:"#FA5252",name:"Red"},{value:"#E64980",name:"Pink"},{value:"#BE4BDB",name:"Grape"},{value:"#7950F2",name:"Violet"},{value:"#4C6EF5",name:"Indigo"},{value:"#228BE6",name:"Blue"},{value:"#15AABF",name:"Cyan"},{value:"#12B886",name:"Teal"},{value:"#40C057",name:"Green"},{value:"#82C91E",name:"Lime"},{value:"#FAB005",name:"Yellow"},{value:"#FD7E14",name:"Orange"}].map(e=>({name:e.name,value:e.value,type:"single",category:"basic"})),gS=[eu,tu,au,ru,nu,su],Ur=[$r,Mw,Jm,ux,Hw,l_,C1,$p,Fg,Jb,Gy,L0,kv,Pb,uw,P_,lx,l0,rC,FC,fC,ef,pS],To=Ur.reduce((e,t)=>(e[t.name]={displayName:t.displayName,displayGroup:t.displayGroup},e),{}),ko=()=>({id:"dashboard",version:Cs,manifest:{viz:Ur,color:[...hS,...gS]}}),Ct=new uu,R={pluginManager:Je("pluginManager"),vizManager:Je("vizManager"),colorManager:Je("colorManager"),panelAddonManager:Je("panelAddonManager"),instanceScope:{panelModel:Je("panelModel"),vizInstance:Je("vizInstance"),interactionManager:Je("interactionManager"),migrator:Je("migrator"),operationManager:Je("operationManager"),triggerManager:Je("triggerManager")}},Yr=()=>{try{Ct.install(ko())}catch{}const e=new Jd(Ct),t=new du(Ct),r=new ou(Ct);return{pluginManager:Ct,vizManager:e,colorManager:t,panelAddonManager:r}},rt=h.createContext(Yr());try{Ct.install(ko())}catch{}const wn=Se.createInstance({debug:!1,fallbackLng:"en",interpolation:{escapeValue:!1},resources:{en:Kd,zh:Xd}}).use(ed).use(x.initReactI18next);wn.init(),Ur.forEach(e=>{var t;(t=e.translation)==null||t.forEach(r=>{wn.addResourceBundle(r.lang,"translation",{viz:r.resources},!0,!0)})});function zo({lang:e,children:t}){return h.useEffect(()=>{wn.changeLanguage(e)},[e]),n.jsx(x.I18nextProvider,{i18n:wn,children:t})}M.extend(id),M.extend(cd),M.extend(dd),M.extend(ud),M.extend(pd),M.extend(hd),M.extend(gd),M.extend(fd),M.extend(bd),M.extend(yd),M.extend(xd),M.extend(wd),M.extend(md),M.extend(Cd),M.extend(Sd),M.extend(vd),M.extend(_d),M.extend(Td),M.extend(kd),M.extend(zd),M.extend(Dd),M.extend(Id),M.extend(Md),M.extend(Ad),M.extend(Pd),M.extend(Vd),M.extend($d),M.extend(Ed),M.extend(Bd),M.extend(Ld),M.extend(Od),M.extend(Nd),M.extend(qd),M.tz.setDefault("UTC"),M.updateLocale("en",{weekStart:1});function fS(e){e=e||{};const t=Object.keys(e).sort(),r=[];for(let a=0;a<t.length;a++){const l=t[a];if(l!="authentication"&&e[l])r.push(t[a]+"="+(typeof e[l]=="object"?JSON.stringify(e[l]):e[l]));else{const o=Object.keys(e[l]).sort();for(let i=0;i<o.length;i++){const c=o[i];c!="sign"&&e[l][c]&&r.push(o[i]+"="+(typeof e[l][c]=="object"?JSON.stringify(e[l][c]):e[l][c]))}}}return r.sort().join("&")}function bS(e,t){let r=fS(e);return r+="&key="+t,Ud.MD5(r).toString().toUpperCase()}class Do{constructor(){this.type="default_api_client",this.baseURL="http://localhost:31200",this.app_id="",this.app_secret=""}getAuthentication(t){if(!this.app_id||!this.app_secret)return;const r=new Date().getTime().toString();return{app_id:this.app_id,nonce_str:r,sign:bS({app_id:this.app_id,nonce_str:r,...t},this.app_secret)}}getRequest(t,r){return(a,l,o,i)=>{const c=this.buildHeader(o),d=this.buildAxiosConfig(t,a,l,o,c,r);return ke(d).then(u=>i?u:u.data).catch(u=>{if(ke.isCancel(u))return Promise.reject(u);const p=u,f=y.get(p,"response.data.detail.message",p.message);return Promise.reject(new Error(f))})}}get(t){return this.getRequest("GET",t)}post(t){return this.getRequest("POST",t)}put(t){return this.getRequest("PUT",t)}buildAxiosConfig(t,r,a,l,o,i){const c={baseURL:this.baseURL,method:t,url:r,params:t==="GET"?a:l.params,headers:o,signal:i};return["POST","PUT"].includes(t)&&(c.data=l.string?JSON.stringify(a):a,c.data.authentication=this.getAuthentication(c.data)),c}buildHeader(t){const r=window.localStorage.getItem("token");return{"X-Requested-With":"XMLHttpRequest","Content-Type":t.string?"application/x-www-form-urlencoded":"application/json",authorization:r?`bearer ${r}`:"",...t.headers}}}class yS{constructor(t){this.implementation=t}getRequest(t,r){return this.implementation.getRequest(t,r)}get(t){return this.getRequest("GET",t)}post(t){return this.getRequest("POST",t)}put(t){return this.getRequest("PUT",t)}}class Io extends Do{constructor(){super(...arguments);P(this,"makeQueryENV",null)}query(r){return async(a,l={})=>{var o;return a.env||(a.env=((o=this.makeQueryENV)==null?void 0:o.call(this))??{error:"failed to run makeQueryENV"}),this.post(r)("/query",a,l)}}httpDataSourceQuery(r){return async(a,l={})=>{var o;return a.env||(a.env=((o=this.makeQueryENV)==null?void 0:o.call(this))??{error:"failed to run makeQueryENV"}),this.getRequest("POST",r)("/query",a,l,!0)}}structure(r){return async(a,l={})=>this.post(r)("/query/structure",a,l)}mericoMetricInfo(r){return async(a,l={})=>this.post(r)("/query/merico_metric_info",a,l,!0)}mericoMetricQuery(r){return async(a,l={})=>this.post(r)("/query",a,l,!0)}}class Mo{constructor(t){this.implementation=t}query(t){return this.implementation.query(t)}httpDataSourceQuery(t){return this.implementation.httpDataSourceQuery(t)}structure(t){return this.implementation.structure(t)}mericoMetricInfo(t){return this.implementation.mericoMetricInfo(t)}mericoMetricQuery(t){return this.implementation.mericoMetricQuery(t)}getRequest(t,r){return this.implementation.getRequest(t,r)}get(t){return this.getRequest("GET",t)}post(t){return this.getRequest("POST",t)}put(t){return this.getRequest("PUT",t)}}const Et=new Io;function Kr(e){Et.baseURL!==e.apiBaseURL&&(Et.baseURL=e.apiBaseURL),e.app_id&&(Et.app_id=e.app_id),e.app_secret&&(Et.app_secret=e.app_secret),e.makeQueryENV&&(Et.makeQueryENV=e.makeQueryENV)}const Ao=new Mo(Et),Ae=Ao,Xr=g.types.model("MockContextMeta",{current:g.types.optional(g.types.frozen(),{})}).views(e=>({get keys(){return Object.keys(e.current)},get keySet(){return new Set(this.keys)},get entries(){return Object.entries(e.current)}})).actions(e=>({replace(t){e.current=t},defaults(t){e.current={...t,...e.current}},get(t){return e.current[t]},set(t,r){e.current[t]=r}}));function Zr(e){return{current:e}}const vS=g.types.model("PanelStyleBorderMeta",{enabled:g.types.boolean}).views(e=>({get json(){const{enabled:t}=e;return{enabled:t}}})).actions(e=>({setEnabled(t){e.enabled=t}})),Po=g.types.model("PanelStyleMeta",{border:vS}).views(e=>({get json(){const{border:t}=e;return{border:t.json}}})).actions(e=>({})),Vo=g.types.model("PanelTitleMeta",{show:g.types.optional(g.types.boolean,!0)}).views(e=>({get json(){const{show:t}=e;return{show:t}}})).actions(e=>({setShow(t){e.show=t}})),$o=g.types.model("VariableMeta",{name:g.types.string,size:g.types.string,weight:g.types.string,color:g.types.union(g.types.model({type:g.types.literal("static"),staticColor:g.types.string}),g.types.model({type:g.types.literal("continuous"),valueRange:g.types.array(g.types.number),colorRange:g.types.array(g.types.string)}),g.types.model({type:g.types.literal("piecewise")})),formatter:g.types.model({output:g.types.enumeration("Output",["number","percent"]),average:g.types.optional(g.types.boolean,!1),mantissa:g.types.number,trimMantissa:g.types.optional(g.types.boolean,!1),absolute:g.types.optional(g.types.boolean,!1)}),data_field:g.types.string,aggregation:g.types.union(g.types.model({type:g.types.enumeration(["none","sum","mean","median","min","max","CV","std"]),config:g.types.frozen(),fallback:g.types.optional(g.types.string,"0")}),g.types.model({type:g.types.literal("quantile"),config:g.types.model({p:g.types.number}),fallback:g.types.optional(g.types.string,"0")}),g.types.model({type:g.types.literal("pick_record"),config:g.types.model({method:g.types.enumeration("Pick Record Method",["first","last"])}),fallback:g.types.optional(g.types.string,"0")}),g.types.model({type:g.types.literal("custom"),config:g.types.model({func:g.types.string}),fallback:g.types.optional(g.types.string,"0")}))}).views(e=>({get json(){const{name:t,size:r,weight:a,color:l,formatter:o,data_field:i,aggregation:c}=e;return y.cloneDeep({name:t,size:r,color:l,weight:a,formatter:o,data_field:i,aggregation:c})}})),Eo=g.types.model("PanelVizMeta",{type:g.types.string,conf:g.types.frozen()}).views(e=>({get json(){return{conf:e.conf,type:e.type}}})).actions(e=>({setType(t){e.type=t},setConf(t){y.isEqual(e.conf,t)||(e.conf=t)}})),Bo=g.types.model({id:g.types.string,name:g.types.optional(g.types.string,""),title:Vo,description:g.types.string,queryIDs:g.types.array(g.types.string),viz:Eo,style:Po,variables:g.types.optional(g.types.array($o),[])}).views(e=>({get json(){const{id:t,name:r,title:a,description:l,queryIDs:o}=e;return{id:t,viz:e.viz.json,name:r,style:e.style.json,title:a.json,queryIDs:[...o],variables:e.variables.map(i=>i.json),description:l}},get queryIDSet(){return new Set(e.queryIDs)}})).actions(e=>({setID(t){e.id=t},setName(t){e.name=t},setDescription(t){e.description=t},addQueryID(t){e.queryIDSet.has(t)||e.queryIDs.push(t)},removeQueryID(t){if(!e.queryIDSet.has(t))return;const r=new Set(e.queryIDSet);r.delete(t),e.queryIDs=g.cast(Array.from(r))},setQueryIDs(t){e.queryIDs=g.cast(t)},addVariable(t){e.variables.push(t)},removeVariable(t){e.variables.remove(t)}}));var j=(e=>(e.Postgresql="postgresql",e.MySQL="mysql",e.HTTP="http",e.Transform="transform",e.MericoMetricSystem="merico_metric_system",e))(j||{});const Lo=g.types.model("DBQueryMeta",{_type:g.types.enumeration([j.MySQL,j.Postgresql]),sql:g.types.string}).views(e=>({get base(){return g.getParent(e)},get valid(){return!!e.sql},get json(){const{sql:t,_type:r}=e;return{sql:t,_type:r}}})).actions(e=>({setSQL(t){e.sql=t}})),_S=e=>Lo.create({_type:e,sql:""}),qo=g.types.model("HTTPQueryMeta",{_type:g.types.literal(j.HTTP),react_to:g.types.optional(g.types.array(g.types.string),[])}).views(e=>({get valid(){return!0},get json(){const{react_to:t,_type:r}=e;return tt({react_to:t,_type:r})}})).actions(e=>({setReactTo(t){e.react_to.length=0,e.react_to.push(...t)}})),xS=()=>qo.create({_type:j.HTTP,react_to:[]}),Oo=g.types.model("TransformQueryMeta",{_type:g.types.literal(j.Transform),dep_query_ids:g.types.optional(g.types.array(g.types.string),[]),react_to:g.types.optional(g.types.array(g.types.string),[])}).views(e=>({get valid(){return e.dep_query_ids.length>0},get json(){const{dep_query_ids:t,_type:r,react_to:a}=e;return tt({dep_query_ids:t,_type:r,react_to:a})}})).actions(e=>({setDependantQueryIDs(t){e.dep_query_ids.length=0,e.dep_query_ids.push(...t)},setReactTo(t){e.react_to.length=0,e.react_to.push(...t)}})),wS=()=>Oo.create({_type:j.Transform,dep_query_ids:[]}),No=g.types.model("MetricFilterColMeta",{dimension:g.types.optional(g.types.string,""),variable:g.types.optional(g.types.string,"")}).views(e=>({get allEmpty(){return!e.dimension&&!e.variable},get json(){const{dimension:t,variable:r}=e;return{dimension:t,variable:r}}})).actions(e=>({removeSelf(){g.getParent(e,2).removeFilter(e)},setDimension(t){e.dimension=t??"",e.allEmpty&&this.removeSelf()},setVariable(t){e.variable=t??"",e.allEmpty&&this.removeSelf()}})),Jr=g.types.model("MericoMetricQueryMeta",{_type:g.types.literal(j.MericoMetricSystem),id:g.types.optional(g.types.string,""),type:g.types.optional(g.types.enumeration("MetricType",["derived","combined"]),"derived"),filters:g.types.optional(g.types.array(No),[]),groupBys:g.types.optional(g.types.array(g.types.string),[]),timeQuery:g.types.model({enabled:g.types.optional(g.types.boolean,!1),range_variable:g.types.optional(g.types.string,""),unit_variable:g.types.optional(g.types.string,""),timezone:g.types.optional(g.types.string,"PRC"),stepKeyFormat:g.types.optional(g.types.string,"YYYY-MM-DD")}),useDefaultValues:g.types.optional(g.types.boolean,!1)}).views(e=>({get query(){return g.getParent(e)},get valid(){return!!e.id},get json(){const{id:t,type:r,filters:a,groupBys:l,timeQuery:o,_type:i}=e;return tt({id:t,type:r,filters:a.map(c=>c.json),groupBys:l,timeQuery:o,_type:i})},get usedFilterDimensionKeys(){const t=e.filters.map(r=>r.dimension).filter(r=>!!r);return new Set(t)},get usedFilterVariableSet(){const t=[...e.filters.map(r=>r.variable)].filter(r=>!!r);return new Set(t)},get usedTimeQueryVariableSet(){const t=[e.timeQuery.range_variable,e.timeQuery.unit_variable].filter(r=>!!r);return new Set(t)},get groupByValues(){const t=e.groupBys.map(r=>r.replace(/^(.+)\s->\s(.*)/,"$1"));return Array.from(new Set(t))}})).actions(e=>({reset(){e.filters.length=0,e.groupBys.length=0,e.timeQuery.enabled=!1,e.timeQuery.range_variable="",e.timeQuery.unit_variable="",e.useDefaultValues=!1,"data"in e.query&&(e.query.setData([]),e.query.setError(null))},setID(t){t!==e.id&&this.reset(),e.id=t},setType(t){t!=="derived"&&t!=="combined"||(e.type=t)},addFilter(t,r){t&&e.usedFilterDimensionKeys.has(t)||e.filters.push(No.create({dimension:t,variable:r}))},removeFilter(t){g.destroy(t)},setGroupBys(t){e.groupBys.length=0,e.groupBys.push(...t)},setRangeVariable(t){e.timeQuery.range_variable=t??""},setUnitVariable(t){e.timeQuery.unit_variable=t??""},setTimeQueryEnabled(t){e.timeQuery.enabled=t,t?e.groupBys.length>1&&(e.groupBys.length=0):(e.timeQuery.range_variable="",e.timeQuery.unit_variable="")},setUseDefaultValues(t){e.useDefaultValues=t}})),Go=()=>Jr.create({_type:j.MericoMetricSystem,id:"",type:"derived",filters:[],groupBys:[],timeQuery:{range_variable:"",unit_variable:"",timezone:"PRC",stepKeyFormat:"YYYY-MM-DD"},useDefaultValues:!1}),Fo=g.types.model("QueryMeta",{id:g.types.string,name:g.types.string,key:g.types.string,type:g.types.enumeration("DataSourceType",[j.Postgresql,j.MySQL,j.HTTP,j.Transform,j.MericoMetricSystem]),config:g.types.union(Lo,qo,Oo,Jr),pre_process:g.types.optional(g.types.string,""),post_process:g.types.optional(g.types.string,""),run_by:g.types.optional(g.types.array(g.types.string),[])}).views(e=>({get valid(){const{id:t,name:r,key:a,type:l,config:o}=e;return o.valid&&!!t&&!!r&&!!a&&!!l},get json(){const{id:t,name:r,key:a,type:l,config:o,pre_process:i,post_process:c,run_by:d}=e;return tt({id:t,name:r,key:a,type:l,config:o.json,pre_process:i,post_process:c,run_by:d})}})).actions(e=>({setName(t){e.name=t},setKey(t){e.key=t},setType(t){switch(e.type=t,t){case j.HTTP:e.config=xS();break;case j.MySQL:case j.Postgresql:e.config=_S(t);break;case j.Transform:e.config=wS();break;case j.MericoMetricSystem:e.config=Go();break;default:throw new Error(`Unexpected query type[${t}]`)}},setRunBy(t){e.run_by.length=0,e.run_by.push(...t)},setPreProcess(t){e.pre_process=t},setPostProcess(t){e.post_process=t}})),jo=g.types.model("LayoutItemMeta",{id:g.types.identifier,panelID:g.types.string,x:g.types.number,y:g.types.maybeNull(g.types.number),w:g.types.number,h:g.types.number,moved:g.types.optional(g.types.boolean,!1),static:g.types.optional(g.types.boolean,!1)}).views(e=>({get json(){const{id:t,panelID:r,x:a,y:l,w:o,h:i,moved:c}=e;return{h:i,w:o,x:a,y:l===null?0:l,id:t,moved:c,static:e.static,panelID:r}},get contentModel(){return g.getRoot(e).content},get panel(){const{panelID:t}=e;return this.contentModel.panels.findByID(t)},get layoutProperies(){const{id:t,x:r,y:a,w:l,h:o,moved:i}=e;return{id:t,i:t,x:r,y:a===null?1/0:a,w:l,h:o,moved:i,static:e.static}}})).actions(e=>({set(t){const{isDraggable:r,x:a,y:l,w:o,h:i,moved:c}=t;e.x=a,e.y=l,e.w=o,e.h=i,e.moved=!!c,e.static=!!t.static},setWidth(t){e.w=t},setHeight(t){e.h=t}})),Qo=g.types.model("LayoutSetMeta",{id:g.types.identifier,name:g.types.string,breakpoint:g.types.number,list:g.types.optional(g.types.array(jo),[])}).views(e=>({get contentModel(){return g.getRoot(e).content},get json(){const{id:t,name:r,breakpoint:a,list:l}=e;return{id:t,name:r,breakpoint:a,list:l.map(o=>tt(o.json))}},jsonByPanelIDSet(t){const{id:r,name:a,breakpoint:l,list:o}=e;return{id:r,name:a,breakpoint:l,list:o.filter(i=>t.has(i.panelID)).map(i=>tt(i.json))}},findByID(t){return e.list.find(r=>r.id===t)},findByPanelID(t){return e.list.find(r=>r.panelID===t)}})).actions(e=>({setName(t){e.name=t},setBreakpoint(t){e.breakpoint=t},addLayout(t){e.list.push(t)},addNewLayout(t){e.list.push({id:Ke.v4(),panelID:t,x:0,y:1/0,w:18,h:300,static:!1,moved:!1})},removeByPanelID(t){const r=e.list.findIndex(a=>a.panelID===t);r>=0&&e.list.splice(r,1)},removeByPanelIDs(t){for(;t.length>0;){const r=t.pop();r&&this.removeByPanelID(r)}},updateLayoutItem(t){const r=e.list.find(a=>a.id===t.i);if(!r){console.error("Trying to update a layout that doesn't exist"),console.log({strangeLayoutItem:t});return}r.set(t)}})).actions(e=>({afterCreate(){g.addDisposer(e,Q.reaction(()=>{const t=e.list.length,r=e.contentModel.panels.list.length;return{match:t===r,layoutCount:t,panelCount:r}},({match:t,panelCount:r,layoutCount:a})=>{if(t)return;const l={id:"layout panel count mismatch",title:"Error detected, please don't save changes.",message:`${a} layout items against and ${r} panels.`,color:"red",autoClose:!1};Ze.showNotification(l),Ze.updateNotification(l)},{fireImmediately:!0,delay:0}))}})),Wo=g.types.model("SQLSnippetMeta",{key:g.types.string,value:g.types.string}).views(e=>({get json(){const{key:t,value:r}=e;return{key:t,value:r}}})).actions(e=>({setKey(t){e.key=t},setValue(t){e.value=t}}));var V=(e=>(e.Select="select",e.MultiSelect="multi-select",e.TreeSelect="tree-select",e.TreeSingleSelect="tree-single-select",e.TextInput="text-input",e.Checkbox="checkbox",e.DateRange="date-range",e))(V||{});const Hr=g.types.optional(g.types.enumeration(["intersect","reset"]),"intersect"),Rr=g.types.model("FilterCheckboxConfigMeta",{_name:g.types.literal("checkbox"),description:g.types.optional(g.types.string,""),default_value:g.types.boolean}).views(e=>({get json(){const{_name:t,description:r,default_value:a}=e;return{_name:t,description:r,default_value:a}},get isDescriptionEmpty(){const{description:t}=e;return t===""||t==="<p></p>"}})).actions(e=>({setDefaultValue(t){e.default_value=t},setDescription(t){e.description=t}})),Uo=()=>Rr.create({_name:"checkbox",description:"",default_value:!1}),Yo=()=>[{key:"d",value:"yesterday",group:"last",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(1,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()],shortcut:"yesterday"}}},{key:"w",value:"last week",group:"last",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(1,"week").startOf("week").toDate(),M(e).subtract(1,"week").endOf("week").toDate()],shortcut:"last week"}}},{key:"m",value:"last month",group:"last",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(1,"month").startOf("month").toDate(),M(e).subtract(1,"month").endOf("month").toDate()],shortcut:"last month"}}},{key:"m2",value:"last 2 months",group:"last",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(2,"month").startOf("month").toDate(),M(e).subtract(1,"month").endOf("month").toDate()],shortcut:"last 2 months"}}},{key:"m3",value:"last 3 months",group:"last",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(3,"month").startOf("month").toDate(),M(e).subtract(1,"month").endOf("month").toDate()],shortcut:"last 3 months"}}},{key:"y",value:"last year",group:"last",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(1,"year").startOf("year").toDate(),M(e).subtract(1,"year").endOf("year").toDate()],shortcut:"last year"}}},{key:"d7",value:"recent 7 days",group:"recent",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(7,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()],shortcut:"recent 7 days"}}},{key:"d30",value:"recent 30 days",group:"recent",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(30,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()],shortcut:"recent 30 days"}}},{key:"d60",value:"recent 60 days",group:"recent",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(60,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()],shortcut:"recent 60 days"}}},{key:"d90",value:"recent 90 days",group:"recent",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(90,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()],shortcut:"recent 90 days"}}},{key:"d180",value:"recent 180 days",group:"recent",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(180,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()],shortcut:"recent 180 days"}}},{key:"d365",value:"recent 365 days",group:"recent",getRange:()=>{const e=Date.now();return{value:[M(e).subtract(365,"day").startOf("day").toDate(),M(e).subtract(1,"day").endOf("day").toDate()],shortcut:"recent 365 days"}}},{key:"d",value:"today",group:"this",getRange:()=>{const e=Date.now();return{value:[M(e).startOf("day").toDate(),M(e).endOf("day").toDate()],shortcut:"today"}}},{key:"w",value:"this week",group:"this",getRange:()=>{const e=Date.now();return{value:[M(e).startOf("week").toDate(),M(e).endOf("week").toDate()],shortcut:"this week"}}},{key:"m",value:"this month",group:"this",getRange:()=>{const e=Date.now();return{value:[M(e).startOf("month").toDate(),M(e).endOf("month").toDate()],shortcut:"this month"}}},{key:"y",value:"this year",group:"this",getRange:()=>{const e=Date.now();return{value:[M(e).startOf("year").toDate(),M(e).endOf("year").toDate()],shortcut:"this year"}}},{key:"w",value:"this week so far",group:"this_so_far",getRange:()=>{const e=Date.now();return{value:[M(e).startOf("week").toDate(),M(e).toDate()],shortcut:"this week so far"}}},{key:"m",value:"this month so far",group:"this_so_far",getRange:()=>{const e=Date.now();return{value:[M(e).startOf("month").toDate(),M(e).toDate()],shortcut:"this month so far"}}},{key:"y",value:"this year so far",group:"this_so_far",getRange:()=>{const e=Date.now();return{value:[M(e).startOf("year").toDate(),M(e).toDate()],shortcut:"this year so far"}}}];function ea(e){if(!e)return null;const r=Yo().find(a=>a.value===e);return r?r.getRange():null}function Ko(){return y.groupBy(Yo(),"group")}function Xo(e){try{if(e.default_shortcut){const r=ea(e.default_shortcut);if(r)return{value:r.value.map(a=>M(a).toDate()),shortcut:e.default_shortcut}}return{value:e.default_value.map(r=>r===null?r:M.tz(r,"UTC").toDate()??r),shortcut:null}}catch(t){return console.error(t),{value:[null,null],shortcut:null}}}function Zo(e,t){return e.map(r=>{try{return r?M.tz(r,"UTC").toISOString():null}catch{return console.log(`[date-range] failed parsing ${r}`),null}})}const mS=g.types.model("FilterDateRangeConfigMeta",{_name:g.types.literal("date-range"),required:g.types.boolean,inputFormat:g.types.enumeration("DateRangeInputFormat",["YYYY","YYYYMM","YYYYMMDD","YYYY-MM","YYYY-MM-DD"]),default_value:g.types.optional(g.types.array(g.types.union(g.types.Date,g.types.null)),[null,null]),default_shortcut:g.types.optional(g.types.string,""),clearable:g.types.boolean,max_days:g.types.optional(g.types.number,0),allowSingleDateInRange:g.types.optional(g.types.boolean,!1)}).views(e=>({get json(){const{_name:t,max_days:r,required:a,clearable:l,inputFormat:o,default_value:i,default_shortcut:c,allowSingleDateInRange:d}=e;return{_name:t,max_days:r,required:a,clearable:l,inputFormat:o,default_value:Zo(i),default_shortcut:c,allowSingleDateInRange:d}},truthy(t){try{const{value:r}=t;return Array.isArray(r)&&r.length===2&&r.every(a=>!!a)}catch(r){return console.error(r),!1}},get filter(){return g.getParent(e)},get dateStringsValue(){try{const t=this.filter.value,[r,a]=t.value,l=r?M(r).format(e.inputFormat):"",o=a?M(a).format(e.inputFormat):"";return[l,o]}catch(t){return console.error(t),["",""]}}})).actions(e=>({setFilterValue(t){try{e.filter.setValue(t)}catch(r){console.error(r)}}})).actions(e=>({setRequired(t){e.required=t},setClearable(t){e.clearable=t},setInputFormat(t){t&&(e.inputFormat=t)},setDefaultValue(t){e.default_value.length=0,e.default_value.push(...t.value),e.setFilterValue(t)},setDefaultShortcut(t){if(e.default_shortcut=t??"",!t)return;const r=ea(e.default_shortcut);r&&e.setFilterValue(r)},setMaxDays(t){const r=Number(t);Number.isFinite(r)&&(e.max_days=r,r>0&&(e.clearable=!0))},setAllowSingleDateInRange(t){e.allowSingleDateInRange=t}})),ta=g.types.snapshotProcessor(mS,{preProcessor({default_value:e,...t}){return{...t,default_value:e.map(r=>r===null?null:M.tz(r,"UTC").toDate())}},postProcessor(e){const{default_value:t,...r}=e;return{...r,default_value:Zo(t,r.inputFormat)}}}),Jo=()=>ta.create({_name:"date-range",required:!1,inputFormat:"YYYY-MM-DD",clearable:!1,default_value:[null,null]}),Ho=g.types.model({label:g.types.string,value:g.types.string}).actions(e=>({setLabel(t){e.label=t},setValue(t){e.value=t}})),na=g.types.model("FilterConfigModel_BaseSelect",{static_options:g.types.optional(g.types.array(Ho),[]),options_query_id:g.types.optional(g.types.string,""),default_selection_count:g.types.optional(g.types.number,0),required:g.types.optional(g.types.boolean,!1)}).views(e=>({get contentModel(){return g.getRoot(e).content},get filter(){return g.getParent(e)},get usingQuery(){return!!e.options_query_id}})).views(e=>({get optionsLoading(){if(!e.usingQuery)return!1;const{state:t}=e.contentModel.getDataStuffByID(e.options_query_id);return t==="loading"},get options(){if(!e.usingQuery)return e.static_options;const{data:t,state:r}=e.contentModel.getDataStuffByID(e.options_query_id);return r==="error"?[]:Array.isArray(t)?t.filter(a=>"label"in a&&"value"in a):[]},get optionValuesSet(){return new Set(this.options.map(t=>t.value))}})).actions(e=>({setRequired(t){e.required=t},addStaticOption(t){e.static_options.push(t)},removeStaticOption(t){e.static_options.splice(t,1)},replaceStaticOptions(t){e.static_options.forEach(a=>g.detach(a));const r=t.map(a=>Ho.create(a));e.static_options.replace(r)},setDefaultSelectionCount(t){const r=Number(t);Number.isFinite(r)&&(e.default_selection_count=r)},setOptionsQueryID(t){e.options_query_id=t??""}})),ra=g.types.compose("FilterMultiSelectConfigMeta",g.types.model({_name:g.types.literal("multi-select"),min_width:g.types.optional(g.types.string,""),default_value:g.types.optional(g.types.array(g.types.string),[]),default_value_mode:Hr}),na).views(e=>({get json(){const{_name:t,default_value:r,default_value_mode:a,required:l,min_width:o,static_options:i,options_query_id:c,default_selection_count:d}=e;return tt({_name:t,required:!!l,min_width:o,default_value:r,static_options:i,options_query_id:c,default_value_mode:a,default_selection_count:d})},get defaultSelection(){const t=e.filter.formattedDefaultValue;return Array.isArray(t)&&t.length>0||!e.usingQuery?t:e.options.slice(0,e.default_selection_count).map(r=>r.value)},optionsByValues(t){if(!Array.isArray(t)||t.length===0)return[];const r=new Set(t);return e.options.filter(a=>r.has(a.value))},initialSelection(t){return t||this.defaultSelection},truthy(t){return Array.isArray(t)&&t.length>0}})).actions(e=>({setDefaultValue(t){e.default_value=g.cast(t)},setDefaultValueMode(t){t!=="intersect"&&t!=="reset"||(e.default_value_mode=t)},setMinWidth(t){e.min_width=t},applyDefaultSelection(){if(e.optionsLoading)return;if(e.default_value_mode==="reset"){e.filter.setValue(e.defaultSelection);return}const t=new Set(e.options.map(l=>l.value)),a=(e.filter.value??[]).filter(l=>t.has(l));a.length>0?e.filter.setValue(a):e.filter.setValue(e.defaultSelection)}})).actions(e=>({afterCreate(){g.addDisposer(e,Q.reaction(()=>Q.toJS(e.defaultSelection),e.applyDefaultSelection,{fireImmediately:!1,delay:0}))}})),Ro=()=>ra.create({_name:"multi-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),aa=g.types.compose("FilterConfigModel_Select",g.types.model({_name:g.types.literal("select"),default_value:g.types.string,width:g.types.optional(g.types.string,""),clearable:g.types.optional(g.types.boolean,!1)}),na).views(e=>({get json(){const{_name:t,clearable:r,default_value:a,required:l,width:o,static_options:i,options_query_id:c,default_selection_count:d}=e;return tt({_name:t,width:o,required:l,clearable:r,default_value:a,static_options:i,options_query_id:c,default_selection_count:d})},truthy(t){return!!t},getSelectOption(t){return e.options.find(r=>r.value===t)},get default_selection(){return e.usingQuery?e.default_selection_count>0&&e.options.length>0?e.options[0].value:"":e.filter.formattedDefaultValue}})).actions(e=>({setDefaultValue(t){t!==null&&(e.default_value=t)},setWidth(t){e.width=t},setClearable(t){e.clearable=t},setDefaultSelection(){var a;const t=e.filter.value,r=(a=e.options.find(l=>l.value===t))==null?void 0:a.value;r?e.filter.setValue(r):e.filter.setValue(e.default_selection)}})).actions(e=>({afterCreate(){g.addDisposer(e,Q.reaction(()=>Q.toJS(e.default_selection),e.setDefaultSelection,{fireImmediately:!1,delay:0}))}})),ei=()=>aa.create({_name:"select",required:!1,default_value:"",static_options:[],options_query_id:"",default_selection_count:0}),sa=g.types.model("FilterTextInputConfigMeta",{_name:g.types.literal("text-input"),required:g.types.boolean,default_value:g.types.string}).views(e=>({get json(){const{_name:t,required:r,default_value:a}=e;return{_name:t,required:r,default_value:a}},truthy(t){return typeof t!="string"?!1:!!t.trim()}})).actions(e=>({setRequired(t){e.required=t},setDefaultValue(t){e.default_value=t}})),la=()=>sa.create({_name:"text-input",required:!1,default_value:""}),CS=`
|
|
531
531
|
// row
|
|
532
532
|
{
|
|
533
533
|
label: string;
|
|
@@ -538,7 +538,7 @@ Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel vari
|
|
|
538
538
|
}
|
|
539
539
|
`,ti=()=>{const{t:e}=x.useTranslation(),[t,r]=h.useState(!1);return n.jsxs(n.Fragment,{children:[n.jsx(s.Button,{variant:"subtle",size:"compact-sm",onClick:()=>r(a=>!a),children:e(t?"common.actions.close":"filter.widget.common.see_data_structure")}),n.jsx(s.Collapse,{in:t,children:n.jsx(Oe.CodeHighlight,{language:"typescript",withCopyButton:!1,code:CS})})]})},SS={[V.Checkbox]:"true",[V.DateRange]:"[new Date('2023-01-01 00:00:00'), new Date('2024-01-01 00:00:00')]",[V.MultiSelect]:"[]",[V.Select]:'""',[V.TreeSelect]:"[]",[V.TreeSingleSelect]:'""',[V.TextInput]:'""'},TS=e=>["function getDefaultValue(filter, utils, context) {",` return ${SS[e]};`,"}"].join(`
|
|
540
540
|
`),St=T.observer(({filter:e})=>{const{t}=x.useTranslation();return n.jsx(tr,{label:"",title:t("filter.field.custom_default_value.title"),triggerLabel:t("filter.field.custom_default_value.trigger"),value:e.default_value_func,onChange:e.setDefaultValueFunc,defaultValue:TS(e.type),triggerButtonProps:{size:"xs",color:"grape",sx:{flexGrow:0,alignSelf:"flex-start"},leftSection:n.jsx(S.IconMathFunction,{size:16})},description:n.jsx(s.Alert,{title:t("filter.field.custom_default_value.tips"),color:"gray",mb:16,children:n.jsxs(s.List,{size:"xs",type:"ordered",children:[n.jsx(s.List.Item,{children:t("filter.field.custom_default_value.tip_1")}),n.jsx(s.List.Item,{children:t("filter.field.custom_default_value.tip_2")})]})})})}),mn=T.observer(({value:e,onChange:t})=>{const{t:r}=x.useTranslation(),a=W(),l=F(),o=h.useMemo(()=>l.queries.options,[l.queries.current]),i=o.length===0,c=d=>{a.editor.setPath(["_QUERIES_",d])};return n.jsx(s.Select,{label:n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Text,{fw:500,size:"sm",children:r("filter.widget.common.use_query_data_as_options")}),e&&n.jsx(s.Button,{size:"xs",leftSection:n.jsx(S.IconArrowCurveRight,{size:16}),variant:"subtle",color:"blue",onClick:()=>c(e),children:r("query.open")})]}),data:o,value:e,onChange:Z(t),allowDeselect:!1,clearable:!0,sx:{flexGrow:1},disabled:i,error:i?"You need to add a query in Data Settings":void 0,styles:{label:{display:"block"}}})}),ni={stroke:1.5,color:"currentColor",opacity:1,size:18},ri={intersect:n.jsx(S.IconLayersIntersect,{...ni}),reset:n.jsx(S.IconLayersSubtract,{...ni})},kS=({option:e,checked:t})=>n.jsxs(s.Group,{flex:"1",gap:"xs",children:[ri[e.value],e.label]}),oa=T.observer(({config:e})=>{const{t,i18n:r}=x.useTranslation(),a=h.useMemo(()=>[{label:t("filter.widget.common.default_value_mode.intersect"),value:"intersect"},{label:t("filter.widget.common.default_value_mode.reset"),value:"reset"}],[r.language]),{default_value_mode:l}=e;return n.jsx(s.Select,{leftSection:ri[l]??null,label:t("filter.widget.common.default_value_mode.label"),data:a,value:l,onChange:e.setDefaultValueMode,renderOption:kS})}),zS=T.observer(function({filter:t}){const{t:r}=x.useTranslation(),a=t.config;return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Checkbox,{checked:a.required,onChange:l=>a.setRequired(l.currentTarget.checked),label:r("filter.widget.select.required")}),n.jsx(St,{filter:t})]}),n.jsx(s.TextInput,{label:r("filter.widget.common.min_width"),value:a.min_width,onChange:l=>a.setMinWidth(l.currentTarget.value),placeholder:"200px"}),n.jsx(s.Divider,{label:r("filter.widget.common.fetch_options_from_datasource"),labelPosition:"center"}),n.jsx(s.Checkbox,{checked:a.treeCheckStrictly,onChange:l=>a.setTreeCheckStrictly(l.currentTarget.checked),label:r("filter.widget.tree_select.strictly")}),n.jsx(mn,{value:a.options_query_id,onChange:a.setOptionsQueryID}),n.jsx(s.NumberInput,{value:a.default_selection_count,onChange:a.setDefaultSelectionCount,label:r("filter.widget.common.default_selection_count")}),n.jsx(oa,{config:a}),n.jsx(ti,{})]})}),ia=({errorMessage:e})=>{const{t}=x.useTranslation();return e?n.jsx(s.Text,{c:"red",size:"12px",children:e}):n.jsx(s.Text,{c:"dimmed",size:"12px",children:t("filter.widget.common.selector_option_empty")})},DS=({rotate:e,onClick:t})=>n.jsx("svg",{onClick:t,className:"caret-icon",viewBox:"0 0 1024 1024",focusable:"false","data-icon":"caret-down",width:"14px",height:"14px",fill:"currentColor","aria-hidden":"true",transform:`rotate(${e})`,children:n.jsx("path",{d:"M840.4 300H183.6c-19.7 0-30.7 20.8-18.5 35l328.4 380.8c9.4 10.9 27.5 10.9 37 0L858.9 335c12.2-14.2 1.2-35-18.5-35z"})}),ai=({expanded:e,isLeaf:t,value:r,onClick:a,...l})=>t?n.jsx("span",{style:{width:"14px",display:"inline-block"}}):n.jsx(DS,{rotate:e?"0":"-90",onClick:a,...l}),IS=({onClick:e})=>n.jsxs("svg",{onClick:e,className:"checkbox-icon",width:"16",height:"16",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{stroke:"none",d:"M0 0h24v24H0z",fill:"none"}),n.jsx("rect",{className:"border",x:"4",y:"4",width:"16",height:"16",rx:"2"}),n.jsx("rect",{className:"checkmark-indeterminate",x:"8",y:"8",width:"8",height:"8",rx:"2",stroke:"none"}),n.jsx("path",{className:"checkmark-checked",d:"M9 12l2 2l4 -4"})]}),si=({onClick:e,...t})=>n.jsx(IS,{onClick:e,...t}),MS=dt.createStyles((e,{radius:t=4,width:r,name:a})=>({root:{borderRadius:s.getRadius(t),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-tree-select.rc-tree-select-open":{borderColor:"#228be6 !important",".rc-tree-select-selection-overflow-item-rest":{display:"none"},".rc-tree-select-selection-overflow-item-suffix":{display:"block"}},".rc-tree-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-tree-select-selection-search-mirror":{display:"none"},".rc-tree-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-tree-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-tree-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-tree-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-tree-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-tree-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-tree-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-tree-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:e.fontSizes.sm,fontWeight:500,color:"#212529"},required:{color:"#fa5252",paddingLeft:"3px"},dropdown:{fontSize:e.fontSizes.xs,zIndex:300,position:"absolute",width:`${r} !important`,backgroundColor:"#fff",border:"1px solid #e9ecef",boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px","&.rc-tree-select-dropdown-slide-up-leave-active":{display:"none"},".rc-tree-select-tree-list .rc-tree-select-tree-list-holder":{},".rc-tree-select-tree-list, .rc-tree-select-empty":{padding:0},".rc-tree-select-empty":{padding:"8px 12px"},".rc-tree-select-tree-treenode":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"0px 12px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden","&:hover":{backgroundColor:"#f1f3f5"},"&.rc-tree-select-tree-treenode-checkbox-checked":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-checked":{stroke:"rgb(64, 192, 87)",animation:"check 200ms linear forwards"}},"&.rc-tree-select-tree-treenode-checkbox-indeterminate":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-indeterminate":{fill:"rgb(64, 192, 87)"}},"&.rc-tree-select-tree-treenode-disabled":{color:"#aaa",".rc-tree-select-tree-title, .rc-tree-select-tree-iconEle":{cursor:"not-allowed"},".rc-tree-select-tree-iconEle":{"svg .border":{fill:"#ced4da"}}},".rc-tree-select-tree-switcher":{height:"16px",alignSelf:"center",paddingRight:"2px",transition:"color 200ms ease","&:hover":{color:"#228be6","svg.caret-icon":{color:"#228be6"}},"svg.caret-icon":{color:"#ced4da",transition:"all 200ms ease"}},".rc-tree-select-tree-node-content-wrapper":{display:"flex",flexWrap:"nowrap",overflow:"hidden",alignItems:"center",gap:"8px",width:"100%",padding:"8px 0",transition:"color 200ms ease","&:hover":{color:"#228be6"}},".rc-tree-select-tree-iconEle":{height:"16px","svg .border":{stroke:"#ced4da"},".checkbox-icon .checkmark-indeterminate":{fill:"transparent",transition:"fill 200ms ease"},".checkbox-icon .checkmark-checked":{transform:"scale(1.2)",transformOrigin:"center center",strokeDasharray:10,strokeDashoffset:-10},"@keyframes check":{"0%":{strokeDashoffset:10},"100%":{strokeDashoffset:0}}},".rc-tree-select-tree-title":{textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden",".rc-tree-select-tree-title-desc":{fontSize:"12px",maxWidth:"100%",textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden"}},".rc-tree-select-tree-indent":{flexGrow:0,height:0,verticalAlign:"bottom"},".rc-tree-select-tree-indent-unit":{display:"inline-block",width:"1em"}}}})),AS=(e,t,r,a)=>{const l=h.useMemo(()=>{if(!a)return y.cloneDeep(e.filter(f=>!f.disabled));const u=[],p=f=>{f.disabled||u.push(f),f.children.forEach(p)};return e.forEach(p),u},[e,a]),o=h.useMemo(()=>new Set(l.map(u=>u.value)),[l]),i=h.useMemo(()=>new Set(t.map(u=>u.value)),[t]),c=h.useMemo(()=>i.size!==o.size?!1:Array.from(o).every(u=>i.has(u)),[i,o]);return{allValueSet:o,selectedValueSet:i,toggleSelectAll:()=>{if(c){r([]);return}const u=Array.from(l);r(u)},allSelected:c}},PS={root:{cursor:"pointer",backgroundColor:"#FFF","&:hover":{backgroundColor:"var(--mantine-color-default-hover)"},"input, .mantine-Checkbox-labelWrapper":{cursor:"pointer",pointerEvents:"none"}}},VS=({disabled:e,radius:t,style:r,label:a,value:l,onChange:o,treeData:i,errorMessage:c,required:d,treeCheckStrictly:u})=>{const{t:p}=x.useTranslation(),{classes:f,cx:v}=MS({radius:t,width:r.width,name:"FilterTreeSelectWidget"}),[_,w]=h.useState(!1),m=L=>{w(L)},k=_&&(l==null?void 0:l.length)>0,z=AS(i,l,o,u),[D,I]=h.useState("");return n.jsxs(s.Stack,{gap:3,children:[n.jsxs(s.Group,{justify:"space-between",children:[n.jsxs(s.Text,{className:f.label,size:"sm",children:[a,d&&n.jsx("span",{className:f.required,"aria-hidden":"true",children:"*"})]}),k&&n.jsx(s.Tooltip,{label:p("filter.widget.common.x_selected",{count:l.length}),children:n.jsx(s.Badge,{variant:"light",children:l.length})})]}),n.jsx(Ln,{disabled:e,allowClear:{clearIcon:n.jsx(s.CloseButton,{size:"sm"})},treeCheckStrictly:u,labelInValue:!0,className:v(f.root,"check-select"),dropdownClassName:v(f.dropdown,""),onDropdownVisibleChange:m,transitionName:"rc-tree-select-dropdown-slide-up",choiceTransitionName:"rc-tree-select-selection__choice-zoom",style:r,listHeight:510,treeLine:!0,switcherIcon:ai,treeIcon:si,maxTagTextLength:10,value:l,treeData:i,notFoundContent:n.jsx(ia,{errorMessage:c}),treeNodeFilterProp:"filterBasis",treeCheckable:!0,showCheckedStrategy:Ln.SHOW_PARENT,onChange:o,onSelect:console.log,maxTagCount:0,maxTagPlaceholder:()=>p("filter.widget.common.x_selected",{count:l.length}),searchValue:D,onSearch:I,dropdownRender:L=>n.jsxs(n.Fragment,{children:[z.allValueSet.size>0&&!D&&n.jsx(s.Group,{px:"xs",pt:8,pb:8,onClick:z.toggleSelectAll,styles:PS,children:n.jsx(s.Checkbox,{size:"xs",checked:z.allSelected,onChange:y.noop,label:p("common.actions.select_all")})}),n.jsx(s.Divider,{}),L]})})]})},$S=T.observer(({label:e,config:t,value:r,onChange:a})=>{const{treeData:l,treeDataLoading:o,errorMessage:i}=t,c=v=>{const _=v.map(w=>w.value);a(_,!1)},d=h.useMemo(()=>t.initialSelection(r),[r,t.initialSelection,o]),u=t.min_width?t.min_width:"200px",f=!!t.options_query_id?o:!1;return n.jsx(VS,{disabled:f,style:{minWidth:"160px",width:u,maxWidth:f?u:"unset",borderColor:"#e9ecef"},value:[...d],onChange:c,treeData:l,errorMessage:i,label:e,required:t.required,treeCheckStrictly:t.treeCheckStrictly})}),ES=T.observer(({filter:e})=>{const{t}=x.useTranslation(),r=e.config;return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Checkbox,{checked:r.required,onChange:a=>r.setRequired(a.currentTarget.checked),label:t("filter.widget.select.required")}),n.jsx(St,{filter:e})]}),n.jsx(s.TextInput,{label:t("filter.widget.common.min_width"),value:r.min_width,onChange:a=>r.setMinWidth(a.currentTarget.value),placeholder:"200px"}),n.jsx(s.Divider,{label:t("filter.widget.common.fetch_options_from_datasource"),labelPosition:"center"}),n.jsx(mn,{value:r.options_query_id,onChange:r.setOptionsQueryID}),n.jsx(s.Checkbox,{checked:r.default_selection_count===1,onChange:a=>r.setDefaultSelectionCount(a.currentTarget.checked?1:0),label:t("filter.widget.tree_single_select.select_first_option_by_default")}),n.jsx(oa,{config:r}),n.jsx(ti,{})]})}),BS=dt.createStyles((e,{radius:t=4,width:r,name:a})=>({root:{borderRadius:s.getRadius(t),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef","&.rc-tree-select.rc-tree-select-open":{borderColor:"#228be6 !important",".rc-tree-select-selection-overflow-item-rest":{display:"none"},".rc-tree-select-selection-overflow-item-suffix":{display:"block"}},"&.rc-tree-select-focused":{".rc-tree-select-selection-item":{color:"#aaa"}},".rc-tree-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"calc(2.25rem / 3)",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",position:"relative"},".rc-tree-select-selection-search":{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:1,".rc-tree-select-selection-search-input":{height:"36px",paddingLeft:"calc(2.25rem / 3)",textOverflow:"ellipsis"}},".rc-tree-select-selection-item":{position:"absolute",top:0,bottom:0,left:0,paddingLeft:"calc(2.25rem / 3)",color:"#000",lineHeight:"36px",fontSize:"0.875rem",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",transition:"color 200ms ease"},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-tree-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-tree-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-tree-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:e.fontSizes.sm,fontWeight:500,color:"#212529"},required:{color:"#fa5252",paddingLeft:"3px"},dropdown:{fontSize:e.fontSizes.xs,zIndex:300,paddingTop:"6px",position:"absolute",width:`${r} !important`,"&.rc-tree-select-dropdown-slide-up-leave-active":{display:"none"},".rc-tree-select-tree-list .rc-tree-select-tree-list-holder":{},".rc-tree-select-tree-list, .rc-tree-select-empty":{backgroundColor:"#fff",border:"1px solid #e9ecef",padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px"},".rc-tree-select-empty":{padding:"8px 12px"},".rc-tree-select-tree-treenode":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"0px 12px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden",transition:"background-color 200ms ease","&:hover":{backgroundColor:"#f1f3f5"},"&.rc-tree-select-tree-treenode-selected":{".rc-tree-select-tree-iconEle .checkbox-icon .checkmark-checked":{stroke:"rgb(64, 192, 87)",animation:"check 200ms linear forwards"}},"&.rc-tree-select-tree-treenode-disabled":{color:"#aaa",".rc-tree-select-tree-title, .rc-tree-select-tree-iconEle":{cursor:"not-allowed"},".rc-tree-select-tree-iconEle":{"svg .border":{fill:"#ced4da"}}},".rc-tree-select-tree-switcher":{height:"16px",alignSelf:"center",paddingRight:"2px",transition:"color 200ms ease","&:hover":{color:"#228be6","svg.caret-icon":{color:"#228be6"}},"svg.caret-icon":{color:"#ced4da",transition:"all 200ms ease"}},".rc-tree-select-tree-node-content-wrapper":{display:"flex",flexWrap:"nowrap",overflow:"hidden",alignItems:"center",gap:"8px",transition:"color 200ms ease",width:"100%",padding:"8px 0","&:hover":{color:"#228be6"}},".rc-tree-select-tree-iconEle":{height:"16px","svg .border":{stroke:"#ced4da"},".checkbox-icon .checkmark-indeterminate":{fill:"transparent",transition:"fill 200ms ease"},".checkbox-icon .checkmark-checked":{transform:"scale(1.2)",transformOrigin:"center center",strokeDasharray:10,strokeDashoffset:-10},"@keyframes check":{"0%":{strokeDashoffset:10},"100%":{strokeDashoffset:0}}},".rc-tree-select-tree-title":{textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden",".rc-tree-select-tree-title-desc":{fontSize:"12px",maxWidth:"100%",textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden"}},".rc-tree-select-tree-indent":{flexGrow:0,height:0,verticalAlign:"bottom"},".rc-tree-select-tree-indent-unit":{display:"inline-block",width:"1em"}}}})),LS=({disabled:e,radius:t,style:r,label:a,value:l,onChange:o,treeData:i,errorMessage:c,required:d})=>{x.useTranslation();const{classes:u,cx:p}=BS({radius:t,width:r.width,name:"FilterTreeSelectWidget"});return n.jsxs(s.Stack,{gap:3,children:[n.jsx(s.Group,{justify:"space-between",children:n.jsxs(s.Text,{className:u.label,size:"sm",children:[a,d&&n.jsx("span",{className:u.required,"aria-hidden":"true",children:"*"})]})}),n.jsx(Ln,{disabled:e,allowClear:{clearIcon:n.jsx(s.CloseButton,{size:"sm"})},multiple:!1,labelInValue:!0,className:p(u.root,"check-select"),dropdownClassName:p(u.dropdown,""),transitionName:"rc-tree-select-dropdown-slide-up",choiceTransitionName:"rc-tree-select-selection__choice-zoom",style:r,listHeight:510,treeLine:!0,switcherIcon:ai,treeIcon:si,value:l,treeData:i,notFoundContent:n.jsx(ia,{errorMessage:c}),treeNodeFilterProp:"filterBasis",treeCheckable:!1,onChange:o,onSelect:console.log,showSearch:!0})]})},qS=T.observer(({label:e,config:t,value:r,onChange:a})=>{const{treeData:l,treeDataLoading:o,errorMessage:i}=t,c=v=>{a(v?v.value:null,!1)},d=h.useMemo(()=>t.initialSelection(r),[r,t.initialSelection,t.treeDataLoading]),u=t.min_width?t.min_width:"200px",f=!!t.options_query_id?o:!1;return n.jsx(LS,{disabled:f,style:{width:u,maxWidth:f?u:"unset",borderColor:"#e9ecef"},value:d,onChange:c,treeData:l,errorMessage:i,label:e,required:t.required})});function OS(e){return Fd.arrayToTree(e,{id:"value",parentId:"parent_value",childrenField:"children",dataField:null})}function NS(e){return e.map(t=>{const{label:r,description:a,...l}=t,o={...l,filterBasis:`${r}___${a??""}`,description:a,label:r};return a&&(o.label=h.createElement("div",{},[h.createElement(s.Text,{key:0,title:t.label},t.label),h.createElement(s.Text,{key:1,className:"rc-tree-select-tree-title-desc",color:"dimmed",title:t.description},t.description)])),o})}const li=g.types.compose("FilterConfigModel_BaseTreeSelect",g.types.model({min_width:g.types.optional(g.types.string,""),default_value_mode:Hr}),na).views(e=>({get plainData(){const{data:t}=e.contentModel.getDataStuffByID(e.options_query_id);return t},get treeData(){const t=this.plainData,r=NS(t);return OS(r)},get errorMessage(){const{error:t}=e.contentModel.getDataStuffByID(e.options_query_id);return t},get treeDataLoading(){const{state:t}=e.contentModel.getDataStuffByID(e.options_query_id);return t==="loading"}})).actions(e=>({setMinWidth(t){e.min_width=t}})),ca=g.types.compose("FilterTreeSelectConfigMeta",g.types.model({_name:g.types.literal("tree-select"),default_value:g.types.optional(g.types.array(g.types.string),[]),treeCheckStrictly:g.types.optional(g.types.boolean,!1)}),li).views(e=>({get json(){const{_name:t,default_value:r,default_value_mode:a,required:l,min_width:o,static_options:i,options_query_id:c,default_selection_count:d,treeCheckStrictly:u}=e;return{_name:t,required:!!l,min_width:o,default_value:r,static_options:i,options_query_id:c,treeCheckStrictly:u,default_value_mode:a,default_selection_count:d}},get defaultSelection(){const t=e.filter.formattedDefaultValue;if(Array.isArray(t)&&t.length>0)return t;const{default_selection_count:r}=e;return r?e.treeData.slice(0,r).map(l=>l.value):[]},optionsByValues(t){if(!Array.isArray(t)||t.length===0)return[];const r=new Set(t);return e.options.filter(a=>r.has(a.value))},valueObjects(t){const r=new Set(t);return e.plainData.filter(a=>r.has(a.value))},initialSelection(t){return t?this.valueObjects(t):this.valueObjects(this.defaultSelection)},truthy(t){return Array.isArray(t)&&t.length>0}})).actions(e=>({setDefaultValue(t){e.default_value=g.cast(t)},setDefaultValueMode(t){t!=="intersect"&&t!=="reset"||(e.default_value_mode=t)},setTreeCheckStrictly(t){e.treeCheckStrictly=t},applyDefaultSelection(){if(e.optionsLoading)return;if(e.default_value_mode==="reset"){e.filter.setValue(e.defaultSelection);return}const t=e.filter.value,r=new Set(e.plainData.map(l=>l.value)),a=(t??[]).filter(l=>r.has(l));a.length>0?e.filter.setValue(a):e.filter.setValue(e.defaultSelection)},afterCreate(){g.addDisposer(e,Q.reaction(()=>JSON.stringify(e.defaultSelection),this.applyDefaultSelection,{fireImmediately:!1,delay:0}))}})),oi=()=>ca.create({_name:"tree-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),da=g.types.compose("FilterTreeSingleSelectConfigMeta",g.types.model({_name:g.types.literal("tree-single-select"),default_value:g.types.optional(g.types.string,"")}),li).views(e=>({get json(){const{_name:t,default_value:r,default_value_mode:a,required:l,min_width:o,static_options:i,options_query_id:c,default_selection_count:d}=e;return{_name:t,required:!!l,min_width:o,default_value:r,static_options:i,options_query_id:c,default_value_mode:a,default_selection_count:d}},get selectFirstByDefault(){return e.default_selection_count===1},get defaultSelection(){if(e.treeDataLoading)return"";const t=e.filter.formattedDefaultValue;return t||(this.selectFirstByDefault&&e.treeData.length>0?e.treeData[0].value:"")},valueObject(t){if(t)return e.plainData.find(r=>r.value===t)},initialSelection(t){if(t)return this.valueObject(t)},truthy(t){return typeof t=="string"&&t!==""}})).actions(e=>({setDefaultValue(t){e.default_value=t},setDefaultValueMode(t){t!=="intersect"&&t!=="reset"||(e.default_value_mode=t)},applyDefaultSelection(){if(e.treeDataLoading)return;if(e.default_value_mode==="reset"){e.filter.setValue(e.defaultSelection);return}const t=e.filter.value;e.optionValuesSet.has(t)?e.filter.setValue(t):e.filter.setValue(e.defaultSelection)},afterCreate(){g.addDisposer(e,Q.reaction(()=>Q.toJS(e.defaultSelection),this.applyDefaultSelection,{fireImmediately:!1,delay:0}))}})),ii=()=>da.create({_name:"tree-single-select",default_value:"",static_options:[],options_query_id:"",default_selection_count:0}),Cn=g.types.model("FilterMeta",{id:g.types.identifier,key:g.types.string,label:g.types.string,order:g.types.number,visibleInViewsIDs:g.types.array(g.types.string),auto_submit:g.types.optional(g.types.boolean,!1),default_value_func:g.types.optional(g.types.string,""),type:g.types.enumeration("DashboardFilterType",[V.Select,V.MultiSelect,V.TreeSelect,V.TreeSingleSelect,V.TextInput,V.Checkbox,V.DateRange]),config:g.types.union(aa,ra,ca,da,sa,Rr,ta)}).views(e=>({get contentModel(){return g.getRoot(e).content},get filters(){return this.contentModel.filters},get value(){return this.filters.values[e.key]},get plainDefaultValue(){const t=e.config.default_value;return Array.isArray(t)?[...t]:t},get usingDefaultValue(){return e.type!==V.TreeSelect&&e.type!==V.TreeSingleSelect},get usingDefaultValueFunc(){return!!e.default_value_func},get formattedDefaultValue(){return this.filters.formattedDefaultValues[e.key]},get auto_submit_supported(){return[V.Select,V.Checkbox,V.DateRange].includes(e.type)}})).views(e=>({get json(){const{id:t,key:r,label:a,order:l,visibleInViewsIDs:o,default_value_func:i,auto_submit:c,type:d,config:u}=e;return{id:t,key:r,type:d,label:a,order:l,config:u.json,auto_submit:c,visibleInViewsIDs:Q.toJS(o),default_value_func:i}},get visibleInViewsIDSet(){return new Set(e.visibleInViewsIDs)},get should_auto_submit(){return e.auto_submit_supported&&e.auto_submit},requiredAndPass(t){return y.get(e.config,"required",!1)?y.get(e.config,"truthy",()=>!0)(t):!1}})).actions(e=>({setKey(t){e.key=t},setValue(t){e.filters.setValueByKey(e.key,t)},setLabel(t){e.label=t},setOrder(t){const r=Number(t);Number.isFinite(r)&&(e.order=r)},setType(t){switch(t){case V.Select:e.config=ei();break;case V.MultiSelect:e.config=Ro();break;case V.TreeSelect:e.config=oi();break;case V.TreeSingleSelect:e.config=ii();break;case V.TextInput:e.config=la();break;case V.Checkbox:e.config=Uo();break;case V.DateRange:e.config=Jo();break;default:return}e.type=t},setVisibleInViewsIDs(t){e.visibleInViewsIDs.length=0,e.visibleInViewsIDs.push(...t)},setAutoSubmit(t){e.auto_submit=e.auto_submit_supported&&t},setDefaultValueFunc(t){e.default_value_func=t}}));var $=(e=>(e.Division="div",e.Modal="modal",e.Tabs="tabs",e))($||{});const ua=g.types.model("ViewDivisionConfig",{_name:g.types.literal($.Division)}).views(e=>({get json(){const{_name:t}=e;return{_name:t}}})),ci=()=>ua.create({_name:$.Division}),GS=g.types.model("CustomModalTitleModel",{enabled:g.types.optional(g.types.boolean,!1),func_content:g.types.optional(g.types.string,"")}).views(e=>({get json(){const{enabled:t,func_content:r}=e;return{enabled:t,func_content:r}},get value(){const{enabled:t,func_content:r}=e,a=g.getParent(e,2),l=g.getRoot(e);if(!t)return a.name;try{const o={filters:l.content.filters.valuesForPayload,context:l.context.current};return new Function(`return ${r}`)()(o)}catch(o){return console.error(o),a.name}}})).actions(e=>({setEnabled(t){e.enabled=t},setFuncContent(t){e.func_content=t},replace({enabled:t,func_content:r}){e.enabled=t,e.func_content=r}})),Sn={enabled:!1,func_content:["function text({ filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
|
|
541
|
-
`)},pa=g.types.model("ViewModalConfig",{_name:g.types.literal($.Modal),width:g.types.string,height:g.types.string,custom_modal_title:g.types.optional(GS,Sn)}).views(e=>({get json(){const{_name:t,width:r,height:a,custom_modal_title:l}=e;return{_name:t,width:r,height:a,custom_modal_title:l.json}}})).actions(e=>({setWidth(t){e.width=t},setHeight(t){e.height=t}})),di=()=>pa.create({_name:$.Modal,width:"90vw",height:"90vh"}),FS=g.types.model("ViewTabsTabModel",{id:g.types.identifier,name:g.types.string,view_id:g.types.string,color:g.types.optional(g.types.string,""),order:g.types.optional(g.types.number,0)}).views(e=>({get json(){const{id:t,name:r,view_id:a,color:l,order:o}=e;return{id:t,name:r,color:l,order:o,view_id:a}}})).actions(e=>({setName(t){e.name=t},setViewID(t){t&&(e.view_id=t)},setColor(t){e.color=t},setOrder(t){typeof t!="string"&&(e.order=t)}})),ha=g.types.model("ViewTabsConfig",{_name:g.types.literal($.Modal),tabs:g.types.optional(g.types.array(FS),[]),variant:g.types.optional(g.types.enumeration("variant",["default","outline","pills"]),"default"),orientation:g.types.optional(g.types.enumeration("orientation",["horizontal","vertical"]),"horizontal"),grow:g.types.optional(g.types.boolean,!1)}).views(e=>({get json(){const{_name:t,variant:r,orientation:a,tabs:l,grow:o}=e;return{grow:o,tabs:l.map(i=>i.json),_name:t,variant:r,orientation:a}},get tabsInOrder(){return y.sortBy(e.tabs,"order")}})).actions(e=>({setVariant(t){t&&(e.variant=t)},setOrientation(t){t&&(e.orientation=t)},setGrow(t){e.grow=t},setTabs(t){e.tabs.length=0,e.tabs=g.cast(t)},addTab(){const t=te.randomId(),r={id:t,name:t,view_id:""};e.tabs.push(r)},removeTab(t){e.tabs.splice(t,1)}})),ui=()=>ha.create({_name:$.Modal,tabs:[]}),pi=g.types.model({id:g.types.identifier,name:g.types.string,type:g.types.enumeration("EViewComponentType",[$.Division,$.Modal,$.Tabs]),config:g.types.union(ua,pa,ha),panelIDs:g.types.optional(g.types.array(g.types.string),[])}).views(e=>({get json(){const{id:t,name:r,type:a,config:l}=e;return{id:t,name:r,type:a,config:l.json,panelIDs:e.panelIDs.map(o=>o)}}})).actions(e=>({setName(t){e.name=t},setType(t){if(e.type!==t){switch(t){case $.Division:e.config=ci();break;case $.Modal:e.config=di();break;case $.Tabs:e.config=ui();break;default:return}e.type=t}},appendPanelID(t){e.panelIDs.push(t)},appendPanelIDs(t){e.panelIDs.push(...t)},removePanelID(t){const r=e.panelIDs.filter(a=>a!==t);e.panelIDs.length=0,e.panelIDs.push(...r)}})),at="14.32.0",jS={definition:{sqlSnippets:[],queries:[],mock_context:{}},views:[{id:"Main",name:"Main",type:$.Division,config:{},panelIDs:[]}],panels:[],filters:[],version:at,layouts:[{id:"basis",name:"basis",list:[],breakpoint:0}]},ga=g.types.model("DataSourceMetaModel",{id:g.types.string,type:g.types.enumeration("DataSourceType",[j.HTTP,j.MySQL,j.Postgresql,j.MericoMetricSystem]),key:g.types.string,config:g.types.frozen()}),hi=g.types.model("DataSourcesMetaModel",{list:g.types.optional(g.types.array(ga),[])}).views(e=>({find({type:t,key:r}){return e.list.find(a=>a.key===r&&a.type===t)},get options(){return e.list.map(t=>({value:t.key,label:t.key}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}})),gi=g.types.model({id:g.types.string,content:g.types.string,create_time:g.types.string,update_time:g.types.string,is_preset:g.types.boolean}),fa=g.types.model("GlobalSQLSnippetsMeta",{list:g.types.optional(g.types.array(gi),[])}).views(e=>({find(t){return e.list.find(r=>r.id===t)},get options(){return e.list.map(t=>({value:t.id,label:t.id}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}})),Tn=g.types.model("ContextMeta",{current:g.types.optional(g.types.frozen(),{})}).views(e=>({get keys(){return Object.keys(e.current)},get entries(){return Object.entries(e.current)}})).actions(e=>({replace(t){e.current=t},get(t){return e.current[t]},set(t,r){e.current[t]=r}}));function ba(e){return Tn.create({current:e})}const ya=g.types.compose("ViewRenderModel",pi,g.types.model({tab:g.types.optional(g.types.string,"")})).views(e=>({get tabs(){return e.config.tabs},get tabInfo(){const t=this.tabs.find(r=>r.id===e.tab);return t?{id:t.id,name:t.name}:null},get tabView(){return e.type!==$.Tabs?null:this.tabs.find(t=>t.id===e.tab)},get tabViewID(){return this.tabView?this.tabView.view_id??"":""},get contentModel(){return g.getParent(e,3)},get panels(){if(e.type!==$.Tabs)return this.contentModel.panels.panelsByIDs(e.panelIDs);const t=this.tabViewID,r=this.contentModel.views.findByID(t);return(r==null?void 0:r.panels)??[]},get renderViewIDs(){const t=[e.id];return e.type===$.Tabs&&t.push(this.tabViewID),t},async downloadScreenshot(t){const r=t.offsetWidth*2+10,a=t.offsetHeight*2+10,l=new fs,o=new Date().getTime(),i=await gs.toBlob(t,{bgcolor:"white",width:r,height:a,style:{transformOrigin:"0 0",transform:"scale(2)"}});l.file(`${e.name}_${o}.png`,i),l.file(`dashboard_state_${o}.json`,JSON.stringify(this.contentModel.dashboardStateValues,null,4)),l.generateAsync({type:"blob"}).then(c=>{Xt.saveAs(c,`${e.name}_${o}.zip`)}).catch(c=>{console.error(c),Ze.notifications.show({color:"red",title:"Failed to download screenshot with dashboard state",message:c.message})})}})).actions(e=>({setTab(t){e.tab=t??""},setTabByTabInfo(t){e.tab=t.id??""}})),va=g.types.model("ViewsRenderModel",{current:g.types.optional(g.types.array(ya),[]),visibleViewIDs:g.types.array(g.types.string)}).views(e=>({get json(){return e.current.map(t=>tt(t.json))},get idMap(){const t=new Map;return e.current.forEach(r=>{t.set(r.id,r)}),t},findByID(t){return e.current.find(r=>r.id===t)},get firstVisibleView(){const[t]=e.visibleViewIDs;return e.current.find(({id:r})=>r===t)},get visibleViews(){const t=new Set(e.visibleViewIDs);return e.current.filter(({id:r})=>t.has(r))},get firstVisibleTabsView(){return this.visibleViews.find(t=>t.type===$.Tabs)},get firstVisibleTabsViewActiveTab(){const t=this.firstVisibleTabsView;return t?t.tabInfo:null},get firstVisibleTabsViewActiveTabStr(){return JSON.stringify(this.firstVisibleTabsViewActiveTab)}})).actions(e=>({appendToVisibles(t){new Set(e.visibleViewIDs.map(a=>a)).has(t)||e.visibleViewIDs.push(t)},rmVisibleViewID(t){const r=e.visibleViewIDs.findIndex(a=>a===t);r!==-1&&e.visibleViewIDs.splice(r,1)},setFirstVisibleTabsViewActiveTab(t){if(!t)return;const r=e.firstVisibleTabsView;r==null||r.setTabByTabInfo(t)}}));function fi(e,t){const r=e.length>0?[e[0].id]:[],a=e.map(l=>{const{_name:o=l.type}=l.config,i={...l,tab:"",config:{...l.config,_name:o},panelIDs:l.panelIDs};if(l.type===$.Tabs){let c=y.minBy(l.config.tabs,d=>d.order);!c&&l.config.tabs.length>0&&(c=l.config.tabs[0]),i.tab=(c==null?void 0:c.id)??""}return i});return t&&(a[0].tab=t.id),{current:a,visibleViewIDs:r}}const QS=new Gd.AsyncParser({withBOM:!0});async function bi(e){return!Array.isArray(e)||e.length===0?"":await QS.parse(e).promise()}async function yi(e,t){const r=await bi(t),a=new Blob([r],{type:"text/csv"});Xt.saveAs(a,`${e}.csv`)}function vi(e,t){const r=new fs,a=t.map(async({id:l,data:o})=>{const i=await bi(o);r.file(`${l}.csv`,i)});Promise.all(a).then(()=>{r.generateAsync({type:"blob"}).then(l=>{Xt.saveAs(l,`${e}.zip`)})}).catch(l=>{console.error(l),Ze.notifications.show({color:"red",title:"Failed to download data",message:l.message})})}function Bt(e,t){const r=new Blob([t],{type:"application/json"});Xt.saveAs(r,`${e}.json`)}const _a=Bo.views(e=>({get contentModel(){return g.getRoot(e).content}})).views(e=>({get queries(){return e.contentModel.queries.findByIDSet(e.queryIDSet)},get firstQuery(){return this.queries.length>0?this.queries[0]:null},get firstQueryData(){return this.firstQuery?this.firstQuery.data:[]},queryByID(t){return this.queries.find(r=>r.id===t)},get data(){return this.queries.reduce((t,r)=>(t[r.id]=r.data,t),{})},get variableStrings(){return sl(e.variables,this.data)},get variableAggValueMap(){const t={},r=this.data;return e.variables.reduce((a,l)=>(a[l.name]=Re(l,r),a),t),t},get variableValueMap(){const t={},r=this.variableAggValueMap;return e.variables.reduce((a,l)=>(a[l.name]=$e(l,r[l.name]),a),t),t},get variableStyleMap(){const t=this.variableValueMap,r={};return e.variables.reduce((a,l)=>{const o=fu(l.color,t[l.name]);return a[l.name]={color:o,"font-size":l.size,"font-weight":l.weight,variable:l},a},r),r},get dataLoading(){return this.queries.some(t=>t.isTransform?t.depQueryModelStates.some(r=>r==="loading"):t.state==="loading")},get queryStateMessages(){const t=this.queries.filter(o=>!o.runByConditionsMet);if(t.length===0)return"";const r=new Set,a=new Set;t.forEach(o=>{const i=o.conditionNames;i.context.forEach(c=>r.add(c)),i.filters.forEach(c=>a.add(c))});const l=[];return r.size>0&&l.push(`context: ${Array.from(r).join(", ")}`),a.size>0&&l.push(`filter${a.size>1?"s":""}: ${Array.from(a).join(", ")}`),l.length===2&&l.splice(1,0,"and"),l.unshift("Waiting for"),l.join(" ")},get queryErrors(){return this.queries.map(t=>t.error??t.metricQueryPayloadErrorString).filter(t=>!!t)},get canRenderViz(){return this.queryErrors.length===0&&this.queryStateMessages===""&&!this.dataLoading}})).actions(e=>({refreshData(){e.queries.forEach(t=>t.fetchData(!0))},downloadData(){e.contentModel.queries.downloadDataByQueryIDs(e.name,e.queryIDs)},getSchema(){const t=e.json;return t.viz.conf={...t.viz.conf,__INTERACTIONS:{},__OPERATIONS:{},__TRIGGERS:{}},{panel:t,queries:e.queries.map(r=>r.json),layouts:e.contentModel.layouts.jsonByPanelIDSet(new Set([e.id]))}},downloadSchema(){const{panel:t,queries:r,layouts:a}=this.getSchema(),o=JSON.stringify({panels:[t],definition:{queries:r},layouts:a,version:at},null,2),i=e.name;Bt(i,o)}}));function _i(e){return{id:e,name:"Panel",title:{show:!0},description:"<p></p>",queryIDs:[],viz:{type:$r.name,conf:$r.createConfig()},style:{border:{enabled:!0}}}}const xa=g.types.model("PanelsRenderModel",{list:g.types.optional(g.types.array(_a),[])}).views(e=>({get json(){return e.list.map(t=>t.json)},findByID(t){return e.list.find(r=>r.id===t)},get idMap(){const t=new Map;return e.list.forEach(r=>{t.set(r.id,r)}),t}})).views(e=>({panelsByIDs(t){const r=[];return t.forEach(a=>{const l=e.idMap.get(a);l?r.push(l):console.warn(`Panel is not found, id:${a}`)}),r}}));function xi(e){const t=e.config,r=t==null?void 0:t.default_value;return r===void 0?r:t._name==="date-range"?Xo(t):r}function WS(e,t){const r=e.default_value_func;try{const a=new Function(`return ${r}`)()(e,je,t);return e.config._name==="date-range"&&Array.isArray(a)?{value:a,shortcut:null}:a}catch(a){return console.error(a),xi(e)}}function wi(e,t){var r;return(r=e.default_value_func)!=null&&r.trim()?WS(e,t):xi(e)}function mi(e,t){return e.reduce((r,a)=>(r[a.key]=wi(a,t),r),{})}function Ci(e,t){const r={};return Object.entries(t).forEach(([a,l])=>{const o=e[a];return typeof l=="object"&&"shortcut"in l&&Array.isArray(o)?r[a]={value:o,shortcut:null}:r[a]=o??l,r}),r}const wa=g.types.model("FiltersRenderModel",{current:g.types.optional(g.types.array(Cn),[]),values:g.types.optional(g.types.frozen(),{})}).views(e=>({get json(){return e.current.map(t=>t.json)},get valuesString(){return JSON.stringify(e.values)},get filter(){return g.getParent(e)},get keysToTypes(){return e.current.reduce((t,r)=>(t[r.key]=r.type,t),{})},keyStateItemMap(t){return e.current.reduce((r,a)=>{const l=t[a.key];return r[a.key]={type:a.type,key:a.key,model:a,label:a.label??a.id,value:l},r},{})},get valuesForPayload(){const t={};return Object.entries(e.values).forEach(([r,a])=>{t[r]=a;const l=this.findByKey(r);l&&l.config._name==="date-range"&&(t[r]=l.config.dateStringsValue)}),t},get contentModel(){return g.getRoot(e).content},get context(){return this.contentModel.payloadForSQL.context},get initialValuesDep(){return JSON.stringify({filters:e.current.map(({default_value_func:t,config:r})=>({default_value_func:t,config:r})),context:this.contentModel.payloadForSQL.context})},get formattedDefaultValues(){return mi(this.json,this.contentModel.context)},get firstID(){if(e.current.length!==0)return e.current[0].id},findByID(t){return e.current.find(r=>r.id===t)},findByKey(t){return e.current.find(r=>r.key===t)},findByIDSet(t){return e.current.filter(r=>t.has(r.id))},get inOrder(){return y.sortBy(e.current,"order")},get empty(){return e.current.length===0},visibleInView(t){return y.sortBy(e.current.filter(r=>r.visibleInViewsIDSet.has(t)),"order")},get firstFilterValueKey(){return Object.keys(e.values)[0]??""},get keySet(){return new Set(e.current.map(t=>t.key))},get keyLabelMap(){return e.current.reduce((t,r)=>(t[r.key]=r.label,t),{})},get keyIDMap(){return e.current.reduce((t,r)=>(t[r.key]=r.id,t),{})},getSelectOption(t){const r=this.findByID(t);if(!r||!("getSelectOption"in r.config))return null;const a=e.values[r.key];return r.config.getSelectOption(a)}})).actions(e=>({setValues(t){console.debug("⚪️ setting filter values: ",JSON.stringify(t)),e.values=t},patchValues(t){console.debug("⚪️ patching filter values: ",JSON.stringify(t)),e.values=Ci(t,e.values)},setValueByKey(t,r){console.debug(`⚪️ setting filter[${t}] to value: `,JSON.stringify(r)),e.values={...e.values,[t]:r}},applyValuesPatch(t){e.values={...e.values,...t}},getValueByKey(t){return e.values[t]},getSchema(t,r){return{filters:e.findByIDSet(new Set(t)).map(o=>({...o.json,visibleInViewsIDs:r?o.json.visibleInViewsIDs:[]})),version:at}},downloadSchema(t){const r=JSON.stringify(this.getSchema(t,!1),null,2);Bt("Filters",r)}}));function ma(e,t,r,a){const l={...r,...t},o=mi(e,l),i=Ci(a,o);return{current:e,values:i}}function US(e,t){const r=bs.decode(t);r!==e&&(console.error("Inconsistent sql"),console.groupCollapsed("Inconsistent sql"),console.table({before:e,after:t,v:r}),console.groupEnd())}async function YS({query:e,name:t,payload:r,additionals:a},l){if(!e.sql)return[];const{type:o,key:i,sql:c,pre_process:d,post_process:u}=e,p=lr(c,r),f=Cp({sql:p,pre_process:d}),v=bs.encode(f);US(f,v);let _=await Ae.query(l)({type:o,key:i,query:v,...a},{params:{name:t}});return _=Sp(u,_,sr(r)),_}async function KS({type:e,key:t,configString:r,name:a,additionals:l},o){try{return await Ae.httpDataSourceQuery(o)({type:e,key:t,query:r,...l},{params:{name:a}})}catch(i){if(ke.isCancel(i))throw i;return console.error(i),i}}async function XS({key:e,configString:t,name:r,additionals:a},l){try{return await Ae.mericoMetricQuery(l)({type:"merico_metric_system",key:e,query:t,...a},{params:{name:r}})}catch(o){throw o}}async function Ca(){try{return(await Ae.post()("/datasource/list",{filter:{},sort:[{field:"create_time",order:"ASC"}],pagination:{page:1,pagesize:100}},{})).data}catch(e){return console.error(e),[]}}async function Si(){try{return(await Ae.post()("/sql_snippet/list",{filter:{},sort:[{field:"id",order:"ASC"}],pagination:{page:1,pagesize:1e3}},{})).data}catch(e){return console.error(e),[]}}const Ti=Fo.views(e=>({get rootModel(){return g.getRoot(e)},get contentModel(){return this.rootModel.content},get conditionOptions(){return this.contentModel.dashboardStateVariableOptions},getConditionOptionsWithInvalidValue(t){const{optionGroups:r,validValues:a}=this.conditionOptions;if(!t||a.has(t))return this.conditionOptions;const l={group:"common.invalid",items:[{label:t,value:t}]};return{optionGroups:[...r,l],validValues:a}},get conditionOptionsWithInvalidRunbys(){const{optionGroups:t,validValues:r}=this.conditionOptions,a={group:"common.invalid",items:[]};return e.run_by.forEach(l=>{r.has(l)||a.items.push({label:l,value:l})}),{optionGroups:[...t,a],validValues:r}},get unmetRunByConditions(){if(!g.isAlive(e))return[];const{run_by:t}=e;if(t.length===0)return[];const r=this.contentModel.payloadForSQL;return t.filter(a=>{const l=y.get(r,a);return Array.isArray(l)?l.length===0:typeof l=="number"?Number.isNaN(l):!l})}})).views(e=>({get payload(){return e.contentModel.payloadForSQL},get formattedSQL(){const t=y.get(e,"config.sql","");return or(t,this.payload)},get httpConfigString(){const{context:t,filters:r}=this.payload,{name:a,pre_process:l}=e.json,o=mp(l,t,r);return console.groupCollapsed(`Request config for: ${a}`),console.log(o),console.groupEnd(),JSON.stringify(o)},get typedAsSQL(){return[j.Postgresql,j.MySQL].includes(e.type)},get typedAsHTTP(){return[j.HTTP].includes(e.type)},get isMericoMetricQuery(){return e.type===j.MericoMetricSystem},get isTransform(){return e.type===j.Transform},get reQueryKey(){const t=y.get(e,"config.react_to",[]);if(t.length===0)return"";const r=e.contentModel.payloadForSQL,a=[...t].reduce((l,o)=>(l[o]=y.get(r,o),l),{});return JSON.stringify(a)},get runByConditionsMet(){return e.unmetRunByConditions.length===0},get conditionNames(){if(e.unmetRunByConditions.length===0)return{context:[],filters:[]};const{keyLabelMap:t}=e.contentModel.filters,r=e.unmetRunByConditions.filter(l=>l.startsWith("context.")).map(l=>l.replace("context.","")),a=e.unmetRunByConditions.filter(l=>l.startsWith("filters.")).map(l=>y.get({filters:t},l,l.replace("filters.",""))).filter(l=>!!l);return{context:r,filters:a}},get queries(){return g.getParent(e,2)},get inUse(){return this.queries.isQueryInUse(e.id)},get dependencies(){if(!this.typedAsSQL)return[];const t=y.get(e,"config.sql","");if(!t)return[];const r=y.uniq(t.match(Mt.sqlSnippet)),a=y.uniq(t.match(Mt.filter)),l=y.uniq(t.match(Mt.context)),o=[];return r.forEach(i=>{o.push({type:"sql_snippet",key:i,valid:e.contentModel.sqlSnippets.keySet.has(i)})}),a.forEach(i=>{o.push({type:"filter",key:i,valid:e.contentModel.filters.keySet.has(i)})}),l.forEach(i=>{o.push({type:"context",key:i,valid:e.contentModel.mock_context.keySet.has(i)})}),o},get usedFilterKeySet(){const t=new Set,r=i=>{t.add(i.replace(/^filters\./,""))};if(e.run_by.forEach(i=>r(i)),y.get(e.config,"react_to",[]).forEach(i=>r(i)),!this.typedAsSQL)return t;const l=y.get(e,"config.sql","");return l&&y.uniq(l.match(Mt.filter)).forEach(i=>r(i)),t},get metricQueryPayload(){if(e.type!==j.MericoMetricSystem)return null;const t=this.payload,r={filters:e.contentModel.filters.keysToTypes},a=e.config,l=a.filters.reduce((f,v)=>{const _=y.get(t,v.variable),w=y.get(r,v.variable),m=v.dimension;if(w===V.DateRange){const z=_.every(D=>Number.isFinite(Number(D)))?_.map(D=>Number(D)):_;f[m]={between:z}}else Array.isArray(_)?f[m]={in:_}:f[m]={eq:_};return f},{}),o={id:a.id,type:a.type,filters:l,groupBys:a.groupBys};if(!a.timeQuery.enabled)return o;const{range_variable:i,unit_variable:c}=a.timeQuery,d="YYYY-MM-DD",u="PRC",p={start:"",end:"",unitOfTime:y.get(t,c,""),unitNumber:1,timezone:"PRC",stepKeyFormat:d};if(i){const f=y.get(t,i);Array.isArray(f)&&f.length===2&&(p.start=M(f[0]).tz(u).format(d),p.end=M(f[1]).tz(u).format(d))}return o.timeQuery=p,o},get metricQueryPayloadString(){return this.metricQueryPayload?JSON.stringify(this.metricQueryPayload,null,2):""},get metricQueryPayloadError(){const t=[];if(!this.metricQueryPayload)return t;const r=e.config,{timeQuery:a}=this.metricQueryPayload;if(!a)return r.groupByValues.length>2&&t.push("分组聚合维度:最多支持两个维度的聚合计算"),t;r.groupByValues.length>1&&t.push("分组聚合维度:按时间序列展示时,仅可选择一个聚合维度");const{start:l,end:o,unitOfTime:i}=a;return(!l||!o)&&t.push("时间维度:时间范围不完整"),i||t.push("步长:必选"),t},get metricQueryPayloadErrorString(){return this.metricQueryPayloadError.join(`
|
|
541
|
+
`)},pa=g.types.model("ViewModalConfig",{_name:g.types.literal($.Modal),width:g.types.string,height:g.types.string,custom_modal_title:g.types.optional(GS,Sn)}).views(e=>({get json(){const{_name:t,width:r,height:a,custom_modal_title:l}=e;return{_name:t,width:r,height:a,custom_modal_title:l.json}}})).actions(e=>({setWidth(t){e.width=t},setHeight(t){e.height=t}})),di=()=>pa.create({_name:$.Modal,width:"90vw",height:"90vh"}),FS=g.types.model("ViewTabsTabModel",{id:g.types.identifier,name:g.types.string,view_id:g.types.string,color:g.types.optional(g.types.string,""),order:g.types.optional(g.types.number,0)}).views(e=>({get json(){const{id:t,name:r,view_id:a,color:l,order:o}=e;return{id:t,name:r,color:l,order:o,view_id:a}}})).actions(e=>({setName(t){e.name=t},setViewID(t){t&&(e.view_id=t)},setColor(t){e.color=t},setOrder(t){typeof t!="string"&&(e.order=t)}})),ha=g.types.model("ViewTabsConfig",{_name:g.types.literal($.Modal),tabs:g.types.optional(g.types.array(FS),[]),variant:g.types.optional(g.types.enumeration("variant",["default","outline","pills"]),"default"),orientation:g.types.optional(g.types.enumeration("orientation",["horizontal","vertical"]),"horizontal"),grow:g.types.optional(g.types.boolean,!1)}).views(e=>({get json(){const{_name:t,variant:r,orientation:a,tabs:l,grow:o}=e;return{grow:o,tabs:l.map(i=>i.json),_name:t,variant:r,orientation:a}},get tabsInOrder(){return y.sortBy(e.tabs,"order")}})).actions(e=>({setVariant(t){t&&(e.variant=t)},setOrientation(t){t&&(e.orientation=t)},setGrow(t){e.grow=t},setTabs(t){e.tabs.length=0,e.tabs=g.cast(t)},addTab(){const t=te.randomId(),r={id:t,name:t,view_id:""};e.tabs.push(r)},removeTab(t){e.tabs.splice(t,1)}})),ui=()=>ha.create({_name:$.Modal,tabs:[]}),pi=g.types.model({id:g.types.identifier,name:g.types.string,type:g.types.enumeration("EViewComponentType",[$.Division,$.Modal,$.Tabs]),config:g.types.union(ua,pa,ha),panelIDs:g.types.optional(g.types.array(g.types.string),[])}).views(e=>({get json(){const{id:t,name:r,type:a,config:l}=e;return{id:t,name:r,type:a,config:l.json,panelIDs:e.panelIDs.map(o=>o)}}})).actions(e=>({setName(t){e.name=t},setType(t){if(e.type!==t){switch(t){case $.Division:e.config=ci();break;case $.Modal:e.config=di();break;case $.Tabs:e.config=ui();break;default:return}e.type=t}},appendPanelID(t){e.panelIDs.push(t)},appendPanelIDs(t){e.panelIDs.push(...t)},removePanelID(t){const r=e.panelIDs.filter(a=>a!==t);e.panelIDs.length=0,e.panelIDs.push(...r)}})),at="14.32.0",jS={definition:{sqlSnippets:[],queries:[],mock_context:{}},views:[{id:"Main",name:"Main",type:$.Division,config:{},panelIDs:[]}],panels:[],filters:[],version:at,layouts:[{id:"basis",name:"basis",list:[],breakpoint:0}]},ga=g.types.model("DataSourceMetaModel",{id:g.types.string,type:g.types.enumeration("DataSourceType",[j.HTTP,j.MySQL,j.Postgresql,j.MericoMetricSystem]),key:g.types.string,config:g.types.frozen()}),hi=g.types.model("DataSourcesMetaModel",{list:g.types.optional(g.types.array(ga),[])}).views(e=>({find({type:t,key:r}){return e.list.find(a=>a.key===r&&a.type===t)},get options(){return e.list.map(t=>({value:t.key,label:t.key}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}})),gi=g.types.model({id:g.types.string,content:g.types.string,create_time:g.types.string,update_time:g.types.string,is_preset:g.types.boolean}),fa=g.types.model("GlobalSQLSnippetsMeta",{list:g.types.optional(g.types.array(gi),[])}).views(e=>({find(t){return e.list.find(r=>r.id===t)},get options(){return e.list.map(t=>({value:t.id,label:t.id}))}})).actions(e=>({replace(t){e.list.length=0,e.list.push(...t)}})),Tn=g.types.model("ContextMeta",{current:g.types.optional(g.types.frozen(),{})}).views(e=>({get keys(){return Object.keys(e.current)},get entries(){return Object.entries(e.current)}})).actions(e=>({replace(t){e.current=t},get(t){return e.current[t]},set(t,r){e.current[t]=r}}));function ba(e){return Tn.create({current:e})}const ya=g.types.compose("ViewRenderModel",pi,g.types.model({tab:g.types.optional(g.types.string,"")})).views(e=>({get tabs(){return e.config.tabs},get tabInfo(){const t=this.tabs.find(r=>r.id===e.tab);return t?{id:t.id,name:t.name}:null},get tabView(){return e.type!==$.Tabs?null:this.tabs.find(t=>t.id===e.tab)},get tabViewID(){return this.tabView?this.tabView.view_id??"":""},get contentModel(){return g.getParent(e,3)},get panels(){if(e.type!==$.Tabs)return this.contentModel.panels.panelsByIDs(e.panelIDs);const t=this.tabViewID,r=this.contentModel.views.findByID(t);return(r==null?void 0:r.panels)??[]},get renderViewIDs(){const t=[e.id];return e.type===$.Tabs&&t.push(this.tabViewID),t},async downloadScreenshot(t){const r=t.offsetWidth*2+10,a=t.offsetHeight*2+10,l=new fs,o=new Date().getTime(),i=await gs.toBlob(t,{bgcolor:"white",width:r,height:a,style:{transformOrigin:"0 0",transform:"scale(2)"}});l.file(`${e.name}_${o}.png`,i),l.file(`dashboard_state_${o}.json`,JSON.stringify(this.contentModel.dashboardStateValues,null,4)),l.generateAsync({type:"blob"}).then(c=>{Xt.saveAs(c,`${e.name}_${o}.zip`)}).catch(c=>{console.error(c),Ze.notifications.show({color:"red",title:"Failed to download screenshot with dashboard state",message:c.message})})}})).actions(e=>({setTab(t){e.tab=t??""},setTabByTabInfo(t){e.tab=t.id??""}})),va=g.types.model("ViewsRenderModel",{current:g.types.optional(g.types.array(ya),[]),visibleViewIDs:g.types.array(g.types.string)}).views(e=>({get json(){return e.current.map(t=>tt(t.json))},get idMap(){const t=new Map;return e.current.forEach(r=>{t.set(r.id,r)}),t},findByID(t){return e.current.find(r=>r.id===t)},get firstVisibleView(){const[t]=e.visibleViewIDs;return e.current.find(({id:r})=>r===t)},get visibleViews(){const t=new Set(e.visibleViewIDs);return e.current.filter(({id:r})=>t.has(r))},get firstVisibleTabsView(){return this.visibleViews.find(t=>t.type===$.Tabs)},get firstVisibleTabsViewActiveTab(){const t=this.firstVisibleTabsView;return t?t.tabInfo:null},get firstVisibleTabsViewActiveTabStr(){return JSON.stringify(this.firstVisibleTabsViewActiveTab)}})).actions(e=>({appendToVisibles(t){new Set(e.visibleViewIDs.map(a=>a)).has(t)||e.visibleViewIDs.push(t)},rmVisibleViewID(t){const r=e.visibleViewIDs.findIndex(a=>a===t);r!==-1&&e.visibleViewIDs.splice(r,1)},setFirstVisibleTabsViewActiveTab(t){if(!t)return;const r=e.firstVisibleTabsView;r==null||r.setTabByTabInfo(t)}}));function fi(e,t){const r=e.length>0?[e[0].id]:[],a=e.map(l=>{const{_name:o=l.type}=l.config,i={...l,tab:"",config:{...l.config,_name:o},panelIDs:l.panelIDs};if(l.type===$.Tabs){let c=y.minBy(l.config.tabs,d=>d.order);!c&&l.config.tabs.length>0&&(c=l.config.tabs[0]),i.tab=(c==null?void 0:c.id)??""}return i});return t&&(a[0].tab=t.id),{current:a,visibleViewIDs:r}}const QS=new Gd.AsyncParser({withBOM:!0});async function bi(e){return!Array.isArray(e)||e.length===0?"":await QS.parse(e).promise()}async function yi(e,t){const r=await bi(t),a=new Blob([r],{type:"text/csv"});Xt.saveAs(a,`${e}.csv`)}function vi(e,t){const r=new fs,a=t.map(async({id:l,data:o})=>{const i=await bi(o);r.file(`${l}.csv`,i)});Promise.all(a).then(()=>{r.generateAsync({type:"blob"}).then(l=>{Xt.saveAs(l,`${e}.zip`)})}).catch(l=>{console.error(l),Ze.notifications.show({color:"red",title:"Failed to download data",message:l.message})})}function Bt(e,t){const r=new Blob([t],{type:"application/json"});Xt.saveAs(r,`${e}.json`)}const _a=Bo.views(e=>({get contentModel(){return g.getRoot(e).content}})).views(e=>({get queries(){return e.contentModel.queries.findByIDSet(e.queryIDSet)},get firstQuery(){return this.queries.length>0?this.queries[0]:null},get firstQueryData(){return this.firstQuery?this.firstQuery.data:[]},queryByID(t){return this.queries.find(r=>r.id===t)},get data(){return this.queries.reduce((t,r)=>(t[r.id]=r.data,t),{})},get variableStrings(){return sl(e.variables,this.data)},get variableAggValueMap(){const t={},r=this.data;return e.variables.reduce((a,l)=>(a[l.name]=Re(l,r),a),t),t},get variableValueMap(){const t={},r=this.variableAggValueMap;return e.variables.reduce((a,l)=>(a[l.name]=$e(l,r[l.name]),a),t),t},get variableStyleMap(){const t=this.variableValueMap,r={};return e.variables.reduce((a,l)=>{const o=fu(l.color,t[l.name]);return a[l.name]={color:o,"font-size":l.size,"font-weight":l.weight,variable:l},a},r),r},get dataLoading(){return this.queries.some(t=>t.isTransform?t.depQueryModelStates.some(r=>r==="loading"):t.state==="loading")},get queryStateMessages(){const t=this.queries.filter(o=>!o.runByConditionsMet);if(t.length===0)return"";const r=new Set,a=new Set;t.forEach(o=>{const i=o.conditionNames;i.context.forEach(c=>r.add(c)),i.filters.forEach(c=>a.add(c))});const l=[];return r.size>0&&l.push(`context: ${Array.from(r).join(", ")}`),a.size>0&&l.push(`filter${a.size>1?"s":""}: ${Array.from(a).join(", ")}`),l.length===2&&l.splice(1,0,"and"),l.unshift("Waiting for"),l.join(" ")},get queryErrors(){return this.queries.map(t=>t.error??t.metricQueryPayloadErrorString).filter(t=>!!t)},get canRenderViz(){return this.queryErrors.length===0&&this.queryStateMessages===""&&!this.dataLoading}})).actions(e=>({refreshData(){e.queries.forEach(t=>t.fetchData(!0))},downloadData(){e.contentModel.queries.downloadDataByQueryIDs(e.name,e.queryIDs)},getSchema(){const t=e.json;return t.viz.conf={...t.viz.conf,__INTERACTIONS:{},__OPERATIONS:{},__TRIGGERS:{}},{panel:t,queries:e.queries.map(r=>r.json),layouts:e.contentModel.layouts.jsonByPanelIDSet(new Set([e.id]))}},downloadSchema(){const{panel:t,queries:r,layouts:a}=this.getSchema(),o=JSON.stringify({panels:[t],definition:{queries:r},layouts:a,version:at},null,2),i=e.name;Bt(i,o)}}));function _i(e){return{id:e,name:"Panel",title:{show:!0},description:"<p></p>",queryIDs:[],viz:{type:$r.name,conf:$r.createConfig()},style:{border:{enabled:!0}}}}const xa=g.types.model("PanelsRenderModel",{list:g.types.optional(g.types.array(_a),[])}).views(e=>({get json(){return e.list.map(t=>t.json)},findByID(t){return e.list.find(r=>r.id===t)},get idMap(){const t=new Map;return e.list.forEach(r=>{t.set(r.id,r)}),t}})).views(e=>({panelsByIDs(t){const r=[];return t.forEach(a=>{const l=e.idMap.get(a);l?r.push(l):console.warn(`Panel is not found, id:${a}`)}),r}}));function xi(e){const t=e.config,r=t==null?void 0:t.default_value;return r===void 0?r:t._name==="date-range"?Xo(t):r}function WS(e,t){const r=e.default_value_func;try{const a=new Function(`return ${r}`)()(e,je,t);return e.config._name==="date-range"&&Array.isArray(a)?{value:a,shortcut:null}:a}catch(a){return console.error(a),xi(e)}}function wi(e,t){var r;return(r=e.default_value_func)!=null&&r.trim()?WS(e,t):xi(e)}function mi(e,t){return e.reduce((r,a)=>(r[a.key]=wi(a,t),r),{})}function Ci(e,t){const r={};return Object.entries(t).forEach(([a,l])=>{const o=e[a];return typeof l=="object"&&"shortcut"in l&&Array.isArray(o)?r[a]={value:o,shortcut:null}:r[a]=o??l,r}),r}const wa=g.types.model("FiltersRenderModel",{current:g.types.optional(g.types.array(Cn),[]),values:g.types.optional(g.types.frozen(),{})}).views(e=>({get json(){return e.current.map(t=>t.json)},get valuesString(){return JSON.stringify(e.values)},get filter(){return g.getParent(e)},get keysToTypes(){return e.current.reduce((t,r)=>(t[r.key]=r.type,t),{})},keyStateItemMap(t){return e.current.reduce((r,a)=>{const l=t[a.key];return r[a.key]={type:a.type,key:a.key,model:a,label:a.label??a.id,value:l},r},{})},get valuesForPayload(){const t={};return Object.entries(e.values).forEach(([r,a])=>{t[r]=a;const l=this.findByKey(r);l&&l.config._name==="date-range"&&(t[r]=l.config.dateStringsValue)}),t},get contentModel(){return g.getRoot(e).content},get context(){return this.contentModel.payloadForSQL.context},get initialValuesDep(){return JSON.stringify({filters:e.current.map(({default_value_func:t,config:r})=>({default_value_func:t,config:r})),context:this.contentModel.payloadForSQL.context})},get formattedDefaultValues(){return mi(this.json,this.contentModel.context)},get firstID(){if(e.current.length!==0)return e.current[0].id},findByID(t){return e.current.find(r=>r.id===t)},findByKey(t){return e.current.find(r=>r.key===t)},findByIDSet(t){return e.current.filter(r=>t.has(r.id))},get inOrder(){return y.sortBy(e.current,"order")},get empty(){return e.current.length===0},visibleInView(t){return y.sortBy(e.current.filter(r=>r.visibleInViewsIDSet.has(t)),"order")},get firstFilterValueKey(){return Object.keys(e.values)[0]??""},get keySet(){return new Set(e.current.map(t=>t.key))},get keyLabelMap(){return e.current.reduce((t,r)=>(t[r.key]=r.label,t),{})},get keyIDMap(){return e.current.reduce((t,r)=>(t[r.key]=r.id,t),{})},getSelectOption(t){const r=this.findByID(t);if(!r||!("getSelectOption"in r.config))return null;const a=e.values[r.key];return r.config.getSelectOption(a)}})).actions(e=>({setValues(t){console.debug("⚪️ setting filter values: ",JSON.stringify(t)),e.values=t},patchValues(t){console.debug("⚪️ patching filter values: ",JSON.stringify(t)),e.values=Ci(t,e.values)},setValueByKey(t,r){console.debug(`⚪️ setting filter[${t}] to value: `,JSON.stringify(r)),e.values={...e.values,[t]:r}},applyValuesPatch(t){e.values={...e.values,...t}},getValueByKey(t){return e.values[t]},getSchema(t,r){return{filters:e.findByIDSet(new Set(t)).map(o=>({...o.json,visibleInViewsIDs:r?o.json.visibleInViewsIDs:[]})),version:at}},downloadSchema(t){const r=JSON.stringify(this.getSchema(t,!1),null,2);Bt("Filters",r)}}));function ma(e,t,r,a){const l={...r,...t},o=mi(e,l),i=Ci(a,o);return{current:e,values:i}}function US(e,t){const r=bs.decode(t);r!==e&&(console.error("Inconsistent sql"),console.groupCollapsed("Inconsistent sql"),console.table({before:e,after:t,v:r}),console.groupEnd())}async function YS({query:e,name:t,payload:r,additionals:a},l){if(!e.sql)return[];const{type:o,key:i,sql:c,pre_process:d,post_process:u}=e,p=lr(c,r),f=Cp({sql:p,pre_process:d}),v=bs.encode(f);US(f,v);let _=await Ae.query(l)({type:o,key:i,query:v,...a},{params:{name:t}});return _=Sp(u,_,sr(r)),_}async function KS({type:e,key:t,configString:r,name:a,additionals:l},o){try{return await Ae.httpDataSourceQuery(o)({type:e,key:t,query:r,...l},{params:{name:a}})}catch(i){if(ke.isCancel(i))throw i;return console.error(i),i}}async function XS({key:e,configString:t,name:r,additionals:a},l){try{return await Ae.mericoMetricQuery(l)({type:"merico_metric_system",key:e,query:t,...a},{params:{name:r}})}catch(o){throw o}}async function Ca(){try{return(await Ae.post()("/datasource/list",{filter:{},sort:[{field:"create_time",order:"ASC"}],pagination:{page:1,pagesize:100}},{})).data}catch(e){return console.error(e),[]}}async function Si(){try{return(await Ae.post()("/sql_snippet/list",{filter:{},sort:[{field:"id",order:"ASC"}],pagination:{page:1,pagesize:1e3}},{})).data}catch(e){return console.error(e),[]}}const Ti=Fo.views(e=>({get rootModel(){return g.getRoot(e)},get contentModel(){return this.rootModel.content},get conditionOptions(){return this.contentModel.dashboardStateVariableOptions},getConditionOptionsWithInvalidValue(t){const{optionGroups:r,validValues:a}=this.conditionOptions;if(!t||a.has(t))return this.conditionOptions;const l={group:"common.invalid",items:[{label:t,value:t}]};return{optionGroups:[...r,l],validValues:a}},get conditionOptionsWithInvalidRunbys(){const{optionGroups:t,validValues:r}=this.conditionOptions,a={group:"common.invalid",items:[]};return e.run_by.forEach(l=>{r.has(l)||a.items.push({label:l,value:l})}),{optionGroups:[...t,a],validValues:r}},get unmetRunByConditions(){if(!g.isAlive(e))return[];const{run_by:t}=e;if(t.length===0)return[];const r=this.contentModel.payloadForSQL;return t.filter(a=>{const l=y.get(r,a);return Array.isArray(l)?l.length===0:typeof l=="number"?Number.isNaN(l):!l})}})).views(e=>({get payload(){return e.contentModel.payloadForSQL},get formattedSQL(){const t=y.get(e,"config.sql","");return or(t,this.payload)},get httpConfigString(){const{context:t,filters:r}=this.payload,{name:a,pre_process:l}=e.json,o=mp(l,t,r);return console.groupCollapsed(`Request config for: ${a}`),console.log(o),console.groupEnd(),JSON.stringify(o)},get typedAsSQL(){return[j.Postgresql,j.MySQL].includes(e.type)},get typedAsHTTP(){return[j.HTTP].includes(e.type)},get isMericoMetricQuery(){return e.type===j.MericoMetricSystem},get isTransform(){return e.type===j.Transform},get reQueryKey(){const t=y.get(e,"config.react_to",[]);if(t.length===0)return"";const r=e.contentModel.payloadForSQL,a=[...t].reduce((l,o)=>(l[o]=y.get(r,o),l),{});return JSON.stringify(a)},get runByConditionsMet(){return e.unmetRunByConditions.length===0},get conditionNames(){if(e.unmetRunByConditions.length===0)return{context:[],filters:[]};const{keyLabelMap:t}=e.contentModel.filters,r=e.unmetRunByConditions.filter(l=>l.startsWith("context.")).map(l=>l.replace("context.","")),a=e.unmetRunByConditions.filter(l=>l.startsWith("filters.")).map(l=>y.get({filters:t},l,l.replace("filters.",""))).filter(l=>!!l);return{context:r,filters:a}},get queries(){return g.getParent(e,2)},get inUse(){return this.queries.isQueryInUse(e.id)},get dependencies(){if(!this.typedAsSQL)return[];const t=y.get(e,"config.sql","");if(!t)return[];const r=y.uniq(t.match(Mt.sqlSnippet)),a=y.uniq(t.match(Mt.filter)),l=y.uniq(t.match(Mt.context)),o=[];return r.forEach(i=>{o.push({type:"sql_snippet",key:i,valid:e.contentModel.sqlSnippets.keySet.has(i)})}),a.forEach(i=>{o.push({type:"filter",key:i,valid:e.contentModel.filters.keySet.has(i)})}),l.forEach(i=>{o.push({type:"context",key:i,valid:e.contentModel.mock_context.keySet.has(i)})}),o},get usedFilterKeySet(){const t=new Set,r=i=>{t.add(i.replace(/^filters\./,""))};if(e.run_by.forEach(i=>r(i)),y.get(e.config,"react_to",[]).forEach(i=>r(i)),!this.typedAsSQL)return t;const l=y.get(e,"config.sql","");return l&&y.uniq(l.match(Mt.filter)).forEach(i=>r(i)),t},get metricQueryPayload(){if(e.type!==j.MericoMetricSystem)return null;const t=this.payload,r={filters:e.contentModel.filters.keysToTypes},a=e.config,l=a.filters.reduce((f,v)=>{const _=y.get(t,v.variable),w=y.get(r,v.variable),m=v.dimension;if(w===V.DateRange){const z=_.every(D=>Number.isFinite(Number(D)))?_.map(D=>Number(D)):_;f[m]={between:z}}else Array.isArray(_)?f[m]={in:_}:f[m]={eq:_};return f},{}),o={id:a.id,type:a.type,filters:l,groupBys:a.groupBys};if(a.useDefaultValues&&(o.useDefaultValues=!0),!a.timeQuery.enabled)return o;const{range_variable:i,unit_variable:c}=a.timeQuery,d="YYYY-MM-DD",u="PRC",p={start:"",end:"",unitOfTime:y.get(t,c,""),unitNumber:1,timezone:"PRC",stepKeyFormat:d};if(i){const f=y.get(t,i);Array.isArray(f)&&f.length===2&&(p.start=M(f[0]).tz(u).format(d),p.end=M(f[1]).tz(u).format(d))}return o.timeQuery=p,o},get metricQueryPayloadString(){return this.metricQueryPayload?JSON.stringify(this.metricQueryPayload,null,2):""},get metricQueryPayloadError(){const t=[];if(!this.metricQueryPayload)return t;const r=e.config,{timeQuery:a}=this.metricQueryPayload;if(!a)return r.groupByValues.length>2&&t.push("分组聚合维度:最多支持两个维度的聚合计算"),t;r.groupByValues.length>1&&t.push("分组聚合维度:按时间序列展示时,仅可选择一个聚合维度");const{start:l,end:o,unitOfTime:i}=a;return(!l||!o)&&t.push("时间维度:时间范围不完整"),i||t.push("步长:必选"),t},get metricQueryPayloadErrorString(){return this.metricQueryPayloadError.join(`
|
|
542
542
|
`)},get metricQueryPayloadValid(){return this.metricQueryPayload?this.metricQueryPayloadError.length===0:!1}})),Sa=g.types.compose("QueryRenderModel",Ti,g.types.model({state:g.types.optional(g.types.enumeration(["idle","loading","error"]),"idle"),data:g.types.optional(g.types.frozen([]),[]),error:g.types.optional(g.types.frozen(),null)})).views(e=>({get datasource(){const{key:t,type:r}=e;return e.rootModel.datasources.find({type:r,key:t})},get additionalQueryInfo(){return e.contentModel.getAdditionalQueryInfo(e.id)},get depQueryModels(){const t=y.get(e,"config.dep_query_ids",[]);return e.contentModel.queries.findByIDSet(new Set(t))},get depQueryModelStates(){return this.depQueryModels.map(t=>t.state)},get depQueryModelStatesString(){return this.depQueryModelStates.toString()}})).views(e=>({get stateMessage(){if(e.state!=="idle")return"";if(!e.runByConditionsMet){const{context:t,filters:r}=e.conditionNames;if(t.length===0&&r.length===0)return"Waiting";const a=[];return t.length>0&&a.push(`context: ${t.join(", ")}`),r.length>0&&a.push(`filter${r.length>1?"s":""}: ${r.join(", ")}`),a.length===2&&a.splice(1,0,"and"),a.unshift("Waiting for"),a.join(" ")}return e.data.length>0?"":"data.empty_data"}})).volatile(()=>({controller:new AbortController})).actions(e=>({setData(t){e.data=t},setError(t){e.error=t}})).actions(e=>({runSQL:g.flow(function*(){var t;if(e.valid&&((t=e.controller)==null||t.abort(),!!e.runByConditionsMet)){e.controller=new AbortController,e.state="loading";try{const r=e.payload,a=e.config;e.data=yield*g.toGenerator(YS({payload:r,name:e.name,query:{type:e.type,key:e.key,sql:a.sql,pre_process:e.pre_process,post_process:e.post_process},additionals:e.additionalQueryInfo},e.controller.signal)),e.state="idle",e.error=null}catch(r){if(ke.isCancel(r))console.debug(`🟡 Query[${e.name}] is cancelled`),e.data=[],e.state="idle";else{e.data=[];const a=y.get(r,"message","unkown error");e.error=y.get(r,"response.data.detail.message",a),e.state="error"}}}}),runHTTP:g.flow(function*(){var t;if(!(!e.valid||!e.datasource)&&((t=e.controller)==null||t.abort(),!!e.runByConditionsMet)){e.controller=new AbortController,e.state="loading";try{const{type:r,key:a,post_process:l}=e.json;let o=JSON.parse(e.httpConfigString);o=rn(e.datasource,o);const i=yield*g.toGenerator(KS({type:r,key:a,configString:JSON.stringify(o),name:e.name,additionals:e.additionalQueryInfo},e.controller.signal)),c=an(e.datasource,i),d=ol(l,c,e.contentModel.dashboardStateValues);e.data=d,e.state="idle",e.error=null}catch(r){if(console.error(r),ke.isCancel(r))console.debug(`🟡 Query[${e.name}] is cancelled`),e.data=[],e.state="idle";else{e.data=[];const a=y.get(r,"message","unkown error");e.error=y.get(r,"response.data.detail.message",a),e.state="error"}}}}),runMericoMetricQuery:g.flow(function*(){var t;if(!(!e.valid||!e.datasource)&&((t=e.controller)==null||t.abort(),!!e.runByConditionsMet&&e.metricQueryPayloadValid)){e.controller=new AbortController,e.state="loading";try{const{type:r,key:a,post_process:l}=e.json;let o={url:"/api/metric_management/query",method:"POST",data:e.metricQueryPayload};o=rn(e.datasource,o);const i=yield*g.toGenerator(XS({key:a,configString:JSON.stringify(o),name:e.name,additionals:e.additionalQueryInfo},e.controller.signal)),c=an(e.datasource,i),d=ol(l,c,e.contentModel.dashboardStateValues);e.data=d.data,e.state="idle",e.error=null}catch(r){if(console.error(r),ke.isCancel(r))console.debug(`🟡 Query[${e.name}] is cancelled`),e.data=[],e.state="idle";else{e.data=[];const a=y.get(r,"message","unkown error");e.error=y.get(r,"response.data.detail.message",a),e.state="error"}}}}),runTransformation(){e.state="loading";try{const t=e.depQueryModels.map(o=>({id:o.id,name:o.name,data:y.cloneDeep(o.data)})),r=e.contentModel.dashboardStateValues,a=e.pre_process,l=new Function(`return ${a}`)()(t,r,je);e.data=l,e.state="idle",e.error=null}catch(t){e.data=[],e.error=t.message,e.state="error"}}})).actions(e=>({fetchData:t=>{if(!e.inUse&&!t){console.debug(`🟡 Skipping query[${e.name}]`);return}return console.debug(`🔵 Running query[${e.name}]`),e.isTransform?e.runTransformation():e.typedAsHTTP?e.runHTTP():e.isMericoMetricQuery?e.runMericoMetricQuery():e.runSQL()},beforeDestroy(){var t;(t=e.controller)==null||t.abort()}})).actions(e=>({afterCreate(){g.addDisposer(e,Q.reaction(()=>{var r,a;if(e.isTransform){const l=e.config;return[e.inUse,e.id,e.key,e.reQueryKey,l.dep_query_ids.toString(),e.pre_process,e.depQueryModelStatesString].join("--")}return e.typedAsHTTP?`${e.inUse}--${e.id}--${e.key}--${e.reQueryKey}--${(r=e.datasource)==null?void 0:r.id}`:e.isMericoMetricQuery?`${e.inUse}--${e.id}--${e.key}--${e.reQueryKey}--${e.metricQueryPayloadString}--${(a=e.datasource)==null?void 0:a.id}`:[e.inUse,e.id,e.key,e.formattedSQL,e.pre_process,e.post_process].join("--")},()=>e.fetchData(!1),{fireImmediately:!0,delay:0}))}})),Ta=g.types.model("QueriesRenderModel",{current:g.types.optional(g.types.array(Sa),[])}).views(e=>({get idSet(){return new Set(e.current.map(t=>t.id))},get firstID(){if(e.current.length!==0)return e.current[0].id},findByID(t){return e.current.find(r=>r.id===t)},findByIDSet(t){return e.current.filter(r=>t.has(r.id))},get json(){return e.current.filter(t=>t.id&&t.key).map(t=>t.json)},get root(){return g.getRoot(e)},get dashboardName(){return this.root.name},get contentModel(){return g.getParent(e,1)},get visibleQueryIDSet(){const{views:t,filters:r}=this.contentModel,a=[];t.visibleViews.forEach(i=>{i.panels.forEach(c=>{a.push(...c.queryIDs)})});const l=y.uniq(t.visibleViews.map(i=>i.renderViewIDs).flat());r.current.forEach(i=>{const c=y.get(i,"config.options_query_id");if(!c)return;l.some(u=>i.visibleInViewsIDSet.has(u))&&a.push(c)}),this.findByIDSet(new Set(a)).forEach(i=>{const c=i.config;!i.isTransform||c.dep_query_ids.length===0||a.push(...c.dep_query_ids)});const o=new Set(a);return console.debug("QueryIDs:",o),o},isQueryInUse(t){return this.visibleQueryIDSet.has(t)},addTransformDepQueryIDs(t,r){this.findByIDSet(t).forEach(a=>{const l=a.config;!a.isTransform||l.dep_query_ids.length===0||l.dep_query_ids.forEach(o=>{r!=null&&r.has(o)||t.add(o)})})},get querisToForceReload(){const t=new Set,r=new Set,{views:a,filters:l}=this.contentModel,o=y.uniq(a.visibleViews.map(i=>i.renderViewIDs).flat());return l.current.forEach(i=>{const c=y.get(i,"config.options_query_id");if(!c)return;o.some(u=>i.visibleInViewsIDSet.has(u))&&t.add(c)}),this.addTransformDepQueryIDs(t),a.visibleViews.forEach(i=>{i.panels.forEach(c=>{c.queryIDs.forEach(d=>{t.has(d)||r.add(d)})})}),this.addTransformDepQueryIDs(r,t),{filterQueries:this.findByIDSet(t),panelQueries:this.findByIDSet(r)}}})).actions(e=>({downloadAllData(){const t=e.current.map(({name:r,data:a})=>({id:r,data:a}));vi(e.dashboardName,t)},downloadDataByQueryIDs(t,r){if(r.length===1)return this.downloadDataByQueryID(t,r[0]);const a=new Set(r),l=e.current.filter(o=>a.has(o.id)).map(({name:o,data:i})=>({id:o,data:i}));vi(t,l)},downloadDataByQueryID(t,r){const a=e.findByID(r);if(!a){console.log("[downloadDataByQueryID] query not found");return}const{data:l}=a,o=t??a.name;yi(o,l)},refetchDataByQueryID(t){const r=e.findByID(t);if(!r){console.error(new Error(`[downloadDataByQueryID] query by ID[${t}] not found`));return}return r.fetchData(!0)},getSchema(t){return{definition:{queries:e.findByIDSet(new Set(t)).map(l=>l.json)},version:at}},downloadSchema(t){const r=JSON.stringify(this.getSchema(t),null,2);Bt("Queries",r)},forceReloadVisibleQueries:g.flow(function*(){const{filterQueries:t,panelQueries:r}=e.querisToForceReload;if(console.log("🟡 Force reloading queries"),t.length>0){const a=yield Promise.allSettled(t.map(l=>l.fetchData(!0)));console.log("🟡 Queries from filters reloaded",a)}else console.log("🟡 Found no query from visible filters, skipping");if(r.length>0){const a=yield Promise.allSettled(r.map(l=>l.fetchData(!0)));console.log("🟡 Queries from filters reloaded",a)}else console.log("🟡 Found no query from visible panels, skipping")})}));function ki(e){return{current:e}}function zi({min:e,max:t}){const r=`${e}px`,a=Number.isFinite(t)?`${t}px`:"∞";return`[${r}, ${a})`}const ka=g.types.model("LayoutsRenderModel",{list:g.types.array(Qo),currentBreakpoint:g.types.string}).views(e=>({get json(){return e.list.map(t=>t.json)},jsonByPanelIDSet(t){return e.list.map(r=>r.jsonByPanelIDSet(t))},get root(){return g.getRoot(e)},get contentModel(){return this.root.content},get basisLayoutSet(){return e.list.find(t=>t.id==="basis")},get currentLayoutSet(){return e.list.find(t=>t.id===e.currentBreakpoint)},get currentLayoutRange(){return this.breakpointRanges.find(t=>t.id===e.currentBreakpoint)},get currentRangeText(){const t=this.currentLayoutRange;return zi(t)},get cols(){const t={};return e.list.forEach(r=>{t[r.id]=36}),t},get breakpoints(){const t={};return e.list.forEach(r=>{t[r.id]=r.breakpoint}),t},get breakpointNameRecord(){const t={};return e.list.forEach(r=>{t[r.name]=r.breakpoint}),t},get breakpointRanges(){const t=e.list.map(r=>({id:r.id,name:r.name,min:r.breakpoint,max:1/0,text:""}));return t.sort((r,a)=>r.min-a.min).forEach((r,a)=>{a!==t.length-1&&(r.max=t[a+1].min)}),t.forEach(r=>{r.text=zi(r)}),t},get breakpointsInfo(){return e.list.map(t=>({id:t.id,name:t.name,breakpoint:t.breakpoint})).sort((t,r)=>t.breakpoint-r.breakpoint)},get currentBreakpointRange(){return this.breakpointRanges.find(t=>t.id===e.currentBreakpoint)},get currentLayoutPreviewWidth(){const t=this.currentBreakpointRange;if(t)return t.max===1/0?t.min===0?void 0:t.min+1:t.max},items(t){const r=new Set(t);return this.currentLayoutSet.list.filter(l=>r.has(l.panelID))},gridLayouts(t){const r=new Set(t),a={};return e.list.forEach(l=>{a[l.id]=l.list.filter(o=>r.has(o.panelID)).map(o=>o.layoutProperies)}),a},findItemByPanelID(t){return this.currentLayoutSet.findByPanelID(t)}})).actions(e=>({setCurrentBreakpoint(t){console.log("🔴 onBreakpointChange:",t),e.currentBreakpoint=t},afterCreate(){g.addDisposer(e,Q.reaction(()=>e.currentBreakpoint,()=>{setTimeout(()=>{window.dispatchEvent(new Event("resize"))},32)},{fireImmediately:!1,delay:0}))}})),Di=Wo.views(e=>({isADuplicatedKey(t){return!t||t===e.key?!1:!!g.getParent(e,2).findByKey(t)}})),za=g.types.model("SQLSnippetsRenderModel",{current:g.types.optional(g.types.array(Di),[])}).views(e=>({get json(){return e.current.map(t=>t.json)},get record(){return e.current.reduce((t,r)=>(t[r.key]=r.value,t),{})},get keySet(){return new Set(e.current.map(t=>t.key))},get firstKey(){if(e.current.length!==0)return e.current[0].key},findByKey(t){return e.current.find(r=>r.key===t)},findByKeySet(t){return e.current.filter(r=>t.has(r.key))}})).actions(e=>({getSchema(t){return{definition:{sqlSnippets:e.findByKeySet(new Set(t)).map(l=>l.json)},version:at}},downloadSchema(t){const r=JSON.stringify(this.getSchema(t),null,2);Bt("SQL Snippets",r)}}));function Ii(e){return{current:e}}function Ut(e,t,r,a){return e.reduce((l,o)=>{try{l[o[t]]=lr(o[r],a)}catch(i){l[o[t]]=i.message}return l},{})}class Mi{constructor(t){P(this,"origin");P(this,"copy");this.origin=t,this.copy=g.clone(t),Q.makeAutoObservable(this,{},{autoBind:!0,deep:!1})}get changed(){return!y.isEqual(g.getSnapshot(this.origin),g.getSnapshot(this.copy))}commit(){g.applySnapshot(this.origin,g.getSnapshot(this.copy))}reset(){g.applySnapshot(this.copy,g.getSnapshot(this.origin))}update(t){g.applySnapshot(this.copy,t)}}const Ai=e=>new Mi(e),ZS=({description:e,isDescriptionEmpty:t})=>t?null:n.jsx(s.Tooltip,{color:"white",label:n.jsx(Dt,{value:e,styles:{root:{border:"none"},content:{padding:0}}}),styles:{tooltip:{border:"0.0625rem solid rgb(233, 236, 239)",boxShadow:"rgb(0 0 0 / 5%) 0px 0.0625rem 0.1875rem, rgb(0 0 0 / 5%) 0px 1.25rem 1.5625rem -0.3125rem, rgb(0 0 0 / 4%) 0px 0.625rem 0.625rem -0.3125rem"}},withArrow:!0,children:n.jsx(s.Box,{sx:{height:"16px",alignSelf:"center"},children:n.jsx(S.IconInfoCircle,{size:16,color:"gray"})})}),JS=T.observer(({label:e,config:{default_value:t,description:r,isDescriptionEmpty:a,...l},value:o,onChange:i})=>n.jsxs(s.Box,{children:[n.jsx(s.Text,{size:"sm",children:" "}),n.jsx(s.Checkbox,{label:n.jsxs(s.Group,{wrap:"nowrap",justify:"space-between",align:"middle",gap:6,children:[n.jsx(s.Box,{sx:{flexGrow:1},children:e}),n.jsx(ZS,{description:r,isDescriptionEmpty:a})]}),checked:o||!1,onChange:c=>i(c.currentTarget.checked),...l,pt:".4em",styles:{input:{borderColor:"#e9ecef"}}})]})),HS=({value:e,onChange:t,close:r,max_days:a,allowSingleDateInRange:l})=>{const o=e.value,[i,c]=o,d=h.useMemo(()=>i||new Date,[i]),u=h.useMemo(()=>{if(i&&!c)return i},[i,c]),p=h.useMemo(()=>{if(i&&!c&&a>0)return M(i).add(a-1,"days").toDate()},[i,c,a]),f=v=>{const[_,w]=v;t({value:v,shortcut:null}),_&&w&&r()};return n.jsx(ps.DatePicker,{defaultDate:d,numberOfColumns:2,type:"range",value:o,onChange:f,onNextMonth:console.log,minDate:u,maxDate:p,allowSingleDateInRange:l})},RS=({begin:e,end:t})=>{const{t:r}=x.useTranslation(),a=h.useMemo(()=>!t&&!e?Number.NaN:M(t).diff(M(e),"days")+1,[e,t]);if(Number.isNaN(a))return n.jsx("span",{style:{userSelect:"none",opacity:0,visibility:"hidden"},children:"."});const l=a===1?r("filter.widget.date_range.one_day"):r("filter.widget.date_range.x_days",{count:a});return n.jsx(s.Tooltip,{label:l,children:n.jsx(s.Badge,{size:"sm",variant:"light",children:a})})},eT=({max_days:e})=>{const{t}=x.useTranslation();return e?n.jsxs(n.Fragment,{children:[n.jsx(s.Group,{justify:"flex-end",children:n.jsx(s.Badge,{size:"xs",variant:"light",children:t("filter.widget.date_range.x_max_days",{max_days:e})})}),n.jsx(s.Divider,{variant:"dashed",my:10})]}):null},tT=({onChange:e})=>{const{t,i18n:r}=x.useTranslation(),a=i=>()=>{const c=i();e(c)},l=h.useMemo(()=>Ko(),[]),o=r.language==="zh";return n.jsxs(n.Fragment,{children:[n.jsx(s.Divider,{variant:"dashed",my:10}),n.jsx(s.Table,{withTableBorder:!1,sx:{"tbody > tr":{border:"none"},"tbody > tr > th, tbody > tr > td":{borderTop:"none",padding:"2px 6px"},"tbody > tr > th":{cursor:"default",userSelect:"none"},td:{paddingLeft:"1px"}},children:n.jsx(s.Table.Tbody,{children:Object.entries(l).map(([i,c])=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:n.jsx(s.Text,{size:"xs",c:"#555",fw:500,sx:{textAlignLast:"justify"},children:t(`filter.widget.date_range.shortcut.${i}.label`)})}),c.map(({key:d,value:u,getRange:p})=>n.jsx(s.Table.Td,{children:n.jsx(s.Button,{size:"compact-xs",variant:"subtle",onClick:a(p),children:t(`filter.widget.date_range.shortcut.${i}.${o?"full.":""}${d}`)})},d))]},i))})})]})},Pi=e=>({label:{display:"block",height:"21.7px"},input:{borderColor:e?"#228be6":"#e9ecef"}}),nT=({label:e,required:t,value:r,onChange:a,max_days:l,allowSingleDateInRange:o,inputFormat:i,disabled:c})=>{const{t:d}=x.useTranslation(),[u,{open:p,close:f}]=te.useDisclosure(!1),[v,_]=r.value,w=v?M(v).format(i):"",m=_?M(_).format(i):"";return n.jsxs(s.Popover,{opened:u,onClose:f,position:"bottom-start",shadow:"md",children:[n.jsxs(s.Group,{justify:"flex-start",grow:!0,wrap:"nowrap",gap:0,w:"288px",sx:{marginTop:"3px"},children:[n.jsx(s.Popover.Target,{children:n.jsx(s.TextInput,{label:e,labelProps:{title:e},required:t,leftSection:n.jsx(S.IconCalendar,{size:16}),placeholder:d("filter.widget.date_range.start_date"),readOnly:!0,disabled:c,value:w,onFocus:p,styles:Pi(u),sx:{".mantine-TextInput-label":{textOverflow:"ellipsis",overflow:"hidden",whiteSpace:"nowrap",width:"calc(240px)",position:"relative",zIndex:1},".mantine-Input-input":{borderRight:"none",borderTopRightRadius:0,borderBottomRightRadius:0},".mantine-Input-input[data-disabled]":{backgroundColor:"transparent",backgroundImage:"linear-gradient(to left, #fff 0%, #f1f3f5 30%)",opacity:1},".mantine-Input-input[data-disabled]::placeholder":{opacity:.6}}})}),n.jsx(s.TextInput,{label:n.jsx(s.Group,{justify:"flex-end",children:n.jsx(RS,{begin:v,end:_})}),leftSection:n.jsx(S.IconMinus,{size:16}),placeholder:d("filter.widget.date_range.end_date"),readOnly:!0,disabled:!v||c,value:m,onFocus:p,styles:Pi(u),sx:{".mantine-Input-section":{transform:"translateX(-18px)"},".mantine-Input-input":{borderLeft:"none",borderTopLeftRadius:0,borderBottomLeftRadius:0},".mantine-Input-input[data-disabled]":{backgroundColor:"transparent",backgroundImage:"linear-gradient(to right, #fff 0%, #f1f3f5 30%)",opacity:1},".mantine-Input-input[data-disabled]::placeholder":{opacity:.6}}})]}),n.jsxs(s.Popover.Dropdown,{p:"sm",children:[n.jsx(eT,{max_days:l}),n.jsx(HS,{value:r,onChange:a,close:f,allowSingleDateInRange:o,max_days:l}),n.jsx(tT,{onChange:a})]})]})},Vi={value:[null,null],shortcut:null},$i=e=>{const t=ea(e.shortcut);return t||(Array.isArray(e.value)?e:Vi)},rT=e=>h.useMemo(()=>$i(e),[e]),Ei=T.observer(({label:e,config:t,value:r=Vi,onChange:a,disabled:l})=>{const{inputFormat:o,required:i,max_days:c,allowSingleDateInRange:d}=t,u=rT(r);return n.jsx(nT,{label:e,value:u,onChange:a,inputFormat:o,allowSingleDateInRange:d,max_days:c,required:i,disabled:l})}),aT=dt.createStyles((e,{radius:t=4,name:r,...a})=>({root:{borderRadius:s.getRadius(t),display:"flex",flexWrap:"nowrap",border:"1px solid #ced4da",paddingLeft:"0px",paddingRight:"30px",backgroundColor:"#fff",transition:"border-color 100ms ease",borderColor:"#e9ecef",...a,"&.rc-select.rc-select-open":{borderColor:"#228be6 !important",".rc-select-selection-overflow-item-rest":{display:"none"},".rc-select-selection-overflow-item-suffix":{display:"block"}},".rc-select-selector":{height:"auto",lineHeight:1.55,paddingLeft:"12px",resize:"none",boxSizing:"border-box",fontSize:"14px",width:"100%",color:"#000",display:"block",textAlign:"left",minHeight:"36px",cursor:"pointer",flexGrow:1},".rc-select-selection-search-mirror":{display:"none"},".rc-select-selection-search":{flexGrow:1,width:"auto !important"},".rc-select-selection-overflow":{display:"flex",minHeight:"34px",alignItems:"center",flexWrap:"nowrap",marginLeft:"calc(-10px / 2)",boxSizing:"border-box"},".rc-select-selection-overflow-item":{display:"flex",alignItems:"center",backgroundColor:"#f1f3f5",color:"#495057",height:"24px",paddingLeft:"12px",paddingRight:"12px",fontWeight:500,fontSize:"12px",borderRadius:"4px",cursor:"default",userSelect:"none",maxWidth:"calc(100% - 20px)",margin:"calc(10px / 2 - 2px) calc(10px / 2)"},".rc-select-selection-overflow-item-rest":{cursor:"pointer"},".rc-select-selection-overflow-item-suffix":{display:"none",backgroundColor:"transparent",width:"100%",maxWidth:"100%",height:"28px",margin:0,paddingLeft:0,paddingRight:0},input:{flex:1,minWidth:"60px",backgroundColor:"transparent",border:0,outline:0,fontSize:"14px",padding:0,marginLeft:0,color:"inherit",height:"28px",lineHeight:"32px",cursor:"pointer",width:"100%","&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration":{display:"none"}},".rc-select-clear":{marginRight:"-24px",alignSelf:"center",cursor:"pointer"},"&.rc-select-disabled":{backgroundColor:"rgb(241, 243, 245)",color:"rgb(144, 146, 150)",opacity:.6,"&, .rc-select-selector, input":{cursor:"not-allowed"}}},label:{fontSize:e.fontSizes.sm,fontWeight:500,color:"#212529"},required:{color:"#fa5252",paddingLeft:"3px"},dropdown:{fontSize:e.fontSizes.xs,zIndex:300,backgroundColor:"#fff",border:"1px solid #e9ecef",marginTop:6,padding:0,boxShadow:"0 1px 3px rgb(0 0 0 / 5%), rgb(0 0 0 / 5%) 0px 10px 15px -5px, rgb(0 0 0 / 4%) 0px 7px 7px -5px",borderRadius:"4px","&.rc-select-dropdown-slide-up-leave-active":{display:"none"},".rc-select-item-empty":{padding:"8px 12px"},".rc-select-item-option":{boxSizing:"border-box",textAlign:"left",width:"100%",padding:"8px 12px 8px 2px",cursor:"pointer",fontSize:"14px",color:"#000",borderRadius:"4px",display:"flex",flexWrap:"nowrap",overflow:"hidden","&:hover":{backgroundColor:"#f1f3f5"},flexDirection:"row-reverse",".rc-select-item-option-state":{flexGrow:0,flexShrink:0,width:"30px",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},".rc-select-item-option-content":{width:"calc(100% - 30px)",overflow:"hidden",'div[data-role="label"]':{overflowWrap:"break-word"}},".rc-select-item-option-state-icon":{lineHeight:"20px"}},".rc-virtual-list-holder-inner":{alignItems:"flex-start"}}})),sT={root:{cursor:"pointer","&:hover":{backgroundColor:"var(--mantine-color-default-hover)"},"input, .mantine-Checkbox-labelWrapper":{cursor:"pointer",pointerEvents:"none"}}},lT=({disabled:e,radius:t,style:r,label:a,value:l,onChange:o,options:i,errorMessage:c,required:d})=>{const{t:u}=x.useTranslation(),{classes:p,cx:f}=aT({radius:t,name:"MultiSelectWidget"}),[v,_]=h.useState(!1),w=N=>{_(N)},m=v&&(l==null?void 0:l.length)>0,[k,z]=h.useState(""),D=h.useMemo(()=>{if(!k)return i;const N=k.toLowerCase(),oe=me=>{var lt;return((lt=me.description)==null?void 0:lt.toLowerCase().includes(N))||me.label.toLowerCase().includes(N)};return i.filter(oe)},[k,i]),I=h.useMemo(()=>new Set(i.map(N=>N.value)),[i]),L=h.useMemo(()=>new Set(l),[l]),E=h.useMemo(()=>L.size!==I.size?!1:Array.from(I).every(N=>L.has(N)),[L,I]),K=()=>{if(E){o([]);return}const N=Array.from(I);o(N)};return n.jsxs(s.Stack,{gap:3,children:[n.jsxs(s.Group,{justify:"space-between",children:[n.jsxs(s.Text,{className:p.label,size:"sm",children:[a,d&&n.jsx("span",{className:p.required,"aria-hidden":"true",children:"*"})]}),m&&n.jsx(s.Tooltip,{label:u("filter.widget.common.x_selected",{count:l.length}),children:n.jsx(s.Badge,{variant:"light",children:l.length})})]}),n.jsx(ys,{disabled:e,allowClear:!0,className:f(p.root,"check-select"),dropdownClassName:f(p.dropdown,""),onDropdownVisibleChange:w,transitionName:"rc-select-dropdown-slide-up",choiceTransitionName:"rc-select-selection__choice-zoom",style:r,clearIcon:()=>n.jsx(s.CloseButton,{size:"sm"}),value:l,onChange:o,onSelect:console.log,mode:"multiple",maxTagCount:0,notFoundContent:n.jsx(ia,{errorMessage:c}),maxTagTextLength:10,maxTagPlaceholder:N=>u("filter.widget.common.x_selected",{count:N.length}),searchValue:k,onSearch:z,filterOption:!1,dropdownRender:N=>n.jsxs(n.Fragment,{children:[I.size>0&&!k&&n.jsx(s.Group,{px:"xs",py:"xs",onClick:K,styles:sT,children:n.jsx(s.Checkbox,{size:"xs",checked:E,onChange:y.noop,label:u("common.actions.select_all")})}),n.jsx(s.Divider,{}),N]}),children:D.map(N=>n.jsxs(ys.Option,{title:N.label,children:[n.jsx(s.Text,{size:"sm","data-role":"label",children:N.label}),N.description&&n.jsx(s.Text,{size:"xs",c:"dimmed","data-role":"description",children:N.description})]},N.value))})]})},oT=T.observer(({label:e,config:t,value:r,onChange:a})=>{const l=J(),o=!!t.options_query_id,{state:i,error:c}=l.getDataStuffByID(t.options_query_id),d=i==="loading",u=t.min_width?t.min_width:"200px",p=o?d:!1,f=h.useMemo(()=>t.initialSelection(r),[r,t.initialSelection]),v=_=>a(_,!1);return n.jsx(lT,{label:e,options:t.options,style:{minWidth:"160px",width:u,maxWidth:p?u:"unset",borderColor:"#e9ecef"},disabled:p,value:[...f],onChange:v,errorMessage:c,required:t.required})}),iT=({option:e,...t})=>{const{label:r,description:a}=e;return n.jsx("div",{...t,children:n.jsx(s.Group,{wrap:"nowrap",children:n.jsxs("div",{children:[n.jsx(s.Text,{size:"sm","data-role":"label",children:r}),n.jsx(s.Text,{size:"xs",c:"dimmed","data-role":"description",children:a})]})})})},cT=T.observer(({label:e,config:t,value:r,onChange:a})=>{const{t:l}=x.useTranslation(),o=J(),i=!!t.options_query_id,{state:c,error:d}=o.getDataStuffByID(t.options_query_id),u=c==="loading",p=h.useCallback((f,v)=>{f&&a(f,!1)},[a]);return n.jsx(s.Select,{label:e,data:t.options,disabled:i?u:!1,value:r,onChange:p,maxDropdownHeight:500,styles:{root:{width:t.width?t.width:"200px"},input:{borderColor:"#e9ecef"}},sx:{".mantine-Select-item[data-selected] .mantine-Text-root[data-role=description]":{color:"rgba(255,255,255,.7)"},".mantine-Select-nothingFound":{fontSize:"0.75rem",textAlign:"left",padding:"4px 10px"}},renderOption:iT,searchable:!d,nothingFoundMessage:d||l("filter.widget.common.selector_option_empty"),clearable:t.clearable})});function dT({label:e,config:t,value:r,onChange:a}){return n.jsx(s.TextInput,{label:e,value:r||"",onChange:l=>a(l.currentTarget.value),...t,styles:{input:{borderColor:"#e9ecef"}}})}const uT=T.observer(({filter:{type:e,config:t,key:r,...a},formFieldProps:l})=>{switch(e){case V.Select:return n.jsx(cT,{...a,...l,config:t});case V.MultiSelect:return n.jsx(oT,{...a,...l,config:t});case V.TreeSelect:return n.jsx($S,{...a,...l,config:t});case V.TreeSingleSelect:return n.jsx(qS,{...a,...l,config:t});case V.TextInput:return n.jsx(dT,{...a,...l,config:t});case V.DateRange:return n.jsx(Ei,{...a,...l,config:t});case V.Checkbox:return n.jsx(JS,{...a,...l,config:t});default:return null}}),pT=T.observer(h.forwardRef(({filter:e,...t},r)=>n.jsx("div",{className:"filter-root",ref:r,children:n.jsx(ne,{children:n.jsx(uT,{filter:e,formFieldProps:t})})}))),hT=({disabled:e,onSubmit:t})=>{const{t:r}=x.useTranslation(),{renderSearchButton:a}=Ds();return a?a({disabled:e,onSubmit:t}):n.jsxs(s.Button.Group,{children:[n.jsx(s.Button,{color:"blue",size:"sm",onClick:()=>t(),disabled:e,children:r("common.actions.search")}),n.jsxs(s.Menu,{trigger:"hover",disabled:e,position:"bottom-end",children:[n.jsx(s.Menu.Target,{children:n.jsx(s.Button,{disabled:e,color:"blue",px:"xs",style:{borderLeft:`1px solid ${e?"white":"var(--mantine-color-gray-4)"}`},children:n.jsx(S.IconChevronDown,{size:16})})}),n.jsx(s.Menu.Dropdown,{children:n.jsx(s.Menu.Item,{leftSection:n.jsx(S.IconRefresh,{size:14}),disabled:e,onClick:()=>t({force:!0}),children:r("common.actions.reload")})})]})]})};function gT(e){const t=F();h.useEffect(()=>{var r,a;(a=(r=t.filters).updatePreviewValues)==null||a.call(r,e)},[e])}const Bi="N/A";function fT(){const e=Nt(),t=e.content.views.visibleViews;return h.useMemo(()=>t.map(l=>{var o;return l.type===$.Tabs?(o=l.tabView)==null?void 0:o.view_id:l.id}).filter(Boolean).flatMap(l=>e.content.filters.visibleInView(l)).filter(Boolean).map(l=>bT(l)),[t])}function bT(e){switch(e.type){case V.Select:case V.MultiSelect:case V.TreeSelect:case V.TreeSingleSelect:return{label:e.label,value:yT(e.config,e.value)};case V.TextInput:return{label:e.label,value:e.value};case V.DateRange:return{label:e.label,value:vT(e.config,e.value)};case V.Checkbox:return{label:e.label,value:_T(e.value)};default:return{label:e.label,value:e.value}}}function yT(e,t){const r=new Set;return Array.isArray(t)?t.forEach(a=>r.add(a)):r.add(t),r.size===0?Bi:e.options.filter(a=>r.has(a.value)).map(a=>a.label).join(", ")}function L5(e){return e}function vT(e,t){const a=$i(t).value.filter(l=>!!l).map(l=>M(l).format(e.inputFormat));return a.length===0?Bi:a.join(" - ")}function _T(e){return e?"✔️":"❌"}const xT=({opened:e,toggle:t})=>{const{t:r}=x.useTranslation();return n.jsx(s.Group,{justify:"flex-end",ml:-4,mt:-4,mb:e?4:0,children:n.jsx(s.Button,{size:"compact-xs",variant:"subtle",color:e?"gray":"blue",leftSection:e?n.jsx(S.IconChevronsUp,{size:14}):n.jsx(S.IconChevronsDown,{size:14}),onClick:t,children:r(e?"filter.hide_filters":"filter.show_filters")})})},Li=T.observer(function({view:t}){const[r,{toggle:a}]=te.useDisclosure(!0),l=J(),{control:o,handleSubmit:i,reset:c}=b.useForm({defaultValues:l.filters.values,reValidateMode:"onBlur"}),d=b.useWatch({control:o});h.useEffect(()=>{c(l.filters.values)},[l.filters.values,c]),gT(d);const u=l.filters.visibleInView(t.id),p=h.useMemo(()=>u.every(m=>m.should_auto_submit),[u]),f=h.useMemo(()=>u.filter(m=>y.get(m,"config.required",!1)),[u]),v=h.useMemo(()=>f.length===0?!1:f.some(m=>!m.requiredAndPass(d[m.key])),[d,f]),_=(m,k)=>(z,D)=>{k(z),(m.should_auto_submit||D)&&l.filters.setValueByKey(m.key,z)},w=h.useCallback(m=>{const k=y.get(m,"force",!1);i(l.filters.setValues)(),k&&l.queries.forceReloadVisibleQueries()},[i,l.filters.setValues]);return u.length===0?null:n.jsxs("form",{children:[n.jsx(xT,{opened:r,toggle:a}),n.jsx(s.Collapse,{in:r,children:n.jsxs(s.Group,{className:"dashboard-filters",justify:"space-between",wrap:"nowrap",sx:p?{}:{border:"1px solid #e9ecef",borderRadius:"4px",padding:"16px"},children:[n.jsx(s.Group,{align:"flex-start",children:u.map(m=>n.jsx(b.Controller,{name:m.key,control:o,render:({field:k})=>n.jsx(pT,{filter:m,value:k.value,onChange:_(m,k.onChange)})},m.id))}),!p&&n.jsx(s.Group,{sx:{alignSelf:"flex-end"},children:n.jsx(hT,{disabled:v,onSubmit:w})})]})})]})}),wT={viewPanelInFullScreen:y.noop,inFullScreen:!1},kn=h.createContext(wT),mT=T.observer(({view:e})=>{const{t}=x.useTranslation(),r=W(),{panel:a}=re(),l=a.realQueryOptions,o=c=>{r.editor.open(["_QUERIES_",c])},i=()=>{r.editor.open(["_VIEWS_",e.id,"_PANELS_",a.id,"_TABS_","Data"])};return l.length===0?null:n.jsxs(n.Fragment,{children:[n.jsx(s.Divider,{label:t(l.length>1?"query.labels":"query.label"),labelPosition:"center"}),n.jsx(s.Menu.Item,{onClick:i,leftSection:n.jsx(S.IconDatabase,{size:14}),children:t("data.label")}),l.map(c=>n.jsx(s.Menu.Item,{onClick:()=>o(c.value),leftSection:n.jsx(S.IconDatabase,{size:14}),children:c.label},c.value))]})}),CT=T.observer(({view:e,title:t})=>{const{t:r}=x.useTranslation(),a=W(),l=F(),o=ze.useModals(),{panel:i,downloadPanelScreenshot:c}=re(),{id:d}=i,{viewPanelInFullScreen:u,inFullScreen:p}=h.useContext(kn),f=()=>{l.duplicatePanelByID(d,e.id)},v=()=>{a.editor.open(["_VIEWS_",e.id,"_PANELS_",d,"_TABS_","Panel"])},_=()=>{a.editor.open(["_VIEWS_",e.id,"_PANELS_",d,"_TABS_","Variables"])},w=()=>{a.editor.open(["_VIEWS_",e.id,"_PANELS_",d,"_TABS_","Visualization"])},m=()=>{a.editor.open(["_VIEWS_",e.id,"_PANELS_",d,"_TABS_","Interactions"])},k=()=>o.openConfirmModal({title:`${r("panel.delete")}?`,labels:{confirm:r("common.actions.confirm"),cancel:r("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>l.removePanelByID(d,e.id),confirmProps:{color:"red"},zIndex:320}),z=h.useCallback(()=>{u(d)},[d,u]),D=!p&&e.type!==$.Modal;return n.jsx(n.Fragment,{children:n.jsx(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},title:t,children:n.jsxs(s.Menu,{withinPortal:!0,children:[n.jsx(s.Menu.Target,{children:n.jsx(s.Box,{className:"panel-dropdown-target",sx:{width:"100%"}})}),n.jsxs(s.Menu.Dropdown,{children:[n.jsx(s.Menu.Item,{onClick:i.refreshData,leftSection:n.jsx(S.IconRefresh,{size:14}),children:r("common.actions.refresh")}),n.jsx(s.Menu.Item,{onClick:i.downloadData,leftSection:n.jsx(S.IconDownload,{size:14}),children:r("common.actions.download_data")}),n.jsx(s.Menu.Item,{onClick:i.downloadSchema,leftSection:n.jsx(S.IconCode,{size:14}),children:r("common.actions.download_schema")}),n.jsx(s.Menu.Item,{onClick:c,leftSection:n.jsx(S.IconCamera,{size:14}),children:r("common.actions.download_screenshot")}),D&&n.jsx(s.Menu.Item,{onClick:z,leftSection:n.jsx(S.IconArrowsMaximize,{size:14}),disabled:!0,children:r("common.actions.enter_fullscreen")}),n.jsx(mT,{view:e}),n.jsx(s.Divider,{label:r("common.actions.edit"),labelPosition:"center"}),n.jsx(s.Menu.Item,{onClick:v,leftSection:n.jsx(S.IconAppWindow,{size:14}),children:r("panel.label")}),n.jsx(s.Menu.Item,{onClick:_,leftSection:n.jsx(S.IconVariable,{size:14}),children:r("panel.variable.labels")}),n.jsx(s.Menu.Item,{onClick:w,leftSection:n.jsx(S.IconChartHistogram,{size:14}),children:r("visualization.label")}),n.jsx(s.Menu.Item,{onClick:m,leftSection:n.jsx(S.IconRoute,{size:14}),children:r("interactions.label")}),n.jsx(s.Divider,{label:r("common.actions.actions"),labelPosition:"center"}),n.jsx(s.Menu.Item,{onClick:f,leftSection:n.jsx(S.IconCopy,{size:14}),children:r("common.actions.duplicate")}),n.jsx(s.Menu.Item,{color:"red",onClick:k,leftSection:n.jsx(S.IconTrash,{size:14}),children:r("common.actions.delete")})]})]})})})});function ST(e){return e?["<p><br></p>","<p></p>"].includes(e):!0}const TT=T.observer(()=>{const e=J(),{panel:t}=be(),r=h.useMemo(()=>ht(t.description,t.json.variables,e.payloadForViz,t.data),[t.data,t.description,t.json.variables,e.payloadForViz]);return n.jsx(Dt,{value:r,styles:{root:{border:"none"},content:{padding:0}},sx:{".mantine-RichTextEditor-content .ProseMirror":{padding:"0 !important"}},dashboardStateValues:e.dashboardStateValues,variableAggValueMap:t.variableAggValueMap})}),Da=T.observer(()=>{const{t:e}=x.useTranslation(),[t,r]=h.useState(!1),{panel:a}=be();return ST(a.description)?null:n.jsxs(n.Fragment,{children:[n.jsx(s.Modal,{opened:t,onClose:()=>r(!1),title:a.title.show?a.name:"",withCloseButton:!1,withinPortal:!0,zIndex:310,children:n.jsx(TT,{})}),n.jsx(s.Tooltip,{label:e("panel.panel_description_click"),position:"top-start",withinPortal:!0,children:n.jsx(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>r(l=>!l),sx:{verticalAlign:"baseline",cursor:"pointer"},children:n.jsx(S.IconInfoCircle,{size:20})})})]})}),q5="",kT=T.observer(function(){const{panel:t}=be(),{name:r,title:a}=t;return a.show?n.jsx(s.Group,{grow:!0,justify:"center",className:"panel-title-wrapper",sx:{flexGrow:1},children:n.jsx(s.Text,{size:"sm",ta:"center",lineClamp:1,className:"panel-title-text",children:r})}):null});function zT(e){const t=h.useRef(null);return{ref:t,downloadPanelScreenshot:()=>{const a=t.current;if(!a)return;const l=a.offsetWidth*2,o=a.offsetHeight*2;gs.toBlob(t.current,{bgcolor:"white",width:l,height:o,style:{border:"none",borderRadius:0,transformOrigin:"0 0",transform:"scale(2)"}}).then(i=>{window.saveAs(i,`${e.name?e.name:e.viz.type}.png`)})}}}var qi=(e=>(e.migrated="migrated",e.nothingToMigrate="nothingToMigrate",e.checkFailed="checkFailed",e.migrationFailed="migrationFailed",e))(qi||{}),zn=(e=>(e.notStarted="notStarted",e.inProgress="inProgress",e.done="done",e))(zn||{});class DT{constructor(t){P(this,"vizInstance");P(this,"operationManager");P(this,"triggerManager");P(this,"vizManager");P(this,"runningMigration");P(this,"panelModel");P(this,"status","notStarted");this.panelModel=t.getRequired(R.instanceScope.panelModel),this.vizInstance=t.getRequired(R.instanceScope.vizInstance),this.operationManager=t.getRequired(R.instanceScope.operationManager),this.triggerManager=t.getRequired(R.instanceScope.triggerManager),this.vizManager=t.getRequired(R.vizManager)}async createMigrationTask(){const t=[];try{await this.instanceNeedMigration()&&t.push(()=>this.runInstanceMigration()),await this.interactionNeedMigration()&&t.push(()=>this.runInteractionMigration())}catch(r){return console.warn("check migration failed",r),"checkFailed"}if(t.length===0)return"nothingToMigrate";try{return await Promise.all(t.map(r=>r())),"migrated"}catch(r){return console.warn("migration failed",r),"migrationFailed"}}async runMigration(){return this.runningMigration||(this.status="inProgress",this.runningMigration=this.createMigrationTask().then(t=>(this.status="done",t))),this.runningMigration}async runInteractionMigration(){await this.operationManager.runMigration(),await this.triggerManager.runMigration()}async runInstanceMigration(){const t=this.vizManager.resolveComponent(this.vizInstance.type),r={configData:this.vizInstance.instanceData,panelModel:this.panelModel};await t.migrator.migrate(r)}async instanceNeedMigration(){const t=this.vizManager.resolveComponent(this.vizInstance.type),r={configData:this.vizInstance.instanceData};return t.migrator.needMigration(r)}async interactionNeedMigration(){return await this.operationManager.needMigration()||await this.triggerManager.needMigration()}}class IT{getTriggerSchemaList(){return[]}getTriggerList(){return Promise.resolve([])}removeTrigger(){return Promise.resolve()}createOrGetTrigger(){return Promise.resolve(Oi)}retrieveTrigger(){return Promise.resolve(Oi)}watchTriggerSnapshotList(){return()=>{}}needMigration(){return Promise.resolve(!1)}runMigration(){return Promise.resolve()}}class MT{constructor(){P(this,"id","");P(this,"schemaRef","");P(this,"triggerData",new Jt({}))}}const Oi=new MT;class AT{getOperationSchemaList(){return[]}getOperationList(){return Promise.resolve([])}removeOperation(){return Promise.resolve()}createOrGetOperation(){return Promise.resolve(Ni)}runOperation(){return Promise.resolve()}retrieveTrigger(){return Promise.resolve(Ni)}runMigration(){return Promise.resolve()}needMigration(){return Promise.resolve(!1)}}class PT{constructor(){P(this,"id","");P(this,"schemaRef","");P(this,"operationData",new Jt({}))}}const Ni=new PT,Vn=class Vn{constructor(){P(this,"triggerManager",new IT);P(this,"operationManager",new AT)}getInteractionList(){return Promise.resolve([])}addInteraction(){return Promise.resolve()}removeInteraction(){return Promise.resolve()}runInteraction(){return Promise.resolve()}};P(Vn,"instance",new Vn);let Ia=Vn;function Gi(e,t=!0){const{panel:r}=be();return h.useCallback(a=>{const l=a.getRequired(R.vizManager),o=l.resolveComponent(e.viz.type);return a.createScoped().provideFactory(R.instanceScope.vizInstance,()=>l.getOrCreateInstance(e)).provideFactory(R.instanceScope.interactionManager,i=>{const c=i.getRequired(R.instanceScope.vizInstance);return t?new gl(c,o,pr):new Ia}).provideFactory(R.instanceScope.operationManager,i=>i.getRequired(R.instanceScope.interactionManager).operationManager).provideFactory(R.instanceScope.triggerManager,i=>i.getRequired(R.instanceScope.interactionManager).triggerManager).provideValue(R.instanceScope.panelModel,r).provideFactory(R.instanceScope.migrator,i=>new DT(i))},[e.viz.type,e.viz.conf,t])}const Fi={withInteraction:!0,withAddon:!0,withPanelTitle:!0},ji=h.createContext(Fi);function VT({children:e,...t}){const r=y.defaults({},t,Fi);return n.jsx(ji.Provider,{value:r,children:e})}function Ma(){return h.useContext(ji)}function Qi(e){const[t,r]=h.useState(!1),a=Qt().getRequired(R.instanceScope.migrator);return O.useAsyncEffect(async()=>{const l=a.status===zn.notStarted;r(a.status===zn.done),a.status===zn.notStarted&&a.runMigration().then(o=>{o===qi.migrated&&l&&(e==null||e())}).finally(()=>{r(!0)})},[a]),t}function Wi(e,t){const r=Qt().getRequired(R.instanceScope.vizInstance);return O.useAsyncEffect(async()=>{y.isEqual(await r.instanceData.getItem(null),t.viz.conf)||await r.instanceData.setItem(null,t.viz.conf)},[r,t.viz.conf]),h.useEffect(()=>r.instanceData.watchItem(null,a=>{e(a)}),[e,t.viz.type]),r}function $T({setVizConf:e,...t}){const{panel:r}=t,a=Wi(e,r),l=Qi(()=>{Ze.showNotification({title:`${r.name} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})});return O.useAsyncEffect(async()=>{await a.instanceData.setItem(null,r.viz.conf)},[a,r.viz.type]),l?n.jsx(Rd,{...t}):n.jsx(s.Text,{size:"sm",children:"Checking update..."})}function ET(e){const{panel:t,setVizConf:r}=e;Wi(r,t);const{inEditMode:a}=h.useContext(Gt);return Qi(()=>{a&&Ze.showNotification({title:`${t.name} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})})?n.jsx(Hd,{...e}):n.jsx(s.Text,{size:"sm",children:"Checking update"})}const O5="";function BT(e,t){const{vizManager:r}=h.useContext(rt),{panel:{viz:a,title:l,id:o,name:i,description:c,queryIDs:d,variables:u}}=be(),p={id:o,name:i,title:l,description:c,queryIDs:d,viz:a},{withInteraction:f}=Ma(),v=Gi(p,f);try{return r.resolveComponent(a.type),n.jsxs(ln,{configure:v,children:[n.jsx(ET,{setVizConf:a.setConf,panel:p,measure:t,data:e,variables:u,vizManager:r}),n.jsx(Yi,{})]})}catch(_){return console.info(y.get(_,"message")),null}}const Ui=T.observer(function({data:t}){const{ref:r,width:a,height:l}=te.useElementSize(),o=BT(t,{w:a,h:l}),i=a>0&&l>0;return n.jsx("div",{className:"viz-root",ref:r,children:n.jsx(s.Box,{sx:{width:a,height:l,overflow:"hidden"},children:i&&n.jsx(ne,{children:o})})})}),Yi=()=>{const e=Qt(),t=e.getRequired(R.instanceScope.vizInstance),{inEditMode:r}=h.useContext(Gt),a=e.getRequired(R.panelAddonManager),{withAddon:l}=Ma(),o=iu();return!o||!l?null:jd.createPortal(n.jsx(n.Fragment,{children:a.createPanelAddonNode({viz:t,isInEditMode:r})}),o,"addon")},Ki=T.observer(({panel:e})=>n.jsxs(s.Stack,{children:[e.queryErrors.map((t,r)=>n.jsx(s.Text,{c:"red",size:"sm",ta:"center",ff:"monospace",children:t},`${r}-${t}`)),n.jsx(s.Text,{c:"gray",ta:"center",size:"sm",children:e.queryStateMessages})]})),Aa=T.observer(({panel:e})=>n.jsxs(s.Flex,{className:"panel-viz-section",direction:"column",sx:{position:"relative",width:"100%"},children:[n.jsx(s.LoadingOverlay,{visible:e.dataLoading,transitionProps:{exitDuration:0}}),!e.canRenderViz&&n.jsx(Ki,{panel:e}),e.canRenderViz&&n.jsx(Ui,{data:e.data})]})),LT={border:"1px solid #e9ecef"},Pa=T.observer(({panel:e,panelStyle:t,dropdownContent:r})=>{const{ref:a,downloadPanelScreenshot:l}=zT(e),{withAddon:o,withPanelTitle:i}=Ma(),c=o?ms:h.Fragment;return n.jsx(Un,{value:{panel:e,data:e.data,loading:e.dataLoading,errors:e.queryErrors,downloadPanelScreenshot:l},children:n.jsx(s.Box,{id:e.id,className:`panel-root ${e.title.show?"panel-root--show-title":""}`,ref:a,p:0,sx:{...LT,...t},children:n.jsxs(c,{children:[i&&n.jsxs(n.Fragment,{children:[n.jsx(s.Box,{className:"panel-description-popover-wrapper",children:n.jsx(Da,{})}),r,n.jsx(kT,{})]}),n.jsx(Aa,{panel:e})]})})})}),qT={border:"1px dashed transparent",transition:"border-color 300ms ease","&:hover":{borderColor:"#e9ecef"}};function OT(e){return e.style.border.enabled?{}:qT}const Xi=T.observer(function({panel:t,view:r}){const a=OT(t);return n.jsx(Pa,{panel:t,panelStyle:a,dropdownContent:n.jsx(CT,{view:r,title:t.name})})});function NT(e){return!["richText","button","vizDashboardState"].includes(e)}const GT=T.observer(({view:e,title:t})=>{const{t:r}=x.useTranslation(),{panel:a,downloadPanelScreenshot:l}=be(),{id:o}=a,{viewPanelInFullScreen:i,inFullScreen:c}=h.useContext(kn),d=h.useCallback(()=>{i(o)},[o,i]),u=!c&&e.type!==$.Modal;return NT(a.viz.type)?n.jsx(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,zIndex:300},title:t,children:n.jsxs(s.Menu,{withinPortal:!0,children:[n.jsx(s.Menu.Target,{children:n.jsx(s.Box,{className:"panel-dropdown-target"})}),n.jsxs(s.Menu.Dropdown,{children:[n.jsx(s.Menu.Item,{onClick:a.refreshData,leftSection:n.jsx(S.IconRefresh,{size:14}),children:r("common.actions.refresh")}),n.jsx(s.Menu.Item,{onClick:a.downloadData,leftSection:n.jsx(S.IconDownload,{size:14}),children:r("common.actions.download_data")}),n.jsx(s.Menu.Item,{onClick:l,leftSection:n.jsx(S.IconCamera,{size:14}),children:r("common.actions.download_screenshot")}),u&&n.jsx(s.Menu.Item,{onClick:d,leftSection:n.jsx(S.IconArrowsMaximize,{size:14}),children:r("common.actions.enter_fullscreen")})]})]})}):null});function FT(e){return e.style.border.enabled?{}:{border:"1px dashed transparent"}}const Va=T.observer(({panel:e,view:t})=>{const r=FT(e);return n.jsx(Pa,{panel:e,panelStyle:r,dropdownContent:n.jsx(GT,{title:e.name,view:t})})}),jT={modal:{display:"flex",flexDirection:"column",flexWrap:"nowrap"},body:{display:"flex",height:"calc(100vh - 88px)"}},Zi=T.observer(function({view:t,panel:r,exitFullScreen:a}){return n.jsx(s.Modal,{opened:!0,fullScreen:!0,onClose:a,title:n.jsx(s.Button,{color:"blue",size:"xs",onClick:a,leftSection:n.jsx(S.IconArrowLeft,{size:20}),children:"Exit fullscreen"}),styles:jT,children:n.jsx(s.Group,{grow:!0,sx:{flexGrow:1,flexShrink:0},children:n.jsx(Va,{view:t,panel:r})})})});function Ji(e,t,r){const{panels:a}=J(),l=e.id==="Main",[o,i]=h.useState(()=>l&&a.findByID(t)?t:null),c=h.useCallback(f=>{i(f),l&&r(f)},[l,r]),d=h.useCallback(()=>{i(null),l&&r("")},[l,r]),u=o?a.findByID(o):null;return{viewPanelInFullScreen:c,exitFullScreen:d,inFullScreen:!!u,fullScreenPanel:u}}function QT(e){const t=Nt(),r=h.useMemo(()=>t.content.panels.findByID(e.panelId),[e.panelId]);return r?n.jsx(VT,{withAddon:!1,withPanelTitle:!1,withInteraction:!1,children:n.jsx(Pa,{panel:r,panelStyle:{}})}):null}const N5="",WT=h.forwardRef(({h:e},t)=>n.jsx(s.ActionIcon,{ref:t,className:"react-grid-customDragHandle",sx:{userSelect:"none",cursor:"grab",position:"absolute",top:5,right:e>38?5:20,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",children:n.jsx(S.IconArrowsMove,{size:16})})),UT=h.forwardRef(({handleAxis:e,...t},r)=>n.jsx(s.ActionIcon,{ref:r,className:"react-grid-customResizeHandle",sx:{userSelect:"none",cursor:"nwse-resize",position:"absolute",bottom:0,right:0,zIndex:400,"&:hover":{color:"#228be6"}},variant:"transparent",...t,children:n.jsx(S.IconChevronDownRight,{size:16})})),YT=Zt.WidthProvider(Zt.Responsive),KT=T.observer(({view:e,className:t="layout"})=>{const a=F().layouts,l=a.items(e.panelIDs),o=a.gridLayouts(e.panelIDs),i=(u,p,f,v)=>{f.h<30&&(f.h=30,v.h=30),f.w<4&&(f.w=4,v.w=4)},c=(u,p,f)=>{console.log("🔴 onResizeStop",{layouts:u,oldItem:p,newItem:f}),a.updateCurrentLayoutItem(f)},d=(u,p,f)=>{console.log("🔴 onDragStop",{layouts:u,oldItem:p,newItem:f}),a.updateCurrentLayoutItems(u)};return n.jsx(YT,{className:`dashboard-layout ${t}`,rowHeight:1,margin:[0,0],isBounded:!0,isDraggable:!0,isResizable:!0,cols:a.cols,layouts:o,draggableHandle:".react-grid-customDragHandle",resizeHandle:n.jsx(UT,{}),onResize:i,breakpoints:a.breakpoints,onBreakpointChange:a.setCurrentBreakpoint,onResizeStop:c,onDragStop:d,width:a.currentLayoutPreviewWidth,children:l.map(u=>n.jsxs("div",{"data-grid":u.layoutProperies,className:"panel-grid-item",children:[n.jsx(WT,{h:u.h}),n.jsx(Xi,{view:e,panel:u.panel})]},u.id))})}),XT=Zt.WidthProvider(Zt.Responsive),ZT=T.observer(({view:e,className:t="layout"})=>{const r=J(),a=r.layouts.items(e.panelIDs),l=r.layouts.gridLayouts(e.panelIDs);return n.jsx(XT,{className:`dashboard-layout ${t}`,rowHeight:1,margin:[0,0],isDraggable:!1,isResizable:!1,cols:r.layouts.cols,layouts:l,breakpoints:r.layouts.breakpoints,onBreakpointChange:r.layouts.setCurrentBreakpoint,children:a.map(o=>n.jsx("div",{"data-grid":o.layoutProperies,className:"panel-grid-item",children:n.jsx(Va,{view:e,panel:o.panel})},o.id))})});function $a(e){const t=h.useRef(null);return{ref:t,downloadScreenshot:()=>{var l;const a=(l=t.current)==null?void 0:l.querySelector(".react-grid-layout");a&&e.downloadScreenshot(a)}}}const JT=T.observer(({downloadScreenshot:e})=>{const{t}=x.useTranslation(),[r,{setTrue:a,setFalse:l}]=O.useBoolean(!1),o=ks(),i=J(),c=()=>{const d=JSON.stringify(i.contentJSON,null,2),u=`${o.name}__${i.name}`;Bt(u,d)};return n.jsxs(s.Menu,{shadow:"md",width:200,trigger:"hover",openDelay:200,closeDelay:400,withinPortal:!0,position:"bottom-end",children:[n.jsx(s.Menu.Target,{children:n.jsx(s.Affix,{position:{bottom:"20px",right:"10px"},zIndex:1,children:n.jsx(s.ActionIcon,{size:"md",variant:"gradient",gradient:{from:"indigo",to:"cyan"},onMouseEnter:a,onMouseLeave:l,sx:{opacity:r?1:.6,transform:`translateX(${r?0:"2px"})`,transition:"all ease 300ms",borderRadius:"50%"},children:n.jsx(S.IconShare3,{size:"1rem"})})})}),n.jsxs(s.Menu.Dropdown,{children:[n.jsx(s.Menu.Item,{leftSection:n.jsx(S.IconCamera,{size:14}),onClick:e,children:t("common.actions.download_screenshot")}),n.jsx(s.Menu.Divider,{}),n.jsx(s.Menu.Item,{leftSection:n.jsx(S.IconDownload,{size:14}),onClick:i.queries.downloadAllData,children:t("common.actions.download_data")}),n.jsx(s.Menu.Item,{leftSection:n.jsx(S.IconCode,{size:14}),onClick:c,children:t("common.actions.download_schema")})]})]})}),Hi=T.observer(({children:e,view:t,sx:r={}})=>{const{ref:a,downloadScreenshot:l}=$a(t);return n.jsxs(n.Fragment,{children:[n.jsx(s.Box,{ref:a,pt:10,pb:10,sx:r,children:e}),n.jsx(JT,{downloadScreenshot:l})]})}),Ri=T.observer(({downloadScreenshot:e})=>n.jsx(s.ActionIcon,{className:"download-screenshot-button",color:"blue",variant:"subtle",onClick:e,children:n.jsx(S.IconCamera,{size:14})})),HT=T.observer(({children:e,view:t})=>{const r=J(),a=t.config,l=r.views.visibleViewIDs.includes(t.id),o=()=>r.views.rmVisibleViewID(t.id),{ref:i,downloadScreenshot:c}=$a(t);return n.jsx(s.Modal,{size:a.width,centered:!0,opened:l,onClose:o,withCloseButton:!1,title:n.jsxs(s.Group,{justify:"space-between",px:"1rem",h:"48px",children:[n.jsx(s.Box,{children:a.custom_modal_title.value}),n.jsx(Ri,{downloadScreenshot:c})]}),trapFocus:!0,onDragStart:d=>{d.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:a.height,overflow:"auto",position:"relative",paddingBottom:10},header:{padding:0},title:{flexGrow:1}},transitionProps:{duration:0},children:n.jsx(s.Box,{ref:i,children:e})})}),RT=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},e2=T.observer(({view:e})=>{const t=J(),r=e.config;return n.jsxs(s.Tabs,{className:"render-view-tabs",variant:r.variant,orientation:r.orientation,value:e.tab,onChange:e.setTab,styles:{root:{height:"100%",overflow:r.orientation==="horizontal"?"hidden":"auto"},panel:{padding:r.orientation==="horizontal"?"0px 0px 36px":"0",height:"100%",overflow:"auto"}},keepMounted:!1,children:[n.jsx(s.Tabs.List,{grow:r.grow,children:r.tabsInOrder.map(a=>n.jsx(s.Tabs.Tab,{value:a.id,sx:RT(a),disabled:!a.view_id,children:a.name??a.id},a.id))}),r.tabsInOrder.map(a=>{const l=t.views.findByID(a.view_id);return l?n.jsx(s.Tabs.Panel,{value:a.id,children:n.jsx(Dn,{view:l})},a.id):null})]})}),t2=T.observer(({view:e,children:t})=>{switch(e.type){case $.Modal:return n.jsx(HT,{view:e,children:t});case $.Tabs:return n.jsx(e2,{view:e});case $.Division:default:return n.jsx(Hi,{view:e,children:t})}}),n2=T.observer(({children:e,view:t})=>{const a=F().layouts,[l,o]=te.useResizeObserver();return h.useEffect(()=>{a.setCurrentLayoutWrapperWidth(o.width)},[o.width]),n.jsx(s.Box,{sx:{height:"100%"},ref:l,children:n.jsx(s.Box,{sx:{paddingBottom:"100px",background:"white",margin:"0 auto",width:a.currentLayoutPreviewWidth??"100%",transform:`scale(${a.divisionPreviewScale})`,transformOrigin:"0 0"},children:n.jsx(Hi,{view:t,sx:{paddingTop:"0px !important",".dashboard-sticky-area > form":{paddingBottom:"5px"},".dashboard-layout":{marginTop:0,marginBottom:0}},children:e})})})});function ec(e){return e.replace(/(vw|vh)/,"%")}const r2=T.observer(({children:e,view:t})=>{const r=t.config,{width:a,height:l}=h.useMemo(()=>({width:ec(r.width),height:ec(r.height)}),[r.width,r.height]),{ref:o,downloadScreenshot:i}=$a(t);return n.jsx(s.Box,{sx:{height:"100%","> div:not(.mantine-Modal-root)":{height:"100%"}},children:n.jsx(s.Modal,{size:r.width,opened:!0,onClose:y.noop,withCloseButton:!1,title:n.jsxs(s.Group,{justify:"space-between",px:"1rem",h:"48px",children:[n.jsx(s.Box,{children:r.custom_modal_title.value}),n.jsx(Ri,{downloadScreenshot:i})]}),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:a,height:l,maxHeight:l},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:n.jsx(s.Box,{ref:o,children:e})})})}),a2=({variant:e,orientation:t})=>{const r={root:{height:"100%",overflow:"hidden"},list:{backgroundColor:"white"},tab:{},panel:{padding:"16px"}};return e==="pills"&&t==="horizontal"&&(r.tab.paddingTop="6px",r.tab.paddingBottom="6px"),t==="vertical"&&(r.tab["&.add-a-tab"]={paddingTop:"1px",paddingBottom:"1px"},r.tab["&.add-a-tab .mantine-Tabs-tabLabel"]={marginLeft:"auto",marginRight:"auto"}),r},s2=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},l2=T.observer(({view:e})=>{const{t}=x.useTranslation(),r=ze.useModals(),a=F(),l=h.useMemo(()=>a.views.options.filter(u=>u.type===$.Division),[e.id,a.views.options]),o=e.config,i=u=>r.openConfirmModal({title:`${t("view.component.tabs.tab.delete")}?`,labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{o.removeTab(u)},confirmProps:{color:"red"},zIndex:320}),c=o.tabs.length===0,d=o.tabsInOrder.length===0?void 0:o.tabsInOrder[0].id;return n.jsxs(s.Tabs,{className:"preview-view-tabs",variant:o.variant,orientation:o.orientation,value:e.tab||d,onChange:e.setTab,styles:a2(o),children:[n.jsxs(s.Tabs.List,{grow:o.grow,children:[o.tabsInOrder.map(u=>n.jsx(s.Tabs.Tab,{value:u.id,sx:s2(u),children:u.name??u.id},u.id)),n.jsx(s.Tabs.Tab,{onClick:o.addTab,value:"add",className:"add-a-tab",children:n.jsx(S.IconPlus,{size:18,color:"#228be6"})})]}),o.tabsInOrder.map((u,p)=>{const f=a.views.findByID(u.view_id);return n.jsxs(s.Tabs.Panel,{value:u.id,sx:{position:"relative"},children:[n.jsxs(s.Box,{sx:{position:"absolute",top:0,left:0,right:0,bottom:0,zIndex:200},children:[n.jsx(s.Overlay,{backgroundOpacity:.8,color:"#FFF",blur:10,zIndex:100}),n.jsxs(s.Stack,{mx:"auto",mt:100,sx:{width:"300px",position:"relative",zIndex:200},children:[n.jsx(s.TextInput,{label:t("view.component.tabs.tab.name"),required:!0,value:u.name,onChange:v=>u.setName(v.currentTarget.value)}),n.jsx(s.Select,{label:t("view.label"),value:u.view_id,onChange:u.setViewID,data:l}),n.jsx(s.NumberInput,{label:t("view.component.tabs.tab.order"),required:!0,value:u.order,onChange:v=>u.setOrder(v||0),min:0,max:1e3,step:1}),n.jsx(s.ColorInput,{label:t("view.component.tabs.tab.color"),value:u.color,onChange:u.setColor,disabled:o.variant!=="default"}),f&&n.jsx(s.Button,{mt:20,variant:"gradient",leftSection:n.jsx(S.IconArrowsLeftRight,{size:18}),gradient:{from:"cyan",to:"indigo"},onClick:()=>a.views.setIDOfVIE(f.id),children:t("view.component.tabs.tab.switch_to_view",{name:f.name})}),n.jsx(s.Button,{mt:20,variant:"subtle",color:"red",onClick:()=>i(p),disabled:c,leftSection:n.jsx(S.IconTrash,{size:14}),children:t("view.component.tabs.tab.delete")})]})]}),f&&n.jsx(Dn,{view:f})]},u.id)})]})}),o2=T.observer(({view:e,children:t})=>{switch(e.type){case $.Modal:return n.jsx(r2,{view:e,children:t});case $.Tabs:return n.jsx(l2,{view:e});case $.Division:default:return n.jsx(n2,{view:e,children:t})}}),tc=T.observer(function({view:t}){const a=F().layouts.divisionPreviewScale!==1;return n.jsx(kn.Provider,{value:{viewPanelInFullScreen:y.noop,inFullScreen:!1},children:n.jsx(s.Box,{className:"dashboard-view","data-enable-scrollbar":!0,sx:{background:a?"transparent":"#efefef"},children:n.jsx(o2,{view:t,children:n.jsxs(s.Box,{sx:{position:"relative"},children:[n.jsx(s.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:n.jsx(Li,{view:t})}),n.jsx(KT,{view:t})]})})})})}),Dn=T.observer(function({view:t}){const{fullScreenPanelID:r,setFullScreenPanelID:a}=Vs(),{viewPanelInFullScreen:l,exitFullScreen:o,inFullScreen:i,fullScreenPanel:c}=Ji(t,r,a);return n.jsx(kn.Provider,{value:{viewPanelInFullScreen:l,inFullScreen:i},children:n.jsxs(s.Box,{className:"dashboard-view","data-enable-scrollbar":!0,sx:{height:t.type===$.Modal?"0 !important":"100%"},children:[i&&n.jsx(Zi,{view:t,panel:c,exitFullScreen:o}),n.jsx(t2,{view:t,children:n.jsxs(s.Box,{sx:{position:"relative"},children:[!i&&n.jsx(s.Box,{className:"dashboard-sticky-area",sx:{position:"sticky",top:"0px"},children:n.jsx(Li,{view:t})}),!i&&n.jsx(ZT,{view:t})]})})]})})});var nc=(e=>(e.Use="use",e.Edit="edit",e))(nc||{});const i2={[$.Division]:"Division",[$.Tabs]:"Tabs",[$.Modal]:"Modal"},rc={[$.Division]:"rgba(255, 0, 0, 0.2)",[$.Modal]:"rgba(0, 0, 0, 0.2)",[$.Tabs]:"rgba(255, 200, 100, 0.4)"},c2={[$.Division]:"#ff4000",[$.Modal]:"#000",[$.Tabs]:"#ffad18"},ac=Cn.views(e=>({get usages(){return e.contentModel.findFilterUsage(e.id)}})).actions(e=>({}));function d2(e,t,r){g.addDisposer(e,g.addMiddleware(e,(a,l)=>{l(a,()=>{g.getType(a.context)===t&&a.type==="action"&&r(a.name,a.context)})}))}const sc=g.types.compose("FiltersModel",wa,g.types.model({current:g.types.optional(g.types.array(ac),[]),previewValues:g.types.optional(g.types.frozen(),{})})).views(e=>({get idSet(){return new Set(e.current.map(t=>t.id))},get keySet(){return new Set(e.current.map(t=>t.key))},get options(){return e.current.map(t=>({label:t.label??t.id,value:t.id,_type:"filter"}))},get selects(){return e.current.filter(t=>t.type===V.Select).map(t=>({label:t.label??t.id,value:t.id}))},get keyLabelOptions(){return e.current.map(t=>({label:t.label??t.key,value:t.key,widget:t.type}))},get sortedList(){return y.sortBy(e.current,t=>t.label.toLowerCase())}})).actions(e=>({replace(t){e.current=g.cast(t)},append(t){e.current.push(t)},appendMultiple(t){if(t.length===0)return;const r=t.filter(a=>!e.idSet.has(a.id));e.current.push(...r)},remove(t){e.current.splice(t,1)},removeByID(t){const r=e.current.findIndex(a=>a.id===t);r>=0&&e.current.splice(r,1)},updatePreviewValues(t){e.previewValues=t}})).actions(e=>{function t(){d2(e.current,Cn,(r,a)=>{if(r==="setType"){const l=wi(a.config.default_value,a.config);e.setValueByKey(a.key,l),e.updatePreviewValues({...e.previewValues,[a.key]:l})}})}return{afterCreate(){t()}}}),lc=Sa.views(e=>({get canPreviewData(){return e.isTransform?e.config.dep_query_ids.length>0&&!!e.pre_process:!!e.datasource},get guideToPreviewData(){return e.isTransform?"Need to complete settings in Transform tab":"Need to pick a Data Source first"},get usage(){return e.contentModel.findQueryUsage(e.id)},get runBySet(){return new Set(e.run_by)},keyInRunBy(t){return this.runBySet.has(t)}})).actions(e=>({changeRunByRecord(t,r){const a=new Set(e.run_by);r?a.add(t):a.delete(t),e.run_by.length=0,e.run_by.push(...a)}})),oc=g.types.compose("QueriesModel",Ta,g.types.model({current:g.types.optional(g.types.array(lc),[])})).views(e=>({get options(){const t=e.current.map(r=>({value:r.id,label:r.name,_type:"query"}));return y.sortBy(t,r=>r.label.toLowerCase())},get optionsWithoutTransform(){const t=e.current.filter(r=>r.type!==j.Transform).map(r=>({value:r.id,label:r.name,_type:"query"}));return y.sortBy(t,r=>r.label.toLowerCase())},get sortedList(){return y.sortBy(e.current,t=>t.name.toLowerCase())}})).actions(e=>({replace(t){e.current=g.cast(t)},append(t){e.current.push(t)},appendMultiple(t){if(t.length===0)return;const r=t.filter(a=>!e.idSet.has(a.id));e.current.push(...r)},remove(t){e.current.splice(t,1)},replaceByIndex(t,r){e.current.splice(t,1,r)},removeQuery(t){const r=e.current.find(a=>a.id===t);r&&(g.detach(r),e.current.remove(r))},removeQueries(t){const r=new Set(t);e.current.forEach(l=>{r.has(l.id)&&g.detach(l)});const a=[...e.current];y.remove(a,l=>r.has(l.id)),e.current=g.cast(a)}})),ic=za.views(e=>({get sortedList(){return y.sortBy(e.current,t=>t.key.toLowerCase())},get options(){const t=e.current.map(r=>({label:r.key,value:r.key,_type:"sql_snippet"}));return y.sortBy(t,r=>r.label.toLowerCase())},get usedFilterKeyMap(){const t=new Map;return e.current.forEach(r=>{const a=y.get(r,"value","");if(!a)return;const l=y.uniq(a.match(Mt.filter)),o=new Set;l.forEach(i=>o.add(i)),t.set(r.key,o)}),t}})).actions(e=>({replace(t){e.current=g.cast(t)},append(t){e.current.push(t)},appendMultiple(t){if(t.length===0)return;const r=t.filter(a=>!e.keySet.has(a.key));e.current.push(...r)},remove(t){e.current.splice(t,1)},removeByKey(t){const r=e.current.findIndex(a=>a.key===t);r>=0&&e.current.splice(r,1)},removeByKeys(t){const r=new Set(t);e.current.forEach(l=>{r.has(l.key)&&g.detach(l)});const a=[...e.current];y.remove(a,l=>r.has(l.key)),e.current=g.cast(a)},replaceByIndex(t,r){e.current.splice(t,1,r)}})),u2=g.types.model({data:g.types.optional(g.types.frozen(),[]),state:g.types.optional(g.types.enumeration(["idle","loading","error"]),"idle"),error:g.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0}})),p2=g.types.model({data:g.types.optional(g.types.frozen(),[]),state:g.types.optional(g.types.enumeration(["idle","loading","error"]),"idle"),error:g.types.frozen()}).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0}})),h2=g.types.model({page:g.types.optional(g.types.number,1),limit:g.types.optional(g.types.number,20),data:g.types.optional(g.types.frozen(),[]),total:g.types.optional(g.types.number,0),state:g.types.optional(g.types.enumeration(["idle","loading","error"]),"idle"),error:g.types.frozen()}).views(e=>({get keywords(){return g.getParent(e,1)},get keywordString(){const{table_name:t,table_schema:r}=g.getParent(e,1);return`${r}||${t}`}})).views(e=>({get loading(){return e.state==="loading"},get empty(){return e.data.length===0},get maxPage(){return Math.ceil(e.total/e.limit)},get offset(){return(e.page-1)*e.limit},get countSql(){const{table_name:t,table_schema:r}=e.keywords;return`
|
|
543
543
|
SELECT count(*) AS total
|
|
544
544
|
FROM ${r}.${t}
|
|
@@ -568,5 +568,5 @@ WHERE
|
|
|
568
568
|
`)},t3=T.observer(({queryModel:e})=>{const{t}=x.useTranslation();return e.typedAsHTTP?n.jsxs(s.Tabs,{defaultValue:"pre_process",orientation:"vertical",sx:{flexGrow:1},children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"pre_process",children:t("query.build_request")}),n.jsx(s.Tabs.Tab,{value:"post_process",children:t("query.process_result")}),n.jsx(Qa,{})]}),n.jsx(s.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:n.jsx(xt,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:Gc.pre})}),n.jsx(s.Tabs.Panel,{value:"post_process",p:"sm",children:n.jsx(xt,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:Gc.post})})]}):null}),Fc=T.observer(({queryModel:e})=>{const{t}=x.useTranslation(),r=W().editor,a=i=>{if(i.type==="filter"){r.setPath(["_FILTERS_",i.id]);return}if(i.type==="panel"){const c=i.views[0].id;r.setPath(["_VIEWS_",c,"_PANELS_",i.id,"_TABS_","Data"]);return}},l=i=>{r.setPath(["_VIEWS_",i])},o=e.usage;return n.jsxs(s.Table,{highlightOnHover:!0,layout:"fixed",styles:{table:{fontSize:"14px"}},children:[n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{style:{width:100},children:t("common.type")}),n.jsx(s.Table.Th,{style:{width:"calc(50% - 50px)"},children:t("common.name")}),n.jsx(s.Table.Th,{children:t("query.usage.in_views")})]})}),n.jsx(s.Table.Tbody,{children:o.map(i=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:t(i.type_label)}),n.jsx(s.Table.Td,{children:n.jsx(s.Anchor,{size:"sm",component:"button",type:"button",onClick:()=>a(i),children:i.label})}),n.jsx(s.Table.Td,{children:n.jsxs(s.Stack,{align:"flex-start",justify:"flex-start",gap:2,children:[i.views.map(c=>n.jsx(s.Anchor,{size:"sm",component:"button",type:"button",onClick:()=>l(c.id),children:n.jsx(s.Box,{children:c.label})},c.id)),i.views.length===0&&n.jsx(s.Box,{children:"--"})]})})]},i.id))})]})}),n3=T.observer(({queryModel:e})=>{const{t}=x.useTranslation(),r=h.useMemo(()=>y.groupBy(e.dependencies,"type"),[e.dependencies]),a=h.useMemo(()=>e.dependencies.some(o=>!o.valid),[e.dependencies]),l=e.dependencies.length>0;return l?n.jsxs(s.HoverCard,{withinPortal:!0,zIndex:340,shadow:"md",disabled:!l,children:[n.jsx(s.HoverCard.Target,{children:n.jsx(s.Button,{size:"xs",variant:"subtle",color:a?"red":"green",disabled:!l,leftSection:a?n.jsx(S.IconAlertTriangle,{size:16}):n.jsx(S.IconDiscountCheckFilled,{size:16}),children:t("query.dependency.label")})}),n.jsx(s.HoverCard.Dropdown,{children:n.jsx(s.List,{spacing:"md",size:"sm",listStyleType:"none",children:Object.entries(r).map(([o,i])=>n.jsxs(s.List.Item,{children:[n.jsx(s.Text,{size:"sm",fw:"bold",ff:"monospace",children:t(`${o}.label`)}),n.jsx(s.List,{withPadding:!0,size:"sm",sx:{fontFamily:"monospace",svg:{verticalAlign:"middle"}},children:i.map(c=>n.jsx(s.List.Item,{icon:n.jsx(s.Box,{sx:{path:{fill:c.valid?"rgb(18, 184, 134)":"rgb(250, 82, 82)"}},children:n.jsx(S.IconPointFilled,{size:12})}),children:c.key},c.key))})]},o))})})]}):n.jsx(s.Tooltip,{label:t("query.dependency.has_none"),children:n.jsx(s.Button,{size:"xs",variant:"subtle",color:"gray",leftSection:n.jsx(S.IconHierarchy,{size:16,style:{transform:"rotate(180deg)"}}),sx:{transform:"none !important"},children:t("query.dependency.label")})})}),r3="SELECT 1",a3=T.observer(({queryModel:e})=>{const{t}=x.useTranslation(),r=e.config,[a,l]=h.useState(r.sql),o=()=>{r.setSQL(a)},i=()=>{l(r.sql)},c=()=>{l(r3)};h.useEffect(()=>{l(r.sql)},[r.sql]);const d=a!==r.sql;return n.jsxs(s.Stack,{gap:4,sx:{height:"100%"},children:[n.jsxs(s.Group,{mb:6,justify:"space-between",sx:{flexShrink:0,flexGrow:0},children:[n.jsx(s.Group,{justify:"flex-start",children:n.jsx(n3,{queryModel:e})}),n.jsxs(s.Group,{justify:"flex-end",children:[n.jsx(s.Button,{onClick:c,size:"xs",variant:"default",leftSection:n.jsx(S.IconPlayerSkipBack,{size:16}),children:t("common.actions.reset_to_default")}),n.jsx(s.Button,{onClick:i,color:"red",size:"xs",disabled:!d,leftSection:n.jsx(S.IconRecycle,{size:16}),children:t("common.actions.revert_changes")}),n.jsx(s.Button,{color:"green",size:"xs",onClick:o,disabled:!d,leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),children:t("common.actions.save_changes")})]})]}),n.jsx(rr,{height:"100%",value:a,onChange:l,theme:"sql-dark",defaultLanguage:"sql"})]})}),s3=({value:e,height:t="200px",defaultLanguage:r="sql"})=>n.jsx(Te,{className:"preview-sql-in-monaco-editor",height:t,defaultLanguage:r,value:e,onChange:void 0,theme:"vs-light",options:{lineNumbers:"on",folding:!0,lineDecorationsWidth:20,wordWrap:"on",minimap:{enabled:!1},readOnly:!0}}),l3=T.observer(({value:e})=>{const r=J().payloadForSQL,a=h.useMemo(()=>or(e,r),[e,r]);return n.jsx(s3,{height:"100%",value:a})}),jc={pre:["function process_request({ context, filters, sql }, utils) {"," // modify and return sql"," return sql","}"].join(`
|
|
569
569
|
`),post:["function process_result(data, utils, state) {"," // process data and return the result"," return data","}"].join(`
|
|
570
570
|
`)},o3=T.observer(({queryModel:e})=>{const{t}=x.useTranslation();if(!e.typedAsSQL)return null;const r=e.config;return n.jsxs(s.Tabs,{defaultValue:"Edit",orientation:"vertical",sx:{flexGrow:1},styles:{tabLabel:{width:"100%",height:"28px",lineHeight:"28px"}},keepMounted:!1,children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"Edit",children:n.jsx(s.Group,{gap:14,justify:"space-between",children:t("query.edit_sql")})}),n.jsx(s.Tabs.Tab,{value:"Preview",children:t("query.preview_sql")}),n.jsx(s.Tabs.Tab,{value:"pre_process",children:t("query.process_request")}),n.jsx(s.Tabs.Tab,{value:"post_process",children:t("query.process_result")}),n.jsx(Qa,{}),e.datasource&&n.jsx(Lc,{dataSource:e.datasource})]}),n.jsx(s.Tabs.Panel,{value:"Edit",sx:{position:"relative"},p:"sm",children:n.jsx(a3,{queryModel:e})}),n.jsx(s.Tabs.Panel,{value:"Preview",p:0,pl:4,children:n.jsx(l3,{value:r.sql})}),n.jsx(s.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:n.jsx(xt,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:jc.pre})}),n.jsx(s.Tabs.Panel,{value:"post_process",p:"sm",children:n.jsx(xt,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:jc.post})})]})}),i3={pre:["function transform(queries, state, utils) {"," // use queries & dashboar state to build new data"," const data = []"," return data","}"].join(`
|
|
571
|
-
`),post:""},c3=T.observer(({queryModel:e})=>{const{t}=x.useTranslation(),r=F();if(!e.isTransform)return null;const a=e.config;return n.jsxs(s.Stack,{py:20,px:20,sx:{height:"100%"},children:[n.jsx(s.Text,{size:"sm",children:t("query.transform.guide.pick_queries")}),n.jsx(s.MultiSelect,{data:r.queries.optionsWithoutTransform,value:[...a.dep_query_ids],onChange:a.setDependantQueryIDs,maxDropdownHeight:800}),n.jsx(s.Text,{size:"sm",children:t("query.transform.guide.write_function")}),n.jsx(s.Box,{sx:{flexGrow:1},children:n.jsx(xt,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:i3.pre})})]})}),Kt={height:"calc(100% - 44px)",padding:0},d3=T.observer(({queryModel:e})=>{const{t}=x.useTranslation(),r=F(),a=h.useMemo(()=>e.datasource?e.typedAsHTTP?"HTTP":"SQL":"Configurations",[e.datasource,e.typedAsHTTP]),[l,o]=h.useState(a);h.useEffect(()=>{o(d=>d!=="Configurations"&&a==="Configurations"?"Configurations":d)},[a]);const c=r.findQueryUsage(e.id).length===0;return n.jsxs(s.Tabs,{value:l,onChange:o,defaultValue:a,orientation:"horizontal",keepMounted:!1,sx:{height:"100vh"},children:[n.jsxs(s.Tabs.List,{grow:!0,children:[n.jsx(s.Tabs.Tab,{value:"Configurations",children:t("query.configurations")}),e.typedAsSQL&&n.jsx(s.Tabs.Tab,{value:"SQL",children:t("query.request")}),e.typedAsHTTP&&n.jsx(s.Tabs.Tab,{value:"HTTP",children:t("query.request")}),e.isTransform&&n.jsx(s.Tabs.Tab,{value:"Transform",children:t("query.transform.label")}),n.jsx(s.Tabs.Tab,{value:"Data",disabled:!e.canPreviewData,children:n.jsx(s.Tooltip,{label:e.guideToPreviewData,disabled:e.canPreviewData,withinPortal:!0,children:n.jsx(s.Text,{size:"sm",children:t("data.preview_data")})})}),n.jsx(s.Tabs.Tab,{value:"Usage",disabled:c,children:n.jsx(s.Tooltip,{label:t("query.usage.unused_description"),disabled:!c,withinPortal:!0,children:n.jsx(s.Text,{size:"sm",children:t("query.usage.label")})})})]}),n.jsx(s.Tabs.Panel,{value:"Configurations",pt:0,p:0,children:n.jsx(Jz,{queryModel:e})}),e.typedAsSQL&&n.jsx(s.Tabs.Panel,{value:"SQL",sx:Kt,children:n.jsx(s.Stack,{sx:{height:"100%"},children:n.jsx(o3,{queryModel:e})})}),e.typedAsHTTP&&n.jsx(s.Tabs.Panel,{value:"HTTP",sx:Kt,children:n.jsx(s.Stack,{sx:{height:"100%"},children:n.jsx(t3,{queryModel:e})})}),e.isTransform&&n.jsx(s.Tabs.Panel,{value:"Transform",sx:Kt,children:n.jsx(s.Stack,{sx:{height:"100%"},children:n.jsx(c3,{queryModel:e})})}),n.jsx(s.Tabs.Panel,{value:"Data",sx:{...Kt,overflow:"hidden"},children:n.jsx(Ga,{id:e.id,moreActions:null,refreshOnMount:!0})}),n.jsx(s.Tabs.Panel,{value:"Usage",py:"sm",px:"md",sx:{...Kt,overflow:"hidden"},children:n.jsx(Fc,{queryModel:e})})]})}),u3=({width:e,height:t})=>n.jsxs("svg",{width:e,height:t,viewBox:"0 0 36 36",fill:"none",children:[n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M7.5 10.5C7.10217 10.5 6.72064 10.658 6.43934 10.9393C6.15804 11.2206 6 11.6022 6 12V28.5C6 28.8978 6.15804 29.2794 6.43934 29.5607C6.72064 29.842 7.10218 30 7.5 30H24C24.3978 30 24.7794 29.842 25.0607 29.5607C25.342 29.2794 25.5 28.8978 25.5 28.5V19.5C25.5 18.6716 26.1716 18 27 18C27.8284 18 28.5 18.6716 28.5 19.5V28.5C28.5 29.6935 28.0259 30.8381 27.182 31.682C26.3381 32.5259 25.1935 33 24 33H7.5C6.30653 33 5.16193 32.5259 4.31802 31.682C3.47411 30.8381 3 29.6935 3 28.5V12C3 10.8065 3.47411 9.66193 4.31802 8.81802C5.16193 7.97411 6.30653 7.5 7.5 7.5H16.5C17.3284 7.5 18 8.17157 18 9C18 9.82843 17.3284 10.5 16.5 10.5H7.5Z",fill:"#3D3E45"}),n.jsx("path",{d:"M32.8862 3.92582C32.8135 3.75021 32.7061 3.5856 32.5638 3.44253C32.5617 3.4404 32.5596 3.43828 32.5575 3.43616C32.2863 3.16658 31.9126 3 31.5 3H22.5C21.6716 3 21 3.67157 21 4.5C21 5.32843 21.6716 6 22.5 6H27.8787L13.9393 19.9393C13.3536 20.5251 13.3536 21.4749 13.9393 22.0607C14.5251 22.6464 15.4749 22.6464 16.0607 22.0607L30 8.12132V13.5C30 14.3284 30.6716 15 31.5 15C32.3284 15 33 14.3284 33 13.5V4.5C33 4.29662 32.9595 4.10268 32.8862 3.92582Z",fill:"#3D3E45"})]}),Qc=({width:e,height:t,color:r="#FFFFFF"})=>n.jsxs("svg",{viewBox:"0 0 36 36",fill:"none",width:e,height:t,children:[n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M24.6931 20.547C26.1129 19.5516 26.113 17.4483 24.6931 16.4529L16.9351 11.0141C15.2783 9.85255 13 11.0377 13 13.0611L13 23.9389C13 25.9623 15.2783 27.1474 16.9351 25.9859L24.6931 20.547ZM16 14.0223L22.387 18.5L16 22.9777L16 14.0223Z",fill:r}),n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M18 1.5C8.8873 1.5 1.5 8.8873 1.5 18C1.5 27.1127 8.8873 34.5 18 34.5C27.1127 34.5 34.5 27.1127 34.5 18C34.5 8.8873 27.1127 1.5 18 1.5ZM4.5 18C4.5 10.5442 10.5442 4.5 18 4.5C25.4558 4.5 31.5 10.5442 31.5 18C31.5 25.4558 25.4558 31.5 18 31.5C10.5442 31.5 4.5 25.4558 4.5 18Z",fill:r})]}),Wc=({width:e,height:t,color:r="#EB1212"})=>n.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",width:e,height:t,children:[n.jsx("path",{d:"M6.66665 6.66699C7.03484 6.66699 7.33331 6.96547 7.33331 7.33366V11.3337C7.33331 11.7018 7.03484 12.0003 6.66665 12.0003C6.29846 12.0003 5.99998 11.7018 5.99998 11.3337V7.33366C5.99998 6.96547 6.29846 6.66699 6.66665 6.66699Z",fill:r}),n.jsx("path",{d:"M9.99998 11.3337V7.33366C9.99998 6.96547 9.7015 6.66699 9.33331 6.66699C8.96512 6.66699 8.66665 6.96547 8.66665 7.33366V11.3337C8.66665 11.7018 8.96512 12.0003 9.33331 12.0003C9.7015 12.0003 9.99998 11.7018 9.99998 11.3337Z",fill:r}),n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M4.66665 3.33366V2.66699C4.66665 2.13656 4.87736 1.62785 5.25243 1.25278C5.62751 0.877706 6.13621 0.666992 6.66665 0.666992H9.33331C9.86375 0.666992 10.3725 0.877706 10.7475 1.25278C11.1226 1.62785 11.3333 2.13656 11.3333 2.66699V3.33366H14C14.3682 3.33366 14.6666 3.63214 14.6666 4.00033C14.6666 4.36852 14.3682 4.66699 14 4.66699H13.3333V13.3337C13.3333 13.8641 13.1226 14.3728 12.7475 14.7479C12.3725 15.1229 11.8637 15.3337 11.3333 15.3337H4.66665C4.13621 15.3337 3.62751 15.1229 3.25243 14.7479C2.87736 14.3728 2.66665 13.8641 2.66665 13.3337V4.66699H1.99998C1.63179 4.66699 1.33331 4.36852 1.33331 4.00033C1.33331 3.63214 1.63179 3.33366 1.99998 3.33366H4.66665ZM6.19524 2.19559C6.32027 2.07056 6.48984 2.00033 6.66665 2.00033H9.33331C9.51012 2.00033 9.67969 2.07056 9.80472 2.19559C9.92974 2.32061 9.99998 2.49018 9.99998 2.66699V3.33366H5.99998V2.66699C5.99998 2.49018 6.07022 2.32061 6.19524 2.19559ZM3.99998 4.66699V13.3337C3.99998 13.5105 4.07022 13.68 4.19524 13.8051C4.32027 13.9301 4.48984 14.0003 4.66665 14.0003H11.3333C11.5101 14.0003 11.6797 13.9301 11.8047 13.8051C11.9297 13.68 12 13.5105 12 13.3337V4.66699H3.99998Z",fill:r})]}),p3=({width:e,height:t})=>n.jsxs("svg",{viewBox:"0 0 18 18",fill:"none",width:e,height:t,children:[n.jsx("path",{d:"M7.5 3.75C7.5 2.92157 8.17157 2.25 9 2.25C9.82843 2.25 10.5 2.92157 10.5 3.75C10.5 4.57843 9.82843 5.25 9 5.25C8.17157 5.25 7.5 4.57843 7.5 3.75Z",fill:"#3D3E45"}),n.jsx("path",{d:"M7.5 9C7.5 8.17157 8.17157 7.5 9 7.5C9.82843 7.5 10.5 8.17157 10.5 9C10.5 9.82843 9.82843 10.5 9 10.5C8.17157 10.5 7.5 9.82843 7.5 9Z",fill:"#3D3E45"}),n.jsx("path",{d:"M9 12.75C8.17157 12.75 7.5 13.4216 7.5 14.25C7.5 15.0784 8.17157 15.75 9 15.75C9.82843 15.75 10.5 15.0784 10.5 14.25C10.5 13.4216 9.82843 12.75 9 12.75Z",fill:"#3D3E45"})]}),h3=T.observer(({queryModel:e})=>{const{t}=x.useTranslation(),r=W(),a=F(),o=a.findQueryUsage(e.id).length>0,i=ze.useModals(),c=()=>{i.openConfirmModal({title:`${t("query.delete")}?`,labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{a.queries.removeQuery(e.id),r.editor.setPath(["_QUERIES_",""])},confirmProps:{color:"red"},zIndex:320})};return o?n.jsx(s.Tooltip,{label:"此查询在使用中,不能删除。请查看“使用情况”标签页以了解详情",withArrow:!0,events:{hover:!0,focus:!1,touch:!1},withinPortal:!0,zIndex:320,position:"bottom-end",children:n.jsx(s.Button,{leftSection:n.jsx(Wc,{width:14,height:14,color:"gray"}),variant:"subtle",color:"gray",onClick:d=>{d.stopPropagation()},children:"删除查询"})}):n.jsx(s.Menu.Item,{leftSection:n.jsx(Wc,{width:14,height:14}),color:"red",onClick:c,children:"删除查询"})}),g3=T.observer(({queryModel:e})=>n.jsxs(s.Menu,{shadow:"md",width:120,trigger:"hover",children:[n.jsx(s.Menu.Target,{children:n.jsx(s.ActionIcon,{variant:"subtle","aria-label":"Settings",children:n.jsx(p3,{width:18,height:18})})}),n.jsx(s.Menu.Dropdown,{children:n.jsx(h3,{queryModel:e})})]})),f3={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",backgroundColor:"rgb(248, 249, 250)"},"@media (hover: hover)":{".resizer":{opacity:"0"},"*:hover > .resizer":{color:"#228be6",opacity:"1"}}};function b3({data:e}){const t=h.useMemo(()=>{if(!Array.isArray(e)||e.length===0)return[];const a=ge.createColumnHelper();return Object.keys(e[0]).map(l=>a.accessor(l,{cell:o=>o.getValue()}))},[e]),r=ge.useReactTable({data:e,columns:t,columnResizeMode:"onChange",getCoreRowModel:ge.getCoreRowModel()});return e.length===0?n.jsx(s.Box,{sx:{height:"5em"}}):n.jsx(ne,{children:n.jsxs(s.Table,{sx:f3,stickyHeader:!0,stickyHeaderOffset:0,children:[n.jsx(s.Table.Thead,{style:{backgroundColor:"#F9F9FA"},children:r.getHeaderGroups().map(a=>n.jsx(s.Table.Tr,{children:a.headers.map(l=>n.jsxs(s.Table.Th,{style:{width:l.getSize()},children:[l.isPlaceholder?null:ge.flexRender(l.column.columnDef.header,l.getContext()),n.jsx(s.ActionIcon,{variant:"subtle",onMouseDown:l.getResizeHandler(),onTouchStart:l.getResizeHandler(),className:`resizer ${l.column.getIsResizing()?"isResizing":""}`,children:n.jsx(S.IconArrowBarToRight,{})})]},l.id))},a.id))}),n.jsx(s.Table.Tbody,{children:r.getRowModel().rows.map(a=>n.jsx(s.Table.Tr,{children:a.getVisibleCells().map(l=>n.jsx(s.Table.Td,{children:n.jsx(ne,{children:typeof l.getValue()=="object"?n.jsx("pre",{children:JSON.stringify(l.getValue(),null,2)}):ge.flexRender(l.column.columnDef.cell,l.getContext())})},l.id))},a.id))})]})})}const y3=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],v3={root:{width:"150px"},section:{"&[data-position=left]":{width:"70px",textAlign:"center"}},input:{paddingLeft:"70px",paddingRight:0}},_3=({data:e,page:t,setPage:r,limit:a,setLimit:l})=>{const{t:o}=x.useTranslation(),i=e.length,c=Math.ceil(i/a),d=p=>{p&&(r(1),l(Number(p)))};if(i===0)return null;const u=c===1&&i<=10;return n.jsxs(s.Group,{pt:10,px:10,justify:"space-between",children:[n.jsxs(s.Group,{justify:"flex-start",children:[!u&&n.jsx(s.Select,{leftSection:n.jsx(s.Text,{ta:"center",c:"dimmed",size:"xs",children:o("common.pagination.page_size")}),size:"xs",styles:v3,data:y3,value:String(a),onChange:d}),c>1&&n.jsx(s.Pagination,{size:"sm",value:t,onChange:r,total:c,withEdges:c>7,styles:{control:{height:"30px"}},color:"red"})]}),n.jsx(s.Group,{justify:"flex-end",children:n.jsx(s.Text,{c:"dimmed",my:0,size:"14px",children:o("common.pagination.total_rows",{total:i})})})]})},x3=ll(({data:e,loading:t})=>{const[r,a]=h.useState(1),[l,o]=h.useState(20),i=h.useMemo(()=>{const c=(r-1)*l,d=c+l;return e.slice(c,d)},[e,r,l]);return n.jsx(ne,{children:n.jsxs(s.Stack,{gap:10,styles:{root:{height:"100%",overflow:"hidden"}},children:[n.jsx(_3,{data:e,page:r,setPage:a,limit:l,setLimit:o}),n.jsxs(s.Box,{sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[n.jsx(s.LoadingOverlay,{visible:t,overlayProps:{blur:2}}),n.jsx(b3,{data:i})]})]})})}),w3=T.observer(({queryModel:e})=>{const{t}=x.useTranslation(),{state:r,error:a,metricQueryPayloadErrorString:l,stateMessage:o}=e;return r==="loading"?null:a?n.jsx(s.Text,{mt:10,c:"red",size:"md",ta:"center",ff:"monospace",children:a}):l?n.jsx(s.Text,{mt:10,c:"red",size:"md",ta:"center",ff:"monospace",children:l}):o?n.jsx(s.Text,{size:"sm",mt:10,c:"gray",ta:"center",children:t(o)}):null}),m3=T.observer(({queryModel:e})=>{x.useTranslation();const{data:t,state:r}=e,a=r==="loading",l=h.useCallback(()=>{e.fetchData(!0)},[e.fetchData]),o=()=>{yi(e.name,e.data)};h.useEffect(()=>{l()},[l]);const i=!Array.isArray(t)||t.length===0;return n.jsxs(s.Stack,{gap:0,sx:{maxHeight:"calc(50vh - 48px)",flexGrow:1,flexShrink:0,background:"#F9F9FA"},children:[n.jsxs(s.Group,{justify:"space-between",py:7,px:8,children:[n.jsx(s.Text,{size:"sm",fw:500,children:"查询结果"}),n.jsx(s.Button,{size:"xs",variant:"transparent",color:"gray",leftSection:n.jsx(S.IconDownload,{size:16}),disabled:a||i,onClick:o,children:"下载查询结果"})]}),n.jsxs(s.Box,{sx:{position:"relative",flexGrow:1,overflow:"hidden"},children:[n.jsx(w3,{queryModel:e}),n.jsx(x3,{data:t,loading:a})]})]})}),C3=T.observer(({queryModel:e})=>{const t=W();return n.jsxs(s.Tabs,{defaultValue:"看板变量预览",w:"40%",maw:"600px",styles:{root:{borderRadius:4,backgroundColor:"#F9F9FA",height:"100%",minHeight:"350px",maxHeight:"50vh",overflow:"hidden"},panel:{height:"calc(100% - 36px)"}},color:"red",children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"看板变量预览",children:"看板变量预览"}),n.jsx(s.Tabs.Tab,{value:"查询预览",children:"查询预览"})]}),n.jsx(s.Tabs.Panel,{value:"查询预览",children:n.jsx(Oe.CodeHighlight,{language:"json",sx:{width:"100%",height:"100%",minHeight:"400px",overflowY:"auto"},withCopyButton:!1,code:e.metricQueryPayloadString})}),n.jsx(s.Tabs.Panel,{value:"看板变量预览",children:n.jsx(Oe.CodeHighlight,{language:"json",sx:{width:"100%",height:"100%",minHeight:"400px",overflowY:"auto"},withCopyButton:!1,code:t.queryVariablesString})})]})}),S3=()=>n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M7.24335 1.62305C7.50108 1.62305 7.71001 1.83198 7.71001 2.08971L7.71001 11.423C7.71001 11.6808 7.50108 11.8897 7.24335 11.8897C6.98561 11.8897 6.77668 11.6808 6.77668 11.423L6.77668 2.08971C6.77668 1.83198 6.98561 1.62305 7.24335 1.62305Z",fill:"#3D3E45"}),n.jsx("path",{d:"M9.93845 9.4786C9.80779 9.4786 9.70045 9.43893 9.61645 9.3596C9.53712 9.2756 9.49745 9.17293 9.49745 9.0516L9.49745 5.0056C9.49745 4.88427 9.53712 4.78393 9.61645 4.7046C9.70045 4.6206 9.80312 4.5786 9.92445 4.5786L12.1995 4.5786C12.3208 4.5786 12.4211 4.61827 12.5005 4.6976C12.5845 4.77227 12.6265 4.87027 12.6265 4.9916C12.6265 5.09427 12.5845 5.18527 12.5005 5.2646C12.4211 5.34393 12.3208 5.3836 12.1995 5.3836L10.3725 5.3836V6.6156H11.8845C12.0058 6.6156 12.1061 6.65527 12.1855 6.7346C12.2695 6.80927 12.3115 6.90727 12.3115 7.0286C12.3115 7.13127 12.2695 7.22227 12.1855 7.3016C12.1061 7.38093 12.0058 7.4206 11.8845 7.4206H10.3725L10.3725 9.0516C10.3725 9.17293 10.3281 9.2756 10.2395 9.3596C10.1555 9.43893 10.0551 9.4786 9.93845 9.4786Z",fill:"#3D3E45"}),n.jsx("path",{d:"M3.34754 9.4786C3.21687 9.4786 3.10954 9.43893 3.02554 9.3596C2.94154 9.2756 2.89954 9.17293 2.89954 9.0516L2.89954 5.3836H1.80054C1.6792 5.3836 1.57654 5.34627 1.49254 5.2716C1.4132 5.19693 1.37354 5.09893 1.37354 4.9776C1.37354 4.85627 1.4132 4.7606 1.49254 4.6906C1.57654 4.61593 1.6792 4.5786 1.80054 4.5786H4.90854C5.02987 4.5786 5.1302 4.61593 5.20954 4.6906C5.29354 4.76527 5.33554 4.86327 5.33554 4.9846C5.33554 5.10593 5.29354 5.20393 5.20954 5.2786C5.1302 5.3486 5.02987 5.3836 4.90854 5.3836H3.80954L3.80954 9.0516C3.80954 9.17293 3.7652 9.2756 3.67654 9.3596C3.59254 9.43893 3.48287 9.4786 3.34754 9.4786Z",fill:"#3D3E45"})]}),T3=()=>n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[n.jsx("g",{clipPath:"url(#clip0_245_10828)",children:n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M9.91663 1.16634C9.91663 0.844175 9.65546 0.583008 9.33329 0.583008C9.01113 0.583008 8.74996 0.844175 8.74996 1.16634V1.74967L5.24996 1.74967V1.16634C5.24996 0.844175 4.98879 0.583008 4.66663 0.583008C4.34446 0.583008 4.08329 0.844175 4.08329 1.16634V1.74967H2.91663C1.95013 1.74967 1.16663 2.53318 1.16663 3.49967L1.16663 11.6663C1.16663 12.6328 1.95013 13.4163 2.91663 13.4163L11.0833 13.4163C12.0498 13.4163 12.8333 12.6328 12.8333 11.6663L12.8333 3.49967C12.8333 2.53318 12.0498 1.74967 11.0833 1.74967H9.91663V1.16634ZM11.6666 5.24967V3.49967C11.6666 3.17751 11.4055 2.91634 11.0833 2.91634H9.91663V3.49967C9.91663 3.82184 9.65546 4.08301 9.33329 4.08301C9.01113 4.08301 8.74996 3.82184 8.74996 3.49967V2.91634L5.24996 2.91634V3.49967C5.24996 3.82184 4.98879 4.08301 4.66663 4.08301C4.34446 4.08301 4.08329 3.82184 4.08329 3.49967V2.91634L2.91663 2.91634C2.59446 2.91634 2.33329 3.17751 2.33329 3.49967L2.33329 5.24967L11.6666 5.24967ZM2.33329 6.41634L11.6666 6.41634L11.6666 11.6663C11.6666 11.9885 11.4055 12.2497 11.0833 12.2497L2.91663 12.2497C2.59446 12.2497 2.33329 11.9885 2.33329 11.6663V6.41634Z",fill:"#3D3E45"})}),n.jsx("defs",{children:n.jsx("clipPath",{id:"clip0_245_10828",children:n.jsx("rect",{width:"14",height:"14",fill:"white"})})})]}),k3=()=>n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M3.11108 2.13932C2.78892 2.13932 2.52775 2.40049 2.52775 2.72266V10.8893C2.52775 11.2115 2.78892 11.4727 3.11108 11.4727H11.2778C11.5999 11.4727 11.8611 11.2115 11.8611 10.8893V2.72266C11.8611 2.40049 11.5999 2.13932 11.2778 2.13932H3.11108ZM1.36108 2.72266C1.36108 1.75616 2.14459 0.972656 3.11108 0.972656H11.2778C12.2442 0.972656 13.0278 1.75616 13.0278 2.72266V10.8893C13.0278 11.8558 12.2442 12.6393 11.2778 12.6393H3.11108C2.14459 12.6393 1.36108 11.8558 1.36108 10.8893V2.72266Z",fill:"#3D3E45"}),n.jsx("path",{d:"M9.84418 8.37166C9.94816 8.37166 10.0348 8.40631 10.1041 8.47563C10.1734 8.54494 10.2081 8.63159 10.2081 8.73556C10.2081 8.8352 10.1734 8.91968 10.1041 8.989C10.0348 9.05398 9.94816 9.08647 9.84418 9.08647H7.63475C7.52211 9.08647 7.4333 9.05182 7.36832 8.9825C7.30334 8.91318 7.27084 8.82437 7.27084 8.71607C7.27084 8.60776 7.30983 8.51245 7.38781 8.43014L8.80445 6.91603C8.96474 6.74274 9.09038 6.56512 9.18135 6.38317C9.27666 6.20121 9.32432 6.04309 9.32432 5.90879C9.32432 5.69218 9.2615 5.51889 9.13587 5.38892C9.01023 5.25462 8.84344 5.18747 8.63549 5.18747C8.55318 5.18747 8.4687 5.20697 8.38206 5.24596C8.29541 5.28495 8.21094 5.3391 8.12862 5.40842C8.05064 5.47773 7.977 5.55788 7.90768 5.64885C7.85569 5.71817 7.80371 5.76149 7.75172 5.77882C7.69973 5.79615 7.65208 5.80481 7.60876 5.80481C7.51345 5.80481 7.42464 5.77016 7.34233 5.70084C7.26435 5.62719 7.22536 5.54271 7.22536 5.44741C7.22536 5.37376 7.24918 5.30228 7.29684 5.23296C7.34882 5.16365 7.41164 5.09216 7.48529 5.01852C7.59359 4.91021 7.7149 4.8149 7.8492 4.73259C7.98349 4.65028 8.12213 4.58746 8.26509 4.54414C8.40805 4.49648 8.54668 4.47266 8.68098 4.47266C8.97124 4.47266 9.22251 4.53114 9.43479 4.64811C9.6514 4.76075 9.81819 4.92321 9.93516 5.13549C10.0521 5.34343 10.1106 5.59037 10.1106 5.8763C10.1106 6.11457 10.0391 6.381 9.89617 6.67559C9.75754 6.96585 9.56909 7.23878 9.33081 7.49438L8.50837 8.37166H9.84418Z",fill:"#3D3E45"}),n.jsx("path",{d:"M5.49994 9.08647C5.37864 9.08647 5.279 9.04965 5.20102 8.976C5.12304 8.89802 5.08405 8.80271 5.08405 8.69007V5.62518L4.70065 5.90879C4.64 5.95644 4.56418 5.98027 4.47321 5.98027C4.36923 5.98027 4.27826 5.94128 4.20028 5.8633C4.1223 5.78532 4.08331 5.69218 4.08331 5.58387C4.08331 5.44524 4.15046 5.3326 4.28475 5.24596L5.22051 4.62212C5.26384 4.59179 5.31149 4.57013 5.36348 4.55713C5.4198 4.54414 5.47178 4.53764 5.51944 4.53764C5.64507 4.53764 5.74471 4.57663 5.81836 4.65461C5.89201 4.72826 5.92883 4.8214 5.92883 4.93404V8.69007C5.92883 8.80271 5.88768 8.89802 5.80536 8.976C5.72738 9.04965 5.62558 9.08647 5.49994 9.08647Z",fill:"#3D3E45"})]}),z3=()=>n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[n.jsx("path",{d:"M12.0334 5.64833C12.3099 5.64833 12.55 5.67744 12.7537 5.73565C12.9623 5.79386 13.1224 5.87632 13.2339 5.98303C13.3504 6.0849 13.4086 6.20859 13.4086 6.35412C13.4086 6.45113 13.3795 6.5433 13.3213 6.63061C13.263 6.71307 13.1782 6.7543 13.0666 6.7543C12.989 6.7543 12.9235 6.7446 12.8701 6.7252C12.8216 6.70094 12.778 6.67184 12.7392 6.63788C12.7004 6.60393 12.6543 6.5724 12.6009 6.54329C12.5524 6.51419 12.4772 6.49236 12.3754 6.47781C12.2783 6.45841 12.2056 6.44871 12.1571 6.44871C11.9097 6.44871 11.6987 6.50206 11.5241 6.60878C11.3543 6.7155 11.2233 6.86102 11.1311 7.04535C11.039 7.22482 10.9929 7.43341 10.9929 7.67109C10.9929 7.90393 11.039 8.11251 11.1311 8.29684C11.2282 8.47631 11.3591 8.61941 11.5241 8.72613C11.6938 8.83284 11.8879 8.8862 12.1061 8.8862C12.2274 8.8862 12.3317 8.87893 12.419 8.86437C12.5063 8.84982 12.5791 8.82799 12.6373 8.79889C12.7052 8.76008 12.7658 8.71885 12.8192 8.6752C12.8726 8.63154 12.9526 8.60971 13.0593 8.60971C13.1854 8.60971 13.2824 8.65094 13.3504 8.7334C13.4183 8.81102 13.4522 8.90803 13.4522 9.02445C13.4522 9.14572 13.3843 9.25728 13.2485 9.35915C13.1127 9.45616 12.9332 9.5362 12.7101 9.59926C12.4918 9.65747 12.2541 9.68657 11.997 9.68657C11.6138 9.68657 11.2815 9.59926 11.0002 9.42463C10.7188 9.24516 10.5005 9.00262 10.3453 8.69702C10.1949 8.39143 10.1198 8.04945 10.1198 7.67109C10.1198 7.27333 10.1998 6.92408 10.3599 6.62333C10.5248 6.31774 10.7504 6.08005 11.0366 5.91027C11.3276 5.73565 11.6599 5.64833 12.0334 5.64833Z",fill:"#3D3E45"}),n.jsx("path",{d:"M7.74826 5.64833C8.08781 5.64833 8.39099 5.73565 8.65778 5.91027C8.92942 6.08005 9.14285 6.31531 9.29807 6.61606C9.45815 6.9168 9.53819 7.26606 9.53819 7.66382C9.53819 8.06158 9.45815 8.41326 9.29807 8.71885C9.14285 9.0196 8.93184 9.25728 8.66505 9.43191C8.40311 9.60169 8.10722 9.68657 7.77737 9.68657C7.58334 9.68657 7.40143 9.65505 7.23166 9.59199C7.06188 9.52893 6.91151 9.44889 6.78054 9.35187C6.65442 9.25486 6.55498 9.15784 6.48222 9.06083C6.41431 8.95896 6.38035 8.87408 6.38035 8.80617L6.60591 8.71158V9.24273C6.60591 9.36885 6.56468 9.47557 6.48222 9.56288C6.39976 9.64534 6.29547 9.68657 6.16935 9.68657C6.04323 9.68657 5.93894 9.64534 5.85647 9.56288C5.77401 9.48042 5.73278 9.3737 5.73278 9.24273V4.67333C5.73278 4.54722 5.77401 4.44292 5.85647 4.36046C5.93894 4.27315 6.04323 4.22949 6.16935 4.22949C6.29547 4.22949 6.39976 4.27315 6.48222 4.36046C6.56468 4.44292 6.60591 4.54722 6.60591 4.67333V6.52147L6.48222 6.45598C6.48222 6.39292 6.51617 6.31774 6.58408 6.23042C6.652 6.13826 6.74416 6.04852 6.86058 5.96121C6.97699 5.86904 7.11039 5.79386 7.26076 5.73565C7.41599 5.67744 7.57849 5.64833 7.74826 5.64833ZM7.63912 6.44871C7.42569 6.44871 7.23893 6.50206 7.07886 6.60878C6.91879 6.7155 6.79267 6.86102 6.7005 7.04535C6.61319 7.22482 6.56953 7.43098 6.56953 7.66382C6.56953 7.8918 6.61319 8.10038 6.7005 8.28956C6.79267 8.47389 6.91879 8.61941 7.07886 8.72613C7.23893 8.83285 7.42569 8.8862 7.63912 8.8862C7.85255 8.8862 8.03688 8.83285 8.19211 8.72613C8.35218 8.61941 8.47587 8.47389 8.56319 8.28956C8.65535 8.10038 8.70143 7.8918 8.70143 7.66382C8.70143 7.43098 8.65535 7.22482 8.56319 7.04535C8.47587 6.86102 8.35218 6.7155 8.19211 6.60878C8.03688 6.50206 7.85255 6.44871 7.63912 6.44871Z",fill:"#3D3E45"}),n.jsx("path",{d:"M3.02845 5.66289L1.45681 9.35915C1.42286 9.45131 1.3695 9.52408 1.29674 9.57743C1.22883 9.62594 1.15364 9.65019 1.07118 9.65019C0.940211 9.65019 0.843196 9.61381 0.780136 9.54105C0.717077 9.46829 0.685547 9.37855 0.685547 9.27184C0.685547 9.22818 0.692823 9.1821 0.707375 9.13359L2.51913 4.78248C2.55793 4.68546 2.61614 4.61028 2.69375 4.55692C2.77622 4.50356 2.86353 4.48173 2.95569 4.49143C3.04301 4.49143 3.12304 4.51811 3.19581 4.57147C3.27342 4.61998 3.3292 4.69031 3.36316 4.78248L5.15308 9.04628C5.17733 9.10934 5.18946 9.16755 5.18946 9.2209C5.18946 9.35187 5.1458 9.45616 5.05849 9.53378C4.97603 9.61139 4.88386 9.65019 4.782 9.65019C4.69468 9.65019 4.61465 9.62352 4.54189 9.57016C4.47398 9.5168 4.42062 9.44404 4.38181 9.35187L2.81745 5.70654L3.02845 5.66289ZM1.68237 8.47146L2.08256 7.63471H4.04711L4.18536 8.47146H1.68237Z",fill:"#3D3E45"})]}),D3=()=>n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[n.jsx("g",{clipPath:"url(#clip0_567_6919)",children:n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M7.00001 1.02051C7.29533 1.02051 7.53473 1.25991 7.53473 1.55523V2.99492L11.3486 5.17429C11.5152 5.2695 11.6181 5.44667 11.6181 5.63856V9.97475L13.0725 10.702C13.3366 10.834 13.4437 11.1552 13.3116 11.4194C13.1795 11.6835 12.8583 11.7906 12.5942 11.6585L11.1002 10.9115L7.26531 13.1028C7.10091 13.1968 6.8991 13.1968 6.73471 13.1028L2.89985 10.9115L1.40581 11.6585C1.14167 11.7906 0.820476 11.6835 0.688405 11.4194C0.556335 11.1552 0.663399 10.834 0.92754 10.702L2.38195 9.97475V5.63856C2.38195 5.44667 2.48477 5.2695 2.65138 5.17429L6.46529 2.99492V1.55523C6.46529 1.25991 6.70469 1.02051 7.00001 1.02051ZM7.00001 3.9211L3.99444 5.63856L7.00001 7.35603L10.0056 5.63856L7.00001 3.9211ZM10.5486 6.55999L7.53473 8.28221V11.7171L10.5486 9.99492V6.55999ZM6.46529 11.7171V8.28221L3.4514 6.55999V9.99492L6.46529 11.7171Z",fill:"#3D3E45"})}),n.jsx("defs",{children:n.jsx("clipPath",{id:"clip0_567_6919",children:n.jsx("rect",{width:"14",height:"14",fill:"white"})})})]}),Wa=({type:e})=>{switch(e){case"boolean":return n.jsx(S3,{});case"date":return n.jsx(T3,{});case"number":return n.jsx(k3,{});case"string":return n.jsx(z3,{});case"dimension":return n.jsx(D3,{});default:return null}},I3={option:{fontFamily:"monospace","&.sub-option":{position:"relative",marginLeft:"22px"},"&.sub-option::before":{content:'""',width:"1px",height:"100%",position:"absolute",left:"-6px",borderLeft:"1px solid #E7E7E9"}},groupLabel:{cursor:"default",fontWeight:"normal","&::before":{content:'""',flex:1,insetInline:0,height:"calc(0.0625rem* var(--mantine-scale))",marginInlineEnd:"var(--mantine-spacing-xs)",borderBottom:"1px dashed var(--mantine-color-gray-2)"},"&::after":{borderBottom:"1px dashed var(--mantine-color-gray-2)",background:"none"}},group:{"&.dimension-group":{paddingBottom:"4px",".mantine-Combobox-groupLabel":{color:"#000"},".mantine-Combobox-groupLabel::before":{display:"none"},".mantine-Combobox-groupLabel::after":{display:"none"}}}},M3={root:{maxWidth:"unset"},option:{fontFamily:"monospace"},input:{paddingInlineStart:"var(--input-padding-inline-start)",height:"auto",color:"black",fontFamily:"monospace"}},Uc=(e,t,r)=>{const a=[];return t&&a.push("sub-option"),r&&a.push("disabled"),n.jsx(s.Combobox.Option,{value:e.value,className:a.join(" "),disabled:r,children:n.jsxs(s.Stack,{gap:1,children:[n.jsxs(s.Group,{gap:4,children:[!!e.dataType&&n.jsx(Wa,{type:e.dataType}),n.jsx(s.Text,{size:"xs",children:e.label})]}),n.jsx(s.Text,{size:"xs",c:"dimmed",pl:18,children:e.description})]})},e.value)},Yc=T.observer(({mmInfo:e,value:t,onChange:r,usedKeys:a})=>{const l=e.metricDetail,o=e.metrics.loading||l.loading,i=l.error,c=l.filterColOptions,d=s.useCombobox({onDropdownClose:()=>d.resetSelectedOption()}),u=h.useMemo(()=>o?n.jsx(s.Loader,{size:"xs"}):t?n.jsx(s.CloseButton,{size:"xs",onClick:()=>r(null)}):n.jsx(s.Combobox.Chevron,{size:"xs"}),[o,t]),p=n.jsx(s.InputBase,{component:"button",type:"button",variant:"unstyled",size:"xs",pointer:!0,rightSection:u,rightSectionPointerEvents:!o&&t?"all":"none",onClick:()=>d.toggleDropdown(),disabled:o||c.length===0,styles:M3,error:!!i,children:t||n.jsx(s.Input.Placeholder,{children:"选择维度"})});return n.jsxs(s.Combobox,{store:d,onOptionSubmit:f=>{r(f),d.closeDropdown()},styles:I3,children:[n.jsx(s.Combobox.Target,{children:i?n.jsx(s.Tooltip,{label:i,children:p}):p}),n.jsx(s.Combobox.Dropdown,{miw:300,children:n.jsx(s.Combobox.Options,{mah:500,style:{overflowY:"auto"},children:c.map(({group:f,items:v})=>n.jsx(s.Combobox.Group,{label:f,children:v.map(_=>{var w;return"group"in _?n.jsx(s.Combobox.Group,{className:"dimension-group",label:n.jsxs(s.Group,{gap:4,children:[n.jsx(Wa,{type:"dimension"}),n.jsx(s.Text,{size:"sm",children:_.group}),n.jsx(s.Text,{size:"xs",c:"dimmed",children:_.description})]}),children:(w=_.items)==null?void 0:w.map(m=>Uc(m,!0,a.has(m.value)))},_.group):Uc(_,!1,a.has(_.value))})},f))})})]})}),Kc={tbody:{td:{fontFamily:"monospace"}}},A3={root:{maxWidth:"unset"},option:{fontFamily:"monospace","&[data-checked=true][data-combobox-disabled]":{opacity:1}},input:{fontFamily:"monospace"},groupLabel:{"&::before":{content:'""',flex:1,insetInline:0,height:"calc(0.0625rem* var(--mantine-scale))",marginInlineEnd:"var(--mantine-spacing-xs)",backgroundColor:"var(--mantine-color-gray-2)"}}},P3=({option:e,...t})=>{const{t:r}=x.useTranslation(),a=e,l=a.type==="filter";return n.jsxs(s.Stack,{gap:0,py:4,styles:{root:{flexGrow:1,'&[data-selected="true"]':{".mantine-Text-root":{color:"white"},svg:{stroke:"white"}}}},...t,children:[n.jsx(s.Group,{flex:"1",gap:4,children:n.jsx(s.Text,{size:"xs",children:e.value})}),l&&n.jsxs(s.Group,{justify:"space-between",wrap:"nowrap",children:[n.jsx(s.Text,{size:"xs",c:t.checked?"rgba(255,255,255,.8)":"dimmed",style:{flexShrink:1,flexGrow:1},children:a.widget_label}),n.jsx(s.Text,{size:"xs",c:t.checked?"rgba(255,255,255,.8)":"dimmed",style:{flexShrink:0,flexGrow:0},children:r(st[a.widget])})]})]})},Pn=T.observer(({queryModel:e,value:t,onChange:r,usedKeys:a})=>{const{t:l}=x.useTranslation();e.config;const o=h.useMemo(()=>e.getConditionOptionsWithInvalidValue(t).optionGroups.map(d=>{const u=d.items.length;return{group:`${l(d.group)}(${u})`,items:d.items.map(f=>({...f,label:f.value,widget_label:f.label,disabled:a==null?void 0:a.has(f.value)}))}}),[e.getConditionOptionsWithInvalidValue,l,t,a]),i=h.useCallback((c,d)=>{r(c,d)},[r]);return n.jsx(s.Select,{size:"xs",variant:"unstyled",placeholder:"选择变量",styles:A3,data:o,renderOption:P3,maxDropdownHeight:600,value:t,onChange:i,clearable:!0})}),Ua=T.observer(({variable:e})=>{const t=W();if(!e)return null;const r=y.has(t.queryVariables,e);return n.jsx(s.ThemeIcon,{variant:"white",size:"xs",color:r?"#88CE98":"#F15050",styles:{root:{flexGrow:0,flexShrink:0}},children:n.jsx(S.IconPointFilled,{})})}),V3=T.observer(({queryModel:e})=>{const t=e.config,a=e.datasource.mericoMetricInfo;return h.useEffect(()=>{a.selectMetric(t.id)},[t.id,a]),n.jsxs(s.Stack,{gap:7,children:[n.jsxs(s.Group,{justify:"flex-start",gap:8,children:[n.jsx(s.Text,{size:"sm",children:"看板变量与指标维度关联"}),n.jsx(s.Tooltip,{label:"将看板的筛选器参数与指标的查询维度关联上,使指标可以按照看板的筛选条件和背景变量进行关联展示。",children:n.jsx(s.ActionIcon,{size:"xs",variant:"subtle",color:"gray",children:n.jsx(S.IconInfoCircle,{})})})]}),n.jsxs(s.Table,{withTableBorder:!0,withColumnBorders:!0,layout:"fixed",styles:Kc,children:[n.jsxs("colgroup",{children:[n.jsx("col",{style:{width:"49%"}}),n.jsx("col",{}),n.jsx("col",{style:{width:130}}),n.jsx("col",{style:{width:40}})]}),n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:"指标筛选维度"}),n.jsx(s.Table.Td,{children:"看板变量"}),n.jsx(s.Table.Td,{colSpan:2,children:"变量值为真时运行查询"})]})}),n.jsxs(s.Table.Tbody,{children:[t.filters.map(l=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{pr:0,children:n.jsx(Yc,{mmInfo:a,value:l.dimension,onChange:l.setDimension,usedKeys:t.usedFilterDimensionKeys})}),n.jsx(s.Table.Td,{colSpan:2,pr:0,children:n.jsxs(s.Group,{justify:"flex-start",grow:!0,gap:0,w:"100%",children:[n.jsx(Ua,{variable:l.variable}),n.jsx(Pn,{queryModel:e,value:l.variable,onChange:l.setVariable})]})}),n.jsx(s.Table.Td,{children:n.jsx(s.Checkbox,{size:"xs",checked:e.keyInRunBy(l.variable),onChange:o=>e.changeRunByRecord(l.variable,o.currentTarget.checked),color:"red"})})]},l.dimension)),n.jsxs(s.Table.Tr,{className:"add-a-row",children:[n.jsx(s.Table.Td,{pr:0,children:n.jsx(Yc,{mmInfo:a,value:null,onChange:l=>l&&t.addFilter(l,""),usedKeys:t.usedFilterDimensionKeys})}),n.jsx(s.Table.Td,{colSpan:2,pr:0,children:n.jsx(Pn,{queryModel:e,value:null,onChange:l=>l&&t.addFilter("",l)})}),n.jsx(s.Table.Td,{})]})]})]})]})}),$3=T.observer(({queryModel:e,variable:t})=>{const r=e.keyInRunBy(t),a=l=>{e.changeRunByRecord(t,l.currentTarget.checked)};return n.jsx(s.Checkbox,{size:"xs",checked:r,onChange:a,color:"red"})}),Xc=({queryModel:e,variable:t})=>t?n.jsx($3,{queryModel:e,variable:t}):null,E3=T.observer(({queryModel:e})=>{const t=e.config,l=e.datasource.mericoMetricInfo.metricDetail,o=l.trendingDateCol,i=t.timeQuery.enabled;return h.useEffect(()=>{if(!i&&l.requireTrendingReason){t.setTimeQueryEnabled(!0);return}},[l.requireTrendingReason,i]),l.supportTrending?l.requireTrendingReason?n.jsx(s.Tooltip,{label:l.requireTrendingReason,children:n.jsx(s.Box,{children:n.jsx(s.Switch,{size:"xs",color:"red",checked:!0,readOnly:!0,styles:{track:{cursor:"not-allowed"}}})})}):n.jsx(s.Switch,{size:"xs",color:"red",checked:i,onChange:c=>t.setTimeQueryEnabled(c.currentTarget.checked),styles:{track:{cursor:"pointer"}}}):n.jsx(s.Tooltip,{label:"由于指标未设定时序维度,所以不具备时间序列展示功能。",children:n.jsx(s.Box,{children:n.jsx(s.Switch,{size:"xs",color:"red",disabled:!o})})})}),B3=T.observer(({queryModel:e})=>{const t=e.config,l=e.datasource.mericoMetricInfo.metricDetail,o=l.trendingDateCol;return!t.timeQuery.enabled||!l.supportTrending?null:n.jsxs(s.Table,{withTableBorder:!0,withColumnBorders:!0,layout:"fixed",styles:Kc,children:[n.jsxs("colgroup",{children:[n.jsx("col",{style:{width:250}}),n.jsx("col",{}),n.jsx("col",{style:{width:130}}),n.jsx("col",{style:{width:40}})]}),n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{}),n.jsx(s.Table.Td,{children:"看板变量"}),n.jsx(s.Table.Td,{colSpan:2,children:"变量值为真时运行查询"})]})}),n.jsxs(s.Table.Tbody,{children:[n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{pr:0,children:n.jsxs(s.Group,{gap:4,children:[n.jsx(s.Text,{size:"xs",children:"时间维度"}),n.jsx(s.Text,{size:"xs",c:"dimmed",ff:"monospace",children:(o==null?void 0:o.name)??null})]})}),n.jsx(s.Table.Td,{colSpan:2,pr:0,children:n.jsxs(s.Group,{justify:"flex-start",gap:0,grow:!0,children:[n.jsx(Ua,{variable:t.timeQuery.range_variable}),n.jsx(Pn,{queryModel:e,value:t.timeQuery.range_variable,onChange:t.setRangeVariable,usedKeys:t.usedTimeQueryVariableSet})]})}),n.jsx(s.Table.Td,{children:n.jsx(Xc,{queryModel:e,variable:t.timeQuery.range_variable})})]},"dimension.time"),n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:n.jsx(s.Text,{size:"xs",children:"步长"})}),n.jsx(s.Table.Td,{colSpan:2,pr:0,children:n.jsxs(s.Group,{justify:"flex-start",gap:0,grow:!0,children:[n.jsx(Ua,{variable:t.timeQuery.unit_variable}),n.jsx(Pn,{queryModel:e,value:t.timeQuery.unit_variable,onChange:t.setUnitVariable,usedKeys:t.usedTimeQueryVariableSet})]})}),n.jsx(s.Table.Td,{children:n.jsx(Xc,{queryModel:e,variable:t.timeQuery.unit_variable})})]},"dimension.step")]})]})}),L3=T.observer(({queryModel:e})=>n.jsxs(s.Stack,{gap:7,children:[n.jsxs(s.Group,{justify:"flex-start",gap:8,children:[n.jsx(s.Text,{size:"sm",children:"按时间序列展示"}),n.jsx(s.Tooltip,{label:"将看板的时间&步长筛选器与相应的查询维度关联上。",children:n.jsx(s.ActionIcon,{size:"xs",variant:"subtle",color:"gray",children:n.jsx(S.IconInfoCircle,{})})}),n.jsx(E3,{queryModel:e})]}),n.jsx(B3,{queryModel:e})]})),q3={label:{fontWeight:"normal"},input:{fontSize:"12px"},groupLabel:{cursor:"default",fontWeight:"normal","&::before":{content:'""',flex:1,insetInline:0,height:"calc(0.0625rem* var(--mantine-scale))",marginInlineEnd:"var(--mantine-spacing-xs)",borderBottom:"1px dashed var(--mantine-color-gray-2)"},"&::after":{borderBottom:"1px dashed var(--mantine-color-gray-2)",background:"none"}},option:{fontFamily:"monospace"}},O3=e=>{const t=e.option;return n.jsxs(s.Stack,{gap:1,styles:{root:{flexGrow:1}},children:[n.jsxs(s.Group,{gap:4,children:[n.jsx(Wa,{type:t.dataType}),n.jsx(s.Text,{size:"xs",children:t.label})]}),n.jsx(s.Text,{size:"xs",c:"dimmed",pl:18,children:t.description})]})},N3=T.observer(({queryModel:e})=>{const t=e.config,a=e.datasource.mericoMetricInfo,l=a.metricDetail,o=a.metrics.loading||l.loading,i=l.groupByColOptions,c=d=>{const u=l.getGroupByOptions(d),p=[];u.forEach(f=>{f.dimension?f.dimension.fields.forEach(v=>{typeof v=="string"?p.push(`${f.value} -> ${v}`):p.push(`${f.value} -> ${v.field}`)}):p.push(f.value)}),t.setGroupBys(p)};return n.jsx(s.MultiSelect,{size:"sm",label:"分组聚合维度",description:"指标在查询时按照哪些维度进行聚合计算。最多支持两个维度的聚合计算。若选择按时间序列展示,则仅可选择一个聚合维度。",data:i,searchable:!0,styles:q3,renderOption:O3,rightSection:o?n.jsx(s.Loader,{size:"xs"}):null,value:[...t.groupByValues],onChange:c,maxValues:t.timeQuery.enabled?1:2,placeholder:t.timeQuery.enabled?"仅可选一个维度":"最多选两个维度",disabled:o})}),G3=T.observer(({queryModel:e})=>{const t=e.config,r=t.id;return h.useEffect(()=>{if(e.run_by.length===0)return;const a=[],l=t.usedFilterVariableSet,o=t.usedTimeQueryVariableSet;e.run_by.forEach(i=>{(l.has(i)||o.has(i))&&a.push(i)}),e.setRunBy(a)},[t.usedFilterVariableSet,t.usedTimeQueryVariableSet,e.run_by]),n.jsxs(s.Stack,{gap:16,pos:"relative",children:[!r&&n.jsx(s.Overlay,{color:"#fff",backgroundOpacity:.5,blur:3,children:n.jsx(s.Center,{h:"100%",children:n.jsx(s.Text,{size:"sm",c:"black",children:"请先选择指标"})})}),n.jsx(V3,{queryModel:e}),n.jsx(L3,{queryModel:e}),n.jsx(N3,{queryModel:e})]})}),F3=["function process_result(resp, utils, state) {"," return resp.data","}"].join(`
|
|
571
|
+
`),post:""},c3=T.observer(({queryModel:e})=>{const{t}=x.useTranslation(),r=F();if(!e.isTransform)return null;const a=e.config;return n.jsxs(s.Stack,{py:20,px:20,sx:{height:"100%"},children:[n.jsx(s.Text,{size:"sm",children:t("query.transform.guide.pick_queries")}),n.jsx(s.MultiSelect,{data:r.queries.optionsWithoutTransform,value:[...a.dep_query_ids],onChange:a.setDependantQueryIDs,maxDropdownHeight:800}),n.jsx(s.Text,{size:"sm",children:t("query.transform.guide.write_function")}),n.jsx(s.Box,{sx:{flexGrow:1},children:n.jsx(xt,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:i3.pre})})]})}),Kt={height:"calc(100% - 44px)",padding:0},d3=T.observer(({queryModel:e})=>{const{t}=x.useTranslation(),r=F(),a=h.useMemo(()=>e.datasource?e.typedAsHTTP?"HTTP":"SQL":"Configurations",[e.datasource,e.typedAsHTTP]),[l,o]=h.useState(a);h.useEffect(()=>{o(d=>d!=="Configurations"&&a==="Configurations"?"Configurations":d)},[a]);const c=r.findQueryUsage(e.id).length===0;return n.jsxs(s.Tabs,{value:l,onChange:o,defaultValue:a,orientation:"horizontal",keepMounted:!1,sx:{height:"100vh"},children:[n.jsxs(s.Tabs.List,{grow:!0,children:[n.jsx(s.Tabs.Tab,{value:"Configurations",children:t("query.configurations")}),e.typedAsSQL&&n.jsx(s.Tabs.Tab,{value:"SQL",children:t("query.request")}),e.typedAsHTTP&&n.jsx(s.Tabs.Tab,{value:"HTTP",children:t("query.request")}),e.isTransform&&n.jsx(s.Tabs.Tab,{value:"Transform",children:t("query.transform.label")}),n.jsx(s.Tabs.Tab,{value:"Data",disabled:!e.canPreviewData,children:n.jsx(s.Tooltip,{label:e.guideToPreviewData,disabled:e.canPreviewData,withinPortal:!0,children:n.jsx(s.Text,{size:"sm",children:t("data.preview_data")})})}),n.jsx(s.Tabs.Tab,{value:"Usage",disabled:c,children:n.jsx(s.Tooltip,{label:t("query.usage.unused_description"),disabled:!c,withinPortal:!0,children:n.jsx(s.Text,{size:"sm",children:t("query.usage.label")})})})]}),n.jsx(s.Tabs.Panel,{value:"Configurations",pt:0,p:0,children:n.jsx(Jz,{queryModel:e})}),e.typedAsSQL&&n.jsx(s.Tabs.Panel,{value:"SQL",sx:Kt,children:n.jsx(s.Stack,{sx:{height:"100%"},children:n.jsx(o3,{queryModel:e})})}),e.typedAsHTTP&&n.jsx(s.Tabs.Panel,{value:"HTTP",sx:Kt,children:n.jsx(s.Stack,{sx:{height:"100%"},children:n.jsx(t3,{queryModel:e})})}),e.isTransform&&n.jsx(s.Tabs.Panel,{value:"Transform",sx:Kt,children:n.jsx(s.Stack,{sx:{height:"100%"},children:n.jsx(c3,{queryModel:e})})}),n.jsx(s.Tabs.Panel,{value:"Data",sx:{...Kt,overflow:"hidden"},children:n.jsx(Ga,{id:e.id,moreActions:null,refreshOnMount:!0})}),n.jsx(s.Tabs.Panel,{value:"Usage",py:"sm",px:"md",sx:{...Kt,overflow:"hidden"},children:n.jsx(Fc,{queryModel:e})})]})}),u3=({width:e,height:t})=>n.jsxs("svg",{width:e,height:t,viewBox:"0 0 36 36",fill:"none",children:[n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M7.5 10.5C7.10217 10.5 6.72064 10.658 6.43934 10.9393C6.15804 11.2206 6 11.6022 6 12V28.5C6 28.8978 6.15804 29.2794 6.43934 29.5607C6.72064 29.842 7.10218 30 7.5 30H24C24.3978 30 24.7794 29.842 25.0607 29.5607C25.342 29.2794 25.5 28.8978 25.5 28.5V19.5C25.5 18.6716 26.1716 18 27 18C27.8284 18 28.5 18.6716 28.5 19.5V28.5C28.5 29.6935 28.0259 30.8381 27.182 31.682C26.3381 32.5259 25.1935 33 24 33H7.5C6.30653 33 5.16193 32.5259 4.31802 31.682C3.47411 30.8381 3 29.6935 3 28.5V12C3 10.8065 3.47411 9.66193 4.31802 8.81802C5.16193 7.97411 6.30653 7.5 7.5 7.5H16.5C17.3284 7.5 18 8.17157 18 9C18 9.82843 17.3284 10.5 16.5 10.5H7.5Z",fill:"#3D3E45"}),n.jsx("path",{d:"M32.8862 3.92582C32.8135 3.75021 32.7061 3.5856 32.5638 3.44253C32.5617 3.4404 32.5596 3.43828 32.5575 3.43616C32.2863 3.16658 31.9126 3 31.5 3H22.5C21.6716 3 21 3.67157 21 4.5C21 5.32843 21.6716 6 22.5 6H27.8787L13.9393 19.9393C13.3536 20.5251 13.3536 21.4749 13.9393 22.0607C14.5251 22.6464 15.4749 22.6464 16.0607 22.0607L30 8.12132V13.5C30 14.3284 30.6716 15 31.5 15C32.3284 15 33 14.3284 33 13.5V4.5C33 4.29662 32.9595 4.10268 32.8862 3.92582Z",fill:"#3D3E45"})]}),Qc=({width:e,height:t,color:r="#FFFFFF"})=>n.jsxs("svg",{viewBox:"0 0 36 36",fill:"none",width:e,height:t,children:[n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M24.6931 20.547C26.1129 19.5516 26.113 17.4483 24.6931 16.4529L16.9351 11.0141C15.2783 9.85255 13 11.0377 13 13.0611L13 23.9389C13 25.9623 15.2783 27.1474 16.9351 25.9859L24.6931 20.547ZM16 14.0223L22.387 18.5L16 22.9777L16 14.0223Z",fill:r}),n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M18 1.5C8.8873 1.5 1.5 8.8873 1.5 18C1.5 27.1127 8.8873 34.5 18 34.5C27.1127 34.5 34.5 27.1127 34.5 18C34.5 8.8873 27.1127 1.5 18 1.5ZM4.5 18C4.5 10.5442 10.5442 4.5 18 4.5C25.4558 4.5 31.5 10.5442 31.5 18C31.5 25.4558 25.4558 31.5 18 31.5C10.5442 31.5 4.5 25.4558 4.5 18Z",fill:r})]}),Wc=({width:e,height:t,color:r="#EB1212"})=>n.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",width:e,height:t,children:[n.jsx("path",{d:"M6.66665 6.66699C7.03484 6.66699 7.33331 6.96547 7.33331 7.33366V11.3337C7.33331 11.7018 7.03484 12.0003 6.66665 12.0003C6.29846 12.0003 5.99998 11.7018 5.99998 11.3337V7.33366C5.99998 6.96547 6.29846 6.66699 6.66665 6.66699Z",fill:r}),n.jsx("path",{d:"M9.99998 11.3337V7.33366C9.99998 6.96547 9.7015 6.66699 9.33331 6.66699C8.96512 6.66699 8.66665 6.96547 8.66665 7.33366V11.3337C8.66665 11.7018 8.96512 12.0003 9.33331 12.0003C9.7015 12.0003 9.99998 11.7018 9.99998 11.3337Z",fill:r}),n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M4.66665 3.33366V2.66699C4.66665 2.13656 4.87736 1.62785 5.25243 1.25278C5.62751 0.877706 6.13621 0.666992 6.66665 0.666992H9.33331C9.86375 0.666992 10.3725 0.877706 10.7475 1.25278C11.1226 1.62785 11.3333 2.13656 11.3333 2.66699V3.33366H14C14.3682 3.33366 14.6666 3.63214 14.6666 4.00033C14.6666 4.36852 14.3682 4.66699 14 4.66699H13.3333V13.3337C13.3333 13.8641 13.1226 14.3728 12.7475 14.7479C12.3725 15.1229 11.8637 15.3337 11.3333 15.3337H4.66665C4.13621 15.3337 3.62751 15.1229 3.25243 14.7479C2.87736 14.3728 2.66665 13.8641 2.66665 13.3337V4.66699H1.99998C1.63179 4.66699 1.33331 4.36852 1.33331 4.00033C1.33331 3.63214 1.63179 3.33366 1.99998 3.33366H4.66665ZM6.19524 2.19559C6.32027 2.07056 6.48984 2.00033 6.66665 2.00033H9.33331C9.51012 2.00033 9.67969 2.07056 9.80472 2.19559C9.92974 2.32061 9.99998 2.49018 9.99998 2.66699V3.33366H5.99998V2.66699C5.99998 2.49018 6.07022 2.32061 6.19524 2.19559ZM3.99998 4.66699V13.3337C3.99998 13.5105 4.07022 13.68 4.19524 13.8051C4.32027 13.9301 4.48984 14.0003 4.66665 14.0003H11.3333C11.5101 14.0003 11.6797 13.9301 11.8047 13.8051C11.9297 13.68 12 13.5105 12 13.3337V4.66699H3.99998Z",fill:r})]}),p3=({width:e,height:t})=>n.jsxs("svg",{viewBox:"0 0 18 18",fill:"none",width:e,height:t,children:[n.jsx("path",{d:"M7.5 3.75C7.5 2.92157 8.17157 2.25 9 2.25C9.82843 2.25 10.5 2.92157 10.5 3.75C10.5 4.57843 9.82843 5.25 9 5.25C8.17157 5.25 7.5 4.57843 7.5 3.75Z",fill:"#3D3E45"}),n.jsx("path",{d:"M7.5 9C7.5 8.17157 8.17157 7.5 9 7.5C9.82843 7.5 10.5 8.17157 10.5 9C10.5 9.82843 9.82843 10.5 9 10.5C8.17157 10.5 7.5 9.82843 7.5 9Z",fill:"#3D3E45"}),n.jsx("path",{d:"M9 12.75C8.17157 12.75 7.5 13.4216 7.5 14.25C7.5 15.0784 8.17157 15.75 9 15.75C9.82843 15.75 10.5 15.0784 10.5 14.25C10.5 13.4216 9.82843 12.75 9 12.75Z",fill:"#3D3E45"})]}),h3=T.observer(({queryModel:e})=>{const{t}=x.useTranslation(),r=W(),a=F(),o=a.findQueryUsage(e.id).length>0,i=ze.useModals(),c=()=>{i.openConfirmModal({title:`${t("query.delete")}?`,labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{a.queries.removeQuery(e.id),r.editor.setPath(["_QUERIES_",""])},confirmProps:{color:"red"},zIndex:320})};return o?n.jsx(s.Tooltip,{label:"此查询在使用中,不能删除。请查看“使用情况”标签页以了解详情",withArrow:!0,events:{hover:!0,focus:!1,touch:!1},withinPortal:!0,zIndex:320,position:"bottom-end",children:n.jsx(s.Button,{leftSection:n.jsx(Wc,{width:14,height:14,color:"gray"}),variant:"subtle",color:"gray",onClick:d=>{d.stopPropagation()},children:"删除查询"})}):n.jsx(s.Menu.Item,{leftSection:n.jsx(Wc,{width:14,height:14}),color:"red",onClick:c,children:"删除查询"})}),g3=T.observer(({queryModel:e})=>n.jsxs(s.Menu,{shadow:"md",width:120,trigger:"hover",children:[n.jsx(s.Menu.Target,{children:n.jsx(s.ActionIcon,{variant:"subtle","aria-label":"Settings",children:n.jsx(p3,{width:18,height:18})})}),n.jsx(s.Menu.Dropdown,{children:n.jsx(h3,{queryModel:e})})]})),f3={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",backgroundColor:"rgb(248, 249, 250)"},"@media (hover: hover)":{".resizer":{opacity:"0"},"*:hover > .resizer":{color:"#228be6",opacity:"1"}}};function b3({data:e}){const t=h.useMemo(()=>{if(!Array.isArray(e)||e.length===0)return[];const a=ge.createColumnHelper();return Object.keys(e[0]).map(l=>a.accessor(l,{cell:o=>o.getValue()}))},[e]),r=ge.useReactTable({data:e,columns:t,columnResizeMode:"onChange",getCoreRowModel:ge.getCoreRowModel()});return e.length===0?n.jsx(s.Box,{sx:{height:"5em"}}):n.jsx(ne,{children:n.jsxs(s.Table,{sx:f3,stickyHeader:!0,stickyHeaderOffset:0,children:[n.jsx(s.Table.Thead,{style:{backgroundColor:"#F9F9FA"},children:r.getHeaderGroups().map(a=>n.jsx(s.Table.Tr,{children:a.headers.map(l=>n.jsxs(s.Table.Th,{style:{width:l.getSize()},children:[l.isPlaceholder?null:ge.flexRender(l.column.columnDef.header,l.getContext()),n.jsx(s.ActionIcon,{variant:"subtle",onMouseDown:l.getResizeHandler(),onTouchStart:l.getResizeHandler(),className:`resizer ${l.column.getIsResizing()?"isResizing":""}`,children:n.jsx(S.IconArrowBarToRight,{})})]},l.id))},a.id))}),n.jsx(s.Table.Tbody,{children:r.getRowModel().rows.map(a=>n.jsx(s.Table.Tr,{children:a.getVisibleCells().map(l=>n.jsx(s.Table.Td,{children:n.jsx(ne,{children:typeof l.getValue()=="object"?n.jsx("pre",{children:JSON.stringify(l.getValue(),null,2)}):ge.flexRender(l.column.columnDef.cell,l.getContext())})},l.id))},a.id))})]})})}const y3=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],v3={root:{width:"150px"},section:{"&[data-position=left]":{width:"70px",textAlign:"center"}},input:{paddingLeft:"70px",paddingRight:0}},_3=({data:e,page:t,setPage:r,limit:a,setLimit:l})=>{const{t:o}=x.useTranslation(),i=e.length,c=Math.ceil(i/a),d=p=>{p&&(r(1),l(Number(p)))};if(i===0)return null;const u=c===1&&i<=10;return n.jsxs(s.Group,{pt:10,px:10,justify:"space-between",children:[n.jsxs(s.Group,{justify:"flex-start",children:[!u&&n.jsx(s.Select,{leftSection:n.jsx(s.Text,{ta:"center",c:"dimmed",size:"xs",children:o("common.pagination.page_size")}),size:"xs",styles:v3,data:y3,value:String(a),onChange:d}),c>1&&n.jsx(s.Pagination,{size:"sm",value:t,onChange:r,total:c,withEdges:c>7,styles:{control:{height:"30px"}},color:"red"})]}),n.jsx(s.Group,{justify:"flex-end",children:n.jsx(s.Text,{c:"dimmed",my:0,size:"14px",children:o("common.pagination.total_rows",{total:i})})})]})},x3=ll(({data:e,loading:t})=>{const[r,a]=h.useState(1),[l,o]=h.useState(20),i=h.useMemo(()=>{const c=(r-1)*l,d=c+l;return e.slice(c,d)},[e,r,l]);return n.jsx(ne,{children:n.jsxs(s.Stack,{gap:10,styles:{root:{height:"100%",overflow:"hidden"}},children:[n.jsx(_3,{data:e,page:r,setPage:a,limit:l,setLimit:o}),n.jsxs(s.Box,{sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[n.jsx(s.LoadingOverlay,{visible:t,overlayProps:{blur:2}}),n.jsx(b3,{data:i})]})]})})}),w3=T.observer(({queryModel:e})=>{const{t}=x.useTranslation(),{state:r,error:a,metricQueryPayloadErrorString:l,stateMessage:o}=e;return r==="loading"?null:a?n.jsx(s.Text,{mt:10,c:"red",size:"md",ta:"center",ff:"monospace",children:a}):l?n.jsx(s.Text,{mt:10,c:"red",size:"md",ta:"center",ff:"monospace",children:l}):o?n.jsx(s.Text,{size:"sm",mt:10,c:"gray",ta:"center",children:t(o)}):null}),m3=T.observer(({queryModel:e})=>{x.useTranslation();const{data:t,state:r}=e,a=r==="loading",l=h.useCallback(()=>{e.fetchData(!0)},[e.fetchData]),o=()=>{yi(e.name,e.data)};h.useEffect(()=>{l()},[l]);const i=!Array.isArray(t)||t.length===0;return n.jsxs(s.Stack,{gap:0,sx:{maxHeight:"calc(50vh - 48px)",flexGrow:1,flexShrink:0,background:"#F9F9FA"},children:[n.jsxs(s.Group,{justify:"space-between",py:7,px:8,children:[n.jsx(s.Text,{size:"sm",fw:500,children:"查询结果"}),n.jsx(s.Button,{size:"xs",variant:"transparent",color:"gray",leftSection:n.jsx(S.IconDownload,{size:16}),disabled:a||i,onClick:o,children:"下载查询结果"})]}),n.jsxs(s.Box,{sx:{position:"relative",flexGrow:1,overflow:"hidden"},children:[n.jsx(w3,{queryModel:e}),n.jsx(x3,{data:t,loading:a})]})]})}),C3=T.observer(({queryModel:e})=>{const t=W();return n.jsxs(s.Tabs,{defaultValue:"看板变量预览",w:"40%",maw:"600px",styles:{root:{borderRadius:4,backgroundColor:"#F9F9FA",height:"100%",minHeight:"350px",maxHeight:"50vh",overflow:"hidden"},panel:{height:"calc(100% - 36px)"}},color:"red",children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"看板变量预览",children:"看板变量预览"}),n.jsx(s.Tabs.Tab,{value:"查询预览",children:"查询预览"})]}),n.jsx(s.Tabs.Panel,{value:"查询预览",children:n.jsx(Oe.CodeHighlight,{language:"json",sx:{width:"100%",height:"100%",minHeight:"400px",overflowY:"auto"},withCopyButton:!1,code:e.metricQueryPayloadString})}),n.jsx(s.Tabs.Panel,{value:"看板变量预览",children:n.jsx(Oe.CodeHighlight,{language:"json",sx:{width:"100%",height:"100%",minHeight:"400px",overflowY:"auto"},withCopyButton:!1,code:t.queryVariablesString})})]})}),S3=()=>n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M7.24335 1.62305C7.50108 1.62305 7.71001 1.83198 7.71001 2.08971L7.71001 11.423C7.71001 11.6808 7.50108 11.8897 7.24335 11.8897C6.98561 11.8897 6.77668 11.6808 6.77668 11.423L6.77668 2.08971C6.77668 1.83198 6.98561 1.62305 7.24335 1.62305Z",fill:"#3D3E45"}),n.jsx("path",{d:"M9.93845 9.4786C9.80779 9.4786 9.70045 9.43893 9.61645 9.3596C9.53712 9.2756 9.49745 9.17293 9.49745 9.0516L9.49745 5.0056C9.49745 4.88427 9.53712 4.78393 9.61645 4.7046C9.70045 4.6206 9.80312 4.5786 9.92445 4.5786L12.1995 4.5786C12.3208 4.5786 12.4211 4.61827 12.5005 4.6976C12.5845 4.77227 12.6265 4.87027 12.6265 4.9916C12.6265 5.09427 12.5845 5.18527 12.5005 5.2646C12.4211 5.34393 12.3208 5.3836 12.1995 5.3836L10.3725 5.3836V6.6156H11.8845C12.0058 6.6156 12.1061 6.65527 12.1855 6.7346C12.2695 6.80927 12.3115 6.90727 12.3115 7.0286C12.3115 7.13127 12.2695 7.22227 12.1855 7.3016C12.1061 7.38093 12.0058 7.4206 11.8845 7.4206H10.3725L10.3725 9.0516C10.3725 9.17293 10.3281 9.2756 10.2395 9.3596C10.1555 9.43893 10.0551 9.4786 9.93845 9.4786Z",fill:"#3D3E45"}),n.jsx("path",{d:"M3.34754 9.4786C3.21687 9.4786 3.10954 9.43893 3.02554 9.3596C2.94154 9.2756 2.89954 9.17293 2.89954 9.0516L2.89954 5.3836H1.80054C1.6792 5.3836 1.57654 5.34627 1.49254 5.2716C1.4132 5.19693 1.37354 5.09893 1.37354 4.9776C1.37354 4.85627 1.4132 4.7606 1.49254 4.6906C1.57654 4.61593 1.6792 4.5786 1.80054 4.5786H4.90854C5.02987 4.5786 5.1302 4.61593 5.20954 4.6906C5.29354 4.76527 5.33554 4.86327 5.33554 4.9846C5.33554 5.10593 5.29354 5.20393 5.20954 5.2786C5.1302 5.3486 5.02987 5.3836 4.90854 5.3836H3.80954L3.80954 9.0516C3.80954 9.17293 3.7652 9.2756 3.67654 9.3596C3.59254 9.43893 3.48287 9.4786 3.34754 9.4786Z",fill:"#3D3E45"})]}),T3=()=>n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[n.jsx("g",{clipPath:"url(#clip0_245_10828)",children:n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M9.91663 1.16634C9.91663 0.844175 9.65546 0.583008 9.33329 0.583008C9.01113 0.583008 8.74996 0.844175 8.74996 1.16634V1.74967L5.24996 1.74967V1.16634C5.24996 0.844175 4.98879 0.583008 4.66663 0.583008C4.34446 0.583008 4.08329 0.844175 4.08329 1.16634V1.74967H2.91663C1.95013 1.74967 1.16663 2.53318 1.16663 3.49967L1.16663 11.6663C1.16663 12.6328 1.95013 13.4163 2.91663 13.4163L11.0833 13.4163C12.0498 13.4163 12.8333 12.6328 12.8333 11.6663L12.8333 3.49967C12.8333 2.53318 12.0498 1.74967 11.0833 1.74967H9.91663V1.16634ZM11.6666 5.24967V3.49967C11.6666 3.17751 11.4055 2.91634 11.0833 2.91634H9.91663V3.49967C9.91663 3.82184 9.65546 4.08301 9.33329 4.08301C9.01113 4.08301 8.74996 3.82184 8.74996 3.49967V2.91634L5.24996 2.91634V3.49967C5.24996 3.82184 4.98879 4.08301 4.66663 4.08301C4.34446 4.08301 4.08329 3.82184 4.08329 3.49967V2.91634L2.91663 2.91634C2.59446 2.91634 2.33329 3.17751 2.33329 3.49967L2.33329 5.24967L11.6666 5.24967ZM2.33329 6.41634L11.6666 6.41634L11.6666 11.6663C11.6666 11.9885 11.4055 12.2497 11.0833 12.2497L2.91663 12.2497C2.59446 12.2497 2.33329 11.9885 2.33329 11.6663V6.41634Z",fill:"#3D3E45"})}),n.jsx("defs",{children:n.jsx("clipPath",{id:"clip0_245_10828",children:n.jsx("rect",{width:"14",height:"14",fill:"white"})})})]}),k3=()=>n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M3.11108 2.13932C2.78892 2.13932 2.52775 2.40049 2.52775 2.72266V10.8893C2.52775 11.2115 2.78892 11.4727 3.11108 11.4727H11.2778C11.5999 11.4727 11.8611 11.2115 11.8611 10.8893V2.72266C11.8611 2.40049 11.5999 2.13932 11.2778 2.13932H3.11108ZM1.36108 2.72266C1.36108 1.75616 2.14459 0.972656 3.11108 0.972656H11.2778C12.2442 0.972656 13.0278 1.75616 13.0278 2.72266V10.8893C13.0278 11.8558 12.2442 12.6393 11.2778 12.6393H3.11108C2.14459 12.6393 1.36108 11.8558 1.36108 10.8893V2.72266Z",fill:"#3D3E45"}),n.jsx("path",{d:"M9.84418 8.37166C9.94816 8.37166 10.0348 8.40631 10.1041 8.47563C10.1734 8.54494 10.2081 8.63159 10.2081 8.73556C10.2081 8.8352 10.1734 8.91968 10.1041 8.989C10.0348 9.05398 9.94816 9.08647 9.84418 9.08647H7.63475C7.52211 9.08647 7.4333 9.05182 7.36832 8.9825C7.30334 8.91318 7.27084 8.82437 7.27084 8.71607C7.27084 8.60776 7.30983 8.51245 7.38781 8.43014L8.80445 6.91603C8.96474 6.74274 9.09038 6.56512 9.18135 6.38317C9.27666 6.20121 9.32432 6.04309 9.32432 5.90879C9.32432 5.69218 9.2615 5.51889 9.13587 5.38892C9.01023 5.25462 8.84344 5.18747 8.63549 5.18747C8.55318 5.18747 8.4687 5.20697 8.38206 5.24596C8.29541 5.28495 8.21094 5.3391 8.12862 5.40842C8.05064 5.47773 7.977 5.55788 7.90768 5.64885C7.85569 5.71817 7.80371 5.76149 7.75172 5.77882C7.69973 5.79615 7.65208 5.80481 7.60876 5.80481C7.51345 5.80481 7.42464 5.77016 7.34233 5.70084C7.26435 5.62719 7.22536 5.54271 7.22536 5.44741C7.22536 5.37376 7.24918 5.30228 7.29684 5.23296C7.34882 5.16365 7.41164 5.09216 7.48529 5.01852C7.59359 4.91021 7.7149 4.8149 7.8492 4.73259C7.98349 4.65028 8.12213 4.58746 8.26509 4.54414C8.40805 4.49648 8.54668 4.47266 8.68098 4.47266C8.97124 4.47266 9.22251 4.53114 9.43479 4.64811C9.6514 4.76075 9.81819 4.92321 9.93516 5.13549C10.0521 5.34343 10.1106 5.59037 10.1106 5.8763C10.1106 6.11457 10.0391 6.381 9.89617 6.67559C9.75754 6.96585 9.56909 7.23878 9.33081 7.49438L8.50837 8.37166H9.84418Z",fill:"#3D3E45"}),n.jsx("path",{d:"M5.49994 9.08647C5.37864 9.08647 5.279 9.04965 5.20102 8.976C5.12304 8.89802 5.08405 8.80271 5.08405 8.69007V5.62518L4.70065 5.90879C4.64 5.95644 4.56418 5.98027 4.47321 5.98027C4.36923 5.98027 4.27826 5.94128 4.20028 5.8633C4.1223 5.78532 4.08331 5.69218 4.08331 5.58387C4.08331 5.44524 4.15046 5.3326 4.28475 5.24596L5.22051 4.62212C5.26384 4.59179 5.31149 4.57013 5.36348 4.55713C5.4198 4.54414 5.47178 4.53764 5.51944 4.53764C5.64507 4.53764 5.74471 4.57663 5.81836 4.65461C5.89201 4.72826 5.92883 4.8214 5.92883 4.93404V8.69007C5.92883 8.80271 5.88768 8.89802 5.80536 8.976C5.72738 9.04965 5.62558 9.08647 5.49994 9.08647Z",fill:"#3D3E45"})]}),z3=()=>n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[n.jsx("path",{d:"M12.0334 5.64833C12.3099 5.64833 12.55 5.67744 12.7537 5.73565C12.9623 5.79386 13.1224 5.87632 13.2339 5.98303C13.3504 6.0849 13.4086 6.20859 13.4086 6.35412C13.4086 6.45113 13.3795 6.5433 13.3213 6.63061C13.263 6.71307 13.1782 6.7543 13.0666 6.7543C12.989 6.7543 12.9235 6.7446 12.8701 6.7252C12.8216 6.70094 12.778 6.67184 12.7392 6.63788C12.7004 6.60393 12.6543 6.5724 12.6009 6.54329C12.5524 6.51419 12.4772 6.49236 12.3754 6.47781C12.2783 6.45841 12.2056 6.44871 12.1571 6.44871C11.9097 6.44871 11.6987 6.50206 11.5241 6.60878C11.3543 6.7155 11.2233 6.86102 11.1311 7.04535C11.039 7.22482 10.9929 7.43341 10.9929 7.67109C10.9929 7.90393 11.039 8.11251 11.1311 8.29684C11.2282 8.47631 11.3591 8.61941 11.5241 8.72613C11.6938 8.83284 11.8879 8.8862 12.1061 8.8862C12.2274 8.8862 12.3317 8.87893 12.419 8.86437C12.5063 8.84982 12.5791 8.82799 12.6373 8.79889C12.7052 8.76008 12.7658 8.71885 12.8192 8.6752C12.8726 8.63154 12.9526 8.60971 13.0593 8.60971C13.1854 8.60971 13.2824 8.65094 13.3504 8.7334C13.4183 8.81102 13.4522 8.90803 13.4522 9.02445C13.4522 9.14572 13.3843 9.25728 13.2485 9.35915C13.1127 9.45616 12.9332 9.5362 12.7101 9.59926C12.4918 9.65747 12.2541 9.68657 11.997 9.68657C11.6138 9.68657 11.2815 9.59926 11.0002 9.42463C10.7188 9.24516 10.5005 9.00262 10.3453 8.69702C10.1949 8.39143 10.1198 8.04945 10.1198 7.67109C10.1198 7.27333 10.1998 6.92408 10.3599 6.62333C10.5248 6.31774 10.7504 6.08005 11.0366 5.91027C11.3276 5.73565 11.6599 5.64833 12.0334 5.64833Z",fill:"#3D3E45"}),n.jsx("path",{d:"M7.74826 5.64833C8.08781 5.64833 8.39099 5.73565 8.65778 5.91027C8.92942 6.08005 9.14285 6.31531 9.29807 6.61606C9.45815 6.9168 9.53819 7.26606 9.53819 7.66382C9.53819 8.06158 9.45815 8.41326 9.29807 8.71885C9.14285 9.0196 8.93184 9.25728 8.66505 9.43191C8.40311 9.60169 8.10722 9.68657 7.77737 9.68657C7.58334 9.68657 7.40143 9.65505 7.23166 9.59199C7.06188 9.52893 6.91151 9.44889 6.78054 9.35187C6.65442 9.25486 6.55498 9.15784 6.48222 9.06083C6.41431 8.95896 6.38035 8.87408 6.38035 8.80617L6.60591 8.71158V9.24273C6.60591 9.36885 6.56468 9.47557 6.48222 9.56288C6.39976 9.64534 6.29547 9.68657 6.16935 9.68657C6.04323 9.68657 5.93894 9.64534 5.85647 9.56288C5.77401 9.48042 5.73278 9.3737 5.73278 9.24273V4.67333C5.73278 4.54722 5.77401 4.44292 5.85647 4.36046C5.93894 4.27315 6.04323 4.22949 6.16935 4.22949C6.29547 4.22949 6.39976 4.27315 6.48222 4.36046C6.56468 4.44292 6.60591 4.54722 6.60591 4.67333V6.52147L6.48222 6.45598C6.48222 6.39292 6.51617 6.31774 6.58408 6.23042C6.652 6.13826 6.74416 6.04852 6.86058 5.96121C6.97699 5.86904 7.11039 5.79386 7.26076 5.73565C7.41599 5.67744 7.57849 5.64833 7.74826 5.64833ZM7.63912 6.44871C7.42569 6.44871 7.23893 6.50206 7.07886 6.60878C6.91879 6.7155 6.79267 6.86102 6.7005 7.04535C6.61319 7.22482 6.56953 7.43098 6.56953 7.66382C6.56953 7.8918 6.61319 8.10038 6.7005 8.28956C6.79267 8.47389 6.91879 8.61941 7.07886 8.72613C7.23893 8.83285 7.42569 8.8862 7.63912 8.8862C7.85255 8.8862 8.03688 8.83285 8.19211 8.72613C8.35218 8.61941 8.47587 8.47389 8.56319 8.28956C8.65535 8.10038 8.70143 7.8918 8.70143 7.66382C8.70143 7.43098 8.65535 7.22482 8.56319 7.04535C8.47587 6.86102 8.35218 6.7155 8.19211 6.60878C8.03688 6.50206 7.85255 6.44871 7.63912 6.44871Z",fill:"#3D3E45"}),n.jsx("path",{d:"M3.02845 5.66289L1.45681 9.35915C1.42286 9.45131 1.3695 9.52408 1.29674 9.57743C1.22883 9.62594 1.15364 9.65019 1.07118 9.65019C0.940211 9.65019 0.843196 9.61381 0.780136 9.54105C0.717077 9.46829 0.685547 9.37855 0.685547 9.27184C0.685547 9.22818 0.692823 9.1821 0.707375 9.13359L2.51913 4.78248C2.55793 4.68546 2.61614 4.61028 2.69375 4.55692C2.77622 4.50356 2.86353 4.48173 2.95569 4.49143C3.04301 4.49143 3.12304 4.51811 3.19581 4.57147C3.27342 4.61998 3.3292 4.69031 3.36316 4.78248L5.15308 9.04628C5.17733 9.10934 5.18946 9.16755 5.18946 9.2209C5.18946 9.35187 5.1458 9.45616 5.05849 9.53378C4.97603 9.61139 4.88386 9.65019 4.782 9.65019C4.69468 9.65019 4.61465 9.62352 4.54189 9.57016C4.47398 9.5168 4.42062 9.44404 4.38181 9.35187L2.81745 5.70654L3.02845 5.66289ZM1.68237 8.47146L2.08256 7.63471H4.04711L4.18536 8.47146H1.68237Z",fill:"#3D3E45"})]}),D3=()=>n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[n.jsx("g",{clipPath:"url(#clip0_567_6919)",children:n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M7.00001 1.02051C7.29533 1.02051 7.53473 1.25991 7.53473 1.55523V2.99492L11.3486 5.17429C11.5152 5.2695 11.6181 5.44667 11.6181 5.63856V9.97475L13.0725 10.702C13.3366 10.834 13.4437 11.1552 13.3116 11.4194C13.1795 11.6835 12.8583 11.7906 12.5942 11.6585L11.1002 10.9115L7.26531 13.1028C7.10091 13.1968 6.8991 13.1968 6.73471 13.1028L2.89985 10.9115L1.40581 11.6585C1.14167 11.7906 0.820476 11.6835 0.688405 11.4194C0.556335 11.1552 0.663399 10.834 0.92754 10.702L2.38195 9.97475V5.63856C2.38195 5.44667 2.48477 5.2695 2.65138 5.17429L6.46529 2.99492V1.55523C6.46529 1.25991 6.70469 1.02051 7.00001 1.02051ZM7.00001 3.9211L3.99444 5.63856L7.00001 7.35603L10.0056 5.63856L7.00001 3.9211ZM10.5486 6.55999L7.53473 8.28221V11.7171L10.5486 9.99492V6.55999ZM6.46529 11.7171V8.28221L3.4514 6.55999V9.99492L6.46529 11.7171Z",fill:"#3D3E45"})}),n.jsx("defs",{children:n.jsx("clipPath",{id:"clip0_567_6919",children:n.jsx("rect",{width:"14",height:"14",fill:"white"})})})]}),Wa=({type:e})=>{switch(e){case"boolean":return n.jsx(S3,{});case"date":return n.jsx(T3,{});case"number":return n.jsx(k3,{});case"string":return n.jsx(z3,{});case"dimension":return n.jsx(D3,{});default:return null}},I3={option:{fontFamily:"monospace","&.sub-option":{position:"relative",marginLeft:"22px"},"&.sub-option::before":{content:'""',width:"1px",height:"100%",position:"absolute",left:"-6px",borderLeft:"1px solid #E7E7E9"}},groupLabel:{cursor:"default",fontWeight:"normal","&::before":{content:'""',flex:1,insetInline:0,height:"calc(0.0625rem* var(--mantine-scale))",marginInlineEnd:"var(--mantine-spacing-xs)",borderBottom:"1px dashed var(--mantine-color-gray-2)"},"&::after":{borderBottom:"1px dashed var(--mantine-color-gray-2)",background:"none"}},group:{"&.dimension-group":{paddingBottom:"4px",".mantine-Combobox-groupLabel":{color:"#000"},".mantine-Combobox-groupLabel::before":{display:"none"},".mantine-Combobox-groupLabel::after":{display:"none"}}}},M3={root:{maxWidth:"unset"},option:{fontFamily:"monospace"},input:{paddingInlineStart:"var(--input-padding-inline-start)",height:"auto",color:"black",fontFamily:"monospace"}},Uc=(e,t,r)=>{const a=[];return t&&a.push("sub-option"),r&&a.push("disabled"),n.jsx(s.Combobox.Option,{value:e.value,className:a.join(" "),disabled:r,children:n.jsxs(s.Stack,{gap:1,children:[n.jsxs(s.Group,{gap:4,children:[!!e.dataType&&n.jsx(Wa,{type:e.dataType}),n.jsx(s.Text,{size:"xs",children:e.label})]}),n.jsx(s.Text,{size:"xs",c:"dimmed",pl:18,children:e.description})]})},e.value)},Yc=T.observer(({mmInfo:e,value:t,onChange:r,usedKeys:a})=>{const l=e.metricDetail,o=e.metrics.loading||l.loading,i=l.error,c=l.filterColOptions,d=s.useCombobox({onDropdownClose:()=>d.resetSelectedOption()}),u=h.useMemo(()=>o?n.jsx(s.Loader,{size:"xs"}):t?n.jsx(s.CloseButton,{size:"xs",onClick:()=>r(null)}):n.jsx(s.Combobox.Chevron,{size:"xs"}),[o,t]),p=n.jsx(s.InputBase,{component:"button",type:"button",variant:"unstyled",size:"xs",pointer:!0,rightSection:u,rightSectionPointerEvents:!o&&t?"all":"none",onClick:()=>d.toggleDropdown(),disabled:o||c.length===0,styles:M3,error:!!i,children:t||n.jsx(s.Input.Placeholder,{children:"选择维度"})});return n.jsxs(s.Combobox,{store:d,onOptionSubmit:f=>{r(f),d.closeDropdown()},styles:I3,children:[n.jsx(s.Combobox.Target,{children:i?n.jsx(s.Tooltip,{label:i,children:p}):p}),n.jsx(s.Combobox.Dropdown,{miw:300,children:n.jsx(s.Combobox.Options,{mah:500,style:{overflowY:"auto"},children:c.map(({group:f,items:v})=>n.jsx(s.Combobox.Group,{label:f,children:v.map(_=>{var w;return"group"in _?n.jsx(s.Combobox.Group,{className:"dimension-group",label:n.jsxs(s.Group,{gap:4,children:[n.jsx(Wa,{type:"dimension"}),n.jsx(s.Text,{size:"sm",children:_.group}),n.jsx(s.Text,{size:"xs",c:"dimmed",children:_.description})]}),children:(w=_.items)==null?void 0:w.map(m=>Uc(m,!0,a.has(m.value)))},_.group):Uc(_,!1,a.has(_.value))})},f))})})]})}),Kc={tbody:{td:{fontFamily:"monospace"}}},A3={root:{maxWidth:"unset"},option:{fontFamily:"monospace","&[data-checked=true][data-combobox-disabled]":{opacity:1}},input:{fontFamily:"monospace"},groupLabel:{"&::before":{content:'""',flex:1,insetInline:0,height:"calc(0.0625rem* var(--mantine-scale))",marginInlineEnd:"var(--mantine-spacing-xs)",backgroundColor:"var(--mantine-color-gray-2)"}}},P3=({option:e,...t})=>{const{t:r}=x.useTranslation(),a=e,l=a.type==="filter";return n.jsxs(s.Stack,{gap:0,py:4,styles:{root:{flexGrow:1,'&[data-selected="true"]':{".mantine-Text-root":{color:"white"},svg:{stroke:"white"}}}},...t,children:[n.jsx(s.Group,{flex:"1",gap:4,children:n.jsx(s.Text,{size:"xs",children:e.value})}),l&&n.jsxs(s.Group,{justify:"space-between",wrap:"nowrap",children:[n.jsx(s.Text,{size:"xs",c:t.checked?"rgba(255,255,255,.8)":"dimmed",style:{flexShrink:1,flexGrow:1},children:a.widget_label}),n.jsx(s.Text,{size:"xs",c:t.checked?"rgba(255,255,255,.8)":"dimmed",style:{flexShrink:0,flexGrow:0},children:r(st[a.widget])})]})]})},Pn=T.observer(({queryModel:e,value:t,onChange:r,usedKeys:a})=>{const{t:l}=x.useTranslation();e.config;const o=h.useMemo(()=>e.getConditionOptionsWithInvalidValue(t).optionGroups.map(d=>{const u=d.items.length;return{group:`${l(d.group)}(${u})`,items:d.items.map(f=>({...f,label:f.value,widget_label:f.label,disabled:a==null?void 0:a.has(f.value)}))}}),[e.getConditionOptionsWithInvalidValue,l,t,a]),i=h.useCallback((c,d)=>{r(c,d)},[r]);return n.jsx(s.Select,{size:"xs",variant:"unstyled",placeholder:"选择变量",styles:A3,data:o,renderOption:P3,maxDropdownHeight:600,value:t,onChange:i,clearable:!0})}),Ua=T.observer(({variable:e})=>{const t=W();if(!e)return null;const r=y.has(t.queryVariables,e);return n.jsx(s.ThemeIcon,{variant:"white",size:"xs",color:r?"#88CE98":"#F15050",styles:{root:{flexGrow:0,flexShrink:0}},children:n.jsx(S.IconPointFilled,{})})}),V3=T.observer(({queryModel:e})=>{const t=e.config,a=e.datasource.mericoMetricInfo;return h.useEffect(()=>{a.selectMetric(t.id)},[t.id,a]),n.jsxs(s.Stack,{gap:7,children:[n.jsxs(s.Group,{justify:"flex-start",gap:8,children:[n.jsx(s.Text,{size:"sm",children:"看板变量与指标维度关联"}),n.jsx(s.Tooltip,{label:"将看板的筛选器参数与指标的查询维度关联上,使指标可以按照看板的筛选条件和背景变量进行关联展示。",children:n.jsx(s.ActionIcon,{size:"xs",variant:"subtle",color:"gray",children:n.jsx(S.IconInfoCircle,{})})})]}),n.jsxs(s.Table,{withTableBorder:!0,withColumnBorders:!0,layout:"fixed",styles:Kc,children:[n.jsxs("colgroup",{children:[n.jsx("col",{style:{width:"49%"}}),n.jsx("col",{}),n.jsx("col",{style:{width:130}}),n.jsx("col",{style:{width:40}})]}),n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:"指标筛选维度"}),n.jsx(s.Table.Td,{children:"看板变量"}),n.jsx(s.Table.Td,{colSpan:2,children:"变量值为真时运行查询"})]})}),n.jsxs(s.Table.Tbody,{children:[t.filters.map(l=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{pr:0,children:n.jsx(Yc,{mmInfo:a,value:l.dimension,onChange:l.setDimension,usedKeys:t.usedFilterDimensionKeys})}),n.jsx(s.Table.Td,{colSpan:2,pr:0,children:n.jsxs(s.Group,{justify:"flex-start",grow:!0,gap:0,w:"100%",children:[n.jsx(Ua,{variable:l.variable}),n.jsx(Pn,{queryModel:e,value:l.variable,onChange:l.setVariable})]})}),n.jsx(s.Table.Td,{children:n.jsx(s.Checkbox,{size:"xs",checked:e.keyInRunBy(l.variable),onChange:o=>e.changeRunByRecord(l.variable,o.currentTarget.checked),color:"red"})})]},l.dimension)),n.jsxs(s.Table.Tr,{className:"add-a-row",children:[n.jsx(s.Table.Td,{pr:0,children:n.jsx(Yc,{mmInfo:a,value:null,onChange:l=>l&&t.addFilter(l,""),usedKeys:t.usedFilterDimensionKeys})}),n.jsx(s.Table.Td,{colSpan:2,pr:0,children:n.jsx(Pn,{queryModel:e,value:null,onChange:l=>l&&t.addFilter("",l)})}),n.jsx(s.Table.Td,{})]})]})]})]})}),$3=T.observer(({queryModel:e,variable:t})=>{const r=e.keyInRunBy(t),a=l=>{e.changeRunByRecord(t,l.currentTarget.checked)};return n.jsx(s.Checkbox,{size:"xs",checked:r,onChange:a,color:"red"})}),Xc=({queryModel:e,variable:t})=>t?n.jsx($3,{queryModel:e,variable:t}):null,E3=T.observer(({queryModel:e})=>{const t=e.config,l=e.datasource.mericoMetricInfo.metricDetail,o=l.trendingDateCol,i=t.timeQuery.enabled;return h.useEffect(()=>{if(!i&&l.requireTrendingReason){t.setTimeQueryEnabled(!0);return}},[l.requireTrendingReason,i]),l.supportTrending?l.requireTrendingReason?n.jsx(s.Tooltip,{label:l.requireTrendingReason,children:n.jsx(s.Box,{children:n.jsx(s.Switch,{size:"xs",color:"red",checked:!0,readOnly:!0,styles:{track:{cursor:"not-allowed"}}})})}):n.jsx(s.Switch,{size:"xs",color:"red",checked:i,onChange:c=>t.setTimeQueryEnabled(c.currentTarget.checked),styles:{track:{cursor:"pointer"}}}):n.jsx(s.Tooltip,{label:"由于指标未设定时序维度,所以不具备时间序列展示功能。",children:n.jsx(s.Box,{children:n.jsx(s.Switch,{size:"xs",color:"red",disabled:!o})})})}),B3=T.observer(({queryModel:e})=>{const t=e.config,l=e.datasource.mericoMetricInfo.metricDetail,o=l.trendingDateCol;return!t.timeQuery.enabled||!l.supportTrending?null:n.jsxs(s.Table,{withTableBorder:!0,withColumnBorders:!0,layout:"fixed",styles:Kc,children:[n.jsxs("colgroup",{children:[n.jsx("col",{style:{width:250}}),n.jsx("col",{}),n.jsx("col",{style:{width:130}}),n.jsx("col",{style:{width:40}})]}),n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{}),n.jsx(s.Table.Td,{children:"看板变量"}),n.jsx(s.Table.Td,{colSpan:2,children:"变量值为真时运行查询"})]})}),n.jsxs(s.Table.Tbody,{children:[n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{pr:0,children:n.jsxs(s.Group,{gap:4,children:[n.jsx(s.Text,{size:"xs",children:"时间维度"}),n.jsx(s.Text,{size:"xs",c:"dimmed",ff:"monospace",children:(o==null?void 0:o.name)??null})]})}),n.jsx(s.Table.Td,{colSpan:2,pr:0,children:n.jsxs(s.Group,{justify:"flex-start",gap:0,grow:!0,children:[n.jsx(Ua,{variable:t.timeQuery.range_variable}),n.jsx(Pn,{queryModel:e,value:t.timeQuery.range_variable,onChange:t.setRangeVariable,usedKeys:t.usedTimeQueryVariableSet})]})}),n.jsx(s.Table.Td,{children:n.jsx(Xc,{queryModel:e,variable:t.timeQuery.range_variable})})]},"dimension.time"),n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:n.jsx(s.Text,{size:"xs",children:"步长"})}),n.jsx(s.Table.Td,{colSpan:2,pr:0,children:n.jsxs(s.Group,{justify:"flex-start",gap:0,grow:!0,children:[n.jsx(Ua,{variable:t.timeQuery.unit_variable}),n.jsx(Pn,{queryModel:e,value:t.timeQuery.unit_variable,onChange:t.setUnitVariable,usedKeys:t.usedTimeQueryVariableSet})]})}),n.jsx(s.Table.Td,{children:n.jsx(Xc,{queryModel:e,variable:t.timeQuery.unit_variable})})]},"dimension.step")]})]})}),L3=T.observer(({queryModel:e})=>n.jsxs(s.Stack,{gap:7,children:[n.jsxs(s.Group,{justify:"flex-start",gap:8,children:[n.jsx(s.Text,{size:"sm",children:"按时间序列展示"}),n.jsx(s.Tooltip,{label:"将看板的时间&步长筛选器与相应的查询维度关联上。",children:n.jsx(s.ActionIcon,{size:"xs",variant:"subtle",color:"gray",children:n.jsx(S.IconInfoCircle,{})})}),n.jsx(E3,{queryModel:e})]}),n.jsx(B3,{queryModel:e})]})),q3={label:{fontWeight:"normal"},input:{fontSize:"12px"},groupLabel:{cursor:"default",fontWeight:"normal","&::before":{content:'""',flex:1,insetInline:0,height:"calc(0.0625rem* var(--mantine-scale))",marginInlineEnd:"var(--mantine-spacing-xs)",borderBottom:"1px dashed var(--mantine-color-gray-2)"},"&::after":{borderBottom:"1px dashed var(--mantine-color-gray-2)",background:"none"}},option:{fontFamily:"monospace"}},O3=e=>{const t=e.option;return n.jsxs(s.Stack,{gap:1,styles:{root:{flexGrow:1}},children:[n.jsxs(s.Group,{gap:4,children:[n.jsx(Wa,{type:t.dataType}),n.jsx(s.Text,{size:"xs",children:t.label})]}),n.jsx(s.Text,{size:"xs",c:"dimmed",pl:18,children:t.description})]})},N3=T.observer(({queryModel:e})=>{const t=e.config,a=e.datasource.mericoMetricInfo,l=a.metricDetail,o=a.metrics.loading||l.loading,i=l.groupByColOptions,c=d=>{const u=l.getGroupByOptions(d),p=[];u.forEach(f=>{f.dimension?f.dimension.fields.forEach(v=>{typeof v=="string"?p.push(`${f.value} -> ${v}`):p.push(`${f.value} -> ${v.field}`)}):p.push(f.value)}),t.setGroupBys(p)};return n.jsxs(n.Fragment,{children:[n.jsx(s.MultiSelect,{size:"sm",label:"分组聚合维度",description:"指标在查询时按照哪些维度进行聚合计算。最多支持两个维度的聚合计算。若选择按时间序列展示,则仅可选择一个聚合维度。",data:i,searchable:!0,styles:q3,renderOption:O3,rightSection:o?n.jsx(s.Loader,{size:"xs"}):null,value:[...t.groupByValues],onChange:c,maxValues:t.timeQuery.enabled?1:2,placeholder:t.timeQuery.enabled?"仅可选一个维度":"最多选两个维度",disabled:o}),n.jsx(s.Switch,{labelPosition:"left",label:"聚合维度为空时,自动补零",size:"sm",color:"red",checked:t.useDefaultValues,onChange:d=>t.setUseDefaultValues(d.currentTarget.checked),disabled:i.length===0})]})}),G3=T.observer(({queryModel:e})=>{const t=e.config,r=t.id;return h.useEffect(()=>{if(e.run_by.length===0)return;const a=[],l=t.usedFilterVariableSet,o=t.usedTimeQueryVariableSet;e.run_by.forEach(i=>{(l.has(i)||o.has(i))&&a.push(i)}),e.setRunBy(a)},[t.usedFilterVariableSet,t.usedTimeQueryVariableSet,e.run_by]),n.jsxs(s.Stack,{gap:16,pos:"relative",children:[!r&&n.jsx(s.Overlay,{color:"#fff",backgroundOpacity:.5,blur:3,children:n.jsx(s.Center,{h:"100%",children:n.jsx(s.Text,{size:"sm",c:"black",children:"请先选择指标"})})}),n.jsx(V3,{queryModel:e}),n.jsx(L3,{queryModel:e}),n.jsx(N3,{queryModel:e})]})}),F3=["function process_result(resp, utils, state) {"," return resp.data","}"].join(`
|
|
572
572
|
`),j3={root:{minHeight:"350px",maxHeight:"50vh",height:"100%",overflow:"hidden"},list:{"&::before":{borderColor:"transparent"}},panel:{height:"calc(100% - 36px)",overflowY:"auto"}},Q3=T.observer(({queryModel:e})=>{const[t,r]=h.useState("编辑查询");return n.jsxs(s.Tabs,{color:"red",defaultValue:"编辑查询",styles:j3,value:t,onChange:r,w:"60%",children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"编辑查询",size:"xs",children:"编辑查询"}),n.jsx(s.Tabs.Tab,{value:"加工结果",size:"xs",children:"加工结果"}),n.jsx(s.Tabs.Tab,{value:"使用情况",size:"xs",children:"使用情况"})]}),n.jsx(s.Tabs.Panel,{value:"编辑查询",pt:"xs",children:n.jsx(G3,{queryModel:e})}),n.jsx(s.Tabs.Panel,{value:"加工结果",pt:"xs",children:n.jsx(xt,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:F3})}),n.jsx(s.Tabs.Panel,{value:"使用情况",pt:"xs",children:n.jsx(Fc,{queryModel:e})})]})}),W3=T.observer(({queryModel:e})=>{const t=e.metricQueryPayloadError;return t.length>0?n.jsxs(s.HoverCard,{shadow:"md",children:[n.jsx(s.HoverCard.Target,{children:n.jsx(s.Box,{children:n.jsx(s.Button,{size:"xs",leftSection:n.jsx(Qc,{width:14,height:14,color:"rgb(173, 181, 189)"}),variant:"filled",color:"red",disabled:!0,children:"执行查询"})})}),n.jsx(s.HoverCard.Dropdown,{children:n.jsx(s.List,{size:"xs",children:t.map(r=>n.jsx(s.List.Item,{children:r},r))})})]}):n.jsx(s.Button,{size:"xs",leftSection:n.jsx(Qc,{width:14,height:14}),variant:"filled",color:"red",onClick:()=>e.fetchData(!0),children:"执行查询"})}),U3=({option:e,...t})=>{const r=e;return n.jsxs(s.Stack,{gap:0,py:4,styles:{root:{flexGrow:1,'&[data-selected="true"]':{".mantine-Text-root":{color:"white"},svg:{stroke:"white"}}}},...t,children:[n.jsxs(s.Group,{flex:"1",gap:4,children:[n.jsx(S.IconHash,{size:12}),n.jsx(s.Text,{size:"xs",children:r.label})]}),n.jsx(s.Text,{ml:16,size:"xs",c:t.checked?"rgba(255,255,255,.8)":"dimmed",children:r.description})]})},Y3=T.observer(({queryModel:e})=>{const t=e.config,a=e.datasource.mericoMetricInfo,l=a.metrics;h.useEffect(()=>{l.load()},[l]),h.useEffect(()=>{!a.metricID&&t.id&&a.selectMetric(t.id)},[t.id]);const o=h.useMemo(()=>l.data.map(p=>({label:p.name,value:p.id,description:p.description,type:p.type})),[l.data]),i=h.useCallback((p,f)=>{p&&(a.selectMetric(p),t.setID(p),t.setType(f.type))},[a,t]),c=h.useMemo(()=>{const p=window.localStorage.getItem("ee_site_url")??"";let f=`${p}/dashboard/admin/metrics/list`;return t.id&&t.type&&(f=`${p}/dashboard/admin/metrics/details/${t.type}/${t.id}`),f.replace("//dashboard","/dashboard")},[t.id,t.type]),{loading:d,error:u}=l;return n.jsx(ne,{children:n.jsxs(s.Group,{justify:"flex-end",gap:12,align:"flex-end",children:[u?n.jsx(s.Tooltip,{label:u,children:n.jsx(s.Select,{size:"xs",label:"指标",error:!0,styles:{root:{flexGrow:1}}})}):n.jsx(s.Select,{size:"xs",label:"指标",data:o,renderOption:U3,styles:{root:{flexGrow:1}},maxDropdownHeight:500,value:t.id,onChange:i,rightSection:d?n.jsx(s.Loader,{size:"xs"}):null}),n.jsx(s.Tooltip,{label:"跳转到指标明细页查看详情。",disabled:d,children:n.jsx(s.Anchor,{size:"md",variant:"subtle",mb:2,href:c,target:"_blank",underline:"never",children:n.jsx(u3,{width:14,height:14})})})]})})}),K3=T.observer(({queryModel:e})=>{const{t}=x.useTranslation();return n.jsxs(s.Stack,{pt:8,pb:16,px:24,gap:8,styles:{root:{height:"100vh",overflow:"hidden"}},children:[n.jsx(s.Group,{styles:{root:{flexGrow:0,flexShrink:0}},children:n.jsx(s.TextInput,{size:"xs",placeholder:t("query.name_description"),label:t("query.name"),value:e.name,onChange:r=>{e.setName(r.currentTarget.value)},styles:{root:{flexGrow:0,width:"calc(50% - 44px)"}}})}),n.jsxs(s.Group,{justify:"space-between",grow:!0,gap:8,align:"flex-end",styles:{root:{flexGrow:0,flexShrink:0}},children:[n.jsxs(s.Group,{justify:"flex-start",grow:!0,gap:24,align:"flex-end",children:[n.jsx(Oc,{queryModel:e,size:"xs"}),n.jsx(Y3,{queryModel:e})]}),n.jsxs(s.Group,{justify:"flex-end",children:[n.jsx(W3,{queryModel:e}),n.jsx(g3,{queryModel:e})]})]}),n.jsxs(s.Group,{justify:"space-between",grow:!0,gap:12,align:"flex-start",sx:{flexGrow:0,flexShrink:1,overflowY:"hidden"},children:[n.jsx(Q3,{queryModel:e}),n.jsx(C3,{queryModel:e})]}),n.jsx(m3,{queryModel:e})]})}),X3=T.observer(({id:e})=>{const r=F().queries.findByID(e);return e===""?null:r?r.isMericoMetricQuery?n.jsx(K3,{queryModel:r}):n.jsx(d3,{queryModel:r}):n.jsx(s.Text,{size:"14px",c:"red",children:"Invalid Query ID"})}),Z3=T.observer(({value:e})=>{const r=J().payloadForSQL,a=h.useMemo(()=>or(e,r),[e,r]);return n.jsx(rr,{height:"100%",value:a})}),J3=T.observer(({item:e,remove:t,onKeyChanged:r})=>{const{t:a}=x.useTranslation(),[l,o]=h.useState("SQL"),[i,c]=h.useState(e.key),d=()=>{e.setKey(i),r(i)},u=i!==e.key,p=e.isADuplicatedKey(i),[f,v]=h.useState(e.value),_=()=>{e.setValue(f)};h.useEffect(()=>{c(e.key),v(e.value)},[e]);const w=f!==e.value,m=ze.useModals(),k=()=>{m.openConfirmModal({title:`${a("sql_snippet.delete")}?`,labels:{confirm:a("common.actions.confirm"),cancel:a("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:t,confirmProps:{color:"red"},zIndex:320})};return n.jsxs(s.Stack,{p:20,sx:{minWidth:"1100px",height:"100vh"},gap:"sm",children:[n.jsxs(s.Group,{sx:{alignItems:"end"},gap:40,children:[n.jsx(s.TextInput,{label:a(p?"sql_snippet.key_occupied":"sql_snippet.key"),value:i,onChange:z=>{c(z.currentTarget.value)},sx:{flexGrow:"1 !important"},rightSection:n.jsx(s.ActionIcon,{color:"blue",variant:"subtle",onClick:d,disabled:!u||p,children:n.jsx(S.IconDeviceFloppy,{size:16})}),error:p}),n.jsx(s.Button,{leftSection:n.jsx(S.IconTrash,{size:16}),color:"red",variant:"light",onClick:k,children:a("sql_snippet.delete")})]}),n.jsxs(s.Tabs,{value:l,onChange:o,sx:{flexGrow:1},styles:{panel:{height:"calc(100% - 50px)"}},children:[n.jsxs(s.Tabs.List,{sx:{position:"relative"},children:[n.jsx(s.Tabs.Tab,{value:"SQL",children:a("sql_snippet.edit_snippet")}),n.jsx(s.Tabs.Tab,{value:"Preview",children:a("sql_snippet.preview_snippet")}),n.jsx(Qa,{}),n.jsx(s.ActionIcon,{color:"blue",variant:"filled",onClick:_,disabled:!w,sx:{position:"absolute",top:0,right:10},children:n.jsx(S.IconDeviceFloppy,{size:18})})]}),n.jsx(s.Tabs.Panel,{value:"SQL",pt:"sm",children:n.jsx(rr,{height:"100%",value:f,onChange:v,defaultLanguage:"sql",theme:"sql-dark"})}),n.jsx(s.Tabs.Panel,{value:"Preview",pt:"sm",children:n.jsx(Z3,{value:f})})]})]})}),H3=T.observer(({id:e})=>{const t=W(),r=F(),a=h.useMemo(()=>r.sqlSnippets.findByKey(e),[e]);if(!e)return null;if(!a)return n.jsxs(s.Text,{size:"14px",children:["SQL Snippet by key[",e,"] is not found"]});const l=()=>{t.editor.setPath(["_SQL_SNIPPETS_",""])},o=()=>{r.sqlSnippets.removeByKey(e),l()},i=c=>{t.editor.setPath(["_SQL_SNIPPETS_",c])};return n.jsx(J3,{item:a,remove:o,onKeyChanged:i})}),R3=T.observer(()=>{const{t:e}=x.useTranslation(),[t,r]=h.useState([]),a=ze.useModals(),l=W(),o=v=>{l.editor.setPath(["_SQL_SNIPPETS_",v])},i=()=>{a.openConfirmModal({title:"Delete ununsed SQL snippets?",children:n.jsx(s.Text,{size:"sm",children:"This action cannot be undone."}),labels:{confirm:e("common.actions.confirm"),cancel:e("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>l.content.removeUnusedSQLSnippets(),confirmProps:{color:"red"},zIndex:320})},c=()=>{l.content.sqlSnippets.downloadSchema(t)},d=h.useMemo(()=>l.content.sqlSnippets.sortedList.map(v=>v.key),[l.content.sqlSnippets.sortedList]),u=()=>{r(d)},p=()=>{r([])},f=l.content.sqlSnippetsUsage;return n.jsxs(s.Stack,{sx:{height:"100%"},gap:"sm",pb:"59px",children:[n.jsx(s.Box,{pt:9,pb:8,sx:{borderBottom:"1px solid #eee"},children:n.jsx(s.Text,{size:"sm",px:"md",ta:"left",sx:{userSelect:"none",cursor:"default"},children:e("sql_snippet.manage")})}),n.jsxs(s.Flex,{justify:"space-between",align:"center",px:12,children:[n.jsxs(s.Group,{justify:"flex-start",children:[n.jsxs(s.Button.Group,{children:[n.jsx(s.Button,{variant:"default",size:"xs",onClick:u,children:e("common.actions.select_all")}),n.jsx(s.Button,{variant:"default",size:"xs",onClick:p,children:e("common.actions.clear_selection")})]}),n.jsx(s.Button,{size:"xs",color:"blue",leftSection:n.jsx(S.IconCode,{size:14}),disabled:t.length===0,onClick:c,children:e("common.actions.download_schema")})]}),n.jsx(s.Button,{variant:"subtle",size:"xs",color:"red",leftSection:n.jsx(S.IconTrash,{size:14}),disabled:!l.content.hasUnusedSQLSnippets,onClick:i,children:e("sql_snippet.delete_unused")})]}),n.jsx(s.Box,{sx:{flexGrow:1,overflow:"auto"},children:n.jsx(s.Checkbox.Group,{size:"xs",value:t,onChange:r,children:n.jsxs(s.Table,{fz:"sm",highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{style:{width:"40px"}}),n.jsx(s.Table.Th,{children:e("common.key")}),n.jsx(s.Table.Th,{style:{width:"100px",textAlign:"center"},children:e("sql_snippet.usage.label")}),n.jsx(s.Table.Th,{style:{width:"300px",paddingLeft:"24px"},children:e("common.action")})]})}),n.jsx(s.Table.Tbody,{children:l.content.sqlSnippets.sortedList.map(v=>{var w;const _=((w=f[v.key])==null?void 0:w.length)??0;return n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:n.jsx(s.Checkbox,{value:v.key,styles:{input:{cursor:"pointer"}}})}),n.jsx(s.Table.Td,{children:v.key}),n.jsx(s.Table.Td,{style:{color:_===0?"#ff0000":"#000",fontWeight:_===0?"bold":"normal",textAlign:"center"},children:_}),n.jsx(s.Table.Td,{children:n.jsx(s.Button,{variant:"subtle",size:"xs",onClick:()=>o(v.key),children:e("common.actions.open")})})]},v.key)})})]})})})]})}),eD=T.observer(({view:e})=>!e||e.type!==$.Division?null:n.jsx(s.Stack,{})),tD=T.observer(({view:e})=>{const{t,i18n:r}=x.useTranslation(),a=h.useMemo(()=>[{value:"default",label:t("common.tabs.variant.default")},{value:"outline",label:t("common.tabs.variant.outline")},{value:"pills",label:t("common.tabs.variant.pills")}],[r.language]),l=h.useMemo(()=>[{value:"horizontal",label:t("common.tabs.orientation.horizontal")},{value:"vertical",label:t("common.tabs.orientation.vertical")}],[r.language]);if(!e||e.type!==$.Tabs)return null;const o=e.config;return n.jsxs(s.Stack,{children:[n.jsx(s.Divider,{mt:8,mb:0,label:t("view.component.tabs.tabs_settings"),labelPosition:"center"}),n.jsx(s.Select,{label:t("common.tabs.variant.label"),value:o.variant,onChange:o.setVariant,data:a}),n.jsx(s.Select,{label:t("common.tabs.orientation.label"),value:o.orientation,onChange:o.setOrientation,data:l}),n.jsx(s.Switch,{label:t("common.tabs.grow_tabs"),checked:o.grow,onChange:i=>o.setGrow(i.currentTarget.checked)})]})}),nD=({disabled:e,value:t,onChange:r})=>{const a=l=>{l&&r(l)};return n.jsxs(s.Box,{sx:{position:"relative"},children:[e&&n.jsx(s.Overlay,{backgroundOpacity:.6,color:"#fff",zIndex:5,blur:2}),n.jsx(Te,{height:"500px",defaultLanguage:"javascript",value:t,onChange:a,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},rD=({value:e,onChange:t})=>{const{t:r}=x.useTranslation(),[a,{setTrue:l,setFalse:o}]=O.useBoolean(),[i,c]=h.useState(e??Sn),d=_=>{c({...i,enabled:_})},u=()=>{o();const{enabled:_,func_content:w}=i,m={enabled:_,func_content:w};c(m),t(m)},p=()=>{o(),c(e)},f=_=>{c(w=>({...w,func_content:_}))},v=()=>{f(Sn.func_content)};return n.jsxs(n.Fragment,{children:[n.jsx(s.ActionIcon,{size:"lg",color:"blue",variant:"filled",mt:26,onClick:l,sx:{flexGrow:0},children:n.jsx(S.IconSettings,{size:14})}),n.jsx(s.Modal,{size:800,title:r("view.component.modal.custom_title"),opened:a,onClose:o,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:a&&n.jsxs(s.Stack,{children:[n.jsx(s.Checkbox,{mt:10,label:r("common.enabled"),checked:i.enabled,onChange:_=>d(_.currentTarget.checked)}),n.jsx(nD,{value:i.func_content,onChange:f,disabled:!i.enabled}),n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Button,{onClick:v,color:"red",leftSection:n.jsx(S.IconRecycle,{size:20}),children:r("common.actions.revert")}),n.jsxs(s.Group,{justify:"flex-end",children:[n.jsx(s.Button,{onClick:p,variant:"subtle",children:r("common.actions.cancel")}),n.jsx(s.Button,{onClick:u,children:r("common.actions.save")})]})]})]})})]})},aD=T.observer(({view:e})=>{const{t}=x.useTranslation();if(!e||e.type!==$.Modal)return null;const r=e.config,a=r.custom_modal_title.value;return n.jsxs(s.Stack,{children:[n.jsx(s.Divider,{mt:8,label:t("view.component.modal.modal_settings"),labelPosition:"center"}),n.jsxs(s.Flex,{gap:10,children:[n.jsx(s.TextInput,{label:t("view.component.modal.title"),value:a,onChange:y.noop,disabled:!0,sx:{flexGrow:1}}),n.jsx(rD,{value:r.custom_modal_title,onChange:r.custom_modal_title.replace})]}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(s.TextInput,{label:t("view.component.modal.width"),value:r.width,onChange:l=>r.setWidth(l.currentTarget.value),placeholder:"600px / 50vw"}),n.jsx(s.TextInput,{label:t("view.component.modal.height"),value:r.height,onChange:l=>r.setHeight(l.currentTarget.value),placeholder:"600px / 50vw"})]})]})}),sD=T.observer(({view:e})=>n.jsxs(n.Fragment,{children:[n.jsx(eD,{view:e}),n.jsx(aD,{view:e}),n.jsx(tD,{view:e})]})),lD=T.observer(({view:e})=>{const{t,i18n:r}=x.useTranslation(),a=h.useMemo(()=>[{label:t("view.component.div.label"),value:$.Division},{label:t("view.component.modal.label"),value:$.Modal},{label:t("view.component.tabs.label"),value:$.Tabs}],[r.language]);return e?n.jsxs(s.Stack,{sx:{position:"relative"},children:[n.jsx(s.TextInput,{label:t("common.name"),value:e.name,onChange:l=>{e.setName(l.currentTarget.value)}}),n.jsx(s.Select,{label:t("common.type"),comboboxProps:{withinPortal:!0,zIndex:320},value:e.type,onChange:e.setType,data:a}),n.jsx(sD,{view:e})]}):null}),oD=T.observer(({id:e})=>{const{t}=x.useTranslation(),r=ze.useModals(),a=W(),l=F();if(e==="")return null;const o=l.views.findByID(e);if(!o)return n.jsxs(s.Text,{size:"14px",children:["View by ID[",e,"] is not found"]});const i=()=>{a.editor.setPath(["_VIEWS_",""])},c=()=>{r.openConfirmModal({title:`${t("view.delete")}?`,labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{l.views.removeByID(e),i()},confirmProps:{color:"red"},zIndex:320})};return n.jsxs(s.Stack,{sx:{maxWidth:"600px",height:"100%"},gap:"sm",children:[n.jsx(s.Group,{justify:"flex-end",pt:10,children:n.jsx(s.Button,{size:"xs",color:"red",leftSection:n.jsx(S.IconTrash,{size:16}),onClick:c,children:t("view.delete")})}),n.jsx(s.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:n.jsx(lD,{view:o})})]})}),iD=T.observer(()=>n.jsx(s.Stack,{sx:{height:"100%"},p:"sm",children:n.jsx(Nc,{})})),cD=T.observer(()=>{const e=W().editor,t=e.path;return T2(t)?n.jsx(iD,{}):k2(t)?n.jsx(Hk,{}):z2(t)?n.jsx(Jk,{}):D2(t)?n.jsx(s.Box,{p:"xs",pl:20,children:n.jsx(Zk,{id:t[1]})}):I2(t)?n.jsx(R3,{}):M2(t)?n.jsx(H3,{id:t[1]}):P2(t)?n.jsx(Az,{}):A2(t)?n.jsx(X3,{id:t[1]}):V2(t)?n.jsx(s.Box,{p:"xs",pl:20,children:n.jsx(oD,{id:t[1]})}):Ea(t)?n.jsx(Mz,{viewID:t[1],panelID:t[3]}):n.jsx(s.Box,{children:e.path})}),dD=T.observer(()=>n.jsx(cD,{})),uD=T.observer(()=>{const{t:e}=x.useTranslation(),t=W(),r=()=>{const a=new Date().getTime().toString(),l={id:a,key:a,label:a,order:t.content.filters.current.length+1,type:V.TextInput,config:la(),visibleInViewsIDs:["Main"],auto_submit:!1};t.content.filters.append(l),t.editor.setPath(["_FILTERS_",a])};return n.jsx(s.Button,{variant:"subtle",leftSection:n.jsx(S.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:r,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:e("filter.add")})}),pD=T.observer(({parentID:e})=>{const{t}=x.useTranslation(),r=F();if(!e)return null;const a=r.views.findByID(e);return!a||a.type===$.Tabs?null:n.jsx(s.Button,{variant:"subtle",leftSection:n.jsx(S.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:()=>r.addANewPanel(a.id),sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:t("panel.add")})}),hD=T.observer(()=>{const{t:e}=x.useTranslation(),t=W(),r=()=>{const a=new Date().getTime().toString(),l={id:a,name:a,type:j.Postgresql,key:"",config:{_type:j.Postgresql,sql:""}};t.content.queries.append(l),t.editor.setPath(["_QUERIES_",a])};return n.jsx(s.Button,{variant:"subtle",leftSection:n.jsx(S.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:r,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:e("query.add")})}),gD=T.observer(()=>{const{t:e}=x.useTranslation(),t=W(),r=()=>{const a=new Date().getTime().toString(),l={key:a,value:""};t.content.sqlSnippets.append(l),t.editor.setPath(["_SQL_SNIPPETS_",a])};return n.jsx(s.Button,{variant:"subtle",leftSection:n.jsx(S.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:r,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:e("sql_snippet.add")})}),fD=T.observer(()=>{const{t:e}=x.useTranslation(),t=F();return n.jsx(s.Button,{variant:"subtle",leftSection:n.jsx(S.IconPlus,{size:14}),size:"sm",px:"xs",mb:10,color:"blue",onClick:t.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"flex-start"}},children:e("view.add")})}),bD=T.observer(()=>{const{t:e}=x.useTranslation(),t=W();return n.jsx(s.Button,{variant:"subtle",rightSection:n.jsx(S.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>t.editor.setPath(["_QUERIES_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:e("query.manage")})}),yD=T.observer(()=>{const{t:e}=x.useTranslation(),t=W();return n.jsx(s.Button,{variant:"subtle",rightSection:n.jsx(S.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>t.editor.setPath(["_SQL_SNIPPETS_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:e("sql_snippet.manage")})}),vD=T.observer(()=>{const{t:e}=x.useTranslation(),t=W();return n.jsx(s.Button,{variant:"subtle",rightSection:n.jsx(S.IconSettings,{size:14}),size:"sm",px:12,mb:0,color:"blue",onClick:()=>t.editor.setPath(["_FILTERS_"]),sx:{width:"100%",borderRadius:0,fontWeight:"normal"},styles:{inner:{justifyContent:"space-between"}},children:e("filter.manage")})}),_D=T.observer(({action_type:e,parentID:t})=>e==="_Add_A_Filter_"?n.jsx(uD,{}):e==="_Add_A_SQL_SNIPPET_"?n.jsx(gD,{}):e==="_Add_A_QUERY_"?n.jsx(hD,{}):e==="_Add_A_VIEW_"?n.jsx(fD,{}):e==="_Add_A_PANEL_"?n.jsx(pD,{parentID:t}):e==="_QUERIES_SETTINGS_"?n.jsx(bD,{}):e==="_SQL_SNIPPETS_SETTINGS_"?n.jsx(yD,{}):e==="_FILTERS_SETTINGS_"?n.jsx(vD,{}):null),Zc=T.observer(({option:e})=>{var p;const{t}=x.useTranslation(),r=W().editor,a=r.isOptionActive,l=a(r.path,e),o=r.isOptionOpened,i=r.navigate,c=o(e),[d,u]=h.useState(c);return h.useEffect(()=>{u(c)},[c]),n.jsx(s.NavLink,{active:l,defaultOpened:c,opened:d,onChange:u,label:t(e.label),onClick:()=>i(e),leftSection:e.Icon?n.jsx(e.Icon,{size:18}):null,children:(p=e.children)==null?void 0:p.map(f=>f._type==="ACTION"?n.jsx(_D,{action_type:f._action_type,parentID:f.parentID},`_ADD_${f.value}_`):n.jsx(Zc,{option:f},f.value))},e.label)}),xD=T.observer(()=>{const e=W();return n.jsx(s.Box,{sx:{position:"relative"},children:e.editor.navOptions.map(t=>n.jsx(Zc,{option:t},t.value))})}),wD=T.observer(()=>{const{t:e}=x.useTranslation(),t=W();return n.jsxs(s.AppShell.Navbar,{p:0,sx:{height:"100vh - 60px - 60px",".mantine-NavLink-body":{wordWrap:"break-word"}},children:[n.jsx(s.AppShell.Section,{sx:{borderBottom:"1px solid #eee",padding:"var(--mantine-spacing-xs) var(--mantine-spacing-md)"},children:n.jsx(s.Text,{size:"sm",ta:"center",sx:{userSelect:"none",cursor:"default"},children:e("common.titles.settings")})}),n.jsx(s.AppShell.Section,{grow:!0,sx:{overflow:"auto"},children:n.jsx(xD,{})}),n.jsx(s.AppShell.Section,{children:n.jsx(s.Group,{grow:!0,p:"md",pt:"sm",sx:{borderTop:"1px solid #eee"},children:n.jsx(s.Button,{size:"xs",color:"red",leftSection:n.jsx(S.IconX,{size:18}),onClick:()=>t.editor.close(),children:e("common.actions.close")})})})]})}),mD={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden",minWidth:"calc(var(--app-shell-navbar-width, 0px) + 1200px)"},body:{flexGrow:1,nav:{top:0,height:"100vh"}},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:0,height:"100vh"}},CD=T.observer(()=>{const e=W().editor;return n.jsx(s.Modal,{onClose:()=>e.setSettingsOpen(!1),closeOnEscape:!1,closeOnClickOutside:!1,opened:e.settings_open,fullScreen:!0,title:null,transitionProps:{duration:0},withCloseButton:!1,withinPortal:!0,zIndex:300,styles:{body:{padding:"0 !important"},content:{overflowY:"hidden !important"}},children:n.jsxs(s.AppShell,{padding:0,navbar:{width:{base:220,xs:220,sm:240,md:260,lg:300,xl:320},breakpoint:"xxs"},styles:mD,children:[n.jsx(wD,{}),n.jsx(s.AppShell.Main,{children:n.jsx(dD,{})})]})})}),SD=e=>e.replace(/([^:])(\/\/+)/g,"$1/");function TD(e){h.useEffect(()=>{if(Te.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/dashboard");const r=SD(e);Te.loader.config({paths:{vs:r}}),Te.loader.init().then(a=>console.log("monaco instance:",a))},[])}const kD=e=>{const t=h.useCallback(r=>{const a=r||window.event;return a.preventDefault(),a&&(a.returnValue=""),""},[]);h.useEffect(()=>{if(e)return window.addEventListener("beforeunload",t),()=>{window.removeEventListener("beforeunload",t)}},[e])};qs(),il();const zD={root:{height:"100vh",display:"flex",flexDirection:"column",overflow:"hidden","--app-shell-header-offset":"calc(3.75rem * var(--mantine-scale))"},body:{flexGrow:1},main:{flexGrow:1,display:"flex",flexDirection:"column",paddingTop:60+30,height:"100vh"}},DD=({context:e,dashboard:t,content:r,update:a,className:l="dashboard",config:o,onChange:i,headerSlot:c,filterValues:d,onFilterValuesChange:u,onExit:p,lang:f},v)=>{TD(o.monacoPath),Kr(o);const{data:_=[]}=O.useRequest(Ca),{data:w=[]}=O.useRequest(Si),m=h.useMemo(()=>vc(t,r,_,w,e,d??{}),[t,r]);h.useImperativeHandle(v,()=>m,[m]),_c(m.content,!0),h.useEffect(()=>{m.context.replace(e)},[e]),h.useEffect(()=>{m.datasources.replace(_)},[_]),h.useEffect(()=>{m.globalSQLSnippets.replace(w)},[w]),h.useEffect(()=>{u==null||u(m.content.filters.values)},[u,m.content.filters.values]),h.useEffect(()=>{d&&m.content.filters.patchValues(d)},[d,m.content.filters.patchValues]),h.useEffect(()=>Q.reaction(()=>Q.toJS(m.json),I=>{i==null||i(I)}),[m]);const k=async()=>{await a(m.json,m.content.json)},z=O.useCreation(Yr,[]),D=xc(z);return kD(m.content.changed),O.useWhyDidYouUpdate("@devtable/dashboard editor",{context:e,dashboard:t,content:r,update:a,className:l,config:o,onChange:i,headerSlot:c,filterValues:d,onFilterValuesChange:u,onExit:p,lang:f}),n.jsx(dt.MantineEmotionProvider,{children:n.jsx(zo,{lang:f,children:n.jsx(ze.ModalsProvider,{children:n.jsx(Xn,{children:n.jsx(Fn,{value:{renderSearchButton:o.renderSearchButton},children:n.jsx(Gn,{value:m,children:n.jsx(Qn,{value:m.content,children:n.jsxs(Gt.Provider,{value:{inEditMode:!0},children:[n.jsx(lk,{}),n.jsx(rt.Provider,{value:z,children:n.jsxs(ln,{configure:D,children:[n.jsxs(s.AppShell,{padding:0,navbar:{width:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},breakpoint:"xxs"},styles:zD,children:[n.jsx(dk,{onExit:p,saveDashboardChanges:k,headerSlot:c}),n.jsx(Lk,{}),n.jsx(s.AppShell.Main,{children:n.jsx(s.Box,{className:`${l} dashboard-root`,sx:{position:"relative"},children:m.content.views.visibleViews.map(I=>n.jsx(tc,{view:I},I.id))})})]}),n.jsx(CD,{})]})})]})})})})})})})})},ID=T.observer(h.forwardRef(DD)),Q5="",Ya=g.types.model({id:g.types.string,name:g.types.string,dashboard_id:g.types.string,create_time:g.types.string,update_time:g.types.string,version:g.types.string,filters:wa,queries:Ta,sqlSnippets:za,views:va,panels:xa,layouts:ka,mock_context:Xr}).views(e=>({get json(){return{id:e.id,name:e.name,create_time:e.create_time,update_time:e.update_time,dashboard_id:e.dashboard_id,content:{views:e.views.json,panels:e.panels.json,filters:e.filters.json,version:e.version,layouts:e.layouts.json,definition:{queries:e.queries.json,sqlSnippets:e.sqlSnippets.json,mock_context:e.mock_context.current}}}},get contentJSON(){return this.json.content},get payloadForSQL(){const t=g.getParent(e).context.current,r=g.getParent(e).globalSQLSnippets,a={context:{...e.mock_context.current,...t},filters:e.filters.valuesForPayload};return{...a,sql_snippets:Ut(e.sqlSnippets.current,"key","value",a),global_sql_snippets:Ut(r.list,"id","content",a)}},get payloadForViz(){const t=g.getParent(e).context.current;return{context:{...e.mock_context.current,...t},filters:e.filters.valuesForPayload}},get dashboardState(){const{context:t,filters:r}=this.payloadForViz,a={context:{},filters:e.filters.keyStateItemMap(r)};return Object.entries(t).forEach(([l,o])=>{a.context[l]={type:"context",key:l,value:o}}),a},get dashboardStateValues(){return sr(this.payloadForSQL)},getAdditionalQueryInfo(t){return{content_id:e.id,query_id:t,params:this.dashboardStateValues}},get data(){return e.queries.current.map(({id:r,data:a})=>({id:r,data:a})).reduce((r,a)=>(r[a.id]=a.data,r),{})},getDataStuffByID(t){const r=e.queries.findByID(t);return r?{data:r.data,len:r.data.length,state:r.state,error:r.error??r.metricQueryPayloadErrorString}:{data:[],len:0,state:"idle",error:void 0}}})).actions(e=>({}));function Jc({id:e,name:t,dashboard_id:r,create_time:a,update_time:l,content:o},i,c,d){if(!o)throw new Error("unexpected null content when creating a content model");const{version:u,filters:p,views:f,panels:v,layouts:_,definition:{queries:w,sqlSnippets:m,mock_context:k={}}}=o;return Ya.create({id:e,name:t,dashboard_id:r,create_time:a,update_time:l,version:u,filters:ma(p,i,k,c),queries:ki(w),sqlSnippets:Ii(m),mock_context:Zr(k),views:fi(f,d),panels:{list:v},layouts:{list:_,currentBreakpoint:_[0].id}})}const Hc=g.types.model({id:g.types.identifier,name:g.types.string,group:g.types.string,content:Ya,content_id:g.types.string,datasources:hi,globalSQLSnippets:fa,context:Tn});function Rc({id:e,name:t,group:r,content_id:a},l,o,i,c,d,u){return Hc.create({id:e,name:t,group:r,content_id:a,content:Jc(l,c,d,u),datasources:{list:o},globalSQLSnippets:{list:i},context:ba(c)})}qs(),il();const MD=({context:e,dashboard:t,content:r,className:a="dashboard",config:l,fullScreenPanelID:o,setFullScreenPanelID:i,filterValues:c,onFilterValuesChange:d,activeTab:u,onActiveTabChange:p,lang:f})=>{Kr(l);const{data:v=[]}=O.useRequest(Ca),{data:_=[]}=O.useRequest(Si),w=h.useMemo(()=>Rc(t,r,v,_,e,c??{},u??null),[t,r]);_c(w.content,!1),h.useEffect(()=>{w.context.replace(e)},[e]),h.useEffect(()=>{w.datasources.replace(v)},[v]),h.useEffect(()=>{w.globalSQLSnippets.replace(_)},[_]),h.useEffect(()=>{console.log("⚪️ calling onFilterValuesChange: ",w.content.filters.values),d==null||d(w.content.filters.values)},[d,w.content.filters.valuesString]),h.useEffect(()=>{c&&w.content.filters.patchValues(c)},[c,w.content.filters.patchValues]),h.useEffect(()=>{p==null||p(w.content.views.firstVisibleTabsViewActiveTab)},[p,w.content.views.firstVisibleTabsViewActiveTabStr]),h.useEffect(()=>{u&&w.content.views.setFirstVisibleTabsViewActiveTab(u)},[u,w.content.views.setFirstVisibleTabsViewActiveTab]);const m=O.useCreation(Yr,[w]),k=xc(m);return O.useWhyDidYouUpdate("@devtable/dashboard render",{context:e,dashboard:t,content:r,className:a,config:l,fullScreenPanelID:o,setFullScreenPanelID:i,filterValues:c,onFilterValuesChange:d,activeTab:u,onActiveTabChange:p,lang:f}),n.jsx(dt.MantineEmotionProvider,{children:n.jsx(zo,{lang:f,children:n.jsx(ze.ModalsProvider,{children:n.jsx(Xn,{children:n.jsx(Fn,{value:{renderSearchButton:l.renderSearchButton},children:n.jsx(Gn,{value:w,children:n.jsx(Qn,{value:w.content,children:n.jsx(Kn.Provider,{value:{fullScreenPanelID:o,setFullScreenPanelID:i},children:n.jsx(Gt.Provider,{value:{inEditMode:!1},children:n.jsx(s.Box,{className:`${a} dashboard-root`,children:n.jsx(rt.Provider,{value:m,children:n.jsx(ln,{configure:k,children:w.content.views.visibleViews.map(z=>n.jsx(Dn,{view:z},z.id))})})})})})})})})})})})})},AD=T.observer(MD),PD=()=>Promise.resolve().then(()=>cu).then(({version:e})=>(console.log(`[@devtable/dashboard] version: ${e}`),e));C.APIClient=Ae,C.CURRENT_SCHEMA_VERSION=at,C.ClientPanelRender=QT,C.ContentModel=La,C.ContentModelContext=jn,C.ContentModelContextProvider=Qn,C.ContentRenderModel=Ya,C.ContextMeta=Tn,C.DEFAULT_CUSTOM_MODAL_TITLE=Sn,C.DashboardApiClient=Io,C.DashboardApiFacadeClient=Mo,C.DashboardEditor=ID,C.DashboardFilterType=V,C.DashboardMode=nc,C.DashboardModel=yc,C.DashboardModelContextProvider=Gn,C.DashboardRenderModel=Hc,C.DashboardThemeContextProvider=Fn,C.DashboardViewEditor=tc,C.DashboardViewRender=Dn,C.DataSourceMetaModel=ga,C.DataSourceType=j,C.DataSourcesMetaModel=hi,C.DatesProvider=Xn,C.DefaultApiClient=Do,C.DefaultValueModeModelType=Hr,C.DescriptionPopover=Da,C.DraftModel=Mi,C.EViewComponentType=$,C.FacadeApiClient=yS,C.FilterCheckboxConfigMeta=Rr,C.FilterDateRangeConfigMeta=ta,C.FilterMeta=Cn,C.FilterModel=ac,C.FilterMultiSelectConfigMeta=ra,C.FilterSelectConfigMeta=aa,C.FilterTextInputConfigMeta=sa,C.FilterTreeSelectConfigMeta=ca,C.FilterTreeSingleSelectConfigMeta=da,C.FiltersModel=sc,C.FiltersRenderModel=wa,C.FullScreenPanel=Zi,C.FullScreenPanelContext=Kn,C.GlobalSQLSnippetMeta=gi,C.GlobalSQLSnippetsMeta=fa,C.LayoutItemMeta=jo,C.LayoutSetMeta=Qo,C.LayoutStateContext=Gt,C.LayoutsRenderModel=ka,C.MericoMetricQueryMeta=Jr,C.MockContextMeta=Xr,C.MuteQueryModel=Ti,C.Panel=Xi,C.PanelContextProvider=Un,C.PanelErrorOrStateMessage=Ki,C.PanelMeta=Bo,C.PanelModel=hc,C.PanelRender=Va,C.PanelRenderModel=_a,C.PanelStyleMeta=Po,C.PanelTitleMeta=Vo,C.PanelVizAddons=Yi,C.PanelVizMeta=Eo,C.PanelVizSection=Aa,C.PanelsModel=gc,C.PanelsRenderModel=xa,C.QueriesModel=oc,C.QueriesRenderModel=Ta,C.QueryMeta=Fo,C.QueryModel=lc,C.QueryRenderModel=Sa,C.ReadOnlyDashboard=AD,C.SQLSnippetMeta=Wo,C.SQLSnippetRenderModel=Di,C.SQLSnippetsModel=ic,C.SQLSnippetsRenderModel=za,C.VariableMeta=$o,C.ViewComponentTypeBackground=rc,C.ViewComponentTypeColor=c2,C.ViewComponentTypeName=i2,C.ViewDivisionConfig=ua,C.ViewMeta=pi,C.ViewModalConfig=pa,C.ViewRenderModel=ya,C.ViewTabsConfig=ha,C.ViewsModel=fc,C.ViewsRenderModel=va,C.Viz=Ui,C.applyPartialDashboard=O2,C.configureAPIClient=Kr,C.createContentModel=bc,C.createContentRenderModel=Jc,C.createContextMeta=ba,C.createDashboardModel=vc,C.createDashboardRenderModel=Rc,C.createDraft=Ai,C.createFilterCheckboxConfig=Uo,C.createFilterDateRangeConfig=Jo,C.createFilterMultiSelectConfig=Ro,C.createFilterSelectConfig=ei,C.createFilterTextInputConfig=la,C.createFilterTreeSelectConfig=oi,C.createFilterTreeSingleSelectConfig=ii,C.createMericoMetricQueryMetaConfig=Go,C.createViewDivisionConfig=ci,C.createViewModalConfig=di,C.createViewTabsConfig=ui,C.facadeApiClient=Ao,C.formatSQLSnippet=Ut,C.getInitialDashboardViewsModel=Ba,C.getInitialFiltersConfig=ma,C.getInitialMockContextMeta=Zr,C.getInitialQueriesRenderModel=ki,C.getInitialSQLSnippetsRenderModel=Ii,C.getInitialViewsRenderModel=fi,C.getNewPanel=_i,C.getStaticDateRangeDefaultValue=Xo,C.getVersion=PD,C.initialDashboardContent=jS,C.notifyVizRendered=de,C.onVizRendered=Dp,C.pluginManager=Ct,C.pluginServices=R,C.useContentModelContext=Wn,C.useDashboardContext=Nt,C.useDashboardThemeContext=Ds,C.useEditContentModelContext=F,C.useEditDashboardContext=W,C.useEditPanelContext=re,C.useFullScreenPanelContext=Vs,C.useIsInEditPanelContext=Ps,C.useIsInRenderPanelContext=As,C.usePanelFullScreen=Ji,C.useRenderContentModelContext=J,C.useRenderDashboardContext=ks,C.useRenderPanelContext=be,C.useServiceLocator=Qt,C.useVisibleFilters=fT,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})});
|