mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
DashboardScene: Fixes url issue with subpath when exiting edit mode (#93962)
This commit is contained in:
parent
1c14c85b97
commit
b17e256a3c
@ -1,4 +1,4 @@
|
||||
import { CoreApp, LoadingState, getDefaultTimeRange, store } from '@grafana/data';
|
||||
import { CoreApp, GrafanaConfig, LoadingState, getDefaultTimeRange, locationUtil, store } from '@grafana/data';
|
||||
import { locationService } from '@grafana/runtime';
|
||||
import {
|
||||
sceneGraph,
|
||||
@ -76,6 +76,12 @@ jest.mock('app/features/manage-dashboards/state/actions', () => ({
|
||||
deleteDashboard: jest.fn().mockResolvedValue({}),
|
||||
}));
|
||||
|
||||
locationUtil.initialize({
|
||||
config: { appSubUrl: '/subUrl' } as GrafanaConfig,
|
||||
getVariablesUrlParams: jest.fn(),
|
||||
getTimeRangeForUrl: jest.fn(),
|
||||
});
|
||||
|
||||
const worker = createWorker();
|
||||
mockResultsOfDetectChangesWorker({ hasChanges: true, hasTimeChanges: false, hasVariableValueChanges: false });
|
||||
|
||||
@ -134,6 +140,7 @@ describe('DashboardScene', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
scene = buildTestScene();
|
||||
locationService.push('/d/dash-1');
|
||||
deactivateScene = scene.activate();
|
||||
scene.onEnterEditMode();
|
||||
jest.clearAllMocks();
|
||||
@ -143,6 +150,11 @@ describe('DashboardScene', () => {
|
||||
expect(scene.state.isEditing).toBe(true);
|
||||
});
|
||||
|
||||
it('Can exit edit mode', () => {
|
||||
scene.exitEditMode({ skipConfirm: true });
|
||||
expect(locationService.getLocation().pathname).toBe('/d/dash-1');
|
||||
});
|
||||
|
||||
it('Exiting already saved dashboard should not restore initial state', () => {
|
||||
scene.setState({ title: 'Updated title' });
|
||||
expect(scene.state.isDirty).toBe(true);
|
||||
|
@ -301,15 +301,15 @@ export class DashboardScene extends SceneObjectBase<DashboardSceneState> {
|
||||
// We are updating url and removing editview and editPanel.
|
||||
// The initial url may be including edit view, edit panel or inspect query params if the user pasted the url,
|
||||
// hence we need to cleanup those query params to get back to the dashboard view. Otherwise url sync can trigger overlays.
|
||||
locationService.replace(
|
||||
locationUtil.getUrlForPartial(this._initialUrlState!, {
|
||||
editPanel: null,
|
||||
editview: null,
|
||||
inspect: null,
|
||||
inspectTab: null,
|
||||
shareView: null,
|
||||
})
|
||||
);
|
||||
const url = locationUtil.getUrlForPartial(this._initialUrlState!, {
|
||||
editPanel: null,
|
||||
editview: null,
|
||||
inspect: null,
|
||||
inspectTab: null,
|
||||
shareView: null,
|
||||
});
|
||||
|
||||
locationService.replace(locationUtil.stripBaseFromUrl(url));
|
||||
|
||||
if (this._fromExplore) {
|
||||
this.cleanupStateFromExplore();
|
||||
|
Loading…
Reference in New Issue
Block a user