From e48dae781f2dd0360239c3aa5afc5f07d8ce52c8 Mon Sep 17 00:00:00 2001 From: "JUST.in DO IT" Date: Tue, 26 Mar 2024 10:19:50 -0700 Subject: [PATCH] fix(sqllab): unable to remove table (#27636) (cherry picked from commit fa3fea9dd811d3cfdbbfe93f31d34992e603ec60) --- .../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 cbab24a21e561..72dc03f001845 100644 --- a/superset-frontend/src/SqlLab/actions/sqlLab.js +++ b/superset-frontend/src/SqlLab/actions/sqlLab.js @@ -1125,9 +1125,11 @@ export function removeTables(tables) { const sync = isFeatureEnabled(FeatureFlag.SQLLAB_BACKEND_PERSISTENCE) ? 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', () => {