mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-08-26 18:06:03 +00:00
parent
e086fb7c25
commit
cbcb910f06
@ -13,11 +13,19 @@
|
|||||||
|
|
||||||
import { Empty } from 'antd';
|
import { Empty } from 'antd';
|
||||||
import { AxiosError } from 'axios';
|
import { AxiosError } from 'axios';
|
||||||
import { capitalize } from 'lodash';
|
import { capitalize, debounce } from 'lodash';
|
||||||
import { FormattedTableData } from 'Models';
|
import { FormattedTableData } from 'Models';
|
||||||
import React, { FC, HTMLAttributes, useEffect, useState } from 'react';
|
import React, {
|
||||||
import { getSuggestions } from '../../axiosAPIs/miscAPI';
|
FC,
|
||||||
|
HTMLAttributes,
|
||||||
|
useCallback,
|
||||||
|
useEffect,
|
||||||
|
useState,
|
||||||
|
} from 'react';
|
||||||
|
import { searchData } from '../../axiosAPIs/miscAPI';
|
||||||
import { FQN_SEPARATOR_CHAR } from '../../constants/char.constants';
|
import { FQN_SEPARATOR_CHAR } from '../../constants/char.constants';
|
||||||
|
import { PAGE_SIZE } from '../../constants/constants';
|
||||||
|
import { INITIAL_FROM } from '../../constants/explore.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';
|
||||||
import { EntityReference } from '../../generated/type/entityReference';
|
import { EntityReference } from '../../generated/type/entityReference';
|
||||||
@ -53,31 +61,43 @@ const NodeSuggestions: FC<EntitySuggestionProps> = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
const getSearchResults = async (value: string) => {
|
||||||
getSuggestions(
|
try {
|
||||||
searchValue,
|
const data = await searchData(
|
||||||
|
value,
|
||||||
|
INITIAL_FROM,
|
||||||
|
PAGE_SIZE,
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
'',
|
||||||
SearchIndex[entityType as keyof typeof SearchIndex]
|
SearchIndex[entityType as keyof typeof SearchIndex]
|
||||||
)
|
|
||||||
.then((res) => {
|
|
||||||
if (res.data) {
|
|
||||||
setData(
|
|
||||||
// TODO: fix types below
|
|
||||||
formatDataResponse(
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
(res.data as any).suggest['metadata-suggest'][0].options
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
} else {
|
setData(formatDataResponse(data.data.hits.hits));
|
||||||
throw jsonData['api-error-messages']['unexpected-server-response'];
|
} catch (error) {
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((err: AxiosError) => {
|
|
||||||
showErrorToast(
|
showErrorToast(
|
||||||
err,
|
error as AxiosError,
|
||||||
jsonData['api-error-messages']['fetch-suggestions-error']
|
jsonData['api-error-messages']['fetch-suggestions-error']
|
||||||
);
|
);
|
||||||
});
|
}
|
||||||
}, [searchValue]);
|
};
|
||||||
|
|
||||||
|
const debouncedOnSearch = useCallback((searchText: string): void => {
|
||||||
|
getSearchResults(searchText);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const debounceOnSearch = useCallback(debounce(debouncedOnSearch, 300), [
|
||||||
|
debouncedOnSearch,
|
||||||
|
]);
|
||||||
|
|
||||||
|
const handleChange = (e: React.ChangeEvent<{ value: string }>): void => {
|
||||||
|
const searchText = e.target.value;
|
||||||
|
setSearchValue(searchText);
|
||||||
|
debounceOnSearch(searchText);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
getSearchResults(searchValue);
|
||||||
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setIsOpen(data.length > 0);
|
setIsOpen(data.length > 0);
|
||||||
@ -90,7 +110,7 @@ const NodeSuggestions: FC<EntitySuggestionProps> = ({
|
|||||||
placeholder={`Search for ${capitalize(entityType)}s...`}
|
placeholder={`Search for ${capitalize(entityType)}s...`}
|
||||||
type="search"
|
type="search"
|
||||||
value={searchValue}
|
value={searchValue}
|
||||||
onChange={(e) => setSearchValue(e.target.value)}
|
onChange={handleChange}
|
||||||
/>
|
/>
|
||||||
{data.length > 0 && isOpen ? (
|
{data.length > 0 && isOpen ? (
|
||||||
<div
|
<div
|
||||||
|
Loading…
x
Reference in New Issue
Block a user