Skip to content

Commit

Permalink
fix(sqllab): unable to remove table (apache#27636)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinpark authored and EnxDev committed Apr 12, 2024
1 parent 858b6bd commit 845ee58
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
8 changes: 5 additions & 3 deletions superset-frontend/src/SqlLab/actions/sqlLab.js
Original file line number Diff line number Diff line change
Expand Up @@ -1131,9 +1131,11 @@ export function removeTables(tables) {
const sync = isFeatureEnabled(FeatureFlag.SqllabBackendPersistence)
? Promise.all(
tablesToRemove.map(table =>
SupersetClient.delete({
endpoint: encodeURI(`/tableschemaview/${table.id}`),
}),
table.initialized
? SupersetClient.delete({
endpoint: encodeURI(`/tableschemaview/${table.id}`),
})
: Promise.resolve(),
),
)
: Promise.resolve();
Expand Down
24 changes: 22 additions & 2 deletions superset-frontend/src/SqlLab/actions/sqlLab.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ describe('async actions', () => {
it('updates the table schema state in the backend', () => {
expect.assertions(2);

const table = { id: 1 };
const table = { id: 1, initialized: true };
const store = mockStore({});
const expectedActions = [
{
Expand All @@ -900,7 +900,10 @@ describe('async actions', () => {
it('deletes multiple tables and updates the table schema state in the backend', () => {
expect.assertions(2);

const tables = [{ id: 1 }, { id: 2 }];
const tables = [
{ id: 1, initialized: true },
{ id: 2, initialized: true },
];
const store = mockStore({});
const expectedActions = [
{
Expand All @@ -913,6 +916,23 @@ describe('async actions', () => {
expect(fetchMock.calls(updateTableSchemaEndpoint)).toHaveLength(2);
});
});

it('only updates the initialized table schema state in the backend', () => {
expect.assertions(2);

const tables = [{ id: 1 }, { id: 2, initialized: true }];
const store = mockStore({});
const expectedActions = [
{
type: actions.REMOVE_TABLES,
tables,
},
];
return store.dispatch(actions.removeTables(tables)).then(() => {
expect(store.getActions()).toEqual(expectedActions);
expect(fetchMock.calls(updateTableSchemaEndpoint)).toHaveLength(1);
});
});
});

describe('migrateQueryEditorFromLocalStorage', () => {
Expand Down

0 comments on commit 845ee58

Please sign in to comment.