@@ -13,14 +13,14 @@ import { FairDOConfigBuilder } from "@/config/FairDOConfigBuilder"
13
13
import { ErrorBoundary , Facet , Paging , PagingInfo , Results , ResultsPerPage , SearchBox , SearchProvider , WithSearch } from "@elastic/react-search-ui"
14
14
import { Layout , ResultViewProps } from "@elastic/react-search-ui-views"
15
15
import { LoaderCircle } from "lucide-react"
16
- import { ComponentType , useMemo } from "react"
16
+ import { ComponentType , useCallback , useMemo } from "react"
17
17
import "../index.css"
18
18
import "../elastic-ui.css"
19
19
import { TooltipProvider } from "./ui/tooltip"
20
20
import { useAutoDarkMode } from "@/components/utils"
21
- import { PlaceholderResultView } from "@/components/result/PlaceholderResultView"
22
21
import { DefaultSorting } from "@/components/search/DefaultSorting"
23
22
import { NodeTypes } from "@xyflow/react"
23
+ import { ResultViewSelector } from "@/components/result/ResultViewSelector"
24
24
25
25
/**
26
26
* 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"
40
40
export function FairDOElasticSearch ( {
41
41
config : rawConfig ,
42
42
resultView,
43
+ resultViewPerIndex,
43
44
facetOptionView,
44
45
dark,
45
46
graphNodeTypes
@@ -50,9 +51,27 @@ export function FairDOElasticSearch({
50
51
config : FairDOConfig
51
52
52
53
/**
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} ... /> }
54
60
*/
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 > >
56
75
57
76
/**
58
77
* 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({
87
106
return config . getFacetFields ( )
88
107
} , [ config ] )
89
108
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
+ )
93
115
94
116
return (
95
117
< SearchProvider config = { elasticConfig } >
0 commit comments