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.

23 lines 1.7 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { Handle, Position } from "@xyflow/react"; import { useCallback, useContext, useMemo } from "react"; import { ReactSearchComponentContext } from "../../components/ReactSearchComponentContext"; import { Button } from "../../components/ui/button"; import { SearchIcon } from "lucide-react"; import { useStore } from "zustand/index"; import { resultCache } from "../../lib/ResultCache"; export function ResultViewWrapper({ resultView: ResultView, id }) { const get = useStore(resultCache, (s) => s.get); const data = useMemo(() => { return get(id); }, [get, id]); const dataEmpty = useMemo(() => { return !data || Object.keys(data).length === 0; }, [data]); const { searchFor } = useContext(ReactSearchComponentContext); const searchForThis = useCallback(() => { searchFor(id); }, [id, searchFor]); return (_jsxs("div", { className: "rfs:w-[800px] rfs:-m-2", children: [_jsx(Handle, { type: "target", position: Position.Left }), !data || dataEmpty ? (_jsxs("div", { className: "rfs:m-2 rfs:p-4 rfs:rounded-lg rfs:bg-background rfs:border rfs:flex rfs:justify-between rfs:items-center", children: [_jsxs("div", { children: [_jsx("div", { children: id }), _jsx("div", { className: "rfs:text-muted-foreground", children: "Not found in cache, try searching for it" })] }), _jsxs(Button, { onClick: searchForThis, children: [_jsx(SearchIcon, { className: "rfs:size-4 rfs:mr-1" }), " Search"] })] })) : (_jsx(ResultView, { result: data, onClickLink: () => { } })), _jsx(Handle, { type: "source", position: Position.Right })] })); } //# sourceMappingURL=ResultViewWrapper.js.map