PanelState: Introduce a new separate redux panel state not keyed by panel.id (#40302)

* Initial pass to move panel state to it's own, and make it by key not panel.id

* Progress

* Not making much progress, having panel.key be mutable is causing a lot of issues

* Think this is starting to work

* Began fixing tests

* Add selector

* Bug fixes and changes to cleanup, and fixing all flicking when switching library panels

* Removed console.log

* fixes after merge

* fixing tests

* fixing tests

* Added new test for changePlugin thunk
This commit is contained in:
Torkel Ödegaard
2021-10-13 08:53:36 +02:00
committed by GitHub
parent 3d9e2d8c82
commit d62ca1283c
48 changed files with 431 additions and 345 deletions

View File

@ -0,0 +1,53 @@
import config from 'app/core/config';
import * as grafanaData from '@grafana/data';
import { getPanelPluginLoadError } from '../panel/components/PanelPluginError';
import { importPluginModule } from './plugin_loader';
interface PanelCache {
[key: string]: Promise<grafanaData.PanelPlugin>;
}
const panelCache: PanelCache = {};
export function importPanelPlugin(id: string): Promise<grafanaData.PanelPlugin> {
const loaded = panelCache[id];
if (loaded) {
return loaded;
}
const meta = config.panels[id];
if (!meta) {
throw new Error(`Plugin ${id} not found`);
}
panelCache[id] = getPanelPlugin(meta);
return panelCache[id];
}
export function importPanelPluginFromMeta(meta: grafanaData.PanelPluginMeta): Promise<grafanaData.PanelPlugin> {
return getPanelPlugin(meta);
}
function getPanelPlugin(meta: grafanaData.PanelPluginMeta): Promise<grafanaData.PanelPlugin> {
return importPluginModule(meta.module)
.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);
});
}