"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[5413],{39408:(z,y,n)=>{n.d(y,{l:()=>g});var m=n(89667),s=n(17172);async function g(){return(0,s.AI)().get("api/live/list").then(b=>{const c=b.channels??[],j={},M=c.map(O=>{if(O.data){const N=new Set,R=(0,m.or)(O.data);for(const D of R.fields)N.add(D.name);j[O.channel]=Array.from(N).map(D=>({value:D,label:D}))}return{value:O.channel,label:O.channel+" ["+O.minute_rate+" msg/min]"}});return{channelFields:j,channels:M}})}},45850:(z,y,n)=>{n.r(y),n.d(y,{plugin:()=>w});var m=n(65158),s=n(74848),g=n(32196),b=n(96540),c=n(55004),j=n(42418),M=n(60029),O=n(90182),N=n(3911),R=n(2913),D=n(39408);const A=[{label:"Grafana",value:c.qD.Grafana,description:"Core grafana live features"},{label:"Data Sources",value:c.qD.DataSource,description:"Data sources with live support"},{label:"Plugins",value:c.qD.Plugin,description:"Plugins with live support"},{label:"Stream",value:c.qD.Stream,description:"data streams (eg, influx style)"}];function W(o){const[i,a]=(0,b.useState)([]),[l,u]=(0,b.useMemo)(()=>{const x=[],L=[],Z=o.value.scope,k=o.value.namespace;if(!Z?.length)return[x,L];const _={};for(let q of i){const F=(0,c.DG)(q.value);!F||F.scope!==Z||(_[F.namespace]||(x.push({value:F.namespace,label:F.namespace}),_[F.namespace]=!0),k?.length&&k===F.namespace&&L.push({...q,value:F.path}))}return[x,L]},[i,o.value.scope,o.value.namespace]);(0,b.useEffect)(()=>{(0,D.l)().then(x=>{a(x.channels)})},[o.value.scope]);const C=x=>{x.value&&o.onChange({scope:x.value,namespace:void 0,path:void 0})},B=x=>{o.onChange({scope:o.value?.scope,namespace:x?.value,path:void 0})},Q=x=>{const{value:L,onChange:Z}=o;Z({scope:L.scope,namespace:L.namespace,path:x?.value})},{scope:T,namespace:V,path:ee}=o.value,Y=J(R.$W.theme2);return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(j.F,{title:"Grafana Live",severity:"info",children:"This supports real-time event streams in grafana core. This feature is under heavy development. Expect the intefaces and structures to change as this becomes more production ready."}),(0,s.jsxs)("div",{children:[(0,s.jsxs)("div",{className:Y.dropWrap,children:[(0,s.jsx)(M.J,{children:"Scope"}),(0,s.jsx)(O.l6,{options:A,value:A.find(x=>x.value===T),onChange:C})]}),T&&(0,s.jsxs)("div",{className:Y.dropWrap,children:[(0,s.jsx)(M.J,{children:"Namespace"}),(0,s.jsx)(O.l6,{options:l,value:l.find(x=>x.value===V)??(V?{label:V,value:V}:void 0),onChange:B,allowCustomValue:!0,backspaceRemovesValue:!0,isClearable:!0})]}),T&&V&&(0,s.jsxs)("div",{className:Y.dropWrap,children:[(0,s.jsx)(M.J,{children:"Path"}),(0,s.jsx)(O.l6,{options:u,value:U(u,ee),onChange:Q,allowCustomValue:!0,backspaceRemovesValue:!0,isClearable:!0})]})]})]})}function U(o,i){const a=o.find(l=>l.value===i);if(a)return a;if(i)return{label:i,value:i}}const J=(0,N.N)(o=>({dropWrap:(0,g.css)`
    margin-bottom: ${o.spacing(1)};
  `}));var K=n(2543),$=n(9631),e=n(90708),r=n(39070),t=n(32264),d=n(78731),E=n(24022),h=n(40276),S=n(24310),P=n(17172),p=n(32372),I=n(55852),v=(o=>(o.Raw="raw",o.JSON="json",o.Auto="auto",o.None="none",o))(v||{}),f=(o=>(o.None="none",o.JSON="json",o.Influx="influx",o))(f||{});function H({height:o,mode:i,body:a,addr:l,onSave:u}){const C=(0,b.useMemo)(()=>i===f.JSON?a?JSON.stringify(a,null,2):"{ }":a==null?"":`${a}`,[i,a]),B=T=>{i===f.JSON?u(JSON.parse(T)):u(T)},Q=async()=>{if(i===f.Influx){if(l?.scope!=="stream"){alert("expected stream scope!");return}return(0,P.AI)().post(`api/live/push/${l.namespace}`,a)}if(!(0,c.aj)(l)){alert("invalid address");return}const T=await(0,d.oF)().publish(l,a);console.log("onPublishClicked (response from publish)",T)};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(p.B,{height:o-32,language:i===f.JSON?"json":"text",value:C,onBlur:B,onSave:B,showMiniMap:!1,showLineNumbers:!0}),(0,s.jsx)("div",{style:{height:32},children:(0,s.jsx)(I.$n,{onClick:Q,children:"Publish"})})]})}class X extends b.PureComponent{constructor(i){super(i),this.styles=G(t.$.theme2),this.streamObserver={next:a=>{(0,c.ew)(a)?this.setState({status:a,changed:Date.now()}):(0,c.Z7)(a)?this.setState({message:a.message,changed:Date.now()}):console.log("ignore",a)}},this.unsubscribe=()=>{this.subscription&&(this.subscription.unsubscribe(),this.subscription=void 0)},this.isValid=!!(0,d.oF)(),this.state={changed:0}}async componentDidMount(){this.loadChannel()}componentWillUnmount(){this.subscription&&this.subscription.unsubscribe()}componentDidUpdate(i){this.props.options?.channel!==i.options?.channel&&this.loadChannel()}async loadChannel(){const i=this.props.options?.channel;if(!(0,c.aj)(i)){console.log("INVALID",i),this.unsubscribe(),this.setState({addr:void 0});return}if((0,K.isEqual)(i,this.state.addr)){console.log("Same channel",this.state.addr);return}const a=(0,d.oF)();if(!a){console.log("INVALID",i),this.unsubscribe(),this.setState({addr:void 0});return}this.unsubscribe(),console.log("LOAD",i);try{this.subscription=a.getStream(i).subscribe(this.streamObserver),this.setState({addr:i,error:void 0})}catch(l){this.setState({addr:void 0,error:l})}}renderNotEnabled(){return(0,s.jsxs)(j.F,{title:"Grafana Live",severity:"info",children:[(0,s.jsx)("p",{children:"Grafana live requires a feature flag to run"}),(0,s.jsx)("b",{children:"custom.ini:"}),(0,s.jsx)("pre",{children:`[feature_toggles]
    enable = live`})]})}renderMessage(i){const{options:a}=this.props,{message:l}=this.state;if(!l)return(0,s.jsxs)("div",{children:[(0,s.jsx)("h4",{children:"Waiting for data:"}),a.channel?.scope,"/",a.channel?.namespace,"/",a.channel?.path]});if(a.display===v.JSON)return(0,s.jsx)(E.B,{json:l,open:5});if(a.display===v.Auto&&l instanceof $.k9){const u={series:(0,e.we)({data:[l],theme:t.$.theme2,replaceVariables:B=>B,fieldConfig:{defaults:{},overrides:[]}}),state:r.Gu.Streaming},C={...this.props,options:{frameIndex:0,showHeader:!0}};return(0,s.jsx)(S.L,{...C,data:u,height:i})}return(0,s.jsx)("pre",{children:JSON.stringify(l)})}renderPublish(i){const{options:a}=this.props;return(0,s.jsx)(H,{height:i,body:a.message,mode:a.publish??f.JSON,onSave:l=>this.props.onOptionsChange({...a,message:l}),addr:this.state.addr})}renderStatus(){const{status:i}=this.state;if(i?.state===c.ZF.Connected)return;let a="";return i&&(a=this.styles.status[i.state]),(0,s.jsx)("div",{className:(0,g.cx)(a,this.styles.statusWrap),children:i?.state})}renderBody(){const{status:i}=this.state,{options:a,height:l}=this.props;if(a.publish===f.JSON||a.publish===f.Influx){if(a.display===v.None)return this.renderPublish(l);const C=l/2;return(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{style:{height:C,overflow:"hidden"},children:(0,s.jsx)(h.E,{autoHeightMin:"100%",autoHeightMax:"100%",children:this.renderMessage(C)})}),(0,s.jsx)("div",{children:this.renderPublish(C)})]})}return a.display===v.None?(0,s.jsx)("pre",{children:JSON.stringify(i)}):(0,s.jsx)("div",{style:{overflow:"hidden",height:l},children:(0,s.jsx)(h.E,{autoHeightMin:"100%",autoHeightMax:"100%",children:this.renderMessage(l)})})}render(){if(!this.isValid)return this.renderNotEnabled();const{addr:i,error:a}=this.state;return i?a?(0,s.jsxs)("div",{children:[(0,s.jsx)("h2",{children:"ERROR"}),(0,s.jsx)("div",{children:JSON.stringify(a)})]}):(0,s.jsxs)(s.Fragment,{children:[this.renderStatus(),this.renderBody()]}):(0,s.jsx)(j.F,{title:"Grafana Live",severity:"info",children:"Use the panel editor to pick a channel"})}}const G=(0,N.N)(o=>({statusWrap:(0,g.css)`
    margin: auto;
    position: absolute;
    top: 0;
    right: 0;
    background: ${o.components.panel.background};
    padding: 10px;
    z-index: ${o.zIndex.modal};
  `,status:{[c.ZF.Pending]:(0,g.css)`
      border: 1px solid ${o.v1.palette.orange};
    `,[c.ZF.Connected]:(0,g.css)`
      border: 1px solid ${o.colors.success.main};
    `,[c.ZF.Connecting]:(0,g.css)`
      border: 1px solid ${o.v1.palette.brandWarning};
    `,[c.ZF.Disconnected]:(0,g.css)`
      border: 1px solid ${o.colors.warning.main};
    `,[c.ZF.Shutdown]:(0,g.css)`
      border: 1px solid ${o.colors.error.main};
    `,[c.ZF.Invalid]:(0,g.css)`
      border: 1px solid red;
    `}})),w=new m.m(X).setPanelOptions(o=>{o.addCustomEditor({category:["Channel"],id:"channel",path:"channel",name:"Channel",editor:W,defaultValue:{}}),o.addRadio({path:"display",name:"Show message",description:"Display the last message received on this channel",settings:{options:[{value:v.Raw,label:"Raw Text"},{value:v.JSON,label:"JSON"},{value:v.Auto,label:"Auto"},{value:v.None,label:"None"}]},defaultValue:v.JSON}).addRadio({path:"publish",name:"Publish",description:"Display a form to publish values",settings:{options:[{value:f.None,label:"None"},{value:f.JSON,label:"JSON"},{value:f.Influx,label:"Influx"}]},defaultValue:f.None})})},24310:(z,y,n)=>{n.d(y,{L:()=>W});var m=n(74848),s=n(32196),g=n(94624),b=n(28240),c=n(1173),j=n(97152),M=n(32264),O=n(40845),N=n(79041),R=n(77093),D=n(90182),A=n(65885);function W(r){const{data:t,height:d,width:E,options:h,fieldConfig:S,id:P,timeRange:p}=r,I=(0,O.$j)(),v=(0,N.d2)(),f=(0,A.gy)(t.series)?(0,A.S5)(t.series):t.series,H=f?.length,X=f.some(u=>u.fields.length>0),G=U(f,h),w=f[G];let o=d;if(!H||!X)return(0,m.jsx)(j.a,{panelId:P,fieldConfig:S,data:t});if(H>1){const u=I.spacing.gridSize*I.components.height.md,C=I.spacing.gridSize;o=d-u-C}const i=v.sync&&v.sync()!==g.y.Off,a=(0,m.jsx)(R.X,{height:o,width:E,data:w,noHeader:!h.showHeader,showTypeIcons:h.showTypeIcons,resizable:!0,initialSortBy:h.sortBy,onSortByChange:u=>K(u,r),onColumnResize:(u,C)=>J(u,C,r),onCellFilterAdded:v.onAddAdHocFilter,footerOptions:h.footer,enablePagination:h.footer?.enablePagination,cellHeight:h.cellHeight,timeRange:p,enableSharedCrosshair:M.$.featureToggles.tableSharedCrosshair&&i,fieldConfig:S});if(H===1)return a;const l=f.map((u,C)=>({label:(0,b.Ri)(u),value:C}));return(0,m.jsxs)("div",{className:e.wrapper,children:[a,(0,m.jsx)("div",{className:e.selectWrapper,children:(0,m.jsx)(D.l6,{options:l,value:l[G],onChange:u=>$(u,r)})})]})}function U(r,t){return t.frameIndex>0&&t.frameIndex<r.length?t.frameIndex:0}function J(r,t,d){const{fieldConfig:E}=d,{overrides:h}=E,S=c.Ct.byName,P="custom.width",p=h.find(I=>I.matcher.id===S&&I.matcher.options===r);if(p){const I=p.properties.find(v=>v.id===P);I?I.value=t:p.properties.push({id:P,value:t})}else h.push({matcher:{id:S,options:r},properties:[{id:P,value:t}]});d.onFieldConfigChange({...E,overrides:h})}function K(r,t){t.onOptionsChange({...t.options,sortBy:r})}function $(r,t){t.onOptionsChange({...t.options,frameIndex:r.value||0})}const e={wrapper:(0,s.css)`
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 100%;
  `,selectWrapper:(0,s.css)`
    padding: 8px 8px 0px 8px;
  `}},65885:(z,y,n)=>{n.d(y,{S5:()=>K,fq:()=>j,gy:()=>$,l1:()=>U});var m=n(2543),s=n.n(m),g=n(1173),b=n(50082),c=n(11261);const j=e=>(!e.pluginVersion&&"columns"in e&&console.log("Was angular table",e),e.options),M={timeseries_to_rows:"seriesToRows",timeseries_to_columns:"seriesToColumns",timeseries_aggregations:"reduce",table:"merge"},O={avg:"mean",min:"min",max:"max",total:"sum",current:"lastNotNull",count:"count"},N={cell:"color-background",row:"color-background",value:"color-text"},R=(e,r)=>[-1/0,...e].map((t,d)=>({color:r[d],value:(0,m.isNumber)(t)?t:parseInt(t,10)})),D=(e,r)=>{const t=e.transformations??[];if(Object.keys(M).includes(r.transform)){const d={reducers:[]};r.transform==="timeseries_aggregations"&&(d.includeTimeField=!1,d.reducers=r.columns.map(E=>O[E.value])),t.push({id:M[r.transform],options:d})}return t},A=e=>{const t={matcher:{id:/^\/.*\/$/.test(e.pattern)?g.Ct.byRegexp:g.Ct.byName,options:e.pattern},properties:[]};return e.alias&&t.properties.push({id:"displayName",value:e.alias}),e.unit&&t.properties.push({id:"unit",value:e.unit}),e.decimals&&t.properties.push({id:"decimals",value:e.decimals}),e.type==="date"&&t.properties.push({id:"unit",value:`time: ${e.dateFormat}`}),e.type==="hidden"&&t.properties.push({id:"custom.hidden",value:!0}),e.link&&t.properties.push({id:"links",value:[{title:(0,m.defaultTo)(e.linkTooltip,""),url:(0,m.defaultTo)(e.linkUrl,""),targetBlank:(0,m.defaultTo)(e.linkTargetBlank,!1)}]}),e.colorMode&&t.properties.push({id:"custom.cellOptions",value:{type:N[e.colorMode]}}),e.align&&t.properties.push({id:"custom.align",value:e.align==="auto"?null:e.align}),e.thresholds?.length&&t.properties.push({id:"thresholds",value:{mode:b.O.Absolute,steps:R(e.thresholds,e.colors)}}),t},W=e=>{let r={custom:{}};if(e){if(r=(0,m.omitBy)({unit:e.unit,decimals:e.decimals,displayName:e.alias,custom:{align:e.align==="auto"?null:e.align}},m.isNil),e.thresholds.length){const t={mode:b.O.Absolute,steps:R(e.thresholds,e.colors)};r.thresholds=t}e.colorMode&&(r.custom.cellOptions={type:N[e.colorMode]})}return r},U=(e,r,t)=>{if(r==="table-old"&&t.angular){const d=t.angular,E=D(e,d),h=d.styles.find(p=>p.pattern==="/.*/"),S=W(h),P=d.styles.filter(p=>p.pattern!=="/.*/").map(A);e.transformations=E,e.fieldConfig={defaults:S,overrides:P}}return{}},J=e=>e?.filter(r=>r.meta?.custom?.parentRowIndex===void 0)||[e?.[0]],K=e=>{const r=[];return J(e).filter(d=>!!d&&d.length!==0)?.forEach(d=>{const E=e?.filter(p=>d.refId===p.refId&&p.meta?.custom?.parentRowIndex!==void 0),h=(0,m.groupBy)(E,p=>p.meta?.custom?.parentRowIndex),S=Object.keys(h).map(p=>h[p]),P={...d};E&&E.length>0&&P.fields.push({name:"nested",type:c.PU.nestedFrames,config:{},values:S}),r.push(P)}),r},$=e=>e?.some(r=>r.meta?.custom?.parentRowIndex!==void 0)}}]);

//# sourceMappingURL=livePanel.db4e0c38c4c7ff721d69.js.map