Bugfix: Refresh search results when clearing category filter (#142853) (#142960)

(cherry picked from commit 022e59f241)

Co-authored-by: Mark Hopkin <mark.hopkin@elastic.co>
This commit is contained in:
Kibana Machine 2022-10-10 04:10:46 -06:00 committed by GitHub
parent e73f29edfc
commit bba1cbfa7d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,7 +6,7 @@
*/
import { Search as LocalSearch, PrefixIndexStrategy } from 'js-search';
import { useEffect, useRef } from 'react';
import { useRef } from 'react';
import type { IntegrationCardItem } from '../../../../common/types/models';
@ -16,13 +16,11 @@ export const fieldsToSearch = ['name', 'title'];
export function useLocalSearch(packageList: IntegrationCardItem[]) {
const localSearchRef = useRef<LocalSearch>(new LocalSearch(searchIdField));
useEffect(() => {
const localSearch = new LocalSearch(searchIdField);
localSearch.indexStrategy = new PrefixIndexStrategy();
fieldsToSearch.forEach((field) => localSearch.addIndex(field));
localSearch.addDocuments(packageList);
localSearchRef.current = localSearch;
}, [packageList]);
const localSearch = new LocalSearch(searchIdField);
localSearch.indexStrategy = new PrefixIndexStrategy();
fieldsToSearch.forEach((field) => localSearch.addIndex(field));
localSearch.addDocuments(packageList);
localSearchRef.current = localSearch;
return localSearchRef;
}