mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
27 lines
706 B
TypeScript
27 lines
706 B
TypeScript
|
import useAsync from 'react-use/lib/useAsync';
|
||
|
|
||
|
import { PluginType } from '@grafana/data';
|
||
|
|
||
|
import { getPluginSettings } from '../pluginSettings';
|
||
|
import { importAppPlugin } from '../plugin_loader';
|
||
|
|
||
|
export const useImportAppPlugin = (id: string) => {
|
||
|
return useAsync(async () => {
|
||
|
const pluginMeta = await getPluginSettings(id);
|
||
|
|
||
|
if (!pluginMeta) {
|
||
|
throw new Error(`Unknown plugin: "${id}"`);
|
||
|
}
|
||
|
|
||
|
if (pluginMeta.type !== PluginType.app) {
|
||
|
throw new Error(`Plugin must be an app (currently "${pluginMeta.type}")`);
|
||
|
}
|
||
|
|
||
|
if (!pluginMeta.enabled) {
|
||
|
throw new Error(`Application "${id}" is not enabled`);
|
||
|
}
|
||
|
|
||
|
return await importAppPlugin(pluginMeta);
|
||
|
});
|
||
|
};
|