"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[2651],{"./public/app/core/hooks/useNavModel.ts":(e,t,n)=>{n.d(t,{q:()=>r});var a=n("./.yarn/__virtual__/react-redux-virtual-7ad20a440e/3/opt/drone/yarncache/react-redux-npm-7.2.6-134f5ed64d-0bf142ce0d.zip/node_modules/react-redux/es/index.js"),s=n("./public/app/core/selectors/navModel.ts");const r=e=>{const t=(0,a.useSelector)((e=>e.navIndex));return(0,s.h)(t,e)}},"./public/app/features/live/pages/PipelineAdminPage.tsx":(e,t,n)=>{n.r(t),n.d(t,{default:()=>w});var a=n("../../opt/drone/yarncache/react-npm-17.0.2-99ba37d931-b254cc17ce.zip/node_modules/react/index.js"),s=n("./packages/grafana-runtime/src/index.ts"),r=n("./packages/grafana-ui/src/index.ts"),l=n("./public/app/core/components/Page/Page.tsx"),o=n("./public/app/core/hooks/useNavModel.ts"),i=n("./.yarn/__virtual__/@emotion-css-virtual-72c314ddb1/3/opt/drone/yarncache/@emotion-css-npm-11.7.1-25ff8755a7-ac1f56656f.zip/node_modules/@emotion/css/dist/emotion-css.esm.js"),c=n("../../opt/drone/yarncache/react-npm-17.0.2-99ba37d931-b254cc17ce.zip/node_modules/react/jsx-runtime.js");const u=e=>{var t;let{onChange:n,value:a,ruleType:s,entitiesInfo:l}=e;return(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(r.Select,{menuShouldPortal:!0,options:l[s],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]:l.getExample(s,t)})}},s),(0,c.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})}})]})};function d(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 p=e=>{let{onChange:t,value:n,ruleType:s,entitiesInfo:l}=e;const[o,i]=(0,a.useState)(0),d=null!=n?n:[];let p=[];for(let e=0;e<=d.length;e++)p.push({label:`${s}: ${e}`,value:e});return(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(r.Select,{placeholder:"Select an index",menuShouldPortal:!0,options:p,value:o,onChange:e=>{i(e.value)}}),(0,c.jsx)(u,{onChange:e=>{if(n){const a=[...n];a[o]=e,t(a)}else t([e])},value:d[o],ruleType:s,entitiesInfo:l})]})};var h=n("./packages/grafana-data/src/index.ts");const v=e=>{const[t,n]=(0,a.useState)(),[l,o]=(0,a.useState)(),i=(0,r.useStyles)(g);return(0,c.jsxs)("div",{children:[(0,c.jsx)(r.CodeEditor,{height:100,value:"",showLineNumbers:!0,readOnly:!1,language:"json",showMiniMap:!1,onBlur:e=>{o(e)}}),(0,c.jsx)(r.Button,{onClick:()=>{(0,s.getBackendSrv)().post("api/live/pipeline-convert-test",{channelRules:[e.rule],channel:e.rule.pattern,data:l}).then((e=>{const t=e.channelFrames;t&&n(t.map((e=>{const t=(0,h.dataFrameFromJSON)(e.frame);for(const e of t.fields)e.display=(0,h.getDisplayProcessor)({field:e,theme:s.config.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,c.jsx)(r.Field,{label:e.channel,children:(0,c.jsx)(r.Table,{data:e.frame,width:700,height:Math.min(10*e.frame.length+10,150),showTypeIcons:!0})},e.channel)))]})},g=e=>({margin:i.css`
      margin-bottom: 15px;
    `}),m=[{label:"Converter",type:"converter",isConverter:!0},{label:"Processors",type:"frameProcessors"},{label:"Outputs",type:"frameOutputs"},{label:"Test",isTest:!0,icon:"flask"}],x=e=>{var t;const{isOpen:n,onClose:l,clickColumn:o}=e,[i,h]=(0,a.useState)(e.rule),[g,x]=(0,a.useState)(m.find((e=>e.type===o))),[f,y]=(0,a.useState)(!1),[b,S]=(0,a.useState)(null!=g&&g.type?null==i||null===(t=i.settings)||void 0===t?void 0:t[g.type]:void 0),[C,k]=(0,a.useState)(),O=(0,r.useStyles)(j),T=e=>{y(!0),null!=g&&g.type&&h(Object.assign({},i,{settings:Object.assign({},i.settings,{[null==g?void 0:g.type]:e})})),S(e)};(0,a.useMemo)((()=>{(async function(){return await(0,s.getBackendSrv)().get("api/live/pipeline-entities").then((e=>({converter:d(e,"converters"),frameProcessors:d(e,"frameProcessors"),frameOutputs:d(e,"frameOutputs"),getExample:(t,n)=>{var a,s,r;return null===(a=e[`${t}s`])||void 0===a||null===(s=a.filter((e=>e.type===n)))||void 0===s||null===(r=s[0])||void 0===r?void 0:r.example}})))})().then((e=>{k(e)}))}),[]);return(0,c.jsxs)(r.Modal,{isOpen:n,title:i.pattern,onDismiss:l,closeOnEscape:!0,children:[(0,c.jsx)(r.TabsBar,{children:m.map(((e,t)=>(0,c.jsx)(r.Tab,{label:e.label,active:e===g,icon:e.icon,onChangeTab:()=>{var t;(x(e),e.type)&&S(null==i||null===(t=i.settings)||void 0===t?void 0:t[e.type])}},t)))}),(0,c.jsxs)(r.TabContent,{children:[C&&i&&g&&(0,c.jsxs)(c.Fragment,{children:[(null==g?void 0:g.isTest)&&(0,c.jsx)(v,{rule:i}),g.isConverter&&(0,c.jsx)(u,{onChange:T,value:b,ruleType:"converter",entitiesInfo:C}),!g.isConverter&&g.type&&(0,c.jsx)(p,{onChange:T,value:b,ruleType:g.type,entitiesInfo:C})]}),(0,c.jsx)(r.Button,{onClick:()=>{(0,s.getBackendSrv)().put("api/live/channel-rules",i).then((()=>{y(!1),l()})).catch((e=>console.error(e)))},className:O.save,variant:f?"primary":"secondary",children:"Save"})]})]})},j=e=>({save:i.css`
      margin-top: 5px;
    `});var f,y,b,S,C=n("./public/app/features/plugins/datasource_srv.ts");function k(e,t){return null!=t&&t.type?(0,c.jsx)(r.Tag,{name:t.type},e):null}const O=e=>{const{rules:t}=e,[n,l]=(0,a.useState)(!1),[o,i]=(0,a.useState)(),[u,d]=(0,a.useState)("converter"),p=(0,r.useStyles)(T),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),i(e),l(!0)};(0,a.useEffect)((()=>{e.selectRule&&h(e.selectRule)}),[e.selectRule]);const v=e=>{if(e.startsWith("ds/")){const t=e.indexOf("/",4);if(t>3){const n=e.substring(3,t),a=(0,C.ak)().getInstanceSettings(n);if(a)return(0,c.jsxs)("div",{children:[(0,c.jsx)(r.Tag,{name:a.name,colorIndex:1}),"  ",(0,c.jsx)("span",{children:e.substring(t+1)})]})}}return e};return(0,c.jsxs)("div",{children:[(0,c.jsx)("div",{className:"admin-list-table",children:(0,c.jsxs)("table",{className:"filter-table filter-table--hover form-inline",children:[(0,c.jsx)("thead",{children:(0,c.jsxs)("tr",{children:[f||(f=(0,c.jsx)("th",{children:"Channel"})),y||(y=(0,c.jsx)("th",{children:"Converter"})),b||(b=(0,c.jsx)("th",{children:"Processor"})),S||(S=(0,c.jsx)("th",{children:"Output"})),(0,c.jsx)("th",{style:{width:10},children:" "})]})}),(0,c.jsx)("tbody",{children:t.map((t=>{var n,a,l,o,i,u;return(0,c.jsxs)("tr",{onClick:e=>h(t,e),className:p.row,children:[(0,c.jsx)("td",{"data-pattern":t.pattern,"data-column":"pattern",children:v(t.pattern)}),(0,c.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,c.jsx)("td",{"data-pattern":t.pattern,"data-column":"processor",children:null===(l=t.settings)||void 0===l||null===(o=l.frameProcessors)||void 0===o?void 0:o.map((e=>(0,c.jsx)("span",{children:e.type},t.pattern+e.type)))}),(0,c.jsx)("td",{"data-pattern":t.pattern,"data-column":"output",children:null===(i=t.settings)||void 0===i||null===(u=i.frameOutputs)||void 0===u?void 0:u.map((e=>(0,c.jsx)("span",{children:k("out",e)},t.pattern+e.type)))}),(0,c.jsx)("td",{children:(0,c.jsx)(r.IconButton,{name:"trash-alt",onClick:n=>{var a;n.stopPropagation(),a=t.pattern,(0,s.getBackendSrv)().delete("api/live/channel-rules",JSON.stringify({pattern:a})).catch((e=>console.error(e))).finally((()=>{e.onRuleChanged()}))}})})]},t.pattern)}))})]})}),n&&o&&(0,c.jsx)(x,{rule:o,isOpen:n,onClose:()=>{l(!1)},clickColumn:u})]})},T=e=>({row:i.css`
      cursor: pointer;
    `});var P=n("./public/app/core/app_events.ts");const E=[{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 N(e){let{onRuleAdded:t}=e;const[n,l]=(0,a.useState)(),[o,i]=(0,a.useState)(),[u,d]=(0,a.useState)(""),[p,v]=(0,a.useState)(),g=()=>{o?"ds"!==n||u.length?(0,s.getBackendSrv)().post("api/live/channel-rules",{pattern:u+o,settings:{converter:{type:"jsonAuto"},frameOutputs:[{type:"managedStream"}]}}).then((e=>{console.log("ADDED",e),i(void 0),l(void 0),t(e.rule)})).catch((e=>{P.Z.emit(h.AppEvents.alertError,["Error adding rule",e]),e.isHandled=!0})):P.Z.emit(h.AppEvents.alertError,["Select datasource"]):P.Z.emit(h.AppEvents.alertError,["Enter path"])};return n?(0,c.jsx)("div",{children:(0,c.jsxs)(r.HorizontalGroup,{children:["any"===n&&(0,c.jsx)(r.Field,{label:"Pattern",children:(0,c.jsx)(r.Input,{value:null!=o?o:"",onChange:e=>i(e.currentTarget.value),placeholder:"scope/namespace/path"})}),"ds"===n&&(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(r.Field,{label:"Data source",children:(0,c.jsx)(s.DataSourcePicker,{current:p,onChange:e=>{v(e),d(`${h.LiveChannelScope.DataSource}/${e.uid}/`)}})}),(0,c.jsx)(r.Field,{label:"Path",children:(0,c.jsx)(r.Input,{value:null!=o?o:"",onChange:e=>i(e.currentTarget.value),placeholder:"path"})})]}),(0,c.jsx)(r.Field,{label:"",children:(0,c.jsx)(r.Button,{onClick:g,variant:null!=o&&o.length?"primary":"secondary",children:"Add"})}),(0,c.jsx)(r.Field,{label:"",children:(0,c.jsx)(r.Button,{variant:"secondary",onClick:()=>l(void 0),children:"Cancel"})})]})}):(0,c.jsx)("div",{children:(0,c.jsx)(r.ValuePicker,{label:"Add channel rule",variant:"secondary",size:"md",icon:"plus",menuPlacement:"auto",isFullWidth:!1,options:E,onChange:e=>l(e.value)})})}function w(){const[e,t]=(0,a.useState)([]),[n,i]=(0,a.useState)([]),[u,d]=(0,a.useState)(),p=(0,o.q)("live-pipeline"),[h,v]=(0,a.useState)(),g=()=>{(0,s.getBackendSrv)().get("api/live/channel-rules").then((e=>{var n,a;t(null!==(n=e.rules)&&void 0!==n?n:[]),i(null!==(a=e.rules)&&void 0!==a?a:[])})).catch((e=>{e.data&&v(JSON.stringify(e.data,null,2))}))};(0,a.useEffect)((()=>{g()}),[]);return(0,c.jsx)(l.Z,{navModel:p,children:(0,c.jsxs)(l.Z.Contents,{children:[h&&(0,c.jsx)("pre",{children:h}),(0,c.jsx)("div",{className:"page-action-bar",children:(0,c.jsx)("div",{className:"gf-form gf-form--grow",children:(0,c.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,c.jsx)(O,{rules:e,onRuleChanged:g,selectRule:u}),(0,c.jsx)(N,{onRuleAdded:t=>{console.log("GOT",t,"vs",e[0]),d(t),g()}})]})})}}}]);
//# sourceMappingURL=PipelineAdminPage.cd4ada1146b53ad3284f.js.map