mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-09-25 17:04:54 +00:00
add debounce on autocomplete in advanced search (#18471)
This commit is contained in:
parent
ba4a480bf1
commit
a47235581f
@ -12,7 +12,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { t } from 'i18next';
|
import { t } from 'i18next';
|
||||||
import { isEmpty, sortBy } from 'lodash';
|
import { debounce, isEmpty, sortBy } from 'lodash';
|
||||||
import {
|
import {
|
||||||
AsyncFetchListValues,
|
AsyncFetchListValues,
|
||||||
AsyncFetchListValuesResult,
|
AsyncFetchListValuesResult,
|
||||||
@ -115,8 +115,9 @@ class AdvancedSearchClassBase {
|
|||||||
entityField: EntityFields;
|
entityField: EntityFields;
|
||||||
suggestField?: SuggestionField;
|
suggestField?: SuggestionField;
|
||||||
}) => SelectFieldSettings['asyncFetch'] = ({ searchIndex, entityField }) => {
|
}) => SelectFieldSettings['asyncFetch'] = ({ searchIndex, entityField }) => {
|
||||||
return (search) => {
|
// Wrapping the fetch function in a debounce of 300 ms
|
||||||
return getAggregateFieldOptions(
|
const debouncedFetch = debounce((search, callback) => {
|
||||||
|
getAggregateFieldOptions(
|
||||||
searchIndex,
|
searchIndex,
|
||||||
entityField,
|
entityField,
|
||||||
search ?? '',
|
search ?? '',
|
||||||
@ -125,13 +126,19 @@ class AdvancedSearchClassBase {
|
|||||||
const buckets =
|
const buckets =
|
||||||
response.data.aggregations[`sterms#${entityField}`].buckets;
|
response.data.aggregations[`sterms#${entityField}`].buckets;
|
||||||
|
|
||||||
return {
|
callback({
|
||||||
values: buckets.map((bucket) => ({
|
values: buckets.map((bucket) => ({
|
||||||
value: bucket.key,
|
value: bucket.key,
|
||||||
title: bucket.label ?? bucket.key,
|
title: bucket.label ?? bucket.key,
|
||||||
})),
|
})),
|
||||||
hasMore: false,
|
hasMore: false,
|
||||||
};
|
});
|
||||||
|
});
|
||||||
|
}, 300);
|
||||||
|
|
||||||
|
return (search) => {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
debouncedFetch(search, resolve);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user