"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[5247],{85247(M,b,s){s.d(b,{FilterByNameTransformerEditor:()=>D});var l=s(74848),g=s(96540),m=s(85453),_=s(72830),h=s(52358),v=s(72396),E=s(81288),f=s(72480),p=s(6634),C=s(87748),O=s(16244),x=s(29798);class D extends g.PureComponent{constructor(r){super(r),this.onFieldToggle=e=>{const{selected:t}=this.state;t.indexOf(e)>-1?this.onChange(t.filter(a=>a!==e)):this.onChange([...t,e])},this.onChange=e=>{const{regex:t,isRegexValid:a}=this.state,n={...this.props.options,include:{names:e}};t&&a&&(n.include=n.include??{},n.include.pattern=t),this.setState({selected:e},()=>{this.props.onChange(n)})},this.onInputBlur=e=>{const{selected:t,regex:a}=this.state;let n=!0;try{a&&(0,m.dO)(a)}catch{n=!1}n?this.props.onChange({...this.props.options,include:{pattern:a}}):this.props.onChange({...this.props.options,include:{names:t}}),this.setState({isRegexValid:n})},this.onVariableChange=e=>{this.props.onChange({...this.props.options,include:{variable:e.value}}),this.setState({variable:e.value})},this.onFromVariableChange=e=>{const t=e.currentTarget.checked;this.props.onChange({...this.props.options,byVariable:t}),this.setState({byVariable:t})},this.state={include:r.options.include?.names||[],regex:r.options.include?.pattern,variable:r.options.include?.variable,byVariable:r.options.byVariable||!1,options:[],variables:[],selected:[],isRegexValid:!0}}componentDidMount(){this.initOptions()}componentDidUpdate(r){this.props.input!==r.input&&this.initOptions()}initOptions(){const{input:r,options:e}=this.props,t=Array.from(e.include?.names??[]),a=(0,v.w)().getVariables().map(i=>({label:"$"+i.name,value:"$"+i.name})),n=[],d={};for(const i of r)for(const o of i.fields){const u=(0,_.Ct)(o,i,r);let c=d[u];c||(c=d[u]={name:u,count:0},n.push(c)),c.count++}if(e.include?.pattern)try{const i=(0,m.dO)(e.include.pattern);for(const o of n)i.test(o.name)&&t.push(o.name)}catch(i){console.error(i)}if(t.length){const i=n.filter(o=>t.includes(o.name));this.setState({options:n,selected:i.map(o=>o.name),variables:a,byVariable:e.byVariable||!1,variable:e.include?.variable,regex:e.include?.pattern})}else this.setState({options:n,selected:n.map(i=>i.name),variables:a,byVariable:e.byVariable||!1,variable:e.include?.variable,regex:e.include?.pattern})}render(){const{options:r,selected:e,isRegexValid:t}=this.state;return(0,l.jsxs)("div",{children:[(0,l.jsx)(p.C,{label:(0,h.t)("transformers.filter-by-name-transformer-editor.label-use-variable","Use variable"),children:(0,l.jsx)(f.I,{label:(0,h.t)("transformers.filter-by-name-transformer-editor.label-from-variable","From variable"),children:(0,l.jsx)(x.K,{value:this.state.byVariable,onChange:this.onFromVariableChange})})}),this.state.byVariable?(0,l.jsx)(p.C,{children:(0,l.jsx)(f.I,{label:(0,h.t)("transformers.filter-by-name-transformer-editor.label-variable","Variable"),children:(0,l.jsx)(C.l6,{value:this.state.variable,onChange:this.onVariableChange,options:this.state.variables||[]})})}):(0,l.jsxs)(p.C,{label:(0,h.t)("transformers.filter-by-name-transformer-editor.label-identifier","Identifier"),children:[(0,l.jsx)(f.I,{label:(0,h.t)("transformers.filter-by-name-transformer-editor.label-identifier","Identifier"),invalid:!t,error:t?void 0:"Invalid pattern",children:(0,l.jsx)(O.p,{placeholder:(0,h.t)("transformers.filter-by-name-transformer-editor.placeholder-regular-expression-pattern","Regular expression pattern"),value:this.state.regex||"",onChange:a=>this.setState({regex:a.currentTarget.value}),onBlur:this.onInputBlur,width:25})}),r.map((a,n)=>{const d=`${a.name}${a.count>1?" ("+a.count+")":""}`,i=e.indexOf(a.name)>-1;return(0,l.jsx)(E.m,{onClick:()=>{this.onFieldToggle(a.name)},label:d,selected:i},`${a.name}/${n}`)})]})]})}}}}]);

//# sourceMappingURL=5247.833e53a3ddc67b9e3907.js.map