Plugins: Fix importing panel modules (#45590)

This commit is contained in:
Torkel Ödegaard 2022-02-18 12:51:55 +01:00 committed by GitHub
parent 530913dd37
commit 0838f4b1ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,22 +28,25 @@ export function importPanelPluginFromMeta(meta: grafanaData.PanelPluginMeta): Pr
return getPanelPlugin(meta);
}
async function getPanelPlugin(meta: grafanaData.PanelPluginMeta): Promise<grafanaData.PanelPlugin> {
try {
const pluginExports = await importPluginModule(meta.module, meta.info?.version);
let plugin = pluginExports.plugin;
if (!plugin && pluginExports.PanelCtrl) {
plugin = new grafanaData.PanelPlugin(null);
plugin.angularPanelCtrl = pluginExports.PanelCtrl;
}
plugin.meta = meta;
return plugin;
} catch (err) {
// TODO, maybe a different error plugin
console.warn('Error loading panel plugin: ' + meta.id, err);
return getPanelPluginLoadError(meta, err);
}
function getPanelPlugin(meta: grafanaData.PanelPluginMeta): Promise<grafanaData.PanelPlugin> {
return importPluginModule(meta.module, meta.info?.version)
.then((pluginExports) => {
if (pluginExports.plugin) {
return pluginExports.plugin as grafanaData.PanelPlugin;
} else if (pluginExports.PanelCtrl) {
const plugin = new grafanaData.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: ' + meta.id, err);
return getPanelPluginLoadError(meta, err);
});
}