feat(frontend): add dataset cache clearing utilities and integration (#35264)

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Geidō <60598000+geido@users.noreply.github.com>
This commit is contained in:
Mehmet Salih Yavuz
2025-11-12 17:23:37 +03:00
committed by GitHub
parent 9fbfcf0ccd
commit 0b535b792e
6 changed files with 303 additions and 4 deletions

View File

@@ -61,6 +61,10 @@ jest.mock('src/SqlLab/actions/sqlLab', () => ({
jest.mock('src/explore/exploreUtils/formData', () => ({
postFormData: jest.fn(),
}));
jest.mock('src/utils/cachedSupersetGet', () => ({
...jest.requireActual('src/utils/cachedSupersetGet'),
clearDatasetCache: jest.fn(),
}));
// eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks
describe('SaveDatasetModal', () => {
@@ -336,4 +340,42 @@ describe('SaveDatasetModal', () => {
templateParams: undefined,
});
});
test('clears dataset cache when creating new dataset', async () => {
const clearDatasetCache = jest.spyOn(
require('src/utils/cachedSupersetGet'),
'clearDatasetCache',
);
const postFormData = jest.spyOn(
require('src/explore/exploreUtils/formData'),
'postFormData',
);
const dummyDispatch = jest.fn().mockResolvedValue({ id: 123 });
useDispatchMock.mockReturnValue(dummyDispatch);
useSelectorMock.mockReturnValue({ ...user });
postFormData.mockResolvedValue('chart_key_123');
render(<SaveDatasetModal {...mockedProps} />, { useRedux: true });
const inputFieldText = screen.getByDisplayValue(/unimportant/i);
fireEvent.change(inputFieldText, { target: { value: 'my dataset' } });
const saveConfirmationBtn = screen.getByRole('button', {
name: /save/i,
});
userEvent.click(saveConfirmationBtn);
await waitFor(() => {
expect(clearDatasetCache).toHaveBeenCalledWith(123);
});
});
test('clearDatasetCache is imported and available', () => {
const clearDatasetCache =
require('src/utils/cachedSupersetGet').clearDatasetCache;
expect(clearDatasetCache).toBeDefined();
expect(typeof clearDatasetCache).toBe('function');
});
});

View File

@@ -59,6 +59,7 @@ import { mountExploreUrl } from 'src/explore/exploreUtils';
import { postFormData } from 'src/explore/exploreUtils/formData';
import { URL_PARAMS } from 'src/constants';
import { isEmpty } from 'lodash';
import { clearDatasetCache } from 'src/utils/cachedSupersetGet';
interface QueryDatabase {
id?: number;
@@ -170,6 +171,9 @@ const updateDataset = async (
headers,
body,
});
clearDatasetCache(datasetId);
return data.json.result;
};
@@ -347,15 +351,17 @@ export const SaveDatasetModal = ({
datasourceName: datasetName,
}),
)
.then((data: { id: number }) =>
postFormData(data.id, 'table', {
.then((data: { id: number }) => {
clearDatasetCache(data.id);
return postFormData(data.id, 'table', {
...formDataWithDefaults,
datasource: `${data.id}__table`,
...(defaultVizType === VizType.Table && {
all_columns: selectedColumns.map(column => column.column_name),
}),
}),
)
});
})
.then((key: string) => {
setLoading(false);
const url = mountExploreUrl(null, {