@@ -13,14 +13,14 @@ import { FairDOConfigBuilder } from "@/config/FairDOConfigBuilder"
1313import { ErrorBoundary , Facet , Paging , PagingInfo , Results , ResultsPerPage , SearchBox , SearchProvider , WithSearch } from "@elastic/react-search-ui"
1414import { Layout , ResultViewProps } from "@elastic/react-search-ui-views"
1515import { LoaderCircle } from "lucide-react"
16- import { ComponentType , useMemo } from "react"
16+ import { ComponentType , useCallback , useMemo } from "react"
1717import "../index.css"
1818import "../elastic-ui.css"
1919import { TooltipProvider } from "./ui/tooltip"
2020import { useAutoDarkMode } from "@/components/utils"
21- import { PlaceholderResultView } from "@/components/result/PlaceholderResultView"
2221import { DefaultSorting } from "@/components/search/DefaultSorting"
2322import { NodeTypes } from "@xyflow/react"
23+ import { ResultViewSelector } from "@/components/result/ResultViewSelector"
2424
2525/**
2626 * All-in-one component for rendering an elastic search UI based on the provided configuration. Includes
@@ -40,6 +40,7 @@ import { NodeTypes } from "@xyflow/react"
4040export function FairDOElasticSearch ( {
4141 config : rawConfig ,
4242 resultView,
43+ resultViewPerIndex,
4344 facetOptionView,
4445 dark,
4546 graphNodeTypes
@@ -50,9 +51,27 @@ export function FairDOElasticSearch({
5051 config : FairDOConfig
5152
5253 /**
53- * React Component that will be used to render the results from the current search. Consider using the `GenericResultView`
54+ * React Component that will be used to render the results from the current search. Consider using the `GenericResultView`.
55+ * You can set custom result views per view using the `resultViewPerIndex` prop. Will be used as the result view
56+ * for all indices that have no override configured in `resultViewPerIndex`
57+ * @optional Can be omitted when `resultViewPerIndex` is specified for each index
58+ * @example
59+ * resultView={ ({ result }) => <GenericResultView result={result} ... /> }
5460 */
55- resultView : ComponentType < ResultViewProps >
61+ resultView ?: ComponentType < ResultViewProps >
62+
63+ /**
64+ * React Component that will be used to render the results from the current search. Consider using the `GenericResultView`.
65+ * In this prop you have to additionally specify which index the result view should be used for. If you want to use
66+ * the same result view for all indices, use `resultView`.
67+ * @optional can be omitted when `resultView` is set
68+ * @example
69+ * resultViewPerIndex={{
70+ * "my-index-1": ({ result }) => <GenericResultView result={result} ... />
71+ * "my-index-2": OtherResultView
72+ * }}
73+ */
74+ resultViewPerIndex ?: Record < string , ComponentType < ResultViewProps > >
5675
5776 /**
5877 * React Component that will be used to render the individual options (text right of the checkboxes) in a facet.
@@ -87,9 +106,12 @@ export function FairDOElasticSearch({
87106 return config . getFacetFields ( )
88107 } , [ config ] )
89108
90- const actualResultView = useMemo ( ( ) => {
91- return resultView ?? ( ( props : ResultViewProps ) => < PlaceholderResultView { ...props } /> )
92- } , [ resultView ] )
109+ const actualResultView = useCallback (
110+ ( props : ResultViewProps ) => {
111+ return < ResultViewSelector resultProps = { props } resultView = { resultView } resultViewPerIndex = { resultViewPerIndex } />
112+ } ,
113+ [ resultView , resultViewPerIndex ]
114+ )
93115
94116 return (
95117 < SearchProvider config = { elasticConfig } >
0 commit comments