From f526fd76ed8451a485d7e73efce182c74ec88c50 Mon Sep 17 00:00:00 2001 From: justinpark Date: Mon, 25 Mar 2024 12:13:26 -0700 Subject: [PATCH] fix(sqllab): unable to remove table --- .../src/SqlLab/actions/sqlLab.js | 8 ++++--- .../src/SqlLab/actions/sqlLab.test.js | 24 +++++++++++++++++-- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/superset-frontend/src/SqlLab/actions/sqlLab.js b/superset-frontend/src/SqlLab/actions/sqlLab.js index e96198a0eab6f..fa5198e5324b1 100644 --- a/superset-frontend/src/SqlLab/actions/sqlLab.js +++ b/superset-frontend/src/SqlLab/actions/sqlLab.js @@ -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(); diff --git a/superset-frontend/src/SqlLab/actions/sqlLab.test.js b/superset-frontend/src/SqlLab/actions/sqlLab.test.js index dd48ed8c7b697..20fd53ad389c9 100644 --- a/superset-frontend/src/SqlLab/actions/sqlLab.test.js +++ b/superset-frontend/src/SqlLab/actions/sqlLab.test.js @@ -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 = [ { @@ -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 = [ { @@ -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', () => {