You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by mi...@apache.org on 2024/02/22 21:09:58 UTC
(superset) 03/04: fix(sqllab): typeahead search is broken in db selector (#27181)
This is an automated email from the ASF dual-hosted git repository.
michaelsmolina pushed a commit to branch 3.1
in repository https://gitbox.apache.org/repos/asf/superset.git
commit 7ff823b02f427cf352565e97720d669e8d75daa3
Author: JUST.in DO IT <ju...@airbnb.com>
AuthorDate: Wed Feb 21 06:03:41 2024 -0800
fix(sqllab): typeahead search is broken in db selector (#27181)
(cherry picked from commit 8fbaf84f66585146c17c23ec3e530d59902efd75)
---
.../DatabaseSelector/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 874d22ea6b..18e6769912 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(<DatabaseSelector {...props} />, { 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 7b4afd9af0..0c0268db5c 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,
};
});
},