@devtable/dashboard 14.54.0 → 14.54.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dashboard.es.js +2915 -2908
- package/dist/dashboard.umd.js +15 -15
- package/dist/stats.html +1 -1
- package/dist/version.json +2 -2
- package/package.json +1 -1
package/dist/dashboard.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(C,Ce){typeof exports=="object"&&typeof module<"u"?Ce(exports,require("i18next"),require("react-i18next"),require("i18next-browser-languagedetector"),require("intl-pluralrules"),require("lodash"),require("mobx"),require("eventemitter2"),require("react/jsx-runtime"),require("react"),require("chroma-js"),require("echarts-for-react/lib/core"),require("echarts-gl"),require("echarts/core"),require("ahooks"),require("@mantine/dates"),require("@mantine/core"),require("@mantine/hooks"),require("popmotion"),require("d3-array"),require("mathjs"),require("@faker-js/faker"),require("crypto-js"),require("dayjs"),require("numbro"),require("@tabler/icons-react"),require("@mantine/tiptap"),require("@tiptap/extension-color"),require("@tiptap/extension-highlight"),require("@tiptap/extension-placeholder"),require("@tiptap/extension-subscript"),require("@tiptap/extension-superscript"),require("@tiptap/extension-table"),require("@tiptap/extension-table-cell"),require("@tiptap/extension-table-header"),require("@tiptap/extension-table-row"),require("@tiptap/extension-text-align"),require("@tiptap/extension-text-style"),require("@tiptap/extension-underline"),require("@tiptap/react"),require("@tiptap/starter-kit"),require("@monaco-editor/react"),require("@tiptap/core"),require("d3-scale"),require("react-hook-form"),require("mobx-react-lite"),require("@dnd-kit/helpers"),require("@dnd-kit/react"),require("@dnd-kit/react/sortable"),require("uuid"),require("echarts/charts"),require("echarts/components"),require("echarts/renderers"),require("constrained-editor-plugin"),require("@mantine/notifications"),require("@mantine/emotion"),require("d3-regression"),require("@mantine/code-highlight"),require("@tanstack/react-table"),require("@tanstack/react-virtual"),require("axios"),require("dayjs/plugin/advancedFormat"),require("dayjs/plugin/arraySupport"),require("dayjs/plugin/buddhistEra"),require("dayjs/plugin/calendar"),require("dayjs/plugin/customParseFormat"),require("dayjs/plugin/dayOfYear"),require("dayjs/plugin/duration"),require("dayjs/plugin/isBetween"),require("dayjs/plugin/isLeapYear"),require("dayjs/plugin/isMoment"),require("dayjs/plugin/isoWeek"),require("dayjs/plugin/isoWeeksInYear"),require("dayjs/plugin/isSameOrAfter"),require("dayjs/plugin/isSameOrBefore"),require("dayjs/plugin/isToday"),require("dayjs/plugin/isTomorrow"),require("dayjs/plugin/isYesterday"),require("dayjs/plugin/localeData"),require("dayjs/plugin/localizedFormat"),require("dayjs/plugin/minMax"),require("dayjs/plugin/objectSupport"),require("dayjs/plugin/pluralGetSet"),require("dayjs/plugin/preParsePostFormat"),require("dayjs/plugin/quarterOfYear"),require("dayjs/plugin/relativeTime"),require("dayjs/plugin/timezone"),require("dayjs/plugin/toArray"),require("dayjs/plugin/toObject"),require("dayjs/plugin/updateLocale"),require("dayjs/plugin/utc"),require("dayjs/plugin/weekday"),require("dayjs/plugin/weekOfYear"),require("dayjs/plugin/weekYear"),require("mobx-state-tree"),require("dom-to-image-more"),require("file-saver"),require("jszip"),require("@json2csv/whatwg"),require("js-base64"),require("rc-tree-select"),require("performant-array-to-tree"),require("rc-select"),require("react-dom"),require("react-grid-layout"),require("@mantine/modals"),require("react-router-dom"),require("@mantine/spotlight"),require("@mantine/spotlight/styles.css"),require("reactflow"),require("reactflow/dist/style.css")):typeof define=="function"&&define.amd?define(["exports","i18next","react-i18next","i18next-browser-languagedetector","intl-pluralrules","lodash","mobx","eventemitter2","react/jsx-runtime","react","chroma-js","echarts-for-react/lib/core","echarts-gl","echarts/core","ahooks","@mantine/dates","@mantine/core","@mantine/hooks","popmotion","d3-array","mathjs","@faker-js/faker","crypto-js","dayjs","numbro","@tabler/icons-react","@mantine/tiptap","@tiptap/extension-color","@tiptap/extension-highlight","@tiptap/extension-placeholder","@tiptap/extension-subscript","@tiptap/extension-superscript","@tiptap/extension-table","@tiptap/extension-table-cell","@tiptap/extension-table-header","@tiptap/extension-table-row","@tiptap/extension-text-align","@tiptap/extension-text-style","@tiptap/extension-underline","@tiptap/react","@tiptap/starter-kit","@monaco-editor/react","@tiptap/core","d3-scale","react-hook-form","mobx-react-lite","@dnd-kit/helpers","@dnd-kit/react","@dnd-kit/react/sortable","uuid","echarts/charts","echarts/components","echarts/renderers","constrained-editor-plugin","@mantine/notifications","@mantine/emotion","d3-regression","@mantine/code-highlight","@tanstack/react-table","@tanstack/react-virtual","axios","dayjs/plugin/advancedFormat","dayjs/plugin/arraySupport","dayjs/plugin/buddhistEra","dayjs/plugin/calendar","dayjs/plugin/customParseFormat","dayjs/plugin/dayOfYear","dayjs/plugin/duration","dayjs/plugin/isBetween","dayjs/plugin/isLeapYear","dayjs/plugin/isMoment","dayjs/plugin/isoWeek","dayjs/plugin/isoWeeksInYear","dayjs/plugin/isSameOrAfter","dayjs/plugin/isSameOrBefore","dayjs/plugin/isToday","dayjs/plugin/isTomorrow","dayjs/plugin/isYesterday","dayjs/plugin/localeData","dayjs/plugin/localizedFormat","dayjs/plugin/minMax","dayjs/plugin/objectSupport","dayjs/plugin/pluralGetSet","dayjs/plugin/preParsePostFormat","dayjs/plugin/quarterOfYear","dayjs/plugin/relativeTime","dayjs/plugin/timezone","dayjs/plugin/toArray","dayjs/plugin/toObject","dayjs/plugin/updateLocale","dayjs/plugin/utc","dayjs/plugin/weekday","dayjs/plugin/weekOfYear","dayjs/plugin/weekYear","mobx-state-tree","dom-to-image-more","file-saver","jszip","@json2csv/whatwg","js-base64","rc-tree-select","performant-array-to-tree","rc-select","react-dom","react-grid-layout","@mantine/modals","react-router-dom","@mantine/spotlight","@mantine/spotlight/styles.css","reactflow","reactflow/dist/style.css"],Ce):(C=typeof globalThis<"u"?globalThis:C||self,Ce(C.dashboard={},C.i18next,C["react-i18next"],C["i18next-browser-languagedetector"],C["intl-pluralrules"],C._,C.mobx,C.eventemitter2,C["react/jsx-runtime"],C.react,C["chroma-js"],C["echarts-for-react/lib/core"],C["echarts-gl"],C["echarts/core"],C.ahooks,C["@mantine/dates"],C["@mantine/core"],C["@mantine/hooks"],C.popmotion,C["d3-array"],C.mathjs,C["@faker-js/faker"],C.CryptoJS,C.dayjs,C.numbro,C["@tabler/icons-react"],C["@mantine/tiptap"],C["@tiptap/extension-color"],C["@tiptap/extension-highlight"],C["@tiptap/extension-placeholder"],C["@tiptap/extension-subscript"],C["@tiptap/extension-superscript"],C["@tiptap/extension-table"],C["@tiptap/extension-table-cell"],C["@tiptap/extension-table-header"],C["@tiptap/extension-table-row"],C["@tiptap/extension-text-align"],C["@tiptap/extension-text-style"],C["@tiptap/extension-underline"],C["@tiptap/react"],C["@tiptap/starter-kit"],C["@monaco-editor/react"],C["@tiptap/core"],C["d3-scale"],C["react-hook-form"],C["mobx-react-lite"],C["@dnd-kit/helpers"],C["@dnd-kit/react"],C["@dnd-kit/react/sortable"],C.uuid,C["echarts/charts"],C["echarts/components"],C["echarts/renderers"],C["constrained-editor-plugin"],C["@mantine/notifications"],C["@mantine/emotion"],C["d3-regression"],C["@mantine/code-highlight"],C["@tanstack/react-table"],C["@tanstack/react-virtual"],C.axios,C["dayjs/plugin/advancedFormat"],C["dayjs/plugin/arraySupport"],C["dayjs/plugin/buddhistEra"],C["dayjs/plugin/calendar"],C["dayjs/plugin/customParseFormat"],C["dayjs/plugin/dayOfYear"],C["dayjs/plugin/duration"],C["dayjs/plugin/isBetween"],C["dayjs/plugin/isLeapYear"],C["dayjs/plugin/isMoment"],C["dayjs/plugin/isoWeek"],C["dayjs/plugin/isoWeeksInYear"],C["dayjs/plugin/isSameOrAfter"],C["dayjs/plugin/isSameOrBefore"],C["dayjs/plugin/isToday"],C["dayjs/plugin/isTomorrow"],C["dayjs/plugin/isYesterday"],C["dayjs/plugin/localeData"],C["dayjs/plugin/localizedFormat"],C["dayjs/plugin/minMax"],C["dayjs/plugin/objectSupport"],C["dayjs/plugin/pluralGetSet"],C["dayjs/plugin/preParsePostFormat"],C["dayjs/plugin/quarterOfYear"],C["dayjs/plugin/relativeTime"],C["dayjs/plugin/timezone"],C["dayjs/plugin/toArray"],C["dayjs/plugin/toObject"],C["dayjs/plugin/updateLocale"],C["dayjs/plugin/utc"],C["dayjs/plugin/weekday"],C["dayjs/plugin/weekOfYear"],C["dayjs/plugin/weekYear"],C["mobx-state-tree"],C["dom-to-image-more"],C["file-saver"],C.jszip,C["@json2csv/whatwg"],C["js-base64"],C["rc-tree-select"],C["performant-array-to-tree"],C["rc-select"],C["react-dom"],C["react-grid-layout"],C["@mantine/modals"],C["react-router-dom"],C["@mantine/spotlight"],C["@mantine/spotlight/styles"].css,C.reactflow))})(this,function(C,Ce,m,Ld,VM,b,F,fs,n,h,Ne,he,PM,bs,O,wt,s,te,ut,Qt,Od,Nd,ys,M,Ee,S,Q,vs,_s,ms,ws,xs,Cs,Ss,Ts,ks,Ds,zs,Ms,Is,Vs,Se,Qn,Gd,y,k,jn,nn,rn,Te,Je,pt,Fd,Qd,Ge,ht,jd,Fe,ge,Wd,ke,Ud,Kd,Yd,Xd,Zd,Jd,Hd,Rd,eu,tu,nu,ru,au,su,ou,lu,iu,cu,du,uu,pu,hu,gu,fu,bu,yu,vu,_u,mu,wu,xu,Cu,Su,g,Ps,an,$s,Tu,As,Wn,ku,Es,Du,sn,De,zu,xt,$M,ie){"use strict";var MM=Object.defineProperty;var IM=(C,Ce,m)=>Ce in C?MM(C,Ce,{enumerable:!0,configurable:!0,writable:!0,value:m}):C[Ce]=m;var V=(C,Ce,m)=>(IM(C,typeof Ce!="symbol"?Ce+"":Ce,m),m);function Ct(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const a=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,a.get?a:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const ce=Ct(bs),Mu=Ct(ut),Bs=Ct(Qt),Qe=Ct(Od),Iu=Ct(ys),Vu=Ct(Gd),gt=Ct(jd),Pu={translation:{filter:{label:"Filter",labels:"Filters",add:"Add a Filter",manage:"Manage Filters",delete:"Delete this filter",show_filters:"Show Filters",hide_filters:"Hide Filters",usage:{label:"Usage",unused_description:"This filter is not used by any query, SQL snippet or view"},field:{widget:"Widget",visible_in:"Visible in...",key_placeholder:"A unique key to refer",label_placeholder:"Label for this field",auto_submit:"Submit automatically",order:"Placement Order",custom_default_value:{trigger:"Custom default value",title:"Custom default value",tips:"Tips",tip_1:"Function has the highest priority of getting filter's default value",tip_2:"Leave this editor empty to disable this feature"}},widget:{names:{select:"Select",multi_select:"Multi Select",tree_select:"Tree Select",tree_single_select:"Tree Single Select",text_input:"Text Input",checkbox:"Checkbox",date_range:"Date Range",merico_date_range:"Merico Date Range"},common:{use_query_data_as_options:"Use query data as options",fetch_options_from_datasource:"Fetch options from datasource",or_fetch_options_from_datasource:"Or fetch options from datasource",selector_option_empty:"Not found",see_data_structure:"Click to see expected data structure",using_query:"Using query",default_selection_count:"Select first N options by default",min_width:"Min width",x_selected:"{{count}} selected",default_value_mode:{label:"When options change",intersect:"Preserve valid entries from current selection",reset:"Use new options"}},text_input:{default_value:"Default Value",required:"Required"},select:{width:"Width",required:"Required",clearable:"Clearable",configure_options:"Configure options",default_selection:"Default Selection",no_default_selection:"none",select_first_option_by_default:"Select the first option by default",preset_options:{apply:"Apply preset options",date_unit:"Date units"}},multi_select:{width_description:"At least 160px"},tree_select:{strictly:"Parent and children nodes are not associated"},tree_single_select:{select_first_option_by_default:"Select the first option by default"},checkbox:{description:"Description",default_checked:"Default checked"},date_range:{required:"Required",allow_single_date:"Allow choosing 1 day",display_format:"Display format",max_days:"Max days",one_day:"1 day",x_days:"{{count}} days",x_max_days:"{{max_days}} days max",default_value:"Default value",default_by_shortcut:"Default by shortcut",default_by_shortcut_placeholder:"Priors default value",start_date:"Start date",end_date:"End date",step:{label:"Step",day:"Day",week:"Week",bi_week:"Bi-Week",month:"Month",quarter:"Quarter",year:"Year"},shortcut:{last:{label:"last",d:"yesterday",w:"week",m:"month",m2:"2 months",m3:"3 months",m6:"6 months",y:"year",full:{d:"yesterday",w:"last week",m:"last month",m2:"last 2 months",m3:"last 3 months",m6:"last 6 months",y:"last year"}},recent:{label:"recent",d7:"7 days",d30:"30 days",d60:"60 days",d90:"90 days",d180:"180 days",d365:"365 days",full:{d7:"recent 7 days",d30:"recent 30 days",d60:"recent 60 days",d90:"recent 90 days",d180:"recent 180 days",d365:"recent 365 days"}},this:{label:"this",d:"today",w:"week",m:"month",y:"year",full:{d:"today",w:"this week",m:"this month",y:"this year"}},this_so_far:{label:"this...so far",w:"week",m:"month",y:"year",full:{w:"this week so far",m:"this month so far",y:"this year so far"}}}}}},view:{label:"View",labels:"Views",add:"Add a View",delete:"Delete this View",download_schema:"Download this View",layout:{drag_to_move:"Drag to move"},component:{div:{label:"Division"},tabs:{label:"Tabs",tabs_settings:"Tabs Settings",tab:{name:"Tab Name",view:"View",order:"Placement Order",color:"Color",delete:"Delete this tab",switch_to_view:"Swith to View: {{name}}"}},modal:{label:"Modal",modal_settings:"Modal settings",title:"Modal Title",custom_title:"Customize modal title",width:"Width",height:"Height"}}},interactions:{label:"Interactions",add:"Add an interaction",interactions_viewer:"Interactions Viewer",unavailable:"Unavailable",unavailable_reason:"This visualization does not have available interactions to choose from",trigger:{setup:"Setup Trigger",label:"Trigger",payload:"Payload"},operation:{setup:"Operation Settings",label:"Operation",settings:"Settings",variables:"Variables",console_log:{label:"console.log | debug",log_content:"log content"},open_link:{label:"Open Link",url:"URL",open_in_new_tab:"Open in new tab"},open_view:{label:"Open View",view:"View"},switch_tab:{label:"Switch Tab",view:"View",tab:"Tab"},scroll_to_panel:{label:"Scroll to Panel",panel:"Panel"},set_filter_values:{label:"Set Filter Values",set_filter:"Set filter",with:"with"},clear_filter_values:{label:"Clear Filter Values",select_filter:"Select filters to clear"}}},query_variable:{label:"Query Variable",labels:"Query Variables",add:"Add a Variable",guide:{tabs:{guide:"Guide",variables_in_this_dashboard:"Variables in this dashboard",global_sql_snippets:"Global SQL Snippets"}},open:"See Query Variables"},sql_snippet:{label:"SQL Snippet",labels:"SQL Snippets",add:"Add a SQL Snippet",delete:"Delete this SQL Snippet",delete_unused:"Delete unused SQL Snippets",manage:"Manage SQL Snippets",key:"Key",key_occupied:"This key is occupied by another snippet",edit_snippet:"Edit SQL Snippet",preview_snippet:"Preview SQL Snippet",usage:{label:"Usage"}},global_sql_snippet:{label:"Global SQL Snippet",labels:"Global SQL Snippets",description:"SQL snippets worth sharing between dashboards are managed in System Settings by admins."},common:{titles:{settings:"Settings",edit:"Edit",config:"Config"},pagination:{label:"Pagination",page_size:"Page Size",total:"Total",total_rows:"Total {{total}} row(s)",to_previous_page:"To previous page",to_next_page:"To next page",showing_rows:"Showing {{start_row}} - {{end_row}} of {{total}} rows"},align:{horizontal:{label:"Horizontal Align",left:"left",center:"center",right:"right"},vertical:{label:"Vertical Align",top:"top",center:"center",bottom:"bottom"}},id:"ID",name:"Name",key:"Key",label:"Label",value:"Value",type:"Type",info:"Info",min:"Min",max:"Max",invalid:"Invalid",data_field:"Data Field",name_data_field:"Name Data Field",value_data_field:"Value Data Field",color_data_field:"Color Data Field",enabled:"Enabled",copied:"Copied to clipboard",action:"Action",actions:{search:"Search",reload:"Reload",actions:"Actions",open:"Open",close:"Close",save:"Save",save_changes:"Save Changes",revert:"Revert",revert_changes:"Revert Changes",reset_to_default:"Reset to default",init_with_default:"Init with default",select_all:"Select All",clear:"Clear",clear_selection:"Clear Selection",refresh:"Refresh",download_data:"Download Data",download_schema:"Download Schema",download_screenshot:"Screenshot",enter_fullscreen:"Full Screen",duplicate:"Duplicate",delete:"Delete",cancel:"Cancel",confirm:"Confirm",add_an_option:"Add an Option",edit:"Edit",end_editing:"End editing <0>{{name}}</0>"},tabs:{variant:{label:"Variant",default:"Default",outline:"Outline",pills:"Pills"},orientation:{label:"Orientation",horizontal:"Horizontal",vertical:"Vertical"},grow_tabs:"Grow Tabs"},choose_a_tab_first:"Please choose a tab first"},breakpoint:{label_one:"Screen size",label_other:"Screen sizes",add:"Add a screen size",manage:"Manage screen sizes",breakpoint:"Min Width"},context:{label:"Context"},mock_context:{label:"Mock Context",hint:"A valid json string is required"},panel:{label:"Panel",labels:"Panels",add:"Add a Panel",delete:"Delete This Panel",panel_name:"Panel Name",panel_description:"Description",panel_description_click:"Click to see description",show_title:"Show title",use_name_as_title:"Use name as title",settings:{change_view:"Move into Another View",change_view_title:"Move panel into another view",choose_queries:"Choose queries",need_to_choose_queries:"Choose at least 1 query for its data"},style:{label:"Style",width:"Width",width_postfix:"of 36 columns",height:"Height",height_postfix:"px",border:"Border"},variable:{label:"Variable",labels:"Variables",add:"Add a Variable",delete:"Delete this Variable",aggregation:{label:"Aggregation",fallback_value:"Fallback Value",fallback_value_description:"Used when data is empty or the aggregation yields NaN"},guide:{text:`-- You may reference dashboard state & panel variables in rich-text content or custom functions.
|
|
1
|
+
(function(C,Ce){typeof exports=="object"&&typeof module<"u"?Ce(exports,require("i18next"),require("react-i18next"),require("i18next-browser-languagedetector"),require("intl-pluralrules"),require("lodash"),require("mobx"),require("eventemitter2"),require("react/jsx-runtime"),require("react"),require("chroma-js"),require("echarts-for-react/lib/core"),require("echarts-gl"),require("echarts/core"),require("ahooks"),require("@mantine/dates"),require("@mantine/core"),require("@mantine/hooks"),require("popmotion"),require("d3-array"),require("mathjs"),require("@faker-js/faker"),require("crypto-js"),require("dayjs"),require("numbro"),require("@tabler/icons-react"),require("@mantine/tiptap"),require("@tiptap/extension-color"),require("@tiptap/extension-highlight"),require("@tiptap/extension-placeholder"),require("@tiptap/extension-subscript"),require("@tiptap/extension-superscript"),require("@tiptap/extension-table"),require("@tiptap/extension-table-cell"),require("@tiptap/extension-table-header"),require("@tiptap/extension-table-row"),require("@tiptap/extension-text-align"),require("@tiptap/extension-text-style"),require("@tiptap/extension-underline"),require("@tiptap/react"),require("@tiptap/starter-kit"),require("@monaco-editor/react"),require("@tiptap/core"),require("d3-scale"),require("react-hook-form"),require("mobx-react-lite"),require("@dnd-kit/helpers"),require("@dnd-kit/react"),require("@dnd-kit/react/sortable"),require("uuid"),require("echarts/charts"),require("echarts/components"),require("echarts/renderers"),require("constrained-editor-plugin"),require("@mantine/notifications"),require("@mantine/emotion"),require("d3-regression"),require("@mantine/code-highlight"),require("@tanstack/react-table"),require("@tanstack/react-virtual"),require("axios"),require("dayjs/plugin/advancedFormat"),require("dayjs/plugin/arraySupport"),require("dayjs/plugin/buddhistEra"),require("dayjs/plugin/calendar"),require("dayjs/plugin/customParseFormat"),require("dayjs/plugin/dayOfYear"),require("dayjs/plugin/duration"),require("dayjs/plugin/isBetween"),require("dayjs/plugin/isLeapYear"),require("dayjs/plugin/isMoment"),require("dayjs/plugin/isoWeek"),require("dayjs/plugin/isoWeeksInYear"),require("dayjs/plugin/isSameOrAfter"),require("dayjs/plugin/isSameOrBefore"),require("dayjs/plugin/isToday"),require("dayjs/plugin/isTomorrow"),require("dayjs/plugin/isYesterday"),require("dayjs/plugin/localeData"),require("dayjs/plugin/localizedFormat"),require("dayjs/plugin/minMax"),require("dayjs/plugin/objectSupport"),require("dayjs/plugin/pluralGetSet"),require("dayjs/plugin/preParsePostFormat"),require("dayjs/plugin/quarterOfYear"),require("dayjs/plugin/relativeTime"),require("dayjs/plugin/timezone"),require("dayjs/plugin/toArray"),require("dayjs/plugin/toObject"),require("dayjs/plugin/updateLocale"),require("dayjs/plugin/utc"),require("dayjs/plugin/weekday"),require("dayjs/plugin/weekOfYear"),require("dayjs/plugin/weekYear"),require("mobx-state-tree"),require("dom-to-image-more"),require("file-saver"),require("jszip"),require("@json2csv/whatwg"),require("js-base64"),require("rc-tree-select"),require("performant-array-to-tree"),require("rc-select"),require("react-dom"),require("react-grid-layout"),require("@mantine/modals"),require("react-router-dom"),require("@mantine/spotlight"),require("@mantine/spotlight/styles.css"),require("reactflow"),require("reactflow/dist/style.css")):typeof define=="function"&&define.amd?define(["exports","i18next","react-i18next","i18next-browser-languagedetector","intl-pluralrules","lodash","mobx","eventemitter2","react/jsx-runtime","react","chroma-js","echarts-for-react/lib/core","echarts-gl","echarts/core","ahooks","@mantine/dates","@mantine/core","@mantine/hooks","popmotion","d3-array","mathjs","@faker-js/faker","crypto-js","dayjs","numbro","@tabler/icons-react","@mantine/tiptap","@tiptap/extension-color","@tiptap/extension-highlight","@tiptap/extension-placeholder","@tiptap/extension-subscript","@tiptap/extension-superscript","@tiptap/extension-table","@tiptap/extension-table-cell","@tiptap/extension-table-header","@tiptap/extension-table-row","@tiptap/extension-text-align","@tiptap/extension-text-style","@tiptap/extension-underline","@tiptap/react","@tiptap/starter-kit","@monaco-editor/react","@tiptap/core","d3-scale","react-hook-form","mobx-react-lite","@dnd-kit/helpers","@dnd-kit/react","@dnd-kit/react/sortable","uuid","echarts/charts","echarts/components","echarts/renderers","constrained-editor-plugin","@mantine/notifications","@mantine/emotion","d3-regression","@mantine/code-highlight","@tanstack/react-table","@tanstack/react-virtual","axios","dayjs/plugin/advancedFormat","dayjs/plugin/arraySupport","dayjs/plugin/buddhistEra","dayjs/plugin/calendar","dayjs/plugin/customParseFormat","dayjs/plugin/dayOfYear","dayjs/plugin/duration","dayjs/plugin/isBetween","dayjs/plugin/isLeapYear","dayjs/plugin/isMoment","dayjs/plugin/isoWeek","dayjs/plugin/isoWeeksInYear","dayjs/plugin/isSameOrAfter","dayjs/plugin/isSameOrBefore","dayjs/plugin/isToday","dayjs/plugin/isTomorrow","dayjs/plugin/isYesterday","dayjs/plugin/localeData","dayjs/plugin/localizedFormat","dayjs/plugin/minMax","dayjs/plugin/objectSupport","dayjs/plugin/pluralGetSet","dayjs/plugin/preParsePostFormat","dayjs/plugin/quarterOfYear","dayjs/plugin/relativeTime","dayjs/plugin/timezone","dayjs/plugin/toArray","dayjs/plugin/toObject","dayjs/plugin/updateLocale","dayjs/plugin/utc","dayjs/plugin/weekday","dayjs/plugin/weekOfYear","dayjs/plugin/weekYear","mobx-state-tree","dom-to-image-more","file-saver","jszip","@json2csv/whatwg","js-base64","rc-tree-select","performant-array-to-tree","rc-select","react-dom","react-grid-layout","@mantine/modals","react-router-dom","@mantine/spotlight","@mantine/spotlight/styles.css","reactflow","reactflow/dist/style.css"],Ce):(C=typeof globalThis<"u"?globalThis:C||self,Ce(C.dashboard={},C.i18next,C["react-i18next"],C["i18next-browser-languagedetector"],C["intl-pluralrules"],C._,C.mobx,C.eventemitter2,C["react/jsx-runtime"],C.react,C["chroma-js"],C["echarts-for-react/lib/core"],C["echarts-gl"],C["echarts/core"],C.ahooks,C["@mantine/dates"],C["@mantine/core"],C["@mantine/hooks"],C.popmotion,C["d3-array"],C.mathjs,C["@faker-js/faker"],C.CryptoJS,C.dayjs,C.numbro,C["@tabler/icons-react"],C["@mantine/tiptap"],C["@tiptap/extension-color"],C["@tiptap/extension-highlight"],C["@tiptap/extension-placeholder"],C["@tiptap/extension-subscript"],C["@tiptap/extension-superscript"],C["@tiptap/extension-table"],C["@tiptap/extension-table-cell"],C["@tiptap/extension-table-header"],C["@tiptap/extension-table-row"],C["@tiptap/extension-text-align"],C["@tiptap/extension-text-style"],C["@tiptap/extension-underline"],C["@tiptap/react"],C["@tiptap/starter-kit"],C["@monaco-editor/react"],C["@tiptap/core"],C["d3-scale"],C["react-hook-form"],C["mobx-react-lite"],C["@dnd-kit/helpers"],C["@dnd-kit/react"],C["@dnd-kit/react/sortable"],C.uuid,C["echarts/charts"],C["echarts/components"],C["echarts/renderers"],C["constrained-editor-plugin"],C["@mantine/notifications"],C["@mantine/emotion"],C["d3-regression"],C["@mantine/code-highlight"],C["@tanstack/react-table"],C["@tanstack/react-virtual"],C.axios,C["dayjs/plugin/advancedFormat"],C["dayjs/plugin/arraySupport"],C["dayjs/plugin/buddhistEra"],C["dayjs/plugin/calendar"],C["dayjs/plugin/customParseFormat"],C["dayjs/plugin/dayOfYear"],C["dayjs/plugin/duration"],C["dayjs/plugin/isBetween"],C["dayjs/plugin/isLeapYear"],C["dayjs/plugin/isMoment"],C["dayjs/plugin/isoWeek"],C["dayjs/plugin/isoWeeksInYear"],C["dayjs/plugin/isSameOrAfter"],C["dayjs/plugin/isSameOrBefore"],C["dayjs/plugin/isToday"],C["dayjs/plugin/isTomorrow"],C["dayjs/plugin/isYesterday"],C["dayjs/plugin/localeData"],C["dayjs/plugin/localizedFormat"],C["dayjs/plugin/minMax"],C["dayjs/plugin/objectSupport"],C["dayjs/plugin/pluralGetSet"],C["dayjs/plugin/preParsePostFormat"],C["dayjs/plugin/quarterOfYear"],C["dayjs/plugin/relativeTime"],C["dayjs/plugin/timezone"],C["dayjs/plugin/toArray"],C["dayjs/plugin/toObject"],C["dayjs/plugin/updateLocale"],C["dayjs/plugin/utc"],C["dayjs/plugin/weekday"],C["dayjs/plugin/weekOfYear"],C["dayjs/plugin/weekYear"],C["mobx-state-tree"],C["dom-to-image-more"],C["file-saver"],C.jszip,C["@json2csv/whatwg"],C["js-base64"],C["rc-tree-select"],C["performant-array-to-tree"],C["rc-select"],C["react-dom"],C["react-grid-layout"],C["@mantine/modals"],C["react-router-dom"],C["@mantine/spotlight"],C["@mantine/spotlight/styles"].css,C.reactflow))})(this,function(C,Ce,m,Ld,VM,b,G,fs,n,h,Ne,he,PM,bs,O,wt,s,te,ut,Qt,Od,Nd,ys,M,Ee,S,Q,vs,_s,ms,ws,xs,Cs,Ss,Ts,ks,Ds,zs,Ms,Is,Vs,Se,Qn,Gd,y,k,jn,nn,rn,Te,Je,pt,Fd,Qd,Ge,ht,jd,Fe,ge,Wd,ke,Ud,Kd,Yd,Xd,Zd,Jd,Hd,Rd,eu,tu,nu,ru,au,su,ou,lu,iu,cu,du,uu,pu,hu,gu,fu,bu,yu,vu,_u,mu,wu,xu,Cu,Su,g,Ps,an,$s,Tu,As,Wn,ku,Es,Du,sn,De,zu,xt,$M,ie){"use strict";var MM=Object.defineProperty;var IM=(C,Ce,m)=>Ce in C?MM(C,Ce,{enumerable:!0,configurable:!0,writable:!0,value:m}):C[Ce]=m;var V=(C,Ce,m)=>(IM(C,typeof Ce!="symbol"?Ce+"":Ce,m),m);function Ct(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const a=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,a.get?a:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const ce=Ct(bs),Mu=Ct(ut),Bs=Ct(Qt),Qe=Ct(Od),Iu=Ct(ys),Vu=Ct(Gd),gt=Ct(jd),Pu={translation:{filter:{label:"Filter",labels:"Filters",add:"Add a Filter",manage:"Manage Filters",delete:"Delete this filter",show_filters:"Show Filters",hide_filters:"Hide Filters",usage:{label:"Usage",unused_description:"This filter is not used by any query, SQL snippet or view"},field:{widget:"Widget",visible_in:"Visible in...",key_placeholder:"A unique key to refer",label_placeholder:"Label for this field",auto_submit:"Submit automatically",order:"Placement Order",custom_default_value:{trigger:"Custom default value",title:"Custom default value",tips:"Tips",tip_1:"Function has the highest priority of getting filter's default value",tip_2:"Leave this editor empty to disable this feature"}},widget:{names:{select:"Select",multi_select:"Multi Select",tree_select:"Tree Select",tree_single_select:"Tree Single Select",text_input:"Text Input",checkbox:"Checkbox",date_range:"Date Range",merico_date_range:"Merico Date Range"},common:{use_query_data_as_options:"Use query data as options",fetch_options_from_datasource:"Fetch options from datasource",or_fetch_options_from_datasource:"Or fetch options from datasource",selector_option_empty:"Not found",see_data_structure:"Click to see expected data structure",using_query:"Using query",default_selection_count:"Select first N options by default",min_width:"Min width",x_selected:"{{count}} selected",default_value_mode:{label:"When options change",intersect:"Preserve valid entries from current selection",reset:"Use new options"}},text_input:{default_value:"Default Value",required:"Required"},select:{width:"Width",required:"Required",clearable:"Clearable",configure_options:"Configure options",default_selection:"Default Selection",no_default_selection:"none",select_first_option_by_default:"Select the first option by default",preset_options:{apply:"Apply preset options",date_unit:"Date units"}},multi_select:{width_description:"At least 160px"},tree_select:{strictly:"Parent and children nodes are not associated"},tree_single_select:{select_first_option_by_default:"Select the first option by default"},checkbox:{description:"Description",default_checked:"Default checked"},date_range:{required:"Required",allow_single_date:"Allow choosing 1 day",display_format:"Display format",max_days:"Max days",one_day:"1 day",x_days:"{{count}} days",x_max_days:"{{max_days}} days max",default_value:"Default value",default_by_shortcut:"Default by shortcut",default_by_shortcut_placeholder:"Priors default value",start_date:"Start date",end_date:"End date",step:{label:"Step",day:"Day",week:"Week",bi_week:"Bi-Week",month:"Month",quarter:"Quarter",year:"Year"},shortcut:{last:{label:"last",d:"yesterday",w:"week",m:"month",m2:"2 months",m3:"3 months",m6:"6 months",y:"year",full:{d:"yesterday",w:"last week",m:"last month",m2:"last 2 months",m3:"last 3 months",m6:"last 6 months",y:"last year"}},recent:{label:"recent",d7:"7 days",d30:"30 days",d60:"60 days",d90:"90 days",d180:"180 days",d365:"365 days",full:{d7:"recent 7 days",d30:"recent 30 days",d60:"recent 60 days",d90:"recent 90 days",d180:"recent 180 days",d365:"recent 365 days"}},this:{label:"this",d:"today",w:"week",m:"month",y:"year",full:{d:"today",w:"this week",m:"this month",y:"this year"}},this_so_far:{label:"this...so far",w:"week",m:"month",y:"year",full:{w:"this week so far",m:"this month so far",y:"this year so far"}}}}}},view:{label:"View",labels:"Views",add:"Add a View",delete:"Delete this View",download_schema:"Download this View",layout:{drag_to_move:"Drag to move"},component:{div:{label:"Division"},tabs:{label:"Tabs",tabs_settings:"Tabs Settings",tab:{name:"Tab Name",view:"View",order:"Placement Order",color:"Color",delete:"Delete this tab",switch_to_view:"Swith to View: {{name}}"}},modal:{label:"Modal",modal_settings:"Modal settings",title:"Modal Title",custom_title:"Customize modal title",width:"Width",height:"Height"}}},interactions:{label:"Interactions",add:"Add an interaction",interactions_viewer:"Interactions Viewer",unavailable:"Unavailable",unavailable_reason:"This visualization does not have available interactions to choose from",trigger:{setup:"Setup Trigger",label:"Trigger",payload:"Payload"},operation:{setup:"Operation Settings",label:"Operation",settings:"Settings",variables:"Variables",console_log:{label:"console.log | debug",log_content:"log content"},open_link:{label:"Open Link",url:"URL",open_in_new_tab:"Open in new tab"},open_view:{label:"Open View",view:"View"},switch_tab:{label:"Switch Tab",view:"View",tab:"Tab"},scroll_to_panel:{label:"Scroll to Panel",panel:"Panel"},set_filter_values:{label:"Set Filter Values",set_filter:"Set filter",with:"with"},clear_filter_values:{label:"Clear Filter Values",select_filter:"Select filters to clear"}}},query_variable:{label:"Query Variable",labels:"Query Variables",add:"Add a Variable",guide:{tabs:{guide:"Guide",variables_in_this_dashboard:"Variables in this dashboard",global_sql_snippets:"Global SQL Snippets"}},open:"See Query Variables"},sql_snippet:{label:"SQL Snippet",labels:"SQL Snippets",add:"Add a SQL Snippet",delete:"Delete this SQL Snippet",delete_unused:"Delete unused SQL Snippets",manage:"Manage SQL Snippets",key:"Key",key_occupied:"This key is occupied by another snippet",edit_snippet:"Edit SQL Snippet",preview_snippet:"Preview SQL Snippet",usage:{label:"Usage"}},global_sql_snippet:{label:"Global SQL Snippet",labels:"Global SQL Snippets",description:"SQL snippets worth sharing between dashboards are managed in System Settings by admins."},common:{titles:{settings:"Settings",edit:"Edit",config:"Config"},pagination:{label:"Pagination",page_size:"Page Size",total:"Total",total_rows:"Total {{total}} row(s)",to_previous_page:"To previous page",to_next_page:"To next page",showing_rows:"Showing {{start_row}} - {{end_row}} of {{total}} rows"},align:{horizontal:{label:"Horizontal Align",left:"left",center:"center",right:"right"},vertical:{label:"Vertical Align",top:"top",center:"center",bottom:"bottom"}},id:"ID",name:"Name",key:"Key",label:"Label",value:"Value",type:"Type",info:"Info",min:"Min",max:"Max",invalid:"Invalid",data_field:"Data Field",name_data_field:"Name Data Field",value_data_field:"Value Data Field",color_data_field:"Color Data Field",enabled:"Enabled",copied:"Copied to clipboard",action:"Action",actions:{search:"Search",reload:"Reload",actions:"Actions",open:"Open",close:"Close",save:"Save",save_changes:"Save Changes",revert:"Revert",revert_changes:"Revert Changes",reset_to_default:"Reset to default",init_with_default:"Init with default",select_all:"Select All",clear:"Clear",clear_selection:"Clear Selection",refresh:"Refresh",download_data:"Download Data",download_schema:"Download Schema",download_screenshot:"Screenshot",enter_fullscreen:"Full Screen",duplicate:"Duplicate",delete:"Delete",cancel:"Cancel",confirm:"Confirm",add_an_option:"Add an Option",edit:"Edit",end_editing:"End editing <0>{{name}}</0>"},tabs:{variant:{label:"Variant",default:"Default",outline:"Outline",pills:"Pills"},orientation:{label:"Orientation",horizontal:"Horizontal",vertical:"Vertical"},grow_tabs:"Grow Tabs"},choose_a_tab_first:"Please choose a tab first"},breakpoint:{label_one:"Screen size",label_other:"Screen sizes",add:"Add a screen size",manage:"Manage screen sizes",breakpoint:"Min Width"},context:{label:"Context"},mock_context:{label:"Mock Context",hint:"A valid json string is required"},panel:{label:"Panel",labels:"Panels",add:"Add a Panel",delete:"Delete This Panel",panel_name:"Panel Name",panel_description:"Description",panel_description_click:"Click to see description",show_title:"Show title",use_name_as_title:"Use name as title",settings:{change_view:"Move into Another View",change_view_title:"Move panel into another view",choose_queries:"Choose queries",need_to_choose_queries:"Choose at least 1 query for its data"},style:{label:"Style",width:"Width",width_postfix:"of 36 columns",height:"Height",height_postfix:"px",border:"Border"},variable:{label:"Variable",labels:"Variables",add:"Add a Variable",delete:"Delete this Variable",aggregation:{label:"Aggregation",fallback_value:"Fallback Value",fallback_value_description:"Used when data is empty or the aggregation yields NaN"},guide:{text:`-- You may reference dashboard state & panel variables in rich-text content or custom functions.
|
|
2
2
|
-- use double curly brackets to wrap code in rich-text content.
|
|
3
3
|
Project ID: {{ context.project_id }}
|
|
4
4
|
Keyword: {{ filters.keyword }}
|
|
@@ -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_field:{selector:{options:{unset:"未设置",default:"默认"}}}},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 on{constructor(t){V(this,"rootRef");this.rootRef=F.observable({current:t})}async deleteItem(t){F.runInAction(()=>{b.unset(this.rootRef.current,[t])})}getItem(t){const r=this.getValueFromRoot(t);return Promise.resolve(r)}getValueFromRoot(t){return t===null?F.toJS(this.rootRef.current):b.get(this.rootRef.current,[t])}setItem(t,r){if(t===null)if(b.isObject(r))F.runInAction(()=>{this.rootRef.current=r});else throw new Error("Cannot set root value to non-object");else F.runInAction(()=>{b.set(this.rootRef.current,[t],r)});return Promise.resolve(this.getItem(t))}watchItem(t,r,a){return F.reaction(()=>this.getValueFromRoot(t),(o,l)=>{r(o,l)},{requiresObservable:!0,fireImmediately:b.get(a,"fireImmediately",!1)})}}class Au{constructor(){V(this,"channels",new Map);V(this,"globalChannel",new fs)}getChannel(t){const r=this.channels.get(t);if(r)return r;const a=new fs;return this.channels.set(t,a),a}}class Eu{constructor(t){V(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 Au,instanceData:new on(t.viz.conf)};return this.instances.set(t.id,a),a}}function qs(e,t,r,a){return{vizManager:r,locale:"zh",msgChannels:e.messageChannels,instanceData:e.instanceData,pluginData:new on({}),colorPalette:{getColor(){return()=>""}},data:t,variables:a}}const Bu=e=>{const{panel:t,measure:r,vizManager:a,data:o,variables:l}=e,i=a.resolveComponent(t.viz.type),c=a.getOrCreateInstance(t),d={...qs(c,o,a,l),viewport:{width:r.w,height:r.h}},u=i.viewRender;return n.jsx(u,{context:d,instance:c,...b.omit(e,["panel","vizManager","data"])})},qu=e=>{const{vizManager:t,panel:r,data:a,variables:o}=e,l=t.resolveComponent(r.viz.type),i=t.getOrCreateInstance(r),c={...qs(i,a,t,o)},d=l.configRender;return n.jsx(d,{context:c,instance:i,...b.omit(e,["panel","vizManager","data"])})},Ls=(e,t)=>{const r=Ne.bezier(e),a=Ne.bezier(t);return function(o){return o<50?r(o*2/100).hex():a((o-50)*2/100).hex()}},ln=e=>{const t=Ne.bezier(e);return function(r){return t(r/100).hex()}},Lu={type:"interpolation",displayName:"style.color.interpolation.palette.red_green",getColor:Ls(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},Ou={type:"interpolation",displayName:"style.color.interpolation.palette.yellow_blue",getColor:Ls(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},Nu={type:"interpolation",displayName:"style.color.interpolation.palette.red",getColor:ln(["#fff7f1","darkred"]),name:"red",category:"sequential"},Gu={type:"interpolation",displayName:"style.color.interpolation.palette.green",getColor:ln(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},Fu={type:"interpolation",displayName:"style.color.interpolation.palette.blue",getColor:ln(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},Qu={type:"interpolation",displayName:"style.color.interpolation.palette.orange",getColor:ln(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class ju{constructor(t){this.pluginManager=t}createPanelAddonNode(t){const a=this.pluginManager.installedPlugins.flatMap(o=>o.manifest.panelAddon).filter(o=>!!o).map(o=>h.createElement(o.addonRender,{...t,key:o.name}));return n.jsx(n.Fragment,{children:a})}}const Os=h.createContext({addonSlotId:null});function Ns({children:e}){const t=`panel-addon-slot-${h.useId()}`;return n.jsxs(Os.Provider,{value:{addonSlotId:t},children:[n.jsx("div",{style:{position:"static",top:0,left:0},id:t}),e]})}function Wu(){const{addonSlotId:e}=h.useContext(Os);return e?document.getElementById(e):null}class Uu{constructor(t){V(this,"symbol");this.symbol=Symbol(t)}}function He(e){return new Uu(e)}class Un{constructor(){V(this,"parent");V(this,"factoryRegistry",new Map);V(this,"instanceRegistry",new Map)}createScoped(){const t=new Un;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=b.get(t,"dispose");b.isFunction(r)&&r.bind(t)()}),this.instanceRegistry.clear(),this.factoryRegistry.clear()}}const Gs="14.54.0",Ku=Object.freeze(Object.defineProperty({__proto__:null,version:Gs},Symbol.toStringTag,{value:"Module"}));class Yu{constructor(t){V(this,"staticColors",new Map);V(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 Xu{constructor(){V(this,"plugins",new Map);V(this,"vizComponents",new Map);V(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 Zu{constructor(){V(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 o=this.migrations.filter(c=>c.version>t.from&&c.version<=t.to),l=b.orderBy(o,"version","asc");if(((i=b.last(l))==null?void 0:i.version)!==t.to)throw new Error(`Migration to version ${t.to} not found`);return l.reduce((c,d)=>d.handler(c,a),r)}}class J extends Zu{constructor(){super(),this.configVersions()}version(t,r){return super.version(t,(a,o)=>({version:t,...r(a,o)}))}async migrate({configData:t,panelModel:r}){const a=await t.getItem(null),o=b.get(a,"version",0),l=this.run({from:o,to:this.VERSION},a,{panelModel:r});await t.setItem(null,l)}async needMigration({configData:t}){const r=await t.getItem(null);return b.get(r,"version",0)<this.VERSION}}const q=(e,t)=>{const[r,{setFalse:a}]=O.useBoolean(!0),[o,l]=h.useState();h.useEffect(()=>(e.getItem(t).then(c=>{l(c),a()}),e.watchItem(t,c=>{l(c)})));const i=h.useCallback(async c=>{await e.setItem(t,c),l(c)},[e,t]);return{loading:r,value:o,set:i}},Fs=h.createContext(null),Kn=Fs.Provider;function jt(){const e=h.useContext(Fs);if(!e)throw new Error("Please use DashboardModelContextProvider");return e}const j=()=>jt(),Qs=()=>jt(),js=h.createContext({}),Yn=js.Provider;function Ws(){return h.useContext(js)}const Xn=h.createContext(null),Zn=Xn.Provider;function Jn(){const e=h.useContext(Xn);if(!e)throw new Error("Please use ContentModelContextProvider");return e}const G=()=>Jn(),Ju={inEditMode:!1},St=h.createContext(Ju);function Us(){const e=h.useContext(St);if(!e)throw new Error("Please use LayoutStateContext.Provider");return e}const Ks=h.createContext({panel:null,data:{},loading:!1,errors:[],downloadPanelScreenshot:()=>{},getEchartsOptions:()=>null,setEchartsOptions:()=>{}}),Hn=Ks.Provider;function Rn(){const e=h.useContext(Ks);if(!e.panel)throw new Error("Please use PanelContextProvider");return e}const re=()=>Rn(),ae=()=>Rn();function Ys(){try{return Rn(),!0}catch{return!1}}const Xs=()=>Ys(),Zs=()=>Ys(),Hu={fullScreenPanelID:"",setFullScreenPanelID:b.noop},er=h.createContext(Hu);function Js(){const e=h.useContext(er);if(!e)throw new Error("Please use FullScreenPanelContext.Provider");return e}const Ru={en:"en",zh:"zh-cn"};function tr({children:e}){const{i18n:t}=m.useTranslation(),r=h.useMemo(()=>{const a=t.language;return Ru[a]??"en"},[t.language]);return n.jsx(wt.DatesProvider,{settings:{locale:r,firstDayOfWeek:1},children:e})}const H=()=>Jn(),ep={items:[]},nr=h.createContext(ep),rr=nr.Provider;function ar(){return h.useContext(nr)}h.forwardRef(function({value:t,onChange:r,...a},o){return n.jsx(s.TextInput,{ref:o,value:t,onChange:r,...a})});class tp{constructor({valueRange:t,colorRange:r}){V(this,"mapper");this.mapper=ut.interpolate(t,r)}getColor(t){return this.mapper(t)}}function np(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 tp(e).getColor(r)}catch(r){return console.error(r),"black"}return"black"}const rp=np;function $(e){const[t,r]=e.split(".");return{queryID:t,columnKey:r}}function Hs(e){return!!e&&!!e.columnKey&&!!e.queryID}function ap(e){return e.includes(".")?$(e):{queryID:"",columnKey:e}}function me(e,t){var o;const{queryID:r,columnKey:a}=$(t);return r?a?((o=e[r])==null?void 0:o.map(l=>l[a]))??[]:e[r]:[]}function cn(e,t){const{queryID:r}=$(t);return r?e[r]:[]}function sp(e){return Object.values(e)[0]}function dn(e,t){const{queryID:r,columnKey:a}=$(t);return e[a]}const je={CryptoJS:ys,d3Array:Bs,dayjs:M,lodash:b,numbro:Ee,mathjs:Qe,faker:Nd.faker,popmotion:Mu},op=[{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"}],lp=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_field:{selector:{options:{unset:"未设置",default:"默认"}}}},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 on{constructor(t){V(this,"rootRef");this.rootRef=G.observable({current:t})}async deleteItem(t){G.runInAction(()=>{b.unset(this.rootRef.current,[t])})}getItem(t){const r=this.getValueFromRoot(t);return Promise.resolve(r)}getValueFromRoot(t){return t===null?G.toJS(this.rootRef.current):b.get(this.rootRef.current,[t])}setItem(t,r){if(t===null)if(b.isObject(r))G.runInAction(()=>{this.rootRef.current=r});else throw new Error("Cannot set root value to non-object");else G.runInAction(()=>{b.set(this.rootRef.current,[t],r)});return Promise.resolve(this.getItem(t))}watchItem(t,r,a){return G.reaction(()=>this.getValueFromRoot(t),(o,l)=>{r(o,l)},{requiresObservable:!0,fireImmediately:b.get(a,"fireImmediately",!1)})}}class Au{constructor(){V(this,"channels",new Map);V(this,"globalChannel",new fs)}getChannel(t){const r=this.channels.get(t);if(r)return r;const a=new fs;return this.channels.set(t,a),a}}class Eu{constructor(t){V(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 Au,instanceData:new on(t.viz.conf)};return this.instances.set(t.id,a),a}}function qs(e,t,r,a){return{vizManager:r,locale:"zh",msgChannels:e.messageChannels,instanceData:e.instanceData,pluginData:new on({}),colorPalette:{getColor(){return()=>""}},data:t,variables:a}}const Bu=e=>{const{panel:t,measure:r,vizManager:a,data:o,variables:l}=e,i=a.resolveComponent(t.viz.type),c=a.getOrCreateInstance(t),d={...qs(c,o,a,l),viewport:{width:r.w,height:r.h}},u=i.viewRender;return n.jsx(u,{context:d,instance:c,...b.omit(e,["panel","vizManager","data"])})},qu=e=>{const{vizManager:t,panel:r,data:a,variables:o}=e,l=t.resolveComponent(r.viz.type),i=t.getOrCreateInstance(r),c={...qs(i,a,t,o)},d=l.configRender;return n.jsx(d,{context:c,instance:i,...b.omit(e,["panel","vizManager","data"])})},Ls=(e,t)=>{const r=Ne.bezier(e),a=Ne.bezier(t);return function(o){return o<50?r(o*2/100).hex():a((o-50)*2/100).hex()}},ln=e=>{const t=Ne.bezier(e);return function(r){return t(r/100).hex()}},Lu={type:"interpolation",displayName:"style.color.interpolation.palette.red_green",getColor:Ls(["darkred","deeppink","lightyellow"],["lightyellow","lightgreen","teal"]),name:"red-green",category:"diverging"},Ou={type:"interpolation",displayName:"style.color.interpolation.palette.yellow_blue",getColor:Ls(["#8f531d","#ffd347","#e3efe3"],["#eefaee","#4ecbbf","#003f94"]),name:"yellow-blue",category:"diverging"},Nu={type:"interpolation",displayName:"style.color.interpolation.palette.red",getColor:ln(["#fff7f1","darkred"]),name:"red",category:"sequential"},Gu={type:"interpolation",displayName:"style.color.interpolation.palette.green",getColor:ln(["#f0ffed","darkgreen"]),name:"green",category:"sequential"},Fu={type:"interpolation",displayName:"style.color.interpolation.palette.blue",getColor:ln(["#f9fcff","#48b3e9","darkblue"]),name:"blue",category:"sequential"},Qu={type:"interpolation",displayName:"style.color.interpolation.palette.orange",getColor:ln(["#fff7f1","darkorange","#b60000"]),name:"orange",category:"sequential"};class ju{constructor(t){this.pluginManager=t}createPanelAddonNode(t){const a=this.pluginManager.installedPlugins.flatMap(o=>o.manifest.panelAddon).filter(o=>!!o).map(o=>h.createElement(o.addonRender,{...t,key:o.name}));return n.jsx(n.Fragment,{children:a})}}const Os=h.createContext({addonSlotId:null});function Ns({children:e}){const t=`panel-addon-slot-${h.useId()}`;return n.jsxs(Os.Provider,{value:{addonSlotId:t},children:[n.jsx("div",{style:{position:"static",top:0,left:0},id:t}),e]})}function Wu(){const{addonSlotId:e}=h.useContext(Os);return e?document.getElementById(e):null}class Uu{constructor(t){V(this,"symbol");this.symbol=Symbol(t)}}function He(e){return new Uu(e)}class Un{constructor(){V(this,"parent");V(this,"factoryRegistry",new Map);V(this,"instanceRegistry",new Map)}createScoped(){const t=new Un;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=b.get(t,"dispose");b.isFunction(r)&&r.bind(t)()}),this.instanceRegistry.clear(),this.factoryRegistry.clear()}}const Gs="14.54.1",Ku=Object.freeze(Object.defineProperty({__proto__:null,version:Gs},Symbol.toStringTag,{value:"Module"}));class Yu{constructor(t){V(this,"staticColors",new Map);V(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 Xu{constructor(){V(this,"plugins",new Map);V(this,"vizComponents",new Map);V(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 Zu{constructor(){V(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 o=this.migrations.filter(c=>c.version>t.from&&c.version<=t.to),l=b.orderBy(o,"version","asc");if(((i=b.last(l))==null?void 0:i.version)!==t.to)throw new Error(`Migration to version ${t.to} not found`);return l.reduce((c,d)=>d.handler(c,a),r)}}class J extends Zu{constructor(){super(),this.configVersions()}version(t,r){return super.version(t,(a,o)=>({version:t,...r(a,o)}))}async migrate({configData:t,panelModel:r}){const a=await t.getItem(null),o=b.get(a,"version",0),l=this.run({from:o,to:this.VERSION},a,{panelModel:r});await t.setItem(null,l)}async needMigration({configData:t}){const r=await t.getItem(null);return b.get(r,"version",0)<this.VERSION}}const q=(e,t)=>{const[r,{setFalse:a}]=O.useBoolean(!0),[o,l]=h.useState();h.useEffect(()=>(e.getItem(t).then(c=>{l(c),a()}),e.watchItem(t,c=>{l(c)})));const i=h.useCallback(async c=>{await e.setItem(t,c),l(c)},[e,t]);return{loading:r,value:o,set:i}},Fs=h.createContext(null),Kn=Fs.Provider;function jt(){const e=h.useContext(Fs);if(!e)throw new Error("Please use DashboardModelContextProvider");return e}const j=()=>jt(),Qs=()=>jt(),js=h.createContext({}),Yn=js.Provider;function Ws(){return h.useContext(js)}const Xn=h.createContext(null),Zn=Xn.Provider;function Jn(){const e=h.useContext(Xn);if(!e)throw new Error("Please use ContentModelContextProvider");return e}const F=()=>Jn(),Ju={inEditMode:!1},St=h.createContext(Ju);function Us(){const e=h.useContext(St);if(!e)throw new Error("Please use LayoutStateContext.Provider");return e}const Ks=h.createContext({panel:null,data:{},loading:!1,errors:[],downloadPanelScreenshot:()=>{},getEchartsOptions:()=>null,setEchartsOptions:()=>{}}),Hn=Ks.Provider;function Rn(){const e=h.useContext(Ks);if(!e.panel)throw new Error("Please use PanelContextProvider");return e}const re=()=>Rn(),ae=()=>Rn();function Ys(){try{return Rn(),!0}catch{return!1}}const Xs=()=>Ys(),Zs=()=>Ys(),Hu={fullScreenPanelID:"",setFullScreenPanelID:b.noop},er=h.createContext(Hu);function Js(){const e=h.useContext(er);if(!e)throw new Error("Please use FullScreenPanelContext.Provider");return e}const Ru={en:"en",zh:"zh-cn"};function tr({children:e}){const{i18n:t}=m.useTranslation(),r=h.useMemo(()=>{const a=t.language;return Ru[a]??"en"},[t.language]);return n.jsx(wt.DatesProvider,{settings:{locale:r,firstDayOfWeek:1},children:e})}const H=()=>Jn(),ep={items:[]},nr=h.createContext(ep),rr=nr.Provider;function ar(){return h.useContext(nr)}h.forwardRef(function({value:t,onChange:r,...a},o){return n.jsx(s.TextInput,{ref:o,value:t,onChange:r,...a})});class tp{constructor({valueRange:t,colorRange:r}){V(this,"mapper");this.mapper=ut.interpolate(t,r)}getColor(t){return this.mapper(t)}}function np(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 tp(e).getColor(r)}catch(r){return console.error(r),"black"}return"black"}const rp=np;function $(e){const[t,r]=e.split(".");return{queryID:t,columnKey:r}}function Hs(e){return!!e&&!!e.columnKey&&!!e.queryID}function ap(e){return e.includes(".")?$(e):{queryID:"",columnKey:e}}function me(e,t){var o;const{queryID:r,columnKey:a}=$(t);return r?a?((o=e[r])==null?void 0:o.map(l=>l[a]))??[]:e[r]:[]}function cn(e,t){const{queryID:r}=$(t);return r?e[r]:[]}function sp(e){return Object.values(e)[0]}function dn(e,t){const{queryID:r,columnKey:a}=$(t);return e[a]}const je={CryptoJS:ys,d3Array:Bs,dayjs:M,lodash:b,numbro:Ee,mathjs:Qe,faker:Nd.faker,popmotion:Mu},op=[{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"}],lp=e=>`
|
|
10
10
|
<tr>
|
|
11
11
|
<td><code>${e.name}</code></td>
|
|
12
12
|
<td>
|
|
@@ -53,7 +53,7 @@ Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel vari
|
|
|
53
53
|
} catch (error) {
|
|
54
54
|
console.error(error);
|
|
55
55
|
return "black";
|
|
56
|
-
}`;return`<span style="${d}"><dynamic-color id="${p}" data-value='${f}'>{{${o}}}</dynamic-color></span>`})}function ah(e,t){const{data_field:r,aggregation:a}=e,o=or(t,r,a);return Be(e,o)}function ko(e,t){const r={};return e.forEach(a=>{r[a.name]=ah(a,t)}),r}function Ut(e,t,r){const a=ko(t,r),o=/^\{(.+)\}(.*)$/;return e.split("$").map(l=>{const i=o.exec(l);if(!i)return l;const c=a[i[1]];if(!c)return l;const d=i[2]??"";return`${c}${d}`}).join("")}function*sh(e){const t=We.graphics[e];if(!t)throw new Error("Invalid palette key provided");const r=Object.values(t);let a=0;for(;;)yield r[a%r.length],a++}function fr(){return{filters:{},context:{}}}function br(e){const t=fr();if(!e)return fr();const{filters:r=t.filters,context:a=t.context}=e;return{filters:r,context:a}}class ne extends h.Component{constructor(t){super(t),this.state={error:null}}componentDidCatch(t){this.setState({error:t})}render(){var t;if(this.state.error){const r=()=>{this.setState({error:null})};return n.jsxs(s.Box,{children:[n.jsx(s.Text,{size:"xs",children:(t=this.state.error)==null?void 0:t.message}),n.jsx(s.Button,{variant:"subtle",mx:"auto",size:"compact-xs",sx:{display:"block"},onClick:r,children:"Retry"})]})}return this.props.children}}function Do(e,t={handleError:!0}){return r=>n.jsx(ne,{...t,children:n.jsx(e,{...r})})}function oh(e,t){return new Function(`return ${e}`)()(t,je)}function lh(e,t,r){return oh(e,{context:t,filters:r})}function hn(e,t){try{return new Function(`return ${e.config.processing.pre}`)()(t,je)}catch(r){return console.error(r),t}}function gn(e,t){return new Function(`return ${e.config.processing.post}`)()(t,je)}function zo(e,t,r){return e?new Function(`return ${e}`)()(t,je,r):t}function Mo(){bs.use([Fd.CanvasRenderer,Je.BarChart,Je.BoxplotChart,Je.CustomChart,Je.FunnelChart,Je.HeatmapChart,Je.LineChart,Je.PieChart,Je.RadarChart,Je.ScatterChart,Je.SunburstChart,pt.CalendarComponent,pt.DataZoomComponent,pt.GridComponent,pt.LegendComponent,pt.TooltipComponent,pt.MarkLineComponent,pt.MarkAreaComponent,pt.VisualMapComponent])}const st=e=>b.cloneDeepWith(e,(t,r)=>{if(r!==void 0&&t)return
|
|
56
|
+
}`;return`<span style="${d}"><dynamic-color id="${p}" data-value='${f}'>{{${o}}}</dynamic-color></span>`})}function ah(e,t){const{data_field:r,aggregation:a}=e,o=or(t,r,a);return Be(e,o)}function ko(e,t){const r={};return e.forEach(a=>{r[a.name]=ah(a,t)}),r}function Ut(e,t,r){const a=ko(t,r),o=/^\{(.+)\}(.*)$/;return e.split("$").map(l=>{const i=o.exec(l);if(!i)return l;const c=a[i[1]];if(!c)return l;const d=i[2]??"";return`${c}${d}`}).join("")}function*sh(e){const t=We.graphics[e];if(!t)throw new Error("Invalid palette key provided");const r=Object.values(t);let a=0;for(;;)yield r[a%r.length],a++}function fr(){return{filters:{},context:{}}}function br(e){const t=fr();if(!e)return fr();const{filters:r=t.filters,context:a=t.context}=e;return{filters:r,context:a}}class ne extends h.Component{constructor(t){super(t),this.state={error:null}}componentDidCatch(t){this.setState({error:t})}render(){var t;if(this.state.error){const r=()=>{this.setState({error:null})};return n.jsxs(s.Box,{children:[n.jsx(s.Text,{size:"xs",children:(t=this.state.error)==null?void 0:t.message}),n.jsx(s.Button,{variant:"subtle",mx:"auto",size:"compact-xs",sx:{display:"block"},onClick:r,children:"Retry"})]})}return this.props.children}}function Do(e,t={handleError:!0}){return r=>n.jsx(ne,{...t,children:n.jsx(e,{...r})})}function oh(e,t){return new Function(`return ${e}`)()(t,je)}function lh(e,t,r){return oh(e,{context:t,filters:r})}function hn(e,t){try{return new Function(`return ${e.config.processing.pre}`)()(t,je)}catch(r){return console.error(r),t}}function gn(e,t){return new Function(`return ${e.config.processing.post}`)()(t,je)}function zo(e,t,r){return e?new Function(`return ${e}`)()(t,je,r):t}function Mo(){bs.use([Fd.CanvasRenderer,Je.BarChart,Je.BoxplotChart,Je.CustomChart,Je.FunnelChart,Je.HeatmapChart,Je.LineChart,Je.PieChart,Je.RadarChart,Je.ScatterChart,Je.SunburstChart,pt.CalendarComponent,pt.DataZoomComponent,pt.GridComponent,pt.LegendComponent,pt.TooltipComponent,pt.MarkLineComponent,pt.MarkAreaComponent,pt.VisualMapComponent])}const st=e=>b.cloneDeepWith(e,(t,r)=>{if(r!==void 0&&t)return G.toJS(t)});function yr(e,t){const r=Object.keys(t),a=Object.values(t);try{return new Function(...r,`return \`${e}\`;`)(...a)}catch(o){throw r.length===0&&e.includes("$")?new Error("[formatSQL] insufficient payload"):o}}function vr(e,t){try{return yr(e,t)}catch(r){return console.error(r),r.message}}function ih({sql:e,pre_process:t}){if(!t.trim())return e;try{return new Function(`return ${t}`)()({sql:e},je)}catch(r){throw console.error(r),r}}function ch(e,t,r){if(!e.trim())return t;try{return new Function(`return ${e}`)()(t,je,r)}catch(a){throw console.error(a),a}}const Et={sqlSnippet:new RegExp("(?<=sql_snippets\\.)([^\\?}.]+)","gm"),context:new RegExp("(?<=context\\.)([^\\?}.]+)","gm"),filter:new RegExp("(?<=filters\\.)([^\\?}.]+)","gm")};function dh(e,t){const r={};return e.forEach(a=>{const{name:o,data_field:l,aggregation:i}=a,c=or(t,l,i);r[o]=Be(a,c)}),r}function uh(e){const t=document.createElement("span");return t.innerHTML=e,t.innerText}function ph(e,t,r){try{return new Function("payload",`
|
|
57
57
|
const filters = payload.filters;
|
|
58
58
|
const context = payload.context;
|
|
59
59
|
${Object.entries(t).map(([a,o])=>`const ${a} = '${o}';`).join(`
|
|
@@ -66,7 +66,7 @@ Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel vari
|
|
|
66
66
|
white-space: ${a};
|
|
67
67
|
overflow: hidden;
|
|
68
68
|
text-overflow: ${o};
|
|
69
|
-
`}function Ke(e){return{width:e.width,overflow:e.overflow,ellipsis:e.ellipsis}}const ue=h.forwardRef(({value:e,onChange:t,hiddenFileds:r},a)=>{const{t:o}=m.useTranslation(),l=h.useMemo(()=>new Set(r??[]),[r]),i=c=>d=>{t({...e,[c]:d})};return n.jsxs(s.Stack,{ref:a,gap:"sm",children:[n.jsx(s.Divider,{mb:-10,label:o("chart.unit.title"),labelPosition:"center",variant:"dashed"}),!l.has("text")&&n.jsx(s.TextInput,{size:"xs",placeholder:o("chart.unit.text.placeholder"),value:e.text,onChange:c=>i("text")(c.currentTarget.value)}),n.jsxs(s.Group,{grow:!0,children:[!l.has("show_in_tooltip")&&n.jsx(s.Checkbox,{size:"xs",label:o("chart.unit.show_in_tooltip"),checked:e.show_in_tooltip,onChange:c=>i("show_in_tooltip")(c.currentTarget.checked)}),!l.has("show_in_legend")&&n.jsx(s.Checkbox,{size:"xs",label:o("chart.unit.show_in_legend"),checked:e.show_in_legend,onChange:c=>i("show_in_legend")(c.currentTarget.checked)})]})]})});function K(){return{text:"",show_in_tooltip:!1,show_in_legend:!1}}const mr={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:_e(),overflow:Ie()}},y_axis:{name:"Y Axis",data_key:"value",label_formatter:de,unit:K()},tooltip:{metrics:[]},color:"rgba(99, 152, 199, 0.10)",reference_lines:[],legend:{show:!0,top:"10",right:"0",left:"auto",bottom:"auto",orient:"vertical",type:"scroll"},dataZoom:Vo()};function Dt(e,t){return h.useMemo(()=>{const{queryID:r,columnKey:a}=$(t);return b.keyBy(e[r],a)},[e,t])}const Ve=(e,t)=>{const[r,a]=h.useState([]);return h.useEffect(()=>e.watchTriggerSnapshotList(o=>a(o.filter(l=>l.schemaRef===t))),[]),r},wr=h.createContext(null);function bn(e){const t=h.useContext(wr),r=O.useCreation(()=>e.configure(t||new Un),[e.configure]),a=O.usePrevious(r);return a&&a!==r&&a.dispose(),n.jsx(wr.Provider,{value:r,children:e.children})}function Yt(){return h.useContext(wr)}const Pe=({})=>Yt().getRequired(ee.instanceScope.interactionManager),$o=e=>{const{t}=m.useTranslation(),{title:r="Variables",variables:a}=e,o=te.useClipboard(),l=i=>{o.copy(i),Ge.showNotification({color:"green",message:t("common.copied")})};return n.jsxs(s.Paper,{withBorder:!0,p:"sm",children:[n.jsx(s.Text,{size:"xs",c:"dimmed",mb:"sm",children:r}),n.jsx(s.Stack,{style:{maxHeight:"500px"},children:a.map(i=>n.jsxs(s.Text,{size:"sm",children:[n.jsxs(s.Code,{color:"teal",children:["// ",i.description]}),n.jsx("br",{}),n.jsxs(s.Code,{onClick:()=>l(i.name),style:{cursor:"pointer"},children:[i.name," : ",i.valueType]})]},i.name))})]})};class Sh{constructor(t,r){V(this,"operationId");V(this,"operation");V(this,"operationSchema");V(this,"variables",[]);this.operationManager=t,this.instance=r,F.makeAutoObservable(this)}get schemaList(){return this.operationManager.getOperationSchemaList()}async configOperation(t,r){const a=await this.operationManager.retrieveTrigger(t),o=this.operationManager.getOperationSchemaList().find(l=>l.id===(a==null?void 0:a.schemaRef));F.runInAction(()=>{this.operationId=t,this.operation=a,this.operationSchema=o,this.variables=r})}async changeSchema(t){this.operationId&&(await this.operationManager.createOrGetOperation(this.operationId,t),await this.configOperation(this.operationId,this.variables))}}function Th(e){return!!e.operationId}const kh=k.observer(({model:e,onClick:t})=>{var o;const{t:r}=m.useTranslation(),a=(o=e.operationSchema)==null?void 0:o.displayName;return n.jsx(s.Button,{variant:"outline",onClick:t,children:r(a)})}),Ao=k.observer(({model:e})=>{const t={operation:e.operation,instance:e.instance,variables:[]};return h.createElement(e.operationSchema.configRender,t)}),Dh=k.observer(({model:e})=>{const{t,i18n:r}=m.useTranslation(),a=e.schemaList,o=h.useMemo(()=>a.map(i=>({label:t(i.displayName),value:i.id})),[a,r.language]);async function l(i){await e.changeSchema(a.find(c=>c.id===i))}return n.jsx(s.Select,{label:t("interactions.operation.label"),data:o,onChange:Z(l),value:e.operationSchema.id,comboboxProps:{withinPortal:!0,zIndex:340},maxDropdownHeight:500})}),zh=k.observer(e=>{const{t}=m.useTranslation(),[r,{setTrue:a,setFalse:o}]=O.useBoolean(!1),{operationManager:l,operationId:i,instance:c,variables:d}=e,u=O.useCreation(()=>new Sh(l,c),[l,c]);return O.useAsyncEffect(async()=>{await u.configOperation(i,d)},[i,u]),Th(u)?n.jsxs(n.Fragment,{children:[n.jsx(kh,{model:u,onClick:a}),n.jsx(s.Modal,{size:600,opened:r,onClose:o,title:t("interactions.operation.setup"),zIndex:320,children:n.jsxs(s.Stack,{children:[n.jsx(Dh,{model:u}),u.variables.length>0?n.jsxs(s.Tabs,{defaultValue:"settings",children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"settings",children:t("interactions.operation.settings")}),n.jsx(s.Tabs.Tab,{value:"variables",children:t("interactions.operation.variables")})]}),n.jsx(s.Tabs.Panel,{value:"settings",pt:10,children:n.jsx(Ao,{model:u})}),n.jsx(s.Tabs.Panel,{value:"variables",pt:10,children:n.jsx($o,{title:t("interactions.operation.variables"),variables:u.variables})})]}):n.jsx(Ao,{model:u})]})})]}):null});class Mh{constructor(t,r){V(this,"triggerId");V(this,"trigger");V(this,"triggerSchema");V(this,"sampleData");this.triggerManager=t,this.instance=r,F.makeAutoObservable(this)}get schemaList(){return this.triggerManager.getTriggerSchemaList()}async configTrigger(t,r){const a=await this.triggerManager.retrieveTrigger(t),o=this.triggerManager.getTriggerSchemaList().find(l=>l.id===(a==null?void 0:a.schemaRef));F.runInAction(()=>{this.triggerId=t,this.trigger=a,this.triggerSchema=o,this.sampleData=r})}async changeSchema(t){this.triggerId&&(await this.triggerManager.createOrGetTrigger(this.triggerId,t),await this.configTrigger(this.triggerId,this.sampleData))}isReady(){return Ih(this)}}function Ih(e){return!!e.triggerId&&!!e.triggerSchema}function Vh(e,t){return O.useCreation(()=>new Mh(e,t),[e,t])}const Ph=k.observer(({model:e,onClick:t})=>{const r=e.triggerSchema.nameRender,a={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return n.jsx(s.Button,{variant:"outline",onClick:t,children:h.createElement(r,a)})}),$h=k.observer(({model:e})=>{const{t,i18n:r}=m.useTranslation(),a=e.schemaList,o=h.useMemo(()=>a.map(i=>({label:t(i.displayName),value:i.id})),[a,r.language]);async function l(i){await e.changeSchema(a.find(c=>c.id===i))}return n.jsx(s.Select,{label:t("interactions.trigger.label"),data:o,value:e.triggerSchema.id,onChange:Z(l)})}),Ah=k.observer(({model:e})=>{const t={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return h.createElement(e.triggerSchema.configRender,t)}),Eh=k.observer(e=>{const{t}=m.useTranslation(),[r,{setTrue:a,setFalse:o}]=O.useBoolean(!1),l=e.model;return n.jsxs(n.Fragment,{children:[n.jsx(s.Modal,{opened:r,onClose:o,title:t("interactions.trigger.setup"),zIndex:320,children:n.jsxs(s.Stack,{children:[n.jsx($h,{model:l}),n.jsx(Ah,{model:l}),n.jsx($o,{title:t("interactions.trigger.payload"),variables:l.triggerSchema.payload})]})}),n.jsx(Ph,{onClick:a,model:l})]})});class Bt{constructor(t,r){this.root=t,this.path=r}async deleteItem(t){t===null&&await this.root.deleteItem(this.path);const r=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,b.omit(r,t))}async getItem(t){const r=await this.root.getItem(this.path);return t===null?r:b.get(r,t)}async setItem(t,r){if(t===null)await this.root.setItem(this.path,r);else{const a=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,{...a,[t]:r})}return await this.getItem(t)}watchItem(t,r,a){return t===null?this.root.watchItem(this.path,(o,l)=>{r(o,l)},a):this.root.watchItem(this.path,(o,l)=>{const i=b.get(o,t),c=b.get(l,t);i!==c&&r(i,c)},a)}}const Bh={"builtin:op:debug":1,"builtin:op:clear_filter_values":2,"builtin:op:set_filter_values":3,"builtin:op:open_view":4,"builtin:op:open-link":5};class xr{constructor(t,r,a){V(this,"attachmentStorage");this.instance=t,this.attachmentKey=r,this.constructInstance=a,this.attachmentStorage=new Bt(t.instanceData,r)}async getInstance(t){if(await this.attachmentStorage.getItem(t))return this.constructInstance(new Bt(this.attachmentStorage,t))}async create(t,r){return await this.attachmentStorage.setItem(t,r),this.constructInstance(new Bt(this.attachmentStorage,t))}async remove(t){await this.attachmentStorage.deleteItem(t)}async list(){const t=await this.attachmentStorage.getItem(null),r=b.orderBy(b.values(t),a=>Bh[a.schemaRef]??10);return Promise.all(r.map(a=>this.constructInstance(new Bt(this.attachmentStorage,a.id))))}}function qh(e,t){const{value:r,set:a}=q(e.operation.operationData,"config"),[o,l]=h.useState(b.defaults({},r,t)),i=async()=>{await a(o)};return h.useEffect(()=>{l(b.defaults({},r,t))},[r]),{config:o,setConfig:l,commit:i}}function Lh(e){const{t}=m.useTranslation(),{config:r,setConfig:a,commit:o}=qh(e,{urlTemplate:"",openInNewTab:!0});async function l(){await o()}async function i(d){a({...r,openInNewTab:d}),await o()}const c=d=>a({...r,urlTemplate:d.currentTarget.value});return n.jsxs(s.Stack,{children:[n.jsx(s.TextInput,{label:t("interactions.operation.open_link.url"),value:r.urlTemplate,onChange:c,onBlur:l}),n.jsx(s.Switch,{label:t("interactions.operation.open_link.open_in_new_tab"),checked:r.openInNewTab,onChange:d=>i(d.currentTarget.checked)})]})}async function Oh(e,t){const{urlTemplate:r,openInNewTab:a}=await t.operationData.getItem("config");window.dispatchEvent(new CustomEvent("open-link",{detail:{urlTemplate:r,openInNewTab:a,payload:e}}))}class Nh extends J{constructor(){super(...arguments);V(this,"VERSION",1)}configVersions(){this.version(1,r=>r)}}const Gh={displayName:"interactions.operation.open_link.label",id:"builtin:op:open-link",configRender:Lh,run:Oh,migrator:new Nh,createDefaultConfig:()=>({version:1,config:{urlTemplate:"",openInNewTab:!0}})};function Fh(e){const{value:t,set:r}=q(e.operationData,"config"),a=o=>void r({template:o});return[(t==null?void 0:t.template)||"",a]}function Qh(e){const{t}=m.useTranslation(),[r,a]=Fh(e.operation);return n.jsx(s.TextInput,{defaultValue:r,onBlur:o=>a(o.currentTarget.value),label:t("interactions.operation.console_log.log_content")})}async function jh(e,t){const r=await t.operationData.getItem("config"),a=b.template(r.template||"");console.log("run with payload",e),console.log(a(e))}const Wh={displayName:"interactions.operation.console_log.label",id:"builtin:op:debug",configRender:Qh,run:jh},Uh=k.observer(e=>{const{t}=m.useTranslation(),r=G(),{value:a,set:o}=q(e.operation.operationData,"config"),l=(a==null?void 0:a.viewID)||"",i=c=>void o({viewID:c});return n.jsx(s.Select,{defaultValue:l,value:l,onChange:Z(i),label:t("interactions.operation.open_view.view"),data:r.views.options,comboboxProps:{withinPortal:!0,zIndex:340},maxDropdownHeight:500})});async function Kh(e,t){const a=(await t.operationData.getItem("config")).viewID;window.dispatchEvent(new CustomEvent("open-view",{detail:{viewID:a}}))}const Yh={displayName:"interactions.operation.open_view.label",id:"builtin:op:open_view",configRender:Uh,run:Kh},Xh={"tbody tr":{opacity:.5,transition:"opacity 200ms ease"},"tr[data-affected=true]":{opacity:1}},Zh=({value:e="",onChange:t})=>{const[r,a]=h.useState(e);h.useEffect(()=>{a(e)},[e]);const o=()=>{t(r)};return n.jsx(s.TextInput,{size:"xs",label:"",value:r,onChange:l=>a(l.currentTarget.value),sx:{flexGrow:1},rightSection:n.jsx(s.ActionIcon,{color:"green",size:"xs",onClick:o,disabled:r===e,children:n.jsx(S.IconDeviceFloppy,{})})})},Jh={dictionary:{}},Hh=k.observer(e=>{const{t}=m.useTranslation(),r=G(),{value:a=Jh,set:o}=q(e.operation.operationData,"config"),{dictionary:l={}}=a;console.log({value:{...a},dictionary:{...l},filters:[...r.filters.keyLabelOptions]});const i=(c,d)=>{if(d===""){const u={...l};delete u[c],o({dictionary:u});return}o({dictionary:{...l,[c]:d}})};return n.jsxs(s.Table,{sx:Xh,children:[n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:t("interactions.operation.set_filter_values.set_filter")}),n.jsx(s.Table.Th,{children:t("interactions.operation.set_filter_values.with")})]})}),n.jsx(s.Table.Tbody,{children:[...r.filters.keyLabelOptions].map(c=>{const d=c.value in l;return n.jsxs(s.Table.Tr,{"data-affected":d,children:[n.jsx(s.Table.Td,{children:c.label}),n.jsx(s.Table.Td,{children:n.jsx(Zh,{value:l[c.value],onChange:u=>i(c.value,u)})})]},c.value)})})]})});async function Rh(e,t){const a=(await t.operationData.getItem("config")).dictionary;window.dispatchEvent(new CustomEvent("set-filter-values",{detail:{dictionary:a,payload:e}}))}const eg={displayName:"interactions.operation.set_filter_values.label",id:"builtin:op:set_filter_values",configRender:Hh,run:Rh},tg={filter_keys:[]},ng=k.observer(e=>{const{t}=m.useTranslation(),r=G(),{value:a=tg,set:o}=q(e.operation.operationData,"config"),{filter_keys:l=[]}=a,i=d=>{o({filter_keys:[...d]})},c=h.useMemo(()=>r.filters.current.map(d=>({label:d.label,value:d.key})),[r.filters.values]);return n.jsx(s.Stack,{gap:10,children:n.jsx(s.MultiSelect,{label:t("interactions.operation.clear_filter_values.select_filter"),data:c,value:l,onChange:i})})});async function rg(e,t){const a=(await t.operationData.getItem("config")).filter_keys;window.dispatchEvent(new CustomEvent("clear-filter-values",{detail:{filter_keys:a,payload:e}}))}const ag={displayName:"interactions.operation.clear_filter_values.label",id:"builtin:op:clear_filter_values",configRender:ng,run:rg},sg=({option:e,checked:t})=>{var o;const{t:r}=m.useTranslation(),a=e;return n.jsxs(s.Group,{justify:"space-between",flex:"1",gap:"xs",children:[n.jsx(s.Text,{size:"xs",children:a.label}),n.jsx(s.Text,{size:"xs",children:r((o=Jl[a.viz_type])==null?void 0:o.displayName)??a.viz_type})]})},og=k.observer(e=>{const{t}=m.useTranslation(),r=G(),{value:a,set:o}=q(e.operation.operationData,"config"),l=(a==null?void 0:a.panelID)||"",i=c=>void o({panelID:c});return n.jsx(s.Select,{defaultValue:l,value:l,onChange:Z(i),label:t("interactions.operation.scroll_to_panel.panel"),data:r.panels.options,comboboxProps:{withinPortal:!0,zIndex:340},maxDropdownHeight:500,renderOption:sg})});async function lg(e,t){const a=(await t.operationData.getItem("config")).panelID;window.dispatchEvent(new CustomEvent("scroll_to_panel",{detail:{panelID:a}}))}const ig={displayName:"interactions.operation.scroll_to_panel.label",id:"builtin:op:scroll_to_panel",configRender:og,run:lg},cg=k.observer(e=>{const{t}=m.useTranslation(),r=G(),{value:a,set:o}=q(e.operation.operationData,"config"),{viewID:l="",tab:i=""}=a??{},c=u=>void o({viewID:u,tab:i}),d=u=>void o({viewID:l,tab:u});return n.jsxs(s.Stack,{gap:"xs",children:[n.jsx(s.Select,{defaultValue:l,value:l,onChange:Z(c),label:t("interactions.operation.switch_tab.view"),data:r.views.tabViewOptions,comboboxProps:{withinPortal:!0,zIndex:340},maxDropdownHeight:500}),n.jsx(s.Select,{defaultValue:i,value:i,onChange:Z(d),label:t("interactions.operation.switch_tab.tab"),data:r.views.tabOptions(l),comboboxProps:{withinPortal:!0,zIndex:340},maxDropdownHeight:500})]})});async function dg(e,t){const r=await t.operationData.getItem("config"),{viewID:a,tab:o}=r;window.dispatchEvent(new CustomEvent("switch_tab",{detail:{viewID:a,tab:o}}))}const Cr=[Wh,Gh,Yh,ig,eg,{displayName:"interactions.operation.switch_tab.label",id:"builtin:op:switch_tab",configRender:cg,run:dg},ag];class ug{constructor(t,r=Cr){V(this,"attachments");this.operations=r;const a=async o=>{const{id:l,schemaRef:i}=await o.getItem(null);return{id:l,schemaRef:i,operationData:new Bt(o,"data")}};this.attachments=new xr(t,"__OPERATIONS",a)}async runOperation(t,r){const a=await this.attachments.getInstance(t);if(!a){console.warn(`Operation '${t}' is not defined`);return}const o=this.tryGetSchema(a.schemaRef);if(!o){console.warn(`Operation schema '${a.schemaRef}' is not defined`);return}await o.run(r,a)}tryGetSchema(t){return this.operations.find(r=>r.id===t)}async needMigration(){const r=(await this.attachments.list()).map(async a=>{const o={configData:a.operationData},l=this.tryGetSchema(a.schemaRef),i=l==null?void 0:l.migrator;return i&&await i.needMigration(o)});return(await Promise.all(r)).some(a=>a)}async runMigration(){const r=(await this.attachments.list()).map(async a=>{const o={configData:a.operationData},l=this.tryGetSchema(a.schemaRef),i=l==null?void 0:l.migrator;i&&await i.needMigration(o)&&await i.migrate(o)});await Promise.all(r)}async createOrGetOperation(t,r){var i;if(!this.getOperationSchemaList().some(c=>c.id===r.id))throw new Error(`Operation schema '${r.id}' is not defined`);const o=await this.attachments.getInstance(t);return!o||o.schemaRef!==r.id?await this.attachments.create(t,{id:t,schemaRef:r.id,data:((i=r.createDefaultConfig)==null?void 0:i.call(r))??{}}):o}getOperationList(){return this.attachments.list()}getOperationSchemaList(){return this.operations}removeOperation(t){return this.attachments.remove(t)}async retrieveTrigger(t){return await this.attachments.getInstance(t)}}const Eo="__TRIGGERS";class pg{constructor(t,r){V(this,"attachments");this.instance=t,this.component=r;const a=async o=>{const{id:l,schemaRef:i}=await o.getItem(null);return{id:l,schemaRef:i,triggerData:new Bt(o,"data")}};this.attachments=new xr(t,Eo,a)}watchTriggerSnapshotList(t){return this.instance.instanceData.watchItem(Eo,r=>{const a=b.values(r).map(o=>({id:b.get(o,"id"),schemaRef:b.get(o,"schemaRef"),config:F.toJS(b.get(o,"data.config"))}));t(a)},{fireImmediately:!0})}async createOrGetTrigger(t,r,a={recreate:!1}){var c;if(!this.getTriggerSchemaList().some(d=>d.id===r.id))throw new Error(`Trigger schema '${r.id}' is not defined in component '${this.component.name}'`);const l=await this.attachments.getInstance(t);return!l||a.recreate||l.schemaRef!==r.id?await this.attachments.create(t,{id:t,schemaRef:r.id,data:((c=r==null?void 0:r.createDefaultConfig)==null?void 0:c.call(r))||{}}):l}async getTriggerList(){return await this.attachments.list()}getTriggerSchemaList(){return this.component.triggers||[]}async removeTrigger(t){await this.attachments.remove(t)}async retrieveTrigger(t){return await this.attachments.getInstance(t)}async getMigrationTasks(){const r=(await this.getTriggerList()).map(async a=>{const o=this.getTriggerSchemaList().find(c=>c.id===a.schemaRef),l=o==null?void 0:o.migrator,i={configData:a.triggerData};return l&&await l.needMigration(i)?()=>l.migrate(i):null});return Promise.all(r).then(a=>a.filter(o=>o))}async needMigration(){return(await this.getMigrationTasks()).length>0}async runMigration(){const t=await this.getMigrationTasks();await Promise.all(t.map(r=>r()))}}class Bo{constructor(t,r,a){V(this,"operationManager");V(this,"triggerManager");V(this,"attachments");this.operationManager=new ug(t,a),this.triggerManager=new pg(t,r);const o=async l=>{const{id:i,triggerRef:c,operationRef:d}=await l.getItem(null);return{id:i,triggerRef:c,operationRef:d}};this.attachments=new xr(t,"__INTERACTIONS",o)}async addInteraction(t,r){const a=t.id,o=r.id,l=`[${a}]:[${o}]`;await this.attachments.create(l,{id:l,triggerRef:a,operationRef:o})}getInteractionList(){return this.attachments.list()}async removeInteraction(t){const r=await this.attachments.getInstance(t);if(!r)return;const{triggerRef:a,operationRef:o}=r;await this.getTriggerRefCount(a)<=1&&await this.triggerManager.removeTrigger(a),await this.getOperationRefCount(o)<=1&&await this.operationManager.removeOperation(o),await this.attachments.remove(t)}async getOperationRefCount(t){return(await this.getInteractionList()).filter(a=>a.operationRef===t).length}async getTriggerRefCount(t){return(await this.getInteractionList()).filter(a=>a.triggerRef===t).length}async runInteraction(t,r){const o=(await this.getInteractionList()).filter(l=>l.triggerRef===t);for(let l of o)try{await this.operationManager.runOperation(l.operationRef,r)}catch(i){console.warn(`Failed to run operation '${l.operationRef}'`,i)}}}function hg(e,t){const[r,a]=h.useState([]);return O.useAsyncEffect(async()=>{const o=await e.getInteractionList();a(o)},[t,e]),r}const gg=k.observer(({item:e,manager:t,instance:r,sampleData:a,variables:o,onRemove:l})=>{const{triggerRef:i,operationRef:c}=e,d=Vh(t.triggerManager,r);if(O.useAsyncEffect(async()=>{await d.configTrigger(i,a)},[d,i,a]),d.isReady()){const u=[...d.triggerSchema.payload,...o];return n.jsxs(s.Group,{children:[n.jsx(Eh,{model:d}),n.jsx(zh,{instance:r,operationId:c,variables:u,operationManager:t.operationManager}),n.jsx(s.ActionIcon,{"aria-label":"delete-interaction",variant:"filled",color:"red",onClick:()=>l(e),children:n.jsx(S.IconTrash,{size:16})})]})}return null}),fg=e=>{const{t}=m.useTranslation(),[r,a]=h.useState(0),{interactionManager:o,instance:l,sampleData:i,variables:c}=e,d=hg(o,r),u=async()=>{const _=await o.triggerManager.createOrGetTrigger(te.randomId(),o.triggerManager.getTriggerSchemaList()[0]),w=await o.operationManager.createOrGetOperation(te.randomId(),o.operationManager.getOperationSchemaList()[0]);await o.addInteraction(_,w),a(x=>x+1)};async function p(_){await o.removeInteraction(_.id),a(w=>w+1)}const{data:f=0,loading:v}=O.useRequest(async()=>{try{return(await o.triggerManager.getTriggerSchemaList()).length}catch{return 0}});return n.jsxs(s.Stack,{children:[n.jsx(s.LoadingOverlay,{visible:v}),f===0&&n.jsx(s.Alert,{icon:n.jsx(S.IconAlertCircle,{size:16}),title:t("interactions.unavailable"),color:"gray",children:t("interactions.unavailable_reason")}),d.map(_=>n.jsx(gg,{onRemove:p,instance:l,sampleData:i,variables:c,item:_,manager:e.interactionManager},_.id)),n.jsx(s.Button,{style:{width:"fit-content"},onClick:()=>u(),disabled:f===0,children:t("interactions.add")})]})},bg=()=>{const{panel:e,data:t}=re(),r=e.viz,{vizManager:a}=h.useContext(lt),o=e.json,l=O.useCreation(()=>a.getOrCreateInstance(o),[a,o]),i=O.useCreation(()=>new Bo(l,a.resolveComponent(r.type),Cr),[l,r.type]);return h.useEffect(()=>l.instanceData.watchItem(null,b.throttle(c=>{e.viz.setConf(c)},100,{leading:!1,trailing:!0})),[l]),{instance:l,vizManager:a,interactionManager:i,sampleData:t,variables:[]}},yg=()=>{const e=bg();return n.jsx(fg,{...e})},qo={axisTick:{show:!0,alignWithLabel:!0,lineStyle:{width:2}},axisLine:{show:!0,lineStyle:{width:3}},splitLine:{show:!1},z:3};function vg(e){return b.defaultsDeep({},e,qo)}const _g=Object.freeze(Object.defineProperty({__proto__:null,getXAxis:vg,xAxis:qo},Symbol.toStringTag,{value:"Module"})),Lo={axisTick:{show:!1},axisLine:{show:!1,lineStyle:{width:3}},splitLine:{show:!0,lineStyle:{type:"dashed"}}};function mg(e){return b.defaultsDeep({},e,Lo)}const wg=Object.freeze(Object.defineProperty({__proto__:null,getYAxis:mg,yAxis:Lo},Symbol.toStringTag,{value:"Module"})),Oo={confine:!0,appendToBody:!0};function xg(e){return b.defaultsDeep({},e,Oo)}const X={..._g,...wg,...Object.freeze(Object.defineProperty({__proto__:null,getTooltip:xg,tooltip:Oo},Symbol.toStringTag,{value:"Module"}))};function Cg(e,t){const r=[],a=[];return{boxplotData:Object.entries(e).map(([l,i])=>{const c=i.map(D=>D[t]).sort((D,z)=>D-z),d=Qt.quantile(c,.25)??0,u=Qt.quantile(c,.5)??0,p=Qt.quantile(c,.75)??0,f=p-d,v=d-1.5*f,_=p+1.5*f,w=Math.max(c[0],v),x=Math.min(b.last(c)??0,_);return i.filter(D=>{const z=D[t];return z<w||z>x}).forEach(D=>r.push([l,D[t],D])),i.filter(D=>{const z=D[t];return z>=w&&z<=x}).forEach(D=>a.push([l,D[t],D])),{name:l,min:w,q1:d,median:u,q3:p,max:x}}),outliersData:r,scatterData:a}}function Sg(e,t){const{x_axis:r,y_axis:a}=e;if(!r.data_key||!a.data_key)return[];const o=$(r.data_key),l=$(a.data_key);if(o.queryID!==l.queryID)throw new Error("Please use the same query for X & Y axis");const i=b.groupBy(t[o.queryID],o.columnKey),{boxplotData:c,outliersData:d,scatterData:u}=Cg(i,l.columnKey);return[{source:c},{source:d},{source:u}]}function Tg(e){const t={top:35,left:20,right:15,bottom:25,containLabel:!0};return e.legend.orient==="vertical"&&(t.right=80),e.dataZoom.x_axis_slider&&(t.top=50),t}function kg({config:e,seriesNames:t}){const r={...e.legend,data:[{name:t.Box,icon:"roundRect",itemStyle:{color:e.color}},{name:t.Scatter,icon:"circle",itemStyle:{color:"#ED6A45",opacity:.5}},{name:t.Outlier,icon:"circle",itemStyle:{color:"#ED6A45"}}]};return e.legend.orient==="horizontal"&&e.dataZoom.x_axis_slider&&(r.top=15),r}function Dg(e,t,r){const a=t.reduce((o,l)=>{const i=Re(l,r);return o[l.name]=Be(l,i),o},{});return e.map(o=>({name:"refs",type:"scatter",data:[],markLine:{data:[{name:o.name,yAxis:Number(a[o.variable_key])}],silent:!0,symbol:["none","triangle"],symbolRotate:90,symbolSize:[10,8],label:{formatter:function(){return Ut(o.template,t,r)},position:"insideEndTop"}}}))}const Sr=["max","q3","median","q1","min"],Tr=[10,40];function kr(e){return e.barLayout({barMinWidth:Tr[0],barMaxWidth:Tr[1],count:2})}function zg(e,t,r){const{itemStyle:{color:a,borderColor:o,borderWidth:l}}=r,i=kr(t),c=t.value(0),d=e.source[c],{min:u,q1:p,median:f,q3:v,max:_}=d,w={min:t.coord([c,u]),q1:t.coord([c,p]),median:t.coord([c,f]),q3:t.coord([c,v]),max:t.coord([c,_])},x={left:i[1].offset,center:(i[1].offset+i[1].width)/2,right:i[1].width},T={type:"group",children:[]},D=[{x1:w.max[0]+x.left,x2:w.max[0]+x.right,y1:w.max[1],y2:w.max[1]},{x1:w.median[0]+x.left,x2:w.median[0]+x.right,y1:w.median[1],y2:w.median[1]},{x1:w.min[0]+x.left,x2:w.min[0]+x.right,y1:w.min[1],y2:w.min[1]},{x1:w.min[0]+x.center,x2:w.min[0]+x.center,y1:w.min[1],y2:w.q1[1]},{x1:w.max[0]+x.center,x2:w.max[0]+x.center,y1:w.max[1],y2:w.q3[1]}],z={stroke:o,lineWidth:l};return D.forEach(I=>{T.children.push({type:"line",shape:I,style:z})}),T.children.push({type:"rect",shape:{x:w.q1[0]+x.left,y:w.q1[1],width:x.right-x.left,height:w.q3[1]-w.q1[1]},style:{fill:a,stroke:o,lineWidth:l}}),T}function Mg(e,t){const{color:r}=t,a={name:"Box",type:"custom",itemStyle:{color:r,borderColor:"#2F8CC0",borderWidth:2},emphasis:{disabled:!0},boxWidth:Tr,datasetIndex:0};return a.renderItem=(o,l)=>zg(e,l,a),a}function Ig(e){const t=kr(e),r=t[0].width,a=e.value(0),o=e.value(1),[l,i]=e.coord([a,o]),d=l+t[0].offset+Math.random()*r;return{type:"circle",transition:["shape"],x:d,y:i,shape:{cx:0,cy:0,r:2},style:{fill:e.visual("color"),opacity:.5}}}function Vg(){const e={name:"Scatter",type:"custom",itemStyle:{color:"#ED6A45"},emphasis:{scale:2},datasetIndex:2};return e.renderItem=(t,r)=>Ig(r),e}function Pg(e,t){const r=kr(e),a=r[0].width,o=e.value(0),l=e.value(1),[i,c]=e.coord([o,l]),u=i+r[0].offset+Math.random()*a;return{type:"circle",transition:["shape"],x:u,y:c,shape:{cx:0,cy:0,r:3},style:{fill:e.visual("color")}}}function $g(){const e={name:"Outlier",type:"custom",itemStyle:{color:"#ED6A45"},emphasis:{scale:2},datasetIndex:1};return e.renderItem=(t,r)=>Pg(r),e}function Ag(e,t){const r=t[0],a=Mg(r,e),o=Vg(),l=$g();return[{name:"Placeholder Box",type:"boxplot",ignore:!0,silent:!0,itemStyle:{color:"none",borderColor:"none",opacity:0},boxWidth:[20,80],datasetIndex:0,encode:{y:Sr,x:"name",itemName:["name"],tooltip:Sr}},{name:"Outlier",type:"scatter",symbolSize:7,itemStyle:{color:"transparent"},ignore:!0,silent:!0,emphasis:{disabled:!0},datasetIndex:1},a,o,l]}const Eg=(e,t)=>{const r=Sr.map(l=>`
|
|
69
|
+
`}function Ke(e){return{width:e.width,overflow:e.overflow,ellipsis:e.ellipsis}}const ue=h.forwardRef(({value:e,onChange:t,hiddenFileds:r},a)=>{const{t:o}=m.useTranslation(),l=h.useMemo(()=>new Set(r??[]),[r]),i=c=>d=>{t({...e,[c]:d})};return n.jsxs(s.Stack,{ref:a,gap:"sm",children:[n.jsx(s.Divider,{mb:-10,label:o("chart.unit.title"),labelPosition:"center",variant:"dashed"}),!l.has("text")&&n.jsx(s.TextInput,{size:"xs",placeholder:o("chart.unit.text.placeholder"),value:e.text,onChange:c=>i("text")(c.currentTarget.value)}),n.jsxs(s.Group,{grow:!0,children:[!l.has("show_in_tooltip")&&n.jsx(s.Checkbox,{size:"xs",label:o("chart.unit.show_in_tooltip"),checked:e.show_in_tooltip,onChange:c=>i("show_in_tooltip")(c.currentTarget.checked)}),!l.has("show_in_legend")&&n.jsx(s.Checkbox,{size:"xs",label:o("chart.unit.show_in_legend"),checked:e.show_in_legend,onChange:c=>i("show_in_legend")(c.currentTarget.checked)})]})]})});function K(){return{text:"",show_in_tooltip:!1,show_in_legend:!1}}const mr={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:_e(),overflow:Ie()}},y_axis:{name:"Y Axis",data_key:"value",label_formatter:de,unit:K()},tooltip:{metrics:[]},color:"rgba(99, 152, 199, 0.10)",reference_lines:[],legend:{show:!0,top:"10",right:"0",left:"auto",bottom:"auto",orient:"vertical",type:"scroll"},dataZoom:Vo()};function Dt(e,t){return h.useMemo(()=>{const{queryID:r,columnKey:a}=$(t);return b.keyBy(e[r],a)},[e,t])}const Ve=(e,t)=>{const[r,a]=h.useState([]);return h.useEffect(()=>e.watchTriggerSnapshotList(o=>a(o.filter(l=>l.schemaRef===t))),[]),r},wr=h.createContext(null);function bn(e){const t=h.useContext(wr),r=O.useCreation(()=>e.configure(t||new Un),[e.configure]),a=O.usePrevious(r);return a&&a!==r&&a.dispose(),n.jsx(wr.Provider,{value:r,children:e.children})}function Yt(){return h.useContext(wr)}const Pe=({})=>Yt().getRequired(ee.instanceScope.interactionManager),$o=e=>{const{t}=m.useTranslation(),{title:r="Variables",variables:a}=e,o=te.useClipboard(),l=i=>{o.copy(i),Ge.showNotification({color:"green",message:t("common.copied")})};return n.jsxs(s.Paper,{withBorder:!0,p:"sm",children:[n.jsx(s.Text,{size:"xs",c:"dimmed",mb:"sm",children:r}),n.jsx(s.Stack,{style:{maxHeight:"500px"},children:a.map(i=>n.jsxs(s.Text,{size:"sm",children:[n.jsxs(s.Code,{color:"teal",children:["// ",i.description]}),n.jsx("br",{}),n.jsxs(s.Code,{onClick:()=>l(i.name),style:{cursor:"pointer"},children:[i.name," : ",i.valueType]})]},i.name))})]})};class Sh{constructor(t,r){V(this,"operationId");V(this,"operation");V(this,"operationSchema");V(this,"variables",[]);this.operationManager=t,this.instance=r,G.makeAutoObservable(this)}get schemaList(){return this.operationManager.getOperationSchemaList()}async configOperation(t,r){const a=await this.operationManager.retrieveTrigger(t),o=this.operationManager.getOperationSchemaList().find(l=>l.id===(a==null?void 0:a.schemaRef));G.runInAction(()=>{this.operationId=t,this.operation=a,this.operationSchema=o,this.variables=r})}async changeSchema(t){this.operationId&&(await this.operationManager.createOrGetOperation(this.operationId,t),await this.configOperation(this.operationId,this.variables))}}function Th(e){return!!e.operationId}const kh=k.observer(({model:e,onClick:t})=>{var o;const{t:r}=m.useTranslation(),a=(o=e.operationSchema)==null?void 0:o.displayName;return n.jsx(s.Button,{variant:"outline",onClick:t,children:r(a)})}),Ao=k.observer(({model:e})=>{const t={operation:e.operation,instance:e.instance,variables:[]};return h.createElement(e.operationSchema.configRender,t)}),Dh=k.observer(({model:e})=>{const{t,i18n:r}=m.useTranslation(),a=e.schemaList,o=h.useMemo(()=>a.map(i=>({label:t(i.displayName),value:i.id})),[a,r.language]);async function l(i){await e.changeSchema(a.find(c=>c.id===i))}return n.jsx(s.Select,{label:t("interactions.operation.label"),data:o,onChange:Z(l),value:e.operationSchema.id,comboboxProps:{withinPortal:!0,zIndex:340},maxDropdownHeight:500})}),zh=k.observer(e=>{const{t}=m.useTranslation(),[r,{setTrue:a,setFalse:o}]=O.useBoolean(!1),{operationManager:l,operationId:i,instance:c,variables:d}=e,u=O.useCreation(()=>new Sh(l,c),[l,c]);return O.useAsyncEffect(async()=>{await u.configOperation(i,d)},[i,u]),Th(u)?n.jsxs(n.Fragment,{children:[n.jsx(kh,{model:u,onClick:a}),n.jsx(s.Modal,{size:600,opened:r,onClose:o,title:t("interactions.operation.setup"),zIndex:320,children:n.jsxs(s.Stack,{children:[n.jsx(Dh,{model:u}),u.variables.length>0?n.jsxs(s.Tabs,{defaultValue:"settings",children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"settings",children:t("interactions.operation.settings")}),n.jsx(s.Tabs.Tab,{value:"variables",children:t("interactions.operation.variables")})]}),n.jsx(s.Tabs.Panel,{value:"settings",pt:10,children:n.jsx(Ao,{model:u})}),n.jsx(s.Tabs.Panel,{value:"variables",pt:10,children:n.jsx($o,{title:t("interactions.operation.variables"),variables:u.variables})})]}):n.jsx(Ao,{model:u})]})})]}):null});class Mh{constructor(t,r){V(this,"triggerId");V(this,"trigger");V(this,"triggerSchema");V(this,"sampleData");this.triggerManager=t,this.instance=r,G.makeAutoObservable(this)}get schemaList(){return this.triggerManager.getTriggerSchemaList()}async configTrigger(t,r){const a=await this.triggerManager.retrieveTrigger(t),o=this.triggerManager.getTriggerSchemaList().find(l=>l.id===(a==null?void 0:a.schemaRef));G.runInAction(()=>{this.triggerId=t,this.trigger=a,this.triggerSchema=o,this.sampleData=r})}async changeSchema(t){this.triggerId&&(await this.triggerManager.createOrGetTrigger(this.triggerId,t),await this.configTrigger(this.triggerId,this.sampleData))}isReady(){return Ih(this)}}function Ih(e){return!!e.triggerId&&!!e.triggerSchema}function Vh(e,t){return O.useCreation(()=>new Mh(e,t),[e,t])}const Ph=k.observer(({model:e,onClick:t})=>{const r=e.triggerSchema.nameRender,a={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return n.jsx(s.Button,{variant:"outline",onClick:t,children:h.createElement(r,a)})}),$h=k.observer(({model:e})=>{const{t,i18n:r}=m.useTranslation(),a=e.schemaList,o=h.useMemo(()=>a.map(i=>({label:t(i.displayName),value:i.id})),[a,r.language]);async function l(i){await e.changeSchema(a.find(c=>c.id===i))}return n.jsx(s.Select,{label:t("interactions.trigger.label"),data:o,value:e.triggerSchema.id,onChange:Z(l)})}),Ah=k.observer(({model:e})=>{const t={trigger:e.trigger,instance:e.instance,sampleData:e.sampleData};return h.createElement(e.triggerSchema.configRender,t)}),Eh=k.observer(e=>{const{t}=m.useTranslation(),[r,{setTrue:a,setFalse:o}]=O.useBoolean(!1),l=e.model;return n.jsxs(n.Fragment,{children:[n.jsx(s.Modal,{opened:r,onClose:o,title:t("interactions.trigger.setup"),zIndex:320,children:n.jsxs(s.Stack,{children:[n.jsx($h,{model:l}),n.jsx(Ah,{model:l}),n.jsx($o,{title:t("interactions.trigger.payload"),variables:l.triggerSchema.payload})]})}),n.jsx(Ph,{onClick:a,model:l})]})});class Bt{constructor(t,r){this.root=t,this.path=r}async deleteItem(t){t===null&&await this.root.deleteItem(this.path);const r=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,b.omit(r,t))}async getItem(t){const r=await this.root.getItem(this.path);return t===null?r:b.get(r,t)}async setItem(t,r){if(t===null)await this.root.setItem(this.path,r);else{const a=await this.root.getItem(this.path)||{};await this.root.setItem(this.path,{...a,[t]:r})}return await this.getItem(t)}watchItem(t,r,a){return t===null?this.root.watchItem(this.path,(o,l)=>{r(o,l)},a):this.root.watchItem(this.path,(o,l)=>{const i=b.get(o,t),c=b.get(l,t);i!==c&&r(i,c)},a)}}const Bh={"builtin:op:debug":1,"builtin:op:clear_filter_values":2,"builtin:op:set_filter_values":3,"builtin:op:open_view":4,"builtin:op:open-link":5};class xr{constructor(t,r,a){V(this,"attachmentStorage");this.instance=t,this.attachmentKey=r,this.constructInstance=a,this.attachmentStorage=new Bt(t.instanceData,r)}async getInstance(t){if(await this.attachmentStorage.getItem(t))return this.constructInstance(new Bt(this.attachmentStorage,t))}async create(t,r){return await this.attachmentStorage.setItem(t,r),this.constructInstance(new Bt(this.attachmentStorage,t))}async remove(t){await this.attachmentStorage.deleteItem(t)}async list(){const t=await this.attachmentStorage.getItem(null),r=b.orderBy(b.values(t),a=>Bh[a.schemaRef]??10);return Promise.all(r.map(a=>this.constructInstance(new Bt(this.attachmentStorage,a.id))))}}function qh(e,t){const{value:r,set:a}=q(e.operation.operationData,"config"),[o,l]=h.useState(b.defaults({},r,t)),i=async()=>{await a(o)};return h.useEffect(()=>{l(b.defaults({},r,t))},[r]),{config:o,setConfig:l,commit:i}}function Lh(e){const{t}=m.useTranslation(),{config:r,setConfig:a,commit:o}=qh(e,{urlTemplate:"",openInNewTab:!0});async function l(){await o()}async function i(d){a({...r,openInNewTab:d}),await o()}const c=d=>a({...r,urlTemplate:d.currentTarget.value});return n.jsxs(s.Stack,{children:[n.jsx(s.TextInput,{label:t("interactions.operation.open_link.url"),value:r.urlTemplate,onChange:c,onBlur:l}),n.jsx(s.Switch,{label:t("interactions.operation.open_link.open_in_new_tab"),checked:r.openInNewTab,onChange:d=>i(d.currentTarget.checked)})]})}async function Oh(e,t){const{urlTemplate:r,openInNewTab:a}=await t.operationData.getItem("config");window.dispatchEvent(new CustomEvent("open-link",{detail:{urlTemplate:r,openInNewTab:a,payload:e}}))}class Nh extends J{constructor(){super(...arguments);V(this,"VERSION",1)}configVersions(){this.version(1,r=>r)}}const Gh={displayName:"interactions.operation.open_link.label",id:"builtin:op:open-link",configRender:Lh,run:Oh,migrator:new Nh,createDefaultConfig:()=>({version:1,config:{urlTemplate:"",openInNewTab:!0}})};function Fh(e){const{value:t,set:r}=q(e.operationData,"config"),a=o=>void r({template:o});return[(t==null?void 0:t.template)||"",a]}function Qh(e){const{t}=m.useTranslation(),[r,a]=Fh(e.operation);return n.jsx(s.TextInput,{defaultValue:r,onBlur:o=>a(o.currentTarget.value),label:t("interactions.operation.console_log.log_content")})}async function jh(e,t){const r=await t.operationData.getItem("config"),a=b.template(r.template||"");console.log("run with payload",e),console.log(a(e))}const Wh={displayName:"interactions.operation.console_log.label",id:"builtin:op:debug",configRender:Qh,run:jh},Uh=k.observer(e=>{const{t}=m.useTranslation(),r=F(),{value:a,set:o}=q(e.operation.operationData,"config"),l=(a==null?void 0:a.viewID)||"",i=c=>void o({viewID:c});return n.jsx(s.Select,{defaultValue:l,value:l,onChange:Z(i),label:t("interactions.operation.open_view.view"),data:r.views.options,comboboxProps:{withinPortal:!0,zIndex:340},maxDropdownHeight:500})});async function Kh(e,t){const a=(await t.operationData.getItem("config")).viewID;window.dispatchEvent(new CustomEvent("open-view",{detail:{viewID:a}}))}const Yh={displayName:"interactions.operation.open_view.label",id:"builtin:op:open_view",configRender:Uh,run:Kh},Xh={"tbody tr":{opacity:.5,transition:"opacity 200ms ease"},"tr[data-affected=true]":{opacity:1}},Zh=({value:e="",onChange:t})=>{const[r,a]=h.useState(e);h.useEffect(()=>{a(e)},[e]);const o=()=>{t(r)};return n.jsx(s.TextInput,{size:"xs",label:"",value:r,onChange:l=>a(l.currentTarget.value),sx:{flexGrow:1},rightSection:n.jsx(s.ActionIcon,{color:"green",size:"xs",onClick:o,disabled:r===e,children:n.jsx(S.IconDeviceFloppy,{})})})},Jh={dictionary:{}},Hh=k.observer(e=>{const{t}=m.useTranslation(),r=F(),{value:a=Jh,set:o}=q(e.operation.operationData,"config"),{dictionary:l={}}=a;console.log({value:{...a},dictionary:{...l},filters:[...r.filters.keyLabelOptions]});const i=(c,d)=>{if(d===""){const u={...l};delete u[c],o({dictionary:u});return}o({dictionary:{...l,[c]:d}})};return n.jsxs(s.Table,{sx:Xh,children:[n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:t("interactions.operation.set_filter_values.set_filter")}),n.jsx(s.Table.Th,{children:t("interactions.operation.set_filter_values.with")})]})}),n.jsx(s.Table.Tbody,{children:[...r.filters.keyLabelOptions].map(c=>{const d=c.value in l;return n.jsxs(s.Table.Tr,{"data-affected":d,children:[n.jsx(s.Table.Td,{children:c.label}),n.jsx(s.Table.Td,{children:n.jsx(Zh,{value:l[c.value],onChange:u=>i(c.value,u)})})]},c.value)})})]})});async function Rh(e,t){const a=(await t.operationData.getItem("config")).dictionary;window.dispatchEvent(new CustomEvent("set-filter-values",{detail:{dictionary:a,payload:e}}))}const eg={displayName:"interactions.operation.set_filter_values.label",id:"builtin:op:set_filter_values",configRender:Hh,run:Rh},tg={filter_keys:[]},ng=k.observer(e=>{const{t}=m.useTranslation(),r=F(),{value:a=tg,set:o}=q(e.operation.operationData,"config"),{filter_keys:l=[]}=a,i=d=>{o({filter_keys:[...d]})},c=h.useMemo(()=>r.filters.current.map(d=>({label:d.label,value:d.key})),[r.filters.values]);return n.jsx(s.Stack,{gap:10,children:n.jsx(s.MultiSelect,{label:t("interactions.operation.clear_filter_values.select_filter"),data:c,value:l,onChange:i})})});async function rg(e,t){const a=(await t.operationData.getItem("config")).filter_keys;window.dispatchEvent(new CustomEvent("clear-filter-values",{detail:{filter_keys:a,payload:e}}))}const ag={displayName:"interactions.operation.clear_filter_values.label",id:"builtin:op:clear_filter_values",configRender:ng,run:rg},sg=({option:e,checked:t})=>{var o;const{t:r}=m.useTranslation(),a=e;return n.jsxs(s.Group,{justify:"space-between",flex:"1",gap:"xs",children:[n.jsx(s.Text,{size:"xs",children:a.label}),n.jsx(s.Text,{size:"xs",children:r((o=Jl[a.viz_type])==null?void 0:o.displayName)??a.viz_type})]})},og=k.observer(e=>{const{t}=m.useTranslation(),r=F(),{value:a,set:o}=q(e.operation.operationData,"config"),l=(a==null?void 0:a.panelID)||"",i=c=>void o({panelID:c});return n.jsx(s.Select,{defaultValue:l,value:l,onChange:Z(i),label:t("interactions.operation.scroll_to_panel.panel"),data:r.panels.options,comboboxProps:{withinPortal:!0,zIndex:340},maxDropdownHeight:500,renderOption:sg})});async function lg(e,t){const a=(await t.operationData.getItem("config")).panelID;window.dispatchEvent(new CustomEvent("scroll_to_panel",{detail:{panelID:a}}))}const ig={displayName:"interactions.operation.scroll_to_panel.label",id:"builtin:op:scroll_to_panel",configRender:og,run:lg},cg=k.observer(e=>{const{t}=m.useTranslation(),r=F(),{value:a,set:o}=q(e.operation.operationData,"config"),{viewID:l="",tab:i=""}=a??{},c=u=>void o({viewID:u,tab:i}),d=u=>void o({viewID:l,tab:u});return n.jsxs(s.Stack,{gap:"xs",children:[n.jsx(s.Select,{defaultValue:l,value:l,onChange:Z(c),label:t("interactions.operation.switch_tab.view"),data:r.views.tabViewOptions,comboboxProps:{withinPortal:!0,zIndex:340},maxDropdownHeight:500}),n.jsx(s.Select,{defaultValue:i,value:i,onChange:Z(d),label:t("interactions.operation.switch_tab.tab"),data:r.views.tabOptions(l),comboboxProps:{withinPortal:!0,zIndex:340},maxDropdownHeight:500})]})});async function dg(e,t){const r=await t.operationData.getItem("config"),{viewID:a,tab:o}=r;window.dispatchEvent(new CustomEvent("switch_tab",{detail:{viewID:a,tab:o}}))}const Cr=[Wh,Gh,Yh,ig,eg,{displayName:"interactions.operation.switch_tab.label",id:"builtin:op:switch_tab",configRender:cg,run:dg},ag];class ug{constructor(t,r=Cr){V(this,"attachments");this.operations=r;const a=async o=>{const{id:l,schemaRef:i}=await o.getItem(null);return{id:l,schemaRef:i,operationData:new Bt(o,"data")}};this.attachments=new xr(t,"__OPERATIONS",a)}async runOperation(t,r){const a=await this.attachments.getInstance(t);if(!a){console.warn(`Operation '${t}' is not defined`);return}const o=this.tryGetSchema(a.schemaRef);if(!o){console.warn(`Operation schema '${a.schemaRef}' is not defined`);return}await o.run(r,a)}tryGetSchema(t){return this.operations.find(r=>r.id===t)}async needMigration(){const r=(await this.attachments.list()).map(async a=>{const o={configData:a.operationData},l=this.tryGetSchema(a.schemaRef),i=l==null?void 0:l.migrator;return i&&await i.needMigration(o)});return(await Promise.all(r)).some(a=>a)}async runMigration(){const r=(await this.attachments.list()).map(async a=>{const o={configData:a.operationData},l=this.tryGetSchema(a.schemaRef),i=l==null?void 0:l.migrator;i&&await i.needMigration(o)&&await i.migrate(o)});await Promise.all(r)}async createOrGetOperation(t,r){var i;if(!this.getOperationSchemaList().some(c=>c.id===r.id))throw new Error(`Operation schema '${r.id}' is not defined`);const o=await this.attachments.getInstance(t);return!o||o.schemaRef!==r.id?await this.attachments.create(t,{id:t,schemaRef:r.id,data:((i=r.createDefaultConfig)==null?void 0:i.call(r))??{}}):o}getOperationList(){return this.attachments.list()}getOperationSchemaList(){return this.operations}removeOperation(t){return this.attachments.remove(t)}async retrieveTrigger(t){return await this.attachments.getInstance(t)}}const Eo="__TRIGGERS";class pg{constructor(t,r){V(this,"attachments");this.instance=t,this.component=r;const a=async o=>{const{id:l,schemaRef:i}=await o.getItem(null);return{id:l,schemaRef:i,triggerData:new Bt(o,"data")}};this.attachments=new xr(t,Eo,a)}watchTriggerSnapshotList(t){return this.instance.instanceData.watchItem(Eo,r=>{const a=b.values(r).map(o=>({id:b.get(o,"id"),schemaRef:b.get(o,"schemaRef"),config:G.toJS(b.get(o,"data.config"))}));t(a)},{fireImmediately:!0})}async createOrGetTrigger(t,r,a={recreate:!1}){var c;if(!this.getTriggerSchemaList().some(d=>d.id===r.id))throw new Error(`Trigger schema '${r.id}' is not defined in component '${this.component.name}'`);const l=await this.attachments.getInstance(t);return!l||a.recreate||l.schemaRef!==r.id?await this.attachments.create(t,{id:t,schemaRef:r.id,data:((c=r==null?void 0:r.createDefaultConfig)==null?void 0:c.call(r))||{}}):l}async getTriggerList(){return await this.attachments.list()}getTriggerSchemaList(){return this.component.triggers||[]}async removeTrigger(t){await this.attachments.remove(t)}async retrieveTrigger(t){return await this.attachments.getInstance(t)}async getMigrationTasks(){const r=(await this.getTriggerList()).map(async a=>{const o=this.getTriggerSchemaList().find(c=>c.id===a.schemaRef),l=o==null?void 0:o.migrator,i={configData:a.triggerData};return l&&await l.needMigration(i)?()=>l.migrate(i):null});return Promise.all(r).then(a=>a.filter(o=>o))}async needMigration(){return(await this.getMigrationTasks()).length>0}async runMigration(){const t=await this.getMigrationTasks();await Promise.all(t.map(r=>r()))}}class Bo{constructor(t,r,a){V(this,"operationManager");V(this,"triggerManager");V(this,"attachments");this.operationManager=new ug(t,a),this.triggerManager=new pg(t,r);const o=async l=>{const{id:i,triggerRef:c,operationRef:d}=await l.getItem(null);return{id:i,triggerRef:c,operationRef:d}};this.attachments=new xr(t,"__INTERACTIONS",o)}async addInteraction(t,r){const a=t.id,o=r.id,l=`[${a}]:[${o}]`;await this.attachments.create(l,{id:l,triggerRef:a,operationRef:o})}getInteractionList(){return this.attachments.list()}async removeInteraction(t){const r=await this.attachments.getInstance(t);if(!r)return;const{triggerRef:a,operationRef:o}=r;await this.getTriggerRefCount(a)<=1&&await this.triggerManager.removeTrigger(a),await this.getOperationRefCount(o)<=1&&await this.operationManager.removeOperation(o),await this.attachments.remove(t)}async getOperationRefCount(t){return(await this.getInteractionList()).filter(a=>a.operationRef===t).length}async getTriggerRefCount(t){return(await this.getInteractionList()).filter(a=>a.triggerRef===t).length}async runInteraction(t,r){const o=(await this.getInteractionList()).filter(l=>l.triggerRef===t);for(let l of o)try{await this.operationManager.runOperation(l.operationRef,r)}catch(i){console.warn(`Failed to run operation '${l.operationRef}'`,i)}}}function hg(e,t){const[r,a]=h.useState([]);return O.useAsyncEffect(async()=>{const o=await e.getInteractionList();a(o)},[t,e]),r}const gg=k.observer(({item:e,manager:t,instance:r,sampleData:a,variables:o,onRemove:l})=>{const{triggerRef:i,operationRef:c}=e,d=Vh(t.triggerManager,r);if(O.useAsyncEffect(async()=>{await d.configTrigger(i,a)},[d,i,a]),d.isReady()){const u=[...d.triggerSchema.payload,...o];return n.jsxs(s.Group,{children:[n.jsx(Eh,{model:d}),n.jsx(zh,{instance:r,operationId:c,variables:u,operationManager:t.operationManager}),n.jsx(s.ActionIcon,{"aria-label":"delete-interaction",variant:"filled",color:"red",onClick:()=>l(e),children:n.jsx(S.IconTrash,{size:16})})]})}return null}),fg=e=>{const{t}=m.useTranslation(),[r,a]=h.useState(0),{interactionManager:o,instance:l,sampleData:i,variables:c}=e,d=hg(o,r),u=async()=>{const _=await o.triggerManager.createOrGetTrigger(te.randomId(),o.triggerManager.getTriggerSchemaList()[0]),w=await o.operationManager.createOrGetOperation(te.randomId(),o.operationManager.getOperationSchemaList()[0]);await o.addInteraction(_,w),a(x=>x+1)};async function p(_){await o.removeInteraction(_.id),a(w=>w+1)}const{data:f=0,loading:v}=O.useRequest(async()=>{try{return(await o.triggerManager.getTriggerSchemaList()).length}catch{return 0}});return n.jsxs(s.Stack,{children:[n.jsx(s.LoadingOverlay,{visible:v}),f===0&&n.jsx(s.Alert,{icon:n.jsx(S.IconAlertCircle,{size:16}),title:t("interactions.unavailable"),color:"gray",children:t("interactions.unavailable_reason")}),d.map(_=>n.jsx(gg,{onRemove:p,instance:l,sampleData:i,variables:c,item:_,manager:e.interactionManager},_.id)),n.jsx(s.Button,{style:{width:"fit-content"},onClick:()=>u(),disabled:f===0,children:t("interactions.add")})]})},bg=()=>{const{panel:e,data:t}=re(),r=e.viz,{vizManager:a}=h.useContext(lt),o=e.json,l=O.useCreation(()=>a.getOrCreateInstance(o),[a,o]),i=O.useCreation(()=>new Bo(l,a.resolveComponent(r.type),Cr),[l,r.type]);return h.useEffect(()=>l.instanceData.watchItem(null,b.throttle(c=>{e.viz.setConf(c)},100,{leading:!1,trailing:!0})),[l]),{instance:l,vizManager:a,interactionManager:i,sampleData:t,variables:[]}},yg=()=>{const e=bg();return n.jsx(fg,{...e})},qo={axisTick:{show:!0,alignWithLabel:!0,lineStyle:{width:2}},axisLine:{show:!0,lineStyle:{width:3}},splitLine:{show:!1},z:3};function vg(e){return b.defaultsDeep({},e,qo)}const _g=Object.freeze(Object.defineProperty({__proto__:null,getXAxis:vg,xAxis:qo},Symbol.toStringTag,{value:"Module"})),Lo={axisTick:{show:!1},axisLine:{show:!1,lineStyle:{width:3}},splitLine:{show:!0,lineStyle:{type:"dashed"}}};function mg(e){return b.defaultsDeep({},e,Lo)}const wg=Object.freeze(Object.defineProperty({__proto__:null,getYAxis:mg,yAxis:Lo},Symbol.toStringTag,{value:"Module"})),Oo={confine:!0,appendToBody:!0};function xg(e){return b.defaultsDeep({},e,Oo)}const X={..._g,...wg,...Object.freeze(Object.defineProperty({__proto__:null,getTooltip:xg,tooltip:Oo},Symbol.toStringTag,{value:"Module"}))};function Cg(e,t){const r=[],a=[];return{boxplotData:Object.entries(e).map(([l,i])=>{const c=i.map(D=>D[t]).sort((D,z)=>D-z),d=Qt.quantile(c,.25)??0,u=Qt.quantile(c,.5)??0,p=Qt.quantile(c,.75)??0,f=p-d,v=d-1.5*f,_=p+1.5*f,w=Math.max(c[0],v),x=Math.min(b.last(c)??0,_);return i.filter(D=>{const z=D[t];return z<w||z>x}).forEach(D=>r.push([l,D[t],D])),i.filter(D=>{const z=D[t];return z>=w&&z<=x}).forEach(D=>a.push([l,D[t],D])),{name:l,min:w,q1:d,median:u,q3:p,max:x}}),outliersData:r,scatterData:a}}function Sg(e,t){const{x_axis:r,y_axis:a}=e;if(!r.data_key||!a.data_key)return[];const o=$(r.data_key),l=$(a.data_key);if(o.queryID!==l.queryID)throw new Error("Please use the same query for X & Y axis");const i=b.groupBy(t[o.queryID],o.columnKey),{boxplotData:c,outliersData:d,scatterData:u}=Cg(i,l.columnKey);return[{source:c},{source:d},{source:u}]}function Tg(e){const t={top:35,left:20,right:15,bottom:25,containLabel:!0};return e.legend.orient==="vertical"&&(t.right=80),e.dataZoom.x_axis_slider&&(t.top=50),t}function kg({config:e,seriesNames:t}){const r={...e.legend,data:[{name:t.Box,icon:"roundRect",itemStyle:{color:e.color}},{name:t.Scatter,icon:"circle",itemStyle:{color:"#ED6A45",opacity:.5}},{name:t.Outlier,icon:"circle",itemStyle:{color:"#ED6A45"}}]};return e.legend.orient==="horizontal"&&e.dataZoom.x_axis_slider&&(r.top=15),r}function Dg(e,t,r){const a=t.reduce((o,l)=>{const i=Re(l,r);return o[l.name]=Be(l,i),o},{});return e.map(o=>({name:"refs",type:"scatter",data:[],markLine:{data:[{name:o.name,yAxis:Number(a[o.variable_key])}],silent:!0,symbol:["none","triangle"],symbolRotate:90,symbolSize:[10,8],label:{formatter:function(){return Ut(o.template,t,r)},position:"insideEndTop"}}}))}const Sr=["max","q3","median","q1","min"],Tr=[10,40];function kr(e){return e.barLayout({barMinWidth:Tr[0],barMaxWidth:Tr[1],count:2})}function zg(e,t,r){const{itemStyle:{color:a,borderColor:o,borderWidth:l}}=r,i=kr(t),c=t.value(0),d=e.source[c],{min:u,q1:p,median:f,q3:v,max:_}=d,w={min:t.coord([c,u]),q1:t.coord([c,p]),median:t.coord([c,f]),q3:t.coord([c,v]),max:t.coord([c,_])},x={left:i[1].offset,center:(i[1].offset+i[1].width)/2,right:i[1].width},T={type:"group",children:[]},D=[{x1:w.max[0]+x.left,x2:w.max[0]+x.right,y1:w.max[1],y2:w.max[1]},{x1:w.median[0]+x.left,x2:w.median[0]+x.right,y1:w.median[1],y2:w.median[1]},{x1:w.min[0]+x.left,x2:w.min[0]+x.right,y1:w.min[1],y2:w.min[1]},{x1:w.min[0]+x.center,x2:w.min[0]+x.center,y1:w.min[1],y2:w.q1[1]},{x1:w.max[0]+x.center,x2:w.max[0]+x.center,y1:w.max[1],y2:w.q3[1]}],z={stroke:o,lineWidth:l};return D.forEach(I=>{T.children.push({type:"line",shape:I,style:z})}),T.children.push({type:"rect",shape:{x:w.q1[0]+x.left,y:w.q1[1],width:x.right-x.left,height:w.q3[1]-w.q1[1]},style:{fill:a,stroke:o,lineWidth:l}}),T}function Mg(e,t){const{color:r}=t,a={name:"Box",type:"custom",itemStyle:{color:r,borderColor:"#2F8CC0",borderWidth:2},emphasis:{disabled:!0},boxWidth:Tr,datasetIndex:0};return a.renderItem=(o,l)=>zg(e,l,a),a}function Ig(e){const t=kr(e),r=t[0].width,a=e.value(0),o=e.value(1),[l,i]=e.coord([a,o]),d=l+t[0].offset+Math.random()*r;return{type:"circle",transition:["shape"],x:d,y:i,shape:{cx:0,cy:0,r:2},style:{fill:e.visual("color"),opacity:.5}}}function Vg(){const e={name:"Scatter",type:"custom",itemStyle:{color:"#ED6A45"},emphasis:{scale:2},datasetIndex:2};return e.renderItem=(t,r)=>Ig(r),e}function Pg(e,t){const r=kr(e),a=r[0].width,o=e.value(0),l=e.value(1),[i,c]=e.coord([o,l]),u=i+r[0].offset+Math.random()*a;return{type:"circle",transition:["shape"],x:u,y:c,shape:{cx:0,cy:0,r:3},style:{fill:e.visual("color")}}}function $g(){const e={name:"Outlier",type:"custom",itemStyle:{color:"#ED6A45"},emphasis:{scale:2},datasetIndex:1};return e.renderItem=(t,r)=>Pg(r),e}function Ag(e,t){const r=t[0],a=Mg(r,e),o=Vg(),l=$g();return[{name:"Placeholder Box",type:"boxplot",ignore:!0,silent:!0,itemStyle:{color:"none",borderColor:"none",opacity:0},boxWidth:[20,80],datasetIndex:0,encode:{y:Sr,x:"name",itemName:["name"],tooltip:Sr}},{name:"Outlier",type:"scatter",symbolSize:7,itemStyle:{color:"transparent"},ignore:!0,silent:!0,emphasis:{disabled:!0},datasetIndex:1},a,o,l]}const Eg=(e,t)=>{const r=Sr.map(l=>`
|
|
70
70
|
<tr>
|
|
71
71
|
<th style="text-align: right; padding: 0 1em;">${b.capitalize(l)}</th>
|
|
72
72
|
<td style="text-align: left; padding: 0 1em;">
|
|
@@ -116,7 +116,7 @@ Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel vari
|
|
|
116
116
|
${o.join("")}
|
|
117
117
|
</tbody>
|
|
118
118
|
</table>
|
|
119
|
-
`}const Og=(e,t)=>r=>{const{seriesName:a,value:o}=r;switch(a){case t.Box:return Eg(e,o);case t.Outlier:return qg(e,o);case t.Scatter:return Lg(e,o)}};function Ng({config:e,seriesNames:t}){return X.getTooltip({trigger:"item",formatter:Og(e,t)})}function yn(e,t){t||(t="none");const r=[];return e.x_axis_scroll&&r.push({type:"inside",xAxisIndex:[0],filterMode:t,minSpan:1}),e.y_axis_scroll&&r.push({type:"inside",yAxisIndex:[0],filterMode:t,minSpan:1}),e.x_axis_slider&&r.push({type:"slider",xAxisIndex:[0],filterMode:t,bottom:"auto",top:0,height:15,moveHandleSize:0,showDataShadow:!1,minSpan:1}),r}function Gg({min:e,max:t}){if(e<=110)return Math.min(0,e);if(e<=200)return 100;const r=Qe.floor(Qe.log10(e)),a=Math.pow(10,r),o=Math.pow(10,r-1);return e/a<=2?b.round(e,-1*(r-1))-o:b.round(e,-1*r)-a}function Fg(e){return{Box:e("viz.boxplot.box"),Scatter:e("viz.boxplot.scatter"),Outlier:e("viz.boxplot.outlier")}}function Qg({config:e,data:t,variables:r,t:a}){const{x_axis:o,y_axis:l,reference_lines:i}=e,c=Sg(e,t),d=Ke(o.axisLabel.overflow.on_axis),u=Fg(a),p=Ag(e,c).map(f=>({...f,name:b.get(u,f.name,f.name)}));return{dataZoom:yn(e.dataZoom,"filter"),grid:Tg(e),dataset:c,legend:kg({config:e,seriesNames:u}),tooltip:Ng({config:e,seriesNames:u}),xAxis:[X.getXAxis({type:"category",name:o.name,nameGap:25,nameLocation:"center",nameTextStyle:{align:"center"},axisLabel:{...o.axisLabel,...d,formatter:Me(o.axisLabel.formatter)}})],yAxis:[X.getYAxis({name:l.name,minInterval:1,axisLabel:{formatter:function(f){return Y(f,l.label_formatter)}},min:Gg})],series:[...p,...Dg(i,r,t)]}}function jg({context:e,instance:t}){const{t:r}=m.useTranslation(),{value:a}=q(e.instanceData,"config"),{variables:o}=e,l=e.data,{width:i,height:c}=e.viewport,d=b.defaults({},a,mr),u=Pe({vizManager:e.vizManager,instance:t}),p=Ve(u.triggerManager,Po.id),f=Dt(l,d.x_axis.data_key),v=h.useCallback(D=>{const z=b.get(f,D.name,{error:"rowData is not found"});p.forEach(I=>{u.runInteraction(I.id,{...D,rowData:z})})},[f,p,u]),_=h.useRef(null),w=h.useCallback(()=>{var z;const D=(z=_.current)==null?void 0:z.getEchartsInstance();D&&fe(t,D.getOption())},[]),x=h.useMemo(()=>({click:v,finished:w}),[v,w]),T=h.useMemo(()=>Qg({config:d,data:l,variables:o,t:r}),[d,l,o,r]);return!a||!i||!c?null:n.jsx(ve,{width:i,height:c,children:n.jsx(he,{echarts:ce,option:T,ref:_,style:Kt(i,c),onEvents:x,notMerge:!0,theme:"merico-light"})})}function se({canSubmit:e,buttonRef:t}){const{t:r}=m.useTranslation();return n.jsxs(s.Group,{justify:"flex-start",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[n.jsx(s.Text,{size:"sm",children:r("viz.viz_config_banner")}),n.jsx(s.ActionIcon,{ref:t,type:"submit",mr:5,variant:"filled",color:"blue",disabled:!e,children:n.jsx(S.IconDeviceFloppy,{size:20})})]})}const Dr=h.forwardRef(({label:e,value:t,onChange:r,sx:a={}},o)=>{const{t:l,i18n:i}=m.useTranslation(),c=h.useMemo(()=>[{label:l("common.align.horizontal.left"),value:"left"},{label:l("common.align.horizontal.center"),value:"center"},{label:l("common.align.horizontal.right"),value:"right"}],[i.language]);return n.jsx(s.Select,{ref:o,label:e??l("common.align.horizontal.label"),data:c,value:t,onChange:Z(r),sx:a})}),Go=h.forwardRef(({label:e,value:t,onChange:r,sx:a={}},o)=>{const{t:l,i18n:i}=m.useTranslation(),c=h.useMemo(()=>[{label:l("common.align.vertical.top"),value:"top"},{label:l("common.align.vertical.center"),value:"center"},{label:l("common.align.vertical.bottom"),value:"bottom"}],[i.language]);return n.jsx(s.Select,{ref:o,label:e??l("common.align.vertical.label"),data:c,value:t,onChange:Z(r),sx:a})}),Fo=ht.createStyles(()=>({palette:{display:"flex",flexFlow:"row nowrap"},paletteItem:{".palette-value":{height:24,overflow:"visible",width:36},".palette-item":{width:"36px",height:36*.618,cursor:"pointer",transition:"transform 100ms ease-in-out","&:hover":{boxShadow:"0 0 0 2px var(--shadow-color)",borderRadius:2,transform:"scale(1.2)"}}}})),Wg=[{from:0,to:0},{from:100,to:100}];class Ug{constructor(){V(this,"steps",new Map);V(this,"interpolation");V(this,"onChange");F.makeAutoObservable(this,{steps:F.observable},{deep:!1}),F.reaction(()=>F.toJS(this.steps),()=>{this.notifyStepChange()})}setSteps(t){for(const r of t)this.steps.set(r.to,r.from)}notifyStepChange(){var t;(t=this.onChange)==null||t.call(this,Array.from(this.steps.entries()).map(([r,a])=>({to:r,from:a})).sort((r,a)=>r.to-a.to||r.from-a.from))}fromProps(t){t.steps.length<2?this.setSteps(Wg):this.setSteps(t.steps),this.interpolation=t.interpolation,this.onChange=t.onChange}changeStep(t,r){t==null?this.steps.delete(r):this.steps.set(r,t)}getStepFromValue(t){return this.steps.get(t)}}function Qo(e){if(typeof e=="number")return String(e)}function Kg(e){const{t}=m.useTranslation(),{onChange:r,color:a,index:o,value:l}=e,{classes:i}=Fo(),[c,d]=h.useState(Qo(l)),[u,{setTrue:p,setFalse:f}]=O.useBoolean(!1),v=o%2===1,_=v&&l!=null,w=!v&&l!=null,x=`map ${l} to color ${o}`,T=()=>{d(Qo(l)),f()},D=()=>{f(),r==null||r(Number(c))},z=()=>{f(),r==null||r(null)},I=Y(l??null,{output:"number",mantissa:10,trimMantissa:!0,average:!0,absolute:!1}),E=!c||Number.isNaN(Number(c));return n.jsxs("div",{"data-testid":`palette-item-${o}`,className:i.paletteItem,children:[n.jsx(s.Text,{title:x,style:{opacity:_?1:0},c:"dimmed",size:"sm",className:"palette-value--up palette-value",children:I}),n.jsxs(s.Popover,{width:240,trapFocus:!0,opened:u,onClose:f,zIndex:340,withinPortal:!0,children:[n.jsx(s.Popover.Target,{children:n.jsx("div",{"data-testid":"palette-item-target",className:"palette-item",onClick:p,style:{"--shadow-color":Ne(a).alpha(.5).hex(),backgroundColor:a}})}),n.jsxs(s.Popover.Dropdown,{children:[n.jsx(s.Tooltip,{withinPortal:!0,zIndex:340,label:t("common.actions.close"),children:n.jsx(s.CloseButton,{"data-testid":"palette-item-cancel",size:"sm",color:"gray",onClick:T,style:{position:"absolute",top:"0.5em",right:"0.8em"}})}),n.jsxs(s.Stack,{children:[n.jsx(s.TextInput,{size:"xs",label:t("style.color.interpolation.palette.mapping.value_input_label"),value:c,onChange:A=>{const U=A.currentTarget.value;d(U)},error:c&&E}),n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Button,{variant:"light",color:"red",size:"xs",onClick:z,leftSection:n.jsx(S.IconTrash,{size:16}),children:t("common.actions.delete")}),n.jsx(s.Button,{color:"green",leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),"data-testid":"palette-item-ok",size:"xs",onClick:D,disabled:E,children:t("common.actions.save")})]})]})]})]}),n.jsx(s.Text,{title:x,style:{opacity:w?1:0},c:"dimmed",size:"sm",className:"palette-value--bottom palette-value",children:I})]})}const Yg=k.observer(({model:e})=>{const{classes:t}=Fo(),r=b.range(0,13,1).map(a=>100/12*a).map(a=>[e.interpolation.getColor(a),a]);return n.jsx("div",{className:t.palette,children:r.map(([a,o],l)=>n.jsx(Kg,{index:l,color:a,value:e.getStepFromValue(o),onChange:i=>e.changeStep(i,o)},a))})}),Xg=k.observer(function(t){const r=O.useCreation(()=>new Ug,[]);return h.useEffect(()=>{r.fromProps(t)}),r.interpolation==null?null:n.jsx(Yg,{model:r})}),Zg=e=>{const{t,i18n:r}=m.useTranslation(),{value:a,onChange:o,colorManager:l}=e,i=l.getColorInterpolations(),[c,d]=h.useState(a),u=l.decodeInterpolation(c.interpolation)||i[0],[p,{setTrue:f,setFalse:v}]=O.useBoolean(),_=h.useMemo(()=>{const z=b.groupBy(i,"category");return Object.entries(z).map(([I,E])=>({group:t(`style.color.interpolation.palette.category.${I}`),items:E.map(A=>({label:t(A.displayName),value:l.encodeColor(A)}))}))},[r.language]);function w(z){z&&d(I=>({...I,interpolation:z}))}const x=()=>{v(),o==null||o(F.toJS(c))};function T(z){d(I=>({...I,steps:z}))}const D=()=>{v(),d(a)};return n.jsxs(n.Fragment,{children:[n.jsx(s.Button,{variant:"outline",onClick:f,children:t(u==null?void 0:u.displayName)}),n.jsx(s.Modal,{size:508,title:t("style.color.interpolation.setup"),opened:p,onClose:v,zIndex:320,children:p&&n.jsxs(s.Stack,{"data-testid":"color-interpolation-modal",children:[n.jsx(s.Select,{label:t("style.color.interpolation.palette.label"),value:c.interpolation,data:_,onChange:w,comboboxProps:{withinPortal:!0,zIndex:340},maxDropdownHeight:500}),n.jsx(Xg,{steps:c.steps,interpolation:u,onChange:T}),n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Button,{onClick:D,variant:"subtle",children:t("common.actions.cancel")}),n.jsx(s.Button,{color:"green",leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),onClick:x,children:t("common.actions.save")})]})]})})]})},Jg=h.forwardRef(({label:e,value:t,onChange:r,sx:a={}},o)=>{const{t:l,i18n:i}=m.useTranslation(),c=h.useMemo(()=>[{label:l("style.color.type.static"),value:"static"},{label:l("style.color.type.interpolation"),value:"interpolation"},{label:l("style.color.type.none"),value:"none"}],[i.language]);return n.jsx(s.Select,{ref:o,label:e??l("style.color.type.label"),data:c,value:t,onChange:Z(r),sx:a})}),Hg=h.forwardRef(({label:e,value:t,onChange:r,sx:a={}},o)=>{const{t:l,i18n:i}=m.useTranslation(),c=h.useMemo(()=>[{label:l("style.flex.justify_content.left"),value:"left"},{label:l("style.flex.justify_content.center"),value:"center"},{label:l("style.flex.justify_content.right"),value:"right"},{label:l("style.flex.justify_content.space_between"),value:"space-between"},{label:l("style.flex.justify_content.space_around"),value:"space-around"},{label:l("style.flex.justify_content.space_evenly"),value:"space-evenly"}],[i.language]);return n.jsx(s.Select,{ref:o,label:e??l("style.flex.justify_content.label"),data:c,value:t,onChange:Z(r),sx:a})}),Rg=h.forwardRef(({label:e,value:t,onChange:r,sx:a={}},o)=>{const{t:l,i18n:i}=m.useTranslation(),c=h.useMemo(()=>[{label:l("style.flex.align_items.start"),value:"start"},{label:l("style.flex.align_items.center"),value:"center"},{label:l("style.flex.align_items.end"),value:"end"},{label:l("style.flex.align_items.stretch"),value:"stretch"}],[i.language]);return n.jsx(s.Select,{ref:o,label:e??l("style.flex.align_items.label"),data:c,value:t,onChange:Z(r),sx:a})}),ef=({value:e,index:t,children:r})=>{const[a,{setTrue:o,setFalse:l}]=O.useBoolean(!1),{ref:i,handleRef:c}=rn.useSortable({id:e,index:t});return n.jsx(s.Tabs.Tab,{ref:i,value:e,leftSection:n.jsx(S.IconGripHorizontal,{size:14,color:a||t===0?"rgb(34, 139, 230)":"transparent"}),onMouseEnter:o,onMouseLeave:l,children:r})},tf=({fieldArray:e,add:t,addButtonText:r,renderTabName:a,controlledFields:o})=>{const l=i=>{const{source:c,target:d}=i.operation,u=o.findIndex(f=>f.id===c.id),p=d.index;e.move(u,p)};return n.jsxs(s.Tabs.List,{children:[n.jsx(nn.DragDropProvider,{onDragEnd:l,children:o.map((i,c)=>n.jsx(ef,{value:i.id,index:c,children:a(i,c)},i.id))}),n.jsx(s.Tabs.Tab,{onClick:t,value:"add",children:n.jsx(s.Tooltip,{label:r,children:n.jsx(s.Center,{children:n.jsx(S.IconPlus,{size:18,color:"#228be6"})})})})]})},nf={tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px"}},R=({control:e,watch:t,name:r,getItem:a,children:o,addButtonText:l,deleteButtonText:i,renderTabName:c,deleteDisalbed:d})=>{var E;const u=y.useFieldArray({control:e,name:r}),{fields:p,append:f,remove:v}=u,_=t(r),w=p.map((A,U)=>({...A,..._[U]})),x=((E=b.last(w))==null?void 0:E.id)??null,[T,D]=h.useState(x),z=A=>{A!=="add"&&D(A)};h.useEffect(()=>{D(A=>x===A?A:x)},[x]);const I=()=>{const A=a();u.append(A),D(A.id)};return n.jsxs(s.Tabs,{value:T,onChange:z,styles:nf,children:[n.jsx(tf,{fieldArray:u,add:I,addButtonText:l,renderTabName:c,controlledFields:w}),w.map((A,U)=>n.jsx(s.Tabs.Panel,{value:A.id,children:n.jsxs(s.Stack,{children:[o({field:A,index:U}),n.jsx(s.Divider,{mb:-10,mt:10,variant:"dashed"}),n.jsx(s.Button,{leftSection:n.jsx(S.IconTrash,{size:16}),color:"red",variant:"light",onClick:()=>v(U),sx:{top:15,right:5},disabled:d==null?void 0:d({field:A,index:U,fields:w}),children:i})]})},A.id))]})},vn=h.forwardRef(({value:e,onChange:t},r)=>{const{t:a}=m.useTranslation(),o=l=>i=>{t({...e,[l]:i})};return n.jsxs(s.Stack,{children:[n.jsx(s.Divider,{variant:"dashed",label:a("chart.zooming.scroll.label"),labelPosition:"center"}),n.jsxs(s.Group,{children:[n.jsx(s.Box,{sx:{flexGrow:1},children:n.jsx(s.Switch,{label:a("chart.zooming.scroll.x_axis"),checked:e.x_axis_scroll,onChange:l=>o("x_axis_scroll")(l.currentTarget.checked)})}),n.jsx(s.Box,{sx:{flexGrow:1},children:n.jsx(s.Switch,{label:a("chart.zooming.scroll.y_axis"),checked:e.y_axis_scroll,onChange:l=>o("y_axis_scroll")(l.currentTarget.checked)})})]}),n.jsx(s.Divider,{variant:"dashed",label:a("chart.zooming.slider.label"),labelPosition:"center"}),n.jsxs(s.Group,{children:[n.jsx(s.Box,{sx:{flexGrow:1},children:n.jsx(s.Switch,{label:a("chart.zooming.slider.x_axis"),checked:e.x_axis_slider,onChange:l=>o("x_axis_slider")(l.currentTarget.checked)})}),n.jsx(s.Tooltip,{label:a("chart.zooming.slider.y_axis_disabled"),children:n.jsx(s.Box,{sx:{flexGrow:1},children:n.jsx(s.Switch,{label:a("chart.zooming.slider.y_axis"),disabled:!e.y_axis_slider,checked:e.y_axis_slider,onChange:l=>o("y_axis_slider")(l.currentTarget.checked)})})})]})]})}),bt=h.forwardRef(({label:e,value:t,onChange:r,sx:a={},disabled:o},l)=>{const{t:i,i18n:c}=m.useTranslation(),d=h.useMemo(()=>[{label:i("chart.orientation.horizontal"),value:"horizontal"},{label:i("chart.orientation.vertical"),value:"vertical"}],[c.language]);return n.jsx(s.Select,{ref:l,label:e??i("chart.orientation.label"),data:d,value:t,onChange:Z(r),sx:a,disabled:o})}),rf=({control:e,watch:t})=>{const{t:r}=m.useTranslation(),a=t("legend"),o=(l,i)=>{const c={...a,orient:l};l==="horizontal"?(c.top="0",c.left="auto",c.right="10",c.bottom="auto"):(c.top="10",c.left="auto",c.right="0",c.bottom="auto"),i(c)};return n.jsxs(s.Stack,{children:[n.jsx(s.Group,{grow:!0,wrap:"nowrap",mt:20,children:n.jsx(y.Controller,{name:"legend.show",control:e,render:({field:l})=>n.jsx(s.Switch,{label:r("chart.legend.show_legend"),sx:{flex:1},checked:l.value,onChange:i=>l.onChange(i.currentTarget.checked)})})}),n.jsx(s.Group,{children:n.jsx(y.Controller,{name:"legend",control:e,render:({field:l})=>n.jsx(bt,{sx:{flex:1},value:l.value.orient,onChange:i=>{o(i,l.onChange)},disabled:!a.show})})})]})};function af({control:e,index:t,variableOptions:r}){const{t:a}=m.useTranslation();return n.jsxs(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(y.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:o})=>n.jsx(s.TextInput,{label:a("common.name"),placeholder:a("chart.reference_line.name_placeholder"),required:!0,sx:{flex:1},...o})}),n.jsx(y.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:o})=>n.jsx(s.Select,{label:a("common.value"),required:!0,data:r,sx:{flex:1},...o})})]}),n.jsx(y.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:o})=>n.jsx(s.TextInput,{label:a("chart.content_template.label"),placeholder:a("chart.content_template.placeholder"),required:!0,sx:{flex:1},...o})})]})}function sf({control:e,watch:t,variables:r}){const{t:a}=m.useTranslation(),o=()=>({name:"",template:"",variable_key:""}),l=h.useMemo(()=>r.map(c=>({label:c.name,value:c.name})),[r]),i=(c,d)=>{const u=c.name.trim();return u||d+1};return n.jsx(R,{control:e,watch:t,name:"reference_lines",getItem:o,addButtonText:a("chart.reference_line.add"),deleteButtonText:a("chart.reference_line.delete"),renderTabName:i,children:({field:c,index:d})=>n.jsx(af,{control:e,index:d,variableOptions:l})})}const of=({control:e,index:t})=>{const{t:r}=m.useTranslation();return n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(y.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),required:!0,sx:{flex:1},...a})}),n.jsx(y.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:a})=>n.jsx(L,{label:r("chart.data_field"),required:!0,sx:{flex:1},...a})})]}),n.jsx(y.Controller,{name:`tooltip.metrics.${t}.unit`,control:e,render:({field:a})=>n.jsx(ue,{hiddenFileds:["show_in_legend"],...a})})]})},lf=({control:e,watch:t})=>{const{t:r}=m.useTranslation(),a=()=>({id:Date.now().toString(),data_key:"",name:"",unit:K()}),o=(l,i)=>{const c=l.name.trim();return c||i+1};return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{gap:2,sx:{cursor:"default",userSelect:"none"},children:[n.jsx(S.IconInfoCircle,{size:14,color:"#888"}),n.jsx(s.Text,{size:"14px",c:"#888",children:r("chart.tooltip.additional_metrics.description")})]}),n.jsx(R,{control:e,watch:t,name:"tooltip.metrics",getItem:a,addButtonText:r("chart.tooltip.additional_metrics.add"),deleteButtonText:r("chart.tooltip.additional_metrics.delete"),renderTabName:o,children:({field:l,index:i})=>n.jsx(of,{control:e,index:i})})]})};function cf({control:e,watch:t}){return n.jsx(s.Stack,{children:n.jsx(lf,{control:e,watch:t})})}const ot=h.forwardRef(({label:e,value:t,onChange:r,sx:a={}},o)=>{const{t:l}=m.useTranslation();return n.jsx(s.NumberInput,{ref:o,label:e??l("chart.rotate"),hideControls:!0,min:-90,max:90,rightSection:n.jsx(s.Text,{size:"xs",c:"dimmed",children:l("chart.degree")}),sx:a,styles:{section:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},value:t,onChange:i=>{typeof i!="string"&&r(i)}})}),df=({control:e,watch:t})=>{const{t:r}=m.useTranslation();return t(["x_axis"]),n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(y.Controller,{name:"x_axis.name",control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("chart.x_axis.x_axis_name"),sx:{flex:1},...a})}),n.jsx(y.Controller,{name:"x_axis.data_key",control:e,render:({field:a})=>n.jsx(L,{label:r("chart.x_axis.x_axis_data_field"),required:!0,sx:{flex:1},...a})})]}),n.jsx(s.Divider,{mb:-15,label:r("chart.axis.tick_label"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(y.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:a})=>n.jsx(ot,{sx:{width:"48%"},...a})}),n.jsx(y.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:a})=>n.jsx(et,{...a})})]}),n.jsx(y.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:a})=>n.jsx(tt,{...a})})]})},zr={root:{alignSelf:"flex-end"},body:{alignItems:"center"},label:{display:"block"}},uf=["123456789","1234","1234.56789","1.234","0.123456789","-0.123456789"];function pf({format:e}){const{t}=m.useTranslation(),[r,{toggle:a}]=te.useDisclosure(!1);return n.jsxs(s.Box,{children:[n.jsx(s.Button,{variant:"subtle",w:"100%",size:"compact-sm",onClick:a,leftSection:r?n.jsx(S.IconChevronUp,{size:14}):n.jsx(S.IconChevronDown,{size:14}),children:t(r?"numbro.format.preview.close":"numbro.format.preview.open")}),n.jsx(s.Collapse,{in:r,children:r&&n.jsxs(s.Table,{highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:t("numbro.format.preview.input")}),n.jsx(s.Table.Th,{children:t("numbro.format.preview.output")})]})}),n.jsx(s.Table.Tbody,{children:uf.map(o=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:o}),n.jsx(s.Table.Td,{children:n.jsx(ne,{children:Y(o,e)})})]},o))})]})})]})}function hf({value:e,onChange:t},r){const{t:a}=m.useTranslation(),o=u=>{t({...e,output:u,absolute:!1,average:!1,trimMantissa:!1,mantissa:0})},l=u=>{if(typeof u=="string")return;const p=u===0?!1:e.trimMantissa;t({...e,mantissa:u,trimMantissa:p})},i=u=>{t({...e,trimMantissa:u.currentTarget.checked})},c=u=>{t({...e,average:u.currentTarget.checked})},d=u=>{const p={...e,absolute:u.currentTarget.checked};t(p)};return n.jsxs(s.Stack,{ref:r,children:[n.jsxs(s.Group,{grow:!0,children:[n.jsx(s.Select,{label:a("numbro.format.label"),data:[{label:"1234",value:"number"},{label:"99%",value:"percent"}],value:e.output,onChange:Z(o),sx:{flexGrow:1}}),n.jsx(s.Switch,{label:n.jsxs(s.Stack,{gap:0,children:[n.jsx(s.Text,{size:"sm",children:a("numbro.format.absolute")}),n.jsx(s.Text,{size:"12px",c:"gray",children:a("numbro.format.absolute_description")})]}),checked:e.absolute,onChange:d,sx:{flexGrow:1},styles:zr}),n.jsx(s.Switch,{label:n.jsxs(s.Stack,{gap:0,children:[n.jsx(s.Text,{size:"sm",children:a("numbro.format.abbreviation")}),n.jsx(s.Text,{size:"12px",c:"gray",children:a("numbro.format.abbreviation_description")})]}),checked:e.average,onChange:c,disabled:e.output!=="number",sx:{flexGrow:1},styles:zr})]}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(s.NumberInput,{label:a("numbro.format.mantissa"),defaultValue:0,min:0,step:1,max:4,value:e.mantissa,onChange:l}),n.jsx(s.Switch,{label:n.jsxs(s.Stack,{gap:0,children:[n.jsx(s.Text,{size:"sm",children:a("numbro.format.trim_mantissa")}),n.jsx(s.Text,{size:"12px",c:"gray",children:a("numbro.format.trim_mantissa_description")})]}),checked:e.trimMantissa,onChange:i,disabled:e.mantissa===0,styles:zr}),n.jsx(s.Box,{})]}),n.jsx(pf,{format:e})]})}const Ye=h.forwardRef(hf),gf=({control:e,watch:t})=>{const{t:r}=m.useTranslation();return t(["y_axis"]),n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(y.Controller,{name:"y_axis.name",control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("chart.y_axis.y_axis_name"),sx:{flex:1},...a})}),n.jsx(y.Controller,{name:"y_axis.data_key",control:e,render:({field:a})=>n.jsx(L,{label:r("chart.y_axis.y_axis_data_field"),required:!0,sx:{flex:1},...a})})]}),n.jsx(y.Controller,{name:"y_axis.unit",control:e,render:({field:a})=>n.jsx(ue,{hiddenFileds:["show_in_legend"],...a})}),n.jsxs(s.Stack,{children:[n.jsx(s.Divider,{mt:10,mb:-15,variant:"dashed",label:r("chart.axis.section_title.label_format"),labelPosition:"center"}),n.jsx(y.Controller,{name:"y_axis.label_formatter",control:e,render:({field:a})=>n.jsx(Ye,{...a})})]})]})};function ff({context:e}){const{t}=m.useTranslation(),{value:r,set:a}=q(e.instanceData,"config"),{variables:o}=e,l=h.useMemo(()=>b.defaults({},r,mr),[r]),{control:i,handleSubmit:c,watch:d,formState:u,reset:p}=y.useForm({defaultValues:l});return h.useEffect(()=>{p(l)},[l]),d(["x_axis","y_axis","reference_lines","color","dataZoom"]),n.jsx(s.Stack,{gap:"xs",children:n.jsxs("form",{onSubmit:c(a),children:[n.jsx(se,{canSubmit:u.isDirty}),n.jsxs(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"X Axis",children:t("chart.x_axis.label")}),n.jsx(s.Tabs.Tab,{value:"Y Axis",children:t("chart.y_axis.label")}),n.jsx(s.Tabs.Tab,{value:"Legend",children:t("chart.legend.label")}),n.jsx(s.Tabs.Tab,{value:"Tooltip",children:t("chart.tooltip.label")}),n.jsx(s.Tabs.Tab,{value:"Style",children:t("chart.style.label")}),n.jsx(s.Tabs.Tab,{value:"Reference Lines",children:t("chart.reference_line.labels")}),n.jsx(s.Tabs.Tab,{value:"Zooming",children:t("chart.zooming.label")})]}),n.jsx(s.Tabs.Panel,{value:"X Axis",children:n.jsx(df,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Y Axis",children:n.jsx(gf,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Legend",children:n.jsx(rf,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Tooltip",children:n.jsx(cf,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Style",children:n.jsx(s.SimpleGrid,{cols:2,children:n.jsx(y.Controller,{name:"color",control:i,render:({field:f})=>n.jsx(ye,{label:t("chart.color.label"),...f})})})}),n.jsx(s.Tabs.Panel,{value:"Reference Lines",children:n.jsx(sf,{variables:o,control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Zooming",children:n.jsx(y.Controller,{name:"dataZoom",control:i,render:({field:f})=>n.jsx(vn,{...f})})})]})]})})}function bf(e){return b.omit(e,"variables")}function yf(e){const{label_formatter:t=de,...r}=e.y_axis;return{...e,y_axis:{...r,label_formatter:t}}}function vf(e){const t={rotate:0,formatter:_e()},{axisLabel:r=t,...a}=e.x_axis;return{...e,x_axis:{...a,axisLabel:r}}}function _f(e){const t={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return b.defaultsDeep(t,e)}function mf(e){delete e.config;const{x_axis:t,tooltip:r}=e.x_axis.axisLabel.overflow,a={x_axis:{axisLabel:{overflow:{on_axis:t,in_tooltip:r}}}};return b.defaultsDeep(a,e)}function wf(e){const t={tooltip:{metrics:[]}};return b.defaultsDeep(t,e)}function xf(e,{panelModel:t}){try{const r=t.queryIDs[0];if(!r)throw new Error("cannot migrate when queryID is empty");const a=d=>d&&`${r}.${d}`,{x_axis:o,y_axis:l,tooltip:i,...c}=e;return{...c,x_axis:{...o,data_key:a(o.data_key)},y_axis:{...l,data_key:a(l.data_key)},tooltip:{...i,metrics:i.metrics.map(d=>({...d,data_key:a(d.data_key)}))}}}catch(r){throw console.error("[Migration failed]",r),r}}function Cf(e){const t={legend:{show:!0,top:"0",right:"10",left:"auto",bottom:"auto",orient:"horizontal",type:"scroll"}};return b.defaultsDeep(t,e)}function Sf(e){const{dataZoom:t,...r}=e;return{...r,dataZoom:t??Vo()}}function Tf(e){const t=e.tooltip.metrics;return{...e,tooltip:{...e.tooltip,metrics:t.map(r=>({...r,unit:r.unit??K()}))}}}function kf(e){const{y_axis:t}=e;return{...e,y_axis:{...t,unit:t.unit??K()}}}class Df extends J{constructor(){super(...arguments);V(this,"VERSION",12)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,(r,{panelModel:a})=>{const{config:o}=r;return(o.variables||[]).forEach(i=>{a.variables.find(c=>c.name===i.name)||a.addVariable(i)}),{...r,version:2,config:bf(o)}}),this.version(3,r=>{const{config:a}=r;return{...r,version:3,config:yf(a)}}),this.version(4,r=>{const{config:a}=r;return{...r,version:4,config:vf(a)}}),this.version(5,r=>{const{config:a}=r;return{...r,version:5,config:_f(a)}}),this.version(6,r=>{const{config:a}=r;return{...r,version:6,config:mf(a)}}),this.version(7,r=>{const{config:a}=r;return{...r,version:7,config:wf(a)}}),this.version(8,(r,a)=>{const{config:o}=r;return{...r,version:8,config:xf(o,a)}}),this.version(9,r=>{const{config:a}=r;return{...r,version:9,config:Cf(a)}}),this.version(10,r=>{const{config:a}=r;return{...r,version:10,config:Sf(a)}}),this.version(11,r=>{const{config:a}=r;return{...r,version:11,config:Tf(a)}}),this.version(12,r=>{const{config:a}=r;return{...r,version:12,config:kf(a)}})}}const zf={displayName:"viz.boxplot.viz_name",displayGroup:"chart.groups.echarts_based_charts",migrator:new Df,name:"boxplot",viewRender:jg,configRender:ff,createConfig(){return{version:12,config:b.cloneDeep(mr)}},triggers:[Po],translation:wh},jo={id:"builtin:button:click-button",displayName:"viz.button.click.label",nameRender:If,configRender:Mf,payload:[]};function Mf(e){return n.jsx(n.Fragment,{})}function If(e){const{t}=m.useTranslation();return n.jsx(s.Text,{size:"sm",children:t("viz.button.click.label")})}const Mr={content:"Button",variant:"filled",color:"blue",size:"xs",compact:!1,horizontal_align:"left",vertical_align:"center"},Vf={left:"flex-start",center:"center",right:"flex-end"},Pf={top:"flex-start",center:"center",bottom:"flex-end"},$f=k.observer(({context:e,instance:t})=>{const r=Pe({vizManager:e.vizManager,instance:t}),a=Ve(r.triggerManager,jo.id),o=H(),{value:l}=q(e.instanceData,"config"),i=h.useMemo(()=>b.defaultsDeep({},l,Mr),[l]),{content:c,horizontal_align:d,vertical_align:u,compact:p,size:f,...v}=i,{width:_,height:w}=e.viewport,x=o.payloadForSQL,T=()=>{a.forEach(z=>{r.runInteraction(z.id,{})})},D=p?`compact-${f}`:f;return n.jsx(s.Center,{sx:{width:_,height:w,justifyContent:Vf[d],alignItems:Pf[u]},children:n.jsx(s.Button,{size:D,...v,onClick:T,children:b.template(c)(x)})})}),Af=({value:e,onChange:t,label:r})=>{const a=s.useMantineTheme(),o=h.useCallback(i=>()=>t(i),[t]),l=i=>e===i;return n.jsxs(s.Stack,{gap:2,children:[n.jsx(s.Text,{size:"14px",fw:500,children:r}),n.jsx(s.Group,{justify:"flex-start",gap:"xs",children:Object.keys(a.colors).map(i=>{const c=a.colors[i][6];return n.jsx(s.ColorSwatch,{color:c,onClick:o(i),radius:4,size:26,sx:{cursor:"pointer"},children:l(i)&&n.jsx(s.CheckIcon,{width:10,color:"white"})},i)})})]})},Ef=["xs","sm","md","lg","xl"],Ir=h.forwardRef(({label:e,value:t,onChange:r,sx:a,disabled:o},l)=>{const{t:i,i18n:c}=m.useTranslation(),d=h.useMemo(()=>Ef.map(u=>({label:i(`style.size.${u}`),value:u})),[c.language]);return n.jsx(s.Select,{ref:l,data:d,label:e,value:t,onChange:Z(r),sx:a,disabled:!0})}),Bf=[{label:"Filled",value:"filled"},{label:"Outline",value:"outline"},{label:"Light",value:"light"},{label:"White",value:"white"},{label:"Default",value:"default"},{label:"Subtle",value:"subtle"},{label:"Gradient",value:"gradient",disabled:!0}];function qf({context:e}){const{value:t,set:r}=q(e.instanceData,"config"),a=h.useMemo(()=>b.defaultsDeep({},t,Mr),[t]),o=a;h.useEffect(()=>{!b.isEqual(a,o)&&(console.log("config malformed, resetting to defaults",a,o),r(o))},[a,o]);const{control:l,handleSubmit:i,watch:c,formState:d,reset:u}=y.useForm({defaultValues:o});return h.useEffect(()=>{u(o)},[o]),c(["content","variant","color","size","compact","horizontal_align","vertical_align"]),n.jsxs("form",{onSubmit:i(r),children:[n.jsx(se,{canSubmit:d.isDirty}),n.jsxs(s.Stack,{children:[n.jsx(y.Controller,{control:l,name:"content",render:({field:p})=>n.jsx(s.TextInput,{label:"Content Template",description:"Filter values & context entries are supported",...p,required:!0})}),n.jsx(s.Divider,{mt:"xs",mb:0,label:"Styles",labelPosition:"center",variant:"dashed"}),n.jsxs(s.SimpleGrid,{cols:2,children:[n.jsx(y.Controller,{control:l,name:"variant",render:({field:p})=>n.jsx(s.Select,{label:"Variant",data:Bf,...p})}),n.jsx(y.Controller,{control:l,name:"color",render:({field:p})=>n.jsx(Af,{label:"Theme",...p})})]}),n.jsxs(s.SimpleGrid,{cols:2,children:[n.jsx(y.Controller,{control:l,name:"size",render:({field:p})=>n.jsx(Ir,{label:"Size",...p})}),n.jsx(y.Controller,{control:l,name:"compact",render:({field:p})=>n.jsx(s.Checkbox,{label:"Compact",checked:p.value,onChange:f=>p.onChange(f.currentTarget.checked),mt:26})})]}),n.jsxs(s.SimpleGrid,{cols:2,children:[n.jsx(y.Controller,{control:l,name:"horizontal_align",render:({field:p})=>n.jsx(Dr,{...p})}),n.jsx(y.Controller,{control:l,name:"vertical_align",render:({field:p})=>n.jsx(Go,{...p})})]})]})]})}const Lf=[{lang:"en",resources:{button:{viz_name:"Button",click:{label:"Click this button"}}}},{lang:"zh",resources:{button:{viz_name:"按钮",click:{label:"点击此按钮"}}}}];class Of extends J{constructor(){super(...arguments);V(this,"VERSION",2)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,r=>{const{horizontal_align:a="left",vertical_align:o="center",...l}=r.config;return{...r,version:2,config:{...l,horizontal_align:a,vertical_align:o}}})}}const Nf={displayName:"viz.button.viz_name",displayGroup:"chart.groups.others",migrator:new Of,name:"button",viewRender:$f,configRender:qf,createConfig(){return{version:2,config:b.cloneDeep(Mr)}},triggers:[jo],translation:Lf},_n=({label:e,field:t})=>{const{t:r}=m.useTranslation();return n.jsx(s.ColorInput,{label:e,placeholder:r("chart.visual_map.skip_range.follow_visual_map"),size:"xs",popoverProps:{withinPortal:!0,zIndex:340},rightSection:t.value?n.jsx(s.CloseButton,{size:"sm",onClick:()=>{t.onChange("")}}):null,...t})},Gf=({form:e})=>{const{t}=m.useTranslation();return n.jsxs(s.Stack,{children:[n.jsx(y.Controller,{control:e.control,name:"visualMap.skipRange.lt_min",render:({field:r})=>n.jsx(_n,{field:r,label:t("chart.visual_map.skip_range.lt_min")})}),n.jsx(y.Controller,{control:e.control,name:"visualMap.skipRange.min",render:({field:r})=>n.jsx(_n,{field:r,label:t("chart.visual_map.skip_range.min")})}),n.jsx(y.Controller,{control:e.control,name:"visualMap.skipRange.max",render:({field:r})=>n.jsx(_n,{field:r,label:t("chart.visual_map.skip_range.max")})}),n.jsx(y.Controller,{control:e.control,name:"visualMap.skipRange.gt_max",render:({field:r})=>n.jsx(_n,{field:r,label:t("chart.visual_map.skip_range.gt_max")})})]})},Ff=({form:e})=>{const{t,i18n:r}=m.useTranslation(),a=e.control,o=e.watch("visualMap"),{type:l,orient:i}=o,c=i==="horizontal",d=u=>p=>{typeof p!="string"&&u(p)};return l!=="continuous"?null:n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,children:[n.jsx(y.Controller,{name:"visualMap.text.1",control:a,render:({field:u})=>n.jsx(s.TextInput,{label:t("chart.visual_map.min_text"),...u})}),n.jsx(y.Controller,{name:"visualMap.text.0",control:a,render:({field:u})=>n.jsx(s.TextInput,{label:t("chart.visual_map.max_text"),...u})})]}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(y.Controller,{name:"visualMap.orient",control:a,render:({field:u})=>n.jsx(bt,{sx:{flex:1},...u})}),n.jsx(y.Controller,{name:"visualMap.calculable",control:a,render:({field:u})=>n.jsx(s.Checkbox,{label:t("chart.visual_map.calculable"),checked:u.value,onChange:p=>u.onChange(p.currentTarget.checked),styles:{root:{transform:"translateY(12px)"}}})})]}),n.jsxs(s.Group,{grow:!0,styles:{root:{flexDirection:c?"row-reverse":"row"}},children:[n.jsx(y.Controller,{name:"visualMap.itemWidth",control:a,render:({field:u})=>n.jsx(s.NumberInput,{label:t(c?"chart.visual_map.bar_height":"chart.visual_map.bar_width"),...u,onChange:d(u.onChange)})}),n.jsx(y.Controller,{name:"visualMap.itemHeight",control:a,render:({field:u})=>n.jsx(s.NumberInput,{label:t(c?"chart.visual_map.bar_width":"chart.visual_map.bar_height"),...u,onChange:d(u.onChange)})})]}),n.jsx(y.Controller,{name:"visualMap.inRange.color",control:a,render:({field:u})=>n.jsx(uo,{...u})}),n.jsx(Gf,{form:e})]})},Qf=({visualMap:e})=>{const{orient:t,itemWidth:r,itemHeight:a}=e,l=t==="horizontal"?r:a,{panel:i}=ae(),c=un(e,i.variableValueMap);return n.jsx(ne,{children:n.jsx(he,{echarts:ce,option:{visualMap:c},style:{width:"100%",height:`${l+40}px`},notMerge:!0,theme:"merico-light"})})},Wo={lower:[{label:"<",value:"gt"},{label:"≤",value:"gte"}],upper:[{label:">",value:"lt"},{label:"≥",value:"lte"}]},Uo={gt:"(",gte:"[",lt:")",lte:"]"},Ko=(e,t)=>e===""?t:Number.isNaN(Number(e))?"INVALID VALUE":e,jf=({form:e,index:t})=>{const{t:r}=m.useTranslation(),{control:a,watch:o}=e,l=o(`visualMap.pieces.${t}`),{lower:i,upper:c}=l,d=[Uo[i.symbol],Ko(i.value,r("chart.visual_map.min_value")),",",Ko(c.value,r("chart.visual_map.max_value")),Uo[c.symbol]].join(""),[u,p]=h.useState(!1);return n.jsx(s.Group,{wrap:"nowrap",children:n.jsxs(s.Popover,{width:400,position:"bottom",withArrow:!0,shadow:"md",opened:u,onChange:p,withinPortal:!0,zIndex:340,children:[n.jsx(s.Popover.Target,{children:n.jsx(s.Button,{variant:"subtle",size:"compact-sm",px:0,onClick:()=>p(f=>!f),fw:"normal",ff:"monospace",children:d})}),n.jsx(s.Popover.Dropdown,{children:n.jsxs(s.Group,{wrap:"nowrap",gap:8,children:[n.jsx(y.Controller,{name:`visualMap.pieces.${t}.lower.value`,control:a,render:({field:f})=>n.jsx(s.TextInput,{...f,placeholder:r("chart.visual_map.min_value"),size:"xs",onChange:v=>f.onChange(v.currentTarget.value),error:f.value!==""&&Number.isNaN(Number(f.value))})}),n.jsx(y.Controller,{name:`visualMap.pieces.${t}.lower.symbol`,control:a,render:({field:f})=>n.jsx(s.Select,{size:"xs",data:Wo.lower,...f,onChange:Z(v=>f.onChange(v))})}),n.jsx(s.Text,{c:"dimmed",size:"sm",sx:{userSelect:"none",cursor:"default"},children:r("common.value").toLowerCase()}),n.jsx(y.Controller,{name:`visualMap.pieces.${t}.upper.symbol`,control:a,render:({field:f})=>n.jsx(s.Select,{size:"xs",data:Wo.upper,...f,onChange:Z(v=>f.onChange(v))})}),n.jsx(y.Controller,{name:`visualMap.pieces.${t}.upper.value`,control:a,render:({field:f})=>n.jsx(s.TextInput,{...f,size:"xs",placeholder:r("chart.visual_map.max_value"),onChange:v=>f.onChange(v.currentTarget.value),error:f.value!==""&&Number.isNaN(Number(f.value))})})]})})]})})},Wf=({form:e,index:t,remove:r})=>{const{control:a}=e,{t:o}=m.useTranslation();return n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:(t+1).toString()}),n.jsx(s.Table.Td,{children:n.jsx(jf,{form:e,index:t})}),n.jsx(s.Table.Td,{children:n.jsx(y.Controller,{name:`visualMap.pieces.${t}.label`,control:a,render:({field:l})=>n.jsx(s.TextInput,{size:"xs",placeholder:"",...l,onChange:i=>l.onChange(i.currentTarget.value)})})}),n.jsx(s.Table.Td,{children:n.jsx(y.Controller,{name:`visualMap.pieces.${t}.color`,control:a,render:({field:l})=>n.jsx(s.ColorInput,{label:o(""),placeholder:o("chart.color.label"),size:"xs",popoverProps:{withinPortal:!0,zIndex:340},rightSection:l.value?n.jsx(s.CloseButton,{size:"sm",onClick:()=>{l.onChange("")}}):null,...l})})}),n.jsx(s.Table.Td,{children:n.jsx(s.CloseButton,{size:"sm",onClick:()=>r(t)})})]})},Uf=({form:e})=>{const{t,i18n:r}=m.useTranslation(),{fields:a,append:o,remove:l}=y.useFieldArray({control:e.control,name:"visualMap.pieces"}),i=e.watch("visualMap.pieces"),c=a.map((u,p)=>({...u,...i[p]})),d=()=>{o(co())};return n.jsx(s.Stack,{children:n.jsxs(s.Table,{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:t("chart.visual_map.piecewise.interval")}),n.jsx(s.Table.Th,{children:t("chart.visual_map.piecewise.piece_label")}),n.jsx(s.Table.Th,{children:t("chart.color.label")}),n.jsx(s.Table.Th,{style:{width:"40px"}})]})}),n.jsx(s.Table.Tbody,{children:c.map((u,p)=>n.jsx(Wf,{index:p,form:e,remove:l},u.id))}),n.jsx(s.Table.Tfoot,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{}),n.jsx(s.Table.Td,{colSpan:3,children:n.jsx(s.Button,{mt:10,size:"xs",color:"blue",leftSection:n.jsx(S.IconPlaylistAdd,{size:20}),onClick:d,sx:{width:"50%"},mx:"auto",children:t("chart.visual_map.piecewise.add_a_piece")})}),n.jsx(s.Table.Td,{})]})})]})})},Kf=({form:e})=>{const{t,i18n:r}=m.useTranslation(),a=e.control,o=e.watch("visualMap");h.useMemo(()=>[{label:t("chart.visual_map.piecewise.mode.pieces"),value:"pieces"},{label:t("chart.visual_map.piecewise.mode.categories"),value:"categories"}],[r.language]);const{type:l,orient:i,piecewise_mode:c}=o,d=u=>p=>{typeof p!="string"&&u(p)};return l!=="piecewise"?null:n.jsxs(s.Stack,{children:[n.jsx(y.Controller,{name:"visualMap.precision",control:a,render:({field:u})=>n.jsx(s.NumberInput,{label:t("chart.visual_map.precision"),...u,onChange:d(u.onChange)})}),n.jsx(y.Controller,{name:"visualMap.orient",control:a,render:({field:u})=>n.jsx(bt,{sx:{flex:1},...u})}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(y.Controller,{name:"visualMap.itemWidth",control:a,render:({field:u})=>n.jsx(s.NumberInput,{label:t("chart.visual_map.item_width"),...u,onChange:d(u.onChange)})}),n.jsx(y.Controller,{name:"visualMap.itemHeight",control:a,render:({field:u})=>n.jsx(s.NumberInput,{label:t("chart.visual_map.item_height"),...u,onChange:d(u.onChange)})})]}),c==="pieces"&&n.jsx(Uf,{form:e})]})},Vr=({form:e})=>{const{t,i18n:r}=m.useTranslation(),a=e.control,o=e.watch("visualMap"),l=h.useMemo(()=>[{label:t("chart.visual_map.continuous.label"),value:"continuous"},{label:t("chart.visual_map.piecewise.label"),value:"piecewise"}],[r.language]),i=c=>{switch(c){case"continuous":e.setValue("visualMap",io());break;case"piecewise":e.setValue("visualMap",Sp());break;default:return}};return n.jsx(ne,{children:n.jsxs(s.Stack,{children:[n.jsx(Qf,{visualMap:o}),n.jsx(y.Controller,{name:"visualMap.type",control:a,render:({field:c})=>n.jsx(s.SegmentedControl,{mt:-10,data:l,sx:{flex:1},...c,onChange:i})}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(y.Controller,{name:"visualMap.min",control:a,render:({field:c})=>n.jsx(oo,{label:t("chart.visual_map.min_value"),...c})}),n.jsx(y.Controller,{name:"visualMap.max",control:a,render:({field:c})=>n.jsx(oo,{label:t("chart.visual_map.max_value"),...c})})]}),n.jsx(s.Divider,{variant:"dashed"}),n.jsx(Ff,{form:e}),n.jsx(Kf,{form:e})]})})};function Yf(e,{panelModel:t}){try{const r=t.queryIDs[0];if(!r)throw new Error("cannot migrate when queryID is empty");const a=d=>d&&`${r}.${d}`,{calendar:o,heat_block:l,tooltip:i,...c}=e;return{...c,calendar:{...o,data_key:a(o.data_key)},heat_block:{...l,data_key:a(l.data_key)},tooltip:{...i,metrics:i.metrics.map(d=>({...d,data_key:a(d.data_key)}))}}}catch(r){throw console.error("[Migration failed]",r),r}}function Xf(e){const{heat_block:t}=e;let{min:r,max:a}=t;return typeof r!="number"&&(r=0),typeof a!="number"&&(a=100),{...e,heat_block:{...t,min:{type:"static",value:r},max:{type:"static",value:a}}}}function Zf(e){const{visualMap:t=at(),heat_block:{min:r,max:a,...o},...l}=e;return{...l,heat_block:o,visualMap:{...at(),min:r,max:a}}}function Jf(e){const t=e.tooltip.metrics;return{...e,tooltip:{...e.tooltip,metrics:t.map(r=>({...r,unit:r.unit??K()}))}}}function Hf(e){const{heat_block:t}=e;return{...e,heat_block:{...t,unit:t.unit??K()}}}const Rf=[{lang:"en",resources:{calendar_heatmap:{viz_name:"Heatmap(Calendar)",calendar:{label:"Calendar",locale:"Langauge"},click_heatmap:{heatblock:{label:"Click heat block"}}}}},{lang:"zh",resources:{calendar_heatmap:{viz_name:"日历热力图",calendar:{label:"日历",locale:"语言"},click_heatmap:{heatblock:{label:"点击热力块"}}}}}];function eb(e){return n.jsx(n.Fragment,{})}function tb(e){const{t}=m.useTranslation();return n.jsx(s.Text,{size:"sm",children:t("viz.calendar_heatmap.click_heatmap.heatblock.label")})}const Yo={id:"builtin:echarts:click-heatmap:heat-block",displayName:"viz.calendar_heatmap.click_heatmap.heatblock.label",nameRender:tb,configRender:eb,payload:[{name:"seriesType",description:"'heatmap'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]},Pr={calendar:{data_key:"",locale:"EN"},heat_block:{name:"Value",data_key:"",unit:K(),value_formatter:de},tooltip:{metrics:[]},visualMap:at()};function nb(e,t,r){if(!e)return r[0];try{return[t,M(t).add(1,"year").subtract(1,"day").valueOf()]}catch(a){return console.error(a),r[0]}}function rb(e,t,r){const a=nb(e,t,r);return{top:50,left:25,right:5,cellSize:["auto",13],range:a,itemStyle:{borderColor:"#eee"},splitLine:{show:!0},dayLabel:{firstDay:1},monthLabel:{position:"end"},yearLabel:{show:!0}}}function ab(e){return{heat_block:function(a){if(!e.heat_block.value_formatter)return a;try{return Y(a,e.heat_block.value_formatter)}catch(o){return console.error(o),a}}}}function sb(e,t){return{show:!e,selectedMode:"single",top:5,right:5,data:t.map(r=>({name:r,icon:"circle"}))}}function ob(e,t,r){return e?{type:"heatmap",name:"heatmap",coordinateSystem:"calendar",calendarIndex:0,data:r}:Object.entries(t).map(([a,o])=>({type:"heatmap",name:a,coordinateSystem:"calendar",calendarIndex:0,data:o}))}const lb=e=>Y(e,{output:"number",trimMantissa:!0,mantissa:2,absolute:!1});function ib({conf:e,valueFormatters:t,dataDict:r,params:a,metricUnitMap:o}){const{value:l}=a,[i,c]=l,u=[{label:e.heat_block.name,value:t.heat_block(c),unit:e.heat_block.unit.show_in_tooltip?e.heat_block.unit.text:""}],p=r[i];return p&&e.tooltip.metrics.forEach(f=>{const v=$(f.data_key),_=o[f.name]??"";u.push({label:f.name,value:lb(b.get(p,v.columnKey,"")),unit:_})}),u}function cb(e,t,r){const a=$(e.calendar.data_key),o=b.keyBy(t[a.queryID],a.columnKey),l=e.tooltip.metrics.reduce((i,{unit:c,name:d})=>(c.show_in_tooltip&&(i[d]=c.text),i),{});return X.getTooltip({formatter:function(i){const d=ib({conf:e,valueFormatters:r,dataDict:o,params:i,metricUnitMap:l}).map(f=>`
|
|
119
|
+
`}const Og=(e,t)=>r=>{const{seriesName:a,value:o}=r;switch(a){case t.Box:return Eg(e,o);case t.Outlier:return qg(e,o);case t.Scatter:return Lg(e,o)}};function Ng({config:e,seriesNames:t}){return X.getTooltip({trigger:"item",formatter:Og(e,t)})}function yn(e,t){t||(t="none");const r=[];return e.x_axis_scroll&&r.push({type:"inside",xAxisIndex:[0],filterMode:t,minSpan:1}),e.y_axis_scroll&&r.push({type:"inside",yAxisIndex:[0],filterMode:t,minSpan:1}),e.x_axis_slider&&r.push({type:"slider",xAxisIndex:[0],filterMode:t,bottom:"auto",top:0,height:15,moveHandleSize:0,showDataShadow:!1,minSpan:1}),r}function Gg({min:e,max:t}){if(e<=110)return Math.min(0,e);if(e<=200)return 100;const r=Qe.floor(Qe.log10(e)),a=Math.pow(10,r),o=Math.pow(10,r-1);return e/a<=2?b.round(e,-1*(r-1))-o:b.round(e,-1*r)-a}function Fg(e){return{Box:e("viz.boxplot.box"),Scatter:e("viz.boxplot.scatter"),Outlier:e("viz.boxplot.outlier")}}function Qg({config:e,data:t,variables:r,t:a}){const{x_axis:o,y_axis:l,reference_lines:i}=e,c=Sg(e,t),d=Ke(o.axisLabel.overflow.on_axis),u=Fg(a),p=Ag(e,c).map(f=>({...f,name:b.get(u,f.name,f.name)}));return{dataZoom:yn(e.dataZoom,"filter"),grid:Tg(e),dataset:c,legend:kg({config:e,seriesNames:u}),tooltip:Ng({config:e,seriesNames:u}),xAxis:[X.getXAxis({type:"category",name:o.name,nameGap:25,nameLocation:"center",nameTextStyle:{align:"center"},axisLabel:{...o.axisLabel,...d,formatter:Me(o.axisLabel.formatter)}})],yAxis:[X.getYAxis({name:l.name,minInterval:1,axisLabel:{formatter:function(f){return Y(f,l.label_formatter)}},min:Gg})],series:[...p,...Dg(i,r,t)]}}function jg({context:e,instance:t}){const{t:r}=m.useTranslation(),{value:a}=q(e.instanceData,"config"),{variables:o}=e,l=e.data,{width:i,height:c}=e.viewport,d=b.defaults({},a,mr),u=Pe({vizManager:e.vizManager,instance:t}),p=Ve(u.triggerManager,Po.id),f=Dt(l,d.x_axis.data_key),v=h.useCallback(D=>{const z=b.get(f,D.name,{error:"rowData is not found"});p.forEach(I=>{u.runInteraction(I.id,{...D,rowData:z})})},[f,p,u]),_=h.useRef(null),w=h.useCallback(()=>{var z;const D=(z=_.current)==null?void 0:z.getEchartsInstance();D&&fe(t,D.getOption())},[]),x=h.useMemo(()=>({click:v,finished:w}),[v,w]),T=h.useMemo(()=>Qg({config:d,data:l,variables:o,t:r}),[d,l,o,r]);return!a||!i||!c?null:n.jsx(ve,{width:i,height:c,children:n.jsx(he,{echarts:ce,option:T,ref:_,style:Kt(i,c),onEvents:x,notMerge:!0,theme:"merico-light"})})}function se({canSubmit:e,buttonRef:t}){const{t:r}=m.useTranslation();return n.jsxs(s.Group,{justify:"flex-start",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[n.jsx(s.Text,{size:"sm",children:r("viz.viz_config_banner")}),n.jsx(s.ActionIcon,{ref:t,type:"submit",mr:5,variant:"filled",color:"blue",disabled:!e,children:n.jsx(S.IconDeviceFloppy,{size:20})})]})}const Dr=h.forwardRef(({label:e,value:t,onChange:r,sx:a={}},o)=>{const{t:l,i18n:i}=m.useTranslation(),c=h.useMemo(()=>[{label:l("common.align.horizontal.left"),value:"left"},{label:l("common.align.horizontal.center"),value:"center"},{label:l("common.align.horizontal.right"),value:"right"}],[i.language]);return n.jsx(s.Select,{ref:o,label:e??l("common.align.horizontal.label"),data:c,value:t,onChange:Z(r),sx:a})}),Go=h.forwardRef(({label:e,value:t,onChange:r,sx:a={}},o)=>{const{t:l,i18n:i}=m.useTranslation(),c=h.useMemo(()=>[{label:l("common.align.vertical.top"),value:"top"},{label:l("common.align.vertical.center"),value:"center"},{label:l("common.align.vertical.bottom"),value:"bottom"}],[i.language]);return n.jsx(s.Select,{ref:o,label:e??l("common.align.vertical.label"),data:c,value:t,onChange:Z(r),sx:a})}),Fo=ht.createStyles(()=>({palette:{display:"flex",flexFlow:"row nowrap"},paletteItem:{".palette-value":{height:24,overflow:"visible",width:36},".palette-item":{width:"36px",height:36*.618,cursor:"pointer",transition:"transform 100ms ease-in-out","&:hover":{boxShadow:"0 0 0 2px var(--shadow-color)",borderRadius:2,transform:"scale(1.2)"}}}})),Wg=[{from:0,to:0},{from:100,to:100}];class Ug{constructor(){V(this,"steps",new Map);V(this,"interpolation");V(this,"onChange");G.makeAutoObservable(this,{steps:G.observable},{deep:!1}),G.reaction(()=>G.toJS(this.steps),()=>{this.notifyStepChange()})}setSteps(t){for(const r of t)this.steps.set(r.to,r.from)}notifyStepChange(){var t;(t=this.onChange)==null||t.call(this,Array.from(this.steps.entries()).map(([r,a])=>({to:r,from:a})).sort((r,a)=>r.to-a.to||r.from-a.from))}fromProps(t){t.steps.length<2?this.setSteps(Wg):this.setSteps(t.steps),this.interpolation=t.interpolation,this.onChange=t.onChange}changeStep(t,r){t==null?this.steps.delete(r):this.steps.set(r,t)}getStepFromValue(t){return this.steps.get(t)}}function Qo(e){if(typeof e=="number")return String(e)}function Kg(e){const{t}=m.useTranslation(),{onChange:r,color:a,index:o,value:l}=e,{classes:i}=Fo(),[c,d]=h.useState(Qo(l)),[u,{setTrue:p,setFalse:f}]=O.useBoolean(!1),v=o%2===1,_=v&&l!=null,w=!v&&l!=null,x=`map ${l} to color ${o}`,T=()=>{d(Qo(l)),f()},D=()=>{f(),r==null||r(Number(c))},z=()=>{f(),r==null||r(null)},I=Y(l??null,{output:"number",mantissa:10,trimMantissa:!0,average:!0,absolute:!1}),E=!c||Number.isNaN(Number(c));return n.jsxs("div",{"data-testid":`palette-item-${o}`,className:i.paletteItem,children:[n.jsx(s.Text,{title:x,style:{opacity:_?1:0},c:"dimmed",size:"sm",className:"palette-value--up palette-value",children:I}),n.jsxs(s.Popover,{width:240,trapFocus:!0,opened:u,onClose:f,zIndex:340,withinPortal:!0,children:[n.jsx(s.Popover.Target,{children:n.jsx("div",{"data-testid":"palette-item-target",className:"palette-item",onClick:p,style:{"--shadow-color":Ne(a).alpha(.5).hex(),backgroundColor:a}})}),n.jsxs(s.Popover.Dropdown,{children:[n.jsx(s.Tooltip,{withinPortal:!0,zIndex:340,label:t("common.actions.close"),children:n.jsx(s.CloseButton,{"data-testid":"palette-item-cancel",size:"sm",color:"gray",onClick:T,style:{position:"absolute",top:"0.5em",right:"0.8em"}})}),n.jsxs(s.Stack,{children:[n.jsx(s.TextInput,{size:"xs",label:t("style.color.interpolation.palette.mapping.value_input_label"),value:c,onChange:A=>{const U=A.currentTarget.value;d(U)},error:c&&E}),n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Button,{variant:"light",color:"red",size:"xs",onClick:z,leftSection:n.jsx(S.IconTrash,{size:16}),children:t("common.actions.delete")}),n.jsx(s.Button,{color:"green",leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),"data-testid":"palette-item-ok",size:"xs",onClick:D,disabled:E,children:t("common.actions.save")})]})]})]})]}),n.jsx(s.Text,{title:x,style:{opacity:w?1:0},c:"dimmed",size:"sm",className:"palette-value--bottom palette-value",children:I})]})}const Yg=k.observer(({model:e})=>{const{classes:t}=Fo(),r=b.range(0,13,1).map(a=>100/12*a).map(a=>[e.interpolation.getColor(a),a]);return n.jsx("div",{className:t.palette,children:r.map(([a,o],l)=>n.jsx(Kg,{index:l,color:a,value:e.getStepFromValue(o),onChange:i=>e.changeStep(i,o)},a))})}),Xg=k.observer(function(t){const r=O.useCreation(()=>new Ug,[]);return h.useEffect(()=>{r.fromProps(t)}),r.interpolation==null?null:n.jsx(Yg,{model:r})}),Zg=e=>{const{t,i18n:r}=m.useTranslation(),{value:a,onChange:o,colorManager:l}=e,i=l.getColorInterpolations(),[c,d]=h.useState(a),u=l.decodeInterpolation(c.interpolation)||i[0],[p,{setTrue:f,setFalse:v}]=O.useBoolean(),_=h.useMemo(()=>{const z=b.groupBy(i,"category");return Object.entries(z).map(([I,E])=>({group:t(`style.color.interpolation.palette.category.${I}`),items:E.map(A=>({label:t(A.displayName),value:l.encodeColor(A)}))}))},[r.language]);function w(z){z&&d(I=>({...I,interpolation:z}))}const x=()=>{v(),o==null||o(G.toJS(c))};function T(z){d(I=>({...I,steps:z}))}const D=()=>{v(),d(a)};return n.jsxs(n.Fragment,{children:[n.jsx(s.Button,{variant:"outline",onClick:f,children:t(u==null?void 0:u.displayName)}),n.jsx(s.Modal,{size:508,title:t("style.color.interpolation.setup"),opened:p,onClose:v,zIndex:320,children:p&&n.jsxs(s.Stack,{"data-testid":"color-interpolation-modal",children:[n.jsx(s.Select,{label:t("style.color.interpolation.palette.label"),value:c.interpolation,data:_,onChange:w,comboboxProps:{withinPortal:!0,zIndex:340},maxDropdownHeight:500}),n.jsx(Xg,{steps:c.steps,interpolation:u,onChange:T}),n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Button,{onClick:D,variant:"subtle",children:t("common.actions.cancel")}),n.jsx(s.Button,{color:"green",leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),onClick:x,children:t("common.actions.save")})]})]})})]})},Jg=h.forwardRef(({label:e,value:t,onChange:r,sx:a={}},o)=>{const{t:l,i18n:i}=m.useTranslation(),c=h.useMemo(()=>[{label:l("style.color.type.static"),value:"static"},{label:l("style.color.type.interpolation"),value:"interpolation"},{label:l("style.color.type.none"),value:"none"}],[i.language]);return n.jsx(s.Select,{ref:o,label:e??l("style.color.type.label"),data:c,value:t,onChange:Z(r),sx:a})}),Hg=h.forwardRef(({label:e,value:t,onChange:r,sx:a={}},o)=>{const{t:l,i18n:i}=m.useTranslation(),c=h.useMemo(()=>[{label:l("style.flex.justify_content.left"),value:"left"},{label:l("style.flex.justify_content.center"),value:"center"},{label:l("style.flex.justify_content.right"),value:"right"},{label:l("style.flex.justify_content.space_between"),value:"space-between"},{label:l("style.flex.justify_content.space_around"),value:"space-around"},{label:l("style.flex.justify_content.space_evenly"),value:"space-evenly"}],[i.language]);return n.jsx(s.Select,{ref:o,label:e??l("style.flex.justify_content.label"),data:c,value:t,onChange:Z(r),sx:a})}),Rg=h.forwardRef(({label:e,value:t,onChange:r,sx:a={}},o)=>{const{t:l,i18n:i}=m.useTranslation(),c=h.useMemo(()=>[{label:l("style.flex.align_items.start"),value:"start"},{label:l("style.flex.align_items.center"),value:"center"},{label:l("style.flex.align_items.end"),value:"end"},{label:l("style.flex.align_items.stretch"),value:"stretch"}],[i.language]);return n.jsx(s.Select,{ref:o,label:e??l("style.flex.align_items.label"),data:c,value:t,onChange:Z(r),sx:a})}),ef=({value:e,index:t,children:r})=>{const[a,{setTrue:o,setFalse:l}]=O.useBoolean(!1),{ref:i,handleRef:c}=rn.useSortable({id:e,index:t});return n.jsx(s.Tabs.Tab,{ref:i,value:e,leftSection:n.jsx(S.IconGripHorizontal,{size:14,color:a||t===0?"rgb(34, 139, 230)":"transparent"}),onMouseEnter:o,onMouseLeave:l,children:r})},tf=({fieldArray:e,add:t,addButtonText:r,renderTabName:a,controlledFields:o})=>{const l=i=>{const{source:c,target:d}=i.operation,u=o.findIndex(f=>f.id===c.id),p=d.index;e.move(u,p)};return n.jsxs(s.Tabs.List,{children:[n.jsx(nn.DragDropProvider,{onDragEnd:l,children:o.map((i,c)=>n.jsx(ef,{value:i.id,index:c,children:a(i,c)},i.id))}),n.jsx(s.Tabs.Tab,{onClick:t,value:"add",children:n.jsx(s.Tooltip,{label:r,children:n.jsx(s.Center,{children:n.jsx(S.IconPlus,{size:18,color:"#228be6"})})})})]})},nf={tab:{paddingTop:"4px",paddingBottom:"4px"},panel:{padding:"0px"}},R=({control:e,watch:t,name:r,getItem:a,children:o,addButtonText:l,deleteButtonText:i,renderTabName:c,deleteDisalbed:d})=>{var E;const u=y.useFieldArray({control:e,name:r}),{fields:p,append:f,remove:v}=u,_=t(r),w=p.map((A,U)=>({...A,..._[U]})),x=((E=b.last(w))==null?void 0:E.id)??null,[T,D]=h.useState(x),z=A=>{A!=="add"&&D(A)};h.useEffect(()=>{D(A=>x===A?A:x)},[x]);const I=()=>{const A=a();u.append(A),D(A.id)};return n.jsxs(s.Tabs,{value:T,onChange:z,styles:nf,children:[n.jsx(tf,{fieldArray:u,add:I,addButtonText:l,renderTabName:c,controlledFields:w}),w.map((A,U)=>n.jsx(s.Tabs.Panel,{value:A.id,children:n.jsxs(s.Stack,{children:[o({field:A,index:U}),n.jsx(s.Divider,{mb:-10,mt:10,variant:"dashed"}),n.jsx(s.Button,{leftSection:n.jsx(S.IconTrash,{size:16}),color:"red",variant:"light",onClick:()=>v(U),sx:{top:15,right:5},disabled:d==null?void 0:d({field:A,index:U,fields:w}),children:i})]})},A.id))]})},vn=h.forwardRef(({value:e,onChange:t},r)=>{const{t:a}=m.useTranslation(),o=l=>i=>{t({...e,[l]:i})};return n.jsxs(s.Stack,{children:[n.jsx(s.Divider,{variant:"dashed",label:a("chart.zooming.scroll.label"),labelPosition:"center"}),n.jsxs(s.Group,{children:[n.jsx(s.Box,{sx:{flexGrow:1},children:n.jsx(s.Switch,{label:a("chart.zooming.scroll.x_axis"),checked:e.x_axis_scroll,onChange:l=>o("x_axis_scroll")(l.currentTarget.checked)})}),n.jsx(s.Box,{sx:{flexGrow:1},children:n.jsx(s.Switch,{label:a("chart.zooming.scroll.y_axis"),checked:e.y_axis_scroll,onChange:l=>o("y_axis_scroll")(l.currentTarget.checked)})})]}),n.jsx(s.Divider,{variant:"dashed",label:a("chart.zooming.slider.label"),labelPosition:"center"}),n.jsxs(s.Group,{children:[n.jsx(s.Box,{sx:{flexGrow:1},children:n.jsx(s.Switch,{label:a("chart.zooming.slider.x_axis"),checked:e.x_axis_slider,onChange:l=>o("x_axis_slider")(l.currentTarget.checked)})}),n.jsx(s.Tooltip,{label:a("chart.zooming.slider.y_axis_disabled"),children:n.jsx(s.Box,{sx:{flexGrow:1},children:n.jsx(s.Switch,{label:a("chart.zooming.slider.y_axis"),disabled:!e.y_axis_slider,checked:e.y_axis_slider,onChange:l=>o("y_axis_slider")(l.currentTarget.checked)})})})]})]})}),bt=h.forwardRef(({label:e,value:t,onChange:r,sx:a={},disabled:o},l)=>{const{t:i,i18n:c}=m.useTranslation(),d=h.useMemo(()=>[{label:i("chart.orientation.horizontal"),value:"horizontal"},{label:i("chart.orientation.vertical"),value:"vertical"}],[c.language]);return n.jsx(s.Select,{ref:l,label:e??i("chart.orientation.label"),data:d,value:t,onChange:Z(r),sx:a,disabled:o})}),rf=({control:e,watch:t})=>{const{t:r}=m.useTranslation(),a=t("legend"),o=(l,i)=>{const c={...a,orient:l};l==="horizontal"?(c.top="0",c.left="auto",c.right="10",c.bottom="auto"):(c.top="10",c.left="auto",c.right="0",c.bottom="auto"),i(c)};return n.jsxs(s.Stack,{children:[n.jsx(s.Group,{grow:!0,wrap:"nowrap",mt:20,children:n.jsx(y.Controller,{name:"legend.show",control:e,render:({field:l})=>n.jsx(s.Switch,{label:r("chart.legend.show_legend"),sx:{flex:1},checked:l.value,onChange:i=>l.onChange(i.currentTarget.checked)})})}),n.jsx(s.Group,{children:n.jsx(y.Controller,{name:"legend",control:e,render:({field:l})=>n.jsx(bt,{sx:{flex:1},value:l.value.orient,onChange:i=>{o(i,l.onChange)},disabled:!a.show})})})]})};function af({control:e,index:t,variableOptions:r}){const{t:a}=m.useTranslation();return n.jsxs(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(y.Controller,{name:`reference_lines.${t}.name`,control:e,render:({field:o})=>n.jsx(s.TextInput,{label:a("common.name"),placeholder:a("chart.reference_line.name_placeholder"),required:!0,sx:{flex:1},...o})}),n.jsx(y.Controller,{name:`reference_lines.${t}.variable_key`,control:e,render:({field:o})=>n.jsx(s.Select,{label:a("common.value"),required:!0,data:r,sx:{flex:1},...o})})]}),n.jsx(y.Controller,{name:`reference_lines.${t}.template`,control:e,render:({field:o})=>n.jsx(s.TextInput,{label:a("chart.content_template.label"),placeholder:a("chart.content_template.placeholder"),required:!0,sx:{flex:1},...o})})]})}function sf({control:e,watch:t,variables:r}){const{t:a}=m.useTranslation(),o=()=>({name:"",template:"",variable_key:""}),l=h.useMemo(()=>r.map(c=>({label:c.name,value:c.name})),[r]),i=(c,d)=>{const u=c.name.trim();return u||d+1};return n.jsx(R,{control:e,watch:t,name:"reference_lines",getItem:o,addButtonText:a("chart.reference_line.add"),deleteButtonText:a("chart.reference_line.delete"),renderTabName:i,children:({field:c,index:d})=>n.jsx(af,{control:e,index:d,variableOptions:l})})}const of=({control:e,index:t})=>{const{t:r}=m.useTranslation();return n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(y.Controller,{name:`tooltip.metrics.${t}.name`,control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("common.name"),required:!0,sx:{flex:1},...a})}),n.jsx(y.Controller,{name:`tooltip.metrics.${t}.data_key`,control:e,render:({field:a})=>n.jsx(L,{label:r("chart.data_field"),required:!0,sx:{flex:1},...a})})]}),n.jsx(y.Controller,{name:`tooltip.metrics.${t}.unit`,control:e,render:({field:a})=>n.jsx(ue,{hiddenFileds:["show_in_legend"],...a})})]})},lf=({control:e,watch:t})=>{const{t:r}=m.useTranslation(),a=()=>({id:Date.now().toString(),data_key:"",name:"",unit:K()}),o=(l,i)=>{const c=l.name.trim();return c||i+1};return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{gap:2,sx:{cursor:"default",userSelect:"none"},children:[n.jsx(S.IconInfoCircle,{size:14,color:"#888"}),n.jsx(s.Text,{size:"14px",c:"#888",children:r("chart.tooltip.additional_metrics.description")})]}),n.jsx(R,{control:e,watch:t,name:"tooltip.metrics",getItem:a,addButtonText:r("chart.tooltip.additional_metrics.add"),deleteButtonText:r("chart.tooltip.additional_metrics.delete"),renderTabName:o,children:({field:l,index:i})=>n.jsx(of,{control:e,index:i})})]})};function cf({control:e,watch:t}){return n.jsx(s.Stack,{children:n.jsx(lf,{control:e,watch:t})})}const ot=h.forwardRef(({label:e,value:t,onChange:r,sx:a={}},o)=>{const{t:l}=m.useTranslation();return n.jsx(s.NumberInput,{ref:o,label:e??l("chart.rotate"),hideControls:!0,min:-90,max:90,rightSection:n.jsx(s.Text,{size:"xs",c:"dimmed",children:l("chart.degree")}),sx:a,styles:{section:{width:"4em",justifyContent:"flex-end",paddingRight:"6px"}},value:t,onChange:i=>{typeof i!="string"&&r(i)}})}),df=({control:e,watch:t})=>{const{t:r}=m.useTranslation();return t(["x_axis"]),n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(y.Controller,{name:"x_axis.name",control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("chart.x_axis.x_axis_name"),sx:{flex:1},...a})}),n.jsx(y.Controller,{name:"x_axis.data_key",control:e,render:({field:a})=>n.jsx(L,{label:r("chart.x_axis.x_axis_data_field"),required:!0,sx:{flex:1},...a})})]}),n.jsx(s.Divider,{mb:-15,label:r("chart.axis.tick_label"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(y.Controller,{name:"x_axis.axisLabel.rotate",control:e,render:({field:a})=>n.jsx(ot,{sx:{width:"48%"},...a})}),n.jsx(y.Controller,{name:"x_axis.axisLabel.formatter",control:e,render:({field:a})=>n.jsx(et,{...a})})]}),n.jsx(y.Controller,{name:"x_axis.axisLabel.overflow",control:e,render:({field:a})=>n.jsx(tt,{...a})})]})},zr={root:{alignSelf:"flex-end"},body:{alignItems:"center"},label:{display:"block"}},uf=["123456789","1234","1234.56789","1.234","0.123456789","-0.123456789"];function pf({format:e}){const{t}=m.useTranslation(),[r,{toggle:a}]=te.useDisclosure(!1);return n.jsxs(s.Box,{children:[n.jsx(s.Button,{variant:"subtle",w:"100%",size:"compact-sm",onClick:a,leftSection:r?n.jsx(S.IconChevronUp,{size:14}):n.jsx(S.IconChevronDown,{size:14}),children:t(r?"numbro.format.preview.close":"numbro.format.preview.open")}),n.jsx(s.Collapse,{in:r,children:r&&n.jsxs(s.Table,{highlightOnHover:!0,sx:{tableLayout:"fixed"},children:[n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:t("numbro.format.preview.input")}),n.jsx(s.Table.Th,{children:t("numbro.format.preview.output")})]})}),n.jsx(s.Table.Tbody,{children:uf.map(o=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:o}),n.jsx(s.Table.Td,{children:n.jsx(ne,{children:Y(o,e)})})]},o))})]})})]})}function hf({value:e,onChange:t},r){const{t:a}=m.useTranslation(),o=u=>{t({...e,output:u,absolute:!1,average:!1,trimMantissa:!1,mantissa:0})},l=u=>{if(typeof u=="string")return;const p=u===0?!1:e.trimMantissa;t({...e,mantissa:u,trimMantissa:p})},i=u=>{t({...e,trimMantissa:u.currentTarget.checked})},c=u=>{t({...e,average:u.currentTarget.checked})},d=u=>{const p={...e,absolute:u.currentTarget.checked};t(p)};return n.jsxs(s.Stack,{ref:r,children:[n.jsxs(s.Group,{grow:!0,children:[n.jsx(s.Select,{label:a("numbro.format.label"),data:[{label:"1234",value:"number"},{label:"99%",value:"percent"}],value:e.output,onChange:Z(o),sx:{flexGrow:1}}),n.jsx(s.Switch,{label:n.jsxs(s.Stack,{gap:0,children:[n.jsx(s.Text,{size:"sm",children:a("numbro.format.absolute")}),n.jsx(s.Text,{size:"12px",c:"gray",children:a("numbro.format.absolute_description")})]}),checked:e.absolute,onChange:d,sx:{flexGrow:1},styles:zr}),n.jsx(s.Switch,{label:n.jsxs(s.Stack,{gap:0,children:[n.jsx(s.Text,{size:"sm",children:a("numbro.format.abbreviation")}),n.jsx(s.Text,{size:"12px",c:"gray",children:a("numbro.format.abbreviation_description")})]}),checked:e.average,onChange:c,disabled:e.output!=="number",sx:{flexGrow:1},styles:zr})]}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(s.NumberInput,{label:a("numbro.format.mantissa"),defaultValue:0,min:0,step:1,max:4,value:e.mantissa,onChange:l}),n.jsx(s.Switch,{label:n.jsxs(s.Stack,{gap:0,children:[n.jsx(s.Text,{size:"sm",children:a("numbro.format.trim_mantissa")}),n.jsx(s.Text,{size:"12px",c:"gray",children:a("numbro.format.trim_mantissa_description")})]}),checked:e.trimMantissa,onChange:i,disabled:e.mantissa===0,styles:zr}),n.jsx(s.Box,{})]}),n.jsx(pf,{format:e})]})}const Ye=h.forwardRef(hf),gf=({control:e,watch:t})=>{const{t:r}=m.useTranslation();return t(["y_axis"]),n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(y.Controller,{name:"y_axis.name",control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("chart.y_axis.y_axis_name"),sx:{flex:1},...a})}),n.jsx(y.Controller,{name:"y_axis.data_key",control:e,render:({field:a})=>n.jsx(L,{label:r("chart.y_axis.y_axis_data_field"),required:!0,sx:{flex:1},...a})})]}),n.jsx(y.Controller,{name:"y_axis.unit",control:e,render:({field:a})=>n.jsx(ue,{hiddenFileds:["show_in_legend"],...a})}),n.jsxs(s.Stack,{children:[n.jsx(s.Divider,{mt:10,mb:-15,variant:"dashed",label:r("chart.axis.section_title.label_format"),labelPosition:"center"}),n.jsx(y.Controller,{name:"y_axis.label_formatter",control:e,render:({field:a})=>n.jsx(Ye,{...a})})]})]})};function ff({context:e}){const{t}=m.useTranslation(),{value:r,set:a}=q(e.instanceData,"config"),{variables:o}=e,l=h.useMemo(()=>b.defaults({},r,mr),[r]),{control:i,handleSubmit:c,watch:d,formState:u,reset:p}=y.useForm({defaultValues:l});return h.useEffect(()=>{p(l)},[l]),d(["x_axis","y_axis","reference_lines","color","dataZoom"]),n.jsx(s.Stack,{gap:"xs",children:n.jsxs("form",{onSubmit:c(a),children:[n.jsx(se,{canSubmit:u.isDirty}),n.jsxs(s.Tabs,{defaultValue:"X Axis",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"X Axis",children:t("chart.x_axis.label")}),n.jsx(s.Tabs.Tab,{value:"Y Axis",children:t("chart.y_axis.label")}),n.jsx(s.Tabs.Tab,{value:"Legend",children:t("chart.legend.label")}),n.jsx(s.Tabs.Tab,{value:"Tooltip",children:t("chart.tooltip.label")}),n.jsx(s.Tabs.Tab,{value:"Style",children:t("chart.style.label")}),n.jsx(s.Tabs.Tab,{value:"Reference Lines",children:t("chart.reference_line.labels")}),n.jsx(s.Tabs.Tab,{value:"Zooming",children:t("chart.zooming.label")})]}),n.jsx(s.Tabs.Panel,{value:"X Axis",children:n.jsx(df,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Y Axis",children:n.jsx(gf,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Legend",children:n.jsx(rf,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Tooltip",children:n.jsx(cf,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Style",children:n.jsx(s.SimpleGrid,{cols:2,children:n.jsx(y.Controller,{name:"color",control:i,render:({field:f})=>n.jsx(ye,{label:t("chart.color.label"),...f})})})}),n.jsx(s.Tabs.Panel,{value:"Reference Lines",children:n.jsx(sf,{variables:o,control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Zooming",children:n.jsx(y.Controller,{name:"dataZoom",control:i,render:({field:f})=>n.jsx(vn,{...f})})})]})]})})}function bf(e){return b.omit(e,"variables")}function yf(e){const{label_formatter:t=de,...r}=e.y_axis;return{...e,y_axis:{...r,label_formatter:t}}}function vf(e){const t={rotate:0,formatter:_e()},{axisLabel:r=t,...a}=e.x_axis;return{...e,x_axis:{...a,axisLabel:r}}}function _f(e){const t={x_axis:{axisLabel:{overflow:{x_axis:{width:80,overflow:"truncate",ellipsis:"..."},tooltip:{width:200,overflow:"break",ellipsis:"..."}}}}};return b.defaultsDeep(t,e)}function mf(e){delete e.config;const{x_axis:t,tooltip:r}=e.x_axis.axisLabel.overflow,a={x_axis:{axisLabel:{overflow:{on_axis:t,in_tooltip:r}}}};return b.defaultsDeep(a,e)}function wf(e){const t={tooltip:{metrics:[]}};return b.defaultsDeep(t,e)}function xf(e,{panelModel:t}){try{const r=t.queryIDs[0];if(!r)throw new Error("cannot migrate when queryID is empty");const a=d=>d&&`${r}.${d}`,{x_axis:o,y_axis:l,tooltip:i,...c}=e;return{...c,x_axis:{...o,data_key:a(o.data_key)},y_axis:{...l,data_key:a(l.data_key)},tooltip:{...i,metrics:i.metrics.map(d=>({...d,data_key:a(d.data_key)}))}}}catch(r){throw console.error("[Migration failed]",r),r}}function Cf(e){const t={legend:{show:!0,top:"0",right:"10",left:"auto",bottom:"auto",orient:"horizontal",type:"scroll"}};return b.defaultsDeep(t,e)}function Sf(e){const{dataZoom:t,...r}=e;return{...r,dataZoom:t??Vo()}}function Tf(e){const t=e.tooltip.metrics;return{...e,tooltip:{...e.tooltip,metrics:t.map(r=>({...r,unit:r.unit??K()}))}}}function kf(e){const{y_axis:t}=e;return{...e,y_axis:{...t,unit:t.unit??K()}}}class Df extends J{constructor(){super(...arguments);V(this,"VERSION",12)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,(r,{panelModel:a})=>{const{config:o}=r;return(o.variables||[]).forEach(i=>{a.variables.find(c=>c.name===i.name)||a.addVariable(i)}),{...r,version:2,config:bf(o)}}),this.version(3,r=>{const{config:a}=r;return{...r,version:3,config:yf(a)}}),this.version(4,r=>{const{config:a}=r;return{...r,version:4,config:vf(a)}}),this.version(5,r=>{const{config:a}=r;return{...r,version:5,config:_f(a)}}),this.version(6,r=>{const{config:a}=r;return{...r,version:6,config:mf(a)}}),this.version(7,r=>{const{config:a}=r;return{...r,version:7,config:wf(a)}}),this.version(8,(r,a)=>{const{config:o}=r;return{...r,version:8,config:xf(o,a)}}),this.version(9,r=>{const{config:a}=r;return{...r,version:9,config:Cf(a)}}),this.version(10,r=>{const{config:a}=r;return{...r,version:10,config:Sf(a)}}),this.version(11,r=>{const{config:a}=r;return{...r,version:11,config:Tf(a)}}),this.version(12,r=>{const{config:a}=r;return{...r,version:12,config:kf(a)}})}}const zf={displayName:"viz.boxplot.viz_name",displayGroup:"chart.groups.echarts_based_charts",migrator:new Df,name:"boxplot",viewRender:jg,configRender:ff,createConfig(){return{version:12,config:b.cloneDeep(mr)}},triggers:[Po],translation:wh},jo={id:"builtin:button:click-button",displayName:"viz.button.click.label",nameRender:If,configRender:Mf,payload:[]};function Mf(e){return n.jsx(n.Fragment,{})}function If(e){const{t}=m.useTranslation();return n.jsx(s.Text,{size:"sm",children:t("viz.button.click.label")})}const Mr={content:"Button",variant:"filled",color:"blue",size:"xs",compact:!1,horizontal_align:"left",vertical_align:"center"},Vf={left:"flex-start",center:"center",right:"flex-end"},Pf={top:"flex-start",center:"center",bottom:"flex-end"},$f=k.observer(({context:e,instance:t})=>{const r=Pe({vizManager:e.vizManager,instance:t}),a=Ve(r.triggerManager,jo.id),o=H(),{value:l}=q(e.instanceData,"config"),i=h.useMemo(()=>b.defaultsDeep({},l,Mr),[l]),{content:c,horizontal_align:d,vertical_align:u,compact:p,size:f,...v}=i,{width:_,height:w}=e.viewport,x=o.payloadForSQL,T=()=>{a.forEach(z=>{r.runInteraction(z.id,{})})},D=p?`compact-${f}`:f;return n.jsx(s.Center,{sx:{width:_,height:w,justifyContent:Vf[d],alignItems:Pf[u]},children:n.jsx(s.Button,{size:D,...v,onClick:T,children:b.template(c)(x)})})}),Af=({value:e,onChange:t,label:r})=>{const a=s.useMantineTheme(),o=h.useCallback(i=>()=>t(i),[t]),l=i=>e===i;return n.jsxs(s.Stack,{gap:2,children:[n.jsx(s.Text,{size:"14px",fw:500,children:r}),n.jsx(s.Group,{justify:"flex-start",gap:"xs",children:Object.keys(a.colors).map(i=>{const c=a.colors[i][6];return n.jsx(s.ColorSwatch,{color:c,onClick:o(i),radius:4,size:26,sx:{cursor:"pointer"},children:l(i)&&n.jsx(s.CheckIcon,{width:10,color:"white"})},i)})})]})},Ef=["xs","sm","md","lg","xl"],Ir=h.forwardRef(({label:e,value:t,onChange:r,sx:a,disabled:o},l)=>{const{t:i,i18n:c}=m.useTranslation(),d=h.useMemo(()=>Ef.map(u=>({label:i(`style.size.${u}`),value:u})),[c.language]);return n.jsx(s.Select,{ref:l,data:d,label:e,value:t,onChange:Z(r),sx:a,disabled:!0})}),Bf=[{label:"Filled",value:"filled"},{label:"Outline",value:"outline"},{label:"Light",value:"light"},{label:"White",value:"white"},{label:"Default",value:"default"},{label:"Subtle",value:"subtle"},{label:"Gradient",value:"gradient",disabled:!0}];function qf({context:e}){const{value:t,set:r}=q(e.instanceData,"config"),a=h.useMemo(()=>b.defaultsDeep({},t,Mr),[t]),o=a;h.useEffect(()=>{!b.isEqual(a,o)&&(console.log("config malformed, resetting to defaults",a,o),r(o))},[a,o]);const{control:l,handleSubmit:i,watch:c,formState:d,reset:u}=y.useForm({defaultValues:o});return h.useEffect(()=>{u(o)},[o]),c(["content","variant","color","size","compact","horizontal_align","vertical_align"]),n.jsxs("form",{onSubmit:i(r),children:[n.jsx(se,{canSubmit:d.isDirty}),n.jsxs(s.Stack,{children:[n.jsx(y.Controller,{control:l,name:"content",render:({field:p})=>n.jsx(s.TextInput,{label:"Content Template",description:"Filter values & context entries are supported",...p,required:!0})}),n.jsx(s.Divider,{mt:"xs",mb:0,label:"Styles",labelPosition:"center",variant:"dashed"}),n.jsxs(s.SimpleGrid,{cols:2,children:[n.jsx(y.Controller,{control:l,name:"variant",render:({field:p})=>n.jsx(s.Select,{label:"Variant",data:Bf,...p})}),n.jsx(y.Controller,{control:l,name:"color",render:({field:p})=>n.jsx(Af,{label:"Theme",...p})})]}),n.jsxs(s.SimpleGrid,{cols:2,children:[n.jsx(y.Controller,{control:l,name:"size",render:({field:p})=>n.jsx(Ir,{label:"Size",...p})}),n.jsx(y.Controller,{control:l,name:"compact",render:({field:p})=>n.jsx(s.Checkbox,{label:"Compact",checked:p.value,onChange:f=>p.onChange(f.currentTarget.checked),mt:26})})]}),n.jsxs(s.SimpleGrid,{cols:2,children:[n.jsx(y.Controller,{control:l,name:"horizontal_align",render:({field:p})=>n.jsx(Dr,{...p})}),n.jsx(y.Controller,{control:l,name:"vertical_align",render:({field:p})=>n.jsx(Go,{...p})})]})]})]})}const Lf=[{lang:"en",resources:{button:{viz_name:"Button",click:{label:"Click this button"}}}},{lang:"zh",resources:{button:{viz_name:"按钮",click:{label:"点击此按钮"}}}}];class Of extends J{constructor(){super(...arguments);V(this,"VERSION",2)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,r=>{const{horizontal_align:a="left",vertical_align:o="center",...l}=r.config;return{...r,version:2,config:{...l,horizontal_align:a,vertical_align:o}}})}}const Nf={displayName:"viz.button.viz_name",displayGroup:"chart.groups.others",migrator:new Of,name:"button",viewRender:$f,configRender:qf,createConfig(){return{version:2,config:b.cloneDeep(Mr)}},triggers:[jo],translation:Lf},_n=({label:e,field:t})=>{const{t:r}=m.useTranslation();return n.jsx(s.ColorInput,{label:e,placeholder:r("chart.visual_map.skip_range.follow_visual_map"),size:"xs",popoverProps:{withinPortal:!0,zIndex:340},rightSection:t.value?n.jsx(s.CloseButton,{size:"sm",onClick:()=>{t.onChange("")}}):null,...t})},Gf=({form:e})=>{const{t}=m.useTranslation();return n.jsxs(s.Stack,{children:[n.jsx(y.Controller,{control:e.control,name:"visualMap.skipRange.lt_min",render:({field:r})=>n.jsx(_n,{field:r,label:t("chart.visual_map.skip_range.lt_min")})}),n.jsx(y.Controller,{control:e.control,name:"visualMap.skipRange.min",render:({field:r})=>n.jsx(_n,{field:r,label:t("chart.visual_map.skip_range.min")})}),n.jsx(y.Controller,{control:e.control,name:"visualMap.skipRange.max",render:({field:r})=>n.jsx(_n,{field:r,label:t("chart.visual_map.skip_range.max")})}),n.jsx(y.Controller,{control:e.control,name:"visualMap.skipRange.gt_max",render:({field:r})=>n.jsx(_n,{field:r,label:t("chart.visual_map.skip_range.gt_max")})})]})},Ff=({form:e})=>{const{t,i18n:r}=m.useTranslation(),a=e.control,o=e.watch("visualMap"),{type:l,orient:i}=o,c=i==="horizontal",d=u=>p=>{typeof p!="string"&&u(p)};return l!=="continuous"?null:n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,children:[n.jsx(y.Controller,{name:"visualMap.text.1",control:a,render:({field:u})=>n.jsx(s.TextInput,{label:t("chart.visual_map.min_text"),...u})}),n.jsx(y.Controller,{name:"visualMap.text.0",control:a,render:({field:u})=>n.jsx(s.TextInput,{label:t("chart.visual_map.max_text"),...u})})]}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(y.Controller,{name:"visualMap.orient",control:a,render:({field:u})=>n.jsx(bt,{sx:{flex:1},...u})}),n.jsx(y.Controller,{name:"visualMap.calculable",control:a,render:({field:u})=>n.jsx(s.Checkbox,{label:t("chart.visual_map.calculable"),checked:u.value,onChange:p=>u.onChange(p.currentTarget.checked),styles:{root:{transform:"translateY(12px)"}}})})]}),n.jsxs(s.Group,{grow:!0,styles:{root:{flexDirection:c?"row-reverse":"row"}},children:[n.jsx(y.Controller,{name:"visualMap.itemWidth",control:a,render:({field:u})=>n.jsx(s.NumberInput,{label:t(c?"chart.visual_map.bar_height":"chart.visual_map.bar_width"),...u,onChange:d(u.onChange)})}),n.jsx(y.Controller,{name:"visualMap.itemHeight",control:a,render:({field:u})=>n.jsx(s.NumberInput,{label:t(c?"chart.visual_map.bar_width":"chart.visual_map.bar_height"),...u,onChange:d(u.onChange)})})]}),n.jsx(y.Controller,{name:"visualMap.inRange.color",control:a,render:({field:u})=>n.jsx(uo,{...u})}),n.jsx(Gf,{form:e})]})},Qf=({visualMap:e})=>{const{orient:t,itemWidth:r,itemHeight:a}=e,l=t==="horizontal"?r:a,{panel:i}=ae(),c=un(e,i.variableValueMap);return n.jsx(ne,{children:n.jsx(he,{echarts:ce,option:{visualMap:c},style:{width:"100%",height:`${l+40}px`},notMerge:!0,theme:"merico-light"})})},Wo={lower:[{label:"<",value:"gt"},{label:"≤",value:"gte"}],upper:[{label:">",value:"lt"},{label:"≥",value:"lte"}]},Uo={gt:"(",gte:"[",lt:")",lte:"]"},Ko=(e,t)=>e===""?t:Number.isNaN(Number(e))?"INVALID VALUE":e,jf=({form:e,index:t})=>{const{t:r}=m.useTranslation(),{control:a,watch:o}=e,l=o(`visualMap.pieces.${t}`),{lower:i,upper:c}=l,d=[Uo[i.symbol],Ko(i.value,r("chart.visual_map.min_value")),",",Ko(c.value,r("chart.visual_map.max_value")),Uo[c.symbol]].join(""),[u,p]=h.useState(!1);return n.jsx(s.Group,{wrap:"nowrap",children:n.jsxs(s.Popover,{width:400,position:"bottom",withArrow:!0,shadow:"md",opened:u,onChange:p,withinPortal:!0,zIndex:340,children:[n.jsx(s.Popover.Target,{children:n.jsx(s.Button,{variant:"subtle",size:"compact-sm",px:0,onClick:()=>p(f=>!f),fw:"normal",ff:"monospace",children:d})}),n.jsx(s.Popover.Dropdown,{children:n.jsxs(s.Group,{wrap:"nowrap",gap:8,children:[n.jsx(y.Controller,{name:`visualMap.pieces.${t}.lower.value`,control:a,render:({field:f})=>n.jsx(s.TextInput,{...f,placeholder:r("chart.visual_map.min_value"),size:"xs",onChange:v=>f.onChange(v.currentTarget.value),error:f.value!==""&&Number.isNaN(Number(f.value))})}),n.jsx(y.Controller,{name:`visualMap.pieces.${t}.lower.symbol`,control:a,render:({field:f})=>n.jsx(s.Select,{size:"xs",data:Wo.lower,...f,onChange:Z(v=>f.onChange(v))})}),n.jsx(s.Text,{c:"dimmed",size:"sm",sx:{userSelect:"none",cursor:"default"},children:r("common.value").toLowerCase()}),n.jsx(y.Controller,{name:`visualMap.pieces.${t}.upper.symbol`,control:a,render:({field:f})=>n.jsx(s.Select,{size:"xs",data:Wo.upper,...f,onChange:Z(v=>f.onChange(v))})}),n.jsx(y.Controller,{name:`visualMap.pieces.${t}.upper.value`,control:a,render:({field:f})=>n.jsx(s.TextInput,{...f,size:"xs",placeholder:r("chart.visual_map.max_value"),onChange:v=>f.onChange(v.currentTarget.value),error:f.value!==""&&Number.isNaN(Number(f.value))})})]})})]})})},Wf=({form:e,index:t,remove:r})=>{const{control:a}=e,{t:o}=m.useTranslation();return n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:(t+1).toString()}),n.jsx(s.Table.Td,{children:n.jsx(jf,{form:e,index:t})}),n.jsx(s.Table.Td,{children:n.jsx(y.Controller,{name:`visualMap.pieces.${t}.label`,control:a,render:({field:l})=>n.jsx(s.TextInput,{size:"xs",placeholder:"",...l,onChange:i=>l.onChange(i.currentTarget.value)})})}),n.jsx(s.Table.Td,{children:n.jsx(y.Controller,{name:`visualMap.pieces.${t}.color`,control:a,render:({field:l})=>n.jsx(s.ColorInput,{label:o(""),placeholder:o("chart.color.label"),size:"xs",popoverProps:{withinPortal:!0,zIndex:340},rightSection:l.value?n.jsx(s.CloseButton,{size:"sm",onClick:()=>{l.onChange("")}}):null,...l})})}),n.jsx(s.Table.Td,{children:n.jsx(s.CloseButton,{size:"sm",onClick:()=>r(t)})})]})},Uf=({form:e})=>{const{t,i18n:r}=m.useTranslation(),{fields:a,append:o,remove:l}=y.useFieldArray({control:e.control,name:"visualMap.pieces"}),i=e.watch("visualMap.pieces"),c=a.map((u,p)=>({...u,...i[p]})),d=()=>{o(co())};return n.jsx(s.Stack,{children:n.jsxs(s.Table,{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:t("chart.visual_map.piecewise.interval")}),n.jsx(s.Table.Th,{children:t("chart.visual_map.piecewise.piece_label")}),n.jsx(s.Table.Th,{children:t("chart.color.label")}),n.jsx(s.Table.Th,{style:{width:"40px"}})]})}),n.jsx(s.Table.Tbody,{children:c.map((u,p)=>n.jsx(Wf,{index:p,form:e,remove:l},u.id))}),n.jsx(s.Table.Tfoot,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{}),n.jsx(s.Table.Td,{colSpan:3,children:n.jsx(s.Button,{mt:10,size:"xs",color:"blue",leftSection:n.jsx(S.IconPlaylistAdd,{size:20}),onClick:d,sx:{width:"50%"},mx:"auto",children:t("chart.visual_map.piecewise.add_a_piece")})}),n.jsx(s.Table.Td,{})]})})]})})},Kf=({form:e})=>{const{t,i18n:r}=m.useTranslation(),a=e.control,o=e.watch("visualMap");h.useMemo(()=>[{label:t("chart.visual_map.piecewise.mode.pieces"),value:"pieces"},{label:t("chart.visual_map.piecewise.mode.categories"),value:"categories"}],[r.language]);const{type:l,orient:i,piecewise_mode:c}=o,d=u=>p=>{typeof p!="string"&&u(p)};return l!=="piecewise"?null:n.jsxs(s.Stack,{children:[n.jsx(y.Controller,{name:"visualMap.precision",control:a,render:({field:u})=>n.jsx(s.NumberInput,{label:t("chart.visual_map.precision"),...u,onChange:d(u.onChange)})}),n.jsx(y.Controller,{name:"visualMap.orient",control:a,render:({field:u})=>n.jsx(bt,{sx:{flex:1},...u})}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(y.Controller,{name:"visualMap.itemWidth",control:a,render:({field:u})=>n.jsx(s.NumberInput,{label:t("chart.visual_map.item_width"),...u,onChange:d(u.onChange)})}),n.jsx(y.Controller,{name:"visualMap.itemHeight",control:a,render:({field:u})=>n.jsx(s.NumberInput,{label:t("chart.visual_map.item_height"),...u,onChange:d(u.onChange)})})]}),c==="pieces"&&n.jsx(Uf,{form:e})]})},Vr=({form:e})=>{const{t,i18n:r}=m.useTranslation(),a=e.control,o=e.watch("visualMap"),l=h.useMemo(()=>[{label:t("chart.visual_map.continuous.label"),value:"continuous"},{label:t("chart.visual_map.piecewise.label"),value:"piecewise"}],[r.language]),i=c=>{switch(c){case"continuous":e.setValue("visualMap",io());break;case"piecewise":e.setValue("visualMap",Sp());break;default:return}};return n.jsx(ne,{children:n.jsxs(s.Stack,{children:[n.jsx(Qf,{visualMap:o}),n.jsx(y.Controller,{name:"visualMap.type",control:a,render:({field:c})=>n.jsx(s.SegmentedControl,{mt:-10,data:l,sx:{flex:1},...c,onChange:i})}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(y.Controller,{name:"visualMap.min",control:a,render:({field:c})=>n.jsx(oo,{label:t("chart.visual_map.min_value"),...c})}),n.jsx(y.Controller,{name:"visualMap.max",control:a,render:({field:c})=>n.jsx(oo,{label:t("chart.visual_map.max_value"),...c})})]}),n.jsx(s.Divider,{variant:"dashed"}),n.jsx(Ff,{form:e}),n.jsx(Kf,{form:e})]})})};function Yf(e,{panelModel:t}){try{const r=t.queryIDs[0];if(!r)throw new Error("cannot migrate when queryID is empty");const a=d=>d&&`${r}.${d}`,{calendar:o,heat_block:l,tooltip:i,...c}=e;return{...c,calendar:{...o,data_key:a(o.data_key)},heat_block:{...l,data_key:a(l.data_key)},tooltip:{...i,metrics:i.metrics.map(d=>({...d,data_key:a(d.data_key)}))}}}catch(r){throw console.error("[Migration failed]",r),r}}function Xf(e){const{heat_block:t}=e;let{min:r,max:a}=t;return typeof r!="number"&&(r=0),typeof a!="number"&&(a=100),{...e,heat_block:{...t,min:{type:"static",value:r},max:{type:"static",value:a}}}}function Zf(e){const{visualMap:t=at(),heat_block:{min:r,max:a,...o},...l}=e;return{...l,heat_block:o,visualMap:{...at(),min:r,max:a}}}function Jf(e){const t=e.tooltip.metrics;return{...e,tooltip:{...e.tooltip,metrics:t.map(r=>({...r,unit:r.unit??K()}))}}}function Hf(e){const{heat_block:t}=e;return{...e,heat_block:{...t,unit:t.unit??K()}}}const Rf=[{lang:"en",resources:{calendar_heatmap:{viz_name:"Heatmap(Calendar)",calendar:{label:"Calendar",locale:"Langauge"},click_heatmap:{heatblock:{label:"Click heat block"}}}}},{lang:"zh",resources:{calendar_heatmap:{viz_name:"日历热力图",calendar:{label:"日历",locale:"语言"},click_heatmap:{heatblock:{label:"点击热力块"}}}}}];function eb(e){return n.jsx(n.Fragment,{})}function tb(e){const{t}=m.useTranslation();return n.jsx(s.Text,{size:"sm",children:t("viz.calendar_heatmap.click_heatmap.heatblock.label")})}const Yo={id:"builtin:echarts:click-heatmap:heat-block",displayName:"viz.calendar_heatmap.click_heatmap.heatblock.label",nameRender:tb,configRender:eb,payload:[{name:"seriesType",description:"'heatmap'",valueType:"string"},{name:"componentType",description:"'series'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"value",description:"String-typed number, or series' actual value",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]},Pr={calendar:{data_key:"",locale:"EN"},heat_block:{name:"Value",data_key:"",unit:K(),value_formatter:de},tooltip:{metrics:[]},visualMap:at()};function nb(e,t,r){if(!e)return r[0];try{return[t,M(t).add(1,"year").subtract(1,"day").valueOf()]}catch(a){return console.error(a),r[0]}}function rb(e,t,r){const a=nb(e,t,r);return{top:50,left:25,right:5,cellSize:["auto",13],range:a,itemStyle:{borderColor:"#eee"},splitLine:{show:!0},dayLabel:{firstDay:1},monthLabel:{position:"end"},yearLabel:{show:!0}}}function ab(e){return{heat_block:function(a){if(!e.heat_block.value_formatter)return a;try{return Y(a,e.heat_block.value_formatter)}catch(o){return console.error(o),a}}}}function sb(e,t){return{show:!e,selectedMode:"single",top:5,right:5,data:t.map(r=>({name:r,icon:"circle"}))}}function ob(e,t,r){return e?{type:"heatmap",name:"heatmap",coordinateSystem:"calendar",calendarIndex:0,data:r}:Object.entries(t).map(([a,o])=>({type:"heatmap",name:a,coordinateSystem:"calendar",calendarIndex:0,data:o}))}const lb=e=>Y(e,{output:"number",trimMantissa:!0,mantissa:2,absolute:!1});function ib({conf:e,valueFormatters:t,dataDict:r,params:a,metricUnitMap:o}){const{value:l}=a,[i,c]=l,u=[{label:e.heat_block.name,value:t.heat_block(c),unit:e.heat_block.unit.show_in_tooltip?e.heat_block.unit.text:""}],p=r[i];return p&&e.tooltip.metrics.forEach(f=>{const v=$(f.data_key),_=o[f.name]??"";u.push({label:f.name,value:lb(b.get(p,v.columnKey,"")),unit:_})}),u}function cb(e,t,r){const a=$(e.calendar.data_key),o=b.keyBy(t[a.queryID],a.columnKey),l=e.tooltip.metrics.reduce((i,{unit:c,name:d})=>(c.show_in_tooltip&&(i[d]=c.text),i),{});return X.getTooltip({formatter:function(i){const d=ib({conf:e,valueFormatters:r,dataDict:o,params:i,metricUnitMap:l}).map(f=>`
|
|
120
120
|
<tr>
|
|
121
121
|
<th style="text-align: right; padding: 0 1em;">
|
|
122
122
|
${f.label}
|
|
@@ -335,7 +335,7 @@ Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel vari
|
|
|
335
335
|
</thead>
|
|
336
336
|
<tbody>${_.join("")}</tbody>
|
|
337
337
|
</table>
|
|
338
|
-
`}})}function Fm(e,t,r){const{overflow:a,rotate:o}=e.x_axis.axisLabel,l=Ke(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:o,...l,formatter:r},splitArea:{show:!1,areaStyle:{color:"#E7E7E9"}},splitLine:{show:!1},nameLocation:"center",nameGap:25,nameTextStyle:{fontWeight:"bold",align:"center"},z:3})}function Qm(e,t){const{nameAlignment:r,data_key:a,...o}=e.y_axis,{overflow:l,rotate:i}=e.y_axis.axisLabel,c=Ke(l.on_axis);return X.getYAxis({...o,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 jm(e,t,r){if(!e.x_axis.data_key||!e.y_axis.data_key||!e.heat_block.data_key)return{};const a=r.reduce((x,T)=>{const D=Re(T,t);return x[T.name]=Be(T,D),x},{}),o=Em(e),l=Bm(e),i=un(e.visualMap,a),{min:c,max:d}=i,u=$(e.x_axis.data_key),p=$(e.y_axis.data_key),f=$(e.heat_block.data_key),v=b.uniq(t[u.queryID].map(x=>x[u.columnKey])),_=t[u.queryID].map(x=>{const T=b.get(x,u.columnKey),D=b.get(x,p.columnKey),z=b.get(x,f.columnKey),I={value:[T,D,z]},{followVisualMap:E,color:A}=dr(z,c,d,e.visualMap);return E||(I.visualMap=!1,I.itemStyle={color:A}),I});return{xAxis:Fm(e,v,o.x_axis),yAxis:Qm(e,o.y_axis),series:Lm(e,_),tooltip:Gm(e,t,o,l),grid:qm(e),visualMap:i}}function Wm({conf:e,data:t,width:r,height:a,interactionManager:o,variables:l,instance:i}){const c=h.useMemo(()=>{const w=$(e.x_axis.data_key),x=$(e.y_axis.data_key);return b.keyBy(t[w.queryID],T=>`${T[w.columnKey]}---${T[x.columnKey]}`)},[t,e.x_axis.data_key,e.y_axis.data_key]),d=Ve(o.triggerManager,il.id),u=h.useCallback(w=>{const[x,T]=w.value,D=b.get(c,`${x}---${T}`,{error:"rowData is not found"});d.forEach(z=>{o.runInteraction(z.id,{...w,rowData:D})})},[c,d,o]),p=h.useRef(null),f=h.useCallback(()=>{var x;const w=(x=p.current)==null?void 0:x.getEchartsInstance();w&&fe(i,w.getOption())},[i]),v=h.useMemo(()=>({click:u,finished:f}),[u,f]),_=h.useMemo(()=>jm(e,t,l),[e,t]);return n.jsx(he,{echarts:ce,option:_,ref:p,style:{width:r,height:a},onEvents:v,notMerge:!0,theme:"merico-light"})}function Um({context:e,instance:t}){const r=Pe({vizManager:e.vizManager,instance:t}),{value:a}=q(e.instanceData,"config"),{variables:o}=e,l=h.useMemo(()=>b.defaults({},a,jr),[a]),i=e.data,{width:c,height:d}=e.viewport;return!c||!d?null:n.jsx(ve,{width:c,height:d,children:n.jsx(Wm,{instance:t,variables:o,width:qe(c),height:Le(d),data:i,conf:l,interactionManager:r})})}const Km=[{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 Ym(e){const{visualMap:t=at(),heat_block:{min:r,max:a,...o},...l}=e;return{...l,heat_block:o,visualMap:{...at(),min:r,max:a}}}function Xm(e){const t=e.tooltip.metrics;return{...e,tooltip:{...e.tooltip,metrics:t.map(r=>({...r,unit:r.unit??K()}))}}}function Zm(e){const{heat_block:t}=e;return{...e,heat_block:{...t,unit:t.unit??K()}}}class Jm extends J{constructor(){super(...arguments);V(this,"VERSION",4)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,r=>({...r,version:2,config:Ym(r.config)})),this.version(3,r=>({...r,version:3,config:Xm(r.config)})),this.version(4,r=>({...r,version:4,config:Zm(r.config)}))}}const Hm={displayName:"viz.merico_heatmap.viz_name",displayGroup:"chart.groups.merico_suite",migrator:new Jm,name:"merico-heatmap",viewRender:Um,configRender:Pm,createConfig:()=>({version:4,config:jr}),triggers:[il],translation:Km};class Rm extends J{constructor(){super(...arguments);V(this,"VERSION",1)}configVersions(){this.version(1,r=>({version:1,config:r}))}}const Wr=()=>({value:"",sections:[{name:"较差",color:"#ff0034",minKey:""},{name:"一般",color:"#ffc04d",minKey:""},{name:"良好",color:"#adcfe4",minKey:""},{name:"优秀",color:"#32cb95",minKey:""}],stats:{top:"",bottom:""}}),ew=(e,t)=>{const r={value:b.get(me(t,e.value),"0","null"),sections:e.sections.map(o=>({name:o.name,color:o.color,min:o.minKey?b.get(me(t,o.minKey),"0","null"):0,pointer:!1,pointer_equal:!1}))},a=r.value;for(let o=0;o<r.sections.length&&!(a<r.sections[o].min);o++)r.sections[o].pointer=!0,r.sections[o].pointer_equal=a===r.sections[o].min,o>0&&(r.sections[o-1].pointer=!1,r.sections[o-1].pointer_equal=!1);return r},Xt={section:"_section_1jopp_1",min:"_min_1jopp_12",name:"_name_1jopp_19",pointer:"_pointer_1jopp_23",pointer_equal:"_pointer_equal_1jopp_30"};function tw({conf:e,data:t,width:r,height:a}){const o=h.useMemo(()=>ew(e,t),[e,t]);return!r||!a?null:n.jsx(s.Group,{justify:"flex-start",grow:!0,wrap:"nowrap",gap:0,pt:"sm",mah:a,w:r,children:o.sections.map(l=>n.jsxs(s.Center,{className:Xt.section,style:{backgroundColor:l.color},children:[n.jsx(s.Text,{size:"sm",className:Xt.name,children:l.name}),l.min>0?n.jsx(s.Text,{size:"xs",className:Xt.min,children:l.min}):null,l.pointer?n.jsx(S.IconArrowUp,{className:`${Xt.pointer} ${l.pointer_equal?Xt.pointer_equal:""}`,stroke:1.5}):null]},`${l.name}-${l.color}-${l.min}`))})}function nw({context:e}){const{value:t}=q(e.instanceData,"config"),r=h.useMemo(()=>b.defaults({},t,Wr()),[t]),a=e.data,{width:o,height:l}=e.viewport,[i,c]=h.useState(0),[d,u]=h.useState(0),p=Math.max(0,Le(l)-i-d),f=qe(o);return n.jsxs(ve,{width:o,height:l,children:[n.jsx(zt,{onHeightChange:c,value:r.stats.top,context:e}),n.jsx(tw,{width:f,height:p,data:a,conf:r})]})}const rw=[{lang:"en",resources:{merico_linear_gauge:{viz_name:"Merico Linear Gauge",sections:{label:"Sections",min_key:{placeholder:"Min value",zero:"Zero"},add:"Add a section"},value:"Value"}}},{lang:"zh",resources:{merico_linear_gauge:{viz_name:"思码逸线性仪表盘",sections:{label:"配置区间",min_key:{placeholder:"区间最小值",zero:"零"},add:"增加一个区间"},value:"值"}}}],aw=({row:e,index:t,handleChange:r,handleRemove:a,data:o})=>{const{t:l}=m.useTranslation(),[i,{setTrue:c}]=O.useBoolean(!1),[d,{setTrue:u,setFalse:p}]=O.useBoolean(!1),{ref:f,handleRef:v}=rn.useSortable({id:e.id,index:t}),_=T=>{r({...e,name:T})},w=T=>{r({...e,minKey:T})},x=T=>{r({...e,color:T})};return n.jsxs(s.Flex,{ref:f,gap:"sm",justify:"flex-start",align:"center",direction:"row",wrap:"nowrap",onMouseEnter:u,onMouseLeave:p,children:[n.jsx(s.Center,{style:{minWidth:"30px",maxWidth:"30px",flex:0},children:d?n.jsx(s.ActionIcon,{size:"xs",ref:v,variant:"subtle",children:n.jsx(S.IconGripVertical,{})}):n.jsx(s.Badge,{size:"sm",variant:"light",children:t+1})}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",style:{flex:1},children:[n.jsx(s.TextInput,{size:"xs",value:e.name,placeholder:l("viz.pie_chart.color.map.name"),onChange:T=>_(T.currentTarget.value),onClick:c,error:i&&!e.name}),n.jsx(s.ColorInput,{styles:{root:{flexGrow:1}},popoverProps:{withinPortal:!0,zIndex:340},size:"xs",value:e.color,onChange:x,onClick:c,error:i&&!e.color}),n.jsx(L,{label:"",placeholder:l("viz.merico_linear_gauge.sections.min_key_placeholder"),onChange:w,value:e.minKey,clearable:!0,unsetKey:"viz.merico_linear_gauge.sections.min_key.zero",size:"xs"})]}),n.jsx("div",{style:{minWidth:"40px",maxWidth:"40px",flex:0},children:n.jsx(s.CloseButton,{onClick:a,size:"sm"})})]})},sw=({append:e})=>{const{t}=m.useTranslation(),r=()=>{e({name:"",color:"",minKey:""})};return n.jsxs(s.Flex,{gap:"sm",justify:"flex-start",align:"center",direction:"row",wrap:"nowrap",children:[n.jsx("div",{style:{minWidth:"30px",maxWidth:"30px",flex:0}}),n.jsx(s.Group,{wrap:"nowrap",style:{flex:1},children:n.jsx(s.Button,{size:"xs",variant:"subtle",onClick:r,leftSection:n.jsx(S.IconPlus,{size:14}),children:t("viz.merico_linear_gauge.sections.add")})}),n.jsx("div",{style:{minWidth:"40px",maxWidth:"40px",flex:0}})]})},ow=Object.entries(b.pick(We.graphics,["compared","level","depth","multiple"])).map(([e,t])=>({name:e,colors:Object.values(t)}));function lw(e){const t=e.length;if(t===0)return"";const r={output:"percent",mantissa:4,trimMantissa:!0},a=b.divide(1,t),o=[];return e.forEach((i,c)=>{o.push(`${i} ${Ee(c*a).format(r)}`),o.push(`${i} ${Ee((c+1)*a).format(r)}`)}),`linear-gradient(90deg, ${o.join(",")})`}const iw=({value:e,onChange:t})=>{const{t:r,i18n:a}=m.useTranslation(),o=l=>{const i=e.map((c,d)=>({name:c.name,color:l[d],minKey:""}));for(let c=i.length-1;c<l.length;c++)i.push({name:"",color:l[c],minKey:""});t(i)};return n.jsxs(s.Menu,{withArrow:!0,shadow:"md",width:400,styles:{item:{overflowX:"hidden"}},children:[n.jsx(s.Menu.Target,{children:n.jsx(s.Button,{size:"compact-xs",variant:"subtle",rightSection:n.jsx(s.Combobox.Chevron,{size:"xs"}),children:r("viz.pie_chart.color.map.use_a_palette")})}),n.jsxs(s.Menu.Dropdown,{children:[n.jsx(s.Menu.Label,{children:r("viz.pie_chart.color.map.click_to_apply_palette")}),n.jsx(s.Menu.Divider,{}),ow.map(l=>n.jsx(s.Menu.Item,{onClick:()=>o(l.colors),children:n.jsx(s.Box,{h:28,style:{backgroundImage:lw(l.colors)}})},l.name))]})]})},cw=h.forwardRef(({value:e,onChange:t,data:r},a)=>{const{t:o}=m.useTranslation(),l=h.useMemo(()=>e.map(p=>({id:Te.v4(),...p})),[e]),i=p=>{t([...e,p])},c=p=>{const f=[...e];f.splice(p,1),t(f)},d=p=>f=>{const v=[...e];v[p]=f,t(v)},u=p=>{const{source:f,target:v}=p.operation,_=jn.move(l,f,v);t(_.map(w=>b.omit(w,"id")))};return n.jsxs(s.Stack,{ref:a,pt:4,children:[n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Text,{size:"sm",fw:"500",mb:-4,children:o("viz.merico_linear_gauge.sections.label")}),n.jsx(iw,{value:e,onChange:t})]}),n.jsx(nn.DragDropProvider,{onDragEnd:u,children:l.map((p,f)=>n.jsx(aw,{row:p,handleChange:d(f),handleRemove:()=>c(f),index:f,data:r},p.id))}),n.jsx(sw,{append:i})]})});function dw({context:e}){const{value:t,set:r}=q(e.instanceData,"config"),{t:a}=m.useTranslation(),o=e.data,l=h.useMemo(()=>b.defaultsDeep({},t,Wr()),[t]),i=y.useForm({defaultValues:l}),{handleSubmit:c,formState:d,reset:u}=i;return h.useEffect(()=>{i.reset(l)},[l]),n.jsxs("form",{onSubmit:c(r),children:[n.jsx(se,{canSubmit:d.isDirty}),n.jsxs(s.Stack,{gap:"lg",pt:"xs",px:"xs",children:[n.jsx(y.Controller,{name:"stats.top",control:i.control,render:({field:p})=>n.jsx(Ue,{label:a("chart.stats.template.above_chart"),styles:{root:{flexGrow:1,minHeight:"240px"}},autoSubmit:!0,...p},"stats.top")}),n.jsx(s.Divider,{}),n.jsx(y.Controller,{name:"value",control:i.control,render:({field:p})=>n.jsx(L,{label:a("viz.merico_linear_gauge.value"),...p,clearable:!0})}),n.jsx(y.Controller,{name:"sections",control:i.control,render:({field:p})=>n.jsx(cw,{...p,data:o})})]})]})}const uw={displayName:"viz.merico_linear_gauge.viz_name",displayGroup:"chart.groups.merico_suite",migrator:new Rm,name:"merico_linear_gauge",viewRender:nw,configRender:dw,createConfig:()=>({version:1,config:Wr()}),translation:rw},Ur={styles:{justify:"space-around",align:"start"},metrics:[]};function pw(){return{id:new Date().getTime().toString(),names:{value:"Value",basis:"Basis"},data_keys:{value:"",basis:""},formatter:de,postfix:{type:"text",value:""}}}const cl=({postfix:e})=>e?n.jsxs(n.Fragment,{children:[n.jsx(s.Text,{size:"12px",c:"#818388",sx:{lineHeight:1},children:"/"}),n.jsx(s.Text,{size:"12px",c:"#818388",sx:{lineHeight:1},children:e})]}):null,hw=k.observer(({metric:e,variableValueMap:t})=>{const{names:r,data_keys:a,formatter:o,postfix:l}=e,i=H(),c=h.useMemo(()=>{if(l.type==="text"&&l.value)return l.value;if(l.type==="filter-option-label"&&l.value){const d=i.filters.getSelectOption(l.value);return d?d.label:null}return null},[l,i]);return n.jsxs(s.Stack,{gap:18,children:[n.jsxs(s.Stack,{gap:12,children:[n.jsx(s.Text,{size:"14px",c:"#818388",children:r.value}),n.jsxs(s.Group,{gap:"2px",align:"baseline",children:[n.jsx(s.Text,{size:"24px",fw:"bold",c:"#3D3E45",sx:{lineHeight:1},children:Y(t[a.value],o)}),n.jsx(cl,{postfix:c})]})]}),n.jsxs(s.Stack,{gap:12,children:[n.jsx(s.Text,{size:"14px",c:"#818388",children:r.basis}),n.jsxs(s.Group,{gap:"2px",align:"baseline",children:[n.jsx(s.Text,{size:"12px",c:"#3D3E45",sx:{lineHeight:1},children:Y(t[a.basis],o)}),n.jsx(cl,{postfix:c})]})]})]})}),gw=k.observer(({context:e,instance:t})=>{const{value:r}=q(e.instanceData,"config"),{variables:a}=e,o=h.useMemo(()=>b.defaults({},r,Ur),[r]),l=e.data,i=h.useMemo(()=>Er(l,a),[a,l]),{width:c,height:d}=e.viewport;return!c||!d||!o?null:n.jsx(s.Flex,{w:`${c}px`,h:`${d}px`,justify:o.styles.justify,align:o.styles.align,direction:"row",wrap:"nowrap",sx:{overflow:"hidden"},children:o.metrics.map(u=>n.jsx(hw,{metric:u,variableValueMap:i},u.id))})}),fw=k.observer(h.forwardRef(({value:e,onChange:t},r)=>{const{t:a,i18n:o}=m.useTranslation(),i=G().filters.selects,c=p=>{if(!p)return;t({type:p,value:e.value})},d=p=>{if(p===null)return p;t({type:e.type,value:p})},u=h.useMemo(()=>[{label:a("viz.merico_stats.metric.postfix_type.text"),value:"text"},{label:a("viz.merico_stats.metric.postfix_type.filter"),value:"filter-option-label"}],[o.language]);return n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(s.Select,{label:a("viz.merico_stats.metric.postfix_type.label"),data:u,value:e.type,onChange:c}),e.type==="text"&&n.jsx(s.TextInput,{label:a("viz.merico_stats.metric.postfix_content"),value:e.value,onChange:p=>{d(p.currentTarget.value)}}),e.type==="filter-option-label"&&n.jsx(s.Select,{label:a("viz.merico_stats.metric.postfix_filter"),value:e.value,onChange:d,data:i})]})}));function bw({control:e,index:t,watch:r,variableOptions:a}){const{t:o}=m.useTranslation();return r(`metrics.${t}.postfix`),n.jsxs(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(y.Controller,{name:`metrics.${t}.names.value`,control:e,render:({field:l})=>n.jsx(s.TextInput,{label:o("viz.merico_stats.metric.metric_name"),required:!0,sx:{flex:1},...l})}),n.jsx(y.Controller,{name:`metrics.${t}.data_keys.value`,control:e,render:({field:l})=>n.jsx(s.Select,{label:o("viz.merico_stats.metric.metric_data_field"),required:!0,data:a,sx:{flex:1},...l})})]}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(y.Controller,{name:`metrics.${t}.names.basis`,control:e,render:({field:l})=>n.jsx(s.TextInput,{label:o("viz.merico_stats.metric.basis_name"),required:!0,sx:{flex:1},...l})}),n.jsx(y.Controller,{name:`metrics.${t}.data_keys.basis`,control:e,render:({field:l})=>n.jsx(s.Select,{label:o("viz.merico_stats.metric.basis_data_field"),required:!0,data:a,sx:{flex:1},...l})})]}),n.jsx(s.Divider,{mb:-15,variant:"dashed",label:o("numbro.format.label"),labelPosition:"center"}),n.jsx(y.Controller,{name:`metrics.${t}.formatter`,control:e,render:({field:l})=>n.jsx(Ye,{...l})}),n.jsx(s.Divider,{mb:-15,variant:"dashed",label:o("viz.merico_stats.metric.others"),labelPosition:"center"}),n.jsx(y.Controller,{name:`metrics.${t}.postfix`,control:e,render:({field:l})=>n.jsx(fw,{...l})})]})}const yw=({control:e,watch:t,variables:r})=>{const{t:a}=m.useTranslation(),o=()=>pw(),l=(d,u)=>{const p=d.names.value.trim();return p||u+1},i=({field:d,index:u,fields:p})=>p.length<=1,c=h.useMemo(()=>r.map(d=>({label:d.name,value:d.name})),[r]);return n.jsxs(n.Fragment,{children:[n.jsx(s.Divider,{mt:15,variant:"dashed",label:a("viz.merico_stats.metric.labels"),labelPosition:"center"}),n.jsx(R,{control:e,watch:t,name:"metrics",getItem:o,addButtonText:a("chart.tooltip.additional_metrics.add"),deleteButtonText:a("chart.tooltip.additional_metrics.delete"),renderTabName:l,deleteDisalbed:i,children:({field:d,index:u})=>n.jsx(bw,{control:e,index:u,variableOptions:c,watch:t})})]})};function vw({control:e,watch:t}){const{t:r}=m.useTranslation();return t("styles"),n.jsxs(n.Fragment,{children:[n.jsx(s.Divider,{mt:15,variant:"dashed",label:r("style.label"),labelPosition:"center"}),n.jsxs(s.Group,{children:[n.jsx(y.Controller,{name:"styles.justify",control:e,render:({field:a})=>n.jsx(Hg,{sx:{flex:1},...a})}),n.jsx(y.Controller,{name:"styles.align",control:e,render:({field:a})=>n.jsx(Rg,{label:r("viz.merico_stats.align_items.label"),sx:{flex:1},...a})})]})]})}function _w({context:e}){const{value:t,set:r}=q(e.instanceData,"config"),{variables:a}=e,o=h.useMemo(()=>b.defaultsDeep({},t,Ur),[t]),{control:l,handleSubmit:i,watch:c,formState:d,reset:u}=y.useForm({defaultValues:o});return h.useEffect(()=>{u(o)},[o]),n.jsx("form",{onSubmit:i(r),children:n.jsxs(s.Stack,{gap:"xs",children:[n.jsx(se,{canSubmit:d.isDirty}),n.jsx(vw,{control:l,watch:c}),n.jsx(yw,{control:l,watch:c,variables:a})]})})}function mw(e){const{metrics:t,...r}=e;return{...r,metrics:t.map(a=>({...a,postfix:a.postfix??{type:"text",value:""}}))}}const ww=[{lang:"en",resources:{merico_stats:{viz_name:"Merico Stats",align_items:{label:"Vertical Align"},metric:{labels:"Metrics",metric_name:"Metric Name",metric_data_field:"Metric Data Field",basis_name:"Basis Name",basis_data_field:"Basis Data Field",others:"Others",postfix_type:{label:"Postfix Type",text:"Text",filter:"Filter Option Label"},postfix_content:"Postfix Content",postfix_filter:"Postfix Filter"}}}},{lang:"zh",resources:{merico_stats:{viz_name:"思码逸数据指标",align_items:{label:"垂直对齐方式"},metric:{labels:"指标",metric_name:"指标名称",metric_data_field:"指标数据字段",basis_name:"基准名",basis_data_field:"基准数据字段",others:"其他",postfix_type:{label:"后缀类型",text:"文本",filter:"筛选器选项文案"},postfix_content:"后缀文案",postfix_filter:"筛选器"}}}}];class xw extends J{constructor(){super(...arguments);V(this,"VERSION",2)}configVersions(){this.version(1,r=>({...r,version:1,config:r.config})),this.version(2,r=>({...r,version:2,config:mw(r.config)}))}}const Cw={displayName:"viz.merico_stats.viz_name",displayGroup:"chart.groups.merico_suite",migrator:new xw,name:"merico-stats",viewRender:gw,configRender:_w,createConfig:()=>({version:2,config:Ur}),translation:ww},Sw=[{lang:"en",resources:{pareto_chart:{viz_name:"Pareto Chart",line_80_20:{label:"80-20 Line",label_template:"Label Template",click_to_see_params:"Click to see params for Label Template",param_section_note_1:"80-20 line stuff",param_section_note_2:"chart configs"},click_series:{label:"Click chart series"}}}},{lang:"zh",resources:{pareto_chart:{viz_name:"帕累托图",line_80_20:{label:"80/20线",label_template:"线上文案模板",click_to_see_params:"点击查看线上文案模板的参数",param_section_note_1:"80-20线相关",param_section_note_2:"图表配置信息"},click_series:{label:"点击柱或线"}}}}],dl={id:"builtin:echarts:click-echart:series",displayName:"viz.pareto_chart.click_series.label",nameRender:kw,configRender:Tw,payload:[{name:"type",description:"Always 'click'",valueType:"string"},{name:"seriesType",description:"'line' | 'bar'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function Tw(e){return n.jsx(n.Fragment,{})}function kw(e){const{t}=m.useTranslation();return n.jsx(s.Text,{size:"sm",children:t("viz.pareto_chart.click_series.label")})}const ul={label_template:"${percentage.x} of ${x_axis.name} causes ${percentage.y} of ${bar.name}",color:"#789AB4"},Kr={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:_e(),overflow:Ie()}},data_key:"value",bar:{name:"Value",nameAlignment:"left",color:"#228be6",label_formatter:de,unit:K()},line:{name:"Value",nameAlignment:"right",color:"red"},dataZoom:kt,markLine:ul,reference_lines:[]};function Cn(e){return Y(e,{output:"percent",mantissa:0,absolute:!1})}function Dw(e){const t=e.value[1];try{return Cn(t)}catch(r){return console.error(r),t}}function zw(e){function t(r){let a=r;if(typeof r=="object"&&(Array.isArray(r.value)&&r.value.length===2?a=r.value[1]:a=r.value),!e.bar.label_formatter)return a;try{return Y(a,e.bar.label_formatter)}catch(o){return console.error(o),a}}return{bar:t,line:Dw,lineValue:Cn}}function Mw(e,t,r){const{label_template:a}=e.markLine;if(!a)return"";const o={...e,percentage:t,count:r},l=Object.keys(o),i=Object.values(o);return new Function(...l,`return \`${a}\`;`)(...i)}function Iw(e){const t=Number(Ee(e).format({output:"number",mantissa:2}));return t<.33?"left":t>.66?"right":"center"}function Vw(e,t){if(t.length===0)return{};const r=t.findIndex(d=>d[1]>=.8);if(r===-1)return{};const a=t[r],o=(r+1)/t.length,l={x:Cn(o),y:Cn(a[1])},i={left:r+1,right:t.length-r-1},c=a[0];return c?{markLine:{name:"",silent:!0,symbol:"triangle",symbolRotate:180,symbolSize:[10,8],data:[{name:"",symbol:"none",xAxis:c,lineStyle:{color:e.markLine.color},label:{formatter:Mw(e,l,i),position:"end",align:Iw(o)}}]},markArea:{name:"",silent:!0,itemStyle:{color:"rgba(47, 140, 192, 0.05)"},data:[[{coord:["min",0]},{xAxis:c}]]}}:{}}function Pw(e,t,r){const a=t.reduce((c,d)=>c+d[1],0),o=t.reduce((c,d,u)=>{const p=u===0?0:c[u-1][1];return c.push([d[0],p+d[1]]),c},[]).map(c=>[c[0],c[1]/a]),{markLine:l,markArea:i}=Vw(e,o);return[{name:e.bar.name,type:"bar",barMaxWidth:20,itemStyle:{color:e.bar.color},label:{show:!1,position:"top",formatter:r.bar},yAxisIndex:0,data:t},{name:e.line.name,type:"line",itemStyle:{color:e.line.color},symbolSize:2,lineStyle:{width:1,shadowColor:"rgba(255,255,255,1)",shadowBlur:0,shadowOffsetX:0,shadowOffsetY:1},label:{show:!1,position:"top",formatter:r.line},yAxisIndex:1,data:o,markLine:l,markArea:i}]}function $w(e){const t=e.bar.unit;return t.show_in_tooltip?t.text:""}const Aw=(e,t)=>r=>{const a=Array.isArray(r)?r:[r];if(a.length===0)return"";const o=$w(e),l=a.map(d=>{const{seriesName:u,componentSubType:p}=d,[f,v]=d.value;return u?p==="bar"?`
|
|
338
|
+
`}})}function Fm(e,t,r){const{overflow:a,rotate:o}=e.x_axis.axisLabel,l=Ke(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:o,...l,formatter:r},splitArea:{show:!1,areaStyle:{color:"#E7E7E9"}},splitLine:{show:!1},nameLocation:"center",nameGap:25,nameTextStyle:{fontWeight:"bold",align:"center"},z:3})}function Qm(e,t){const{nameAlignment:r,data_key:a,...o}=e.y_axis,{overflow:l,rotate:i}=e.y_axis.axisLabel,c=Ke(l.on_axis);return X.getYAxis({...o,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 jm(e,t,r){if(!e.x_axis.data_key||!e.y_axis.data_key||!e.heat_block.data_key)return{};const a=r.reduce((x,T)=>{const D=Re(T,t);return x[T.name]=Be(T,D),x},{}),o=Em(e),l=Bm(e),i=un(e.visualMap,a),{min:c,max:d}=i,u=$(e.x_axis.data_key),p=$(e.y_axis.data_key),f=$(e.heat_block.data_key),v=b.uniq(t[u.queryID].map(x=>x[u.columnKey])),_=t[u.queryID].map(x=>{const T=b.get(x,u.columnKey),D=b.get(x,p.columnKey),z=b.get(x,f.columnKey),I={value:[T,D,z]},{followVisualMap:E,color:A}=dr(z,c,d,e.visualMap);return E||(I.visualMap=!1,I.itemStyle={color:A}),I});return{xAxis:Fm(e,v,o.x_axis),yAxis:Qm(e,o.y_axis),series:Lm(e,_),tooltip:Gm(e,t,o,l),grid:qm(e),visualMap:i}}function Wm({conf:e,data:t,width:r,height:a,interactionManager:o,variables:l,instance:i}){const c=h.useMemo(()=>{const w=$(e.x_axis.data_key),x=$(e.y_axis.data_key);return b.keyBy(t[w.queryID],T=>`${T[w.columnKey]}---${T[x.columnKey]}`)},[t,e.x_axis.data_key,e.y_axis.data_key]),d=Ve(o.triggerManager,il.id),u=h.useCallback(w=>{const[x,T]=w.value,D=b.get(c,`${x}---${T}`,{error:"rowData is not found"});d.forEach(z=>{o.runInteraction(z.id,{...w,rowData:D})})},[c,d,o]),p=h.useRef(null),f=h.useCallback(()=>{var x;const w=(x=p.current)==null?void 0:x.getEchartsInstance();w&&fe(i,w.getOption())},[i]),v=h.useMemo(()=>({click:u,finished:f}),[u,f]),_=h.useMemo(()=>jm(e,t,l),[e,t]);return n.jsx(he,{echarts:ce,option:_,ref:p,style:{width:r,height:a},onEvents:v,notMerge:!0,theme:"merico-light"})}function Um({context:e,instance:t}){const r=Pe({vizManager:e.vizManager,instance:t}),{value:a}=q(e.instanceData,"config"),{variables:o}=e,l=h.useMemo(()=>b.defaults({},a,jr),[a]),i=e.data,{width:c,height:d}=e.viewport;return!c||!d?null:n.jsx(ve,{width:c,height:d,children:n.jsx(Wm,{instance:t,variables:o,width:qe(c),height:Le(d),data:i,conf:l,interactionManager:r})})}const Km=[{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 Ym(e){const{visualMap:t=at(),heat_block:{min:r,max:a,...o},...l}=e;return{...l,heat_block:o,visualMap:{...at(),min:r,max:a}}}function Xm(e){const t=e.tooltip.metrics;return{...e,tooltip:{...e.tooltip,metrics:t.map(r=>({...r,unit:r.unit??K()}))}}}function Zm(e){const{heat_block:t}=e;return{...e,heat_block:{...t,unit:t.unit??K()}}}class Jm extends J{constructor(){super(...arguments);V(this,"VERSION",4)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,r=>({...r,version:2,config:Ym(r.config)})),this.version(3,r=>({...r,version:3,config:Xm(r.config)})),this.version(4,r=>({...r,version:4,config:Zm(r.config)}))}}const Hm={displayName:"viz.merico_heatmap.viz_name",displayGroup:"chart.groups.merico_suite",migrator:new Jm,name:"merico-heatmap",viewRender:Um,configRender:Pm,createConfig:()=>({version:4,config:jr}),triggers:[il],translation:Km};class Rm extends J{constructor(){super(...arguments);V(this,"VERSION",1)}configVersions(){this.version(1,r=>({version:1,config:r}))}}const Wr=()=>({value:"",sections:[{name:"较差",color:"#ff0034",minKey:""},{name:"一般",color:"#ffc04d",minKey:""},{name:"良好",color:"#adcfe4",minKey:""},{name:"优秀",color:"#32cb95",minKey:""}],stats:{top:"",bottom:""}}),ew=(e,t)=>{const r={value:b.get(me(t,e.value),"0","null"),sections:e.sections.map(o=>({name:o.name,color:o.color,min:o.minKey?b.get(me(t,o.minKey),"0","null"):0,pointer:!1,pointer_equal:!1}))},a=r.value;for(let o=0;o<r.sections.length&&!(a<r.sections[o].min);o++)r.sections[o].pointer=!0,r.sections[o].pointer_equal=a===r.sections[o].min,o>0&&(r.sections[o-1].pointer=!1,r.sections[o-1].pointer_equal=!1);return r},Xt={section:"_section_1jopp_1",min:"_min_1jopp_12",name:"_name_1jopp_19",pointer:"_pointer_1jopp_23",pointer_equal:"_pointer_equal_1jopp_30"};function tw({conf:e,data:t,width:r,height:a}){const o=h.useMemo(()=>ew(e,t),[e,t]);return!r||!a?null:n.jsx(s.Group,{justify:"flex-start",grow:!0,wrap:"nowrap",gap:0,pt:"sm",mah:a,w:r,children:o.sections.map(l=>n.jsxs(s.Center,{className:Xt.section,style:{backgroundColor:l.color},children:[n.jsx(s.Text,{size:"sm",className:Xt.name,children:l.name}),l.min>0?n.jsx(s.Text,{size:"xs",className:Xt.min,children:l.min}):null,l.pointer?n.jsx(S.IconArrowUp,{className:`${Xt.pointer} ${l.pointer_equal?Xt.pointer_equal:""}`,stroke:1.5}):null]},`${l.name}-${l.color}-${l.min}`))})}function nw({context:e}){const{value:t}=q(e.instanceData,"config"),r=h.useMemo(()=>b.defaults({},t,Wr()),[t]),a=e.data,{width:o,height:l}=e.viewport,[i,c]=h.useState(0),[d,u]=h.useState(0),p=Math.max(0,Le(l)-i-d),f=qe(o);return n.jsxs(ve,{width:o,height:l,children:[n.jsx(zt,{onHeightChange:c,value:r.stats.top,context:e}),n.jsx(tw,{width:f,height:p,data:a,conf:r})]})}const rw=[{lang:"en",resources:{merico_linear_gauge:{viz_name:"Merico Linear Gauge",sections:{label:"Sections",min_key:{placeholder:"Min value",zero:"Zero"},add:"Add a section"},value:"Value"}}},{lang:"zh",resources:{merico_linear_gauge:{viz_name:"思码逸线性仪表盘",sections:{label:"配置区间",min_key:{placeholder:"区间最小值",zero:"零"},add:"增加一个区间"},value:"值"}}}],aw=({row:e,index:t,handleChange:r,handleRemove:a,data:o})=>{const{t:l}=m.useTranslation(),[i,{setTrue:c}]=O.useBoolean(!1),[d,{setTrue:u,setFalse:p}]=O.useBoolean(!1),{ref:f,handleRef:v}=rn.useSortable({id:e.id,index:t}),_=T=>{r({...e,name:T})},w=T=>{r({...e,minKey:T})},x=T=>{r({...e,color:T})};return n.jsxs(s.Flex,{ref:f,gap:"sm",justify:"flex-start",align:"center",direction:"row",wrap:"nowrap",onMouseEnter:u,onMouseLeave:p,children:[n.jsx(s.Center,{style:{minWidth:"30px",maxWidth:"30px",flex:0},children:d?n.jsx(s.ActionIcon,{size:"xs",ref:v,variant:"subtle",children:n.jsx(S.IconGripVertical,{})}):n.jsx(s.Badge,{size:"sm",variant:"light",children:t+1})}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",style:{flex:1},children:[n.jsx(s.TextInput,{size:"xs",value:e.name,placeholder:l("viz.pie_chart.color.map.name"),onChange:T=>_(T.currentTarget.value),onClick:c,error:i&&!e.name}),n.jsx(s.ColorInput,{styles:{root:{flexGrow:1}},popoverProps:{withinPortal:!0,zIndex:340},size:"xs",value:e.color,onChange:x,onClick:c,error:i&&!e.color}),n.jsx(L,{label:"",placeholder:l("viz.merico_linear_gauge.sections.min_key_placeholder"),onChange:w,value:e.minKey,clearable:!0,unsetKey:"viz.merico_linear_gauge.sections.min_key.zero",size:"xs"})]}),n.jsx("div",{style:{minWidth:"40px",maxWidth:"40px",flex:0},children:n.jsx(s.CloseButton,{onClick:a,size:"sm"})})]})},sw=({append:e})=>{const{t}=m.useTranslation(),r=()=>{e({name:"",color:"",minKey:""})};return n.jsxs(s.Flex,{gap:"sm",justify:"flex-start",align:"center",direction:"row",wrap:"nowrap",children:[n.jsx("div",{style:{minWidth:"30px",maxWidth:"30px",flex:0}}),n.jsx(s.Group,{wrap:"nowrap",style:{flex:1},children:n.jsx(s.Button,{size:"xs",variant:"subtle",onClick:r,leftSection:n.jsx(S.IconPlus,{size:14}),children:t("viz.merico_linear_gauge.sections.add")})}),n.jsx("div",{style:{minWidth:"40px",maxWidth:"40px",flex:0}})]})},ow=Object.entries(b.pick(We.graphics,["compared","level","depth","multiple"])).map(([e,t])=>({name:e,colors:Object.values(t)}));function lw(e){const t=e.length;if(t===0)return"";const r={output:"percent",mantissa:4,trimMantissa:!0},a=b.divide(1,t),o=[];return e.forEach((i,c)=>{o.push(`${i} ${Ee(c*a).format(r)}`),o.push(`${i} ${Ee((c+1)*a).format(r)}`)}),`linear-gradient(90deg, ${o.join(",")})`}const iw=({value:e,onChange:t})=>{const{t:r,i18n:a}=m.useTranslation(),o=l=>{const i=e.map((c,d)=>({name:c.name,color:l[d],minKey:""}));for(let c=i.length-1;c<l.length;c++)i.push({name:"",color:l[c],minKey:""});t(i)};return n.jsxs(s.Menu,{withArrow:!0,shadow:"md",width:400,styles:{item:{overflowX:"hidden"}},children:[n.jsx(s.Menu.Target,{children:n.jsx(s.Button,{size:"compact-xs",variant:"subtle",rightSection:n.jsx(s.Combobox.Chevron,{size:"xs"}),children:r("viz.pie_chart.color.map.use_a_palette")})}),n.jsxs(s.Menu.Dropdown,{children:[n.jsx(s.Menu.Label,{children:r("viz.pie_chart.color.map.click_to_apply_palette")}),n.jsx(s.Menu.Divider,{}),ow.map(l=>n.jsx(s.Menu.Item,{onClick:()=>o(l.colors),children:n.jsx(s.Box,{h:28,style:{backgroundImage:lw(l.colors)}})},l.name))]})]})},cw=h.forwardRef(({value:e,onChange:t,data:r},a)=>{const{t:o}=m.useTranslation(),l=h.useMemo(()=>e.map(p=>({id:Te.v4(),...p})),[e]),i=p=>{t([...e,p])},c=p=>{const f=[...e];f.splice(p,1),t(f)},d=p=>f=>{const v=[...e];v[p]=f,t(v)},u=p=>{const{source:f,target:v}=p.operation,_=jn.move(l,f,v);t(_.map(w=>b.omit(w,"id")))};return n.jsxs(s.Stack,{ref:a,pt:4,children:[n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Text,{size:"sm",fw:"500",mb:-4,children:o("viz.merico_linear_gauge.sections.label")}),n.jsx(iw,{value:e,onChange:t})]}),n.jsx(nn.DragDropProvider,{onDragEnd:u,children:l.map((p,f)=>n.jsx(aw,{row:p,handleChange:d(f),handleRemove:()=>c(f),index:f,data:r},p.id))}),n.jsx(sw,{append:i})]})});function dw({context:e}){const{value:t,set:r}=q(e.instanceData,"config"),{t:a}=m.useTranslation(),o=e.data,l=h.useMemo(()=>b.defaultsDeep({},t,Wr()),[t]),i=y.useForm({defaultValues:l}),{handleSubmit:c,formState:d,reset:u}=i;return h.useEffect(()=>{i.reset(l)},[l]),n.jsxs("form",{onSubmit:c(r),children:[n.jsx(se,{canSubmit:d.isDirty}),n.jsxs(s.Stack,{gap:"lg",pt:"xs",px:"xs",children:[n.jsx(y.Controller,{name:"stats.top",control:i.control,render:({field:p})=>n.jsx(Ue,{label:a("chart.stats.template.above_chart"),styles:{root:{flexGrow:1,minHeight:"240px"}},autoSubmit:!0,...p},"stats.top")}),n.jsx(s.Divider,{}),n.jsx(y.Controller,{name:"value",control:i.control,render:({field:p})=>n.jsx(L,{label:a("viz.merico_linear_gauge.value"),...p,clearable:!0})}),n.jsx(y.Controller,{name:"sections",control:i.control,render:({field:p})=>n.jsx(cw,{...p,data:o})})]})]})}const uw={displayName:"viz.merico_linear_gauge.viz_name",displayGroup:"chart.groups.merico_suite",migrator:new Rm,name:"merico_linear_gauge",viewRender:nw,configRender:dw,createConfig:()=>({version:1,config:Wr()}),translation:rw},Ur={styles:{justify:"space-around",align:"start"},metrics:[]};function pw(){return{id:new Date().getTime().toString(),names:{value:"Value",basis:"Basis"},data_keys:{value:"",basis:""},formatter:de,postfix:{type:"text",value:""}}}const cl=({postfix:e})=>e?n.jsxs(n.Fragment,{children:[n.jsx(s.Text,{size:"12px",c:"#818388",sx:{lineHeight:1},children:"/"}),n.jsx(s.Text,{size:"12px",c:"#818388",sx:{lineHeight:1},children:e})]}):null,hw=k.observer(({metric:e,variableValueMap:t})=>{const{names:r,data_keys:a,formatter:o,postfix:l}=e,i=H(),c=h.useMemo(()=>{if(l.type==="text"&&l.value)return l.value;if(l.type==="filter-option-label"&&l.value){const d=i.filters.getSelectOption(l.value);return d?d.label:null}return null},[l,i]);return n.jsxs(s.Stack,{gap:18,children:[n.jsxs(s.Stack,{gap:12,children:[n.jsx(s.Text,{size:"14px",c:"#818388",children:r.value}),n.jsxs(s.Group,{gap:"2px",align:"baseline",children:[n.jsx(s.Text,{size:"24px",fw:"bold",c:"#3D3E45",sx:{lineHeight:1},children:Y(t[a.value],o)}),n.jsx(cl,{postfix:c})]})]}),n.jsxs(s.Stack,{gap:12,children:[n.jsx(s.Text,{size:"14px",c:"#818388",children:r.basis}),n.jsxs(s.Group,{gap:"2px",align:"baseline",children:[n.jsx(s.Text,{size:"12px",c:"#3D3E45",sx:{lineHeight:1},children:Y(t[a.basis],o)}),n.jsx(cl,{postfix:c})]})]})]})}),gw=k.observer(({context:e,instance:t})=>{const{value:r}=q(e.instanceData,"config"),{variables:a}=e,o=h.useMemo(()=>b.defaults({},r,Ur),[r]),l=e.data,i=h.useMemo(()=>Er(l,a),[a,l]),{width:c,height:d}=e.viewport;return!c||!d||!o?null:n.jsx(s.Flex,{w:`${c}px`,h:`${d}px`,justify:o.styles.justify,align:o.styles.align,direction:"row",wrap:"nowrap",sx:{overflow:"hidden"},children:o.metrics.map(u=>n.jsx(hw,{metric:u,variableValueMap:i},u.id))})}),fw=k.observer(h.forwardRef(({value:e,onChange:t},r)=>{const{t:a,i18n:o}=m.useTranslation(),i=F().filters.selects,c=p=>{if(!p)return;t({type:p,value:e.value})},d=p=>{if(p===null)return p;t({type:e.type,value:p})},u=h.useMemo(()=>[{label:a("viz.merico_stats.metric.postfix_type.text"),value:"text"},{label:a("viz.merico_stats.metric.postfix_type.filter"),value:"filter-option-label"}],[o.language]);return n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(s.Select,{label:a("viz.merico_stats.metric.postfix_type.label"),data:u,value:e.type,onChange:c}),e.type==="text"&&n.jsx(s.TextInput,{label:a("viz.merico_stats.metric.postfix_content"),value:e.value,onChange:p=>{d(p.currentTarget.value)}}),e.type==="filter-option-label"&&n.jsx(s.Select,{label:a("viz.merico_stats.metric.postfix_filter"),value:e.value,onChange:d,data:i})]})}));function bw({control:e,index:t,watch:r,variableOptions:a}){const{t:o}=m.useTranslation();return r(`metrics.${t}.postfix`),n.jsxs(s.Stack,{my:0,p:"md",pr:40,sx:{border:"1px solid #eee",position:"relative"},children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(y.Controller,{name:`metrics.${t}.names.value`,control:e,render:({field:l})=>n.jsx(s.TextInput,{label:o("viz.merico_stats.metric.metric_name"),required:!0,sx:{flex:1},...l})}),n.jsx(y.Controller,{name:`metrics.${t}.data_keys.value`,control:e,render:({field:l})=>n.jsx(s.Select,{label:o("viz.merico_stats.metric.metric_data_field"),required:!0,data:a,sx:{flex:1},...l})})]}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(y.Controller,{name:`metrics.${t}.names.basis`,control:e,render:({field:l})=>n.jsx(s.TextInput,{label:o("viz.merico_stats.metric.basis_name"),required:!0,sx:{flex:1},...l})}),n.jsx(y.Controller,{name:`metrics.${t}.data_keys.basis`,control:e,render:({field:l})=>n.jsx(s.Select,{label:o("viz.merico_stats.metric.basis_data_field"),required:!0,data:a,sx:{flex:1},...l})})]}),n.jsx(s.Divider,{mb:-15,variant:"dashed",label:o("numbro.format.label"),labelPosition:"center"}),n.jsx(y.Controller,{name:`metrics.${t}.formatter`,control:e,render:({field:l})=>n.jsx(Ye,{...l})}),n.jsx(s.Divider,{mb:-15,variant:"dashed",label:o("viz.merico_stats.metric.others"),labelPosition:"center"}),n.jsx(y.Controller,{name:`metrics.${t}.postfix`,control:e,render:({field:l})=>n.jsx(fw,{...l})})]})}const yw=({control:e,watch:t,variables:r})=>{const{t:a}=m.useTranslation(),o=()=>pw(),l=(d,u)=>{const p=d.names.value.trim();return p||u+1},i=({field:d,index:u,fields:p})=>p.length<=1,c=h.useMemo(()=>r.map(d=>({label:d.name,value:d.name})),[r]);return n.jsxs(n.Fragment,{children:[n.jsx(s.Divider,{mt:15,variant:"dashed",label:a("viz.merico_stats.metric.labels"),labelPosition:"center"}),n.jsx(R,{control:e,watch:t,name:"metrics",getItem:o,addButtonText:a("chart.tooltip.additional_metrics.add"),deleteButtonText:a("chart.tooltip.additional_metrics.delete"),renderTabName:l,deleteDisalbed:i,children:({field:d,index:u})=>n.jsx(bw,{control:e,index:u,variableOptions:c,watch:t})})]})};function vw({control:e,watch:t}){const{t:r}=m.useTranslation();return t("styles"),n.jsxs(n.Fragment,{children:[n.jsx(s.Divider,{mt:15,variant:"dashed",label:r("style.label"),labelPosition:"center"}),n.jsxs(s.Group,{children:[n.jsx(y.Controller,{name:"styles.justify",control:e,render:({field:a})=>n.jsx(Hg,{sx:{flex:1},...a})}),n.jsx(y.Controller,{name:"styles.align",control:e,render:({field:a})=>n.jsx(Rg,{label:r("viz.merico_stats.align_items.label"),sx:{flex:1},...a})})]})]})}function _w({context:e}){const{value:t,set:r}=q(e.instanceData,"config"),{variables:a}=e,o=h.useMemo(()=>b.defaultsDeep({},t,Ur),[t]),{control:l,handleSubmit:i,watch:c,formState:d,reset:u}=y.useForm({defaultValues:o});return h.useEffect(()=>{u(o)},[o]),n.jsx("form",{onSubmit:i(r),children:n.jsxs(s.Stack,{gap:"xs",children:[n.jsx(se,{canSubmit:d.isDirty}),n.jsx(vw,{control:l,watch:c}),n.jsx(yw,{control:l,watch:c,variables:a})]})})}function mw(e){const{metrics:t,...r}=e;return{...r,metrics:t.map(a=>({...a,postfix:a.postfix??{type:"text",value:""}}))}}const ww=[{lang:"en",resources:{merico_stats:{viz_name:"Merico Stats",align_items:{label:"Vertical Align"},metric:{labels:"Metrics",metric_name:"Metric Name",metric_data_field:"Metric Data Field",basis_name:"Basis Name",basis_data_field:"Basis Data Field",others:"Others",postfix_type:{label:"Postfix Type",text:"Text",filter:"Filter Option Label"},postfix_content:"Postfix Content",postfix_filter:"Postfix Filter"}}}},{lang:"zh",resources:{merico_stats:{viz_name:"思码逸数据指标",align_items:{label:"垂直对齐方式"},metric:{labels:"指标",metric_name:"指标名称",metric_data_field:"指标数据字段",basis_name:"基准名",basis_data_field:"基准数据字段",others:"其他",postfix_type:{label:"后缀类型",text:"文本",filter:"筛选器选项文案"},postfix_content:"后缀文案",postfix_filter:"筛选器"}}}}];class xw extends J{constructor(){super(...arguments);V(this,"VERSION",2)}configVersions(){this.version(1,r=>({...r,version:1,config:r.config})),this.version(2,r=>({...r,version:2,config:mw(r.config)}))}}const Cw={displayName:"viz.merico_stats.viz_name",displayGroup:"chart.groups.merico_suite",migrator:new xw,name:"merico-stats",viewRender:gw,configRender:_w,createConfig:()=>({version:2,config:Ur}),translation:ww},Sw=[{lang:"en",resources:{pareto_chart:{viz_name:"Pareto Chart",line_80_20:{label:"80-20 Line",label_template:"Label Template",click_to_see_params:"Click to see params for Label Template",param_section_note_1:"80-20 line stuff",param_section_note_2:"chart configs"},click_series:{label:"Click chart series"}}}},{lang:"zh",resources:{pareto_chart:{viz_name:"帕累托图",line_80_20:{label:"80/20线",label_template:"线上文案模板",click_to_see_params:"点击查看线上文案模板的参数",param_section_note_1:"80-20线相关",param_section_note_2:"图表配置信息"},click_series:{label:"点击柱或线"}}}}],dl={id:"builtin:echarts:click-echart:series",displayName:"viz.pareto_chart.click_series.label",nameRender:kw,configRender:Tw,payload:[{name:"type",description:"Always 'click'",valueType:"string"},{name:"seriesType",description:"'line' | 'bar'",valueType:"string"},{name:"name",description:"Name of the series clicked",valueType:"string"},{name:"color",description:"Color",valueType:"string"},{name:"rowData",description:"Data of the row",valueType:"object"}]};function Tw(e){return n.jsx(n.Fragment,{})}function kw(e){const{t}=m.useTranslation();return n.jsx(s.Text,{size:"sm",children:t("viz.pareto_chart.click_series.label")})}const ul={label_template:"${percentage.x} of ${x_axis.name} causes ${percentage.y} of ${bar.name}",color:"#789AB4"},Kr={x_axis:{name:"X Axis",data_key:"",axisLabel:{rotate:0,formatter:_e(),overflow:Ie()}},data_key:"value",bar:{name:"Value",nameAlignment:"left",color:"#228be6",label_formatter:de,unit:K()},line:{name:"Value",nameAlignment:"right",color:"red"},dataZoom:kt,markLine:ul,reference_lines:[]};function Cn(e){return Y(e,{output:"percent",mantissa:0,absolute:!1})}function Dw(e){const t=e.value[1];try{return Cn(t)}catch(r){return console.error(r),t}}function zw(e){function t(r){let a=r;if(typeof r=="object"&&(Array.isArray(r.value)&&r.value.length===2?a=r.value[1]:a=r.value),!e.bar.label_formatter)return a;try{return Y(a,e.bar.label_formatter)}catch(o){return console.error(o),a}}return{bar:t,line:Dw,lineValue:Cn}}function Mw(e,t,r){const{label_template:a}=e.markLine;if(!a)return"";const o={...e,percentage:t,count:r},l=Object.keys(o),i=Object.values(o);return new Function(...l,`return \`${a}\`;`)(...i)}function Iw(e){const t=Number(Ee(e).format({output:"number",mantissa:2}));return t<.33?"left":t>.66?"right":"center"}function Vw(e,t){if(t.length===0)return{};const r=t.findIndex(d=>d[1]>=.8);if(r===-1)return{};const a=t[r],o=(r+1)/t.length,l={x:Cn(o),y:Cn(a[1])},i={left:r+1,right:t.length-r-1},c=a[0];return c?{markLine:{name:"",silent:!0,symbol:"triangle",symbolRotate:180,symbolSize:[10,8],data:[{name:"",symbol:"none",xAxis:c,lineStyle:{color:e.markLine.color},label:{formatter:Mw(e,l,i),position:"end",align:Iw(o)}}]},markArea:{name:"",silent:!0,itemStyle:{color:"rgba(47, 140, 192, 0.05)"},data:[[{coord:["min",0]},{xAxis:c}]]}}:{}}function Pw(e,t,r){const a=t.reduce((c,d)=>c+d[1],0),o=t.reduce((c,d,u)=>{const p=u===0?0:c[u-1][1];return c.push([d[0],p+d[1]]),c},[]).map(c=>[c[0],c[1]/a]),{markLine:l,markArea:i}=Vw(e,o);return[{name:e.bar.name,type:"bar",barMaxWidth:20,itemStyle:{color:e.bar.color},label:{show:!1,position:"top",formatter:r.bar},yAxisIndex:0,data:t},{name:e.line.name,type:"line",itemStyle:{color:e.line.color},symbolSize:2,lineStyle:{width:1,shadowColor:"rgba(255,255,255,1)",shadowBlur:0,shadowOffsetX:0,shadowOffsetY:1},label:{show:!1,position:"top",formatter:r.line},yAxisIndex:1,data:o,markLine:l,markArea:i}]}function $w(e){const t=e.bar.unit;return t.show_in_tooltip?t.text:""}const Aw=(e,t)=>r=>{const a=Array.isArray(r)?r:[r];if(a.length===0)return"";const o=$w(e),l=a.map(d=>{const{seriesName:u,componentSubType:p}=d,[f,v]=d.value;return u?p==="bar"?`
|
|
339
339
|
<tr>
|
|
340
340
|
<th style="text-align: right; padding: 0 1em;">${u}</th>
|
|
341
341
|
<td style="text-align: left; padding: 0 2px 0 1em;">${t.bar(v)}</td>
|
|
@@ -527,8 +527,8 @@ Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel vari
|
|
|
527
527
|
</table>
|
|
528
528
|
`}}function _C(e){const t=e.unit.show_in_tooltip?e.unit.text:"";return X.getTooltip({trigger:"item",formatter:vC(t)})}const mC={tooltip:{show:!0},series:{type:"sunburst",radius:[0,"90%"],emphasis:{focus:"ancestor"}}};function wC(e,t,r){r.reduce((l,i)=>{const c=Re(i,t);return l[i.name]=Be(i,c),l},{});const o={series:{data:fC(e,t),levels:yC(e)},tooltip:_C(e)};return b.defaultsDeep({},o,mC)}function xC({context:e,instance:t}){const{variables:r}=e,{value:a}=q(e.instanceData,"config"),o=h.useMemo(()=>b.defaults({},a,Zr),[a]),l=e.data,{width:i,height:c}=e.viewport,d=h.useRef(null),u=h.useCallback(()=>{var _;const v=(_=d.current)==null?void 0:_.getEchartsInstance();v&&fe(t,v.getOption())},[t]),p=h.useMemo(()=>({finished:u}),[u]),f=h.useMemo(()=>wC(o,l,r),[o,l,r]);return!i||!c?null:n.jsx(ve,{width:i,height:c,children:n.jsx(he,{echarts:ce,option:f,ref:d,onEvents:p,style:Kt(i,c),notMerge:!0,theme:"merico-light"})})}function CC({control:e,watch:t}){const{t:r}=m.useTranslation();return t(["label_key","value_key","group_key"]),n.jsxs(s.Stack,{children:[n.jsx(y.Controller,{name:"label_key",control:e,render:({field:a})=>n.jsx(L,{label:r("common.name_data_field"),required:!0,...a})}),n.jsx(y.Controller,{name:"value_key",control:e,render:({field:a})=>n.jsx(L,{label:r("common.value_data_field"),required:!0,...a})}),n.jsx(y.Controller,{name:"group_key",control:e,render:({field:a})=>n.jsx(L,{label:r("viz.sunburst_chart.group_key"),clearable:!0,...a})}),n.jsx(y.Controller,{name:"unit",control:e,render:({field:a})=>n.jsx(ue,{hiddenFileds:["show_in_legend"],...a})})]})}const SC=({control:e,index:t})=>{const{t:r,i18n:a}=m.useTranslation(),o=h.useMemo(()=>[{label:r("viz.sunburst_chart.label.rotate.radial"),value:"radial"},{label:r("viz.sunburst_chart.label.rotate.tangential"),value:"tangential"},{label:r("viz.sunburst_chart.label.rotate.none"),value:"0"}],[a.language]);return n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(y.Controller,{name:`levels.${t}.r0`,control:e,render:({field:l})=>n.jsx(s.TextInput,{label:r("viz.sunburst_chart.level.inside_radius"),placeholder:"0%",...l})}),n.jsx(y.Controller,{name:`levels.${t}.r`,control:e,render:({field:l})=>n.jsx(s.TextInput,{label:r("viz.sunburst_chart.level.outside_radius"),placeholder:"50%",...l})})]}),n.jsx(s.Divider,{mb:-10,mt:10,variant:"dashed",label:r("chart.label.label_full"),labelPosition:"center"}),n.jsx(y.Controller,{name:`levels.${t}.label.show_label_tolerance`,control:e,render:({field:l})=>n.jsx(s.NumberInput,{label:r("viz.sunburst_chart.label.show_label_tolerance"),decimalScale:4,step:5e-4,min:0,max:1,...l})}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(y.Controller,{name:`levels.${t}.label.rotate`,control:e,render:({field:l})=>n.jsx(s.Select,{label:r("viz.sunburst_chart.label.rotate.label"),data:o,...l})}),n.jsx(y.Controller,{name:`levels.${t}.label.align`,control:e,render:({field:l})=>n.jsx(yt,{...l})})]}),n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(y.Controller,{name:`levels.${t}.label.position`,control:e,render:({field:l})=>n.jsx(Lt,{label:r("chart.label_position.label"),...l,onChange:i=>{i&&l.onChange(i)}})}),n.jsx(y.Controller,{name:`levels.${t}.label.padding`,control:e,render:({field:l})=>n.jsx(s.NumberInput,{label:r("chart.padding"),min:0,hideControls:!0,...l})})]})]})},TC=({control:e,watch:t})=>{const{t:r}=m.useTranslation(),a=()=>({id:Date.now().toString(),r0:"",r:"",label:{show_label_tolerance:.001,rotate:"0",align:"center",position:"inside",padding:0}}),o=(l,i)=>i+1;return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{gap:2,sx:{cursor:"default",userSelect:"none"},children:[n.jsx(S.IconInfoCircle,{size:14,color:"#888"}),n.jsx(s.Text,{size:"14px",c:"#888",children:r("viz.sunburst_chart.level.hint")})]}),n.jsx(s.Divider,{variant:"dashed",my:10}),n.jsx(R,{control:e,watch:t,name:"levels",getItem:a,addButtonText:r("viz.sunburst_chart.level.add"),deleteButtonText:r("viz.sunburst_chart.level.delete"),renderTabName:o,children:({field:l,index:i})=>n.jsx(SC,{control:e,index:i})})]})};function kC({context:e}){const{t}=m.useTranslation(),{value:r,set:a}=q(e.instanceData,"config"),o=h.useMemo(()=>b.defaultsDeep({},r,Zr),[r]),l=h.useMemo(()=>b.clone(o),[o]),{control:i,handleSubmit:c,watch:d,formState:u,reset:p}=y.useForm({defaultValues:l});h.useEffect(()=>{p(l)},[l]),d(["label_key","value_key","group_key","levels"]);const[f,v]=h.useState("Data");return n.jsx("form",{onSubmit:c(a),children:n.jsxs(s.Stack,{gap:"xs",children:[n.jsx(se,{canSubmit:u.isDirty}),n.jsxs(s.Tabs,{value:f,onChange:v,orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"Data",children:t("data.label")}),n.jsx(s.Tabs.Tab,{value:"Levels",children:t("viz.sunburst_chart.level.labels")})]}),n.jsx(s.Tabs.Panel,{value:"Data",children:n.jsx(CC,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Levels",children:n.jsx(TC,{control:i,watch:d})})]})]})})}const DC=[{lang:"en",resources:{sunburst_chart:{viz_name:"Sunburst Chart",level:{labels:"Levels",hint:"Configure ring style on each level",inside_radius:"Inside Radius",outside_radius:"Outside Radius",add:"Add a level",delete:"Delete this level"},label:{show_label_tolerance:"Hide label when its percentage is less than...",rotate:{label:"Rotate",radial:"Radial",tangential:"Tangential",none:"None"}},group_key:"Group Key"}}},{lang:"zh",resources:{sunburst_chart:{viz_name:"旭日图",level:{labels:"层级",hint:"为每层配置圆环样式",inside_radius:"内径",outside_radius:"外径",add:"增加一层",delete:"删除这一层"},label:{show_label_tolerance:"当百分比低于此值时,隐藏文案",rotate:{label:"旋转",radial:"径向旋转",tangential:"切向旋转",none:"不旋转"}},group_key:"分组字段"}}}];function zC(e){const{label_field:t,value_field:r,...a}=e;return{...a,label_key:t,value_key:r}}function MC(e){const{group_key:t="",...r}=e;return{...r,group_key:t}}function IC(e){const{levels:t=[],...r}=e;return{...r,levels:t}}function VC(e,{panelModel:t}){try{const r=t.queryIDs[0];if(!r)throw new Error("cannot migrate when queryID is empty");const a=d=>d&&`${r}.${d}`,{label_key:o,value_key:l,group_key:i,...c}=e;return{...c,label_key:a(o),value_key:a(l),group_key:a(i)}}catch(r){throw console.error("[Migration failed]",r),r}}function PC(e){const{unit:t}=e;return{...e,unit:t??K()}}class $C extends J{constructor(){super(...arguments);V(this,"VERSION",6)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,r=>({...r,version:2,config:zC(r.config)})),this.version(3,r=>({...r,version:3,config:MC(r.config)})),this.version(4,r=>({...r,version:4,config:IC(r.config)})),this.version(5,(r,a)=>({...r,version:5,config:VC(r.config,a)})),this.version(6,r=>({...r,version:6,config:PC(r.config)}))}}const AC={displayName:"viz.sunburst_chart.viz_name",displayGroup:"chart.groups.echarts_based_charts",migrator:new $C,name:"sunburst",viewRender:xC,configRender:kC,createConfig(){return{version:6,config:b.cloneDeep(Zr)}},translation:DC};var Xe=(e=>(e.string="string",e.number="number",e.eloc="eloc",e.percentage="percentage",e.url="url",e.custom="custom",e))(Xe||{});function Vl(){return{page_size:0}}const Pl=["function text({ value, row_data }, utils) {"," return value","}"].join(`
|
|
529
529
|
`),$l={columns:[],fontSize:"14px",highlightOnHover:!0,horizontalSpacing:"14px",query_id:"",striped:!0,use_raw_columns:!0,ignored_column_keys:"",verticalSpacing:"14px",pagination:Vl()};function EC(e){const{columns:t,...r}=e;return{...e,columns:t.map(a=>({...a,align:a.align??"left"}))}}function BC(e,{panelModel:t}){try{const r=t.queryIDs[0];if(!r)throw new Error("cannot migrate when queryID is empty");const a=c=>c&&`${r}.${c}`,{id_field:o,columns:l,...i}=e;return{...i,id_field:a(o),columns:l.map(c=>({...c,value_field:a(c.value_field)}))}}catch(r){throw console.error("[Migration failed]",r),r}}function qC(e){const{columns:t,...r}=e;return{...r,columns:t.map(a=>({...a,align:a.align??"left",cellBackgroundColor:a.cellBackgroundColor??"",width:a.width??""}))}}function LC(e){const{id_field:t,...r}=e,{queryID:a}=$(t);return{...r,query_id:a??""}}function OC(e){const{ignored_column_keys:t,...r}=e;return{...r,ignored_column_keys:t??""}}function NC(e){const{pagination:t=Vl(),...r}=e;return{...r,pagination:t}}class GC extends J{constructor(){super(...arguments);V(this,"VERSION",8)}configVersions(){this.version(1,r=>({version:1,config:r})),this.version(2,r=>{const{columns:a,...o}=r.config;return{...r,version:2,config:{...o,columns:a.map(({id:l,...i})=>({id:l??te.randomId(),...i}))}}}),this.version(3,r=>({...r,version:3,config:EC(r.config)})),this.version(4,(r,a)=>({...r,version:4,config:BC(r.config,a)})),this.version(5,r=>({...r,version:5,config:qC(r.config)})),this.version(6,r=>({...r,version:6,config:LC(r.config)})),this.version(7,r=>({...r,version:7,config:OC(r.config)})),this.version(8,r=>({...r,version:8,config:NC(r.config)}))}}const Al={left:"flex-start",center:"center",right:"flex-end"},FC=({header:e,cx:t})=>{const r=b.get(e.column.columnDef.meta,"align","left");return n.jsxs(s.Text,{className:t("table-head-cell",{"table-head-cell--sortable":e.column.getCanSort()}),onClick:e.column.getToggleSortingHandler(),ta:r,sx:{justifyContent:Al[r]},size:"sm",children:[e.isPlaceholder?null:ge.flexRender(e.column.columnDef.header,e.getContext()),n.jsx(QC,{direction:e.column.getIsSorted()})]})},QC=({direction:e})=>{switch(e){case"asc":return n.jsx(S.IconArrowUp,{size:16});case"desc":return n.jsx(S.IconArrowDown,{size:"1em"});default:return null}},jC=ht.createStyles(e=>({root:{overflow:"auto",position:"relative","& .table-head-cell":{display:"flex",flexFlow:"row nowrap",alignItems:"center",whiteSpace:"nowrap","&.table-head-cell--sortable":{cursor:"pointer",userSelect:"none"}},"&.table-highlight-on-hover tr":{transition:"background-color 0.2s","&:hover":{backgroundColor:e.colors.gray[0]}}},thead:{background:e.white,position:"sticky",top:24,transform:"translateY(-1px)",zIndex:10},info_bar:{position:"sticky",top:0,left:0,right:0,zIndex:10,background:"white"}})),WC={tableLayout:"fixed",width:"fit-content",minWidth:"100%","thead, tbody":{tr:{width:"fit-content",th:{position:"relative"},"th, td":{padding:"2px 10px",div:{overflow:"hidden",textOverflow:"ellipsis"},"&:first-of-type":{paddingLeft:2,paddingRight:2}}}},".resizer":{position:"absolute",right:0,top:"50%",transform:"translateY(-50%)",cursor:"col-resize",userSelect:"none",touchAction:"none"},".resizer.isResizing":{color:"#228be6",opacity:"1",transform:"translateY(-50%)",backgroundColor:"rgb(248, 249, 250)"},"@media (hover: hover)":{".resizer":{opacity:"0"},"*:hover > .resizer":{color:"#228be6",opacity:"1"}}},El=ht.createStyles((e,t)=>({content:{display:"flex",alignItems:"center",justifyContent:Al[t.align],".table-cell-text":{whiteSpace:"nowrap",cursor:t.clickable?"pointer":"default",textDecoration:t.clickable?"underline":"none"}}}));function UC(e){return e?Ne(e).oklch()[0]>.7?"black":"white":"inherit"}function Bl(e){const t=e.tableCellContext.bgColor;return{backgroundColor:t,color:UC(t)}}function Ot(e){const t=e.tableCellContext.isClickable(),r=El({clickable:t,align:e.align});return n.jsx("div",{className:r.classes.content,style:{...Bl(e)},children:n.jsx(s.Text,{size:"sm",className:"table-cell-text",onClick:e.tableCellContext.getClickHandler(),children:n.jsx("span",{title:e.children,children:e.children})})})}function KC(e){return n.jsx(Ot,{...e,children:e.value})}function YC(e){const t=El({clickable:!0,align:e.align}),r=e.value;return n.jsx("div",{className:t.classes.content,style:{...Bl(e)},children:n.jsx(s.Anchor,{className:"table-cell-text",href:r,target:"_blank",color:"black",children:r})})}function XC(e){const t=Y(e.value,{output:"number",average:!0,mantissa:2,trimMantissa:!0,absolute:!1});return n.jsx(Ot,{...e,children:t})}function ZC(e){const t=Y(e.value,{output:"number",mantissa:0,thousandSeparated:!0,absolute:!1});return n.jsx(Ot,{...e,children:t})}function JC(e){const t=Y(e.value,{output:"percent",mantissa:3,trimMantissa:!0,absolute:!1});return n.jsx(Ot,{...e,children:t})}function HC(e){const{value:t,row_data:r,func_content:a}=e;if(!a)return n.jsx(Ot,{...e,children:t});const o=new Function(`return ${a}`)()({value:t,row_data:r},je);return n.jsx(Ot,{...e,children:o})}function RC(e){switch(e.type){case Xe.string:return n.jsx(KC,{...e});case Xe.eloc:return n.jsx(XC,{...e});case Xe.number:return n.jsx(ZC,{...e});case Xe.percentage:return n.jsx(JC,{...e});case Xe.url:return n.jsx(YC,{...e});case Xe.custom:return n.jsx(HC,{...e})}}function eS({tableContainerRef:e,rows:t}){var c,d;const r=Wd.useVirtualizer({getScrollElement:()=>e.current,count:t.length,estimateSize:h.useCallback(()=>28,[]),overscan:20}),a=r.getVirtualItems(),o=r.getTotalSize(),l=a.length>0&&((c=a==null?void 0:a[0])==null?void 0:c.start)||0,i=a.length>0?o-(((d=a==null?void 0:a[a.length-1])==null?void 0:d.end)||0):0;return n.jsxs(s.Table.Tbody,{children:[l>0&&n.jsx(s.Table.Tr,{children:n.jsx(s.Table.Td,{style:{height:`${l}px`}})}),a.map(u=>{const p=t[u.index];return n.jsx(s.Table.Tr,{children:p.getVisibleCells().map(f=>n.jsx(s.Table.Td,{children:ge.flexRender(f.column.columnDef.cell,f.getContext())},f.id))},p.id)}),i>0&&n.jsx(s.Table.Tr,{children:n.jsx(s.Table.Td,{style:{height:`${i}px`}})})]})}const Jr={id:"builtin:table:click-cell-content",displayName:"viz.table.click_cell.click_cell_content",nameRender:aS,configRender:nS,payload:[{name:"row_index",description:"Index of the row that the cell belongs to",valueType:"number"},{name:"col_index",description:"Index of the column that the cell belongs to",valueType:"number"},{name:"row_data",description:"Data of the row that the cell belongs to",valueType:"object"}]},tS={column:""};function ql(e,t){const{value:r}=q(e.instanceData,"config"),a={columnsFromConfig:[],columnsFromData:[]};if(r&&(a.columnsFromConfig=r.columns.map((o,l)=>({label:o.label,value:l.toString()}))),!t)return a;if(r!=null&&r.query_id){const o=t[r.query_id];(o==null?void 0:o.length)>0&&(a.columnsFromData=Object.keys(o[0]).map(l=>({label:l,value:l})))}return a}function Ll(e){const{value:t}=q(e.instanceData,"config");return(t==null?void 0:t.use_raw_columns)??!1}function nS(e){const{t}=m.useTranslation(),{columnsFromConfig:r,columnsFromData:a}=ql(e.instance,e.sampleData),o=Ll(e.instance),l=r.length>0?r:a,{value:i,set:c}=q(e.trigger.triggerData,"config"),{column:d}=b.defaults({},i,tS),u=p=>{p&&(isNaN(+p)?c({column:p}):c({column:+p}))};return o?n.jsxs(s.Stack,{children:[n.jsx(s.Alert,{icon:n.jsx(S.IconAlertCircle,{size:"1rem"}),color:"gray",children:n.jsxs(m.Trans,{i18nKey:"viz.table.click_cell.why_column_data_field",children:["Option ",n.jsx(s.Mark,{children:"Use original data columns"})," is enabled, you have to address trigger column by its data field"]})}),n.jsx(s.TextInput,{label:t("viz.table.click_cell.column_data_field"),value:d.toString(),onChange:p=>u(p.currentTarget.value)})]}):n.jsx(s.Select,{clearable:!1,data:l,label:t("viz.table.click_cell.choose_a_column"),value:d.toString(),onChange:u,comboboxProps:{zIndex:340},maxDropdownHeight:500})}function rS(e,t,r){const{t:a}=m.useTranslation();if(!e)return a("viz.table.click_cell.click_cell_content");if(b.isNumber(e.column)){if(r)return a("viz.table.click_cell.click_cell_of_x_th",{x:e.column+1});const o=t[e.column];return o?a("viz.table.click_cell.click_cell_of_x",{x:o.label}):a("viz.table.click_cell.click_cell_invalid_config")}return a("viz.table.click_cell.click_cell_of_x",{x:e.column})}function aS(e){const{columnsFromConfig:t}=ql(e.instance),{value:r}=q(e.trigger.triggerData,"config"),a=Ll(e.instance);return n.jsx(s.Text,{size:"sm",children:rS(r,t,a)})}function Ol(e,t,r){return Math.min(Math.max(e,t),r)}class sS{constructor(t){this.steps=t;const r=[],a=new Set;for(const o of t)a.has(o.to)||(r.push(o),a.add(o.to));if(r.sort((o,l)=>o.from-l.from),r.length<2)throw new Error("MultiStepValueMapper requires at least 2 steps");this.steps=r}getLinearFunction(t,r){const a=(r.to-t.to)/(r.from-t.from),o=t.to-a*t.from;return l=>a*l+o}getStepFunctionForValue(t){let r=b.findLastIndex(this.steps,a=>a.from<=t);return r=Ol(r,0,this.steps.length-2),this.getLinearFunction(this.steps[r],this.steps[r+1])}mapValue(t){return Ol(this.getStepFunctionForValue(t)(t),0,100)}}class oS{constructor(t,r,a,o,l){this.getColIndex=t,this.cell=r,this.triggers=a,this.interactionManager=o,this.colorManager=l}getClickHandler(){const t=this.getRelatedTrigger();if(t.length!==0)return()=>{const r={row_data:this.cell.row.original,row_index:this.cell.row.index,col_index:this.getColIndex(this.cell)};for(const a of t)this.interactionManager.runInteraction(a.id,r)}}getRelatedTrigger(){return this.triggers.filter(r=>r.schemaRef===Jr.id).filter(r=>{const a=this.getColIndex(this.cell),o=b.get(this.cell.column.columnDef.meta,"value_field"),l=b.get(r.config,"column");return l==a||l==o})}isClickable(){return this.getRelatedTrigger().length>0}get columnConf(){return this.cell.column.columnDef.meta}get bgColor(){const t=this.columnConf.cellBackgroundColor;if(!t||t==="none")return;if(b.isString(t))return t;const r=+this.cell.getValue();if(isFinite(r)){const a=this.colorManager.decodeInterpolation(t.interpolation),l=new sS(t.steps).mapValue(r);return a==null?void 0:a.getColor(l)}}}const lS=e=>{const t=Pe(e),r=Ve(t.triggerManager,Jr.id),{colorManager:a}=h.useContext(lt);return h.useCallback(o=>new oS(e.getColIndex,o,r,t,a),[r,t,e.getColIndex])},iS=({classes:e,pagination:t,setPagination:r,pageCount:a,totalRows:o})=>{const{t:l}=m.useTranslation(),{pageSize:i,pageIndex:c}=t;if(o===0)return null;if(i===0)return n.jsx(s.Box,{className:e.info_bar,sx:{height:22},children:n.jsx(s.Text,{ta:"right",pr:6,size:"14px",c:"dimmed",fw:"normal",children:l("common.pagination.total_rows",{total:o})})});const d=()=>{r({...t,pageIndex:c-1})},u=()=>{r({...t,pageIndex:c+1})};return n.jsxs(s.Group,{wrap:"nowrap",justify:"flex-end",gap:4,className:e.info_bar,sx:{height:22},children:[n.jsx(s.Text,{ta:"right",pr:6,size:"14px",c:"dimmed",fw:"normal",children:l("common.pagination.showing_rows",{start_row:c*i+1,end_row:(c+1)*i,total:o})}),n.jsx(s.ActionIcon,{variant:"default","aria-label":"to previous page",onClick:d,size:"xs",disabled:c===0,children:n.jsx(S.IconChevronLeft,{})}),n.jsx(s.ActionIcon,{variant:"default","aria-label":"to next page",onClick:u,size:"xs",disabled:c===a-1,children:n.jsx(S.IconChevronRight,{})})]})};function Nl({queryData:e,width:t,height:r,conf:a,context:o,instance:l}){m.useTranslation();const{use_raw_columns:i,ignored_column_keys:c,columns:d,...u}=a,{classes:p,cx:f}=jC(),v=h.useMemo(()=>{if(!i)return d;if(!Array.isArray(e)||e.length===0)return[];let Ae=Object.keys(e[0]);const xe=new Set(c==null?void 0:c.split(/\r?\n|\r|\n/g).filter(pe=>!!pe));return xe.size>0&&(Ae=Ae.filter(pe=>!xe.has(pe))),Ae.map(pe=>({id:pe,label:pe,value_field:pe,value_type:Xe.string,align:"left",width:"",cellBackgroundColor:""}))},[i,c,d,e]),_=lS({getColIndex:h.useCallback(Ae=>v.indexOf(Ae.column.columnDef.meta),[v]),vizManager:o.vizManager,instance:l}),w=h.useMemo(()=>{const Ae=ge.createColumnHelper();return v.map(pe=>{const zM=ap(pe.value_field);return Ae.accessor(zM.columnKey,{cell:gs=>n.jsx(RC,{tableCellContext:_(gs.cell),value:gs.getValue(),type:pe.value_type,row_data:gs.row.original,...pe}),header:pe.label,enableSorting:!0,meta:pe,size:typeof pe.width=="number"?pe.width:void 0,minSize:typeof pe.width=="number"?pe.width:void 0})})},[v,_]),[x,T]=h.useState([]),[D,z]=h.useState({pageIndex:0,pageSize:a.pagination.page_size}),I=h.useMemo(()=>{const{pageIndex:Ae,pageSize:xe}=D;return xe===0?e:e.slice(Ae*xe,(Ae+1)*xe)},[e,D]),E=Math.ceil(e.length/D.pageSize),A=ge.useReactTable({data:I,state:{sorting:x},onSortingChange:T,columns:w,columnResizeMode:"onChange",getCoreRowModel:ge.getCoreRowModel(),getSortedRowModel:ge.getSortedRowModel()}),{rows:U}=A.getRowModel(),N=h.useRef(null),oe=e.length,be=oe>0,dt=be?r-22:r,mt=be?22:0;return n.jsxs("div",{ref:N,style:{height:r,width:t,padding:"0 5px"},"data-enable-scrollbar":!0,className:f(p.root,{"table-highlight-on-hover":a.highlightOnHover}),children:[n.jsx(iS,{classes:p,pagination:D,totalRows:oe,setPagination:z,pageCount:E}),n.jsxs(s.Table,{sx:{...WC,maxHeight:dt},...u,striped:a.striped,children:[n.jsx(s.Table.Thead,{className:p.thead,style:{top:mt},children:A.getHeaderGroups().map(Ae=>n.jsx(s.Table.Tr,{children:Ae.headers.map(xe=>n.jsxs(s.Table.Th,{style:{width:xe.getSize()},children:[n.jsx(FC,{header:xe,cx:f}),n.jsx(s.ActionIcon,{variant:"subtle",onMouseDown:xe.getResizeHandler(),onTouchStart:xe.getResizeHandler(),className:`resizer ${xe.column.getIsResizing()?"isResizing":""}`,children:n.jsx(S.IconArrowBarToRight,{})})]},xe.id))},Ae.id))}),n.jsx(eS,{tableContainerRef:N,rows:U})]})]})}function Gl(){const{t:e}=m.useTranslation();return n.jsx(s.Text,{size:"sm",c:"gray",ta:"center",children:e("data.empty_data")})}function cS({data:e,width:t,height:r,conf:a,context:o,instance:l}){const{t:i}=m.useTranslation(),{panel:c}=re(),d=c.firstQueryData??[];if(c.queryIDs.length===0)return n.jsx(s.Text,{size:"sm",c:"gray",ta:"center",children:i("panel.settings.need_to_choose_queries")});const{query_id:u}=a;if(!u)return d.length===0?n.jsx(Gl,{}):n.jsx(Nl,{queryData:d,width:t,height:r,conf:{...a,use_raw_columns:!0,columns:[]},context:o,instance:l});const p=e[u];return!Array.isArray(p)||p.length===0?n.jsx(Gl,{}):n.jsx(Nl,{queryData:p,width:t,height:r,conf:a,context:o,instance:l})}function dS({context:e,instance:t}){const r=e.data,{height:a,width:o}=e.viewport,{value:l}=q(e.instanceData,"config");return l?n.jsx(cS,{data:r,width:o,height:a,conf:l,context:e,instance:t}):null}const uS=[{lang:"en",resources:{table:{viz_name:"Table",column:{labels:"Columns",add:"Add a column",delete:"Delete this column",query_id:"Query",query_id_hint:"Load table data from this query",use_original_data_columns:"Use original data columns",ignore_columns_by_these_key:"Ignore columns by these keys",separate_by_line_break:"Separate by line break",width:"Width",min_width:"Min Width",max_width:"Max Width",cell_background:"Cell background",custom_cell_content:"Custom cell content",value_type:{label:"Value Type",string:"String",number:"Number",percentage:"Percentage",eloc:"ELOC",url:"URL",custom:"Custom"}},style:{horizontal_spacing:"Horizontal Spacing",vertical_spacing:"Vertical Spacing",striped:"Striped",highlight_on_hover:"Hightlight on hover"},click_cell:{label:"Click cell content",click_cell_content:"Click cell content (click to config)",click_cell_of_x:"Click cell of {{ x }}",click_cell_of_x_th:"Click cell by column order {{ x }}",click_cell_invalid_config:"Invalid config",choose_a_column:"Choose a column",why_column_data_field:"Option <1>Use original data columns</1> is enabled, you have to address trigger column by its data field",column_data_field:"Column data field"}}}},{lang:"zh",resources:{table:{viz_name:"表格",column:{labels:"列设置",add:"加一列",delete:"删除这个列",query_id:"表格数据来源",query_id_hint:"通过所选的查询获取表格数据",use_original_data_columns:"使用数据本身的列",ignore_columns_by_these_key:"按下述列名忽略列",separate_by_line_break:"以换行符分隔",width:"宽度",min_width:"最小宽度",max_width:"最大宽度",cell_background:"单元格背景",custom_cell_content:"自定义单元格内容",value_type:{label:"数据类型",string:"文本",number:"数字",percentage:"百分比",eloc:"ELOC",url:"URL",custom:"自定义"}},style:{horizontal_spacing:"水平间距",vertical_spacing:"垂直间距",striped:"隔行变色",highlight_on_hover:"鼠标悬停时高亮整行"},click_cell:{label:"点击单元格",click_cell_content:"点击单元格内容",click_cell_of_x:"点击 {{ x }} 列单元格",click_cell_of_x_th:"点击第 {{ x }} 列单元格",click_cell_invalid_config:"配置信息已失效",choose_a_column:"选择列",why_column_data_field:"选项 <1>使用数据本身的列</1> 已开启,只能通过填写数据字段来指定触发动作的列",column_data_field:"列的数据字段"}}}}],pS=k.observer(h.forwardRef(({label:e,required:t,description:r,value:a,onChange:o,clearable:l=!1,sx:i,...c},d)=>{const{panel:u}=ae(),p=h.useMemo(()=>u.queryOptions(a,l),[a,l]);return p.length===0?n.jsx(s.Box,{children:n.jsx(s.TextInput,{label:e,required:t,defaultValue:a,readOnly:!0,disabled:!0})}):n.jsx(s.Select,{ref:d,label:e,description:r,data:p,value:a,onChange:Z(o),required:t,sx:i,maxDropdownHeight:500,...c})})),hS=[{from:0,to:0},{from:100,to:100}];function Fl(e){return e?b.isString(e)?e==="none"?"none":"static":"interpolation":"none"}function gS(e,t){var r;return Fl(t)==="static"?t:(r=e.getStaticColors()[0])==null?void 0:r.value}function fS(e,t){return b.isObject(t)?t:{steps:hS,interpolation:e.encodeColor(e.getColorInterpolations()[0])}}const bS=h.forwardRef((e,t)=>{const{t:r}=m.useTranslation(),{colorManager:a}=h.useContext(lt),[o,l]=h.useState(Fl(e.value)),[i,c]=h.useState(gS(a,e.value)),d=O.useLatest(i),[u,p]=h.useState(fS(a,e.value)),f=O.useLatest(u),v=x=>{var T,D,z;l(x||"none"),x==="static"?(T=e.onChange)==null||T.call(e,d.current):x==="none"||!x?(D=e.onChange)==null||D.call(e,"none"):(z=e.onChange)==null||z.call(e,f.current)},_=x=>{var T;c(x),(T=e.onChange)==null||T.call(e,x)},w=x=>{var T;p(x),(T=e.onChange)==null||T.call(e,x)};return n.jsxs(s.Stack,{align:"stretch",children:[n.jsx(Jg,{label:r("viz.table.column.cell_background"),value:o||"none",onChange:v}),o==="static"&&n.jsx(ye,{label:r("chart.color.label"),value:i,onChange:_}),o==="interpolation"&&n.jsx(Zg,{colorManager:a,value:u,onChange:w})]})}),yS=h.forwardRef(({value:e,onChange:t,sx:r},a)=>{const{t:o,i18n:l}=m.useTranslation(),i=h.useMemo(()=>Object.values(Xe).map(c=>({label:o(`viz.table.column.value_type.${c}`),value:c})),[l.language]);return n.jsx(s.Select,{ref:a,label:o("viz.table.column.value_type.label"),data:i,value:e,onChange:Z(t),maxDropdownHeight:500,sx:r})}),vS=h.forwardRef(({value:e,onChange:t},r)=>{const{t:a}=m.useTranslation(),[o,{setTrue:l,setFalse:i}]=O.useBoolean(),[c,d]=h.useState(e),u=()=>{i(),t(c)},p=()=>{i(),d(e)},f=()=>{d(Pl)};return h.useEffect(()=>{d(e)},[e]),n.jsxs(n.Fragment,{children:[n.jsx(s.Button,{color:"grape",variant:"filled",leftSection:n.jsx(S.IconMathFunction,{size:16}),mt:24,onClick:l,sx:{flexGrow:0},children:a("viz.table.column.custom_cell_content")}),n.jsx(s.Modal,{size:800,title:a("viz.table.column.custom_cell_content"),opened:o,onClose:i,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:o&&n.jsxs(s.Stack,{children:[n.jsx(s.Group,{justify:"flex-start",children:n.jsx(mo,{})}),n.jsx(s.Box,{sx:{position:"relative"},children:n.jsx(Se,{height:"500px",defaultLanguage:"javascript",value:c,onChange:v=>d(v??""),theme:"vs-dark",options:{minimap:{enabled:!1}}})}),n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Button,{onClick:f,color:"red",leftSection:n.jsx(S.IconRecycle,{size:20}),children:a("common.actions.reset_to_default")}),n.jsxs(s.Group,{justify:"flex-end",children:[n.jsx(s.Button,{onClick:p,variant:"subtle",children:a("common.actions.cancel")}),n.jsx(s.Button,{color:"green",leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),onClick:u,children:a("common.actions.save")})]})]})]})})]})}),Hr=()=>n.jsx(s.Text,{c:"dimmed",size:"12px",children:"px"}),_S=({control:e,index:t,watch:r})=>{const{t:a}=m.useTranslation(),o=r(`columns.${t}.value_type`),l=r("query_id");return n.jsxs(s.Stack,{my:0,sx:{position:"relative"},children:[n.jsxs(s.Group,{grow:!0,children:[n.jsx(y.Controller,{name:`columns.${t}.label`,control:e,render:({field:i})=>n.jsx(s.TextInput,{label:a("chart.label.label"),required:!0,id:`col-label-${t}`,sx:{flex:1},...i})}),n.jsx(y.Controller,{name:`columns.${t}.value_field`,control:e,render:({field:i})=>n.jsx(L,{label:a("common.data_field"),required:!0,queryID:l,...i})})]}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(y.Controller,{name:`columns.${t}.value_type`,control:e,render:({field:i})=>n.jsx(yS,{sx:{flex:1},...i})}),o===Xe.custom&&n.jsx(y.Controller,{name:`columns.${t}.func_content`,control:e,render:({field:i})=>n.jsx(vS,{value:i.value??Pl,onChange:c=>i.onChange(c??"")})})]}),n.jsx(s.Divider,{mb:-10,variant:"dashed",label:a("style.label"),labelPosition:"center"}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(s.NumberInput,{hideControls:!0,label:a("viz.table.column.min_width"),rightSection:n.jsx(Hr,{}),disabled:!0}),n.jsx(y.Controller,{name:`columns.${t}.width`,control:e,render:({field:i})=>n.jsx(s.NumberInput,{hideControls:!0,label:a("viz.table.column.width"),rightSection:n.jsx(Hr,{}),...i})}),n.jsx(s.NumberInput,{hideControls:!0,label:a("viz.table.column.max_width"),rightSection:n.jsx(Hr,{}),disabled:!0})]}),n.jsx(s.Group,{grow:!0,wrap:"nowrap",children:n.jsx(y.Controller,{name:`columns.${t}.align`,control:e,render:({field:i})=>n.jsx(Dr,{...i})})}),n.jsx(y.Controller,{name:`columns.${t}.cellBackgroundColor`,control:e,render:({field:i})=>n.jsx(bS,{...i})})]})},mS=({control:e,watch:t})=>{const{t:r}=m.useTranslation(),a=()=>{const i=te.randomId();return{id:i,label:i,align:"center",value_field:"",value_type:Xe.string,width:""}},o=(i,c)=>{const d=i.label.trim();return d||c+1};t(["columns","ignored_column_keys"]);const l=t("use_raw_columns");return n.jsxs(n.Fragment,{children:[n.jsx(y.Controller,{name:"use_raw_columns",control:e,render:({field:i})=>n.jsx(s.Switch,{mt:20,mb:20,label:r("viz.table.column.use_original_data_columns"),checked:i.value,onChange:c=>i.onChange(c.currentTarget.checked)})}),l&&n.jsx(y.Controller,{name:"ignored_column_keys",control:e,render:({field:i})=>n.jsx(s.Textarea,{label:r("viz.table.column.ignore_columns_by_these_key"),placeholder:r("viz.table.column.separate_by_line_break"),autosize:!0,minRows:2,maxRows:10,...i})}),!l&&n.jsx(R,{control:e,watch:t,name:"columns",getItem:a,addButtonText:r("viz.table.column.add"),deleteButtonText:r("viz.table.column.delete"),renderTabName:o,children:({field:i,index:c})=>n.jsx(_S,{control:e,watch:t,index:c})})]})};function wS({control:e,watch:t}){const{t:r}=m.useTranslation();return t(["horizontalSpacing","verticalSpacing","fontSize","striped","highlightOnHover"]),n.jsxs(s.Stack,{gap:"xs",children:[n.jsxs(s.Group,{justify:"space-between",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:[n.jsx(y.Controller,{name:"horizontalSpacing",control:e,render:({field:a})=>n.jsx(Ir,{disabled:!0,label:r("viz.table.style.horizontal_spacing"),sx:{flex:1},...a})}),n.jsx(y.Controller,{name:"verticalSpacing",control:e,render:({field:a})=>n.jsx(Ir,{disabled:!0,label:r("viz.table.style.vertical_spacing"),sx:{flex:1},...a})})]}),n.jsx(s.Group,{justify:"space-between",mb:"lg",grow:!0,sx:{"> *":{flexGrow:1}},children:n.jsx(y.Controller,{name:"fontSize",control:e,render:({field:a})=>n.jsx(s.TextInput,{label:r("style.font_size.label"),placeholder:r("style.font_size.placeholder"),required:!0,sx:{flex:1},...a})})}),n.jsxs(s.Group,{justify:"space-between",grow:!0,children:[n.jsx(y.Controller,{name:"striped",control:e,render:({field:a})=>n.jsx(s.Switch,{label:r("viz.table.style.striped"),checked:a.value,onChange:o=>a.onChange(o.currentTarget.checked)})}),n.jsx(y.Controller,{name:"highlightOnHover",control:e,render:({field:a})=>n.jsx(s.Switch,{label:r("viz.table.style.highlight_on_hover"),checked:a.value,onChange:o=>a.onChange(o.currentTarget.checked)})})]})]})}function xS({control:e,watch:t}){const{t:r}=m.useTranslation();return t(["pagination"]),n.jsx(s.Stack,{children:n.jsx(y.Controller,{name:"pagination.page_size",control:e,render:({field:a})=>n.jsx(s.NumberInput,{label:r("common.pagination.page_size"),description:r("viz.heatmap.pagination.page_size_hint"),size:"xs",sx:{flex:1},...a,onChange:o=>{typeof o!="string"&&a.onChange(o)}})})})}function CS({columns:e,...t}){return{...t,columns:e.map(({id:r,...a})=>({id:r??te.randomId(),...a}))}}function SS({context:e}){const{t}=m.useTranslation(),{value:r,set:a}=q(e.instanceData,"config"),o=h.useMemo(()=>b.defaultsDeep({},r,$l),[r]),l=h.useMemo(()=>CS(o),[o]);h.useEffect(()=>{!b.isEqual(o,l)&&(console.log("config malformed, resetting to defaults",o,l),a(l))},[o,l]);const{control:i,handleSubmit:c,watch:d,formState:u,reset:p}=y.useForm({defaultValues:l});return h.useEffect(()=>{p(l)},[l]),d(["query_id"]),n.jsxs("form",{onSubmit:c(a),children:[n.jsx(se,{canSubmit:u.isDirty}),n.jsxs(s.Tabs,{defaultValue:"Columns",orientation:"vertical",styles:{tab:{paddingLeft:"6px",paddingRight:"6px"},panel:{paddingTop:"6px",paddingLeft:"12px"}},children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"Columns",children:t("viz.table.column.labels")}),n.jsx(s.Tabs.Tab,{value:"Style",children:t("style.label")}),n.jsx(s.Tabs.Tab,{value:"Pagination",children:t("common.pagination.label")})]}),n.jsxs(s.Tabs.Panel,{value:"Columns",children:[n.jsx(y.Controller,{name:"query_id",control:i,render:({field:f})=>n.jsx(pS,{label:t("viz.table.column.query_id"),description:t("viz.table.column.query_id_hint"),required:!0,...f})}),n.jsx(s.Divider,{mt:20,mb:10,variant:"dashed"}),n.jsx(mS,{control:i,watch:d})]}),n.jsx(s.Tabs.Panel,{value:"Style",children:n.jsx(wS,{control:i,watch:d})}),n.jsx(s.Tabs.Panel,{value:"Pagination",children:n.jsx(xS,{control:i,watch:d})})]})]})}const Ql=new GC,Rr={createConfig(){return{version:Ql.VERSION,config:b.cloneDeep($l)}},displayName:"viz.table.viz_name",displayGroup:"chart.groups.others",migrator:Ql,name:"table",viewRender:dS,configRender:SS,triggers:[Jr],translation:uS},jl=["function text({ data, variables, filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
|
|
530
|
-
`),ea={func_content:jl,horizontal_align:"left",font_size:"14px",font_weight:"normal"},TS=k.observer(({context:e})=>{const t=H(),{value:r=ea}=q(e.instanceData,"config"),{variables:a}=e,o=e.data,{func_content:l,horizontal_align:i,font_size:c,font_weight:d}=r,u=h.useMemo(()=>a.reduce((f,v)=>{const _=Re(v,o);return f[v.name]=Be(v,_),f},{}),[a,o]),p=h.useMemo(()=>new Function(`return ${l}`)()({data:o,variables:u,filters:t.payloadForSQL.filters,context:t.payloadForSQL.context}),[l,o,u,t.payloadForSQL]);return n.jsx(s.Text,{ta:i,fw:d,sx:{fontSize:c},children:p})}),zn=[{label:"initial",value:0},{label:"500",value:25},{label:"700",value:50},{label:"semibold",value:75},{label:"bold",value:100}];function kS({label:e,value:t,onChange:r},a){var i;const[o,l]=h.useState(((i=zn.find(c=>c.label===t))==null?void 0:i.value)??zn[0].value);return h.useEffect(()=>{const c=zn.find(d=>d.value===o);c&&r(c.label)},[o]),n.jsxs(s.Stack,{gap:0,mt:"sm",mb:"lg",children:[n.jsx(s.Text,{size:"sm",children:e}),n.jsx(s.Box,{px:"1.5em",children:n.jsx(s.Slider,{label:null,marks:zn,value:o,onChange:l,step:25,ref:a})})]})}const DS=h.forwardRef(kS),zS=({value:e,onChange:t})=>{const r=a=>{a&&t(a)};return n.jsx(s.Box,{sx:{position:"relative"},children:n.jsx(Se,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},MS=h.forwardRef(({value:e,onChange:t},r)=>{const{t:a}=m.useTranslation(),[o,{setTrue:l,setFalse:i}]=O.useBoolean(),[c,d]=h.useState(e),u=()=>{i(),t(c)},p=()=>{i(),d(e)},f=()=>{d(jl)};return h.useEffect(()=>{d(e)},[e]),n.jsxs(n.Fragment,{children:[n.jsx(s.Button,{color:"grape",variant:"filled",leftSection:n.jsx(S.IconMathFunction,{size:16}),mt:24,onClick:l,sx:{flexGrow:0},children:a("viz.text.content.edit")}),n.jsx(s.Modal,{size:800,title:a("viz.text.content.label"),opened:o,onClose:i,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:o&&n.jsxs(s.Stack,{children:[n.jsx(zS,{value:c,onChange:d}),n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Button,{onClick:f,color:"red",leftSection:n.jsx(S.IconRecycle,{size:20}),children:a("common.actions.reset_to_default")}),n.jsxs(s.Group,{justify:"flex-end",children:[n.jsx(s.Button,{onClick:p,variant:"subtle",children:a("common.actions.cancel")}),n.jsx(s.Button,{color:"green",leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),onClick:u,children:a("common.actions.save_changes")})]})]})]})})]})});function IS({context:e}){const{t}=m.useTranslation(),{value:r,set:a}=q(e.instanceData,"config"),o=h.useMemo(()=>b.defaultsDeep({},r,ea),[r]),l=h.useMemo(()=>{const{func_content:f,horizontal_align:v,font_size:_,font_weight:w}=o;return{func_content:f,horizontal_align:v,font_size:_,font_weight:w}},[o]);h.useEffect(()=>{!b.isEqual(o,l)&&(console.log("config malformed, resetting to defaults",o,l),a(l))},[o,l]);const{control:i,handleSubmit:c,watch:d,formState:u,reset:p}=y.useForm({defaultValues:l});return h.useEffect(()=>{p(l)},[l]),d(["func_content","horizontal_align","font_size","font_weight"]),n.jsx(s.Stack,{gap:"xs",children:n.jsxs("form",{onSubmit:c(a),children:[n.jsx(se,{canSubmit:u.isDirty}),n.jsxs(s.Stack,{gap:10,children:[n.jsx(y.Controller,{name:"func_content",control:i,render:({field:f})=>n.jsx(MS,{...f})}),n.jsx(s.Divider,{mt:10,mb:-10,variant:"dashed",label:t("chart.style.label"),labelPosition:"center"}),n.jsx(y.Controller,{name:"horizontal_align",control:i,render:({field:f})=>n.jsx(Dr,{...f})}),n.jsx(y.Controller,{name:"font_size",control:i,render:({field:f})=>n.jsx(s.TextInput,{label:t("style.font_size.label"),placeholder:t("style.font_size.placeholder"),sx:{flex:1},...f})}),n.jsx(s.Group,{justify:"space-between",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:n.jsx(y.Controller,{name:"font_weight",control:i,render:({field:f})=>n.jsx(DS,{label:t("style.font_weight.label"),...f})})})]})]})})}const VS=[{lang:"en",resources:{text:{viz_name:"Text",content:{label:"Text content",edit:"Edit Content"}}}},{lang:"zh",resources:{text:{viz_name:"文本",content:{label:"文本内容",edit:"编辑文本内容"}}}}];class PS extends J{constructor(){super(...arguments);V(this,"VERSION",1)}configVersions(){this.version(1,r=>({version:1,config:r}))}}const $S={displayName:"viz.text.viz_name",displayGroup:"chart.groups.others",migrator:new PS,name:"text",viewRender:TS,configRender:IS,createConfig(){return{version:1,config:b.cloneDeep(ea)}},translation:VS},ta={item_badge:"_item_badge_l2t3l_1",label:"_label_l2t3l_8",value:"_value_l2t3l_20"},AS=({children:e})=>["string","number"].includes(typeof e)?n.jsx(s.Text,{size:"xs",ff:"monospace",children:e}):e,vt=h.forwardRef(({label:e,value:t,label_description:r,value_description:a},o)=>n.jsxs("div",{ref:o,className:ta.item_badge,children:[n.jsx("div",{className:ta.label,children:e}),n.jsxs(s.HoverCard,{shadow:"md",disabled:!a,children:[n.jsx(s.HoverCard.Target,{children:n.jsx("div",{className:ta.value,"data-with-tooltip":!!a,children:t})}),n.jsx(s.HoverCard.Dropdown,{p:"xs",children:n.jsx(AS,{children:a})})]})]})),ES=({item:e})=>e.type!=="checkbox"?null:n.jsx(vt,{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}`}),BS=({item:e})=>e.type!=="context"?null:n.jsx(vt,{label:e.key,value:e.value,label_description:`context.${e.key}`}),qS=k.observer(({item:e})=>{const{t}=m.useTranslation(),a=e.model.value,[o,l]=a.value,i=h.useMemo(()=>!l&&!o?Number.NaN:M(l).diff(M(o),"days")+1,[o,l]);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(vt,{label:e.label,value:e.value.join(" ~ "),label_description:`filters.${e.key}`,value_description:c})}),LS=({item:e})=>e.type!=="date-range"?null:n.jsx(qS,{item:e}),Wl=({selection:e})=>(m.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))})),OS=k.observer(({item:e})=>{m.useTranslation();const r=e.model.config,a=h.useMemo(()=>r.optionsByValues(e.value),[e.value,r.options]);return n.jsx(vt,{label:e.label,value:a.length,label_description:`filters.${e.key}`,value_description:n.jsx(Wl,{selection:a})})}),NS=({item:e})=>e.type!=="multi-select"?null:n.jsx(OS,{item:e}),GS=k.observer(({item:e})=>{m.useTranslation();const r=e.model.config,a=h.useMemo(()=>{var o;return((o=r.options.find(l=>l.value===e.value))==null?void 0:o.label)??e.value},[e.value,r.options]);return n.jsx(vt,{label:e.label,value:a,label_description:`filters.${e.key}`})}),FS=({item:e})=>e.type!=="select"?null:n.jsx(GS,{item:e}),QS=({item:e})=>e.type!=="text-input"?null:n.jsx(vt,{label:e.label,value:n.jsx(s.Text,{maw:200,size:"xs",truncate:"end",ff:"monospace",children:e.value}),value_description:e.value}),jS=k.observer(({item:e})=>{m.useTranslation();const r=e.model.config,a=h.useMemo(()=>r.optionsByValues(e.value),[e.value,r.options]);return n.jsx(vt,{label:e.label,value:a.length,label_description:`filters.${e.key}`,value_description:n.jsx(Wl,{selection:a})})}),WS=({item:e})=>e.type!=="tree-select"?null:n.jsx(jS,{item:e}),US=k.observer(({item:e})=>{m.useTranslation();const r=e.model.config,a=h.useMemo(()=>{var o;return((o=r.options.find(l=>l.value===e.value))==null?void 0:o.label)??e.value},[e.value,r.options]);return n.jsx(vt,{label:e.label,value:a,label_description:`filters.${e.key}`,value_description:e.value})}),KS=({item:e})=>e.type!=="tree-single-select"?null:n.jsx(US,{item:e}),na=({item:e})=>{switch(e.type){case"date-range":return n.jsx(LS,{item:e});case"select":return n.jsx(FS,{item:e});case"tree-single-select":return n.jsx(KS,{item:e});case"multi-select":return n.jsx(NS,{item:e});case"tree-select":return n.jsx(WS,{item:e});case"text-input":return n.jsx(QS,{item:e});case"checkbox":return n.jsx(ES,{item:e});case"context":return n.jsx(BS,{item:e});default:return null}},YS=k.observer(({conf:e})=>{const r=H().dashboardState,{all:a,keys:o}=e;return a?n.jsxs(n.Fragment,{children:[Object.entries(r.context).map(([l,i])=>n.jsx(na,{item:i},l)),Object.entries(r.filters).map(([l,i])=>n.jsx(na,{item:i},l))]}):n.jsx(n.Fragment,{children:o.map(l=>{const i=b.get(r,l);return i?n.jsx(na,{item:i},l):null})})}),XS=k.observer(({context:e})=>{const{value:t}=q(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(YS,{conf:t})}):null}),Ul={all:!0,keys:[]},ZS={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"},JS=({option:e,checked:t,...r})=>{const{t:a}=m.useTranslation(),o=e,l=o.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}),l&&n.jsx(s.Text,{size:"xs",c:t?"rgba(0,0,0,.8)":"dimmed",style:{flexShrink:0,flexGrow:0},children:a(ZS[o.widget])})]})})]})},HS=k.observer(({value:e,onChange:t,disabled:r})=>{const{t:a}=m.useTranslation(),l=G().dashboardStateVariableOptions,i=h.useMemo(()=>{const{optionGroups:c,validValues:d}=l,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},[l,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:JS,maxDropdownHeight:600,value:e,onChange:t,disabled:r,clearable:!0})}),RS=({form:e})=>{const{t}=m.useTranslation(),r=e.watch("all");return n.jsxs(s.Stack,{gap:"xs",p:"xs",children:[n.jsx(y.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:o=>a.onChange(o.currentTarget.checked)})}),n.jsx(y.Controller,{name:"keys",control:e.control,render:({field:a})=>n.jsx(HS,{disabled:r,...a})})]})};function eT({context:e}){const{value:t,set:r}=q(e.instanceData,"config"),a=h.useMemo(()=>b.defaultsDeep({},t,Ul),[t]),o=y.useForm({defaultValues:a}),{handleSubmit:l,formState:i,reset:c}=o;return h.useEffect(()=>{c(a)},[a]),n.jsxs("form",{onSubmit:l(r),children:[n.jsx(se,{canSubmit:i.isDirty}),n.jsx(RS,{form:o})]})}const tT=[{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 nT extends J{constructor(){super(...arguments);V(this,"VERSION",1)}configVersions(){this.version(1,r=>({version:1,config:r}))}}const rT={displayName:"viz.vizDashboardState.viz_name",displayGroup:"chart.groups.others",migrator:new nT,name:"vizDashboardState",viewRender:XS,configRender:eT,createConfig:()=>({version:1,config:Ul}),translation:tT},aT=()=>n.jsxs("svg",{width:"64",height:"64",viewBox:"0 0 64 64",fill:"none",children:[n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M22.49 27.79H14.47C13.55 27.79 12.81 28.53 12.81 29.45C12.81 30.37 13.55 31.11 14.47 31.11H22.49C23.41 31.11 24.15 30.37 24.15 29.45C24.15 28.54 23.41 27.79 22.49 27.79ZM34.32 31.28C35.22 31.32 35.7 31.82 35.74 32.76C35.78 33.54 35.37 34.3 34.51 35.04C33.52 35.9 33.03 36.95 33.03 38.19V38.81H34.82V38.25C34.78 37.59 35.07 37.02 35.68 36.52C37.12 35.41 37.82 34.15 37.78 32.75C37.66 30.53 36.5 29.35 34.32 29.23C32.3 29.23 31.05 30.46 30.55 32.93L32.53 33.55C32.82 32.04 33.42 31.28 34.32 31.28ZM35 39.93H32.84V42.21H35V39.93ZM14.83 36.42H18.54C19.46 36.42 20.2 37.17 20.2 38.08C20.2 39 19.46 39.74 18.54 39.74H10.52C9.6 39.74 8.86 39 8.86 38.08C8.86 37.61 9.06 37.19 9.37 36.89H5.66C4.74 36.89 4 36.15 4 35.23C4 34.31 4.74 33.57 5.66 33.57H13.68C14.6 33.57 15.34 34.31 15.34 35.23C15.34 35.7 15.14 36.12 14.83 36.42ZM50.94 36.85H58.74C59.66 36.85 60.4 37.59 60.41 38.51C60.41 39.43 59.67 40.17 58.75 40.17H54.26C54.56 40.47 54.74 40.88 54.74 41.34C54.74 42.26 54 43 53.08 43H50.94V36.85Z",fill:"#B8C0CC"}),n.jsx("path",{d:"M18.39 32.28H16.51V35.02H18.39V32.28Z",fill:"#9399A5"}),n.jsx("path",{d:"M46.87 15H20.69C18.38 15 16.5 16.88 16.5 19.19V26.22H18.38V23.45H49.18V47.68H18.38V41.07H16.5V49.55H51.05V19.19C51.06 16.88 49.18 15 46.87 15ZM39.46 20.73C38.81 20.73 38.29 20.2 38.29 19.56C38.29 18.92 38.82 18.39 39.46 18.39C40.11 18.39 40.63 18.92 40.63 19.56C40.63 20.2 40.11 20.73 39.46 20.73ZM43.22 20.73C42.57 20.73 42.05 20.2 42.05 19.56C42.05 18.92 42.58 18.39 43.22 18.39C43.87 18.39 44.39 18.92 44.39 19.56C44.39 20.2 43.87 20.73 43.22 20.73ZM46.97 20.73C46.32 20.73 45.8 20.2 45.8 19.56C45.8 18.92 46.33 18.39 46.97 18.39C47.62 18.39 48.14 18.92 48.14 19.56C48.14 20.2 47.62 20.73 46.97 20.73Z",fill:"#9399A5"})]});function Kl(e,t){const r=b.get(e,t,"");if(r)throw new Error(r)}async function sT(e,t,r,a={}){const o={"X-Requested-With":"XMLHttpRequest","Content-Type":a.string?"application/x-www-form-urlencoded":"application/json",...a.headers},l={baseURL:e,method:"POST",url:t,params:a.params,headers:o};return l.data=a.string?JSON.stringify(r):r,ke(l).then(i=>i.data).catch(i=>Promise.reject(i))}const oT=({conf:e,panelData:t})=>async()=>{const{expertSystemURL:r,path:a,goal:o,question:l}=e;if(!a||!o||!l)return;const i=sp(t);if(!i)return;const c={dashboard:o,panel:l,data:i};try{const d=r.startsWith("http")?r:window.location.origin;return await sT(d,`/expert/v3/devtable/${a}`,c,{})}catch(d){throw Kl(d,"response.data.detail"),Kl(d,"response.data.error"),console.error(d),d}},ra={expertSystemURL:"",path:"",goal:"",question:""},aa={height:"100%",overflowY:"auto",...lr},Yl=({message:e})=>n.jsx(s.Box,{sx:aa,children:n.jsx("div",{dangerouslySetInnerHTML:{__html:e},style:{fontSize:"14px",lineHeight:"32px",color:"#3D3E45"}})}),lT=({error:e,width:t,height:r})=>{const a=e.message;if(a.startsWith("<"))return n.jsx(Yl,{message:a});const l=r-25-20-30;return n.jsx(s.Center,{sx:{width:"100%",height:l},children:n.jsxs(s.Stack,{align:"center",gap:20,children:[n.jsx(aT,{}),n.jsx(Yl,{message:a})]})})};function iT({context:e}){const{value:t}=q(e.instanceData,"config"),r=h.useMemo(()=>b.defaultsDeep({},t,ra),[t]),{width:a,height:o}=e.viewport,l=e.data,{data:i,error:c,loading:d}=O.useRequest(oT({conf:r,panelData:l}),{refreshDeps:[l,r]});return!a||!o||!r?null:d?n.jsx(s.Box,{sx:{position:"relative",height:o},children:n.jsx(s.LoadingOverlay,{visible:!0})}):c?n.jsx(s.Box,{sx:aa,"data-enable-scrollbar":!0,children:n.jsx(lT,{error:c,width:a,height:o})}):!i||!Array.isArray(i.replies)||i.replies.length===0?null:n.jsx(s.Box,{sx:aa,"data-enable-scrollbar":!0,children:i.replies.map((u,p)=>n.jsx("div",{dangerouslySetInnerHTML:{__html:u.interpretation.html}},p))})}function cT({context:e}){const{value:t,set:r}=q(e.instanceData,"config"),a=h.useMemo(()=>b.defaultsDeep({},t,ra),[t]),{control:o,handleSubmit:l,watch:i,formState:c,reset:d}=y.useForm({defaultValues:a});return h.useEffect(()=>{d(a)},[a]),i(["expertSystemURL","goal","path","question"]),n.jsx("form",{onSubmit:l(r),children:n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,children:[n.jsx(y.Controller,{name:"expertSystemURL",control:o,render:({field:u})=>n.jsx(s.TextInput,{label:"Expert System URL",...u})}),n.jsx(y.Controller,{name:"path",control:o,render:({field:u})=>n.jsx(s.TextInput,{label:"Path",required:!0,...u})})]}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(y.Controller,{name:"goal",control:o,render:({field:u})=>n.jsx(s.TextInput,{label:"Goal",required:!0,...u})}),n.jsx(y.Controller,{name:"question",control:o,render:({field:u})=>n.jsx(s.TextInput,{label:"Question",required:!0,...u})})]}),n.jsx(s.Divider,{variant:"dashed",mt:16,mb:8}),n.jsx(s.Button,{type:"submit",variant:"filled",color:"blue",leftSection:n.jsx(S.IconDeviceFloppy,{size:20}),disabled:!c.isDirty,sx:{alignSelf:"flex-end"},children:"Submit Changes"})]})})}const dT=[{lang:"en",resources:{merico_gqm:{viz_name:"Merico GQM"}}},{lang:"zh",resources:{merico_gqm:{viz_name:"思码逸GQM组件"}}}];class uT extends J{constructor(){super(...arguments);V(this,"VERSION",1)}configVersions(){this.version(1,r=>({version:1,config:r}))}}const pT={displayName:"viz.merico_gqm.viz_name",displayGroup:"chart.groups.merico_suite",migrator:new uT,name:"mericoGQM",viewRender:iT,configRender:cT,createConfig(){return{version:1,config:b.cloneDeep(ra)}},translation:dT};class hT extends J{constructor(){super(...arguments);V(this,"VERSION",1)}configVersions(){this.version(1,r=>({version:1,config:r}))}}function gT({context:e}){const{t}=m.useTranslation(),{inEditMode:r}=Us();if(!r)return null;const{width:a,height:o}=e.viewport;return n.jsx(s.Center,{w:a,h:o,title:t("viz.merico_panel_groups.render"),children:n.jsx(s.Text,{c:"dimmed",size:"xs",children:t("viz.merico_panel_groups.render")})})}const fT=[{lang:"en",resources:{merico_panel_groups:{viz_name:"Merico Panel Groups",render:'"Merico Panel Groups" is a ghost viz, the whole panel will not shown in dashboard',groups:{label:"Groups",add:"Add a group",name:"Name",comment:"Remark",panel_ids:"Panels",yaml:{button:"Import from YAML",modal_title:"Import from YAML",label:"YAML content",submit:"Submit",error_title:"Failed"}}}}},{lang:"zh",resources:{merico_panel_groups:{viz_name:"思码逸卡片组",render:"在使用看板时,思码逸卡片组不会参与渲染",groups:{label:"卡片组",add:"增加一组",name:"名称",comment:"备注",panel_ids:"卡片",yaml:{button:"从YAML导入",modal_title:"从YAML导入",label:"YAML内容",submit:"提交",error_title:"解析失败"}}}}}],Xl=()=>({groups:[]}),bT=({append:e})=>{const{t}=m.useTranslation(),r=()=>{e({name:"",comment:"",panelIDs:[]})};return n.jsx(s.Flex,{gap:"sm",justify:"center",align:"center",direction:"row",wrap:"nowrap",children:n.jsx(s.Group,{wrap:"nowrap",style:{flex:1},children:n.jsx(s.Button,{size:"xs",variant:"subtle",onClick:r,leftSection:n.jsx(S.IconPlus,{size:14}),children:t("viz.merico_panel_groups.groups.add")})})})},yT=({row:e,index:t,handleChange:r,handleRemove:a,panelOptions:o})=>{const{t:l}=m.useTranslation(),[i,{setTrue:c}]=O.useBoolean(!1),d=f=>{r({...e,name:f})},u=f=>{r({...e,comment:f})},p=f=>{r({...e,panelIDs:f})};return n.jsxs(s.Stack,{gap:"xs",p:"xs",style:{border:"1px solid var(--mantine-color-gray-4)",borderRadius:"2px"},children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",style:{flex:1},children:[n.jsx(s.TextInput,{size:"xs",value:e.name,placeholder:l("viz.merico_panel_groups.groups.name"),onChange:f=>d(f.currentTarget.value),onClick:c,error:i&&!e.name}),n.jsx(s.TextInput,{size:"xs",value:e.comment,placeholder:l("viz.merico_panel_groups.groups.comment"),onChange:f=>u(f.currentTarget.value)})]}),n.jsx(s.MultiSelect,{label:"",placeholder:l("viz.merico_panel_groups.groups.panel_ids"),onChange:p,value:e.panelIDs,clearable:!0,size:"xs",data:o,maxDropdownHeight:500,comboboxProps:{width:300,position:"bottom-start"}}),n.jsx(s.Button,{variant:"subtle",color:"red",size:"xs",ml:"auto",mt:"md",leftSection:n.jsx(S.IconTrash,{size:14}),onClick:a,children:"删除这一组"})]})};function vT(e){try{const t=[],r=e.split(`
|
|
531
|
-
`);let a="";for(let o=0;o<r.length;o++){const l=r[o];if(l.includes("#")){const d=l.split("# ")[1].trim();d&&(a=d,console.log({comment:a}));continue}const[i,c]=l.split(": ").map(d=>d.trim());console.log({name:i,panelIDString:c}),t.push({name:i,comment:a,panelIDs:JSON.parse(c)})}return t}catch(t){throw t}}const _T=({onSubmit:e})=>{const{t}=m.useTranslation(),[r,{setTrue:a,setFalse:o}]=O.useBoolean(!1),[l,i]=h.useState("");h.useEffect(()=>{i("")},[r]);const c=()=>{try{const d=vT(l);e(d),o()}catch(d){console.error(d),Ge.showNotification({title:t("viz.merico_panel_groups.groups.yaml.error_title"),message:d.message,color:"red"})}};return n.jsxs(n.Fragment,{children:[n.jsx(s.Button,{onClick:a,disabled:r,size:"xs",variant:"light",children:t("viz.merico_panel_groups.groups.yaml.button")}),n.jsx(s.Modal,{opened:r,onClose:o,title:t("viz.merico_panel_groups.groups.yaml.modal_title"),zIndex:340,size:800,children:n.jsxs(s.Stack,{gap:"lg",children:[n.jsx(s.Textarea,{label:t("viz.merico_panel_groups.groups.yaml.label"),value:l,onChange:d=>i(d.currentTarget.value),autosize:!0,minRows:10,maxRows:40,styles:{input:{fontFamily:"monospace",fontSize:"12px"}}}),n.jsx(s.Button,{ml:"auto",onClick:c,children:t("viz.merico_panel_groups.groups.yaml.submit")})]})})]})},mT=h.forwardRef(({value:e,onChange:t,data:r},a)=>{const{t:o}=m.useTranslation(),l=G(),i=h.useMemo(()=>e.map(w=>({id:Te.v4(),...w})),[e]),c=w=>{t([...e,w])},d=w=>{t(w)},u=w=>{const x=[...e];x.splice(w,1),t(x)},p=w=>x=>{const T=[...e];T[w]=x,t(T)},f=l.panels.options,v=h.useMemo(()=>new Set(i.map(w=>w.panelIDs).flat()),[i]),_=h.useMemo(()=>f.map(w=>({...w,disabled:v.has(w.value)})),[f,v]);return n.jsxs(s.Stack,{ref:a,pt:4,children:[n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Text,{size:"sm",fw:"500",mb:-4,children:o("viz.merico_panel_groups.groups.label")}),n.jsx(_T,{onSubmit:d})]}),i.map((w,x)=>n.jsx(yT,{row:w,handleChange:p(x),handleRemove:()=>u(x),index:x,panelOptions:_},w.id)),n.jsx(bT,{append:c})]})});function wT({context:e}){const{value:t,set:r}=q(e.instanceData,"config");m.useTranslation();const a=e.data,o=h.useMemo(()=>b.defaultsDeep({},t,Xl()),[t]),l=y.useForm({defaultValues:o}),{handleSubmit:i,formState:c,reset:d}=l;h.useEffect(()=>{l.reset(o)},[o]);const u=p=>{const f=p;f.groups=f.groups.filter(v=>v.panelIDs.length>0||!!v.name.trim()||!!v.comment.trim()),r(f)};return n.jsxs("form",{onSubmit:i(u),children:[n.jsx(se,{canSubmit:c.isDirty}),n.jsx(s.Stack,{gap:"lg",pt:"xs",px:"xs",children:n.jsx(y.Controller,{name:"groups",control:l.control,render:({field:p})=>n.jsx(mT,{...p,data:a})})})]})}const Zl={displayName:"viz.merico_panel_groups.viz_name",displayGroup:"chart.groups.merico_suite",migrator:new hT,name:"merico_panel_groups",viewRender:gT,configRender:wT,createConfig:()=>({version:1,config:Xl()}),translation:fT},xT=[{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"})),CT=[Lu,Ou,Fu,Gu,Nu,Qu],sa=[Rr,pC,$S,K0,AC,Fx,W_,_h,zf,mv,r_,Sb,ix,tv,K1,g0,F0,pT,Tm,Hm,Cw,Zl,uw,Nf,rT],Jl=sa.reduce((e,t)=>(e[t.name]={displayName:t.displayName,displayGroup:t.displayGroup},e),{}),Hl=()=>({id:"dashboard",version:Gs,manifest:{viz:sa,color:[...xT,...CT]}}),Mt=new Xu,ee={pluginManager:He("pluginManager"),vizManager:He("vizManager"),colorManager:He("colorManager"),panelAddonManager:He("panelAddonManager"),instanceScope:{panelModel:He("panelModel"),vizInstance:He("vizInstance"),interactionManager:He("interactionManager"),migrator:He("migrator"),operationManager:He("operationManager"),triggerManager:He("triggerManager")}},oa=()=>{try{Mt.install(Hl())}catch{}const e=new Eu(Mt),t=new Yu(Mt),r=new ju(Mt);return{pluginManager:Mt,vizManager:e,colorManager:t,panelAddonManager:r}},lt=h.createContext(oa());try{Mt.install(Hl())}catch{}const Mn=Ce.createInstance({debug:!1,fallbackLng:"en",interpolation:{escapeValue:!1},resources:{en:Pu,zh:$u}}).use(Ld).use(m.initReactI18next);Mn.init(),sa.forEach(e=>{var t;(t=e.translation)==null||t.forEach(r=>{Mn.addResourceBundle(r.lang,"translation",{viz:r.resources},!0,!0)})});function Rl({lang:e,children:t}){return h.useEffect(()=>{Mn.changeLanguage(e)},[e]),n.jsx(m.I18nextProvider,{i18n:Mn,children:t})}M.extend(Ud),M.extend(Kd),M.extend(Yd),M.extend(Xd),M.extend(Zd),M.extend(Jd),M.extend(Hd),M.extend(Rd),M.extend(eu),M.extend(tu),M.extend(au),M.extend(su),M.extend(ou),M.extend(lu),M.extend(iu),M.extend(nu),M.extend(ru),M.extend(cu),M.extend(du),M.extend(uu),M.extend(pu),M.extend(hu),M.extend(gu),M.extend(fu),M.extend(bu),M.extend(yu),M.extend(vu),M.extend(_u),M.extend(mu),M.extend(wu),M.extend(Cu),M.extend(Su),M.extend(xu),M.tz.setDefault("UTC"),M.updateLocale("en",{weekStart:1});function ST(e){e=e||{};const t=Object.keys(e).sort(),r=[];for(let a=0;a<t.length;a++){const o=t[a];if(o!="authentication"&&e[o])r.push(t[a]+"="+(typeof e[o]=="object"?JSON.stringify(e[o]):e[o]));else{const l=Object.keys(e[o]).sort();for(let i=0;i<l.length;i++){const c=l[i];c!="sign"&&e[o][c]&&r.push(l[i]+"="+(typeof e[o][c]=="object"?JSON.stringify(e[o][c]):e[o][c]))}}}return r.sort().join("&")}function TT(e,t){let r=ST(e);return r+="&key="+t,Iu.MD5(r).toString().toUpperCase()}class ei{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:TT({app_id:this.app_id,nonce_str:r,...t},this.app_secret)}}getRequest(t,r){return(a,o,l,i)=>{const c=this.buildHeader(l),d=this.buildAxiosConfig(t,a,o,l,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=b.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,o,l,i){const c={baseURL:this.baseURL,method:t,url:r,params:t==="GET"?a:o.params,headers:l,signal:i};return["POST","PUT"].includes(t)&&(c.data=o.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 kT{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 ti extends ei{constructor(){super(...arguments);V(this,"makeQueryENV",null)}query(r){return async(a,o={})=>{var l;return a.env||(a.env=((l=this.makeQueryENV)==null?void 0:l.call(this))??{error:"failed to run makeQueryENV"}),this.post(r)("/query",a,o)}}httpDataSourceQuery(r){return async(a,o={})=>{var l;return a.env||(a.env=((l=this.makeQueryENV)==null?void 0:l.call(this))??{error:"failed to run makeQueryENV"}),this.getRequest("POST",r)("/query",a,o,!0)}}structure(r){return async(a,o={})=>this.post(r)("/query/structure",a,o)}mericoMetricInfo(r){return async(a,o={})=>this.post(r)("/query/merico_metric_info",a,o,!0)}mericoMetricQuery(r){return async(a,o={})=>this.post(r)("/query",a,o,!0)}}class ni{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 Nt=new ti;function la(e){Nt.baseURL!==e.apiBaseURL&&(Nt.baseURL=e.apiBaseURL),e.app_id&&(Nt.app_id=e.app_id),e.app_secret&&(Nt.app_secret=e.app_secret),e.makeQueryENV&&(Nt.makeQueryENV=e.makeQueryENV)}const ri=new ni(Nt),$e=ri,ia=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 ca(e){return{current:e}}const DT=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}})),ai=g.types.model("PanelStyleMeta",{border:DT}).views(e=>({get json(){const{border:t}=e;return{border:t.json}}})).actions(e=>({})),si=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}})),oi=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:o,formatter:l,data_field:i,aggregation:c}=e;return b.cloneDeep({name:t,size:r,color:o,weight:a,formatter:l,data_field:i,aggregation:c})}})),li=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){b.isEqual(e.conf,t)||(e.conf=t)}})),ii=g.types.model({id:g.types.string,name:g.types.optional(g.types.string,""),title:si,description:g.types.string,queryIDs:g.types.array(g.types.string),viz:li,style:ai,variables:g.types.optional(g.types.array(oi),[])}).views(e=>({get json(){const{id:t,name:r,title:a,description:o,queryIDs:l}=e;return{id:t,viz:e.viz.json,name:r,style:e.style.json,title:a.json,queryIDs:[...l],variables:e.variables.map(i=>i.json),description:o}},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 W=(e=>(e.Postgresql="postgresql",e.MySQL="mysql",e.HTTP="http",e.Transform="transform",e.MericoMetricSystem="merico_metric_system",e))(W||{});const ci=g.types.model("DBQueryMeta",{_type:g.types.enumeration([W.MySQL,W.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}})),zT=e=>ci.create({_type:e,sql:""}),di=g.types.model("HTTPQueryMeta",{_type:g.types.literal(W.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 st({react_to:t,_type:r})}})).actions(e=>({setReactTo(t){e.react_to.length=0,e.react_to.push(...t)}})),MT=()=>di.create({_type:W.HTTP,react_to:[]}),ui=g.types.model("TransformQueryMeta",{_type:g.types.literal(W.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 st({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)}})),IT=()=>ui.create({_type:W.Transform,dep_query_ids:[]}),pi=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()}})),da=g.types.model("MericoMetricQueryMeta",{_type:g.types.literal(W.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(pi),[]),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),extraCalculations:g.types.optional(g.types.array(g.types.string),[])}).views(e=>({get query(){return g.getParent(e)},get valid(){return!!e.id},get json(){const{id:t,type:r,filters:a,groupBys:o,timeQuery:l,useDefaultValues:i,extraCalculations:c,_type:d}=e;return st({id:t,type:r,filters:a.map(u=>u.json),groupBys:o,timeQuery:l,useDefaultValues:i,extraCalculations:c,_type:d})},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,e.extraCalculations.length=0,"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(pi.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},setExtraCalculations(t){e.extraCalculations.length=0,e.extraCalculations.push(...t)}})),hi=()=>da.create({_type:W.MericoMetricSystem,id:"",type:"derived",filters:[],groupBys:[],timeQuery:{range_variable:"",unit_variable:"",timezone:"PRC",stepKeyFormat:"YYYY-MM-DD"},useDefaultValues:!1,extraCalculations:[]}),gi=g.types.model("QueryMeta",{id:g.types.string,name:g.types.string,key:g.types.string,type:g.types.enumeration("DataSourceType",[W.Postgresql,W.MySQL,W.HTTP,W.Transform,W.MericoMetricSystem]),config:g.types.union(ci,di,ui,da),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:o,config:l}=e;return l.valid&&!!t&&!!r&&!!a&&!!o},get json(){const{id:t,name:r,key:a,type:o,config:l,pre_process:i,post_process:c,run_by:d}=e;return st({id:t,name:r,key:a,type:o,config:l.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 W.HTTP:e.config=MT();break;case W.MySQL:case W.Postgresql:e.config=zT(t);break;case W.Transform:e.config=IT();break;case W.MericoMetricSystem:e.config=hi();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}})),fi=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:o,w:l,h:i,moved:c}=e;return{h:i,w:l,x:a,y:o===null?0:o,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:o,h:l,moved:i}=e;return{id:t,i:t,x:r,y:a===null?1/0:a,w:o,h:l,moved:i,static:e.static}}})).actions(e=>({set(t){const{isDraggable:r,x:a,y:o,w:l,h:i,moved:c}=t;e.x=a,e.y=o,e.w=l,e.h=i,e.moved=!!c,e.static=!!t.static},setWidth(t){e.w=t},setHeight(t){e.h=t}})),bi=g.types.model("LayoutSetMeta",{id:g.types.identifier,name:g.types.string,breakpoint:g.types.number,list:g.types.optional(g.types.array(fi),[])}).views(e=>({get contentModel(){return g.getRoot(e).content},get json(){const{id:t,name:r,breakpoint:a,list:o}=e;return{id:t,name:r,breakpoint:a,list:o.map(l=>st(l.json))}},jsonByPanelIDSet(t){const{id:r,name:a,breakpoint:o,list:l}=e;return{id:r,name:a,breakpoint:o,list:l.filter(i=>t.has(i.panelID)).map(i=>st(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:Te.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,F.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 o={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};Ge.showNotification(o),Ge.updateNotification(o)},{fireImmediately:!0,delay:0}))}})),yi=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 P=(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.MericoDateRange="merico-date-range",e))(P||{});const ua=g.types.optional(g.types.enumeration(["intersect","reset"]),"intersect"),pa=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}})),vi=()=>pa.create({_name:"checkbox",description:"",default_value:!1}),_i=()=>[{key:"d",value:"yesterday",group:"last",getRange:()=>{const e=M();return{value:[e.subtract(1,"day").startOf("day").toDate(),e.subtract(1,"day").endOf("day").toDate()],shortcut:"yesterday"}}},{key:"w",value:"last week",group:"last",getRange:()=>{const e=M();return{value:[e.subtract(1,"week").startOf("week").toDate(),e.subtract(1,"week").endOf("week").toDate()],shortcut:"last week"}}},{key:"m",value:"last month",group:"last",getRange:()=>{const e=M();return{value:[e.subtract(1,"month").startOf("month").toDate(),e.subtract(1,"month").endOf("month").toDate()],shortcut:"last month"}}},{key:"m2",value:"last 2 months",group:"last",getRange:()=>{const e=M();return{value:[e.subtract(2,"month").startOf("month").toDate(),e.subtract(1,"month").endOf("month").toDate()],shortcut:"last 2 months"}}},{key:"m3",value:"last 3 months",group:"last",getRange:()=>{const e=M();return{value:[e.subtract(3,"month").startOf("month").toDate(),e.subtract(1,"month").endOf("month").toDate()],shortcut:"last 3 months"}}},{key:"y",value:"last year",group:"last",getRange:()=>{const e=M();return{value:[e.subtract(1,"year").startOf("year").toDate(),e.subtract(1,"year").endOf("year").toDate()],shortcut:"last year"}}},{key:"d7",value:"recent 7 days",group:"recent",getRange:()=>{const e=M();return{value:[e.subtract(7,"day").startOf("day").toDate(),e.subtract(1,"day").endOf("day").toDate()],shortcut:"recent 7 days"}}},{key:"d30",value:"recent 30 days",group:"recent",getRange:()=>{const e=M();return{value:[e.subtract(30,"day").startOf("day").toDate(),e.subtract(1,"day").endOf("day").toDate()],shortcut:"recent 30 days"}}},{key:"d60",value:"recent 60 days",group:"recent",getRange:()=>{const e=M();return{value:[e.subtract(60,"day").startOf("day").toDate(),e.subtract(1,"day").endOf("day").toDate()],shortcut:"recent 60 days"}}},{key:"d90",value:"recent 90 days",group:"recent",getRange:()=>{const e=M();return{value:[e.subtract(90,"day").startOf("day").toDate(),e.subtract(1,"day").endOf("day").toDate()],shortcut:"recent 90 days"}}},{key:"d180",value:"recent 180 days",group:"recent",getRange:()=>{const e=M();return{value:[e.subtract(180,"day").startOf("day").toDate(),e.subtract(1,"day").endOf("day").toDate()],shortcut:"recent 180 days"}}},{key:"d365",value:"recent 365 days",group:"recent",getRange:()=>{const e=M();return{value:[e.subtract(365,"day").startOf("day").toDate(),e.subtract(1,"day").endOf("day").toDate()],shortcut:"recent 365 days"}}},{key:"d",value:"today",group:"this",getRange:()=>{const e=M();return{value:[e.startOf("day").toDate(),e.endOf("day").toDate()],shortcut:"today"}}},{key:"w",value:"this week",group:"this",getRange:()=>{const e=M();return{value:[e.startOf("week").toDate(),e.endOf("week").toDate()],shortcut:"this week"}}},{key:"m",value:"this month",group:"this",getRange:()=>{const e=M();return{value:[e.startOf("month").toDate(),e.endOf("month").toDate()],shortcut:"this month"}}},{key:"y",value:"this year",group:"this",getRange:()=>{const e=M();return{value:[e.startOf("year").toDate(),e.endOf("year").toDate()],shortcut:"this year"}}},{key:"w",value:"this week so far",group:"this_so_far",getRange:()=>{const e=M();return{value:[e.startOf("week").toDate(),e.endOf("day").toDate()],shortcut:"this week so far"}}},{key:"m",value:"this month so far",group:"this_so_far",getRange:()=>{const e=M();return{value:[e.startOf("month").toDate(),e.endOf("day").toDate()],shortcut:"this month so far"}}},{key:"y",value:"this year so far",group:"this_so_far",getRange:()=>{const e=M();return{value:[e.startOf("year").toDate(),e.endOf("day").toDate()],shortcut:"this year so far"}}}];function In(e){if(!e)return null;const r=_i().find(a=>a.value===e);return r?r.getRange():null}function mi(){return b.groupBy(_i(),"group")}function wi(e){try{if(e.default_shortcut){const r=In(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 xi(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 VT=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:o,inputFormat:l,default_value:i,default_shortcut:c,allowSingleDateInRange:d}=e;return{_name:t,max_days:r,required:a,clearable:o,inputFormat:l,default_value:xi(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,o=r?M(r).format(e.inputFormat):"",l=a?M(a).format(e.inputFormat):"";return[o,l]}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=In(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}})),ha=g.types.snapshotProcessor(VT,{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:xi(t,r.inputFormat)}}}),Ci=()=>ha.create({_name:"date-range",required:!1,inputFormat:"YYYY-MM-DD",clearable:!1,default_value:[null,null]}),Si=g.types.model({label:g.types.string,value:g.types.string}).actions(e=>({setLabel(t){e.label=t},setValue(t){e.value=t}})),ga=g.types.model("FilterConfigModel_BaseSelect",{static_options:g.types.optional(g.types.array(Si),[]),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=>Si.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??""}})),fa=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:ua}),ga).views(e=>({get json(){const{_name:t,default_value:r,default_value_mode:a,required:o,min_width:l,static_options:i,options_query_id:c,default_selection_count:d}=e;return st({_name:t,required:!!o,min_width:l,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(o=>o.value)),a=(e.filter.value??[]).filter(o=>t.has(o));a.length>0?e.filter.setValue(a):e.filter.setValue(e.defaultSelection)}})).actions(e=>({afterCreate(){g.addDisposer(e,F.reaction(()=>F.toJS(e.defaultSelection),e.applyDefaultSelection,{fireImmediately:!1,delay:0}))}})),Ti=()=>fa.create({_name:"multi-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),ba=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)}),ga).views(e=>({get json(){const{_name:t,clearable:r,default_value:a,required:o,width:l,static_options:i,options_query_id:c,default_selection_count:d}=e;return st({_name:t,width:l,required:o,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(o=>o.value===t))==null?void 0:a.value;r?e.filter.setValue(r):e.filter.setValue(e.default_selection)}})).actions(e=>({afterCreate(){g.addDisposer(e,F.reaction(()=>F.toJS(e.default_selection),e.setDefaultSelection,{fireImmediately:!1,delay:0}))}})),ki=()=>ba.create({_name:"select",required:!1,default_value:"",static_options:[],options_query_id:"",default_selection_count:0}),ya=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}})),va=()=>ya.create({_name:"text-input",required:!1,default_value:""}),PT=`
|
|
530
|
+
`),ea={func_content:jl,horizontal_align:"left",font_size:"14px",font_weight:"normal"},TS=k.observer(({context:e})=>{const t=H(),{value:r=ea}=q(e.instanceData,"config"),{variables:a}=e,o=e.data,{func_content:l,horizontal_align:i,font_size:c,font_weight:d}=r,u=h.useMemo(()=>a.reduce((f,v)=>{const _=Re(v,o);return f[v.name]=Be(v,_),f},{}),[a,o]),p=h.useMemo(()=>new Function(`return ${l}`)()({data:o,variables:u,filters:t.payloadForSQL.filters,context:t.payloadForSQL.context}),[l,o,u,t.payloadForSQL]);return n.jsx(s.Text,{ta:i,fw:d,sx:{fontSize:c},children:p})}),zn=[{label:"initial",value:0},{label:"500",value:25},{label:"700",value:50},{label:"semibold",value:75},{label:"bold",value:100}];function kS({label:e,value:t,onChange:r},a){var i;const[o,l]=h.useState(((i=zn.find(c=>c.label===t))==null?void 0:i.value)??zn[0].value);return h.useEffect(()=>{const c=zn.find(d=>d.value===o);c&&r(c.label)},[o]),n.jsxs(s.Stack,{gap:0,mt:"sm",mb:"lg",children:[n.jsx(s.Text,{size:"sm",children:e}),n.jsx(s.Box,{px:"1.5em",children:n.jsx(s.Slider,{label:null,marks:zn,value:o,onChange:l,step:25,ref:a})})]})}const DS=h.forwardRef(kS),zS=({value:e,onChange:t})=>{const r=a=>{a&&t(a)};return n.jsx(s.Box,{sx:{position:"relative"},children:n.jsx(Se,{height:"500px",defaultLanguage:"javascript",value:e,onChange:r,theme:"vs-dark",options:{minimap:{enabled:!1}}})})},MS=h.forwardRef(({value:e,onChange:t},r)=>{const{t:a}=m.useTranslation(),[o,{setTrue:l,setFalse:i}]=O.useBoolean(),[c,d]=h.useState(e),u=()=>{i(),t(c)},p=()=>{i(),d(e)},f=()=>{d(jl)};return h.useEffect(()=>{d(e)},[e]),n.jsxs(n.Fragment,{children:[n.jsx(s.Button,{color:"grape",variant:"filled",leftSection:n.jsx(S.IconMathFunction,{size:16}),mt:24,onClick:l,sx:{flexGrow:0},children:a("viz.text.content.edit")}),n.jsx(s.Modal,{size:800,title:a("viz.text.content.label"),opened:o,onClose:i,closeOnClickOutside:!1,withCloseButton:!1,zIndex:320,children:o&&n.jsxs(s.Stack,{children:[n.jsx(zS,{value:c,onChange:d}),n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Button,{onClick:f,color:"red",leftSection:n.jsx(S.IconRecycle,{size:20}),children:a("common.actions.reset_to_default")}),n.jsxs(s.Group,{justify:"flex-end",children:[n.jsx(s.Button,{onClick:p,variant:"subtle",children:a("common.actions.cancel")}),n.jsx(s.Button,{color:"green",leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),onClick:u,children:a("common.actions.save_changes")})]})]})]})})]})});function IS({context:e}){const{t}=m.useTranslation(),{value:r,set:a}=q(e.instanceData,"config"),o=h.useMemo(()=>b.defaultsDeep({},r,ea),[r]),l=h.useMemo(()=>{const{func_content:f,horizontal_align:v,font_size:_,font_weight:w}=o;return{func_content:f,horizontal_align:v,font_size:_,font_weight:w}},[o]);h.useEffect(()=>{!b.isEqual(o,l)&&(console.log("config malformed, resetting to defaults",o,l),a(l))},[o,l]);const{control:i,handleSubmit:c,watch:d,formState:u,reset:p}=y.useForm({defaultValues:l});return h.useEffect(()=>{p(l)},[l]),d(["func_content","horizontal_align","font_size","font_weight"]),n.jsx(s.Stack,{gap:"xs",children:n.jsxs("form",{onSubmit:c(a),children:[n.jsx(se,{canSubmit:u.isDirty}),n.jsxs(s.Stack,{gap:10,children:[n.jsx(y.Controller,{name:"func_content",control:i,render:({field:f})=>n.jsx(MS,{...f})}),n.jsx(s.Divider,{mt:10,mb:-10,variant:"dashed",label:t("chart.style.label"),labelPosition:"center"}),n.jsx(y.Controller,{name:"horizontal_align",control:i,render:({field:f})=>n.jsx(Dr,{...f})}),n.jsx(y.Controller,{name:"font_size",control:i,render:({field:f})=>n.jsx(s.TextInput,{label:t("style.font_size.label"),placeholder:t("style.font_size.placeholder"),sx:{flex:1},...f})}),n.jsx(s.Group,{justify:"space-between",grow:!0,sx:{"> *":{flexGrow:1,maxWidth:"100%"}},children:n.jsx(y.Controller,{name:"font_weight",control:i,render:({field:f})=>n.jsx(DS,{label:t("style.font_weight.label"),...f})})})]})]})})}const VS=[{lang:"en",resources:{text:{viz_name:"Text",content:{label:"Text content",edit:"Edit Content"}}}},{lang:"zh",resources:{text:{viz_name:"文本",content:{label:"文本内容",edit:"编辑文本内容"}}}}];class PS extends J{constructor(){super(...arguments);V(this,"VERSION",1)}configVersions(){this.version(1,r=>({version:1,config:r}))}}const $S={displayName:"viz.text.viz_name",displayGroup:"chart.groups.others",migrator:new PS,name:"text",viewRender:TS,configRender:IS,createConfig(){return{version:1,config:b.cloneDeep(ea)}},translation:VS},ta={item_badge:"_item_badge_l2t3l_1",label:"_label_l2t3l_8",value:"_value_l2t3l_20"},AS=({children:e})=>["string","number"].includes(typeof e)?n.jsx(s.Text,{size:"xs",ff:"monospace",children:e}):e,vt=h.forwardRef(({label:e,value:t,label_description:r,value_description:a},o)=>n.jsxs("div",{ref:o,className:ta.item_badge,children:[n.jsx("div",{className:ta.label,children:e}),n.jsxs(s.HoverCard,{shadow:"md",disabled:!a,children:[n.jsx(s.HoverCard.Target,{children:n.jsx("div",{className:ta.value,"data-with-tooltip":!!a,children:t})}),n.jsx(s.HoverCard.Dropdown,{p:"xs",children:n.jsx(AS,{children:a})})]})]})),ES=({item:e})=>e.type!=="checkbox"?null:n.jsx(vt,{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}`}),BS=({item:e})=>e.type!=="context"?null:n.jsx(vt,{label:e.key,value:e.value,label_description:`context.${e.key}`}),qS=k.observer(({item:e})=>{const{t}=m.useTranslation(),a=e.model.value,[o,l]=a.value,i=h.useMemo(()=>!l&&!o?Number.NaN:M(l).diff(M(o),"days")+1,[o,l]);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(vt,{label:e.label,value:e.value.join(" ~ "),label_description:`filters.${e.key}`,value_description:c})}),LS=({item:e})=>e.type!=="date-range"?null:n.jsx(qS,{item:e}),Wl=({selection:e})=>(m.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))})),OS=k.observer(({item:e})=>{m.useTranslation();const r=e.model.config,a=h.useMemo(()=>r.optionsByValues(e.value),[e.value,r.options]);return n.jsx(vt,{label:e.label,value:a.length,label_description:`filters.${e.key}`,value_description:n.jsx(Wl,{selection:a})})}),NS=({item:e})=>e.type!=="multi-select"?null:n.jsx(OS,{item:e}),GS=k.observer(({item:e})=>{m.useTranslation();const r=e.model.config,a=h.useMemo(()=>{var o;return((o=r.options.find(l=>l.value===e.value))==null?void 0:o.label)??e.value},[e.value,r.options]);return n.jsx(vt,{label:e.label,value:a,label_description:`filters.${e.key}`})}),FS=({item:e})=>e.type!=="select"?null:n.jsx(GS,{item:e}),QS=({item:e})=>e.type!=="text-input"?null:n.jsx(vt,{label:e.label,value:n.jsx(s.Text,{maw:200,size:"xs",truncate:"end",ff:"monospace",children:e.value}),value_description:e.value}),jS=k.observer(({item:e})=>{m.useTranslation();const r=e.model.config,a=h.useMemo(()=>r.optionsByValues(e.value),[e.value,r.options]);return n.jsx(vt,{label:e.label,value:a.length,label_description:`filters.${e.key}`,value_description:n.jsx(Wl,{selection:a})})}),WS=({item:e})=>e.type!=="tree-select"?null:n.jsx(jS,{item:e}),US=k.observer(({item:e})=>{m.useTranslation();const r=e.model.config,a=h.useMemo(()=>{var o;return((o=r.options.find(l=>l.value===e.value))==null?void 0:o.label)??e.value},[e.value,r.options]);return n.jsx(vt,{label:e.label,value:a,label_description:`filters.${e.key}`,value_description:e.value})}),KS=({item:e})=>e.type!=="tree-single-select"?null:n.jsx(US,{item:e}),na=({item:e})=>{switch(e.type){case"date-range":return n.jsx(LS,{item:e});case"select":return n.jsx(FS,{item:e});case"tree-single-select":return n.jsx(KS,{item:e});case"multi-select":return n.jsx(NS,{item:e});case"tree-select":return n.jsx(WS,{item:e});case"text-input":return n.jsx(QS,{item:e});case"checkbox":return n.jsx(ES,{item:e});case"context":return n.jsx(BS,{item:e});default:return null}},YS=k.observer(({conf:e})=>{const r=H().dashboardState,{all:a,keys:o}=e;return a?n.jsxs(n.Fragment,{children:[Object.entries(r.context).map(([l,i])=>n.jsx(na,{item:i},l)),Object.entries(r.filters).map(([l,i])=>n.jsx(na,{item:i},l))]}):n.jsx(n.Fragment,{children:o.map(l=>{const i=b.get(r,l);return i?n.jsx(na,{item:i},l):null})})}),XS=k.observer(({context:e})=>{const{value:t}=q(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(YS,{conf:t})}):null}),Ul={all:!0,keys:[]},ZS={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"},JS=({option:e,checked:t,...r})=>{const{t:a}=m.useTranslation(),o=e,l=o.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}),l&&n.jsx(s.Text,{size:"xs",c:t?"rgba(0,0,0,.8)":"dimmed",style:{flexShrink:0,flexGrow:0},children:a(ZS[o.widget])})]})})]})},HS=k.observer(({value:e,onChange:t,disabled:r})=>{const{t:a}=m.useTranslation(),l=F().dashboardStateVariableOptions,i=h.useMemo(()=>{const{optionGroups:c,validValues:d}=l,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},[l,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:JS,maxDropdownHeight:600,value:e,onChange:t,disabled:r,clearable:!0})}),RS=({form:e})=>{const{t}=m.useTranslation(),r=e.watch("all");return n.jsxs(s.Stack,{gap:"xs",p:"xs",children:[n.jsx(y.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:o=>a.onChange(o.currentTarget.checked)})}),n.jsx(y.Controller,{name:"keys",control:e.control,render:({field:a})=>n.jsx(HS,{disabled:r,...a})})]})};function eT({context:e}){const{value:t,set:r}=q(e.instanceData,"config"),a=h.useMemo(()=>b.defaultsDeep({},t,Ul),[t]),o=y.useForm({defaultValues:a}),{handleSubmit:l,formState:i,reset:c}=o;return h.useEffect(()=>{c(a)},[a]),n.jsxs("form",{onSubmit:l(r),children:[n.jsx(se,{canSubmit:i.isDirty}),n.jsx(RS,{form:o})]})}const tT=[{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 nT extends J{constructor(){super(...arguments);V(this,"VERSION",1)}configVersions(){this.version(1,r=>({version:1,config:r}))}}const rT={displayName:"viz.vizDashboardState.viz_name",displayGroup:"chart.groups.others",migrator:new nT,name:"vizDashboardState",viewRender:XS,configRender:eT,createConfig:()=>({version:1,config:Ul}),translation:tT},aT=()=>n.jsxs("svg",{width:"64",height:"64",viewBox:"0 0 64 64",fill:"none",children:[n.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M22.49 27.79H14.47C13.55 27.79 12.81 28.53 12.81 29.45C12.81 30.37 13.55 31.11 14.47 31.11H22.49C23.41 31.11 24.15 30.37 24.15 29.45C24.15 28.54 23.41 27.79 22.49 27.79ZM34.32 31.28C35.22 31.32 35.7 31.82 35.74 32.76C35.78 33.54 35.37 34.3 34.51 35.04C33.52 35.9 33.03 36.95 33.03 38.19V38.81H34.82V38.25C34.78 37.59 35.07 37.02 35.68 36.52C37.12 35.41 37.82 34.15 37.78 32.75C37.66 30.53 36.5 29.35 34.32 29.23C32.3 29.23 31.05 30.46 30.55 32.93L32.53 33.55C32.82 32.04 33.42 31.28 34.32 31.28ZM35 39.93H32.84V42.21H35V39.93ZM14.83 36.42H18.54C19.46 36.42 20.2 37.17 20.2 38.08C20.2 39 19.46 39.74 18.54 39.74H10.52C9.6 39.74 8.86 39 8.86 38.08C8.86 37.61 9.06 37.19 9.37 36.89H5.66C4.74 36.89 4 36.15 4 35.23C4 34.31 4.74 33.57 5.66 33.57H13.68C14.6 33.57 15.34 34.31 15.34 35.23C15.34 35.7 15.14 36.12 14.83 36.42ZM50.94 36.85H58.74C59.66 36.85 60.4 37.59 60.41 38.51C60.41 39.43 59.67 40.17 58.75 40.17H54.26C54.56 40.47 54.74 40.88 54.74 41.34C54.74 42.26 54 43 53.08 43H50.94V36.85Z",fill:"#B8C0CC"}),n.jsx("path",{d:"M18.39 32.28H16.51V35.02H18.39V32.28Z",fill:"#9399A5"}),n.jsx("path",{d:"M46.87 15H20.69C18.38 15 16.5 16.88 16.5 19.19V26.22H18.38V23.45H49.18V47.68H18.38V41.07H16.5V49.55H51.05V19.19C51.06 16.88 49.18 15 46.87 15ZM39.46 20.73C38.81 20.73 38.29 20.2 38.29 19.56C38.29 18.92 38.82 18.39 39.46 18.39C40.11 18.39 40.63 18.92 40.63 19.56C40.63 20.2 40.11 20.73 39.46 20.73ZM43.22 20.73C42.57 20.73 42.05 20.2 42.05 19.56C42.05 18.92 42.58 18.39 43.22 18.39C43.87 18.39 44.39 18.92 44.39 19.56C44.39 20.2 43.87 20.73 43.22 20.73ZM46.97 20.73C46.32 20.73 45.8 20.2 45.8 19.56C45.8 18.92 46.33 18.39 46.97 18.39C47.62 18.39 48.14 18.92 48.14 19.56C48.14 20.2 47.62 20.73 46.97 20.73Z",fill:"#9399A5"})]});function Kl(e,t){const r=b.get(e,t,"");if(r)throw new Error(r)}async function sT(e,t,r,a={}){const o={"X-Requested-With":"XMLHttpRequest","Content-Type":a.string?"application/x-www-form-urlencoded":"application/json",...a.headers},l={baseURL:e,method:"POST",url:t,params:a.params,headers:o};return l.data=a.string?JSON.stringify(r):r,ke(l).then(i=>i.data).catch(i=>Promise.reject(i))}const oT=({conf:e,panelData:t})=>async()=>{const{expertSystemURL:r,path:a,goal:o,question:l}=e;if(!a||!o||!l)return;const i=sp(t);if(!i)return;const c={dashboard:o,panel:l,data:i};try{const d=r.startsWith("http")?r:window.location.origin;return await sT(d,`/expert/v3/devtable/${a}`,c,{})}catch(d){throw Kl(d,"response.data.detail"),Kl(d,"response.data.error"),console.error(d),d}},ra={expertSystemURL:"",path:"",goal:"",question:""},aa={height:"100%",overflowY:"auto",...lr},Yl=({message:e})=>n.jsx(s.Box,{sx:aa,children:n.jsx("div",{dangerouslySetInnerHTML:{__html:e},style:{fontSize:"14px",lineHeight:"32px",color:"#3D3E45"}})}),lT=({error:e,width:t,height:r})=>{const a=e.message;if(a.startsWith("<"))return n.jsx(Yl,{message:a});const l=r-25-20-30;return n.jsx(s.Center,{sx:{width:"100%",height:l},children:n.jsxs(s.Stack,{align:"center",gap:20,children:[n.jsx(aT,{}),n.jsx(Yl,{message:a})]})})};function iT({context:e}){const{value:t}=q(e.instanceData,"config"),r=h.useMemo(()=>b.defaultsDeep({},t,ra),[t]),{width:a,height:o}=e.viewport,l=e.data,{data:i,error:c,loading:d}=O.useRequest(oT({conf:r,panelData:l}),{refreshDeps:[l,r]});return!a||!o||!r?null:d?n.jsx(s.Box,{sx:{position:"relative",height:o},children:n.jsx(s.LoadingOverlay,{visible:!0})}):c?n.jsx(s.Box,{sx:aa,"data-enable-scrollbar":!0,children:n.jsx(lT,{error:c,width:a,height:o})}):!i||!Array.isArray(i.replies)||i.replies.length===0?null:n.jsx(s.Box,{sx:aa,"data-enable-scrollbar":!0,children:i.replies.map((u,p)=>n.jsx("div",{dangerouslySetInnerHTML:{__html:u.interpretation.html}},p))})}function cT({context:e}){const{value:t,set:r}=q(e.instanceData,"config"),a=h.useMemo(()=>b.defaultsDeep({},t,ra),[t]),{control:o,handleSubmit:l,watch:i,formState:c,reset:d}=y.useForm({defaultValues:a});return h.useEffect(()=>{d(a)},[a]),i(["expertSystemURL","goal","path","question"]),n.jsx("form",{onSubmit:l(r),children:n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{grow:!0,children:[n.jsx(y.Controller,{name:"expertSystemURL",control:o,render:({field:u})=>n.jsx(s.TextInput,{label:"Expert System URL",...u})}),n.jsx(y.Controller,{name:"path",control:o,render:({field:u})=>n.jsx(s.TextInput,{label:"Path",required:!0,...u})})]}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(y.Controller,{name:"goal",control:o,render:({field:u})=>n.jsx(s.TextInput,{label:"Goal",required:!0,...u})}),n.jsx(y.Controller,{name:"question",control:o,render:({field:u})=>n.jsx(s.TextInput,{label:"Question",required:!0,...u})})]}),n.jsx(s.Divider,{variant:"dashed",mt:16,mb:8}),n.jsx(s.Button,{type:"submit",variant:"filled",color:"blue",leftSection:n.jsx(S.IconDeviceFloppy,{size:20}),disabled:!c.isDirty,sx:{alignSelf:"flex-end"},children:"Submit Changes"})]})})}const dT=[{lang:"en",resources:{merico_gqm:{viz_name:"Merico GQM"}}},{lang:"zh",resources:{merico_gqm:{viz_name:"思码逸GQM组件"}}}];class uT extends J{constructor(){super(...arguments);V(this,"VERSION",1)}configVersions(){this.version(1,r=>({version:1,config:r}))}}const pT={displayName:"viz.merico_gqm.viz_name",displayGroup:"chart.groups.merico_suite",migrator:new uT,name:"mericoGQM",viewRender:iT,configRender:cT,createConfig(){return{version:1,config:b.cloneDeep(ra)}},translation:dT};class hT extends J{constructor(){super(...arguments);V(this,"VERSION",1)}configVersions(){this.version(1,r=>({version:1,config:r}))}}function gT({context:e}){const{t}=m.useTranslation(),{inEditMode:r}=Us();if(!r)return null;const{width:a,height:o}=e.viewport;return n.jsx(s.Center,{w:a,h:o,title:t("viz.merico_panel_groups.render"),children:n.jsx(s.Text,{c:"dimmed",size:"xs",children:t("viz.merico_panel_groups.render")})})}const fT=[{lang:"en",resources:{merico_panel_groups:{viz_name:"Merico Panel Groups",render:'"Merico Panel Groups" is a ghost viz, the whole panel will not shown in dashboard',groups:{label:"Groups",add:"Add a group",name:"Name",comment:"Remark",panel_ids:"Panels",yaml:{button:"Import from YAML",modal_title:"Import from YAML",label:"YAML content",submit:"Submit",error_title:"Failed"}}}}},{lang:"zh",resources:{merico_panel_groups:{viz_name:"思码逸卡片组",render:"在使用看板时,思码逸卡片组不会参与渲染",groups:{label:"卡片组",add:"增加一组",name:"名称",comment:"备注",panel_ids:"卡片",yaml:{button:"从YAML导入",modal_title:"从YAML导入",label:"YAML内容",submit:"提交",error_title:"解析失败"}}}}}],Xl=()=>({groups:[]}),bT=({append:e})=>{const{t}=m.useTranslation(),r=()=>{e({name:"",comment:"",panelIDs:[]})};return n.jsx(s.Flex,{gap:"sm",justify:"center",align:"center",direction:"row",wrap:"nowrap",children:n.jsx(s.Group,{wrap:"nowrap",style:{flex:1},children:n.jsx(s.Button,{size:"xs",variant:"subtle",onClick:r,leftSection:n.jsx(S.IconPlus,{size:14}),children:t("viz.merico_panel_groups.groups.add")})})})},yT=({row:e,index:t,handleChange:r,handleRemove:a,panelOptions:o})=>{const{t:l}=m.useTranslation(),[i,{setTrue:c}]=O.useBoolean(!1),d=f=>{r({...e,name:f})},u=f=>{r({...e,comment:f})},p=f=>{r({...e,panelIDs:f})};return n.jsxs(s.Stack,{gap:"xs",p:"xs",style:{border:"1px solid var(--mantine-color-gray-4)",borderRadius:"2px"},children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",style:{flex:1},children:[n.jsx(s.TextInput,{size:"xs",value:e.name,placeholder:l("viz.merico_panel_groups.groups.name"),onChange:f=>d(f.currentTarget.value),onClick:c,error:i&&!e.name}),n.jsx(s.TextInput,{size:"xs",value:e.comment,placeholder:l("viz.merico_panel_groups.groups.comment"),onChange:f=>u(f.currentTarget.value)})]}),n.jsx(s.MultiSelect,{label:"",placeholder:l("viz.merico_panel_groups.groups.panel_ids"),onChange:p,value:e.panelIDs,clearable:!0,size:"xs",data:o,maxDropdownHeight:500,comboboxProps:{width:300,position:"bottom-start"}}),n.jsx(s.Button,{variant:"subtle",color:"red",size:"xs",ml:"auto",mt:"md",leftSection:n.jsx(S.IconTrash,{size:14}),onClick:a,children:"删除这一组"})]})};function vT(e){try{const t=[],r=e.split(`
|
|
531
|
+
`);let a="";for(let o=0;o<r.length;o++){const l=r[o];if(l.includes("#")){const d=l.split("# ")[1].trim();d&&(a=d,console.log({comment:a}));continue}const[i,c]=l.split(": ").map(d=>d.trim());console.log({name:i,panelIDString:c}),t.push({name:i,comment:a,panelIDs:JSON.parse(c)})}return t}catch(t){throw t}}const _T=({onSubmit:e})=>{const{t}=m.useTranslation(),[r,{setTrue:a,setFalse:o}]=O.useBoolean(!1),[l,i]=h.useState("");h.useEffect(()=>{i("")},[r]);const c=()=>{try{const d=vT(l);e(d),o()}catch(d){console.error(d),Ge.showNotification({title:t("viz.merico_panel_groups.groups.yaml.error_title"),message:d.message,color:"red"})}};return n.jsxs(n.Fragment,{children:[n.jsx(s.Button,{onClick:a,disabled:r,size:"xs",variant:"light",children:t("viz.merico_panel_groups.groups.yaml.button")}),n.jsx(s.Modal,{opened:r,onClose:o,title:t("viz.merico_panel_groups.groups.yaml.modal_title"),zIndex:340,size:800,children:n.jsxs(s.Stack,{gap:"lg",children:[n.jsx(s.Textarea,{label:t("viz.merico_panel_groups.groups.yaml.label"),value:l,onChange:d=>i(d.currentTarget.value),autosize:!0,minRows:10,maxRows:40,styles:{input:{fontFamily:"monospace",fontSize:"12px"}}}),n.jsx(s.Button,{ml:"auto",onClick:c,children:t("viz.merico_panel_groups.groups.yaml.submit")})]})})]})},mT=h.forwardRef(({value:e,onChange:t,data:r},a)=>{const{t:o}=m.useTranslation(),l=F(),i=h.useMemo(()=>e.map(w=>({id:Te.v4(),...w})),[e]),c=w=>{t([...e,w])},d=w=>{t(w)},u=w=>{const x=[...e];x.splice(w,1),t(x)},p=w=>x=>{const T=[...e];T[w]=x,t(T)},f=l.panels.options,v=h.useMemo(()=>new Set(i.map(w=>w.panelIDs).flat()),[i]),_=h.useMemo(()=>f.map(w=>({...w,disabled:v.has(w.value)})),[f,v]);return n.jsxs(s.Stack,{ref:a,pt:4,children:[n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Text,{size:"sm",fw:"500",mb:-4,children:o("viz.merico_panel_groups.groups.label")}),n.jsx(_T,{onSubmit:d})]}),i.map((w,x)=>n.jsx(yT,{row:w,handleChange:p(x),handleRemove:()=>u(x),index:x,panelOptions:_},w.id)),n.jsx(bT,{append:c})]})});function wT({context:e}){const{value:t,set:r}=q(e.instanceData,"config");m.useTranslation();const a=e.data,o=h.useMemo(()=>b.defaultsDeep({},t,Xl()),[t]),l=y.useForm({defaultValues:o}),{handleSubmit:i,formState:c,reset:d}=l;h.useEffect(()=>{l.reset(o)},[o]);const u=p=>{const f=p;f.groups=f.groups.filter(v=>v.panelIDs.length>0||!!v.name.trim()||!!v.comment.trim()),r(f)};return n.jsxs("form",{onSubmit:i(u),children:[n.jsx(se,{canSubmit:c.isDirty}),n.jsx(s.Stack,{gap:"lg",pt:"xs",px:"xs",children:n.jsx(y.Controller,{name:"groups",control:l.control,render:({field:p})=>n.jsx(mT,{...p,data:a})})})]})}const Zl={displayName:"viz.merico_panel_groups.viz_name",displayGroup:"chart.groups.merico_suite",migrator:new hT,name:"merico_panel_groups",viewRender:gT,configRender:wT,createConfig:()=>({version:1,config:Xl()}),translation:fT},xT=[{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"})),CT=[Lu,Ou,Fu,Gu,Nu,Qu],sa=[Rr,pC,$S,K0,AC,Fx,W_,_h,zf,mv,r_,Sb,ix,tv,K1,g0,F0,pT,Tm,Hm,Cw,Zl,uw,Nf,rT],Jl=sa.reduce((e,t)=>(e[t.name]={displayName:t.displayName,displayGroup:t.displayGroup},e),{}),Hl=()=>({id:"dashboard",version:Gs,manifest:{viz:sa,color:[...xT,...CT]}}),Mt=new Xu,ee={pluginManager:He("pluginManager"),vizManager:He("vizManager"),colorManager:He("colorManager"),panelAddonManager:He("panelAddonManager"),instanceScope:{panelModel:He("panelModel"),vizInstance:He("vizInstance"),interactionManager:He("interactionManager"),migrator:He("migrator"),operationManager:He("operationManager"),triggerManager:He("triggerManager")}},oa=()=>{try{Mt.install(Hl())}catch{}const e=new Eu(Mt),t=new Yu(Mt),r=new ju(Mt);return{pluginManager:Mt,vizManager:e,colorManager:t,panelAddonManager:r}},lt=h.createContext(oa());try{Mt.install(Hl())}catch{}const Mn=Ce.createInstance({debug:!1,fallbackLng:"en",interpolation:{escapeValue:!1},resources:{en:Pu,zh:$u}}).use(Ld).use(m.initReactI18next);Mn.init(),sa.forEach(e=>{var t;(t=e.translation)==null||t.forEach(r=>{Mn.addResourceBundle(r.lang,"translation",{viz:r.resources},!0,!0)})});function Rl({lang:e,children:t}){return h.useEffect(()=>{Mn.changeLanguage(e)},[e]),n.jsx(m.I18nextProvider,{i18n:Mn,children:t})}M.extend(Ud),M.extend(Kd),M.extend(Yd),M.extend(Xd),M.extend(Zd),M.extend(Jd),M.extend(Hd),M.extend(Rd),M.extend(eu),M.extend(tu),M.extend(au),M.extend(su),M.extend(ou),M.extend(lu),M.extend(iu),M.extend(nu),M.extend(ru),M.extend(cu),M.extend(du),M.extend(uu),M.extend(pu),M.extend(hu),M.extend(gu),M.extend(fu),M.extend(bu),M.extend(yu),M.extend(vu),M.extend(_u),M.extend(mu),M.extend(wu),M.extend(Cu),M.extend(Su),M.extend(xu),M.tz.setDefault("UTC"),M.updateLocale("en",{weekStart:1});function ST(e){e=e||{};const t=Object.keys(e).sort(),r=[];for(let a=0;a<t.length;a++){const o=t[a];if(o!="authentication"&&e[o])r.push(t[a]+"="+(typeof e[o]=="object"?JSON.stringify(e[o]):e[o]));else{const l=Object.keys(e[o]).sort();for(let i=0;i<l.length;i++){const c=l[i];c!="sign"&&e[o][c]&&r.push(l[i]+"="+(typeof e[o][c]=="object"?JSON.stringify(e[o][c]):e[o][c]))}}}return r.sort().join("&")}function TT(e,t){let r=ST(e);return r+="&key="+t,Iu.MD5(r).toString().toUpperCase()}class ei{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:TT({app_id:this.app_id,nonce_str:r,...t},this.app_secret)}}getRequest(t,r){return(a,o,l,i)=>{const c=this.buildHeader(l),d=this.buildAxiosConfig(t,a,o,l,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=b.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,o,l,i){const c={baseURL:this.baseURL,method:t,url:r,params:t==="GET"?a:o.params,headers:l,signal:i};return["POST","PUT"].includes(t)&&(c.data=o.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 kT{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 ti extends ei{constructor(){super(...arguments);V(this,"makeQueryENV",null)}query(r){return async(a,o={})=>{var l;return a.env||(a.env=((l=this.makeQueryENV)==null?void 0:l.call(this))??{error:"failed to run makeQueryENV"}),this.post(r)("/query",a,o)}}httpDataSourceQuery(r){return async(a,o={})=>{var l;return a.env||(a.env=((l=this.makeQueryENV)==null?void 0:l.call(this))??{error:"failed to run makeQueryENV"}),this.getRequest("POST",r)("/query",a,o,!0)}}structure(r){return async(a,o={})=>this.post(r)("/query/structure",a,o)}mericoMetricInfo(r){return async(a,o={})=>this.post(r)("/query/merico_metric_info",a,o,!0)}mericoMetricQuery(r){return async(a,o={})=>this.post(r)("/query",a,o,!0)}}class ni{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 Nt=new ti;function la(e){Nt.baseURL!==e.apiBaseURL&&(Nt.baseURL=e.apiBaseURL),e.app_id&&(Nt.app_id=e.app_id),e.app_secret&&(Nt.app_secret=e.app_secret),e.makeQueryENV&&(Nt.makeQueryENV=e.makeQueryENV)}const ri=new ni(Nt),$e=ri,ia=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 ca(e){return{current:e}}const DT=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}})),ai=g.types.model("PanelStyleMeta",{border:DT}).views(e=>({get json(){const{border:t}=e;return{border:t.json}}})).actions(e=>({})),si=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}})),oi=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:o,formatter:l,data_field:i,aggregation:c}=e;return b.cloneDeep({name:t,size:r,color:o,weight:a,formatter:l,data_field:i,aggregation:c})}})),li=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){b.isEqual(e.conf,t)||(e.conf=t)}})),ii=g.types.model({id:g.types.string,name:g.types.optional(g.types.string,""),title:si,description:g.types.string,queryIDs:g.types.array(g.types.string),viz:li,style:ai,variables:g.types.optional(g.types.array(oi),[])}).views(e=>({get json(){const{id:t,name:r,title:a,description:o,queryIDs:l}=e;return{id:t,viz:e.viz.json,name:r,style:e.style.json,title:a.json,queryIDs:[...l],variables:e.variables.map(i=>i.json),description:o}},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 W=(e=>(e.Postgresql="postgresql",e.MySQL="mysql",e.HTTP="http",e.Transform="transform",e.MericoMetricSystem="merico_metric_system",e))(W||{});const ci=g.types.model("DBQueryMeta",{_type:g.types.enumeration([W.MySQL,W.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}})),zT=e=>ci.create({_type:e,sql:""}),di=g.types.model("HTTPQueryMeta",{_type:g.types.literal(W.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 st({react_to:t,_type:r})}})).actions(e=>({setReactTo(t){e.react_to.length=0,e.react_to.push(...t)}})),MT=()=>di.create({_type:W.HTTP,react_to:[]}),ui=g.types.model("TransformQueryMeta",{_type:g.types.literal(W.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 st({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)}})),IT=()=>ui.create({_type:W.Transform,dep_query_ids:[]}),pi=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()}})),da=g.types.model("MericoMetricQueryMeta",{_type:g.types.literal(W.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(pi),[]),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),extraCalculations:g.types.optional(g.types.array(g.types.string),[])}).views(e=>({get query(){return g.getParent(e)},get valid(){return!!e.id},get json(){const{id:t,type:r,filters:a,groupBys:o,timeQuery:l,useDefaultValues:i,extraCalculations:c,_type:d}=e;return st({id:t,type:r,filters:a.map(u=>u.json),groupBys:o,timeQuery:l,useDefaultValues:i,extraCalculations:c,_type:d})},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,e.extraCalculations.length=0,"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(pi.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},setExtraCalculations(t){e.extraCalculations.length=0,e.extraCalculations.push(...t)}})),hi=()=>da.create({_type:W.MericoMetricSystem,id:"",type:"derived",filters:[],groupBys:[],timeQuery:{range_variable:"",unit_variable:"",timezone:"PRC",stepKeyFormat:"YYYY-MM-DD"},useDefaultValues:!1,extraCalculations:[]}),gi=g.types.model("QueryMeta",{id:g.types.string,name:g.types.string,key:g.types.string,type:g.types.enumeration("DataSourceType",[W.Postgresql,W.MySQL,W.HTTP,W.Transform,W.MericoMetricSystem]),config:g.types.union(ci,di,ui,da),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:o,config:l}=e;return l.valid&&!!t&&!!r&&!!a&&!!o},get json(){const{id:t,name:r,key:a,type:o,config:l,pre_process:i,post_process:c,run_by:d}=e;return st({id:t,name:r,key:a,type:o,config:l.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 W.HTTP:e.config=MT();break;case W.MySQL:case W.Postgresql:e.config=zT(t);break;case W.Transform:e.config=IT();break;case W.MericoMetricSystem:e.config=hi();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}})),fi=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:o,w:l,h:i,moved:c}=e;return{h:i,w:l,x:a,y:o===null?0:o,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:o,h:l,moved:i}=e;return{id:t,i:t,x:r,y:a===null?1/0:a,w:o,h:l,moved:i,static:e.static}}})).actions(e=>({set(t){const{isDraggable:r,x:a,y:o,w:l,h:i,moved:c}=t;e.x=a,e.y=o,e.w=l,e.h=i,e.moved=!!c,e.static=!!t.static},setWidth(t){e.w=t},setHeight(t){e.h=t}})),bi=g.types.model("LayoutSetMeta",{id:g.types.identifier,name:g.types.string,breakpoint:g.types.number,list:g.types.optional(g.types.array(fi),[])}).views(e=>({get contentModel(){return g.getRoot(e).content},get json(){const{id:t,name:r,breakpoint:a,list:o}=e;return{id:t,name:r,breakpoint:a,list:o.map(l=>st(l.json))}},jsonByPanelIDSet(t){const{id:r,name:a,breakpoint:o,list:l}=e;return{id:r,name:a,breakpoint:o,list:l.filter(i=>t.has(i.panelID)).map(i=>st(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:Te.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,G.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 o={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};Ge.showNotification(o),Ge.updateNotification(o)},{fireImmediately:!0,delay:0}))}})),yi=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 P=(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.MericoDateRange="merico-date-range",e))(P||{});const ua=g.types.optional(g.types.enumeration(["intersect","reset"]),"intersect"),pa=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}})),vi=()=>pa.create({_name:"checkbox",description:"",default_value:!1}),_i=()=>[{key:"d",value:"yesterday",group:"last",getRange:()=>{const e=M();return{value:[e.subtract(1,"day").startOf("day").toDate(),e.subtract(1,"day").endOf("day").toDate()],shortcut:"yesterday"}}},{key:"w",value:"last week",group:"last",getRange:()=>{const e=M();return{value:[e.subtract(1,"week").startOf("week").toDate(),e.subtract(1,"week").endOf("week").toDate()],shortcut:"last week"}}},{key:"m",value:"last month",group:"last",getRange:()=>{const e=M();return{value:[e.subtract(1,"month").startOf("month").toDate(),e.subtract(1,"month").endOf("month").toDate()],shortcut:"last month"}}},{key:"m2",value:"last 2 months",group:"last",getRange:()=>{const e=M();return{value:[e.subtract(2,"month").startOf("month").toDate(),e.subtract(1,"month").endOf("month").toDate()],shortcut:"last 2 months"}}},{key:"m3",value:"last 3 months",group:"last",getRange:()=>{const e=M();return{value:[e.subtract(3,"month").startOf("month").toDate(),e.subtract(1,"month").endOf("month").toDate()],shortcut:"last 3 months"}}},{key:"y",value:"last year",group:"last",getRange:()=>{const e=M();return{value:[e.subtract(1,"year").startOf("year").toDate(),e.subtract(1,"year").endOf("year").toDate()],shortcut:"last year"}}},{key:"d7",value:"recent 7 days",group:"recent",getRange:()=>{const e=M();return{value:[e.subtract(7,"day").startOf("day").toDate(),e.subtract(1,"day").endOf("day").toDate()],shortcut:"recent 7 days"}}},{key:"d30",value:"recent 30 days",group:"recent",getRange:()=>{const e=M();return{value:[e.subtract(30,"day").startOf("day").toDate(),e.subtract(1,"day").endOf("day").toDate()],shortcut:"recent 30 days"}}},{key:"d60",value:"recent 60 days",group:"recent",getRange:()=>{const e=M();return{value:[e.subtract(60,"day").startOf("day").toDate(),e.subtract(1,"day").endOf("day").toDate()],shortcut:"recent 60 days"}}},{key:"d90",value:"recent 90 days",group:"recent",getRange:()=>{const e=M();return{value:[e.subtract(90,"day").startOf("day").toDate(),e.subtract(1,"day").endOf("day").toDate()],shortcut:"recent 90 days"}}},{key:"d180",value:"recent 180 days",group:"recent",getRange:()=>{const e=M();return{value:[e.subtract(180,"day").startOf("day").toDate(),e.subtract(1,"day").endOf("day").toDate()],shortcut:"recent 180 days"}}},{key:"d365",value:"recent 365 days",group:"recent",getRange:()=>{const e=M();return{value:[e.subtract(365,"day").startOf("day").toDate(),e.subtract(1,"day").endOf("day").toDate()],shortcut:"recent 365 days"}}},{key:"d",value:"today",group:"this",getRange:()=>{const e=M();return{value:[e.startOf("day").toDate(),e.endOf("day").toDate()],shortcut:"today"}}},{key:"w",value:"this week",group:"this",getRange:()=>{const e=M();return{value:[e.startOf("week").toDate(),e.endOf("week").toDate()],shortcut:"this week"}}},{key:"m",value:"this month",group:"this",getRange:()=>{const e=M();return{value:[e.startOf("month").toDate(),e.endOf("month").toDate()],shortcut:"this month"}}},{key:"y",value:"this year",group:"this",getRange:()=>{const e=M();return{value:[e.startOf("year").toDate(),e.endOf("year").toDate()],shortcut:"this year"}}},{key:"w",value:"this week so far",group:"this_so_far",getRange:()=>{const e=M();return{value:[e.startOf("week").toDate(),e.endOf("day").toDate()],shortcut:"this week so far"}}},{key:"m",value:"this month so far",group:"this_so_far",getRange:()=>{const e=M();return{value:[e.startOf("month").toDate(),e.endOf("day").toDate()],shortcut:"this month so far"}}},{key:"y",value:"this year so far",group:"this_so_far",getRange:()=>{const e=M();return{value:[e.startOf("year").toDate(),e.endOf("day").toDate()],shortcut:"this year so far"}}}];function In(e){if(!e)return null;const r=_i().find(a=>a.value===e);return r?r.getRange():null}function mi(){return b.groupBy(_i(),"group")}function wi(e){try{if(e.default_shortcut){const r=In(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 xi(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 VT=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:o,inputFormat:l,default_value:i,default_shortcut:c,allowSingleDateInRange:d}=e;return{_name:t,max_days:r,required:a,clearable:o,inputFormat:l,default_value:xi(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,o=r?M(r).format(e.inputFormat):"",l=a?M(a).format(e.inputFormat):"";return[o,l]}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=In(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}})),ha=g.types.snapshotProcessor(VT,{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:xi(t,r.inputFormat)}}}),Ci=()=>ha.create({_name:"date-range",required:!1,inputFormat:"YYYY-MM-DD",clearable:!1,default_value:[null,null]}),Si=g.types.model({label:g.types.string,value:g.types.string}).actions(e=>({setLabel(t){e.label=t},setValue(t){e.value=t}})),ga=g.types.model("FilterConfigModel_BaseSelect",{static_options:g.types.optional(g.types.array(Si),[]),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=>Si.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??""}})),fa=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:ua}),ga).views(e=>({get json(){const{_name:t,default_value:r,default_value_mode:a,required:o,min_width:l,static_options:i,options_query_id:c,default_selection_count:d}=e;return st({_name:t,required:!!o,min_width:l,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(o=>o.value)),a=(e.filter.value??[]).filter(o=>t.has(o));a.length>0?e.filter.setValue(a):e.filter.setValue(e.defaultSelection)}})).actions(e=>({afterCreate(){g.addDisposer(e,G.reaction(()=>G.toJS(e.defaultSelection),e.applyDefaultSelection,{fireImmediately:!1,delay:0}))}})),Ti=()=>fa.create({_name:"multi-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),ba=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)}),ga).views(e=>({get json(){const{_name:t,clearable:r,default_value:a,required:o,width:l,static_options:i,options_query_id:c,default_selection_count:d}=e;return st({_name:t,width:l,required:o,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(o=>o.value===t))==null?void 0:a.value;r?e.filter.setValue(r):e.filter.setValue(e.default_selection)}})).actions(e=>({afterCreate(){g.addDisposer(e,G.reaction(()=>G.toJS(e.default_selection),e.setDefaultSelection,{fireImmediately:!1,delay:0}))}})),ki=()=>ba.create({_name:"select",required:!1,default_value:"",static_options:[],options_query_id:"",default_selection_count:0}),ya=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}})),va=()=>ya.create({_name:"text-input",required:!1,default_value:""}),PT=`
|
|
532
532
|
// row
|
|
533
533
|
{
|
|
534
534
|
label: string;
|
|
@@ -538,19 +538,19 @@ Variable: {{ your_var }}`,tabs:{guide:"Guide",vars:"Dashboard state & Panel vari
|
|
|
538
538
|
disabled?: boolean;
|
|
539
539
|
}
|
|
540
540
|
`,Di=()=>{const{t:e}=m.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(Fe.CodeHighlight,{language:"typescript",withCopyButton:!1,code:PT})})]})},$T={[P.Checkbox]:"true",[P.DateRange]:"[new Date('2023-01-01 00:00:00'), new Date('2024-01-01 00:00:00')]",[P.MericoDateRange]:"[new Date('2023-01-01 00:00:00'), new Date('2024-01-01 00:00:00')]",[P.MultiSelect]:"[]",[P.Select]:'""',[P.TreeSelect]:"[]",[P.TreeSingleSelect]:'""',[P.TextInput]:'""'},AT=e=>["function getDefaultValue(filter, utils, context) {",` return ${$T[e]};`,"}"].join(`
|
|
541
|
-
`),_t=k.observer(({filter:e})=>{const{t}=m.useTranslation();return n.jsx(pr,{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:AT(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")})]})})})}),Vn=k.observer(({value:e,onChange:t})=>{const{t:r}=m.useTranslation(),a=j(),o=G(),l=h.useMemo(()=>o.queries.options,[o.queries.current]),i=l.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:l,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"}}})}),zi={stroke:1.5,color:"currentColor",opacity:1,size:18},Mi={intersect:n.jsx(S.IconLayersIntersect,{...zi}),reset:n.jsx(S.IconLayersSubtract,{...zi})},ET=({option:e,checked:t})=>n.jsxs(s.Group,{flex:"1",gap:"xs",children:[Mi[e.value],e.label]}),_a=k.observer(({config:e})=>{const{t,i18n:r}=m.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:o}=e;return n.jsx(s.Select,{leftSection:Mi[o]??null,label:t("filter.widget.common.default_value_mode.label"),data:a,value:o,onChange:e.setDefaultValueMode,renderOption:ET})}),BT=k.observer(function({filter:t}){const{t:r}=m.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:o=>a.setRequired(o.currentTarget.checked),label:r("filter.widget.select.required")}),n.jsx(_t,{filter:t})]}),n.jsx(s.TextInput,{label:r("filter.widget.common.min_width"),value:a.min_width,onChange:o=>a.setMinWidth(o.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:o=>a.setTreeCheckStrictly(o.currentTarget.checked),label:r("filter.widget.tree_select.strictly")}),n.jsx(Vn,{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(_a,{config:a}),n.jsx(Di,{})]})}),ma=({errorMessage:e})=>{const{t}=m.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")})},qT=({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"})}),Ii=({expanded:e,isLeaf:t,value:r,onClick:a,...o})=>t?n.jsx("span",{style:{width:"14px",display:"inline-block"}}):n.jsx(qT,{rotate:e?"0":"-90",onClick:a,...o}),LT=({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"})]}),Vi=({onClick:e,...t})=>n.jsx(LT,{onClick:e,...t}),OT=ht.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"}}}})),NT=(e,t,r,a)=>{const o=h.useMemo(()=>{if(!a)return b.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]),l=h.useMemo(()=>new Set(o.map(u=>u.value)),[o]),i=h.useMemo(()=>new Set(t.map(u=>u.value)),[t]),c=h.useMemo(()=>i.size!==l.size?!1:Array.from(l).every(u=>i.has(u)),[i,l]);return{allValueSet:l,selectedValueSet:i,toggleSelectAll:()=>{if(c){r([]);return}const u=Array.from(o);r(u)},allSelected:c}},GT={root:{cursor:"pointer",backgroundColor:"#FFF","&:hover":{backgroundColor:"var(--mantine-color-default-hover)"},"input, .mantine-Checkbox-labelWrapper":{cursor:"pointer",pointerEvents:"none"}}},FT=({disabled:e,radius:t,style:r,label:a,value:o,onChange:l,treeData:i,errorMessage:c,required:d,treeCheckStrictly:u})=>{const{t:p}=m.useTranslation(),{classes:f,cx:v}=OT({radius:t,width:r.width,name:"FilterTreeSelectWidget"}),[_,w]=h.useState(!1),x=E=>{w(E)},T=_&&(o==null?void 0:o.length)>0,D=NT(i,o,l,u),[z,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:"*"})]}),T&&n.jsx(s.Tooltip,{label:p("filter.widget.common.x_selected",{count:o.length}),children:n.jsx(s.Badge,{variant:"light",children:o.length})})]}),n.jsx(Wn,{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:x,transitionName:"rc-tree-select-dropdown-slide-up",choiceTransitionName:"rc-tree-select-selection__choice-zoom",style:r,listHeight:510,treeLine:!0,switcherIcon:Ii,treeIcon:Vi,maxTagTextLength:10,value:o,treeData:i,notFoundContent:n.jsx(ma,{errorMessage:c}),treeNodeFilterProp:"filterBasis",treeCheckable:!0,showCheckedStrategy:Wn.SHOW_PARENT,onChange:l,onSelect:console.log,maxTagCount:0,maxTagPlaceholder:()=>p("filter.widget.common.x_selected",{count:o.length}),searchValue:z,onSearch:I,dropdownRender:E=>n.jsxs(n.Fragment,{children:[D.allValueSet.size>0&&!z&&n.jsx(s.Group,{px:"xs",pt:8,pb:8,onClick:D.toggleSelectAll,styles:GT,children:n.jsx(s.Checkbox,{size:"xs",checked:D.allSelected,onChange:b.noop,label:p("common.actions.select_all")})}),n.jsx(s.Divider,{}),E]})})]})},QT=k.observer(({label:e,config:t,value:r,onChange:a})=>{const{treeData:o,treeDataLoading:l,errorMessage:i}=t,c=v=>{const _=v.map(w=>w.value);a(_,!1)},d=h.useMemo(()=>t.initialSelection(r),[r,t.initialSelection,l]),u=t.min_width?t.min_width:"200px",f=!!t.options_query_id?l:!1;return n.jsx(FT,{disabled:f,style:{minWidth:"160px",width:u,maxWidth:f?u:"unset",borderColor:"#e9ecef"},value:[...d],onChange:c,treeData:o,errorMessage:i,label:e,required:t.required,treeCheckStrictly:t.treeCheckStrictly})}),jT=k.observer(({filter:e})=>{const{t}=m.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(_t,{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(Vn,{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(_a,{config:r}),n.jsx(Di,{})]})}),WT=ht.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"}}}})),UT=({disabled:e,radius:t,style:r,label:a,value:o,onChange:l,treeData:i,errorMessage:c,required:d})=>{m.useTranslation();const{classes:u,cx:p}=WT({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(Wn,{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:Ii,treeIcon:Vi,value:o,treeData:i,notFoundContent:n.jsx(ma,{errorMessage:c}),treeNodeFilterProp:"filterBasis",treeCheckable:!1,onChange:l,onSelect:console.log,showSearch:!0})]})},KT=k.observer(({label:e,config:t,value:r,onChange:a})=>{const{treeData:o,treeDataLoading:l,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?l:!1;return n.jsx(UT,{disabled:f,style:{width:u,maxWidth:f?u:"unset",borderColor:"#e9ecef"},value:d,onChange:c,treeData:o,errorMessage:i,label:e,required:t.required})});function YT(e){return ku.arrayToTree(e,{id:"value",parentId:"parent_value",childrenField:"children",dataField:null})}function XT(e){return e.map(t=>{const{label:r,description:a,...o}=t,l={...o,filterBasis:`${r}___${a??""}`,description:a,label:r};return a&&(l.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)])),l})}const Pi=g.types.compose("FilterConfigModel_BaseTreeSelect",g.types.model({min_width:g.types.optional(g.types.string,""),default_value_mode:ua}),ga).views(e=>({get plainData(){const{data:t}=e.contentModel.getDataStuffByID(e.options_query_id);return t},get treeData(){const t=this.plainData,r=XT(t);return YT(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}})),wa=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)}),Pi).views(e=>({get json(){const{_name:t,default_value:r,default_value_mode:a,required:o,min_width:l,static_options:i,options_query_id:c,default_selection_count:d,treeCheckStrictly:u}=e;return{_name:t,required:!!o,min_width:l,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(o=>o.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(o=>o.value)),a=(t??[]).filter(o=>r.has(o));a.length>0?e.filter.setValue(a):e.filter.setValue(e.defaultSelection)},afterCreate(){g.addDisposer(e,F.reaction(()=>JSON.stringify(e.defaultSelection),this.applyDefaultSelection,{fireImmediately:!1,delay:0}))}})),$i=()=>wa.create({_name:"tree-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),xa=g.types.compose("FilterTreeSingleSelectConfigMeta",g.types.model({_name:g.types.literal("tree-single-select"),default_value:g.types.optional(g.types.string,"")}),Pi).views(e=>({get json(){const{_name:t,default_value:r,default_value_mode:a,required:o,min_width:l,static_options:i,options_query_id:c,default_selection_count:d}=e;return{_name:t,required:!!o,min_width:l,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,F.reaction(()=>F.toJS(e.defaultSelection),this.applyDefaultSelection,{fireImmediately:!1,delay:0}))}})),Ai=()=>xa.create({_name:"tree-single-select",default_value:"",static_options:[],options_query_id:"",default_selection_count:0});function ZT(e,t){const r=e.startOf("week");let a=r.add(1,"week").endOf("week");for(;a.isBefore(t);)a=a.add(2,"week");return[r.toDate(),a.toDate()]}function Jt(e,t,r){return!e||!t?[e,t]:Ze(M(e),M(t),r)}function Ze(e,t,r){if(!e||!t)return[(e==null?void 0:e.toDate())??null,(t==null?void 0:t.toDate())??null];switch(r){case"day":return[e.startOf("day").toDate(),t.endOf("day").toDate()];case"week":return[e.startOf("week").toDate(),t.endOf("week").toDate()];case"bi-week":return ZT(e,t);case"month":return[e.startOf("month").toDate(),t.endOf("month").toDate()];case"quarter":return[e.startOf("quarter").toDate(),t.endOf("quarter").toDate()];default:throw new Error(`[merico-date-range] unexpected date-range step: ${r}`)}}const JT={day:new Set(["m","m2","m3","m6","y","d30","d60","d90","d180","d365"]),week:new Set(["m","m2","m3","m6","y"]),"bi-week":new Set(["m","m2","m3","m6","y"]),month:new Set(["m","m2","m3","m6","y"]),quarter:new Set(["m","m2","m6","y"])};function nt(e,t){return!JT[e].has(t)}const Ei=e=>[{key:"m",value:"last month",group:"last",disabled:nt(e,"m"),getRange:t=>{const r=M();return{value:Ze(r.subtract(1,"month").startOf("month"),r.subtract(1,"month").endOf("month"),t),shortcut:"last month",step:t}}},{key:"m2",value:"last 2 months",group:"last",disabled:nt(e,"m2"),getRange:t=>{const r=M();return{value:Ze(r.subtract(2,"month").startOf("month"),r.subtract(1,"month").endOf("month"),t),shortcut:"last 2 months",step:t}}},{key:"m3",value:"last 3 months",group:"last",disabled:nt(e,"m3"),getRange:t=>{const r=M();return{value:Ze(r.subtract(3,"month").startOf("month"),r.subtract(1,"month").endOf("month"),t),shortcut:"last 3 months",step:t}}},{key:"m6",value:"last 6 months",group:"last",disabled:nt(e,"m6"),getRange:t=>{const r=M();return{value:Ze(r.subtract(6,"month").startOf("month"),r.subtract(1,"month").endOf("month"),t),shortcut:"last 6 months",step:t}}},{key:"y",value:"last year",group:"last",disabled:nt(e,"y"),getRange:t=>{const r=M();return{value:Ze(r.subtract(1,"year").startOf("year"),r.subtract(1,"year").endOf("year"),t),shortcut:"last year",step:t}}},{key:"d30",value:"recent 30 days",group:"recent",disabled:nt(e,"d30"),getRange:t=>{const r=M();return{value:Ze(r.subtract(30,"day").startOf("day"),r.subtract(1,"day").endOf("day"),t),shortcut:"recent 30 days",step:t}}},{key:"d60",value:"recent 60 days",group:"recent",disabled:nt(e,"d60"),getRange:t=>{const r=M();return{value:Ze(r.subtract(60,"day").startOf("day"),r.subtract(1,"day").endOf("day"),t),shortcut:"recent 60 days",step:t}}},{key:"d90",value:"recent 90 days",group:"recent",disabled:nt(e,"d90"),getRange:t=>{const r=M();return{value:Ze(r.subtract(90,"day").startOf("day"),r.subtract(1,"day").endOf("day"),t),shortcut:"recent 90 days",step:t}}},{key:"d180",value:"recent 180 days",group:"recent",disabled:nt(e,"d180"),getRange:t=>{const r=M();return{value:Ze(r.subtract(180,"day").startOf("day"),r.subtract(1,"day").endOf("day"),t),shortcut:"recent 180 days",step:t}}},{key:"d365",value:"recent 365 days",group:"recent",disabled:nt(e,"d365"),getRange:t=>{const r=M();return{value:Ze(r.subtract(365,"day").startOf("day"),r.subtract(1,"day").endOf("day"),t),shortcut:"recent 365 days",step:t}}}];function Ht(e,t){if(!e)return null;const a=Ei(t).find(o=>o.value===e);return a?a.getRange(t):null}function Bi(e){return b.groupBy(Ei(e),"group")}function qi(e){try{if(e.default_shortcut){const r=Ht(e.default_shortcut,e.default_step);if(r)return{value:r.value.map(a=>M(a).toDate()),shortcut:e.default_shortcut,step:e.default_step}}const t=e.default_value.map(r=>r===null?r:M.tz(r,"UTC").toDate()??r);return{value:Jt(t[0],t[1],e.default_step),shortcut:null,step:e.default_step}}catch(t){return console.error(t),{value:[null,null],shortcut:null,step:e.default_step}}}function Li(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 HT=g.types.model("FilterMericoDateRangeConfigMeta",{_name:g.types.literal("merico-date-range"),required:g.types.boolean,inputFormat:g.types.enumeration("DateRangeInputFormat",["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,""),default_step:g.types.optional(g.types.string,"day")}).views(e=>({get json(){const{_name:t,required:r,inputFormat:a,default_step:o,default_value:l,default_shortcut:i}=e;return{_name:t,required:r,inputFormat:a,default_step:o,default_value:Li(l),default_shortcut:i}},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,o=r?M(r).format(e.inputFormat):"",l=a?M(a).format(e.inputFormat):"";return[o,l]}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},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=Ht(e.default_shortcut,e.default_step);r&&e.setFilterValue(r)},setDefaultStep(t){e.default_step=t}})),Ca=g.types.snapshotProcessor(HT,{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:Li(t,r.inputFormat)}}}),Oi=()=>Ca.create({_name:"merico-date-range",required:!1,inputFormat:"YYYY/MM/DD",default_value:[null,null],default_shortcut:"",default_step:"day"}),Pn=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",[P.Select,P.MultiSelect,P.TreeSelect,P.TreeSingleSelect,P.TextInput,P.Checkbox,P.DateRange,P.MericoDateRange]),config:g.types.union(ba,fa,wa,xa,ya,pa,ha,Ca)}).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!==P.TreeSelect&&e.type!==P.TreeSingleSelect},get usingDefaultValueFunc(){return!!e.default_value_func},get formattedDefaultValue(){return this.filters.formattedDefaultValues[e.key]},get auto_submit_supported(){return[P.Select,P.Checkbox,P.DateRange].includes(e.type)}})).views(e=>({get json(){const{id:t,key:r,label:a,order:o,visibleInViewsIDs:l,default_value_func:i,auto_submit:c,type:d,config:u}=e;return{id:t,key:r,type:d,label:a,order:o,config:u.json,auto_submit:c,visibleInViewsIDs:F.toJS(l),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 b.get(e.config,"required",!1)?b.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 P.Select:e.config=ki();break;case P.MultiSelect:e.config=Ti();break;case P.TreeSelect:e.config=$i();break;case P.TreeSingleSelect:e.config=Ai();break;case P.TextInput:e.config=va();break;case P.Checkbox:e.config=vi();break;case P.DateRange:e.config=Ci();break;case P.MericoDateRange:e.config=Oi();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 B=(e=>(e.Division="div",e.Modal="modal",e.Tabs="tabs",e))(B||{});const Sa=g.types.model("ViewDivisionConfig",{_name:g.types.literal(B.Division)}).views(e=>({get json(){const{_name:t}=e;return{_name:t}}})),Ni=()=>Sa.create({_name:B.Division}),RT=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),o=g.getRoot(e);if(!t)return a.name;try{const l={filters:o.content.filters.valuesForPayload,context:o.context.current};return new Function(`return ${r}`)()(l)}catch(l){return console.error(l),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}})),$n={enabled:!1,func_content:["function text({ filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
|
|
541
|
+
`),_t=k.observer(({filter:e})=>{const{t}=m.useTranslation();return n.jsx(pr,{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:AT(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")})]})})})}),Vn=k.observer(({value:e,onChange:t})=>{const{t:r}=m.useTranslation(),a=j(),o=F(),l=h.useMemo(()=>o.queries.options,[o.queries.current]),i=l.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:l,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"}}})}),zi={stroke:1.5,color:"currentColor",opacity:1,size:18},Mi={intersect:n.jsx(S.IconLayersIntersect,{...zi}),reset:n.jsx(S.IconLayersSubtract,{...zi})},ET=({option:e,checked:t})=>n.jsxs(s.Group,{flex:"1",gap:"xs",children:[Mi[e.value],e.label]}),_a=k.observer(({config:e})=>{const{t,i18n:r}=m.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:o}=e;return n.jsx(s.Select,{leftSection:Mi[o]??null,label:t("filter.widget.common.default_value_mode.label"),data:a,value:o,onChange:e.setDefaultValueMode,renderOption:ET})}),BT=k.observer(function({filter:t}){const{t:r}=m.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:o=>a.setRequired(o.currentTarget.checked),label:r("filter.widget.select.required")}),n.jsx(_t,{filter:t})]}),n.jsx(s.TextInput,{label:r("filter.widget.common.min_width"),value:a.min_width,onChange:o=>a.setMinWidth(o.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:o=>a.setTreeCheckStrictly(o.currentTarget.checked),label:r("filter.widget.tree_select.strictly")}),n.jsx(Vn,{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(_a,{config:a}),n.jsx(Di,{})]})}),ma=({errorMessage:e})=>{const{t}=m.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")})},qT=({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"})}),Ii=({expanded:e,isLeaf:t,value:r,onClick:a,...o})=>t?n.jsx("span",{style:{width:"14px",display:"inline-block"}}):n.jsx(qT,{rotate:e?"0":"-90",onClick:a,...o}),LT=({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"})]}),Vi=({onClick:e,...t})=>n.jsx(LT,{onClick:e,...t}),OT=ht.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"}}}})),NT=(e,t,r,a)=>{const o=h.useMemo(()=>{if(!a)return b.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]),l=h.useMemo(()=>new Set(o.map(u=>u.value)),[o]),i=h.useMemo(()=>new Set(t.map(u=>u.value)),[t]),c=h.useMemo(()=>i.size!==l.size?!1:Array.from(l).every(u=>i.has(u)),[i,l]);return{allValueSet:l,selectedValueSet:i,toggleSelectAll:()=>{if(c){r([]);return}const u=Array.from(o);r(u)},allSelected:c}},GT={root:{cursor:"pointer",backgroundColor:"#FFF","&:hover":{backgroundColor:"var(--mantine-color-default-hover)"},"input, .mantine-Checkbox-labelWrapper":{cursor:"pointer",pointerEvents:"none"}}},FT=({disabled:e,radius:t,style:r,label:a,value:o,onChange:l,treeData:i,errorMessage:c,required:d,treeCheckStrictly:u})=>{const{t:p}=m.useTranslation(),{classes:f,cx:v}=OT({radius:t,width:r.width,name:"FilterTreeSelectWidget"}),[_,w]=h.useState(!1),x=E=>{w(E)},T=_&&(o==null?void 0:o.length)>0,D=NT(i,o,l,u),[z,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:"*"})]}),T&&n.jsx(s.Tooltip,{label:p("filter.widget.common.x_selected",{count:o.length}),children:n.jsx(s.Badge,{variant:"light",children:o.length})})]}),n.jsx(Wn,{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:x,transitionName:"rc-tree-select-dropdown-slide-up",choiceTransitionName:"rc-tree-select-selection__choice-zoom",style:r,listHeight:510,treeLine:!0,switcherIcon:Ii,treeIcon:Vi,maxTagTextLength:10,value:o,treeData:i,notFoundContent:n.jsx(ma,{errorMessage:c}),treeNodeFilterProp:"filterBasis",treeCheckable:!0,showCheckedStrategy:Wn.SHOW_PARENT,onChange:l,onSelect:console.log,maxTagCount:0,maxTagPlaceholder:()=>p("filter.widget.common.x_selected",{count:o.length}),searchValue:z,onSearch:I,dropdownRender:E=>n.jsxs(n.Fragment,{children:[D.allValueSet.size>0&&!z&&n.jsx(s.Group,{px:"xs",pt:8,pb:8,onClick:D.toggleSelectAll,styles:GT,children:n.jsx(s.Checkbox,{size:"xs",checked:D.allSelected,onChange:b.noop,label:p("common.actions.select_all")})}),n.jsx(s.Divider,{}),E]})})]})},QT=k.observer(({label:e,config:t,value:r,onChange:a})=>{const{treeData:o,treeDataLoading:l,errorMessage:i}=t,c=v=>{const _=v.map(w=>w.value);a(_,!1)},d=h.useMemo(()=>t.initialSelection(r),[r,t.initialSelection,l]),u=t.min_width?t.min_width:"200px",f=!!t.options_query_id?l:!1;return n.jsx(FT,{disabled:f,style:{minWidth:"160px",width:u,maxWidth:f?u:"unset",borderColor:"#e9ecef"},value:[...d],onChange:c,treeData:o,errorMessage:i,label:e,required:t.required,treeCheckStrictly:t.treeCheckStrictly})}),jT=k.observer(({filter:e})=>{const{t}=m.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(_t,{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(Vn,{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(_a,{config:r}),n.jsx(Di,{})]})}),WT=ht.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"}}}})),UT=({disabled:e,radius:t,style:r,label:a,value:o,onChange:l,treeData:i,errorMessage:c,required:d})=>{m.useTranslation();const{classes:u,cx:p}=WT({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(Wn,{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:Ii,treeIcon:Vi,value:o,treeData:i,notFoundContent:n.jsx(ma,{errorMessage:c}),treeNodeFilterProp:"filterBasis",treeCheckable:!1,onChange:l,onSelect:console.log,showSearch:!0})]})},KT=k.observer(({label:e,config:t,value:r,onChange:a})=>{const{treeData:o,treeDataLoading:l,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?l:!1;return n.jsx(UT,{disabled:f,style:{width:u,maxWidth:f?u:"unset",borderColor:"#e9ecef"},value:d,onChange:c,treeData:o,errorMessage:i,label:e,required:t.required})});function YT(e){return ku.arrayToTree(e,{id:"value",parentId:"parent_value",childrenField:"children",dataField:null})}function XT(e){return e.map(t=>{const{label:r,description:a,...o}=t,l={...o,filterBasis:`${r}___${a??""}`,description:a,label:r};return a&&(l.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)])),l})}const Pi=g.types.compose("FilterConfigModel_BaseTreeSelect",g.types.model({min_width:g.types.optional(g.types.string,""),default_value_mode:ua}),ga).views(e=>({get plainData(){const{data:t}=e.contentModel.getDataStuffByID(e.options_query_id);return t},get treeData(){const t=this.plainData,r=XT(t);return YT(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}})),wa=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)}),Pi).views(e=>({get json(){const{_name:t,default_value:r,default_value_mode:a,required:o,min_width:l,static_options:i,options_query_id:c,default_selection_count:d,treeCheckStrictly:u}=e;return{_name:t,required:!!o,min_width:l,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(o=>o.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(o=>o.value)),a=(t??[]).filter(o=>r.has(o));a.length>0?e.filter.setValue(a):e.filter.setValue(e.defaultSelection)},afterCreate(){g.addDisposer(e,G.reaction(()=>JSON.stringify(e.defaultSelection),this.applyDefaultSelection,{fireImmediately:!1,delay:0}))}})),$i=()=>wa.create({_name:"tree-select",default_value:[],static_options:[],options_query_id:"",default_selection_count:0}),xa=g.types.compose("FilterTreeSingleSelectConfigMeta",g.types.model({_name:g.types.literal("tree-single-select"),default_value:g.types.optional(g.types.string,"")}),Pi).views(e=>({get json(){const{_name:t,default_value:r,default_value_mode:a,required:o,min_width:l,static_options:i,options_query_id:c,default_selection_count:d}=e;return{_name:t,required:!!o,min_width:l,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,G.reaction(()=>G.toJS(e.defaultSelection),this.applyDefaultSelection,{fireImmediately:!1,delay:0}))}})),Ai=()=>xa.create({_name:"tree-single-select",default_value:"",static_options:[],options_query_id:"",default_selection_count:0});function ZT(e,t){const r=e.startOf("week");let a=r.add(1,"week").endOf("week");for(;a.isBefore(t);)a=a.add(2,"week");return[r.toDate(),a.toDate()]}function Jt(e,t,r){return!e||!t?[e,t]:Ze(M(e),M(t),r)}function Ze(e,t,r){if(!e||!t)return[(e==null?void 0:e.toDate())??null,(t==null?void 0:t.toDate())??null];switch(r){case"day":return[e.startOf("day").toDate(),t.endOf("day").toDate()];case"week":return[e.startOf("week").toDate(),t.endOf("week").toDate()];case"bi-week":return ZT(e,t);case"month":return[e.startOf("month").toDate(),t.endOf("month").toDate()];case"quarter":return[e.startOf("quarter").toDate(),t.endOf("quarter").toDate()];default:throw new Error(`[merico-date-range] unexpected date-range step: ${r}`)}}const JT={day:new Set(["m","m2","m3","m6","y","d30","d60","d90","d180","d365"]),week:new Set(["m","m2","m3","m6","y"]),"bi-week":new Set(["m","m2","m3","m6","y"]),month:new Set(["m","m2","m3","m6","y"]),quarter:new Set(["m","m2","m6","y"])};function nt(e,t){return!JT[e].has(t)}const Ei=e=>[{key:"m",value:"last month",group:"last",disabled:nt(e,"m"),getRange:t=>{const r=M();return{value:Ze(r.subtract(1,"month").startOf("month"),r.subtract(1,"month").endOf("month"),t),shortcut:"last month",step:t}}},{key:"m2",value:"last 2 months",group:"last",disabled:nt(e,"m2"),getRange:t=>{const r=M();return{value:Ze(r.subtract(2,"month").startOf("month"),r.subtract(1,"month").endOf("month"),t),shortcut:"last 2 months",step:t}}},{key:"m3",value:"last 3 months",group:"last",disabled:nt(e,"m3"),getRange:t=>{const r=M();return{value:Ze(r.subtract(3,"month").startOf("month"),r.subtract(1,"month").endOf("month"),t),shortcut:"last 3 months",step:t}}},{key:"m6",value:"last 6 months",group:"last",disabled:nt(e,"m6"),getRange:t=>{const r=M();return{value:Ze(r.subtract(6,"month").startOf("month"),r.subtract(1,"month").endOf("month"),t),shortcut:"last 6 months",step:t}}},{key:"y",value:"last year",group:"last",disabled:nt(e,"y"),getRange:t=>{const r=M();return{value:Ze(r.subtract(1,"year").startOf("year"),r.subtract(1,"year").endOf("year"),t),shortcut:"last year",step:t}}},{key:"d30",value:"recent 30 days",group:"recent",disabled:nt(e,"d30"),getRange:t=>{const r=M();return{value:Ze(r.subtract(30,"day").startOf("day"),r.subtract(1,"day").endOf("day"),t),shortcut:"recent 30 days",step:t}}},{key:"d60",value:"recent 60 days",group:"recent",disabled:nt(e,"d60"),getRange:t=>{const r=M();return{value:Ze(r.subtract(60,"day").startOf("day"),r.subtract(1,"day").endOf("day"),t),shortcut:"recent 60 days",step:t}}},{key:"d90",value:"recent 90 days",group:"recent",disabled:nt(e,"d90"),getRange:t=>{const r=M();return{value:Ze(r.subtract(90,"day").startOf("day"),r.subtract(1,"day").endOf("day"),t),shortcut:"recent 90 days",step:t}}},{key:"d180",value:"recent 180 days",group:"recent",disabled:nt(e,"d180"),getRange:t=>{const r=M();return{value:Ze(r.subtract(180,"day").startOf("day"),r.subtract(1,"day").endOf("day"),t),shortcut:"recent 180 days",step:t}}},{key:"d365",value:"recent 365 days",group:"recent",disabled:nt(e,"d365"),getRange:t=>{const r=M();return{value:Ze(r.subtract(365,"day").startOf("day"),r.subtract(1,"day").endOf("day"),t),shortcut:"recent 365 days",step:t}}}];function Ht(e,t){if(!e)return null;const a=Ei(t).find(o=>o.value===e);return a?a.getRange(t):null}function Bi(e){return b.groupBy(Ei(e),"group")}function qi(e){try{if(e.default_shortcut){const r=Ht(e.default_shortcut,e.default_step);if(r)return{value:r.value.map(a=>M(a).toDate()),shortcut:e.default_shortcut,step:e.default_step}}const t=e.default_value.map(r=>r===null?r:M.tz(r,"UTC").toDate()??r);return{value:Jt(t[0],t[1],e.default_step),shortcut:null,step:e.default_step}}catch(t){return console.error(t),{value:[null,null],shortcut:null,step:e.default_step}}}function Li(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 HT=g.types.model("FilterMericoDateRangeConfigMeta",{_name:g.types.literal("merico-date-range"),required:g.types.boolean,inputFormat:g.types.enumeration("DateRangeInputFormat",["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,""),default_step:g.types.optional(g.types.string,"day")}).views(e=>({get json(){const{_name:t,required:r,inputFormat:a,default_step:o,default_value:l,default_shortcut:i}=e;return{_name:t,required:r,inputFormat:a,default_step:o,default_value:Li(l),default_shortcut:i}},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,o=r?M(r).format(e.inputFormat):"",l=a?M(a).format(e.inputFormat):"";return[o,l]}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},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=Ht(e.default_shortcut,e.default_step);r&&e.setFilterValue(r)},setDefaultStep(t){e.default_step=t}})),Ca=g.types.snapshotProcessor(HT,{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:Li(t,r.inputFormat)}}}),Oi=()=>Ca.create({_name:"merico-date-range",required:!1,inputFormat:"YYYY/MM/DD",default_value:[null,null],default_shortcut:"",default_step:"day"}),Pn=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",[P.Select,P.MultiSelect,P.TreeSelect,P.TreeSingleSelect,P.TextInput,P.Checkbox,P.DateRange,P.MericoDateRange]),config:g.types.union(ba,fa,wa,xa,ya,pa,ha,Ca)}).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!==P.TreeSelect&&e.type!==P.TreeSingleSelect},get usingDefaultValueFunc(){return!!e.default_value_func},get formattedDefaultValue(){return this.filters.formattedDefaultValues[e.key]},get auto_submit_supported(){return[P.Select,P.Checkbox,P.DateRange].includes(e.type)}})).views(e=>({get json(){const{id:t,key:r,label:a,order:o,visibleInViewsIDs:l,default_value_func:i,auto_submit:c,type:d,config:u}=e;return{id:t,key:r,type:d,label:a,order:o,config:u.json,auto_submit:c,visibleInViewsIDs:G.toJS(l),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 b.get(e.config,"required",!1)?b.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 P.Select:e.config=ki();break;case P.MultiSelect:e.config=Ti();break;case P.TreeSelect:e.config=$i();break;case P.TreeSingleSelect:e.config=Ai();break;case P.TextInput:e.config=va();break;case P.Checkbox:e.config=vi();break;case P.DateRange:e.config=Ci();break;case P.MericoDateRange:e.config=Oi();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 B=(e=>(e.Division="div",e.Modal="modal",e.Tabs="tabs",e))(B||{});const Sa=g.types.model("ViewDivisionConfig",{_name:g.types.literal(B.Division)}).views(e=>({get json(){const{_name:t}=e;return{_name:t}}})),Ni=()=>Sa.create({_name:B.Division}),RT=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),o=g.getRoot(e);if(!t)return a.name;try{const l={filters:o.content.filters.valuesForPayload,context:o.context.current};return new Function(`return ${r}`)()(l)}catch(l){return console.error(l),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}})),$n={enabled:!1,func_content:["function text({ filters, context}) {"," // your code goes here",' return "text"',"}"].join(`
|
|
542
542
|
`)},Ta=g.types.model("ViewModalConfig",{_name:g.types.literal(B.Modal),width:g.types.string,height:g.types.string,custom_modal_title:g.types.optional(RT,$n)}).views(e=>({get json(){const{_name:t,width:r,height:a,custom_modal_title:o}=e;return{_name:t,width:r,height:a,custom_modal_title:o.json}}})).actions(e=>({setWidth(t){e.width=t},setHeight(t){e.height=t}})),Gi=()=>Ta.create({_name:B.Modal,width:"90vw",height:"90vh"}),e2=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:o,order:l}=e;return{id:t,name:r,color:o,order:l,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)}})),ka=g.types.model("ViewTabsConfig",{_name:g.types.literal(B.Modal),tabs:g.types.optional(g.types.array(e2),[]),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:o,grow:l}=e;return{grow:l,tabs:o.map(i=>i.json),_name:t,variant:r,orientation:a}},get tabsInOrder(){return b.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){const r=e.tabs.find(a=>a.id===t);r&&e.tabs.remove(r)}})),Fi=()=>ka.create({_name:B.Modal,tabs:[]}),Qi=g.types.model({id:g.types.identifier,name:g.types.string,type:g.types.enumeration("EViewComponentType",[B.Division,B.Modal,B.Tabs]),config:g.types.union(Sa,Ta,ka),panelIDs:g.types.optional(g.types.array(g.types.string),[])}).views(e=>({get json(){const{id:t,name:r,type:a,config:o}=e;return{id:t,name:r,type:a,config:o.json,panelIDs:e.panelIDs.map(l=>l)}}})).actions(e=>({setName(t){e.name=t},setType(t){if(e.type!==t){switch(t){case B.Division:e.config=Ni();break;case B.Modal:e.config=Gi();break;case B.Tabs:e.config=Fi();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)}})),ct="14.32.0",t2={definition:{sqlSnippets:[],queries:[],mock_context:{}},views:[{id:"Main",name:"Main",type:B.Division,config:{},panelIDs:[]}],panels:[],filters:[],version:ct,layouts:[{id:"basis",name:"basis",list:[],breakpoint:0}]},Da=g.types.model("DataSourceMetaModel",{id:g.types.string,type:g.types.enumeration("DataSourceType",[W.HTTP,W.MySQL,W.Postgresql,W.MericoMetricSystem]),key:g.types.string,config:g.types.frozen()}),ji=g.types.model("DataSourcesMetaModel",{list:g.types.optional(g.types.array(Da),[])}).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)}})),Wi=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}),za=g.types.model("GlobalSQLSnippetsMeta",{list:g.types.optional(g.types.array(Wi),[])}).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)}})),An=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 Ma(e){return An.create({current:e})}const Ia=g.types.compose("ViewRenderModel",Qi,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!==B.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!==B.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===B.Tabs&&t.push(this.tabViewID),t},async downloadScreenshot(t,r){const a=t.offsetWidth*2+10,o=t.offsetHeight*2+10,l=new $s,i=new Date().getTime(),c=await Ps.toCanvas(t,{bgcolor:"white",width:a,height:o,style:{transformOrigin:"0 0",transform:"scale(2)"}}).then(d=>(r==null||r(d),new Promise(u=>{d.toBlob(p=>{u(p)})})));l.file(`${e.name}_${i}.png`,c),l.file(`dashboard_state_${i}.json`,JSON.stringify(this.contentModel.dashboardStateValues,null,4)),l.generateAsync({type:"blob"}).then(d=>{an.saveAs(d,`${e.name}_${i}.zip`)}).catch(d=>{console.error(d),Ge.notifications.show({color:"red",title:"Failed to download screenshot with dashboard state",message:d.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(Ia),[]),visibleViewIDs:g.types.array(g.types.string)}).views(e=>({get json(){return e.current.map(t=>st(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===B.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 Ui(e,t){const r=e.length>0?[e[0].id]:[],a=e.map(o=>{const{_name:l=o.type}=o.config,i={...o,tab:"",config:{...o.config,_name:l},panelIDs:o.panelIDs};if(o.type===B.Tabs){let c=b.minBy(o.config.tabs,d=>d.order);!c&&o.config.tabs.length>0&&(c=o.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 n2=new Tu.AsyncParser({withBOM:!0});async function Ki(e){return!Array.isArray(e)||e.length===0?"":await n2.parse(e).promise()}async function Yi(e,t){const r=await Ki(t),a=new Blob([r],{type:"text/csv"});an.saveAs(a,`${e}.csv`)}function Xi(e,t){const r=new $s,a=t.map(async({id:o,data:l})=>{const i=await Ki(l);r.file(`${o}.csv`,i)});Promise.all(a).then(()=>{r.generateAsync({type:"blob"}).then(o=>{an.saveAs(o,`${e}.zip`)})}).catch(o=>{console.error(o),Ge.notifications.show({color:"red",title:"Failed to download data",message:o.message})})}function Gt(e,t){const r=new Blob([t],{type:"application/json"});an.saveAs(r,`${e}.json`)}const Pa=ii.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:[]},get usingGhostViz(){return e.viz.type===Zl.name},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 ko(e.variables,this.data)},get variableAggValueMap(){const t={},r=this.data;return e.variables.reduce((a,o)=>(a[o.name]=Re(o,r),a),t),t},get variableValueMap(){const t={},r=this.variableAggValueMap;return e.variables.reduce((a,o)=>(a[o.name]=Be(o,r[o.name]),a),t),t},get variableStyleMap(){const t=this.variableValueMap,r={};return e.variables.reduce((a,o)=>{const l=rp(o.color,t[o.name]);return a[o.name]={color:l,"font-size":o.size,"font-weight":o.weight,variable:o},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(l=>!l.runByConditionsMet);if(t.length===0)return"";const r=new Set,a=new Set;t.forEach(l=>{const i=l.conditionNames;i.context.forEach(c=>r.add(c)),i.filters.forEach(c=>a.add(c))});const o=[];return r.size>0&&o.push(`context: ${Array.from(r).join(", ")}`),a.size>0&&o.push(`filter${a.size>1?"s":""}: ${Array.from(a).join(", ")}`),o.length===2&&o.splice(1,0,"and"),o.unshift("Waiting for"),o.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},get realDataFieldOptions(){return e.queryIDs.length===0?[]:this.queries.map(t=>{const r=t.data;return r.length===0?[]:Object.keys(r[0]).map(o=>({label:o,value:`${t.id}.${o}`,group:t.name,group_id:t.id,disabled:!1}))}).flat()},dataFieldOptions(t,r,a,o){let l=[...this.realDataFieldOptions];if(o&&(l=l.filter(i=>i.group_id===o)),t&&!l.find(i=>i.value===t)){const i=$(t),c=this.queryByID(i.queryID);l.unshift({label:i.columnKey,value:t,group:c?c.name:i.queryID,group_id:c?c.id:"",disabled:!0})}return r&&l.unshift({label:a,value:"",group:"",group_id:"",disabled:!1}),l},dataFieldOptionGroups(t,r,a,o){const l=this.dataFieldOptions(t,r,a,o);return Object.entries(b.groupBy(l,"group")).map(([c,d])=>({group:c,items:d.map(u=>({label:u.label,value:u.value,group_id:u.group_id,disabled:u.disabled}))}))}})).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(),l=JSON.stringify({panels:[t],definition:{queries:r},layouts:a,version:ct},null,2),i=e.name;Gt(i,l)}}));function Zi(e){return{id:e,name:"Panel",title:{show:!0},description:"<p></p>",queryIDs:[],viz:{type:Rr.name,conf:Rr.createConfig()},style:{border:{enabled:!0}}}}const $a=g.types.model("PanelsRenderModel",{list:g.types.optional(g.types.array(Pa),[])}).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 o=e.idMap.get(a);o?r.push(o):console.warn(`Panel is not found, id:${a}`)}),r}}));function Ji(e){const t=e.config,r=t==null?void 0:t.default_value;return r===void 0?r:t._name==="date-range"?wi(t):t._name==="merico-date-range"?qi(t):r}function r2(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}:e.config._name==="merico-date-range"&&Array.isArray(a)?{value:a,shortcut:null,step:e.config.step}:a}catch(a){return console.error(a),Ji(e)}}function Hi(e,t){var r;return(r=e.default_value_func)!=null&&r.trim()?r2(e,t):Ji(e)}function Ri(e,t){return e.reduce((r,a)=>(r[a.key]=Hi(a,t),r),{})}function ec(e,t){const r={};return Object.entries(t).forEach(([a,o])=>{const l=e[a];if(typeof o!="object"||!("shortcut"in o)||!l)return r[a]=l??o,r;if(Array.isArray(l))return console.log("⚪️ adapting legacy date-range value: ",l),r[a]={value:l,shortcut:null},r;const i=l,{shortcut:c}=i;if(!c)return console.log("⚪️ skipping input date range when it has no shortcut",i),r[a]=i,r;if("step"in o){const d=i.step;r[a]=Ht(c,d)}else r[a]=In(c);return r}),r}const Aa=g.types.model("FiltersRenderModel",{current:g.types.optional(g.types.array(Pn),[]),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 o=t[a.key];return r[a.key]={type:a.type,key:a.key,model:a,label:a.label??a.id,value:o},r},{})},get valuesForPayload(){const t={};return Object.entries(e.values).forEach(([r,a])=>{t[r]=a;const o=this.findByKey(r);o&&o.config._name===P.DateRange&&(t[r]=o.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 Ri(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 b.sortBy(e.current,"order")},get empty(){return e.current.length===0},visibleInView(t){return b.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=ec(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(l=>({...l.json,visibleInViewsIDs:r?l.json.visibleInViewsIDs:[]})),version:ct}},downloadSchema(t){const r=JSON.stringify(this.getSchema(t,!1),null,2);Gt("Filters",r)}}));function Ea(e,t,r,a){const o={...r,...t},l=Ri(e,o),i=ec(a,l);return console.groupCollapsed("⚪️ initialValues"),console.log("filters",e),console.log("defaultValues",l),console.log("filterValues ",a),console.log("initialValues ",i),console.groupEnd(),{current:e,values:i}}function a2(e,t){const r=As.decode(t);r!==e&&(console.error("Inconsistent sql"),console.groupCollapsed("Inconsistent sql"),console.table({before:e,after:t,v:r}),console.groupEnd())}async function s2({query:e,name:t,payload:r,additionals:a},o){if(!e.sql)return[];const{type:l,key:i,sql:c,pre_process:d,post_process:u}=e,p=yr(c,r),f=ih({sql:p,pre_process:d}),v=As.encode(f);a2(f,v);let _=await $e.query(o)({type:l,key:i,query:v,...a},{params:{name:t}});return _=ch(u,_,br(r)),_}async function o2({type:e,key:t,configString:r,name:a,additionals:o},l){try{return await $e.httpDataSourceQuery(l)({type:e,key:t,query:r,...o},{params:{name:a}})}catch(i){if(ke.isCancel(i))throw i;return console.error(i),i}}async function l2({key:e,configString:t,name:r,additionals:a},o){try{return await $e.mericoMetricQuery(o)({type:"merico_metric_system",key:e,query:t,...a},{params:{name:r}})}catch(l){throw l}}async function Ba(){try{return(await $e.post()("/datasource/list",{filter:{},sort:[{field:"create_time",order:"ASC"}],pagination:{page:1,pagesize:100}},{})).data}catch(e){return console.error(e),[]}}async function tc(){try{return(await $e.post()("/sql_snippet/list",{filter:{},sort:[{field:"id",order:"ASC"}],pagination:{page:1,pagesize:1e3}},{})).data}catch(e){return console.error(e),[]}}function i2(e){var t;if("cols"in e){const{cols:r}=e,a=((t=r.find(o=>o.type==="trending_date_col"))==null?void 0:t.metricSourceCol)??null;return{filters:r.filter(o=>o.type==="filter").map(o=>o.metricSourceCol),groupBys:r.filter(o=>o.type==="group_by").map(o=>o.metricSourceCol),trendingDateCol:a,supportTrending:!!a}}return{filters:e.filters,groupBys:e.groupBys,trendingDateCol:null,supportTrending:e.supportTrending}}const nc={string:"维度列",number:"数值列",date:"数值列",boolean:"维度列",dimension:"扩展维度"};function rc(e){return b.groupBy(e,r=>{const{dataType:a}=r;return a?nc[a]:r.dimension!==null?nc.dimension:"ERROR"})}function c2(e){if(e.length===0)return[];const t=rc(e);return Object.entries(t).map(([a,o])=>({group:`${a}(${o.length})`,items:o.map(l=>{const{dataType:i,dimension:c}=l;return c?{group:l.name,description:l.description,items:c.fields.map(d=>typeof d=="string"?{label:d,value:`${l.name} -> ${d}`}:{label:d.field,value:`${l.name} -> ${d.field}`,...d})}:{label:l.name,value:l.name,...l}})}))}function d2(e){if(e.length===0)return[];const t=rc(e);return Object.entries(t).map(([a,o])=>({group:`${a}(${o.length})`,items:o.map(l=>({label:l.name,value:l.name,description:l.description,dataType:l.dataType??"dimension",dimension:l.dimension}))}))}const ac=new Map([["accumulate",{name:"累计计算",description:"按指定的聚合方式,依次计算指标值的累计值。",requireWindowConfig:!1,requireTrendingDateCol:!1}],["yoyRatio",{name:"年同比率(yoy)",description:"对比当前年份与上一个年份同期指标值的变化率。",requireWindowConfig:!1,requireTrendingDateCol:!0}],["stepRatio",{name:"环比率",description:"对比当前步长与上一个步长指标值的变化率。",requireWindowConfig:!1,requireTrendingDateCol:!0}],["stepSpansRatio",{name:"移动计算",description:"按设定的窗口沿时序对指标值进行滚动计算。",requireWindowConfig:!0,requireTrendingDateCol:!0}],["percentage",{name:"总占比",description:"总占比 = 当前值 / 总值。",requireWindowConfig:!1,requireTrendingDateCol:!1}],["percentage_accumulate",{name:"累计占比",description:"按聚合规则计算各项占比,再依次计算占比率的累计值,如帕累托的累计占比值。",requireWindowConfig:!1,requireTrendingDateCol:!1}],["accumulate_yoyRatio",{name:"累计年同比",description:"按聚合规则累加数据,再与上一年同期累计值对比得出变化率。",requireWindowConfig:!1,requireTrendingDateCol:!0}],["yoyRatio_accumulate",{name:"年同比累计",description:"先计算各步长指标相对上一年同期的同比率,再依次计算同比率的累计值。",requireWindowConfig:!1,requireTrendingDateCol:!0}],["stepRatio_accumulate",{name:"环比累计",description:"先计算各步长指标相对上一步长的环比率,再依次计算环比率的累计值。",requireWindowConfig:!1,requireTrendingDateCol:!0}],["percentage_yoyRatio",{name:"占比年同比",description:"按聚合规则计算各项占比,再与去年同期占比对比得出变化率。",requireWindowConfig:!1,requireTrendingDateCol:!0}],["yoyRatio_stepSpansRatio",{name:"年同比移动计算",description:"先计算各步长指标相对上一年同期的同比率,再按移动设置沿时序滚动计算。",requireWindowConfig:!0,requireTrendingDateCol:!0}],["stepRatio_stepSpansRatio",{name:"环比移动计算",description:"先计算各步长指标相对上一步长的环比率,再按移动设置沿时序滚动计算。",requireWindowConfig:!0,requireTrendingDateCol:!0}]]);function sc(e,t){if(t)return e;const r=Array.from(ac.entries()).filter(([a,o])=>o.requireTrendingDateCol).map(([a])=>a);return e.filter(a=>!r.includes(a))}function oc(e,t,r){return Array.isArray(e)&&e.length===2?{start:M(e[0]).tz(t).format(r),end:M(e[1]).tz(t).format(r)}:null}const lc=gi.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 o={group:"common.invalid",items:[{label:t,value:t}]};return{optionGroups:[...r,o],validValues:a}},get conditionOptionsWithInvalidRunbys(){const{optionGroups:t,validValues:r}=this.conditionOptions,a={group:"common.invalid",items:[]};return e.run_by.forEach(o=>{r.has(o)||a.items.push({label:o,value:o})}),{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 o=b.get(r,a);return Array.isArray(o)?o.length===0:typeof o=="number"?Number.isNaN(o):!o})}})).views(e=>({get payload(){return e.contentModel.payloadForSQL},get formattedSQL(){const t=b.get(e,"config.sql","");return vr(t,this.payload)},get httpConfigString(){const{context:t,filters:r}=this.payload,{name:a,pre_process:o}=e.json,l=lh(o,t,r);return console.groupCollapsed(`Request config for: ${a}`),console.log(l),console.groupEnd(),JSON.stringify(l)},get typedAsSQL(){return[W.Postgresql,W.MySQL].includes(e.type)},get typedAsHTTP(){return[W.HTTP].includes(e.type)},get isMericoMetricQuery(){return e.type===W.MericoMetricSystem},get isTransform(){return e.type===W.Transform},get reQueryKey(){const t=b.get(e,"config.react_to",[]);if(t.length===0)return"";const r=e.contentModel.payloadForSQL,a=[...t].reduce((o,l)=>(o[l]=b.get(r,l),o),{});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(o=>o.startsWith("context.")).map(o=>o.replace("context.","")),a=e.unmetRunByConditions.filter(o=>o.startsWith("filters.")).map(o=>b.get({filters:t},o,o.replace("filters.",""))).filter(o=>!!o);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=b.get(e,"config.sql","");if(!t)return[];const r=b.uniq(t.match(Et.sqlSnippet)),a=b.uniq(t.match(Et.filter)),o=b.uniq(t.match(Et.context)),l=[];return r.forEach(i=>{l.push({type:"sql_snippet",key:i,valid:e.contentModel.sqlSnippets.keySet.has(i)})}),a.forEach(i=>{l.push({type:"filter",key:i,valid:e.contentModel.filters.keySet.has(i)})}),o.forEach(i=>{l.push({type:"context",key:i,valid:e.contentModel.mock_context.keySet.has(i)})}),l},get usedFilterKeySet(){const t=new Set,r=i=>{t.add(i.replace(/^filters\./,""))};if(e.run_by.forEach(i=>r(i)),b.get(e.config,"react_to",[]).forEach(i=>r(i)),!this.typedAsSQL)return t;const o=b.get(e,"config.sql","");return o&&b.uniq(o.match(Et.filter)).forEach(i=>r(i)),t},get metricQueryPayload(){if(e.type!==W.MericoMetricSystem)return null;const t=this.payload,r={filters:e.contentModel.filters.keysToTypes},a=e.config,o=a.filters.reduce((w,x)=>{const T=b.get(t,x.variable),D=b.get(r,x.variable),z=x.dimension;if(D===P.DateRange){const E=T.every(A=>Number.isFinite(Number(A)))?T.map(A=>Number(A)):T;w[z]={between:E}}else if(D===P.MericoDateRange){const E=T.value.every(A=>Number.isFinite(Number(A)))?T.value.map(A=>Number(A)):T;w[z]={between:E}}else Array.isArray(T)?w[z]={in:T}:w[z]={eq:T};return w},{}),l={id:a.id,type:a.type,filters:o,groupBys:a.groupBys};if(a.extraCalculations&&a.extraCalculations.length>0&&(l.extraCalculations=sc(a.extraCalculations,a.timeQuery.enabled)),a.useDefaultValues&&(l.useDefaultValues=!0),!a.timeQuery.enabled)return l;const{range_variable:i,unit_variable:c}=a.timeQuery,d="YYYY-MM-DD",u="PRC",p=b.get(r,c),f=b.get(r,i);let v=b.get(t,c,"");p===P.MericoDateRange&&(v=b.get(t,`${c}.step`,""));const _={start:"",end:"",unitOfTime:v,unitNumber:1,timezone:"PRC",stepKeyFormat:d};if(i)if(f===P.MericoDateRange){const w=b.get(t,`${i}.value`),x=oc(w,u,d);x&&(_.start=x.start,_.end=x.end)}else{const w=b.get(t,i),x=oc(w,u,d);x&&(_.start=x.start,_.end=x.end)}return l.timeQuery=_,l},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:o,end:l,unitOfTime:i}=a;return(!o||!l)&&t.push("时间维度:时间范围不完整"),i||t.push("步长:必选"),t},get metricQueryPayloadErrorString(){return this.metricQueryPayloadError.join(`
|
|
543
|
-
`)},get metricQueryPayloadValid(){return this.metricQueryPayload?this.metricQueryPayloadError.length===0:!1}})),qa=g.types.compose("QueryRenderModel",lc,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=b.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(s2({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=b.get(r,"message","unkown error");e.error=b.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:o}=e.json;let l=JSON.parse(e.httpConfigString);l=hn(e.datasource,l);const i=yield*g.toGenerator(o2({type:r,key:a,configString:JSON.stringify(l),name:e.name,additionals:e.additionalQueryInfo},e.controller.signal)),c=gn(e.datasource,i),d=zo(o,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=b.get(r,"message","unkown error");e.error=b.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:o}=e.json;let l={url:"/api/metric_management/query",method:"POST",data:e.metricQueryPayload};l=hn(e.datasource,l);const i=yield*g.toGenerator(l2({key:a,configString:JSON.stringify(l),name:e.name,additionals:e.additionalQueryInfo},e.controller.signal)),c=gn(e.datasource,i),d=zo(o,c,e.contentModel.dashboardStateValues);e.data=u2(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=b.get(r,"message","unkown error");e.error=b.get(r,"response.data.detail.message",a),e.state="error"}}}}),runTransformation(){e.state="loading";try{const t=e.depQueryModels.map(l=>({id:l.id,name:l.name,data:b.cloneDeep(l.data)})),r=e.contentModel.dashboardStateValues,a=e.pre_process,o=new Function(`return ${a}`)()(t,r,je);e.data=o,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,F.reaction(()=>{var r,a;if(e.isTransform){const o=e.config;return[e.inUse,e.id,e.key,e.reQueryKey,o.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}))}}));function u2(e){if("sortedColumns"in e&&"result"in e){const t=new Set(e.sortedColumns);return b.map(e.result,r=>{const a={};for(const o of t)a[o]=r[o];for(const o in r)t.has(o)||(a[o]=r[o]);return a})}return e}const La=g.types.model("QueriesRenderModel",{current:g.types.optional(g.types.array(qa),[])}).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 o=b.uniq(t.visibleViews.map(i=>i.renderViewIDs).flat());r.current.forEach(i=>{const c=b.get(i,"config.options_query_id");if(!c)return;o.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 l=new Set(a);return console.debug("QueryIDs:",l),l},isQueryInUse(t){return this.visibleQueryIDSet.has(t)},addTransformDepQueryIDs(t,r){this.findByIDSet(t).forEach(a=>{const o=a.config;!a.isTransform||o.dep_query_ids.length===0||o.dep_query_ids.forEach(l=>{r!=null&&r.has(l)||t.add(l)})})},get querisToForceReload(){const t=new Set,r=new Set,{views:a,filters:o}=this.contentModel,l=b.uniq(a.visibleViews.map(i=>i.renderViewIDs).flat());return o.current.forEach(i=>{const c=b.get(i,"config.options_query_id");if(!c)return;l.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}));Xi(e.dashboardName,t)},downloadDataByQueryIDs(t,r){if(r.length===1)return this.downloadDataByQueryID(t,r[0]);const a=new Set(r),o=e.current.filter(l=>a.has(l.id)).map(({name:l,data:i})=>({id:l,data:i}));Xi(t,o)},downloadDataByQueryID(t,r){const a=e.findByID(r);if(!a){console.log("[downloadDataByQueryID] query not found");return}const{data:o}=a,l=t??a.name;Yi(l,o)},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(o=>o.json)},version:ct}},downloadSchema(t){const r=JSON.stringify(this.getSchema(t),null,2);Gt("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(o=>o.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(o=>o.fetchData(!0)));console.log("🟡 Queries from filters reloaded",a)}else console.log("🟡 Found no query from visible panels, skipping")})}));function ic(e){return{current:e}}function cc({min:e,max:t}){const r=`${e}px`,a=Number.isFinite(t)?`${t}px`:"∞";return`[${r}, ${a})`}const Oa=g.types.model("LayoutsRenderModel",{list:g.types.array(bi),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 cc(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=cc(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(o=>r.has(o.panelID))},gridLayouts(t){const r=new Set(t),a={};return e.list.forEach(o=>{a[o.id]=o.list.filter(l=>r.has(l.panelID)).map(l=>l.layoutProperies)}),a},findItemByPanelID(t){return this.currentLayoutSet.findByPanelID(t)}})).actions(e=>({setCurrentBreakpoint(t){console.log("🔴 onBreakpointChange:",t),e.currentBreakpoint=t},afterCreate(){g.addDisposer(e,F.reaction(()=>e.currentBreakpoint,()=>{setTimeout(()=>{window.dispatchEvent(new Event("resize"))},32)},{fireImmediately:!1,delay:0}))}})),dc=yi.views(e=>({isADuplicatedKey(t){return!t||t===e.key?!1:!!g.getParent(e,2).findByKey(t)}})),Na=g.types.model("SQLSnippetsRenderModel",{current:g.types.optional(g.types.array(dc),[])}).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(o=>o.json)},version:ct}},downloadSchema(t){const r=JSON.stringify(this.getSchema(t),null,2);Gt("SQL Snippets",r)}}));function uc(e){return{current:e}}function Rt(e,t,r,a){return e.reduce((o,l)=>{try{o[l[t]]=yr(l[r],a)}catch(i){o[l[t]]=i.message}return o},{})}class pc{constructor(t){V(this,"origin");V(this,"copy");this.origin=t,this.copy=g.clone(t),F.makeAutoObservable(this,{},{autoBind:!0,deep:!1})}get changed(){return!b.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 hc=e=>new pc(e),p2=({description:e,isDescriptionEmpty:t})=>t?null:n.jsx(s.Tooltip,{color:"white",label:n.jsx($t,{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"})})}),h2=k.observer(({label:e,config:{default_value:t,description:r,isDescriptionEmpty:a,...o},value:l,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(p2,{description:r,isDescriptionEmpty:a})]}),checked:l||!1,onChange:c=>i(c.currentTarget.checked),...o,pt:".4em",styles:{input:{borderColor:"#e9ecef"}}})]})),g2=({value:e,onChange:t,onClose:r,max_days:a,allowSingleDateInRange:o})=>{const l=e.value,[i,c]=l,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(wt.DatePicker,{defaultDate:d,numberOfColumns:2,type:"range",value:l,onChange:f,onNextMonth:console.log,minDate:u,maxDate:p,allowSingleDateInRange:o})},f2=({begin:e,end:t})=>{const{t:r}=m.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 o=a===1?r("filter.widget.date_range.one_day"):r("filter.widget.date_range.x_days",{count:a});return n.jsx(s.Tooltip,{label:o,children:n.jsx(s.Badge,{size:"sm",variant:"light",children:a})})},b2=({max_days:e})=>{const{t}=m.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},y2=({onChange:e,onClose:t})=>{const{t:r,i18n:a}=m.useTranslation(),o=c=>()=>{const d=c();e(d),t()},l=h.useMemo(()=>mi(),[]),i=a.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(([c,d])=>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:r(`filter.widget.date_range.shortcut.${c}.label`)})}),d.map(({key:u,value:p,getRange:f})=>n.jsx(s.Table.Td,{children:n.jsx(s.Button,{size:"compact-xs",variant:"subtle",onClick:o(f),children:r(`filter.widget.date_range.shortcut.${c}.${i?"full.":""}${u}`)})},u))]},c))})})]})},gc=e=>({label:{display:"block",height:"21.7px"},input:{borderColor:e?"#228be6":"#e9ecef"}}),v2=({label:e,required:t,value:r,onChange:a,max_days:o,allowSingleDateInRange:l,inputFormat:i,disabled:c})=>{const{t:d}=m.useTranslation(),[u,{open:p,close:f}]=te.useDisclosure(!1),[v,_]=r.value,w=v?M(v).format(i):"",x=_?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:gc(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(f2,{begin:v,end:_})}),leftSection:n.jsx(S.IconMinus,{size:16}),placeholder:d("filter.widget.date_range.end_date"),readOnly:!0,disabled:!v||c,value:x,onFocus:p,styles:gc(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(b2,{max_days:o}),n.jsx(g2,{value:r,onChange:a,onClose:f,allowSingleDateInRange:l,max_days:o}),n.jsx(y2,{onChange:a,onClose:f})]})]})},fc={value:[null,null],shortcut:null},Ga=e=>{const t=In(e.shortcut);return t||(Array.isArray(e.value)?e:fc)},_2=e=>h.useMemo(()=>Ga(e),[e]),bc=k.observer(({label:e,config:t,value:r=fc,onChange:a,disabled:o})=>{const{inputFormat:l,required:i,max_days:c,allowSingleDateInRange:d}=t,u=_2(r);return n.jsx(v2,{label:e,value:u,onChange:a,inputFormat:l,allowSingleDateInRange:d,max_days:c,required:i,disabled:o})}),m2=ht.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"}}})),w2={root:{cursor:"pointer","&:hover":{backgroundColor:"var(--mantine-color-default-hover)"},"input, .mantine-Checkbox-labelWrapper":{cursor:"pointer",pointerEvents:"none"}}},x2=({disabled:e,radius:t,style:r,label:a,value:o,onChange:l,options:i,errorMessage:c,required:d})=>{const{t:u}=m.useTranslation(),{classes:p,cx:f}=m2({radius:t,name:"MultiSelectWidget"}),[v,_]=h.useState(!1),w=N=>{_(N)},x=v&&(o==null?void 0:o.length)>0,[T,D]=h.useState(""),z=h.useMemo(()=>{if(!T)return i;const N=T.toLowerCase(),oe=be=>{var dt;return((dt=be.description)==null?void 0:dt.toLowerCase().includes(N))||be.label.toLowerCase().includes(N)};return i.filter(oe)},[T,i]),I=h.useMemo(()=>new Set(i.map(N=>N.value)),[i]),E=h.useMemo(()=>new Set(o),[o]),A=h.useMemo(()=>E.size!==I.size?!1:Array.from(I).every(N=>E.has(N)),[E,I]),U=()=>{if(A){l([]);return}const N=Array.from(I);l(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:"*"})]}),x&&n.jsx(s.Tooltip,{label:u("filter.widget.common.x_selected",{count:o.length}),children:n.jsx(s.Badge,{variant:"light",children:o.length})})]}),n.jsx(Es,{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:o,onChange:l,onSelect:console.log,mode:"multiple",maxTagCount:0,notFoundContent:n.jsx(ma,{errorMessage:c}),maxTagTextLength:10,maxTagPlaceholder:N=>u("filter.widget.common.x_selected",{count:N.length}),searchValue:T,onSearch:D,filterOption:!1,dropdownRender:N=>n.jsxs(n.Fragment,{children:[I.size>0&&!T&&n.jsx(s.Group,{px:"xs",py:"xs",onClick:U,styles:w2,children:n.jsx(s.Checkbox,{size:"xs",checked:A,onChange:b.noop,label:u("common.actions.select_all")})}),n.jsx(s.Divider,{}),N]}),children:z.map(N=>n.jsxs(Es.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))})]})},C2=k.observer(({label:e,config:t,value:r,onChange:a})=>{const o=H(),l=!!t.options_query_id,{state:i,error:c}=o.getDataStuffByID(t.options_query_id),d=i==="loading",u=t.min_width?t.min_width:"200px",p=l?d:!1,f=h.useMemo(()=>t.initialSelection(r),[r,t.initialSelection]),v=_=>a(_,!1);return n.jsx(x2,{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})}),S2=({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})]})})})},T2=k.observer(({label:e,config:t,value:r,onChange:a})=>{const{t:o}=m.useTranslation(),l=H(),i=!!t.options_query_id,{state:c,error:d}=l.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:S2,searchable:!d,nothingFoundMessage:d||o("filter.widget.common.selector_option_empty"),clearable:t.clearable})});function k2({label:e,config:t,value:r,onChange:a}){return n.jsx(s.TextInput,{label:e,value:r||"",onChange:o=>a(o.currentTarget.value),...t,styles:{input:{borderColor:"#e9ecef"}}})}const D2=({value:e,handleRangeChange:t})=>{const r=e.value,[a,o]=r,l=h.useMemo(()=>a||new Date,[a]),i=h.useMemo(()=>{if(a&&!o)return a},[a,o]),c=h.useMemo(()=>M().add(365,"days").toDate(),[]);return n.jsx(wt.DatePicker,{defaultDate:l,numberOfColumns:2,type:"range",value:r,onChange:t,onNextMonth:console.log,minDate:i,maxDate:c,allowSingleDateInRange:!0})};function Fa(e,t){if(!e)return null;const r=M(e);switch(t){case"day":case"week":case"month":case"quarter":return r.startOf(t);case"bi-week":return r.startOf("week").subtract(1,"week");default:throw new Error(`[merico-date-range] unexpected date-range step: ${t}`)}}function Qa(e,t){if(!e)return null;const r=M(e);switch(t){case"day":case"week":case"month":case"quarter":return r.endOf(t);case"bi-week":return r.endOf("week");default:throw new Error(`[merico-date-range] unexpected date-range step: ${t}`)}}function z2(e,t){if(!e)return null;const r=Fa(e,t),a=Qa(e,t);return{start:r,end:a}}function M2(e,t,r,a){if(!t)return!1;const[o]=r,l=Fa(t,a),i=Qa(t,a),c=M(e).isBefore(i);return o?M(e).isAfter(o)&&c:M(e).isAfter(l)&&c}function I2(e,t,r){if(!t)return!1;const[a]=r;return a?e.isSame(a,"day"):e.isSame(t,"day")}function V2(e,t){return t?e.isSame(t,"day"):!1}function P2(e,t){const[r,a]=t;if(!r||!a)return{inRange:!1,firstInRange:!1,lastInRange:!1,selected:!1};const o=e.isSame(r,"day"),l=e.isSame(a,"day");return{inRange:e.isBetween(r,a,"day","[]"),firstInRange:o,lastInRange:l,selected:o||l}}const $2=(e,t,r)=>{const a=e.step,[o,l]=h.useState(null),[i,c]=h.useState(e.value),d=(_,w)=>{if(!_||!w)return;const[x,T]=i,D=_.toDate(),z=w.toDate();if(x===null){c([D,null]);return}const E=D.getTime()<x.getTime()?[D,T]:[x,z];c(E),t(E)};h.useEffect(()=>{c(e.value)},[e]),h.useEffect(()=>{c([null,null])},[r]);const u=h.useMemo(()=>r?null:i[0]?M(i[0]):null,[i,r]),p=h.useMemo(()=>r?null:i[0]?M(i[0]).add(365,"days"):null,[i,r]),f=h.useCallback(_=>{const w=M(_);return P2(w,e.value)},[r,e.value]),v=h.useCallback(_=>{const w=M(_),x=u&&p&&(w.isBefore(u)||w.isAfter(p)),T=!o&&i[0]?i[0]:o,D=z2(T,a);if(!D)return{onMouseEnter:()=>l(_),onMouseLeave:()=>l(null),inRange:!1,firstInRange:!1,lastInRange:!1,selected:!1,disabled:x};if(w.format("MM-DD"),x)return{onMouseEnter:b.noop,onMouseLeave:b.noop,inRange:!1,firstInRange:!1,lastInRange:!1,selected:!1,disabled:!0};const{start:z,end:I}=D,E=I2(w,z,i),A=V2(w,I),U=M2(_,T,i,a),N=U&&E,oe=U&&A,be=w.isBefore(u)||w.isAfter(p);return{onMouseEnter:()=>l(_),onMouseLeave:()=>l(null),inRange:U,firstInRange:N,lastInRange:oe,selected:E||A,onClick:()=>d(z,I),disabled:be}},[o,t,a,r,u,p,i]);return{getDayProps:r?f:v}},A2=({value:e,onChange:t,handleRangeChange:r})=>{const[a,o]=h.useState(!0),l=e.value,[i,c]=l,d=h.useMemo(()=>i||new Date,[i]),{getDayProps:u}=$2(e,r,a),p=()=>{o(!1)},f=()=>{o(!!i&&!!c)};return n.jsx(wt.Calendar,{defaultDate:d,numberOfColumns:2,withCellSpacing:!1,getDayProps:u,onMouseEnter:p,onMouseLeave:f,hideOutsideDates:!0})},E2=({value:e,handleRangeChange:t})=>{const r=e.value,[a,o]=r,l=h.useMemo(()=>a||new Date,[a]),i=h.useMemo(()=>{if(a&&!o)return a},[a,o]),c=h.useMemo(()=>M().add(365,"days").toDate(),[]);return n.jsx(wt.MonthPicker,{defaultDate:l,numberOfColumns:2,type:"range",value:r,onChange:t,minDate:i,maxDate:c,allowSingleDateInRange:!0})},En={calendar_header:"_calendar_header_xr0sl_1",months_list:"_months_list_xr0sl_5",months_list_row:"_months_list_row_xr0sl_12",months_list_control:"_months_list_control_xr0sl_25"},B2=({value:e,handleRangeChange:t})=>{const r=e.value,[a,o]=r,l=h.useMemo(()=>a||new Date,[a]),i=h.useMemo(()=>{if(a&&!o)return a},[a,o]),c=h.useMemo(()=>M(a).add(365,"days").subtract(1,"second").toDate(),[a]),d=h.useMemo(()=>o?M(o):null,[o]),u=h.useCallback(p=>d&&M(p).isSame(d,"quarter")?{lastInRange:!0,selected:!0}:{},[d]);return n.jsx(wt.MonthPicker,{classNames:{calendarHeader:En.calendar_header,monthsList:En.months_list,monthsListRow:En.months_list_row,monthsListControl:En.months_list_control},defaultDate:l,numberOfColumns:2,type:"range",value:r,onChange:t,minDate:i,maxDate:c,allowSingleDateInRange:!0,maxLevel:"year",monthsListFormat:"Q",getMonthControlProps:u})},q2=({value:e,onChange:t,onClose:r})=>{const a=l=>{const[i,c]=l,d=Fa(i,e.step),u=Qa(c,e.step);t([(d==null?void 0:d.toDate())??null,(u==null?void 0:u.toDate())??null]),i&&c&&r()},o=e.step;return o==="day"?n.jsx(D2,{value:e,handleRangeChange:a}):o==="week"||o==="bi-week"?n.jsx(A2,{value:e,onChange:t,handleRangeChange:a}):o==="month"?n.jsx(E2,{value:e,handleRangeChange:a}):o==="quarter"?n.jsx(B2,{value:e,handleRangeChange:a}):`错误的步长:${o}`},L2=({begin:e,end:t})=>{const{t:r}=m.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 o=a===1?r("filter.widget.date_range.one_day"):r("filter.widget.date_range.x_days",{count:a});return n.jsx(s.Tooltip,{label:o,children:n.jsx(s.Badge,{size:"sm",variant:"light",children:a})})},ja={begin:"_begin_1cder_1",end:"_end_1cder_27",step:"_step_1cder_52"},yc=({label:e,value:t,onChange:r,className:a})=>{const{t:o,i18n:l}=m.useTranslation(),i=h.useMemo(()=>[{label:o("filter.widget.date_range.step.day"),value:"day"},{label:o("filter.widget.date_range.step.week"),value:"week"},{label:o("filter.widget.date_range.step.bi_week"),value:"bi-week"},{label:o("filter.widget.date_range.step.month"),value:"month"},{label:o("filter.widget.date_range.step.quarter"),value:"quarter"}],[o]),c=d=>{d&&r(d)};return n.jsx(s.Select,{className:a,label:e,data:i,value:t,onChange:c})},O2=({onChange:e,step:t,onClose:r})=>{const{t:a,i18n:o}=m.useTranslation(),l=d=>()=>{const u=d(t);e(u),r()},i=h.useMemo(()=>Bi(t),[t]),c=o.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(i).map(([d,u])=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{w:80,children:n.jsx(s.Text,{size:"xs",c:"#555",fw:500,sx:{textAlignLast:"justify"},children:a(`filter.widget.date_range.shortcut.${d}.label`)})}),u.map(({key:p,value:f,getRange:v})=>n.jsx(s.Table.Td,{children:n.jsx(s.Button,{size:"compact-xs",variant:"subtle",onClick:l(v),children:a(`filter.widget.date_range.shortcut.${d}.${c?"full.":""}${p}`)})},p))]},d))})})]})},vc=e=>({label:{display:"block",height:"21.7px"},input:{borderColor:e?"#228be6":"#e9ecef"}}),N2=({label:e,required:t,value:r,onChange:a,inputFormat:o,disabled:l})=>{const{t:i}=m.useTranslation(),[c,{open:d,close:u}]=te.useDisclosure(!1),[p,f]=r.value,v=p?M(p).format(o):"",_=f?M(f).format(o):"",w=T=>{a({value:Jt(T[0],T[1],r.step),shortcut:null,step:r.step})},x=T=>{if(r.shortcut)return a(Ht(r.shortcut,T));a({value:Jt(r.value[0],r.value[1],T),shortcut:r.shortcut,step:T})};return n.jsxs(s.Popover,{opened:c,onClose:u,position:"bottom-start",shadow:"md",children:[n.jsxs(s.Group,{justify:"flex-start",align:"text-anchor",wrap:"nowrap",gap:0,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:i("filter.widget.date_range.start_date"),readOnly:!0,disabled:l,value:v,onFocus:d,styles:vc(c),className:ja.begin})}),n.jsx(s.TextInput,{label:n.jsx(s.Box,{children:" "}),leftSection:n.jsx(S.IconMinus,{size:16,onClick:d}),placeholder:i("filter.widget.date_range.end_date"),readOnly:!0,disabled:l,value:_,onFocus:d,styles:vc(c),className:ja.end}),n.jsx(yc,{className:ja.step,value:r.step,onChange:x,label:n.jsx(s.Group,{justify:"flex-end",children:n.jsx(L2,{begin:p,end:f})})})]}),n.jsxs(s.Popover.Dropdown,{p:"sm",children:[n.jsx(q2,{value:r,onChange:w,onClose:u}),n.jsx(O2,{onChange:a,step:r.step,onClose:u})]})]})},_c={value:[null,null],shortcut:null,step:"day"},G2=e=>{const t=Ht(e.shortcut,e.step);return t||(Array.isArray(e.value)?e:_c)},F2=e=>h.useMemo(()=>G2(e),[e]),Q2=k.observer(({label:e,config:t,value:r=_c,onChange:a,disabled:o})=>{const{inputFormat:l,required:i}=t,c=F2(r);return n.jsx(N2,{label:e,value:c,onChange:a,inputFormat:l,required:i,disabled:o})}),j2=k.observer(({filter:{type:e,config:t,key:r,...a},formFieldProps:o})=>{switch(e){case P.Select:return n.jsx(T2,{...a,...o,config:t});case P.MultiSelect:return n.jsx(C2,{...a,...o,config:t});case P.TreeSelect:return n.jsx(QT,{...a,...o,config:t});case P.TreeSingleSelect:return n.jsx(KT,{...a,...o,config:t});case P.TextInput:return n.jsx(k2,{...a,...o,config:t});case P.DateRange:return n.jsx(bc,{...a,...o,config:t});case P.MericoDateRange:return n.jsx(Q2,{...a,...o,config:t});case P.Checkbox:return n.jsx(h2,{...a,...o,config:t});default:return null}}),W2=k.observer(h.forwardRef(({filter:e,...t},r)=>n.jsx("div",{className:"filter-root",ref:r,children:n.jsx(ne,{children:n.jsx(j2,{filter:e,formFieldProps:t})})}))),U2=({disabled:e,onSubmit:t})=>{const{t:r}=m.useTranslation(),{renderSearchButton:a}=Ws();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 K2(e){const t=G();h.useEffect(()=>{var r,a;(a=(r=t.filters).updatePreviewValues)==null||a.call(r,e)},[e])}const Wa="N/A";function Y2(){const e=jt(),t=e.content.views.visibleViews;return h.useMemo(()=>t.map(o=>{var l;return o.type===B.Tabs?(l=o.tabView)==null?void 0:l.view_id:o.id}).filter(Boolean).flatMap(o=>e.content.filters.visibleInView(o)).filter(Boolean).map(o=>X2(o)),[t])}function X2(e){switch(e.type){case P.Select:case P.MultiSelect:case P.TreeSelect:case P.TreeSingleSelect:return{label:e.label,value:Z2(e.config,e.value)};case P.TextInput:return{label:e.label,value:e.value};case P.DateRange:return{label:e.label,value:J2(e.config,e.value)};case P.MericoDateRange:return{label:e.label,value:H2(e.config,e.value)};case P.Checkbox:return{label:e.label,value:R2(e.value)};default:return{label:e.label,value:e.value}}}function Z2(e,t){const r=new Set;return Array.isArray(t)?t.forEach(a=>r.add(a)):r.add(t),r.size===0?Wa:e.options.filter(a=>r.has(a.value)).map(a=>a.label).join(", ")}function YI(e){return e}function J2(e,t){const a=Ga(t).value.filter(o=>!!o).map(o=>M(o).format(e.inputFormat));return a.length===0?Wa:a.join(" - ")}function H2(e,t){const a=Ga(t).value.filter(o=>!!o).map(o=>M(o).format(e.inputFormat));return a.length===0?Wa:a.join(" - ")}function R2(e){return e?"✔️":"❌"}const ek=({opened:e,toggle:t})=>{const{t:r}=m.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")})})},mc=k.observer(function({view:t}){const[r,{toggle:a}]=te.useDisclosure(!0),o=H(),{control:l,handleSubmit:i,reset:c}=y.useForm({defaultValues:o.filters.values,reValidateMode:"onBlur"}),d=y.useWatch({control:l});h.useEffect(()=>{c(o.filters.values)},[o.filters.values,c]),K2(d);const u=o.filters.visibleInView(t.id),p=h.useMemo(()=>u.every(x=>x.should_auto_submit),[u]),f=h.useMemo(()=>u.filter(x=>b.get(x,"config.required",!1)),[u]),v=h.useMemo(()=>f.length===0?!1:f.some(x=>!x.requiredAndPass(d[x.key])),[d,f]),_=(x,T)=>(D,z)=>{T(D),(x.should_auto_submit||z)&&o.filters.setValueByKey(x.key,D)},w=h.useCallback(x=>{const T=b.get(x,"force",!1);i(o.filters.setValues)(),T&&o.queries.forceReloadVisibleQueries()},[i,o.filters.setValues]);return u.length===0?null:n.jsxs("form",{children:[n.jsx(ek,{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(x=>n.jsx(y.Controller,{name:x.key,control:l,render:({field:T})=>n.jsx(W2,{filter:x,value:T.value,onChange:_(x,T.onChange)})},x.id))}),!p&&n.jsx(s.Group,{sx:{alignSelf:"flex-end"},children:n.jsx(U2,{disabled:v,onSubmit:w})})]})})]})}),wc={withInteraction:!0,withAddon:!0,withPanelTitle:!0},xc=h.createContext(wc);function tk({children:e,...t}){const r=b.defaults({},t,wc);return n.jsx(xc.Provider,{value:r,children:e})}function Ua(){return h.useContext(xc)}function nk(e){return e?["<p><br></p>","<p></p>"].includes(e):!0}const rk=k.observer(()=>{const e=H(),{panel:t}=re(),r=h.useMemo(()=>ft(t.description,t.json.variables,e.payloadForViz,t.data),[t.data,t.description,t.json.variables,e.payloadForViz]);return n.jsx($t,{value:r,styles:{root:{border:"none"},content:{padding:0}},sx:{".mantine-RichTextEditor-content .ProseMirror":{padding:"0 !important"}},dashboardStateValues:e.dashboardStateValues,variableAggValueMap:t.variableAggValueMap})}),Ka=k.observer(()=>{const{t:e}=m.useTranslation(),[t,r]=h.useState(!1),{panel:a}=re();return nk(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(rk,{})}),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(o=>!o),sx:{verticalAlign:"baseline",cursor:"pointer"},children:n.jsx(S.IconInfoCircle,{size:20})})})]})}),XI="",ak=k.observer(function(){const{panel:t}=re(),{name:r,title:a}=t;return a.show?n.jsx(s.Group,{"data-testid":"panel-title-bar",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}),Ya=h.createContext({onScreenshot:b.noop});function sk(e){const t=h.useRef(null),{onScreenshot:r}=h.useContext(Ya);return{ref:t,downloadPanelScreenshot:()=>{const o=t.current;if(!o)return;const l=o.offsetWidth*2,i=o.offsetHeight*2;Ps.toCanvas(t.current,{bgcolor:"white",width:l,height:i,style:{border:"none",borderRadius:0,transformOrigin:"0 0",transform:"scale(2)"}}).then(c=>(r(c),c)).then(c=>new Promise(d=>{c.toBlob(u=>{d(u)})})).then(c=>{window.saveAs(c,`${e.name?e.name:e.viz.type}.png`)})}}}var Cc=(e=>(e.migrated="migrated",e.nothingToMigrate="nothingToMigrate",e.checkFailed="checkFailed",e.migrationFailed="migrationFailed",e))(Cc||{}),Bn=(e=>(e.notStarted="notStarted",e.inProgress="inProgress",e.done="done",e))(Bn||{});class ok{constructor(t){V(this,"vizInstance");V(this,"operationManager");V(this,"triggerManager");V(this,"vizManager");V(this,"runningMigration");V(this,"panelModel");V(this,"status","notStarted");this.panelModel=t.getRequired(ee.instanceScope.panelModel),this.vizInstance=t.getRequired(ee.instanceScope.vizInstance),this.operationManager=t.getRequired(ee.instanceScope.operationManager),this.triggerManager=t.getRequired(ee.instanceScope.triggerManager),this.vizManager=t.getRequired(ee.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 lk{getTriggerSchemaList(){return[]}getTriggerList(){return Promise.resolve([])}removeTrigger(){return Promise.resolve()}createOrGetTrigger(){return Promise.resolve(Sc)}retrieveTrigger(){return Promise.resolve(Sc)}watchTriggerSnapshotList(){return()=>{}}needMigration(){return Promise.resolve(!1)}runMigration(){return Promise.resolve()}}class ik{constructor(){V(this,"id","");V(this,"schemaRef","");V(this,"triggerData",new on({}))}}const Sc=new ik;class ck{getOperationSchemaList(){return[]}getOperationList(){return Promise.resolve([])}removeOperation(){return Promise.resolve()}createOrGetOperation(){return Promise.resolve(Tc)}runOperation(){return Promise.resolve()}retrieveTrigger(){return Promise.resolve(Tc)}runMigration(){return Promise.resolve()}needMigration(){return Promise.resolve(!1)}}class dk{constructor(){V(this,"id","");V(this,"schemaRef","");V(this,"operationData",new on({}))}}const Tc=new dk,Fn=class Fn{constructor(){V(this,"triggerManager",new lk);V(this,"operationManager",new ck)}getInteractionList(){return Promise.resolve([])}addInteraction(){return Promise.resolve()}removeInteraction(){return Promise.resolve()}runInteraction(){return Promise.resolve()}};V(Fn,"instance",new Fn);let Xa=Fn;function kc(e,t=!0){const{panel:r}=re();return h.useCallback(a=>{const o=a.getRequired(ee.vizManager),l=o.resolveComponent(e.viz.type);return a.createScoped().provideFactory(ee.instanceScope.vizInstance,()=>o.getOrCreateInstance(e)).provideFactory(ee.instanceScope.interactionManager,i=>{const c=i.getRequired(ee.instanceScope.vizInstance);return t?new Bo(c,l,Cr):new Xa}).provideFactory(ee.instanceScope.operationManager,i=>i.getRequired(ee.instanceScope.interactionManager).operationManager).provideFactory(ee.instanceScope.triggerManager,i=>i.getRequired(ee.instanceScope.interactionManager).triggerManager).provideValue(ee.instanceScope.panelModel,r).provideFactory(ee.instanceScope.migrator,i=>new ok(i))},[e.viz.type,e.viz.conf,t])}function Dc(e){const[t,r]=h.useState(!1),a=Yt().getRequired(ee.instanceScope.migrator);return O.useAsyncEffect(async()=>{const o=a.status===Bn.notStarted;r(a.status===Bn.done),a.status===Bn.notStarted&&a.runMigration().then(l=>{l===Cc.migrated&&o&&(e==null||e())}).finally(()=>{r(!0)})},[a]),t}function zc(e,t){const r=Yt().getRequired(ee.instanceScope.vizInstance);return O.useAsyncEffect(async()=>{b.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 uk({setVizConf:e,...t}){const{panel:r}=t,a=zc(e,r),o=Dc(()=>{Ge.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]),o?n.jsx(qu,{...t}):n.jsx(s.Text,{size:"sm",children:"Checking update..."})}function pk(e){const{panel:t,setVizConf:r}=e;zc(r,t);const{inEditMode:a}=h.useContext(St);return Dc(()=>{a&&Ge.showNotification({title:`${t.name} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})})?n.jsx(Bu,{...e}):n.jsx(s.Text,{size:"sm",children:"Checking update"})}const ZI="";function hk(e,t){const{vizManager:r}=h.useContext(lt),{panel:{viz:a,title:o,id:l,name:i,description:c,queryIDs:d,variables:u}}=re(),p={id:l,name:i,title:o,description:c,queryIDs:d,viz:a},{withInteraction:f}=Ua(),v=kc(p,f);try{return r.resolveComponent(a.type),n.jsxs(bn,{configure:v,children:[n.jsx(pk,{setVizConf:a.setConf,panel:p,measure:t,data:e,variables:u,vizManager:r}),n.jsx(Ic,{})]})}catch(_){return console.info(b.get(_,"message")),null}}const Mc=k.observer(function({data:t}){const{ref:r,width:a,height:o}=te.useElementSize(),l=hk(t,{w:a,h:o}),i=a>0&&o>0;return n.jsx("div",{className:"viz-root",ref:r,children:n.jsx(s.Box,{sx:{width:a,height:o,overflow:"hidden"},children:i&&n.jsx(ne,{children:l})})})});function gk(e){const{setEchartsOptions:t}=re();h.useEffect(()=>{const r=o=>{t(o)},a=e.messageChannels.getChannel("viz");return a.on("rendered",r),()=>{a.off("rendered",r)}},[e.messageChannels])}const Ic=()=>{const e=Yt(),t=e.getRequired(ee.instanceScope.vizInstance);gk(t);const{inEditMode:r}=h.useContext(St),a=e.getRequired(ee.panelAddonManager),{withAddon:o}=Ua(),l=Wu();return!l||!o?null:Du.createPortal(n.jsx(n.Fragment,{children:a.createPanelAddonNode({viz:t,isInEditMode:r})}),l,"addon")},Vc=k.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})]})),Za=k.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(Vc,{panel:e}),e.canRenderViz&&n.jsx(Mc,{data:e.data})]}));function fk(e){return!["richText","button","vizDashboardState"].includes(e)}const bk=k.observer(({children:e})=>n.jsx(n.Fragment,{children:n.jsxs(s.Menu,{withinPortal:!0,trigger:"hover",children:[n.jsx(s.Menu.Target,{children:n.jsx(s.ActionIcon,{variant:"subtle",color:"black",size:"md",pos:"absolute",top:16,right:16,style:{zIndex:410},children:n.jsx(S.IconDotsVertical,{size:14,style:{width:"70%",height:"70%"}})})}),n.jsx(s.Menu.Dropdown,{children:e})]})}));function yk(e){const t=h.useRef(null),r=h.useCallback(a=>{t.current=a},[]);return h.useEffect(()=>{t.current=null},[e]),{getEchartsOptions:()=>t.current,setEchartsOptions:r}}const vk={border:"1px solid #e9ecef"},Ja=k.observer(({panel:e,panelStyle:t,dropdownContent:r})=>{const{ref:a,downloadPanelScreenshot:o}=sk(e),{withAddon:l,withPanelTitle:i}=Ua(),c=l?Ns:h.Fragment,{getEchartsOptions:d,setEchartsOptions:u}=yk(e.viz.type),{inEditMode:p}=h.useContext(St),f=p||fk(e.viz.type);return n.jsx(Hn,{value:{panel:e,data:e.data,loading:e.dataLoading,errors:e.queryErrors,downloadPanelScreenshot:o,getEchartsOptions:d,setEchartsOptions:u},children:n.jsx(s.Box,{id:e.id,"data-testid":"panel-root",className:`panel-root ${e.title.show?"panel-root--show-title":""}`,ref:a,p:0,sx:{...vk,...t},children:n.jsxs(c,{children:[i&&n.jsxs(n.Fragment,{children:[n.jsx(s.Box,{className:"panel-description-popover-wrapper",children:n.jsx(Ka,{})}),f&&n.jsx(bk,{children:r}),n.jsx(ak,{})]}),n.jsx(Za,{panel:e})]})})})}),Pc=k.observer(()=>{const{t:e}=m.useTranslation(),{panel:t}=re();return n.jsx(s.Menu.Item,{onClick:t.downloadData,leftSection:n.jsx(S.IconDownload,{size:14}),children:e("common.actions.download_data")})}),$c=k.observer(()=>{const{t:e}=m.useTranslation(),{panel:t,downloadPanelScreenshot:r}=re();return n.jsx(s.Menu.Item,{onClick:r,leftSection:n.jsx(S.IconCamera,{size:14}),children:e("common.actions.download_screenshot")})}),_k=k.observer(()=>{const{t:e}=m.useTranslation(),{panel:t}=re();return n.jsx(s.Menu.Item,{onClick:t.downloadSchema,leftSection:n.jsx(S.IconCode,{size:14}),children:e("common.actions.download_schema")})}),mk={viewPanelInFullScreen:b.noop,inFullScreen:!1},Ha=h.createContext(mk),Ac=k.observer(({view:e})=>{const{t}=m.useTranslation(),{panel:r}=re(),a=r.id,{viewPanelInFullScreen:o,inFullScreen:l}=h.useContext(Ha),i=h.useCallback(()=>{o(a)},[a,o]);return!l&&e.type!==B.Modal?n.jsx(s.Menu.Item,{onClick:i,leftSection:n.jsx(S.IconArrowsMaximize,{size:14}),disabled:!0,children:t("common.actions.enter_fullscreen")}):null}),Ec=k.observer(()=>{const{t:e}=m.useTranslation(),{panel:t}=re();return n.jsx(s.Menu.Item,{onClick:t.refreshData,leftSection:n.jsx(S.IconRefresh,{size:14}),children:e("common.actions.refresh")})}),wk=e=>{const{items:t}=ar();return h.useMemo(()=>[{order:10,render:()=>n.jsx(Ec,{},"refresh")},{order:100,render:()=>n.jsx(Pc,{},"download-data")},{order:300,render:()=>n.jsx($c,{},"download-screenshot")},{order:400,render:()=>n.jsx(Ac,{view:e},"enter-full-screen")},...t].sort((a,o)=>a.order-o.order),[t])},xk=k.observer(({view:e})=>{const{getEchartsOptions:t,panel:r}=re();return wk(e).map(o=>o.render({getEchartsOptions:t,inEditMode:!1,panelID:r.id,viewID:e.id}))}),Ck=k.observer(({panelID:e,viewID:t})=>{const{t:r}=m.useTranslation(),a=j(),o=()=>{a.editor.open(["_VIEWS_",t,"_PANELS_",e,"_TABS_","Panel"])};return n.jsx(s.Menu.Item,{onClick:o,leftSection:n.jsx(S.IconAppWindow,{size:14}),children:r("panel.label")})}),Sk=k.observer(({panelID:e,viewID:t})=>{const{t:r}=m.useTranslation(),a=j(),o=()=>{a.editor.open(["_VIEWS_",t,"_PANELS_",e,"_TABS_","Variables"])};return n.jsx(s.Menu.Item,{onClick:o,leftSection:n.jsx(S.IconVariable,{size:14}),children:r("panel.variable.labels")})}),Tk=k.observer(({panelID:e,viewID:t})=>{const{t:r}=m.useTranslation(),a=j(),o=()=>{a.editor.open(["_VIEWS_",t,"_PANELS_",e,"_TABS_","Visualization"])};return n.jsx(s.Menu.Item,{onClick:o,leftSection:n.jsx(S.IconChartHistogram,{size:14}),children:r("visualization.label")})}),kk=k.observer(({panelID:e,viewID:t})=>{const{t:r}=m.useTranslation(),a=j(),o=()=>{a.editor.open(["_VIEWS_",t,"_PANELS_",e,"_TABS_","Interactions"])};return n.jsx(s.Menu.Item,{onClick:o,leftSection:n.jsx(S.IconRoute,{size:14}),children:r("interactions.label")})}),Dk=k.observer(({panelID:e,viewID:t})=>{const{t:r}=m.useTranslation(),a=De.useModals(),o=G(),l=()=>a.openConfirmModal({title:`${r("panel.delete")}?`,labels:{confirm:r("common.actions.confirm"),cancel:r("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>o.removePanelByID(e,t),confirmProps:{color:"red"},zIndex:320});return n.jsx(s.Menu.Item,{color:"red",onClick:l,leftSection:n.jsx(S.IconTrash,{size:14}),children:r("common.actions.delete")})}),zk=k.observer(({panelID:e,viewID:t})=>{const{t:r}=m.useTranslation(),a=G(),o=()=>{a.duplicatePanelByID(e,t)};return n.jsx(s.Menu.Item,{onClick:o,leftSection:n.jsx(S.IconCopy,{size:14}),children:r("common.actions.duplicate")})}),Mk=k.observer(({panelID:e,viewID:t})=>{const{t:r}=m.useTranslation(),a=j(),o=()=>{a.editor.open(["_VIEWS_",t,"_PANELS_",e,"_TABS_","Data"])};return n.jsx(s.Menu.Item,{onClick:o,leftSection:n.jsx(S.IconDatabase,{size:14}),children:r("data.label")})}),Ik=e=>{const{t}=m.useTranslation(),r=j(),{panel:a}=ae(),o=a.realQueryOptions,l=i=>{r.editor.open(["_QUERIES_",i])};return h.useMemo(()=>o.length===0?[]:[{order:500,render:()=>n.jsx(s.Divider,{label:t(o.length>1?"query.labels":"query.label"),labelPosition:"center"},"data-divider")},{order:501,render:()=>n.jsx(Mk,{panelID:a.id,viewID:e.id},"open-tab-data")},...o.map((i,c)=>({order:502+c,render:()=>n.jsx(s.Menu.Item,{onClick:()=>l(i.value),leftSection:n.jsx(S.IconDatabase,{size:14}),children:i.label},i.value)}))],[o])},Vk=e=>{const{t}=m.useTranslation(),{panel:r}=ae(),a=r.id,o=e.id,{items:l}=ar(),i=Ik(e);return h.useMemo(()=>[{order:10,render:()=>n.jsx(Ec,{},"refresh")},{order:100,render:()=>n.jsx(Pc,{},"download-data")},{order:200,render:()=>n.jsx(_k,{},"download-schema")},{order:300,render:()=>n.jsx($c,{},"download-screenshot")},{order:400,render:()=>n.jsx(Ac,{view:e},"enter-full-screen")},...i,{order:600,render:()=>n.jsx(s.Divider,{label:t("common.actions.edit"),labelPosition:"center"},"edit-divider")},{order:700,render:()=>n.jsx(Ck,{panelID:a,viewID:o},"open-tab-panel")},{order:800,render:()=>n.jsx(Sk,{panelID:a,viewID:o},"open-tab-variable")},{order:900,render:()=>n.jsx(Tk,{panelID:a,viewID:o},"open-tab-visualization")},{order:1e3,render:()=>n.jsx(kk,{panelID:a,viewID:o},"open-tab-interaction")},{order:1100,render:()=>n.jsx(s.Divider,{label:t("common.actions.actions"),labelPosition:"center"},"actions-divider")},{order:1200,render:()=>n.jsx(zk,{panelID:a,viewID:o},"duplicate")},{order:1300,render:()=>n.jsx(Dk,{panelID:a,viewID:o},"delete-panel")},...l].sort((d,u)=>d.order-u.order),[i,l])},Pk=k.observer(({view:e})=>{const{getEchartsOptions:t,panel:r}=re();return Vk(e).map(o=>o.render({getEchartsOptions:t,inEditMode:!0,panelID:r.id,viewID:e.id}))}),$k={border:"1px dashed transparent",transition:"border-color 300ms ease","&:hover":{borderColor:"#e9ecef"}};function Ak(e){return e.style.border.enabled?{}:$k}const Bc=k.observer(function({panel:t,view:r}){const a=Ak(t);return n.jsx(Ja,{panel:t,panelStyle:a,dropdownContent:n.jsx(Pk,{view:r})})});function Ek(e){return e.style.border.enabled?{}:{border:"1px dashed transparent"}}const Ra=k.observer(({panel:e,view:t})=>{const r=Ek(e);return n.jsx(Ja,{panel:e,panelStyle:r,dropdownContent:n.jsx(xk,{view:t})})}),Bk={modal:{display:"flex",flexDirection:"column",flexWrap:"nowrap"},body:{display:"flex",height:"calc(100vh - 88px)"}},qc=k.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:Bk,children:n.jsx(s.Group,{grow:!0,sx:{flexGrow:1,flexShrink:0},children:n.jsx(Ra,{view:t,panel:r})})})});function Lc(e,t,r){const{panels:a}=H(),o=e.id==="Main",[l,i]=h.useState(()=>o&&a.findByID(t)?t:null),c=h.useCallback(f=>{i(f),o&&r(f)},[o,r]),d=h.useCallback(()=>{i(null),o&&r("")},[o,r]),u=l?a.findByID(l):null;return{viewPanelInFullScreen:c,exitFullScreen:d,inFullScreen:!!u,fullScreenPanel:u}}function qk(e){const t=jt(),r=h.useMemo(()=>t.content.panels.findByID(e.panelId),[e.panelId]);return r?n.jsx(tk,{withAddon:!1,withPanelTitle:!1,withInteraction:!1,children:n.jsx(Ja,{panel:r,panelStyle:{}})}):null}const JI="",Lk=h.forwardRef(({title:e},t)=>n.jsx(s.Box,{ref:t,className:"react-grid-customDragHandle",title:e,children:n.jsx(s.ActionIcon,{variant:"transparent",color:"gray",children:n.jsx(S.IconMenu2,{size:16})})})),Ok=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})})),Nk=sn.WidthProvider(sn.Responsive),Gk=k.observer(({view:e,className:t="layout"})=>{const{t:r}=m.useTranslation(),o=G().layouts,l=o.items(e.panelIDs),i=o.gridLayouts(e.panelIDs),c=(p,f,v,_)=>{v.h<30&&(v.h=30,_.h=30),v.w<4&&(v.w=4,_.w=4)},d=(p,f,v)=>{console.log("🔴 onResizeStop",{layouts:p,oldItem:f,newItem:v}),o.updateCurrentLayoutItem(v)},u=(p,f,v)=>{console.log("🔴 onDragStop",{layouts:p,oldItem:f,newItem:v}),o.updateCurrentLayoutItems(p)};return n.jsx(Nk,{className:`dashboard-layout ${t}`,rowHeight:1,margin:[0,0],isBounded:!0,isDraggable:!0,isResizable:!0,cols:o.cols,layouts:i,draggableHandle:".react-grid-customDragHandle",resizeHandle:n.jsx(Ok,{}),onResize:c,breakpoints:o.breakpoints,onBreakpointChange:o.setCurrentBreakpoint,onResizeStop:d,onDragStop:u,width:o.currentLayoutPreviewWidth,children:l.map(p=>n.jsxs("div",{"data-grid":p.layoutProperies,className:"panel-grid-item",children:[n.jsx(Lk,{title:r("view.layout.drag_to_move")}),n.jsx(Bc,{view:e,panel:p.panel})]},p.id))})}),Fk=sn.WidthProvider(sn.Responsive),Qk=k.observer(({view:e,className:t="layout"})=>{const r=H(),a=r.layouts.items(e.panelIDs),o=r.layouts.gridLayouts(e.panelIDs);return n.jsx(Fk,{className:`dashboard-layout ${t}`,rowHeight:1,margin:[0,0],isDraggable:!1,isResizable:!1,cols:r.layouts.cols,layouts:o,breakpoints:r.layouts.breakpoints,onBreakpointChange:r.layouts.setCurrentBreakpoint,children:a.map(l=>l.panel.usingGhostViz?null:n.jsx("div",{"data-grid":l.layoutProperies,className:"panel-grid-item",children:n.jsx(Ra,{view:e,panel:l.panel})},l.id))})});function es(e){const t=h.useRef(null),{onScreenshot:r}=h.useContext(Ya);return{ref:t,downloadScreenshot:()=>{var l;const o=(l=t.current)==null?void 0:l.querySelector(".react-grid-layout");o&&e.downloadScreenshot(o,r)}}}const jk=k.observer(({downloadScreenshot:e})=>{const{t}=m.useTranslation(),[r,{setTrue:a,setFalse:o}]=O.useBoolean(!1),l=Qs(),i=H(),c=()=>{const d=JSON.stringify(i.contentJSON,null,2),u=`${l.name}__${i.name}`;Gt(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:o,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")})]})]})}),Oc=k.observer(({children:e,view:t,sx:r={}})=>{const{ref:a,downloadScreenshot:o}=es(t);return n.jsxs(n.Fragment,{children:[n.jsx(s.Box,{ref:a,pt:10,pb:10,sx:r,children:e}),n.jsx(jk,{downloadScreenshot:o})]})}),Nc=k.observer(({downloadScreenshot:e})=>n.jsx(s.ActionIcon,{className:"download-screenshot-button",color:"blue",variant:"subtle",onClick:e,children:n.jsx(S.IconCamera,{size:14})})),Wk=k.observer(({children:e,view:t})=>{const r=H(),a=t.config,o=r.views.visibleViewIDs.includes(t.id),l=()=>r.views.rmVisibleViewID(t.id),{ref:i,downloadScreenshot:c}=es(t);return n.jsx(s.Modal,{size:a.width,centered:!0,opened:o,onClose:l,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(Nc,{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})})}),Uk=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},Kk=k.observer(({view:e})=>{const t=H(),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:Uk(a),disabled:!a.view_id,children:a.name??a.id},a.id))}),r.tabsInOrder.map(a=>{const o=t.views.findByID(a.view_id);return o?n.jsx(s.Tabs.Panel,{value:a.id,children:n.jsx(qn,{view:o})},a.id):null})]})}),Yk=k.observer(({view:e,children:t})=>{switch(e.type){case B.Modal:return n.jsx(Wk,{view:e,children:t});case B.Tabs:return n.jsx(Kk,{view:e});case B.Division:default:return n.jsx(Oc,{view:e,children:t})}}),Xk=k.observer(({children:e,view:t})=>{const a=G().layouts,[o,l]=te.useResizeObserver();return h.useEffect(()=>{a.setCurrentLayoutWrapperWidth(l.width)},[l.width]),n.jsx(s.Box,{sx:{height:"100%"},ref:o,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(Oc,{view:t,sx:{paddingTop:"0px !important",".dashboard-sticky-area > form":{paddingBottom:"5px"},".dashboard-layout":{marginTop:0,marginBottom:0}},children:e})})})});function Gc(e){return e.replace(/(vw|vh)/,"%")}const Zk=k.observer(({children:e,view:t})=>{const r=t.config,{width:a,height:o}=h.useMemo(()=>({width:Gc(r.width),height:Gc(r.height)}),[r.width,r.height]),{ref:l,downloadScreenshot:i}=es(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:b.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(Nc,{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:o,maxHeight:o},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:l,children:e})})})}),Jk=({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},Hk=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},Rk=k.observer(({view:e})=>{const{t}=m.useTranslation(),r=De.useModals(),a=G(),o=h.useMemo(()=>a.views.options.filter(u=>u.type===B.Division),[e.id,a.views.options]),l=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:()=>{l.removeTab(u),d&&e.setTab(d)},confirmProps:{color:"red"},zIndex:320}),c=l.tabs.length===0,d=l.tabsInOrder.length===0?void 0:l.tabsInOrder[0].id;return n.jsxs(s.Tabs,{className:"preview-view-tabs",variant:l.variant,orientation:l.orientation,value:e.tab||d,onChange:e.setTab,styles:Jk(l),children:[n.jsxs(s.Tabs.List,{grow:l.grow,children:[l.tabsInOrder.map(u=>n.jsx(s.Tabs.Tab,{value:u.id,sx:Hk(u),children:u.name??u.id},u.id)),n.jsx(s.Tabs.Tab,{onClick:l.addTab,value:"add",className:"add-a-tab",children:n.jsx(S.IconPlus,{size:18,color:"#228be6"})})]}),l.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:o}),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:l.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(u.id),disabled:c,leftSection:n.jsx(S.IconTrash,{size:14}),children:t("view.component.tabs.tab.delete")})]})]}),f&&n.jsx(qn,{view:f})]},u.id)})]})}),eD=k.observer(({view:e,children:t})=>{switch(e.type){case B.Modal:return n.jsx(Zk,{view:e,children:t});case B.Tabs:return n.jsx(Rk,{view:e});case B.Division:default:return n.jsx(Xk,{view:e,children:t})}}),Fc=k.observer(function({view:t}){const a=G().layouts.divisionPreviewScale!==1;return n.jsx(Ha.Provider,{value:{viewPanelInFullScreen:b.noop,inFullScreen:!1},children:n.jsx(s.Box,{className:"dashboard-view","data-enable-scrollbar":!0,sx:{background:a?"transparent":"#efefef"},children:n.jsx(eD,{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(mc,{view:t})}),n.jsx(Gk,{view:t})]})})})})}),qn=k.observer(function({view:t}){const{fullScreenPanelID:r,setFullScreenPanelID:a}=Js(),{viewPanelInFullScreen:o,exitFullScreen:l,inFullScreen:i,fullScreenPanel:c}=Lc(t,r,a);return n.jsx(Ha.Provider,{value:{viewPanelInFullScreen:o,inFullScreen:i},children:n.jsxs(s.Box,{className:"dashboard-view","data-enable-scrollbar":!0,sx:{height:t.type===B.Modal?"0 !important":"100%"},children:[i&&n.jsx(qc,{view:t,panel:c,exitFullScreen:l}),n.jsx(Yk,{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(mc,{view:t})}),!i&&n.jsx(Qk,{view:t})]})})]})})});var Qc=(e=>(e.Use="use",e.Edit="edit",e))(Qc||{});const tD={[B.Division]:"Division",[B.Tabs]:"Tabs",[B.Modal]:"Modal"},jc={[B.Division]:"rgba(255, 0, 0, 0.2)",[B.Modal]:"rgba(0, 0, 0, 0.2)",[B.Tabs]:"rgba(255, 200, 100, 0.4)"},nD={[B.Division]:"#ff4000",[B.Modal]:"#000",[B.Tabs]:"#ffad18"},Wc=Pn.views(e=>({get usages(){return e.contentModel.findFilterUsage(e.id)}})).actions(e=>({}));function rD(e,t,r){g.addDisposer(e,g.addMiddleware(e,(a,o)=>{o(a,()=>{g.getType(a.context)===t&&a.type==="action"&&r(a.name,a.context)})}))}const Uc=g.types.compose("FiltersModel",Aa,g.types.model({current:g.types.optional(g.types.array(Wc),[]),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===P.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 b.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(){rD(e.current,Pn,(r,a)=>{if(r==="setType"){const o=Hi(a.config.default_value,a.config);e.setValueByKey(a.key,o),e.updatePreviewValues({...e.previewValues,[a.key]:o})}})}return{afterCreate(){t()}}}),Kc=qa.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)}})),Yc=g.types.compose("QueriesModel",La,g.types.model({current:g.types.optional(g.types.array(Kc),[])})).views(e=>({get options(){const t=e.current.map(r=>({value:r.id,label:r.name,_type:"query"}));return b.sortBy(t,r=>r.label.toLowerCase())},get optionsWithoutTransform(){const t=e.current.filter(r=>r.type!==W.Transform).map(r=>({value:r.id,label:r.name,_type:"query"}));return b.sortBy(t,r=>r.label.toLowerCase())},get sortedList(){return b.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(o=>{r.has(o.id)&&g.detach(o)});const a=[...e.current];b.remove(a,o=>r.has(o.id)),e.current=g.cast(a)},duplicateByID(t){const r=e.current.find(o=>o.id===t);if(!r){console.error(new Error(`[duplicate query] Can't find a query by id[${t}]`));return}const a=Te.v4();return e.current.push({...r.json,name:`${r.name} (${a})`,id:a}),a}})),Xc=Na.views(e=>({get sortedList(){return b.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 b.sortBy(t,r=>r.label.toLowerCase())},get usedFilterKeyMap(){const t=new Map;return e.current.forEach(r=>{const a=b.get(r,"value","");if(!a)return;const o=b.uniq(a.match(Et.filter)),l=new Set;o.forEach(i=>l.add(i)),t.set(r.key,l)}),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(o=>{r.has(o.key)&&g.detach(o)});const a=[...e.current];b.remove(a,o=>r.has(o.key)),e.current=g.cast(a)},replaceByIndex(t,r){e.current.splice(t,1,r)}})),aD=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}})),sD=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}})),oD=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
|
+
`)},get metricQueryPayloadValid(){return this.metricQueryPayload?this.metricQueryPayloadError.length===0:!1}})),qa=g.types.compose("QueryRenderModel",lc,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=b.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(s2({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=b.get(r,"message","unkown error");e.error=b.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:o}=e.json;let l=JSON.parse(e.httpConfigString);l=hn(e.datasource,l);const i=yield*g.toGenerator(o2({type:r,key:a,configString:JSON.stringify(l),name:e.name,additionals:e.additionalQueryInfo},e.controller.signal)),c=gn(e.datasource,i),d=zo(o,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=b.get(r,"message","unkown error");e.error=b.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:o}=e.json;let l={url:"/api/metric_management/query",method:"POST",data:e.metricQueryPayload};l=hn(e.datasource,l);const i=yield*g.toGenerator(l2({key:a,configString:JSON.stringify(l),name:e.name,additionals:e.additionalQueryInfo},e.controller.signal)),c=gn(e.datasource,i),d=zo(o,c,e.contentModel.dashboardStateValues);e.data=u2(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=b.get(r,"message","unkown error");e.error=b.get(r,"response.data.detail.message",a),e.state="error"}}}}),runTransformation(){e.state="loading";try{const t=e.depQueryModels.map(l=>({id:l.id,name:l.name,data:b.cloneDeep(l.data)})),r=e.contentModel.dashboardStateValues,a=e.pre_process,o=new Function(`return ${a}`)()(t,r,je);e.data=o,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,G.reaction(()=>{var r,a;if(e.isTransform){const o=e.config;return[e.inUse,e.id,e.key,e.reQueryKey,o.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}))}}));function u2(e){if("sortedColumns"in e&&"result"in e){const t=new Set(e.sortedColumns);return b.map(e.result,r=>{const a={};for(const o of t)a[o]=r[o];for(const o in r)t.has(o)||(a[o]=r[o]);return a})}return e}const La=g.types.model("QueriesRenderModel",{current:g.types.optional(g.types.array(qa),[])}).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 o=b.uniq(t.visibleViews.map(i=>i.renderViewIDs).flat());r.current.forEach(i=>{const c=b.get(i,"config.options_query_id");if(!c)return;o.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 l=new Set(a);return console.debug("QueryIDs:",l),l},isQueryInUse(t){return this.visibleQueryIDSet.has(t)},addTransformDepQueryIDs(t,r){this.findByIDSet(t).forEach(a=>{const o=a.config;!a.isTransform||o.dep_query_ids.length===0||o.dep_query_ids.forEach(l=>{r!=null&&r.has(l)||t.add(l)})})},get querisToForceReload(){const t=new Set,r=new Set,{views:a,filters:o}=this.contentModel,l=b.uniq(a.visibleViews.map(i=>i.renderViewIDs).flat());return o.current.forEach(i=>{const c=b.get(i,"config.options_query_id");if(!c)return;l.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}));Xi(e.dashboardName,t)},downloadDataByQueryIDs(t,r){if(r.length===1)return this.downloadDataByQueryID(t,r[0]);const a=new Set(r),o=e.current.filter(l=>a.has(l.id)).map(({name:l,data:i})=>({id:l,data:i}));Xi(t,o)},downloadDataByQueryID(t,r){const a=e.findByID(r);if(!a){console.log("[downloadDataByQueryID] query not found");return}const{data:o}=a,l=t??a.name;Yi(l,o)},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(o=>o.json)},version:ct}},downloadSchema(t){const r=JSON.stringify(this.getSchema(t),null,2);Gt("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(o=>o.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(o=>o.fetchData(!0)));console.log("🟡 Queries from filters reloaded",a)}else console.log("🟡 Found no query from visible panels, skipping")})}));function ic(e){return{current:e}}function cc({min:e,max:t}){const r=`${e}px`,a=Number.isFinite(t)?`${t}px`:"∞";return`[${r}, ${a})`}const Oa=g.types.model("LayoutsRenderModel",{list:g.types.array(bi),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 cc(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=cc(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(o=>r.has(o.panelID))},gridLayouts(t){const r=new Set(t),a={};return e.list.forEach(o=>{a[o.id]=o.list.filter(l=>r.has(l.panelID)).map(l=>l.layoutProperies)}),a},findItemByPanelID(t){return this.currentLayoutSet.findByPanelID(t)}})).actions(e=>({setCurrentBreakpoint(t){console.log("🔴 onBreakpointChange:",t),e.currentBreakpoint=t},afterCreate(){g.addDisposer(e,G.reaction(()=>e.currentBreakpoint,()=>{setTimeout(()=>{window.dispatchEvent(new Event("resize"))},32)},{fireImmediately:!1,delay:0}))}})),dc=yi.views(e=>({isADuplicatedKey(t){return!t||t===e.key?!1:!!g.getParent(e,2).findByKey(t)}})),Na=g.types.model("SQLSnippetsRenderModel",{current:g.types.optional(g.types.array(dc),[])}).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(o=>o.json)},version:ct}},downloadSchema(t){const r=JSON.stringify(this.getSchema(t),null,2);Gt("SQL Snippets",r)}}));function uc(e){return{current:e}}function Rt(e,t,r,a){return e.reduce((o,l)=>{try{o[l[t]]=yr(l[r],a)}catch(i){o[l[t]]=i.message}return o},{})}class pc{constructor(t){V(this,"origin");V(this,"copy");this.origin=t,this.copy=g.clone(t),G.makeAutoObservable(this,{},{autoBind:!0,deep:!1})}get changed(){return!b.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 hc=e=>new pc(e),p2=({description:e,isDescriptionEmpty:t})=>t?null:n.jsx(s.Tooltip,{color:"white",label:n.jsx($t,{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"})})}),h2=k.observer(({label:e,config:{default_value:t,description:r,isDescriptionEmpty:a,...o},value:l,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(p2,{description:r,isDescriptionEmpty:a})]}),checked:l||!1,onChange:c=>i(c.currentTarget.checked),...o,pt:".4em",styles:{input:{borderColor:"#e9ecef"}}})]})),g2=({value:e,onChange:t,onClose:r,max_days:a,allowSingleDateInRange:o})=>{const l=e.value,[i,c]=l,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(wt.DatePicker,{defaultDate:d,numberOfColumns:2,type:"range",value:l,onChange:f,onNextMonth:console.log,minDate:u,maxDate:p,allowSingleDateInRange:o})},f2=({begin:e,end:t})=>{const{t:r}=m.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 o=a===1?r("filter.widget.date_range.one_day"):r("filter.widget.date_range.x_days",{count:a});return n.jsx(s.Tooltip,{label:o,children:n.jsx(s.Badge,{size:"sm",variant:"light",children:a})})},b2=({max_days:e})=>{const{t}=m.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},y2=({onChange:e,onClose:t})=>{const{t:r,i18n:a}=m.useTranslation(),o=c=>()=>{const d=c();e(d),t()},l=h.useMemo(()=>mi(),[]),i=a.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(([c,d])=>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:r(`filter.widget.date_range.shortcut.${c}.label`)})}),d.map(({key:u,value:p,getRange:f})=>n.jsx(s.Table.Td,{children:n.jsx(s.Button,{size:"compact-xs",variant:"subtle",onClick:o(f),children:r(`filter.widget.date_range.shortcut.${c}.${i?"full.":""}${u}`)})},u))]},c))})})]})},gc=e=>({label:{display:"block",height:"21.7px"},input:{borderColor:e?"#228be6":"#e9ecef"}}),v2=({label:e,required:t,value:r,onChange:a,max_days:o,allowSingleDateInRange:l,inputFormat:i,disabled:c})=>{const{t:d}=m.useTranslation(),[u,{open:p,close:f}]=te.useDisclosure(!1),[v,_]=r.value,w=v?M(v).format(i):"",x=_?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:gc(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(f2,{begin:v,end:_})}),leftSection:n.jsx(S.IconMinus,{size:16}),placeholder:d("filter.widget.date_range.end_date"),readOnly:!0,disabled:!v||c,value:x,onFocus:p,styles:gc(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(b2,{max_days:o}),n.jsx(g2,{value:r,onChange:a,onClose:f,allowSingleDateInRange:l,max_days:o}),n.jsx(y2,{onChange:a,onClose:f})]})]})},fc={value:[null,null],shortcut:null},Ga=e=>{const t=In(e.shortcut);return t||(Array.isArray(e.value)?e:fc)},_2=e=>h.useMemo(()=>Ga(e),[e]),bc=k.observer(({label:e,config:t,value:r=fc,onChange:a,disabled:o})=>{const{inputFormat:l,required:i,max_days:c,allowSingleDateInRange:d}=t,u=_2(r);return n.jsx(v2,{label:e,value:u,onChange:a,inputFormat:l,allowSingleDateInRange:d,max_days:c,required:i,disabled:o})}),m2=ht.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"}}})),w2={root:{cursor:"pointer","&:hover":{backgroundColor:"var(--mantine-color-default-hover)"},"input, .mantine-Checkbox-labelWrapper":{cursor:"pointer",pointerEvents:"none"}}},x2=({disabled:e,radius:t,style:r,label:a,value:o,onChange:l,options:i,errorMessage:c,required:d})=>{const{t:u}=m.useTranslation(),{classes:p,cx:f}=m2({radius:t,name:"MultiSelectWidget"}),[v,_]=h.useState(!1),w=N=>{_(N)},x=v&&(o==null?void 0:o.length)>0,[T,D]=h.useState(""),z=h.useMemo(()=>{if(!T)return i;const N=T.toLowerCase(),oe=be=>{var dt;return((dt=be.description)==null?void 0:dt.toLowerCase().includes(N))||be.label.toLowerCase().includes(N)};return i.filter(oe)},[T,i]),I=h.useMemo(()=>new Set(i.map(N=>N.value)),[i]),E=h.useMemo(()=>new Set(o),[o]),A=h.useMemo(()=>E.size!==I.size?!1:Array.from(I).every(N=>E.has(N)),[E,I]),U=()=>{if(A){l([]);return}const N=Array.from(I);l(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:"*"})]}),x&&n.jsx(s.Tooltip,{label:u("filter.widget.common.x_selected",{count:o.length}),children:n.jsx(s.Badge,{variant:"light",children:o.length})})]}),n.jsx(Es,{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:o,onChange:l,onSelect:console.log,mode:"multiple",maxTagCount:0,notFoundContent:n.jsx(ma,{errorMessage:c}),maxTagTextLength:10,maxTagPlaceholder:N=>u("filter.widget.common.x_selected",{count:N.length}),searchValue:T,onSearch:D,filterOption:!1,dropdownRender:N=>n.jsxs(n.Fragment,{children:[I.size>0&&!T&&n.jsx(s.Group,{px:"xs",py:"xs",onClick:U,styles:w2,children:n.jsx(s.Checkbox,{size:"xs",checked:A,onChange:b.noop,label:u("common.actions.select_all")})}),n.jsx(s.Divider,{}),N]}),children:z.map(N=>n.jsxs(Es.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))})]})},C2=k.observer(({label:e,config:t,value:r,onChange:a})=>{const o=H(),l=!!t.options_query_id,{state:i,error:c}=o.getDataStuffByID(t.options_query_id),d=i==="loading",u=t.min_width?t.min_width:"200px",p=l?d:!1,f=h.useMemo(()=>t.initialSelection(r),[r,t.initialSelection]),v=_=>a(_,!1);return n.jsx(x2,{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})}),S2=({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})]})})})},T2=k.observer(({label:e,config:t,value:r,onChange:a})=>{const{t:o}=m.useTranslation(),l=H(),i=!!t.options_query_id,{state:c,error:d}=l.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:S2,searchable:!d,nothingFoundMessage:d||o("filter.widget.common.selector_option_empty"),clearable:t.clearable})});function k2({label:e,config:t,value:r,onChange:a}){return n.jsx(s.TextInput,{label:e,value:r||"",onChange:o=>a(o.currentTarget.value),...t,styles:{input:{borderColor:"#e9ecef"}}})}const D2=({value:e,handleRangeChange:t})=>{const r=e.value,[a,o]=r,l=h.useMemo(()=>a||new Date,[a]),i=h.useMemo(()=>{if(a&&!o)return a},[a,o]),c=h.useMemo(()=>M().add(365,"days").toDate(),[]);return n.jsx(wt.DatePicker,{defaultDate:l,numberOfColumns:2,type:"range",value:r,onChange:t,onNextMonth:console.log,minDate:i,maxDate:c,allowSingleDateInRange:!0})};function Fa(e,t){if(!e)return null;const r=M(e);switch(t){case"day":case"week":case"month":case"quarter":return r.startOf(t);case"bi-week":return r.startOf("week").subtract(1,"week");default:throw new Error(`[merico-date-range] unexpected date-range step: ${t}`)}}function Qa(e,t){if(!e)return null;const r=M(e);switch(t){case"day":case"week":case"month":case"quarter":return r.endOf(t);case"bi-week":return r.endOf("week");default:throw new Error(`[merico-date-range] unexpected date-range step: ${t}`)}}function z2(e,t){if(!e)return null;const r=Fa(e,t),a=Qa(e,t);return{start:r,end:a}}function M2(e,t,r,a){if(!t)return!1;const[o]=r,l=Fa(t,a),i=Qa(t,a),c=M(e).isBefore(i);return o?M(e).isAfter(o)&&c:M(e).isAfter(l)&&c}function I2(e,t,r){if(!t)return!1;const[a]=r;return a?e.isSame(a,"day"):e.isSame(t,"day")}function V2(e,t){return t?e.isSame(t,"day"):!1}function P2(e,t){const[r,a]=t;if(!r||!a)return{inRange:!1,firstInRange:!1,lastInRange:!1,selected:!1};const o=e.isSame(r,"day"),l=e.isSame(a,"day");return{inRange:e.isBetween(r,a,"day","[]"),firstInRange:o,lastInRange:l,selected:o||l}}const $2=(e,t,r)=>{const a=e.step,[o,l]=h.useState(null),[i,c]=h.useState(e.value),d=(_,w)=>{if(!_||!w)return;const[x,T]=i,D=_.toDate(),z=w.toDate();if(x===null){c([D,null]);return}const E=D.getTime()<x.getTime()?[D,T]:[x,z];c(E),t(E)};h.useEffect(()=>{c(e.value)},[e]),h.useEffect(()=>{c([null,null])},[r]);const u=h.useMemo(()=>r?null:i[0]?M(i[0]):null,[i,r]),p=h.useMemo(()=>r?null:i[0]?M(i[0]).add(365,"days"):null,[i,r]),f=h.useCallback(_=>{const w=M(_);return P2(w,e.value)},[r,e.value]),v=h.useCallback(_=>{const w=M(_),x=u&&p&&(w.isBefore(u)||w.isAfter(p)),T=!o&&i[0]?i[0]:o,D=z2(T,a);if(!D)return{onMouseEnter:()=>l(_),onMouseLeave:()=>l(null),inRange:!1,firstInRange:!1,lastInRange:!1,selected:!1,disabled:x};if(w.format("MM-DD"),x)return{onMouseEnter:b.noop,onMouseLeave:b.noop,inRange:!1,firstInRange:!1,lastInRange:!1,selected:!1,disabled:!0};const{start:z,end:I}=D,E=I2(w,z,i),A=V2(w,I),U=M2(_,T,i,a),N=U&&E,oe=U&&A,be=w.isBefore(u)||w.isAfter(p);return{onMouseEnter:()=>l(_),onMouseLeave:()=>l(null),inRange:U,firstInRange:N,lastInRange:oe,selected:E||A,onClick:()=>d(z,I),disabled:be}},[o,t,a,r,u,p,i]);return{getDayProps:r?f:v}},A2=({value:e,onChange:t,handleRangeChange:r})=>{const[a,o]=h.useState(!0),l=e.value,[i,c]=l,d=h.useMemo(()=>i||new Date,[i]),{getDayProps:u}=$2(e,r,a),p=()=>{o(!1)},f=()=>{o(!!i&&!!c)};return n.jsx(wt.Calendar,{defaultDate:d,numberOfColumns:2,withCellSpacing:!1,getDayProps:u,onMouseEnter:p,onMouseLeave:f,hideOutsideDates:!0})},E2=({value:e,handleRangeChange:t})=>{const r=e.value,[a,o]=r,l=h.useMemo(()=>a||new Date,[a]),i=h.useMemo(()=>{if(a&&!o)return a},[a,o]),c=h.useMemo(()=>M().add(365,"days").toDate(),[]);return n.jsx(wt.MonthPicker,{defaultDate:l,numberOfColumns:2,type:"range",value:r,onChange:t,minDate:i,maxDate:c,allowSingleDateInRange:!0})},En={calendar_header:"_calendar_header_xr0sl_1",months_list:"_months_list_xr0sl_5",months_list_row:"_months_list_row_xr0sl_12",months_list_control:"_months_list_control_xr0sl_25"},B2=({value:e,handleRangeChange:t})=>{const r=e.value,[a,o]=r,l=h.useMemo(()=>a||new Date,[a]),i=h.useMemo(()=>{if(a&&!o)return a},[a,o]),c=h.useMemo(()=>M(a).add(365,"days").subtract(1,"second").toDate(),[a]),d=h.useMemo(()=>o?M(o):null,[o]),u=h.useCallback(p=>d&&M(p).isSame(d,"quarter")?{lastInRange:!0,selected:!0}:{},[d]);return n.jsx(wt.MonthPicker,{classNames:{calendarHeader:En.calendar_header,monthsList:En.months_list,monthsListRow:En.months_list_row,monthsListControl:En.months_list_control},defaultDate:l,numberOfColumns:2,type:"range",value:r,onChange:t,minDate:i,maxDate:c,allowSingleDateInRange:!0,maxLevel:"year",monthsListFormat:"Q",getMonthControlProps:u})},q2=({value:e,onChange:t,onClose:r})=>{const a=l=>{const[i,c]=l,d=Fa(i,e.step),u=Qa(c,e.step);t([(d==null?void 0:d.toDate())??null,(u==null?void 0:u.toDate())??null]),i&&c&&r()},o=e.step;return o==="day"?n.jsx(D2,{value:e,handleRangeChange:a}):o==="week"||o==="bi-week"?n.jsx(A2,{value:e,onChange:t,handleRangeChange:a}):o==="month"?n.jsx(E2,{value:e,handleRangeChange:a}):o==="quarter"?n.jsx(B2,{value:e,handleRangeChange:a}):`错误的步长:${o}`},L2=({begin:e,end:t})=>{const{t:r}=m.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 o=a===1?r("filter.widget.date_range.one_day"):r("filter.widget.date_range.x_days",{count:a});return n.jsx(s.Tooltip,{label:o,children:n.jsx(s.Badge,{size:"sm",variant:"light",children:a})})},ja={begin:"_begin_1cder_1",end:"_end_1cder_27",step:"_step_1cder_52"},yc=({label:e,value:t,onChange:r,className:a})=>{const{t:o,i18n:l}=m.useTranslation(),i=h.useMemo(()=>[{label:o("filter.widget.date_range.step.day"),value:"day"},{label:o("filter.widget.date_range.step.week"),value:"week"},{label:o("filter.widget.date_range.step.bi_week"),value:"bi-week"},{label:o("filter.widget.date_range.step.month"),value:"month"},{label:o("filter.widget.date_range.step.quarter"),value:"quarter"}],[o]),c=d=>{d&&r(d)};return n.jsx(s.Select,{className:a,label:e,data:i,value:t,onChange:c})},O2=({onChange:e,step:t,onClose:r})=>{const{t:a,i18n:o}=m.useTranslation(),l=d=>()=>{const u=d(t);e(u),r()},i=h.useMemo(()=>Bi(t),[t]),c=o.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(i).map(([d,u])=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{w:80,children:n.jsx(s.Text,{size:"xs",c:"#555",fw:500,sx:{textAlignLast:"justify"},children:a(`filter.widget.date_range.shortcut.${d}.label`)})}),u.map(({key:p,value:f,getRange:v})=>n.jsx(s.Table.Td,{children:n.jsx(s.Button,{size:"compact-xs",variant:"subtle",onClick:l(v),children:a(`filter.widget.date_range.shortcut.${d}.${c?"full.":""}${p}`)})},p))]},d))})})]})},vc=e=>({label:{display:"block",height:"21.7px"},input:{borderColor:e?"#228be6":"#e9ecef"}}),N2=({label:e,required:t,value:r,onChange:a,inputFormat:o,disabled:l})=>{const{t:i}=m.useTranslation(),[c,{open:d,close:u}]=te.useDisclosure(!1),[p,f]=r.value,v=p?M(p).format(o):"",_=f?M(f).format(o):"",w=T=>{a({value:Jt(T[0],T[1],r.step),shortcut:null,step:r.step})},x=T=>{if(r.shortcut)return a(Ht(r.shortcut,T));a({value:Jt(r.value[0],r.value[1],T),shortcut:r.shortcut,step:T})};return n.jsxs(s.Popover,{opened:c,onClose:u,position:"bottom-start",shadow:"md",children:[n.jsxs(s.Group,{justify:"flex-start",align:"text-anchor",wrap:"nowrap",gap:0,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:i("filter.widget.date_range.start_date"),readOnly:!0,disabled:l,value:v,onFocus:d,styles:vc(c),className:ja.begin})}),n.jsx(s.TextInput,{label:n.jsx(s.Box,{children:" "}),leftSection:n.jsx(S.IconMinus,{size:16,onClick:d}),placeholder:i("filter.widget.date_range.end_date"),readOnly:!0,disabled:l,value:_,onFocus:d,styles:vc(c),className:ja.end}),n.jsx(yc,{className:ja.step,value:r.step,onChange:x,label:n.jsx(s.Group,{justify:"flex-end",children:n.jsx(L2,{begin:p,end:f})})})]}),n.jsxs(s.Popover.Dropdown,{p:"sm",children:[n.jsx(q2,{value:r,onChange:w,onClose:u}),n.jsx(O2,{onChange:a,step:r.step,onClose:u})]})]})},_c={value:[null,null],shortcut:null,step:"day"},G2=e=>{const t=Ht(e.shortcut,e.step);return t||(Array.isArray(e.value)?e:_c)},F2=e=>h.useMemo(()=>G2(e),[e]),Q2=k.observer(({label:e,config:t,value:r=_c,onChange:a,disabled:o})=>{const{inputFormat:l,required:i}=t,c=F2(r);return n.jsx(N2,{label:e,value:c,onChange:a,inputFormat:l,required:i,disabled:o})}),j2=k.observer(({filter:{type:e,config:t,key:r,...a},formFieldProps:o})=>{switch(e){case P.Select:return n.jsx(T2,{...a,...o,config:t});case P.MultiSelect:return n.jsx(C2,{...a,...o,config:t});case P.TreeSelect:return n.jsx(QT,{...a,...o,config:t});case P.TreeSingleSelect:return n.jsx(KT,{...a,...o,config:t});case P.TextInput:return n.jsx(k2,{...a,...o,config:t});case P.DateRange:return n.jsx(bc,{...a,...o,config:t});case P.MericoDateRange:return n.jsx(Q2,{...a,...o,config:t});case P.Checkbox:return n.jsx(h2,{...a,...o,config:t});default:return null}}),W2=k.observer(h.forwardRef(({filter:e,...t},r)=>n.jsx("div",{className:"filter-root",ref:r,children:n.jsx(ne,{children:n.jsx(j2,{filter:e,formFieldProps:t})})}))),U2=({disabled:e,onSubmit:t})=>{const{t:r}=m.useTranslation(),{renderSearchButton:a}=Ws();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 K2(e){const t=F();h.useEffect(()=>{var r,a;(a=(r=t.filters).updatePreviewValues)==null||a.call(r,e)},[e])}const Wa="N/A";function Y2(){const e=jt(),[t,r]=h.useState([]);return h.useEffect(()=>{const a=G.computed(()=>e.content.views.visibleViews.map(d=>{var u;return d.type===B.Tabs?(u=d.tabView)==null?void 0:u.view_id:d.id}).filter(Boolean).flatMap(d=>e.content.filters.visibleInView(d)).filter(Boolean).map(d=>X2(d)),{equals:G.comparer.structural}),o=G.autorun(()=>{r(a.get())});return()=>o()},[e]),t}function X2(e){switch(e.type){case P.Select:case P.MultiSelect:case P.TreeSelect:case P.TreeSingleSelect:return{label:e.label,value:Z2(e.config,e.value)};case P.TextInput:return{label:e.label,value:e.value};case P.DateRange:return{label:e.label,value:J2(e.config,e.value)};case P.MericoDateRange:return{label:e.label,value:H2(e.config,e.value)};case P.Checkbox:return{label:e.label,value:R2(e.value)};default:return{label:e.label,value:e.value}}}function Z2(e,t){const r=new Set;return Array.isArray(t)?t.forEach(a=>r.add(a)):r.add(t),r.size===0?Wa:e.options.filter(a=>r.has(a.value)).map(a=>a.label).join(", ")}function YI(e){return e}function J2(e,t){const a=Ga(t).value.filter(o=>!!o).map(o=>M(o).format(e.inputFormat));return a.length===0?Wa:a.join(" - ")}function H2(e,t){const a=Ga(t).value.filter(o=>!!o).map(o=>M(o).format(e.inputFormat));return a.length===0?Wa:a.join(" - ")}function R2(e){return e?"✔️":"❌"}const ek=({opened:e,toggle:t})=>{const{t:r}=m.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")})})},mc=k.observer(function({view:t}){const[r,{toggle:a}]=te.useDisclosure(!0),o=H(),{control:l,handleSubmit:i,reset:c}=y.useForm({defaultValues:o.filters.values,reValidateMode:"onBlur"}),d=y.useWatch({control:l});h.useEffect(()=>{c(o.filters.values)},[o.filters.values,c]),K2(d);const u=o.filters.visibleInView(t.id),p=h.useMemo(()=>u.every(x=>x.should_auto_submit),[u]),f=h.useMemo(()=>u.filter(x=>b.get(x,"config.required",!1)),[u]),v=h.useMemo(()=>f.length===0?!1:f.some(x=>!x.requiredAndPass(d[x.key])),[d,f]),_=(x,T)=>(D,z)=>{T(D),(x.should_auto_submit||z)&&o.filters.setValueByKey(x.key,D)},w=h.useCallback(x=>{const T=b.get(x,"force",!1);i(o.filters.setValues)(),T&&o.queries.forceReloadVisibleQueries()},[i,o.filters.setValues]);return u.length===0?null:n.jsxs("form",{children:[n.jsx(ek,{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(x=>n.jsx(y.Controller,{name:x.key,control:l,render:({field:T})=>n.jsx(W2,{filter:x,value:T.value,onChange:_(x,T.onChange)})},x.id))}),!p&&n.jsx(s.Group,{sx:{alignSelf:"flex-end"},children:n.jsx(U2,{disabled:v,onSubmit:w})})]})})]})}),wc={withInteraction:!0,withAddon:!0,withPanelTitle:!0},xc=h.createContext(wc);function tk({children:e,...t}){const r=b.defaults({},t,wc);return n.jsx(xc.Provider,{value:r,children:e})}function Ua(){return h.useContext(xc)}function nk(e){return e?["<p><br></p>","<p></p>"].includes(e):!0}const rk=k.observer(()=>{const e=H(),{panel:t}=re(),r=h.useMemo(()=>ft(t.description,t.json.variables,e.payloadForViz,t.data),[t.data,t.description,t.json.variables,e.payloadForViz]);return n.jsx($t,{value:r,styles:{root:{border:"none"},content:{padding:0}},sx:{".mantine-RichTextEditor-content .ProseMirror":{padding:"0 !important"}},dashboardStateValues:e.dashboardStateValues,variableAggValueMap:t.variableAggValueMap})}),Ka=k.observer(()=>{const{t:e}=m.useTranslation(),[t,r]=h.useState(!1),{panel:a}=re();return nk(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(rk,{})}),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(o=>!o),sx:{verticalAlign:"baseline",cursor:"pointer"},children:n.jsx(S.IconInfoCircle,{size:20})})})]})}),XI="",ak=k.observer(function(){const{panel:t}=re(),{name:r,title:a}=t;return a.show?n.jsx(s.Group,{"data-testid":"panel-title-bar",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}),Ya=h.createContext({onScreenshot:b.noop});function sk(e){const t=h.useRef(null),{onScreenshot:r}=h.useContext(Ya);return{ref:t,downloadPanelScreenshot:()=>{const o=t.current;if(!o)return;const l=o.offsetWidth*2,i=o.offsetHeight*2;Ps.toCanvas(t.current,{bgcolor:"white",width:l,height:i,style:{border:"none",borderRadius:0,transformOrigin:"0 0",transform:"scale(2)"}}).then(c=>(r(c),c)).then(c=>new Promise(d=>{c.toBlob(u=>{d(u)})})).then(c=>{window.saveAs(c,`${e.name?e.name:e.viz.type}.png`)})}}}var Cc=(e=>(e.migrated="migrated",e.nothingToMigrate="nothingToMigrate",e.checkFailed="checkFailed",e.migrationFailed="migrationFailed",e))(Cc||{}),Bn=(e=>(e.notStarted="notStarted",e.inProgress="inProgress",e.done="done",e))(Bn||{});class ok{constructor(t){V(this,"vizInstance");V(this,"operationManager");V(this,"triggerManager");V(this,"vizManager");V(this,"runningMigration");V(this,"panelModel");V(this,"status","notStarted");this.panelModel=t.getRequired(ee.instanceScope.panelModel),this.vizInstance=t.getRequired(ee.instanceScope.vizInstance),this.operationManager=t.getRequired(ee.instanceScope.operationManager),this.triggerManager=t.getRequired(ee.instanceScope.triggerManager),this.vizManager=t.getRequired(ee.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 lk{getTriggerSchemaList(){return[]}getTriggerList(){return Promise.resolve([])}removeTrigger(){return Promise.resolve()}createOrGetTrigger(){return Promise.resolve(Sc)}retrieveTrigger(){return Promise.resolve(Sc)}watchTriggerSnapshotList(){return()=>{}}needMigration(){return Promise.resolve(!1)}runMigration(){return Promise.resolve()}}class ik{constructor(){V(this,"id","");V(this,"schemaRef","");V(this,"triggerData",new on({}))}}const Sc=new ik;class ck{getOperationSchemaList(){return[]}getOperationList(){return Promise.resolve([])}removeOperation(){return Promise.resolve()}createOrGetOperation(){return Promise.resolve(Tc)}runOperation(){return Promise.resolve()}retrieveTrigger(){return Promise.resolve(Tc)}runMigration(){return Promise.resolve()}needMigration(){return Promise.resolve(!1)}}class dk{constructor(){V(this,"id","");V(this,"schemaRef","");V(this,"operationData",new on({}))}}const Tc=new dk,Fn=class Fn{constructor(){V(this,"triggerManager",new lk);V(this,"operationManager",new ck)}getInteractionList(){return Promise.resolve([])}addInteraction(){return Promise.resolve()}removeInteraction(){return Promise.resolve()}runInteraction(){return Promise.resolve()}};V(Fn,"instance",new Fn);let Xa=Fn;function kc(e,t=!0){const{panel:r}=re();return h.useCallback(a=>{const o=a.getRequired(ee.vizManager),l=o.resolveComponent(e.viz.type);return a.createScoped().provideFactory(ee.instanceScope.vizInstance,()=>o.getOrCreateInstance(e)).provideFactory(ee.instanceScope.interactionManager,i=>{const c=i.getRequired(ee.instanceScope.vizInstance);return t?new Bo(c,l,Cr):new Xa}).provideFactory(ee.instanceScope.operationManager,i=>i.getRequired(ee.instanceScope.interactionManager).operationManager).provideFactory(ee.instanceScope.triggerManager,i=>i.getRequired(ee.instanceScope.interactionManager).triggerManager).provideValue(ee.instanceScope.panelModel,r).provideFactory(ee.instanceScope.migrator,i=>new ok(i))},[e.viz.type,e.viz.conf,t])}function Dc(e){const[t,r]=h.useState(!1),a=Yt().getRequired(ee.instanceScope.migrator);return O.useAsyncEffect(async()=>{const o=a.status===Bn.notStarted;r(a.status===Bn.done),a.status===Bn.notStarted&&a.runMigration().then(l=>{l===Cc.migrated&&o&&(e==null||e())}).finally(()=>{r(!0)})},[a]),t}function zc(e,t){const r=Yt().getRequired(ee.instanceScope.vizInstance);return O.useAsyncEffect(async()=>{b.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 uk({setVizConf:e,...t}){const{panel:r}=t,a=zc(e,r),o=Dc(()=>{Ge.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]),o?n.jsx(qu,{...t}):n.jsx(s.Text,{size:"sm",children:"Checking update..."})}function pk(e){const{panel:t,setVizConf:r}=e;zc(r,t);const{inEditMode:a}=h.useContext(St);return Dc(()=>{a&&Ge.showNotification({title:`${t.name} - Updated`,message:"Your plugin configuration has been migrated to the latest version"})})?n.jsx(Bu,{...e}):n.jsx(s.Text,{size:"sm",children:"Checking update"})}const ZI="";function hk(e,t){const{vizManager:r}=h.useContext(lt),{panel:{viz:a,title:o,id:l,name:i,description:c,queryIDs:d,variables:u}}=re(),p={id:l,name:i,title:o,description:c,queryIDs:d,viz:a},{withInteraction:f}=Ua(),v=kc(p,f);try{return r.resolveComponent(a.type),n.jsxs(bn,{configure:v,children:[n.jsx(pk,{setVizConf:a.setConf,panel:p,measure:t,data:e,variables:u,vizManager:r}),n.jsx(Ic,{})]})}catch(_){return console.info(b.get(_,"message")),null}}const Mc=k.observer(function({data:t}){const{ref:r,width:a,height:o}=te.useElementSize(),l=hk(t,{w:a,h:o}),i=a>0&&o>0;return n.jsx("div",{className:"viz-root",ref:r,children:n.jsx(s.Box,{sx:{width:a,height:o,overflow:"hidden"},children:i&&n.jsx(ne,{children:l})})})});function gk(e){const{setEchartsOptions:t}=re();h.useEffect(()=>{const r=o=>{t(o)},a=e.messageChannels.getChannel("viz");return a.on("rendered",r),()=>{a.off("rendered",r)}},[e.messageChannels])}const Ic=()=>{const e=Yt(),t=e.getRequired(ee.instanceScope.vizInstance);gk(t);const{inEditMode:r}=h.useContext(St),a=e.getRequired(ee.panelAddonManager),{withAddon:o}=Ua(),l=Wu();return!l||!o?null:Du.createPortal(n.jsx(n.Fragment,{children:a.createPanelAddonNode({viz:t,isInEditMode:r})}),l,"addon")},Vc=k.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})]})),Za=k.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(Vc,{panel:e}),e.canRenderViz&&n.jsx(Mc,{data:e.data})]}));function fk(e){return!["richText","button","vizDashboardState"].includes(e)}const bk=k.observer(({children:e})=>n.jsx(n.Fragment,{children:n.jsxs(s.Menu,{withinPortal:!0,trigger:"hover",children:[n.jsx(s.Menu.Target,{children:n.jsx(s.ActionIcon,{variant:"subtle",color:"black",size:"md",pos:"absolute",top:16,right:16,style:{zIndex:410},children:n.jsx(S.IconDotsVertical,{size:14,style:{width:"70%",height:"70%"}})})}),n.jsx(s.Menu.Dropdown,{children:e})]})}));function yk(e){const t=h.useRef(null),r=h.useCallback(a=>{t.current=a},[]);return h.useEffect(()=>{t.current=null},[e]),{getEchartsOptions:()=>t.current,setEchartsOptions:r}}const vk={border:"1px solid #e9ecef"},Ja=k.observer(({panel:e,panelStyle:t,dropdownContent:r})=>{const{ref:a,downloadPanelScreenshot:o}=sk(e),{withAddon:l,withPanelTitle:i}=Ua(),c=l?Ns:h.Fragment,{getEchartsOptions:d,setEchartsOptions:u}=yk(e.viz.type),{inEditMode:p}=h.useContext(St),f=p||fk(e.viz.type);return n.jsx(Hn,{value:{panel:e,data:e.data,loading:e.dataLoading,errors:e.queryErrors,downloadPanelScreenshot:o,getEchartsOptions:d,setEchartsOptions:u},children:n.jsx(s.Box,{id:e.id,"data-testid":"panel-root",className:`panel-root ${e.title.show?"panel-root--show-title":""}`,ref:a,p:0,sx:{...vk,...t},children:n.jsxs(c,{children:[i&&n.jsxs(n.Fragment,{children:[n.jsx(s.Box,{className:"panel-description-popover-wrapper",children:n.jsx(Ka,{})}),f&&n.jsx(bk,{children:r}),n.jsx(ak,{})]}),n.jsx(Za,{panel:e})]})})})}),Pc=k.observer(()=>{const{t:e}=m.useTranslation(),{panel:t}=re();return n.jsx(s.Menu.Item,{onClick:t.downloadData,leftSection:n.jsx(S.IconDownload,{size:14}),children:e("common.actions.download_data")})}),$c=k.observer(()=>{const{t:e}=m.useTranslation(),{panel:t,downloadPanelScreenshot:r}=re();return n.jsx(s.Menu.Item,{onClick:r,leftSection:n.jsx(S.IconCamera,{size:14}),children:e("common.actions.download_screenshot")})}),_k=k.observer(()=>{const{t:e}=m.useTranslation(),{panel:t}=re();return n.jsx(s.Menu.Item,{onClick:t.downloadSchema,leftSection:n.jsx(S.IconCode,{size:14}),children:e("common.actions.download_schema")})}),mk={viewPanelInFullScreen:b.noop,inFullScreen:!1},Ha=h.createContext(mk),Ac=k.observer(({view:e})=>{const{t}=m.useTranslation(),{panel:r}=re(),a=r.id,{viewPanelInFullScreen:o,inFullScreen:l}=h.useContext(Ha),i=h.useCallback(()=>{o(a)},[a,o]);return!l&&e.type!==B.Modal?n.jsx(s.Menu.Item,{onClick:i,leftSection:n.jsx(S.IconArrowsMaximize,{size:14}),disabled:!0,children:t("common.actions.enter_fullscreen")}):null}),Ec=k.observer(()=>{const{t:e}=m.useTranslation(),{panel:t}=re();return n.jsx(s.Menu.Item,{onClick:t.refreshData,leftSection:n.jsx(S.IconRefresh,{size:14}),children:e("common.actions.refresh")})}),wk=e=>{const{items:t}=ar();return h.useMemo(()=>[{order:10,render:()=>n.jsx(Ec,{},"refresh")},{order:100,render:()=>n.jsx(Pc,{},"download-data")},{order:300,render:()=>n.jsx($c,{},"download-screenshot")},{order:400,render:()=>n.jsx(Ac,{view:e},"enter-full-screen")},...t].sort((a,o)=>a.order-o.order),[t])},xk=k.observer(({view:e})=>{const{getEchartsOptions:t,panel:r}=re();return wk(e).map(o=>o.render({getEchartsOptions:t,inEditMode:!1,panelID:r.id,viewID:e.id}))}),Ck=k.observer(({panelID:e,viewID:t})=>{const{t:r}=m.useTranslation(),a=j(),o=()=>{a.editor.open(["_VIEWS_",t,"_PANELS_",e,"_TABS_","Panel"])};return n.jsx(s.Menu.Item,{onClick:o,leftSection:n.jsx(S.IconAppWindow,{size:14}),children:r("panel.label")})}),Sk=k.observer(({panelID:e,viewID:t})=>{const{t:r}=m.useTranslation(),a=j(),o=()=>{a.editor.open(["_VIEWS_",t,"_PANELS_",e,"_TABS_","Variables"])};return n.jsx(s.Menu.Item,{onClick:o,leftSection:n.jsx(S.IconVariable,{size:14}),children:r("panel.variable.labels")})}),Tk=k.observer(({panelID:e,viewID:t})=>{const{t:r}=m.useTranslation(),a=j(),o=()=>{a.editor.open(["_VIEWS_",t,"_PANELS_",e,"_TABS_","Visualization"])};return n.jsx(s.Menu.Item,{onClick:o,leftSection:n.jsx(S.IconChartHistogram,{size:14}),children:r("visualization.label")})}),kk=k.observer(({panelID:e,viewID:t})=>{const{t:r}=m.useTranslation(),a=j(),o=()=>{a.editor.open(["_VIEWS_",t,"_PANELS_",e,"_TABS_","Interactions"])};return n.jsx(s.Menu.Item,{onClick:o,leftSection:n.jsx(S.IconRoute,{size:14}),children:r("interactions.label")})}),Dk=k.observer(({panelID:e,viewID:t})=>{const{t:r}=m.useTranslation(),a=De.useModals(),o=F(),l=()=>a.openConfirmModal({title:`${r("panel.delete")}?`,labels:{confirm:r("common.actions.confirm"),cancel:r("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>o.removePanelByID(e,t),confirmProps:{color:"red"},zIndex:320});return n.jsx(s.Menu.Item,{color:"red",onClick:l,leftSection:n.jsx(S.IconTrash,{size:14}),children:r("common.actions.delete")})}),zk=k.observer(({panelID:e,viewID:t})=>{const{t:r}=m.useTranslation(),a=F(),o=()=>{a.duplicatePanelByID(e,t)};return n.jsx(s.Menu.Item,{onClick:o,leftSection:n.jsx(S.IconCopy,{size:14}),children:r("common.actions.duplicate")})}),Mk=k.observer(({panelID:e,viewID:t})=>{const{t:r}=m.useTranslation(),a=j(),o=()=>{a.editor.open(["_VIEWS_",t,"_PANELS_",e,"_TABS_","Data"])};return n.jsx(s.Menu.Item,{onClick:o,leftSection:n.jsx(S.IconDatabase,{size:14}),children:r("data.label")})}),Ik=e=>{const{t}=m.useTranslation(),r=j(),{panel:a}=ae(),o=a.realQueryOptions,l=i=>{r.editor.open(["_QUERIES_",i])};return h.useMemo(()=>o.length===0?[]:[{order:500,render:()=>n.jsx(s.Divider,{label:t(o.length>1?"query.labels":"query.label"),labelPosition:"center"},"data-divider")},{order:501,render:()=>n.jsx(Mk,{panelID:a.id,viewID:e.id},"open-tab-data")},...o.map((i,c)=>({order:502+c,render:()=>n.jsx(s.Menu.Item,{onClick:()=>l(i.value),leftSection:n.jsx(S.IconDatabase,{size:14}),children:i.label},i.value)}))],[o])},Vk=e=>{const{t}=m.useTranslation(),{panel:r}=ae(),a=r.id,o=e.id,{items:l}=ar(),i=Ik(e);return h.useMemo(()=>[{order:10,render:()=>n.jsx(Ec,{},"refresh")},{order:100,render:()=>n.jsx(Pc,{},"download-data")},{order:200,render:()=>n.jsx(_k,{},"download-schema")},{order:300,render:()=>n.jsx($c,{},"download-screenshot")},{order:400,render:()=>n.jsx(Ac,{view:e},"enter-full-screen")},...i,{order:600,render:()=>n.jsx(s.Divider,{label:t("common.actions.edit"),labelPosition:"center"},"edit-divider")},{order:700,render:()=>n.jsx(Ck,{panelID:a,viewID:o},"open-tab-panel")},{order:800,render:()=>n.jsx(Sk,{panelID:a,viewID:o},"open-tab-variable")},{order:900,render:()=>n.jsx(Tk,{panelID:a,viewID:o},"open-tab-visualization")},{order:1e3,render:()=>n.jsx(kk,{panelID:a,viewID:o},"open-tab-interaction")},{order:1100,render:()=>n.jsx(s.Divider,{label:t("common.actions.actions"),labelPosition:"center"},"actions-divider")},{order:1200,render:()=>n.jsx(zk,{panelID:a,viewID:o},"duplicate")},{order:1300,render:()=>n.jsx(Dk,{panelID:a,viewID:o},"delete-panel")},...l].sort((d,u)=>d.order-u.order),[i,l])},Pk=k.observer(({view:e})=>{const{getEchartsOptions:t,panel:r}=re();return Vk(e).map(o=>o.render({getEchartsOptions:t,inEditMode:!0,panelID:r.id,viewID:e.id}))}),$k={border:"1px dashed transparent",transition:"border-color 300ms ease","&:hover":{borderColor:"#e9ecef"}};function Ak(e){return e.style.border.enabled?{}:$k}const Bc=k.observer(function({panel:t,view:r}){const a=Ak(t);return n.jsx(Ja,{panel:t,panelStyle:a,dropdownContent:n.jsx(Pk,{view:r})})});function Ek(e){return e.style.border.enabled?{}:{border:"1px dashed transparent"}}const Ra=k.observer(({panel:e,view:t})=>{const r=Ek(e);return n.jsx(Ja,{panel:e,panelStyle:r,dropdownContent:n.jsx(xk,{view:t})})}),Bk={modal:{display:"flex",flexDirection:"column",flexWrap:"nowrap"},body:{display:"flex",height:"calc(100vh - 88px)"}},qc=k.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:Bk,children:n.jsx(s.Group,{grow:!0,sx:{flexGrow:1,flexShrink:0},children:n.jsx(Ra,{view:t,panel:r})})})});function Lc(e,t,r){const{panels:a}=H(),o=e.id==="Main",[l,i]=h.useState(()=>o&&a.findByID(t)?t:null),c=h.useCallback(f=>{i(f),o&&r(f)},[o,r]),d=h.useCallback(()=>{i(null),o&&r("")},[o,r]),u=l?a.findByID(l):null;return{viewPanelInFullScreen:c,exitFullScreen:d,inFullScreen:!!u,fullScreenPanel:u}}function qk(e){const t=jt(),r=h.useMemo(()=>t.content.panels.findByID(e.panelId),[e.panelId]);return r?n.jsx(tk,{withAddon:!1,withPanelTitle:!1,withInteraction:!1,children:n.jsx(Ja,{panel:r,panelStyle:{}})}):null}const JI="",Lk=h.forwardRef(({title:e},t)=>n.jsx(s.Box,{ref:t,className:"react-grid-customDragHandle",title:e,children:n.jsx(s.ActionIcon,{variant:"transparent",color:"gray",children:n.jsx(S.IconMenu2,{size:16})})})),Ok=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})})),Nk=sn.WidthProvider(sn.Responsive),Gk=k.observer(({view:e,className:t="layout"})=>{const{t:r}=m.useTranslation(),o=F().layouts,l=o.items(e.panelIDs),i=o.gridLayouts(e.panelIDs),c=(p,f,v,_)=>{v.h<30&&(v.h=30,_.h=30),v.w<4&&(v.w=4,_.w=4)},d=(p,f,v)=>{console.log("🔴 onResizeStop",{layouts:p,oldItem:f,newItem:v}),o.updateCurrentLayoutItem(v)},u=(p,f,v)=>{console.log("🔴 onDragStop",{layouts:p,oldItem:f,newItem:v}),o.updateCurrentLayoutItems(p)};return n.jsx(Nk,{className:`dashboard-layout ${t}`,rowHeight:1,margin:[0,0],isBounded:!0,isDraggable:!0,isResizable:!0,cols:o.cols,layouts:i,draggableHandle:".react-grid-customDragHandle",resizeHandle:n.jsx(Ok,{}),onResize:c,breakpoints:o.breakpoints,onBreakpointChange:o.setCurrentBreakpoint,onResizeStop:d,onDragStop:u,width:o.currentLayoutPreviewWidth,children:l.map(p=>n.jsxs("div",{"data-grid":p.layoutProperies,className:"panel-grid-item",children:[n.jsx(Lk,{title:r("view.layout.drag_to_move")}),n.jsx(Bc,{view:e,panel:p.panel})]},p.id))})}),Fk=sn.WidthProvider(sn.Responsive),Qk=k.observer(({view:e,className:t="layout"})=>{const r=H(),a=r.layouts.items(e.panelIDs),o=r.layouts.gridLayouts(e.panelIDs);return n.jsx(Fk,{className:`dashboard-layout ${t}`,rowHeight:1,margin:[0,0],isDraggable:!1,isResizable:!1,cols:r.layouts.cols,layouts:o,breakpoints:r.layouts.breakpoints,onBreakpointChange:r.layouts.setCurrentBreakpoint,children:a.map(l=>l.panel.usingGhostViz?null:n.jsx("div",{"data-grid":l.layoutProperies,className:"panel-grid-item",children:n.jsx(Ra,{view:e,panel:l.panel})},l.id))})});function es(e){const t=h.useRef(null),{onScreenshot:r}=h.useContext(Ya);return{ref:t,downloadScreenshot:()=>{var l;const o=(l=t.current)==null?void 0:l.querySelector(".react-grid-layout");o&&e.downloadScreenshot(o,r)}}}const jk=k.observer(({downloadScreenshot:e})=>{const{t}=m.useTranslation(),[r,{setTrue:a,setFalse:o}]=O.useBoolean(!1),l=Qs(),i=H(),c=()=>{const d=JSON.stringify(i.contentJSON,null,2),u=`${l.name}__${i.name}`;Gt(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:o,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")})]})]})}),Oc=k.observer(({children:e,view:t,sx:r={}})=>{const{ref:a,downloadScreenshot:o}=es(t);return n.jsxs(n.Fragment,{children:[n.jsx(s.Box,{ref:a,pt:10,pb:10,sx:r,children:e}),n.jsx(jk,{downloadScreenshot:o})]})}),Nc=k.observer(({downloadScreenshot:e})=>n.jsx(s.ActionIcon,{className:"download-screenshot-button",color:"blue",variant:"subtle",onClick:e,children:n.jsx(S.IconCamera,{size:14})})),Wk=k.observer(({children:e,view:t})=>{const r=H(),a=t.config,o=r.views.visibleViewIDs.includes(t.id),l=()=>r.views.rmVisibleViewID(t.id),{ref:i,downloadScreenshot:c}=es(t);return n.jsx(s.Modal,{size:a.width,centered:!0,opened:o,onClose:l,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(Nc,{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})})}),Uk=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},Kk=k.observer(({view:e})=>{const t=H(),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:Uk(a),disabled:!a.view_id,children:a.name??a.id},a.id))}),r.tabsInOrder.map(a=>{const o=t.views.findByID(a.view_id);return o?n.jsx(s.Tabs.Panel,{value:a.id,children:n.jsx(qn,{view:o})},a.id):null})]})}),Yk=k.observer(({view:e,children:t})=>{switch(e.type){case B.Modal:return n.jsx(Wk,{view:e,children:t});case B.Tabs:return n.jsx(Kk,{view:e});case B.Division:default:return n.jsx(Oc,{view:e,children:t})}}),Xk=k.observer(({children:e,view:t})=>{const a=F().layouts,[o,l]=te.useResizeObserver();return h.useEffect(()=>{a.setCurrentLayoutWrapperWidth(l.width)},[l.width]),n.jsx(s.Box,{sx:{height:"100%"},ref:o,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(Oc,{view:t,sx:{paddingTop:"0px !important",".dashboard-sticky-area > form":{paddingBottom:"5px"},".dashboard-layout":{marginTop:0,marginBottom:0}},children:e})})})});function Gc(e){return e.replace(/(vw|vh)/,"%")}const Zk=k.observer(({children:e,view:t})=>{const r=t.config,{width:a,height:o}=h.useMemo(()=>({width:Gc(r.width),height:Gc(r.height)}),[r.width,r.height]),{ref:l,downloadScreenshot:i}=es(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:b.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(Nc,{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:o,maxHeight:o},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:l,children:e})})})}),Jk=({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},Hk=e=>e.color?{"&[data-active], &[data-active]:hover":{borderColor:e.color?e.color:"..."}}:{},Rk=k.observer(({view:e})=>{const{t}=m.useTranslation(),r=De.useModals(),a=F(),o=h.useMemo(()=>a.views.options.filter(u=>u.type===B.Division),[e.id,a.views.options]),l=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:()=>{l.removeTab(u),d&&e.setTab(d)},confirmProps:{color:"red"},zIndex:320}),c=l.tabs.length===0,d=l.tabsInOrder.length===0?void 0:l.tabsInOrder[0].id;return n.jsxs(s.Tabs,{className:"preview-view-tabs",variant:l.variant,orientation:l.orientation,value:e.tab||d,onChange:e.setTab,styles:Jk(l),children:[n.jsxs(s.Tabs.List,{grow:l.grow,children:[l.tabsInOrder.map(u=>n.jsx(s.Tabs.Tab,{value:u.id,sx:Hk(u),children:u.name??u.id},u.id)),n.jsx(s.Tabs.Tab,{onClick:l.addTab,value:"add",className:"add-a-tab",children:n.jsx(S.IconPlus,{size:18,color:"#228be6"})})]}),l.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:o}),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:l.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(u.id),disabled:c,leftSection:n.jsx(S.IconTrash,{size:14}),children:t("view.component.tabs.tab.delete")})]})]}),f&&n.jsx(qn,{view:f})]},u.id)})]})}),eD=k.observer(({view:e,children:t})=>{switch(e.type){case B.Modal:return n.jsx(Zk,{view:e,children:t});case B.Tabs:return n.jsx(Rk,{view:e});case B.Division:default:return n.jsx(Xk,{view:e,children:t})}}),Fc=k.observer(function({view:t}){const a=F().layouts.divisionPreviewScale!==1;return n.jsx(Ha.Provider,{value:{viewPanelInFullScreen:b.noop,inFullScreen:!1},children:n.jsx(s.Box,{className:"dashboard-view","data-enable-scrollbar":!0,sx:{background:a?"transparent":"#efefef"},children:n.jsx(eD,{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(mc,{view:t})}),n.jsx(Gk,{view:t})]})})})})}),qn=k.observer(function({view:t}){const{fullScreenPanelID:r,setFullScreenPanelID:a}=Js(),{viewPanelInFullScreen:o,exitFullScreen:l,inFullScreen:i,fullScreenPanel:c}=Lc(t,r,a);return n.jsx(Ha.Provider,{value:{viewPanelInFullScreen:o,inFullScreen:i},children:n.jsxs(s.Box,{className:"dashboard-view","data-enable-scrollbar":!0,sx:{height:t.type===B.Modal?"0 !important":"100%"},children:[i&&n.jsx(qc,{view:t,panel:c,exitFullScreen:l}),n.jsx(Yk,{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(mc,{view:t})}),!i&&n.jsx(Qk,{view:t})]})})]})})});var Qc=(e=>(e.Use="use",e.Edit="edit",e))(Qc||{});const tD={[B.Division]:"Division",[B.Tabs]:"Tabs",[B.Modal]:"Modal"},jc={[B.Division]:"rgba(255, 0, 0, 0.2)",[B.Modal]:"rgba(0, 0, 0, 0.2)",[B.Tabs]:"rgba(255, 200, 100, 0.4)"},nD={[B.Division]:"#ff4000",[B.Modal]:"#000",[B.Tabs]:"#ffad18"},Wc=Pn.views(e=>({get usages(){return e.contentModel.findFilterUsage(e.id)}})).actions(e=>({}));function rD(e,t,r){g.addDisposer(e,g.addMiddleware(e,(a,o)=>{o(a,()=>{g.getType(a.context)===t&&a.type==="action"&&r(a.name,a.context)})}))}const Uc=g.types.compose("FiltersModel",Aa,g.types.model({current:g.types.optional(g.types.array(Wc),[]),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===P.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 b.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(){rD(e.current,Pn,(r,a)=>{if(r==="setType"){const o=Hi(a.config.default_value,a.config);e.setValueByKey(a.key,o),e.updatePreviewValues({...e.previewValues,[a.key]:o})}})}return{afterCreate(){t()}}}),Kc=qa.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)}})),Yc=g.types.compose("QueriesModel",La,g.types.model({current:g.types.optional(g.types.array(Kc),[])})).views(e=>({get options(){const t=e.current.map(r=>({value:r.id,label:r.name,_type:"query"}));return b.sortBy(t,r=>r.label.toLowerCase())},get optionsWithoutTransform(){const t=e.current.filter(r=>r.type!==W.Transform).map(r=>({value:r.id,label:r.name,_type:"query"}));return b.sortBy(t,r=>r.label.toLowerCase())},get sortedList(){return b.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(o=>{r.has(o.id)&&g.detach(o)});const a=[...e.current];b.remove(a,o=>r.has(o.id)),e.current=g.cast(a)},duplicateByID(t){const r=e.current.find(o=>o.id===t);if(!r){console.error(new Error(`[duplicate query] Can't find a query by id[${t}]`));return}const a=Te.v4();return e.current.push({...r.json,name:`${r.name} (${a})`,id:a}),a}})),Xc=Na.views(e=>({get sortedList(){return b.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 b.sortBy(t,r=>r.label.toLowerCase())},get usedFilterKeyMap(){const t=new Map;return e.current.forEach(r=>{const a=b.get(r,"value","");if(!a)return;const o=b.uniq(a.match(Et.filter)),l=new Set;o.forEach(i=>l.add(i)),t.set(r.key,l)}),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(o=>{r.has(o.key)&&g.detach(o)});const a=[...e.current];b.remove(a,o=>r.has(o.key)),e.current=g.cast(a)},replaceByIndex(t,r){e.current.splice(t,1,r)}})),aD=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}})),sD=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}})),oD=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`
|
|
544
544
|
SELECT count(*) AS total
|
|
545
545
|
FROM ${r}.${t}
|
|
546
|
-
`}})).actions(e=>({setPage(t){e.page=t},resetPage(){e.page=1},setLimit(t){e.limit=t}})).actions(e=>({afterCreate(){g.addDisposer(e,F.reaction(()=>e.keywordString,e.resetPage,{fireImmediately:!1,delay:0})),g.addDisposer(e,F.reaction(()=>e.limit,e.resetPage,{fireImmediately:!1,delay:0}))}})),lD=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 Object.keys(e.data).length===0}})),iD=g.types.model({tables:g.types.optional(lD,{}),columns:g.types.optional(aD,{}),tableData:g.types.optional(oD,{}),indexes:g.types.optional(sD,{}),table_schema:g.types.optional(g.types.string,""),table_name:g.types.optional(g.types.string,"")}).views(e=>({get dataSource(){return g.getParent(e)},get key(){return this.dataSource.key},get type(){return this.dataSource.type},get sqlDataSourceType(){return this.type},get reloadConditionString(){const t=this.type,{table_name:r,table_schema:a}=e;return`${t};${r};${a}`}})).volatile(()=>({controllers:{tables:new AbortController,columns:new AbortController,indexes:new AbortController,tableData:new AbortController}})).actions(e=>({setKeywords(t,r){e.table_schema=t,e.table_name=r}})).actions(e=>({initKeywords(){if(e.tables.empty)return;const t=Object.keys(e.tables.data)[0],r=e.tables.data[t][0].table_name;e.setKeywords(t,r)}})).actions(e=>{const t=g.flow(function*(){var r;(r=e.controllers.tables)==null||r.abort(),e.controllers.tables=new AbortController,e.tables.state="loading";try{const a=yield*g.toGenerator($e.structure(e.controllers.tables.signal)({query_type:"TABLES",type:e.sqlDataSourceType,key:e.key,table_schema:"",table_name:""},{params:{query_type:"TABLES"}}));e.tables.data=b.groupBy(a,"table_schema"),e.tables.state="idle",e.tables.error=null,e.initKeywords()}catch(a){if(!ke.isCancel(a)){e.tables.data={};const o=b.get(a,"message","unkown error");e.tables.error=b.get(a,"response.data.detail.message",o),e.tables.state="error"}}});return{loadTables:t,loadTablesIfEmpty(){e.tables.empty&&t()},loadColumns:g.flow(function*(){var r;(r=e.controllers.columns)==null||r.abort(),e.controllers.columns=new AbortController,e.columns.state="loading";try{e.columns.data=yield*g.toGenerator($e.structure(e.controllers.columns.signal)({query_type:"COLUMNS",type:e.sqlDataSourceType,key:e.key,table_schema:e.table_schema,table_name:e.table_name},{params:{query_type:"COLUMNS"}})),e.columns.state="idle",e.columns.error=null}catch(a){if(ke.isCancel(a))e.columns.state="idle",e.columns.error=null;else{e.columns.data=[];const o=b.get(a,"message","unkown error");e.columns.error=b.get(a,"response.data.detail.message",o),e.columns.state="error"}}}),loadIndexes:g.flow(function*(){var r;(r=e.controllers.indexes)==null||r.abort(),e.controllers.indexes=new AbortController,e.indexes.state="loading";try{e.indexes.data=yield*g.toGenerator($e.structure(e.controllers.indexes.signal)({query_type:"INDEXES",type:e.sqlDataSourceType,key:e.key,table_schema:e.table_schema,table_name:e.table_name},{params:{query_type:"INDEXES"}})),e.indexes.state="idle",e.indexes.error=null}catch(a){if(ke.isCancel(a))e.indexes.state="idle",e.indexes.error=null;else{e.indexes.data=[];const o=b.get(a,"message","unkown error");e.indexes.error=b.get(a,"response.data.detail.message",o),e.indexes.state="error"}}}),loadTableData:g.flow(function*(){var a;(a=e.controllers.tableData)==null||a.abort(),e.controllers.tableData=new AbortController;const r=e.tableData;r.state="loading";try{r.data=yield*g.toGenerator($e.structure(e.controllers.tableData.signal)({query_type:"DATA",type:e.sqlDataSourceType,key:e.key,table_schema:e.table_schema,table_name:e.table_name,limit:r.limit,offset:r.offset},{params:{query_type:"DATA"}}));const[{total:o}]=yield*g.toGenerator($e.structure(e.controllers.tableData.signal)({query_type:"COUNT",type:e.sqlDataSourceType,key:e.key,table_schema:e.table_schema,table_name:e.table_name},{params:{query_type:"COUNT"}}));r.total=Number(o),r.state="idle",r.error=null}catch(o){if(ke.isCancel(o))r.state="idle",r.error=null;else{r.data=[];const l=b.get(o,"message","unkown error");r.error=b.get(o,"response.data.detail.message",l),r.state="error"}}})}}).actions(e=>({afterCreate(){g.addDisposer(e,F.reaction(()=>e.reloadConditionString,e.loadColumns,{fireImmediately:!1,delay:500}))}})).actions(e=>({afterCreate(){g.addDisposer(e,F.reaction(()=>e.reloadConditionString,e.loadIndexes,{fireImmediately:!1,delay:500})),g.addDisposer(e,F.reaction(()=>`${e.reloadConditionString};limit:${e.tableData.limit};offset:${e.tableData.offset}`,e.loadTableData,{fireImmediately:!1,delay:0}))}}));function cD(e,t){if(!t)throw new Error("Shouldnt run query without ID");if(e==="derived")return`/api/metric_management/derived_metric/${t}`;if(e==="combined")return`/api/metric_management/combined_metric/${t}`;throw new Error(`Unexpected metric type[${e}]`)}const dD=g.types.model({data:g.types.optional(g.types.frozen(),null),filters:g.types.optional(g.types.frozen(),[]),groupBys:g.types.optional(g.types.frozen(),[]),trendingDateCol:g.types.optional(g.types.frozen(),null),supportTrending:g.types.optional(g.types.boolean,!1),state:g.types.optional(g.types.enumeration(["idle","loading","error"]),"idle"),error:g.types.frozen()}).volatile(()=>({controller:new AbortController})).views(e=>({get loading(){return e.state==="loading"},get hasData(){return e.data!==null},get mmInfo(){return g.getParent(e)},get metricID(){return this.mmInfo.metricID},get metric(){return this.mmInfo.metric},get metricType(){var t;return(t=this.metric)==null?void 0:t.type},get filterColOptions(){return c2(e.filters)},get groupByColOptions(){return d2(e.groupBys)},get flatGroupByColOptions(){const t=this.groupByColOptions,r=[];return t.forEach(({group:a,items:o})=>{r.push(...o)}),r},getGroupByOptions(t){const r=new Set(t);return this.flatGroupByColOptions.filter(a=>r.has(a.value))}})).actions(e=>({load:g.flow(function*(){var t;if(e.mmInfo.type===W.MericoMetricSystem&&!(!e.metricID||!e.metricType)){(t=e.controller)==null||t.abort(),e.controller=new AbortController,e.state="loading";try{const r=cD(e.metricType,e.metricID),a=hn(e.mmInfo.dataSource,{url:r,method:"GET",data:{key:e.mmInfo.key}}),o=yield*g.toGenerator($e.mericoMetricInfo(e.controller.signal)({key:e.mmInfo.key,query:JSON.stringify(a),...e.mmInfo.additionalQueryInfo},e.controller.signal)),l=gn(e.mmInfo.dataSource,o),i=b.cloneDeep(l.data),{filters:c,groupBys:d,trendingDateCol:u,supportTrending:p}=i2(l.data);e.data=i,e.filters=c,e.groupBys=d,e.supportTrending=p,e.trendingDateCol=u,e.state="idle",e.error=null}catch(r){if(!ke.isCancel(r)){e.data=null;const a=b.get(r,"message","unkown error");e.error=b.get(r,"response.data.detail.message",a),e.state="error"}}}})})).actions(e=>({afterCreate(){g.addDisposer(e,F.reaction(()=>e.metricID+e.metricType,e.load,{fireImmediately:!0,delay:0}))}})),uD=g.types.model({keyword:g.types.optional(g.types.string,""),data:g.types.optional(g.types.frozen(),[]),state:g.types.optional(g.types.enumeration(["idle","loading","error"]),"idle"),error:g.types.frozen()}).volatile(()=>({controller:new AbortController})).views(e=>({get loading(){return e.state==="loading"},get empty(){return Object.keys(e.data).length===0},get mmInfo(){return g.getParent(e)}})).actions(e=>({setKeyword(t){e.keyword=t}})).actions(e=>({load:g.flow(function*(){var t;if(e.mmInfo.type===W.MericoMetricSystem){(t=e.controller)==null||t.abort(),e.controller=new AbortController,e.state="loading";try{const r=hn(e.mmInfo.dataSource,{url:"/api/metric_management/search",method:"POST",data:{key:e.mmInfo.key},params:{search:e.keyword}}),a=yield*g.toGenerator($e.mericoMetricInfo(e.controller.signal)({key:e.mmInfo.key,query:JSON.stringify(r),...e.mmInfo.additionalQueryInfo},e.controller.signal)),l=gn(e.mmInfo.dataSource,a).data;e.data=l,e.state="idle",e.error=null}catch(r){if(!ke.isCancel(r)){e.data=[];const a=b.get(r,"message","unkown error");e.error=b.get(r,"response.data.detail.message",a),e.state="error"}}}})})).actions(e=>({afterCreate(){g.addDisposer(e,F.reaction(()=>`${e.mmInfo.type}:${e.keyword}`,e.load,{fireImmediately:!0,delay:0}))}})),pD=g.types.model({metrics:g.types.optional(uD,{}),metricDetail:g.types.optional(dD,{}),keyword:g.types.optional(g.types.string,""),metricID:g.types.optional(g.types.string,"")}).views(e=>({get rootModel(){return g.getRoot(e)},get contentModel(){return this.rootModel.content},get additionalQueryInfo(){return this.contentModel.getAdditionalQueryInfo("")},get dataSource(){return g.getParent(e)},get key(){return this.dataSource.key},get type(){return this.dataSource.type},get metric(){return e.metricID?e.metrics.data.find(t=>t.id===e.metricID)??null:null}})).actions(e=>({selectMetric(t){e.metricID=t}})),hD=g.types.compose("DataSourceModel",Da,g.types.model({dbInfo:g.types.optional(iD,{}),mericoMetricInfo:g.types.optional(pD,{})})),gD=g.types.model("DataSourcesModel",{list:g.types.optional(g.types.array(hD),[])}).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)}}));function fD(e){return e.length===1&&e[0]==="_QUERY_VARS_"}function bD(e){return e.length===1&&e[0]==="_MOCK_CONTEXT_"}function yD(e){return e.length===1&&e[0]==="_FILTERS_"}function vD(e){return e.length===2&&e[0]==="_FILTERS_"}function _D(e){return e.length===1&&e[0]==="_SQL_SNIPPETS_"}function mD(e){return e.length===2&&e[0]==="_SQL_SNIPPETS_"}function wD(e){return e.length===2&&e[0]==="_QUERIES_"}function xD(e){return e.length===1&&e[0]==="_QUERIES_"}function CD(e){return e.length===2&&e[0]==="_VIEWS_"}function ts(e){return e.length===6&&e[0]==="_VIEWS_"&&e[2]==="_PANELS_"}function It(e){return{label:e,value:e,_type:"ACTION",_action_type:e,Icon:null,children:null}}function SD(e){switch(e._type){case"GROUP":case"ACTION":return null;case"query_variables":return["_QUERY_VARS_"];case"mock_context":return["_MOCK_CONTEXT_"];case"filter":return["_FILTERS_",e.value];case"sql_snippet":return["_SQL_SNIPPETS_",e.value];case"query":return["_QUERIES_",e.value];case"view":return["_VIEWS_",e.value];case"panel":return e.parentID?["_VIEWS_",e.parentID,"_PANELS_",e.value,"_TABS_","Data"]:(console.error("[getPathFromOption] parentID is required"),null)}}const TD=g.types.model("EditorModel",{path:g.types.optional(g.types.frozen(),[]),settings_open:g.types.optional(g.types.boolean,!1)}).views(e=>({get isPanelPath(){return ts(e.path)},get panelTab(){return this.isPanelPath?b.get(e.path,5,"Data"):null},get navOptions(){const{content:t}=g.getRoot(e),{filters:r,views:a,sqlSnippets:o,queries:l}=t;return[{label:"query_variable.labels",value:"_QUERY_VARS_",_type:"query_variables",Icon:S.IconVariable},{label:"mock_context.label",value:"_MOCK_CONTEXT_",Icon:S.IconCodeDots,_type:"mock_context"},{label:"filter.labels",value:"_FILTERS_",Icon:S.IconFilter,children:[It("_FILTERS_SETTINGS_"),...r.options,It("_Add_A_Filter_")],_type:"GROUP"},{label:"sql_snippet.labels",value:"_SQL_SNIPPETS_",Icon:S.IconCopy,children:[It("_SQL_SNIPPETS_SETTINGS_"),...o.options,It("_Add_A_SQL_SNIPPET_")],_type:"GROUP"},{label:"query.labels",value:"_QUERIES_",Icon:S.IconDatabase,children:[It("_QUERIES_SETTINGS_"),...l.options,It("_Add_A_QUERY_")],_type:"GROUP"},{label:"view.labels",value:"_VIEWS_",Icon:S.IconBoxMultiple,children:[...a.editorOptions,It("_Add_A_VIEW_")],_type:"GROUP"}]},isOptionActive(t,r){return t.length===0?!1:ts(t)?t[3]===r.value:t[t.length-1]===r.value},isOptionOpened(t){const{path:r}=e;return r.length===0||!t.children||t.children.length===0?!1:r.includes(t.value)}})).actions(e=>({setPath(t){e.path=t},setSettingsOpen(t){e.settings_open=t},openAndSetPath(t){this.setPath(t),e.settings_open||(e.settings_open=!0)}})).actions(e=>({setPanelTab(t){if(!e.isPanelPath||e.panelTab===t||!t)return;const r=b.clone(e.path);r[5]=t,e.setPath(r)},open(t){e.setPath(t),e.setSettingsOpen(!0)},close(){e.setSettingsOpen(!1)},navigate(t){const r=SD(t);r&&e.setPath(r)}})).views(e=>({get spotlightActionGroups(){const{content:t}=g.getRoot(e),{filters:r,views:a,sqlSnippets:o,queries:l}=t,i={group:"spotlight.main_group",actions:[{id:"query_variable.labels",title:"query_variable.labels",onClick:()=>e.openAndSetPath(["_QUERY_VARS_"]),iconKey:"query_variables"},{id:"mock_context.label",title:"mock_context.label",onClick:()=>e.openAndSetPath(["_MOCK_CONTEXT_"]),iconKey:"mock_context"},{id:"filter.labels",title:"filter.labels",onClick:()=>e.openAndSetPath(["_FILTERS_"]),iconKey:"filter"},{id:"sql_snippet.labels",title:"sql_snippet.labels",onClick:()=>e.openAndSetPath(["_SQL_SNIPPETS_"]),iconKey:"sql_snippet"},{id:"query.labels",title:"query.labels",onClick:()=>e.openAndSetPath(["_QUERIES_"]),iconKey:"query"}]},c={group:"filter.labels",actions:[]};r.options.forEach(f=>{c.actions.push({id:`_FILTERS_.${f.value}`,title:f.label,onClick:()=>e.openAndSetPath(["_FILTERS_",f.value]),iconKey:"filter"})});const d={group:"sql_snippet.labels",actions:[]};o.options.forEach(f=>{d.actions.push({id:`_SQL_SNIPPETS_.${f.value}`,title:f.label,onClick:()=>e.openAndSetPath(["_SQL_SNIPPETS_",f.value]),iconKey:"sql_snippet"})});const u={group:"query.labels",actions:[]};l.options.forEach(f=>{u.actions.push({id:`_QUERIES_.${f.value}`,title:f.label,onClick:()=>e.openAndSetPath(["_QUERIES_",f.value]),iconKey:"query"})});const p=[i,c,d,u];return a.editorOptions.forEach(f=>{const v={group:f.label,actions:[]};v.actions.push({id:`_VIEWS_.${f.value}`,title:f.label,onClick:()=>e.openAndSetPath(["_VIEWS_",f.value]),iconKey:"view",group:f.label}),f.children.forEach(_=>{_._type!=="ACTION"&&v.actions.push({id:`_VIEWS_._PANELS_.${_.value}`,title:_.label,viz:_.viz,onClick:()=>e.openAndSetPath(["_VIEWS_",f.value,"_PANELS_",_.value,"_TABS_","Panel"]),iconKey:"panel",group:f.label})}),p.push(v)}),p}})),kD=g.types.compose("LayoutsModel",Oa,g.types.model({currentLayoutWrapperWidth:g.types.optional(g.types.number,0)})).views(e=>({get divisionPreviewScale(){const t=e.currentLayoutPreviewWidth,r=e.currentLayoutWrapperWidth;return!t||!r||t<=r?1:r/t}})).actions(e=>({addALayoutItem(t){e.list.forEach(r=>{r.addNewLayout(t)})},duplicateLayoutItemsByPanelID(t,r){e.list.forEach(a=>{const o=a.findByPanelID(t);if(!o){console.error(`Can't find a layout item by panelID[${t}] in layoutSet[${a.name}]`);return}a.list.push({...o,id:Te.v4(),panelID:r,y:1/0})})},removeByPanelID(t){e.list.forEach(r=>{r.removeByPanelID(t)})},removeByPanelIDs(t){e.list.forEach(r=>{r.removeByPanelIDs(t)})},setCurrentLayoutWrapperWidth(t){e.currentLayoutWrapperWidth=t},addALayoutSet(t,r,a){const o=e.basisLayoutSet,l={id:t,name:r,breakpoint:a,list:o.json.list.map(i=>({...i,id:Te.v4()}))};e.list.push(l)},updateLayoutSetsInfo(t){const r=b.keyBy(e.list,"id");t.forEach(l=>{const i=r[l.id];if(i){i.setName(l.name),i.setBreakpoint(l.breakpoint),delete r[l.id];return}this.addALayoutSet(l.id,l.name,l.breakpoint)});const a=new Set(Object.keys(r)),o=a.size>0;a.forEach(l=>{const i=e.list.findIndex(c=>c.id===l);e.list.splice(i,1)}),o&&e.setCurrentBreakpoint("basis")},updateCurrentLayoutItem(t){e.currentLayoutSet.updateLayoutItem(t)},updateCurrentLayoutItems(t){t.forEach(r=>{e.currentLayoutSet.updateLayoutItem(r)})},append(t){e.list.push(t)},appendMultiple(t){t.length!==0&&e.list.push(...t)},remove(t){e.list.splice(t,1)},removeByID(t){const r=e.list.findIndex(a=>a.id===t);r!==-1&&e.list.splice(r,1)},removeByIDs(t){t.forEach(r=>{this.removeByID(r)})}})),Zc=Pa.views(e=>({get realQueryOptions(){return e.queryIDs.length===0?[]:e.queries.map(t=>({label:t.name,value:t.id,disabled:!1}))},queryOptions(t,r){const a=[...this.realQueryOptions];return t&&!a.find(o=>o.value===t)&&a.unshift({label:t,value:t,disabled:!0}),r&&a.unshift({label:"unset",value:"",disabled:!1}),a},get realVariableOptions(){const t=e.variableValueMap;return Object.entries(e.variableAggValueMap).map(([r,a])=>({label:r,value:r,formattedValue:t[r],aggValue:a,disabled:!1}))},variableOptions(t,r){const a=[...this.realVariableOptions];return t&&!a.find(o=>o.value===t)&&a.unshift({label:t,value:t,formattedValue:"",aggValue:"",disabled:!0}),r&&a.unshift({label:"unset",value:"",formattedValue:"",aggValue:"",disabled:!1}),a},explainDataKey(t){const{queryID:r,columnKey:a}=$(t),o=e.queries.find(l=>l.id===r);return o?{queryID:r,queryName:o.name,columnKey:a}:{queryID:r,queryName:null,columnKey:a}}})).actions(e=>({removeSelf(){g.getParent(e,2).removeByID(e.id)}})).actions(e=>({moveToView(t,r){g.getRoot(e).content.views.findByID(t).removePanelID(e.id),g.getRoot(e).content.views.findByID(r).appendPanelID(e.id),g.getRoot(e).editor.setPath(["_VIEWS_",r,"_PANELS_",e.id])}})),Jc=g.types.compose("PanelsModel",$a,g.types.model({list:g.types.optional(g.types.array(Zc),[])})).views(e=>({get contentModel(){return g.getRoot(e).content},get options(){return e.list.map(t=>({label:t.name,value:t.id,viz_type:t.viz.type}))},editorOptions(t,r){const a=e.panelsByIDs(r);a.length!==r.length&&console.warn(`Unfulfilled panels for View[${t}]`);const o=a.map(i=>({label:i.name,value:i.id,_type:"panel",parentID:t,viz:Jl[i.viz.type]})),l="_Add_A_PANEL_";return o.push({label:l,value:l,_type:"ACTION",_action_type:l,parentID:t,Icon:null,children:null}),o}})).actions(e=>({replace(t){e.list=g.castToSnapshot(t)},append(t){e.list.push(t)},appendMultiple(t){t.length!==0&&e.list.push(...t)},remove(t){e.list.splice(t,1)},removeByID(t){const r=e.list.findIndex(a=>a.id===t);r!==-1&&e.list.splice(r,1)},removeByIDs(t){t.forEach(r=>{this.removeByID(r)})},duplicateByID(t){const r=e.list.find(o=>o.id===t);if(!r){console.error(new Error(`[duplicate panel] Can't find a panel by id[${t}]`));return}const a=new Date().getTime().toString();return e.list.push({...r.json,id:a,title:{...r.json.title}}),e.contentModel.layouts.duplicateLayoutItemsByPanelID(r.id,a),a},replaceByIndex(t,r){e.list.splice(t,1,r)}})),DD=Ia.actions(e=>({getSchema(){const t=e.json,r=[],a=[];e.panels.forEach(i=>{const c=i.getSchema();r.push(c.panel),c.queries.length>0&&a.push(...c.queries)});const o=e.contentModel.layouts.jsonByPanelIDSet(new Set(e.panelIDs));return{views:[t],panels:r,definition:{queries:b.uniqBy(a,i=>i.id)},layouts:o,version:ct}},downloadSchema(){if(e.type===B.Tabs){console.error(new Error("Please choose a tab first"));return}const t=JSON.stringify(this.getSchema(),null,2),r=e.name;Gt(r,t)}})),Hc=g.types.compose("ViewsModel",Va,g.types.model({current:g.types.optional(g.types.array(DD),[]),idOfVIE:g.types.string})).views(e=>({get isVIETheFirstView(){return e.current.length===0||!e.idOfVIE?!1:e.current[0].id===e.idOfVIE},get VIE(){return e.current.find(({id:t})=>t===e.idOfVIE)},get options(){return e.current.map(t=>({label:t.name,value:t.id,type:t.type}))},get tabViewOptions(){return this.options.filter(t=>t.type===B.Tabs)},tabOptions(t){const r=e.current.find(a=>a.id===t&&a.type===B.Tabs&&a.tabs.length>0);return r?r.tabs.map(a=>({label:a.name,value:a.id})):[]},get editorOptions(){const t=g.getRoot(e).content.panels;return e.current.map(r=>({label:r.name,value:r.id,_type:"view",children:t.editorOptions(r.id,r.panelIDs)}))},get contentModel(){return g.getRoot(e).content}})).actions(e=>({setIDOfVIE(t){e.idOfVIE=t,e.visibleViewIDs.length=0,e.visibleViewIDs.push(t)},resetIDOfVIE(){this.setIDOfVIE(e.current[0].id)},replace(t){e.current.replace(t)},addANewView(t,r,a,o){e.current.push({id:t,name:r,type:a,config:o,panelIDs:[]})},append(t){e.current.push(t)},appendMultiple(t){t.length!==0&&e.current.push(...t)},remove(t){e.current.splice(t,1)},removeByID(t){const r=e.current.findIndex(i=>i.id===t);if(r===-1)return;const a=e.current[r],o=e.contentModel.panels,l=e.contentModel.layouts;o.removeByIDs(a.panelIDs),l.removeByPanelIDs(a.panelIDs),e.current.splice(r,1),this.resetIDOfVIE()},replaceByIndex(t,r){e.current.splice(t,1,r)},addARandomNewView(){const t=new Date().getTime().toString();this.addANewView(t,B.Division,B.Division,{_name:B.Division}),this.setIDOfVIE(t)},removeVIE(){e.current.length!==1&&(this.removeByID(e.idOfVIE),this.resetIDOfVIE())}}));function ns(e){const t=e.length>0?[e[0].id]:[],r=e.length>0?e[0].id:"";return{current:e.map(o=>{const{_name:l=o.type}=o.config;return{...o,config:{...o.config,_name:l},panelIDs:o.panelIDs}}),visibleViewIDs:t,idOfVIE:r}}const zD=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:Uc,queries:Yc,sqlSnippets:Xc,views:Hc,panels:Jc,layouts:kD,mock_context:ia,origin:g.types.maybe(g.types.frozen())}).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 filtersChanged(){const t="filters.current";return!b.isEqual(g.getSnapshot(b.get(e,t)),b.get(e.origin,t))},get queriesChanged(){const t="queries.current",r=g.getSnapshot(b.get(e,t)).map(o=>b.pick(o,["id","name","key","type","run_by","pre_process","post_process","config"])),a=b.get(e.origin,t);return!b.isEqual(r,a)},get sqlSnippetsChanged(){const t="sqlSnippets.current";return!b.isEqual(g.getSnapshot(b.get(e,t)),b.get(e.origin,t))},get viewsChanged(){const t="views.current";return!b.isEqual(e.views.json,b.get(e.origin,t))},get panelsChanged(){const t="panels.list";return!b.isEqual(g.getSnapshot(b.get(e,t)),b.get(e.origin,t))},get layoutsChanged(){const t="layouts.list";return!b.isEqual(g.getSnapshot(b.get(e,t)),b.get(e.origin,t))},get mockContextChanged(){const t="mock_context.current";return!b.isEqual(b.get(e,t),b.get(e.origin,t))},get context(){const t=g.getParent(e).context.current;return{...e.mock_context.current,...t}},get payloadForSQL(){const t=g.getParent(e).globalSQLSnippets,r={context:this.context,filters:e.filters.valuesForPayload};return{...r,sql_snippets:Rt(e.sqlSnippets.current,"key","value",r),global_sql_snippets:Rt(t.list,"id","content",r)}},get payloadForViz(){return{context:this.context,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(([o,l])=>{a.context[o]={key:o,type:"context",value:l}}),a},get dashboardStateValues(){return br(this.payloadForSQL)},get dashboardStateVariableOptions(){if(!g.isAlive(e))return{optionGroups:[],validValues:new Set};const t=new Set,{context:r}=this.payloadForSQL,a={group:"context.label",items:Object.keys(r).map(i=>{const c=`context.${i}`;return t.add(c),{label:i,value:c,description:void 0,type:"context"}})},o={group:"filter.labels",items:e.filters.keyLabelOptions.map(i=>{const c=`filters.${i.value}`;return t.add(c),{label:i.label,value:c,description:i.value,type:"filter",widget:i.widget}})};return{optionGroups:[a,o],validValues:t}},getAdditionalQueryInfo(t){return{content_id:e.id,query_id:t,params:this.dashboardStateValues}},get changed(){return this.filtersChanged||this.queriesChanged||this.sqlSnippetsChanged||this.viewsChanged||this.panelsChanged||this.layoutsChanged||this.mockContextChanged},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}:{data:[],len:0,state:"idle",error:void 0}}})).views(e=>({get filtersUsage(){const t=[],r=e.views.idMap;e.filters.current.forEach(o=>{o.visibleInViewsIDs.forEach(l=>{var i;t.push({filterID:o.id,type:"view",type_label:"view.label",id:l,label:((i=r.get(l))==null?void 0:i.name)??l})})});const a=e.filters.keyIDMap;return e.queries.current.forEach(o=>{o.usedFilterKeySet.forEach(l=>{t.push({filterID:a[l]??l,type:"query",type_label:"query.label",id:o.id,label:o.name})})}),e.sqlSnippets.usedFilterKeyMap.forEach((o,l)=>{o.forEach(i=>{t.push({filterID:a[i]??i,type:"sql_snippet",type_label:"sql_snippet.label",id:l,label:l})})}),b.groupBy(t,"filterID")},findFilterUsage(t){return this.filtersUsage[t]??[]},get queriesUsage(){const t=e.panels.idMap,r=[];e.views.current.forEach(o=>{o.panelIDs.forEach(l=>{const i=t.get(l);if(!i)return;const c="panel",d=i.name,u=[{id:o.id,label:o.name}];i.queryIDs.forEach(p=>{r.push({id:l,queryID:p,type:c,type_label:"panel.label",label:d,views:u})})})});const a=e.views.idMap;return e.filters.current.filter(o=>!!b.get(o,"config.options_query_id")).forEach(o=>{r.push({type:"filter",type_label:"filter.label",id:o.id,queryID:b.get(o,"config.options_query_id"),label:o.label,views:o.visibleInViewsIDs.map(l=>{var i;return{id:l,label:((i=a.get(l))==null?void 0:i.name)??l}})})}),e.queries.current.forEach(o=>{if(!o.isTransform)return;o.config.dep_query_ids.forEach(i=>{r.push({type:"transform-query",type_label:"query.transform.full_label",id:o.id,queryID:i,label:o.name,views:[]})})}),b.groupBy(r,"queryID")},get hasUnusedQueries(){return e.queries.current.length>Object.keys(this.queriesUsage).length},findQueryUsage(t){return this.queriesUsage[t]??[]},get sqlSnippetsUsage(){const t=[];return e.queries.current.forEach(r=>{if(!r.typedAsSQL)return;const a=r.config;b.uniq(a.sql.match(Et.sqlSnippet)).forEach(l=>{t.push({queryID:r.id,sqlSnippetKey:l,queryName:r.name})})}),b.groupBy(t,"sqlSnippetKey")},get hasUnusedSQLSnippets(){return e.sqlSnippets.current.length>Object.keys(this.sqlSnippetsUsage).length},findSQLSnippetUsage(t){return this.sqlSnippetsUsage[t]??[]}})).actions(e=>({removeUnusedQueries(){const t=new Set(Object.keys(e.queriesUsage)),r=e.queries.current.filter(a=>!t.has(a.id)).map(a=>a.id);e.queries.removeQueries(r)},removeUnusedSQLSnippets(){const t=new Set(Object.keys(e.sqlSnippetsUsage)),r=e.sqlSnippets.current.filter(a=>!t.has(a.key)).map(a=>a.key);e.sqlSnippets.removeByKeys(r)},duplicatePanelByID(t,r){var o;const a=e.panels.duplicateByID(t);a&&((o=e.views.findByID(r))==null||o.appendPanelID(a))},removePanelByID(t,r){var a;e.panels.removeByID(t),e.layouts.removeByPanelID(t),(a=e.views.findByID(r))==null||a.removePanelID(t)},addANewPanel(t){var a;const r=Te.v4();e.panels.append(Zi(r)),(a=e.views.findByID(t))==null||a.appendPanelID(r),e.layouts.addALayoutItem(r)},applyJSONSchema(t){var f;const{views:r,panels:a,filters:o,definition:l={},layouts:i}=t,{queries:c,sqlSnippets:d,mock_context:u}=l,p=new Map;if(Array.isArray(a)){const v=a.map(_=>{const w=Te.v4();return p.set(_.id,w),{..._,id:w}});if(e.panels.appendMultiple(v),!Array.isArray(r)||r.length===0){const _=v.map(w=>w.id);(f=e.views.VIE)==null||f.appendPanelIDs(_)}}if(Array.isArray(r)){const v=r.map(_=>{const w=_.panelIDs.map(x=>p.get(x)??x);return{..._,id:Te.v4(),panelIDs:w}});e.views.appendMultiple(v)}if(Array.isArray(i)){const v=(x,T)=>e.layouts.breakpointNameRecord[x]===T;let _=[];const w=i.filter(x=>v(x.name,x.breakpoint));w.forEach(x=>{x.id==="basis"&&(_=x.list),x.list.forEach(T=>{const D=p.get(T.panelID);T.id=Te.v4(),T.panelID=D})}),e.layouts.list.forEach(x=>{const T=w.find(D=>D.name===x.name&&D.breakpoint===x.breakpoint);if(!T){_.forEach(D=>{x.addLayout(D)});return}T.list.forEach(D=>{x.addLayout(D)})})}Array.isArray(o)&&e.filters.appendMultiple(o),Array.isArray(c)&&e.queries.appendMultiple(c),Array.isArray(d)&&e.sqlSnippets.appendMultiple(d),u&&Object.keys(u).length>0&&e.mock_context.defaults(u)}})).actions(e=>({reset(){g.applySnapshot(e.filters.current,e.origin.filters.current),g.applySnapshot(e.queries.current,e.origin.queries.current),g.applySnapshot(e.sqlSnippets.current,e.origin.sqlSnippets.current),g.applySnapshot(e.views.current,e.origin.views.current),g.applySnapshot(e.panels.list,e.origin.panels.list),g.applySnapshot(e.layouts.list,e.origin.layouts.list),e.mock_context.current=e.origin.mock_context.current},resetFilters(){g.applySnapshot(e.filters.current,e.origin.filters.current)},updateCurrent(t){const{id:r,name:a,content:o}=t;if(!o)throw new Error("unexpected null content when updating a content model");const{version:l,filters:i,views:c,panels:d,definition:{queries:u,sqlSnippets:p,mock_context:f={}}}=o;e.id=r,e.name=a,e.version=l,g.applySnapshot(e.filters.current,i),g.applySnapshot(e.views.current,ns(c).current),g.applySnapshot(e.panels.list,d),g.applySnapshot(e.queries.current,u),g.applySnapshot(e.sqlSnippets.current,p),e.mock_context.current=f}})),rs=g.types.snapshotProcessor(zD,{preProcessor(e){return{...e,origin:e}},postProcessor(e){delete e.origin;const t=g.castToSnapshot(e.queries.current.map(r=>b.pick(r,["id","key","type","sql"])));return b.defaults({},{queries:{current:t}},e)}});function MD(e,t){t.filters&&g.applySnapshot(e.filters.current,t.filters)}function Rc({id:e,name:t,dashboard_id:r,create_time:a,update_time:o,content:l},i,c){if(!l)throw new Error("unexpected null content when creating a content model");const{version:d,filters:u,views:p,panels:f,layouts:v,definition:{queries:_,sqlSnippets:w,mock_context:x={}}}=l;return rs.create({id:e,name:t,dashboard_id:r,create_time:a,update_time:o,version:d,filters:Ea(u,i,x,c),queries:{current:_},sqlSnippets:{current:w},mock_context:ca(x),views:ns(p),panels:{list:f},layouts:{list:v,currentBreakpoint:v[0].id}})}const ed=g.types.model({id:g.types.identifier,name:g.types.string,group:g.types.string,content:rs,content_id:g.types.string,datasources:gD,globalSQLSnippets:za,context:An,editor:TD}).views(e=>({get json(){return{id:e.id,name:e.name,group:e.group,content_id:e.content_id}},get queryVariables(){return{context:{...e.content.mock_context.current,...e.context.current},filters:e.content.filters.previewValues}},get queryVariablesString(){return JSON.stringify(this.queryVariables,null,2)}})).actions(e=>({updateCurrentContent(t){e.content.updateCurrent(t)},updateCurrent(t,r){const{id:a,name:o,group:l,content_id:i}=t;e.id=a,e.name=o,e.group=l,e.content_id=i,this.updateCurrentContent(r)}}));function td({id:e,name:t,group:r,content_id:a},o,l,i,c,d){return ed.create({id:e,name:t,group:r,content_id:a,content:Rc(o,c,d),datasources:{list:l},globalSQLSnippets:{list:i},context:Ma(c),editor:{}})}function Ft(e){console.groupCollapsed("Running operation ",e.type),console.log(e),console.groupEnd()}function nd(e,t){h.useEffect(()=>{const a=o=>{Ft(o);const{viewID:l}=o.detail;if(!l){console.error(new Error("[Open View] Needs to pick a view first"));return}e.views.appendToVisibles(l),t&&e.views.setIDOfVIE(l)};return window.addEventListener("open-view",a),()=>{window.removeEventListener("open-view",a)}},[e,t]);const r=zu.useNavigate();h.useEffect(()=>{const a=o=>{Ft(o);const{panelID:l}=o.detail;if(!l){console.error(new Error("[Scroll to Panel] Needs to pick a panel first"));return}r(`#${l}`),setTimeout(()=>{const i=document.getElementById(l);i&&i.scrollIntoView({behavior:"smooth"})},300)};return window.addEventListener("scroll_to_panel",a),()=>{window.removeEventListener("scroll_to_panel",a)}},[r]),h.useEffect(()=>{const a=o=>{Ft(o);const{viewID:l,tab:i}=o.detail;if(!l){console.error(new Error("[Switch Tab] Needs to pick a view and a tab first"));return}const c=e.views.findByID(l);if(!c){console.error(new Error(`[Switch Tab] View by ID[${l}] is not found`));return}c.setTab(i)};return window.addEventListener("switch_tab",a),()=>{window.removeEventListener("switch_tab",a)}},[e,t]),h.useEffect(()=>{const a=o=>{Ft(o);const{dictionary:l,payload:i}=o.detail;if(!i||Object.keys(i).length===0){console.error(new Error("[Set Filter Values] payload is empty"));return}const c={};Object.entries(l).forEach(([d,u])=>{const p=b.get(i,u);c[d]=p}),e.filters.applyValuesPatch(c)};return window.addEventListener("set-filter-values",a),()=>{window.removeEventListener("set-filter-values",a)}},[e]),h.useEffect(()=>{function a(l){return Array.isArray(l)?[]:typeof l=="object"?{}:typeof l=="boolean"?!1:typeof l=="string"?"":typeof l=="number"?0:l}const o=l=>{Ft(l);const i={},{filter_keys:c}=l.detail;c.forEach(d=>{const u=b.get(e.filters.values,d),p=a(u);i[d]=p}),e.filters.applyValuesPatch(i)};return window.addEventListener("clear-filter-values",o),()=>{window.removeEventListener("clear-filter-values",o)}},[e]),h.useEffect(()=>{const a=o=>{Ft(o);const{urlTemplate:l,openInNewTab:i,enableEncoding:c=!1,payload:d}=o.detail;if(!l){console.error(new Error("[Open Link] URL is empty"));return}function u(v){return b.cloneDeepWith(v,w=>{if(c&&typeof w=="string")return encodeURIComponent(w)})}const f=b.template(l||"")(u({...d,filters:e.payloadForSQL.filters,context:e.payloadForSQL.context}));window.open(f,i?"_blank":"_self","noopener")};return window.addEventListener("open-link",a),()=>{window.removeEventListener("open-link",a)}},[e])}function rd(e){return h.useCallback(t=>t.provideValue(ee.pluginManager,e.pluginManager).provideValue(ee.vizManager,e.vizManager).provideValue(ee.panelAddonManager,e.panelAddonManager).provideValue(ee.colorManager,e.colorManager),[e])}const HI="",ID=k.observer(({saveDashboardChanges:e})=>{const{t}=m.useTranslation(),r=De.useModals(),a=G(),o=()=>{r.openConfirmModal({title:n.jsxs(s.Group,{justify:"flex-start",children:[n.jsx(S.IconAlertTriangle,{size:18,color:"red"}),n.jsx(s.Text,{size:"sm",children:"You are reverting changes"})]}),labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:()=>a.reset(),zIndex:320,withCloseButton:!1})},l=a.changed;return n.jsxs(s.Group,{gap:0,children:[n.jsx(s.Button,{color:"green",variant:"filled",size:"xs",leftSection:n.jsx(S.IconDeviceFloppy,{size:18}),onClick:e,disabled:!l,sx:{borderTopRightRadius:0,borderBottomRightRadius:0},children:t("common.actions.save_changes")}),n.jsxs(s.Menu,{width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:320,disabled:!l,children:[n.jsx(s.Menu.Target,{children:n.jsx(s.ActionIcon,{variant:"default",disabled:!l,sx:{height:"30px",borderTopLeftRadius:0,borderBottomLeftRadius:0,svg:{fill:"rgb(173, 181, 189)",stroke:"none"}},children:n.jsx(S.IconCaretDown,{size:18})})}),n.jsx(s.Menu.Dropdown,{children:n.jsx(s.Menu.Item,{leftSection:n.jsx(S.IconRecycle,{size:14,color:"red"}),disabled:!l,onClick:o,children:t("common.actions.revert_changes")})})]})]})}),VD=k.observer(({saveDashboardChanges:e,onExit:t,headerSlot:r=null})=>{m.useTranslation();const a=j(),o=a.content.changed,l=()=>{t({hasChanges:o,dashboardId:a.id})};return n.jsx(s.AppShell.Header,{h:60,py:0,px:"md",sx:{zIndex:299},children:n.jsxs(s.Group,{justify:"space-between",sx:{height:60,minWidth:"1000px",position:"relative"},children:[n.jsxs(s.Group,{children:[n.jsx(s.Button,{size:"xs",color:o?"red":"green",leftSection:n.jsx(S.IconArrowLeft,{size:20}),onClick:l,children:n.jsx(s.Group,{gap:4,children:n.jsx(m.Trans,{i18nKey:"common.actions.end_editing",values:{name:a.name},children:n.jsx(s.Text,{td:"underline",size:"xs",children:a.name})})})}),n.jsx(ID,{saveDashboardChanges:e})]}),n.jsx(s.Group,{justify:"flex-end",sx:{flexGrow:1},children:r})]})})}),ad={height:"30px",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},PD=k.observer(()=>{var o;const{t:e}=m.useTranslation(),t=G(),r=((o=t.views.VIE)==null?void 0:o.type)===B.Tabs,a=()=>t.addANewPanel(t.views.idOfVIE);return r?n.jsx(s.Tooltip,{label:e("common.choose_a_tab_first"),children:n.jsx(s.Button,{variant:"outline",color:"gray",radius:0,size:"xs",leftSection:n.jsx(S.IconPlaylistAdd,{size:20}),sx:{...ad,transform:"none !important"},children:e("panel.add")})}):n.jsx(s.Button,{variant:"outline",color:"blue",radius:0,size:"xs",onClick:a,leftSection:n.jsx(S.IconPlaylistAdd,{size:20}),sx:{...ad,background:"rgb(231, 245, 255)"},children:e("panel.add")})}),$D=k.observer(({done:e})=>{var A,U;const{t}=m.useTranslation(),a=G().layouts,o=h.useMemo(()=>({list:a.breakpointsInfo}),[a.breakpointsInfo]),{control:l,handleSubmit:i,watch:c,getValues:d,reset:u,formState:p}=y.useForm({defaultValues:o}),{fields:f,append:v,remove:_}=y.useFieldArray({control:l,name:"list",rules:{validate:N=>{if(b.uniqBy(N,"breakpoint").length!==N.length)return"Screen sizes should be unique by min width"}}}),w=c("list"),x=f.map((N,oe)=>({...N,...w[oe]})),T=()=>{v({id:Te.v4(),name:"",breakpoint:""})},D=({list:N})=>{const oe=N.filter(be=>Number.isFinite(be.breakpoint));a.updateLayoutSetsInfo(oe),e()},z=d(),I=h.useMemo(()=>{const N={list:z.list.filter(oe=>!!oe.name&&Number.isFinite(oe.breakpoint))};return!b.isEqual(N,o)},[z,o]),E=(U=(A=p.errors.list)==null?void 0:A.root)==null?void 0:U.message;return n.jsx(n.Fragment,{children:n.jsxs("form",{onSubmit:i(D),children:[n.jsxs(s.Table,{fz:"sm",highlightOnHover:!0,withTableBorder:!0,sx:{tableLayout:"fixed"},children:[n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{style:{width:"340px"},children:t("common.name")}),n.jsx(s.Table.Th,{style:{width:"160px"},children:t("breakpoint.breakpoint")}),n.jsx(s.Table.Th,{})]})}),n.jsxs(s.Table.Tbody,{children:[x.map((N,oe)=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:N.id==="basis"?N.name:n.jsx(y.Controller,{name:`list.${oe}.name`,control:l,render:({field:be})=>n.jsx(s.TextInput,{size:"xs",label:"",required:!0,sx:{flex:1},...be})})}),n.jsx(s.Table.Td,{children:N.id==="basis"?n.jsxs(s.Text,{size:"sm",ff:"monospace",children:[N.breakpoint,"px"]}):n.jsx(y.Controller,{name:`list.${oe}.breakpoint`,control:l,render:({field:be})=>n.jsx(s.NumberInput,{size:"xs",label:"",required:!0,max:1e4,hideControls:!0,rightSection:n.jsx(s.Text,{size:"sm",c:"dimmed",children:"px"}),rightSectionProps:{style:{width:"30px"}},sx:{flex:1},ff:"monospace",styles:{input:{paddingRight:"30px"}},...be})})}),n.jsx(s.Table.Td,{children:N.id!=="basis"&&n.jsx(s.ActionIcon,{mx:"auto",size:"xs",variant:"subtle",color:"red",onClick:()=>_(oe),children:n.jsx(S.IconTrash,{})})})]},N.id)),n.jsx(s.Table.Tr,{style:{backgroundColor:"transparent"},children:n.jsx(s.Table.Td,{colSpan:3,style:{padding:"0"},children:n.jsx(s.Tooltip,{label:t("breakpoint.add"),children:n.jsx(s.ActionIcon,{variant:"subtle",size:"md",color:"blue",onClick:T,sx:{width:"100%"},children:n.jsx(S.IconPlus,{size:18})})})})})]})]}),n.jsx(s.Text,{mt:6,ta:"right",size:"xs",c:"red",children:E??" "}),n.jsxs(s.Group,{mt:6,justify:"space-between",children:[n.jsx(s.Button,{color:"orange",size:"xs",onClick:()=>u(),leftSection:n.jsx(S.IconRecycle,{size:18}),disabled:!I,children:t("common.actions.revert")}),n.jsx(s.Button,{color:"green",size:"xs",type:"submit",leftSection:n.jsx(S.IconDeviceFloppy,{size:18}),disabled:!I,children:t("common.actions.save_changes")})]})]})})}),AD=k.observer(()=>{const{t:e}=m.useTranslation(),[t,{open:r,close:a}]=te.useDisclosure(!1),o=G(),l=o.layouts.currentBreakpoint,i=o.layouts.currentLayoutRange,c=()=>{setTimeout(()=>{window.dispatchEvent(new Event("resize"))},32)},d=()=>{a(),c()};return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{children:[n.jsxs(s.Menu,{withArrow:!0,withinPortal:!0,zIndex:320,trigger:"hover",children:[n.jsx(s.Menu.Target,{children:n.jsx(s.Button,{size:"xs",variant:"subtle",leftSection:n.jsx(S.IconDevices,{size:16}),sx:{borderRadius:0},children:n.jsxs(s.Group,{gap:6,children:[n.jsx(s.Text,{size:"xs",fw:"normal",children:i.name}),n.jsx(s.Text,{size:"xs",c:"#777",children:o.layouts.currentRangeText})]})})}),n.jsxs(s.Menu.Dropdown,{children:[o.layouts.breakpointRanges.map(u=>n.jsx(s.Menu.Item,{onClick:()=>o.layouts.setCurrentBreakpoint(u.id),disabled:l===u.id,children:n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Text,{size:"sm",children:u.name}),n.jsx(s.Text,{size:"xs",c:"dimmed",children:u.text})]})},u.id)),n.jsx(s.Menu.Divider,{}),n.jsx(s.Menu.Item,{color:"blue",leftSection:n.jsx(S.IconSettings,{size:14}),onClick:r,children:n.jsx(s.Text,{size:"sm",children:e("breakpoint.manage")})})]})]}),o.layouts.divisionPreviewScale<1&&n.jsx(s.Text,{size:"xs",c:"dimmed",children:Ee(o.layouts.divisionPreviewScale).format({output:"percent",mantissa:0})})]}),n.jsx(s.Modal,{opened:t,onClose:d,title:e("breakpoint.label",{count:2}),withinPortal:!0,zIndex:320,size:600,closeOnClickOutside:!1,children:n.jsx($D,{done:d})})]})}),sd={height:"30px",borderRight:"none",borderTop:"none",borderLeft:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},ED=k.observer(()=>{var o;const{t:e}=m.useTranslation(),t=G(),r=((o=t.views.VIE)==null?void 0:o.type)===B.Tabs,a=()=>{var l;return(l=t.views.VIE)==null?void 0:l.downloadSchema()};return r?n.jsx(s.Tooltip,{label:e("common.choose_a_tab_first"),children:n.jsx(s.Button,{variant:"outline",color:"gray",radius:0,size:"xs",leftSection:n.jsx(S.IconCode,{size:16}),sx:{...sd,transform:"none !important"},children:e("view.download_schema")})}):n.jsx(s.Button,{variant:"outline",color:"blue",radius:0,size:"xs",onClick:a,leftSection:n.jsx(S.IconCode,{size:16}),sx:{...sd},children:e("view.download_schema")})}),Ln=({headers:e,rows:t})=>n.jsxs(s.Table,{fz:"xs",highlightOnHover:!0,sx:{tableLayout:"fixed",fontFamily:"monospace"},children:[n.jsx(s.Table.Thead,{children:e}),n.jsx(s.Table.Tbody,{children:t})]}),BD=({content:e})=>{const{t}=m.useTranslation(),r=e.views;return!Array.isArray(r)||r.length===0?null:n.jsxs(s.Box,{children:[n.jsx(s.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:t("view.labels")}),n.jsx(Ln,{headers:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{style:{width:"160px"},children:t("common.id")}),n.jsx(s.Table.Th,{children:t("common.name")}),n.jsx(s.Table.Th,{children:t("common.type")})]}),rows:r.map(a=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:a.id}),n.jsx(s.Table.Td,{children:a.name}),n.jsx(s.Table.Td,{children:t(`view.component.${a.type}.label`)})]},a.id))})]})},qD=({content:e})=>{const{t}=m.useTranslation(),r=e.filters;return!Array.isArray(r)||r.length===0?null:n.jsxs(s.Box,{children:[n.jsx(s.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:t("filter.labels")}),n.jsx(Ln,{headers:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{style:{width:"160px"},children:t("common.id")}),n.jsx(s.Table.Th,{children:t("common.key")}),n.jsx(s.Table.Th,{children:t("common.label")})]}),rows:r.map(a=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:a.id}),n.jsx(s.Table.Td,{children:a.key}),n.jsx(s.Table.Td,{children:a.label})]},a.id))})]})},LD=({content:e})=>{const{t}=m.useTranslation(),r=e.panels;return!Array.isArray(r)||r.length===0?null:n.jsxs(s.Box,{children:[n.jsx(s.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:t("panel.labels")}),n.jsx(Ln,{headers:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{style:{width:"160px"},children:t("common.id")}),n.jsx(s.Table.Th,{children:t("common.name")}),n.jsx(s.Table.Th,{children:t("visualization.component")})]}),rows:r.map(a=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:a.id}),n.jsx(s.Table.Td,{children:a.name}),n.jsx(s.Table.Td,{children:a.viz.type})]},a.id))})]})},OD=({content:e})=>{var a;const{t}=m.useTranslation(),r=(a=e.definition)==null?void 0:a.queries;return!Array.isArray(r)||r.length===0?null:n.jsxs(s.Box,{children:[n.jsx(s.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:t("query.labels")}),n.jsx(Ln,{headers:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{style:{width:"160px"},children:t("common.id")}),n.jsx(s.Table.Th,{children:t("common.name")}),n.jsx(s.Table.Th,{style:{width:"140px"},children:t("common.type")}),n.jsx(s.Table.Th,{style:{width:"260px"},children:t("data_source.label")})]}),rows:r.map(o=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:o.id}),n.jsx(s.Table.Td,{children:o.name}),n.jsx(s.Table.Td,{children:o.type}),n.jsx(s.Table.Td,{children:o.key})]},o.id))})]})},ND=({content:e})=>{var a;const{t}=m.useTranslation(),r=(a=e.definition)==null?void 0:a.sqlSnippets;return!Array.isArray(r)||r.length===0?null:n.jsxs(s.Box,{children:[n.jsx(s.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:t("sql_snippet.labels")}),n.jsx(s.List,{size:"sm",pl:10,ff:"monospace",icon:n.jsx(S.IconPointFilled,{size:10}),children:r.map(o=>n.jsx(s.List.Item,{children:o.key},o.key))})]})},GD=({content:e})=>{var a;const{t}=m.useTranslation(),r=Object.keys(((a=e.definition)==null?void 0:a.mock_context)??{});return r.length===0?null:n.jsxs(s.Box,{children:[n.jsx(s.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:t("mock_context.label")}),n.jsx(s.List,{size:"sm",pl:10,ff:"monospace",icon:n.jsx(S.IconPointFilled,{size:10}),children:r.map(o=>n.jsx(s.List.Item,{children:o},o))})]})},FD=({content:e})=>e?n.jsxs(s.Box,{children:[n.jsx(s.Divider,{mt:20,mb:10,variant:"dashed"}),n.jsx(s.Text,{ta:"left",c:"dimmed",size:"sm",children:"Preview"}),n.jsxs(s.Stack,{children:[n.jsx(BD,{content:e}),n.jsx(qD,{content:e}),n.jsx(LD,{content:e}),n.jsx(OD,{content:e}),n.jsx(ND,{content:e}),n.jsx(GD,{content:e})]})]}):null;function QD(e){if(e.target===null)throw new Error("FileReader failed with null result");if(typeof e.target.result!="string")throw new Error(`Unparsable file content of type: ${typeof e.target.result}`);let t=JSON.parse(e.target.result);if("content"in t&&(t=t.content),t.version!==ct)throw new Error("Schema version mismatch");return t}const jD=k.observer(({onSuccess:e,stretchModal:t,shrinkModal:r})=>{var D,z;const{t:a}=m.useTranslation(),o=G(),{handleSubmit:l,formState:{errors:i},setValue:c,watch:d,setError:u,clearErrors:p}=y.useForm({defaultValues:{content:null}}),f=({content:I})=>{try{if(!I)throw new Error("please use a valid json file");o.applyJSONSchema(I),Ge.showNotification({title:"Successful",message:"",color:"green"}),e()}catch(E){console.error(E),Ge.showNotification({title:"Failed",message:E.message,color:"red"})}},[v,_]=h.useState(null);h.useEffect(()=>{if(!v)return;const I=new FileReader;I.readAsText(v,"UTF-8"),I.onload=E=>{try{const A=QD(E);c("content",A),p("content")}catch(A){console.error(A),u("content",{type:"custom",message:A.message})}},I.onabort=()=>console.log("🟨 abort"),I.onerror=()=>{I.error&&(console.error(I.error),u("content",{type:"custom",message:I.error.message}))}},[v]);const[w]=d(["content"]),x=!w,T=(D=i==null?void 0:i.content)==null?void 0:D.message;return h.useEffect(()=>{!w||T?r():t()},[w,T]),n.jsx(s.Box,{mx:"auto",sx:{position:"relative"},children:n.jsxs("form",{onSubmit:l(f),children:[n.jsx(s.FileInput,{label:a("import.json_file"),required:!0,value:v,onChange:_,error:(z=i==null?void 0:i.content)==null?void 0:z.message,sx:{maxWidth:500}}),T?n.jsx(s.Table,{fz:12,mt:10,children:n.jsxs(s.Table.Tbody,{children:[n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:a("import.this_dashboard")}),n.jsx(s.Table.Td,{children:ct})]}),n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:a("import.this_file")}),n.jsx(s.Table.Td,{style:{color:"red"},children:w==null?void 0:w.version})]})]})}):n.jsxs(n.Fragment,{children:[n.jsx(FD,{content:w}),n.jsx(s.Group,{justify:"flex-end",my:"md",children:n.jsx(s.Button,{type:"submit",color:"green",disabled:x,children:a("common.actions.confirm")})})]})]})})}),od={height:"30px",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},WD=k.observer(()=>{var u;const{t:e}=m.useTranslation(),[t,{open:r,close:a}]=te.useDisclosure(!1),[o,{setTrue:l,setFalse:i}]=O.useBoolean(!1),d=((u=j().content.views.VIE)==null?void 0:u.type)===B.Tabs;return d?n.jsx(s.Tooltip,{label:e("common.choose_a_tab_first"),children:n.jsx(s.Button,{variant:"outline",color:"gray",radius:0,size:"xs",leftSection:n.jsx(S.IconFileImport,{size:16}),sx:{...od,transform:"none !important"},children:e("import.label")})}):n.jsxs(n.Fragment,{children:[n.jsx(s.Button,{variant:"subtle",color:"blue",radius:0,size:"xs",disabled:d||t,onClick:r,leftSection:n.jsx(S.IconFileImport,{size:16}),sx:{...od},children:e("import.label")}),n.jsx(s.Modal,{opened:t,onClose:a,title:e("import.title"),trapFocus:!0,onDragStart:p=>{p.stopPropagation()},withinPortal:!0,zIndex:320,size:o?"90vw":500,children:n.jsx(jD,{onSuccess:a,stretchModal:l,shrinkModal:i})})]})}),UD=({iconKey:e,...t})=>{switch(e){case"query_variables":return n.jsx(S.IconVariable,{...t});case"mock_context":return n.jsx(S.IconCodeDots,{...t});case"filter":return n.jsx(S.IconFilter,{...t});case"sql_snippet":return n.jsx(S.IconCopy,{...t});case"query":return n.jsx(S.IconDatabase,{...t});case"view":return n.jsx(S.IconBoxMultiple,{...t});case"panel":return n.jsx(S.IconAppWindow,{...t});default:return null}},KD=({action:e})=>{const{t}=m.useTranslation();return e.description?n.jsx(s.Text,{c:"dimmed",size:"xs",children:t(e.description)}):e.viz?n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Text,{c:"dimmed",size:"xs",children:t(e.viz.displayName)}),n.jsx(s.Text,{c:"dimmed",size:"xs",className:"spotlight-action-viz-group",children:t(e.viz.displayGroup)})]}):null},YD=k.observer(({action:e,query:t})=>{const{t:r}=m.useTranslation();return n.jsx(s.Box,{className:"spotlight-custom-action-component",children:n.jsxs(s.Group,{wrap:"nowrap",children:[n.jsx(UD,{iconKey:e.iconKey,size:14}),n.jsxs("div",{style:{flex:1},children:[n.jsx(s.Highlight,{highlight:t,size:"sm",children:e.title?r(e.title):""}),n.jsx(KD,{action:e})]})]})})}),XD=({groups:e,query:t})=>{const{t:r}=m.useTranslation();return e.length===0?n.jsx(xt.Spotlight.Empty,{children:r("spotlight.not_found")}):n.jsx(n.Fragment,{children:e.map(a=>n.jsx(xt.Spotlight.ActionsGroup,{label:a.group,children:a.actions.map(o=>n.jsx(xt.Spotlight.Action,{onClick:o.onClick,children:n.jsx(YD,{action:o,query:t})},o.id))},a.group))})},ZD=k.observer(()=>{const{t:e,i18n:t}=m.useTranslation(),r=s.useMantineTheme(),a=j(),[o,l]=h.useState(""),i=h.useMemo(()=>a.editor.spotlightActionGroups.map(d=>({group:e(d.group),keywords:[d.group,e(d.group)],actions:d.actions.map(u=>{const p=[];return u.title&&(p.push(u.title.toLowerCase()),p.push(e(u.title).toLowerCase())),u.group&&p.push(u.group.toLowerCase()),u.viz&&(p.push(u.viz.displayGroup.toLowerCase()),p.push(u.viz.displayName.toLowerCase())),u.iconKey&&p.push(u.iconKey),{...u,keywords:p}})})),[a.editor.spotlightActionGroups,t.language]),c=h.useMemo(()=>{const d=o.toLowerCase().trim();return d?i.map(p=>{if(p.keywords.some(_=>_.includes(d)))return p;const v=p.actions.filter(_=>_.keywords.some(w=>w.includes(d)));return v.length===0?null:{...p,actions:v}}).filter(p=>p!==null):[i[0]]},[i,o]);return n.jsxs(xt.Spotlight.Root,{onQueryChange:l,shortcut:["mod + P","mod + K"],radius:"md",styles:{search:{border:"none"},action:{position:"relative",display:"block",width:"100%",padding:`${s.rem(10)} ${s.rem(12)}`,borderRadius:r.radius.sm,".spotlight-action-viz-group":{opacity:0},"&:hover, &[data-selected]":{backgroundColor:r.colors.gray[1],".spotlight-action-viz-group":{opacity:1}}}},children:[n.jsx(xt.Spotlight.Search,{placeholder:e("spotlight.placeholder"),leftSection:n.jsx(S.IconSearch,{size:"1.2rem"})}),n.jsx(xt.Spotlight.ActionsList,{children:n.jsx(XD,{groups:c,query:o})})]})}),ld=({children:e})=>n.jsx(s.Text,{style:{fontSize:"0.6875rem",lineHeight:1,padding:"0.25rem 0.2375rem",borderRadius:"0.25rem"},children:e}),id=function(){var t;return(((t=navigator.userAgentData)==null?void 0:t.platform)??navigator.platform).toLowerCase().includes("mac")}(),JD=()=>{const{t:e}=m.useTranslation();return n.jsx(s.Tooltip,{label:n.jsxs(n.Fragment,{children:[id&&n.jsx(ld,{children:"⌘ + K"}),!id&&n.jsx(ld,{children:"Ctrl + K"})]}),children:n.jsx(s.UnstyledButton,{onClick:()=>xt.spotlight.open(),style:{height:"1.875rem",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef",paddingLeft:"calc(0.875rem / 1.5)",paddingRight:"1rem"},sx:{color:"#228be6",background:"transparent","&:hover":{background:"rgb(231, 245, 255)"}},children:n.jsxs(s.Group,{gap:"0.625rem",children:[n.jsx(S.IconSearch,{size:"1rem",color:"#228be6"}),n.jsx(s.Text,{fw:500,style:{flexGrow:1,fontWeight:500,fontSize:"0.75rem",lineHeight:1},children:e("spotlight.trigger_text")})]})})})},HD={position:"fixed",top:60,left:0,right:0,height:30,zIndex:299,borderBottom:"1px solid #e9ecef",background:"rgba(233,236,239, 0.15)"},RD=k.observer(()=>n.jsx(s.Box,{sx:HD,pl:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},children:n.jsxs(s.Group,{justify:"space-between",align:"center",sx:{height:"30px"},children:[n.jsxs(s.Group,{justify:"flex-start",gap:0,children:[n.jsx(PD,{}),n.jsx(WD,{}),n.jsx(JD,{})]}),n.jsx(AD,{}),n.jsx(s.Group,{justify:"flex-end",gap:0,children:n.jsx(ED,{})})]})})),ez=k.observer(e=>n.jsxs(n.Fragment,{children:[n.jsx(VD,{...e}),n.jsx(RD,{})]}));function tz(e,t,r){const a=[];return e.filter(o=>"__INTERACTIONS"in o.viz.conf).forEach((o,l)=>{const i=t[o.id];i.data.interactions=b.get(i,"data.interactions",[]);const{__INTERACTIONS:c,__OPERATIONS:d,__TRIGGERS:u}=o.viz.conf;Object.entries(d).forEach(([p,f])=>{const{schemaRef:v,data:_}=f,{config:w}=_;switch(v){case"builtin:op:open-link":let x=w.urlTemplate.substring(0,100);w.urlTemplate.length>=20&&(x+="..."),i.type="interaction",i.data.interactions.push({schemaRef:v,urlTemplate:w.urlTemplate,shortURLTemplate:x});return;case"builtin:op:open_view":a.push({id:`OPERATION--${p}`,source:o.id,target:w.viewID,label:"Open View",style:{stroke:"rgba(0,0,0,0.8)"},type:"default"});return;case"builtin:op:set_filter_values":i.type="interaction",i.data.interactions.push({schemaRef:v,filters:Object.keys(w.dictionary).map(T=>({key:T,label:r[T]}))});return;case"builtin:op:clear_filter_values":i.type="interaction",i.data.interactions.push({schemaRef:v,filters:w.filter_keys.map(T=>({key:T,label:r[T]}))});return;default:return}})}),a}function nz(e,t){const r=e.filters.keyLabelMap;return{edges:tz(e.panels.list,t,r),edgeNodes:[]}}function cd(e,t,r){return e*t+e*r}function rz(e,t,r){return e*t+(e-1)*r}const On=25,as=40,dd=25,ss=350,az=150,sz=150,ud=150,pd=300,Nn=40,hd=25,oz=300;function lz(e,t){const r=b.keyBy(t,o=>o.id),a=[];return e.current.forEach((o,l)=>{o.panelIDs.forEach((i,c)=>{const d=cd(c,Nn,hd)+as,u=r[i];if(!u){a.push({id:i,_node_type:"panel",parentNode:o.id,data:{label:`!: ${i}`},position:{x:On,y:d},sourcePosition:ie.Position.Right,targetPosition:ie.Position.Left,style:{width:pd,height:Nn}});return}const p=u.name;a.push({id:u.id,_node_type:"panel",parentNode:o.id,data:{label:p},position:{x:On,y:d},sourcePosition:ie.Position.Right,targetPosition:ie.Position.Left,style:{width:pd,height:Nn}})})}),a}const iz={[B.Division]:"Div",[B.Modal]:"Modal",[B.Tabs]:"Tabs"},cz=jc;function dz(e){return e.current.map((r,a)=>{const o=rz(r.panelIDs.length,Nn,hd)+as+dd;let l=[];return r.type===B.Tabs&&(l=r.config.tabsInOrder.map(c=>c.view_id)),{id:r.id,_node_type:"view-root",_view_type:r.type,_view_level:0,_sub_view_ids:[],_tab_view_ids:l,data:{label:`${iz[r.type]}:${r.name}`},position:{x:0,y:0},sourcePosition:ie.Position.Right,targetPosition:ie.Position.Left,className:"light",style:{backgroundColor:cz[r.type],width:ss,height:o}}})}function uz(e){const t=b.keyBy(e,r=>r.id);e.forEach(r=>{r._node_type!=="view-root"||r._view_type!==B.Tabs||r._tab_view_ids.forEach(a=>{t[a].parentNode=r.id})})}function pz(e){const t=dz(e.views);uz(t);const r=lz(e.views,e.panels.list);return[...t,...r]}function hz({nodeMap:e,nodes:t,edges:r}){t.forEach(a=>{a._node_type!=="view-root"||a._view_type!==B.Tabs||(a.sourcePosition=ie.Position.Bottom,a.style.width=ss+On*2,a.style.height=dd+a._tab_view_ids.reduce((o,l)=>{const i=e[l];i.position.y=o,i.position.x=On;const c=i.style.height;return o+c+20},as))})}function gz({nodeMap:e,nodes:t,edges:r}){r.filter(a=>a.label==="Open View").forEach(a=>{const o=e[a.source],l=e[a.target];if(!o||!l||!o.parentNode)return;const i=e[o.parentNode];i._node_type!=="view-root"||l._node_type!=="view-root"||(l._view_level+=1+i._view_level,i._sub_view_ids.push(l.id))}),t.sort((a,o)=>a._node_type==="view-root"&&o._node_type==="view-root"?a._view_level-o._view_level:a._node_type!=="view-root"&&o._node_type!=="view-root"?0:a._node_type==="view-root"?-1:1)}function fz({nodeMap:e,nodes:t,edges:r}){const a={};r.forEach(o=>{if(o.label!=="Open View")return;const l=e[o.source],i=e[o.target];if(l&&i&&l.parentNode){const c=e[l.parentNode],d=c.position.x,u=Number(b.get(i,"style.height",0)),p=Number(c.style.width);i.position.x=d+p+oz,c._view_level===0&&i._sub_view_ids.length===0&&(l.sourcePosition=ie.Position.Left,i.targetPosition=ie.Position.Right,i.position.x*=-1);const v=i.position.x,_=b.get(a,v,0);i.position.y=_,a[v]=_+u+ud}})}function bz({nodeMap:e,nodes:t,edges:r}){const a=new Set,o=new Set;r.forEach(i=>{a.add(i.source),o.add(i.target)}),t.filter(i=>i._node_type!=="view-root"||i.id==="Main"||i.parentNode?!1:!a.has(i.id)&&!o.has(i.id)).forEach((i,c)=>{i.position.x=cd(c,ss,sz),i.position.y=0-az-ud})}function yz({nodeMap:e,nodes:t,edges:r}){const a={nodeMap:e,nodes:t,edges:r};return bz(a),gz(a),hz(a),fz(a),{nodes:t,edges:r}}function vz(e){const t=pz(e),r=b.keyBy(t,d=>d.id),{edges:a,edgeNodes:o}=nz(e,r),l=[...t,...o],i=b.keyBy(l,d=>d.id),c={edges:b.uniqBy(a,d=>d.id),nodes:l,nodeMap:i};return yz(c)}const RI="",os={"builtin:op:open-link":n.jsx(s.ThemeIcon,{color:"blue",size:20,radius:"xl",children:n.jsx(S.IconCircleDashed,{size:14})}),"builtin:op:set_filter_values":n.jsx(s.ThemeIcon,{color:"orange",size:20,radius:"xl",children:n.jsx(S.IconCircleDot,{size:14})}),"builtin:op:clear_filter_values":n.jsx(s.ThemeIcon,{color:"orange",size:20,radius:"xl",children:n.jsx(S.IconCircleOff,{size:14})})};function _z(e){const t=[];return e.forEach(r=>{switch(r.schemaRef){case"builtin:op:open-link":t.push({key:r.urlTemplate,icon:os[r.schemaRef],text:n.jsxs(s.Group,{gap:4,children:[n.jsx(s.Text,{size:"sm",children:"Open: "}),n.jsx(s.Text,{size:"sm",c:"dimmed",children:r.shortURLTemplate})]})});return;case"builtin:op:set_filter_values":r.filters.forEach(({key:a,label:o})=>{t.push({key:r.schemaRef+a,icon:os[r.schemaRef],text:n.jsx(s.Group,{gap:4,children:n.jsxs(s.Text,{size:"sm",children:["Set Filter: ",o]})})})});return;case"builtin:op:clear_filter_values":r.filters.forEach(({key:a,label:o})=>{t.push({key:r.schemaRef+a,icon:os[r.schemaRef],text:n.jsx(s.Group,{gap:4,children:n.jsxs(s.Text,{size:"sm",children:["Clear Filter: ",o]})})})});return}}),t}const mz=h.memo(({data:e,isConnectable:t,sourcePosition:r=ie.Position.Right,targetPosition:a=ie.Position.Left,...o})=>{const l=h.useMemo(()=>_z(e.interactions),[e.interactions]);return n.jsxs(n.Fragment,{children:[n.jsx(ie.Handle,{type:"target",position:a,isConnectable:t}),n.jsx(s.Box,{sx:{position:"absolute",top:0,right:0},children:n.jsx(S.IconChevronsUpRight,{size:12})}),n.jsxs(s.HoverCard,{shadow:"xl",withinPortal:!0,children:[n.jsx(s.HoverCard.Target,{children:n.jsx(s.Text,{size:"sm",children:e.label})}),n.jsx(s.HoverCard.Dropdown,{children:n.jsx(s.List,{spacing:"xs",size:"sm",center:!0,children:l.map(i=>n.jsx(s.List.Item,{icon:i.icon,children:i.text},i.key))})})]}),n.jsx(ie.Handle,{type:"source",position:r,isConnectable:t})]})}),e6="",wz={interaction:mz},xz=k.observer(()=>{const e=H(),{edges:t,nodes:r}=vz(e);return n.jsxs(ie,{nodes:r,edges:t,onNodesChange:b.noop,onEdgesChange:b.noop,onConnect:b.noop,className:"interactions-viewer",fitView:!0,nodeTypes:wz,children:[n.jsx(ie.MiniMap,{}),n.jsx(ie.Controls,{}),n.jsx(ie.Background,{})]})}),Cz=k.observer(({opened:e,close:t})=>{const{t:r}=m.useTranslation();return n.jsx(s.Modal,{size:"96vw",opened:e,onClose:t,title:r("interactions.interactions_viewer"),trapFocus:!0,onDragStart:a=>{a.stopPropagation()},styles:{body:{height:"calc(90vh - 54px)"},content:{transform:"none !important"}},zIndex:300,children:n.jsx(xz,{})})}),Sz={"> button":{"&:first-of-type":{borderTopRightRadius:0,borderBottomRightRadius:0,borderRightWidth:.5},":not(:first-of-type):not(:last-of-type)":{borderTopRightRadius:0,borderBottomRightRadius:0,borderTopLeftRadius:0,borderBottomLeftRadius:0,borderLeftWidth:.5,borderRightWidth:.5},"&:last-of-type":{borderTopLeftRadius:0,borderBottomLeftRadius:0,borderLeftWidth:.5}}};function Tz({onClick:e,name:t,active:r,openSettings:a}){return n.jsxs(s.Box,{sx:{position:"relative"},children:[n.jsx(s.UnstyledButton,{sx:o=>({display:"block",width:"100%",padding:o.spacing.xs,borderRadius:0,position:"relative",color:o.black,"&:hover":{backgroundColor:o.colors.gray[0]},backgroundColor:r?o.colors.gray[2]:"transparent"}),children:n.jsx(s.Group,{sx:{width:"calc(100% - 28px)"},onClick:e,children:n.jsx(s.Text,{size:"sm",children:t})})}),r&&n.jsx(s.Tooltip,{label:"Edit",position:"right",withinPortal:!0,children:n.jsx(s.ActionIcon,{onClick:a,variant:"light",color:"blue",sx:{position:"absolute",top:0,bottom:0,height:"100%",right:0,zIndex:0,borderRadius:0},children:n.jsx(S.IconAdjustments,{size:16})})})]})}const kz=k.observer(()=>{const{t:e}=m.useTranslation(),t=j(),r=G(),a=h.useCallback(l=>()=>r.views.setIDOfVIE(l),[r]),o=l=>{t.editor.open(["_VIEWS_",l])};return n.jsxs(s.Box,{sx:{position:"relative"},children:[r.views.options.map(l=>n.jsx(Tz,{active:r.views.idOfVIE===l.value,name:l.label,onClick:a(l.value),openSettings:()=>o(l.value)},l.value)),n.jsx(s.Divider,{variant:"dashed"}),n.jsx(s.Button,{variant:"subtle",rightSection:n.jsx(S.IconPlus,{size:14}),size:"sm",px:"xs",color:"blue",onClick:r.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"space-between"}},children:e("view.add")})]})}),Dz=k.observer(()=>{const{t:e}=m.useTranslation(),t=j(),r=G(),a=()=>{if(!r.queries.firstID){t.editor.open(["_QUERIES_",""]);return}t.editor.open(["_QUERIES_",r.queries.firstID])},o=()=>{if(!r.filters.firstID){t.editor.open(["_FILTERS_",""]);return}t.editor.open(["_FILTERS_",r.filters.firstID])},[l,i]=h.useState(!1),c=()=>i(!0),d=()=>i(!1);return n.jsxs(s.AppShell.Navbar,{p:0,zIndex:299,children:[n.jsxs(s.AppShell.Section,{children:[n.jsxs(s.Group,{grow:!0,gap:0,sx:{...Sz,button:{borderWidth:0,borderBottomWidth:1,borderColor:"#e9ecef"}},children:[n.jsx(s.Tooltip,{label:e("filter.labels"),withinPortal:!0,children:n.jsx(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:o,children:n.jsx(S.IconFilter,{size:18})})}),n.jsx(s.Tooltip,{label:e("query.labels"),withinPortal:!0,children:n.jsx(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:a,children:n.jsx(S.IconDatabase,{size:18})})}),n.jsx(s.Tooltip,{label:e("interactions.interactions_viewer"),withinPortal:!0,children:n.jsx(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:c,children:n.jsx(S.IconRoute,{size:18})})})]}),n.jsx(Cz,{opened:l,close:d})]}),n.jsx(s.AppShell.Section,{py:5,sx:{borderBottom:"1px solid #eee"},children:n.jsx(s.Text,{size:"sm",ta:"center",sx:{userSelect:"none",cursor:"default"},children:e("view.labels")})}),n.jsx(s.AppShell.Section,{grow:!0,sx:{overflow:"auto"},children:n.jsx(kz,{})}),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",leftSection:n.jsx(S.IconSettings,{size:20}),onClick:()=>t.editor.open([]),children:e("common.titles.settings")})})})]})}),zz=k.observer(({filter:e})=>{const{t}=m.useTranslation(),r=e.config;return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Checkbox,{checked:r.default_value,onChange:a=>r.setDefaultValue(a.currentTarget.checked),label:t("filter.widget.checkbox.default_checked")}),n.jsx(_t,{filter:e})]}),n.jsx(Ue,{label:t("filter.widget.checkbox.description"),value:r.description,onChange:r.setDescription,styles:{root:{flexGrow:1,minHeight:"400px"}}},e.id)]})}),Mz=[{label:"2022",value:"YYYY"},{label:"202201",value:"YYYYMM"},{label:"20220101",value:"YYYYMMDD"},{label:"2022-01",value:"YYYY-MM"},{label:"2022-01-01",value:"YYYY-MM-DD"}],Iz=k.observer(function({filter:t}){const{t:r}=m.useTranslation(),a=t.config,o=h.useMemo(()=>{const i=mi();return Object.entries(i).map(([c,d])=>({group:r(`filter.widget.date_range.shortcut.${c}.label`),items:d.map(({key:u,value:p})=>({label:r(`filter.widget.date_range.shortcut.${c}.full.${u}`),value:p}))}))},[]),l=[...a.default_value];return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{children:[n.jsx(s.Checkbox,{checked:a.required,onChange:i=>a.setRequired(i.currentTarget.checked),label:r("filter.widget.date_range.required")}),n.jsx(s.Checkbox,{checked:a.allowSingleDateInRange,onChange:i=>a.setAllowSingleDateInRange(i.currentTarget.checked),label:r("filter.widget.date_range.allow_single_date")})]}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(s.Select,{data:Mz,label:r("filter.widget.date_range.display_format"),value:a.inputFormat,onChange:a.setInputFormat}),n.jsx(s.NumberInput,{label:r("filter.widget.date_range.max_days"),min:0,value:a.max_days,onChange:a.setMaxDays,hideControls:!0})]}),n.jsxs(s.Group,{children:[n.jsx(bc,{label:r("filter.widget.date_range.default_value"),config:a,value:{value:l,shortcut:null},onChange:a.setDefaultValue,disabled:!!a.default_shortcut}),n.jsx(s.Select,{data:o,label:r("filter.widget.date_range.default_by_shortcut"),value:a.default_shortcut,onChange:a.setDefaultShortcut,placeholder:r("filter.widget.date_range.default_by_shortcut_placeholder"),clearable:!0,sx:{flexGrow:1},maxDropdownHeight:500})]}),n.jsx(_t,{filter:t})]})}),Vz=`
|
|
546
|
+
`}})).actions(e=>({setPage(t){e.page=t},resetPage(){e.page=1},setLimit(t){e.limit=t}})).actions(e=>({afterCreate(){g.addDisposer(e,G.reaction(()=>e.keywordString,e.resetPage,{fireImmediately:!1,delay:0})),g.addDisposer(e,G.reaction(()=>e.limit,e.resetPage,{fireImmediately:!1,delay:0}))}})),lD=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 Object.keys(e.data).length===0}})),iD=g.types.model({tables:g.types.optional(lD,{}),columns:g.types.optional(aD,{}),tableData:g.types.optional(oD,{}),indexes:g.types.optional(sD,{}),table_schema:g.types.optional(g.types.string,""),table_name:g.types.optional(g.types.string,"")}).views(e=>({get dataSource(){return g.getParent(e)},get key(){return this.dataSource.key},get type(){return this.dataSource.type},get sqlDataSourceType(){return this.type},get reloadConditionString(){const t=this.type,{table_name:r,table_schema:a}=e;return`${t};${r};${a}`}})).volatile(()=>({controllers:{tables:new AbortController,columns:new AbortController,indexes:new AbortController,tableData:new AbortController}})).actions(e=>({setKeywords(t,r){e.table_schema=t,e.table_name=r}})).actions(e=>({initKeywords(){if(e.tables.empty)return;const t=Object.keys(e.tables.data)[0],r=e.tables.data[t][0].table_name;e.setKeywords(t,r)}})).actions(e=>{const t=g.flow(function*(){var r;(r=e.controllers.tables)==null||r.abort(),e.controllers.tables=new AbortController,e.tables.state="loading";try{const a=yield*g.toGenerator($e.structure(e.controllers.tables.signal)({query_type:"TABLES",type:e.sqlDataSourceType,key:e.key,table_schema:"",table_name:""},{params:{query_type:"TABLES"}}));e.tables.data=b.groupBy(a,"table_schema"),e.tables.state="idle",e.tables.error=null,e.initKeywords()}catch(a){if(!ke.isCancel(a)){e.tables.data={};const o=b.get(a,"message","unkown error");e.tables.error=b.get(a,"response.data.detail.message",o),e.tables.state="error"}}});return{loadTables:t,loadTablesIfEmpty(){e.tables.empty&&t()},loadColumns:g.flow(function*(){var r;(r=e.controllers.columns)==null||r.abort(),e.controllers.columns=new AbortController,e.columns.state="loading";try{e.columns.data=yield*g.toGenerator($e.structure(e.controllers.columns.signal)({query_type:"COLUMNS",type:e.sqlDataSourceType,key:e.key,table_schema:e.table_schema,table_name:e.table_name},{params:{query_type:"COLUMNS"}})),e.columns.state="idle",e.columns.error=null}catch(a){if(ke.isCancel(a))e.columns.state="idle",e.columns.error=null;else{e.columns.data=[];const o=b.get(a,"message","unkown error");e.columns.error=b.get(a,"response.data.detail.message",o),e.columns.state="error"}}}),loadIndexes:g.flow(function*(){var r;(r=e.controllers.indexes)==null||r.abort(),e.controllers.indexes=new AbortController,e.indexes.state="loading";try{e.indexes.data=yield*g.toGenerator($e.structure(e.controllers.indexes.signal)({query_type:"INDEXES",type:e.sqlDataSourceType,key:e.key,table_schema:e.table_schema,table_name:e.table_name},{params:{query_type:"INDEXES"}})),e.indexes.state="idle",e.indexes.error=null}catch(a){if(ke.isCancel(a))e.indexes.state="idle",e.indexes.error=null;else{e.indexes.data=[];const o=b.get(a,"message","unkown error");e.indexes.error=b.get(a,"response.data.detail.message",o),e.indexes.state="error"}}}),loadTableData:g.flow(function*(){var a;(a=e.controllers.tableData)==null||a.abort(),e.controllers.tableData=new AbortController;const r=e.tableData;r.state="loading";try{r.data=yield*g.toGenerator($e.structure(e.controllers.tableData.signal)({query_type:"DATA",type:e.sqlDataSourceType,key:e.key,table_schema:e.table_schema,table_name:e.table_name,limit:r.limit,offset:r.offset},{params:{query_type:"DATA"}}));const[{total:o}]=yield*g.toGenerator($e.structure(e.controllers.tableData.signal)({query_type:"COUNT",type:e.sqlDataSourceType,key:e.key,table_schema:e.table_schema,table_name:e.table_name},{params:{query_type:"COUNT"}}));r.total=Number(o),r.state="idle",r.error=null}catch(o){if(ke.isCancel(o))r.state="idle",r.error=null;else{r.data=[];const l=b.get(o,"message","unkown error");r.error=b.get(o,"response.data.detail.message",l),r.state="error"}}})}}).actions(e=>({afterCreate(){g.addDisposer(e,G.reaction(()=>e.reloadConditionString,e.loadColumns,{fireImmediately:!1,delay:500}))}})).actions(e=>({afterCreate(){g.addDisposer(e,G.reaction(()=>e.reloadConditionString,e.loadIndexes,{fireImmediately:!1,delay:500})),g.addDisposer(e,G.reaction(()=>`${e.reloadConditionString};limit:${e.tableData.limit};offset:${e.tableData.offset}`,e.loadTableData,{fireImmediately:!1,delay:0}))}}));function cD(e,t){if(!t)throw new Error("Shouldnt run query without ID");if(e==="derived")return`/api/metric_management/derived_metric/${t}`;if(e==="combined")return`/api/metric_management/combined_metric/${t}`;throw new Error(`Unexpected metric type[${e}]`)}const dD=g.types.model({data:g.types.optional(g.types.frozen(),null),filters:g.types.optional(g.types.frozen(),[]),groupBys:g.types.optional(g.types.frozen(),[]),trendingDateCol:g.types.optional(g.types.frozen(),null),supportTrending:g.types.optional(g.types.boolean,!1),state:g.types.optional(g.types.enumeration(["idle","loading","error"]),"idle"),error:g.types.frozen()}).volatile(()=>({controller:new AbortController})).views(e=>({get loading(){return e.state==="loading"},get hasData(){return e.data!==null},get mmInfo(){return g.getParent(e)},get metricID(){return this.mmInfo.metricID},get metric(){return this.mmInfo.metric},get metricType(){var t;return(t=this.metric)==null?void 0:t.type},get filterColOptions(){return c2(e.filters)},get groupByColOptions(){return d2(e.groupBys)},get flatGroupByColOptions(){const t=this.groupByColOptions,r=[];return t.forEach(({group:a,items:o})=>{r.push(...o)}),r},getGroupByOptions(t){const r=new Set(t);return this.flatGroupByColOptions.filter(a=>r.has(a.value))}})).actions(e=>({load:g.flow(function*(){var t;if(e.mmInfo.type===W.MericoMetricSystem&&!(!e.metricID||!e.metricType)){(t=e.controller)==null||t.abort(),e.controller=new AbortController,e.state="loading";try{const r=cD(e.metricType,e.metricID),a=hn(e.mmInfo.dataSource,{url:r,method:"GET",data:{key:e.mmInfo.key}}),o=yield*g.toGenerator($e.mericoMetricInfo(e.controller.signal)({key:e.mmInfo.key,query:JSON.stringify(a),...e.mmInfo.additionalQueryInfo},e.controller.signal)),l=gn(e.mmInfo.dataSource,o),i=b.cloneDeep(l.data),{filters:c,groupBys:d,trendingDateCol:u,supportTrending:p}=i2(l.data);e.data=i,e.filters=c,e.groupBys=d,e.supportTrending=p,e.trendingDateCol=u,e.state="idle",e.error=null}catch(r){if(!ke.isCancel(r)){e.data=null;const a=b.get(r,"message","unkown error");e.error=b.get(r,"response.data.detail.message",a),e.state="error"}}}})})).actions(e=>({afterCreate(){g.addDisposer(e,G.reaction(()=>e.metricID+e.metricType,e.load,{fireImmediately:!0,delay:0}))}})),uD=g.types.model({keyword:g.types.optional(g.types.string,""),data:g.types.optional(g.types.frozen(),[]),state:g.types.optional(g.types.enumeration(["idle","loading","error"]),"idle"),error:g.types.frozen()}).volatile(()=>({controller:new AbortController})).views(e=>({get loading(){return e.state==="loading"},get empty(){return Object.keys(e.data).length===0},get mmInfo(){return g.getParent(e)}})).actions(e=>({setKeyword(t){e.keyword=t}})).actions(e=>({load:g.flow(function*(){var t;if(e.mmInfo.type===W.MericoMetricSystem){(t=e.controller)==null||t.abort(),e.controller=new AbortController,e.state="loading";try{const r=hn(e.mmInfo.dataSource,{url:"/api/metric_management/search",method:"POST",data:{key:e.mmInfo.key},params:{search:e.keyword}}),a=yield*g.toGenerator($e.mericoMetricInfo(e.controller.signal)({key:e.mmInfo.key,query:JSON.stringify(r),...e.mmInfo.additionalQueryInfo},e.controller.signal)),l=gn(e.mmInfo.dataSource,a).data;e.data=l,e.state="idle",e.error=null}catch(r){if(!ke.isCancel(r)){e.data=[];const a=b.get(r,"message","unkown error");e.error=b.get(r,"response.data.detail.message",a),e.state="error"}}}})})).actions(e=>({afterCreate(){g.addDisposer(e,G.reaction(()=>`${e.mmInfo.type}:${e.keyword}`,e.load,{fireImmediately:!0,delay:0}))}})),pD=g.types.model({metrics:g.types.optional(uD,{}),metricDetail:g.types.optional(dD,{}),keyword:g.types.optional(g.types.string,""),metricID:g.types.optional(g.types.string,"")}).views(e=>({get rootModel(){return g.getRoot(e)},get contentModel(){return this.rootModel.content},get additionalQueryInfo(){return this.contentModel.getAdditionalQueryInfo("")},get dataSource(){return g.getParent(e)},get key(){return this.dataSource.key},get type(){return this.dataSource.type},get metric(){return e.metricID?e.metrics.data.find(t=>t.id===e.metricID)??null:null}})).actions(e=>({selectMetric(t){e.metricID=t}})),hD=g.types.compose("DataSourceModel",Da,g.types.model({dbInfo:g.types.optional(iD,{}),mericoMetricInfo:g.types.optional(pD,{})})),gD=g.types.model("DataSourcesModel",{list:g.types.optional(g.types.array(hD),[])}).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)}}));function fD(e){return e.length===1&&e[0]==="_QUERY_VARS_"}function bD(e){return e.length===1&&e[0]==="_MOCK_CONTEXT_"}function yD(e){return e.length===1&&e[0]==="_FILTERS_"}function vD(e){return e.length===2&&e[0]==="_FILTERS_"}function _D(e){return e.length===1&&e[0]==="_SQL_SNIPPETS_"}function mD(e){return e.length===2&&e[0]==="_SQL_SNIPPETS_"}function wD(e){return e.length===2&&e[0]==="_QUERIES_"}function xD(e){return e.length===1&&e[0]==="_QUERIES_"}function CD(e){return e.length===2&&e[0]==="_VIEWS_"}function ts(e){return e.length===6&&e[0]==="_VIEWS_"&&e[2]==="_PANELS_"}function It(e){return{label:e,value:e,_type:"ACTION",_action_type:e,Icon:null,children:null}}function SD(e){switch(e._type){case"GROUP":case"ACTION":return null;case"query_variables":return["_QUERY_VARS_"];case"mock_context":return["_MOCK_CONTEXT_"];case"filter":return["_FILTERS_",e.value];case"sql_snippet":return["_SQL_SNIPPETS_",e.value];case"query":return["_QUERIES_",e.value];case"view":return["_VIEWS_",e.value];case"panel":return e.parentID?["_VIEWS_",e.parentID,"_PANELS_",e.value,"_TABS_","Data"]:(console.error("[getPathFromOption] parentID is required"),null)}}const TD=g.types.model("EditorModel",{path:g.types.optional(g.types.frozen(),[]),settings_open:g.types.optional(g.types.boolean,!1)}).views(e=>({get isPanelPath(){return ts(e.path)},get panelTab(){return this.isPanelPath?b.get(e.path,5,"Data"):null},get navOptions(){const{content:t}=g.getRoot(e),{filters:r,views:a,sqlSnippets:o,queries:l}=t;return[{label:"query_variable.labels",value:"_QUERY_VARS_",_type:"query_variables",Icon:S.IconVariable},{label:"mock_context.label",value:"_MOCK_CONTEXT_",Icon:S.IconCodeDots,_type:"mock_context"},{label:"filter.labels",value:"_FILTERS_",Icon:S.IconFilter,children:[It("_FILTERS_SETTINGS_"),...r.options,It("_Add_A_Filter_")],_type:"GROUP"},{label:"sql_snippet.labels",value:"_SQL_SNIPPETS_",Icon:S.IconCopy,children:[It("_SQL_SNIPPETS_SETTINGS_"),...o.options,It("_Add_A_SQL_SNIPPET_")],_type:"GROUP"},{label:"query.labels",value:"_QUERIES_",Icon:S.IconDatabase,children:[It("_QUERIES_SETTINGS_"),...l.options,It("_Add_A_QUERY_")],_type:"GROUP"},{label:"view.labels",value:"_VIEWS_",Icon:S.IconBoxMultiple,children:[...a.editorOptions,It("_Add_A_VIEW_")],_type:"GROUP"}]},isOptionActive(t,r){return t.length===0?!1:ts(t)?t[3]===r.value:t[t.length-1]===r.value},isOptionOpened(t){const{path:r}=e;return r.length===0||!t.children||t.children.length===0?!1:r.includes(t.value)}})).actions(e=>({setPath(t){e.path=t},setSettingsOpen(t){e.settings_open=t},openAndSetPath(t){this.setPath(t),e.settings_open||(e.settings_open=!0)}})).actions(e=>({setPanelTab(t){if(!e.isPanelPath||e.panelTab===t||!t)return;const r=b.clone(e.path);r[5]=t,e.setPath(r)},open(t){e.setPath(t),e.setSettingsOpen(!0)},close(){e.setSettingsOpen(!1)},navigate(t){const r=SD(t);r&&e.setPath(r)}})).views(e=>({get spotlightActionGroups(){const{content:t}=g.getRoot(e),{filters:r,views:a,sqlSnippets:o,queries:l}=t,i={group:"spotlight.main_group",actions:[{id:"query_variable.labels",title:"query_variable.labels",onClick:()=>e.openAndSetPath(["_QUERY_VARS_"]),iconKey:"query_variables"},{id:"mock_context.label",title:"mock_context.label",onClick:()=>e.openAndSetPath(["_MOCK_CONTEXT_"]),iconKey:"mock_context"},{id:"filter.labels",title:"filter.labels",onClick:()=>e.openAndSetPath(["_FILTERS_"]),iconKey:"filter"},{id:"sql_snippet.labels",title:"sql_snippet.labels",onClick:()=>e.openAndSetPath(["_SQL_SNIPPETS_"]),iconKey:"sql_snippet"},{id:"query.labels",title:"query.labels",onClick:()=>e.openAndSetPath(["_QUERIES_"]),iconKey:"query"}]},c={group:"filter.labels",actions:[]};r.options.forEach(f=>{c.actions.push({id:`_FILTERS_.${f.value}`,title:f.label,onClick:()=>e.openAndSetPath(["_FILTERS_",f.value]),iconKey:"filter"})});const d={group:"sql_snippet.labels",actions:[]};o.options.forEach(f=>{d.actions.push({id:`_SQL_SNIPPETS_.${f.value}`,title:f.label,onClick:()=>e.openAndSetPath(["_SQL_SNIPPETS_",f.value]),iconKey:"sql_snippet"})});const u={group:"query.labels",actions:[]};l.options.forEach(f=>{u.actions.push({id:`_QUERIES_.${f.value}`,title:f.label,onClick:()=>e.openAndSetPath(["_QUERIES_",f.value]),iconKey:"query"})});const p=[i,c,d,u];return a.editorOptions.forEach(f=>{const v={group:f.label,actions:[]};v.actions.push({id:`_VIEWS_.${f.value}`,title:f.label,onClick:()=>e.openAndSetPath(["_VIEWS_",f.value]),iconKey:"view",group:f.label}),f.children.forEach(_=>{_._type!=="ACTION"&&v.actions.push({id:`_VIEWS_._PANELS_.${_.value}`,title:_.label,viz:_.viz,onClick:()=>e.openAndSetPath(["_VIEWS_",f.value,"_PANELS_",_.value,"_TABS_","Panel"]),iconKey:"panel",group:f.label})}),p.push(v)}),p}})),kD=g.types.compose("LayoutsModel",Oa,g.types.model({currentLayoutWrapperWidth:g.types.optional(g.types.number,0)})).views(e=>({get divisionPreviewScale(){const t=e.currentLayoutPreviewWidth,r=e.currentLayoutWrapperWidth;return!t||!r||t<=r?1:r/t}})).actions(e=>({addALayoutItem(t){e.list.forEach(r=>{r.addNewLayout(t)})},duplicateLayoutItemsByPanelID(t,r){e.list.forEach(a=>{const o=a.findByPanelID(t);if(!o){console.error(`Can't find a layout item by panelID[${t}] in layoutSet[${a.name}]`);return}a.list.push({...o,id:Te.v4(),panelID:r,y:1/0})})},removeByPanelID(t){e.list.forEach(r=>{r.removeByPanelID(t)})},removeByPanelIDs(t){e.list.forEach(r=>{r.removeByPanelIDs(t)})},setCurrentLayoutWrapperWidth(t){e.currentLayoutWrapperWidth=t},addALayoutSet(t,r,a){const o=e.basisLayoutSet,l={id:t,name:r,breakpoint:a,list:o.json.list.map(i=>({...i,id:Te.v4()}))};e.list.push(l)},updateLayoutSetsInfo(t){const r=b.keyBy(e.list,"id");t.forEach(l=>{const i=r[l.id];if(i){i.setName(l.name),i.setBreakpoint(l.breakpoint),delete r[l.id];return}this.addALayoutSet(l.id,l.name,l.breakpoint)});const a=new Set(Object.keys(r)),o=a.size>0;a.forEach(l=>{const i=e.list.findIndex(c=>c.id===l);e.list.splice(i,1)}),o&&e.setCurrentBreakpoint("basis")},updateCurrentLayoutItem(t){e.currentLayoutSet.updateLayoutItem(t)},updateCurrentLayoutItems(t){t.forEach(r=>{e.currentLayoutSet.updateLayoutItem(r)})},append(t){e.list.push(t)},appendMultiple(t){t.length!==0&&e.list.push(...t)},remove(t){e.list.splice(t,1)},removeByID(t){const r=e.list.findIndex(a=>a.id===t);r!==-1&&e.list.splice(r,1)},removeByIDs(t){t.forEach(r=>{this.removeByID(r)})}})),Zc=Pa.views(e=>({get realQueryOptions(){return e.queryIDs.length===0?[]:e.queries.map(t=>({label:t.name,value:t.id,disabled:!1}))},queryOptions(t,r){const a=[...this.realQueryOptions];return t&&!a.find(o=>o.value===t)&&a.unshift({label:t,value:t,disabled:!0}),r&&a.unshift({label:"unset",value:"",disabled:!1}),a},get realVariableOptions(){const t=e.variableValueMap;return Object.entries(e.variableAggValueMap).map(([r,a])=>({label:r,value:r,formattedValue:t[r],aggValue:a,disabled:!1}))},variableOptions(t,r){const a=[...this.realVariableOptions];return t&&!a.find(o=>o.value===t)&&a.unshift({label:t,value:t,formattedValue:"",aggValue:"",disabled:!0}),r&&a.unshift({label:"unset",value:"",formattedValue:"",aggValue:"",disabled:!1}),a},explainDataKey(t){const{queryID:r,columnKey:a}=$(t),o=e.queries.find(l=>l.id===r);return o?{queryID:r,queryName:o.name,columnKey:a}:{queryID:r,queryName:null,columnKey:a}}})).actions(e=>({removeSelf(){g.getParent(e,2).removeByID(e.id)}})).actions(e=>({moveToView(t,r){g.getRoot(e).content.views.findByID(t).removePanelID(e.id),g.getRoot(e).content.views.findByID(r).appendPanelID(e.id),g.getRoot(e).editor.setPath(["_VIEWS_",r,"_PANELS_",e.id])}})),Jc=g.types.compose("PanelsModel",$a,g.types.model({list:g.types.optional(g.types.array(Zc),[])})).views(e=>({get contentModel(){return g.getRoot(e).content},get options(){return e.list.map(t=>({label:t.name,value:t.id,viz_type:t.viz.type}))},editorOptions(t,r){const a=e.panelsByIDs(r);a.length!==r.length&&console.warn(`Unfulfilled panels for View[${t}]`);const o=a.map(i=>({label:i.name,value:i.id,_type:"panel",parentID:t,viz:Jl[i.viz.type]})),l="_Add_A_PANEL_";return o.push({label:l,value:l,_type:"ACTION",_action_type:l,parentID:t,Icon:null,children:null}),o}})).actions(e=>({replace(t){e.list=g.castToSnapshot(t)},append(t){e.list.push(t)},appendMultiple(t){t.length!==0&&e.list.push(...t)},remove(t){e.list.splice(t,1)},removeByID(t){const r=e.list.findIndex(a=>a.id===t);r!==-1&&e.list.splice(r,1)},removeByIDs(t){t.forEach(r=>{this.removeByID(r)})},duplicateByID(t){const r=e.list.find(o=>o.id===t);if(!r){console.error(new Error(`[duplicate panel] Can't find a panel by id[${t}]`));return}const a=new Date().getTime().toString();return e.list.push({...r.json,id:a,title:{...r.json.title}}),e.contentModel.layouts.duplicateLayoutItemsByPanelID(r.id,a),a},replaceByIndex(t,r){e.list.splice(t,1,r)}})),DD=Ia.actions(e=>({getSchema(){const t=e.json,r=[],a=[];e.panels.forEach(i=>{const c=i.getSchema();r.push(c.panel),c.queries.length>0&&a.push(...c.queries)});const o=e.contentModel.layouts.jsonByPanelIDSet(new Set(e.panelIDs));return{views:[t],panels:r,definition:{queries:b.uniqBy(a,i=>i.id)},layouts:o,version:ct}},downloadSchema(){if(e.type===B.Tabs){console.error(new Error("Please choose a tab first"));return}const t=JSON.stringify(this.getSchema(),null,2),r=e.name;Gt(r,t)}})),Hc=g.types.compose("ViewsModel",Va,g.types.model({current:g.types.optional(g.types.array(DD),[]),idOfVIE:g.types.string})).views(e=>({get isVIETheFirstView(){return e.current.length===0||!e.idOfVIE?!1:e.current[0].id===e.idOfVIE},get VIE(){return e.current.find(({id:t})=>t===e.idOfVIE)},get options(){return e.current.map(t=>({label:t.name,value:t.id,type:t.type}))},get tabViewOptions(){return this.options.filter(t=>t.type===B.Tabs)},tabOptions(t){const r=e.current.find(a=>a.id===t&&a.type===B.Tabs&&a.tabs.length>0);return r?r.tabs.map(a=>({label:a.name,value:a.id})):[]},get editorOptions(){const t=g.getRoot(e).content.panels;return e.current.map(r=>({label:r.name,value:r.id,_type:"view",children:t.editorOptions(r.id,r.panelIDs)}))},get contentModel(){return g.getRoot(e).content}})).actions(e=>({setIDOfVIE(t){e.idOfVIE=t,e.visibleViewIDs.length=0,e.visibleViewIDs.push(t)},resetIDOfVIE(){this.setIDOfVIE(e.current[0].id)},replace(t){e.current.replace(t)},addANewView(t,r,a,o){e.current.push({id:t,name:r,type:a,config:o,panelIDs:[]})},append(t){e.current.push(t)},appendMultiple(t){t.length!==0&&e.current.push(...t)},remove(t){e.current.splice(t,1)},removeByID(t){const r=e.current.findIndex(i=>i.id===t);if(r===-1)return;const a=e.current[r],o=e.contentModel.panels,l=e.contentModel.layouts;o.removeByIDs(a.panelIDs),l.removeByPanelIDs(a.panelIDs),e.current.splice(r,1),this.resetIDOfVIE()},replaceByIndex(t,r){e.current.splice(t,1,r)},addARandomNewView(){const t=new Date().getTime().toString();this.addANewView(t,B.Division,B.Division,{_name:B.Division}),this.setIDOfVIE(t)},removeVIE(){e.current.length!==1&&(this.removeByID(e.idOfVIE),this.resetIDOfVIE())}}));function ns(e){const t=e.length>0?[e[0].id]:[],r=e.length>0?e[0].id:"";return{current:e.map(o=>{const{_name:l=o.type}=o.config;return{...o,config:{...o.config,_name:l},panelIDs:o.panelIDs}}),visibleViewIDs:t,idOfVIE:r}}const zD=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:Uc,queries:Yc,sqlSnippets:Xc,views:Hc,panels:Jc,layouts:kD,mock_context:ia,origin:g.types.maybe(g.types.frozen())}).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 filtersChanged(){const t="filters.current";return!b.isEqual(g.getSnapshot(b.get(e,t)),b.get(e.origin,t))},get queriesChanged(){const t="queries.current",r=g.getSnapshot(b.get(e,t)).map(o=>b.pick(o,["id","name","key","type","run_by","pre_process","post_process","config"])),a=b.get(e.origin,t);return!b.isEqual(r,a)},get sqlSnippetsChanged(){const t="sqlSnippets.current";return!b.isEqual(g.getSnapshot(b.get(e,t)),b.get(e.origin,t))},get viewsChanged(){const t="views.current";return!b.isEqual(e.views.json,b.get(e.origin,t))},get panelsChanged(){const t="panels.list";return!b.isEqual(g.getSnapshot(b.get(e,t)),b.get(e.origin,t))},get layoutsChanged(){const t="layouts.list";return!b.isEqual(g.getSnapshot(b.get(e,t)),b.get(e.origin,t))},get mockContextChanged(){const t="mock_context.current";return!b.isEqual(b.get(e,t),b.get(e.origin,t))},get context(){const t=g.getParent(e).context.current;return{...e.mock_context.current,...t}},get payloadForSQL(){const t=g.getParent(e).globalSQLSnippets,r={context:this.context,filters:e.filters.valuesForPayload};return{...r,sql_snippets:Rt(e.sqlSnippets.current,"key","value",r),global_sql_snippets:Rt(t.list,"id","content",r)}},get payloadForViz(){return{context:this.context,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(([o,l])=>{a.context[o]={key:o,type:"context",value:l}}),a},get dashboardStateValues(){return br(this.payloadForSQL)},get dashboardStateVariableOptions(){if(!g.isAlive(e))return{optionGroups:[],validValues:new Set};const t=new Set,{context:r}=this.payloadForSQL,a={group:"context.label",items:Object.keys(r).map(i=>{const c=`context.${i}`;return t.add(c),{label:i,value:c,description:void 0,type:"context"}})},o={group:"filter.labels",items:e.filters.keyLabelOptions.map(i=>{const c=`filters.${i.value}`;return t.add(c),{label:i.label,value:c,description:i.value,type:"filter",widget:i.widget}})};return{optionGroups:[a,o],validValues:t}},getAdditionalQueryInfo(t){return{content_id:e.id,query_id:t,params:this.dashboardStateValues}},get changed(){return this.filtersChanged||this.queriesChanged||this.sqlSnippetsChanged||this.viewsChanged||this.panelsChanged||this.layoutsChanged||this.mockContextChanged},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}:{data:[],len:0,state:"idle",error:void 0}}})).views(e=>({get filtersUsage(){const t=[],r=e.views.idMap;e.filters.current.forEach(o=>{o.visibleInViewsIDs.forEach(l=>{var i;t.push({filterID:o.id,type:"view",type_label:"view.label",id:l,label:((i=r.get(l))==null?void 0:i.name)??l})})});const a=e.filters.keyIDMap;return e.queries.current.forEach(o=>{o.usedFilterKeySet.forEach(l=>{t.push({filterID:a[l]??l,type:"query",type_label:"query.label",id:o.id,label:o.name})})}),e.sqlSnippets.usedFilterKeyMap.forEach((o,l)=>{o.forEach(i=>{t.push({filterID:a[i]??i,type:"sql_snippet",type_label:"sql_snippet.label",id:l,label:l})})}),b.groupBy(t,"filterID")},findFilterUsage(t){return this.filtersUsage[t]??[]},get queriesUsage(){const t=e.panels.idMap,r=[];e.views.current.forEach(o=>{o.panelIDs.forEach(l=>{const i=t.get(l);if(!i)return;const c="panel",d=i.name,u=[{id:o.id,label:o.name}];i.queryIDs.forEach(p=>{r.push({id:l,queryID:p,type:c,type_label:"panel.label",label:d,views:u})})})});const a=e.views.idMap;return e.filters.current.filter(o=>!!b.get(o,"config.options_query_id")).forEach(o=>{r.push({type:"filter",type_label:"filter.label",id:o.id,queryID:b.get(o,"config.options_query_id"),label:o.label,views:o.visibleInViewsIDs.map(l=>{var i;return{id:l,label:((i=a.get(l))==null?void 0:i.name)??l}})})}),e.queries.current.forEach(o=>{if(!o.isTransform)return;o.config.dep_query_ids.forEach(i=>{r.push({type:"transform-query",type_label:"query.transform.full_label",id:o.id,queryID:i,label:o.name,views:[]})})}),b.groupBy(r,"queryID")},get hasUnusedQueries(){return e.queries.current.length>Object.keys(this.queriesUsage).length},findQueryUsage(t){return this.queriesUsage[t]??[]},get sqlSnippetsUsage(){const t=[];return e.queries.current.forEach(r=>{if(!r.typedAsSQL)return;const a=r.config;b.uniq(a.sql.match(Et.sqlSnippet)).forEach(l=>{t.push({queryID:r.id,sqlSnippetKey:l,queryName:r.name})})}),b.groupBy(t,"sqlSnippetKey")},get hasUnusedSQLSnippets(){return e.sqlSnippets.current.length>Object.keys(this.sqlSnippetsUsage).length},findSQLSnippetUsage(t){return this.sqlSnippetsUsage[t]??[]}})).actions(e=>({removeUnusedQueries(){const t=new Set(Object.keys(e.queriesUsage)),r=e.queries.current.filter(a=>!t.has(a.id)).map(a=>a.id);e.queries.removeQueries(r)},removeUnusedSQLSnippets(){const t=new Set(Object.keys(e.sqlSnippetsUsage)),r=e.sqlSnippets.current.filter(a=>!t.has(a.key)).map(a=>a.key);e.sqlSnippets.removeByKeys(r)},duplicatePanelByID(t,r){var o;const a=e.panels.duplicateByID(t);a&&((o=e.views.findByID(r))==null||o.appendPanelID(a))},removePanelByID(t,r){var a;e.panels.removeByID(t),e.layouts.removeByPanelID(t),(a=e.views.findByID(r))==null||a.removePanelID(t)},addANewPanel(t){var a;const r=Te.v4();e.panels.append(Zi(r)),(a=e.views.findByID(t))==null||a.appendPanelID(r),e.layouts.addALayoutItem(r)},applyJSONSchema(t){var f;const{views:r,panels:a,filters:o,definition:l={},layouts:i}=t,{queries:c,sqlSnippets:d,mock_context:u}=l,p=new Map;if(Array.isArray(a)){const v=a.map(_=>{const w=Te.v4();return p.set(_.id,w),{..._,id:w}});if(e.panels.appendMultiple(v),!Array.isArray(r)||r.length===0){const _=v.map(w=>w.id);(f=e.views.VIE)==null||f.appendPanelIDs(_)}}if(Array.isArray(r)){const v=r.map(_=>{const w=_.panelIDs.map(x=>p.get(x)??x);return{..._,id:Te.v4(),panelIDs:w}});e.views.appendMultiple(v)}if(Array.isArray(i)){const v=(x,T)=>e.layouts.breakpointNameRecord[x]===T;let _=[];const w=i.filter(x=>v(x.name,x.breakpoint));w.forEach(x=>{x.id==="basis"&&(_=x.list),x.list.forEach(T=>{const D=p.get(T.panelID);T.id=Te.v4(),T.panelID=D})}),e.layouts.list.forEach(x=>{const T=w.find(D=>D.name===x.name&&D.breakpoint===x.breakpoint);if(!T){_.forEach(D=>{x.addLayout(D)});return}T.list.forEach(D=>{x.addLayout(D)})})}Array.isArray(o)&&e.filters.appendMultiple(o),Array.isArray(c)&&e.queries.appendMultiple(c),Array.isArray(d)&&e.sqlSnippets.appendMultiple(d),u&&Object.keys(u).length>0&&e.mock_context.defaults(u)}})).actions(e=>({reset(){g.applySnapshot(e.filters.current,e.origin.filters.current),g.applySnapshot(e.queries.current,e.origin.queries.current),g.applySnapshot(e.sqlSnippets.current,e.origin.sqlSnippets.current),g.applySnapshot(e.views.current,e.origin.views.current),g.applySnapshot(e.panels.list,e.origin.panels.list),g.applySnapshot(e.layouts.list,e.origin.layouts.list),e.mock_context.current=e.origin.mock_context.current},resetFilters(){g.applySnapshot(e.filters.current,e.origin.filters.current)},updateCurrent(t){const{id:r,name:a,content:o}=t;if(!o)throw new Error("unexpected null content when updating a content model");const{version:l,filters:i,views:c,panels:d,definition:{queries:u,sqlSnippets:p,mock_context:f={}}}=o;e.id=r,e.name=a,e.version=l,g.applySnapshot(e.filters.current,i),g.applySnapshot(e.views.current,ns(c).current),g.applySnapshot(e.panels.list,d),g.applySnapshot(e.queries.current,u),g.applySnapshot(e.sqlSnippets.current,p),e.mock_context.current=f}})),rs=g.types.snapshotProcessor(zD,{preProcessor(e){return{...e,origin:e}},postProcessor(e){delete e.origin;const t=g.castToSnapshot(e.queries.current.map(r=>b.pick(r,["id","key","type","sql"])));return b.defaults({},{queries:{current:t}},e)}});function MD(e,t){t.filters&&g.applySnapshot(e.filters.current,t.filters)}function Rc({id:e,name:t,dashboard_id:r,create_time:a,update_time:o,content:l},i,c){if(!l)throw new Error("unexpected null content when creating a content model");const{version:d,filters:u,views:p,panels:f,layouts:v,definition:{queries:_,sqlSnippets:w,mock_context:x={}}}=l;return rs.create({id:e,name:t,dashboard_id:r,create_time:a,update_time:o,version:d,filters:Ea(u,i,x,c),queries:{current:_},sqlSnippets:{current:w},mock_context:ca(x),views:ns(p),panels:{list:f},layouts:{list:v,currentBreakpoint:v[0].id}})}const ed=g.types.model({id:g.types.identifier,name:g.types.string,group:g.types.string,content:rs,content_id:g.types.string,datasources:gD,globalSQLSnippets:za,context:An,editor:TD}).views(e=>({get json(){return{id:e.id,name:e.name,group:e.group,content_id:e.content_id}},get queryVariables(){return{context:{...e.content.mock_context.current,...e.context.current},filters:e.content.filters.previewValues}},get queryVariablesString(){return JSON.stringify(this.queryVariables,null,2)}})).actions(e=>({updateCurrentContent(t){e.content.updateCurrent(t)},updateCurrent(t,r){const{id:a,name:o,group:l,content_id:i}=t;e.id=a,e.name=o,e.group=l,e.content_id=i,this.updateCurrentContent(r)}}));function td({id:e,name:t,group:r,content_id:a},o,l,i,c,d){return ed.create({id:e,name:t,group:r,content_id:a,content:Rc(o,c,d),datasources:{list:l},globalSQLSnippets:{list:i},context:Ma(c),editor:{}})}function Ft(e){console.groupCollapsed("Running operation ",e.type),console.log(e),console.groupEnd()}function nd(e,t){h.useEffect(()=>{const a=o=>{Ft(o);const{viewID:l}=o.detail;if(!l){console.error(new Error("[Open View] Needs to pick a view first"));return}e.views.appendToVisibles(l),t&&e.views.setIDOfVIE(l)};return window.addEventListener("open-view",a),()=>{window.removeEventListener("open-view",a)}},[e,t]);const r=zu.useNavigate();h.useEffect(()=>{const a=o=>{Ft(o);const{panelID:l}=o.detail;if(!l){console.error(new Error("[Scroll to Panel] Needs to pick a panel first"));return}r(`#${l}`),setTimeout(()=>{const i=document.getElementById(l);i&&i.scrollIntoView({behavior:"smooth"})},300)};return window.addEventListener("scroll_to_panel",a),()=>{window.removeEventListener("scroll_to_panel",a)}},[r]),h.useEffect(()=>{const a=o=>{Ft(o);const{viewID:l,tab:i}=o.detail;if(!l){console.error(new Error("[Switch Tab] Needs to pick a view and a tab first"));return}const c=e.views.findByID(l);if(!c){console.error(new Error(`[Switch Tab] View by ID[${l}] is not found`));return}c.setTab(i)};return window.addEventListener("switch_tab",a),()=>{window.removeEventListener("switch_tab",a)}},[e,t]),h.useEffect(()=>{const a=o=>{Ft(o);const{dictionary:l,payload:i}=o.detail;if(!i||Object.keys(i).length===0){console.error(new Error("[Set Filter Values] payload is empty"));return}const c={};Object.entries(l).forEach(([d,u])=>{const p=b.get(i,u);c[d]=p}),e.filters.applyValuesPatch(c)};return window.addEventListener("set-filter-values",a),()=>{window.removeEventListener("set-filter-values",a)}},[e]),h.useEffect(()=>{function a(l){return Array.isArray(l)?[]:typeof l=="object"?{}:typeof l=="boolean"?!1:typeof l=="string"?"":typeof l=="number"?0:l}const o=l=>{Ft(l);const i={},{filter_keys:c}=l.detail;c.forEach(d=>{const u=b.get(e.filters.values,d),p=a(u);i[d]=p}),e.filters.applyValuesPatch(i)};return window.addEventListener("clear-filter-values",o),()=>{window.removeEventListener("clear-filter-values",o)}},[e]),h.useEffect(()=>{const a=o=>{Ft(o);const{urlTemplate:l,openInNewTab:i,enableEncoding:c=!1,payload:d}=o.detail;if(!l){console.error(new Error("[Open Link] URL is empty"));return}function u(v){return b.cloneDeepWith(v,w=>{if(c&&typeof w=="string")return encodeURIComponent(w)})}const f=b.template(l||"")(u({...d,filters:e.payloadForSQL.filters,context:e.payloadForSQL.context}));window.open(f,i?"_blank":"_self","noopener")};return window.addEventListener("open-link",a),()=>{window.removeEventListener("open-link",a)}},[e])}function rd(e){return h.useCallback(t=>t.provideValue(ee.pluginManager,e.pluginManager).provideValue(ee.vizManager,e.vizManager).provideValue(ee.panelAddonManager,e.panelAddonManager).provideValue(ee.colorManager,e.colorManager),[e])}const HI="",ID=k.observer(({saveDashboardChanges:e})=>{const{t}=m.useTranslation(),r=De.useModals(),a=F(),o=()=>{r.openConfirmModal({title:n.jsxs(s.Group,{justify:"flex-start",children:[n.jsx(S.IconAlertTriangle,{size:18,color:"red"}),n.jsx(s.Text,{size:"sm",children:"You are reverting changes"})]}),labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},confirmProps:{color:"red"},onCancel:()=>console.log("Cancel"),onConfirm:()=>a.reset(),zIndex:320,withCloseButton:!1})},l=a.changed;return n.jsxs(s.Group,{gap:0,children:[n.jsx(s.Button,{color:"green",variant:"filled",size:"xs",leftSection:n.jsx(S.IconDeviceFloppy,{size:18}),onClick:e,disabled:!l,sx:{borderTopRightRadius:0,borderBottomRightRadius:0},children:t("common.actions.save_changes")}),n.jsxs(s.Menu,{width:200,trigger:"hover",openDelay:100,closeDelay:400,withinPortal:!0,zIndex:320,disabled:!l,children:[n.jsx(s.Menu.Target,{children:n.jsx(s.ActionIcon,{variant:"default",disabled:!l,sx:{height:"30px",borderTopLeftRadius:0,borderBottomLeftRadius:0,svg:{fill:"rgb(173, 181, 189)",stroke:"none"}},children:n.jsx(S.IconCaretDown,{size:18})})}),n.jsx(s.Menu.Dropdown,{children:n.jsx(s.Menu.Item,{leftSection:n.jsx(S.IconRecycle,{size:14,color:"red"}),disabled:!l,onClick:o,children:t("common.actions.revert_changes")})})]})]})}),VD=k.observer(({saveDashboardChanges:e,onExit:t,headerSlot:r=null})=>{m.useTranslation();const a=j(),o=a.content.changed,l=()=>{t({hasChanges:o,dashboardId:a.id})};return n.jsx(s.AppShell.Header,{h:60,py:0,px:"md",sx:{zIndex:299},children:n.jsxs(s.Group,{justify:"space-between",sx:{height:60,minWidth:"1000px",position:"relative"},children:[n.jsxs(s.Group,{children:[n.jsx(s.Button,{size:"xs",color:o?"red":"green",leftSection:n.jsx(S.IconArrowLeft,{size:20}),onClick:l,children:n.jsx(s.Group,{gap:4,children:n.jsx(m.Trans,{i18nKey:"common.actions.end_editing",values:{name:a.name},children:n.jsx(s.Text,{td:"underline",size:"xs",children:a.name})})})}),n.jsx(ID,{saveDashboardChanges:e})]}),n.jsx(s.Group,{justify:"flex-end",sx:{flexGrow:1},children:r})]})})}),ad={height:"30px",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},PD=k.observer(()=>{var o;const{t:e}=m.useTranslation(),t=F(),r=((o=t.views.VIE)==null?void 0:o.type)===B.Tabs,a=()=>t.addANewPanel(t.views.idOfVIE);return r?n.jsx(s.Tooltip,{label:e("common.choose_a_tab_first"),children:n.jsx(s.Button,{variant:"outline",color:"gray",radius:0,size:"xs",leftSection:n.jsx(S.IconPlaylistAdd,{size:20}),sx:{...ad,transform:"none !important"},children:e("panel.add")})}):n.jsx(s.Button,{variant:"outline",color:"blue",radius:0,size:"xs",onClick:a,leftSection:n.jsx(S.IconPlaylistAdd,{size:20}),sx:{...ad,background:"rgb(231, 245, 255)"},children:e("panel.add")})}),$D=k.observer(({done:e})=>{var A,U;const{t}=m.useTranslation(),a=F().layouts,o=h.useMemo(()=>({list:a.breakpointsInfo}),[a.breakpointsInfo]),{control:l,handleSubmit:i,watch:c,getValues:d,reset:u,formState:p}=y.useForm({defaultValues:o}),{fields:f,append:v,remove:_}=y.useFieldArray({control:l,name:"list",rules:{validate:N=>{if(b.uniqBy(N,"breakpoint").length!==N.length)return"Screen sizes should be unique by min width"}}}),w=c("list"),x=f.map((N,oe)=>({...N,...w[oe]})),T=()=>{v({id:Te.v4(),name:"",breakpoint:""})},D=({list:N})=>{const oe=N.filter(be=>Number.isFinite(be.breakpoint));a.updateLayoutSetsInfo(oe),e()},z=d(),I=h.useMemo(()=>{const N={list:z.list.filter(oe=>!!oe.name&&Number.isFinite(oe.breakpoint))};return!b.isEqual(N,o)},[z,o]),E=(U=(A=p.errors.list)==null?void 0:A.root)==null?void 0:U.message;return n.jsx(n.Fragment,{children:n.jsxs("form",{onSubmit:i(D),children:[n.jsxs(s.Table,{fz:"sm",highlightOnHover:!0,withTableBorder:!0,sx:{tableLayout:"fixed"},children:[n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{style:{width:"340px"},children:t("common.name")}),n.jsx(s.Table.Th,{style:{width:"160px"},children:t("breakpoint.breakpoint")}),n.jsx(s.Table.Th,{})]})}),n.jsxs(s.Table.Tbody,{children:[x.map((N,oe)=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:N.id==="basis"?N.name:n.jsx(y.Controller,{name:`list.${oe}.name`,control:l,render:({field:be})=>n.jsx(s.TextInput,{size:"xs",label:"",required:!0,sx:{flex:1},...be})})}),n.jsx(s.Table.Td,{children:N.id==="basis"?n.jsxs(s.Text,{size:"sm",ff:"monospace",children:[N.breakpoint,"px"]}):n.jsx(y.Controller,{name:`list.${oe}.breakpoint`,control:l,render:({field:be})=>n.jsx(s.NumberInput,{size:"xs",label:"",required:!0,max:1e4,hideControls:!0,rightSection:n.jsx(s.Text,{size:"sm",c:"dimmed",children:"px"}),rightSectionProps:{style:{width:"30px"}},sx:{flex:1},ff:"monospace",styles:{input:{paddingRight:"30px"}},...be})})}),n.jsx(s.Table.Td,{children:N.id!=="basis"&&n.jsx(s.ActionIcon,{mx:"auto",size:"xs",variant:"subtle",color:"red",onClick:()=>_(oe),children:n.jsx(S.IconTrash,{})})})]},N.id)),n.jsx(s.Table.Tr,{style:{backgroundColor:"transparent"},children:n.jsx(s.Table.Td,{colSpan:3,style:{padding:"0"},children:n.jsx(s.Tooltip,{label:t("breakpoint.add"),children:n.jsx(s.ActionIcon,{variant:"subtle",size:"md",color:"blue",onClick:T,sx:{width:"100%"},children:n.jsx(S.IconPlus,{size:18})})})})})]})]}),n.jsx(s.Text,{mt:6,ta:"right",size:"xs",c:"red",children:E??" "}),n.jsxs(s.Group,{mt:6,justify:"space-between",children:[n.jsx(s.Button,{color:"orange",size:"xs",onClick:()=>u(),leftSection:n.jsx(S.IconRecycle,{size:18}),disabled:!I,children:t("common.actions.revert")}),n.jsx(s.Button,{color:"green",size:"xs",type:"submit",leftSection:n.jsx(S.IconDeviceFloppy,{size:18}),disabled:!I,children:t("common.actions.save_changes")})]})]})})}),AD=k.observer(()=>{const{t:e}=m.useTranslation(),[t,{open:r,close:a}]=te.useDisclosure(!1),o=F(),l=o.layouts.currentBreakpoint,i=o.layouts.currentLayoutRange,c=()=>{setTimeout(()=>{window.dispatchEvent(new Event("resize"))},32)},d=()=>{a(),c()};return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{children:[n.jsxs(s.Menu,{withArrow:!0,withinPortal:!0,zIndex:320,trigger:"hover",children:[n.jsx(s.Menu.Target,{children:n.jsx(s.Button,{size:"xs",variant:"subtle",leftSection:n.jsx(S.IconDevices,{size:16}),sx:{borderRadius:0},children:n.jsxs(s.Group,{gap:6,children:[n.jsx(s.Text,{size:"xs",fw:"normal",children:i.name}),n.jsx(s.Text,{size:"xs",c:"#777",children:o.layouts.currentRangeText})]})})}),n.jsxs(s.Menu.Dropdown,{children:[o.layouts.breakpointRanges.map(u=>n.jsx(s.Menu.Item,{onClick:()=>o.layouts.setCurrentBreakpoint(u.id),disabled:l===u.id,children:n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Text,{size:"sm",children:u.name}),n.jsx(s.Text,{size:"xs",c:"dimmed",children:u.text})]})},u.id)),n.jsx(s.Menu.Divider,{}),n.jsx(s.Menu.Item,{color:"blue",leftSection:n.jsx(S.IconSettings,{size:14}),onClick:r,children:n.jsx(s.Text,{size:"sm",children:e("breakpoint.manage")})})]})]}),o.layouts.divisionPreviewScale<1&&n.jsx(s.Text,{size:"xs",c:"dimmed",children:Ee(o.layouts.divisionPreviewScale).format({output:"percent",mantissa:0})})]}),n.jsx(s.Modal,{opened:t,onClose:d,title:e("breakpoint.label",{count:2}),withinPortal:!0,zIndex:320,size:600,closeOnClickOutside:!1,children:n.jsx($D,{done:d})})]})}),sd={height:"30px",borderRight:"none",borderTop:"none",borderLeft:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},ED=k.observer(()=>{var o;const{t:e}=m.useTranslation(),t=F(),r=((o=t.views.VIE)==null?void 0:o.type)===B.Tabs,a=()=>{var l;return(l=t.views.VIE)==null?void 0:l.downloadSchema()};return r?n.jsx(s.Tooltip,{label:e("common.choose_a_tab_first"),children:n.jsx(s.Button,{variant:"outline",color:"gray",radius:0,size:"xs",leftSection:n.jsx(S.IconCode,{size:16}),sx:{...sd,transform:"none !important"},children:e("view.download_schema")})}):n.jsx(s.Button,{variant:"outline",color:"blue",radius:0,size:"xs",onClick:a,leftSection:n.jsx(S.IconCode,{size:16}),sx:{...sd},children:e("view.download_schema")})}),Ln=({headers:e,rows:t})=>n.jsxs(s.Table,{fz:"xs",highlightOnHover:!0,sx:{tableLayout:"fixed",fontFamily:"monospace"},children:[n.jsx(s.Table.Thead,{children:e}),n.jsx(s.Table.Tbody,{children:t})]}),BD=({content:e})=>{const{t}=m.useTranslation(),r=e.views;return!Array.isArray(r)||r.length===0?null:n.jsxs(s.Box,{children:[n.jsx(s.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:t("view.labels")}),n.jsx(Ln,{headers:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{style:{width:"160px"},children:t("common.id")}),n.jsx(s.Table.Th,{children:t("common.name")}),n.jsx(s.Table.Th,{children:t("common.type")})]}),rows:r.map(a=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:a.id}),n.jsx(s.Table.Td,{children:a.name}),n.jsx(s.Table.Td,{children:t(`view.component.${a.type}.label`)})]},a.id))})]})},qD=({content:e})=>{const{t}=m.useTranslation(),r=e.filters;return!Array.isArray(r)||r.length===0?null:n.jsxs(s.Box,{children:[n.jsx(s.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:t("filter.labels")}),n.jsx(Ln,{headers:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{style:{width:"160px"},children:t("common.id")}),n.jsx(s.Table.Th,{children:t("common.key")}),n.jsx(s.Table.Th,{children:t("common.label")})]}),rows:r.map(a=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:a.id}),n.jsx(s.Table.Td,{children:a.key}),n.jsx(s.Table.Td,{children:a.label})]},a.id))})]})},LD=({content:e})=>{const{t}=m.useTranslation(),r=e.panels;return!Array.isArray(r)||r.length===0?null:n.jsxs(s.Box,{children:[n.jsx(s.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:t("panel.labels")}),n.jsx(Ln,{headers:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{style:{width:"160px"},children:t("common.id")}),n.jsx(s.Table.Th,{children:t("common.name")}),n.jsx(s.Table.Th,{children:t("visualization.component")})]}),rows:r.map(a=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:a.id}),n.jsx(s.Table.Td,{children:a.name}),n.jsx(s.Table.Td,{children:a.viz.type})]},a.id))})]})},OD=({content:e})=>{var a;const{t}=m.useTranslation(),r=(a=e.definition)==null?void 0:a.queries;return!Array.isArray(r)||r.length===0?null:n.jsxs(s.Box,{children:[n.jsx(s.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:t("query.labels")}),n.jsx(Ln,{headers:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{style:{width:"160px"},children:t("common.id")}),n.jsx(s.Table.Th,{children:t("common.name")}),n.jsx(s.Table.Th,{style:{width:"140px"},children:t("common.type")}),n.jsx(s.Table.Th,{style:{width:"260px"},children:t("data_source.label")})]}),rows:r.map(o=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:o.id}),n.jsx(s.Table.Td,{children:o.name}),n.jsx(s.Table.Td,{children:o.type}),n.jsx(s.Table.Td,{children:o.key})]},o.id))})]})},ND=({content:e})=>{var a;const{t}=m.useTranslation(),r=(a=e.definition)==null?void 0:a.sqlSnippets;return!Array.isArray(r)||r.length===0?null:n.jsxs(s.Box,{children:[n.jsx(s.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:t("sql_snippet.labels")}),n.jsx(s.List,{size:"sm",pl:10,ff:"monospace",icon:n.jsx(S.IconPointFilled,{size:10}),children:r.map(o=>n.jsx(s.List.Item,{children:o.key},o.key))})]})},GD=({content:e})=>{var a;const{t}=m.useTranslation(),r=Object.keys(((a=e.definition)==null?void 0:a.mock_context)??{});return r.length===0?null:n.jsxs(s.Box,{children:[n.jsx(s.Text,{pl:10,size:"sm",fw:500,c:"dimmed",ta:"center",children:t("mock_context.label")}),n.jsx(s.List,{size:"sm",pl:10,ff:"monospace",icon:n.jsx(S.IconPointFilled,{size:10}),children:r.map(o=>n.jsx(s.List.Item,{children:o},o))})]})},FD=({content:e})=>e?n.jsxs(s.Box,{children:[n.jsx(s.Divider,{mt:20,mb:10,variant:"dashed"}),n.jsx(s.Text,{ta:"left",c:"dimmed",size:"sm",children:"Preview"}),n.jsxs(s.Stack,{children:[n.jsx(BD,{content:e}),n.jsx(qD,{content:e}),n.jsx(LD,{content:e}),n.jsx(OD,{content:e}),n.jsx(ND,{content:e}),n.jsx(GD,{content:e})]})]}):null;function QD(e){if(e.target===null)throw new Error("FileReader failed with null result");if(typeof e.target.result!="string")throw new Error(`Unparsable file content of type: ${typeof e.target.result}`);let t=JSON.parse(e.target.result);if("content"in t&&(t=t.content),t.version!==ct)throw new Error("Schema version mismatch");return t}const jD=k.observer(({onSuccess:e,stretchModal:t,shrinkModal:r})=>{var D,z;const{t:a}=m.useTranslation(),o=F(),{handleSubmit:l,formState:{errors:i},setValue:c,watch:d,setError:u,clearErrors:p}=y.useForm({defaultValues:{content:null}}),f=({content:I})=>{try{if(!I)throw new Error("please use a valid json file");o.applyJSONSchema(I),Ge.showNotification({title:"Successful",message:"",color:"green"}),e()}catch(E){console.error(E),Ge.showNotification({title:"Failed",message:E.message,color:"red"})}},[v,_]=h.useState(null);h.useEffect(()=>{if(!v)return;const I=new FileReader;I.readAsText(v,"UTF-8"),I.onload=E=>{try{const A=QD(E);c("content",A),p("content")}catch(A){console.error(A),u("content",{type:"custom",message:A.message})}},I.onabort=()=>console.log("🟨 abort"),I.onerror=()=>{I.error&&(console.error(I.error),u("content",{type:"custom",message:I.error.message}))}},[v]);const[w]=d(["content"]),x=!w,T=(D=i==null?void 0:i.content)==null?void 0:D.message;return h.useEffect(()=>{!w||T?r():t()},[w,T]),n.jsx(s.Box,{mx:"auto",sx:{position:"relative"},children:n.jsxs("form",{onSubmit:l(f),children:[n.jsx(s.FileInput,{label:a("import.json_file"),required:!0,value:v,onChange:_,error:(z=i==null?void 0:i.content)==null?void 0:z.message,sx:{maxWidth:500}}),T?n.jsx(s.Table,{fz:12,mt:10,children:n.jsxs(s.Table.Tbody,{children:[n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:a("import.this_dashboard")}),n.jsx(s.Table.Td,{children:ct})]}),n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:a("import.this_file")}),n.jsx(s.Table.Td,{style:{color:"red"},children:w==null?void 0:w.version})]})]})}):n.jsxs(n.Fragment,{children:[n.jsx(FD,{content:w}),n.jsx(s.Group,{justify:"flex-end",my:"md",children:n.jsx(s.Button,{type:"submit",color:"green",disabled:x,children:a("common.actions.confirm")})})]})]})})}),od={height:"30px",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef"},WD=k.observer(()=>{var u;const{t:e}=m.useTranslation(),[t,{open:r,close:a}]=te.useDisclosure(!1),[o,{setTrue:l,setFalse:i}]=O.useBoolean(!1),d=((u=j().content.views.VIE)==null?void 0:u.type)===B.Tabs;return d?n.jsx(s.Tooltip,{label:e("common.choose_a_tab_first"),children:n.jsx(s.Button,{variant:"outline",color:"gray",radius:0,size:"xs",leftSection:n.jsx(S.IconFileImport,{size:16}),sx:{...od,transform:"none !important"},children:e("import.label")})}):n.jsxs(n.Fragment,{children:[n.jsx(s.Button,{variant:"subtle",color:"blue",radius:0,size:"xs",disabled:d||t,onClick:r,leftSection:n.jsx(S.IconFileImport,{size:16}),sx:{...od},children:e("import.label")}),n.jsx(s.Modal,{opened:t,onClose:a,title:e("import.title"),trapFocus:!0,onDragStart:p=>{p.stopPropagation()},withinPortal:!0,zIndex:320,size:o?"90vw":500,children:n.jsx(jD,{onSuccess:a,stretchModal:l,shrinkModal:i})})]})}),UD=({iconKey:e,...t})=>{switch(e){case"query_variables":return n.jsx(S.IconVariable,{...t});case"mock_context":return n.jsx(S.IconCodeDots,{...t});case"filter":return n.jsx(S.IconFilter,{...t});case"sql_snippet":return n.jsx(S.IconCopy,{...t});case"query":return n.jsx(S.IconDatabase,{...t});case"view":return n.jsx(S.IconBoxMultiple,{...t});case"panel":return n.jsx(S.IconAppWindow,{...t});default:return null}},KD=({action:e})=>{const{t}=m.useTranslation();return e.description?n.jsx(s.Text,{c:"dimmed",size:"xs",children:t(e.description)}):e.viz?n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Text,{c:"dimmed",size:"xs",children:t(e.viz.displayName)}),n.jsx(s.Text,{c:"dimmed",size:"xs",className:"spotlight-action-viz-group",children:t(e.viz.displayGroup)})]}):null},YD=k.observer(({action:e,query:t})=>{const{t:r}=m.useTranslation();return n.jsx(s.Box,{className:"spotlight-custom-action-component",children:n.jsxs(s.Group,{wrap:"nowrap",children:[n.jsx(UD,{iconKey:e.iconKey,size:14}),n.jsxs("div",{style:{flex:1},children:[n.jsx(s.Highlight,{highlight:t,size:"sm",children:e.title?r(e.title):""}),n.jsx(KD,{action:e})]})]})})}),XD=({groups:e,query:t})=>{const{t:r}=m.useTranslation();return e.length===0?n.jsx(xt.Spotlight.Empty,{children:r("spotlight.not_found")}):n.jsx(n.Fragment,{children:e.map(a=>n.jsx(xt.Spotlight.ActionsGroup,{label:a.group,children:a.actions.map(o=>n.jsx(xt.Spotlight.Action,{onClick:o.onClick,children:n.jsx(YD,{action:o,query:t})},o.id))},a.group))})},ZD=k.observer(()=>{const{t:e,i18n:t}=m.useTranslation(),r=s.useMantineTheme(),a=j(),[o,l]=h.useState(""),i=h.useMemo(()=>a.editor.spotlightActionGroups.map(d=>({group:e(d.group),keywords:[d.group,e(d.group)],actions:d.actions.map(u=>{const p=[];return u.title&&(p.push(u.title.toLowerCase()),p.push(e(u.title).toLowerCase())),u.group&&p.push(u.group.toLowerCase()),u.viz&&(p.push(u.viz.displayGroup.toLowerCase()),p.push(u.viz.displayName.toLowerCase())),u.iconKey&&p.push(u.iconKey),{...u,keywords:p}})})),[a.editor.spotlightActionGroups,t.language]),c=h.useMemo(()=>{const d=o.toLowerCase().trim();return d?i.map(p=>{if(p.keywords.some(_=>_.includes(d)))return p;const v=p.actions.filter(_=>_.keywords.some(w=>w.includes(d)));return v.length===0?null:{...p,actions:v}}).filter(p=>p!==null):[i[0]]},[i,o]);return n.jsxs(xt.Spotlight.Root,{onQueryChange:l,shortcut:["mod + P","mod + K"],radius:"md",styles:{search:{border:"none"},action:{position:"relative",display:"block",width:"100%",padding:`${s.rem(10)} ${s.rem(12)}`,borderRadius:r.radius.sm,".spotlight-action-viz-group":{opacity:0},"&:hover, &[data-selected]":{backgroundColor:r.colors.gray[1],".spotlight-action-viz-group":{opacity:1}}}},children:[n.jsx(xt.Spotlight.Search,{placeholder:e("spotlight.placeholder"),leftSection:n.jsx(S.IconSearch,{size:"1.2rem"})}),n.jsx(xt.Spotlight.ActionsList,{children:n.jsx(XD,{groups:c,query:o})})]})}),ld=({children:e})=>n.jsx(s.Text,{style:{fontSize:"0.6875rem",lineHeight:1,padding:"0.25rem 0.2375rem",borderRadius:"0.25rem"},children:e}),id=function(){var t;return(((t=navigator.userAgentData)==null?void 0:t.platform)??navigator.platform).toLowerCase().includes("mac")}(),JD=()=>{const{t:e}=m.useTranslation();return n.jsx(s.Tooltip,{label:n.jsxs(n.Fragment,{children:[id&&n.jsx(ld,{children:"⌘ + K"}),!id&&n.jsx(ld,{children:"Ctrl + K"})]}),children:n.jsx(s.UnstyledButton,{onClick:()=>xt.spotlight.open(),style:{height:"1.875rem",borderLeft:"none",borderTop:"none",borderRight:"1px solid #e9ecef",borderBottom:"1px solid #e9ecef",paddingLeft:"calc(0.875rem / 1.5)",paddingRight:"1rem"},sx:{color:"#228be6",background:"transparent","&:hover":{background:"rgb(231, 245, 255)"}},children:n.jsxs(s.Group,{gap:"0.625rem",children:[n.jsx(S.IconSearch,{size:"1rem",color:"#228be6"}),n.jsx(s.Text,{fw:500,style:{flexGrow:1,fontWeight:500,fontSize:"0.75rem",lineHeight:1},children:e("spotlight.trigger_text")})]})})})},HD={position:"fixed",top:60,left:0,right:0,height:30,zIndex:299,borderBottom:"1px solid #e9ecef",background:"rgba(233,236,239, 0.15)"},RD=k.observer(()=>n.jsx(s.Box,{sx:HD,pl:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},children:n.jsxs(s.Group,{justify:"space-between",align:"center",sx:{height:"30px"},children:[n.jsxs(s.Group,{justify:"flex-start",gap:0,children:[n.jsx(PD,{}),n.jsx(WD,{}),n.jsx(JD,{})]}),n.jsx(AD,{}),n.jsx(s.Group,{justify:"flex-end",gap:0,children:n.jsx(ED,{})})]})})),ez=k.observer(e=>n.jsxs(n.Fragment,{children:[n.jsx(VD,{...e}),n.jsx(RD,{})]}));function tz(e,t,r){const a=[];return e.filter(o=>"__INTERACTIONS"in o.viz.conf).forEach((o,l)=>{const i=t[o.id];i.data.interactions=b.get(i,"data.interactions",[]);const{__INTERACTIONS:c,__OPERATIONS:d,__TRIGGERS:u}=o.viz.conf;Object.entries(d).forEach(([p,f])=>{const{schemaRef:v,data:_}=f,{config:w}=_;switch(v){case"builtin:op:open-link":let x=w.urlTemplate.substring(0,100);w.urlTemplate.length>=20&&(x+="..."),i.type="interaction",i.data.interactions.push({schemaRef:v,urlTemplate:w.urlTemplate,shortURLTemplate:x});return;case"builtin:op:open_view":a.push({id:`OPERATION--${p}`,source:o.id,target:w.viewID,label:"Open View",style:{stroke:"rgba(0,0,0,0.8)"},type:"default"});return;case"builtin:op:set_filter_values":i.type="interaction",i.data.interactions.push({schemaRef:v,filters:Object.keys(w.dictionary).map(T=>({key:T,label:r[T]}))});return;case"builtin:op:clear_filter_values":i.type="interaction",i.data.interactions.push({schemaRef:v,filters:w.filter_keys.map(T=>({key:T,label:r[T]}))});return;default:return}})}),a}function nz(e,t){const r=e.filters.keyLabelMap;return{edges:tz(e.panels.list,t,r),edgeNodes:[]}}function cd(e,t,r){return e*t+e*r}function rz(e,t,r){return e*t+(e-1)*r}const On=25,as=40,dd=25,ss=350,az=150,sz=150,ud=150,pd=300,Nn=40,hd=25,oz=300;function lz(e,t){const r=b.keyBy(t,o=>o.id),a=[];return e.current.forEach((o,l)=>{o.panelIDs.forEach((i,c)=>{const d=cd(c,Nn,hd)+as,u=r[i];if(!u){a.push({id:i,_node_type:"panel",parentNode:o.id,data:{label:`!: ${i}`},position:{x:On,y:d},sourcePosition:ie.Position.Right,targetPosition:ie.Position.Left,style:{width:pd,height:Nn}});return}const p=u.name;a.push({id:u.id,_node_type:"panel",parentNode:o.id,data:{label:p},position:{x:On,y:d},sourcePosition:ie.Position.Right,targetPosition:ie.Position.Left,style:{width:pd,height:Nn}})})}),a}const iz={[B.Division]:"Div",[B.Modal]:"Modal",[B.Tabs]:"Tabs"},cz=jc;function dz(e){return e.current.map((r,a)=>{const o=rz(r.panelIDs.length,Nn,hd)+as+dd;let l=[];return r.type===B.Tabs&&(l=r.config.tabsInOrder.map(c=>c.view_id)),{id:r.id,_node_type:"view-root",_view_type:r.type,_view_level:0,_sub_view_ids:[],_tab_view_ids:l,data:{label:`${iz[r.type]}:${r.name}`},position:{x:0,y:0},sourcePosition:ie.Position.Right,targetPosition:ie.Position.Left,className:"light",style:{backgroundColor:cz[r.type],width:ss,height:o}}})}function uz(e){const t=b.keyBy(e,r=>r.id);e.forEach(r=>{r._node_type!=="view-root"||r._view_type!==B.Tabs||r._tab_view_ids.forEach(a=>{t[a].parentNode=r.id})})}function pz(e){const t=dz(e.views);uz(t);const r=lz(e.views,e.panels.list);return[...t,...r]}function hz({nodeMap:e,nodes:t,edges:r}){t.forEach(a=>{a._node_type!=="view-root"||a._view_type!==B.Tabs||(a.sourcePosition=ie.Position.Bottom,a.style.width=ss+On*2,a.style.height=dd+a._tab_view_ids.reduce((o,l)=>{const i=e[l];i.position.y=o,i.position.x=On;const c=i.style.height;return o+c+20},as))})}function gz({nodeMap:e,nodes:t,edges:r}){r.filter(a=>a.label==="Open View").forEach(a=>{const o=e[a.source],l=e[a.target];if(!o||!l||!o.parentNode)return;const i=e[o.parentNode];i._node_type!=="view-root"||l._node_type!=="view-root"||(l._view_level+=1+i._view_level,i._sub_view_ids.push(l.id))}),t.sort((a,o)=>a._node_type==="view-root"&&o._node_type==="view-root"?a._view_level-o._view_level:a._node_type!=="view-root"&&o._node_type!=="view-root"?0:a._node_type==="view-root"?-1:1)}function fz({nodeMap:e,nodes:t,edges:r}){const a={};r.forEach(o=>{if(o.label!=="Open View")return;const l=e[o.source],i=e[o.target];if(l&&i&&l.parentNode){const c=e[l.parentNode],d=c.position.x,u=Number(b.get(i,"style.height",0)),p=Number(c.style.width);i.position.x=d+p+oz,c._view_level===0&&i._sub_view_ids.length===0&&(l.sourcePosition=ie.Position.Left,i.targetPosition=ie.Position.Right,i.position.x*=-1);const v=i.position.x,_=b.get(a,v,0);i.position.y=_,a[v]=_+u+ud}})}function bz({nodeMap:e,nodes:t,edges:r}){const a=new Set,o=new Set;r.forEach(i=>{a.add(i.source),o.add(i.target)}),t.filter(i=>i._node_type!=="view-root"||i.id==="Main"||i.parentNode?!1:!a.has(i.id)&&!o.has(i.id)).forEach((i,c)=>{i.position.x=cd(c,ss,sz),i.position.y=0-az-ud})}function yz({nodeMap:e,nodes:t,edges:r}){const a={nodeMap:e,nodes:t,edges:r};return bz(a),gz(a),hz(a),fz(a),{nodes:t,edges:r}}function vz(e){const t=pz(e),r=b.keyBy(t,d=>d.id),{edges:a,edgeNodes:o}=nz(e,r),l=[...t,...o],i=b.keyBy(l,d=>d.id),c={edges:b.uniqBy(a,d=>d.id),nodes:l,nodeMap:i};return yz(c)}const RI="",os={"builtin:op:open-link":n.jsx(s.ThemeIcon,{color:"blue",size:20,radius:"xl",children:n.jsx(S.IconCircleDashed,{size:14})}),"builtin:op:set_filter_values":n.jsx(s.ThemeIcon,{color:"orange",size:20,radius:"xl",children:n.jsx(S.IconCircleDot,{size:14})}),"builtin:op:clear_filter_values":n.jsx(s.ThemeIcon,{color:"orange",size:20,radius:"xl",children:n.jsx(S.IconCircleOff,{size:14})})};function _z(e){const t=[];return e.forEach(r=>{switch(r.schemaRef){case"builtin:op:open-link":t.push({key:r.urlTemplate,icon:os[r.schemaRef],text:n.jsxs(s.Group,{gap:4,children:[n.jsx(s.Text,{size:"sm",children:"Open: "}),n.jsx(s.Text,{size:"sm",c:"dimmed",children:r.shortURLTemplate})]})});return;case"builtin:op:set_filter_values":r.filters.forEach(({key:a,label:o})=>{t.push({key:r.schemaRef+a,icon:os[r.schemaRef],text:n.jsx(s.Group,{gap:4,children:n.jsxs(s.Text,{size:"sm",children:["Set Filter: ",o]})})})});return;case"builtin:op:clear_filter_values":r.filters.forEach(({key:a,label:o})=>{t.push({key:r.schemaRef+a,icon:os[r.schemaRef],text:n.jsx(s.Group,{gap:4,children:n.jsxs(s.Text,{size:"sm",children:["Clear Filter: ",o]})})})});return}}),t}const mz=h.memo(({data:e,isConnectable:t,sourcePosition:r=ie.Position.Right,targetPosition:a=ie.Position.Left,...o})=>{const l=h.useMemo(()=>_z(e.interactions),[e.interactions]);return n.jsxs(n.Fragment,{children:[n.jsx(ie.Handle,{type:"target",position:a,isConnectable:t}),n.jsx(s.Box,{sx:{position:"absolute",top:0,right:0},children:n.jsx(S.IconChevronsUpRight,{size:12})}),n.jsxs(s.HoverCard,{shadow:"xl",withinPortal:!0,children:[n.jsx(s.HoverCard.Target,{children:n.jsx(s.Text,{size:"sm",children:e.label})}),n.jsx(s.HoverCard.Dropdown,{children:n.jsx(s.List,{spacing:"xs",size:"sm",center:!0,children:l.map(i=>n.jsx(s.List.Item,{icon:i.icon,children:i.text},i.key))})})]}),n.jsx(ie.Handle,{type:"source",position:r,isConnectable:t})]})}),e6="",wz={interaction:mz},xz=k.observer(()=>{const e=H(),{edges:t,nodes:r}=vz(e);return n.jsxs(ie,{nodes:r,edges:t,onNodesChange:b.noop,onEdgesChange:b.noop,onConnect:b.noop,className:"interactions-viewer",fitView:!0,nodeTypes:wz,children:[n.jsx(ie.MiniMap,{}),n.jsx(ie.Controls,{}),n.jsx(ie.Background,{})]})}),Cz=k.observer(({opened:e,close:t})=>{const{t:r}=m.useTranslation();return n.jsx(s.Modal,{size:"96vw",opened:e,onClose:t,title:r("interactions.interactions_viewer"),trapFocus:!0,onDragStart:a=>{a.stopPropagation()},styles:{body:{height:"calc(90vh - 54px)"},content:{transform:"none !important"}},zIndex:300,children:n.jsx(xz,{})})}),Sz={"> button":{"&:first-of-type":{borderTopRightRadius:0,borderBottomRightRadius:0,borderRightWidth:.5},":not(:first-of-type):not(:last-of-type)":{borderTopRightRadius:0,borderBottomRightRadius:0,borderTopLeftRadius:0,borderBottomLeftRadius:0,borderLeftWidth:.5,borderRightWidth:.5},"&:last-of-type":{borderTopLeftRadius:0,borderBottomLeftRadius:0,borderLeftWidth:.5}}};function Tz({onClick:e,name:t,active:r,openSettings:a}){return n.jsxs(s.Box,{sx:{position:"relative"},children:[n.jsx(s.UnstyledButton,{sx:o=>({display:"block",width:"100%",padding:o.spacing.xs,borderRadius:0,position:"relative",color:o.black,"&:hover":{backgroundColor:o.colors.gray[0]},backgroundColor:r?o.colors.gray[2]:"transparent"}),children:n.jsx(s.Group,{sx:{width:"calc(100% - 28px)"},onClick:e,children:n.jsx(s.Text,{size:"sm",children:t})})}),r&&n.jsx(s.Tooltip,{label:"Edit",position:"right",withinPortal:!0,children:n.jsx(s.ActionIcon,{onClick:a,variant:"light",color:"blue",sx:{position:"absolute",top:0,bottom:0,height:"100%",right:0,zIndex:0,borderRadius:0},children:n.jsx(S.IconAdjustments,{size:16})})})]})}const kz=k.observer(()=>{const{t:e}=m.useTranslation(),t=j(),r=F(),a=h.useCallback(l=>()=>r.views.setIDOfVIE(l),[r]),o=l=>{t.editor.open(["_VIEWS_",l])};return n.jsxs(s.Box,{sx:{position:"relative"},children:[r.views.options.map(l=>n.jsx(Tz,{active:r.views.idOfVIE===l.value,name:l.label,onClick:a(l.value),openSettings:()=>o(l.value)},l.value)),n.jsx(s.Divider,{variant:"dashed"}),n.jsx(s.Button,{variant:"subtle",rightSection:n.jsx(S.IconPlus,{size:14}),size:"sm",px:"xs",color:"blue",onClick:r.views.addARandomNewView,sx:{width:"100%",borderRadius:0},styles:{inner:{justifyContent:"space-between"}},children:e("view.add")})]})}),Dz=k.observer(()=>{const{t:e}=m.useTranslation(),t=j(),r=F(),a=()=>{if(!r.queries.firstID){t.editor.open(["_QUERIES_",""]);return}t.editor.open(["_QUERIES_",r.queries.firstID])},o=()=>{if(!r.filters.firstID){t.editor.open(["_FILTERS_",""]);return}t.editor.open(["_FILTERS_",r.filters.firstID])},[l,i]=h.useState(!1),c=()=>i(!0),d=()=>i(!1);return n.jsxs(s.AppShell.Navbar,{p:0,zIndex:299,children:[n.jsxs(s.AppShell.Section,{children:[n.jsxs(s.Group,{grow:!0,gap:0,sx:{...Sz,button:{borderWidth:0,borderBottomWidth:1,borderColor:"#e9ecef"}},children:[n.jsx(s.Tooltip,{label:e("filter.labels"),withinPortal:!0,children:n.jsx(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:o,children:n.jsx(S.IconFilter,{size:18})})}),n.jsx(s.Tooltip,{label:e("query.labels"),withinPortal:!0,children:n.jsx(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:a,children:n.jsx(S.IconDatabase,{size:18})})}),n.jsx(s.Tooltip,{label:e("interactions.interactions_viewer"),withinPortal:!0,children:n.jsx(s.ActionIcon,{variant:"default",radius:0,size:"md",sx:{height:"30px"},onClick:c,children:n.jsx(S.IconRoute,{size:18})})})]}),n.jsx(Cz,{opened:l,close:d})]}),n.jsx(s.AppShell.Section,{py:5,sx:{borderBottom:"1px solid #eee"},children:n.jsx(s.Text,{size:"sm",ta:"center",sx:{userSelect:"none",cursor:"default"},children:e("view.labels")})}),n.jsx(s.AppShell.Section,{grow:!0,sx:{overflow:"auto"},children:n.jsx(kz,{})}),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",leftSection:n.jsx(S.IconSettings,{size:20}),onClick:()=>t.editor.open([]),children:e("common.titles.settings")})})})]})}),zz=k.observer(({filter:e})=>{const{t}=m.useTranslation(),r=e.config;return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Checkbox,{checked:r.default_value,onChange:a=>r.setDefaultValue(a.currentTarget.checked),label:t("filter.widget.checkbox.default_checked")}),n.jsx(_t,{filter:e})]}),n.jsx(Ue,{label:t("filter.widget.checkbox.description"),value:r.description,onChange:r.setDescription,styles:{root:{flexGrow:1,minHeight:"400px"}}},e.id)]})}),Mz=[{label:"2022",value:"YYYY"},{label:"202201",value:"YYYYMM"},{label:"20220101",value:"YYYYMMDD"},{label:"2022-01",value:"YYYY-MM"},{label:"2022-01-01",value:"YYYY-MM-DD"}],Iz=k.observer(function({filter:t}){const{t:r}=m.useTranslation(),a=t.config,o=h.useMemo(()=>{const i=mi();return Object.entries(i).map(([c,d])=>({group:r(`filter.widget.date_range.shortcut.${c}.label`),items:d.map(({key:u,value:p})=>({label:r(`filter.widget.date_range.shortcut.${c}.full.${u}`),value:p}))}))},[]),l=[...a.default_value];return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{children:[n.jsx(s.Checkbox,{checked:a.required,onChange:i=>a.setRequired(i.currentTarget.checked),label:r("filter.widget.date_range.required")}),n.jsx(s.Checkbox,{checked:a.allowSingleDateInRange,onChange:i=>a.setAllowSingleDateInRange(i.currentTarget.checked),label:r("filter.widget.date_range.allow_single_date")})]}),n.jsxs(s.Group,{grow:!0,children:[n.jsx(s.Select,{data:Mz,label:r("filter.widget.date_range.display_format"),value:a.inputFormat,onChange:a.setInputFormat}),n.jsx(s.NumberInput,{label:r("filter.widget.date_range.max_days"),min:0,value:a.max_days,onChange:a.setMaxDays,hideControls:!0})]}),n.jsxs(s.Group,{children:[n.jsx(bc,{label:r("filter.widget.date_range.default_value"),config:a,value:{value:l,shortcut:null},onChange:a.setDefaultValue,disabled:!!a.default_shortcut}),n.jsx(s.Select,{data:o,label:r("filter.widget.date_range.default_by_shortcut"),value:a.default_shortcut,onChange:a.setDefaultShortcut,placeholder:r("filter.widget.date_range.default_by_shortcut_placeholder"),clearable:!0,sx:{flexGrow:1},maxDropdownHeight:500})]}),n.jsx(_t,{filter:t})]})}),Vz=`
|
|
547
547
|
// row
|
|
548
548
|
{
|
|
549
549
|
label: string;
|
|
550
550
|
value: string;
|
|
551
551
|
description?: string; // optional
|
|
552
552
|
}
|
|
553
|
-
`,gd=()=>{const{t:e}=m.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(Fe.CodeHighlight,{language:"typescript",withCopyButton:!1,code:Vz})})]})},Pz=k.observer(function({filter:t}){const{t:r}=m.useTranslation(),a=t.config,o=()=>{a.addStaticOption({label:"",value:""})},l=a.static_options,i=l.filter(c=>c.value!==""&&c.label!=="");return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Checkbox,{checked:a.required,onChange:c=>a.setRequired(c.currentTarget.checked),label:r("filter.widget.select.required")}),n.jsx(_t,{filter:t})]}),n.jsx(s.TextInput,{label:r("filter.widget.select.width"),description:r("filter.widget.multi_select.width_description"),value:a.min_width,onChange:c=>a.setMinWidth(c.currentTarget.value),placeholder:"200px"}),n.jsx(s.Divider,{label:r("filter.widget.select.configure_options"),labelPosition:"center"}),n.jsxs(s.Stack,{gap:10,sx:{position:"relative",minHeight:"50px"},children:[a.usingQuery&&n.jsxs(n.Fragment,{children:[n.jsx(s.Overlay,{backgroundOpacity:.8,color:"#000",sx:{left:"-5px",right:"-5px",top:"-5px",bottom:"-5px"}}),n.jsx(s.Center,{sx:{position:"absolute",top:0,left:0,zIndex:200,height:"100%",width:"100%"},children:n.jsx(s.Text,{c:"white",size:"16px",children:r("filter.widget.common.using_query")})})]}),i.length>0&&n.jsx(s.MultiSelect,{label:r("filter.widget.select.default_selection"),placeholder:r("filter.widget.select.no_default_selection"),data:i,value:[...a.default_value],onChange:a.setDefaultValue}),l.map((c,d)=>n.jsxs(s.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[n.jsx(s.TextInput,{label:r("common.label"),required:!0,value:a.static_options[d].label,onChange:u=>{a.static_options[d].setLabel(u.currentTarget.value)},sx:{flexGrow:1}}),n.jsx(s.TextInput,{label:r("common.value"),required:!0,value:a.static_options[d].value,onChange:u=>{a.static_options[d].setValue(u.currentTarget.value)},sx:{flexGrow:1}}),n.jsx(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>a.removeStaticOption(d),sx:{position:"absolute",top:28,right:5},children:n.jsx(S.IconTrash,{size:16})})]},d)),n.jsx(s.Button,{mt:10,size:"xs",color:"blue",leftSection:n.jsx(S.IconPlaylistAdd,{size:20}),onClick:o,sx:{width:"50%"},mx:"auto",children:r("common.actions.add_an_option")})]}),n.jsx(s.Divider,{label:r("filter.widget.common.or_fetch_options_from_datasource"),labelPosition:"center"}),n.jsx(Vn,{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(_a,{config:a}),n.jsx(gd,{})]})}),fd={date_unit:{zh:[{label:"天",value:"day"},{label:"周",value:"week"},{label:"双周",value:"bi-week"},{label:"月",value:"month"},{label:"季度",value:"quarter"},{label:"年",value:"year"}],en:[{label:"Day",value:"day"},{label:"Week",value:"week"},{label:"Bi-Week",value:"bi-week"},{label:"Month",value:"month"},{label:"Quarter",value:"quarter"},{label:"Year",value:"year"}]}},bd=k.observer(({config:e})=>{const{t,i18n:r}=m.useTranslation(),a=()=>{e.addStaticOption({label:"",value:""})},o=h.useMemo(()=>[{label:t("filter.widget.select.preset_options.date_unit"),value:"date_unit"}],[r.language]),l=i=>{if(!i||!(i in fd))return;const c=fd[i][r.language];e.replaceStaticOptions(c),c.length>0&&e.setDefaultValue(c[0].value)};return n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Button,{size:"xs",color:"blue",leftSection:n.jsx(S.IconPlaylistAdd,{size:20}),onClick:a,children:t("common.actions.add_an_option")}),n.jsx(s.Select,{placeholder:t("filter.widget.select.preset_options.apply"),value:null,onChange:l,data:o,size:"xs"})]})}),$z=k.observer(({config:e})=>{const{t,i18n:r}=m.useTranslation(),a=[...e.static_options],o=h.useMemo(()=>[{label:t("filter.widget.select.no_default_selection"),value:""},...a.filter(l=>l.value!=="")],[r.language,a]);return a.length===0?n.jsx(bd,{config:e}):n.jsxs(n.Fragment,{children:[n.jsx(s.Select,{label:t("filter.widget.select.default_selection"),data:o,value:e.default_value,onChange:e.setDefaultValue}),a.map((l,i)=>n.jsxs(s.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[n.jsx(s.TextInput,{label:t("common.label"),required:!0,value:e.static_options[i].label,onChange:c=>{e.static_options[i].setLabel(c.currentTarget.value)},sx:{flexGrow:1}}),n.jsx(s.TextInput,{label:t("common.value"),required:!0,value:e.static_options[i].value,onChange:c=>{e.static_options[i].setValue(c.currentTarget.value)},sx:{flexGrow:1}}),n.jsx(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>e.removeStaticOption(i),sx:{position:"absolute",top:28,right:5},children:n.jsx(S.IconTrash,{size:16})})]},i)),n.jsx(bd,{config:e})]})}),Az=k.observer(({filter:e})=>{const{t}=m.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(s.Checkbox,{checked:r.clearable,onChange:a=>r.setClearable(a.currentTarget.checked),label:t("filter.widget.select.clearable")}),n.jsx(_t,{filter:e})]}),n.jsx(s.TextInput,{label:t("filter.widget.select.width"),value:r.width,onChange:a=>r.setWidth(a.currentTarget.value),placeholder:"200px"}),n.jsx(s.Divider,{label:t("filter.widget.select.configure_options"),labelPosition:"center"}),n.jsxs(s.Stack,{gap:10,sx:{position:"relative",minHeight:"50px"},children:[r.usingQuery&&n.jsxs(n.Fragment,{children:[n.jsx(s.Overlay,{backgroundOpacity:.8,color:"#000",sx:{left:"-5px",right:"-5px",top:"-5px",bottom:"-5px"}}),n.jsx(s.Center,{sx:{position:"absolute",top:0,left:0,zIndex:200,height:"100%",width:"100%"},children:n.jsx(s.Text,{c:"white",size:"16px",children:t("filter.widget.common.using_query")})})]}),n.jsx($z,{config:r})]}),n.jsx(s.Divider,{label:t("filter.widget.common.or_fetch_options_from_datasource"),labelPosition:"center"}),n.jsx(s.Checkbox,{checked:r.default_selection_count===1,onChange:a=>r.setDefaultSelectionCount(a.currentTarget.checked?1:0),label:t("filter.widget.select.select_first_option_by_default")}),n.jsx(Vn,{value:r.options_query_id,onChange:r.setOptionsQueryID}),n.jsx(gd,{})]})}),Ez=k.observer(function({filter:t}){const{t:r}=m.useTranslation(),a=t.config;return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{children:[n.jsx(s.TextInput,{label:r("filter.widget.text_input.default_value"),value:a.default_value,onChange:o=>{a.setDefaultValue(o.currentTarget.value)},sx:{flexGrow:1}}),n.jsx(s.Box,{mt:22,children:n.jsx(_t,{filter:t})})]}),n.jsx(s.Checkbox,{checked:a.required,onChange:o=>a.setRequired(o.currentTarget.checked),label:r("filter.widget.text_input.required")})]})}),Bz=k.observer(({filter:e})=>{const{t}=m.useTranslation(),r=j().editor,a=e.usages,o=l=>{switch(l.type){case"query":r.setPath(["_QUERIES_",l.id]);break;case"sql_snippet":r.setPath(["_SQL_SNIPPETS_",l.id]);break;case"view":r.setPath(["_VIEWS_",l.id]);default:return}};return a.length===0?n.jsx(s.Text,{mt:10,ml:10,size:"sm",children:t("filter.usage.unused_description")}):n.jsxs(s.Table,{highlightOnHover:!0,layout:"fixed",styles:{table:{fontSize:"14px"}},children:[n.jsxs("colgroup",{children:[n.jsx("col",{style:{width:80}}),n.jsx("col",{})]}),n.jsx(s.Table.Tbody,{children:a.map(l=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:n.jsx(s.Text,{size:"xs",children:t(l.type_label)})}),n.jsx(s.Table.Td,{children:n.jsx(s.Anchor,{size:"xs",title:l.label,onClick:()=>o(l),children:n.jsx(s.Text,{truncate:"end",children:l.label})})})]},l.id))})]})}),qz=k.observer(({filter:e})=>{const{t}=m.useTranslation();return n.jsxs(s.Tabs,{defaultValue:"usage",children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"config",children:t("common.titles.config")}),n.jsx(s.Tabs.Tab,{value:"usage",children:t("filter.usage.label")})]}),n.jsx(s.Tabs.Panel,{value:"config",children:n.jsx(s.Box,{sx:{minWidth:"480px"},children:n.jsx(Fe.CodeHighlight,{mt:22,language:"json",withCopyButton:!1,code:JSON.stringify(e,null,4)})})}),n.jsx(s.Tabs.Panel,{value:"usage",children:n.jsx(Bz,{filter:e})})]})}),Lz=k.observer(({filter:e})=>{const{t}=m.useTranslation(),r=e.config,a=h.useMemo(()=>{const p=Bi(r.default_step);return Object.entries(p).map(([f,v])=>({group:t(`filter.widget.date_range.shortcut.${f}.label`),items:v.map(({key:_,value:w})=>({label:t(`filter.widget.date_range.shortcut.${f}.full.${_}`),value:w}))}))},[r.default_step]),o=[...r.default_value],[l,i]=h.useState(o),c=p=>{i(p),!(p[0]===null||p[1]===null)&&(r.setDefaultValue({value:Jt(p[0],p[1],r.default_step),shortcut:null,step:r.default_step}),r.setDefaultShortcut(null))},d=p=>{i([null,null]),r.setDefaultValue({value:[null,null],shortcut:p,step:r.default_step}),r.setDefaultShortcut(p)},u=p=>{r.setDefaultValue({value:r.default_shortcut?[null,null]:Jt(r.default_value[0],r.default_value[1],p),shortcut:r.default_shortcut,step:p}),r.setDefaultStep(p)};return n.jsxs(n.Fragment,{children:[n.jsx(s.Group,{children:n.jsx(s.Checkbox,{checked:r.required,onChange:p=>r.setRequired(p.currentTarget.checked),label:t("filter.widget.date_range.required")})}),n.jsx(yc,{value:r.default_step,onChange:u,label:"默认步长"}),n.jsxs(s.Group,{children:[n.jsx(s.Select,{data:a,label:t("filter.widget.date_range.default_by_shortcut"),value:r.default_shortcut,onChange:d,placeholder:t("filter.widget.date_range.default_by_shortcut_placeholder"),clearable:!0,sx:{flexGrow:1},maxDropdownHeight:500}),n.jsx(wt.DatePickerInput,{type:"range",label:t("filter.widget.date_range.default_value"),value:l,onChange:c,valueFormat:r.inputFormat,allowSingleDateInRange:!0,numberOfColumns:2,w:"50%",disabled:!!r.default_shortcut})]}),r.required&&!r.default_shortcut&&r.default_value.every(p=>!p)&&n.jsx(s.Text,{size:"xs",mt:-10,ta:"center",children:"快捷方式与具体日期范围二选一,且必填"}),n.jsx(_t,{filter:e})]})}),Oz={[P.Select]:Az,[P.MultiSelect]:Pz,[P.TreeSelect]:BT,[P.TreeSingleSelect]:jT,[P.TextInput]:Ez,[P.Checkbox]:zz,[P.DateRange]:Iz,[P.MericoDateRange]:Lz},rt={[P.Select]:"filter.widget.names.select",[P.MultiSelect]:"filter.widget.names.multi_select",[P.TreeSelect]:"filter.widget.names.tree_select",[P.TreeSingleSelect]:"filter.widget.names.tree_single_select",[P.TextInput]:"filter.widget.names.text_input",[P.Checkbox]:"filter.widget.names.checkbox",[P.DateRange]:"filter.widget.names.date_range",[P.MericoDateRange]:"filter.widget.names.merico_date_range"},Nz=k.observer(({filter:e})=>{const{t,i18n:r}=m.useTranslation(),a=G(),o=h.useMemo(()=>Oz[e.type],[e.type]),l=h.useMemo(()=>[{label:t(rt[P.Select]),value:"select"},{label:t(rt[P.MultiSelect]),value:"multi-select"},{label:t(rt[P.TreeSelect]),value:"tree-select"},{label:t(rt[P.TreeSingleSelect]),value:"tree-single-select"},{label:t(rt[P.TextInput]),value:"text-input"},{label:t(rt[P.Checkbox]),value:"checkbox"},{label:t(rt[P.DateRange]),value:"date-range"},{label:t(rt[P.MericoDateRange]),value:"merico-date-range"}],[r.language]);return n.jsxs(s.Group,{grow:!0,gap:20,align:"top",children:[n.jsxs(s.Box,{w:600,children:[n.jsx(s.Text,{pb:"md",c:"gray",size:"sm",children:t("common.titles.edit")}),n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{wrap:"nowrap",children:[n.jsx(s.NumberInput,{label:t("filter.field.order"),required:!0,value:e.order,onChange:e.setOrder,hideControls:!0,sx:{flexGrow:"1 !important"}}),e.auto_submit_supported&&n.jsx(s.Checkbox,{label:t("filter.field.auto_submit"),checked:e.auto_submit,onChange:i=>e.setAutoSubmit(i.currentTarget.checked),mt:22})]}),n.jsx(s.MultiSelect,{label:t("filter.field.visible_in"),data:a.views.options,value:[...e.visibleInViewsIDs],onChange:e.setVisibleInViewsIDs}),n.jsx(s.TextInput,{label:t("common.key"),placeholder:t("filter.field.key_placeholder"),required:!0,value:e.key,onChange:i=>{e.setKey(i.currentTarget.value)}}),n.jsx(s.TextInput,{label:t("common.label"),placeholder:t("filter.field.label_placeholder"),required:!0,value:e.label,onChange:i=>{e.setLabel(i.currentTarget.value)}}),n.jsx(s.Select,{label:t("filter.field.widget"),data:l,required:!0,value:e.type,onChange:e.setType,maxDropdownHeight:500}),n.jsx(s.Divider,{mb:0,mt:10,variant:"dashed",labelPosition:"center"}),n.jsx(o,{filter:e})]})]}),n.jsx(qz,{filter:e})]})}),Gz=k.observer(({id:e})=>{const{t}=m.useTranslation(),r=De.useModals(),a=j(),o=G();if(e==="")return null;const l=o.filters.findByID(e);if(!l)return n.jsxs(s.Text,{size:"14px",children:["Filter by ID[",e,"] is not found"]});const i=()=>{a.editor.setPath(["_FILTERS_",""])},c=()=>{r.openConfirmModal({title:`${t("filter.delete")}?`,labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{o.filters.removeByID(e),i()},confirmProps:{color:"red"},zIndex:320})};return n.jsxs(s.Stack,{sx:{minWidth:"1100px",height:"100vh"},gap:"sm",pb:30,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("filter.delete")})}),n.jsx(s.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:n.jsx(Nz,{filter:l})})]})}),Fz=k.observer(()=>{const{t:e}=m.useTranslation(),[t,r]=h.useState([]),a=j(),o=u=>{a.editor.setPath(["_FILTERS_",u])},l=()=>{a.content.filters.downloadSchema(t)},i=h.useMemo(()=>a.content.filters.sortedList.map(u=>u.id),[a.content.filters.sortedList]),c=()=>{r(i)},d=()=>{r([])};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("filter.manage")})}),n.jsx(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:c,children:e("common.actions.select_all")}),n.jsx(s.Button,{variant:"default",size:"xs",onClick:d,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:l,children:e("common.actions.download_schema")})]})}),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,{style:{width:"300px"},children:e("common.label")}),n.jsx(s.Table.Th,{children:e("common.key")}),n.jsx(s.Table.Th,{style:{width:"100px"},children:e("filter.field.widget")}),n.jsx(s.Table.Th,{style:{width:"300px",paddingLeft:"24px"},children:e("common.action")})]})}),n.jsx(s.Table.Tbody,{children:a.content.filters.sortedList.map(u=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:n.jsx(s.Checkbox,{value:u.id,styles:{input:{cursor:"pointer"}}})}),n.jsx(s.Table.Td,{children:u.label}),n.jsx(s.Table.Td,{children:u.key}),n.jsx(s.Table.Td,{children:e(rt[u.type])}),n.jsx(s.Table.Td,{children:n.jsx(s.Button,{variant:"subtle",size:"xs",onClick:()=>o(u.id),children:e("common.actions.open")})})]},u.id))})]})})})]})}),Qz=k.observer(()=>{const{t:e}=m.useTranslation(),t=G(),[r,a]=h.useState(()=>JSON.stringify(t.mock_context.current,null,4)),o=()=>{try{t.mock_context.replace(JSON.parse(r))}catch(i){Ge.showNotification({title:"Failed",message:i.message,color:"red"})}},l=h.useMemo(()=>{try{return JSON.stringify(JSON.parse(r))!==JSON.stringify(t.mock_context.current)}catch{return!1}},[r,t.mock_context.current]);return n.jsxs(s.Stack,{sx:{border:"1px solid #eee",borderLeft:"none",borderRight:"none",flexGrow:1,maxWidth:"unset"},children:[n.jsx(s.Group,{justify:"flex-start",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:n.jsx(s.Text,{size:"sm",fw:500,children:e("mock_context.label")})}),n.jsx(s.Group,{grow:!0,px:"md",pb:"md",pt:0,sx:{flexGrow:1,position:"relative",alignItems:"flex-start"},children:n.jsxs(s.Stack,{gap:10,sx:{maxWidth:"unset !important"},children:[n.jsxs(s.Group,{justify:"flex-start",children:[n.jsx(s.Text,{size:"sm",children:e("mock_context.hint")}),n.jsx(s.Button,{color:"green",size:"compact-sm",leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),onClick:o,disabled:!l,children:e("common.actions.save")})]}),n.jsx(s.JsonInput,{validationError:"Invalid json",formatOnBlur:!0,autosize:!0,minRows:30,value:r,onChange:a,sx:{flexGrow:1}})]})})]})}),jz=k.observer(()=>{const{t:e}=m.useTranslation(),{panel:t}=ae();return n.jsx(Ue,{label:e("panel.panel_description"),value:t.description,onChange:t.setDescription,styles:{root:{flexGrow:1}}},t.id)}),Wz=k.observer(()=>{const{t:e}=m.useTranslation(),{panel:t}=ae(),r=H().layouts.findItemByPanelID(t.id),{style:a}=t;return n.jsx(n.Fragment,{children:n.jsxs(s.Stack,{gap:20,children:[n.jsxs(s.Group,{grow:!0,align:"top",children:[n.jsx(s.NumberInput,{label:e("panel.style.width"),min:1,max:36,step:1,decimalScale:0,rightSection:n.jsx(s.Text,{size:"12px",children:e("panel.style.width_postfix")}),styles:{section:{width:"auto",maxWidth:"100px",paddingRight:"14px",justifyContent:"flex-end"}},value:r.w,onChange:o=>{typeof o!="string"&&r.setWidth(o)}}),n.jsx(s.NumberInput,{label:e("panel.style.height"),rightSection:n.jsx(s.Text,{size:"12px",children:e("panel.style.height_postfix")}),styles:{section:{width:"40px"}},value:r.h,onChange:o=>{typeof o!="string"&&r.setHeight(o)}})]}),n.jsx(s.Checkbox,{ml:6,label:e("panel.style.border"),checked:a.border.enabled,onChange:o=>a.border.setEnabled(o.currentTarget.checked)})]})})}),Uz=()=>n.jsxs("span",{className:"mantine-103svbs mantine-InputWrapper-required mantine-Select-required","aria-hidden":"true",children:[" ","*"]}),Kz=k.observer(()=>{const{t:e}=m.useTranslation(),{panel:t}=ae(),{name:r}=t,[a,o]=te.useInputState(r),l=r!==a,i=h.useCallback(()=>{l&&t.setName(a)},[l,a]);h.useEffect(()=>{o(r)},[r]);const c=!a.trim();return n.jsxs(s.Stack,{gap:4,children:[n.jsxs(s.Group,{align:"center",children:[n.jsxs(s.Text,{size:"14px",fw:500,children:[e("panel.panel_name"),n.jsx(Uz,{})]}),n.jsx(s.ActionIcon,{variant:"subtle",color:"blue",disabled:!l||c,onClick:i,children:n.jsx(S.IconDeviceFloppy,{size:18})})]}),n.jsx(s.TextInput,{value:a,onChange:o,required:!0})]})}),Yz=k.observer(()=>{const{t:e}=m.useTranslation(),{panel:t}=ae();return n.jsx(s.Stack,{gap:6,mb:10,children:n.jsxs(s.Group,{pl:6,justify:"flex-start",gap:20,children:[n.jsx(s.Checkbox,{size:"sm",checked:t.title.show,onChange:r=>t.title.setShow(r.currentTarget.checked),label:e("panel.show_title"),sx:{userSelect:"none"}}),n.jsx(s.Checkbox,{size:"sm",checked:!0,disabled:!0,label:e("panel.use_name_as_title")})]})})});function Xz(){const{t:e}=m.useTranslation();return n.jsxs(s.Stack,{sx:{height:"100%"},children:[n.jsx(Wz,{}),n.jsx(s.Divider,{label:e("common.info"),labelPosition:"center",variant:"dashed"}),n.jsx(Kz,{}),n.jsx(Yz,{}),n.jsx(jz,{})]})}const Zz={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 yd({data:e}){const t=h.useMemo(()=>{if(!Array.isArray(e)||e.length===0)return[];const a=ge.createColumnHelper();return Object.keys(e[0]).map(o=>a.accessor(o,{cell:l=>l.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:Zz,children:[n.jsx(s.Table.Thead,{children:r.getHeaderGroups().map(a=>n.jsx(s.Table.Tr,{children:a.headers.map(o=>n.jsxs(s.Table.Th,{style:{width:o.getSize()},children:[o.isPlaceholder?null:ge.flexRender(o.column.columnDef.header,o.getContext()),n.jsx(s.ActionIcon,{variant:"subtle",onMouseDown:o.getResizeHandler(),onTouchStart:o.getResizeHandler(),className:`resizer ${o.column.getIsResizing()?"isResizing":""}`,children:n.jsx(S.IconArrowBarToRight,{})})]},o.id))},a.id))}),n.jsx(s.Table.Tbody,{children:r.getRowModel().rows.map(a=>n.jsx(s.Table.Tr,{children:a.getVisibleCells().map(o=>n.jsx(s.Table.Td,{children:n.jsx(ne,{children:typeof o.getValue()=="object"?n.jsx("pre",{children:JSON.stringify(o.getValue(),null,2)}):ge.flexRender(o.column.columnDef.cell,o.getContext())})},o.id))},a.id))})]})})}const Jz=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],Hz={section:{"&[data-position=left]":{width:"70px",textAlign:"center"}},input:{paddingLeft:"70px"}},Rz=({data:e,page:t,setPage:r,limit:a,setLimit:o})=>{const{t:l}=m.useTranslation(),i=e.length,c=Math.ceil(i/a),d=p=>{p&&(r(1),o(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:[c>1&&n.jsx(s.Pagination,{size:"sm",value:t,onChange:r,total:c,withEdges:c>7,styles:{control:{height:"30px"}}}),!u&&n.jsx(s.Select,{leftSection:n.jsx(s.Text,{ta:"center",c:"dimmed",size:"14px",children:l("common.pagination.page_size")}),size:"xs",styles:Hz,data:Jz,value:String(a),onChange:d})]}),n.jsx(s.Group,{justify:"flex-end",children:n.jsx(s.Text,{c:"dimmed",my:0,size:"14px",children:l("common.pagination.total_rows",{total:i})})})]})},e3=Do(({data:e,loading:t})=>{const[r,a]=h.useState(1),[o,l]=h.useState(20),i=h.useMemo(()=>{const c=(r-1)*o,d=c+o;return e.slice(c,d)},[e,r,o]);return n.jsxs(ne,{children:[n.jsx(Rz,{data:e,page:r,setPage:a,limit:o,setLimit:l}),n.jsxs(s.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[n.jsx(s.LoadingOverlay,{visible:t,overlayProps:{blur:2}}),n.jsx(yd,{data:i})]})]})}),t3=k.observer(({queryID:e})=>{const{t}=m.useTranslation(),r=H(),a=h.useMemo(()=>r.queries.findByID(e),[r,e]);if(!a||a.state==="loading")return null;const{error:o,metricQueryPayloadErrorString:l,stateMessage:i}=a;return o||l?n.jsx(s.Text,{mt:10,c:"red",size:"md",ta:"center",ff:"monospace",children:o??l}):i?n.jsx(s.Text,{size:"sm",mt:10,c:"gray",ta:"center",children:t(i)}):null}),ls=k.observer(({id:e,moreActions:t,refreshOnMount:r})=>{const{t:a}=m.useTranslation(),o=H(),{data:l,state:i}=o.getDataStuffByID(e),c=i==="loading",d=h.useCallback(()=>{o.queries.refetchDataByQueryID(e)},[e,o]),u=()=>{o.queries.downloadDataByQueryID(null,e)};h.useEffect(()=>{r&&d()},[d,r]);const p=!Array.isArray(l)||l.length===0;return n.jsxs(s.Stack,{gap:0,sx:{height:"100%",border:"1px solid #eee"},children:[n.jsxs(s.Group,{justify:"space-between",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[n.jsx(s.Group,{justify:"flex-start",children:n.jsx(s.Text,{size:"sm",fw:500,children:a("data.preview_data")})}),n.jsxs(s.Group,{pr:15,children:[t,n.jsx(s.ActionIcon,{variant:"subtle",color:"blue",disabled:c,onClick:d,children:n.jsx(S.IconRefresh,{size:16})}),n.jsx(s.ActionIcon,{variant:"subtle",color:"blue",disabled:c||p,onClick:u,children:n.jsx(S.IconDownload,{size:16})})]})]}),n.jsxs(s.Box,{pb:20,sx:{position:"relative",flexGrow:1,overflow:"auto"},children:[n.jsx(t3,{queryID:e}),n.jsx(e3,{data:l,loading:c})]})]})}),n3=k.observer(function(){const{t}=m.useTranslation(),r=j(),a=G(),{panel:o}=ae(),[l,i]=h.useState(!1),c=u=>{r.editor.setPath(["_QUERIES_",u])},d=o.queryIDs.length;return n.jsxs(n.Fragment,{children:[n.jsx(s.Drawer,{opened:l,onClose:()=>i(!1),title:t("panel.settings.choose_queries"),padding:"xl",size:500,zIndex:320,children:n.jsx(s.Checkbox.Group,{value:[...o.queryIDs],onChange:o.setQueryIDs,children:n.jsx(s.Stack,{gap:"lg",children:a.queries.options.map(u=>n.jsx(s.Checkbox,{label:u.label,value:u.value},u.value))})})}),n.jsxs(s.Stack,{gap:6,children:[n.jsx(s.Group,{justify:"flex-start",children:n.jsx(s.Button,{variant:"light",size:"sm",leftSection:n.jsx(S.IconLine,{size:16}),onClick:()=>i(!0),children:t(d===0?"panel.settings.need_to_choose_queries":"panel.settings.choose_queries")})}),d===1&&n.jsx(ls,{id:o.queryIDs[0],moreActions:n.jsx(s.Tooltip,{label:t("query.open"),children:n.jsx(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>c(o.queryIDs[0]),children:n.jsx(S.IconArrowCurveRight,{size:16})})})}),d>1&&n.jsxs(s.Tabs,{defaultValue:o.queryIDs[0],children:[n.jsx(s.Tabs.List,{children:o.queries.map(u=>n.jsx(s.Tabs.Tab,{value:u.id,children:u.name},u.id))}),o.queries.map(u=>n.jsx(s.Tabs.Panel,{value:u.id,children:n.jsx(ls,{id:u.id,moreActions:n.jsx(s.Tooltip,{label:t("query.open"),children:n.jsx(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>c(u.id),children:n.jsx(S.IconArrowCurveRight,{size:16})})})})},u.id))]})]})]})}),r3=k.observer(()=>{const{panel:e}=re();return e.title.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:e.title.show?e.name:""})}):null}),a3=k.observer(()=>{const{panel:e}=re();return n.jsx(ne,{children:n.jsx(s.Box,{className:`panel-root ${e.title.show?"panel-root--show-title":""}`,p:0,sx:{border:"1px solid",borderColor:e.style.border.enabled?"#e9ecef":"transparent",flexGrow:0,flexShrink:0,width:"600px !important",height:"450px !important"},children:n.jsxs(Ns,{children:[n.jsx(s.Box,{className:"panel-description-popover-wrapper",children:n.jsx(Ka,{})}),n.jsx(r3,{}),n.jsx(Za,{panel:e})]})})})});function s3(){const{t:e}=m.useTranslation(),{vizManager:t}=h.useContext(lt);return h.useMemo(()=>b.orderBy(Object.entries(b.groupBy(t.availableVizList,"displayGroup")),[o=>o[0]],["asc"]).map(([o,l])=>{const i=l.map(c=>({value:c.name,label:e(c.displayName??it.name)}));return{group:e(o??"ungrouped"),items:b.orderBy(i,[c=>c.label],["asc"])}}),[t])}const o3=k.observer(({value:e,submit:t})=>{const{t:r}=m.useTranslation(),[a,o]=te.useInputState(e);h.useEffect(()=>{o(e)},[e]);const l=s3(),i=e!==a;return n.jsx(s.Select,{label:r("visualization.component"),value:a,searchable:!0,onChange:o,data:l,rightSection:n.jsx(s.ActionIcon,{variant:"filled",color:"green",disabled:!i,onClick:()=>t(a),styles:{root:{pointerEvents:"all"}},children:n.jsx(S.IconDeviceFloppy,{size:20})}),maxDropdownHeight:600})}),vd=[];function l3(e,t){try{return e.resolveComponent(t).createConfig()}catch{return null}}function i3(){const{data:e,panel:{variables:t,viz:r,title:a,name:o,queryIDs:l,description:i,id:c}}=ae(),{vizManager:d}=h.useContext(lt),u={name:o,title:a,description:i,viz:r,queryIDs:l,id:c},p=kc(u);try{return d.resolveComponent(u.viz.type),n.jsx(bn,{configure:p,children:n.jsx(uk,{variables:t,setVizConf:r.setConf,panel:u,vizManager:d,data:e})})}catch(f){return console.info(b.get(f,"message")),null}}const c3=k.observer(()=>{const{data:e,panel:{viz:t}}=ae(),{vizManager:r}=h.useContext(lt),a=h.useCallback(u=>{if(u===t.type)return;const p=l3(r,u);t.setType(u),t.setConf(p||{})},[t.type]),o=u=>{try{t.setConf(JSON.parse(u))}catch(p){console.error(p)}},l=h.useMemo(()=>{var u;return(u=vd.find(p=>p.value===t.type))==null?void 0:u.Panel},[t.type,vd]),i=i3(),c=l?h.createElement(l,{data:e,conf:t.conf,setConf:t.setConf}):null,d=i||c;return n.jsxs(s.Stack,{align:"stretch",sx:{height:"100%",overflow:"hidden"},children:[n.jsx(o3,{submit:a,value:t.type}),n.jsxs(ne,{children:[n.jsx(s.Stack,{pb:10,sx:{flexGrow:1,maxHeight:"100%",overflow:"auto"},children:d}),!d&&n.jsx(s.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(t.conf,null,2),onChange:o})]})]})}),d3=k.observer(({panel:e,sourceViewID:t})=>{const{t:r}=m.useTranslation(),a=G(),[o,l]=h.useState(t);h.useEffect(()=>{l(t)},[t]);const[i,{open:c,close:d}]=te.useDisclosure(!1),u=()=>{e.moveToView(t,o),d()};return n.jsxs(n.Fragment,{children:[n.jsx(s.Button,{size:"xs",variant:"subtle",color:"blue",onClick:c,leftSection:n.jsx(S.IconBoxMultiple,{size:14}),children:r("panel.settings.change_view")}),n.jsx(s.Modal,{opened:i,onClose:d,title:r("panel.settings.change_view_title"),zIndex:320,children:n.jsxs(s.Stack,{sx:{maxHeight:"calc(100vh - 185px)",overflow:"hidden"},children:[n.jsx(s.Radio.Group,{value:o,onChange:l,pb:10,sx:{flexGrow:1,maxHeight:"calc(100vh - 185px - 30px)",overflow:"auto"},children:n.jsx(s.Stack,{gap:"xs",children:a.views.options.map(p=>n.jsx(s.Radio,{value:p.value,label:p.label},p.value))})}),n.jsxs(s.Group,{wrap:"nowrap",justify:"space-between",sx:{flexGrow:0,flexShrink:0},children:[n.jsx(s.Button,{size:"xs",color:"red",leftSection:n.jsx(S.IconX,{size:14}),onClick:d,children:r("common.actions.cancel")}),n.jsx(s.Button,{size:"xs",color:"blue",leftSection:n.jsx(S.IconDeviceFloppy,{size:14}),onClick:u,disabled:o===t,children:r("common.actions.confirm")})]})]})})]})}),u3=k.observer(({sx:e={}})=>{const{t}=m.useTranslation(),r=H(),{panel:a}=re(),o=r.dashboardStateValues,l=(()=>{const i={...o,...a.variableStrings};return JSON.stringify(i,null,2)})();return n.jsx(s.Stack,{sx:{overflow:"hidden",...e},children:n.jsxs(s.Tabs,{defaultValue:"vars",keepMounted:!1,children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"guide",leftSection:n.jsx(S.IconAlertCircle,{size:14}),children:t("panel.variable.guide.tabs.guide")}),n.jsx(s.Tabs.Tab,{value:"vars",leftSection:n.jsx(S.IconVariable,{size:14}),children:t("panel.variable.guide.tabs.vars")})]}),n.jsx(s.Tabs.Panel,{value:"guide",pt:"xs",children:n.jsx(Fe.CodeHighlight,{language:"sql",sx:{width:"100%"},withCopyButton:!1,code:t("panel.variable.guide.text")})}),n.jsx(s.Tabs.Panel,{value:"vars",pt:"xs",children:n.jsx(Fe.CodeHighlight,{language:"json",sx:{width:"100%"},withCopyButton:!1,code:l})})]})})}),is={name:"new_var",size:"1rem",weight:"initial",color:{type:"static",staticColor:"Red"},data_field:"",aggregation:{type:"sum",config:{},fallback:"0"},formatter:{output:"number",mantissa:0,trimMantissa:!1,average:!1}};class p3{constructor(t){V(this,"panel");V(this,"selected");this.panel=t,t.variables.length>0&&(this.selected=t.variables[0]),F.makeAutoObservable(this,{},{deep:!1,autoBind:!0})}get variables(){return this.panel.variables}get variableOptions(){return this.panel.variables.map(t=>({label:t.name,value:t.name,description:t.aggregation.type}))}addNew(){const t=this.panel.variables.filter(r=>r.name.startsWith(is.name)).length;this.panel.addVariable(b.cloneDeep({...is,name:`${is.name}${t||""}`})),this.selected=b.last(this.panel.variables)}select(t){this.selected=t}selectByName(t){if(!t){console.warn("Unexpected null name when calling selectByName");return}const r=this.variables.find(a=>a.name===t);if(!r){console.error(`Variable by name[${t}] not found`);return}this.selected=r}remove(t){this.selected===t&&(this.selected=void 0);const r=this.panel.variables.indexOf(t);if(this.panel.removeVariable(t),!this.selected&&!b.isEmpty(this.panel.variables)){const a=Math.min(this.panel.variables.length-1,r);this.selected=this.panel.variables[a]}}}function h3(){const{panel:e}=ae();return O.useCreation(()=>new p3(e),[e])}const g3=h.forwardRef(function({value:t,onChange:r,remove:a},o){const{t:l}=m.useTranslation(),i=(c,d)=>{const u=b.cloneDeep(t);b.set(u,c,d),r(u)};return n.jsxs(s.Stack,{ref:o,children:[n.jsxs(s.Stack,{gap:"xs",px:"sm",py:"md",sx:{border:"1px solid #e9ecef"},children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(s.TextInput,{label:l("common.name"),required:!0,value:t.name,onChange:c=>i("name",c.currentTarget.value)}),n.jsx(L,{label:l("common.data_field"),required:!0,value:t.data_field,onChange:c=>i("data_field",c)})]}),n.jsx(Lr,{label:l("panel.variable.aggregation.label"),pt:0,value:t.aggregation,onChange:c=>i("aggregation",c),withFallback:!0}),t.aggregation.type!=="custom"&&n.jsxs(n.Fragment,{children:[n.jsx(s.Divider,{mt:"xl",mb:0,label:l("numbro.format.label"),labelPosition:"center",variant:"dashed"}),n.jsx(Ye,{value:t.formatter,onChange:c=>i("formatter",c)})]})]}),n.jsx(s.Button,{mt:20,leftSection:n.jsx(S.IconTrash,{size:16}),color:"red",variant:"light",onClick:a,children:l("panel.variable.delete")})]})}),f3=k.observer(e=>{const{t}=m.useTranslation(),r=O.useCreation(()=>hc(e.variable),[e.variable]),a=()=>e.uiModel.remove(e.variable);return n.jsxs(s.Stack,{"data-testid":"variable-editor",align:"stretch",children:[n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Button,{variant:"subtle",size:"xs",disabled:!r.changed,color:"red",onClick:r.reset,leftSection:n.jsx(S.IconRecycle,{size:18}),children:t("common.actions.revert_changes")}),n.jsx(s.Button,{variant:"filled",size:"xs",disabled:!r.changed,color:"green",onClick:r.commit,leftSection:n.jsx(S.IconDeviceFloppy,{size:18}),children:t("common.actions.save_changes")})]}),n.jsx(g3,{value:g.getSnapshot(r.copy),onChange:r.update,remove:a})]})});k.observer(e=>{const{uiModel:t}=e;return n.jsx(s.Stack,{className:"var-list",children:t.variables.map(r=>n.jsx(s.Button,{variant:t.selected===r?"filled":"subtle",color:"gray",onClick:()=>t.select(r),children:r.name},r.name))})});const b3=k.observer(({model:e})=>{const{t}=m.useTranslation();return n.jsx(s.Overlay,{color:"#fff",backgroundOpacity:1,sx:{position:"absolute"},children:n.jsx(s.Button,{variant:"light",size:"xs",leftSection:n.jsx(S.IconPlus,{size:16}),onClick:e.addNew,sx:{flexGrow:0,flexShrink:0,alignSelf:"flex-end",height:"38px"},children:t("panel.variable.add")})})}),y3=k.observer(()=>{var r;const{t:e}=m.useTranslation(),t=h3();return t.variableOptions.length===0?n.jsx(b3,{model:t}):n.jsxs(s.Stack,{pb:20,children:[n.jsxs(s.Group,{justify:"flex-start",children:[n.jsx(s.Select,{label:e("panel.variable.labels"),data:t.variableOptions,value:(r=t.selected)==null?void 0:r.name,onChange:t.selectByName,maxDropdownHeight:600,sx:{flexGrow:1}}),n.jsx(s.Button,{variant:"light",size:"xs",leftSection:n.jsx(S.IconPlus,{size:16}),onClick:t.addNew,sx:{flexGrow:0,flexShrink:0,alignSelf:"flex-end",height:"38px"},children:e("panel.variable.add")})]}),n.jsx(s.Divider,{variant:"dashed"}),t.selected?n.jsx(f3,{uiModel:t,variable:t.selected}):n.jsx("span",{children:"Select or create a new variable on right side"})]})}),v3={root:{flexGrow:1,width:"100%",minWidth:"1200px",overflow:"hidden"},panel:{width:"100%",minWidth:"1200px",height:"calc(100% - 44px)",padding:10,overflow:"auto"}},cs=({children:e})=>n.jsxs(s.Group,{wrap:"nowrap",grow:!0,justify:"flex-start",gap:20,sx:{width:"100%",height:"100%",position:"relative"},children:[n.jsx(s.Box,{sx:{maxWidth:"calc(100% - 610px - 10px)",height:"100%",overflow:"auto"},children:e}),n.jsxs(s.Stack,{justify:"flex-start",sx:{alignSelf:"flex-start",width:"600px",flexGrow:0,flexShrink:0},children:[n.jsx(a3,{}),n.jsx(s.Box,{sx:{flexGrow:1},children:n.jsx(u3,{})})]})]});function _3(e){return!["richText","button"].includes(e)}const m3=k.observer(({panel:e})=>{const{t}=m.useTranslation(),r=De.useModals(),a=j(),o=G(),[l,i]=h.useState(a.editor.panelTab),c=e.queries,u=_3(e.viz.type)&&e.dataLoading,p=u||e.queryErrors.length>0||e.queryStateMessages!==""||c.length===0,f=a.editor.path[1];h.useEffect(()=>{i(x=>p&&x==="Visualization"?"Data":x)},[e.id,p]);const v=h.useCallback(x=>{i(x),a.editor.setPanelTab(l)},[]),_=()=>{a.editor.setPath(["_VIEWS_",f])},w=()=>r.openConfirmModal({title:`${t("panel.delete")}?`,labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{o.removePanelByID(e.id,f),_()},confirmProps:{color:"red"},zIndex:320});return n.jsxs(Hn,{value:{panel:e,data:e.data,loading:u,errors:e.queryErrors,downloadPanelScreenshot:()=>{},getEchartsOptions:()=>null,setEchartsOptions:()=>{}},children:[n.jsxs(s.Group,{px:16,justify:"space-between",sx:{borderBottom:"1px solid #eee"},children:[n.jsx(s.Text,{size:"sm",pt:9,pb:8,children:e.name}),n.jsxs(s.Group,{justify:"flex-end",wrap:"nowrap",children:[n.jsx(d3,{panel:e,sourceViewID:f}),n.jsx(s.Button,{size:"xs",variant:"subtle",color:"red",onClick:w,leftSection:n.jsx(S.IconTrash,{size:14}),children:t("panel.delete")})]})]}),n.jsxs(s.Tabs,{value:l,onChange:v,keepMounted:!1,styles:v3,children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"Data",leftSection:n.jsx(S.IconDatabase,{size:14}),disabled:u,children:t("data.label")}),n.jsx(s.Tabs.Tab,{value:"Panel",leftSection:n.jsx(S.IconAppWindow,{size:14}),children:t("panel.label")}),n.jsx(s.Tabs.Tab,{value:"Variables",leftSection:n.jsx(S.IconVariable,{size:14}),disabled:p,children:n.jsx(s.Tooltip,{label:t("data.requires_data"),disabled:!p,withinPortal:!0,zIndex:310,children:n.jsx(s.Text,{size:"sm",children:t("panel.variable.labels")})})}),n.jsx(s.Tabs.Tab,{value:"Visualization",leftSection:n.jsx(S.IconChartHistogram,{size:14}),disabled:p,children:n.jsx(s.Tooltip,{label:t("data.requires_data"),disabled:!p,withinPortal:!0,zIndex:310,children:n.jsx(s.Text,{size:"sm",children:t("visualization.label")})})}),n.jsx(s.Tabs.Tab,{value:"Interactions",leftSection:n.jsx(S.IconRoute,{size:14}),children:t("interactions.label")})]}),n.jsxs(s.Tabs.Panel,{value:"Data",children:[n.jsx(s.LoadingOverlay,{visible:u,transitionProps:{exitDuration:0}}),n.jsx(n3,{})]}),n.jsx(s.Tabs.Panel,{value:"Panel",children:n.jsx(cs,{children:n.jsx(Xz,{})})}),n.jsx(s.Tabs.Panel,{value:"Variables",children:n.jsx(cs,{children:n.jsx(y3,{})})}),n.jsx(s.Tabs.Panel,{value:"Visualization",children:n.jsx(ne,{children:n.jsx(cs,{children:n.jsx(c3,{})})})}),n.jsx(s.Tabs.Panel,{value:"Interactions",children:n.jsx(ne,{children:n.jsx(yg,{})})})]})]})}),w3=k.observer(({viewID:e,panelID:t})=>{const r=G();if(!r.views.findByID(e))return n.jsxs(s.Text,{size:"14px",children:["View by ID[",e,"] is not found"]});const o=r.panels.findByID(t);return o?n.jsx(m3,{panel:o}):n.jsxs(s.Text,{size:"14px",children:["Panel by ID[",t,"] is not found"]})}),x3=k.observer(()=>{const{t:e}=m.useTranslation(),[t,r]=h.useState([]),a=De.useModals(),o=j(),l=v=>{o.editor.setPath(["_QUERIES_",v])},i=()=>{a.openConfirmModal({title:"Delete ununsed queries?",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:()=>o.content.removeUnusedQueries(),confirmProps:{color:"red"},zIndex:320})},c=()=>{o.content.queries.downloadSchema(t)},d=h.useMemo(()=>o.content.queries.sortedList.map(v=>v.id),[o.content.queries.sortedList]),u=()=>{r(d)},p=()=>{r([])},f=o.content.queriesUsage;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,{px:"md",ta:"left",sx:{userSelect:"none",cursor:"default"},children:e("query.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:!o.content.hasUnusedQueries,onClick:i,children:e("query.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.name")}),n.jsx(s.Table.Th,{style:{width:"200px"},children:e("data_source.label")}),n.jsx(s.Table.Th,{style:{width:"100px",textAlign:"right"},children:e("common.type")}),n.jsx(s.Table.Th,{style:{width:"100px",textAlign:"center"},children:e("query.usage.label")}),n.jsx(s.Table.Th,{style:{width:"300px",paddingLeft:"24px"},children:e("common.action")})]})}),n.jsx(s.Table.Tbody,{children:o.content.queries.sortedList.map(v=>{var w;const _=((w=f[v.id])==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.id,styles:{input:{cursor:"pointer"}}})}),n.jsx(s.Table.Td,{children:v.name}),n.jsx(s.Table.Td,{children:v.key}),n.jsx(s.Table.Td,{style:{textAlign:"right"},children:v.type}),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:()=>l(v.id),children:e("common.actions.open")})})]},v.id)})})]})})})]})}),C3=e=>{const{t}=m.useTranslation(),{queryModel:r}=e,a=j(),o=G(),i=o.findQueryUsage(r.id).length>0,c=De.useModals(),d=()=>{c.openConfirmModal({title:`${t("query.delete")}?`,labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{o.queries.removeQuery(r.id),a.editor.setPath(["_QUERIES_",""])},confirmProps:{color:"red"},zIndex:320})};return i?n.jsx(s.Tooltip,{label:t("query.cant_delete"),withArrow:!0,events:{hover:!0,focus:!1,touch:!1},withinPortal:!0,zIndex:320,position:"top-end",children:n.jsx(s.Box,{sx:{alignSelf:"flex-end"},children:n.jsx(s.Button,{disabled:!0,size:"xs",leftSection:n.jsx(S.IconTrash,{size:16}),children:t("query.delete")})})}):n.jsx(s.Button,{color:"red",size:"xs",onClick:d,leftSection:n.jsx(S.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:t("query.delete")})},S3=k.observer(C3),_d=({width:e="calc(100% - 32px)",lastWidth:t="50%",height:r,count:a,spacing:o=16,pl:l=0})=>n.jsxs(s.Stack,{gap:o,mt:6,pl:l,children:[Array.from(new Array(a-1),(i,c)=>n.jsx(s.Skeleton,{width:e,height:r,radius:"xs"},c)),n.jsx(s.Skeleton,{width:t,height:r,radius:"xs"})]}),en=({value:e})=>e===null||e===""?null:n.jsx(s.Tooltip,{label:e,disabled:!e,multiline:!0,zIndex:340,children:n.jsx(s.ActionIcon,{variant:"subtle",children:n.jsx(S.IconInfoCircle,{size:14})})}),T3=({column:e})=>{const{column_key:t,column_key_text:r}=e;return t?n.jsx(s.Tooltip,{label:r,disabled:!r,children:n.jsx(s.Badge,{variant:"light",children:t})}):null},k3=k.observer(({dataSource:e})=>{const{columns:t}=e.dbInfo;return t.loading?n.jsx(_d,{height:"24px",width:"100%",lastWidth:"100%",count:20,pl:6}):t.empty?null:n.jsxs(s.Table,{highlightOnHover:!0,fz:14,sx:{width:"auto",minWidth:"1000px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[n.jsxs("colgroup",{children:[n.jsx("col",{style:{width:50}}),n.jsx("col",{style:{minWidth:300}}),n.jsx("col",{style:{width:30}}),n.jsx("col",{style:{width:70}}),n.jsx("col",{style:{minWidth:300}}),n.jsx("col",{style:{minWidth:80,width:80}}),n.jsx("col",{style:{minWidth:120,width:120}})]}),n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:"#"}),n.jsx(s.Table.Th,{children:"Column Name"}),n.jsx(s.Table.Th,{}),n.jsx(s.Table.Th,{}),n.jsx(s.Table.Th,{children:"Type"}),n.jsx(s.Table.Th,{children:"Nullable"}),n.jsx(s.Table.Th,{children:"Default Value"})]})}),n.jsx(s.Table.Tbody,{children:t.data.map(r=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:r.ordinal_position}),n.jsx(s.Table.Td,{children:r.column_name}),n.jsx(s.Table.Td,{children:n.jsx(en,{value:r.column_comment})}),n.jsx(s.Table.Td,{children:n.jsx(T3,{column:r})}),n.jsx(s.Table.Td,{children:r.column_type}),n.jsx(s.Table.Td,{children:r.is_nullable}),n.jsx(s.Table.Td,{children:n.jsx(en,{value:r.column_default})})]},r.column_name))})]})}),D3=k.observer(({dataSource:e})=>{const{indexes:t}=e.dbInfo,r=t.data;return n.jsxs(s.Table,{highlightOnHover:!0,fz:14,sx:{width:"auto",minWidth:"950px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[n.jsxs("colgroup",{children:[n.jsx("col",{style:{width:100}}),n.jsx("col",{style:{minWidth:300}}),n.jsx("col",{style:{width:150}}),n.jsx("col",{style:{width:150}}),n.jsx("col",{style:{width:250}})]}),n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:"Index Length"}),n.jsx(s.Table.Th,{children:"Index Name"}),n.jsx(s.Table.Th,{children:"Index Algorithm"}),n.jsx(s.Table.Th,{children:"Unique"}),n.jsx(s.Table.Th,{children:"Column Name"})]})}),n.jsx(s.Table.Tbody,{children:r.map(a=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:a.index_length}),n.jsx(s.Table.Td,{children:a.index_name}),n.jsx(s.Table.Td,{children:a.index_algorithm}),n.jsx(s.Table.Td,{children:a.is_unique?"YES":"NO"}),n.jsx(s.Table.Td,{children:a.column_name})]},a.index_name))})]})}),z3=k.observer(({dataSource:e})=>{const{indexes:t}=e.dbInfo,r=t.data;return n.jsxs(s.Table,{highlightOnHover:!0,fz:14,sx:{width:"auto",minWidth:"850px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[n.jsxs("colgroup",{children:[n.jsx("col",{style:{minWidth:300}}),n.jsx("col",{style:{width:150}}),n.jsx("col",{style:{width:100}}),n.jsx("col",{style:{width:100}}),n.jsx("col",{style:{width:100}}),n.jsx("col",{style:{width:100}})]}),n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:"Index Name"}),n.jsx(s.Table.Th,{children:"Index Algorithm"}),n.jsx(s.Table.Th,{children:"Unique"}),n.jsx(s.Table.Th,{children:"Definition"}),n.jsx(s.Table.Th,{children:"Condition"}),n.jsx(s.Table.Th,{children:"Comment"})]})}),n.jsx(s.Table.Tbody,{children:r.map(a=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:a.index_name}),n.jsx(s.Table.Td,{children:a.index_algorithm}),n.jsx(s.Table.Td,{children:a.is_unique?"YES":"NO"}),n.jsx(s.Table.Td,{children:n.jsx(en,{value:a.index_definition})}),n.jsx(s.Table.Td,{children:n.jsx(en,{value:a.condition})}),n.jsx(s.Table.Td,{children:n.jsx(en,{value:a.comment})})]},a.index_name))})]})}),M3=k.observer(({dataSource:e})=>{const{indexes:t}=e.dbInfo;return t.loading||t.empty?null:e.type===W.MySQL?n.jsx(D3,{dataSource:e}):e.type===W.Postgresql?n.jsx(z3,{dataSource:e}):null}),I3=k.observer(({dataSource:e})=>n.jsxs(s.Stack,{gap:40,pt:10,sx:{flexGrow:1,overflow:"auto",position:"relative"},children:[n.jsx(ne,{children:n.jsx(k3,{dataSource:e})}),n.jsx(ne,{children:n.jsx(M3,{dataSource:e})})]}));function V3({table_type:e}){return e==="VIEW"?n.jsx(S.IconEye,{size:14}):e==="BASE TABLE"?n.jsx(S.IconTable,{size:14}):null}const P3=k.observer(({dataSource:e})=>{const t=e.dbInfo,{tables:r}=t;return r.loading?n.jsx(_d,{height:"24px",lastWidth:"50%",count:15}):n.jsx(s.Box,{h:"100%",sx:{overflow:"auto",".mantine-NavLink-label":{fontFamily:"monospace"}},children:Object.entries(r.data).map(([a,o])=>n.jsx(s.NavLink,{label:a,title:a,leftSection:n.jsx(S.IconDatabase,{size:14}),defaultOpened:t.table_schema===a,pl:0,childrenOffset:14,children:o.map(l=>n.jsx(s.NavLink,{label:l.table_name,title:l.table_name,leftSection:n.jsx(V3,{table_type:l.table_type}),onClick:()=>{t.setKeywords(a,l.table_name)},active:t.table_name===l.table_name},l.table_name))},a))})}),$3=({visible:e})=>n.jsx(s.Box,{py:10,sx:{width:"100%",height:"100%",overflow:"hidden",position:"relative"},children:n.jsx(s.LoadingOverlay,{visible:e})}),A3=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],E3={section:{"&[data-position=left]":{width:"70px",textAlign:"center"}},input:{paddingLeft:"70px"}},B3=k.observer(({dataSource:e})=>{const{t}=m.useTranslation(),{tableData:r}=e.dbInfo;return n.jsxs(s.Group,{pt:10,px:10,justify:"space-between",children:[n.jsxs(s.Group,{justify:"flex-start",children:[r.maxPage>1&&n.jsx(s.Pagination,{size:"sm",value:r.page,onChange:r.setPage,total:r.maxPage,withEdges:r.maxPage>7,styles:{control:{height:"30px"}}}),n.jsx(s.Select,{leftSection:n.jsx(s.Text,{ta:"center",c:"dimmed",size:"14px",children:t("common.pagination.page_size")}),size:"xs",styles:E3,data:A3,value:String(r.limit),onChange:a=>r.setLimit(Number(a)),comboboxProps:{zIndex:340}})]}),n.jsx(s.Group,{justify:"flex-end",children:n.jsx(s.Text,{c:"dimmed",my:0,size:"14px",children:t("common.pagination.total_rows",{total:r.total})})})]})}),q3=k.observer(({dataSource:e})=>{const t=e.dbInfo.tableData;return t.maxPage===0?n.jsx(s.Text,{mt:20,c:"red",size:"md",ta:"center",ff:"monospace",children:"This table is empty"}):t.error?n.jsx(s.Text,{mt:20,c:"red",size:"md",ta:"center",ff:"monospace",children:t.error}):t.page===1&&t.loading?n.jsx($3,{visible:!0}):n.jsxs(ne,{children:[n.jsx(B3,{dataSource:e}),n.jsxs(s.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[n.jsx(s.LoadingOverlay,{visible:t.loading,overlayProps:{blur:2}}),n.jsx(yd,{data:t.data})]})]})}),L3={root:{flexGrow:1,overflow:"auto",borderLeft:"1px solid #efefef"},tabsList:{borderBottom:"1px solid #efefef"},tab:{minWidth:120}},O3=k.observer(({dataSource:e})=>{const{t}=m.useTranslation(),r=e.dbInfo;return h.useEffect(()=>{r.loadTablesIfEmpty()},[r]),r.tables.error?n.jsx(s.Text,{c:"red",size:"md",ta:"center",ff:"monospace",children:r.tables.error}):n.jsxs(s.Flex,{sx:{height:"100%"},children:[n.jsx(s.Box,{w:300,sx:{flexGrow:0,flexShrink:0,position:"relative"},children:n.jsx(ne,{children:n.jsx(P3,{dataSource:e})})}),n.jsxs(s.Tabs,{defaultValue:"structure",styles:L3,children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"structure",leftSection:n.jsx(S.IconColumns,{size:14}),children:t("data_source.table_structure_short")}),n.jsx(s.Tabs.Tab,{value:"data",leftSection:n.jsx(S.IconDatabase,{size:14}),children:t("data.label")})]}),n.jsx(s.Tabs.Panel,{value:"structure",children:n.jsx(I3,{dataSource:e})}),n.jsx(s.Tabs.Panel,{value:"data",sx:{width:"100%",height:"calc(100% - 36px)",overflow:"hidden"},children:n.jsx(q3,{dataSource:e})})]})]})}),N3={modal:{paddingLeft:"0px !important",paddingRight:"0px !important"},header:{marginBottom:0,padding:"20px 20px 10px",borderBottom:"1px solid #efefef",gap:"20px"},title:{flexGrow:1},body:{padding:"0 0 0 20px"}},md=k.observer(({dataSource:e,triggerButtonProps:t={}})=>{const{t:r}=m.useTranslation(),[a,o]=h.useState(!1),{type:l}=e;return l==="http"||l==="merico_metric_system"?null:n.jsxs(n.Fragment,{children:[n.jsx(s.Modal,{opened:a,onClose:()=>o(!1),title:n.jsxs(s.Group,{justify:"space-between",sx:{flexGrow:1},children:[n.jsx(s.Text,{size:"sm",fw:500,children:r("data_source.explorer")}),n.jsxs(s.Group,{gap:7,children:[n.jsx(s.Badge,{variant:"gradient",gradient:{from:"indigo",to:"cyan"},children:e.key}),n.jsx(s.Badge,{variant:"gradient",gradient:{from:"orange",to:"red"},children:e.type})]})]}),zIndex:320,size:"96vw",styles:N3,children:n.jsx(s.Box,{sx:{height:"calc(100vh - 220px)"},children:n.jsx(O3,{dataSource:e})})}),n.jsx(s.Button,{variant:"subtle",onClick:()=>o(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},...t,children:r("data_source.see_table_structure")})]})}),wd={http:"HTTP",mysql:"MySQL",postgresql:"PostgreSQL",merico_metric_system:"指标系统"},G3=({option:e,...t})=>{const{label:r,type:a}=e;return a===W.Transform?n.jsxs(s.Group,{className:"transform-query-option",justify:"flex-start",...t,sx:{flexGrow:1,'&[data-selected="true"]':{".mantine-Text-root":{color:"white"},svg:{stroke:"white"}}},children:[n.jsx(S.IconVectorTriangle,{size:14,color:"#228be6"}),n.jsx(s.Text,{size:"sm",c:"blue",children:r})]}):n.jsxs(s.Group,{justify:"space-between",...t,sx:{flexGrow:1},children:[n.jsx(s.Text,{size:"sm",children:r}),n.jsx(s.Text,{size:"sm",children:wd[a]})]})},xd=k.observer(({queryModel:e,size:t="sm"})=>{const{t:r}=m.useTranslation(),a=j(),{data:o=[],loading:l}=O.useRequest(Ba,{refreshDeps:[]},[]),i=h.useMemo(()=>{const p=o.map(f=>({label:f.key,value:f.key,type:f.type}));return p.push({label:r("query.transform.data_source"),value:W.Transform,type:W.Transform}),p},[o]),c=h.useMemo(()=>i.reduce((p,f)=>(p[f.value]=f.type,p),{}),[i]),d=p=>{p!==null&&(e.setKey(p),e.setType(c[p]))},u=h.useMemo(()=>a.datasources.find({type:e.type,key:e.key}),[a,e.type,e.key]);return n.jsx(s.Select,{size:t,data:i,label:n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Box,{children:r("data_source.label")}),u&&n.jsx(md,{dataSource:u,triggerButtonProps:{size:"compact-xs",px:10}})]}),renderOption:G3,rightSection:u?n.jsx(s.Text,{size:"xs",c:"dimmed",children:wd[u.type]??u.type}):void 0,rightSectionWidth:85,maxDropdownHeight:500,styles:{root:{flex:1,minWidth:"300px"},label:{display:"block"},section:{pointerEvents:"none",justifyContent:"flex-end",paddingRight:"10px",".mantine-Text-root":{userSelect:"none"}}},disabled:l,value:e.key,onChange:d})}),F3=k.observer(({queryModel:e})=>{const{t}=m.useTranslation(),[r,a]=h.useState(e.name);h.useEffect(()=>{a(e.name)},[e.name]);const o=h.useMemo(()=>e.conditionOptionsWithInvalidRunbys.optionGroups.map(i=>({group:t(i.group),items:i.items})),[e.conditionOptionsWithInvalidRunbys.optionGroups]);return n.jsx(s.Center,{ml:20,mt:20,sx:{maxWidth:"600px"},children:n.jsxs(s.Stack,{gap:10,sx:{width:"100%"},children:[n.jsx(s.Divider,{mb:-10,variant:"dashed",label:t("query.basics"),labelPosition:"center"}),n.jsx(s.TextInput,{placeholder:t("query.name_description"),label:t("query.name"),required:!0,sx:{flex:1},value:r,onChange:l=>{a(l.currentTarget.value)},rightSection:n.jsx(s.ActionIcon,{variant:"filled",color:"blue",size:"sm",onClick:()=>e.setName(r),disabled:r===e.name,children:n.jsx(S.IconDeviceFloppy,{size:16})}),onBlur:()=>{e.setName(r)}}),n.jsx(xd,{queryModel:e}),n.jsx(s.Divider,{mt:10,mb:-10,variant:"dashed",label:t("query.conditions"),labelPosition:"center"}),n.jsx(s.MultiSelect,{label:t("query.run_by_condition.label"),description:t("query.run_by_condition.description"),placeholder:t("query.run_by_condition.unset"),data:o,value:[...e.run_by],onChange:e.setRunBy,renderOption:hr,maxDropdownHeight:500}),e.typedAsHTTP&&n.jsx(s.MultiSelect,{label:t("query.re_run_condition.label"),placeholder:t("query.re_run_condition.label"),data:o,value:[...e.config.react_to],onChange:e.config.setReactTo,renderOption:hr,maxDropdownHeight:500}),e.isTransform&&n.jsx(s.MultiSelect,{label:t("query.re_run_condition.label"),placeholder:t("query.re_run_condition.label"),data:o,value:[...e.config.react_to],onChange:e.config.setReactTo,renderOption:hr,maxDropdownHeight:500}),n.jsx(s.Divider,{mt:20,mb:10,variant:"dashed"}),n.jsx(S3,{queryModel:e})]})})});function Q3({content:e}){return n.jsxs(s.HoverCard,{width:"60vw",shadow:"md",zIndex:340,children:[n.jsx(s.HoverCard.Target,{children:n.jsx(s.ActionIcon,{size:16,color:"blue",variant:"subtle",children:n.jsx(S.IconEye,{})})}),n.jsx(s.HoverCard.Dropdown,{children:n.jsx(Fe.CodeHighlight,{language:"sql",withCopyButton:!1,code:e})})]})}const j3=k.observer(()=>{const t=[...j().globalSQLSnippets.list];return t.length===0?null:n.jsxs(s.Table,{horizontalSpacing:"xs",verticalSpacing:"xs",fz:"sm",highlightOnHover:!0,children:[n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:"Key"}),n.jsx(s.Table.Th,{children:"Value"})]})}),n.jsx(s.Table.Tbody,{children:t.map(r=>{const{id:a,content:o}=r;return n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:a}),n.jsx(s.Table.Td,{width:200,children:n.jsx(Q3,{content:o})})]},a)})})]})}),W3=`
|
|
553
|
+
`,gd=()=>{const{t:e}=m.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(Fe.CodeHighlight,{language:"typescript",withCopyButton:!1,code:Vz})})]})},Pz=k.observer(function({filter:t}){const{t:r}=m.useTranslation(),a=t.config,o=()=>{a.addStaticOption({label:"",value:""})},l=a.static_options,i=l.filter(c=>c.value!==""&&c.label!=="");return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Checkbox,{checked:a.required,onChange:c=>a.setRequired(c.currentTarget.checked),label:r("filter.widget.select.required")}),n.jsx(_t,{filter:t})]}),n.jsx(s.TextInput,{label:r("filter.widget.select.width"),description:r("filter.widget.multi_select.width_description"),value:a.min_width,onChange:c=>a.setMinWidth(c.currentTarget.value),placeholder:"200px"}),n.jsx(s.Divider,{label:r("filter.widget.select.configure_options"),labelPosition:"center"}),n.jsxs(s.Stack,{gap:10,sx:{position:"relative",minHeight:"50px"},children:[a.usingQuery&&n.jsxs(n.Fragment,{children:[n.jsx(s.Overlay,{backgroundOpacity:.8,color:"#000",sx:{left:"-5px",right:"-5px",top:"-5px",bottom:"-5px"}}),n.jsx(s.Center,{sx:{position:"absolute",top:0,left:0,zIndex:200,height:"100%",width:"100%"},children:n.jsx(s.Text,{c:"white",size:"16px",children:r("filter.widget.common.using_query")})})]}),i.length>0&&n.jsx(s.MultiSelect,{label:r("filter.widget.select.default_selection"),placeholder:r("filter.widget.select.no_default_selection"),data:i,value:[...a.default_value],onChange:a.setDefaultValue}),l.map((c,d)=>n.jsxs(s.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[n.jsx(s.TextInput,{label:r("common.label"),required:!0,value:a.static_options[d].label,onChange:u=>{a.static_options[d].setLabel(u.currentTarget.value)},sx:{flexGrow:1}}),n.jsx(s.TextInput,{label:r("common.value"),required:!0,value:a.static_options[d].value,onChange:u=>{a.static_options[d].setValue(u.currentTarget.value)},sx:{flexGrow:1}}),n.jsx(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>a.removeStaticOption(d),sx:{position:"absolute",top:28,right:5},children:n.jsx(S.IconTrash,{size:16})})]},d)),n.jsx(s.Button,{mt:10,size:"xs",color:"blue",leftSection:n.jsx(S.IconPlaylistAdd,{size:20}),onClick:o,sx:{width:"50%"},mx:"auto",children:r("common.actions.add_an_option")})]}),n.jsx(s.Divider,{label:r("filter.widget.common.or_fetch_options_from_datasource"),labelPosition:"center"}),n.jsx(Vn,{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(_a,{config:a}),n.jsx(gd,{})]})}),fd={date_unit:{zh:[{label:"天",value:"day"},{label:"周",value:"week"},{label:"双周",value:"bi-week"},{label:"月",value:"month"},{label:"季度",value:"quarter"},{label:"年",value:"year"}],en:[{label:"Day",value:"day"},{label:"Week",value:"week"},{label:"Bi-Week",value:"bi-week"},{label:"Month",value:"month"},{label:"Quarter",value:"quarter"},{label:"Year",value:"year"}]}},bd=k.observer(({config:e})=>{const{t,i18n:r}=m.useTranslation(),a=()=>{e.addStaticOption({label:"",value:""})},o=h.useMemo(()=>[{label:t("filter.widget.select.preset_options.date_unit"),value:"date_unit"}],[r.language]),l=i=>{if(!i||!(i in fd))return;const c=fd[i][r.language];e.replaceStaticOptions(c),c.length>0&&e.setDefaultValue(c[0].value)};return n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Button,{size:"xs",color:"blue",leftSection:n.jsx(S.IconPlaylistAdd,{size:20}),onClick:a,children:t("common.actions.add_an_option")}),n.jsx(s.Select,{placeholder:t("filter.widget.select.preset_options.apply"),value:null,onChange:l,data:o,size:"xs"})]})}),$z=k.observer(({config:e})=>{const{t,i18n:r}=m.useTranslation(),a=[...e.static_options],o=h.useMemo(()=>[{label:t("filter.widget.select.no_default_selection"),value:""},...a.filter(l=>l.value!=="")],[r.language,a]);return a.length===0?n.jsx(bd,{config:e}):n.jsxs(n.Fragment,{children:[n.jsx(s.Select,{label:t("filter.widget.select.default_selection"),data:o,value:e.default_value,onChange:e.setDefaultValue}),a.map((l,i)=>n.jsxs(s.Flex,{gap:10,sx:{position:"relative"},pr:"40px",children:[n.jsx(s.TextInput,{label:t("common.label"),required:!0,value:e.static_options[i].label,onChange:c=>{e.static_options[i].setLabel(c.currentTarget.value)},sx:{flexGrow:1}}),n.jsx(s.TextInput,{label:t("common.value"),required:!0,value:e.static_options[i].value,onChange:c=>{e.static_options[i].setValue(c.currentTarget.value)},sx:{flexGrow:1}}),n.jsx(s.ActionIcon,{color:"red",variant:"subtle",onClick:()=>e.removeStaticOption(i),sx:{position:"absolute",top:28,right:5},children:n.jsx(S.IconTrash,{size:16})})]},i)),n.jsx(bd,{config:e})]})}),Az=k.observer(({filter:e})=>{const{t}=m.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(s.Checkbox,{checked:r.clearable,onChange:a=>r.setClearable(a.currentTarget.checked),label:t("filter.widget.select.clearable")}),n.jsx(_t,{filter:e})]}),n.jsx(s.TextInput,{label:t("filter.widget.select.width"),value:r.width,onChange:a=>r.setWidth(a.currentTarget.value),placeholder:"200px"}),n.jsx(s.Divider,{label:t("filter.widget.select.configure_options"),labelPosition:"center"}),n.jsxs(s.Stack,{gap:10,sx:{position:"relative",minHeight:"50px"},children:[r.usingQuery&&n.jsxs(n.Fragment,{children:[n.jsx(s.Overlay,{backgroundOpacity:.8,color:"#000",sx:{left:"-5px",right:"-5px",top:"-5px",bottom:"-5px"}}),n.jsx(s.Center,{sx:{position:"absolute",top:0,left:0,zIndex:200,height:"100%",width:"100%"},children:n.jsx(s.Text,{c:"white",size:"16px",children:t("filter.widget.common.using_query")})})]}),n.jsx($z,{config:r})]}),n.jsx(s.Divider,{label:t("filter.widget.common.or_fetch_options_from_datasource"),labelPosition:"center"}),n.jsx(s.Checkbox,{checked:r.default_selection_count===1,onChange:a=>r.setDefaultSelectionCount(a.currentTarget.checked?1:0),label:t("filter.widget.select.select_first_option_by_default")}),n.jsx(Vn,{value:r.options_query_id,onChange:r.setOptionsQueryID}),n.jsx(gd,{})]})}),Ez=k.observer(function({filter:t}){const{t:r}=m.useTranslation(),a=t.config;return n.jsxs(n.Fragment,{children:[n.jsxs(s.Group,{children:[n.jsx(s.TextInput,{label:r("filter.widget.text_input.default_value"),value:a.default_value,onChange:o=>{a.setDefaultValue(o.currentTarget.value)},sx:{flexGrow:1}}),n.jsx(s.Box,{mt:22,children:n.jsx(_t,{filter:t})})]}),n.jsx(s.Checkbox,{checked:a.required,onChange:o=>a.setRequired(o.currentTarget.checked),label:r("filter.widget.text_input.required")})]})}),Bz=k.observer(({filter:e})=>{const{t}=m.useTranslation(),r=j().editor,a=e.usages,o=l=>{switch(l.type){case"query":r.setPath(["_QUERIES_",l.id]);break;case"sql_snippet":r.setPath(["_SQL_SNIPPETS_",l.id]);break;case"view":r.setPath(["_VIEWS_",l.id]);default:return}};return a.length===0?n.jsx(s.Text,{mt:10,ml:10,size:"sm",children:t("filter.usage.unused_description")}):n.jsxs(s.Table,{highlightOnHover:!0,layout:"fixed",styles:{table:{fontSize:"14px"}},children:[n.jsxs("colgroup",{children:[n.jsx("col",{style:{width:80}}),n.jsx("col",{})]}),n.jsx(s.Table.Tbody,{children:a.map(l=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:n.jsx(s.Text,{size:"xs",children:t(l.type_label)})}),n.jsx(s.Table.Td,{children:n.jsx(s.Anchor,{size:"xs",title:l.label,onClick:()=>o(l),children:n.jsx(s.Text,{truncate:"end",children:l.label})})})]},l.id))})]})}),qz=k.observer(({filter:e})=>{const{t}=m.useTranslation();return n.jsxs(s.Tabs,{defaultValue:"usage",children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"config",children:t("common.titles.config")}),n.jsx(s.Tabs.Tab,{value:"usage",children:t("filter.usage.label")})]}),n.jsx(s.Tabs.Panel,{value:"config",children:n.jsx(s.Box,{sx:{minWidth:"480px"},children:n.jsx(Fe.CodeHighlight,{mt:22,language:"json",withCopyButton:!1,code:JSON.stringify(e,null,4)})})}),n.jsx(s.Tabs.Panel,{value:"usage",children:n.jsx(Bz,{filter:e})})]})}),Lz=k.observer(({filter:e})=>{const{t}=m.useTranslation(),r=e.config,a=h.useMemo(()=>{const p=Bi(r.default_step);return Object.entries(p).map(([f,v])=>({group:t(`filter.widget.date_range.shortcut.${f}.label`),items:v.map(({key:_,value:w})=>({label:t(`filter.widget.date_range.shortcut.${f}.full.${_}`),value:w}))}))},[r.default_step]),o=[...r.default_value],[l,i]=h.useState(o),c=p=>{i(p),!(p[0]===null||p[1]===null)&&(r.setDefaultValue({value:Jt(p[0],p[1],r.default_step),shortcut:null,step:r.default_step}),r.setDefaultShortcut(null))},d=p=>{i([null,null]),r.setDefaultValue({value:[null,null],shortcut:p,step:r.default_step}),r.setDefaultShortcut(p)},u=p=>{r.setDefaultValue({value:r.default_shortcut?[null,null]:Jt(r.default_value[0],r.default_value[1],p),shortcut:r.default_shortcut,step:p}),r.setDefaultStep(p)};return n.jsxs(n.Fragment,{children:[n.jsx(s.Group,{children:n.jsx(s.Checkbox,{checked:r.required,onChange:p=>r.setRequired(p.currentTarget.checked),label:t("filter.widget.date_range.required")})}),n.jsx(yc,{value:r.default_step,onChange:u,label:"默认步长"}),n.jsxs(s.Group,{children:[n.jsx(s.Select,{data:a,label:t("filter.widget.date_range.default_by_shortcut"),value:r.default_shortcut,onChange:d,placeholder:t("filter.widget.date_range.default_by_shortcut_placeholder"),clearable:!0,sx:{flexGrow:1},maxDropdownHeight:500}),n.jsx(wt.DatePickerInput,{type:"range",label:t("filter.widget.date_range.default_value"),value:l,onChange:c,valueFormat:r.inputFormat,allowSingleDateInRange:!0,numberOfColumns:2,w:"50%",disabled:!!r.default_shortcut})]}),r.required&&!r.default_shortcut&&r.default_value.every(p=>!p)&&n.jsx(s.Text,{size:"xs",mt:-10,ta:"center",children:"快捷方式与具体日期范围二选一,且必填"}),n.jsx(_t,{filter:e})]})}),Oz={[P.Select]:Az,[P.MultiSelect]:Pz,[P.TreeSelect]:BT,[P.TreeSingleSelect]:jT,[P.TextInput]:Ez,[P.Checkbox]:zz,[P.DateRange]:Iz,[P.MericoDateRange]:Lz},rt={[P.Select]:"filter.widget.names.select",[P.MultiSelect]:"filter.widget.names.multi_select",[P.TreeSelect]:"filter.widget.names.tree_select",[P.TreeSingleSelect]:"filter.widget.names.tree_single_select",[P.TextInput]:"filter.widget.names.text_input",[P.Checkbox]:"filter.widget.names.checkbox",[P.DateRange]:"filter.widget.names.date_range",[P.MericoDateRange]:"filter.widget.names.merico_date_range"},Nz=k.observer(({filter:e})=>{const{t,i18n:r}=m.useTranslation(),a=F(),o=h.useMemo(()=>Oz[e.type],[e.type]),l=h.useMemo(()=>[{label:t(rt[P.Select]),value:"select"},{label:t(rt[P.MultiSelect]),value:"multi-select"},{label:t(rt[P.TreeSelect]),value:"tree-select"},{label:t(rt[P.TreeSingleSelect]),value:"tree-single-select"},{label:t(rt[P.TextInput]),value:"text-input"},{label:t(rt[P.Checkbox]),value:"checkbox"},{label:t(rt[P.DateRange]),value:"date-range"},{label:t(rt[P.MericoDateRange]),value:"merico-date-range"}],[r.language]);return n.jsxs(s.Group,{grow:!0,gap:20,align:"top",children:[n.jsxs(s.Box,{w:600,children:[n.jsx(s.Text,{pb:"md",c:"gray",size:"sm",children:t("common.titles.edit")}),n.jsxs(s.Stack,{children:[n.jsxs(s.Group,{wrap:"nowrap",children:[n.jsx(s.NumberInput,{label:t("filter.field.order"),required:!0,value:e.order,onChange:e.setOrder,hideControls:!0,sx:{flexGrow:"1 !important"}}),e.auto_submit_supported&&n.jsx(s.Checkbox,{label:t("filter.field.auto_submit"),checked:e.auto_submit,onChange:i=>e.setAutoSubmit(i.currentTarget.checked),mt:22})]}),n.jsx(s.MultiSelect,{label:t("filter.field.visible_in"),data:a.views.options,value:[...e.visibleInViewsIDs],onChange:e.setVisibleInViewsIDs}),n.jsx(s.TextInput,{label:t("common.key"),placeholder:t("filter.field.key_placeholder"),required:!0,value:e.key,onChange:i=>{e.setKey(i.currentTarget.value)}}),n.jsx(s.TextInput,{label:t("common.label"),placeholder:t("filter.field.label_placeholder"),required:!0,value:e.label,onChange:i=>{e.setLabel(i.currentTarget.value)}}),n.jsx(s.Select,{label:t("filter.field.widget"),data:l,required:!0,value:e.type,onChange:e.setType,maxDropdownHeight:500}),n.jsx(s.Divider,{mb:0,mt:10,variant:"dashed",labelPosition:"center"}),n.jsx(o,{filter:e})]})]}),n.jsx(qz,{filter:e})]})}),Gz=k.observer(({id:e})=>{const{t}=m.useTranslation(),r=De.useModals(),a=j(),o=F();if(e==="")return null;const l=o.filters.findByID(e);if(!l)return n.jsxs(s.Text,{size:"14px",children:["Filter by ID[",e,"] is not found"]});const i=()=>{a.editor.setPath(["_FILTERS_",""])},c=()=>{r.openConfirmModal({title:`${t("filter.delete")}?`,labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{o.filters.removeByID(e),i()},confirmProps:{color:"red"},zIndex:320})};return n.jsxs(s.Stack,{sx:{minWidth:"1100px",height:"100vh"},gap:"sm",pb:30,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("filter.delete")})}),n.jsx(s.Box,{sx:{flexGrow:1,maxHeight:"calc(100% - 52px)",overflow:"auto"},children:n.jsx(Nz,{filter:l})})]})}),Fz=k.observer(()=>{const{t:e}=m.useTranslation(),[t,r]=h.useState([]),a=j(),o=u=>{a.editor.setPath(["_FILTERS_",u])},l=()=>{a.content.filters.downloadSchema(t)},i=h.useMemo(()=>a.content.filters.sortedList.map(u=>u.id),[a.content.filters.sortedList]),c=()=>{r(i)},d=()=>{r([])};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("filter.manage")})}),n.jsx(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:c,children:e("common.actions.select_all")}),n.jsx(s.Button,{variant:"default",size:"xs",onClick:d,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:l,children:e("common.actions.download_schema")})]})}),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,{style:{width:"300px"},children:e("common.label")}),n.jsx(s.Table.Th,{children:e("common.key")}),n.jsx(s.Table.Th,{style:{width:"100px"},children:e("filter.field.widget")}),n.jsx(s.Table.Th,{style:{width:"300px",paddingLeft:"24px"},children:e("common.action")})]})}),n.jsx(s.Table.Tbody,{children:a.content.filters.sortedList.map(u=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:n.jsx(s.Checkbox,{value:u.id,styles:{input:{cursor:"pointer"}}})}),n.jsx(s.Table.Td,{children:u.label}),n.jsx(s.Table.Td,{children:u.key}),n.jsx(s.Table.Td,{children:e(rt[u.type])}),n.jsx(s.Table.Td,{children:n.jsx(s.Button,{variant:"subtle",size:"xs",onClick:()=>o(u.id),children:e("common.actions.open")})})]},u.id))})]})})})]})}),Qz=k.observer(()=>{const{t:e}=m.useTranslation(),t=F(),[r,a]=h.useState(()=>JSON.stringify(t.mock_context.current,null,4)),o=()=>{try{t.mock_context.replace(JSON.parse(r))}catch(i){Ge.showNotification({title:"Failed",message:i.message,color:"red"})}},l=h.useMemo(()=>{try{return JSON.stringify(JSON.parse(r))!==JSON.stringify(t.mock_context.current)}catch{return!1}},[r,t.mock_context.current]);return n.jsxs(s.Stack,{sx:{border:"1px solid #eee",borderLeft:"none",borderRight:"none",flexGrow:1,maxWidth:"unset"},children:[n.jsx(s.Group,{justify:"flex-start",pl:"md",py:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef",flexGrow:0},children:n.jsx(s.Text,{size:"sm",fw:500,children:e("mock_context.label")})}),n.jsx(s.Group,{grow:!0,px:"md",pb:"md",pt:0,sx:{flexGrow:1,position:"relative",alignItems:"flex-start"},children:n.jsxs(s.Stack,{gap:10,sx:{maxWidth:"unset !important"},children:[n.jsxs(s.Group,{justify:"flex-start",children:[n.jsx(s.Text,{size:"sm",children:e("mock_context.hint")}),n.jsx(s.Button,{color:"green",size:"compact-sm",leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),onClick:o,disabled:!l,children:e("common.actions.save")})]}),n.jsx(s.JsonInput,{validationError:"Invalid json",formatOnBlur:!0,autosize:!0,minRows:30,value:r,onChange:a,sx:{flexGrow:1}})]})})]})}),jz=k.observer(()=>{const{t:e}=m.useTranslation(),{panel:t}=ae();return n.jsx(Ue,{label:e("panel.panel_description"),value:t.description,onChange:t.setDescription,styles:{root:{flexGrow:1}}},t.id)}),Wz=k.observer(()=>{const{t:e}=m.useTranslation(),{panel:t}=ae(),r=H().layouts.findItemByPanelID(t.id),{style:a}=t;return n.jsx(n.Fragment,{children:n.jsxs(s.Stack,{gap:20,children:[n.jsxs(s.Group,{grow:!0,align:"top",children:[n.jsx(s.NumberInput,{label:e("panel.style.width"),min:1,max:36,step:1,decimalScale:0,rightSection:n.jsx(s.Text,{size:"12px",children:e("panel.style.width_postfix")}),styles:{section:{width:"auto",maxWidth:"100px",paddingRight:"14px",justifyContent:"flex-end"}},value:r.w,onChange:o=>{typeof o!="string"&&r.setWidth(o)}}),n.jsx(s.NumberInput,{label:e("panel.style.height"),rightSection:n.jsx(s.Text,{size:"12px",children:e("panel.style.height_postfix")}),styles:{section:{width:"40px"}},value:r.h,onChange:o=>{typeof o!="string"&&r.setHeight(o)}})]}),n.jsx(s.Checkbox,{ml:6,label:e("panel.style.border"),checked:a.border.enabled,onChange:o=>a.border.setEnabled(o.currentTarget.checked)})]})})}),Uz=()=>n.jsxs("span",{className:"mantine-103svbs mantine-InputWrapper-required mantine-Select-required","aria-hidden":"true",children:[" ","*"]}),Kz=k.observer(()=>{const{t:e}=m.useTranslation(),{panel:t}=ae(),{name:r}=t,[a,o]=te.useInputState(r),l=r!==a,i=h.useCallback(()=>{l&&t.setName(a)},[l,a]);h.useEffect(()=>{o(r)},[r]);const c=!a.trim();return n.jsxs(s.Stack,{gap:4,children:[n.jsxs(s.Group,{align:"center",children:[n.jsxs(s.Text,{size:"14px",fw:500,children:[e("panel.panel_name"),n.jsx(Uz,{})]}),n.jsx(s.ActionIcon,{variant:"subtle",color:"blue",disabled:!l||c,onClick:i,children:n.jsx(S.IconDeviceFloppy,{size:18})})]}),n.jsx(s.TextInput,{value:a,onChange:o,required:!0})]})}),Yz=k.observer(()=>{const{t:e}=m.useTranslation(),{panel:t}=ae();return n.jsx(s.Stack,{gap:6,mb:10,children:n.jsxs(s.Group,{pl:6,justify:"flex-start",gap:20,children:[n.jsx(s.Checkbox,{size:"sm",checked:t.title.show,onChange:r=>t.title.setShow(r.currentTarget.checked),label:e("panel.show_title"),sx:{userSelect:"none"}}),n.jsx(s.Checkbox,{size:"sm",checked:!0,disabled:!0,label:e("panel.use_name_as_title")})]})})});function Xz(){const{t:e}=m.useTranslation();return n.jsxs(s.Stack,{sx:{height:"100%"},children:[n.jsx(Wz,{}),n.jsx(s.Divider,{label:e("common.info"),labelPosition:"center",variant:"dashed"}),n.jsx(Kz,{}),n.jsx(Yz,{}),n.jsx(jz,{})]})}const Zz={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 yd({data:e}){const t=h.useMemo(()=>{if(!Array.isArray(e)||e.length===0)return[];const a=ge.createColumnHelper();return Object.keys(e[0]).map(o=>a.accessor(o,{cell:l=>l.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:Zz,children:[n.jsx(s.Table.Thead,{children:r.getHeaderGroups().map(a=>n.jsx(s.Table.Tr,{children:a.headers.map(o=>n.jsxs(s.Table.Th,{style:{width:o.getSize()},children:[o.isPlaceholder?null:ge.flexRender(o.column.columnDef.header,o.getContext()),n.jsx(s.ActionIcon,{variant:"subtle",onMouseDown:o.getResizeHandler(),onTouchStart:o.getResizeHandler(),className:`resizer ${o.column.getIsResizing()?"isResizing":""}`,children:n.jsx(S.IconArrowBarToRight,{})})]},o.id))},a.id))}),n.jsx(s.Table.Tbody,{children:r.getRowModel().rows.map(a=>n.jsx(s.Table.Tr,{children:a.getVisibleCells().map(o=>n.jsx(s.Table.Td,{children:n.jsx(ne,{children:typeof o.getValue()=="object"?n.jsx("pre",{children:JSON.stringify(o.getValue(),null,2)}):ge.flexRender(o.column.columnDef.cell,o.getContext())})},o.id))},a.id))})]})})}const Jz=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],Hz={section:{"&[data-position=left]":{width:"70px",textAlign:"center"}},input:{paddingLeft:"70px"}},Rz=({data:e,page:t,setPage:r,limit:a,setLimit:o})=>{const{t:l}=m.useTranslation(),i=e.length,c=Math.ceil(i/a),d=p=>{p&&(r(1),o(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:[c>1&&n.jsx(s.Pagination,{size:"sm",value:t,onChange:r,total:c,withEdges:c>7,styles:{control:{height:"30px"}}}),!u&&n.jsx(s.Select,{leftSection:n.jsx(s.Text,{ta:"center",c:"dimmed",size:"14px",children:l("common.pagination.page_size")}),size:"xs",styles:Hz,data:Jz,value:String(a),onChange:d})]}),n.jsx(s.Group,{justify:"flex-end",children:n.jsx(s.Text,{c:"dimmed",my:0,size:"14px",children:l("common.pagination.total_rows",{total:i})})})]})},e3=Do(({data:e,loading:t})=>{const[r,a]=h.useState(1),[o,l]=h.useState(20),i=h.useMemo(()=>{const c=(r-1)*o,d=c+o;return e.slice(c,d)},[e,r,o]);return n.jsxs(ne,{children:[n.jsx(Rz,{data:e,page:r,setPage:a,limit:o,setLimit:l}),n.jsxs(s.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[n.jsx(s.LoadingOverlay,{visible:t,overlayProps:{blur:2}}),n.jsx(yd,{data:i})]})]})}),t3=k.observer(({queryID:e})=>{const{t}=m.useTranslation(),r=H(),a=h.useMemo(()=>r.queries.findByID(e),[r,e]);if(!a||a.state==="loading")return null;const{error:o,metricQueryPayloadErrorString:l,stateMessage:i}=a;return o||l?n.jsx(s.Text,{mt:10,c:"red",size:"md",ta:"center",ff:"monospace",children:o??l}):i?n.jsx(s.Text,{size:"sm",mt:10,c:"gray",ta:"center",children:t(i)}):null}),ls=k.observer(({id:e,moreActions:t,refreshOnMount:r})=>{const{t:a}=m.useTranslation(),o=H(),{data:l,state:i}=o.getDataStuffByID(e),c=i==="loading",d=h.useCallback(()=>{o.queries.refetchDataByQueryID(e)},[e,o]),u=()=>{o.queries.downloadDataByQueryID(null,e)};h.useEffect(()=>{r&&d()},[d,r]);const p=!Array.isArray(l)||l.length===0;return n.jsxs(s.Stack,{gap:0,sx:{height:"100%",border:"1px solid #eee"},children:[n.jsxs(s.Group,{justify:"space-between",py:"md",pl:"md",sx:{borderBottom:"1px solid #eee",background:"#efefef"},children:[n.jsx(s.Group,{justify:"flex-start",children:n.jsx(s.Text,{size:"sm",fw:500,children:a("data.preview_data")})}),n.jsxs(s.Group,{pr:15,children:[t,n.jsx(s.ActionIcon,{variant:"subtle",color:"blue",disabled:c,onClick:d,children:n.jsx(S.IconRefresh,{size:16})}),n.jsx(s.ActionIcon,{variant:"subtle",color:"blue",disabled:c||p,onClick:u,children:n.jsx(S.IconDownload,{size:16})})]})]}),n.jsxs(s.Box,{pb:20,sx:{position:"relative",flexGrow:1,overflow:"auto"},children:[n.jsx(t3,{queryID:e}),n.jsx(e3,{data:l,loading:c})]})]})}),n3=k.observer(function(){const{t}=m.useTranslation(),r=j(),a=F(),{panel:o}=ae(),[l,i]=h.useState(!1),c=u=>{r.editor.setPath(["_QUERIES_",u])},d=o.queryIDs.length;return n.jsxs(n.Fragment,{children:[n.jsx(s.Drawer,{opened:l,onClose:()=>i(!1),title:t("panel.settings.choose_queries"),padding:"xl",size:500,zIndex:320,children:n.jsx(s.Checkbox.Group,{value:[...o.queryIDs],onChange:o.setQueryIDs,children:n.jsx(s.Stack,{gap:"lg",children:a.queries.options.map(u=>n.jsx(s.Checkbox,{label:u.label,value:u.value},u.value))})})}),n.jsxs(s.Stack,{gap:6,children:[n.jsx(s.Group,{justify:"flex-start",children:n.jsx(s.Button,{variant:"light",size:"sm",leftSection:n.jsx(S.IconLine,{size:16}),onClick:()=>i(!0),children:t(d===0?"panel.settings.need_to_choose_queries":"panel.settings.choose_queries")})}),d===1&&n.jsx(ls,{id:o.queryIDs[0],moreActions:n.jsx(s.Tooltip,{label:t("query.open"),children:n.jsx(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>c(o.queryIDs[0]),children:n.jsx(S.IconArrowCurveRight,{size:16})})})}),d>1&&n.jsxs(s.Tabs,{defaultValue:o.queryIDs[0],children:[n.jsx(s.Tabs.List,{children:o.queries.map(u=>n.jsx(s.Tabs.Tab,{value:u.id,children:u.name},u.id))}),o.queries.map(u=>n.jsx(s.Tabs.Panel,{value:u.id,children:n.jsx(ls,{id:u.id,moreActions:n.jsx(s.Tooltip,{label:t("query.open"),children:n.jsx(s.ActionIcon,{variant:"subtle",color:"blue",onClick:()=>c(u.id),children:n.jsx(S.IconArrowCurveRight,{size:16})})})})},u.id))]})]})]})}),r3=k.observer(()=>{const{panel:e}=re();return e.title.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:e.title.show?e.name:""})}):null}),a3=k.observer(()=>{const{panel:e}=re();return n.jsx(ne,{children:n.jsx(s.Box,{className:`panel-root ${e.title.show?"panel-root--show-title":""}`,p:0,sx:{border:"1px solid",borderColor:e.style.border.enabled?"#e9ecef":"transparent",flexGrow:0,flexShrink:0,width:"600px !important",height:"450px !important"},children:n.jsxs(Ns,{children:[n.jsx(s.Box,{className:"panel-description-popover-wrapper",children:n.jsx(Ka,{})}),n.jsx(r3,{}),n.jsx(Za,{panel:e})]})})})});function s3(){const{t:e}=m.useTranslation(),{vizManager:t}=h.useContext(lt);return h.useMemo(()=>b.orderBy(Object.entries(b.groupBy(t.availableVizList,"displayGroup")),[o=>o[0]],["asc"]).map(([o,l])=>{const i=l.map(c=>({value:c.name,label:e(c.displayName??it.name)}));return{group:e(o??"ungrouped"),items:b.orderBy(i,[c=>c.label],["asc"])}}),[t])}const o3=k.observer(({value:e,submit:t})=>{const{t:r}=m.useTranslation(),[a,o]=te.useInputState(e);h.useEffect(()=>{o(e)},[e]);const l=s3(),i=e!==a;return n.jsx(s.Select,{label:r("visualization.component"),value:a,searchable:!0,onChange:o,data:l,rightSection:n.jsx(s.ActionIcon,{variant:"filled",color:"green",disabled:!i,onClick:()=>t(a),styles:{root:{pointerEvents:"all"}},children:n.jsx(S.IconDeviceFloppy,{size:20})}),maxDropdownHeight:600})}),vd=[];function l3(e,t){try{return e.resolveComponent(t).createConfig()}catch{return null}}function i3(){const{data:e,panel:{variables:t,viz:r,title:a,name:o,queryIDs:l,description:i,id:c}}=ae(),{vizManager:d}=h.useContext(lt),u={name:o,title:a,description:i,viz:r,queryIDs:l,id:c},p=kc(u);try{return d.resolveComponent(u.viz.type),n.jsx(bn,{configure:p,children:n.jsx(uk,{variables:t,setVizConf:r.setConf,panel:u,vizManager:d,data:e})})}catch(f){return console.info(b.get(f,"message")),null}}const c3=k.observer(()=>{const{data:e,panel:{viz:t}}=ae(),{vizManager:r}=h.useContext(lt),a=h.useCallback(u=>{if(u===t.type)return;const p=l3(r,u);t.setType(u),t.setConf(p||{})},[t.type]),o=u=>{try{t.setConf(JSON.parse(u))}catch(p){console.error(p)}},l=h.useMemo(()=>{var u;return(u=vd.find(p=>p.value===t.type))==null?void 0:u.Panel},[t.type,vd]),i=i3(),c=l?h.createElement(l,{data:e,conf:t.conf,setConf:t.setConf}):null,d=i||c;return n.jsxs(s.Stack,{align:"stretch",sx:{height:"100%",overflow:"hidden"},children:[n.jsx(o3,{submit:a,value:t.type}),n.jsxs(ne,{children:[n.jsx(s.Stack,{pb:10,sx:{flexGrow:1,maxHeight:"100%",overflow:"auto"},children:d}),!d&&n.jsx(s.JsonInput,{minRows:20,label:"Config",value:JSON.stringify(t.conf,null,2),onChange:o})]})]})}),d3=k.observer(({panel:e,sourceViewID:t})=>{const{t:r}=m.useTranslation(),a=F(),[o,l]=h.useState(t);h.useEffect(()=>{l(t)},[t]);const[i,{open:c,close:d}]=te.useDisclosure(!1),u=()=>{e.moveToView(t,o),d()};return n.jsxs(n.Fragment,{children:[n.jsx(s.Button,{size:"xs",variant:"subtle",color:"blue",onClick:c,leftSection:n.jsx(S.IconBoxMultiple,{size:14}),children:r("panel.settings.change_view")}),n.jsx(s.Modal,{opened:i,onClose:d,title:r("panel.settings.change_view_title"),zIndex:320,children:n.jsxs(s.Stack,{sx:{maxHeight:"calc(100vh - 185px)",overflow:"hidden"},children:[n.jsx(s.Radio.Group,{value:o,onChange:l,pb:10,sx:{flexGrow:1,maxHeight:"calc(100vh - 185px - 30px)",overflow:"auto"},children:n.jsx(s.Stack,{gap:"xs",children:a.views.options.map(p=>n.jsx(s.Radio,{value:p.value,label:p.label},p.value))})}),n.jsxs(s.Group,{wrap:"nowrap",justify:"space-between",sx:{flexGrow:0,flexShrink:0},children:[n.jsx(s.Button,{size:"xs",color:"red",leftSection:n.jsx(S.IconX,{size:14}),onClick:d,children:r("common.actions.cancel")}),n.jsx(s.Button,{size:"xs",color:"blue",leftSection:n.jsx(S.IconDeviceFloppy,{size:14}),onClick:u,disabled:o===t,children:r("common.actions.confirm")})]})]})})]})}),u3=k.observer(({sx:e={}})=>{const{t}=m.useTranslation(),r=H(),{panel:a}=re(),o=r.dashboardStateValues,l=(()=>{const i={...o,...a.variableStrings};return JSON.stringify(i,null,2)})();return n.jsx(s.Stack,{sx:{overflow:"hidden",...e},children:n.jsxs(s.Tabs,{defaultValue:"vars",keepMounted:!1,children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"guide",leftSection:n.jsx(S.IconAlertCircle,{size:14}),children:t("panel.variable.guide.tabs.guide")}),n.jsx(s.Tabs.Tab,{value:"vars",leftSection:n.jsx(S.IconVariable,{size:14}),children:t("panel.variable.guide.tabs.vars")})]}),n.jsx(s.Tabs.Panel,{value:"guide",pt:"xs",children:n.jsx(Fe.CodeHighlight,{language:"sql",sx:{width:"100%"},withCopyButton:!1,code:t("panel.variable.guide.text")})}),n.jsx(s.Tabs.Panel,{value:"vars",pt:"xs",children:n.jsx(Fe.CodeHighlight,{language:"json",sx:{width:"100%"},withCopyButton:!1,code:l})})]})})}),is={name:"new_var",size:"1rem",weight:"initial",color:{type:"static",staticColor:"Red"},data_field:"",aggregation:{type:"sum",config:{},fallback:"0"},formatter:{output:"number",mantissa:0,trimMantissa:!1,average:!1}};class p3{constructor(t){V(this,"panel");V(this,"selected");this.panel=t,t.variables.length>0&&(this.selected=t.variables[0]),G.makeAutoObservable(this,{},{deep:!1,autoBind:!0})}get variables(){return this.panel.variables}get variableOptions(){return this.panel.variables.map(t=>({label:t.name,value:t.name,description:t.aggregation.type}))}addNew(){const t=this.panel.variables.filter(r=>r.name.startsWith(is.name)).length;this.panel.addVariable(b.cloneDeep({...is,name:`${is.name}${t||""}`})),this.selected=b.last(this.panel.variables)}select(t){this.selected=t}selectByName(t){if(!t){console.warn("Unexpected null name when calling selectByName");return}const r=this.variables.find(a=>a.name===t);if(!r){console.error(`Variable by name[${t}] not found`);return}this.selected=r}remove(t){this.selected===t&&(this.selected=void 0);const r=this.panel.variables.indexOf(t);if(this.panel.removeVariable(t),!this.selected&&!b.isEmpty(this.panel.variables)){const a=Math.min(this.panel.variables.length-1,r);this.selected=this.panel.variables[a]}}}function h3(){const{panel:e}=ae();return O.useCreation(()=>new p3(e),[e])}const g3=h.forwardRef(function({value:t,onChange:r,remove:a},o){const{t:l}=m.useTranslation(),i=(c,d)=>{const u=b.cloneDeep(t);b.set(u,c,d),r(u)};return n.jsxs(s.Stack,{ref:o,children:[n.jsxs(s.Stack,{gap:"xs",px:"sm",py:"md",sx:{border:"1px solid #e9ecef"},children:[n.jsxs(s.Group,{grow:!0,wrap:"nowrap",children:[n.jsx(s.TextInput,{label:l("common.name"),required:!0,value:t.name,onChange:c=>i("name",c.currentTarget.value)}),n.jsx(L,{label:l("common.data_field"),required:!0,value:t.data_field,onChange:c=>i("data_field",c)})]}),n.jsx(Lr,{label:l("panel.variable.aggregation.label"),pt:0,value:t.aggregation,onChange:c=>i("aggregation",c),withFallback:!0}),t.aggregation.type!=="custom"&&n.jsxs(n.Fragment,{children:[n.jsx(s.Divider,{mt:"xl",mb:0,label:l("numbro.format.label"),labelPosition:"center",variant:"dashed"}),n.jsx(Ye,{value:t.formatter,onChange:c=>i("formatter",c)})]})]}),n.jsx(s.Button,{mt:20,leftSection:n.jsx(S.IconTrash,{size:16}),color:"red",variant:"light",onClick:a,children:l("panel.variable.delete")})]})}),f3=k.observer(e=>{const{t}=m.useTranslation(),r=O.useCreation(()=>hc(e.variable),[e.variable]),a=()=>e.uiModel.remove(e.variable);return n.jsxs(s.Stack,{"data-testid":"variable-editor",align:"stretch",children:[n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Button,{variant:"subtle",size:"xs",disabled:!r.changed,color:"red",onClick:r.reset,leftSection:n.jsx(S.IconRecycle,{size:18}),children:t("common.actions.revert_changes")}),n.jsx(s.Button,{variant:"filled",size:"xs",disabled:!r.changed,color:"green",onClick:r.commit,leftSection:n.jsx(S.IconDeviceFloppy,{size:18}),children:t("common.actions.save_changes")})]}),n.jsx(g3,{value:g.getSnapshot(r.copy),onChange:r.update,remove:a})]})});k.observer(e=>{const{uiModel:t}=e;return n.jsx(s.Stack,{className:"var-list",children:t.variables.map(r=>n.jsx(s.Button,{variant:t.selected===r?"filled":"subtle",color:"gray",onClick:()=>t.select(r),children:r.name},r.name))})});const b3=k.observer(({model:e})=>{const{t}=m.useTranslation();return n.jsx(s.Overlay,{color:"#fff",backgroundOpacity:1,sx:{position:"absolute"},children:n.jsx(s.Button,{variant:"light",size:"xs",leftSection:n.jsx(S.IconPlus,{size:16}),onClick:e.addNew,sx:{flexGrow:0,flexShrink:0,alignSelf:"flex-end",height:"38px"},children:t("panel.variable.add")})})}),y3=k.observer(()=>{var r;const{t:e}=m.useTranslation(),t=h3();return t.variableOptions.length===0?n.jsx(b3,{model:t}):n.jsxs(s.Stack,{pb:20,children:[n.jsxs(s.Group,{justify:"flex-start",children:[n.jsx(s.Select,{label:e("panel.variable.labels"),data:t.variableOptions,value:(r=t.selected)==null?void 0:r.name,onChange:t.selectByName,maxDropdownHeight:600,sx:{flexGrow:1}}),n.jsx(s.Button,{variant:"light",size:"xs",leftSection:n.jsx(S.IconPlus,{size:16}),onClick:t.addNew,sx:{flexGrow:0,flexShrink:0,alignSelf:"flex-end",height:"38px"},children:e("panel.variable.add")})]}),n.jsx(s.Divider,{variant:"dashed"}),t.selected?n.jsx(f3,{uiModel:t,variable:t.selected}):n.jsx("span",{children:"Select or create a new variable on right side"})]})}),v3={root:{flexGrow:1,width:"100%",minWidth:"1200px",overflow:"hidden"},panel:{width:"100%",minWidth:"1200px",height:"calc(100% - 44px)",padding:10,overflow:"auto"}},cs=({children:e})=>n.jsxs(s.Group,{wrap:"nowrap",grow:!0,justify:"flex-start",gap:20,sx:{width:"100%",height:"100%",position:"relative"},children:[n.jsx(s.Box,{sx:{maxWidth:"calc(100% - 610px - 10px)",height:"100%",overflow:"auto"},children:e}),n.jsxs(s.Stack,{justify:"flex-start",sx:{alignSelf:"flex-start",width:"600px",flexGrow:0,flexShrink:0},children:[n.jsx(a3,{}),n.jsx(s.Box,{sx:{flexGrow:1},children:n.jsx(u3,{})})]})]});function _3(e){return!["richText","button"].includes(e)}const m3=k.observer(({panel:e})=>{const{t}=m.useTranslation(),r=De.useModals(),a=j(),o=F(),[l,i]=h.useState(a.editor.panelTab),c=e.queries,u=_3(e.viz.type)&&e.dataLoading,p=u||e.queryErrors.length>0||e.queryStateMessages!==""||c.length===0,f=a.editor.path[1];h.useEffect(()=>{i(x=>p&&x==="Visualization"?"Data":x)},[e.id,p]);const v=h.useCallback(x=>{i(x),a.editor.setPanelTab(l)},[]),_=()=>{a.editor.setPath(["_VIEWS_",f])},w=()=>r.openConfirmModal({title:`${t("panel.delete")}?`,labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{o.removePanelByID(e.id,f),_()},confirmProps:{color:"red"},zIndex:320});return n.jsxs(Hn,{value:{panel:e,data:e.data,loading:u,errors:e.queryErrors,downloadPanelScreenshot:()=>{},getEchartsOptions:()=>null,setEchartsOptions:()=>{}},children:[n.jsxs(s.Group,{px:16,justify:"space-between",sx:{borderBottom:"1px solid #eee"},children:[n.jsx(s.Text,{size:"sm",pt:9,pb:8,children:e.name}),n.jsxs(s.Group,{justify:"flex-end",wrap:"nowrap",children:[n.jsx(d3,{panel:e,sourceViewID:f}),n.jsx(s.Button,{size:"xs",variant:"subtle",color:"red",onClick:w,leftSection:n.jsx(S.IconTrash,{size:14}),children:t("panel.delete")})]})]}),n.jsxs(s.Tabs,{value:l,onChange:v,keepMounted:!1,styles:v3,children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"Data",leftSection:n.jsx(S.IconDatabase,{size:14}),disabled:u,children:t("data.label")}),n.jsx(s.Tabs.Tab,{value:"Panel",leftSection:n.jsx(S.IconAppWindow,{size:14}),children:t("panel.label")}),n.jsx(s.Tabs.Tab,{value:"Variables",leftSection:n.jsx(S.IconVariable,{size:14}),disabled:p,children:n.jsx(s.Tooltip,{label:t("data.requires_data"),disabled:!p,withinPortal:!0,zIndex:310,children:n.jsx(s.Text,{size:"sm",children:t("panel.variable.labels")})})}),n.jsx(s.Tabs.Tab,{value:"Visualization",leftSection:n.jsx(S.IconChartHistogram,{size:14}),disabled:p,children:n.jsx(s.Tooltip,{label:t("data.requires_data"),disabled:!p,withinPortal:!0,zIndex:310,children:n.jsx(s.Text,{size:"sm",children:t("visualization.label")})})}),n.jsx(s.Tabs.Tab,{value:"Interactions",leftSection:n.jsx(S.IconRoute,{size:14}),children:t("interactions.label")})]}),n.jsxs(s.Tabs.Panel,{value:"Data",children:[n.jsx(s.LoadingOverlay,{visible:u,transitionProps:{exitDuration:0}}),n.jsx(n3,{})]}),n.jsx(s.Tabs.Panel,{value:"Panel",children:n.jsx(cs,{children:n.jsx(Xz,{})})}),n.jsx(s.Tabs.Panel,{value:"Variables",children:n.jsx(cs,{children:n.jsx(y3,{})})}),n.jsx(s.Tabs.Panel,{value:"Visualization",children:n.jsx(ne,{children:n.jsx(cs,{children:n.jsx(c3,{})})})}),n.jsx(s.Tabs.Panel,{value:"Interactions",children:n.jsx(ne,{children:n.jsx(yg,{})})})]})]})}),w3=k.observer(({viewID:e,panelID:t})=>{const r=F();if(!r.views.findByID(e))return n.jsxs(s.Text,{size:"14px",children:["View by ID[",e,"] is not found"]});const o=r.panels.findByID(t);return o?n.jsx(m3,{panel:o}):n.jsxs(s.Text,{size:"14px",children:["Panel by ID[",t,"] is not found"]})}),x3=k.observer(()=>{const{t:e}=m.useTranslation(),[t,r]=h.useState([]),a=De.useModals(),o=j(),l=v=>{o.editor.setPath(["_QUERIES_",v])},i=()=>{a.openConfirmModal({title:"Delete ununsed queries?",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:()=>o.content.removeUnusedQueries(),confirmProps:{color:"red"},zIndex:320})},c=()=>{o.content.queries.downloadSchema(t)},d=h.useMemo(()=>o.content.queries.sortedList.map(v=>v.id),[o.content.queries.sortedList]),u=()=>{r(d)},p=()=>{r([])},f=o.content.queriesUsage;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,{px:"md",ta:"left",sx:{userSelect:"none",cursor:"default"},children:e("query.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:!o.content.hasUnusedQueries,onClick:i,children:e("query.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.name")}),n.jsx(s.Table.Th,{style:{width:"200px"},children:e("data_source.label")}),n.jsx(s.Table.Th,{style:{width:"100px",textAlign:"right"},children:e("common.type")}),n.jsx(s.Table.Th,{style:{width:"100px",textAlign:"center"},children:e("query.usage.label")}),n.jsx(s.Table.Th,{style:{width:"300px",paddingLeft:"24px"},children:e("common.action")})]})}),n.jsx(s.Table.Tbody,{children:o.content.queries.sortedList.map(v=>{var w;const _=((w=f[v.id])==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.id,styles:{input:{cursor:"pointer"}}})}),n.jsx(s.Table.Td,{children:v.name}),n.jsx(s.Table.Td,{children:v.key}),n.jsx(s.Table.Td,{style:{textAlign:"right"},children:v.type}),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:()=>l(v.id),children:e("common.actions.open")})})]},v.id)})})]})})})]})}),C3=e=>{const{t}=m.useTranslation(),{queryModel:r}=e,a=j(),o=F(),i=o.findQueryUsage(r.id).length>0,c=De.useModals(),d=()=>{c.openConfirmModal({title:`${t("query.delete")}?`,labels:{confirm:t("common.actions.confirm"),cancel:t("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:()=>{o.queries.removeQuery(r.id),a.editor.setPath(["_QUERIES_",""])},confirmProps:{color:"red"},zIndex:320})};return i?n.jsx(s.Tooltip,{label:t("query.cant_delete"),withArrow:!0,events:{hover:!0,focus:!1,touch:!1},withinPortal:!0,zIndex:320,position:"top-end",children:n.jsx(s.Box,{sx:{alignSelf:"flex-end"},children:n.jsx(s.Button,{disabled:!0,size:"xs",leftSection:n.jsx(S.IconTrash,{size:16}),children:t("query.delete")})})}):n.jsx(s.Button,{color:"red",size:"xs",onClick:d,leftSection:n.jsx(S.IconTrash,{size:16}),sx:{alignSelf:"flex-end"},children:t("query.delete")})},S3=k.observer(C3),_d=({width:e="calc(100% - 32px)",lastWidth:t="50%",height:r,count:a,spacing:o=16,pl:l=0})=>n.jsxs(s.Stack,{gap:o,mt:6,pl:l,children:[Array.from(new Array(a-1),(i,c)=>n.jsx(s.Skeleton,{width:e,height:r,radius:"xs"},c)),n.jsx(s.Skeleton,{width:t,height:r,radius:"xs"})]}),en=({value:e})=>e===null||e===""?null:n.jsx(s.Tooltip,{label:e,disabled:!e,multiline:!0,zIndex:340,children:n.jsx(s.ActionIcon,{variant:"subtle",children:n.jsx(S.IconInfoCircle,{size:14})})}),T3=({column:e})=>{const{column_key:t,column_key_text:r}=e;return t?n.jsx(s.Tooltip,{label:r,disabled:!r,children:n.jsx(s.Badge,{variant:"light",children:t})}):null},k3=k.observer(({dataSource:e})=>{const{columns:t}=e.dbInfo;return t.loading?n.jsx(_d,{height:"24px",width:"100%",lastWidth:"100%",count:20,pl:6}):t.empty?null:n.jsxs(s.Table,{highlightOnHover:!0,fz:14,sx:{width:"auto",minWidth:"1000px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[n.jsxs("colgroup",{children:[n.jsx("col",{style:{width:50}}),n.jsx("col",{style:{minWidth:300}}),n.jsx("col",{style:{width:30}}),n.jsx("col",{style:{width:70}}),n.jsx("col",{style:{minWidth:300}}),n.jsx("col",{style:{minWidth:80,width:80}}),n.jsx("col",{style:{minWidth:120,width:120}})]}),n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:"#"}),n.jsx(s.Table.Th,{children:"Column Name"}),n.jsx(s.Table.Th,{}),n.jsx(s.Table.Th,{}),n.jsx(s.Table.Th,{children:"Type"}),n.jsx(s.Table.Th,{children:"Nullable"}),n.jsx(s.Table.Th,{children:"Default Value"})]})}),n.jsx(s.Table.Tbody,{children:t.data.map(r=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:r.ordinal_position}),n.jsx(s.Table.Td,{children:r.column_name}),n.jsx(s.Table.Td,{children:n.jsx(en,{value:r.column_comment})}),n.jsx(s.Table.Td,{children:n.jsx(T3,{column:r})}),n.jsx(s.Table.Td,{children:r.column_type}),n.jsx(s.Table.Td,{children:r.is_nullable}),n.jsx(s.Table.Td,{children:n.jsx(en,{value:r.column_default})})]},r.column_name))})]})}),D3=k.observer(({dataSource:e})=>{const{indexes:t}=e.dbInfo,r=t.data;return n.jsxs(s.Table,{highlightOnHover:!0,fz:14,sx:{width:"auto",minWidth:"950px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[n.jsxs("colgroup",{children:[n.jsx("col",{style:{width:100}}),n.jsx("col",{style:{minWidth:300}}),n.jsx("col",{style:{width:150}}),n.jsx("col",{style:{width:150}}),n.jsx("col",{style:{width:250}})]}),n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:"Index Length"}),n.jsx(s.Table.Th,{children:"Index Name"}),n.jsx(s.Table.Th,{children:"Index Algorithm"}),n.jsx(s.Table.Th,{children:"Unique"}),n.jsx(s.Table.Th,{children:"Column Name"})]})}),n.jsx(s.Table.Tbody,{children:r.map(a=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:a.index_length}),n.jsx(s.Table.Td,{children:a.index_name}),n.jsx(s.Table.Td,{children:a.index_algorithm}),n.jsx(s.Table.Td,{children:a.is_unique?"YES":"NO"}),n.jsx(s.Table.Td,{children:a.column_name})]},a.index_name))})]})}),z3=k.observer(({dataSource:e})=>{const{indexes:t}=e.dbInfo,r=t.data;return n.jsxs(s.Table,{highlightOnHover:!0,fz:14,sx:{width:"auto",minWidth:"850px",alignSelf:"flex-start",flexGrow:0,tableLayout:"fixed",tbody:{fontFamily:"monospace"}},children:[n.jsxs("colgroup",{children:[n.jsx("col",{style:{minWidth:300}}),n.jsx("col",{style:{width:150}}),n.jsx("col",{style:{width:100}}),n.jsx("col",{style:{width:100}}),n.jsx("col",{style:{width:100}}),n.jsx("col",{style:{width:100}})]}),n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:"Index Name"}),n.jsx(s.Table.Th,{children:"Index Algorithm"}),n.jsx(s.Table.Th,{children:"Unique"}),n.jsx(s.Table.Th,{children:"Definition"}),n.jsx(s.Table.Th,{children:"Condition"}),n.jsx(s.Table.Th,{children:"Comment"})]})}),n.jsx(s.Table.Tbody,{children:r.map(a=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:a.index_name}),n.jsx(s.Table.Td,{children:a.index_algorithm}),n.jsx(s.Table.Td,{children:a.is_unique?"YES":"NO"}),n.jsx(s.Table.Td,{children:n.jsx(en,{value:a.index_definition})}),n.jsx(s.Table.Td,{children:n.jsx(en,{value:a.condition})}),n.jsx(s.Table.Td,{children:n.jsx(en,{value:a.comment})})]},a.index_name))})]})}),M3=k.observer(({dataSource:e})=>{const{indexes:t}=e.dbInfo;return t.loading||t.empty?null:e.type===W.MySQL?n.jsx(D3,{dataSource:e}):e.type===W.Postgresql?n.jsx(z3,{dataSource:e}):null}),I3=k.observer(({dataSource:e})=>n.jsxs(s.Stack,{gap:40,pt:10,sx:{flexGrow:1,overflow:"auto",position:"relative"},children:[n.jsx(ne,{children:n.jsx(k3,{dataSource:e})}),n.jsx(ne,{children:n.jsx(M3,{dataSource:e})})]}));function V3({table_type:e}){return e==="VIEW"?n.jsx(S.IconEye,{size:14}):e==="BASE TABLE"?n.jsx(S.IconTable,{size:14}):null}const P3=k.observer(({dataSource:e})=>{const t=e.dbInfo,{tables:r}=t;return r.loading?n.jsx(_d,{height:"24px",lastWidth:"50%",count:15}):n.jsx(s.Box,{h:"100%",sx:{overflow:"auto",".mantine-NavLink-label":{fontFamily:"monospace"}},children:Object.entries(r.data).map(([a,o])=>n.jsx(s.NavLink,{label:a,title:a,leftSection:n.jsx(S.IconDatabase,{size:14}),defaultOpened:t.table_schema===a,pl:0,childrenOffset:14,children:o.map(l=>n.jsx(s.NavLink,{label:l.table_name,title:l.table_name,leftSection:n.jsx(V3,{table_type:l.table_type}),onClick:()=>{t.setKeywords(a,l.table_name)},active:t.table_name===l.table_name},l.table_name))},a))})}),$3=({visible:e})=>n.jsx(s.Box,{py:10,sx:{width:"100%",height:"100%",overflow:"hidden",position:"relative"},children:n.jsx(s.LoadingOverlay,{visible:e})}),A3=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],E3={section:{"&[data-position=left]":{width:"70px",textAlign:"center"}},input:{paddingLeft:"70px"}},B3=k.observer(({dataSource:e})=>{const{t}=m.useTranslation(),{tableData:r}=e.dbInfo;return n.jsxs(s.Group,{pt:10,px:10,justify:"space-between",children:[n.jsxs(s.Group,{justify:"flex-start",children:[r.maxPage>1&&n.jsx(s.Pagination,{size:"sm",value:r.page,onChange:r.setPage,total:r.maxPage,withEdges:r.maxPage>7,styles:{control:{height:"30px"}}}),n.jsx(s.Select,{leftSection:n.jsx(s.Text,{ta:"center",c:"dimmed",size:"14px",children:t("common.pagination.page_size")}),size:"xs",styles:E3,data:A3,value:String(r.limit),onChange:a=>r.setLimit(Number(a)),comboboxProps:{zIndex:340}})]}),n.jsx(s.Group,{justify:"flex-end",children:n.jsx(s.Text,{c:"dimmed",my:0,size:"14px",children:t("common.pagination.total_rows",{total:r.total})})})]})}),q3=k.observer(({dataSource:e})=>{const t=e.dbInfo.tableData;return t.maxPage===0?n.jsx(s.Text,{mt:20,c:"red",size:"md",ta:"center",ff:"monospace",children:"This table is empty"}):t.error?n.jsx(s.Text,{mt:20,c:"red",size:"md",ta:"center",ff:"monospace",children:t.error}):t.page===1&&t.loading?n.jsx($3,{visible:!0}):n.jsxs(ne,{children:[n.jsx(B3,{dataSource:e}),n.jsxs(s.Box,{py:10,sx:{width:"100%",height:"calc(100% - 42px)",overflow:"auto",position:"relative"},children:[n.jsx(s.LoadingOverlay,{visible:t.loading,overlayProps:{blur:2}}),n.jsx(yd,{data:t.data})]})]})}),L3={root:{flexGrow:1,overflow:"auto",borderLeft:"1px solid #efefef"},tabsList:{borderBottom:"1px solid #efefef"},tab:{minWidth:120}},O3=k.observer(({dataSource:e})=>{const{t}=m.useTranslation(),r=e.dbInfo;return h.useEffect(()=>{r.loadTablesIfEmpty()},[r]),r.tables.error?n.jsx(s.Text,{c:"red",size:"md",ta:"center",ff:"monospace",children:r.tables.error}):n.jsxs(s.Flex,{sx:{height:"100%"},children:[n.jsx(s.Box,{w:300,sx:{flexGrow:0,flexShrink:0,position:"relative"},children:n.jsx(ne,{children:n.jsx(P3,{dataSource:e})})}),n.jsxs(s.Tabs,{defaultValue:"structure",styles:L3,children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Tab,{value:"structure",leftSection:n.jsx(S.IconColumns,{size:14}),children:t("data_source.table_structure_short")}),n.jsx(s.Tabs.Tab,{value:"data",leftSection:n.jsx(S.IconDatabase,{size:14}),children:t("data.label")})]}),n.jsx(s.Tabs.Panel,{value:"structure",children:n.jsx(I3,{dataSource:e})}),n.jsx(s.Tabs.Panel,{value:"data",sx:{width:"100%",height:"calc(100% - 36px)",overflow:"hidden"},children:n.jsx(q3,{dataSource:e})})]})]})}),N3={modal:{paddingLeft:"0px !important",paddingRight:"0px !important"},header:{marginBottom:0,padding:"20px 20px 10px",borderBottom:"1px solid #efefef",gap:"20px"},title:{flexGrow:1},body:{padding:"0 0 0 20px"}},md=k.observer(({dataSource:e,triggerButtonProps:t={}})=>{const{t:r}=m.useTranslation(),[a,o]=h.useState(!1),{type:l}=e;return l==="http"||l==="merico_metric_system"?null:n.jsxs(n.Fragment,{children:[n.jsx(s.Modal,{opened:a,onClose:()=>o(!1),title:n.jsxs(s.Group,{justify:"space-between",sx:{flexGrow:1},children:[n.jsx(s.Text,{size:"sm",fw:500,children:r("data_source.explorer")}),n.jsxs(s.Group,{gap:7,children:[n.jsx(s.Badge,{variant:"gradient",gradient:{from:"indigo",to:"cyan"},children:e.key}),n.jsx(s.Badge,{variant:"gradient",gradient:{from:"orange",to:"red"},children:e.type})]})]}),zIndex:320,size:"96vw",styles:N3,children:n.jsx(s.Box,{sx:{height:"calc(100vh - 220px)"},children:n.jsx(O3,{dataSource:e})})}),n.jsx(s.Button,{variant:"subtle",onClick:()=>o(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},...t,children:r("data_source.see_table_structure")})]})}),wd={http:"HTTP",mysql:"MySQL",postgresql:"PostgreSQL",merico_metric_system:"指标系统"},G3=({option:e,...t})=>{const{label:r,type:a}=e;return a===W.Transform?n.jsxs(s.Group,{className:"transform-query-option",justify:"flex-start",...t,sx:{flexGrow:1,'&[data-selected="true"]':{".mantine-Text-root":{color:"white"},svg:{stroke:"white"}}},children:[n.jsx(S.IconVectorTriangle,{size:14,color:"#228be6"}),n.jsx(s.Text,{size:"sm",c:"blue",children:r})]}):n.jsxs(s.Group,{justify:"space-between",...t,sx:{flexGrow:1},children:[n.jsx(s.Text,{size:"sm",children:r}),n.jsx(s.Text,{size:"sm",children:wd[a]})]})},xd=k.observer(({queryModel:e,size:t="sm"})=>{const{t:r}=m.useTranslation(),a=j(),{data:o=[],loading:l}=O.useRequest(Ba,{refreshDeps:[]},[]),i=h.useMemo(()=>{const p=o.map(f=>({label:f.key,value:f.key,type:f.type}));return p.push({label:r("query.transform.data_source"),value:W.Transform,type:W.Transform}),p},[o]),c=h.useMemo(()=>i.reduce((p,f)=>(p[f.value]=f.type,p),{}),[i]),d=p=>{p!==null&&(e.setKey(p),e.setType(c[p]))},u=h.useMemo(()=>a.datasources.find({type:e.type,key:e.key}),[a,e.type,e.key]);return n.jsx(s.Select,{size:t,data:i,label:n.jsxs(s.Group,{justify:"space-between",children:[n.jsx(s.Box,{children:r("data_source.label")}),u&&n.jsx(md,{dataSource:u,triggerButtonProps:{size:"compact-xs",px:10}})]}),renderOption:G3,rightSection:u?n.jsx(s.Text,{size:"xs",c:"dimmed",children:wd[u.type]??u.type}):void 0,rightSectionWidth:85,maxDropdownHeight:500,styles:{root:{flex:1,minWidth:"300px"},label:{display:"block"},section:{pointerEvents:"none",justifyContent:"flex-end",paddingRight:"10px",".mantine-Text-root":{userSelect:"none"}}},disabled:l,value:e.key,onChange:d})}),F3=k.observer(({queryModel:e})=>{const{t}=m.useTranslation(),[r,a]=h.useState(e.name);h.useEffect(()=>{a(e.name)},[e.name]);const o=h.useMemo(()=>e.conditionOptionsWithInvalidRunbys.optionGroups.map(i=>({group:t(i.group),items:i.items})),[e.conditionOptionsWithInvalidRunbys.optionGroups]);return n.jsx(s.Center,{ml:20,mt:20,sx:{maxWidth:"600px"},children:n.jsxs(s.Stack,{gap:10,sx:{width:"100%"},children:[n.jsx(s.Divider,{mb:-10,variant:"dashed",label:t("query.basics"),labelPosition:"center"}),n.jsx(s.TextInput,{placeholder:t("query.name_description"),label:t("query.name"),required:!0,sx:{flex:1},value:r,onChange:l=>{a(l.currentTarget.value)},rightSection:n.jsx(s.ActionIcon,{variant:"filled",color:"blue",size:"sm",onClick:()=>e.setName(r),disabled:r===e.name,children:n.jsx(S.IconDeviceFloppy,{size:16})}),onBlur:()=>{e.setName(r)}}),n.jsx(xd,{queryModel:e}),n.jsx(s.Divider,{mt:10,mb:-10,variant:"dashed",label:t("query.conditions"),labelPosition:"center"}),n.jsx(s.MultiSelect,{label:t("query.run_by_condition.label"),description:t("query.run_by_condition.description"),placeholder:t("query.run_by_condition.unset"),data:o,value:[...e.run_by],onChange:e.setRunBy,renderOption:hr,maxDropdownHeight:500}),e.typedAsHTTP&&n.jsx(s.MultiSelect,{label:t("query.re_run_condition.label"),placeholder:t("query.re_run_condition.label"),data:o,value:[...e.config.react_to],onChange:e.config.setReactTo,renderOption:hr,maxDropdownHeight:500}),e.isTransform&&n.jsx(s.MultiSelect,{label:t("query.re_run_condition.label"),placeholder:t("query.re_run_condition.label"),data:o,value:[...e.config.react_to],onChange:e.config.setReactTo,renderOption:hr,maxDropdownHeight:500}),n.jsx(s.Divider,{mt:20,mb:10,variant:"dashed"}),n.jsx(S3,{queryModel:e})]})})});function Q3({content:e}){return n.jsxs(s.HoverCard,{width:"60vw",shadow:"md",zIndex:340,children:[n.jsx(s.HoverCard.Target,{children:n.jsx(s.ActionIcon,{size:16,color:"blue",variant:"subtle",children:n.jsx(S.IconEye,{})})}),n.jsx(s.HoverCard.Dropdown,{children:n.jsx(Fe.CodeHighlight,{language:"sql",withCopyButton:!1,code:e})})]})}const j3=k.observer(()=>{const t=[...j().globalSQLSnippets.list];return t.length===0?null:n.jsxs(s.Table,{horizontalSpacing:"xs",verticalSpacing:"xs",fz:"sm",highlightOnHover:!0,children:[n.jsx(s.Table.Thead,{children:n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Th,{children:"Key"}),n.jsx(s.Table.Th,{children:"Value"})]})}),n.jsx(s.Table.Tbody,{children:t.map(r=>{const{id:a,content:o}=r;return n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{children:a}),n.jsx(s.Table.Td,{width:200,children:n.jsx(Q3,{content:o})})]},a)})})]})}),W3=`
|
|
554
554
|
-- You may reference query variables in SQL or VizConfig.
|
|
555
555
|
SELECT *
|
|
556
556
|
FROM commit
|
|
@@ -563,10 +563,10 @@ WHERE
|
|
|
563
563
|
AND \${sql_snippets.author_email_condition}
|
|
564
564
|
-- Global SQL snippets (shared between dashboards)
|
|
565
565
|
AND \${global_sql_snippets.account_condition}
|
|
566
|
-
`,Cd=k.observer(function({showSQLSnippets:t=!0,sx:r={}}){const{t:a}=m.useTranslation(),o=j(),l=
|
|
566
|
+
`,Cd=k.observer(function({showSQLSnippets:t=!0,sx:r={}}){const{t:a}=m.useTranslation(),o=j(),l=F(),i=(()=>{const c=o.queryVariables;return t&&(c.sql_snippets=l.sqlSnippets.record),JSON.stringify(c,null,2)})();return n.jsx(s.Stack,{sx:{overflow:"hidden",...r},children:n.jsxs(s.Tabs,{defaultValue:"guide",keepMounted:!1,children:[n.jsxs(s.Tabs.List,{grow:!0,children:[n.jsx(s.Tabs.Tab,{value:"guide",leftSection:n.jsx(S.IconAlertCircle,{size:14}),children:a("query_variable.guide.tabs.guide")}),n.jsx(s.Tabs.Tab,{value:"local_query_vars",leftSection:n.jsx(S.IconVariable,{size:14}),children:a("query_variable.guide.tabs.variables_in_this_dashboard")}),n.jsx(s.Tabs.Tab,{value:"global_sql_snippets",leftSection:n.jsx(S.IconVariablePlus,{size:14}),children:a("query_variable.guide.tabs.global_sql_snippets")})]}),n.jsx(s.Tabs.Panel,{value:"guide",pt:"xs",children:n.jsx(Fe.CodeHighlight,{language:"sql",sx:{width:"100%"},withCopyButton:!1,code:W3})}),n.jsx(s.Tabs.Panel,{value:"local_query_vars",pt:"xs",children:n.jsx(Fe.CodeHighlight,{language:"json",sx:{width:"100%"},withCopyButton:!1,code:i})}),n.jsx(s.Tabs.Panel,{value:"global_sql_snippets",pt:"xs",children:n.jsxs(s.Stack,{gap:10,children:[n.jsx(s.Alert,{icon:n.jsx(S.IconAlertCircle,{size:16}),title:a("global_sql_snippet.labels"),children:a("global_sql_snippet.description")}),n.jsx(j3,{})]})})]})})}),ds=k.observer(()=>{const{t:e}=m.useTranslation(),[t,r]=h.useState(!1);return n.jsxs(n.Fragment,{children:[n.jsx(s.Modal,{opened:t,onClose:()=>r(!1),title:e("query_variable.labels"),zIndex:320,size:"800px",children:n.jsx(Cd,{})}),n.jsx(s.Button,{variant:"subtle",onClick:()=>r(!0),px:16,styles:{inner:{justifyContent:"flex-start"}},children:e("query_variable.open")})]})}),Sd={pre:["function build_request({ context, filters }, utils) {"," // build the quest"," return { method: 'POST', url: '/', params: {}, headers: {}, data: {} }","}"].join(`
|
|
567
567
|
`),post:["function process_result(resp, utils, state) {"," return resp.data","}"].join(`
|
|
568
568
|
`)},U3=k.observer(({queryModel:e})=>{const{t}=m.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(ds,{})]}),n.jsx(s.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:n.jsx(Tt,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:Sd.pre})}),n.jsx(s.Tabs.Panel,{value:"post_process",p:"sm",children:n.jsx(Tt,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:Sd.post})})]}):null}),Td=k.observer(({queryModel:e})=>{const{t}=m.useTranslation(),r=j().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}},o=i=>{r.setPath(["_VIEWS_",i])},l=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:l.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:()=>o(c.id),children:n.jsx(s.Box,{children:c.label})},c.id)),i.views.length===0&&n.jsx(s.Box,{children:"--"})]})})]},i.id))})]})}),K3=k.observer(({queryModel:e})=>{const{t}=m.useTranslation(),r=h.useMemo(()=>b.groupBy(e.dependencies,"type"),[e.dependencies]),a=h.useMemo(()=>e.dependencies.some(l=>!l.valid),[e.dependencies]),o=e.dependencies.length>0;return o?n.jsxs(s.HoverCard,{withinPortal:!0,zIndex:340,shadow:"md",disabled:!o,children:[n.jsx(s.HoverCard.Target,{children:n.jsx(s.Button,{size:"xs",variant:"subtle",color:a?"red":"green",disabled:!o,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(([l,i])=>n.jsxs(s.List.Item,{children:[n.jsx(s.Text,{size:"sm",fw:"bold",ff:"monospace",children:t(`${l}.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))})]},l))})})]}):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")})})}),Y3="SELECT 1",X3=k.observer(({queryModel:e})=>{const{t}=m.useTranslation(),r=e.config,[a,o]=h.useState(r.sql),l=()=>{r.setSQL(a)},i=()=>{o(r.sql)},c=()=>{o(Y3)};h.useEffect(()=>{o(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(K3,{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:l,disabled:!d,leftSection:n.jsx(S.IconDeviceFloppy,{size:16}),children:t("common.actions.save_changes")})]})]}),n.jsx(gr,{height:"100%",value:a,onChange:o,theme:"sql-dark",defaultLanguage:"sql"})]})}),Z3=({value:e,height:t="200px",defaultLanguage:r="sql"})=>n.jsx(Se,{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}}),J3=k.observer(({value:e})=>{const r=H().payloadForSQL,a=h.useMemo(()=>vr(e,r),[e,r]);return n.jsx(Z3,{height:"100%",value:a})}),kd={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
|
`)},H3=k.observer(({queryModel:e})=>{const{t}=m.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(ds,{}),e.datasource&&n.jsx(md,{dataSource:e.datasource})]}),n.jsx(s.Tabs.Panel,{value:"Edit",sx:{position:"relative"},p:"sm",children:n.jsx(X3,{queryModel:e})}),n.jsx(s.Tabs.Panel,{value:"Preview",p:0,pl:4,children:n.jsx(J3,{value:r.sql})}),n.jsx(s.Tabs.Panel,{value:"pre_process",sx:{position:"relative"},p:"sm",children:n.jsx(Tt,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:kd.pre})}),n.jsx(s.Tabs.Panel,{value:"post_process",p:"sm",children:n.jsx(Tt,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:kd.post})})]})}),R3={pre:["function transform(queries, state, utils) {"," // use queries & dashboar state to build new data"," const data = []"," return data","}"].join(`
|
|
571
|
-
`),post:""},e5=k.observer(({queryModel:e})=>{const{t}=m.useTranslation(),r=G();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(Tt,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:R3.pre})})]})}),tn={height:"calc(100% - 44px)",padding:0},t5=k.observer(({queryModel:e})=>{const{t}=m.useTranslation(),r=G(),a=h.useMemo(()=>e.datasource?e.typedAsHTTP?"HTTP":"SQL":"Configurations",[e.datasource,e.typedAsHTTP]),[o,l]=h.useState(a);h.useEffect(()=>{l(d=>d!=="Configurations"&&a==="Configurations"?"Configurations":d)},[a]);const c=r.findQueryUsage(e.id).length===0;return n.jsxs(s.Tabs,{value:o,onChange:l,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(F3,{queryModel:e})}),e.typedAsSQL&&n.jsx(s.Tabs.Panel,{value:"SQL",sx:tn,children:n.jsx(s.Stack,{sx:{height:"100%"},children:n.jsx(H3,{queryModel:e})})}),e.typedAsHTTP&&n.jsx(s.Tabs.Panel,{value:"HTTP",sx:tn,children:n.jsx(s.Stack,{sx:{height:"100%"},children:n.jsx(U3,{queryModel:e})})}),e.isTransform&&n.jsx(s.Tabs.Panel,{value:"Transform",sx:tn,children:n.jsx(s.Stack,{sx:{height:"100%"},children:n.jsx(e5,{queryModel:e})})}),n.jsx(s.Tabs.Panel,{value:"Data",sx:{...tn,overflow:"hidden"},children:n.jsx(ls,{id:e.id,moreActions:null,refreshOnMount:!0})}),n.jsx(s.Tabs.Panel,{value:"Usage",py:"sm",px:"md",sx:{...tn,overflow:"hidden"},children:n.jsx(Td,{queryModel:e})})]})}),n5=({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"})]}),Dd=({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})]}),zd=({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})]}),r5=({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"})]}),a5=k.observer(({queryModel:e})=>{const{t}=m.useTranslation(),r=j(),a=G(),l=a.findQueryUsage(e.id).length>0,i=De.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 l?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(zd,{width:14,height:14,color:"gray"}),variant:"subtle",color:"gray",onClick:d=>{d.stopPropagation()},children:"删除查询"})}):n.jsx(s.Menu.Item,{leftSection:n.jsx(zd,{width:14,height:14}),color:"red",onClick:c,children:"删除查询"})}),s5=k.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(r5,{width:18,height:18})})}),n.jsx(s.Menu.Dropdown,{children:n.jsx(a5,{queryModel:e})})]})),o5={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 l5({data:e}){const t=h.useMemo(()=>{if(!Array.isArray(e)||e.length===0)return[];const a=ge.createColumnHelper();return Object.keys(e[0]).map(o=>a.accessor(o,{cell:l=>l.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:o5,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(o=>n.jsxs(s.Table.Th,{style:{width:o.getSize()},children:[o.isPlaceholder?null:ge.flexRender(o.column.columnDef.header,o.getContext()),n.jsx(s.ActionIcon,{variant:"subtle",onMouseDown:o.getResizeHandler(),onTouchStart:o.getResizeHandler(),className:`resizer ${o.column.getIsResizing()?"isResizing":""}`,children:n.jsx(S.IconArrowBarToRight,{})})]},o.id))},a.id))}),n.jsx(s.Table.Tbody,{children:r.getRowModel().rows.map(a=>n.jsx(s.Table.Tr,{children:a.getVisibleCells().map(o=>n.jsx(s.Table.Td,{children:n.jsx(ne,{children:typeof o.getValue()=="object"?n.jsx("pre",{children:JSON.stringify(o.getValue(),null,2)}):ge.flexRender(o.column.columnDef.cell,o.getContext())})},o.id))},a.id))})]})})}const i5=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],c5={root:{width:"150px"},section:{"&[data-position=left]":{width:"70px",textAlign:"center"}},input:{paddingLeft:"70px",paddingRight:0}},d5=({data:e,page:t,setPage:r,limit:a,setLimit:o})=>{const{t:l}=m.useTranslation(),i=e.length,c=Math.ceil(i/a),d=p=>{p&&(r(1),o(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:l("common.pagination.page_size")}),size:"xs",styles:c5,data:i5,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:l("common.pagination.total_rows",{total:i})})})]})},u5=Do(({data:e,loading:t})=>{const[r,a]=h.useState(1),[o,l]=h.useState(20),i=h.useMemo(()=>{const c=(r-1)*o,d=c+o;return e.slice(c,d)},[e,r,o]);return n.jsx(ne,{children:n.jsxs(s.Stack,{gap:10,styles:{root:{height:"100%",overflow:"hidden"}},children:[n.jsx(d5,{data:e,page:r,setPage:a,limit:o,setLimit:l}),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(l5,{data:i})]})]})})}),p5=k.observer(({queryModel:e})=>{const{t}=m.useTranslation(),{state:r,error:a,metricQueryPayloadErrorString:o,stateMessage:l}=e;return r==="loading"?null:a?n.jsx(s.Text,{mt:10,c:"red",size:"md",ta:"center",ff:"monospace",children:a}):o?n.jsx(s.Text,{mt:10,c:"red",size:"md",ta:"center",ff:"monospace",children:o}):l?n.jsx(s.Text,{size:"sm",mt:10,c:"gray",ta:"center",children:t(l)}):null}),h5=k.observer(({queryModel:e})=>{m.useTranslation();const{data:t,state:r}=e,a=r==="loading",o=h.useCallback(()=>{e.fetchData(!0)},[e.fetchData]),l=()=>{Yi(e.name,e.data)};h.useEffect(()=>{o()},[o]);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:l,children:"下载查询结果"})]}),n.jsxs(s.Box,{sx:{position:"relative",flexGrow:1,overflow:"hidden"},children:[n.jsx(p5,{queryModel:e}),n.jsx(u5,{data:t,loading:a})]})]})}),g5=k.observer(({queryModel:e})=>{const t=j();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(Fe.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(Fe.CodeHighlight,{language:"json",sx:{width:"100%",height:"100%",minHeight:"400px",overflowY:"auto"},withCopyButton:!1,code:t.queryVariablesString})})]})}),f5=()=>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"})]}),b5=()=>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"})})})]}),y5=()=>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"})]}),v5=()=>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"})]}),_5=()=>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"})})})]}),us=({type:e})=>{switch(e){case"boolean":return n.jsx(f5,{});case"date":return n.jsx(b5,{});case"number":return n.jsx(y5,{});case"string":return n.jsx(v5,{});case"dimension":return n.jsx(_5,{});default:return null}},m5={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"}}}},w5={root:{maxWidth:"unset"},option:{fontFamily:"monospace"},input:{paddingInlineStart:"var(--input-padding-inline-start)",height:"auto",color:"black",fontFamily:"monospace"}},Md=(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(us,{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)},Id=k.observer(({mmInfo:e,value:t,onChange:r,usedKeys:a})=>{const o=e.metricDetail,l=e.metrics.loading||o.loading,i=o.error,c=o.filterColOptions,d=s.useCombobox({onDropdownClose:()=>d.resetSelectedOption()}),u=h.useMemo(()=>l?n.jsx(s.Loader,{size:"xs"}):t?n.jsx(s.CloseButton,{size:"xs",onClick:()=>r(null)}):n.jsx(s.Combobox.Chevron,{size:"xs"}),[l,t]),p=n.jsx(s.InputBase,{component:"button",type:"button",variant:"unstyled",size:"xs",pointer:!0,rightSection:u,rightSectionPointerEvents:!l&&t?"all":"none",onClick:()=>d.toggleDropdown(),disabled:l||c.length===0,styles:w5,error:!!i,children:t||n.jsx(s.Input.Placeholder,{children:"选择维度"})});return n.jsxs(s.Combobox,{store:d,onOptionSubmit:f=>{r(f),d.closeDropdown()},styles:m5,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(us,{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(x=>Md(x,!0,a.has(x.value)))},_.group):Md(_,!1,a.has(_.value))})},f))})})]})}),Vd={tbody:{td:{fontFamily:"monospace"}}},x5={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)"}}},C5=({option:e,...t})=>{const{t:r}=m.useTranslation(),a=e,o=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})}),o&&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(rt[a.widget])})]})]})},Gn=k.observer(({queryModel:e,value:t,onChange:r,usedKeys:a})=>{const{t:o}=m.useTranslation();e.config;const l=h.useMemo(()=>e.getConditionOptionsWithInvalidValue(t).optionGroups.map(d=>{const u=d.items.length;return{group:`${o(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,o,t,a]),i=h.useCallback((c,d)=>{r(c,d)},[r]);return n.jsx(s.Select,{size:"xs",variant:"unstyled",placeholder:"选择变量",styles:x5,data:l,renderOption:C5,maxDropdownHeight:600,value:t,onChange:i,clearable:!0})}),ps=k.observer(({variable:e})=>{const t=j();if(!e)return null;const r=b.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,{})})}),S5=k.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:Vd,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(o=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{pr:0,children:n.jsx(Id,{mmInfo:a,value:o.dimension,onChange:o.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(ps,{variable:o.variable}),n.jsx(Gn,{queryModel:e,value:o.variable,onChange:o.setVariable})]})}),n.jsx(s.Table.Td,{children:n.jsx(s.Checkbox,{size:"xs",checked:e.keyInRunBy(o.variable),onChange:l=>e.changeRunByRecord(o.variable,l.currentTarget.checked),color:"red"})})]},o.dimension)),n.jsxs(s.Table.Tr,{className:"add-a-row",children:[n.jsx(s.Table.Td,{pr:0,children:n.jsx(Id,{mmInfo:a,value:null,onChange:o=>o&&t.addFilter(o,""),usedKeys:t.usedFilterDimensionKeys})}),n.jsx(s.Table.Td,{colSpan:2,pr:0,children:n.jsx(Gn,{queryModel:e,value:null,onChange:o=>o&&t.addFilter("",o)})}),n.jsx(s.Table.Td,{})]})]})]})]})}),T5=k.observer(({queryModel:e,variable:t})=>{const r=e.keyInRunBy(t),a=o=>{e.changeRunByRecord(t,o.currentTarget.checked)};return n.jsx(s.Checkbox,{size:"xs",checked:r,onChange:a,color:"red"})}),Pd=({queryModel:e,variable:t})=>t?n.jsx(T5,{queryModel:e,variable:t}):null,k5=k.observer(({queryModel:e})=>{const t=e.config,o=e.datasource.mericoMetricInfo.metricDetail,l=o.trendingDateCol,i=t.timeQuery.enabled;return o.supportTrending?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:!l})})})}),D5=k.observer(({queryModel:e})=>{const t=e.config,o=e.datasource.mericoMetricInfo.metricDetail,l=o.trendingDateCol;return!t.timeQuery.enabled||!o.supportTrending?null:n.jsxs(s.Table,{withTableBorder:!0,withColumnBorders:!0,layout:"fixed",styles:Vd,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:(l==null?void 0:l.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(ps,{variable:t.timeQuery.range_variable}),n.jsx(Gn,{queryModel:e,value:t.timeQuery.range_variable,onChange:t.setRangeVariable,usedKeys:t.usedTimeQueryVariableSet})]})}),n.jsx(s.Table.Td,{children:n.jsx(Pd,{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(ps,{variable:t.timeQuery.unit_variable}),n.jsx(Gn,{queryModel:e,value:t.timeQuery.unit_variable,onChange:t.setUnitVariable})]})}),n.jsx(s.Table.Td,{children:n.jsx(Pd,{queryModel:e,variable:t.timeQuery.unit_variable})})]},"dimension.step")]})]})}),z5=k.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(k5,{queryModel:e})]}),n.jsx(D5,{queryModel:e})]})),M5={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"}},I5=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(us,{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})]})},V5=k.observer(({queryModel:e})=>{const t=e.config,a=e.datasource.mericoMetricInfo,o=a.metricDetail,l=a.metrics.loading||o.loading,i=o.groupByColOptions,c=d=>{const u=o.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:M5,renderOption:I5,rightSection:l?n.jsx(s.Loader,{size:"xs"}):null,value:[...t.groupByValues],onChange:c,maxValues:t.timeQuery.enabled?1:2,placeholder:t.timeQuery.enabled?"仅可选一个维度":"最多选两个维度",disabled:l}),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})]})}),P5=e=>{if(!e)return null;try{const t=JSON.parse(e);return{calculation:t.calculation,n:t.n,direction:t.direction}}catch{return null}},$5=(e,t,r)=>{const a={max:"最大值",min:"最小值",sum:"总和",avg:"平均值"};return Array.from(ac.entries()).filter(([o])=>e.includes(o)).map(([o,l])=>{const c=!r&&l.requireTrendingDateCol;let d=l.name;if(l.requireWindowConfig&&t){const u=a[t.calculation]||t.calculation,p=t.direction==="forward"?"向前":"向后";d=`${l.name} · ${u} · ${t.n} 个步长 · ${p}`}return{value:o,label:d,description:l.description,disabled:c,disabledReason:c?"需要开启按时序查询":void 0}})},A5=e=>{const t=e.option,r=n.jsx(s.Group,{gap:"xs",wrap:"nowrap",children:n.jsxs("div",{children:[n.jsx(s.Text,{size:"sm",fw:500,children:t.label}),n.jsx(s.Text,{size:"xs",c:"dimmed",children:t.description})]})});return t.disabled&&t.disabledReason?n.jsx(s.Tooltip,{label:t.disabledReason,position:"top",withArrow:!0,children:n.jsx("div",{...e,style:{opacity:.6,cursor:"not-allowed"},children:r})}):n.jsx("div",{...e,children:r})},E5=k.observer(({queryModel:e})=>{const t=e.config,a=e.datasource.mericoMetricInfo,o=a.metricDetail,l=a.metrics.loading||o.loading,i=o.error,c=h.useRef(t.timeQuery.enabled);if(h.useEffect(()=>{if(c.current&&!t.timeQuery.enabled){const d=F.toJS(t.extraCalculations)||[],u=sc(d,!1);u.length!==d.length&&t.setExtraCalculations(u)}c.current=t.timeQuery.enabled},[t.timeQuery.enabled]),!t.id)return null;if(l)return n.jsxs(s.Stack,{gap:8,children:[n.jsx(s.Text,{size:"sm",fw:500,children:"衍生计算配置"}),n.jsx(s.Loader,{size:"xs"})]});if(i)return n.jsxs(s.Stack,{gap:8,children:[n.jsx(s.Text,{size:"sm",fw:500,children:"衍生计算配置"}),n.jsxs(s.Text,{size:"sm",c:"red",children:["加载失败: ",i]})]});if(o.hasData&&o.data){const d=o.data.extraCalculations;if(!d||d.length===0)return null;const u=P5(o.data.extraCalculationConfig),p=$5(d,u,t.timeQuery.enabled);return p.length===0?null:n.jsxs(s.Stack,{gap:8,children:[n.jsx(s.Text,{size:"sm",fw:500,children:"衍生计算配置"}),n.jsx(s.MultiSelect,{data:p,value:F.toJS(t.extraCalculations)||[],onChange:f=>t.setExtraCalculations(f),placeholder:"选择要使用的计算方式",searchable:!0,clearable:!0,nothingFoundMessage:"未找到可用的计算方式",renderOption:A5,maxDropdownHeight:300})]})}return null}),B5=k.observer(({queryModel:e})=>{const t=e.config,r=t.id;return h.useEffect(()=>{if(e.run_by.length===0)return;const a=[],o=t.usedFilterVariableSet,l=t.usedTimeQueryVariableSet;e.run_by.forEach(i=>{(o.has(i)||l.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(S5,{queryModel:e}),n.jsx(z5,{queryModel:e}),n.jsx(V5,{queryModel:e}),n.jsx(E5,{queryModel:e})]})}),q5=["function process_result(resp, utils, state) {"," return resp.data","}"].join(`
|
|
572
|
-
`),L5={root:{minHeight:"350px",maxHeight:"50vh",height:"100%",overflow:"hidden"},list:{"&::before":{borderColor:"transparent"}},panel:{height:"calc(100% - 36px)",overflowY:"auto"}},O5=k.observer(({queryModel:e})=>{const[t,r]=h.useState("编辑查询");return n.jsxs(s.Tabs,{color:"red",defaultValue:"编辑查询",styles:L5,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(B5,{queryModel:e})}),n.jsx(s.Tabs.Panel,{value:"加工结果",pt:"xs",children:n.jsx(Tt,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:q5})}),n.jsx(s.Tabs.Panel,{value:"使用情况",pt:"xs",children:n.jsx(Td,{queryModel:e})})]})}),N5=k.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(Dd,{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(Dd,{width:14,height:14}),variant:"filled",color:"red",onClick:()=>e.fetchData(!0),children:"执行查询"})}),G5=({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})]})},F5=k.observer(({queryModel:e})=>{const t=e.config,a=e.datasource.mericoMetricInfo,o=a.metrics;h.useEffect(()=>{o.load()},[o]),h.useEffect(()=>{!a.metricID&&t.id&&a.selectMetric(t.id)},[t.id]);const l=h.useMemo(()=>o.data.map(p=>({label:p.name,value:p.id,description:p.description,type:p.type})),[o.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}=o;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:l,renderOption:G5,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(n5,{width:14,height:14})})})]})})}),Q5=k.observer(({queryModel:e})=>{const{t}=m.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(xd,{queryModel:e,size:"xs"}),n.jsx(F5,{queryModel:e})]}),n.jsxs(s.Group,{justify:"flex-end",children:[n.jsx(N5,{queryModel:e}),n.jsx(s5,{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(O5,{queryModel:e}),n.jsx(g5,{queryModel:e})]}),n.jsx(h5,{queryModel:e})]})}),j5=k.observer(({id:e})=>{const r=G().queries.findByID(e);return e===""?null:r?r.isMericoMetricQuery?n.jsx(Q5,{queryModel:r}):n.jsx(t5,{queryModel:r}):n.jsx(s.Text,{size:"14px",c:"red",children:"Invalid Query ID"})}),W5=k.observer(({value:e})=>{const r=H().payloadForSQL,a=h.useMemo(()=>vr(e,r),[e,r]);return n.jsx(gr,{height:"100%",value:a})}),U5=k.observer(({item:e,remove:t,onKeyChanged:r})=>{const{t:a}=m.useTranslation(),[o,l]=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,x=De.useModals(),T=()=>{x.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:D=>{c(D.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:T,children:a("sql_snippet.delete")})]}),n.jsxs(s.Tabs,{value:o,onChange:l,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(ds,{}),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(gr,{height:"100%",value:f,onChange:v,defaultLanguage:"sql",theme:"sql-dark"})}),n.jsx(s.Tabs.Panel,{value:"Preview",pt:"sm",children:n.jsx(W5,{value:f})})]})]})}),K5=k.observer(({id:e})=>{const t=j(),r=G(),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 o=()=>{t.editor.setPath(["_SQL_SNIPPETS_",""])},l=()=>{r.sqlSnippets.removeByKey(e),o()},i=c=>{t.editor.setPath(["_SQL_SNIPPETS_",c])};return n.jsx(U5,{item:a,remove:l,onKeyChanged:i})}),Y5=k.observer(()=>{const{t:e}=m.useTranslation(),[t,r]=h.useState([]),a=De.useModals(),o=j(),l=v=>{o.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:()=>o.content.removeUnusedSQLSnippets(),confirmProps:{color:"red"},zIndex:320})},c=()=>{o.content.sqlSnippets.downloadSchema(t)},d=h.useMemo(()=>o.content.sqlSnippets.sortedList.map(v=>v.key),[o.content.sqlSnippets.sortedList]),u=()=>{r(d)},p=()=>{r([])},f=o.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:!o.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:o.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:()=>l(v.key),children:e("common.actions.open")})})]},v.key)})})]})})})]})}),X5=k.observer(({view:e})=>!e||e.type!==B.Division?null:n.jsx(s.Stack,{})),Z5=k.observer(({view:e})=>{const{t,i18n:r}=m.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]),o=h.useMemo(()=>[{value:"horizontal",label:t("common.tabs.orientation.horizontal")},{value:"vertical",label:t("common.tabs.orientation.vertical")}],[r.language]);if(!e||e.type!==B.Tabs)return null;const l=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:l.variant,onChange:l.setVariant,data:a}),n.jsx(s.Select,{label:t("common.tabs.orientation.label"),value:l.orientation,onChange:l.setOrientation,data:o}),n.jsx(s.Switch,{label:t("common.tabs.grow_tabs"),checked:l.grow,onChange:i=>l.setGrow(i.currentTarget.checked)})]})}),J5=({disabled:e,value:t,onChange:r})=>{const a=o=>{o&&r(o)};return n.jsxs(s.Box,{sx:{position:"relative"},children:[e&&n.jsx(s.Overlay,{backgroundOpacity:.6,color:"#fff",zIndex:5,blur:2}),n.jsx(Se,{height:"500px",defaultLanguage:"javascript",value:t,onChange:a,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},H5=({value:e,onChange:t})=>{const{t:r}=m.useTranslation(),[a,{setTrue:o,setFalse:l}]=O.useBoolean(),[i,c]=h.useState(e??$n),d=_=>{c({...i,enabled:_})},u=()=>{l();const{enabled:_,func_content:w}=i,x={enabled:_,func_content:w};c(x),t(x)},p=()=>{l(),c(e)},f=_=>{c(w=>({...w,func_content:_}))},v=()=>{f($n.func_content)};return n.jsxs(n.Fragment,{children:[n.jsx(s.ActionIcon,{size:"lg",color:"blue",variant:"filled",mt:26,onClick:o,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:l,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(J5,{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")})]})]})]})})]})},R5=k.observer(({view:e})=>{const{t}=m.useTranslation();if(!e||e.type!==B.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:b.noop,disabled:!0,sx:{flexGrow:1}}),n.jsx(H5,{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:o=>r.setWidth(o.currentTarget.value),placeholder:"600px / 50vw"}),n.jsx(s.TextInput,{label:t("view.component.modal.height"),value:r.height,onChange:o=>r.setHeight(o.currentTarget.value),placeholder:"600px / 50vw"})]})]})}),eM=k.observer(({view:e})=>n.jsxs(n.Fragment,{children:[n.jsx(X5,{view:e}),n.jsx(R5,{view:e}),n.jsx(Z5,{view:e})]})),tM=k.observer(({view:e})=>{const{t,i18n:r}=m.useTranslation(),a=h.useMemo(()=>[{label:t("view.component.div.label"),value:B.Division},{label:t("view.component.modal.label"),value:B.Modal},{label:t("view.component.tabs.label"),value:B.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:o=>{e.setName(o.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(eM,{view:e})]}):null}),nM=k.observer(({id:e})=>{const{t}=m.useTranslation(),r=De.useModals(),a=j(),o=G();if(e==="")return null;const l=o.views.findByID(e);if(!l)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:()=>{o.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(tM,{view:l})})]})}),rM=k.observer(()=>n.jsx(s.Stack,{sx:{height:"100%"},p:"sm",children:n.jsx(Cd,{})})),aM=k.observer(()=>{const e=j().editor,t=e.path;return fD(t)?n.jsx(rM,{}):bD(t)?n.jsx(Qz,{}):yD(t)?n.jsx(Fz,{}):vD(t)?n.jsx(s.Box,{p:"xs",pl:20,children:n.jsx(Gz,{id:t[1]})}):_D(t)?n.jsx(Y5,{}):mD(t)?n.jsx(K5,{id:t[1]}):xD(t)?n.jsx(x3,{}):wD(t)?n.jsx(j5,{id:t[1]}):CD(t)?n.jsx(s.Box,{p:"xs",pl:20,children:n.jsx(nM,{id:t[1]})}):ts(t)?n.jsx(w3,{viewID:t[1],panelID:t[3]}):n.jsx(s.Box,{children:e.path})}),sM=k.observer(()=>n.jsx(aM,{})),oM=k.observer(()=>{const{t:e}=m.useTranslation(),t=j(),r=()=>{const a=new Date().getTime().toString(),o={id:a,key:a,label:a,order:t.content.filters.current.length+1,type:P.TextInput,config:va(),visibleInViewsIDs:["Main"],auto_submit:!1};t.content.filters.append(o),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")})}),lM=k.observer(({parentID:e})=>{const{t}=m.useTranslation(),r=G();if(!e)return null;const a=r.views.findByID(e);return!a||a.type===B.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")})}),iM=k.observer(()=>{const{t:e}=m.useTranslation(),t=j(),r=()=>{const a=new Date().getTime().toString(),o={id:a,name:a,type:W.Postgresql,key:"",config:{_type:W.Postgresql,sql:""}};t.content.queries.append(o),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")})}),cM=k.observer(()=>{const{t:e}=m.useTranslation(),t=j(),r=()=>{const a=new Date().getTime().toString(),o={key:a,value:""};t.content.sqlSnippets.append(o),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")})}),dM=k.observer(()=>{const{t:e}=m.useTranslation(),t=G();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")})}),uM=k.observer(()=>{const{t:e}=m.useTranslation(),t=j();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")})}),pM=k.observer(()=>{const{t:e}=m.useTranslation(),t=j();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")})}),hM=k.observer(()=>{const{t:e}=m.useTranslation(),t=j();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")})}),gM=k.observer(({action_type:e,parentID:t})=>e==="_Add_A_Filter_"?n.jsx(oM,{}):e==="_Add_A_SQL_SNIPPET_"?n.jsx(cM,{}):e==="_Add_A_QUERY_"?n.jsx(iM,{}):e==="_Add_A_VIEW_"?n.jsx(dM,{}):e==="_Add_A_PANEL_"?n.jsx(lM,{parentID:t}):e==="_QUERIES_SETTINGS_"?n.jsx(uM,{}):e==="_SQL_SNIPPETS_SETTINGS_"?n.jsx(pM,{}):e==="_FILTERS_SETTINGS_"?n.jsx(hM,{}):null),$d={menu_target:"_menu_target_m5ywm_1",query:"_query_m5ywm_12"},Ad=k.observer(({option:e})=>{var v;const{t}=m.useTranslation(),r=G(),a=j().editor,o=a.isOptionActive,l=o(a.path,e),i=a.isOptionOpened,c=a.navigate,d=i(e),[u,p]=h.useState(d);h.useEffect(()=>{p(d)},[d]);const f=e._type==="query";return n.jsx(s.NavLink,{pos:"relative",active:l,defaultOpened:d,opened:u,onChange:p,label:t(e.label),onClick:()=>c(e),leftSection:e.Icon?n.jsx(e.Icon,{size:18}):null,rightSection:f?n.jsxs(s.Menu,{trigger:"hover",position:"right",withArrow:!0,shadow:"xl",children:[n.jsx(s.Menu.Target,{children:n.jsx(s.ActionIcon,{variant:"subtle",className:$d.menu_target,children:n.jsx(S.IconDotsVertical,{size:16})})}),n.jsx(s.Menu.Dropdown,{children:n.jsx(s.Menu.Item,{leftSection:n.jsx(S.IconCopy,{size:16}),onClick:()=>r.queries.duplicateByID(e.value),children:t("common.actions.duplicate")})})]}):null,className:f?$d.query:"",children:(v=e.children)==null?void 0:v.map(_=>_._type==="ACTION"?n.jsx(gM,{action_type:_._action_type,parentID:_.parentID},`_ADD_${_.value}_`):n.jsx(Ad,{option:_},_.value))},e.label)}),fM=k.observer(()=>{const e=j();return n.jsx(s.Box,{sx:{position:"relative"},children:e.editor.navOptions.map(t=>n.jsx(Ad,{option:t},t.value))})}),bM=k.observer(()=>{const{t:e}=m.useTranslation(),t=j();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(fM,{})}),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")})})})]})}),yM={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"}},vM=k.observer(()=>{const e=j().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:yM,children:[n.jsx(bM,{}),n.jsx(s.AppShell.Main,{children:n.jsx(sM,{})})]})})}),_M=e=>e.replace(/([^:])(\/\/+)/g,"$1/");function mM(e){h.useEffect(()=>{if(Se.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/dashboard");const r=_M(e);Se.loader.config({paths:{vs:r}}),Se.loader.init().then(a=>console.log("monaco instance:",a))},[])}const wM=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])};ao(),Mo();const xM={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"}},CM=({context:e,dashboard:t,content:r,update:a,className:o="dashboard",config:l,onChange:i,headerSlot:c,filterValues:d,onFilterValuesChange:u,onExit:p,lang:f,additionalPanelMenuItems:v},_)=>{mM(l.monacoPath),la(l);const{data:w=[]}=O.useRequest(Ba),{data:x=[]}=O.useRequest(tc),T=h.useMemo(()=>td(t,r,w,x,e,d??{}),[t,r]);h.useImperativeHandle(_,()=>T,[T]),nd(T.content,!0),h.useEffect(()=>{T.context.replace(e)},[e]),h.useEffect(()=>{T.datasources.replace(w)},[w]),h.useEffect(()=>{T.globalSQLSnippets.replace(x)},[x]),h.useEffect(()=>{u==null||u(T.content.filters.values)},[u,T.content.filters.values]),h.useEffect(()=>{d&&T.content.filters.patchValues(d)},[d,T.content.filters.patchValues]),h.useEffect(()=>F.reaction(()=>F.toJS(T.json),E=>{i==null||i(E)}),[T]);const D=async()=>{await a(T.json,T.content.json)},z=O.useCreation(oa,[]),I=rd(z);return wM(T.content.changed),O.useWhyDidYouUpdate("@devtable/dashboard editor",{context:e,dashboard:t,content:r,update:a,className:o,config:l,onChange:i,headerSlot:c,filterValues:d,onFilterValuesChange:u,onExit:p,lang:f}),n.jsx(ht.MantineEmotionProvider,{children:n.jsx(Rl,{lang:f,children:n.jsx(De.ModalsProvider,{children:n.jsx(tr,{children:n.jsx(Yn,{value:{renderSearchButton:l.renderSearchButton},children:n.jsx(rr,{value:{items:v??[]},children:n.jsx(Kn,{value:T,children:n.jsx(Zn,{value:T.content,children:n.jsxs(St.Provider,{value:{inEditMode:!0},children:[n.jsx(ZD,{}),n.jsx(lt.Provider,{value:z,children:n.jsxs(bn,{configure:I,children:[n.jsxs(s.AppShell,{padding:0,navbar:{width:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},breakpoint:"xxs"},styles:xM,children:[n.jsx(ez,{onExit:p,saveDashboardChanges:D,headerSlot:c}),n.jsx(Dz,{}),n.jsx(s.AppShell.Main,{children:n.jsx(s.Box,{className:`${o} dashboard-root`,sx:{position:"relative"},children:T.content.views.visibleViews.map(E=>n.jsx(Fc,{view:E},E.id))})})]}),n.jsx(vM,{})]})})]})})})})})})})})})},SM=k.observer(h.forwardRef(CM)),r6="",hs=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:Aa,queries:La,sqlSnippets:Na,views:Va,panels:$a,layouts:Oa,mock_context:ia}).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:Rt(e.sqlSnippets.current,"key","value",a),global_sql_snippets:Rt(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(([o,l])=>{a.context[o]={type:"context",key:o,value:l}}),a},get dashboardStateValues(){return br(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 Ed({id:e,name:t,dashboard_id:r,create_time:a,update_time:o,content:l},i,c,d){if(!l)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:x,mock_context:T={}}}=l;return hs.create({id:e,name:t,dashboard_id:r,create_time:a,update_time:o,version:u,filters:Ea(p,i,T,c),queries:ic(w),sqlSnippets:uc(x),mock_context:ca(T),views:Ui(f,d),panels:{list:v},layouts:{list:_,currentBreakpoint:_[0].id}})}const Bd=g.types.model({id:g.types.identifier,name:g.types.string,group:g.types.string,content:hs,content_id:g.types.string,datasources:ji,globalSQLSnippets:za,context:An});function qd({id:e,name:t,group:r,content_id:a},o,l,i,c,d,u){return Bd.create({id:e,name:t,group:r,content_id:a,content:Ed(o,c,d,u),datasources:{list:l},globalSQLSnippets:{list:i},context:Ma(c)})}ao(),Mo();const TM=({context:e,dashboard:t,content:r,className:a="dashboard",config:o,fullScreenPanelID:l,setFullScreenPanelID:i,filterValues:c,onFilterValuesChange:d,activeTab:u,onActiveTabChange:p,lang:f,onScreenshot:v,additionalPanelMenuItems:_})=>{la(o);const{data:w=[]}=O.useRequest(Ba),{data:x=[]}=O.useRequest(tc),T=h.useMemo(()=>qd(t,r,w,x,e,c??{},u??null),[t,r]);nd(T.content,!1),h.useEffect(()=>{T.context.replace(e)},[e]),h.useEffect(()=>{T.datasources.replace(w)},[w]),h.useEffect(()=>{T.globalSQLSnippets.replace(x)},[x]),h.useEffect(()=>{console.log("⚪️ calling onFilterValuesChange: ",T.content.filters.values),d==null||d(T.content.filters.values)},[d,T.content.filters.valuesString]),h.useEffect(()=>{c&&T.content.filters.patchValues(c)},[c,T.content.filters.patchValues]),h.useEffect(()=>{p==null||p(T.content.views.firstVisibleTabsViewActiveTab)},[p,T.content.views.firstVisibleTabsViewActiveTabStr]),h.useEffect(()=>{u&&T.content.views.setFirstVisibleTabsViewActiveTab(u)},[u,T.content.views.setFirstVisibleTabsViewActiveTab]);const D=O.useCreation(oa,[T]),z=rd(D);return O.useWhyDidYouUpdate("@devtable/dashboard render",{context:e,dashboard:t,content:r,className:a,config:o,fullScreenPanelID:l,setFullScreenPanelID:i,filterValues:c,onFilterValuesChange:d,activeTab:u,onActiveTabChange:p,lang:f}),n.jsx(Ya.Provider,{value:{onScreenshot:v??b.noop},children:n.jsx(ht.MantineEmotionProvider,{children:n.jsx(Rl,{lang:f,children:n.jsx(De.ModalsProvider,{children:n.jsx(tr,{children:n.jsx(Yn,{value:{renderSearchButton:o.renderSearchButton},children:n.jsx(rr,{value:{items:_??[]},children:n.jsx(Kn,{value:T,children:n.jsx(Zn,{value:T.content,children:n.jsx(er.Provider,{value:{fullScreenPanelID:l,setFullScreenPanelID:i},children:n.jsx(St.Provider,{value:{inEditMode:!1},children:n.jsx(s.Box,{className:`${a} dashboard-root`,children:n.jsx(lt.Provider,{value:D,children:n.jsx(bn,{configure:z,children:T.content.views.visibleViews.map(I=>n.jsx(qn,{view:I},I.id))})})})})})})})})})})})})})})},kM=k.observer(TM),DM=()=>Promise.resolve().then(()=>Ku).then(({version:e})=>(console.log(`[@devtable/dashboard] version: ${e}`),e));C.APIClient=$e,C.AdditionalPanelMenuItemsContext=nr,C.AdditionalPanelMenuItemsContextProvider=rr,C.CURRENT_SCHEMA_VERSION=ct,C.ClientPanelRender=qk,C.ContentModel=rs,C.ContentModelContext=Xn,C.ContentModelContextProvider=Zn,C.ContentRenderModel=hs,C.ContextMeta=An,C.DEFAULT_CUSTOM_MODAL_TITLE=$n,C.DashboardApiClient=ti,C.DashboardApiFacadeClient=ni,C.DashboardEditor=SM,C.DashboardFilterType=P,C.DashboardMode=Qc,C.DashboardModel=ed,C.DashboardModelContextProvider=Kn,C.DashboardRenderModel=Bd,C.DashboardThemeContextProvider=Yn,C.DashboardViewEditor=Fc,C.DashboardViewRender=qn,C.DataSourceMetaModel=Da,C.DataSourceType=W,C.DataSourcesMetaModel=ji,C.DatesProvider=tr,C.DefaultApiClient=ei,C.DefaultValueModeModelType=ua,C.DescriptionPopover=Ka,C.DraftModel=pc,C.EViewComponentType=B,C.FacadeApiClient=kT,C.FilterCheckboxConfigMeta=pa,C.FilterDateRangeConfigMeta=ha,C.FilterMericoDateRangeConfigMeta=Ca,C.FilterMeta=Pn,C.FilterModel=Wc,C.FilterMultiSelectConfigMeta=fa,C.FilterSelectConfigMeta=ba,C.FilterTextInputConfigMeta=ya,C.FilterTreeSelectConfigMeta=wa,C.FilterTreeSingleSelectConfigMeta=xa,C.FiltersModel=Uc,C.FiltersRenderModel=Aa,C.FullScreenPanel=qc,C.FullScreenPanelContext=er,C.GlobalSQLSnippetMeta=Wi,C.GlobalSQLSnippetsMeta=za,C.LayoutItemMeta=fi,C.LayoutSetMeta=bi,C.LayoutStateContext=St,C.LayoutsRenderModel=Oa,C.MericoMetricQueryMeta=da,C.MockContextMeta=ia,C.MuteQueryModel=lc,C.Panel=Bc,C.PanelContextProvider=Hn,C.PanelErrorOrStateMessage=Vc,C.PanelMeta=ii,C.PanelModel=Zc,C.PanelRender=Ra,C.PanelRenderModel=Pa,C.PanelStyleMeta=ai,C.PanelTitleMeta=si,C.PanelVizAddons=Ic,C.PanelVizMeta=li,C.PanelVizSection=Za,C.PanelsModel=Jc,C.PanelsRenderModel=$a,C.QueriesModel=Yc,C.QueriesRenderModel=La,C.QueryMeta=gi,C.QueryModel=Kc,C.QueryRenderModel=qa,C.ReadOnlyDashboard=kM,C.SQLSnippetMeta=yi,C.SQLSnippetRenderModel=dc,C.SQLSnippetsModel=Xc,C.SQLSnippetsRenderModel=Na,C.VariableMeta=oi,C.ViewComponentTypeBackground=jc,C.ViewComponentTypeColor=nD,C.ViewComponentTypeName=tD,C.ViewDivisionConfig=Sa,C.ViewMeta=Qi,C.ViewModalConfig=Ta,C.ViewRenderModel=Ia,C.ViewTabsConfig=ka,C.ViewsModel=Hc,C.ViewsRenderModel=Va,C.Viz=Mc,C.applyPartialDashboard=MD,C.configureAPIClient=la,C.createContentModel=Rc,C.createContentRenderModel=Ed,C.createContextMeta=Ma,C.createDashboardModel=td,C.createDashboardRenderModel=qd,C.createDraft=hc,C.createFilterCheckboxConfig=vi,C.createFilterDateRangeConfig=Ci,C.createFilterMericoDateRangeConfig=Oi,C.createFilterMultiSelectConfig=Ti,C.createFilterSelectConfig=ki,C.createFilterTextInputConfig=va,C.createFilterTreeSelectConfig=$i,C.createFilterTreeSingleSelectConfig=Ai,C.createMericoMetricQueryMetaConfig=hi,C.createViewDivisionConfig=Ni,C.createViewModalConfig=Gi,C.createViewTabsConfig=Fi,C.facadeApiClient=ri,C.formatSQLSnippet=Rt,C.getInitialDashboardViewsModel=ns,C.getInitialFiltersConfig=Ea,C.getInitialMockContextMeta=ca,C.getInitialQueriesRenderModel=ic,C.getInitialSQLSnippetsRenderModel=uc,C.getInitialViewsRenderModel=Ui,C.getNewPanel=Zi,C.getStaticDateRangeDefaultValue=wi,C.getStaticMericoDateRangeDefaultValue=qi,C.getVersion=DM,C.initialDashboardContent=t2,C.notifyVizRendered=fe,C.onVizRendered=hh,C.pluginManager=Mt,C.pluginServices=ee,C.useAdditionalPanelMenuItems=ar,C.useContentModelContext=Jn,C.useDashboardContext=jt,C.useDashboardThemeContext=Ws,C.useEditContentModelContext=G,C.useEditDashboardContext=j,C.useEditPanelContext=ae,C.useFullScreenPanelContext=Js,C.useIsInEditPanelContext=Zs,C.useIsInRenderPanelContext=Xs,C.useLayoutStateContext=Us,C.usePanelFullScreen=Lc,C.useRenderContentModelContext=H,C.useRenderDashboardContext=Qs,C.useRenderPanelContext=re,C.useServiceLocator=Yt,C.useVisibleFilters=Y2,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})});
|
|
571
|
+
`),post:""},e5=k.observer(({queryModel:e})=>{const{t}=m.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(Tt,{label:"",value:e.pre_process,onChange:e.setPreProcess,defaultValue:R3.pre})})]})}),tn={height:"calc(100% - 44px)",padding:0},t5=k.observer(({queryModel:e})=>{const{t}=m.useTranslation(),r=F(),a=h.useMemo(()=>e.datasource?e.typedAsHTTP?"HTTP":"SQL":"Configurations",[e.datasource,e.typedAsHTTP]),[o,l]=h.useState(a);h.useEffect(()=>{l(d=>d!=="Configurations"&&a==="Configurations"?"Configurations":d)},[a]);const c=r.findQueryUsage(e.id).length===0;return n.jsxs(s.Tabs,{value:o,onChange:l,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(F3,{queryModel:e})}),e.typedAsSQL&&n.jsx(s.Tabs.Panel,{value:"SQL",sx:tn,children:n.jsx(s.Stack,{sx:{height:"100%"},children:n.jsx(H3,{queryModel:e})})}),e.typedAsHTTP&&n.jsx(s.Tabs.Panel,{value:"HTTP",sx:tn,children:n.jsx(s.Stack,{sx:{height:"100%"},children:n.jsx(U3,{queryModel:e})})}),e.isTransform&&n.jsx(s.Tabs.Panel,{value:"Transform",sx:tn,children:n.jsx(s.Stack,{sx:{height:"100%"},children:n.jsx(e5,{queryModel:e})})}),n.jsx(s.Tabs.Panel,{value:"Data",sx:{...tn,overflow:"hidden"},children:n.jsx(ls,{id:e.id,moreActions:null,refreshOnMount:!0})}),n.jsx(s.Tabs.Panel,{value:"Usage",py:"sm",px:"md",sx:{...tn,overflow:"hidden"},children:n.jsx(Td,{queryModel:e})})]})}),n5=({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"})]}),Dd=({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})]}),zd=({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})]}),r5=({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"})]}),a5=k.observer(({queryModel:e})=>{const{t}=m.useTranslation(),r=j(),a=F(),l=a.findQueryUsage(e.id).length>0,i=De.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 l?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(zd,{width:14,height:14,color:"gray"}),variant:"subtle",color:"gray",onClick:d=>{d.stopPropagation()},children:"删除查询"})}):n.jsx(s.Menu.Item,{leftSection:n.jsx(zd,{width:14,height:14}),color:"red",onClick:c,children:"删除查询"})}),s5=k.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(r5,{width:18,height:18})})}),n.jsx(s.Menu.Dropdown,{children:n.jsx(a5,{queryModel:e})})]})),o5={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 l5({data:e}){const t=h.useMemo(()=>{if(!Array.isArray(e)||e.length===0)return[];const a=ge.createColumnHelper();return Object.keys(e[0]).map(o=>a.accessor(o,{cell:l=>l.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:o5,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(o=>n.jsxs(s.Table.Th,{style:{width:o.getSize()},children:[o.isPlaceholder?null:ge.flexRender(o.column.columnDef.header,o.getContext()),n.jsx(s.ActionIcon,{variant:"subtle",onMouseDown:o.getResizeHandler(),onTouchStart:o.getResizeHandler(),className:`resizer ${o.column.getIsResizing()?"isResizing":""}`,children:n.jsx(S.IconArrowBarToRight,{})})]},o.id))},a.id))}),n.jsx(s.Table.Tbody,{children:r.getRowModel().rows.map(a=>n.jsx(s.Table.Tr,{children:a.getVisibleCells().map(o=>n.jsx(s.Table.Td,{children:n.jsx(ne,{children:typeof o.getValue()=="object"?n.jsx("pre",{children:JSON.stringify(o.getValue(),null,2)}):ge.flexRender(o.column.columnDef.cell,o.getContext())})},o.id))},a.id))})]})})}const i5=[{label:"10",value:"10"},{label:"20",value:"20"},{label:"50",value:"50"},{label:"100",value:"100"}],c5={root:{width:"150px"},section:{"&[data-position=left]":{width:"70px",textAlign:"center"}},input:{paddingLeft:"70px",paddingRight:0}},d5=({data:e,page:t,setPage:r,limit:a,setLimit:o})=>{const{t:l}=m.useTranslation(),i=e.length,c=Math.ceil(i/a),d=p=>{p&&(r(1),o(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:l("common.pagination.page_size")}),size:"xs",styles:c5,data:i5,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:l("common.pagination.total_rows",{total:i})})})]})},u5=Do(({data:e,loading:t})=>{const[r,a]=h.useState(1),[o,l]=h.useState(20),i=h.useMemo(()=>{const c=(r-1)*o,d=c+o;return e.slice(c,d)},[e,r,o]);return n.jsx(ne,{children:n.jsxs(s.Stack,{gap:10,styles:{root:{height:"100%",overflow:"hidden"}},children:[n.jsx(d5,{data:e,page:r,setPage:a,limit:o,setLimit:l}),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(l5,{data:i})]})]})})}),p5=k.observer(({queryModel:e})=>{const{t}=m.useTranslation(),{state:r,error:a,metricQueryPayloadErrorString:o,stateMessage:l}=e;return r==="loading"?null:a?n.jsx(s.Text,{mt:10,c:"red",size:"md",ta:"center",ff:"monospace",children:a}):o?n.jsx(s.Text,{mt:10,c:"red",size:"md",ta:"center",ff:"monospace",children:o}):l?n.jsx(s.Text,{size:"sm",mt:10,c:"gray",ta:"center",children:t(l)}):null}),h5=k.observer(({queryModel:e})=>{m.useTranslation();const{data:t,state:r}=e,a=r==="loading",o=h.useCallback(()=>{e.fetchData(!0)},[e.fetchData]),l=()=>{Yi(e.name,e.data)};h.useEffect(()=>{o()},[o]);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:l,children:"下载查询结果"})]}),n.jsxs(s.Box,{sx:{position:"relative",flexGrow:1,overflow:"hidden"},children:[n.jsx(p5,{queryModel:e}),n.jsx(u5,{data:t,loading:a})]})]})}),g5=k.observer(({queryModel:e})=>{const t=j();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(Fe.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(Fe.CodeHighlight,{language:"json",sx:{width:"100%",height:"100%",minHeight:"400px",overflowY:"auto"},withCopyButton:!1,code:t.queryVariablesString})})]})}),f5=()=>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"})]}),b5=()=>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"})})})]}),y5=()=>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"})]}),v5=()=>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"})]}),_5=()=>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"})})})]}),us=({type:e})=>{switch(e){case"boolean":return n.jsx(f5,{});case"date":return n.jsx(b5,{});case"number":return n.jsx(y5,{});case"string":return n.jsx(v5,{});case"dimension":return n.jsx(_5,{});default:return null}},m5={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"}}}},w5={root:{maxWidth:"unset"},option:{fontFamily:"monospace"},input:{paddingInlineStart:"var(--input-padding-inline-start)",height:"auto",color:"black",fontFamily:"monospace"}},Md=(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(us,{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)},Id=k.observer(({mmInfo:e,value:t,onChange:r,usedKeys:a})=>{const o=e.metricDetail,l=e.metrics.loading||o.loading,i=o.error,c=o.filterColOptions,d=s.useCombobox({onDropdownClose:()=>d.resetSelectedOption()}),u=h.useMemo(()=>l?n.jsx(s.Loader,{size:"xs"}):t?n.jsx(s.CloseButton,{size:"xs",onClick:()=>r(null)}):n.jsx(s.Combobox.Chevron,{size:"xs"}),[l,t]),p=n.jsx(s.InputBase,{component:"button",type:"button",variant:"unstyled",size:"xs",pointer:!0,rightSection:u,rightSectionPointerEvents:!l&&t?"all":"none",onClick:()=>d.toggleDropdown(),disabled:l||c.length===0,styles:w5,error:!!i,children:t||n.jsx(s.Input.Placeholder,{children:"选择维度"})});return n.jsxs(s.Combobox,{store:d,onOptionSubmit:f=>{r(f),d.closeDropdown()},styles:m5,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(us,{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(x=>Md(x,!0,a.has(x.value)))},_.group):Md(_,!1,a.has(_.value))})},f))})})]})}),Vd={tbody:{td:{fontFamily:"monospace"}}},x5={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)"}}},C5=({option:e,...t})=>{const{t:r}=m.useTranslation(),a=e,o=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})}),o&&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(rt[a.widget])})]})]})},Gn=k.observer(({queryModel:e,value:t,onChange:r,usedKeys:a})=>{const{t:o}=m.useTranslation();e.config;const l=h.useMemo(()=>e.getConditionOptionsWithInvalidValue(t).optionGroups.map(d=>{const u=d.items.length;return{group:`${o(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,o,t,a]),i=h.useCallback((c,d)=>{r(c,d)},[r]);return n.jsx(s.Select,{size:"xs",variant:"unstyled",placeholder:"选择变量",styles:x5,data:l,renderOption:C5,maxDropdownHeight:600,value:t,onChange:i,clearable:!0})}),ps=k.observer(({variable:e})=>{const t=j();if(!e)return null;const r=b.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,{})})}),S5=k.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:Vd,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(o=>n.jsxs(s.Table.Tr,{children:[n.jsx(s.Table.Td,{pr:0,children:n.jsx(Id,{mmInfo:a,value:o.dimension,onChange:o.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(ps,{variable:o.variable}),n.jsx(Gn,{queryModel:e,value:o.variable,onChange:o.setVariable})]})}),n.jsx(s.Table.Td,{children:n.jsx(s.Checkbox,{size:"xs",checked:e.keyInRunBy(o.variable),onChange:l=>e.changeRunByRecord(o.variable,l.currentTarget.checked),color:"red"})})]},o.dimension)),n.jsxs(s.Table.Tr,{className:"add-a-row",children:[n.jsx(s.Table.Td,{pr:0,children:n.jsx(Id,{mmInfo:a,value:null,onChange:o=>o&&t.addFilter(o,""),usedKeys:t.usedFilterDimensionKeys})}),n.jsx(s.Table.Td,{colSpan:2,pr:0,children:n.jsx(Gn,{queryModel:e,value:null,onChange:o=>o&&t.addFilter("",o)})}),n.jsx(s.Table.Td,{})]})]})]})]})}),T5=k.observer(({queryModel:e,variable:t})=>{const r=e.keyInRunBy(t),a=o=>{e.changeRunByRecord(t,o.currentTarget.checked)};return n.jsx(s.Checkbox,{size:"xs",checked:r,onChange:a,color:"red"})}),Pd=({queryModel:e,variable:t})=>t?n.jsx(T5,{queryModel:e,variable:t}):null,k5=k.observer(({queryModel:e})=>{const t=e.config,o=e.datasource.mericoMetricInfo.metricDetail,l=o.trendingDateCol,i=t.timeQuery.enabled;return o.supportTrending?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:!l})})})}),D5=k.observer(({queryModel:e})=>{const t=e.config,o=e.datasource.mericoMetricInfo.metricDetail,l=o.trendingDateCol;return!t.timeQuery.enabled||!o.supportTrending?null:n.jsxs(s.Table,{withTableBorder:!0,withColumnBorders:!0,layout:"fixed",styles:Vd,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:(l==null?void 0:l.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(ps,{variable:t.timeQuery.range_variable}),n.jsx(Gn,{queryModel:e,value:t.timeQuery.range_variable,onChange:t.setRangeVariable,usedKeys:t.usedTimeQueryVariableSet})]})}),n.jsx(s.Table.Td,{children:n.jsx(Pd,{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(ps,{variable:t.timeQuery.unit_variable}),n.jsx(Gn,{queryModel:e,value:t.timeQuery.unit_variable,onChange:t.setUnitVariable})]})}),n.jsx(s.Table.Td,{children:n.jsx(Pd,{queryModel:e,variable:t.timeQuery.unit_variable})})]},"dimension.step")]})]})}),z5=k.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(k5,{queryModel:e})]}),n.jsx(D5,{queryModel:e})]})),M5={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"}},I5=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(us,{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})]})},V5=k.observer(({queryModel:e})=>{const t=e.config,a=e.datasource.mericoMetricInfo,o=a.metricDetail,l=a.metrics.loading||o.loading,i=o.groupByColOptions,c=d=>{const u=o.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:M5,renderOption:I5,rightSection:l?n.jsx(s.Loader,{size:"xs"}):null,value:[...t.groupByValues],onChange:c,maxValues:t.timeQuery.enabled?1:2,placeholder:t.timeQuery.enabled?"仅可选一个维度":"最多选两个维度",disabled:l}),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})]})}),P5=e=>{if(!e)return null;try{const t=JSON.parse(e);return{calculation:t.calculation,n:t.n,direction:t.direction}}catch{return null}},$5=(e,t,r)=>{const a={max:"最大值",min:"最小值",sum:"总和",avg:"平均值"};return Array.from(ac.entries()).filter(([o])=>e.includes(o)).map(([o,l])=>{const c=!r&&l.requireTrendingDateCol;let d=l.name;if(l.requireWindowConfig&&t){const u=a[t.calculation]||t.calculation,p=t.direction==="forward"?"向前":"向后";d=`${l.name} · ${u} · ${t.n} 个步长 · ${p}`}return{value:o,label:d,description:l.description,disabled:c,disabledReason:c?"需要开启按时序查询":void 0}})},A5=e=>{const t=e.option,r=n.jsx(s.Group,{gap:"xs",wrap:"nowrap",children:n.jsxs("div",{children:[n.jsx(s.Text,{size:"sm",fw:500,children:t.label}),n.jsx(s.Text,{size:"xs",c:"dimmed",children:t.description})]})});return t.disabled&&t.disabledReason?n.jsx(s.Tooltip,{label:t.disabledReason,position:"top",withArrow:!0,children:n.jsx("div",{...e,style:{opacity:.6,cursor:"not-allowed"},children:r})}):n.jsx("div",{...e,children:r})},E5=k.observer(({queryModel:e})=>{const t=e.config,a=e.datasource.mericoMetricInfo,o=a.metricDetail,l=a.metrics.loading||o.loading,i=o.error,c=h.useRef(t.timeQuery.enabled);if(h.useEffect(()=>{if(c.current&&!t.timeQuery.enabled){const d=G.toJS(t.extraCalculations)||[],u=sc(d,!1);u.length!==d.length&&t.setExtraCalculations(u)}c.current=t.timeQuery.enabled},[t.timeQuery.enabled]),!t.id)return null;if(l)return n.jsxs(s.Stack,{gap:8,children:[n.jsx(s.Text,{size:"sm",fw:500,children:"衍生计算配置"}),n.jsx(s.Loader,{size:"xs"})]});if(i)return n.jsxs(s.Stack,{gap:8,children:[n.jsx(s.Text,{size:"sm",fw:500,children:"衍生计算配置"}),n.jsxs(s.Text,{size:"sm",c:"red",children:["加载失败: ",i]})]});if(o.hasData&&o.data){const d=o.data.extraCalculations;if(!d||d.length===0)return null;const u=P5(o.data.extraCalculationConfig),p=$5(d,u,t.timeQuery.enabled);return p.length===0?null:n.jsxs(s.Stack,{gap:8,children:[n.jsx(s.Text,{size:"sm",fw:500,children:"衍生计算配置"}),n.jsx(s.MultiSelect,{data:p,value:G.toJS(t.extraCalculations)||[],onChange:f=>t.setExtraCalculations(f),placeholder:"选择要使用的计算方式",searchable:!0,clearable:!0,nothingFoundMessage:"未找到可用的计算方式",renderOption:A5,maxDropdownHeight:300})]})}return null}),B5=k.observer(({queryModel:e})=>{const t=e.config,r=t.id;return h.useEffect(()=>{if(e.run_by.length===0)return;const a=[],o=t.usedFilterVariableSet,l=t.usedTimeQueryVariableSet;e.run_by.forEach(i=>{(o.has(i)||l.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(S5,{queryModel:e}),n.jsx(z5,{queryModel:e}),n.jsx(V5,{queryModel:e}),n.jsx(E5,{queryModel:e})]})}),q5=["function process_result(resp, utils, state) {"," return resp.data","}"].join(`
|
|
572
|
+
`),L5={root:{minHeight:"350px",maxHeight:"50vh",height:"100%",overflow:"hidden"},list:{"&::before":{borderColor:"transparent"}},panel:{height:"calc(100% - 36px)",overflowY:"auto"}},O5=k.observer(({queryModel:e})=>{const[t,r]=h.useState("编辑查询");return n.jsxs(s.Tabs,{color:"red",defaultValue:"编辑查询",styles:L5,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(B5,{queryModel:e})}),n.jsx(s.Tabs.Panel,{value:"加工结果",pt:"xs",children:n.jsx(Tt,{label:"",value:e.post_process,onChange:e.setPostProcess,defaultValue:q5})}),n.jsx(s.Tabs.Panel,{value:"使用情况",pt:"xs",children:n.jsx(Td,{queryModel:e})})]})}),N5=k.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(Dd,{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(Dd,{width:14,height:14}),variant:"filled",color:"red",onClick:()=>e.fetchData(!0),children:"执行查询"})}),G5=({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})]})},F5=k.observer(({queryModel:e})=>{const t=e.config,a=e.datasource.mericoMetricInfo,o=a.metrics;h.useEffect(()=>{o.load()},[o]),h.useEffect(()=>{!a.metricID&&t.id&&a.selectMetric(t.id)},[t.id]);const l=h.useMemo(()=>o.data.map(p=>({label:p.name,value:p.id,description:p.description,type:p.type})),[o.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}=o;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:l,renderOption:G5,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(n5,{width:14,height:14})})})]})})}),Q5=k.observer(({queryModel:e})=>{const{t}=m.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(xd,{queryModel:e,size:"xs"}),n.jsx(F5,{queryModel:e})]}),n.jsxs(s.Group,{justify:"flex-end",children:[n.jsx(N5,{queryModel:e}),n.jsx(s5,{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(O5,{queryModel:e}),n.jsx(g5,{queryModel:e})]}),n.jsx(h5,{queryModel:e})]})}),j5=k.observer(({id:e})=>{const r=F().queries.findByID(e);return e===""?null:r?r.isMericoMetricQuery?n.jsx(Q5,{queryModel:r}):n.jsx(t5,{queryModel:r}):n.jsx(s.Text,{size:"14px",c:"red",children:"Invalid Query ID"})}),W5=k.observer(({value:e})=>{const r=H().payloadForSQL,a=h.useMemo(()=>vr(e,r),[e,r]);return n.jsx(gr,{height:"100%",value:a})}),U5=k.observer(({item:e,remove:t,onKeyChanged:r})=>{const{t:a}=m.useTranslation(),[o,l]=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,x=De.useModals(),T=()=>{x.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:D=>{c(D.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:T,children:a("sql_snippet.delete")})]}),n.jsxs(s.Tabs,{value:o,onChange:l,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(ds,{}),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(gr,{height:"100%",value:f,onChange:v,defaultLanguage:"sql",theme:"sql-dark"})}),n.jsx(s.Tabs.Panel,{value:"Preview",pt:"sm",children:n.jsx(W5,{value:f})})]})]})}),K5=k.observer(({id:e})=>{const t=j(),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 o=()=>{t.editor.setPath(["_SQL_SNIPPETS_",""])},l=()=>{r.sqlSnippets.removeByKey(e),o()},i=c=>{t.editor.setPath(["_SQL_SNIPPETS_",c])};return n.jsx(U5,{item:a,remove:l,onKeyChanged:i})}),Y5=k.observer(()=>{const{t:e}=m.useTranslation(),[t,r]=h.useState([]),a=De.useModals(),o=j(),l=v=>{o.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:()=>o.content.removeUnusedSQLSnippets(),confirmProps:{color:"red"},zIndex:320})},c=()=>{o.content.sqlSnippets.downloadSchema(t)},d=h.useMemo(()=>o.content.sqlSnippets.sortedList.map(v=>v.key),[o.content.sqlSnippets.sortedList]),u=()=>{r(d)},p=()=>{r([])},f=o.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:!o.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:o.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:()=>l(v.key),children:e("common.actions.open")})})]},v.key)})})]})})})]})}),X5=k.observer(({view:e})=>!e||e.type!==B.Division?null:n.jsx(s.Stack,{})),Z5=k.observer(({view:e})=>{const{t,i18n:r}=m.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]),o=h.useMemo(()=>[{value:"horizontal",label:t("common.tabs.orientation.horizontal")},{value:"vertical",label:t("common.tabs.orientation.vertical")}],[r.language]);if(!e||e.type!==B.Tabs)return null;const l=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:l.variant,onChange:l.setVariant,data:a}),n.jsx(s.Select,{label:t("common.tabs.orientation.label"),value:l.orientation,onChange:l.setOrientation,data:o}),n.jsx(s.Switch,{label:t("common.tabs.grow_tabs"),checked:l.grow,onChange:i=>l.setGrow(i.currentTarget.checked)})]})}),J5=({disabled:e,value:t,onChange:r})=>{const a=o=>{o&&r(o)};return n.jsxs(s.Box,{sx:{position:"relative"},children:[e&&n.jsx(s.Overlay,{backgroundOpacity:.6,color:"#fff",zIndex:5,blur:2}),n.jsx(Se,{height:"500px",defaultLanguage:"javascript",value:t,onChange:a,theme:"vs-dark",options:{minimap:{enabled:!1},readOnly:e}})]})},H5=({value:e,onChange:t})=>{const{t:r}=m.useTranslation(),[a,{setTrue:o,setFalse:l}]=O.useBoolean(),[i,c]=h.useState(e??$n),d=_=>{c({...i,enabled:_})},u=()=>{l();const{enabled:_,func_content:w}=i,x={enabled:_,func_content:w};c(x),t(x)},p=()=>{l(),c(e)},f=_=>{c(w=>({...w,func_content:_}))},v=()=>{f($n.func_content)};return n.jsxs(n.Fragment,{children:[n.jsx(s.ActionIcon,{size:"lg",color:"blue",variant:"filled",mt:26,onClick:o,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:l,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(J5,{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")})]})]})]})})]})},R5=k.observer(({view:e})=>{const{t}=m.useTranslation();if(!e||e.type!==B.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:b.noop,disabled:!0,sx:{flexGrow:1}}),n.jsx(H5,{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:o=>r.setWidth(o.currentTarget.value),placeholder:"600px / 50vw"}),n.jsx(s.TextInput,{label:t("view.component.modal.height"),value:r.height,onChange:o=>r.setHeight(o.currentTarget.value),placeholder:"600px / 50vw"})]})]})}),eM=k.observer(({view:e})=>n.jsxs(n.Fragment,{children:[n.jsx(X5,{view:e}),n.jsx(R5,{view:e}),n.jsx(Z5,{view:e})]})),tM=k.observer(({view:e})=>{const{t,i18n:r}=m.useTranslation(),a=h.useMemo(()=>[{label:t("view.component.div.label"),value:B.Division},{label:t("view.component.modal.label"),value:B.Modal},{label:t("view.component.tabs.label"),value:B.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:o=>{e.setName(o.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(eM,{view:e})]}):null}),nM=k.observer(({id:e})=>{const{t}=m.useTranslation(),r=De.useModals(),a=j(),o=F();if(e==="")return null;const l=o.views.findByID(e);if(!l)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:()=>{o.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(tM,{view:l})})]})}),rM=k.observer(()=>n.jsx(s.Stack,{sx:{height:"100%"},p:"sm",children:n.jsx(Cd,{})})),aM=k.observer(()=>{const e=j().editor,t=e.path;return fD(t)?n.jsx(rM,{}):bD(t)?n.jsx(Qz,{}):yD(t)?n.jsx(Fz,{}):vD(t)?n.jsx(s.Box,{p:"xs",pl:20,children:n.jsx(Gz,{id:t[1]})}):_D(t)?n.jsx(Y5,{}):mD(t)?n.jsx(K5,{id:t[1]}):xD(t)?n.jsx(x3,{}):wD(t)?n.jsx(j5,{id:t[1]}):CD(t)?n.jsx(s.Box,{p:"xs",pl:20,children:n.jsx(nM,{id:t[1]})}):ts(t)?n.jsx(w3,{viewID:t[1],panelID:t[3]}):n.jsx(s.Box,{children:e.path})}),sM=k.observer(()=>n.jsx(aM,{})),oM=k.observer(()=>{const{t:e}=m.useTranslation(),t=j(),r=()=>{const a=new Date().getTime().toString(),o={id:a,key:a,label:a,order:t.content.filters.current.length+1,type:P.TextInput,config:va(),visibleInViewsIDs:["Main"],auto_submit:!1};t.content.filters.append(o),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")})}),lM=k.observer(({parentID:e})=>{const{t}=m.useTranslation(),r=F();if(!e)return null;const a=r.views.findByID(e);return!a||a.type===B.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")})}),iM=k.observer(()=>{const{t:e}=m.useTranslation(),t=j(),r=()=>{const a=new Date().getTime().toString(),o={id:a,name:a,type:W.Postgresql,key:"",config:{_type:W.Postgresql,sql:""}};t.content.queries.append(o),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")})}),cM=k.observer(()=>{const{t:e}=m.useTranslation(),t=j(),r=()=>{const a=new Date().getTime().toString(),o={key:a,value:""};t.content.sqlSnippets.append(o),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")})}),dM=k.observer(()=>{const{t:e}=m.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")})}),uM=k.observer(()=>{const{t:e}=m.useTranslation(),t=j();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")})}),pM=k.observer(()=>{const{t:e}=m.useTranslation(),t=j();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")})}),hM=k.observer(()=>{const{t:e}=m.useTranslation(),t=j();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")})}),gM=k.observer(({action_type:e,parentID:t})=>e==="_Add_A_Filter_"?n.jsx(oM,{}):e==="_Add_A_SQL_SNIPPET_"?n.jsx(cM,{}):e==="_Add_A_QUERY_"?n.jsx(iM,{}):e==="_Add_A_VIEW_"?n.jsx(dM,{}):e==="_Add_A_PANEL_"?n.jsx(lM,{parentID:t}):e==="_QUERIES_SETTINGS_"?n.jsx(uM,{}):e==="_SQL_SNIPPETS_SETTINGS_"?n.jsx(pM,{}):e==="_FILTERS_SETTINGS_"?n.jsx(hM,{}):null),$d={menu_target:"_menu_target_m5ywm_1",query:"_query_m5ywm_12"},Ad=k.observer(({option:e})=>{var v;const{t}=m.useTranslation(),r=F(),a=j().editor,o=a.isOptionActive,l=o(a.path,e),i=a.isOptionOpened,c=a.navigate,d=i(e),[u,p]=h.useState(d);h.useEffect(()=>{p(d)},[d]);const f=e._type==="query";return n.jsx(s.NavLink,{pos:"relative",active:l,defaultOpened:d,opened:u,onChange:p,label:t(e.label),onClick:()=>c(e),leftSection:e.Icon?n.jsx(e.Icon,{size:18}):null,rightSection:f?n.jsxs(s.Menu,{trigger:"hover",position:"right",withArrow:!0,shadow:"xl",children:[n.jsx(s.Menu.Target,{children:n.jsx(s.ActionIcon,{variant:"subtle",className:$d.menu_target,children:n.jsx(S.IconDotsVertical,{size:16})})}),n.jsx(s.Menu.Dropdown,{children:n.jsx(s.Menu.Item,{leftSection:n.jsx(S.IconCopy,{size:16}),onClick:()=>r.queries.duplicateByID(e.value),children:t("common.actions.duplicate")})})]}):null,className:f?$d.query:"",children:(v=e.children)==null?void 0:v.map(_=>_._type==="ACTION"?n.jsx(gM,{action_type:_._action_type,parentID:_.parentID},`_ADD_${_.value}_`):n.jsx(Ad,{option:_},_.value))},e.label)}),fM=k.observer(()=>{const e=j();return n.jsx(s.Box,{sx:{position:"relative"},children:e.editor.navOptions.map(t=>n.jsx(Ad,{option:t},t.value))})}),bM=k.observer(()=>{const{t:e}=m.useTranslation(),t=j();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(fM,{})}),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")})})})]})}),yM={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"}},vM=k.observer(()=>{const e=j().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:yM,children:[n.jsx(bM,{}),n.jsx(s.AppShell.Main,{children:n.jsx(sM,{})})]})})}),_M=e=>e.replace(/([^:])(\/\/+)/g,"$1/");function mM(e){h.useEffect(()=>{if(Se.loader.__getMonacoInstance())return;console.log("loading monaco for @devtable/dashboard");const r=_M(e);Se.loader.config({paths:{vs:r}}),Se.loader.init().then(a=>console.log("monaco instance:",a))},[])}const wM=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])};ao(),Mo();const xM={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"}},CM=({context:e,dashboard:t,content:r,update:a,className:o="dashboard",config:l,onChange:i,headerSlot:c,filterValues:d,onFilterValuesChange:u,onExit:p,lang:f,additionalPanelMenuItems:v},_)=>{mM(l.monacoPath),la(l);const{data:w=[]}=O.useRequest(Ba),{data:x=[]}=O.useRequest(tc),T=h.useMemo(()=>td(t,r,w,x,e,d??{}),[t,r]);h.useImperativeHandle(_,()=>T,[T]),nd(T.content,!0),h.useEffect(()=>{T.context.replace(e)},[e]),h.useEffect(()=>{T.datasources.replace(w)},[w]),h.useEffect(()=>{T.globalSQLSnippets.replace(x)},[x]),h.useEffect(()=>{u==null||u(T.content.filters.values)},[u,T.content.filters.values]),h.useEffect(()=>{d&&T.content.filters.patchValues(d)},[d,T.content.filters.patchValues]),h.useEffect(()=>G.reaction(()=>G.toJS(T.json),E=>{i==null||i(E)}),[T]);const D=async()=>{await a(T.json,T.content.json)},z=O.useCreation(oa,[]),I=rd(z);return wM(T.content.changed),O.useWhyDidYouUpdate("@devtable/dashboard editor",{context:e,dashboard:t,content:r,update:a,className:o,config:l,onChange:i,headerSlot:c,filterValues:d,onFilterValuesChange:u,onExit:p,lang:f}),n.jsx(ht.MantineEmotionProvider,{children:n.jsx(Rl,{lang:f,children:n.jsx(De.ModalsProvider,{children:n.jsx(tr,{children:n.jsx(Yn,{value:{renderSearchButton:l.renderSearchButton},children:n.jsx(rr,{value:{items:v??[]},children:n.jsx(Kn,{value:T,children:n.jsx(Zn,{value:T.content,children:n.jsxs(St.Provider,{value:{inEditMode:!0},children:[n.jsx(ZD,{}),n.jsx(lt.Provider,{value:z,children:n.jsxs(bn,{configure:I,children:[n.jsxs(s.AppShell,{padding:0,navbar:{width:{base:200,xs:200,sm:200,md:220,lg:240,xl:260},breakpoint:"xxs"},styles:xM,children:[n.jsx(ez,{onExit:p,saveDashboardChanges:D,headerSlot:c}),n.jsx(Dz,{}),n.jsx(s.AppShell.Main,{children:n.jsx(s.Box,{className:`${o} dashboard-root`,sx:{position:"relative"},children:T.content.views.visibleViews.map(E=>n.jsx(Fc,{view:E},E.id))})})]}),n.jsx(vM,{})]})})]})})})})})})})})})},SM=k.observer(h.forwardRef(CM)),r6="",hs=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:Aa,queries:La,sqlSnippets:Na,views:Va,panels:$a,layouts:Oa,mock_context:ia}).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:Rt(e.sqlSnippets.current,"key","value",a),global_sql_snippets:Rt(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(([o,l])=>{a.context[o]={type:"context",key:o,value:l}}),a},get dashboardStateValues(){return br(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 Ed({id:e,name:t,dashboard_id:r,create_time:a,update_time:o,content:l},i,c,d){if(!l)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:x,mock_context:T={}}}=l;return hs.create({id:e,name:t,dashboard_id:r,create_time:a,update_time:o,version:u,filters:Ea(p,i,T,c),queries:ic(w),sqlSnippets:uc(x),mock_context:ca(T),views:Ui(f,d),panels:{list:v},layouts:{list:_,currentBreakpoint:_[0].id}})}const Bd=g.types.model({id:g.types.identifier,name:g.types.string,group:g.types.string,content:hs,content_id:g.types.string,datasources:ji,globalSQLSnippets:za,context:An});function qd({id:e,name:t,group:r,content_id:a},o,l,i,c,d,u){return Bd.create({id:e,name:t,group:r,content_id:a,content:Ed(o,c,d,u),datasources:{list:l},globalSQLSnippets:{list:i},context:Ma(c)})}ao(),Mo();const TM=({context:e,dashboard:t,content:r,className:a="dashboard",config:o,fullScreenPanelID:l,setFullScreenPanelID:i,filterValues:c,onFilterValuesChange:d,activeTab:u,onActiveTabChange:p,lang:f,onScreenshot:v,additionalPanelMenuItems:_})=>{la(o);const{data:w=[]}=O.useRequest(Ba),{data:x=[]}=O.useRequest(tc),T=h.useMemo(()=>qd(t,r,w,x,e,c??{},u??null),[t,r]);nd(T.content,!1),h.useEffect(()=>{T.context.replace(e)},[e]),h.useEffect(()=>{T.datasources.replace(w)},[w]),h.useEffect(()=>{T.globalSQLSnippets.replace(x)},[x]),h.useEffect(()=>{console.log("⚪️ calling onFilterValuesChange: ",T.content.filters.values),d==null||d(T.content.filters.values)},[d,T.content.filters.valuesString]),h.useEffect(()=>{c&&T.content.filters.patchValues(c)},[c,T.content.filters.patchValues]),h.useEffect(()=>{p==null||p(T.content.views.firstVisibleTabsViewActiveTab)},[p,T.content.views.firstVisibleTabsViewActiveTabStr]),h.useEffect(()=>{u&&T.content.views.setFirstVisibleTabsViewActiveTab(u)},[u,T.content.views.setFirstVisibleTabsViewActiveTab]);const D=O.useCreation(oa,[T]),z=rd(D);return O.useWhyDidYouUpdate("@devtable/dashboard render",{context:e,dashboard:t,content:r,className:a,config:o,fullScreenPanelID:l,setFullScreenPanelID:i,filterValues:c,onFilterValuesChange:d,activeTab:u,onActiveTabChange:p,lang:f}),n.jsx(Ya.Provider,{value:{onScreenshot:v??b.noop},children:n.jsx(ht.MantineEmotionProvider,{children:n.jsx(Rl,{lang:f,children:n.jsx(De.ModalsProvider,{children:n.jsx(tr,{children:n.jsx(Yn,{value:{renderSearchButton:o.renderSearchButton},children:n.jsx(rr,{value:{items:_??[]},children:n.jsx(Kn,{value:T,children:n.jsx(Zn,{value:T.content,children:n.jsx(er.Provider,{value:{fullScreenPanelID:l,setFullScreenPanelID:i},children:n.jsx(St.Provider,{value:{inEditMode:!1},children:n.jsx(s.Box,{className:`${a} dashboard-root`,children:n.jsx(lt.Provider,{value:D,children:n.jsx(bn,{configure:z,children:T.content.views.visibleViews.map(I=>n.jsx(qn,{view:I},I.id))})})})})})})})})})})})})})})},kM=k.observer(TM),DM=()=>Promise.resolve().then(()=>Ku).then(({version:e})=>(console.log(`[@devtable/dashboard] version: ${e}`),e));C.APIClient=$e,C.AdditionalPanelMenuItemsContext=nr,C.AdditionalPanelMenuItemsContextProvider=rr,C.CURRENT_SCHEMA_VERSION=ct,C.ClientPanelRender=qk,C.ContentModel=rs,C.ContentModelContext=Xn,C.ContentModelContextProvider=Zn,C.ContentRenderModel=hs,C.ContextMeta=An,C.DEFAULT_CUSTOM_MODAL_TITLE=$n,C.DashboardApiClient=ti,C.DashboardApiFacadeClient=ni,C.DashboardEditor=SM,C.DashboardFilterType=P,C.DashboardMode=Qc,C.DashboardModel=ed,C.DashboardModelContextProvider=Kn,C.DashboardRenderModel=Bd,C.DashboardThemeContextProvider=Yn,C.DashboardViewEditor=Fc,C.DashboardViewRender=qn,C.DataSourceMetaModel=Da,C.DataSourceType=W,C.DataSourcesMetaModel=ji,C.DatesProvider=tr,C.DefaultApiClient=ei,C.DefaultValueModeModelType=ua,C.DescriptionPopover=Ka,C.DraftModel=pc,C.EViewComponentType=B,C.FacadeApiClient=kT,C.FilterCheckboxConfigMeta=pa,C.FilterDateRangeConfigMeta=ha,C.FilterMericoDateRangeConfigMeta=Ca,C.FilterMeta=Pn,C.FilterModel=Wc,C.FilterMultiSelectConfigMeta=fa,C.FilterSelectConfigMeta=ba,C.FilterTextInputConfigMeta=ya,C.FilterTreeSelectConfigMeta=wa,C.FilterTreeSingleSelectConfigMeta=xa,C.FiltersModel=Uc,C.FiltersRenderModel=Aa,C.FullScreenPanel=qc,C.FullScreenPanelContext=er,C.GlobalSQLSnippetMeta=Wi,C.GlobalSQLSnippetsMeta=za,C.LayoutItemMeta=fi,C.LayoutSetMeta=bi,C.LayoutStateContext=St,C.LayoutsRenderModel=Oa,C.MericoMetricQueryMeta=da,C.MockContextMeta=ia,C.MuteQueryModel=lc,C.Panel=Bc,C.PanelContextProvider=Hn,C.PanelErrorOrStateMessage=Vc,C.PanelMeta=ii,C.PanelModel=Zc,C.PanelRender=Ra,C.PanelRenderModel=Pa,C.PanelStyleMeta=ai,C.PanelTitleMeta=si,C.PanelVizAddons=Ic,C.PanelVizMeta=li,C.PanelVizSection=Za,C.PanelsModel=Jc,C.PanelsRenderModel=$a,C.QueriesModel=Yc,C.QueriesRenderModel=La,C.QueryMeta=gi,C.QueryModel=Kc,C.QueryRenderModel=qa,C.ReadOnlyDashboard=kM,C.SQLSnippetMeta=yi,C.SQLSnippetRenderModel=dc,C.SQLSnippetsModel=Xc,C.SQLSnippetsRenderModel=Na,C.VariableMeta=oi,C.ViewComponentTypeBackground=jc,C.ViewComponentTypeColor=nD,C.ViewComponentTypeName=tD,C.ViewDivisionConfig=Sa,C.ViewMeta=Qi,C.ViewModalConfig=Ta,C.ViewRenderModel=Ia,C.ViewTabsConfig=ka,C.ViewsModel=Hc,C.ViewsRenderModel=Va,C.Viz=Mc,C.applyPartialDashboard=MD,C.configureAPIClient=la,C.createContentModel=Rc,C.createContentRenderModel=Ed,C.createContextMeta=Ma,C.createDashboardModel=td,C.createDashboardRenderModel=qd,C.createDraft=hc,C.createFilterCheckboxConfig=vi,C.createFilterDateRangeConfig=Ci,C.createFilterMericoDateRangeConfig=Oi,C.createFilterMultiSelectConfig=Ti,C.createFilterSelectConfig=ki,C.createFilterTextInputConfig=va,C.createFilterTreeSelectConfig=$i,C.createFilterTreeSingleSelectConfig=Ai,C.createMericoMetricQueryMetaConfig=hi,C.createViewDivisionConfig=Ni,C.createViewModalConfig=Gi,C.createViewTabsConfig=Fi,C.facadeApiClient=ri,C.formatSQLSnippet=Rt,C.getInitialDashboardViewsModel=ns,C.getInitialFiltersConfig=Ea,C.getInitialMockContextMeta=ca,C.getInitialQueriesRenderModel=ic,C.getInitialSQLSnippetsRenderModel=uc,C.getInitialViewsRenderModel=Ui,C.getNewPanel=Zi,C.getStaticDateRangeDefaultValue=wi,C.getStaticMericoDateRangeDefaultValue=qi,C.getVersion=DM,C.initialDashboardContent=t2,C.notifyVizRendered=fe,C.onVizRendered=hh,C.pluginManager=Mt,C.pluginServices=ee,C.useAdditionalPanelMenuItems=ar,C.useContentModelContext=Jn,C.useDashboardContext=jt,C.useDashboardThemeContext=Ws,C.useEditContentModelContext=F,C.useEditDashboardContext=j,C.useEditPanelContext=ae,C.useFullScreenPanelContext=Js,C.useIsInEditPanelContext=Zs,C.useIsInRenderPanelContext=Xs,C.useLayoutStateContext=Us,C.usePanelFullScreen=Lc,C.useRenderContentModelContext=H,C.useRenderDashboardContext=Qs,C.useRenderPanelContext=re,C.useServiceLocator=Yt,C.useVisibleFilters=Y2,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})});
|