1
- import { Meta , } from " @storybook/blocks"
1
+ import { Meta , Source } from " @storybook/blocks"
2
2
3
3
import " ../index.css"
4
4
@@ -7,9 +7,123 @@ import "../index.css"
7
7
<div >
8
8
# React FairDO Search
9
9
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.
11
11
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
+ ` } />
13
128
14
- See ` FairDOElasticSearch -> Demo Elastic 3 ` for an example
15
129
</div >
0 commit comments