Skip to content

Commit ded9f97

Browse files
committed
Make result view generic
1 parent d557834 commit ded9f97

16 files changed

+506
-436
lines changed

.storybook/preview.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ const preview: Preview = {
1010
color: /(background|color)$/i,
1111
date: /Date$/i
1212
}
13+
},
14+
docs: {
15+
toc: true
1316
}
1417
},
1518

src/components/FairDOElasticSearch.tsx

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type { FairDOConfig } from "@/config/FairDOConfig"
44
import type { SearchContextState } from "@elastic/search-ui"
55
import { FairDOSearchProvider } from "@/components/FairDOSearchProvider"
66
import { GlobalModalProvider } from "@/components/GlobalModalProvider"
7-
import { NMRResultView } from "@/components/result/NMRResultView"
87
import { ClearFilters } from "@/components/search/ClearFilters"
98
import { DefaultFacet, OptionViewProps } from "@/components/search/DefaultFacet"
109
import { DefaultSearchBox } from "@/components/search/DefaultSearchBox"
@@ -19,15 +18,23 @@ import "../index.css"
1918
import "../elastic-ui.css"
2019
import { TooltipProvider } from "./ui/tooltip"
2120
import { useAutoDarkMode } from "@/components/utils"
21+
import { PlaceholderResultView } from "@/components/result/PlaceholderResultView"
2222

2323
/**
2424
* All-in-one component for rendering an elastic search UI based on the provided configuration. Includes
25-
* an interactive graph of related records
26-
* @constructor
25+
* an interactive graph of related records. Pass in a config object ({@link FairDOConfig}) to configure the search.
26+
*
27+
* #### ⚠️ Warning
28+
*
29+
* Make sure your configuration is memoized or defined outside of any components
30+
*
31+
*
32+
* #### 🖌️ Customization
33+
* You can customize the default behaviour by overriding the default result view (resultView) or the views of the facet
34+
* options (facetOptionView)
2735
*/
2836
export function FairDOElasticSearch({
2937
config: rawConfig,
30-
debug,
3138
resultView,
3239
facetOptionView,
3340
dark
@@ -36,14 +43,13 @@ export function FairDOElasticSearch({
3643
* Make sure the config is either memoized or constant (defined outside any components)
3744
*/
3845
config: FairDOConfig
39-
resultView?: ComponentType<ResultViewProps>
46+
resultView: ComponentType<ResultViewProps>
4047
facetOptionView?: ComponentType<OptionViewProps>
4148

4249
/**
4350
* Set to true to enable dark mode. Alternatively, set class="dark" on your html or body element
4451
*/
4552
dark?: boolean
46-
debug?: boolean
4753
}) {
4854
useAutoDarkMode(dark)
4955

@@ -60,8 +66,8 @@ export function FairDOElasticSearch({
6066
}, [config])
6167

6268
const actualResultView = useMemo(() => {
63-
return resultView ?? ((props: ResultViewProps) => <NMRResultView result={props.result} debug={debug} />)
64-
}, [debug, resultView])
69+
return resultView ?? ((props: ResultViewProps) => <PlaceholderResultView {...props} />)
70+
}, [resultView])
6571

6672
return (
6773
<SearchProvider config={elasticConfig}>
@@ -112,7 +118,7 @@ export function FairDOElasticSearch({
112118
<>
113119
{isLoading && !wasSearched && (
114120
<div className="rfs-flex rfs-justify-center">
115-
<LoaderCircle className="size-6 animate-spin" />
121+
<LoaderCircle className="rfs-size-6 rfs-animate-spin" />
116122
</div>
117123
)}
118124

src/components/GlobalModalProvider.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { PropsWithChildren } from "react"
55
import { RelationsGraphModal } from "@/components/graph/RelationsGraphModal"
66
import { ReactFlowProvider } from "@xyflow/react"
77
import { useCallback, useState } from "react"
8-
import { GlobalModalContext } from "./GlobalModalContext"
8+
import { RFS_GlobalModalContext } from "./RFS_GlobalModalContext"
99

1010
export function GlobalModalProvider(props: PropsWithChildren) {
1111
const [relationGraphState, setRelationGraphState] = useState<{
@@ -31,7 +31,7 @@ export function GlobalModalProvider(props: PropsWithChildren) {
3131
}, [])
3232

3333
return (
34-
<GlobalModalContext.Provider value={{ openRelationGraph }}>
34+
<RFS_GlobalModalContext.Provider value={{ openRelationGraph }}>
3535
<ReactFlowProvider>
3636
<RelationsGraphModal
3737
isOpen={relationGraphState.isOpen}
@@ -42,6 +42,6 @@ export function GlobalModalProvider(props: PropsWithChildren) {
4242

4343
{props.children}
4444
</ReactFlowProvider>
45-
</GlobalModalContext.Provider>
45+
</RFS_GlobalModalContext.Provider>
4646
)
4747
}

src/components/GlobalModalContext.tsx renamed to src/components/RFS_GlobalModalContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { RelationNode } from "@/lib/RelationNode"
22
import { createContext } from "react"
33

4-
export const GlobalModalContext = createContext<{
4+
export const RFS_GlobalModalContext = createContext<{
55
openRelationGraph: (base: RelationNode, referenced: RelationNode[]) => void
66
}>({
77
openRelationGraph: (): void => {

src/components/graph/RelationsGraph.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,7 @@ import type { RelationNode } from "@/lib/RelationNode"
22

33
import { buildGraphForReferences } from "@/components/graph/helpers"
44
import { PlainNode } from "@/components/graph/PlainNode"
5-
import {
6-
Background,
7-
BackgroundVariant,
8-
ReactFlow,
9-
useEdgesState,
10-
useNodesInitialized,
11-
useNodesState,
12-
useReactFlow
13-
} from "@xyflow/react"
5+
import { Background, BackgroundVariant, ReactFlow, useEdgesState, useNodesInitialized, useNodesState, useReactFlow } from "@xyflow/react"
146
import { useEffect, useMemo } from "react"
157
import "@xyflow/react/dist/style.css"
168

@@ -57,7 +49,7 @@ export function RelationsGraph(props: {
5749
onEdgesChange={onEdgesChange}
5850
proOptions={{ hideAttribution: true }}
5951
>
60-
<Background color="hsl(var(--border))" variant={BackgroundVariant.Lines} />
52+
<Background color="hsl(var(--rfs-border))" variant={BackgroundVariant.Lines} />
6153
</ReactFlow>
6254
)
6355
}

0 commit comments

Comments
 (0)