mirror of
https://github.com/apache/superset.git
synced 2026-04-24 10:35:01 +00:00
fix(dashboard): Navigate to new dashboard when saved as a new one (#35339)
(cherry picked from commit 891f826143)
This commit is contained in:
committed by
Joe Li
parent
e61a0dd619
commit
8dbbbbf136
@@ -57,7 +57,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,
|
||||
@@ -372,6 +372,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;
|
||||
};
|
||||
|
||||
@@ -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,24 @@ 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(),
|
||||
}));
|
||||
|
||||
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 = {
|
||||
dashboardState: {
|
||||
@@ -194,5 +207,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}/`,
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user