UNPKG

@kit-data-manager/react-search-component

Version:

All-in-one component for rendering an elastic search UI for searching anything. Built-in support for visualizing related items in a graph and resolving unique identifiers.

44 lines 2.02 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { ReactSearchComponentContext } from "../components/ReactSearchComponentContext"; import { WithSearch } from "@elastic/react-search-ui"; import { useCallback } from "react"; import { backgroundSearchQuery } from "../lib/queries"; /** * Extends the elasticsearch SearchContext with additional functionality. This provider automatically * detects the SearchContext and uses it. When used outside a SearchContext, this provider silently does nothing. * @param props * @constructor */ export function ReactSearchComponentContextProvider(props) { const searchForBackground = useCallback(async (query) => { console.log("Background query"); const res = await backgroundSearchQuery(props.config, query); return res.hits.hits; }, [props.config]); return (_jsx(WithSearch, { mapContextToProps: ({ searchTerm, setSearchTerm, clearFilters, setSort }) => ({ searchTerm, setSearchTerm, clearFilters, setSort }), children: ({ searchTerm, setSearchTerm, clearFilters, setSort }) => { return (_jsx(ReactSearchComponentContext.Provider, { value: { searchTerm: searchTerm ?? "", searchFor: (query) => { if (clearFilters) clearFilters(); if (setSearchTerm) setSearchTerm(query); if (setSort) setSort([{ field: "_score", direction: "desc" }], "desc"); window.scrollTo({ top: 0, left: 0, behavior: "smooth" }); }, searchForBackground, config: props.config }, children: props.children })); } })); } //# sourceMappingURL=ReactSearchComponentContextProvider.js.map