mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
@@ -1,7 +1,7 @@
|
|||||||
import { PanelModel, DashboardModel } from '../../../state';
|
import { PanelModel, DashboardModel } from '../../../state';
|
||||||
import { PanelData } from '@grafana/data';
|
import { PanelData } from '@grafana/data';
|
||||||
import { ThunkResult } from 'app/types';
|
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> {
|
export function initPanelEditor(sourcePanel: PanelModel, dashboard: DashboardModel): ThunkResult<void> {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
@@ -33,5 +33,7 @@ export function panelEditorCleanUp(): ThunkResult<void> {
|
|||||||
|
|
||||||
dashboard.exitPanelEditor();
|
dashboard.exitPanelEditor();
|
||||||
querySubscription.unsubscribe();
|
querySubscription.unsubscribe();
|
||||||
|
|
||||||
|
dispatch(closeCompleted());
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ export interface PanelEditorStateNew {
|
|||||||
querySubscription?: Unsubscribable;
|
querySubscription?: Unsubscribable;
|
||||||
initDone: boolean;
|
initDone: boolean;
|
||||||
shouldDiscardChanges: boolean;
|
shouldDiscardChanges: boolean;
|
||||||
|
isOpen: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const initialState: PanelEditorStateNew = {
|
export const initialState: PanelEditorStateNew = {
|
||||||
@@ -29,6 +30,7 @@ export const initialState: PanelEditorStateNew = {
|
|||||||
mode: DisplayMode.Fill,
|
mode: DisplayMode.Fill,
|
||||||
initDone: false,
|
initDone: false,
|
||||||
shouldDiscardChanges: false,
|
shouldDiscardChanges: false,
|
||||||
|
isOpen: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
interface InitEditorPayload {
|
interface InitEditorPayload {
|
||||||
@@ -46,6 +48,7 @@ const pluginsSlice = createSlice({
|
|||||||
state.getSourcePanel = () => action.payload.sourcePanel;
|
state.getSourcePanel = () => action.payload.sourcePanel;
|
||||||
state.querySubscription = action.payload.querySubscription;
|
state.querySubscription = action.payload.querySubscription;
|
||||||
state.initDone = true;
|
state.initDone = true;
|
||||||
|
state.isOpen = true;
|
||||||
},
|
},
|
||||||
setEditorPanelData: (state, action: PayloadAction<PanelData>) => {
|
setEditorPanelData: (state, action: PayloadAction<PanelData>) => {
|
||||||
state.getData = () => action.payload;
|
state.getData = () => action.payload;
|
||||||
@@ -59,6 +62,10 @@ const pluginsSlice = createSlice({
|
|||||||
setDiscardChanges: (state, action: PayloadAction<boolean>) => {
|
setDiscardChanges: (state, action: PayloadAction<boolean>) => {
|
||||||
state.shouldDiscardChanges = action.payload;
|
state.shouldDiscardChanges = action.payload;
|
||||||
},
|
},
|
||||||
|
closeCompleted: state => {
|
||||||
|
state.isOpen = false;
|
||||||
|
state.initDone = false;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -68,6 +75,7 @@ export const {
|
|||||||
toggleOptionsView,
|
toggleOptionsView,
|
||||||
setDisplayMode,
|
setDisplayMode,
|
||||||
setDiscardChanges,
|
setDiscardChanges,
|
||||||
|
closeCompleted,
|
||||||
} = pluginsSlice.actions;
|
} = pluginsSlice.actions;
|
||||||
|
|
||||||
export const panelEditorReducerNew = pluginsSlice.reducer;
|
export const panelEditorReducerNew = pluginsSlice.reducer;
|
||||||
|
|||||||
@@ -271,6 +271,7 @@ describe('DashboardPage', () => {
|
|||||||
edit: false,
|
edit: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
panelEditorNew: {},
|
||||||
dashboard: {
|
dashboard: {
|
||||||
getModel: () => null as DashboardModel,
|
getModel: () => null as DashboardModel,
|
||||||
},
|
},
|
||||||
@@ -289,6 +290,7 @@ describe('DashboardPage', () => {
|
|||||||
edit: 'true',
|
edit: 'true',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
panelEditorNew: {},
|
||||||
dashboard: {
|
dashboard: {
|
||||||
getModel: () => null as DashboardModel,
|
getModel: () => null as DashboardModel,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ export interface Props {
|
|||||||
notifyApp: typeof notifyApp;
|
notifyApp: typeof notifyApp;
|
||||||
updateLocation: typeof updateLocation;
|
updateLocation: typeof updateLocation;
|
||||||
inspectTab?: InspectTab;
|
inspectTab?: InspectTab;
|
||||||
|
isNewEditorOpen?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface State {
|
export interface State {
|
||||||
@@ -260,6 +261,7 @@ export class DashboardPage extends PureComponent<Props, State> {
|
|||||||
inspectPanelId,
|
inspectPanelId,
|
||||||
urlEditPanel,
|
urlEditPanel,
|
||||||
inspectTab,
|
inspectTab,
|
||||||
|
isNewEditorOpen,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
const { isSettingsOpening, isEditing, isFullscreen, scrollTop, updateScrollTop } = this.state;
|
const { isSettingsOpening, isEditing, isFullscreen, scrollTop, updateScrollTop } = this.state;
|
||||||
|
|
||||||
@@ -316,6 +318,7 @@ export class DashboardPage extends PureComponent<Props, State> {
|
|||||||
dashboard={dashboard}
|
dashboard={dashboard}
|
||||||
isEditing={isEditing}
|
isEditing={isEditing}
|
||||||
isFullscreen={isFullscreen}
|
isFullscreen={isFullscreen}
|
||||||
|
isNewEditorOpen={isNewEditorOpen}
|
||||||
scrollTop={approximateScrollTop}
|
scrollTop={approximateScrollTop}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -349,6 +352,7 @@ export const mapStateToProps = (state: StoreState) => ({
|
|||||||
initError: state.dashboard.initError,
|
initError: state.dashboard.initError,
|
||||||
dashboard: state.dashboard.getModel() as DashboardModel,
|
dashboard: state.dashboard.getModel() as DashboardModel,
|
||||||
inspectTab: state.location.query.tab,
|
inspectTab: state.location.query.tab,
|
||||||
|
isNewEditorOpen: state.panelEditorNew.isOpen,
|
||||||
});
|
});
|
||||||
|
|
||||||
const mapDispatchToProps = {
|
const mapDispatchToProps = {
|
||||||
|
|||||||
@@ -98,6 +98,7 @@ export interface Props {
|
|||||||
isEditing: boolean;
|
isEditing: boolean;
|
||||||
isFullscreen: boolean;
|
isFullscreen: boolean;
|
||||||
scrollTop: number;
|
scrollTop: number;
|
||||||
|
isNewEditorOpen?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class DashboardGrid extends PureComponent<Props> {
|
export class DashboardGrid extends PureComponent<Props> {
|
||||||
|
|||||||
Reference in New Issue
Block a user