NewPanelEditor: Fixed issue going back to dashboard after pull page reload (#22121)

* Fixed issue going back to dashboard

* fixed logic

* Fixed unit test

* Fixed unit test
This commit is contained in:
Torkel Ödegaard
2020-02-12 18:36:32 +01:00
committed by GitHub
parent 1448767c08
commit cfe30080e4
5 changed files with 18 additions and 1 deletions

View File

@@ -1,7 +1,7 @@
import { PanelModel, DashboardModel } from '../../../state';
import { PanelData } from '@grafana/data';
import { ThunkResult } from 'app/types';
import { setEditorPanelData, updateEditorInitState } from './reducers';
import { setEditorPanelData, updateEditorInitState, closeCompleted } from './reducers';
export function initPanelEditor(sourcePanel: PanelModel, dashboard: DashboardModel): ThunkResult<void> {
return dispatch => {
@@ -33,5 +33,7 @@ export function panelEditorCleanUp(): ThunkResult<void> {
dashboard.exitPanelEditor();
querySubscription.unsubscribe();
dispatch(closeCompleted());
};
}

View File

@@ -15,6 +15,7 @@ export interface PanelEditorStateNew {
querySubscription?: Unsubscribable;
initDone: boolean;
shouldDiscardChanges: boolean;
isOpen: boolean;
}
export const initialState: PanelEditorStateNew = {
@@ -29,6 +30,7 @@ export const initialState: PanelEditorStateNew = {
mode: DisplayMode.Fill,
initDone: false,
shouldDiscardChanges: false,
isOpen: false,
};
interface InitEditorPayload {
@@ -46,6 +48,7 @@ const pluginsSlice = createSlice({
state.getSourcePanel = () => action.payload.sourcePanel;
state.querySubscription = action.payload.querySubscription;
state.initDone = true;
state.isOpen = true;
},
setEditorPanelData: (state, action: PayloadAction<PanelData>) => {
state.getData = () => action.payload;
@@ -59,6 +62,10 @@ const pluginsSlice = createSlice({
setDiscardChanges: (state, action: PayloadAction<boolean>) => {
state.shouldDiscardChanges = action.payload;
},
closeCompleted: state => {
state.isOpen = false;
state.initDone = false;
},
},
});
@@ -68,6 +75,7 @@ export const {
toggleOptionsView,
setDisplayMode,
setDiscardChanges,
closeCompleted,
} = pluginsSlice.actions;
export const panelEditorReducerNew = pluginsSlice.reducer;