2019-06-03 10:55:59 -05:00
|
|
|
import { getBackendSrv } from '@grafana/runtime';
|
2020-02-10 07:23:54 -06:00
|
|
|
import { PanelPlugin } from '@grafana/data';
|
2020-01-13 01:03:22 -06:00
|
|
|
import { ThunkResult } from 'app/types';
|
2021-09-09 05:20:35 -05:00
|
|
|
import { config } from 'app/core/config';
|
2021-10-13 01:53:36 -05:00
|
|
|
import { importPanelPlugin } from 'app/features/plugins/importPanelPlugin';
|
2021-09-09 05:20:35 -05:00
|
|
|
import {
|
|
|
|
loadPanelPlugin as loadPanelPluginNew,
|
|
|
|
loadPluginDashboards as loadPluginDashboardsNew,
|
|
|
|
} from '../admin/state/actions';
|
2020-10-27 07:08:08 -05:00
|
|
|
import {
|
|
|
|
pluginDashboardsLoad,
|
|
|
|
pluginDashboardsLoaded,
|
|
|
|
pluginsLoaded,
|
|
|
|
panelPluginLoaded,
|
|
|
|
pluginsErrorsLoaded,
|
|
|
|
} from './reducers';
|
2018-09-25 07:53:55 -05:00
|
|
|
|
|
|
|
export function loadPlugins(): ThunkResult<void> {
|
2021-01-20 00:59:48 -06:00
|
|
|
return async (dispatch) => {
|
2020-10-27 07:08:08 -05:00
|
|
|
const plugins = await getBackendSrv().get('api/plugins', { embedded: 0 });
|
|
|
|
dispatch(pluginsLoaded(plugins));
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function loadPluginsErrors(): ThunkResult<void> {
|
2021-01-20 00:59:48 -06:00
|
|
|
return async (dispatch) => {
|
2020-10-27 07:08:08 -05:00
|
|
|
const errors = await getBackendSrv().get('api/plugins/errors');
|
|
|
|
dispatch(pluginsErrorsLoaded(errors));
|
2018-09-25 07:53:55 -05:00
|
|
|
};
|
|
|
|
}
|
2018-10-17 07:36:18 -05:00
|
|
|
|
2021-09-09 05:20:35 -05:00
|
|
|
function loadPluginDashboardsOriginal(): ThunkResult<void> {
|
2018-10-17 07:36:18 -05:00
|
|
|
return async (dispatch, getStore) => {
|
2019-01-28 10:11:55 -06:00
|
|
|
dispatch(pluginDashboardsLoad());
|
2018-10-17 07:36:18 -05:00
|
|
|
const dataSourceType = getStore().dataSources.dataSource.type;
|
|
|
|
const response = await getBackendSrv().get(`api/plugins/${dataSourceType}/dashboards`);
|
|
|
|
dispatch(pluginDashboardsLoaded(response));
|
|
|
|
};
|
|
|
|
}
|
2020-02-10 07:23:54 -06:00
|
|
|
|
2021-09-09 05:20:35 -05:00
|
|
|
function loadPanelPluginOriginal(pluginId: string): ThunkResult<Promise<PanelPlugin>> {
|
2020-02-10 07:23:54 -06:00
|
|
|
return async (dispatch, getStore) => {
|
|
|
|
let plugin = getStore().plugins.panels[pluginId];
|
|
|
|
|
|
|
|
if (!plugin) {
|
|
|
|
plugin = await importPanelPlugin(pluginId);
|
|
|
|
|
|
|
|
// second check to protect against raise condition
|
|
|
|
if (!getStore().plugins.panels[pluginId]) {
|
|
|
|
dispatch(panelPluginLoaded(plugin));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return plugin;
|
|
|
|
};
|
|
|
|
}
|
2021-09-09 05:20:35 -05:00
|
|
|
|
|
|
|
export const loadPluginDashboards = config.pluginAdminEnabled ? loadPluginDashboardsNew : loadPluginDashboardsOriginal;
|
|
|
|
export const loadPanelPlugin = config.pluginAdminEnabled ? loadPanelPluginNew : loadPanelPluginOriginal;
|