@grafana/data#PanelPlugin TypeScript Examples

The following examples show how to use @grafana/data#PanelPlugin. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: module.tsx    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
plugin = new PanelPlugin<TextOptions>(TextPanel)
  .setDefaults(defaults)
  .setEditor(TextPanelEditor)
  .setPanelChangeHandler((options: TextOptions, prevPluginId: string, prevOptions: any) => {
    if (prevPluginId === 'text') {
      return prevOptions as TextOptions;
    }
    return options;
  })
Example #2
Source File: PanelEditor.tsx    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
renderFieldOptions(plugin: PanelPlugin) {
    const { panel, data } = this.props;

    const fieldOptions = panel.options['fieldOptions'] as FieldConfigSource;

    if (!fieldOptions) {
      return null;
    }

    return (
      <FieldConfigEditor
        config={fieldOptions}
        plugin={plugin}
        onChange={this.onFieldConfigsChange}
        data={data.series}
      />
    );
  }
Example #3
Source File: PanelEditor.tsx    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
renderPanelSettings(plugin: PanelPlugin) {
    const { data, panel, dashboard } = this.props;

    if (plugin.editor && panel) {
      return (
        <div style={{ marginTop: '10px' }}>
          <plugin.editor data={data} options={panel.getOptions()} onOptionsChange={this.onPanelOptionsChanged} />
        </div>
      );
    }

    return <AngularPanelOptions panel={panel} dashboard={dashboard} plugin={plugin} />;
  }
Example #4
Source File: module.ts    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
plugin = new PanelPlugin<AnnoOptions>(AnnoListPanel)
  .setDefaults(defaults)
  .setEditor(AnnoListEditor)

  // TODO, we should support this directly in the plugin infrastructure
  .setPanelChangeHandler((options: AnnoOptions, prevPluginId: string, prevOptions: any) => {
    if (prevPluginId === 'ryantxu-annolist-panel') {
      return prevOptions as AnnoOptions;
    }
    return options;
  })
Example #5
Source File: PanelPluginError.tsx    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
export function getPanelPluginLoadError(meta: PanelPluginMeta, err: any): PanelPlugin {
  const LoadError = class LoadError extends PureComponent<PanelProps> {
    render() {
      const text = (
        <>
          Check the server startup logs for more information. <br />
          If this plugin was loaded from git, make sure it was compiled.
        </>
      );
      return <PanelPluginError title={`Error loading: ${meta.id}`} text={text} />;
    }
  };
  const plugin = new PanelPlugin(LoadError);
  plugin.meta = meta;
  plugin.loadError = true;
  return plugin;
}
Example #6
Source File: PanelPluginError.tsx    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
export function getPanelPluginNotFound(id: string): PanelPlugin {
  const NotFound = class NotFound extends PureComponent<PanelProps> {
    render() {
      return <PanelPluginError title={`Panel plugin not found: ${id}`} />;
    }
  };

  const plugin = new PanelPlugin(NotFound);
  plugin.meta = {
    id: id,
    name: id,
    sort: 100,
    type: PluginType.panel,
    module: '',
    baseUrl: '',
    info: {
      author: {
        name: '',
      },
      description: '',
      links: [],
      logos: {
        large: '',
        small: '',
      },
      screenshots: [],
      updated: '',
      version: '',
    },
  };
  return plugin;
}
Example #7
Source File: PanelModel.ts    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
private applyPluginOptionDefaults(plugin: PanelPlugin) {
    if (plugin.angularConfigCtrl) {
      return;
    }
    this.options = _.mergeWith({}, plugin.defaults, this.options || {}, (objValue: any, srcValue: any): any => {
      if (_.isArray(srcValue)) {
        return srcValue;
      }
    });
  }
Example #8
Source File: PanelModel.ts    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
pluginLoaded(plugin: PanelPlugin) {
    this.plugin = plugin;

    if (plugin.panel && plugin.onPanelMigration) {
      const version = getPluginVersion(plugin);

      if (version !== this.pluginVersion) {
        this.options = plugin.onPanelMigration(this);
        this.pluginVersion = version;
      }
    }

    this.applyPluginOptionDefaults(plugin);
  }
Example #9
Source File: reducers.ts    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
pluginsSlice = createSlice({
  name: 'plugins',
  initialState,
  reducers: {
    pluginsLoaded: (state, action: PayloadAction<PluginMeta[]>) => {
      state.hasFetched = true;
      state.plugins = action.payload;
    },
    setPluginsSearchQuery: (state, action: PayloadAction<string>) => {
      state.searchQuery = action.payload;
    },
    setPluginsLayoutMode: (state, action: PayloadAction<LayoutMode>) => {
      state.layoutMode = action.payload;
    },
    pluginDashboardsLoad: (state, action: PayloadAction<undefined>) => {
      state.isLoadingPluginDashboards = true;
      state.dashboards = [];
    },
    pluginDashboardsLoaded: (state, action: PayloadAction<PluginDashboard[]>) => {
      state.isLoadingPluginDashboards = false;
      state.dashboards = action.payload;
    },
    panelPluginLoaded: (state, action: PayloadAction<PanelPlugin>) => {
      state.panels[action.payload.meta!.id] = action.payload;
    },
  },
})
Example #10
Source File: actions.ts    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
export function loadPanelPlugin(pluginId: string): ThunkResult<Promise<PanelPlugin>> {
  return async (dispatch, getStore) => {
    let plugin = getStore().plugins.panels[pluginId];

    if (!plugin) {
      plugin = await importPanelPlugin(pluginId);

      // second check to protect against raise condition
      if (!getStore().plugins.panels[pluginId]) {
        dispatch(panelPluginLoaded(plugin));
      }
    }

    return plugin;
  };
}
Example #11
Source File: pluginMocks.ts    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
getPanelPlugin = (
  options: Partial<PanelPluginMeta>,
  reactPanel?: ComponentType<PanelProps>,
  angularPanel?: any
): PanelPlugin => {
  const plugin = new PanelPlugin(reactPanel);
  plugin.angularPanelCtrl = angularPanel;
  plugin.meta = {
    id: options.id,
    type: PluginType.panel,
    name: options.id,
    sort: options.sort || 1,
    info: {
      author: {
        name: options.id + 'name',
      },
      description: '',
      links: [],
      logos: {
        large: '',
        small: '',
      },
      screenshots: [],
      updated: '',
      version: '',
    },
    hideFromList: options.hideFromList === true,
    module: '',
    baseUrl: '',
  };
  return plugin;
}
Example #12
Source File: plugin_loader.ts    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
export function importPanelPlugin(id: string): Promise<PanelPlugin> {
  const loaded = panelCache[id];

  if (loaded) {
    return loaded;
  }

  const meta = config.panels[id];

  if (!meta) {
    return Promise.resolve(getPanelPluginNotFound(id));
  }

  panelCache[id] = importPluginModule(meta.module)
    .then(pluginExports => {
      if (pluginExports.plugin) {
        return pluginExports.plugin as PanelPlugin;
      } else if (pluginExports.PanelCtrl) {
        const plugin = new PanelPlugin(null);
        plugin.angularPanelCtrl = pluginExports.PanelCtrl;
        return plugin;
      }
      throw new Error('missing export: plugin or PanelCtrl');
    })
    .then(plugin => {
      plugin.meta = meta;
      return plugin;
    })
    .catch(err => {
      // TODO, maybe a different error plugin
      console.warn('Error loading panel plugin: ' + id, err);
      return getPanelPluginLoadError(meta, err);
    });

  return panelCache[id];
}
Example #13
Source File: module.ts    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
plugin = new PanelPlugin(GettingStarted)
Example #14
Source File: module.ts    From grafana-weathermap-panel with Apache License 2.0 5 votes vote down vote up
plugin = new PanelPlugin<SimpleOptions>(SimplePanel).setDefaults(defaults).setEditor(SimpleEditor)
Example #15
Source File: module.tsx    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
plugin = new PanelPlugin<Options>(GraphPanel).setDefaults(defaults).setEditor(GraphPanelEditor)
Example #16
Source File: module.tsx    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
plugin = new PanelPlugin(GrafanaLinksPanel).setDefaults({}).setNoPadding()
Example #17
Source File: module.tsx    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
plugin = new PanelPlugin<Options>(LogsPanel).setDefaults(defaults).setEditor(LogsPanelEditor)
Example #18
Source File: module.tsx    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
plugin = new PanelPlugin<NewsOptions>(NewsPanel).setDefaults(defaults).setEditor(NewsPanelEditor)
Example #19
Source File: module.tsx    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
plugin = new PanelPlugin<PieChartOptions>(PieChartPanel)
  .setDefaults(defaults)
  .setEditor(PieChartPanelEditor)
Example #20
Source File: module.tsx    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
plugin = new PanelPlugin<StatPanelOptions>(StatPanel)
  .setDefaults(defaults)
  .setEditor(StatPanelEditor)
  .setNoPadding()
  .setPanelChangeHandler(sharedSingleStatPanelChangedHandler)
  .setMigrationHandler(sharedSingleStatMigrationHandler)
Example #21
Source File: module.ts    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
plugin = new PanelPlugin(null)
Example #22
Source File: module.tsx    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
plugin = new PanelPlugin<Options>(TablePanel)
  .setDefaults(defaults)
  .setCustomFieldConfigs(tableFieldRegistry)
  .setEditor(TablePanelEditor)
Example #23
Source File: module.tsx    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
plugin = new PanelPlugin<GaugeOptions>(GaugePanel)
  .setDefaults(defaults)
  .setEditor(GaugePanelEditor)
  .setPanelChangeHandler(gaugePanelChangedHandler)
  .setMigrationHandler(gaugePanelMigrationHandler)
Example #24
Source File: module.tsx    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
plugin = new PanelPlugin<BarGaugeOptions>(BarGaugePanel)
  .setDefaults(defaults)
  .setEditor(BarGaugePanelEditor)
  .setPanelChangeHandler(sharedSingleStatPanelChangedHandler)
  .setMigrationHandler(barGaugePanelMigrationHandler)
Example #25
Source File: plugin_loader.ts    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
grafanaUI.PanelPlugin = grafanaData.PanelPlugin;
Example #26
Source File: PanelModel.ts    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
function getPluginVersion(plugin: PanelPlugin): string {
  return plugin && plugin.meta.info.version ? plugin.meta.info.version : config.buildInfo.version;
}
Example #27
Source File: PanelModel.ts    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
plugin?: PanelPlugin;
Example #28
Source File: PanelModel.ts    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
changePlugin(newPlugin: PanelPlugin) {
    const pluginId = newPlugin.meta.id;
    const oldOptions: any = this.getOptionsToRemember();
    const oldPluginId = this.type;
    const wasAngular = !!this.plugin.angularPanelCtrl;

    // remove panel type specific  options
    for (const key of _.keys(this)) {
      if (mustKeepProps[key]) {
        continue;
      }

      delete (this as any)[key];
    }

    this.cachedPluginOptions[oldPluginId] = oldOptions;
    this.restorePanelOptions(pluginId);

    // Let panel plugins inspect options from previous panel and keep any that it can use
    if (newPlugin.onPanelTypeChanged) {
      let old: any = {};

      if (wasAngular) {
        old = { angular: oldOptions };
      } else if (oldOptions && oldOptions.options) {
        old = oldOptions.options;
      }
      this.options = this.options || {};
      Object.assign(this.options, newPlugin.onPanelTypeChanged(this.options, oldPluginId, old));
    }

    // switch
    this.type = pluginId;
    this.plugin = newPlugin;
    this.applyPluginOptionDefaults(newPlugin);

    if (newPlugin.onPanelMigration) {
      this.pluginVersion = getPluginVersion(newPlugin);
    }
  }
Example #29
Source File: DashboardPanel.tsx    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
renderPanel(plugin: PanelPlugin) {
    const { dashboard, panel, isFullscreen, isEditing, isInView, isInEditMode } = this.props;

    const autoSizerStyle = { height: isEditing ? '100%' : '' };

    return (
      <AutoSizer style={autoSizerStyle}>
        {({ width, height }) => {
          if (width === 0) {
            return null;
          }

          if (plugin.angularPanelCtrl) {
            return (
              <PanelChromeAngular
                plugin={plugin}
                panel={panel}
                dashboard={dashboard}
                isFullscreen={isFullscreen}
                isInView={isInView}
                width={width}
                height={height}
              />
            );
          }

          return (
            <PanelChrome
              plugin={plugin}
              panel={panel}
              dashboard={dashboard}
              isFullscreen={isFullscreen}
              isInView={isInView}
              isInEditMode={isInEditMode}
              width={width}
              height={height}
            />
          );
        }}
      </AutoSizer>
    );
  }