mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-22 08:26:19 +01:00
893af0a92c
* fix: set date in query string in utc format * app/vmselect: `make vmui-update` Co-authored-by: Aliaksandr Valialkin <valyala@victoriametrics.com>
1 line
30 KiB
JavaScript
1 line
30 KiB
JavaScript
(this.webpackJsonpvmui=this.webpackJsonpvmui||[]).push([[0],{229:function(e,t,n){},342: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(229),n(20)),l=n(415),u=n(413),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(406),h=n(396),p=n(410),f=n(95),x=n(389),m=n(398),v=n(377),y=n(379),g=n(380),E=n(418),S=n(208),T=n(182),A=n.n(T),C=n(13),w=n(14),_=n(44),R=n.n(_),U=n(178),k=n.n(U),D=n(179),H=n.n(D);R.a.extend(k.a),R.a.extend(H.a);var M,I=window.screen.availWidth/7.68,N=1e3,P=1578e8,L="YYYY-MM-DD[T]HH:mm:ss",B=[{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"}],z=B.map((function(e){return e.short})),q=function(e){var t=e.match(/\d+/g),n=e.match(/[a-zA-Z]+/g);if(n&&t&&z.includes(n[0]))return Object(C.a)({},n[0],t[0])},Y=function(e,t){var n=(t||new Date).valueOf()/1e3,a=e.trim().split(" ").reduce((function(e,t){var n=q(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/I),date:F(t||new Date)}},F=function(e){return R()(e).utc().format(L)},Q=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(" ")},W=function(e){return new Date(1e3*e)},G=function(e,t){t?window.localStorage.setItem(e,JSON.stringify({value:t})):V([e])},J=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}},V=function(e){return e.forEach((function(e){return window.localStorage.removeItem(e)}))},Z=["BASIC_AUTH_DATA","BEARER_AUTH_DATA"],K=n(180),X=n.n(K),$=n(144),ee=n.n($),te={query:"g0.expr","time.duration":"g0.range_input","time.period.date":"g0.end_input","time.period.step":"g0.step_input",stacked:"g0.stacked"},ne=function(e){var t=new Map(Object.entries(te)),n=[];t.forEach((function(t,a){encodeURIComponent(t);var r=ee()(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("&"))},ae=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:window.location.search,a=X.a.parse(n,{ignoreQueryPrefix:!0});return ee()(a,e,t||"")},re=ae("g0.range_input","1h"),ce=(M=ae("g0.end_input",new Date(R()().utc().format(L))),R()(M).utcOffset(0,!0).local().format(L)),oe={serverUrl:window.location.href.replace(/\/(?:prometheus\/)?(?:graph|vmui)\/.*/,"/prometheus/"),displayType:"chart",query:ae("g0.expr",J("LAST_QUERY")||"\n"),time:{duration:re,period:Y(re,new Date(ce))},queryControls:{autoRefresh:!1,autocomplete:J("AUTOCOMPLETE")||!1}};function ie(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:Y(t.payload,W(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:Y(e.time.duration,t.payload)})});case"SET_PERIOD":var n=function(e){var t=e.to.valueOf()-e.from.valueOf();return Q(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:Y(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:Y(e.time.duration,W(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:Y(e.time.duration)})});default:throw new Error}}var se=Object(r.createContext)({}),le=function(){return Object(r.useContext)(se).state},ue=function(){return Object(r.useContext)(se).dispatch},je=Object.entries(oe).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,ae(a)||r))}),{}),de=function(e){var t=e.children,n=Object(r.useReducer)(ie,je),c=Object(s.a)(n,2),o=c[0],i=c[1];Object(r.useEffect)((function(){ne(o)}),[o]);var l=Object(r.useMemo)((function(){return{state:o,dispatch:i}}),[o,i]);return Object(a.jsx)(se.Provider,{value:l,children:t})},be=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")})})]})},Oe=n(378),he=Object(Oe.a)({colorizing:{color:"white"}}),pe=function(){var e=he(),t=ue(),n=le().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)(be,{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"}})})})})]})]})},fe=n(185),xe=n.n(fe),me=n(183),ve=n.n(me),ye=n(184),ge=n.n(ye),Ee=n(382),Se=n(422),Te=n(11),Ae=Object(Te.a)({root:{padding:6,color:"white","&.Mui-selected":{color:"white"}}})(Ee.a),Ce=function(){var e=le().displayType,t=ue();return Object(a.jsxs)(Se.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)(Ae,{value:"chart","aria-label":"display as chart",children:[Object(a.jsx)(ve.a,{}),"\xa0Query Range as Chart"]}),Object(a.jsxs)(Ae,{value:"code","aria-label":"display as code",children:[Object(a.jsx)(ge.a,{}),"\xa0Instant Query as JSON"]}),Object(a.jsxs)(Ae,{value:"table","aria-label":"display as table",children:[Object(a.jsx)(xe.a,{}),"\xa0Instant Query as Table"]})]})},we=n(203),_e=n(122),Re=(n(341),n(145)),Ue=n.n(Re),ke=function(e){var t=e.data,n=void 0===t?[]:t,c=le().time,o=c.duration,i=c.period,l=ue(),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(_e.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:Ue()((function(e){var t=e.chart.scales.x,n=t.min,a=t.max;if(n&&a){var r=Y(o,new Date(a)),c=r.start,i=r.end;l({type:"SET_PERIOD",payload:{from:W(c),to:W(i)}})}}),750)},zoom:{pinch:{enabled:!0},wheel:{enabled:!0,speed:.05},mode:"x",onZoom:Ue()((function(e){var t=e.chart.scales.x,n=t.min,a=t.max;if(n&&a){var r=a-n;r<N&&(a=n+N),r>P&&(n=a-P),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)(we.a,{data:d,options:h,ref:O})})},De=n(46),He=n(202);De.a.register(He.a);var Me=function(e){var t=e.data,n=void 0===t?[]:t;return Object(a.jsx)(a.Fragment,{children:n.length>0?Object(a.jsx)(ke,{data:n}):Object(a.jsx)("div",{style:{textAlign:"center"},children:"No data to show"})})},Ie=n(383),Ne=n(206),Pe=n(384),Le=n(385),Be=n(386),ze=n(387),qe=n(388),Ye=Object(Oe.a)({deemphasized:{opacity:.4}}),Fe=function(e){var t=e.data,n=Ye(),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)(Ie.a,{component:Ne.a,children:Object(a.jsxs)(Pe.a,{"aria-label":"simple table",children:[Object(a.jsx)(Le.a,{children:Object(a.jsxs)(Be.a,{children:[c.map((function(e,t){return Object(a.jsx)(ze.a,{style:{textTransform:"capitalize"},children:e.key},t)})),Object(a.jsx)(ze.a,{align:"right",children:"Value"})]})}),Object(a.jsx)(qe.a,{children:o.map((function(e,t){return Object(a.jsxs)(Be.a,{children:[e.metadata.map((function(e,r){var c=o[t-1]&&o[t-1].metadata[r];return Object(a.jsx)(ze.a,{className:c===e?n.deemphasized:void 0,children:e},r)})),Object(a.jsx)(ze.a,{align:"right",children:e.value})]},t)}))})]})}):Object(a.jsx)("div",{style:{textAlign:"center"},children:"No data to show"})})},Qe=n(416),We=n(404),Ge=n(405),Je=n(401),Ve=n(411),Ze=n(5),Ke=n(10),Xe=n(117),$e=n(200),et=n(201),tt={windows:"Windows",mac:"Mac OS",linux:"Linux"},nt=function(){return(Object.values(tt).find((function(e){return navigator.userAgent.indexOf(e)>=0}))||"unknown")===tt.mac},at=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 Ke.d({parent:j.current})),function(){return null===O||void 0===O?void 0:O.destroy()}}),[]),Object(r.useEffect)((function(){var e=new $e.a;e.activateCompletion(u),e.setComplete({url:o});var a=Ke.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(Ze.e.create({doc:t,extensions:[et.a,Object(Ke.k)(Xe.a),a,e.asExtension(),Object(Ke.k)([{key:nt()?"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})})},rt=n(392),ct=n(409),ot=function(){return Object(a.jsx)(Ie.a,{component:Ne.a,children:Object(a.jsxs)(Pe.a,{"aria-label":"simple table",size:"small",children:[Object(a.jsx)(Le.a,{children:Object(a.jsxs)(Be.a,{children:[Object(a.jsx)(ze.a,{children:"Long"}),Object(a.jsx)(ze.a,{children:"Short"})]})}),Object(a.jsx)(qe.a,{children:B.map((function(e,t){return Object(a.jsxs)(Be.a,{children:[Object(a.jsx)(ze.a,{component:"th",scope:"row",children:e.long}),Object(a.jsx)(ze.a,{children:e.short})]},t)}))})]})})},it=Object(Oe.a)({inlineBtn:{"&:hover":{cursor:"pointer"}}}),st=function(e){var t=e.handler,n=e.text,r=it();return Object(a.jsx)(x.a,{component:"span",className:r.inlineBtn,onClick:t,children:n})},lt=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=le().time,y=v.period.end,g=v.duration,E=ue(),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(function(e){return R()(e).format(L)}(W(y)))}),[y]),Object(r.useEffect)((function(){if(!i){var e=function(e){var t=e.trim().split(" ").reduce((function(e,t){var n=q(t);return n?Object(w.a)(Object(w.a)({},e),n):Object(w.a)({},e)}),{}),n=R.a.duration(t).asMilliseconds();return n<N?Q(N):n>P?Q(P):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)(Ve.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)(rt.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)(ot,{})}),Object(a.jsx)(st,{handler:function(){return C("5m")},text:"5m"}),",\xa0",Object(a.jsx)(st,{handler:function(){return C("1h")},text:"1h"}),",\xa0",Object(a.jsx)(st,{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)(ct.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)(st,{handler:function(){return E({type:"RUN_QUERY_TO_NOW"})},text:"Switch to now"})]})})]})]})},ut=n(190),jt=n.n(ut),dt=n(192),bt=n.n(dt),Ot=n(402),ht=n(421),pt=n(420),ft=n(399),xt=n(403),mt=n(412),vt=n(394),yt=n(391),gt=n(419),Et=n(390),St=n(397),Tt=n(414),At=n(393),Ct=n(400),wt=n(395),_t=function(e){var t=e.children,n=e.value,r=e.index,c=Object(_e.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})}))},Rt=n(188),Ut=n.n(Rt),kt=n(189),Dt=n.n(kt),Ht={authMethod:"NO_AUTH",saveAuthLocally:!1},Mt=J("AUTH_TYPE"),It=J("BASIC_AUTH_DATA"),Nt=J("BEARER_AUTH_DATA"),Pt=Object(w.a)(Object(w.a)({},Ht),{},{authMethod:Mt||Ht.authMethod,basicData:It,bearerData:Nt,saveAuthLocally:!(!It&&!Nt)}),Lt=function(){V(Z)};function Bt(e,t){switch(t.type){case"SET_BASIC_AUTH":return t.payload.checkbox?G("BASIC_AUTH_DATA",t.payload.value):Lt(),G("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?G("BEARER_AUTH_DATA",t.payload.value):Lt(),G("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&&Lt(),G("AUTH_TYPE","NO_AUTH"),Object(w.a)(Object(w.a)({},e),{},{authMethod:"NO_AUTH"});default:throw new Error}}var zt=Object(r.createContext)({}),qt=function(){return Object(r.useContext)(zt).state},Yt=function(e){var t=e.children,n=Object(r.useReducer)(Bt,Pt),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)(zt.Provider,{value:l,children:t})},Ft=Object(Oe.a)((function(){return Object(pt.a)({tabsContent:{height:"200px"}})})),Qt="Bearer ",Wt=[{title:"No auth",id:"NO_AUTH"},{title:"Basic Auth",id:"BASIC_AUTH"},{title:"Bearer Token",id:"BEARER_AUTH"}],Gt=function(e){var t=Ft(),n=e.onClose,c=e.open,o=qt(),i=o.saveAuthLocally,l=o.basicData,u=o.bearerData,j=o.authMethod,d=Object(r.useContext)(zt).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)||Qt),T=Object(s.a)(S,2),A=T[0],C=T[1],_=Object(r.useState)(Wt.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)(ht.a,{onClose:D,"aria-labelledby":"simple-dialog-title",open:c,children:[Object(a.jsx)(Ot.a,{id:"simple-dialog-title",children:"Request Auth Settings"}),Object(a.jsxs)(ft.a,{children:[Object(a.jsx)(xt.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)(mt.a,{value:U,onChange:function(e,t){k(t)},indicatorColor:"primary",textColor:"primary",children:Wt.map((function(e){return Object(a.jsx)(vt.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)(_t,{value:U,index:0,children:Object(a.jsx)(f.a,{style:{fontStyle:"italic"},children:"No Authorization Header"})}),Object(a.jsxs)(_t,{value:U,index:1,children:[Object(a.jsxs)(yt.a,{margin:"dense",fullWidth:!0,children:[Object(a.jsx)(gt.a,{htmlFor:"basic-login",children:"User"}),Object(a.jsx)(Et.a,{id:"basic-login",startAdornment:Object(a.jsx)(St.a,{position:"start",children:Object(a.jsx)(Ut.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)(yt.a,{margin:"dense",fullWidth:!0,children:[Object(a.jsx)(gt.a,{htmlFor:"basic-pass",children:"Password"}),Object(a.jsx)(Et.a,{id:"basic-pass",startAdornment:Object(a.jsx)(St.a,{position:"start",children:Object(a.jsx)(Dt.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)(_t,{value:U,index:2,children:Object(a.jsx)(Ve.a,{id:"bearer-auth",label:"Bearer token",multiline:!0,fullWidth:!0,value:A,onChange:function(e){var t=e.target.value;t.startsWith(Qt)?C(t):C(Qt)},InputProps:{onPaste:function(e){var t=e.clipboardData.getData("text/plain");t.startsWith(Qt)?C(t):C(Qt+t),e.preventDefault()}},rowsMax:6})})]}),Object(a.jsxs)(yt.a,{children:[Object(a.jsx)(y.a,{control:Object(a.jsx)(Tt.a,{checked:h,onChange:function(){return x((function(e){return!e}))},name:"checkedB",color:"primary"}),label:"Persist Auth Data Locally"}),Object(a.jsx)(At.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)(Ct.a,{children:Object(a.jsx)(wt.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"})})]})},Jt=n(191),Vt=n.n(Jt),Zt=n(381),Kt=n(193),Xt=n.n(Kt),$t=function(){var e=le(),t=e.serverUrl,n=e.query,c=e.time.duration,o=ue(),i=le().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)(Qe.a,{expanded:h,onChange:function(){return x((function(e){return!e}))},children:[Object(a.jsxs)(We.a,{expandIcon:Object(a.jsx)(jt.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)(Zt.a,{disablePortal:!h,container:w.current,children:Object(a.jsx)(at,{server:t,query:n,oneLiner:!h,autocomplete:i,runQuery:_,setQuery:function(e){return o({type:"SET_QUERY",payload:e})}})})})]}),Object(a.jsx)(Ge.a,{children:Object(a.jsxs)(Je.a,{container:!0,spacing:2,children:[Object(a.jsx)(Je.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)(Ve.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)(Vt.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)(bt.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)(Xt.a,{ref:C})})}),Object(a.jsx)(rt.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"}),G("AUTOCOMPLETE",!i)}}),label:"Autocomplete"})})})]})]})]})}),Object(a.jsx)(Je.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)(lt,{setDuration:function(e){return o({type:"SET_DURATION",payload:e})},duration:c})})})]})})]}),Object(a.jsx)(Gt,{open:j,onClose:function(){return d(!1)}})]})},en=n(146),tn=n.n(en),nn=n(194),an=function(){var e=le(),t=e.query,n=e.displayType,a=e.serverUrl,c=e.time.period,o=qt(),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(nn.a)(tn.a.mark((function e(){var a,r,c,o;return tn.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 G("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}},rn=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)(wt.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})]})},cn=n(195),on=n.n(cn),sn=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)(on.a,{style:{color:"white"}})})})})},ln=function(){var e=le(),t=e.displayType,n=e.time.period,r=an(),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)(pe,{})}),Object(a.jsx)(Ce,{}),Object(a.jsx)(sn,{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)($t,{})}),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)(Me,{data:s}),i&&"code"===t&&Object(a.jsx)(rn,{data:i}),i&&"table"===t&&Object(a.jsx)(Fe,{data:i})]})]})]})]})},un=n(199),jn=n(408),dn=n(407),bn=n(33),On=n(196),hn=function(){var e=Object(un.a)({typography:{fontSize:10}});return Object(a.jsxs)(a.Fragment,{children:[Object(a.jsx)(dn.a,{})," ",Object(a.jsxs)(bn.a,{utils:On.a,children:[" ",Object(a.jsxs)(jn.a,{theme:e,children:[" ",Object(a.jsxs)(de,{children:[" ",Object(a.jsxs)(Yt,{children:[" ",Object(a.jsxs)(b,{children:[" ",Object(a.jsx)(ln,{})]})]})]})]})]})]})},pn=function(e){e&&e instanceof Function&&n.e(3).then(n.bind(null,424)).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)(hn,{})}),document.getElementById("root")),pn()}},[[342,1,2]]]); |