"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[4215],{14215(A,D,o){o.d(D,{JoinByLabelsTransformerEditor:()=>C});var n=o(74848),y=o(96540),s=o(52358),O=o(33100),P=o(34788),x=o(68763),j=o(72480),_=o(6634),v=o(87748),B=o(75251);function C({input:b,options:e,onChange:f}){const i=(0,y.useMemo)(()=>{let l;const r=(0,B.aG)(b),a=Array.from(r).map(t=>({label:t,value:t}));let d=a.find(t=>t.value===e.value);!d&&e.value&&(d={label:`${e.value} (not found)`,value:e.value},a.push(d)),b.length?r.size===0&&(l=(0,n.jsx)(O.F,{title:(0,s.t)("transformers.join-by-labels-transformer-editor.info.title-no-labels-found","No labels found"),children:(0,n.jsx)(s.x6,{i18nKey:"transformers.join-by-labels-transformer-editor.info.input-contain-labels",children:"The input does not contain any labels"})})):l=(0,n.jsx)(O.F,{title:(0,s.t)("transformers.join-by-labels-transformer-editor.info.title-no-input-found","No input found"),children:(0,n.jsx)(s.x6,{i18nKey:"transformers.join-by-labels-transformer-editor.info.no-input-or-labels-found",children:"No input (or labels) found"})}),r.delete(e.value);const u=Array.from(r).map(t=>({label:t,value:t}));let E=u;const M=!!e.join?.length;let g="Join";return M?E=u.filter(t=>!e.join.includes(t.value)):g=u.map(t=>t.value).join(", "),{warn:l,valueOptions:a,valueOption:d,joinOptions:u,addOptions:E,addText:g,hasJoin:M,key:Date.now()}},[e,b]),T=(l,r)=>{if(!e.join)return;const a=e.join.slice();if(r)a[l]=r;else if(a.splice(l,1),!a.length){f({...e,join:void 0});return}const d=new Set(a);e.value&&d.delete(e.value),f({...e,join:Array.from(d)})},m=l=>{const r=l?.value;if(!r)return;const a=e.join?e.join.slice():[];a.push(r),f({...e,join:a})},c=10,h="No labels found";return(0,n.jsxs)("div",{children:[i.warn,(0,n.jsx)(_.C,{children:(0,n.jsx)(j.I,{error:(0,s.t)("transformers.join-by-labels-transformer-editor.error-required","Required"),invalid:!e.value?.length,label:(0,s.t)("transformers.join-by-labels-transformer-editor.label-value","Value"),labelWidth:c,tooltip:(0,s.t)("transformers.join-by-labels-transformer-editor.tooltip-select-label-indicating-values","Select the label indicating the values name"),children:(0,n.jsx)(v.l6,{options:i.valueOptions,value:i.valueOption,onChange:l=>f({...e,value:l.value}),noOptionsMessage:h})})}),i.hasJoin?e.join.map((l,r)=>(0,n.jsx)(_.C,{children:(0,n.jsx)(j.I,{label:(0,s.t)("transformers.join-by-labels-transformer-editor.label-join","Join"),labelWidth:c,error:"Unable to join by the value label",invalid:l===e.value,children:(0,n.jsxs)(x.B,{children:[(0,n.jsx)(v.l6,{options:i.joinOptions,value:i.joinOptions.find(a=>a.value===l),isClearable:!0,onChange:a=>T(r,a?.value),noOptionsMessage:h}),!!(i.addOptions.length&&r===e.join.length-1)&&(0,n.jsx)(P.i,{icon:"plus",label:"",options:i.addOptions,onChange:m,variant:"secondary"})]})})},l+r)):(0,n.jsx)(n.Fragment,{children:!!i.addOptions.length&&(0,n.jsx)(_.C,{children:(0,n.jsx)(j.I,{label:(0,s.t)("transformers.join-by-labels-transformer-editor.label-join","Join"),labelWidth:c,children:(0,n.jsx)(v.l6,{options:i.addOptions,placeholder:i.addText,onChange:m,noOptionsMessage:h})})})})]})}}}]);

//# sourceMappingURL=4215.303e1cb833b4c792fa47.js.map