mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Dashboard: Refactor panel cleanup (#47323)
This commit is contained in:
@@ -256,7 +256,6 @@ export class PanelEditorUnconnected extends PureComponent<Props> {
|
||||
lazy={false}
|
||||
width={panelSize.width}
|
||||
height={panelSize.height}
|
||||
skipStateCleanUp={true}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { thunkTester } from '../../../../../../test/core/thunk/thunkTester';
|
||||
import { closeEditor, initialState, PanelEditorState } from './reducers';
|
||||
import { exitPanelEditor, initPanelEditor, skipPanelUpdate } from './actions';
|
||||
import { cleanUpPanelState, panelModelAndPluginReady } from 'app/features/panel/state/reducers';
|
||||
import { panelModelAndPluginReady, removePanel } from 'app/features/panel/state/reducers';
|
||||
import { DashboardModel, PanelModel } from '../../../state';
|
||||
import { getPanelPlugin } from 'app/features/plugins/__mocks__/pluginMocks';
|
||||
|
||||
@@ -48,6 +48,7 @@ describe('panelEditor actions', () => {
|
||||
};
|
||||
|
||||
const dispatchedActions = await thunkTester({
|
||||
panels: {},
|
||||
panelEditor: state,
|
||||
dashboard: {
|
||||
getModel: () => dashboard,
|
||||
@@ -57,7 +58,7 @@ describe('panelEditor actions', () => {
|
||||
.whenThunkIsDispatched();
|
||||
|
||||
expect(dispatchedActions.length).toBe(2);
|
||||
expect(dispatchedActions[0].type).toBe(cleanUpPanelState.type);
|
||||
expect(dispatchedActions[0].type).toBe(removePanel.type);
|
||||
expect(dispatchedActions[1].type).toBe(closeEditor.type);
|
||||
expect(sourcePanel.getOptions()).toEqual({ prop: true });
|
||||
expect(sourcePanel.id).toEqual(12);
|
||||
@@ -84,6 +85,7 @@ describe('panelEditor actions', () => {
|
||||
|
||||
const dispatchedActions = await thunkTester({
|
||||
panelEditor: state,
|
||||
panels: {},
|
||||
dashboard: {
|
||||
getModel: () => dashboard,
|
||||
},
|
||||
@@ -119,6 +121,7 @@ describe('panelEditor actions', () => {
|
||||
|
||||
const dispatchedActions = await thunkTester({
|
||||
panelEditor: state,
|
||||
panels: {},
|
||||
dashboard: {
|
||||
getModel: () => dashboard,
|
||||
},
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { DashboardModel, PanelModel } from '../../../state';
|
||||
import { pick } from 'lodash';
|
||||
import { ThunkResult } from 'app/types';
|
||||
import store from 'app/core/store';
|
||||
import { panelModelAndPluginReady } from 'app/features/panel/state/reducers';
|
||||
import { cleanUpPanelState, initPanelState } from 'app/features/panel/state/actions';
|
||||
import {
|
||||
closeEditor,
|
||||
PANEL_EDITOR_UI_STATE_STORAGE_KEY,
|
||||
@@ -8,10 +11,7 @@ import {
|
||||
setPanelEditorUIState,
|
||||
updateEditorInitState,
|
||||
} from './reducers';
|
||||
import { cleanUpPanelState, panelModelAndPluginReady } from 'app/features/panel/state/reducers';
|
||||
import store from 'app/core/store';
|
||||
import { pick } from 'lodash';
|
||||
import { initPanelState } from 'app/features/panel/state/actions';
|
||||
import { DashboardModel, PanelModel } from '../../../state';
|
||||
|
||||
export function initPanelEditor(sourcePanel: PanelModel, dashboard: DashboardModel): ThunkResult<void> {
|
||||
return async (dispatch) => {
|
||||
@@ -63,9 +63,10 @@ export function updateDuplicateLibraryPanels(
|
||||
panel.configRev++;
|
||||
|
||||
if (pluginChanged) {
|
||||
const cleanUpKey = panel.key;
|
||||
panel.generateNewKey();
|
||||
|
||||
dispatch(panelModelAndPluginReady({ key: panel.key, plugin: panel.plugin! }));
|
||||
dispatch(panelModelAndPluginReady({ key: panel.key, plugin: panel.plugin!, cleanUpKey }));
|
||||
}
|
||||
|
||||
// Resend last query result on source panel query runner
|
||||
@@ -125,9 +126,10 @@ export function exitPanelEditor(): ThunkResult<void> {
|
||||
if (panelTypeChanged) {
|
||||
// Loaded plugin is not included in the persisted properties so is not handled by restoreModel
|
||||
sourcePanel.plugin = panel.plugin;
|
||||
const cleanUpKey = sourcePanel.key;
|
||||
sourcePanel.generateNewKey();
|
||||
|
||||
await dispatch(panelModelAndPluginReady({ key: sourcePanel.key, plugin: panel.plugin! }));
|
||||
await dispatch(panelModelAndPluginReady({ key: sourcePanel.key, plugin: panel.plugin!, cleanUpKey }));
|
||||
}
|
||||
|
||||
// Resend last query result on source panel query runner
|
||||
@@ -138,7 +140,7 @@ export function exitPanelEditor(): ThunkResult<void> {
|
||||
}, 20);
|
||||
}
|
||||
|
||||
dispatch(cleanUpPanelState({ key: panel.key }));
|
||||
dispatch(cleanUpPanelState(panel.key));
|
||||
dispatch(closeEditor());
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user