AppRootPage.2255d1f23f976dbf2f3e.js 6.0 KB

12
  1. "use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[295],{20469:(t,e,n)=>{n.d(e,{ZP:()=>s,hF:()=>a,rb:()=>i});var o=n(93964),r=n.n(o);const a=r().module("grafana.core",["ngRoute"]),i=[a,r().module("grafana.controllers",[]),r().module("grafana.directives",[]),r().module("grafana.factories",[]),r().module("grafana.services",[]),r().module("grafana.filters",[]),r().module("grafana.routes",[])],s=a},72800:(t,e,n)=>{n.r(e),n.d(e,{default:()=>O,getAppPluginPageError:()=>S});var o,r=n(68404),a=n(87524),i=(o=function(t,e){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])},o(t,e)},function(t,e){function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),s="html",l="svg",u=function(t,e){var n,o,r,a={};if(t===s)r=document.createElement("div");else{if(t!==l)throw new Error('Invalid element type "'+t+'" for createPortalNode: must be "html" or "svg".');r=document.createElementNS("http://www.w3.org/2000/svg","g")}if(e&&"object"==typeof e)for(var i=0,u=Object.entries(e.attributes);i<u.length;i++){var p=u[i],d=p[0],c=p[1];r.setAttribute(d,c)}var h={element:r,elementType:t,setPortalProps:function(t){a=t},getInitialPortalProps:function(){return a},mount:function(e,r){if(r!==o){if(h.unmount(),e!==n&&!function(t,e){if(e===s)return t instanceof HTMLElement;if(e===l)return t instanceof SVGElement;throw new Error('Unrecognized element type "'+e+'" for validateElementType.')}(e,t))throw new Error('Invalid element type for portal: "'+t+'" portalNodes must be used with '+t+" elements, but OutPortal is within <"+e.tagName+">.");e.replaceChild(h.element,r),n=e,o=r}},unmount:function(t){t&&t!==o||n&&o&&(n.replaceChild(o,h.element),n=void 0,o=void 0)}};return h},p=function(t){function e(e){var n=t.call(this,e)||this;return n.addPropsChannel=function(){Object.assign(n.props.node,{setPortalProps:function(t){n.setState({nodeProps:t})}})},n.state={nodeProps:n.props.node.getInitialPortalProps()},n}return i(e,t),e.prototype.componentDidMount=function(){this.addPropsChannel()},e.prototype.componentDidUpdate=function(){this.addPropsChannel()},e.prototype.render=function(){var t=this,e=this.props,n=e.children,o=e.node;return a.createPortal(r.Children.map(n,(function(e){return r.isValidElement(e)?r.cloneElement(e,t.state.nodeProps):e})),o.element)},e}(r.PureComponent),d=function(t){function e(e){var n=t.call(this,e)||this;return n.placeholderNode=r.createRef(),n.passPropsThroughPortal(),n}return i(e,t),e.prototype.passPropsThroughPortal=function(){var t=Object.assign({},this.props,{node:void 0});this.props.node.setPortalProps(t)},e.prototype.componentDidMount=function(){var t=this.props.node;this.currentPortalNode=t;var e=this.placeholderNode.current,n=e.parentNode;t.mount(n,e),this.passPropsThroughPortal()},e.prototype.componentDidUpdate=function(){var t=this.props.node;this.currentPortalNode&&t!==this.currentPortalNode&&(this.currentPortalNode.unmount(this.placeholderNode.current),this.currentPortalNode=t);var e=this.placeholderNode.current,n=e.parentNode;t.mount(n,e),this.passPropsThroughPortal()},e.prototype.componentWillUnmount=function(){this.props.node.unmount(this.placeholderNode.current)},e.prototype.render=function(){return r.createElement("div",{ref:this.placeholderNode})},e}(r.PureComponent),c=u.bind(null,s),h=(u.bind(null,l),n(43215)),m=n(20469),f=n(78837);class v{constructor(){var t,e,n;n=void 0,(e="navItems")in(t=this)?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,this.navItems=f.ZP.bootData.navTree}getCfgNode(){return this.navItems.find((t=>"cfg"===t.id))}getNav(){var t;let e=this.navItems;const n={breadcrumbs:[]};for(var o=arguments.length,r=new Array(o),a=0;a<o;a++)r[a]=arguments[a];for(const t of r){if("number"==typeof t){n.main=n.breadcrumbs[t];break}const o=e.find((e=>e.id===t));var i;if(o)n.breadcrumbs.push(o),n.node=o,n.main=o,e=null!==(i=o.children)&&void 0!==i?i:[]}if(null!==(t=n.main)&&void 0!==t&&t.children)for(const t of n.main.children){var s;t.active=t.url===(null===(s=n.node)||void 0===s?void 0:s.url)}return n}getNotFoundNav(){return g()}}function g(){return P("Page not found","404 Error")}function P(t,e){const n={text:t,subTitle:e,icon:"exclamation-triangle"};return{breadcrumbs:[n],node:n,main:n}}v.$inject=[],m.ZP.service("navModelSrv",v);var b,y,N=n(33801),w=n(22584),j=n(98163),C=n(32569),E=n(92808),x=n(45916);function S(t){return t?t.type!==h.PluginType.app?"Plugin must be an app":t.enabled?null:"Application Not Enabled":"Unknown Plugin"}class I extends r.Component{constructor(t){var e,n,o;super(t),o=t=>{this.setState({nav:t})},(n="onNavChanged")in(e=this)?Object.defineProperty(e,n,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[n]=o,this.state={loading:!0,portalNode:c()}}shouldComponentUpdate(t){return t.location.pathname.startsWith("/a/")}async loadPluginSettings(){const{params:t}=this.props.match;try{const e=await(0,C.a)(t.pluginId).then((t=>{const e=S(t);return e?(j.h$.emit(h.AppEvents.alertError,[e]),this.setState({nav:P(e)}),null):(0,E.Av)(t)}));this.setState({plugin:e,loading:!1,nav:void 0})}catch(t){this.setState({plugin:null,loading:!1,nav:g()})}}componentDidMount(){this.loadPluginSettings()}componentDidUpdate(t){const{params:e}=this.props.match;t.match.params.pluginId!==e.pluginId&&(this.setState({loading:!0}),this.loadPluginSettings())}render(){const{loading:t,plugin:e,nav:n,portalNode:o}=this.state;return e&&!e.root?b||(b=(0,x.jsx)("div",{children:"No Root App"})):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(p,{node:o,children:e&&e.root&&(0,x.jsx)(e.root,{meta:e.meta,basename:this.props.match.url,onNavChanged:this.onNavChanged,query:this.props.queryParams,path:this.props.location.pathname})}),n?(0,x.jsx)(N.Z,{navModel:n,children:(0,x.jsx)(N.Z.Contents,{isLoading:t,children:(0,x.jsx)(d,{node:o})})}):(0,x.jsxs)(N.Z,{children:[(0,x.jsx)(d,{node:o}),t&&(y||(y=(0,x.jsx)(w.Z,{})))]})]})}}const O=I}}]);
  2. //# sourceMappingURL=AppRootPage.2255d1f23f976dbf2f3e.js.map