"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[2651],{42509:(e,t,n)=>{n.r(t),n.d(t,{default:()=>U});var a=n(68404),l=n(6932),s=n(1652),r=n(90894),i=n(93970),o=n(11979),c=n(63672),u=n(25049),d=n(84719),h=n(40920),p=n(14024),v=n(58257),g=n(45916);const x=[{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 j(e){let{onRuleAdded:t}=e;const[n,r]=(0,a.useState)(),[i,j]=(0,a.useState)(),[m,y]=(0,a.useState)(""),[f,C]=(0,a.useState)(),b=(0,v.iG)(),S=()=>{i?"ds"!==n||m.length?(0,l.i)().post("api/live/channel-rules",{pattern:m+i,settings:{converter:{type:"jsonAuto"},frameOutputs:[{type:"managedStream"}]}}).then((e=>{console.log("ADDED",e),j(void 0),r(void 0),t(e.rule)})).catch((e=>{b.error("Error adding rule",e),e.isHandled=!0})):b.error("Select datasource"):b.error("Enter path")};return n?(0,g.jsx)("div",{children:(0,g.jsxs)(u.Lh,{children:["any"===n&&(0,g.jsx)(d.g,{label:"Pattern",children:(0,g.jsx)(s.I,{value:null!=i?i:"",onChange:e=>j(e.currentTarget.value),placeholder:"scope/namespace/path"})}),"ds"===n&&(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(d.g,{label:"Data source",children:(0,g.jsx)(c.q,{current:f,onChange:e=>{C(e),y(`${o.z.DataSource}/${e.uid}/`)}})}),(0,g.jsx)(d.g,{label:"Path",children:(0,g.jsx)(s.I,{value:null!=i?i:"",onChange:e=>j(e.currentTarget.value),placeholder:"path"})})]}),(0,g.jsx)(d.g,{label:"",children:(0,g.jsx)(h.zx,{onClick:S,variant:null!=i&&i.length?"primary":"secondary",children:"Add"})}),(0,g.jsx)(d.g,{label:"",children:(0,g.jsx)(h.zx,{variant:"secondary",onClick:()=>r(void 0),children:"Cancel"})})]})}):(0,g.jsx)("div",{children:(0,g.jsx)(p.b,{label:"Add channel rule",variant:"secondary",size:"md",icon:"plus",menuPlacement:"auto",isFullWidth:!1,options:x,onChange:e=>r(e.value)})})}var m=n(27549),y=n(74410),f=n(9617),C=n(85965),b=n(67436),S=n(59385),O=n(83971),T=n(22583),w=n(9991),k=n(2563),N=n(38465);const P=e=>{var t;let{onChange:n,value:a,ruleType:l,entitiesInfo:s}=e;return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(k.Ph,{options:s[l],placeholder:"Select an option",value:null!==(t=null==a?void 0:a.type)&&void 0!==t?t:"",onChange:e=>{const t=e.value;n({type:t,[t]:s.getExample(l,t)})}},l),(0,g.jsx)(N.p,{height:"50vh",value:a?JSON.stringify(a[a.type],null,"\t"):"",showLineNumbers:!0,readOnly:!1,language:"json",showMiniMap:!1,onBlur:e=>{const t=JSON.parse(e);n({type:a.type,[a.type]:t})}})]})},I=e=>{let{onChange:t,value:n,ruleType:l,entitiesInfo:s}=e;const[r,i]=(0,a.useState)(0),o=null!=n?n:[];let c=[];for(let e=0;e<=o.length;e++)c.push({label:`${l}: ${e}`,value:e});return(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(k.Ph,{placeholder:"Select an index",options:c,value:r,onChange:e=>{i(e.value)}}),(0,g.jsx)(P,{onChange:e=>{if(n){const a=[...n];a[r]=e,t(a)}else t([e])},value:o[r],ruleType:l,entitiesInfo:s})]})};var A=n(83044),E=n(14488),R=n(48147),D=n(13261);const M=e=>{const[t,n]=(0,a.useState)(),[s,r]=(0,a.useState)(),i=(0,f.yK)(z);return(0,g.jsxs)("div",{children:[(0,g.jsx)(N.p,{height:100,value:"",showLineNumbers:!0,readOnly:!1,language:"json",showMiniMap:!1,onBlur:e=>{r(e)}}),(0,g.jsx)(h.zx,{onClick:()=>{(0,l.i)().post("api/live/pipeline-convert-test",{channelRules:[e.rule],channel:e.rule.pattern,data:s}).then((e=>{const t=e.channelFrames;t&&n(t.map((e=>{const t=(0,A.vP)(e.frame);for(const e of t.fields)e.display=(0,E.U)({field:e,theme:R.v.theme2});return{channel:e.channel,frame:t}})))})).catch((e=>{n(e)}))},className:i.margin,children:"Test"}),(null==t?void 0:t.length)&&t.map((e=>(0,g.jsx)(d.g,{label:e.channel,children:(0,g.jsx)(D.i,{data:e.frame,width:700,height:Math.min(10*e.frame.length+10,150),showTypeIcons:!0})},e.channel)))]})},z=e=>({margin:m.css`
      margin-bottom: 15px;
    `});function F(e,t){return Array.isArray(e)?e.map((e=>({label:e[t],value:e[t]}))):e[t].map((e=>({label:e.type,value:e.type})))}const J=[{label:"Converter",type:"converter",isConverter:!0},{label:"Processors",type:"frameProcessors"},{label:"Outputs",type:"frameOutputs"},{label:"Test",isTest:!0,icon:"flask"}],L=e=>{var t;const{isOpen:n,onClose:s,clickColumn:r}=e,[i,o]=(0,a.useState)(e.rule),[c,u]=(0,a.useState)(J.find((e=>e.type===r))),[d,p]=(0,a.useState)(!1),[v,x]=(0,a.useState)(null!=c&&c.type?null==i||null===(t=i.settings)||void 0===t?void 0:t[c.type]:void 0),[j,m]=(0,a.useState)(),y=(0,f.yK)($),C=e=>{p(!0),null!=c&&c.type&&o(Object.assign({},i,{settings:Object.assign({},i.settings,{[null==c?void 0:c.type]:e})})),x(e)};(0,a.useMemo)((()=>{(async function(){return await(0,l.i)().get("api/live/pipeline-entities").then((e=>({converter:F(e,"converters"),frameProcessors:F(e,"frameProcessors"),frameOutputs:F(e,"frameOutputs"),getExample:(t,n)=>{var a,l,s;return null===(a=e[`${t}s`])||void 0===a||null===(l=a.filter((e=>e.type===n)))||void 0===l||null===(s=l[0])||void 0===s?void 0:s.example}})))})().then((e=>{m(e)}))}),[]);return(0,g.jsxs)(S.u,{isOpen:n,title:i.pattern,onDismiss:s,closeOnEscape:!0,children:[(0,g.jsx)(O.J,{children:J.map(((e,t)=>(0,g.jsx)(T.O,{label:e.label,active:e===c,icon:e.icon,onChangeTab:()=>{var t;(u(e),e.type)&&x(null==i||null===(t=i.settings)||void 0===t?void 0:t[e.type])}},t)))}),(0,g.jsxs)(w.I,{children:[j&&i&&c&&(0,g.jsxs)(g.Fragment,{children:[(null==c?void 0:c.isTest)&&(0,g.jsx)(M,{rule:i}),c.isConverter&&(0,g.jsx)(P,{onChange:C,value:v,ruleType:"converter",entitiesInfo:j}),!c.isConverter&&c.type&&(0,g.jsx)(I,{onChange:C,value:v,ruleType:c.type,entitiesInfo:j})]}),(0,g.jsx)(h.zx,{onClick:()=>{(0,l.i)().put("api/live/channel-rules",i).then((()=>{p(!1),s()})).catch((e=>console.error(e)))},className:y.save,variant:d?"primary":"secondary",children:"Save"})]})]})},$=e=>({save:m.css`
      margin-top: 5px;
    `});var K,q,B,G;function V(e,t){return null!=t&&t.type?(0,g.jsx)(y.V,{name:t.type},e):null}const W=e=>{const{rules:t}=e,[n,s]=(0,a.useState)(!1),[r,i]=(0,a.useState)(),[o,c]=(0,a.useState)("converter"),u=(0,f.yK)(H),d=(e,t)=>{var n;if(!e)return;let a=null==t||null===(n=t.target)||void 0===n?void 0:n.getAttribute("data-column");a&&"pattern"!==a||(a="converter"),c(a),i(e),s(!0)};(0,a.useEffect)((()=>{e.selectRule&&d(e.selectRule)}),[e.selectRule]);const h=e=>{if(e.startsWith("ds/")){const t=e.indexOf("/",4);if(t>3){const n=e.substring(3,t),a=(0,b.ak)().getInstanceSettings(n);if(a)return(0,g.jsxs)("div",{children:[(0,g.jsx)(y.V,{name:a.name,colorIndex:1}),"  ",(0,g.jsx)("span",{children:e.substring(t+1)})]})}}return e};return(0,g.jsxs)("div",{children:[(0,g.jsx)("div",{className:"admin-list-table",children:(0,g.jsxs)("table",{className:"filter-table filter-table--hover form-inline",children:[(0,g.jsx)("thead",{children:(0,g.jsxs)("tr",{children:[K||(K=(0,g.jsx)("th",{children:"Channel"})),q||(q=(0,g.jsx)("th",{children:"Converter"})),B||(B=(0,g.jsx)("th",{children:"Processor"})),G||(G=(0,g.jsx)("th",{children:"Output"})),(0,g.jsx)("th",{style:{width:10},children:" "})]})}),(0,g.jsx)("tbody",{children:t.map((t=>{var n,a,s,r,i,o;return(0,g.jsxs)("tr",{onClick:e=>d(t,e),className:u.row,children:[(0,g.jsx)("td",{"data-pattern":t.pattern,"data-column":"pattern",children:h(t.pattern)}),(0,g.jsx)("td",{"data-pattern":t.pattern,"data-column":"converter",children:null===(n=t.settings)||void 0===n||null===(a=n.converter)||void 0===a?void 0:a.type}),(0,g.jsx)("td",{"data-pattern":t.pattern,"data-column":"processor",children:null===(s=t.settings)||void 0===s||null===(r=s.frameProcessors)||void 0===r?void 0:r.map((e=>(0,g.jsx)("span",{children:e.type},t.pattern+e.type)))}),(0,g.jsx)("td",{"data-pattern":t.pattern,"data-column":"output",children:null===(i=t.settings)||void 0===i||null===(o=i.frameOutputs)||void 0===o?void 0:o.map((e=>(0,g.jsx)("span",{children:V("out",e)},t.pattern+e.type)))}),(0,g.jsx)("td",{children:(0,g.jsx)(C.h,{name:"trash-alt",onClick:n=>{var a;n.stopPropagation(),a=t.pattern,(0,l.i)().delete("api/live/channel-rules",JSON.stringify({pattern:a})).catch((e=>console.error(e))).finally((()=>{e.onRuleChanged()}))}})})]},t.pattern)}))})]})}),n&&r&&(0,g.jsx)(L,{rule:r,isOpen:n,onClose:()=>{s(!1)},clickColumn:o})]})},H=e=>({row:m.css`
      cursor: pointer;
    `});function U(){const[e,t]=(0,a.useState)([]),[n,o]=(0,a.useState)([]),[c,u]=(0,a.useState)(),d=(0,i.q)("live-pipeline"),[h,p]=(0,a.useState)(),v=()=>{(0,l.i)().get("api/live/channel-rules").then((e=>{var n,a;t(null!==(n=e.rules)&&void 0!==n?n:[]),o(null!==(a=e.rules)&&void 0!==a?a:[])})).catch((e=>{e.data&&p(JSON.stringify(e.data,null,2))}))};(0,a.useEffect)((()=>{v()}),[]);return(0,g.jsx)(r.T,{navModel:d,children:(0,g.jsxs)(r.T.Contents,{children:[h&&(0,g.jsx)("pre",{children:h}),(0,g.jsx)("div",{className:"page-action-bar",children:(0,g.jsx)("div",{className:"gf-form gf-form--grow",children:(0,g.jsx)(s.I,{placeholder:"Search pattern...",onChange:a=>{a.target.value?t(e.filter((e=>e.pattern.toLowerCase().includes(a.target.value.toLowerCase())))):t(n)}})})}),(0,g.jsx)(W,{rules:e,onRuleChanged:v,selectRule:c}),(0,g.jsx)(j,{onRuleAdded:t=>{console.log("GOT",t,"vs",e[0]),u(t),v()}})]})})}}}]);
//# sourceMappingURL=PipelineAdminPage.b5bac156347076da78c2.js.map