mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-10-18 12:18:35 +00:00
fix: use search api instead of suggest (#11423)
This commit is contained in:
parent
3f65c8ab0f
commit
98d09ec6a3
@ -24,7 +24,7 @@ import React, {
|
|||||||
useState,
|
useState,
|
||||||
} from 'react';
|
} from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
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 { FQN_SEPARATOR_CHAR } from '../../constants/char.constants';
|
||||||
import { EntityType, FqnPart } from '../../enums/entity.enum';
|
import { EntityType, FqnPart } from '../../enums/entity.enum';
|
||||||
import { SearchIndex } from '../../enums/search.enum';
|
import { SearchIndex } from '../../enums/search.enum';
|
||||||
@ -63,27 +63,6 @@ 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) => {
|
const getSearchResults = async (value: string) => {
|
||||||
try {
|
try {
|
||||||
const data = await searchData<ExploreSearchIndex>(
|
const data = await searchData<ExploreSearchIndex>(
|
||||||
@ -109,11 +88,7 @@ const NodeSuggestions: FC<EntitySuggestionProps> = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const debouncedOnSearch = useCallback((searchText: string): void => {
|
const debouncedOnSearch = useCallback((searchText: string): void => {
|
||||||
if (searchText) {
|
getSearchResults(searchText);
|
||||||
getSuggestResults(searchText);
|
|
||||||
} else {
|
|
||||||
getSearchResults(searchText);
|
|
||||||
}
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const debounceOnSearch = useCallback(debounce(debouncedOnSearch, 300), [
|
const debounceOnSearch = useCallback(debounce(debouncedOnSearch, 300), [
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
import { act, fireEvent, render, screen } from '@testing-library/react';
|
import { act, fireEvent, render, screen } from '@testing-library/react';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { getSuggestions, searchData } from 'rest/miscAPI';
|
import { searchData } from 'rest/miscAPI';
|
||||||
import { SearchIndex } from '../../enums/search.enum';
|
import { SearchIndex } from '../../enums/search.enum';
|
||||||
import NodeSuggestions from './NodeSuggestions.component';
|
import NodeSuggestions from './NodeSuggestions.component';
|
||||||
|
|
||||||
@ -25,7 +25,6 @@ const mockProps = {
|
|||||||
const entityType = ['TABLE', 'TOPIC', 'DASHBOARD', 'MLMODEL'];
|
const entityType = ['TABLE', 'TOPIC', 'DASHBOARD', 'MLMODEL'];
|
||||||
|
|
||||||
jest.mock('rest/miscAPI', () => ({
|
jest.mock('rest/miscAPI', () => ({
|
||||||
getSuggestions: jest.fn().mockImplementation(() => Promise.resolve()),
|
|
||||||
searchData: 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 () => {
|
it(`Suggest & Suggest API for ${value} should work properly`, async () => {
|
||||||
jest.useFakeTimers('modern');
|
jest.useFakeTimers('modern');
|
||||||
const mockSearchData = searchData as jest.Mock;
|
const mockSearchData = searchData as jest.Mock;
|
||||||
const mockSuggestions = getSuggestions as jest.Mock;
|
|
||||||
const searchValue = 'sale';
|
const searchValue = 'sale';
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
render(<NodeSuggestions {...mockProps} entityType={value} />);
|
render(<NodeSuggestions {...mockProps} entityType={value} />);
|
||||||
@ -71,13 +69,7 @@ describe('Test NodeSuggestions Component', () => {
|
|||||||
jest.runAllTimers();
|
jest.runAllTimers();
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(mockSearchData.mock.instances).toHaveLength(1);
|
expect(mockSearchData.mock.instances).toHaveLength(2);
|
||||||
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);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user