@@ -6,7 +6,7 @@ import { resultCache } from "@/lib/ResultCache"
6
6
import { autoUnwrap , autoUnwrapArray , toArray } from "@/components/result/utils"
7
7
import { DateTime } from "luxon"
8
8
import { BasicRelationNode } from "@/lib/RelationNode"
9
- import { BookText , ChevronDown , GitFork , ImageOff , LinkIcon , Microscope } from "lucide-react"
9
+ import { ChevronDown , GitFork , ImageOff , LinkIcon , Microscope } from "lucide-react"
10
10
import { Badge } from "@/components/ui/badge"
11
11
import { Button } from "@/components/ui/button"
12
12
import { DropdownMenu , DropdownMenuContent , DropdownMenuItem , DropdownMenuTrigger } from "@/components/ui/dropdown-menu"
@@ -116,7 +116,7 @@ export function GenericResultView({
116
116
showOpenInFairDoScope = true
117
117
} : GenericResultViewProps ) {
118
118
const { openRelationGraph } = useContext ( RFS_GlobalModalContext )
119
- const { searchFor , searchTerm, elasticConnector } = useContext ( FairDOSearchContext )
119
+ const { searchTerm, elasticConnector } = useContext ( FairDOSearchContext )
120
120
const addToResultCache = useStore ( resultCache , ( s ) => s . set )
121
121
const getResultFromCache = useStore ( resultCache , ( s ) => s . get )
122
122
@@ -259,54 +259,37 @@ export function GenericResultView({
259
259
)
260
260
261
261
const showRelatedItemsGraph = useCallback ( async ( ) => {
262
- if ( ! isMetadataFor || ! pid ) return
263
- await fetchRelatedItems ( pid , isMetadataFor . length )
264
-
265
- if ( isMetadataFor . length === 1 ) {
266
- searchFor ( isMetadataFor [ 0 ] )
267
- } else {
268
- openRelationGraph (
269
- [
270
- {
271
- id : pid ?? "source" ,
272
- label : title ?? "Source" ,
273
- tag : "Current" ,
274
- remoteURL : doLocation ,
275
- searchQuery : pid
276
- }
277
- ] ,
278
- isMetadataFor . map ( ( pid ) => {
279
- const cached = getResultFromCache ( pid )
280
- return new BasicRelationNode ( pid , "Related" , cached ?. name )
281
- } )
282
- )
283
- }
284
- } , [ doLocation , fetchRelatedItems , getResultFromCache , isMetadataFor , openRelationGraph , pid , searchFor , title ] )
285
-
286
- const showHasMetadataGraph = useCallback ( async ( ) => {
287
- if ( ! hasMetadata ) return
288
- await fetchRelatedItems ( hasMetadata . join ( " " ) , hasMetadata . length )
289
-
290
- if ( hasMetadata . length === 1 ) {
291
- searchFor ( hasMetadata [ 0 ] )
292
- } else {
293
- openRelationGraph (
294
- hasMetadata . map ( ( pid ) => {
295
- const cached = getResultFromCache ( pid )
296
- return new BasicRelationNode ( pid , "Metadata" , cached ?. name )
297
- } ) ,
298
- [
299
- {
300
- id : pid ?? "current" ,
301
- label : title ?? "Current" ,
302
- tag : "Current" ,
303
- remoteURL : doLocation ,
304
- searchQuery : pid
305
- }
306
- ]
307
- )
308
- }
309
- } , [ doLocation , fetchRelatedItems , getResultFromCache , hasMetadata , openRelationGraph , pid , searchFor , title ] )
262
+ if ( ! pid ) return
263
+ if ( isMetadataFor ) await fetchRelatedItems ( isMetadataFor . join ( " " ) , isMetadataFor . length )
264
+ if ( hasMetadata ) await fetchRelatedItems ( hasMetadata . join ( " " ) , hasMetadata . length )
265
+
266
+ openRelationGraph (
267
+ hasMetadata ?. map ( ( pid ) => {
268
+ const cached = getResultFromCache ( pid )
269
+ return new BasicRelationNode ( pid , "Related" , cached ?. name )
270
+ } ) ?? [ ] ,
271
+ {
272
+ id : pid ?? "source" ,
273
+ label : title ?? "Source" ,
274
+ tag : "Current" ,
275
+ remoteURL : doLocation ,
276
+ searchQuery : pid ,
277
+ highlight : true
278
+ } ,
279
+ isMetadataFor ?. map ( ( pid ) => {
280
+ const cached = getResultFromCache ( pid )
281
+ return new BasicRelationNode ( pid , "Related" , cached ?. name )
282
+ } ) ?? [ ]
283
+ )
284
+ } , [ doLocation , fetchRelatedItems , getResultFromCache , hasMetadata , isMetadataFor , openRelationGraph , pid , title ] )
285
+
286
+ const showRelatedItemsButton = useMemo ( ( ) => {
287
+ return ( hasMetadata && hasMetadata . length > 0 ) || ( isMetadataFor && isMetadataFor . length > 0 )
288
+ } , [ hasMetadata , isMetadataFor ] )
289
+
290
+ const relatedItemsAmount = useMemo ( ( ) => {
291
+ return ( hasMetadata ? hasMetadata . length : 0 ) + ( isMetadataFor ? isMetadataFor . length : 0 )
292
+ } , [ hasMetadata , isMetadataFor ] )
310
293
311
294
const exactPidMatch = useMemo ( ( ) => {
312
295
return searchTerm === pid || searchTerm === doLocation
@@ -369,7 +352,7 @@ export function GenericResultView({
369
352
</ div >
370
353
< div className = "rfs-grow" > { description } </ div >
371
354
< div className = "rfs-mt-8 rfs-flex rfs-flex-col rfs-flex-wrap rfs-justify-end rfs-gap-2 md:rfs-flex-row md:rfs-items-center md:rfs-gap-4" >
372
- { isMetadataFor && isMetadataFor . length > 0 && (
355
+ { showRelatedItemsButton && (
373
356
< div className = "rfs-flex rfs-items-center" >
374
357
< Button className = "rfs-grow rfs-rounded-r-none" size = "sm" variant = "secondary" onClick = { showRelatedItemsGraph } >
375
358
< GitFork className = "rfs-mr-1 rfs-size-4" /> Show Related Items
@@ -380,15 +363,10 @@ export function GenericResultView({
380
363
variant = "secondary"
381
364
onClick = { showRelatedItemsGraph }
382
365
>
383
- { isMetadataFor . length }
366
+ { relatedItemsAmount }
384
367
</ Button >
385
368
</ div >
386
369
) }
387
- { hasMetadata && (
388
- < Button className = "" size = "sm" variant = "secondary" onClick = { showHasMetadataGraph } >
389
- < BookText className = "rfs-mr-1 rfs-size-4" /> Find Metadata
390
- </ Button >
391
- ) }
392
370
393
371
{ landingPageLocation && (
394
372
< div className = "rfs-flex rfs-items-center" >
0 commit comments