diff --git a/superset-frontend/src/dashboard/actions/dashboardState.js b/superset-frontend/src/dashboard/actions/dashboardState.js index d3305f2e6dad..c92faa8ab329 100644 --- a/superset-frontend/src/dashboard/actions/dashboardState.js +++ b/superset-frontend/src/dashboard/actions/dashboardState.js @@ -58,7 +58,7 @@ import { safeStringify } from 'src/utils/safeStringify'; import { logEvent } from 'src/logger/actions'; import { LOG_ACTIONS_CONFIRM_OVERWRITE_DASHBOARD_METADATA } from 'src/logger/LogUtils'; import { isEqual } from 'lodash'; -import { navigateWithState } from 'src/utils/navigationUtils'; +import { navigateWithState, navigateTo } from 'src/utils/navigationUtils'; import { UPDATE_COMPONENTS_PARENTS_LIST } from './dashboardLayout'; import { saveChartConfiguration, @@ -368,6 +368,7 @@ export function saveDashboardRequest(data, id, saveType) { }), ); dispatch(saveDashboardFinished()); + navigateTo(`/superset/dashboard/${response.json.result.id}/`); dispatch(addSuccessToast(t('This dashboard was saved successfully.'))); return response; }; diff --git a/superset-frontend/src/dashboard/actions/dashboardState.test.js b/superset-frontend/src/dashboard/actions/dashboardState.test.js index 390688a769cd..a305a1209060 100644 --- a/superset-frontend/src/dashboard/actions/dashboardState.test.js +++ b/superset-frontend/src/dashboard/actions/dashboardState.test.js @@ -30,6 +30,7 @@ import { DASHBOARD_GRID_ID, SAVE_TYPE_OVERWRITE, SAVE_TYPE_OVERWRITE_CONFIRMED, + SAVE_TYPE_NEWDASHBOARD, } from 'src/dashboard/util/constants'; import { filterId, @@ -37,12 +38,18 @@ import { } from 'spec/fixtures/mockSliceEntities'; import { emptyFilters } from 'spec/fixtures/mockDashboardFilters'; import mockDashboardData from 'spec/fixtures/mockDashboardData'; +import { navigateTo } from 'src/utils/navigationUtils'; jest.mock('@superset-ui/core', () => ({ ...jest.requireActual('@superset-ui/core'), isFeatureEnabled: jest.fn(), })); +jest.mock('src/utils/navigationUtils', () => ({ + navigateTo: jest.fn(), + navigateWithState: jest.fn(), +})); + // eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks describe('dashboardState actions', () => { const mockState = { @@ -197,5 +204,34 @@ describe('dashboardState actions', () => { expect(body).toBe(JSON.stringify(confirmedDashboardData)); }); }); + + test('should navigate to the new dashboard after Save As', async () => { + const newDashboardId = 999; + const { getState, dispatch } = setup({ + dashboardState: { hasUnsavedChanges: true }, + }); + + postStub.restore(); + postStub = sinon.stub(SupersetClient, 'post').resolves({ + json: { + result: { + ...mockDashboardData, + id: newDashboardId, + }, + }, + }); + + const thunk = saveDashboardRequest( + newDashboardData, + null, + SAVE_TYPE_NEWDASHBOARD, + ); + await thunk(dispatch, getState); + + await waitFor(() => expect(postStub.callCount).toBe(1)); + expect(navigateTo).toHaveBeenCalledWith( + `/superset/dashboard/${newDashboardId}/`, + ); + }); }); });