Skip to content

Commit ee1adc3

Browse files
committed
Rename some props and change docs to make related items clearer on GenericResultView
1 parent c524c28 commit ee1adc3

File tree

3 files changed

+32
-26
lines changed

3 files changed

+32
-26
lines changed

src/components/result/GenericResultView.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,20 @@ export interface GenericResultViewProps {
5959
pidField?: string
6060

6161
/**
62-
* The elastic field where the related items of the current FDO will be read from. Should be an array of PIDs or otherwise unique identifiers. Will be displayed in a related items graph.
62+
* The elastic field where the unique identifier of the child item(s) of the current FDO will be read from. Should be an array of PIDs or otherwise unique identifiers. Will be displayed in a related items graph.
6363
*/
64-
relatedItemPidsField?: string
64+
childItemPidField?: string
6565

6666
/**
6767
* Options for prefetching of related items in the relations graph. It is recommended to define this if the default settings don't work properly.
68+
* @default Value of pidField
69+
* @example
70+
* relatedItemsPrefetch={{ searchFields: { pid: {} } }}
6871
*/
69-
relatedItemsPrefetch?: { searchFields?: Record<string, SearchFieldConfiguration> }
72+
relatedItemsPrefetchOptions?: { searchFields?: Record<string, SearchFieldConfiguration> }
7073

7174
/**
72-
* The elastic field where the unique identifier of the parent item (metadata item) of the current FDO will be read from. Will be accessible via a `Find Metadata` button
75+
* The elastic field where the unique identifier of the parent item(s) of the current FDO will be read from. Should be an array of PIDs or otherwise unique identifiers. Will be displayed in a related items graph.
7376
*/
7477
parentItemPidField?: string
7578

@@ -112,12 +115,12 @@ export function GenericResultView({
112115
landingPageLocationField = "landingPageLocation",
113116
digitalObjectLocationField = "digitalObjectLocation",
114117
pidField = "pid",
115-
relatedItemPidsField = "isMetadataFor",
118+
childItemPidField = "isMetadataFor",
116119
parentItemPidField = "hasMetadata",
117120
creationDateField = "creationDate",
118121
editedDateField = "editedDate",
119122
additionalIdentifierField = "identifier",
120-
relatedItemsPrefetch = { searchFields: { pid: {} } },
123+
relatedItemsPrefetchOptions = { searchFields: { pid: {} } },
121124
tags = [],
122125
showOpenInFairDoScope = true
123126
}: GenericResultViewProps) {
@@ -229,9 +232,9 @@ export function GenericResultView({
229232
}, [getArrayOrSingleField, additionalIdentifierField])
230233

231234
const isMetadataFor = useMemo(() => {
232-
const val = getArrayOrSingleField(relatedItemPidsField ?? "isMetadataFor")
235+
const val = getArrayOrSingleField(childItemPidField ?? "isMetadataFor")
233236
return val ? toArray(val) : undefined
234-
}, [getArrayOrSingleField, relatedItemPidsField])
237+
}, [getArrayOrSingleField, childItemPidField])
235238

236239
const creationDate = useMemo(() => {
237240
const value = getField(creationDateField ?? "dateCreated")
@@ -260,7 +263,7 @@ export function GenericResultView({
260263
{
261264
result_fields: {},
262265
searchTerm: term,
263-
search_fields: relatedItemsPrefetch?.searchFields ?? { [pidField ?? "pid"]: {} },
266+
search_fields: relatedItemsPrefetchOptions?.searchFields ?? { [pidField ?? "pid"]: {} },
264267
resultsPerPage: amount
265268
}
266269
)
@@ -277,7 +280,7 @@ export function GenericResultView({
277280
alert("Failed to fetch related items, graph may be incomplete")
278281
}
279282
},
280-
[addToResultCache, elasticConnector, pidField, relatedItemsPrefetch?.searchFields]
283+
[addToResultCache, elasticConnector, pidField, relatedItemsPrefetchOptions?.searchFields]
281284
)
282285

283286
const showRelatedItemsGraph = useCallback(async () => {

src/stories/0 Getting Started.mdx

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,15 @@ export default function Home() {
8181
return (
8282
<GenericResultView
8383
result={props.result}
84-
invertImageInDarkMode // Not recommended for colorful images
84+
85+
pidField="pid"
86+
titleField="name"
87+
creationDateField="dateCreatedRfc3339"
88+
imageField="locationPreview/Sample"
89+
90+
parentItemPidField="hasMetadata"
91+
childItemPidField="isMetadataFor"
92+
8593
tags={[
8694
{
8795
icon: <GraduationCap />,
@@ -91,28 +99,24 @@ export default function Home() {
9199
{
92100
icon: <GlobeIcon />,
93101
field: "hadPrimarySource",
94-
valueMapper: tryURLPrettyPrint
102+
singleValueMapper: tryURLPrettyPrint
95103
},
96104
{
97105
icon: <ScaleIcon />,
98106
field: "licenseURL",
99-
valueMapper: tryURLPrettyPrint
107+
singleValueMapper: value => value + " can be mapped" // Can use simple string mapping
100108
},
101109
{
102110
icon: <AtomIcon />,
103-
field: "Compound"
111+
field: "Compound",
112+
singleValueMapper: value => <div>{value}</div> // Can pass any component as tag content
104113
}
105114
]}
106-
titleField="name"
107-
creationDateField="dateCreatedRfc3339"
108-
identifierField="identifier"
109-
digitalObjectLocationField="digitalObjectLocation"
110-
imageField="locationPreview/Sample"
111-
parentItemPidField="hasMetadata"
112-
relatedItemPidsField="isMetadataFor"
113-
pidField="pid"
114-
relatedItemsPrefetch={{ searchFields: { pid: {} } }}
115-
showOpenInFairDoScope // Many more options exist, use TypeScript to easily view them in your code
115+
116+
invertImageInDarkMode // Not recommended for colorful images
117+
showOpenInFairDoScope
118+
119+
// ...many more options exist, use TypeScript to easily view them in your code
116120
/>
117121
)
118122
}, [])

src/stories/FairDOElasticSearch.stories.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,8 @@ export const GenericResultRenderer: Story = {
212212
digitalObjectLocationField="digitalObjectLocation"
213213
imageField="locationPreview/Sample"
214214
parentItemPidField="hasMetadata"
215-
relatedItemPidsField="isMetadataFor"
215+
childItemPidField="isMetadataFor"
216216
pidField="pid"
217-
relatedItemsPrefetch={{ searchFields: { pid: {} } }}
218217
showOpenInFairDoScope
219218
/>
220219
)

0 commit comments

Comments
 (0)