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
This commit is contained in:
Torkel Ödegaard
2020-02-10 14:23:54 +01:00
committed by GitHub
parent 258b507179
commit 49407987fe
21 changed files with 688 additions and 146 deletions

View File

@@ -3,10 +3,12 @@ import { getBackendSrv } from '@grafana/runtime';
import { createSuccessNotification } from 'app/core/copy/appNotification';
// Actions
import { loadPluginDashboards } from '../../plugins/state/actions';
import { loadDashboardPermissions } from './reducers';
import { loadDashboardPermissions, dashboardPanelTypeChanged } from './reducers';
import { notifyApp } from 'app/core/actions';
import { loadPanelPlugin } from 'app/features/plugins/state/actions';
// Types
import { DashboardAcl, DashboardAclUpdateDTO, NewDashboardAclItem, PermissionLevel, ThunkResult } from 'app/types';
import { PanelModel } from './PanelModel';
export function getDashboardPermissions(id: number): ThunkResult<void> {
return async dispatch => {
@@ -108,3 +110,35 @@ export function removeDashboard(uri: string): ThunkResult<void> {
dispatch(loadPluginDashboards());
};
}
export function initDashboardPanel(panel: PanelModel): ThunkResult<void> {
return async (dispatch, getStore) => {
let plugin = getStore().plugins.panels[panel.type];
if (!plugin) {
plugin = await dispatch(loadPanelPlugin(panel.type));
}
if (!panel.plugin) {
panel.pluginLoaded(plugin);
}
};
}
export function changePanelPlugin(panel: PanelModel, pluginId: string): ThunkResult<void> {
return async (dispatch, getStore) => {
// ignore action is no change
if (panel.type === pluginId) {
return;
}
let plugin = getStore().plugins.panels[pluginId];
if (!plugin) {
plugin = await dispatch(loadPanelPlugin(pluginId));
}
panel.changePlugin(plugin);
dispatch(dashboardPanelTypeChanged({ panelId: panel.id, pluginId }));
};
}