mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Runtime: Expose panel plugin import utils (#60799)
* Runtime: Expose plugin import utils * Review * Fix
This commit is contained in:
parent
7de81ca673
commit
370aa9f6ea
@ -6,7 +6,13 @@
|
||||
export * from './services';
|
||||
export * from './config';
|
||||
export * from './analytics/types';
|
||||
export { loadPluginCss, SystemJS, type PluginCssOptions } from './utils/plugin';
|
||||
export {
|
||||
loadPluginCss,
|
||||
SystemJS,
|
||||
type PluginCssOptions,
|
||||
setPluginImportUtils,
|
||||
getPluginImportUtils,
|
||||
} from './utils/plugin';
|
||||
export { reportMetaAnalytics, reportInteraction, reportPageview, reportExperimentView } from './analytics/utils';
|
||||
export { featureEnabled } from './utils/licensing';
|
||||
export { logInfo, logDebug, logWarning, logError } from './utils/logging';
|
||||
|
@ -1,6 +1,8 @@
|
||||
// @ts-ignore
|
||||
import System from 'systemjs/dist/system.js';
|
||||
|
||||
import { PanelPlugin } from '@grafana/data';
|
||||
|
||||
import { config } from '../config';
|
||||
|
||||
// @ts-ignore
|
||||
@ -32,3 +34,26 @@ export function loadPluginCss(options: PluginCssOptions): Promise<any> {
|
||||
const theme = config.bootData.user.lightTheme ? options.light : options.dark;
|
||||
return SystemJS.import(`${theme}!css`);
|
||||
}
|
||||
|
||||
interface PluginImportUtils {
|
||||
importPanelPlugin: (id: string) => Promise<PanelPlugin>;
|
||||
getPanelPluginFromCache: (id: string) => PanelPlugin | undefined;
|
||||
}
|
||||
|
||||
let pluginImportUtils: PluginImportUtils | undefined;
|
||||
|
||||
export function setPluginImportUtils(utils: PluginImportUtils) {
|
||||
if (pluginImportUtils) {
|
||||
throw new Error('pluginImportUtils should only be set once, when Grafana is starting.');
|
||||
}
|
||||
|
||||
pluginImportUtils = utils;
|
||||
}
|
||||
|
||||
export function getPluginImportUtils(): PluginImportUtils {
|
||||
if (!pluginImportUtils) {
|
||||
throw new Error('pluginImportUtils can only be used after Grafana instance has started.');
|
||||
}
|
||||
|
||||
return pluginImportUtils;
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ import {
|
||||
setLocationSrv,
|
||||
setQueryRunnerFactory,
|
||||
setRunRequest,
|
||||
setPluginImportUtils,
|
||||
} from '@grafana/runtime';
|
||||
import { setPanelDataErrorView } from '@grafana/runtime/src/components/PanelDataErrorView';
|
||||
import { setPanelRenderer } from '@grafana/runtime/src/components/PanelRenderer';
|
||||
@ -68,6 +69,7 @@ import { getTimeSrv } from './features/dashboard/services/TimeSrv';
|
||||
import { PanelDataErrorView } from './features/panel/components/PanelDataErrorView';
|
||||
import { PanelRenderer } from './features/panel/components/PanelRenderer';
|
||||
import { DatasourceSrv } from './features/plugins/datasource_srv';
|
||||
import { importPanelPlugin, syncGetPanelPlugin } from './features/plugins/importPanelPlugin';
|
||||
import { preloadPlugins } from './features/plugins/pluginPreloader';
|
||||
import { QueryRunner } from './features/query/state/QueryRunner';
|
||||
import { runRequest } from './features/query/state/runRequest';
|
||||
@ -145,6 +147,12 @@ export class GrafanaApp {
|
||||
// Provide runRequest implementation to packages, @grafana/scenes in particular
|
||||
setRunRequest(runRequest);
|
||||
|
||||
// Privide plugin import utils to packages, @grafana/scenes in particular
|
||||
setPluginImportUtils({
|
||||
importPanelPlugin,
|
||||
getPanelPluginFromCache: syncGetPanelPlugin,
|
||||
});
|
||||
|
||||
locationUtil.initialize({
|
||||
config,
|
||||
getTimeRangeForUrl: getTimeSrv().timeRangeForUrl,
|
||||
|
Loading…
Reference in New Issue
Block a user