grafana/public/app/features/plugins/PluginSettingsCache.ts
Jack Westbrook 7cf3c84c92
Datasources: Fix deletion of datasource if plugin cannot be found (#40095)
* fix(pluginsettings): reject with error so datasource plugin loading failures still render ui

* feat(pluginpage): handle plugin loading error

* refactor(datasources): separate out datasource and meta loading so store has info for deletion

* fix(datasourcesettings): introduce loading flag to wait for datasource and meta loading

* test(datasourcesettings): fix failing test

* test(datasources): assert loading status of datasource settings

* test(datasources): update action tests for latest changes
2021-10-08 12:31:43 +02:00

25 lines
622 B
TypeScript

import { getBackendSrv } from '@grafana/runtime';
import { PluginMeta } from '@grafana/data';
type PluginCache = {
[key: string]: PluginMeta;
};
const pluginInfoCache: PluginCache = {};
export function getPluginSettings(pluginId: string): Promise<PluginMeta> {
const v = pluginInfoCache[pluginId];
if (v) {
return Promise.resolve(v);
}
return getBackendSrv()
.get(`/api/plugins/${pluginId}/settings`)
.then((settings: any) => {
pluginInfoCache[pluginId] = settings;
return settings;
})
.catch((err: any) => {
return Promise.reject(new Error('Unknown Plugin'));
});
}