grafana/public/app/features/plugins/state/actions.ts
Torkel Ödegaard 49407987fe
Dashboard: Move some plugin & panel state to redux (#22052)
* WIP: dashboard panel redux

* Progress

* Progress

* Changing plugin type

* Progress

* Updated

* Progess

* Fixed timing issue

* Updated

* Fixed unit tests

* Fixed issue in dashboard page

* Updated test
2020-02-10 14:23:54 +01:00

39 lines
1.3 KiB
TypeScript

import { getBackendSrv } from '@grafana/runtime';
import { PanelPlugin } from '@grafana/data';
import { ThunkResult } from 'app/types';
import { pluginDashboardsLoad, pluginDashboardsLoaded, pluginsLoaded, panelPluginLoaded } from './reducers';
import { importPanelPlugin } from 'app/features/plugins/plugin_loader';
export function loadPlugins(): ThunkResult<void> {
return async dispatch => {
const result = await getBackendSrv().get('api/plugins', { embedded: 0 });
dispatch(pluginsLoaded(result));
};
}
export function loadPluginDashboards(): ThunkResult<void> {
return async (dispatch, getStore) => {
dispatch(pluginDashboardsLoad());
const dataSourceType = getStore().dataSources.dataSource.type;
const response = await getBackendSrv().get(`api/plugins/${dataSourceType}/dashboards`);
dispatch(pluginDashboardsLoaded(response));
};
}
export function loadPanelPlugin(pluginId: string): ThunkResult<Promise<PanelPlugin>> {
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;
};
}