mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-11 14:53:49 +00:00
0ff8fcac6a
* Run `vmui-update` * Document the changes in README.md and CHANGELOG.md
1 line
No EOL
30 KiB
JavaScript
1 line
No EOL
30 KiB
JavaScript
(this.webpackJsonpvmui=this.webpackJsonpvmui||[]).push([[0],{176:function(e,t,n){},185:function(e,t,n){},189: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(176),n(17)),l=n(262),u=n(260),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],f=Object(r.useState)(void 0),p=Object(s.a)(f,2),x=p[0],v=p[1];Object(r.useEffect)((function(){x&&(i({message:x,key:(new Date).getTime()}),h(!0))}),[x]);return Object(a.jsxs)(j.Provider,{value:{showInfoMessage:v},children:[Object(a.jsx)(l.a,{open:O,autoHideDuration:4e3,onClose:function(e,t){"clickaway"!==t&&(v(void 0),h(!1))},children:Object(a.jsx)(u.a,{children:o.message})},o.key),t]})},O=n(253),h=n(243),f=n(257),p=n(85),x=n(236),v=n(245),m=n(224),y=n(226),g=n(227),E=n(265),T=n(155),A=n(130),S=n.n(A),w=n(13),C=n(14),_=n(44),R=n.n(_),U=n(126),D=n.n(U),k=n(127),M=n.n(k);R.a.extend(D.a),R.a.extend(M.a);var I,L=window.screen.availWidth/2,H=1e3,N=1578e8,B="YYYY-MM-DD[T]HH:mm:ss",P=[{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"}],Y=P.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&&Y.includes(n[0]))return Object(w.a)({},n[0],t[0])},z=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(C.a)(Object(C.a)({},e),n):Object(C.a)({},e)}),{}),r=R.a.duration(a).asSeconds();return{start:n-r,end:n,step:Math.ceil(r/L),date:Q(t||new Date)}},Q=function(e){return R()(e).utc().format(B)},F=function(e){var t=Math.floor(e%1e3),n=Math.floor(e/1e3%60),a=Math.floor(e/1e3/60%60),r=Math.floor(e/1e3/3600%24),c=Math.floor(e/864e5),o=["d","h","m","s","ms"];return[c,r,a,n,t].map((function(e,t){return e?"".concat(e).concat(o[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)}))},K=["BASIC_AUTH_DATA","BEARER_AUTH_DATA"],X=n(128),Z=n.n(X),$=n(113),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=Z.a.parse(n,{ignoreQueryPrefix:!0});return ee()(a,e,t||"")},re=ae("g0.range_input","1h"),ce=(I=ae("g0.end_input",new Date(R()().utc().format(B))),R()(I).utcOffset(0,!0).local().format(B)),oe={serverUrl:window.location.href.replace(/\/(?:prometheus\/)?(?:graph|vmui)\/.*/,"/prometheus/"),displayType:"chart",query:ae("g0.expr",J("LAST_QUERY")||"\n"),time:{duration:re,period:z(re,new Date(ce))},queryControls:{autoRefresh:!1,autocomplete:J("AUTOCOMPLETE")||!1}};function ie(e,t){switch(t.type){case"SET_DISPLAY_TYPE":return Object(C.a)(Object(C.a)({},e),{},{displayType:t.payload});case"SET_SERVER":return Object(C.a)(Object(C.a)({},e),{},{serverUrl:t.payload});case"SET_QUERY":return Object(C.a)(Object(C.a)({},e),{},{query:t.payload});case"SET_DURATION":return Object(C.a)(Object(C.a)({},e),{},{time:Object(C.a)(Object(C.a)({},e.time),{},{duration:t.payload,period:z(t.payload,W(e.time.period.end))})});case"SET_UNTIL":return Object(C.a)(Object(C.a)({},e),{},{time:Object(C.a)(Object(C.a)({},e.time),{},{period:z(e.time.duration,t.payload)})});case"SET_PERIOD":var n=function(e){var t=e.to.valueOf()-e.from.valueOf();return F(t)}(t.payload);return Object(C.a)(Object(C.a)({},e),{},{queryControls:Object(C.a)(Object(C.a)({},e.queryControls),{},{autoRefresh:!1}),time:Object(C.a)(Object(C.a)({},e.time),{},{duration:n,period:z(n,t.payload.to)})});case"TOGGLE_AUTOREFRESH":return Object(C.a)(Object(C.a)({},e),{},{queryControls:Object(C.a)(Object(C.a)({},e.queryControls),{},{autoRefresh:!e.queryControls.autoRefresh})});case"TOGGLE_AUTOCOMPLETE":return Object(C.a)(Object(C.a)({},e),{},{queryControls:Object(C.a)(Object(C.a)({},e.queryControls),{},{autocomplete:!e.queryControls.autocomplete})});case"RUN_QUERY":return Object(C.a)(Object(C.a)({},e),{},{time:Object(C.a)(Object(C.a)({},e.time),{},{period:z(e.time.duration,W(e.time.period.end))})});case"RUN_QUERY_TO_NOW":return Object(C.a)(Object(C.a)({},e),{},{time:Object(C.a)(Object(C.a)({},e.time),{},{period:z(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(C.a)(Object(C.a)({},e),{},Object(w.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)(f.a,{position:"relative",display:"inline-flex",children:[Object(a.jsx)(m.a,Object(C.a)({variant:"determinate"},e)),Object(a.jsx)(f.a,{top:0,left:0,bottom:0,right:0,position:"absolute",display:"flex",alignItems:"center",justifyContent:"center",children:Object(a.jsx)(p.a,{variant:"caption",component:"div",children:"".concat(e.label,"s")})})]})},Oe=n(225),he=Object(Oe.a)({colorizing:{color:"white"}}),fe=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),p=Object(s.a)(h,2),x=p[0],v=p[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);v(t)}}),16);return function(){clearInterval(e)}}),[n,b,l]);var m=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)(f.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(){m()}}),Object(a.jsx)(E.a,{title:"Change delay refresh",children:Object(a.jsx)(f.a,{ml:1,children:Object(a.jsx)(T.a,{onClick:function(){m()},children:Object(a.jsx)(S.a,{style:{color:"white"}})})})})]})]})},pe=n(133),xe=n.n(pe),ve=n(131),me=n.n(ve),ye=n(132),ge=n.n(ye),Ee=n(229),Te=n(269),Ae=n(11),Se=Object(Ae.a)({root:{padding:6,color:"white","&.Mui-selected":{color:"white"}}})(Ee.a),we=function(){var e=le().displayType,t=ue();return Object(a.jsxs)(Te.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)(Se,{value:"chart","aria-label":"display as chart",children:[Object(a.jsx)(me.a,{}),"\xa0Query Range as Chart"]}),Object(a.jsxs)(Se,{value:"code","aria-label":"display as code",children:[Object(a.jsx)(ge.a,{}),"\xa0Instant Query as JSON"]}),Object(a.jsxs)(Se,{value:"table","aria-label":"display as table",children:[Object(a.jsx)(xe.a,{}),"\xa0Instant Query as Table"]})]})},Ce=n(25),_e=n(104),Re=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(", "),"}")},Ue=(n(188),n(134)),De=n.n(Ue),ke=(n(184),n(135)),Me=n.n(ke),Ie=(n(185),function(e){var t=e.data,n=void 0===t?[]:t,c=ue(),o=le().time.period,i=Object(r.useState)(),l=Object(s.a)(i,2),u=l[0],j=l[1],d=Object(r.useState)([]),b=Object(s.a)(d,2),O=b[0],h=b[1],f=Object(r.useState)({min:o.start,max:o.end}),p=Object(s.a)(f,2),x=p[0],v=p[1],m=Object(r.useRef)(null),y=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},g=Object(r.useMemo)((function(){for(var e=n.map((function(e){return e.values.map((function(e){return e[0]}))})).flat(),t=Math.min.apply(Math,Object(Ce.a)(e)),a=Math.max.apply(Math,Object(Ce.a)(e)),r=[],c=t;c<a;c+=o.step||1)r.push(c);return r}),[n]);Object(r.useEffect)((function(){var e=n.map((function(e){return g.map((function(t){var n=e.values.find((function(e){return e[0]===t}));return n?+n[1]:null}))})),t=n.map((function(e){return{label:Re(e),width:1,font:"11px Arial",stroke:y(Re(e))}}));h([{}].concat(Object(Ce.a)(t))),j([g].concat(Object(Ce.a)(e)))}),[n]);Object(r.useEffect)((function(){v({min:o.start,max:o.end})}),[o]),Object(r.useEffect)((function(){var e=(o.end-o.start)/3,t=e/(x.max-x.min);(x.max>o.end+e||x.min<o.start-e||t>=.7)&&c({type:"SET_PERIOD",payload:{from:new Date(1e3*x.min),to:new Date(1e3*x.max)}})}),[x]);var E={width:m.current?m.current.offsetWidth:400,height:500,series:O,plugins:[{hooks:{ready:function(e){e.over.addEventListener("mousedown",(function(t){if(0===t.button){t.preventDefault();var n=t.clientX,a=e.scales.x.min||1,r=e.scales.x.max||1,c=e.posToVal(1,"x")-e.posToVal(0,"x"),o=function(t){t.preventDefault();var o=c*(t.clientX-n),i=a-o,s=r-o;e.setScale("x",{min:i,max:s}),v({min:i,max:s})};document.addEventListener("mousemove",o),document.addEventListener("mouseup",(function e(){document.removeEventListener("mousemove",o),document.removeEventListener("mouseup",e)}))}})),e.over.addEventListener("wheel",(function(t){if(t.ctrlKey||t.metaKey){t.preventDefault();var n=e.over.getBoundingClientRect().width,a=e.cursor.left,r=void 0===a?n/2:a,c=r/n,o=e.posToVal(r,"x"),i=(e.scales.x.max||0)-(e.scales.x.min||0),s=t.deltaY<0?.85*i:i/.85,l=o-c*s,u=l+s;e.batch((function(){e.setScale("x",{min:l,max:u}),v({min:l,max:u})}))}}))}}}],cursor:{drag:{x:!1,y:!1}},axes:[{space:80},{show:!0,font:"10px Arial",values:function(e,t){return t.map((function(e){return e>1e3?Me()(e).format("0.0a"):e}))}}],scales:{x:{range:function(){return[x.min,x.max]}}}};return Object(a.jsx)("div",{ref:m,children:u&&Object(a.jsx)(De.a,{options:E,data:u})})}),Le=n(97),He=n(150);Le.a.register(He.a);var Ne=function(e){var t=e.data,n=void 0===t?[]:t;return Object(a.jsx)(a.Fragment,{children:n.length>0?Object(a.jsx)(Ie,{data:n}):Object(a.jsx)("div",{style:{textAlign:"center"},children:"No data to show"})})},Be=n(230),Pe=n(153),Ye=n(231),qe=n(232),ze=n(233),Qe=n(234),Fe=n(235),We=Object(Oe.a)({deemphasized:{opacity:.4}}),Ge=function(e){var t=e.data,n=We(),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)(Be.a,{component:Pe.a,children:Object(a.jsxs)(Ye.a,{"aria-label":"simple table",children:[Object(a.jsx)(qe.a,{children:Object(a.jsxs)(ze.a,{children:[c.map((function(e,t){return Object(a.jsx)(Qe.a,{style:{textTransform:"capitalize"},children:e.key},t)})),Object(a.jsx)(Qe.a,{align:"right",children:"Value"})]})}),Object(a.jsx)(Fe.a,{children:o.map((function(e,t){return Object(a.jsxs)(ze.a,{children:[e.metadata.map((function(e,r){var c=o[t-1]&&o[t-1].metadata[r];return Object(a.jsx)(Qe.a,{className:c===e?n.deemphasized:void 0,children:e},r)})),Object(a.jsx)(Qe.a,{align:"right",children:e.value})]},t)}))})]})}):Object(a.jsx)("div",{style:{textAlign:"center"},children:"No data to show"})})},Je=n(263),Ve=n(251),Ke=n(252),Xe=n(248),Ze=n(258),$e=n(5),et=n(10),tt=n(99),nt=n(148),at=n(149),rt={windows:"Windows",mac:"Mac OS",linux:"Linux"},ct=function(){return(Object.values(rt).find((function(e){return navigator.userAgent.indexOf(e)>=0}))||"unknown")===rt.mac},ot=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 et.d({parent:j.current})),function(){return null===O||void 0===O?void 0:O.destroy()}}),[]),Object(r.useEffect)((function(){var e=new nt.a;e.activateCompletion(u),e.setComplete({url:o});var a=et.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($e.e.create({doc:t,extensions:[at.a,Object(et.k)(tt.a),a,e.asExtension(),Object(et.k)([{key:ct()?"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})})},it=n(239),st=n(256),lt=function(){return Object(a.jsx)(Be.a,{component:Pe.a,children:Object(a.jsxs)(Ye.a,{"aria-label":"simple table",size:"small",children:[Object(a.jsx)(qe.a,{children:Object(a.jsxs)(ze.a,{children:[Object(a.jsx)(Qe.a,{children:"Long"}),Object(a.jsx)(Qe.a,{children:"Short"})]})}),Object(a.jsx)(Fe.a,{children:P.map((function(e,t){return Object(a.jsxs)(ze.a,{children:[Object(a.jsx)(Qe.a,{component:"th",scope:"row",children:e.long}),Object(a.jsx)(Qe.a,{children:e.short})]},t)}))})]})})},ut=Object(Oe.a)({inlineBtn:{"&:hover":{cursor:"pointer"}}}),jt=function(e){var t=e.handler,n=e.text,r=ut();return Object(a.jsx)(x.a,{component:"span",className:r.inlineBtn,onClick:t,children:n})},dt=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],v=h[1],m=le().time,y=m.period.end,g=m.duration,E=ue(),T=Object(r.useState)(g),A=Object(s.a)(T,2),S=A[0],w=A[1];Object(r.useEffect)((function(){w(g)}),[g]),Object(r.useEffect)((function(){v(function(e){return R()(e).format(B)}(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(C.a)(Object(C.a)({},e),n):Object(C.a)({},e)}),{}),n=R.a.duration(t).asMilliseconds();return n<H?F(H):n>N?F(N):e}(S);w(e),t(e)}}),[S,i]);var _=function(){b(null)},U=Boolean(d);return Object(a.jsxs)(f.a,{m:1,flexDirection:"row",display:"flex",children:[Object(a.jsxs)(f.a,{px:1,children:[Object(a.jsx)(f.a,{children:Object(a.jsx)(Ze.a,{label:"Duration",value:S,onChange:function(e){w(e.target.value)},fullWidth:!0,onBlur:function(){l(!1)},onFocus:function(){l(!0)}})}),Object(a.jsx)(f.a,{my:2,children:Object(a.jsxs)(p.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)(it.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)(lt,{})}),Object(a.jsx)(jt,{handler:function(){return w("5m")},text:"5m"}),",\xa0",Object(a.jsx)(jt,{handler:function(){return w("1h")},text:"1h"}),",\xa0",Object(a.jsx)(jt,{handler:function(){return w("1h 30m")},text:"1h 30m"})]})})]}),Object(a.jsxs)(f.a,{px:1,children:[Object(a.jsx)(f.a,{children:Object(a.jsx)(st.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)(f.a,{my:2,children:Object(a.jsxs)(p.a,{variant:"body2",children:["Will be changed to current time for auto-refresh mode.\xa0",Object(a.jsx)(jt,{handler:function(){return E({type:"RUN_QUERY_TO_NOW"})},text:"Switch to now"})]})})]})]})},bt=n(138),Ot=n.n(bt),ht=n(140),ft=n.n(ht),pt=n(249),xt=n(268),vt=n(267),mt=n(246),yt=n(250),gt=n(259),Et=n(241),Tt=n(238),At=n(266),St=n(237),wt=n(244),Ct=n(261),_t=n(240),Rt=n(247),Ut=n(242),Dt=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(C.a)(Object(C.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)(f.a,{py:2,children:t})}))},kt=n(136),Mt=n.n(kt),It=n(137),Lt=n.n(It),Ht={authMethod:"NO_AUTH",saveAuthLocally:!1},Nt=J("AUTH_TYPE"),Bt=J("BASIC_AUTH_DATA"),Pt=J("BEARER_AUTH_DATA"),Yt=Object(C.a)(Object(C.a)({},Ht),{},{authMethod:Nt||Ht.authMethod,basicData:Bt,bearerData:Pt,saveAuthLocally:!(!Bt&&!Pt)}),qt=function(){V(K)};function zt(e,t){switch(t.type){case"SET_BASIC_AUTH":return t.payload.checkbox?G("BASIC_AUTH_DATA",t.payload.value):qt(),G("AUTH_TYPE","BASIC_AUTH"),Object(C.a)(Object(C.a)({},e),{},{authMethod:"BASIC_AUTH",basicData:t.payload.value});case"SET_BEARER_AUTH":return t.payload.checkbox?G("BEARER_AUTH_DATA",t.payload.value):qt(),G("AUTH_TYPE","BEARER_AUTH"),Object(C.a)(Object(C.a)({},e),{},{authMethod:"BEARER_AUTH",bearerData:t.payload.value});case"SET_NO_AUTH":return!t.payload.checkbox&&qt(),G("AUTH_TYPE","NO_AUTH"),Object(C.a)(Object(C.a)({},e),{},{authMethod:"NO_AUTH"});default:throw new Error}}var Qt=Object(r.createContext)({}),Ft=function(){return Object(r.useContext)(Qt).state},Wt=function(e){var t=e.children,n=Object(r.useReducer)(zt,Yt),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)(Qt.Provider,{value:l,children:t})},Gt=Object(Oe.a)((function(){return Object(vt.a)({tabsContent:{height:"200px"}})})),Jt="Bearer ",Vt=[{title:"No auth",id:"NO_AUTH"},{title:"Basic Auth",id:"BASIC_AUTH"},{title:"Bearer Token",id:"BEARER_AUTH"}],Kt=function(e){var t=Gt(),n=e.onClose,c=e.open,o=Ft(),i=o.saveAuthLocally,l=o.basicData,u=o.bearerData,j=o.authMethod,d=Object(r.useContext)(Qt).dispatch,b=Object(r.useState)(i),O=Object(s.a)(b,2),h=O[0],x=O[1],v=Object(r.useState)(l||{password:"",login:""}),m=Object(s.a)(v,2),g=m[0],E=m[1],T=Object(r.useState)((null===u||void 0===u?void 0:u.token)||Jt),A=Object(s.a)(T,2),S=A[0],w=A[1],_=Object(r.useState)(Vt.findIndex((function(e){return e.id===j}))||0),R=Object(s.a)(_,2),U=R[0],D=R[1],k=function(){n()};return Object(a.jsxs)(xt.a,{onClose:k,"aria-labelledby":"simple-dialog-title",open:c,children:[Object(a.jsx)(pt.a,{id:"simple-dialog-title",children:"Request Auth Settings"}),Object(a.jsxs)(mt.a,{children:[Object(a.jsx)(yt.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)(gt.a,{value:U,onChange:function(e,t){D(t)},indicatorColor:"primary",textColor:"primary",children:Vt.map((function(e){return Object(a.jsx)(Et.a,{label:e.title},e.id)}))}),Object(a.jsxs)(f.a,{p:0,display:"flex",flexDirection:"column",className:t.tabsContent,children:[Object(a.jsxs)(f.a,{flexGrow:1,children:[Object(a.jsx)(Dt,{value:U,index:0,children:Object(a.jsx)(p.a,{style:{fontStyle:"italic"},children:"No Authorization Header"})}),Object(a.jsxs)(Dt,{value:U,index:1,children:[Object(a.jsxs)(Tt.a,{margin:"dense",fullWidth:!0,children:[Object(a.jsx)(At.a,{htmlFor:"basic-login",children:"User"}),Object(a.jsx)(St.a,{id:"basic-login",startAdornment:Object(a.jsx)(wt.a,{position:"start",children:Object(a.jsx)(Mt.a,{})}),required:!0,onChange:function(e){return E((function(t){return Object(C.a)(Object(C.a)({},t),{},{login:e.target.value||""})}))},value:(null===g||void 0===g?void 0:g.login)||""})]}),Object(a.jsxs)(Tt.a,{margin:"dense",fullWidth:!0,children:[Object(a.jsx)(At.a,{htmlFor:"basic-pass",children:"Password"}),Object(a.jsx)(St.a,{id:"basic-pass",startAdornment:Object(a.jsx)(wt.a,{position:"start",children:Object(a.jsx)(Lt.a,{})}),onChange:function(e){return E((function(t){return Object(C.a)(Object(C.a)({},t),{},{password:e.target.value||""})}))},value:(null===g||void 0===g?void 0:g.password)||""})]})]}),Object(a.jsx)(Dt,{value:U,index:2,children:Object(a.jsx)(Ze.a,{id:"bearer-auth",label:"Bearer token",multiline:!0,fullWidth:!0,value:S,onChange:function(e){var t=e.target.value;t.startsWith(Jt)?w(t):w(Jt)},InputProps:{onPaste:function(e){var t=e.clipboardData.getData("text/plain");t.startsWith(Jt)?w(t):w(Jt+t),e.preventDefault()}},rowsMax:6})})]}),Object(a.jsxs)(Tt.a,{children:[Object(a.jsx)(y.a,{control:Object(a.jsx)(Ct.a,{checked:h,onChange:function(){return x((function(e){return!e}))},name:"checkedB",color:"primary"}),label:"Persist Auth Data Locally"}),Object(a.jsx)(_t.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)(Rt.a,{children:Object(a.jsx)(Ut.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:S}}})}k()},color:"primary",children:"Apply"})})]})},Xt=n(139),Zt=n.n(Xt),$t=n(228),en=n(141),tn=n.n(en),nn=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],v=Object(r.useState)(!1),m=Object(s.a)(v,2),A=m[0],S=m[1],w=Object(r.useRef)(null),C=Object(r.useRef)(null),_=function(){return o({type:"RUN_QUERY"})};return Object(a.jsxs)(a.Fragment,{children:[Object(a.jsxs)(Je.a,{expanded:h,onChange:function(){return x((function(e){return!e}))},children:[Object(a.jsxs)(Ve.a,{expandIcon:Object(a.jsx)(Ot.a,{}),"aria-controls":"panel1a-content",id:"panel1a-header",children:[Object(a.jsx)(f.a,{mr:2,children:Object(a.jsx)(p.a,{variant:"h6",component:"h2",children:"Query Configuration"})}),Object(a.jsx)(f.a,{flexGrow:1,onClick:function(e){return e.stopPropagation()},onFocusCapture:function(e){return e.stopPropagation()},children:Object(a.jsx)($t.a,{disablePortal:!h,container:C.current,children:Object(a.jsx)(ot,{server:t,query:n,oneLiner:!h,autocomplete:i,runQuery:_,setQuery:function(e){return o({type:"SET_QUERY",payload:e})}})})})]}),Object(a.jsx)(Ke.a,{children:Object(a.jsxs)(Xe.a,{container:!0,spacing:2,children:[Object(a.jsx)(Xe.a,{item:!0,xs:12,md:6,children:Object(a.jsxs)(f.a,{children:[Object(a.jsxs)(f.a,{py:2,display:"flex",alignItems:"center",children:[Object(a.jsx)(Ze.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)(f.a,{ml:1,children:Object(a.jsx)(E.a,{title:"Execute Query",children:Object(a.jsx)(T.a,{onClick:_,children:Object(a.jsx)(Zt.a,{})})})}),Object(a.jsx)(f.a,{children:Object(a.jsx)(E.a,{title:"Request Auth Settings",children:Object(a.jsx)(T.a,{onClick:function(){return d(!0)},children:Object(a.jsx)(ft.a,{})})})})]}),Object(a.jsxs)(f.a,{py:2,display:"flex",children:[Object(a.jsx)(f.a,{flexGrow:1,mr:2,children:Object(a.jsx)("div",{ref:C})}),Object(a.jsxs)("div",{children:[Object(a.jsx)(E.a,{title:"Query Editor Settings",children:Object(a.jsx)(T.a,{onClick:function(){return S(!A)},children:Object(a.jsx)(tn.a,{ref:w})})}),Object(a.jsx)(it.a,{open:A,transformOrigin:{vertical:-20,horizontal:"left"},onClose:function(){return S(!1)},anchorEl:w.current,children:Object(a.jsx)(f.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)(Xe.a,{item:!0,xs:8,md:6,children:Object(a.jsx)(f.a,{style:{borderRadius:"4px",borderColor:"#b9b9b9",borderStyle:"solid",borderWidth:"1px",height:"calc(100% - 18px)",marginTop:"16px"},children:Object(a.jsx)(dt,{setDuration:function(e){return o({type:"SET_DURATION",payload:e})},duration:c})})})]})})]}),Object(a.jsx)(Kt,{open:j,onClose:function(){return d(!1)}})]})},an=n(114),rn=n.n(an),cn=n(142),on=function(){var e=le(),t=e.query,n=e.displayType,a=e.serverUrl,c=e.time.period,o=Ft(),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)(),f=Object(s.a)(h,2),p=f[0],x=f[1],v=Object(r.useState)(),m=Object(s.a)(v,2),y=m[0],g=m[1],E=Object(r.useState)(),T=Object(s.a)(E,2),A=T[0],S=T[1];Object(r.useEffect)((function(){A&&(x(void 0),g(void 0))}),[A]);var w=Object(r.useMemo)((function(){if(c){if(!a)return void S("Please enter Server URL");if(!t.trim())return void S("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(C.a)(Object(C.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)}S("Please provide a valid URL")}}),[a,c,n]);return Object(r.useEffect)((function(){Object(cn.a)(rn.a.mark((function e(){var a,r,c,o;return rn.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!w){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(w,{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,S(void 0),"chart"===n?x(c.data.result):g(c.data.result),e.next=32;break;case 18:return e.t0=S,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),S(e.t5.message);case 37:O(!1);case 38:case"end":return e.stop()}}),e,null,[[5,34]])})))()}),[w,a,n]),{fetchUrl:w,isLoading:b,graphData:p,liveData:y,error:A}},sn=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)(f.a,{position:"relative",children:[Object(a.jsx)(f.a,{flexDirection:"column",justifyContent:"flex-end",display:"flex",style:{position:"fixed",right:"16px"},children:Object(a.jsx)(Ut.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})]})},ln=n(143),un=n.n(ln),jn=function(e){var t=e.url,n=d().showInfoMessage;return Object(a.jsx)(f.a,{pl:2,py:1,flexShrink:0,display:"flex",children:Object(a.jsx)(E.a,{title:"Copy Query URL",children:Object(a.jsx)(T.a,{size:"small",onClick:function(e){t&&(navigator.clipboard.writeText(t),n("Value has been copied"),e.preventDefault())},children:Object(a.jsx)(un.a,{style:{color:"white"}})})})})},dn=function(){var e=le(),t=e.displayType,n=e.time.period,r=on(),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)(f.a,{display:"flex",children:[Object(a.jsxs)(p.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)(f.a,{ml:4,flexGrow:1,children:Object(a.jsx)(fe,{})}),Object(a.jsx)(we,{}),Object(a.jsx)(jn,{url:c})]})}),Object(a.jsxs)(f.a,{p:2,display:"grid",gridTemplateRows:"auto 1fr",gridGap:"20px",style:{minHeight:"calc(100vh - 64px)"},children:[Object(a.jsx)(f.a,{children:Object(a.jsx)(nn,{})}),Object(a.jsxs)(f.a,{height:"100%",children:[o&&Object(a.jsx)(v.a,{in:o,style:{transitionDelay:o?"300ms":"0ms"},children:Object(a.jsx)(f.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)(m.a,{})})}),Object(a.jsxs)(f.a,{height:"100%",p:3,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)(Ne,{data:s}),i&&"code"===t&&Object(a.jsx)(sn,{data:i}),i&&"table"===t&&Object(a.jsx)(Ge,{data:i})]})]})]})]})},bn=n(147),On=n(255),hn=n(254),fn=n(33),pn=n(144),xn=function(){var e=Object(bn.a)({typography:{fontSize:10}});return Object(a.jsxs)(a.Fragment,{children:[Object(a.jsx)(hn.a,{})," ",Object(a.jsxs)(fn.a,{utils:pn.a,children:[" ",Object(a.jsxs)(On.a,{theme:e,children:[" ",Object(a.jsxs)(de,{children:[" ",Object(a.jsxs)(Wt,{children:[" ",Object(a.jsxs)(b,{children:[" ",Object(a.jsx)(dn,{})]})]})]})]})]})]})},vn=function(e){e&&e instanceof Function&&n.e(3).then(n.bind(null,271)).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)(xn,{})}),document.getElementById("root")),vn()}},[[189,1,2]]]); |