mirror of
https://github.com/grafana/grafana.git
synced 2024-11-29 12:14:08 -06:00
Plugins: Fix importing panel modules (#45590)
This commit is contained in:
parent
530913dd37
commit
0838f4b1ad
@ -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);
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user