Fixed Table isn't found to be added in the lineage #9746 (#9782)

* Fixed Table isn't found to be added in the lineage #9746

* added support for suggestion

* addressing comments
This commit is contained in:
Shailesh Parmar 2023-01-18 19:16:23 +05:30 committed by GitHub
parent 4bf60bd2f4
commit 11ebd8c050
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 16 deletions

View File

@ -13,6 +13,7 @@
import { Empty } from 'antd';
import { AxiosError } from 'axios';
import { PAGE_SIZE } from 'constants/constants';
import { capitalize, debounce } from 'lodash';
import { FormattedTableData } from 'Models';
import React, {
@ -22,13 +23,12 @@ import React, {
useEffect,
useState,
} from 'react';
import { searchData } from 'rest/miscAPI';
import { useTranslation } from 'react-i18next';
import { getSuggestions, searchData } from 'rest/miscAPI';
import { FQN_SEPARATOR_CHAR } from '../../constants/char.constants';
import { PAGE_SIZE } from '../../constants/constants';
import { EntityType, FqnPart } from '../../enums/entity.enum';
import { SearchIndex } from '../../enums/search.enum';
import { EntityReference } from '../../generated/type/entityReference';
import jsonData from '../../jsons/en';
import { formatDataResponse } from '../../utils/APIUtils';
import { getPartialNameFromTableFQN } from '../../utils/CommonUtils';
import { serviceTypeLogo } from '../../utils/ServiceUtils';
@ -44,6 +44,8 @@ const NodeSuggestions: FC<EntitySuggestionProps> = ({
entityType,
onSelectHandler,
}) => {
const { t } = useTranslation();
const [data, setData] = useState<Array<FormattedTableData>>([]);
const [isOpen, setIsOpen] = useState<boolean>(false);
const [searchValue, setSearchValue] = useState<string>('');
@ -61,6 +63,27 @@ const NodeSuggestions: FC<EntitySuggestionProps> = ({
}
};
const getSuggestResults = async (value: string) => {
try {
const data = await getSuggestions<ExploreSearchIndex>(
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<ExploreSearchIndex>(
@ -78,13 +101,19 @@ const NodeSuggestions: FC<EntitySuggestionProps> = ({
} catch (error) {
showErrorToast(
error as AxiosError,
jsonData['api-error-messages']['fetch-suggestions-error']
t('server.entity-fetch-error', {
entity: t('label.suggestion-lowercase-plural'),
})
);
}
};
const debouncedOnSearch = useCallback((searchText: string): void => {
getSearchResults(searchText);
if (searchText) {
getSuggestResults(searchText);
} else {
getSearchResults(searchText);
}
}, []);
const debounceOnSearch = useCallback(debounce(debouncedOnSearch, 300), [
@ -97,14 +126,14 @@ const NodeSuggestions: FC<EntitySuggestionProps> = ({
debounceOnSearch(searchText);
};
useEffect(() => {
getSearchResults(searchValue);
}, []);
useEffect(() => {
setIsOpen(data.length > 0);
}, [data]);
useEffect(() => {
getSearchResults(searchValue);
}, []);
return (
<div data-testid="suggestion-node">
<input

View File

@ -13,7 +13,7 @@
import { act, fireEvent, render, screen } from '@testing-library/react';
import React from 'react';
import { searchData } from 'rest/miscAPI';
import { getSuggestions, searchData } from 'rest/miscAPI';
import { SearchIndex } from '../../enums/search.enum';
import NodeSuggestions from './NodeSuggestions.component';
@ -25,6 +25,7 @@ const mockProps = {
const entityType = ['TABLE', 'TOPIC', 'DASHBOARD', 'MLMODEL'];
jest.mock('rest/miscAPI', () => ({
getSuggestions: jest.fn().mockImplementation(() => Promise.resolve()),
searchData: jest.fn().mockImplementation(() => Promise.resolve()),
}));
@ -40,9 +41,10 @@ describe('Test NodeSuggestions Component', () => {
});
entityType.forEach((value) => {
it(`Search API for ${value} should work properly`, async () => {
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(<NodeSuggestions {...mockProps} entityType={value} />);
@ -69,14 +71,13 @@ describe('Test NodeSuggestions Component', () => {
jest.runAllTimers();
});
// This function was instantiated exactly twice
expect(mockSearchData.mock.instances).toHaveLength(2);
expect(mockSearchData.mock.instances).toHaveLength(1);
expect(mockSuggestions.mock.instances).toHaveLength(1);
// 2nd call with value search and respective searchIndex
expect(mockSearchData.mock.calls[1][6]).toEqual(
expect(mockSuggestions.mock.calls[0][1]).toEqual(
SearchIndex[value as keyof typeof SearchIndex]
);
expect(mockSearchData.mock.calls[1][0]).toEqual(searchValue);
expect(mockSuggestions.mock.calls[0][0]).toEqual(searchValue);
});
});
});

View File

@ -508,6 +508,7 @@
"status": "Status",
"submit": "Submit",
"success": "Success",
"suggestion-lowercase-plural": "suggestions",
"suite": "Suite",
"summary": "Summary",
"synonym-plural": "synonyms",