From 96de314c0cee53eaea4008b07b599907a5450f1f Mon Sep 17 00:00:00 2001 From: Antonio Rivero Martinez <38889534+Antonio-RiveroMartnez@users.noreply.github.com> Date: Mon, 5 Dec 2022 17:15:27 -0300 Subject: [PATCH] fix(sqllab): Fix autocomplete for SQL Lab (#22329) --- .../SqlEditorLeftBar/SqlEditorLeftBar.test.jsx | 4 ++-- .../src/components/TableSelector/index.tsx | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/superset-frontend/src/SqlLab/components/SqlEditorLeftBar/SqlEditorLeftBar.test.jsx b/superset-frontend/src/SqlLab/components/SqlEditorLeftBar/SqlEditorLeftBar.test.jsx index c2cf1b5a785fb..fa8363f9e2aa0 100644 --- a/superset-frontend/src/SqlLab/components/SqlEditorLeftBar/SqlEditorLeftBar.test.jsx +++ b/superset-frontend/src/SqlLab/components/SqlEditorLeftBar/SqlEditorLeftBar.test.jsx @@ -110,8 +110,8 @@ test('should toggle the table when the header is clicked', async () => { userEvent.click(header); await waitFor(() => { - expect(store.getActions()).toHaveLength(2); - expect(store.getActions()[1].type).toEqual('COLLAPSE_TABLE'); + expect(store.getActions()).toHaveLength(4); + expect(store.getActions()[3].type).toEqual('COLLAPSE_TABLE'); }); }); diff --git a/superset-frontend/src/components/TableSelector/index.tsx b/superset-frontend/src/components/TableSelector/index.tsx index 2adf70c74c867..1cf65bbc688af 100644 --- a/superset-frontend/src/components/TableSelector/index.tsx +++ b/superset-frontend/src/components/TableSelector/index.tsx @@ -185,8 +185,7 @@ const TableSelector: FunctionComponent = ({ } = useTables({ dbId: database?.id, schema: currentSchema, - onSuccess: (data: { options: Table[] }) => { - onTablesLoad?.(data.options); + onSuccess: () => { if (isFetched) { addSuccessToast(t('List updated')); } @@ -203,6 +202,14 @@ const TableSelector: FunctionComponent = ({ }, }); + useEffect(() => { + // Set the tableOptions in the queryEditor so autocomplete + // works on new tabs + if (data && isFetched) { + onTablesLoad?.(data.options); + } + }, [data, isFetched, onTablesLoad]); + const tableOptions = useMemo( () => data