mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
@@ -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 }));
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user