Skip to content

Commit 0a89b30

Browse files
betodealmeidasadpandajoe
authored andcommitted
fix(SQL Lab): syncTable on new tabs (#35216)
(cherry picked from commit 94686dd)
1 parent 7263133 commit 0a89b30

File tree

5 files changed

+91
-3
lines changed

5 files changed

+91
-3
lines changed

superset-frontend/src/SqlLab/actions/sqlLab.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,7 @@ export function addTable(queryEditor, tableName, catalogName, schemaName) {
952952
const { dbId } = getUpToDateQuery(getState(), queryEditor, queryEditor.id);
953953
const table = {
954954
dbId,
955-
queryEditorId: queryEditor.id,
955+
queryEditorId: queryEditor.tabViewId ?? queryEditor.id,
956956
catalog: catalogName,
957957
schema: schemaName,
958958
name: tableName,

superset-frontend/src/SqlLab/actions/sqlLab.test.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,85 @@ describe('async actions', () => {
10021002
}),
10031003
);
10041004
});
1005+
1006+
it('uses tabViewId when available', () => {
1007+
const tableName = 'table';
1008+
const catalogName = null;
1009+
const schemaName = 'schema';
1010+
const expectedDbId = 473892;
1011+
const tabViewId = '123';
1012+
const queryWithTabViewId = { ...query, tabViewId };
1013+
1014+
const store = mockStore({
1015+
...initialState,
1016+
sqlLab: {
1017+
...initialState.sqlLab,
1018+
unsavedQueryEditor: {
1019+
id: query.id,
1020+
dbId: expectedDbId,
1021+
},
1022+
},
1023+
});
1024+
1025+
const request = actions.addTable(
1026+
queryWithTabViewId,
1027+
tableName,
1028+
catalogName,
1029+
schemaName,
1030+
);
1031+
request(store.dispatch, store.getState);
1032+
1033+
expect(store.getActions()[0]).toEqual(
1034+
expect.objectContaining({
1035+
table: expect.objectContaining({
1036+
name: tableName,
1037+
catalog: catalogName,
1038+
schema: schemaName,
1039+
dbId: expectedDbId,
1040+
queryEditorId: tabViewId, // Should use tabViewId, not id
1041+
}),
1042+
}),
1043+
);
1044+
});
1045+
1046+
it('falls back to id when tabViewId is not available', () => {
1047+
const tableName = 'table';
1048+
const catalogName = null;
1049+
const schemaName = 'schema';
1050+
const expectedDbId = 473892;
1051+
const queryWithoutTabViewId = { ...query, tabViewId: undefined };
1052+
1053+
const store = mockStore({
1054+
...initialState,
1055+
sqlLab: {
1056+
...initialState.sqlLab,
1057+
unsavedQueryEditor: {
1058+
id: query.id,
1059+
dbId: expectedDbId,
1060+
},
1061+
},
1062+
});
1063+
1064+
const request = actions.addTable(
1065+
queryWithoutTabViewId,
1066+
tableName,
1067+
catalogName,
1068+
schemaName,
1069+
);
1070+
request(store.dispatch, store.getState);
1071+
1072+
expect(store.getActions()[0]).toEqual(
1073+
expect.objectContaining({
1074+
table: expect.objectContaining({
1075+
name: tableName,
1076+
catalog: catalogName,
1077+
schema: schemaName,
1078+
dbId: expectedDbId,
1079+
queryEditorId: query.id, // Should use id when tabViewId is not available
1080+
}),
1081+
}),
1082+
);
1083+
});
10051084
});
10061085

10071086
describe('syncTable', () => {

superset-frontend/src/SqlLab/components/AceEditorWrapper/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ const AceEditorWrapper = ({
6565
'catalog',
6666
'schema',
6767
'templateParams',
68+
'tabViewId',
6869
]);
6970
// Prevent a maximum update depth exceeded error
7071
// by skipping access the unsaved query editor state
@@ -172,6 +173,7 @@ const AceEditorWrapper = ({
172173
dbId: queryEditor.dbId,
173174
catalog: queryEditor.catalog,
174175
schema: queryEditor.schema,
176+
tabViewId: queryEditor.tabViewId,
175177
},
176178
!autocomplete,
177179
);

superset-frontend/src/SqlLab/components/AceEditorWrapper/useKeywords.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type Params = {
4444
dbId?: string | number;
4545
catalog?: string | null;
4646
schema?: string;
47+
tabViewId?: string;
4748
};
4849

4950
const EMPTY_LIST = [] as typeof sqlKeywords;
@@ -59,7 +60,7 @@ const getHelperText = (value: string) =>
5960
const extensionsRegistry = getExtensionsRegistry();
6061

6162
export function useKeywords(
62-
{ queryEditorId, dbId, catalog, schema }: Params,
63+
{ queryEditorId, dbId, catalog, schema, tabViewId }: Params,
6364
skip = false,
6465
) {
6566
const useCustomKeywords = extensionsRegistry.get(
@@ -147,7 +148,12 @@ export function useKeywords(
147148
const insertMatch = useEffectEvent((editor: Editor, data: any) => {
148149
if (data.meta === 'table') {
149150
dispatch(
150-
addTable({ id: queryEditorId, dbId }, data.value, catalog, schema),
151+
addTable(
152+
{ id: queryEditorId, dbId, tabViewId },
153+
data.value,
154+
catalog,
155+
schema,
156+
),
151157
);
152158
}
153159

superset-frontend/src/SqlLab/components/SqlEditorLeftBar/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ const SqlEditorLeftBar = ({
8484
'dbId',
8585
'catalog',
8686
'schema',
87+
'tabViewId',
8788
]);
8889

8990
const [_emptyResultsWithSearch, setEmptyResultsWithSearch] = useState(false);

0 commit comments

Comments
 (0)