VictoriaMetrics/app/vmselect/vmui/static/js/main.a0567498.chunk.js
Yury Molodov a64155d91e
vmui: use Chart.js as default engine for graph (#1634)
* feat: add Plotly as default engine for graph

* fix: remove unused components

* feat: use Chart.js as default engine graph

* fix: correct styles for loader

* feat: add zoom/pan for chart

* feat: add height for chart

* fix: remove unused code

* fix: remove empty units from duration

* fix: change debounce for pan to 500ms

* fix: add utility for plugins register globally

* fix: optimize render graph

* feat: add buffer data for zoom

* fix: add limits for zoom in/out

* fix: change update data while zooming

* app/vmselect: `make vmui-update`

Co-authored-by: Aliaksandr Valialkin <valyala@victoriametrics.com>
2021-09-27 22:26:14 +03:00

1 line
30 KiB
JavaScript

(this.webpackJsonpvmui=this.webpackJsonpvmui||[]).push([[0],{228:function(e,t,n){},341:function(e,t,n){"use strict";n.r(t);var a=n(3),r=n(0),c=n.n(r),o=n(26),i=n.n(o),s=(n(228),n(20)),l=n(414),u=n(412),j=Object(r.createContext)({showInfoMessage:function(){}}),d=function(){return Object(r.useContext)(j)},b=function(e){var t=e.children,n=Object(r.useState)({}),c=Object(s.a)(n,2),o=c[0],i=c[1],d=Object(r.useState)(!1),b=Object(s.a)(d,2),O=b[0],h=b[1],p=Object(r.useState)(void 0),f=Object(s.a)(p,2),x=f[0],m=f[1];Object(r.useEffect)((function(){x&&(i({message:x,key:(new Date).getTime()}),h(!0))}),[x]);return Object(a.jsxs)(j.Provider,{value:{showInfoMessage:m},children:[Object(a.jsx)(l.a,{open:O,autoHideDuration:4e3,onClose:function(e,t){"clickaway"!==t&&(m(void 0),h(!1))},children:Object(a.jsx)(u.a,{children:o.message})},o.key),t]})},O=n(405),h=n(395),p=n(409),f=n(95),x=n(388),m=n(397),v=n(376),y=n(378),g=n(379),E=n(417),S=n(207),T=n(181),A=n.n(T),C=n(13),w=n(14),_=n(65),R=n.n(_),U=n(178),k=n.n(U);R.a.extend(k.a);var D=window.screen.availWidth/7.68,H=1e3,M=1578e8,I=[{long:"days",short:"d",possible:"day"},{long:"weeks",short:"w",possible:"week"},{long:"months",short:"M",possible:"mon"},{long:"years",short:"y",possible:"year"},{long:"hours",short:"h",possible:"hour"},{long:"minutes",short:"m",possible:"min"},{long:"seconds",short:"s",possible:"sec"},{long:"milliseconds",short:"ms",possible:"millisecond"}],N=I.map((function(e){return e.short})),P=function(e){var t=e.match(/\d+/g),n=e.match(/[a-zA-Z]+/g);if(n&&t&&N.includes(n[0]))return Object(C.a)({},n[0],t[0])},L=function(e,t){var n=(t||new Date).valueOf()/1e3,a=e.trim().split(" ").reduce((function(e,t){var n=P(t);return n?Object(w.a)(Object(w.a)({},e),n):Object(w.a)({},e)}),{}),r=R.a.duration(a).asSeconds();return{start:n-r,end:n,step:Math.ceil(r/D),date:B(t||new Date)}},B=function(e){return R()(e).format("YYYY-MM-DD[T]HH:mm:ss")},z=function(e){var t=Math.floor(e/1e3%60),n=Math.floor(e/1e3/60%60),a=Math.floor(e/1e3/3600%24),r=Math.floor(e/864e5),c=["d","h","m","s"];return[r,a,n,t].map((function(e,t){return e?"".concat(e).concat(c[t]):""})).filter((function(e){return e})).join(" ")},q=function(e){return new Date(1e3*e)},Y=function(e,t){t?window.localStorage.setItem(e,JSON.stringify({value:t})):Q([e])},F=function(e){var t=window.localStorage.getItem(e);if(null!==t)try{var n;return null===(n=JSON.parse(t))||void 0===n?void 0:n.value}catch(a){return t}},Q=function(e){return e.forEach((function(e){return window.localStorage.removeItem(e)}))},W=["BASIC_AUTH_DATA","BEARER_AUTH_DATA"],G=n(179),J=n.n(G),V=n(144),Z=n.n(V),K={query:"g0.expr","time.duration":"g0.range_input","time.period.date":"g0.end_input","time.period.step":"g0.step_input",stacked:"g0.stacked"},X=function(e){var t=new Map(Object.entries(K)),n=[];t.forEach((function(t,a){encodeURIComponent(t);var r=Z()(e,a,"");if(r){var c=encodeURIComponent(r);n.push("".concat(t,"=").concat(c))}})),function(e){var t=window;if(t){var n="".concat(t.location.protocol,"//").concat(t.location.host).concat(t.location.pathname,"?").concat(e);t.history.pushState({path:n},"",n)}}(n.join("&"))},$=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:window.location.search,a=J.a.parse(n,{ignoreQueryPrefix:!0});return Z()(a,e,t||"")},ee=$("g0.range_input","1h"),te=$("g0.end_input",void 0),ne={serverUrl:window.location.href.replace(/\/(?:prometheus\/)?(?:graph|vmui)\/.*/,"/prometheus/"),displayType:"chart",query:$("g0.expr",F("LAST_QUERY")||"\n"),time:{duration:ee,period:L(ee,te&&new Date(te))},queryControls:{autoRefresh:!1,autocomplete:F("AUTOCOMPLETE")||!1}};function ae(e,t){switch(t.type){case"SET_DISPLAY_TYPE":return Object(w.a)(Object(w.a)({},e),{},{displayType:t.payload});case"SET_SERVER":return Object(w.a)(Object(w.a)({},e),{},{serverUrl:t.payload});case"SET_QUERY":return Object(w.a)(Object(w.a)({},e),{},{query:t.payload});case"SET_DURATION":return Object(w.a)(Object(w.a)({},e),{},{time:Object(w.a)(Object(w.a)({},e.time),{},{duration:t.payload,period:L(t.payload,q(e.time.period.end))})});case"SET_UNTIL":return Object(w.a)(Object(w.a)({},e),{},{time:Object(w.a)(Object(w.a)({},e.time),{},{period:L(e.time.duration,t.payload)})});case"SET_PERIOD":var n=function(e){var t=e.to.valueOf()-e.from.valueOf();return z(t)}(t.payload);return Object(w.a)(Object(w.a)({},e),{},{queryControls:Object(w.a)(Object(w.a)({},e.queryControls),{},{autoRefresh:!1}),time:Object(w.a)(Object(w.a)({},e.time),{},{duration:n,period:L(n,t.payload.to)})});case"TOGGLE_AUTOREFRESH":return Object(w.a)(Object(w.a)({},e),{},{queryControls:Object(w.a)(Object(w.a)({},e.queryControls),{},{autoRefresh:!e.queryControls.autoRefresh})});case"TOGGLE_AUTOCOMPLETE":return Object(w.a)(Object(w.a)({},e),{},{queryControls:Object(w.a)(Object(w.a)({},e.queryControls),{},{autocomplete:!e.queryControls.autocomplete})});case"RUN_QUERY":return Object(w.a)(Object(w.a)({},e),{},{time:Object(w.a)(Object(w.a)({},e.time),{},{period:L(e.time.duration,q(e.time.period.end))})});case"RUN_QUERY_TO_NOW":return Object(w.a)(Object(w.a)({},e),{},{time:Object(w.a)(Object(w.a)({},e.time),{},{period:L(e.time.duration)})});default:throw new Error}}var re=Object(r.createContext)({}),ce=function(){return Object(r.useContext)(re).state},oe=function(){return Object(r.useContext)(re).dispatch},ie=Object.entries(ne).reduce((function(e,t){var n=Object(s.a)(t,2),a=n[0],r=n[1];return Object(w.a)(Object(w.a)({},e),{},Object(C.a)({},a,$(a)||r))}),{}),se=function(e){var t=e.children,n=Object(r.useReducer)(ae,ie),c=Object(s.a)(n,2),o=c[0],i=c[1];Object(r.useEffect)((function(){X(o)}),[o]);var l=Object(r.useMemo)((function(){return{state:o,dispatch:i}}),[o,i]);return Object(a.jsx)(re.Provider,{value:l,children:t})},le=function(e){return Object(a.jsxs)(p.a,{position:"relative",display:"inline-flex",children:[Object(a.jsx)(v.a,Object(w.a)({variant:"determinate"},e)),Object(a.jsx)(p.a,{top:0,left:0,bottom:0,right:0,position:"absolute",display:"flex",alignItems:"center",justifyContent:"center",children:Object(a.jsx)(f.a,{variant:"caption",component:"div",children:"".concat(e.label,"s")})})]})},ue=n(377),je=Object(ue.a)({colorizing:{color:"white"}}),de=function(){var e=je(),t=oe(),n=ce().queryControls.autoRefresh,o=Object(r.useState)(5),i=Object(s.a)(o,2),l=i[0],u=i[1],j=Object(r.useState)(),d=Object(s.a)(j,2),b=d[0],O=d[1],h=c.a.useState(100),f=Object(s.a)(h,2),x=f[0],m=f[1];Object(r.useEffect)((function(){var e;return n&&(O((new Date).valueOf()),e=setInterval((function(){O((new Date).valueOf()),t({type:"RUN_QUERY_TO_NOW"})}),1e3*l)),function(){e&&clearInterval(e)}}),[l,n]),Object(r.useEffect)((function(){var e=setInterval((function(){if(n&&b){var e=((new Date).valueOf()-b)/1e3,t=Math.floor(e/l*100);m(t)}}),16);return function(){clearInterval(e)}}),[n,b,l]);var v=function(){u((function(e){switch(e){case 1:return 2;case 2:return 5;case 5:return 1;default:return 5}}))};return Object(a.jsxs)(p.a,{display:"flex",alignItems:"center",children:[Object(a.jsx)(y.a,{control:Object(a.jsx)(g.a,{size:"small",className:e.colorizing,checked:n,onChange:function(){t({type:"TOGGLE_AUTOREFRESH"})}}),label:"Auto-refresh"}),n&&Object(a.jsxs)(a.Fragment,{children:[Object(a.jsx)(le,{className:e.colorizing,label:l,value:x,onClick:function(){v()}}),Object(a.jsx)(E.a,{title:"Change delay refresh",children:Object(a.jsx)(p.a,{ml:1,children:Object(a.jsx)(S.a,{onClick:function(){v()},children:Object(a.jsx)(A.a,{style:{color:"white"}})})})})]})]})},be=n(184),Oe=n.n(be),he=n(182),pe=n.n(he),fe=n(183),xe=n.n(fe),me=n(381),ve=n(421),ye=n(11),ge=Object(ye.a)({root:{padding:6,color:"white","&.Mui-selected":{color:"white"}}})(me.a),Ee=function(){var e=ce().displayType,t=oe();return Object(a.jsxs)(ve.a,{value:e,exclusive:!0,onChange:function(n,a){return t({type:"SET_DISPLAY_TYPE",payload:null!==a&&void 0!==a?a:e})},children:[Object(a.jsxs)(ge,{value:"chart","aria-label":"display as chart",children:[Object(a.jsx)(pe.a,{}),"\xa0Query Range as Chart"]}),Object(a.jsxs)(ge,{value:"code","aria-label":"display as code",children:[Object(a.jsx)(xe.a,{}),"\xa0Instant Query as JSON"]}),Object(a.jsxs)(ge,{value:"table","aria-label":"display as table",children:[Object(a.jsx)(Oe.a,{}),"\xa0Instant Query as Table"]})]})},Se=n(202),Te=n(122),Ae=(n(340),n(145)),Ce=n.n(Ae),we=function(e){var t=e.data,n=void 0===t?[]:t,c=ce().time,o=c.duration,i=c.period,l=oe(),u=Object(r.useState)(),j=Object(s.a)(u,2),d=j[0],b=j[1],O=Object(r.useRef)(null);Object(r.useEffect)((function(){b({datasets:null===n||void 0===n?void 0:n.map((function(e){var t=function(e){if(0===Object.keys(e.metric).length)return"Query result";var t=e.metric,n=t.__name__,a=Object(Te.a)(t,["__name__"]);return"".concat(n||""," {").concat(Object.entries(a).map((function(e){return"".concat(e[0],": ").concat(e[1])})).join(", "),"}")}(e),n=function(e){for(var t=0,n=0;n<e.length;n++)t=e.charCodeAt(n)+((t<<5)-t);for(var a="#",r=0;r<3;r++)a+=("00"+(t>>8*r&255).toString(16)).substr(-2);return a}(t);return{label:t,data:e.values.map((function(e){return{y:+e[1],x:1e3*e[0]}})),borderColor:n,backgroundColor:n}}))}),O.current&&(O.current.stop(),O.current.update("none"))}),[n]);var h={animation:{duration:0},parsing:!1,normalized:!0,scales:{x:{type:"time",position:"bottom",min:1e3*i.start,max:1e3*i.end,time:{tooltipFormat:"yyyy-MM-dd HH:mm:ss.SSS",displayFormats:{millisecond:":ss.SSS",second:"HH:mm:ss",minute:"HH:mm",hour:"HH:mm"}},ticks:{source:"auto",autoSkip:!0,autoSkipPadding:105,crossAlign:"center",maxRotation:0,minRotation:0,sampleSize:1,color:"#000",font:{size:10}}},y:{type:"linear",position:"left",ticks:{maxRotation:0,minRotation:0,color:"#000",font:{size:10}}}},elements:{line:{tension:0,stepped:!1,borderDash:[],borderWidth:1,capBezierPoints:!1},point:{radius:0,hitRadius:10}},plugins:{legend:{position:"bottom",align:"start",labels:{padding:20,color:"#000"}},zoom:{pan:{enabled:!0,mode:"x",onPan:Ce()((function(e){var t=e.chart.scales.x,n=t.min,a=t.max;if(n&&a){var r=L(o,new Date(a)),c=r.start,i=r.end;l({type:"SET_PERIOD",payload:{from:q(c),to:q(i)}})}}),750)},zoom:{pinch:{enabled:!0},wheel:{enabled:!0,speed:.05},mode:"x",onZoom:Ce()((function(e){var t=e.chart.scales.x,n=t.min,a=t.max;if(n&&a){var r=a-n;r<H&&(a=n+H),r>M&&(n=a-M),l({type:"SET_PERIOD",payload:{from:new Date(n),to:new Date(a)}})}}),250)}}}};return Object(a.jsx)(a.Fragment,{children:d&&Object(a.jsx)(Se.a,{data:d,options:h,ref:O})})},_e=n(45),Re=n(201);_e.a.register(Re.a);var Ue=function(e){var t=e.data,n=void 0===t?[]:t;return Object(a.jsx)(a.Fragment,{children:n.length>0?Object(a.jsx)(we,{data:n}):Object(a.jsx)("div",{style:{textAlign:"center"},children:"No data to show"})})},ke=n(382),De=n(205),He=n(383),Me=n(384),Ie=n(385),Ne=n(386),Pe=n(387),Le=Object(ue.a)({deemphasized:{opacity:.4}}),Be=function(e){var t=e.data,n=Le(),c=function(e){return Object(r.useMemo)((function(){var t={};return e.forEach((function(e){return Object.entries(e.metric).forEach((function(e){return t[e[0]]?t[e[0]].options.add(e[1]):t[e[0]]={options:new Set([e[1]])}}))})),Object.entries(t).map((function(e){return{key:e[0],variations:e[1].options.size}})).sort((function(e,t){return e.variations-t.variations}))}),[e])}(t),o=Object(r.useMemo)((function(){return null===t||void 0===t?void 0:t.map((function(e){return{metadata:c.map((function(t){return e.metric[t.key]||"-"})),value:e.value[1]}}))}),[c,t]);return Object(a.jsx)(a.Fragment,{children:o.length>0?Object(a.jsx)(ke.a,{component:De.a,children:Object(a.jsxs)(He.a,{"aria-label":"simple table",children:[Object(a.jsx)(Me.a,{children:Object(a.jsxs)(Ie.a,{children:[c.map((function(e,t){return Object(a.jsx)(Ne.a,{style:{textTransform:"capitalize"},children:e.key},t)})),Object(a.jsx)(Ne.a,{align:"right",children:"Value"})]})}),Object(a.jsx)(Pe.a,{children:o.map((function(e,t){return Object(a.jsxs)(Ie.a,{children:[e.metadata.map((function(e,r){var c=o[t-1]&&o[t-1].metadata[r];return Object(a.jsx)(Ne.a,{className:c===e?n.deemphasized:void 0,children:e},r)})),Object(a.jsx)(Ne.a,{align:"right",children:e.value})]},t)}))})]})}):Object(a.jsx)("div",{style:{textAlign:"center"},children:"No data to show"})})},ze=n(415),qe=n(403),Ye=n(404),Fe=n(400),Qe=n(410),We=n(5),Ge=n(10),Je=n(117),Ve=n(199),Ze=n(200),Ke={windows:"Windows",mac:"Mac OS",linux:"Linux"},Xe=function(){return(Object.values(Ke).find((function(e){return navigator.userAgent.indexOf(e)>=0}))||"unknown")===Ke.mac},$e=function(e){var t=e.query,n=e.setQuery,c=e.runQuery,o=e.server,i=e.oneLiner,l=void 0!==i&&i,u=e.autocomplete,j=Object(r.useRef)(null),d=Object(r.useState)(),b=Object(s.a)(d,2),O=b[0],h=b[1];return Object(r.useEffect)((function(){return j.current&&h(new Ge.d({parent:j.current})),function(){return null===O||void 0===O?void 0:O.destroy()}}),[]),Object(r.useEffect)((function(){var e=new Ve.a;e.activateCompletion(u),e.setComplete({url:o});var a=Ge.d.updateListener.of((function(e){e.docChanged&&n(e.state.doc.toJSON().map((function(e){return e.trim()})).join(""))}));null===O||void 0===O||O.setState(We.e.create({doc:t,extensions:[Ze.a,Object(Ge.k)(Je.a),a,e.asExtension(),Object(Ge.k)([{key:Xe()?"Cmd-Enter":"Ctrl-Enter",run:function(){return c(),!0}}])]}))}),[o,O,u]),Object(a.jsx)(a.Fragment,{children:Object(a.jsx)("div",{ref:j,className:l?"one-line-scroll":void 0})})},et=n(391),tt=n(408),nt=function(){return Object(a.jsx)(ke.a,{component:De.a,children:Object(a.jsxs)(He.a,{"aria-label":"simple table",size:"small",children:[Object(a.jsx)(Me.a,{children:Object(a.jsxs)(Ie.a,{children:[Object(a.jsx)(Ne.a,{children:"Long"}),Object(a.jsx)(Ne.a,{children:"Short"})]})}),Object(a.jsx)(Pe.a,{children:I.map((function(e,t){return Object(a.jsxs)(Ie.a,{children:[Object(a.jsx)(Ne.a,{component:"th",scope:"row",children:e.long}),Object(a.jsx)(Ne.a,{children:e.short})]},t)}))})]})})},at=Object(ue.a)({inlineBtn:{"&:hover":{cursor:"pointer"}}}),rt=function(e){var t=e.handler,n=e.text,r=at();return Object(a.jsx)(x.a,{component:"span",className:r.inlineBtn,onClick:t,children:n})},ct=function(e){var t=e.setDuration,n=Object(r.useState)(!1),o=Object(s.a)(n,2),i=o[0],l=o[1],u=c.a.useState(null),j=Object(s.a)(u,2),d=j[0],b=j[1],O=Object(r.useState)(),h=Object(s.a)(O,2),x=h[0],m=h[1],v=ce().time,y=v.period.end,g=v.duration,E=oe(),S=Object(r.useState)(g),T=Object(s.a)(S,2),A=T[0],C=T[1];Object(r.useEffect)((function(){C(g)}),[g]),Object(r.useEffect)((function(){m(B(q(y)))}),[y]),Object(r.useEffect)((function(){if(!i){var e=function(e){var t=e.trim().split(" ").reduce((function(e,t){var n=P(t);return n?Object(w.a)(Object(w.a)({},e),n):Object(w.a)({},e)}),{}),n=R.a.duration(t).asMilliseconds();return n<H?z(H):n>M?z(M):e}(A);C(e),t(e)}}),[A,i]);var _=function(){b(null)},U=Boolean(d);return Object(a.jsxs)(p.a,{m:1,flexDirection:"row",display:"flex",children:[Object(a.jsxs)(p.a,{px:1,children:[Object(a.jsx)(p.a,{children:Object(a.jsx)(Qe.a,{label:"Duration",value:A,onChange:function(e){C(e.target.value)},fullWidth:!0,onBlur:function(){l(!1)},onFocus:function(){l(!0)}})}),Object(a.jsx)(p.a,{my:2,children:Object(a.jsxs)(f.a,{variant:"body2",children:["Possible options",Object(a.jsx)("span",{"aria-owns":U?"mouse-over-popover":void 0,"aria-haspopup":"true",style:{cursor:"pointer"},onMouseEnter:function(e){b(e.currentTarget)},onMouseLeave:_,children:":\xa0"}),Object(a.jsx)(et.a,{open:U,anchorEl:d,anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"left"},style:{pointerEvents:"none"},onClose:_,disableRestoreFocus:!0,children:Object(a.jsx)(nt,{})}),Object(a.jsx)(rt,{handler:function(){return C("5m")},text:"5m"}),",\xa0",Object(a.jsx)(rt,{handler:function(){return C("1h")},text:"1h"}),",\xa0",Object(a.jsx)(rt,{handler:function(){return C("1h 30m")},text:"1h 30m"})]})})]}),Object(a.jsxs)(p.a,{px:1,children:[Object(a.jsx)(p.a,{children:Object(a.jsx)(tt.a,{variant:"inline",ampm:!1,label:"Until",value:x,onChange:function(e){return E({type:"SET_UNTIL",payload:e})},onError:console.log,format:"DD/MM/YYYY HH:mm:ss"})}),Object(a.jsx)(p.a,{my:2,children:Object(a.jsxs)(f.a,{variant:"body2",children:["Will be changed to current time for auto-refresh mode.\xa0",Object(a.jsx)(rt,{handler:function(){return E({type:"RUN_QUERY_TO_NOW"})},text:"Switch to now"})]})})]})]})},ot=n(189),it=n.n(ot),st=n(191),lt=n.n(st),ut=n(401),jt=n(420),dt=n(419),bt=n(398),Ot=n(402),ht=n(411),pt=n(393),ft=n(390),xt=n(418),mt=n(389),vt=n(396),yt=n(413),gt=n(392),Et=n(399),St=n(394),Tt=function(e){var t=e.children,n=e.value,r=e.index,c=Object(Te.a)(e,["children","value","index"]);return Object(a.jsx)("div",Object(w.a)(Object(w.a)({role:"tabpanel",hidden:n!==r,id:"auth-config-tabpanel-".concat(r),"aria-labelledby":"auth-config-tab-".concat(r)},c),{},{children:n===r&&Object(a.jsx)(p.a,{py:2,children:t})}))},At=n(187),Ct=n.n(At),wt=n(188),_t=n.n(wt),Rt={authMethod:"NO_AUTH",saveAuthLocally:!1},Ut=F("AUTH_TYPE"),kt=F("BASIC_AUTH_DATA"),Dt=F("BEARER_AUTH_DATA"),Ht=Object(w.a)(Object(w.a)({},Rt),{},{authMethod:Ut||Rt.authMethod,basicData:kt,bearerData:Dt,saveAuthLocally:!(!kt&&!Dt)}),Mt=function(){Q(W)};function It(e,t){switch(t.type){case"SET_BASIC_AUTH":return t.payload.checkbox?Y("BASIC_AUTH_DATA",t.payload.value):Mt(),Y("AUTH_TYPE","BASIC_AUTH"),Object(w.a)(Object(w.a)({},e),{},{authMethod:"BASIC_AUTH",basicData:t.payload.value});case"SET_BEARER_AUTH":return t.payload.checkbox?Y("BEARER_AUTH_DATA",t.payload.value):Mt(),Y("AUTH_TYPE","BEARER_AUTH"),Object(w.a)(Object(w.a)({},e),{},{authMethod:"BEARER_AUTH",bearerData:t.payload.value});case"SET_NO_AUTH":return!t.payload.checkbox&&Mt(),Y("AUTH_TYPE","NO_AUTH"),Object(w.a)(Object(w.a)({},e),{},{authMethod:"NO_AUTH"});default:throw new Error}}var Nt=Object(r.createContext)({}),Pt=function(){return Object(r.useContext)(Nt).state},Lt=function(e){var t=e.children,n=Object(r.useReducer)(It,Ht),c=Object(s.a)(n,2),o=c[0],i=c[1],l=Object(r.useMemo)((function(){return{state:o,dispatch:i}}),[o,i]);return Object(a.jsx)(Nt.Provider,{value:l,children:t})},Bt=Object(ue.a)((function(){return Object(dt.a)({tabsContent:{height:"200px"}})})),zt="Bearer ",qt=[{title:"No auth",id:"NO_AUTH"},{title:"Basic Auth",id:"BASIC_AUTH"},{title:"Bearer Token",id:"BEARER_AUTH"}],Yt=function(e){var t=Bt(),n=e.onClose,c=e.open,o=Pt(),i=o.saveAuthLocally,l=o.basicData,u=o.bearerData,j=o.authMethod,d=Object(r.useContext)(Nt).dispatch,b=Object(r.useState)(i),O=Object(s.a)(b,2),h=O[0],x=O[1],m=Object(r.useState)(l||{password:"",login:""}),v=Object(s.a)(m,2),g=v[0],E=v[1],S=Object(r.useState)((null===u||void 0===u?void 0:u.token)||zt),T=Object(s.a)(S,2),A=T[0],C=T[1],_=Object(r.useState)(qt.findIndex((function(e){return e.id===j}))||0),R=Object(s.a)(_,2),U=R[0],k=R[1],D=function(){n()};return Object(a.jsxs)(jt.a,{onClose:D,"aria-labelledby":"simple-dialog-title",open:c,children:[Object(a.jsx)(ut.a,{id:"simple-dialog-title",children:"Request Auth Settings"}),Object(a.jsxs)(bt.a,{children:[Object(a.jsx)(Ot.a,{children:"This affects Authorization header sent to the server you specify. Not shown in URL and can be optionally stored on a client side"}),Object(a.jsx)(ht.a,{value:U,onChange:function(e,t){k(t)},indicatorColor:"primary",textColor:"primary",children:qt.map((function(e){return Object(a.jsx)(pt.a,{label:e.title},e.id)}))}),Object(a.jsxs)(p.a,{p:0,display:"flex",flexDirection:"column",className:t.tabsContent,children:[Object(a.jsxs)(p.a,{flexGrow:1,children:[Object(a.jsx)(Tt,{value:U,index:0,children:Object(a.jsx)(f.a,{style:{fontStyle:"italic"},children:"No Authorization Header"})}),Object(a.jsxs)(Tt,{value:U,index:1,children:[Object(a.jsxs)(ft.a,{margin:"dense",fullWidth:!0,children:[Object(a.jsx)(xt.a,{htmlFor:"basic-login",children:"User"}),Object(a.jsx)(mt.a,{id:"basic-login",startAdornment:Object(a.jsx)(vt.a,{position:"start",children:Object(a.jsx)(Ct.a,{})}),required:!0,onChange:function(e){return E((function(t){return Object(w.a)(Object(w.a)({},t),{},{login:e.target.value||""})}))},value:(null===g||void 0===g?void 0:g.login)||""})]}),Object(a.jsxs)(ft.a,{margin:"dense",fullWidth:!0,children:[Object(a.jsx)(xt.a,{htmlFor:"basic-pass",children:"Password"}),Object(a.jsx)(mt.a,{id:"basic-pass",startAdornment:Object(a.jsx)(vt.a,{position:"start",children:Object(a.jsx)(_t.a,{})}),onChange:function(e){return E((function(t){return Object(w.a)(Object(w.a)({},t),{},{password:e.target.value||""})}))},value:(null===g||void 0===g?void 0:g.password)||""})]})]}),Object(a.jsx)(Tt,{value:U,index:2,children:Object(a.jsx)(Qe.a,{id:"bearer-auth",label:"Bearer token",multiline:!0,fullWidth:!0,value:A,onChange:function(e){var t=e.target.value;t.startsWith(zt)?C(t):C(zt)},InputProps:{onPaste:function(e){var t=e.clipboardData.getData("text/plain");t.startsWith(zt)?C(t):C(zt+t),e.preventDefault()}},rowsMax:6})})]}),Object(a.jsxs)(ft.a,{children:[Object(a.jsx)(y.a,{control:Object(a.jsx)(yt.a,{checked:h,onChange:function(){return x((function(e){return!e}))},name:"checkedB",color:"primary"}),label:"Persist Auth Data Locally"}),Object(a.jsx)(gt.a,{children:h?"Auth Data and the Selected method will be saved to LocalStorage":"Auth Data won't be saved. All previously saved Auth Data will be removed"})]})]})]}),Object(a.jsx)(Et.a,{children:Object(a.jsx)(St.a,{onClick:function(){switch(U){case 0:d({type:"SET_NO_AUTH",payload:{checkbox:h}});break;case 1:d({type:"SET_BASIC_AUTH",payload:{checkbox:h,value:g}});break;case 2:d({type:"SET_BEARER_AUTH",payload:{checkbox:h,value:{token:A}}})}D()},color:"primary",children:"Apply"})})]})},Ft=n(190),Qt=n.n(Ft),Wt=n(380),Gt=n(192),Jt=n.n(Gt),Vt=function(){var e=ce(),t=e.serverUrl,n=e.query,c=e.time.duration,o=oe(),i=ce().queryControls.autocomplete,l=Object(r.useState)(!1),u=Object(s.a)(l,2),j=u[0],d=u[1],b=Object(r.useState)(!0),O=Object(s.a)(b,2),h=O[0],x=O[1],m=Object(r.useState)(!1),v=Object(s.a)(m,2),T=v[0],A=v[1],C=Object(r.useRef)(null),w=Object(r.useRef)(null),_=function(){return o({type:"RUN_QUERY"})};return Object(a.jsxs)(a.Fragment,{children:[Object(a.jsxs)(ze.a,{expanded:h,onChange:function(){return x((function(e){return!e}))},children:[Object(a.jsxs)(qe.a,{expandIcon:Object(a.jsx)(it.a,{}),"aria-controls":"panel1a-content",id:"panel1a-header",children:[Object(a.jsx)(p.a,{mr:2,children:Object(a.jsx)(f.a,{variant:"h6",component:"h2",children:"Query Configuration"})}),Object(a.jsx)(p.a,{flexGrow:1,onClick:function(e){return e.stopPropagation()},onFocusCapture:function(e){return e.stopPropagation()},children:Object(a.jsx)(Wt.a,{disablePortal:!h,container:w.current,children:Object(a.jsx)($e,{server:t,query:n,oneLiner:!h,autocomplete:i,runQuery:_,setQuery:function(e){return o({type:"SET_QUERY",payload:e})}})})})]}),Object(a.jsx)(Ye.a,{children:Object(a.jsxs)(Fe.a,{container:!0,spacing:2,children:[Object(a.jsx)(Fe.a,{item:!0,xs:12,md:6,children:Object(a.jsxs)(p.a,{children:[Object(a.jsxs)(p.a,{py:2,display:"flex",alignItems:"center",children:[Object(a.jsx)(Qe.a,{variant:"outlined",fullWidth:!0,label:"Server URL",value:t,inputProps:{style:{fontFamily:"Monospace"}},onChange:function(e){var t=e.target.value;o({type:"SET_SERVER",payload:t})}}),Object(a.jsx)(p.a,{ml:1,children:Object(a.jsx)(E.a,{title:"Execute Query",children:Object(a.jsx)(S.a,{onClick:_,children:Object(a.jsx)(Qt.a,{})})})}),Object(a.jsx)(p.a,{children:Object(a.jsx)(E.a,{title:"Request Auth Settings",children:Object(a.jsx)(S.a,{onClick:function(){return d(!0)},children:Object(a.jsx)(lt.a,{})})})})]}),Object(a.jsxs)(p.a,{py:2,display:"flex",children:[Object(a.jsx)(p.a,{flexGrow:1,mr:2,children:Object(a.jsx)("div",{ref:w})}),Object(a.jsxs)("div",{children:[Object(a.jsx)(E.a,{title:"Query Editor Settings",children:Object(a.jsx)(S.a,{onClick:function(){return A(!T)},children:Object(a.jsx)(Jt.a,{ref:C})})}),Object(a.jsx)(et.a,{open:T,transformOrigin:{vertical:-20,horizontal:"left"},onClose:function(){return A(!1)},anchorEl:C.current,children:Object(a.jsx)(p.a,{p:2,children:Object(a.jsx)(y.a,{control:Object(a.jsx)(g.a,{size:"small",checked:i,onChange:function(){o({type:"TOGGLE_AUTOCOMPLETE"}),Y("AUTOCOMPLETE",!i)}}),label:"Autocomplete"})})})]})]})]})}),Object(a.jsx)(Fe.a,{item:!0,xs:8,md:6,children:Object(a.jsx)(p.a,{style:{borderRadius:"4px",borderColor:"#b9b9b9",borderStyle:"solid",borderWidth:"1px",height:"calc(100% - 18px)",marginTop:"16px"},children:Object(a.jsx)(ct,{setDuration:function(e){return o({type:"SET_DURATION",payload:e})},duration:c})})})]})})]}),Object(a.jsx)(Yt,{open:j,onClose:function(){return d(!1)}})]})},Zt=n(146),Kt=n.n(Zt),Xt=n(193),$t=function(){var e=ce(),t=e.query,n=e.displayType,a=e.serverUrl,c=e.time.period,o=Pt(),i=o.basicData,l=o.bearerData,u=o.authMethod,j=Object(r.useState)(!1),d=Object(s.a)(j,2),b=d[0],O=d[1],h=Object(r.useState)(),p=Object(s.a)(h,2),f=p[0],x=p[1],m=Object(r.useState)(),v=Object(s.a)(m,2),y=v[0],g=v[1],E=Object(r.useState)(),S=Object(s.a)(E,2),T=S[0],A=S[1];Object(r.useEffect)((function(){T&&(x(void 0),g(void 0))}),[T]);var C=Object(r.useMemo)((function(){if(c){if(!a)return void A("Please enter Server URL");if(!t.trim())return void A("Please enter a valid Query and execute it");if(function(e){var t;try{t=new URL(e)}catch(n){return!1}return"http:"===t.protocol||"https:"===t.protocol}(a)){var e=(c.end-c.start)/2,r=Object(w.a)(Object(w.a)({},c),{},{start:c.start-e,end:c.end+e});return"chart"===n?function(e,t,n){return"".concat(e,"/api/v1/query_range?query=").concat(encodeURIComponent(t),"&start=").concat(n.start,"&end=").concat(n.end,"&step=").concat(n.step)}(a,t,r):function(e,t,n){return"".concat(e,"/api/v1/query?query=").concat(encodeURIComponent(t),"&start=").concat(n.start,"&end=").concat(n.end,"&step=").concat(n.step)}(a,t,c)}A("Please provide a valid URL")}}),[a,c,n]);return Object(r.useEffect)((function(){Object(Xt.a)(Kt.a.mark((function e(){var a,r,c,o;return Kt.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!C){e.next=38;break}return a=new Headers,"BASIC_AUTH"===u&&a.set("Authorization","Basic "+btoa("".concat((null===i||void 0===i?void 0:i.login)||"",":").concat((null===i||void 0===i?void 0:i.password)||""))),"BEARER_AUTH"===u&&a.set("Authorization",(null===l||void 0===l?void 0:l.token)||""),O(!0),e.prev=5,e.next=8,fetch(C,{headers:a});case 8:if(!(r=e.sent).ok){e.next=18;break}return Y("LAST_QUERY",t),e.next=13,r.json();case 13:c=e.sent,A(void 0),"chart"===n?x(c.data.result):g(c.data.result),e.next=32;break;case 18:return e.t0=A,e.next=21,r.json();case 21:if(e.t2=o=e.sent,e.t1=null===e.t2,e.t1){e.next=25;break}e.t1=void 0===o;case 25:if(!e.t1){e.next=29;break}e.t3=void 0,e.next=30;break;case 29:e.t3=o.error;case 30:e.t4=e.t3,(0,e.t0)(e.t4);case 32:e.next=37;break;case 34:e.prev=34,e.t5=e.catch(5),A(e.t5.message);case 37:O(!1);case 38:case"end":return e.stop()}}),e,null,[[5,34]])})))()}),[C,a,n]),{fetchUrl:C,isLoading:b,graphData:f,liveData:y,error:T}},en=function(e){var t=e.data,n=d().showInfoMessage,c=Object(r.useMemo)((function(){return JSON.stringify(t,null,2)}),[t]);return Object(a.jsxs)(p.a,{position:"relative",children:[Object(a.jsx)(p.a,{flexDirection:"column",justifyContent:"flex-end",display:"flex",style:{position:"fixed",right:"16px"},children:Object(a.jsx)(St.a,{variant:"outlined",onClick:function(e){navigator.clipboard.writeText(c),n("Formatted JSON has been copied"),e.preventDefault()},children:"Copy JSON"})}),Object(a.jsx)("pre",{children:c})]})},tn=n(194),nn=n.n(tn),an=function(e){var t=e.url,n=d().showInfoMessage;return Object(a.jsx)(p.a,{pl:2,py:1,flexShrink:0,display:"flex",children:Object(a.jsx)(E.a,{title:"Copy Query URL",children:Object(a.jsx)(S.a,{size:"small",onClick:function(e){t&&(navigator.clipboard.writeText(t),n("Value has been copied"),e.preventDefault())},children:Object(a.jsx)(nn.a,{style:{color:"white"}})})})})},rn=function(){var e=ce(),t=e.displayType,n=e.time.period,r=$t(),c=r.fetchUrl,o=r.isLoading,i=r.liveData,s=r.graphData,l=r.error;return Object(a.jsxs)(a.Fragment,{children:[Object(a.jsx)(O.a,{position:"static",children:Object(a.jsxs)(h.a,{children:[Object(a.jsxs)(p.a,{display:"flex",children:[Object(a.jsxs)(f.a,{variant:"h5",children:[Object(a.jsx)("span",{style:{fontWeight:"bolder"},children:"VM"}),Object(a.jsx)("span",{style:{fontWeight:"lighter"},children:"UI"})]}),Object(a.jsx)("div",{style:{fontSize:"10px",marginTop:"-2px"},children:Object(a.jsx)("div",{children:"BETA"})})]}),Object(a.jsx)("div",{style:{fontSize:"10px",position:"absolute",top:"40px",opacity:".4"},children:Object(a.jsx)(x.a,{color:"inherit",href:"https://github.com/VictoriaMetrics/vmui/issues/new",target:"_blank",children:"Create an issue"})}),Object(a.jsx)(p.a,{ml:4,flexGrow:1,children:Object(a.jsx)(de,{})}),Object(a.jsx)(Ee,{}),Object(a.jsx)(an,{url:c})]})}),Object(a.jsxs)(p.a,{p:2,display:"grid",gridTemplateRows:"auto 1fr",gridGap:"20px",style:{minHeight:"calc(100vh - 64px)"},children:[Object(a.jsx)(p.a,{children:Object(a.jsx)(Vt,{})}),Object(a.jsxs)(p.a,{height:"100%",children:[o&&Object(a.jsx)(m.a,{in:o,style:{transitionDelay:o?"300ms":"0ms"},children:Object(a.jsx)(p.a,{alignItems:"center",justifyContent:"center",flexDirection:"column",display:"flex",style:{width:"100%",maxWidth:"calc(100vw - 32px)",position:"absolute",height:"50%",background:"linear-gradient(rgba(255,255,255,.7), rgba(255,255,255,.7), rgba(255,255,255,0))"},children:Object(a.jsx)(v.a,{})})}),Object(a.jsxs)(p.a,{height:"100%",py:3,px:6,bgcolor:"#fff",children:[l&&Object(a.jsx)(u.a,{color:"error",severity:"error",style:{fontSize:"14px"},children:l}),s&&n&&"chart"===t&&Object(a.jsx)(Ue,{data:s}),i&&"code"===t&&Object(a.jsx)(en,{data:i}),i&&"table"===t&&Object(a.jsx)(Be,{data:i})]})]})]})]})},cn=n(198),on=n(407),sn=n(406),ln=n(33),un=n(195),jn=function(){var e=Object(cn.a)({typography:{fontSize:10}});return Object(a.jsxs)(a.Fragment,{children:[Object(a.jsx)(sn.a,{})," ",Object(a.jsxs)(ln.a,{utils:un.a,children:[" ",Object(a.jsxs)(on.a,{theme:e,children:[" ",Object(a.jsxs)(se,{children:[" ",Object(a.jsxs)(Lt,{children:[" ",Object(a.jsxs)(b,{children:[" ",Object(a.jsx)(rn,{})]})]})]})]})]})]})},dn=function(e){e&&e instanceof Function&&n.e(3).then(n.bind(null,423)).then((function(t){var n=t.getCLS,a=t.getFID,r=t.getFCP,c=t.getLCP,o=t.getTTFB;n(e),a(e),r(e),c(e),o(e)}))};i.a.render(Object(a.jsx)(c.a.StrictMode,{children:Object(a.jsx)(jn,{})}),document.getElementById("root")),dn()}},[[341,1,2]]]);