This is an automated email from the ASF dual-hosted git repository. michaelsmolina pushed a commit to branch 3.0 in repository https://gitbox.apache.org/repos/asf/superset.git
commit 90e7e769ce59108f4255eafbbc02222acf249945 Author: JUST.in DO IT <[email protected]> AuthorDate: Tue Aug 29 14:38:07 2023 -0700 fix(sqllab): error while removing a referenced table (#25114) (cherry picked from commit 29355577f148d1210c40043ef6028804469d2c30) --- .../src/SqlLab/components/TableElement/index.tsx | 11 ++++++-- superset-frontend/src/SqlLab/reducers/sqlLab.js | 3 ++ .../src/SqlLab/reducers/sqlLab.test.js | 32 ++++++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/superset-frontend/src/SqlLab/components/TableElement/index.tsx b/superset-frontend/src/SqlLab/components/TableElement/index.tsx index 147422b3c0..c47d1d86d3 100644 --- a/superset-frontend/src/SqlLab/components/TableElement/index.tsx +++ b/superset-frontend/src/SqlLab/components/TableElement/index.tsx @@ -21,7 +21,7 @@ import { useDispatch } from 'react-redux'; import Collapse from 'src/components/Collapse'; import Card from 'src/components/Card'; import ButtonGroup from 'src/components/ButtonGroup'; -import { css, t, styled } from '@superset-ui/core'; +import { css, t, styled, useTheme } from '@superset-ui/core'; import { debounce } from 'lodash'; import { @@ -111,6 +111,7 @@ const StyledCollapsePanel = styled(Collapse.Panel)` const TableElement = ({ table, ...props }: TableElementProps) => { const { dbId, schema, name, expanded } = table; + const theme = useTheme(); const dispatch = useDispatch(); const { data: tableMetadata, @@ -258,7 +259,13 @@ const TableElement = ({ table, ...props }: TableElementProps) => { ); } return ( - <ButtonGroup className="ws-el-controls"> + <ButtonGroup + css={css` + display: flex; + column-gap: ${theme.gridUnit * 1.5}px; + margin-right: ${theme.gridUnit}px; + `} + > {keyLink} <IconTooltip className={ diff --git a/superset-frontend/src/SqlLab/reducers/sqlLab.js b/superset-frontend/src/SqlLab/reducers/sqlLab.js index 9f92372fd2..2b82f42d09 100644 --- a/superset-frontend/src/SqlLab/reducers/sqlLab.js +++ b/superset-frontend/src/SqlLab/reducers/sqlLab.js @@ -184,6 +184,9 @@ export default function sqlLabReducer(state = {}, action) { if (action.query) { at.dataPreviewQueryId = action.query.id; } + if (existingTable.initialized) { + at.id = existingTable.id; + } return alterInArr(state, 'tables', existingTable, at); } // for new table, associate Id of query for data preview diff --git a/superset-frontend/src/SqlLab/reducers/sqlLab.test.js b/superset-frontend/src/SqlLab/reducers/sqlLab.test.js index 8827813698..40597c41b0 100644 --- a/superset-frontend/src/SqlLab/reducers/sqlLab.test.js +++ b/superset-frontend/src/SqlLab/reducers/sqlLab.test.js @@ -248,6 +248,38 @@ describe('sqlLabReducer', () => { expect(newState.tables).toHaveLength(1); expect(newState.tables[0].extra).toBe(true); }); + it('should overwrite table ID be ignored when the existing table is already initialized', () => { + const action = { + type: actions.MERGE_TABLE, + table: newTable, + }; + newState = sqlLabReducer(newState, action); + expect(newState.tables).toHaveLength(1); + // Merging the initialized remote id + const remoteId = 1; + const syncAction = { + type: actions.MERGE_TABLE, + table: { + ...newTable, + id: remoteId, + initialized: true, + }, + }; + newState = sqlLabReducer(newState, syncAction); + expect(newState.tables).toHaveLength(1); + expect(newState.tables[0].initialized).toBe(true); + expect(newState.tables[0].id).toBe(remoteId); + const overwriteAction = { + type: actions.MERGE_TABLE, + table: { + id: 'rnd_new_id', + ...newTable, + }, + }; + newState = sqlLabReducer(newState, overwriteAction); + expect(newState.tables).toHaveLength(1); + expect(newState.tables[0].id).toBe(remoteId); + }); it('should expand and collapse a table', () => { const collapseTableAction = { type: actions.COLLAPSE_TABLE,
