"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[2001],{19480:(e,t,r)=>{r.r(t),r.d(t,{Datasource:()=>h,MixedDatasource:()=>h});var a=r(82897),s=r(2937),o=r(80890),u=r(88399),n=r(44998),i=r(10010),d=r(57892),c=r(76913),g=r(64864),p=r(40665),l=r(43215),f=r(90923);class h extends l.DataSourceApi{constructor(e){super(e)}query(e){const t=e.targets.filter((e=>{var t;return"-- Mixed --"!==(null===(t=e.datasource)||void 0===t?void 0:t.uid)}));if(!t.length)return(0,s.of)({data:[]});const r=(0,a.groupBy)(t,"datasource.uid"),o=[];for(const t in r){const a=r[t];o.push({datasource:(0,f.getDataSourceSrv)().get(a[0].datasource,e.scopedVars),targets:a})}return o.length?this.batchQueries(o,e):(0,s.of)({data:[]})}batchQueries(e,t){const r=e.filter(this.isQueryable).map(((e,r)=>(0,o.D)(e.datasource).pipe((0,n.z)((u=>{const n=(0,a.cloneDeep)(t);return n.requestId=`mixed-${r}-${n.requestId||""}`,n.targets=e.targets,(0,o.D)(u.query(n)).pipe((0,i.U)((e=>Object.assign({},e,{data:e.data||[],state:l.LoadingState.Loading,key:`mixed-${r}-${e.key||""}`}))),(0,d.q)(),(0,c.K)((e=>((e=(0,f.toDataQueryError)(e)).message=`${u.name}: ${e.message}`,(0,s.of)([{data:[],state:l.LoadingState.Error,error:e,key:`mixed-${r}-${n.requestId||""}`}])))))})))));return(0,u.D)(r).pipe((0,p.u)(((e,t)=>t.reduce(((e,t)=>(e.push.apply(e,t),e)),e)),[]),(0,i.U)(this.finalizeResponses),(0,g.J)())}testDatasource(){return Promise.resolve({})}isQueryable(e){return e&&Array.isArray(e.targets)&&e.targets.length>0}finalizeResponses(e){const{length:t}=e;if(0===t)return e;const r=e.find((e=>e.state===l.LoadingState.Error));return r?e.push(r):e[t-1].state=l.LoadingState.Done,e}}}}]);
//# sourceMappingURL=mixedPlugin.d12c346debc311e81817.js.map