Fix: panel crash after esc (#38646)

This commit is contained in:
Zoltán Bedi 2021-08-30 09:57:07 +02:00 committed by GitHub
parent d90c822e69
commit 38b398feb4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 8 additions and 15 deletions

View File

@ -1,5 +1,5 @@
import { thunkTester } from '../../../../../../test/core/thunk/thunkTester'; import { thunkTester } from '../../../../../../test/core/thunk/thunkTester';
import { closeCompleted, initialState, PanelEditorState } from './reducers'; import { closeEditor, initialState, PanelEditorState } from './reducers';
import { initPanelEditor, exitPanelEditor } from './actions'; import { initPanelEditor, exitPanelEditor } from './actions';
import { cleanUpEditPanel, panelModelAndPluginReady } from '../../../state/reducers'; import { cleanUpEditPanel, panelModelAndPluginReady } from '../../../state/reducers';
import { DashboardModel, PanelModel } from '../../../state'; import { DashboardModel, PanelModel } from '../../../state';
@ -52,8 +52,8 @@ describe('panelEditor actions', () => {
.whenThunkIsDispatched(); .whenThunkIsDispatched();
expect(dispatchedActions.length).toBe(2); expect(dispatchedActions.length).toBe(2);
expect(dispatchedActions[0].type).toBe(cleanUpEditPanel.type); expect(dispatchedActions[0].type).toBe(closeEditor.type);
expect(dispatchedActions[1].type).toBe(closeCompleted.type); expect(dispatchedActions[1].type).toBe(cleanUpEditPanel.type);
expect(sourcePanel.getOptions()).toEqual({ prop: true }); expect(sourcePanel.getOptions()).toEqual({ prop: true });
expect(sourcePanel.id).toEqual(12); expect(sourcePanel.id).toEqual(12);
}); });

View File

@ -1,7 +1,7 @@
import { DashboardModel, PanelModel } from '../../../state'; import { DashboardModel, PanelModel } from '../../../state';
import { ThunkResult } from 'app/types'; import { ThunkResult } from 'app/types';
import { import {
closeCompleted, closeEditor,
PANEL_EDITOR_UI_STATE_STORAGE_KEY, PANEL_EDITOR_UI_STATE_STORAGE_KEY,
PanelEditorUIState, PanelEditorUIState,
setPanelEditorUIState, setPanelEditorUIState,
@ -105,8 +105,8 @@ export function exitPanelEditor(): ThunkResult<void> {
dashboard.exitPanelEditor(); dashboard.exitPanelEditor();
} }
dispatch(closeEditor());
dispatch(cleanUpEditPanel()); dispatch(cleanUpEditPanel());
dispatch(closeCompleted());
}; };
} }

View File

@ -106,7 +106,7 @@ const pluginsSlice = createSlice({
toggleTableView(state) { toggleTableView(state) {
state.tableViewEnabled = !state.tableViewEnabled; state.tableViewEnabled = !state.tableViewEnabled;
}, },
closeCompleted: (state) => { closeEditor: (state) => {
state.isOpen = false; state.isOpen = false;
state.initDone = false; state.initDone = false;
state.isVizPickerOpen = false; state.isVizPickerOpen = false;
@ -119,7 +119,7 @@ export const {
updateEditorInitState, updateEditorInitState,
setEditorPanelData, setEditorPanelData,
setDiscardChanges, setDiscardChanges,
closeCompleted, closeEditor,
setPanelEditorUIState, setPanelEditorUIState,
toggleVizPicker, toggleVizPicker,
toggleTableView, toggleTableView,

View File

@ -68,14 +68,9 @@ const mapDispatchToProps = {
const connector = connect(mapStateToProps, mapDispatchToProps); const connector = connect(mapStateToProps, mapDispatchToProps);
interface OwnProps {
isPanelEditorOpen?: boolean;
}
export type Props = Themeable2 & export type Props = Themeable2 &
GrafanaRouteComponentProps<DashboardPageRouteParams, DashboardPageRouteSearchParams> & GrafanaRouteComponentProps<DashboardPageRouteParams, DashboardPageRouteSearchParams> &
ConnectedProps<typeof connector> & ConnectedProps<typeof connector>;
OwnProps;
export interface State { export interface State {
editPanel: PanelModel | null; editPanel: PanelModel | null;

View File

@ -76,14 +76,12 @@ const dashbardSlice = createSlice({
updatePanelState(state, action.payload.panelId, { plugin: action.payload.plugin }); updatePanelState(state, action.payload.panelId, { plugin: action.payload.plugin });
}, },
cleanUpEditPanel: (state) => { cleanUpEditPanel: (state) => {
// TODO: refactor, since the state should be mutated by copying only
delete state.panels[EDIT_PANEL_ID]; delete state.panels[EDIT_PANEL_ID];
}, },
setPanelAngularComponent: (state, action: PayloadAction<SetPanelAngularComponentPayload>) => { setPanelAngularComponent: (state, action: PayloadAction<SetPanelAngularComponentPayload>) => {
updatePanelState(state, action.payload.panelId, { angularComponent: action.payload.angularComponent }); updatePanelState(state, action.payload.panelId, { angularComponent: action.payload.angularComponent });
}, },
addPanel: (state, action: PayloadAction<PanelModel>) => { addPanel: (state, action: PayloadAction<PanelModel>) => {
// TODO: refactor, since the state should be mutated by copying only
state.panels[action.payload.id] = { pluginId: action.payload.type }; state.panels[action.payload.id] = { pluginId: action.payload.type };
}, },
}, },