"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[2651],{93970:(e,t,n)=>{n.d(t,{q:()=>r});var a=n(18745),l=n(8674);const r=e=>{const t=(0,a.useSelector)((e=>e.navIndex));return(0,l.h)(t,e)}},42509:(e,t,n)=>{n.r(t),n.d(t,{default:()=>N});var a=n(68404),l=n(90923),r=n(69783),s=n(33801),i=n(93970),o=n(43215),c=n(58257),u=n(45916);const d=[{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 p(e){let{onRuleAdded:t}=e;const[n,s]=(0,a.useState)(),[i,p]=(0,a.useState)(),[h,v]=(0,a.useState)(""),[g,x]=(0,a.useState)(),j=(0,c.iG)(),m=()=>{i?"ds"!==n||h.length?(0,l.getBackendSrv)().post("api/live/channel-rules",{pattern:h+i,settings:{converter:{type:"jsonAuto"},frameOutputs:[{type:"managedStream"}]}}).then((e=>{console.log("ADDED",e),p(void 0),s(void 0),t(e.rule)})).catch((e=>{j.error("Error adding rule",e),e.isHandled=!0})):j.error("Select datasource"):j.error("Enter path")};return n?(0,u.jsx)("div",{children:(0,u.jsxs)(r.HorizontalGroup,{children:["any"===n&&(0,u.jsx)(r.Field,{label:"Pattern",children:(0,u.jsx)(r.Input,{value:null!=i?i:"",onChange:e=>p(e.currentTarget.value),placeholder:"scope/namespace/path"})}),"ds"===n&&(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(r.Field,{label:"Data source",children:(0,u.jsx)(l.DataSourcePicker,{current:g,onChange:e=>{x(e),v(`${o.LiveChannelScope.DataSource}/${e.uid}/`)}})}),(0,u.jsx)(r.Field,{label:"Path",children:(0,u.jsx)(r.Input,{value:null!=i?i:"",onChange:e=>p(e.currentTarget.value),placeholder:"path"})})]}),(0,u.jsx)(r.Field,{label:"",children:(0,u.jsx)(r.Button,{onClick:m,variant:null!=i&&i.length?"primary":"secondary",children:"Add"})}),(0,u.jsx)(r.Field,{label:"",children:(0,u.jsx)(r.Button,{variant:"secondary",onClick:()=>s(void 0),children:"Cancel"})})]})}):(0,u.jsx)("div",{children:(0,u.jsx)(r.ValuePicker,{label:"Add channel rule",variant:"secondary",size:"md",icon:"plus",menuPlacement:"auto",isFullWidth:!1,options:d,onChange:e=>s(e.value)})})}var h=n(36636),v=n(67436);const g=e=>{var t;let{onChange:n,value:a,ruleType:l,entitiesInfo:s}=e;return(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(r.Select,{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,u.jsx)(r.CodeEditor,{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})}})]})},x=e=>{let{onChange:t,value:n,ruleType:l,entitiesInfo:s}=e;const[i,o]=(0,a.useState)(0),c=null!=n?n:[];let d=[];for(let e=0;e<=c.length;e++)d.push({label:`${l}: ${e}`,value:e});return(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(r.Select,{placeholder:"Select an index",options:d,value:i,onChange:e=>{o(e.value)}}),(0,u.jsx)(g,{onChange:e=>{if(n){const a=[...n];a[i]=e,t(a)}else t([e])},value:c[i],ruleType:l,entitiesInfo:s})]})},j=e=>{const[t,n]=(0,a.useState)(),[s,i]=(0,a.useState)(),c=(0,r.useStyles)(m);return(0,u.jsxs)("div",{children:[(0,u.jsx)(r.CodeEditor,{height:100,value:"",showLineNumbers:!0,readOnly:!1,language:"json",showMiniMap:!1,onBlur:e=>{i(e)}}),(0,u.jsx)(r.Button,{onClick:()=>{(0,l.getBackendSrv)().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,o.dataFrameFromJSON)(e.frame);for(const e of t.fields)e.display=(0,o.getDisplayProcessor)({field:e,theme:l.config.theme2});return{channel:e.channel,frame:t}})))})).catch((e=>{n(e)}))},className:c.margin,children:"Test"}),(null==t?void 0:t.length)&&t.map((e=>(0,u.jsx)(r.Field,{label:e.channel,children:(0,u.jsx)(r.Table,{data:e.frame,width:700,height:Math.min(10*e.frame.length+10,150),showTypeIcons:!0})},e.channel)))]})},m=e=>({margin:h.css` margin-bottom: 15px; `});function y(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 f=[{label:"Converter",type:"converter",isConverter:!0},{label:"Processors",type:"frameProcessors"},{label:"Outputs",type:"frameOutputs"},{label:"Test",isTest:!0,icon:"flask"}],S=e=>{var t;const{isOpen:n,onClose:s,clickColumn:i}=e,[o,c]=(0,a.useState)(e.rule),[d,p]=(0,a.useState)(f.find((e=>e.type===i))),[h,v]=(0,a.useState)(!1),[m,S]=(0,a.useState)(null!=d&&d.type?null==o||null===(t=o.settings)||void 0===t?void 0:t[d.type]:void 0),[b,k]=(0,a.useState)(),O=(0,r.useStyles)(C),T=e=>{v(!0),null!=d&&d.type&&c(Object.assign({},o,{settings:Object.assign({},o.settings,{[null==d?void 0:d.type]:e})})),S(e)};(0,a.useMemo)((()=>{(async function(){return await(0,l.getBackendSrv)().get("api/live/pipeline-entities").then((e=>({converter:y(e,"converters"),frameProcessors:y(e,"frameProcessors"),frameOutputs:y(e,"frameOutputs"),getExample:(t,n)=>{var a,l,r;return null===(a=e[`${t}s`])||void 0===a||null===(l=a.filter((e=>e.type===n)))||void 0===l||null===(r=l[0])||void 0===r?void 0:r.example}})))})().then((e=>{k(e)}))}),[]);return(0,u.jsxs)(r.Modal,{isOpen:n,title:o.pattern,onDismiss:s,closeOnEscape:!0,children:[(0,u.jsx)(r.TabsBar,{children:f.map(((e,t)=>(0,u.jsx)(r.Tab,{label:e.label,active:e===d,icon:e.icon,onChangeTab:()=>{var t;(p(e),e.type)&&S(null==o||null===(t=o.settings)||void 0===t?void 0:t[e.type])}},t)))}),(0,u.jsxs)(r.TabContent,{children:[b&&o&&d&&(0,u.jsxs)(u.Fragment,{children:[(null==d?void 0:d.isTest)&&(0,u.jsx)(j,{rule:o}),d.isConverter&&(0,u.jsx)(g,{onChange:T,value:m,ruleType:"converter",entitiesInfo:b}),!d.isConverter&&d.type&&(0,u.jsx)(x,{onChange:T,value:m,ruleType:d.type,entitiesInfo:b})]}),(0,u.jsx)(r.Button,{onClick:()=>{(0,l.getBackendSrv)().put("api/live/channel-rules",o).then((()=>{v(!1),s()})).catch((e=>console.error(e)))},className:O.save,variant:h?"primary":"secondary",children:"Save"})]})]})},C=e=>({save:h.css` margin-top: 5px; `});var b,k,O,T;function w(e,t){return null!=t&&t.type?(0,u.jsx)(r.Tag,{name:t.type},e):null}const B=e=>{const{rules:t}=e,[n,s]=(0,a.useState)(!1),[i,o]=(0,a.useState)(),[c,d]=(0,a.useState)("converter"),p=(0,r.useStyles)(F),h=(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"),d(a),o(e),s(!0)};(0,a.useEffect)((()=>{e.selectRule&&h(e.selectRule)}),[e.selectRule]);const g=e=>{if(e.startsWith("ds/")){const t=e.indexOf("/",4);if(t>3){const n=e.substring(3,t),a=(0,v.ak)().getInstanceSettings(n);if(a)return(0,u.jsxs)("div",{children:[(0,u.jsx)(r.Tag,{name:a.name,colorIndex:1}),"  ",(0,u.jsx)("span",{children:e.substring(t+1)})]})}}return e};return(0,u.jsxs)("div",{children:[(0,u.jsx)("div",{className:"admin-list-table",children:(0,u.jsxs)("table",{className:"filter-table filter-table--hover form-inline",children:[(0,u.jsx)("thead",{children:(0,u.jsxs)("tr",{children:[b||(b=(0,u.jsx)("th",{children:"Channel"})),k||(k=(0,u.jsx)("th",{children:"Converter"})),O||(O=(0,u.jsx)("th",{children:"Processor"})),T||(T=(0,u.jsx)("th",{children:"Output"})),(0,u.jsx)("th",{style:{width:10},children:" "})]})}),(0,u.jsx)("tbody",{children:t.map((t=>{var n,a,s,i,o,c;return(0,u.jsxs)("tr",{onClick:e=>h(t,e),className:p.row,children:[(0,u.jsx)("td",{"data-pattern":t.pattern,"data-column":"pattern",children:g(t.pattern)}),(0,u.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,u.jsx)("td",{"data-pattern":t.pattern,"data-column":"processor",children:null===(s=t.settings)||void 0===s||null===(i=s.frameProcessors)||void 0===i?void 0:i.map((e=>(0,u.jsx)("span",{children:e.type},t.pattern+e.type)))}),(0,u.jsx)("td",{"data-pattern":t.pattern,"data-column":"output",children:null===(o=t.settings)||void 0===o||null===(c=o.frameOutputs)||void 0===c?void 0:c.map((e=>(0,u.jsx)("span",{children:w("out",e)},t.pattern+e.type)))}),(0,u.jsx)("td",{children:(0,u.jsx)(r.IconButton,{name:"trash-alt",onClick:n=>{var a;n.stopPropagation(),a=t.pattern,(0,l.getBackendSrv)().delete("api/live/channel-rules",JSON.stringify({pattern:a})).catch((e=>console.error(e))).finally((()=>{e.onRuleChanged()}))}})})]},t.pattern)}))})]})}),n&&i&&(0,u.jsx)(S,{rule:i,isOpen:n,onClose:()=>{s(!1)},clickColumn:c})]})},F=e=>({row:h.css` cursor: pointer; `});function N(){const[e,t]=(0,a.useState)([]),[n,o]=(0,a.useState)([]),[c,d]=(0,a.useState)(),h=(0,i.q)("live-pipeline"),[v,g]=(0,a.useState)(),x=()=>{(0,l.getBackendSrv)().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&&g(JSON.stringify(e.data,null,2))}))};(0,a.useEffect)((()=>{x()}),[]);return(0,u.jsx)(s.Z,{navModel:h,children:(0,u.jsxs)(s.Z.Contents,{children:[v&&(0,u.jsx)("pre",{children:v}),(0,u.jsx)("div",{className:"page-action-bar",children:(0,u.jsx)("div",{className:"gf-form gf-form--grow",children:(0,u.jsx)(r.Input,{placeholder:"Search pattern...",onChange:a=>{a.target.value?t(e.filter((e=>e.pattern.toLowerCase().includes(a.target.value.toLowerCase())))):t(n)}})})}),(0,u.jsx)(B,{rules:e,onRuleChanged:x,selectRule:c}),(0,u.jsx)(p,{onRuleAdded:t=>{console.log("GOT",t,"vs",e[0]),d(t),x()}})]})})}}}]); //# sourceMappingURL=PipelineAdminPage.7942977ac0444301c1c6.js.map