@perses-dev/table-plugin 0.13.0-rc.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +0,0 @@
1
- "use strict";(self.chunk_Table=self.chunk_Table||[]).push([["2669"],{54042(e,t,n){var l;t.default=void 0,t.default=(0,((l=n(1448))&&l.__esModule?l:{default:l}).default)("M5,20H19V18H5M19,9H15V3H9V9H5L12,16L19,9Z","Download")},42524(e,t,n){var l;t.default=void 0,t.default=(0,((l=n(1448))&&l.__esModule?l:{default:l}).default)("M19,13H5V11H19V13Z","Minus")},38019(e,t,n){n.r(t),n.d(t,{Table:()=>en});var l=n(62540),i=n(70451),o=n.n(i),r=n(54381),a=n(315),s=n(93648),d=n(97653),u=n(88091),c=n(47095),h=n(65211),p=n(6227),g=n(7013),x=n(86067),m=n(86742),f=n(3862);function v(e){let t=e.trim();if(""===t)return;let n=Number(t);return Number.isNaN(n)?void 0:n}function j(e,t){for(let l of t)if(function(e,t){var n,l,i,o,r,a,s;switch(e.kind){case"Value":return(null==(n=e.spec)?void 0:n.value)===String(t);case"Range":{if(Number.isNaN(Number(t)))return!1;let n=Number(t);if((null==(l=e.spec)?void 0:l.min)!==void 0&&(null==(i=e.spec)?void 0:i.max)!==void 0)return n>=+e.spec.min&&n<=+e.spec.max;if((null==(o=e.spec)?void 0:o.min)!==void 0)return n>=+e.spec.min;if((null==(r=e.spec)?void 0:r.max)!==void 0)return n<=+e.spec.max;return!1}case"Regex":if(!(null==(a=e.spec)?void 0:a.expr))return!1;try{return new RegExp(e.spec.expr).test(String(t))}catch{return!1}case"Misc":switch(null==(s=e.spec)?void 0:s.value){case"empty":return""===t;case"null":return null==t;case"NaN":return Number.isNaN(t);case"true":return!0===t;case"false":return!1===t;default:return!1}default:return!1}}(l.condition,e)){let t;if("Misc"===l.condition.kind){var n;switch(null==(n=l.condition.spec)?void 0:n.value){case"null":t="null";break;case"NaN":t="NaN"}}return function(e,t,n){let l=t.text||n||String(e);return{text:`${t.prefix??""}${l}${t.suffix??""}`,textColor:t.textColor,backgroundColor:t.backgroundColor}}(e,l,t)}}function b(e){let{cell:t,onChange:n,onDelete:i,...p}=e;return(0,l.jsxs)(r.A,{container:!0,spacing:2,...p,children:[(0,l.jsx)(r.A,{size:{xs:5},children:(0,l.jsxs)(a.A,{direction:"row",gap:1,width:"100%",children:[(0,l.jsxs)(s.A,{select:!0,label:"Type",value:t.condition.kind,onChange:e=>n({...t,condition:{kind:e.target.value}}),required:!0,sx:{width:"120px"},children:[(0,l.jsx)(d.A,{value:"Value",children:(0,l.jsxs)(a.A,{children:[(0,l.jsx)(u.A,{children:"Value"}),"Value"!==t.condition.kind&&(0,l.jsx)(u.A,{variant:"caption",children:"Matches an exact text value"})]})}),(0,l.jsx)(d.A,{value:"Range",children:(0,l.jsxs)(a.A,{children:[(0,l.jsx)(u.A,{children:"Range"}),"Range"!==t.condition.kind&&(0,l.jsx)(u.A,{variant:"caption",children:"Matches against a numerical range"})]})}),(0,l.jsx)(d.A,{value:"Regex",children:(0,l.jsxs)(a.A,{children:[(0,l.jsx)(u.A,{children:"Regex"}),"Regex"!==t.condition.kind&&(0,l.jsx)(u.A,{variant:"caption",children:"Matches against a regular expression"})]})}),(0,l.jsx)(d.A,{value:"Misc",children:(0,l.jsxs)(a.A,{children:[(0,l.jsx)(u.A,{children:"Misc"}),"Misc"!==t.condition.kind&&(0,l.jsx)(u.A,{variant:"caption",children:"Matches against empty, null and NaN values"})]})})]}),function(e,t){var n,l,i,r,c;let h=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"small";return"Value"===e.kind?o().createElement(s.A,{label:"Value",placeholder:"Exact value",value:(null==(n=e.spec)?void 0:n.value)??"",onChange:n=>t({...e,spec:{value:n.target.value}}),fullWidth:!0,size:h}):"Range"===e.kind?o().createElement(a.A,{gap:1,direction:"row"},[o().createElement(s.A,{key:"min",label:"From",placeholder:"Start of range",value:(null==(l=e.spec)?void 0:l.min)??"",onChange:n=>{let l=v(n.target.value);t({...e,spec:{...e.spec,min:l}})},type:"number",slotProps:{htmlInput:{step:"any"}},fullWidth:!0,size:h}),o().createElement(s.A,{key:"max",label:"To",placeholder:"End of range (inclusive)",value:(null==(i=e.spec)?void 0:i.max)??"",onChange:n=>{let l=v(n.target.value);t({...e,spec:{...e.spec,max:l}})},type:"number",slotProps:{htmlInput:{step:"any"}},fullWidth:!0,size:h})]):"Regex"===e.kind?o().createElement(s.A,{label:"Regular Expression",placeholder:"JavaScript regular expression",value:(null==(r=e.spec)?void 0:r.expr)??"",onChange:n=>t({...e,spec:{expr:n.target.value}}),fullWidth:!0,size:h}):"Misc"===e.kind?o().createElement(s.A,{select:!0,label:"Value",value:(null==(c=e.spec)?void 0:c.value)??"",onChange:n=>t({...e,spec:{value:n.target.value}}),fullWidth:!0,size:h},[{value:"empty",label:"Empty",caption:"Matches empty string"},{value:"null",label:"Null",caption:"Matches null or undefined"},{value:"NaN",label:"NaN",caption:"Matches Not a Number value"},{value:"true",label:"True",caption:"Matches true boolean"},{value:"false",label:"False",caption:"Matches false boolean"}].map(e=>o().createElement(d.A,{key:e.value,value:e.value},o().createElement(a.A,{key:"stack"},[o().createElement(u.A,{key:"title"},e.label),o().createElement(u.A,{key:"caption",variant:"caption"},e.caption)])))):null}(t.condition,e=>n({...t,condition:e}),"small")]})}),(0,l.jsx)(r.A,{size:{xs:4},children:(0,l.jsxs)(a.A,{spacing:1,children:[(0,l.jsx)(s.A,{label:"Display text",value:t.text,onChange:e=>n({...t,text:e.target.value}),fullWidth:!0,size:"small"}),(0,l.jsxs)(a.A,{direction:"row",spacing:1,children:[(0,l.jsx)(s.A,{label:"Prefix",placeholder:"$",value:t.prefix??"",onChange:e=>n({...t,prefix:e.target.value}),size:"small"}),(0,l.jsx)(s.A,{label:"Suffix",placeholder:"%",value:t.suffix??"",onChange:e=>n({...t,suffix:e.target.value}),size:"small"})]})]})}),(0,l.jsx)(r.A,{size:{xs:1},children:(0,l.jsx)(a.A,{direction:"row",justifyContent:"center",gap:1,children:t.textColor?(0,l.jsx)(f.OptionsColorPicker,{label:"Text Color",color:t.textColor??"#000",onColorChange:e=>n({...t,textColor:e}),onClear:()=>n({...t,textColor:void 0})}):(0,l.jsx)(c.A,{onClick:()=>n({...t,textColor:"#000"}),children:(0,l.jsx)(m.default,{})})})}),(0,l.jsx)(r.A,{size:{xs:1},children:(0,l.jsx)(a.A,{direction:"row",justifyContent:"center",children:t.backgroundColor?(0,l.jsx)(f.OptionsColorPicker,{label:"Background Color",color:t.backgroundColor??"#fff",onColorChange:e=>n({...t,backgroundColor:e}),onClear:()=>n({...t,backgroundColor:void 0})}):(0,l.jsx)(c.A,{onClick:()=>n({...t,backgroundColor:"#000"}),children:(0,l.jsx)(m.default,{})})})}),(0,l.jsx)(r.A,{size:{xs:1},textAlign:"end",children:(0,l.jsx)(h.A,{title:"Remove cell settings",placement:"top",children:(0,l.jsx)(c.A,{size:"small",sx:{marginLeft:"auto"},onClick:i,children:(0,l.jsx)(x.default,{})},"delete-cell-button")})})]})}function C(e){let{cellSettings:t=[],onChange:n,addButtonText:i="Add Conditional Format"}=e;return(0,l.jsxs)(a.A,{spacing:3,sx:{mt:2},children:[(0,l.jsxs)(r.A,{container:!0,spacing:3,children:[(0,l.jsx)(r.A,{size:{xs:5},children:(0,l.jsx)(u.A,{variant:"subtitle1",children:"Condition"})}),(0,l.jsx)(r.A,{size:{xs:4},children:(0,l.jsx)(u.A,{variant:"subtitle1",children:"Display Text"})}),(0,l.jsx)(r.A,{size:{xs:1},textAlign:"center",children:(0,l.jsx)(u.A,{variant:"subtitle1",children:"Color"})}),(0,l.jsx)(r.A,{size:{xs:1},textAlign:"center",children:(0,l.jsx)(u.A,{variant:"subtitle1",children:"Background"})}),(0,l.jsx)(r.A,{size:{xs:1}})]}),(0,l.jsx)(a.A,{gap:1.5,divider:(0,l.jsx)(p.A,{flexItem:!0,orientation:"horizontal"}),children:t.map((e,i)=>(0,l.jsx)(b,{cell:e,onChange:e=>{let l;(l=[...t])[i]=e,n(l)},onDelete:()=>{let e;(e=[...t]).splice(i,1),n(e.length>0?e:void 0)}},i))}),(0,l.jsx)(g.A,{variant:"outlined",startIcon:(0,l.jsx)(m.default,{}),sx:{marginTop:1},onClick:()=>{let e=[...t];e.push({condition:{kind:"Value",spec:{value:""}}}),n(e)},children:i})]})}function y(e){let{cellSettings:t,onChange:n}=e;return(0,l.jsx)(C,{cellSettings:t,onChange:e=>n(e||[])})}var A=n(68003),k=n(12138),S=n(39420),w=n(42524);let E=e=>{let{onChange:t,column:n,column:{dataLink:i}}=e;if(!i)return(0,l.jsxs)(a.A,{sx:{width:"100%",alignItems:"center"},direction:"row",children:[(0,l.jsx)(u.A,{flex:1,variant:"subtitle1",mb:2,fontStyle:"italic",children:"No link defined"}),(0,l.jsx)(c.A,{style:{width:"fit-content",height:"fit-content"},onClick:()=>t({...n,dataLink:{url:"",openNewTab:!0,title:""}}),children:(0,l.jsx)(m.default,{})})]});let{url:o,openNewTab:r,title:s}=i;return(0,l.jsxs)(a.A,{sx:{width:"100%",alignItems:"center"},direction:"row",children:[(0,l.jsx)(f.LinkEditorForm,{mode:"inline",url:{label:"Url",onChange:e=>{t({...n,dataLink:{...i,url:e}})},value:o,placeholder:"URL",error:{hasError:!1,helperText:""}},name:{label:"Name",onChange:e=>{t({...n,dataLink:{...i,title:e}})},value:s??"",placeholder:"Name"},newTabOpen:{label:"Open in new tab",onChange:e=>{t({...n,dataLink:{...i,openNewTab:e}})},value:r}}),(0,l.jsx)(c.A,{style:{width:"fit-content",height:"fit-content"},onClick:()=>{t({...n,dataLink:void 0})},children:(0,l.jsx)(w.default,{})})]})};var M=n(25742),O=n(25632),z=n.n(O);function T(e,t){let n=e.createInitialOptions()??{};return z()({},n,t??{})}function N(e){let{kind:t,spec:n,onChange:o}=e,{data:r,isLoading:s,isError:d,error:c}=(0,S.usePlugin)("Panel",t),h=(0,i.useMemo)(()=>r?T(r,n):n,[r,n]),p=(0,i.useRef)(o);if(p.current=o,(0,i.useEffect)(()=>{r&&(null==n||"object"==typeof n&&0===Object.keys(n).length)&&p.current(T(r,n))},[r,t,n]),s)return(0,l.jsxs)(a.A,{direction:"row",alignItems:"center",spacing:1,sx:{py:1},children:[(0,l.jsx)(M.A,{size:22}),(0,l.jsx)(u.A,{variant:"body2",color:"text.secondary",children:"Loading panel settings…"})]});if(d||!r)return(0,l.jsx)(u.A,{variant:"body2",color:"error",children:(null==c?void 0:c.message)??"Could not load panel plugin."});let g=r.panelOptionsEditorComponents??[];return 0===g.length?(0,l.jsx)(u.A,{variant:"body2",color:"text.secondary",children:"This visualization has no editable settings."}):(0,l.jsx)(a.A,{spacing:2.5,sx:{width:"100%",py:1},children:(0,l.jsx)(S.OptionsEditorTabs,{tabs:g.map(e=>{let t=e.content;return{label:e.label,content:(0,l.jsx)(t,{value:h,onChange:e=>{o(e)}})}})})})}let D={unit:"decimal",shortValues:!0};function R(e){var t,n;let{column:o,onChange:r,...d}=e,[c,h]=(0,i.useState)(void 0===o.width||"auto"===o.width?100:o.width);return(0,l.jsxs)(a.A,{...d,children:[(0,l.jsxs)(f.OptionsEditorGrid,{children:[(0,l.jsx)(f.OptionsEditorColumn,{children:(0,l.jsxs)(f.OptionsEditorGroup,{title:"Column",children:[(0,l.jsx)(f.OptionsEditorControl,{label:"Name*",control:(0,l.jsx)(s.A,{value:o.name,onChange:e=>r({...o,name:e.target.value}),required:!0})}),(0,l.jsx)(f.OptionsEditorControl,{label:"Header",control:(0,l.jsx)(s.A,{value:o.header??"",onChange:e=>r({...o,header:e.target.value?e.target.value:void 0})})}),(0,l.jsx)(f.OptionsEditorControl,{label:"Header Tooltip",control:(0,l.jsx)(s.A,{value:o.headerDescription??"",onChange:e=>r({...o,headerDescription:e.target.value?e.target.value:void 0})})}),(0,l.jsx)(f.OptionsEditorControl,{label:"Cell Tooltip",control:(0,l.jsx)(s.A,{value:o.cellDescription??"",onChange:e=>r({...o,cellDescription:e.target.value?e.target.value:void 0})})}),(0,l.jsx)(f.OptionsEditorControl,{label:"Enable sorting",control:(0,l.jsx)(A.A,{checked:o.enableSorting??!1,onChange:e=>r({...o,enableSorting:e.target.checked})})}),o.enableSorting&&(0,l.jsx)(f.OptionsEditorControl,{label:"Default Sort",control:(0,l.jsx)(f.SortSelectorButtons,{size:"medium",value:o.sort,sx:{margin:.5},onChange:e=>r({...o,sort:e})})})]})}),(0,l.jsx)(f.OptionsEditorColumn,{children:(0,l.jsxs)(f.OptionsEditorGroup,{title:"Visual",children:[(0,l.jsx)(f.OptionsEditorControl,{label:"Show column",control:(0,l.jsx)(A.A,{checked:!o.hide,onChange:e=>r({...o,hide:!e.target.checked})})}),(0,l.jsx)(f.OptionsEditorControl,{label:"Cell display",control:(0,l.jsxs)(a.A,{spacing:1,children:[(0,l.jsxs)(k.A,{"aria-label":"Cell display",size:"small",children:[(0,l.jsx)(g.A,{variant:o.plugin?"outlined":"contained",onClick:()=>r({...o,plugin:void 0}),children:"Text"}),(0,l.jsx)(g.A,{variant:o.plugin?"contained":"outlined",onClick:()=>r({...o,plugin:{kind:"GaugeChart",spec:{}}}),children:"Visualization"})]}),(0,l.jsx)(u.A,{variant:"caption",color:"text.secondary",sx:{maxWidth:360},children:"Visualizations reuse panel settings (thresholds, units, colors). Text mode uses value formatting below."})]})}),o.plugin?(0,l.jsx)(f.OptionsEditorControl,{label:"Visualization type",control:(0,l.jsx)(S.PluginKindSelect,{pluginTypes:["Panel"],size:"small",value:{type:"Panel",kind:o.plugin.kind},onChange:e=>r({...o,plugin:{kind:e.kind,spec:{}}})})}):(0,l.jsx)(f.FormatControls,{value:o.format??D,onChange:e=>r({...o,format:e})}),(0,l.jsx)(f.OptionsEditorControl,{label:"Alignment",control:(0,l.jsx)(f.AlignSelector,{size:"small",value:o.align??"left",onChange:e=>r({...o,align:e})})}),(0,l.jsx)(f.OptionsEditorControl,{label:"Custom width",control:(0,l.jsx)(A.A,{checked:void 0!==o.width&&"auto"!==o.width,onChange:e=>r({...o,width:e.target.checked?c:"auto"})})}),void 0!==o.width&&"auto"!==o.width&&(0,l.jsx)(f.OptionsEditorControl,{label:"Width",control:(0,l.jsx)(s.A,{type:"number",value:c,slotProps:{htmlInput:{min:1}},onChange:e=>{h(+e.target.value),r({...o,width:+e.target.value})}})})]})}),(0,l.jsx)(f.OptionsEditorColumn,{children:(0,l.jsx)(f.OptionsEditorGroup,{title:"Link",children:(0,l.jsx)(E,{column:o,onChange:r})})})]}),(null==(t=o.plugin)?void 0:t.kind)==="GaugeChart"&&(0,l.jsx)(a.A,{sx:{px:8,mt:4,width:"100%"},spacing:2,children:(0,l.jsx)(f.OptionsEditorGroup,{title:"Visualization settings",children:(0,l.jsx)(N,{kind:"GaugeChart",spec:o.plugin.spec,onChange:e=>r({...o,plugin:{kind:"GaugeChart",spec:e}})})})}),(0,l.jsx)(a.A,{sx:{px:8,mt:3*((null==(n=o.plugin)?void 0:n.kind)==="GaugeChart")},children:(0,l.jsx)(f.OptionsEditorGroup,{title:"Conditional Cell Format",children:(0,l.jsx)(C,{cellSettings:o.cellSettings,onChange:e=>r({...o,cellSettings:e})})})})]})}var V=n(11061),I=n(87275),L=n(1355),F=n(78536);function $(e){let{column:t,isCollapsed:n,onChange:i,onCollapse:o,onDelete:r,onMoveUp:s,onMoveDown:d}=e;return(0,l.jsxs)(f.DragAndDropElement,{data:t,children:[(0,l.jsxs)(a.A,{direction:"row",alignItems:"center",borderBottom:1,borderColor:e=>e.palette.divider,justifyContent:"space-between",gap:4,children:[(0,l.jsxs)(a.A,{direction:"row",gap:1,children:[(0,l.jsx)(c.A,{"data-testid":`column-toggle#${t.name}`,size:"small",onClick:()=>o(!n),children:n?(0,l.jsx)(V.default,{}):(0,l.jsx)(I.default,{})}),(0,l.jsxs)(u.A,{variant:"overline",component:"h4",sx:{textTransform:"none"},children:["COLUMN:"," ",t.header?(0,l.jsxs)("span",{children:[(0,l.jsx)("strong",{children:t.header})," (",t.name,")"]}):(0,l.jsx)("strong",{children:t.name})]})]}),(0,l.jsxs)(a.A,{direction:"row",gap:1,children:[n&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(h.A,{title:t.hide?"Show column":"Hide column",placement:"top",children:(0,l.jsx)(c.A,{size:"small",sx:{marginLeft:"auto"},onClick:function(){i({...t,hide:!t.hide})},children:t.hide?(0,l.jsx)(F.default,{}):(0,l.jsx)(L.default,{})},"hide-column")}),(0,l.jsx)(p.A,{flexItem:!0,orientation:"vertical",variant:"middle"})]}),(0,l.jsx)(h.A,{title:"Remove column settings",placement:"top",children:(0,l.jsx)(c.A,{size:"small",sx:{marginLeft:"auto"},onClick:r,children:(0,l.jsx)(x.default,{})},"delete-column-button")}),(0,l.jsx)(h.A,{title:"Reorder column settings",placement:"top",children:(0,l.jsx)(f.DragButton,{onMoveUp:s,onMoveDown:d,menuSx:{".MuiPaper-root":{backgroundColor:e=>e.palette.background.lighter}}},"reorder-column-button")})]})]}),!n&&(0,l.jsx)("div",{children:(0,l.jsx)(R,{column:t,onChange:i})})]})}function H(e){let{columnSettings:t,onChange:n}=e,[o,r]=(0,i.useState)(t.map(()=>!0));return(0,f.useDragAndDropMonitor)({elements:t,accessKey:"name",onChange:n}),(0,l.jsxs)(a.A,{spacing:1,children:[t.map((e,i)=>(0,l.jsx)($,{column:e,isCollapsed:o[i]??!0,onChange:e=>{let l;(l=[...t])[i]=e,n(l)},onDelete:()=>{let e;(e=[...t]).splice(i,1),n(e),r(e=>(e.splice(i,1),[...e]))},onCollapse:e=>{r(t=>(t[i]=e,[...t]))},onMoveUp:()=>n((0,f.handleMoveUp)(e,t)),onMoveDown:()=>n((0,f.handleMoveDown)(e,t))},i)),(0,l.jsx)(g.A,{variant:"contained",startIcon:(0,l.jsx)(m.default,{}),sx:{marginTop:1},onClick:function(){let e=`column_${Object.keys(t).length}`,l=[...t];l.push({name:e}),n(l),r(e=>(e.push(!1),[...e]))},children:"Add Column Settings"})]})}var P=n(21860),W=n(85180);function G(e){let{kind:t,spec:n,queryResults:i}=e,{ref:o,width:r=1,height:a=1}=(0,W.default)();return(0,l.jsx)("div",{ref:o,style:{height:"100%"},children:(0,l.jsx)(f.ErrorBoundary,{FallbackComponent:f.ErrorAlert,children:(0,l.jsx)(P.PanelPluginLoader,{kind:t,contentDimensions:{width:r,height:a},spec:n,queryResults:i})})})}var U=n(74628),_=n(56599);function B(e){return(e.columnSettings??[]).some(e=>e.plugin)?"range":"instant"}function K(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},{forExport:l=!1}=n,i=B(t);return e.flatMap((e,t)=>{var n;return((null==(n=e.data)?void 0:n.series)??[]).map(n=>({data:e,ts:n,queryIndex:t}))}).map(n=>{let o,{data:r,ts:a,queryIndex:s}=n;if(void 0===a.values[0])return{...a.labels};let d=1===e.length?"value":`value #${s+1}`,u=1===e.length?a.labels:Object.entries(a.labels??{}).reduce((e,t)=>{let[n,l]=t;return n&&(e[`${n} #${s+1}`]=l),e},{});if(l)o=a.values[0][1];else{var c;o=(null==(c=(t.columnSettings??[]).find(e=>e.name===d))?void 0:c.plugin)?{...r,data:{...r.data,series:r.data.series.filter(e=>e===a)}}:a.values[0][1]}return"instant"===i?{timestamp:a.values[0][0],[d]:o,...u}:{[d]:o,...u}})}function q(e){if("number"==typeof e&&Number.isFinite(e))return e;if("string"==typeof e){let t=Number(e);if(Number.isFinite(t))return t}}function Q(e){return"object"==typeof e&&null!==e&&void 0!==e.definition&&void 0!==e.data}function Z(e){if(Q(e)){var t,n;let l=null==(t=e.data)?void 0:t.series,i=null==l?void 0:l[0];if(!(null==i||null==(n=i.values)?void 0:n.length))return;let o=S.CalculationsMap["last-number"];if("function"!=typeof o)return;let r=o(i.values);return"number"==typeof r?r:void 0}return q(e)}function J(e){let{value:t,range:n,fillColor:i,format:o}=e;if(void 0===t)return(0,l.jsx)(l.Fragment,{});let r=0;return void 0!==n&&(r=n.max===n.min?100:(t-n.min)/(n.max-n.min)*100),r=Math.max(0,Math.min(100,r)),(0,l.jsxs)(U.A,{sx:{display:"flex",alignItems:"center",width:"100%",gap:1},children:[(0,l.jsx)(U.A,{sx:{flexGrow:1,borderRadius:1,backgroundColor:"rgba(127,127,127,0.20)",height:24,overflow:"hidden"},children:(0,l.jsx)(U.A,{sx:{width:`${r}%`,height:"100%",backgroundColor:i??"success.main",borderRadius:1}})}),(0,l.jsx)(u.A,{variant:"body2",sx:{minWidth:52,textAlign:"right"},children:o?(0,f.formatValue)(t,o):t.toFixed(2)})]})}function Y(e){let{allValues:t,selectedValues:n,onFilterChange:o,theme:r}=e,[a,s]=(0,i.useState)(""),d=[...new Set(t)].filter(e=>null!==e).sort(),u=a?d.filter(e=>String(e).toLowerCase().includes(a.toLowerCase())):d;return 0===d.length?(0,l.jsx)("div",{"data-filter-dropdown":!0,style:{width:200,padding:10,backgroundColor:r.palette.background.paper,border:`1px solid ${r.palette.divider}`,borderRadius:4,boxShadow:r.shadows[4]},children:(0,l.jsx)("div",{style:{color:r.palette.text.secondary,fontSize:14},children:"No values found"})}):(0,l.jsxs)("div",{"data-filter-dropdown":!0,style:{width:200,padding:10,backgroundColor:r.palette.background.paper,border:`1px solid ${r.palette.divider}`,borderRadius:4,boxShadow:r.shadows[4],maxHeight:250,overflowY:"auto"},children:[(0,l.jsx)("input",{type:"text",placeholder:"Search...",value:a,onChange:e=>s(e.target.value),style:{width:"100%",padding:"6px 8px",marginBottom:8,fontSize:13,border:`1px solid ${r.palette.divider}`,borderRadius:4,backgroundColor:r.palette.background.default,color:r.palette.text.primary,boxSizing:"border-box"}}),(0,l.jsx)("div",{style:{marginBottom:8,fontSize:14,fontWeight:"bold"},children:(0,l.jsxs)("label",{style:{display:"flex",alignItems:"center",cursor:"pointer"},children:[(0,l.jsx)("input",{type:"checkbox",checked:n.length===d.length&&d.length>0,onChange:e=>o(e.target.checked?d.map(e=>e.original):[]),style:{marginRight:8}}),(0,l.jsxs)("span",{style:{color:r.palette.text.primary},children:["Select All (",d.length,")"]})]})}),(0,l.jsx)("hr",{style:{margin:"8px 0",border:"none",borderTop:`1px solid ${r.palette.divider}`}}),u.map((e,t)=>(0,l.jsx)("div",{style:{marginBottom:4},children:(0,l.jsxs)("label",{style:{display:"flex",alignItems:"center",cursor:"pointer",padding:"2px 0",borderRadius:2},onMouseEnter:e=>{e.currentTarget.style.backgroundColor=r.palette.action.hover},onMouseLeave:e=>{e.currentTarget.style.backgroundColor="transparent"},children:[(0,l.jsx)("input",{type:"checkbox",checked:n.includes(e.original),onChange:t=>{t.target.checked?o([...n,e.original]):o(n.filter(t=>t!==e.original))},style:{marginRight:8}}),(0,l.jsx)("span",{style:{fontSize:14,color:r.palette.text.primary},children:null==e||""===e.formatted?"(empty)":String(e.formatted)})]})},`value-${t}`))]})}function X(e,t,n,i){let o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[];for(let r of t)if(r.name===e){if(r.hide)return;let{name:e,header:t,headerDescription:a,enableSorting:s,width:d,align:u,dataLink:c}=r;return{accessorKey:e,header:t??e,headerDescription:a,enableSorting:s,width:d,align:u,dataLink:c?{...c,url:(0,S.replaceVariablesInString)(c.url,n)}:void 0,...function(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],i=e.plugin;return void 0!==i?{cell:o=>{let r=o.getValue();if("GaugeChart"===i.kind){var a;let o=Z(r),s=function(e,t,n){let l=j(e,t);if(null==n?void 0:n.length){let t=j(e,n);t&&(l=t)}return(null==l?void 0:l.backgroundColor)??(null==l?void 0:l.textColor)}(o,n,e.cellSettings);return(0,l.jsx)(J,{value:o,range:t,fillColor:s,format:(null==(a=i.spec)?void 0:a.format)??e.format})}let s=Q(r)?r:function(e,t){let n=q(e);if(void 0===n)return;let l=Date.now();return{definition:{kind:"TimeSeriesQuery",spec:{plugin:{kind:"PrometheusTimeSeriesQuery",spec:{query:""}}}},data:{timeRange:{start:new Date(l),end:new Date(l)},stepMs:1,series:[{name:t,values:[[l,n]],labels:{}}]}}}(r,e.name);return s?(0,l.jsx)(G,{kind:i.kind,spec:i.spec,queryResults:[s]}):(0,l.jsx)(l.Fragment,{})},cellDescription:e.cellDescription?()=>`${e.cellDescription}`:()=>""}:{cell:t=>{let n=t.getValue();return"number"==typeof n&&e.format?(0,f.formatValue)(n,e.format):n},cellDescription:e.cellDescription?()=>`${e.cellDescription}`:void 0}}(r,i[e],o)}}return{accessorKey:e,header:e}}function ee(e){let{label:t,defaultValue:n,value:i,onChange:o}=e;return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(f.OptionsEditorControl,{label:`Auto Columns ${t}`,control:(0,l.jsx)(A.A,{checked:void 0===i||"auto"===i,onChange:function(e,t){if(t)return o("auto");o(n)}})}),void 0!==i&&"auto"!==i&&(0,l.jsx)(f.OptionsEditorControl,{label:`Default Columns ${t}`,control:(0,l.jsx)(s.A,{type:"number",value:i??n,slotProps:{input:{inputProps:{min:1,step:1}}},onChange:e=>o(parseInt(e.target.value))})})]})}var et=n(54042);let en={PanelComponent:function(e){var t,n;let{contentDimensions:o,spec:r,queryResults:a}=e,s=(0,_.A)(),d=(0,S.useAllVariableValues)(),c=(null==(t=r.selection)?void 0:t.enabled)??!1,{selectionMap:h,setSelection:p,clearSelection:g}=(0,f.useSelection)(),x=r.actions?r.actions:void 0,m=(null==x?void 0:x.enabled)&&x.displayWithItem?x.actionsList:[],{getItemActionButtons:v,confirmDialog:b,actionButtons:C}=(0,P.useSelectionItemActions)({actions:m,variableState:d}),y=(0,i.useRef)([]),A=(0,i.useMemo)(()=>{let e={};return h.forEach((t,n)=>{e[n]=!0}),e},[h]),k=(0,i.useCallback)(e=>{let t=[];for(let[n,l]of Object.entries(e))if(l){let e=parseInt(n,10);void 0!==y.current[e]&&t.push({id:n,item:y.current[e]})}0===t.length?g():p(t)},[p,g]),w=(0,i.useMemo)(()=>K(a,r),[a,r]),E=(0,i.useMemo)(()=>(0,f.transformData)(w,r.transforms??[]),[w,r.transforms]),M=(0,i.useMemo)(()=>{let e=[];for(let t of E)for(let n of Object.keys(t))e.includes(n)||e.push(n);for(let t of r.columnSettings??[])e.includes(t.name)||e.push(t.name);return e},[E,r.columnSettings]),O=(0,i.useMemo)(()=>{let e={},t=null==r?void 0:r.columnSettings;if(t)for(let n=0;n<t.length;n++){let{name:l,format:i}=t[n]||{};l&&i&&(e[l]=i)}return e},[r]),z=(0,i.useMemo)(()=>{let e={};for(let t of M){let n=null==O?void 0:O[t];e[t]=[];let l=new Map;for(let i of E){let o=i[t];""!==o&&null!=o&&(l.get(String(o))||("string"==typeof o||"number"==typeof o)&&(e[t].push({original:o,formatted:n&&"number"==typeof o?(0,f.formatValue)(o,n):o}),l.set(String(o),!0)))}}return e},[E,M,O]),T=(0,i.useMemo)(()=>{let e={};for(let t of M){let n=1/0,l=-1/0;for(let e of E){let i=Z(e[t]);void 0!==i&&(n=Math.min(n,i),l=Math.max(l,i))}n!==1/0&&l!==-1/0&&(e[t]={min:n,max:l})}return e},[E,M]),N=(0,i.useMemo)(()=>{let e=[],t=new Set;for(let n of r.columnSettings??[]){if(t.has(n.name))continue;let l=X(n.name,r.columnSettings??[],d,T,r.cellSettings??[]);void 0!==l&&(e.push(l),t.add(n.name))}if(!r.defaultColumnHidden){for(let n of M)if(!t.has(n)){let t=X(n,r.columnSettings??[],d,T,r.cellSettings??[]);void 0!==t&&e.push(t)}}return e},[M,r.columnSettings,r.defaultColumnHidden,d,T,r.cellSettings]),[D,R]=(0,i.useState)([]),V=(0,i.useMemo)(()=>r.enableFiltering&&0!==D.length?E.filter(e=>D.every(t=>{let n=e[t.id],l=t.value;return!l||0===l.length||l.includes(n)})):E,[E,D,r.enableFiltering]),I=(0,i.useMemo)(()=>{var e,t,n;if(void 0===r.cellSettings&&!(null==(e=r.columnSettings)?void 0:e.some(e=>void 0!==e.cellSettings)))return{};let l={},i=0;for(let e of V){for(let[o,a]of Object.entries({...M.reduce((e,t)=>(e[t]=void 0,e),{}),...e})){let e=j(a,r.cellSettings??[]),s=null==(t=r.columnSettings)?void 0:t.find(e=>e.name===o);if(null==s||null==(n=s.cellSettings)?void 0:n.length){let t=j(a,s.cellSettings);t&&(e=t)}e&&(l[`${i}_${o}`]=e)}i++}return l},[V,M,r.cellSettings,r.columnSettings]),[L,F]=(0,i.useState)((null==(n=r.columnSettings)?void 0:n.filter(e=>void 0!==e.sort).map(e=>({id:e.name,desc:"desc"===e.sort})))??[]),[$,H]=(0,i.useState)({}),[W,G]=(0,i.useState)(null);(0,i.useEffect)(()=>{if(!W)return;let e=e=>{let t=e.target;t.closest("[data-filter-dropdown]")||t.closest("button")||(H({}),G(null))},t=setTimeout(()=>{document.addEventListener("click",e)},100);return()=>{clearTimeout(t),document.removeEventListener("click",e)}},[W]),y.current=V;let[B,q]=(0,i.useState)(r.pagination?{pageIndex:0,pageSize:10}:void 0);return((0,i.useEffect)(()=>{r.pagination&&!B?q({pageIndex:0,pageSize:10}):!r.pagination&&B&&q(void 0)},[r.pagination,B]),void 0===o)?null:(null==E?void 0:E.length)?(0,l.jsxs)(l.Fragment,{children:[b,r.enableFiltering&&(0,l.jsx)("div",{style:{display:"flex",background:s.palette.background.default,borderBottom:`1px solid ${s.palette.divider}`,width:o.width,boxSizing:"border-box"},children:N.map((e,t)=>{var n;let i,o=(n=e.accessorKey,(i=D.find(e=>e.id===n))?i.value:[]),a=e.width||r.defaultColumnWidth;return(0,l.jsxs)("div",{style:{padding:"8px",borderRight:t<N.length-1?`1px solid ${s.palette.divider}`:"none",width:a,minWidth:a,maxWidth:a,display:"flex",alignItems:"center",position:"relative",boxSizing:"border-box",flex:"number"==typeof a?"none":"1 1 auto"},children:[(0,l.jsx)("span",{style:{marginRight:8,fontSize:"12px",color:s.palette.text.secondary,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:o.length?`${o.length} items`:"All"}),(0,l.jsx)("button",{onClick:t=>{var n;n=e.accessorKey,t.preventDefault(),t.stopPropagation(),H({...$,[n]:t.currentTarget}),G(n)},style:{border:`1px solid ${s.palette.divider}`,background:s.palette.background.paper,cursor:"pointer",fontSize:"12px",color:o.length?s.palette.primary.main:s.palette.text.secondary,padding:"4px 8px",borderRadius:"4px",minWidth:"20px",height:"24px",flexShrink:0,transition:"all 0.2s ease"},onMouseEnter:e=>{e.currentTarget.style.background=s.palette.action.hover},onMouseLeave:e=>{e.currentTarget.style.background=s.palette.background.paper},type:"button",children:"▼"}),W===e.accessorKey&&(0,l.jsx)("div",{style:{position:"absolute",top:"100%",left:0,zIndex:1e3,marginTop:4},children:(0,l.jsx)(Y,{allValues:z[e.accessorKey]||[],selectedValues:o,onFilterChange:t=>{var n;let l;return n=e.accessorKey,l=D.filter(e=>e.id!==n),void(t.length>0&&l.push({id:n,value:t}),R(l))},theme:s})})]},`filter-${t}`)})}),(0,l.jsx)(f.Table,{data:V,columns:N,cellConfigs:I,height:r.enableFiltering?o.height-40:o.height,width:o.width,density:r.density,defaultColumnWidth:r.defaultColumnWidth,defaultColumnHeight:r.defaultColumnHeight,sorting:L,onSortingChange:F,pagination:B,onPaginationChange:q,checkboxSelection:c,rowSelection:A,onRowSelectionChange:k,getItemActions:e=>{let{id:t,data:n}=e;return v({id:t,data:n})},hasItemActions:C&&C.length>0})]}):(0,l.jsx)(U.A,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"100%"},children:(0,l.jsx)(u.A,{children:"No data"})})},supportedQueryTypes:["TimeSeriesQuery"],queryOptions:function(e){return{mode:B(e)}},panelOptionsEditorComponents:[{label:"General Settings",content:function(e){let{onChange:t,value:n}=e;return(0,l.jsx)(f.OptionsEditorGrid,{children:(0,l.jsx)(f.OptionsEditorColumn,{children:(0,l.jsxs)(f.OptionsEditorGroup,{title:"Display",children:[(0,l.jsx)(f.DensitySelector,{value:n.density,onChange:function(e){t({...n,density:e})}}),(0,l.jsx)(f.OptionsEditorControl,{label:"Pagination",control:(0,l.jsx)(A.A,{checked:!!n.pagination,onChange:function(e,l){t({...n,pagination:l})}})}),(0,l.jsx)(f.OptionsEditorControl,{label:"Columns Hidden by Default",control:(0,l.jsx)(A.A,{checked:!!n.defaultColumnHidden,onChange:function(e,l){t({...n,defaultColumnHidden:l})}})}),(0,l.jsx)(f.OptionsEditorControl,{label:"Enable Column Filtering",control:(0,l.jsx)(A.A,{checked:!!n.enableFiltering,onChange:function(e,l){t({...n,enableFiltering:l})}})}),(0,l.jsx)(ee,{label:"Width",defaultValue:f.DEFAULT_COLUMN_WIDTH,value:n.defaultColumnWidth,onChange:function(e){t({...n,defaultColumnWidth:e})}}),(0,l.jsx)(ee,{label:"Height",defaultValue:f.DEFAULT_COLUMN_HEIGHT,value:n.defaultColumnHeight,onChange:function(e){t({...n,defaultColumnHeight:e})}})]})})})}},{label:"Column Settings",content:function(e){let{onChange:t,value:n}=e;return(0,l.jsx)(H,{columnSettings:n.columnSettings??[],onChange:function(e){t({...n,columnSettings:e})}})}},{label:"Cell Settings",content:function(e){let{onChange:t,value:n}=e;return(0,l.jsx)(y,{cellSettings:n.cellSettings??[],onChange:function(e){t({...n,cellSettings:e})}})}},{label:"Transforms",content:function(e){let{value:t,onChange:n}=e;return(0,l.jsx)(f.TransformsEditor,{value:t.transforms??[],onChange:function(e){n({...t,transforms:e})}})}},{label:"Item Actions",content:function(e){let{value:t,onChange:n}=e;return(0,l.jsx)(S.ItemSelectionActionsEditor,{actionOptions:t.actions,onChangeActions:function(e){n({...t,actions:e})},selectionOptions:t.selection,onChangeSelection:function(e){n({...t,selection:e})}})}}],createInitialOptions:function(){return{density:"standard",enableFiltering:!0}},actions:[{component:e=>{let{queryResults:t,spec:n,definition:o}=e,r=(0,i.useMemo)(()=>(function(e,t){let n=K(e,t,{forExport:!0}),l=(0,f.transformData)(n,t.transforms??[]),i=[];for(let e of l)for(let t of Object.keys(e))i.includes(t)||i.push(t);let o=t.columnSettings??[],r=[],a=new Set;for(let e of o)!a.has(e.name)&&(a.add(e.name),e.hide||r.push({key:e.name,header:e.header??e.name}));if(!t.defaultColumnHidden)for(let e of i)a.has(e)||r.push({key:e,header:e});return{data:l,columns:r}})(t,n),[t,n]),a=r.data.length>0&&r.columns.length>0,s=(0,i.useCallback)(()=>{if(a)try{var e,t;let n=(null==o||null==(t=o.spec)||null==(e=t.display)?void 0:e.name)||"Table Data",{data:l,columns:i}=r,a=i.map(e=>(0,S.escapeCsvValue)(e.header)).join(","),s=l.map(e=>i.map(t=>(0,S.escapeCsvValue)(e[t.key])).join(",")),d=[a,...s].join("\n")+"\n",u=new Blob([d],{type:"text/csv;charset=utf-8"}),c=(0,S.sanitizeFilename)(n),h=`${c}_data.csv`,p=URL.createObjectURL(u);try{let e=document.createElement("a");e.href=p,e.download=h,document.body.appendChild(e),e.click(),document.body.removeChild(e)}finally{URL.revokeObjectURL(p)}}catch(e){console.error("Table CSV export failed:",e)}},[a,r,o]);return a?(0,l.jsx)(f.InfoTooltip,{description:"Export as CSV",children:(0,l.jsx)(c.A,{size:"small",onClick:s,"aria-label":"Export table data as CSV",children:(0,l.jsx)(et.default,{fontSize:"inherit"})})}):null},location:"header"}]}}}]);