Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sqllab): error while removing a referenced table #25114

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions superset-frontend/src/SqlLab/components/TableElement/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import type { Table } from 'src/SqlLab/types';
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 {
Expand Down Expand Up @@ -102,6 +102,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,
Expand Down Expand Up @@ -253,7 +254,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={
Expand Down
3 changes: 3 additions & 0 deletions superset-frontend/src/SqlLab/reducers/sqlLab.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions superset-frontend/src/SqlLab/reducers/sqlLab.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading