mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-02-09 15:27:11 +00:00
![Yury Molodov](/assets/img/avatar_default.png)
* feat: initial uPlot graph * feat: add zoom/pan for graph * fix: add zoom by ctrl/mac * fix: remove unused code * feat: add toggle cache for fetch * feat: add fix y-axis limits * fix: stop point events while panning * fix: change getting cursor position when scaling * feat: add cursor tooltip to graph * fix: uninstall chart.js * fix: change link for create an issue * fix: set default cache value to true * app/vmalert: follow-up after0e2486df56
* docs/CHANGELOG.md: document5416e18007
* app/vmui: `make vmui-update` Co-authored-by: Aliaksandr Valialkin <valyala@victoriametrics.com>
1 line
No EOL
34 KiB
JavaScript
1 line
No EOL
34 KiB
JavaScript
(this.webpackJsonpvmui=this.webpackJsonpvmui||[]).push([[0],{172:function(e,t,n){},181:function(e,t,n){},182:function(e,t,n){},185:function(e,t,n){"use strict";n.r(t);var a=n(2),r=n(0),c=n.n(r),i=n(24),o=n.n(i),s=(n(172),n(13)),l=n(257),u=n(255),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),i=c[0],o=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],m=p[1];Object(r.useEffect)((function(){x&&(o({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:i.message})},i.key),t]})},O=n(248),h=n(238),f=n(252),p=n(83),x=n(231),m=n(240),v=n(219),y=n(221),g=n(222),E=n(260),T=n(151),_=n(128),S=n.n(_),C=n(16),A=n(12),w=n(32),I=n.n(w),R=n(124),U=n.n(R),D=n(125),k=n.n(D);I.a.extend(U.a),I.a.extend(k.a);var M,L=window.screen.availWidth/2,H=1e3,N=1578e8,B="YYYY-MM-DD[T]HH:mm:ss",Y=[{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"}],P=Y.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&&P.includes(n[0]))return Object(C.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(A.a)(Object(A.a)({},e),n):Object(A.a)({},e)}),{}),r=I.a.duration(a).asSeconds();return{start:n-r,end:n,step:Math.ceil(r/L),date:F(t||new Date)}},F=function(e){return I()(e).utc().format(B)},Q=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),i=["d","h","m","s","ms"];return[c,r,a,n,t].map((function(e,t){return e?"".concat(e).concat(i[t]):""})).filter((function(e){return e})).join(" ")},G=function(e){return new Date(1e3*e)},W=function(e,t){t?window.localStorage.setItem(e,JSON.stringify({value:t})):J([e])},V=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}},J=function(e){return e.forEach((function(e){return window.localStorage.removeItem(e)}))},X=["BASIC_AUTH_DATA","BEARER_AUTH_DATA"],K=n(126),Z=n.n(K),$=n(109),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=(M=ae("g0.end_input",new Date(I()().utc().format(B))),I()(M).utcOffset(0,!0).local().format(B)),ie={serverUrl:window.location.href.replace(/\/(?:prometheus\/)?(?:graph|vmui)\/.*/,"/prometheus/"),displayType:"chart",query:ae("g0.expr",V("LAST_QUERY")||"\n"),time:{duration:re,period:z(re,new Date(ce))},queryControls:{autoRefresh:!1,autocomplete:V("AUTOCOMPLETE")||!1,nocache:V("NO_CACHE")||!1}};function oe(e,t){switch(t.type){case"SET_DISPLAY_TYPE":return Object(A.a)(Object(A.a)({},e),{},{displayType:t.payload});case"SET_SERVER":return Object(A.a)(Object(A.a)({},e),{},{serverUrl:t.payload});case"SET_QUERY":return Object(A.a)(Object(A.a)({},e),{},{query:t.payload});case"SET_DURATION":return Object(A.a)(Object(A.a)({},e),{},{time:Object(A.a)(Object(A.a)({},e.time),{},{duration:t.payload,period:z(t.payload,G(e.time.period.end))})});case"SET_UNTIL":return Object(A.a)(Object(A.a)({},e),{},{time:Object(A.a)(Object(A.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 Q(t)}(t.payload);return Object(A.a)(Object(A.a)({},e),{},{queryControls:Object(A.a)(Object(A.a)({},e.queryControls),{},{autoRefresh:!1}),time:Object(A.a)(Object(A.a)({},e.time),{},{duration:n,period:z(n,t.payload.to)})});case"TOGGLE_AUTOREFRESH":return Object(A.a)(Object(A.a)({},e),{},{queryControls:Object(A.a)(Object(A.a)({},e.queryControls),{},{autoRefresh:!e.queryControls.autoRefresh})});case"TOGGLE_AUTOCOMPLETE":return Object(A.a)(Object(A.a)({},e),{},{queryControls:Object(A.a)(Object(A.a)({},e.queryControls),{},{autocomplete:!e.queryControls.autocomplete})});case"NO_CACHE":return Object(A.a)(Object(A.a)({},e),{},{queryControls:Object(A.a)(Object(A.a)({},e.queryControls),{},{nocache:!e.queryControls.nocache})});case"RUN_QUERY":return Object(A.a)(Object(A.a)({},e),{},{time:Object(A.a)(Object(A.a)({},e.time),{},{period:z(e.time.duration,G(e.time.period.end))})});case"RUN_QUERY_TO_NOW":return Object(A.a)(Object(A.a)({},e),{},{time:Object(A.a)(Object(A.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(ie).reduce((function(e,t){var n=Object(s.a)(t,2),a=n[0],r=n[1];return Object(A.a)(Object(A.a)({},e),{},Object(C.a)({},a,ae(a)||r))}),{}),de=function(e){var t=e.children,n=Object(r.useReducer)(oe,je),c=Object(s.a)(n,2),i=c[0],o=c[1];Object(r.useEffect)((function(){ne(i)}),[i]);var l=Object(r.useMemo)((function(){return{state:i,dispatch:o}}),[i,o]);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)(v.a,Object(A.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(220),he=Object(Oe.a)({colorizing:{color:"white"}}),fe=function(){var e=he(),t=ue(),n=le().queryControls.autoRefresh,i=Object(r.useState)(5),o=Object(s.a)(i,2),l=o[0],u=o[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],m=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);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)(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(){v()}}),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(){v()},children:Object(a.jsx)(S.a,{style:{color:"white"}})})})})]})]})},pe=n(131),xe=n.n(pe),me=n(129),ve=n.n(me),ye=n(130),ge=n.n(ye),Ee=n(224),Te=n(264),_e=n(10),Se=Object(_e.a)({root:{padding:6,color:"white","&.Mui-selected":{color:"white"}}})(Ee.a),Ce=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)(ve.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"]})]})},Ae=n(132),we=n.n(Ae),Ie=(n(180),n(133)),Re=n.n(Ie),Ue=(n(181),n(182),{yaxis:{limits:{enable:!1,range:[0,0]}}});function De(e,t){switch(t.type){case"TOGGLE_ENABLE_YAXIS_LIMITS":return Object(A.a)(Object(A.a)({},e),{},{yaxis:Object(A.a)(Object(A.a)({},e.yaxis),{},{limits:Object(A.a)(Object(A.a)({},e.yaxis.limits),{},{enable:!e.yaxis.limits.enable})})});case"SET_YAXIS_LIMITS":return Object(A.a)(Object(A.a)({},e),{},{yaxis:Object(A.a)(Object(A.a)({},e.yaxis),{},{limits:Object(A.a)(Object(A.a)({},e.yaxis.limits),{},{range:t.payload})})});default:throw new Error}}var ke=Object(r.createContext)({}),Me=function(){return Object(r.useContext)(ke).state},Le=function(){return Object(r.useContext)(ke).dispatch},He=function(e){var t=e.children,n=Object(r.useReducer)(De,Ue),c=Object(s.a)(n,2),i=c[0],o=c[1],l=Object(r.useMemo)((function(){return{state:i,dispatch:o}}),[i,o]);return Object(a.jsx)(ke.Provider,{value:l,children:t})},Ne=n(26),Be=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},Ye=n(102),Pe=function(e){if(0===Object.keys(e.metric).length)return"Query result";var t=e.metric,n=t.__name__,a=Object(Ye.a)(t,["__name__"]);return"".concat(n||""," {").concat(Object.entries(a).map((function(e){return"".concat(e[0],": ").concat(e[1])})).join(", "),"}")},qe=function(e){var t,n=e.u,a=e.tooltipIdx,r=e.data,c=e.series,i=e.tooltip,o=e.tooltipOffset,s=a.seriesIdx,l=a.dataIdx,u=n.data[s][l],j=n.data[0][l],d=(null===(t=r[s-1])||void 0===t?void 0:t.metric)||{},b=Be(c[s].label||""),O=n.over.getBoundingClientRect(),h=O.width,f=O.height,p=n.valToPos(u||0,"y"),x=n.valToPos(j,"x"),m=i.getBoundingClientRect(),v=m.width,y=m.height,g=x+v>=h,E=p+y>=f;i.style.display="grid",i.style.top="".concat(o.top+p+10-(E?y+10:0),"px"),i.style.left="".concat(o.left+x+10-(g?v+20:0),"px");var T=I()(new Date(1e3*j)).format("YYYY-MM-DD HH:mm:ss:SSS (Z)"),_=Object.keys(d).filter((function(e){return"__name__"!==e})).map((function(e){return"<div><b>".concat(e,"</b>: ").concat(d[e],"</div>")})).join(""),S='<div class="u-tooltip__marker" style="background: '.concat(b,'"></div>');i.innerHTML="<div>".concat(T,'</div>\n <div class="u-tooltip-data">\n ').concat(S).concat(d.__name__||"",": <b>").concat(u,'</b>\n </div>\n <div class="u-tooltip__info">').concat(_,"</div>")},ze=function(e){var t=e.data,n=void 0===t?[]:t,c=ue(),i=le().time.period,o=Object(r.useState)({min:i.start,max:i.end}),l=Object(s.a)(o,2),u=l[0],j=l[1],d=Object(r.useRef)(null),b=Object(r.useState)(!1),O=Object(s.a)(b,2),h=O[0],f=O[1],p=Object(r.useState)(0),x=Object(s.a)(p,2),m=x[0],v=x[1],y={seriesIdx:1,dataIdx:0},g={left:0,top:0},E=Me().yaxis,T=Le(),_=Object(r.useMemo)((function(){for(var e=function(e){var t=e.map((function(e){return e.values.map((function(e){return e[0]}))})).flat().sort((function(e,t){return e-t}));return[t[0],t[t.length-1]]}(n),t=Object(s.a)(e,2),a=t[0],r=t[1],c=[],o=a;o<r;o+=i.step||1)c.push(o);return c}),[n]),S=Object(r.useMemo)((function(){return function(e){return[{}].concat(Object(Ne.a)(e.map((function(e){return{label:Pe(e),width:1.5,stroke:Be(Pe(e))}}))))}(n)}),[n]),C=Object(r.useMemo)((function(){return function(e,t){return[t].concat(Object(Ne.a)(e.map((function(e){return t.map((function(t){var n=e.values.find((function(e){return e[0]===t}));return n?+n[1]:null}))}))))}(n,_)}),[n]),A=document.createElement("div");A.className="u-tooltip";Object(r.useEffect)((function(){var e;e=function(e){var t=e.map((function(e){return e.values.map((function(e){return+e[1]}))})).flat().sort((function(e,t){return e-t}));return[t[0],t[t.length-1]]}(n),E.limits.enable&&!E.limits.range.every((function(e){return!e}))||T({type:"SET_YAXIS_LIMITS",payload:e})}),[n]),Object(r.useEffect)((function(){j({min:i.start,max:i.end})}),[i]),Object(r.useEffect)((function(){var e=(i.end-i.start)/3,t=e/(u.max-u.min);(u.max>i.end+e||u.min<i.start-e||t>=.7)&&c({type:"SET_PERIOD",payload:{from:new Date(1e3*u.min),to:new Date(1e3*u.max)}})}),[u]);var w={width:d.current?d.current.offsetWidth:400,height:500,series:S,plugins:[{hooks:{ready:function(e){var t;g.left=parseFloat(e.over.style.left),g.top=parseFloat(e.over.style.top),null===(t=e.root.querySelector(".u-wrap"))||void 0===t||t.appendChild(A),e.over.addEventListener("mousedown",(function(t){if(0===t.button){f(!0),t.preventDefault();var n=t.clientX,a=function(t){t.preventDefault();var a=(e.posToVal(1,"x")-e.posToVal(0,"x"))*(t.clientX-n),r=(e.scales.x.min||1)-a,c=(e.scales.x.max||1)-a;e.setScale("x",{min:r,max:c}),j({min:r,max:c})};document.addEventListener("mousemove",a),document.addEventListener("mouseup",(function e(){f(!1),document.removeEventListener("mousemove",a),document.removeEventListener("mouseup",e)}))}})),e.over.addEventListener("wheel",(function(t){if(t.ctrlKey||t.metaKey){t.preventDefault();var n=e.over.getBoundingClientRect().width;e.cursor.left&&e.cursor.left>0&&v(e.cursor.left);var a=e.posToVal(m,"x"),r=(e.scales.x.max||0)-(e.scales.x.min||0),c=t.deltaY<0?.85*r:r/.85,i=a-m/n*c,o=i+c;e.batch((function(){e.setScale("x",{min:i,max:o}),j({min:i,max:o})}))}}))},setCursor:function(e){y.dataIdx!==e.cursor.idx&&(y.dataIdx=e.cursor.idx||0,y.seriesIdx&&y.dataIdx&&qe({u:e,tooltipIdx:y,data:n,series:S,tooltip:A,tooltipOffset:g}))},setSeries:function(e,t){y.seriesIdx!==t&&(y.seriesIdx=t||0,t&&y.dataIdx?qe({u:e,tooltipIdx:y,data:n,series:S,tooltip:A,tooltipOffset:g}):A.style.display="none")}}}],cursor:{drag:{x:!1,y:!1},focus:{prox:30}},axes:[{space:80},{show:!0,font:"10px Arial",values:function(e,t){return t.map((function(e){return e>1e3?Re()(e).format("0.0a"):e}))}}],scales:{x:{range:function(){return[u.min,u.max]}},y:{range:function(e,t,n){return E.limits.enable?E.limits.range:[t,n]}}}};return Object(a.jsx)("div",{ref:d,style:{pointerEvents:h?"none":"auto"},children:C&&Object(a.jsx)(we.a,{options:w,data:C})})},Fe=function(e){var t=e.data,n=void 0===t?[]:t;return Object(a.jsx)(a.Fragment,{children:n.length>0?Object(a.jsx)(ze,{data:n}):Object(a.jsx)("div",{style:{textAlign:"center"},children:"No data to show"})})},Qe=n(225),Ge=n(149),We=n(226),Ve=n(227),Je=n(228),Xe=n(229),Ke=n(230),Ze=Object(Oe.a)({deemphasized:{opacity:.4}}),$e=function(e){var t=e.data,n=Ze(),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),i=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:i.length>0?Object(a.jsx)(Qe.a,{component:Ge.a,children:Object(a.jsxs)(We.a,{"aria-label":"simple table",children:[Object(a.jsx)(Ve.a,{children:Object(a.jsxs)(Je.a,{children:[c.map((function(e,t){return Object(a.jsx)(Xe.a,{style:{textTransform:"capitalize"},children:e.key},t)})),Object(a.jsx)(Xe.a,{align:"right",children:"Value"})]})}),Object(a.jsx)(Ke.a,{children:i.map((function(e,t){return Object(a.jsxs)(Je.a,{children:[e.metadata.map((function(e,r){var c=i[t-1]&&i[t-1].metadata[r];return Object(a.jsx)(Xe.a,{className:c===e?n.deemphasized:void 0,children:e},r)})),Object(a.jsx)(Xe.a,{align:"right",children:e.value})]},t)}))})]})}):Object(a.jsx)("div",{style:{textAlign:"center"},children:"No data to show"})})},et=n(258),tt=n(246),nt=n(247),at=n(243),rt=n(253),ct=n(3),it=n(9),ot=n(97),st=n(145),lt=n(146),ut={windows:"Windows",mac:"Mac OS",linux:"Linux"},jt=function(){return(Object.values(ut).find((function(e){return navigator.userAgent.indexOf(e)>=0}))||"unknown")===ut.mac},dt=function(e){var t=e.query,n=e.setQuery,c=e.runQuery,i=e.server,o=e.oneLiner,l=void 0!==o&&o,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 it.d({parent:j.current})),function(){return null===O||void 0===O?void 0:O.destroy()}}),[]),Object(r.useEffect)((function(){var e=new st.a;e.activateCompletion(u),e.setComplete({url:i});var a=it.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(ct.e.create({doc:t,extensions:[lt.a,Object(it.k)(ot.a),a,e.asExtension(),Object(it.k)([{key:jt()?"Cmd-Enter":"Ctrl-Enter",run:function(){return c(),!0}}])]}))}),[i,O,u]),Object(a.jsx)(a.Fragment,{children:Object(a.jsx)("div",{ref:j,className:l?"one-line-scroll":void 0})})},bt=n(234),Ot=n(251),ht=function(){return Object(a.jsx)(Qe.a,{component:Ge.a,children:Object(a.jsxs)(We.a,{"aria-label":"simple table",size:"small",children:[Object(a.jsx)(Ve.a,{children:Object(a.jsxs)(Je.a,{children:[Object(a.jsx)(Xe.a,{children:"Long"}),Object(a.jsx)(Xe.a,{children:"Short"})]})}),Object(a.jsx)(Ke.a,{children:Y.map((function(e,t){return Object(a.jsxs)(Je.a,{children:[Object(a.jsx)(Xe.a,{component:"th",scope:"row",children:e.long}),Object(a.jsx)(Xe.a,{children:e.short})]},t)}))})]})})},ft=Object(Oe.a)({inlineBtn:{"&:hover":{cursor:"pointer"}}}),pt=function(e){var t=e.handler,n=e.text,r=ft();return Object(a.jsx)(x.a,{component:"span",className:r.inlineBtn,onClick:t,children:n})},xt=function(e){var t=e.setDuration,n=Object(r.useState)(!1),i=Object(s.a)(n,2),o=i[0],l=i[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(),T=Object(r.useState)(g),_=Object(s.a)(T,2),S=_[0],C=_[1];Object(r.useEffect)((function(){C(g)}),[g]),Object(r.useEffect)((function(){m(function(e){return I()(e).format(B)}(G(y)))}),[y]),Object(r.useEffect)((function(){if(!o){var e=function(e){var t=e.trim().split(" ").reduce((function(e,t){var n=q(t);return n?Object(A.a)(Object(A.a)({},e),n):Object(A.a)({},e)}),{}),n=I.a.duration(t).asMilliseconds();return n<H?Q(H):n>N?Q(N):e}(S);C(e),t(e)}}),[S,o]);var w=function(){b(null)},R=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)(rt.a,{label:"Duration",value:S,onChange:function(e){C(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":R?"mouse-over-popover":void 0,"aria-haspopup":"true",style:{cursor:"pointer"},onMouseEnter:function(e){b(e.currentTarget)},onMouseLeave:w,children:":\xa0"}),Object(a.jsx)(bt.a,{open:R,anchorEl:d,anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"left"},style:{pointerEvents:"none"},onClose:w,disableRestoreFocus:!0,children:Object(a.jsx)(ht,{})}),Object(a.jsx)(pt,{handler:function(){return C("5m")},text:"5m"}),",\xa0",Object(a.jsx)(pt,{handler:function(){return C("1h")},text:"1h"}),",\xa0",Object(a.jsx)(pt,{handler:function(){return C("1h 30m")},text:"1h 30m"})]})})]}),Object(a.jsxs)(f.a,{px:1,children:[Object(a.jsx)(f.a,{children:Object(a.jsx)(Ot.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)(pt,{handler:function(){return E({type:"RUN_QUERY_TO_NOW"})},text:"Switch to now"})]})})]})]})},mt=n(136),vt=n.n(mt),yt=n(138),gt=n.n(yt),Et=n(244),Tt=n(263),_t=n(262),St=n(241),Ct=n(245),At=n(254),wt=n(236),It=n(233),Rt=n(261),Ut=n(232),Dt=n(239),kt=n(256),Mt=n(235),Lt=n(242),Ht=n(237),Nt=function(e){var t=e.children,n=e.value,r=e.index,c=Object(Ye.a)(e,["children","value","index"]);return Object(a.jsx)("div",Object(A.a)(Object(A.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})}))},Bt=n(134),Yt=n.n(Bt),Pt=n(135),qt=n.n(Pt),zt={authMethod:"NO_AUTH",saveAuthLocally:!1},Ft=V("AUTH_TYPE"),Qt=V("BASIC_AUTH_DATA"),Gt=V("BEARER_AUTH_DATA"),Wt=Object(A.a)(Object(A.a)({},zt),{},{authMethod:Ft||zt.authMethod,basicData:Qt,bearerData:Gt,saveAuthLocally:!(!Qt&&!Gt)}),Vt=function(){J(X)};function Jt(e,t){switch(t.type){case"SET_BASIC_AUTH":return t.payload.checkbox?W("BASIC_AUTH_DATA",t.payload.value):Vt(),W("AUTH_TYPE","BASIC_AUTH"),Object(A.a)(Object(A.a)({},e),{},{authMethod:"BASIC_AUTH",basicData:t.payload.value});case"SET_BEARER_AUTH":return t.payload.checkbox?W("BEARER_AUTH_DATA",t.payload.value):Vt(),W("AUTH_TYPE","BEARER_AUTH"),Object(A.a)(Object(A.a)({},e),{},{authMethod:"BEARER_AUTH",bearerData:t.payload.value});case"SET_NO_AUTH":return!t.payload.checkbox&&Vt(),W("AUTH_TYPE","NO_AUTH"),Object(A.a)(Object(A.a)({},e),{},{authMethod:"NO_AUTH"});default:throw new Error}}var Xt=Object(r.createContext)({}),Kt=function(){return Object(r.useContext)(Xt).state},Zt=function(e){var t=e.children,n=Object(r.useReducer)(Jt,Wt),c=Object(s.a)(n,2),i=c[0],o=c[1],l=Object(r.useMemo)((function(){return{state:i,dispatch:o}}),[i,o]);return Object(a.jsx)(Xt.Provider,{value:l,children:t})},$t=Object(Oe.a)((function(){return Object(_t.a)({tabsContent:{height:"200px"}})})),en="Bearer ",tn=[{title:"No auth",id:"NO_AUTH"},{title:"Basic Auth",id:"BASIC_AUTH"},{title:"Bearer Token",id:"BEARER_AUTH"}],nn=function(e){var t=$t(),n=e.onClose,c=e.open,i=Kt(),o=i.saveAuthLocally,l=i.basicData,u=i.bearerData,j=i.authMethod,d=Object(r.useContext)(Xt).dispatch,b=Object(r.useState)(o),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],T=Object(r.useState)((null===u||void 0===u?void 0:u.token)||en),_=Object(s.a)(T,2),S=_[0],C=_[1],w=Object(r.useState)(tn.findIndex((function(e){return e.id===j}))||0),I=Object(s.a)(w,2),R=I[0],U=I[1],D=function(){n()};return Object(a.jsxs)(Tt.a,{onClose:D,"aria-labelledby":"simple-dialog-title",open:c,children:[Object(a.jsx)(Et.a,{id:"simple-dialog-title",children:"Request Auth Settings"}),Object(a.jsxs)(St.a,{children:[Object(a.jsx)(Ct.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)(At.a,{value:R,onChange:function(e,t){U(t)},indicatorColor:"primary",textColor:"primary",children:tn.map((function(e){return Object(a.jsx)(wt.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)(Nt,{value:R,index:0,children:Object(a.jsx)(p.a,{style:{fontStyle:"italic"},children:"No Authorization Header"})}),Object(a.jsxs)(Nt,{value:R,index:1,children:[Object(a.jsxs)(It.a,{margin:"dense",fullWidth:!0,children:[Object(a.jsx)(Rt.a,{htmlFor:"basic-login",children:"User"}),Object(a.jsx)(Ut.a,{id:"basic-login",startAdornment:Object(a.jsx)(Dt.a,{position:"start",children:Object(a.jsx)(Yt.a,{})}),required:!0,onChange:function(e){return E((function(t){return Object(A.a)(Object(A.a)({},t),{},{login:e.target.value||""})}))},value:(null===g||void 0===g?void 0:g.login)||""})]}),Object(a.jsxs)(It.a,{margin:"dense",fullWidth:!0,children:[Object(a.jsx)(Rt.a,{htmlFor:"basic-pass",children:"Password"}),Object(a.jsx)(Ut.a,{id:"basic-pass",startAdornment:Object(a.jsx)(Dt.a,{position:"start",children:Object(a.jsx)(qt.a,{})}),onChange:function(e){return E((function(t){return Object(A.a)(Object(A.a)({},t),{},{password:e.target.value||""})}))},value:(null===g||void 0===g?void 0:g.password)||""})]})]}),Object(a.jsx)(Nt,{value:R,index:2,children:Object(a.jsx)(rt.a,{id:"bearer-auth",label:"Bearer token",multiline:!0,fullWidth:!0,value:S,onChange:function(e){var t=e.target.value;t.startsWith(en)?C(t):C(en)},InputProps:{onPaste:function(e){var t=e.clipboardData.getData("text/plain");t.startsWith(en)?C(t):C(en+t),e.preventDefault()}},rowsMax:6})})]}),Object(a.jsxs)(It.a,{children:[Object(a.jsx)(y.a,{control:Object(a.jsx)(kt.a,{checked:h,onChange:function(){return x((function(e){return!e}))},name:"checkedB",color:"primary"}),label:"Persist Auth Data Locally"}),Object(a.jsx)(Mt.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)(Lt.a,{children:Object(a.jsx)(Ht.a,{onClick:function(){switch(R){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}}})}D()},color:"primary",children:"Apply"})})]})},an=n(137),rn=n.n(an),cn=n(223),on=n(110),sn=n.n(on),ln=function(){var e=le(),t=e.serverUrl,n=e.query,c=e.time.duration,i=e.queryControls,o=i.autocomplete,l=i.nocache,u=ue(),j=Me().yaxis,d=Le(),b=Object(r.useState)(!1),O=Object(s.a)(b,2),h=O[0],x=O[1],m=Object(r.useState)(!0),v=Object(s.a)(m,2),_=v[0],S=v[1],C=Object(r.useRef)(null),A=function(){return u({type:"RUN_QUERY"})};return Object(a.jsxs)(a.Fragment,{children:[Object(a.jsxs)(et.a,{expanded:_,onChange:function(){return S((function(e){return!e}))},children:[Object(a.jsxs)(tt.a,{expandIcon:Object(a.jsx)(vt.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)(cn.a,{disablePortal:!_,container:C.current,children:Object(a.jsx)(dt,{server:t,query:n,oneLiner:!_,autocomplete:o,runQuery:A,setQuery:function(e){return u({type:"SET_QUERY",payload:e})}})})})]}),Object(a.jsx)(nt.a,{children:Object(a.jsxs)(at.a,{container:!0,spacing:2,children:[Object(a.jsx)(at.a,{item:!0,xs:12,md:6,children:Object(a.jsxs)(f.a,{display:"grid",gridGap:16,children:[Object(a.jsxs)(f.a,{display:"flex",alignItems:"center",children:[Object(a.jsx)(rt.a,{variant:"outlined",fullWidth:!0,label:"Server URL",value:t,inputProps:{style:{fontFamily:"Monospace"}},onChange:function(e){var t=e.target.value;u({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:A,children:Object(a.jsx)(rn.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 x(!0)},children:Object(a.jsx)(gt.a,{})})})})]}),Object(a.jsx)(f.a,{flexGrow:1,children:Object(a.jsx)("div",{ref:C})})]})}),Object(a.jsx)(at.a,{item:!0,xs:8,md:6,children:Object(a.jsx)(f.a,{style:{borderRadius:"4px",borderColor:"#b9b9b9",borderStyle:"solid",borderWidth:"1px",height:"100%"},children:Object(a.jsx)(xt,{setDuration:function(e){return u({type:"SET_DURATION",payload:e})},duration:c})})}),Object(a.jsx)(at.a,{item:!0,xs:12,children:Object(a.jsxs)(f.a,{px:1,display:"flex",alignItems:"center",minHeight:52,children:[Object(a.jsx)(f.a,{children:Object(a.jsx)(y.a,{control:Object(a.jsx)(g.a,{size:"small",checked:o,onChange:function(){u({type:"TOGGLE_AUTOCOMPLETE"}),W("AUTOCOMPLETE",!o)}}),label:"Enable autocomplete"})}),Object(a.jsx)(f.a,{ml:4,children:Object(a.jsx)(y.a,{control:Object(a.jsx)(g.a,{size:"small",checked:!l,onChange:function(){u({type:"NO_CACHE"}),W("NO_CACHE",!l)}}),label:"Enable cache"})}),Object(a.jsxs)(f.a,{ml:4,display:"flex",alignItems:"center",children:[Object(a.jsx)(y.a,{control:Object(a.jsx)(g.a,{size:"small",checked:j.limits.enable,onChange:function(){d({type:"TOGGLE_ENABLE_YAXIS_LIMITS"})}}),label:"fix the limits for y-axis"}),j.limits.enable&&Object(a.jsxs)(f.a,{display:"grid",gridTemplateColumns:"120px 120px",gridGap:10,children:[Object(a.jsx)(rt.a,{label:"Min",type:"number",size:"small",variant:"outlined",defaultValue:j.limits.range[0],onChange:sn()((function(e){var t=e.target.value;d({type:"SET_YAXIS_LIMITS",payload:[+t,j.limits.range[1]]})}),750)}),Object(a.jsx)(rt.a,{label:"Max",type:"number",size:"small",variant:"outlined",defaultValue:j.limits.range[1],onChange:sn()((function(e){var t=e.target.value;d({type:"SET_YAXIS_LIMITS",payload:[j.limits.range[0],+t]})}),750)})]})]})]})})]})})]}),Object(a.jsx)(nn,{open:h,onClose:function(){return x(!1)}})]})},un=n(111),jn=n.n(un),dn=n(139),bn=function(){var e=le(),t=e.query,n=e.displayType,a=e.serverUrl,c=e.time.period,i=e.queryControls.nocache,o=Kt(),l=o.basicData,u=o.bearerData,j=o.authMethod,d=Object(r.useState)(!1),b=Object(s.a)(d,2),O=b[0],h=b[1],f=Object(r.useState)(),p=Object(s.a)(f,2),x=p[0],m=p[1],v=Object(r.useState)(),y=Object(s.a)(v,2),g=y[0],E=y[1],T=Object(r.useState)(),_=Object(s.a)(T,2),S=_[0],C=_[1];Object(r.useEffect)((function(){S&&(m(void 0),E(void 0))}),[S]);var w=Object(r.useMemo)((function(){if(c){if(!a)return void C("Please enter Server URL");if(!t.trim())return void C("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(A.a)(Object(A.a)({},c),{},{start:c.start-e,end:c.end+e});return"chart"===n?function(e,t,n,a){return"".concat(e,"/api/v1/query_range?query=").concat(encodeURIComponent(t),"&start=").concat(n.start,"&end=").concat(n.end,"&step=").concat(n.step).concat(a?"&nocache=1":"")}(a,t,r,i):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)}C("Please provide a valid URL")}}),[a,c,n]);return Object(r.useEffect)((function(){Object(dn.a)(jn.a.mark((function e(){var a,r,c,i;return jn.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!w){e.next=38;break}return a=new Headers,"BASIC_AUTH"===j&&a.set("Authorization","Basic "+btoa("".concat((null===l||void 0===l?void 0:l.login)||"",":").concat((null===l||void 0===l?void 0:l.password)||""))),"BEARER_AUTH"===j&&a.set("Authorization",(null===u||void 0===u?void 0:u.token)||""),h(!0),e.prev=5,e.next=8,fetch(w,{headers:a});case 8:if(!(r=e.sent).ok){e.next=18;break}return W("LAST_QUERY",t),e.next=13,r.json();case 13:c=e.sent,C(void 0),"chart"===n?m(c.data.result):E(c.data.result),e.next=32;break;case 18:return e.t0=C,e.next=21,r.json();case 21:if(e.t2=i=e.sent,e.t1=null===e.t2,e.t1){e.next=25;break}e.t1=void 0===i;case 25:if(!e.t1){e.next=29;break}e.t3=void 0,e.next=30;break;case 29:e.t3=i.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),C(e.t5.message);case 37:h(!1);case 38:case"end":return e.stop()}}),e,null,[[5,34]])})))()}),[w,a,n]),{fetchUrl:w,isLoading:O,graphData:x,liveData:g,error:S}},On=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)(Ht.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})]})},hn=n(140),fn=n.n(hn),pn=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)(fn.a,{style:{color:"white"}})})})})},xn=function(){var e=le(),t=e.displayType,n=e.time.period,r=bn(),c=r.fetchUrl,i=r.isLoading,o=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/VictoriaMetrics/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)(Ce,{}),Object(a.jsx)(pn,{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)(ln,{})}),Object(a.jsxs)(f.a,{height:"100%",children:[i&&Object(a.jsx)(m.a,{in:i,style:{transitionDelay:i?"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)(v.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)(Fe,{data:s}),o&&"code"===t&&Object(a.jsx)(On,{data:o}),o&&"table"===t&&Object(a.jsx)($e,{data:o})]})]})]})]})},mn=n(144),vn=n(250),yn=n(249),gn=n(30),En=n(141),Tn=function(){var e=Object(mn.a)({typography:{fontSize:10}});return Object(a.jsxs)(a.Fragment,{children:[Object(a.jsx)(yn.a,{})," ",Object(a.jsxs)(gn.a,{utils:En.a,children:[" ",Object(a.jsxs)(vn.a,{theme:e,children:[" ",Object(a.jsxs)(de,{children:[" ",Object(a.jsxs)(Zt,{children:[" ",Object(a.jsxs)(He,{children:[" ",Object(a.jsxs)(b,{children:[" ",Object(a.jsx)(xn,{})]})]})]})]})]})]})]})},_n=function(e){e&&e instanceof Function&&n.e(3).then(n.bind(null,266)).then((function(t){var n=t.getCLS,a=t.getFID,r=t.getFCP,c=t.getLCP,i=t.getTTFB;n(e),a(e),r(e),c(e),i(e)}))};o.a.render(Object(a.jsx)(c.a.StrictMode,{children:Object(a.jsx)(Tn,{})}),document.getElementById("root")),_n()}},[[185,1,2]]]); |