"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[9336],{69336(D,b,l){l.d(b,{extractFieldsTransformerEditor:()=>C});var e=l(74848),t=l(52358),m=l(6634),p=l(72480),I=l(87748),K=l(16244),R=l(78364),P=l(29798),S=l(12592),j=l(22803),T=l(96540),o=l(31944),r=l(45270);function i({options:v,onChange:a}){const[s,E]=(0,T.useState)(v),O=n(),N=d(),A=()=>{s.push({path:""}),E([...s]),g()},J=u=>{s&&(s.splice(u,1),E([...s]),g())},y=(u,x,c)=>{s&&(c==="alias"?s[x].alias=u.currentTarget.value??"":s[x].path=u.currentTarget.value??"",E([...s]))},g=()=>{a(s)};return(0,e.jsxs)("ol",{className:(0,j.cx)(N.list),children:[s&&s.map((u,x)=>(0,e.jsx)("li",{children:(0,e.jsxs)(m.C,{children:[(0,e.jsx)(p.I,{label:(0,t.t)("transformers.jsonpath-editor.label-field","Field"),tooltip:O.field,grow:!0,children:(0,e.jsx)(K.p,{onBlur:g,onChange:c=>y(c,x,"path"),value:u.path,placeholder:(0,t.t)("transformers.jsonpath-editor.placeholder-valid-objectvalue",'A valid json path, e.g. "object.value1" or "object.value2[0]"')})}),(0,e.jsx)(p.I,{label:(0,t.t)("transformers.jsonpath-editor.label-alias","Alias"),tooltip:O.alias,children:(0,e.jsx)(K.p,{width:12,value:u.alias,onBlur:g,onChange:c=>y(c,x,"alias")})}),(0,e.jsx)(p.I,{className:(0,j.cx)(N.removeIcon),children:(0,e.jsx)(o.K,{onClick:()=>J(x),name:"trash-alt",tooltip:(0,t.t)("transformers.jsonpath-editor.tooltip-remove-path","Remove path")})})]})},x)),(0,e.jsx)(p.I,{children:(0,e.jsx)(r.$n,{icon:"plus",onClick:()=>A(),variant:"secondary",children:(0,e.jsx)(t.x6,{i18nKey:"transformers.jsonpath-editor.add-path",children:"Add path"})})})]})}const n=()=>{const v=[{path:"object",description:(0,t.t)("transformers.get-tooltips.map-valid-paths.description.extract-fields-from-object","=> extract fields from object")},{path:"object.value1",description:(0,e.jsxs)(t.x6,{i18nKey:"transformers.get-tooltips.map-valid-paths.description.extract-value",values:{value:"value1"},children:["=> extract ",(0,e.jsx)("code",{children:"{{ value }}"})]})},{path:"object.value2",description:(0,e.jsxs)(t.x6,{i18nKey:"transformers.get-tooltips.map-valid-paths.description.extract-value",values:{value:"value2"},children:["=> extract ",(0,e.jsx)("code",{children:"{{ value }}"})]})},{path:"object.value2[0]",description:(0,e.jsxs)(t.x6,{i18nKey:"transformers.get-tooltips.map-valid-paths.description.extract-value-first-element",values:{value:"value2"},children:["=> extract ",(0,e.jsx)("code",{children:"{{ value }}"})," first element"]})},{path:"object.value2[1]",description:(0,e.jsxs)(t.x6,{i18nKey:"transformers.get-tooltips.map-valid-paths.description.extract-value-second-element",values:{value:"value2"},children:["=> extract ",(0,e.jsx)("code",{children:"{{ value }}"})," second element"]})}];return{field:(0,e.jsxs)("div",{children:[(0,e.jsx)(t.x6,{i18nKey:"transformers.get-tooltips.description",children:"A valid path of an json object."}),(0,e.jsx)("div",{children:(0,e.jsx)("strong",{children:(0,e.jsx)(t.x6,{i18nKey:"transformers.get-tooltips.json-value",children:"JSON Value:"})})}),(0,e.jsx)("pre",{children:(0,e.jsx)("code",{children:["{",'  "object": {','    "value1": "hello world"','    "value2": [1, 2, 3, 4]',"  }","}"].join(`
`)})}),(0,e.jsx)("strong",{children:(0,e.jsx)(t.x6,{i18nKey:"transformers.get-tooltips.valid-paths",children:"Valid Paths:"})}),v.map((a,s)=>(0,e.jsxs)("p",{children:[(0,e.jsx)("code",{children:a.path}),(0,e.jsx)("i",{children:a.description})]},s))]}),alias:"An alias name for the variable in the dashboard. If left blank the given path will be used."}};function d(){return{list:(0,j.css)({marginLeft:"20px"}),removeIcon:(0,j.css)({margin:"0 0 0 4px",alignItems:"center"})}}var f=l(9868),h=l(64032);const C=({input:v,options:a={delimiter:","},onChange:s})=>{const E={settings:{width:30,placeholderText:(0,t.t)("transformers.extract-fields-transformer-editor.field-name-picker-settings.placeholderText.select-field","Select field")},name:"",id:"",editor:()=>null},O=c=>{s({...a,source:c})},N=c=>{s({...a,format:c?.value})},A=c=>{s({...a,jsonPaths:c})},J=c=>{s({...a,regExp:c.target.value})},y=c=>{s({...a,delimiter:c.value})},g=()=>{a.replace&&(a.keepTime=!1),s({...a,replace:!a.replace})},u=()=>{s({...a,keepTime:!a.keepTime})},x=f.S.selectOptions(a.format?[a.format]:void 0);return(0,e.jsxs)("div",{children:[(0,e.jsx)(m.C,{children:(0,e.jsx)(p.I,{label:(0,t.t)("transformers.extract-fields-transformer-editor.label-source","Source"),labelWidth:16,children:(0,e.jsx)(S.O,{context:{data:v},value:a.source??"",onChange:O,item:E})})}),(0,e.jsx)(m.C,{children:(0,e.jsx)(p.I,{label:(0,t.t)("transformers.extract-fields-transformer-editor.label-format","Format"),labelWidth:16,children:(0,e.jsx)(I.l6,{value:x.current[0],options:x.options,onChange:N,width:24,placeholder:(0,t.t)("transformers.extract-fields-transformer-editor.placeholder-auto","Auto")})})}),a.format===h.K.RegExp&&(0,e.jsx)(m.C,{children:(0,e.jsx)(p.I,{label:"RegExp",labelWidth:16,interactive:!0,tooltip:(0,t.t)("transformers.extract-fields-transformer-editor.tooltip-regexp","Example: {{regexExample}}",{regexExample:"/(?<NewField>.*)/",interpolation:{escapeValue:!1}}),children:(0,e.jsx)(K.p,{placeholder:"/(?<NewField>.*)/",value:a.regExp,onChange:J})})}),a.format===h.K.JSON&&(0,e.jsx)(i,{options:a.jsonPaths??[],onChange:A}),a.format===h.K.Delimiter&&(0,e.jsx)(m.C,{children:(0,e.jsx)(p.I,{label:(0,t.t)("transformers.extract-fields-transformer-editor.label-delimiter","Delimiter"),labelWidth:16,children:(0,e.jsx)(R.G,{value:a.delimiter,options:[{value:","},{value:";"},{value:"|"}],onChange:y,placeholder:(0,t.t)("transformers.extract-fields-transformer-editor.placeholder-select-delimiter","Select delimiter..."),width:24})})}),(0,e.jsx)(m.C,{children:(0,e.jsx)(p.I,{label:(0,t.t)("transformers.extract-fields-transformer-editor.label-replace-all-fields","Replace all fields"),labelWidth:16,children:(0,e.jsx)(P.K,{value:a.replace??!1,onChange:g})})}),a.replace&&(0,e.jsx)(m.C,{children:(0,e.jsx)(p.I,{label:(0,t.t)("transformers.extract-fields-transformer-editor.label-keep-time","Keep time"),labelWidth:16,children:(0,e.jsx)(P.K,{value:a.keepTime??!1,onChange:u})})})]})}},9868(D,b,l){l.d(b,{S:()=>T});var e=l(85453),t=l(11011),m=l(64032);const p={id:m.K.JSON,name:"JSON",description:"Parse JSON string",getParser:o=>r=>JSON.parse(r)},I={id:m.K.RegExp,name:"RegExp",description:"Parse with RegExp",getParser:o=>{let r=/(?<NewField>.*)/;if((0,e.AP)(o.regExp))try{r=(0,e.dO)(o.regExp)}catch(i){i instanceof Error&&console.warn(i.message)}return i=>i.match(r)?.groups}};function K(o){const r=[];let i="",n="";const d={};for(let f=0;f<o.length;f++){let h=o[f];h===i&&(i="",h=o[++f]);const C=h==="\\";if(C&&(h=o[++f]),C||i.length){r.push(h);continue}switch((h==='"'||h==="'")&&(i=h),h){case":":case"=":r.length&&(n&&(d[n]=""),n=r.join(""),r.length=0);break;case'"':case"'":case" ":case"	":case"\r":case`
`:r.length&&n===""&&(d[r.join("")]="",r.length=0);case",":case";":case"&":case"{":case"}":if(r.length){const v=r.join("");n.length?(d[n]=v,n=""):n=v,r.length=0}break;default:r.push(h),f===o.length-1&&n===""&&r.length&&(d[r.join("")]="",r.length=0)}}return n.length&&(d[n]=r.join("")),d}const R={id:m.K.KeyValues,name:"Key+value pairs",description:"Look for a=b, c: d values in the line",getParser:o=>K},P={id:m.K.Delimiter,name:"Split by delimiter",description:"Splits at delimited values, such as commas",getParser:({delimiter:o=","})=>{const r=new RegExp(`\\s*${(0,e.jD)(o)}\\s*`,"g");return i=>{const n=i.trim().split(r),d={};for(const f of n)d[f]=1;return d}}},S=[p,R,P,I],j={id:m.K.Auto,name:"Auto",description:"parse new fields automatically",getParser:o=>{const r=S.map(i=>i.getParser(o));return i=>{for(const n of r)try{const d=n(i);if(d!=null)return d}catch{}}}},T=new t.O(()=>[...S,j])},64032(D,b,l){l.d(b,{K:()=>e});var e=(t=>(t.JSON="json",t.KeyValues="kvp",t.Auto="auto",t.RegExp="regexp",t.Delimiter="delimiter",t))(e||{})}}]);

//# sourceMappingURL=9336.53f0637988dfbf8dda3a.js.map