Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions superset-frontend/src/explore/components/SaveModal.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
5 changes: 2 additions & 3 deletions superset-frontend/src/explore/components/SaveModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just double-checking. If we now remove this always, is there any intended functionality that we are going to lose?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just double-checking. If we now remove this always, is there any intended functionality that we are going to lose?

Good question!
Previously, the cached form_data_key could sometimes reference an outdated datasource, causing charts to show stale data after saving changes.
By always removing it, we make sure the chart reloads from the database and reflects the most up-to-date state.
The only minor trade-off is a slightly slower load, but it ensures full data consistency


searchParams.set('slice_id', chart.id.toString());
return searchParams;
Expand Down
Loading