utils.ts 996 B

123456789101112131415161718192021222324252627282930
  1. import { GrafanaPlugin, PanelPluginMeta, PluginType } from '@grafana/data';
  2. import { importPanelPluginFromMeta } from './importPanelPlugin';
  3. import { getPluginSettings } from './pluginSettings';
  4. import { importAppPlugin, importDataSourcePlugin } from './plugin_loader';
  5. export async function loadPlugin(pluginId: string): Promise<GrafanaPlugin> {
  6. const info = await getPluginSettings(pluginId);
  7. let result: GrafanaPlugin | undefined;
  8. if (info.type === PluginType.app) {
  9. result = await importAppPlugin(info);
  10. }
  11. if (info.type === PluginType.datasource) {
  12. result = await importDataSourcePlugin(info);
  13. }
  14. if (info.type === PluginType.panel) {
  15. const panelPlugin = await importPanelPluginFromMeta(info as PanelPluginMeta);
  16. result = panelPlugin as unknown as GrafanaPlugin;
  17. }
  18. if (info.type === PluginType.renderer) {
  19. result = { meta: info } as GrafanaPlugin;
  20. }
  21. if (!result) {
  22. throw new Error('Unknown Plugin type: ' + info.type);
  23. }
  24. return result;
  25. }