Skip to content

Commit d62a9fc

Browse files
committed
Write some documentation
1 parent ded9f97 commit d62a9fc

File tree

2 files changed

+120
-4
lines changed

2 files changed

+120
-4
lines changed

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
export { FairDOElasticSearch } from "./components/FairDOElasticSearch"
2+
export { GenericResultView } from "@/components/result/GenericResultView"
3+
export type { ResultViewProps } from "@elastic/react-search-ui-views"
24
export * from "@/config/FairDOConfig"
35
export * from "@/config/FairDOConfigBuilder"

src/stories/Configure.mdx

Lines changed: 118 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Meta, } from "@storybook/blocks"
1+
import { Meta, Source } from "@storybook/blocks"
22

33
import "../index.css"
44

@@ -7,9 +7,123 @@ import "../index.css"
77
<div>
88
# React FairDO Search
99

10-
All-in-one component for rendering an elastic search UI for exploring fair digital objects.
10+
All-in-one component for rendering an elastic search UI for searching fair digital objects.
1111

12-
## Demo
12+
### Demo
13+
14+
Select `FairDOElasticSearch` on the right for an example
15+
16+
17+
### Usage
18+
19+
To use the component you have to provide the search configuration as well as a result view. The search configuration will be used
20+
to configure the underlying elastic adapter. The result view is used to render UI for the results received from elastic. Since
21+
the result can be of any form, this requires some configuration. Take a look at the GenericResultView component (in the Storybook) to
22+
see what the default result renderer can do. You can also define your own component. It is also possible to use the RelationsGraph in your
23+
own components.
24+
25+
You will need to bring your own solution for authenticating requests to elastic. Common approaches could be...
26+
27+
1. Proxy server that adds an API header to your requests
28+
2. Authentication in the browser that attaches an access code to the requests
29+
30+
See the example below for an initial configuration of the component.
31+
32+
### Example Configuration
33+
34+
<Source code={`
35+
export default function Home() {
36+
// First we configure the search itself. Here we defined the elastic endpoint as well as the facets.
37+
const config: FairDOConfig = useMemo(() => {
38+
return {
39+
alwaysSearchOnInitialLoad: true,
40+
host: <elastic host>,
41+
indices: [
42+
{
43+
name: "index1",
44+
facets: [
45+
{
46+
key: "hadPrimarySource.keyword",
47+
label: "Source",
48+
prettyPrintURLs: true
49+
},
50+
{
51+
key: "licenseURL.keyword",
52+
label: "License",
53+
prettyPrintURLs: true
54+
}
55+
],
56+
resultFields: [], // Leave empty to get all fields
57+
searchFields: ["name", "pid", "hasMetadata", "isMetadataFor"]
58+
}
59+
],
60+
initialState: {
61+
sortList: [
62+
{
63+
field: "_score",
64+
direction: "desc"
65+
},
66+
{
67+
field: "name.keyword",
68+
direction: "asc"
69+
}
70+
]
71+
},
72+
connectionOptions: {
73+
headers: {
74+
// Pass your authentication headers here
75+
}
76+
}
77+
}
78+
}, []) // Make sure to add all non-static dependencies here! E.g. access code
79+
80+
// To display our results we have to define a result view. Since every FDOs can look very different, the different
81+
// field names have to be defined here. You can also define your own component for rendering results.
82+
const resultView = useCallback((props: ResultViewProps) => {
83+
// GenericResultView is a configurable fallback component for displaying simple results
84+
return (
85+
<GenericResultView
86+
result={props.result}
87+
invertImageInDarkMode // Not recommended for colorful images
88+
tags={[
89+
{
90+
icon: <GraduationCap className="rfs-shrink-0 rfs-size-4 rfs-mr-2" />,
91+
label: "Resource Type",
92+
field: "resourceType"
93+
},
94+
{
95+
icon: <GlobeIcon className="rfs-shrink-0 rfs-size-4 rfs-mr-2" />,
96+
field: "hadPrimarySource",
97+
valueMapper: tryURLPrettyPrint
98+
},
99+
{
100+
icon: <ScaleIcon className="rfs-shrink-0 rfs-size-4 rfs-mr-2" />,
101+
field: "licenseURL",
102+
valueMapper: tryURLPrettyPrint
103+
},
104+
{
105+
icon: <AtomIcon className="rfs-shrink-0 rfs-size-4 rfs-mr-2" />,
106+
field: "Compound"
107+
}
108+
]}
109+
titleField="name"
110+
creationDateField="dateCreatedRfc3339"
111+
identifierField="identifier"
112+
digitalObjectLocationField="digitalObjectLocation"
113+
imageField="locationPreview/Sample"
114+
parentItemPidField="hasMetadata"
115+
relatedItemPidsField="isMetadataFor"
116+
pidField="pid"
117+
relatedItemsPrefetch={{ prefetchAmount: 20, searchFields: { pid: {}, isMetadataFor: {}, hasMetadata: {} } }}
118+
showOpenInFairDoScope
119+
/>
120+
)
121+
}, [])
122+
123+
return (
124+
<FairDOElasticSearch config={config} resultView={resultView} />
125+
)
126+
}
127+
`} />
13128

14-
See `FairDOElasticSearch -> Demo Elastic 3` for an example
15129
</div>

0 commit comments

Comments
 (0)