From 98d09ec6a35c78eb6246fab60fbf73fe9950b772 Mon Sep 17 00:00:00 2001 From: karanh37 <33024356+karanh37@users.noreply.github.com> Date: Thu, 4 May 2023 15:02:14 +0530 Subject: [PATCH] fix: use search api instead of suggest (#11423) --- .../NodeSuggestions.component.tsx | 29 ++----------------- .../EntityLineage/NodeSuggestions.test.tsx | 12 ++------ 2 files changed, 4 insertions(+), 37 deletions(-) diff --git a/openmetadata-ui/src/main/resources/ui/src/components/EntityLineage/NodeSuggestions.component.tsx b/openmetadata-ui/src/main/resources/ui/src/components/EntityLineage/NodeSuggestions.component.tsx index f406c48ecd8..571643f6991 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/EntityLineage/NodeSuggestions.component.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/EntityLineage/NodeSuggestions.component.tsx @@ -24,7 +24,7 @@ import React, { useState, } from 'react'; import { useTranslation } from 'react-i18next'; -import { getSuggestions, searchData } from 'rest/miscAPI'; +import { searchData } from 'rest/miscAPI'; import { FQN_SEPARATOR_CHAR } from '../../constants/char.constants'; import { EntityType, FqnPart } from '../../enums/entity.enum'; import { SearchIndex } from '../../enums/search.enum'; @@ -63,27 +63,6 @@ const NodeSuggestions: FC = ({ } }; - const getSuggestResults = async (value: string) => { - try { - const data = await getSuggestions( - value, - SearchIndex[ - entityType as keyof typeof SearchIndex - ] as ExploreSearchIndex - ); - setData( - formatDataResponse(data.data.suggest['metadata-suggest'][0].options) - ); - } catch (error) { - showErrorToast( - error as AxiosError, - t('server.entity-fetch-error', { - entity: t('label.suggestion-lowercase-plural'), - }) - ); - } - }; - const getSearchResults = async (value: string) => { try { const data = await searchData( @@ -109,11 +88,7 @@ const NodeSuggestions: FC = ({ }; const debouncedOnSearch = useCallback((searchText: string): void => { - if (searchText) { - getSuggestResults(searchText); - } else { - getSearchResults(searchText); - } + getSearchResults(searchText); }, []); const debounceOnSearch = useCallback(debounce(debouncedOnSearch, 300), [ diff --git a/openmetadata-ui/src/main/resources/ui/src/components/EntityLineage/NodeSuggestions.test.tsx b/openmetadata-ui/src/main/resources/ui/src/components/EntityLineage/NodeSuggestions.test.tsx index ab89c551d14..624d565e790 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/EntityLineage/NodeSuggestions.test.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/EntityLineage/NodeSuggestions.test.tsx @@ -13,7 +13,7 @@ import { act, fireEvent, render, screen } from '@testing-library/react'; import React from 'react'; -import { getSuggestions, searchData } from 'rest/miscAPI'; +import { searchData } from 'rest/miscAPI'; import { SearchIndex } from '../../enums/search.enum'; import NodeSuggestions from './NodeSuggestions.component'; @@ -25,7 +25,6 @@ const mockProps = { const entityType = ['TABLE', 'TOPIC', 'DASHBOARD', 'MLMODEL']; jest.mock('rest/miscAPI', () => ({ - getSuggestions: jest.fn().mockImplementation(() => Promise.resolve()), searchData: jest.fn().mockImplementation(() => Promise.resolve()), })); @@ -44,7 +43,6 @@ describe('Test NodeSuggestions Component', () => { it(`Suggest & Suggest API for ${value} should work properly`, async () => { jest.useFakeTimers('modern'); const mockSearchData = searchData as jest.Mock; - const mockSuggestions = getSuggestions as jest.Mock; const searchValue = 'sale'; await act(async () => { render(); @@ -71,13 +69,7 @@ describe('Test NodeSuggestions Component', () => { jest.runAllTimers(); }); - expect(mockSearchData.mock.instances).toHaveLength(1); - expect(mockSuggestions.mock.instances).toHaveLength(1); - - expect(mockSuggestions.mock.calls[0][1]).toEqual( - SearchIndex[value as keyof typeof SearchIndex] - ); - expect(mockSuggestions.mock.calls[0][0]).toEqual(searchValue); + expect(mockSearchData.mock.instances).toHaveLength(2); }); }); });