From 8fbaf84f66585146c17c23ec3e530d59902efd75 Mon Sep 17 00:00:00 2001 From: "JUST.in DO IT" Date: Wed, 21 Feb 2024 06:03:41 -0800 Subject: [PATCH] fix(sqllab): typeahead search is broken in db selector (#27181) --- .../DatabaseSelector.test.tsx | 26 +++++++++++++++++++ .../src/components/DatabaseSelector/index.tsx | 4 +-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/superset-frontend/src/components/DatabaseSelector/DatabaseSelector.test.tsx b/superset-frontend/src/components/DatabaseSelector/DatabaseSelector.test.tsx index 874d22ea6bb2b..18e676991261b 100644 --- a/superset-frontend/src/components/DatabaseSelector/DatabaseSelector.test.tsx +++ b/superset-frontend/src/components/DatabaseSelector/DatabaseSelector.test.tsx @@ -229,6 +229,32 @@ test('Should database select display options', async () => { expect(await screen.findByText('test-mysql')).toBeInTheDocument(); }); +test('Should fetch the search keyword when total count exceeds initial options', async () => { + fetchMock.get( + databaseApiRoute, + { + ...fakeDatabaseApiResult, + count: fakeDatabaseApiResult.result.length + 1, + }, + { overwriteRoutes: true }, + ); + + const props = createProps(); + render(, { useRedux: true, store }); + const select = screen.getByRole('combobox', { + name: 'Select database or type to search databases', + }); + await waitFor(() => + expect(fetchMock.calls(databaseApiRoute)).toHaveLength(1), + ); + expect(select).toBeInTheDocument(); + userEvent.type(select, 'keywordtest'); + await waitFor(() => + expect(fetchMock.calls(databaseApiRoute)).toHaveLength(2), + ); + expect(fetchMock.calls(databaseApiRoute)[1][0]).toContain('keywordtest'); +}); + test('should show empty state if there are no options', async () => { fetchMock.reset(); fetchMock.get(databaseApiRoute, { result: [] }); diff --git a/superset-frontend/src/components/DatabaseSelector/index.tsx b/superset-frontend/src/components/DatabaseSelector/index.tsx index 7b4afd9af05aa..0c0268db5c9e6 100644 --- a/superset-frontend/src/components/DatabaseSelector/index.tsx +++ b/superset-frontend/src/components/DatabaseSelector/index.tsx @@ -167,7 +167,7 @@ export default function DatabaseSelector({ }); const endpoint = `/api/v1/database/?q=${queryParams}`; return SupersetClient.get({ endpoint }).then(({ json }) => { - const { result } = json; + const { result, count } = json; if (getDbList) { getDbList(result); } @@ -189,7 +189,7 @@ export default function DatabaseSelector({ return { data: options, - totalCount: options.length, + totalCount: count ?? options.length, }; }); },