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 { locationService } from '@grafana/runtime';
|
||||||
import {
|
import {
|
||||||
sceneGraph,
|
sceneGraph,
|
||||||
@ -76,6 +76,12 @@ jest.mock('app/features/manage-dashboards/state/actions', () => ({
|
|||||||
deleteDashboard: jest.fn().mockResolvedValue({}),
|
deleteDashboard: jest.fn().mockResolvedValue({}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
locationUtil.initialize({
|
||||||
|
config: { appSubUrl: '/subUrl' } as GrafanaConfig,
|
||||||
|
getVariablesUrlParams: jest.fn(),
|
||||||
|
getTimeRangeForUrl: jest.fn(),
|
||||||
|
});
|
||||||
|
|
||||||
const worker = createWorker();
|
const worker = createWorker();
|
||||||
mockResultsOfDetectChangesWorker({ hasChanges: true, hasTimeChanges: false, hasVariableValueChanges: false });
|
mockResultsOfDetectChangesWorker({ hasChanges: true, hasTimeChanges: false, hasVariableValueChanges: false });
|
||||||
|
|
||||||
@ -134,6 +140,7 @@ describe('DashboardScene', () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
scene = buildTestScene();
|
scene = buildTestScene();
|
||||||
|
locationService.push('/d/dash-1');
|
||||||
deactivateScene = scene.activate();
|
deactivateScene = scene.activate();
|
||||||
scene.onEnterEditMode();
|
scene.onEnterEditMode();
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
@ -143,6 +150,11 @@ describe('DashboardScene', () => {
|
|||||||
expect(scene.state.isEditing).toBe(true);
|
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', () => {
|
it('Exiting already saved dashboard should not restore initial state', () => {
|
||||||
scene.setState({ title: 'Updated title' });
|
scene.setState({ title: 'Updated title' });
|
||||||
expect(scene.state.isDirty).toBe(true);
|
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.
|
// 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,
|
// 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.
|
// hence we need to cleanup those query params to get back to the dashboard view. Otherwise url sync can trigger overlays.
|
||||||
locationService.replace(
|
const url = locationUtil.getUrlForPartial(this._initialUrlState!, {
|
||||||
locationUtil.getUrlForPartial(this._initialUrlState!, {
|
editPanel: null,
|
||||||
editPanel: null,
|
editview: null,
|
||||||
editview: null,
|
inspect: null,
|
||||||
inspect: null,
|
inspectTab: null,
|
||||||
inspectTab: null,
|
shareView: null,
|
||||||
shareView: null,
|
});
|
||||||
})
|
|
||||||
);
|
locationService.replace(locationUtil.stripBaseFromUrl(url));
|
||||||
|
|
||||||
if (this._fromExplore) {
|
if (this._fromExplore) {
|
||||||
this.cleanupStateFromExplore();
|
this.cleanupStateFromExplore();
|
||||||
|
Loading…
Reference in New Issue
Block a user