Skip to content

Commit db85d05

Browse files
committed
Finish graph improvements
1 parent 655b062 commit db85d05

File tree

4 files changed

+42
-62
lines changed

4 files changed

+42
-62
lines changed

src/components/graph/PlainNode.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ export function PlainNode(data: NodeProps) {
6060
}, [relationNode.searchQuery, searchFor])
6161

6262
return (
63-
<>
63+
<div>
6464
<Handle type="target" position={Position.Left} />
6565
<div
66-
className={`rfs-grid rfs-rounded-lg rfs-border rfs-border-border rfs-bg-background rfs-transition-all ${expand ? "rfs-grid-rows-[auto_1fr] rfs-shadow-lg" : "rfs-grid-rows-[auto_0fr]"}`}
66+
className={`rfs-grid rfs-rounded-lg rfs-border rfs-border-border rfs-bg-background rfs-transition-all ${expand ? "rfs-grid-rows-[auto_1fr] rfs-shadow-lg" : "rfs-grid-rows-[auto_0fr]"} rfs-max-w-[500px] ${relationNode.highlight ? "rfs-border-2 rfs-border-primary" : ""}`}
6767
>
6868
<div onClick={toggleExpand} className="rfs-p-4">
6969
<div className="rfs-items-centers rfs-flex rfs-gap-3">
@@ -95,6 +95,6 @@ export function PlainNode(data: NodeProps) {
9595
</div>
9696
</div>
9797
<Handle type="source" position={Position.Right} id="a" />
98-
</>
98+
</div>
9999
)
100100
}

src/components/result/GenericResultView.tsx

Lines changed: 35 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { resultCache } from "@/lib/ResultCache"
66
import { autoUnwrap, autoUnwrapArray, toArray } from "@/components/result/utils"
77
import { DateTime } from "luxon"
88
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"
1010
import { Badge } from "@/components/ui/badge"
1111
import { Button } from "@/components/ui/button"
1212
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"
@@ -116,7 +116,7 @@ export function GenericResultView({
116116
showOpenInFairDoScope = true
117117
}: GenericResultViewProps) {
118118
const { openRelationGraph } = useContext(RFS_GlobalModalContext)
119-
const { searchFor, searchTerm, elasticConnector } = useContext(FairDOSearchContext)
119+
const { searchTerm, elasticConnector } = useContext(FairDOSearchContext)
120120
const addToResultCache = useStore(resultCache, (s) => s.set)
121121
const getResultFromCache = useStore(resultCache, (s) => s.get)
122122

@@ -259,54 +259,37 @@ export function GenericResultView({
259259
)
260260

261261
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])
310293

311294
const exactPidMatch = useMemo(() => {
312295
return searchTerm === pid || searchTerm === doLocation
@@ -369,7 +352,7 @@ export function GenericResultView({
369352
</div>
370353
<div className="rfs-grow">{description}</div>
371354
<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 && (
373356
<div className="rfs-flex rfs-items-center">
374357
<Button className="rfs-grow rfs-rounded-r-none" size="sm" variant="secondary" onClick={showRelatedItemsGraph}>
375358
<GitFork className="rfs-mr-1 rfs-size-4" /> Show Related Items
@@ -380,15 +363,10 @@ export function GenericResultView({
380363
variant="secondary"
381364
onClick={showRelatedItemsGraph}
382365
>
383-
{isMetadataFor.length}
366+
{relatedItemsAmount}
384367
</Button>
385368
</div>
386369
)}
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-
)}
392370

393371
{landingPageLocation && (
394372
<div className="rfs-flex rfs-items-center">

src/lib/RelationNode.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export interface RelationNode {
44
tag?: string
55
remoteURL?: string
66
searchQuery?: string
7+
highlight?: boolean
78
}
89

910
export class BasicRelationNode implements RelationNode {
@@ -13,7 +14,8 @@ export class BasicRelationNode implements RelationNode {
1314
constructor(
1415
public id: string,
1516
public tag: string = "",
16-
public label: string = ""
17+
public label: string = "",
18+
public highlight: boolean = false
1719
) {
1820
this.label = label ?? ""
1921
this.remoteURL = `https://hdl.handle.net/${id}`

src/stories/RelationsGraph.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const Default: Story = {
2929
new BasicRelationNode("T10/parentB", "Parent"),
3030
new BasicRelationNode("T10/parentC", "Source")
3131
],
32-
base: new BasicRelationNode("T10/436895408650943, abcde", "Source"),
32+
base: new BasicRelationNode("T10/436895408650943, abcde", "Current", "", true),
3333
references: [
3434
new BasicRelationNode("T10/436895408650941", "Dataset", "Something else"),
3535
new BasicRelationNode("T10/436895408650942", "Dataset"),

0 commit comments

Comments
 (0)