"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[2651],{44654:(oe,T,r)=>{r.r(T),r.d(T,{default:()=>le});var e=r(68404),f=r(54899),S=r(46967),O=r(79396),I=r(76770),M=r(62626),F=r(53117),L=r(52081),E=r(24799),C=r(31403),z=r(15670),J=r(60499);const B=[{label:"Data source",description:"Configure a channel scoped to a data source instance",value:"ds"},{label:"Any",description:"Enter an arbitray channel pattern",value:"any"}];function $({onRuleAdded:a}){const[n,l]=(0,e.useState)(),[u,s]=(0,e.useState)(),[d,i]=(0,e.useState)(""),[m,h]=(0,e.useState)(),o=(0,J.iG)(),v=()=>{if(!u){o.error("Enter path");return}if(n==="ds"&&!d.length){o.error("Select datasource");return}(0,f.i)().post("api/live/channel-rules",{pattern:d+u,settings:{converter:{type:"jsonAuto"},frameOutputs:[{type:"managedStream"}]}}).then(t=>{console.log("ADDED",t),s(void 0),l(void 0),a(t.rule)}).catch(t=>{o.error("Error adding rule",t),t.isHandled=!0})};return n?e.createElement("div",null,e.createElement(L.Lh,null,n==="any"&&e.createElement(E.g,{label:"Pattern"},e.createElement(S.I,{value:u??"",onChange:t=>s(t.currentTarget.value),placeholder:"scope/namespace/path"})),n==="ds"&&e.createElement(e.Fragment,null,e.createElement(E.g,{label:"Data source"},e.createElement(F.q,{current:m,onChange:t=>{h(t),i(`${M.z.DataSource}/${t.uid}/`)}})),e.createElement(E.g,{label:"Path"},e.createElement(S.I,{value:u??"",onChange:t=>s(t.currentTarget.value),placeholder:"path"}))),e.createElement(E.g,{label:""},e.createElement(C.zx,{onClick:v,variant:u?.length?"primary":"secondary"},"Add")),e.createElement(E.g,{label:""},e.createElement(C.zx,{variant:"secondary",onClick:()=>l(void 0)},"Cancel")))):e.createElement("div",null,e.createElement(z.b,{label:"Add channel rule",variant:"secondary",size:"md",icon:"plus",menuPlacement:"auto",isFullWidth:!1,options:B,onChange:t=>l(t.value)}))}var R=r(52423),x=r(34719),V=r(8180),j=r(91162),G=r(35029),W=r(72142),H=r(79841),Q=r(94893),N=r(53217),A=r(9405);const b=({onChange:a,value:n,ruleType:l,entitiesInfo:u})=>e.createElement(e.Fragment,null,e.createElement(N.Ph,{key:l,options:u[l],placeholder:"Select an option",value:n?.type??"",onChange:s=>{const d=s.value;a({type:d,[d]:u.getExample(l,d)})}}),e.createElement(A.p,{height:"50vh",value:n?JSON.stringify(n[n.type],null,"	"):"",showLineNumbers:!0,readOnly:!1,language:"json",showMiniMap:!1,onBlur:s=>{const d=JSON.parse(s);a({type:n.type,[n.type]:d})}})),U=({onChange:a,value:n,ruleType:l,entitiesInfo:u})=>{const[s,d]=(0,e.useState)(0),i=n??[],m=o=>{if(!n)a([o]);else{const v=[...n];v[s]=o,a(v)}};let h=[];for(let o=0;o<=i.length;o++)h.push({label:`${l}: ${o}`,value:o});return e.createElement(e.Fragment,null,e.createElement(N.Ph,{placeholder:"Select an index",options:h,value:s,onChange:o=>{d(o.value)}}),e.createElement(b,{onChange:m,value:i[s],ruleType:l,entitiesInfo:u}))};var K=r(70006),X=r(36512),Y=r(35645),Z=r(88144);const k=a=>{const[n,l]=(0,e.useState)(),[u,s]=(0,e.useState)(),d=m=>{s(m)},i=()=>{(0,f.i)().post("api/live/pipeline-convert-test",{channelRules:[a.rule],channel:a.rule.pattern,data:u}).then(m=>{const h=m.channelFrames;h&&l(h.map(o=>{const v=(0,K.vP)(o.frame);for(const t of v.fields)t.display=(0,X.U)({field:t,theme:Y.v.theme2});return{channel:o.channel,frame:v}}))}).catch(m=>{l(m)})};return e.createElement("div",null,e.createElement(A.p,{height:100,value:"",showLineNumbers:!0,readOnly:!1,language:"json",showMiniMap:!1,onBlur:d}),e.createElement(C.zx,{onClick:i,className:w.margin},"Test"),n?.length&&n.map(m=>e.createElement(E.g,{key:m.channel,label:m.channel},e.createElement(Z.i,{data:m.frame,width:700,height:Math.min(10*m.frame.length+10,150),showTypeIcons:!0}))))},w={margin:R.css`
    margin-bottom: 15px;
  `};async function q(){return await(0,f.i)().get("api/live/pipeline-entities").then(a=>({converter:P(a,"converters"),frameProcessors:P(a,"frameProcessors"),frameOutputs:P(a,"frameOutputs"),getExample:(n,l)=>a[`${n}s`]?.filter(u=>u.type===l)?.[0]?.example}))}function P(a,n){return Array.isArray(a)?a.map(l=>({label:l[n],value:l[n]})):a[n].map(l=>({label:l.type,value:l.type}))}const D=[{label:"Converter",type:"converter",isConverter:!0},{label:"Processors",type:"frameProcessors"},{label:"Outputs",type:"frameOutputs"},{label:"Test",isTest:!0,icon:"flask"}],_=a=>{const{isOpen:n,onClose:l,clickColumn:u}=a,[s,d]=(0,e.useState)(a.rule),[i,m]=(0,e.useState)(D.find(p=>p.type===u)),[h,o]=(0,e.useState)(!1),[v,t]=(0,e.useState)(i?.type?s?.settings?.[i.type]:void 0),[c,g]=(0,e.useState)(),y=p=>{o(!0),i?.type&&d({...s,settings:{...s.settings,[i?.type]:p}}),t(p)};(0,e.useMemo)(()=>{q().then(p=>{g(p)})},[]);const re=()=>{(0,f.i)().put("api/live/channel-rules",s).then(()=>{o(!1),l()}).catch(p=>console.error(p))};return e.createElement(G.u,{isOpen:n,title:s.pattern,onDismiss:l,closeOnEscape:!0},e.createElement(W.J,null,D.map((p,se)=>e.createElement(H.O,{key:se,label:p.label,active:p===i,icon:p.icon,onChangeTab:()=>{m(p),p.type&&t(s?.settings?.[p.type])}}))),e.createElement(Q.I,null,c&&s&&i&&e.createElement(e.Fragment,null,i?.isTest&&e.createElement(k,{rule:s}),i.isConverter&&e.createElement(b,{onChange:y,value:v,ruleType:"converter",entitiesInfo:c}),!i.isConverter&&i.type&&e.createElement(U,{onChange:y,value:v,ruleType:i.type,entitiesInfo:c})),e.createElement(C.zx,{onClick:re,className:ee.save,variant:h?"primary":"secondary"},"Save")))},ee={save:R.css`
    margin-top: 5px;
  `};function te(a,n){return n?.type?e.createElement(x.V,{key:a,name:n.type}):null}const ne=a=>{const{rules:n}=a,[l,u]=(0,e.useState)(!1),[s,d]=(0,e.useState)(),[i,m]=(0,e.useState)("converter"),h=(t,c)=>{if(!t)return;let g=c?.target?.getAttribute("data-column");(!g||g==="pattern")&&(g="converter"),m(g),d(t),u(!0)};(0,e.useEffect)(()=>{a.selectRule&&h(a.selectRule)},[a.selectRule]);const o=t=>{(0,f.i)().delete("api/live/channel-rules",JSON.stringify({pattern:t})).catch(c=>console.error(c)).finally(()=>{a.onRuleChanged()})},v=t=>{if(t.startsWith("ds/")){const c=t.indexOf("/",4);if(c>3){const g=t.substring(3,c),y=(0,j.ak)().getInstanceSettings(g);if(y)return e.createElement("div",null,e.createElement(x.V,{name:y.name,colorIndex:1})," \xA0",e.createElement("span",null,t.substring(c+1)))}}return t};return e.createElement("div",null,e.createElement("div",{className:"admin-list-table"},e.createElement("table",{className:"filter-table filter-table--hover form-inline"},e.createElement("thead",null,e.createElement("tr",null,e.createElement("th",null,"Channel"),e.createElement("th",null,"Converter"),e.createElement("th",null,"Processor"),e.createElement("th",null,"Output"),e.createElement("th",{style:{width:10}},"\xA0"))),e.createElement("tbody",null,n.map(t=>e.createElement("tr",{key:t.pattern,onClick:c=>h(t,c),className:ae.row},e.createElement("td",{"data-pattern":t.pattern,"data-column":"pattern"},v(t.pattern)),e.createElement("td",{"data-pattern":t.pattern,"data-column":"converter"},t.settings?.converter?.type),e.createElement("td",{"data-pattern":t.pattern,"data-column":"processor"},t.settings?.frameProcessors?.map(c=>e.createElement("span",{key:t.pattern+c.type},c.type))),e.createElement("td",{"data-pattern":t.pattern,"data-column":"output"},t.settings?.frameOutputs?.map(c=>e.createElement("span",{key:t.pattern+c.type},te("out",c)))),e.createElement("td",null,e.createElement(V.h,{name:"trash-alt",onClick:c=>{c.stopPropagation(),o(t.pattern)}}))))))),l&&s&&e.createElement(_,{rule:s,isOpen:l,onClose:()=>{u(!1)},clickColumn:i}))},ae={row:R.css`
    cursor: pointer;
  `};function le(){const[a,n]=(0,e.useState)([]),[l,u]=(0,e.useState)([]),[s,d]=(0,e.useState)(),i=(0,I.q)("live-pipeline"),[m,h]=(0,e.useState)(),o=()=>{(0,f.i)().get("api/live/channel-rules").then(t=>{n(t.rules??[]),u(t.rules??[])}).catch(t=>{t.data&&h(JSON.stringify(t.data,null,2))})};(0,e.useEffect)(()=>{o()},[]);const v=t=>{t.target.value?n(a.filter(c=>c.pattern.toLowerCase().includes(t.target.value.toLowerCase()))):n(l)};return e.createElement(O.T,{navModel:i},e.createElement(O.T.Contents,null,m&&e.createElement("pre",null,m),e.createElement("div",{className:"page-action-bar"},e.createElement("div",{className:"gf-form gf-form--grow"},e.createElement(S.I,{placeholder:"Search pattern...",onChange:v}))),e.createElement(ne,{rules:a,onRuleChanged:o,selectRule:s}),e.createElement($,{onRuleAdded:t=>{console.log("GOT",t,"vs",a[0]),d(t),o()}})))}}}]);

//# sourceMappingURL=PipelineAdminPage.811a3c438f0e90f12105.js.map