mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
fix(explore): Overwriting a chart updates the form_data_key (#35888)
This commit is contained in:
committed by
GitHub
parent
a1d4dff99d
commit
3f49938b79
@@ -315,3 +315,33 @@ test('make sure slice_id in the URLSearchParams before the redirect', () => {
|
||||
);
|
||||
expect(result.get('slice_id')).toEqual('1');
|
||||
});
|
||||
|
||||
test('removes form_data_key from URL parameters after save', () => {
|
||||
const myProps = {
|
||||
...defaultProps,
|
||||
slice: { slice_id: 1, slice_name: 'title', owners: [1] },
|
||||
actions: {
|
||||
setFormData: jest.fn(),
|
||||
updateSlice: jest.fn(() => Promise.resolve({ id: 1 })),
|
||||
getSliceDashboards: jest.fn(),
|
||||
},
|
||||
user: { userId: 1 },
|
||||
history: {
|
||||
replace: jest.fn(),
|
||||
},
|
||||
dispatch: jest.fn(),
|
||||
};
|
||||
|
||||
const saveModal = new PureSaveModal(myProps);
|
||||
|
||||
// Test with form_data_key in the URL
|
||||
const urlWithFormDataKey = '?form_data_key=12345&other_param=value';
|
||||
const result = saveModal.handleRedirect(urlWithFormDataKey, { id: 1 });
|
||||
|
||||
// form_data_key should be removed
|
||||
expect(result.has('form_data_key')).toBe(false);
|
||||
// other parameters should remain
|
||||
expect(result.get('other_param')).toEqual('value');
|
||||
expect(result.get('slice_id')).toEqual('1');
|
||||
expect(result.get('save_action')).toEqual('overwrite');
|
||||
});
|
||||
|
||||
@@ -169,9 +169,8 @@ class SaveModal extends Component<SaveModalProps, SaveModalState> {
|
||||
handleRedirect = (windowLocationSearch: string, chart: any) => {
|
||||
const searchParams = new URLSearchParams(windowLocationSearch);
|
||||
searchParams.set('save_action', this.state.action);
|
||||
if (this.state.action !== 'overwrite') {
|
||||
searchParams.delete('form_data_key');
|
||||
}
|
||||
|
||||
searchParams.delete('form_data_key');
|
||||
|
||||
searchParams.set('slice_id', chart.id.toString());
|
||||
return searchParams;
|
||||
|
||||
Reference in New Issue
Block a user