浏览代码

wip: panel plugin not found

Torkel Ödegaard 7 年之前
父节点
当前提交
119e94f745

+ 19 - 2
public/app/features/dashboard/dashgrid/DashboardPanel.tsx

@@ -5,13 +5,14 @@ import { getAngularLoader, AngularComponent } from 'app/core/services/AngularLoa
 import { importPluginModule } from 'app/features/plugins/plugin_loader';
 
 import { AddPanelPanel } from './AddPanelPanel';
+import { PanelPluginNotFound } from './PanelPluginNotFound';
 import { DashboardRow } from './DashboardRow';
-import { PanelPlugin } from 'app/types/plugins';
 import { PanelChrome } from './PanelChrome';
 import { PanelEditor } from './PanelEditor';
 
 import { PanelModel } from '../panel_model';
 import { DashboardModel } from '../dashboard_model';
+import { PanelPlugin, PanelProps } from 'app/types';
 
 export interface Props {
   panel: PanelModel;
@@ -70,7 +71,7 @@ export class DashboardPanel extends PureComponent<Props, State> {
 
     // handle plugin loading & changing of plugin type
     if (!this.state.plugin || this.state.plugin.id !== panel.type) {
-      const plugin = config.panels[panel.type];
+      const plugin = config.panels[panel.type] || this.getPanelPluginNotFound(panel.type);
 
       if (plugin.exports) {
         this.cleanUpAngularPanel();
@@ -87,6 +88,22 @@ export class DashboardPanel extends PureComponent<Props, State> {
     }
   }
 
+  getPanelPluginNotFound(id: string): PanelPlugin {
+    const NotFound = class NotFound extends PureComponent<PanelProps> {
+      render() {
+        return <PanelPluginNotFound pluginId={id} />;
+      }
+    };
+
+    return {
+      id: id,
+      name: id,
+      exports: {
+        PanelComponent: NotFound,
+      },
+    };
+  }
+
   componentDidMount() {
     this.loadPlugin();
   }

+ 1 - 1
public/app/features/dashboard/dashgrid/EditorTabBody.tsx

@@ -81,7 +81,7 @@ export class EditorTabBody extends PureComponent<Props, State> {
           {toolbarItems.map(item => this.renderButton(item))}
         </div>
         <div className="panel-editor__scroll">
-          <CustomScrollbar>
+          <CustomScrollbar autoHide={false}>
             <div className="panel-editor__content">
               <FadeIn in={openView !== null} duration={200}>
                 {openView && this.renderOpenView(openView)}

+ 16 - 0
public/app/features/dashboard/dashgrid/PanelPluginNotFound.tsx

@@ -0,0 +1,16 @@
+import _ from 'lodash';
+import React, { PureComponent } from 'react';
+
+interface Props {
+  pluginId: string;
+}
+
+export class PanelPluginNotFound extends PureComponent<Props> {
+  constructor(props) {
+    super(props);
+  }
+
+  render() {
+    return <h2>Panel plugin with id {this.props.id} could not be found</h2>;
+  }
+}

+ 2 - 1
public/app/types/index.ts

@@ -21,7 +21,7 @@ import {
   DataQueryOptions,
 } from './series';
 import { PanelProps, PanelOptionsProps } from './panel';
-import { PluginDashboard, PluginMeta, Plugin, PluginsState } from './plugins';
+import { PluginDashboard, PluginMeta, Plugin, PanelPlugin, PluginsState } from './plugins';
 import { Organization, OrganizationPreferences, OrganizationState } from './organization';
 import {
   AppNotification,
@@ -69,6 +69,7 @@ export {
   UsersState,
   TimeRange,
   LoadingState,
+  PanelPlugin,
   PanelProps,
   PanelOptionsProps,
   TimeSeries,

+ 2 - 2
public/app/types/plugins.ts

@@ -12,13 +12,13 @@ export interface PluginExports {
   // Panel plugin
   PanelCtrl?;
   PanelComponent?: ComponentClass<PanelProps>;
-  PanelOptionsComponent: ComponentClass<PanelOptionsProps>;
+  PanelOptionsComponent?: ComponentClass<PanelOptionsProps>;
 }
 
 export interface PanelPlugin {
   id: string;
   name: string;
-  meta: any;
+  meta: PluginMeta;
   hideFromList: boolean;
   module: string;
   baseUrl: string;