Skip to content

Commit 8e73af5

Browse files
committed
Fix #4
1 parent f92617f commit 8e73af5

File tree

1 file changed

+16
-69
lines changed

1 file changed

+16
-69
lines changed

src/components/result/NMRResultView.tsx

Lines changed: 16 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,17 @@ import { PidDisplay } from "@/components/result/PidDisplay"
88
import { Badge } from "@/components/ui/badge"
99
import { Button } from "@/components/ui/button"
1010
import { Dialog, DialogContent, DialogTrigger } from "@/components/ui/dialog"
11-
import {
12-
DropdownMenu,
13-
DropdownMenuContent,
14-
DropdownMenuItem,
15-
DropdownMenuTrigger
16-
} from "@/components/ui/dropdown-menu"
11+
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"
1712
import { BasicRelationNode } from "@/lib/RelationNode"
1813
import { resultCache } from "@/lib/ResultCache"
19-
import {
20-
BookText,
21-
ChevronDown,
22-
File,
23-
GitFork,
24-
Globe,
25-
GraduationCap,
26-
ImageOff,
27-
LinkIcon,
28-
Microscope,
29-
Scale
30-
} from "lucide-react"
14+
import { BookText, ChevronDown, File, GitFork, Globe, GraduationCap, ImageOff, LinkIcon, Microscope, Scale } from "lucide-react"
3115
import { DateTime } from "luxon"
3216
import { useCallback, useContext, useEffect, useMemo } from "react"
3317
import { useStore } from "zustand"
3418
import Image from "next/image"
3519

20+
const HTTP_REGEX = /https?:\/\/[a-z]+\.[a-z]+.*/gm
21+
3622
function autoUnwrap(item: string | { raw: string }) {
3723
if (typeof item === "string") {
3824
return item
@@ -112,7 +98,9 @@ export function NMRResultView({ result, debug }: { result: SearchResult; debug?:
11298
}, [getField])
11399

114100
const doLocation = useMemo(() => {
115-
return getField("digitalObjectLocation")
101+
const value = getField("digitalObjectLocation")
102+
if (HTTP_REGEX.test(value)) return value
103+
else return `https://doi.org/${value}`
116104
}, [getField])
117105

118106
const previewImage = useMemo(() => {
@@ -178,15 +166,7 @@ export function NMRResultView({ result, debug }: { result: SearchResult; debug?:
178166
return new BasicRelationNode(pid, "Dataset", cached?.name)
179167
})
180168
)
181-
}, [
182-
doLocation,
183-
fetchRelatedItems,
184-
getResultFromCache,
185-
isMetadataFor,
186-
openRelationGraph,
187-
pid,
188-
title
189-
])
169+
}, [doLocation, fetchRelatedItems, getResultFromCache, isMetadataFor, openRelationGraph, pid, title])
190170

191171
const goToMetadata = useCallback(() => {
192172
searchFor(hasMetadata)
@@ -206,19 +186,11 @@ export function NMRResultView({ result, debug }: { result: SearchResult; debug?:
206186
}, [addToResultCache, pid, title])
207187

208188
return (
209-
<div
210-
className={`m-2 rounded-lg border border-border p-4 ${exactPidMatch ? "animate-outline-ping" : ""}`}
211-
>
189+
<div className={`m-2 rounded-lg border border-border p-4 ${exactPidMatch ? "animate-outline-ping" : ""}`}>
212190
<div className="grid grid-rows-[100px_1fr] gap-4 overflow-x-auto md:max-w-full md:grid-cols-[200px_1fr] md:grid-rows-1">
213191
<div className="flex justify-center rounded dark:bg-white md:items-center md:p-2">
214192
{previewImage ? (
215-
<Image
216-
className="md:size-[200px]"
217-
src={previewImage}
218-
alt={`Preview for ${title}`}
219-
width={200}
220-
height={200}
221-
/>
193+
<Image className="md:size-[200px]" src={previewImage} alt={`Preview for ${title}`} width={200} height={200} />
222194
) : (
223195
<div className="flex flex-col justify-center dark:text-background">
224196
<ImageOff className="size-6 text-muted-foreground/50" />
@@ -237,11 +209,7 @@ export function NMRResultView({ result, debug }: { result: SearchResult; debug?:
237209
{identifier} -{creationDate}
238210
</span>
239211
</div>
240-
<a
241-
href={`https://hdl.handle.net/${id}`}
242-
target="_blank"
243-
className="mb-2 block leading-3 hover:underline"
244-
>
212+
<a href={`https://hdl.handle.net/${id}`} target="_blank" className="mb-2 block leading-3 hover:underline">
245213
<span className="text-sm text-muted-foreground">{id}</span>
246214
</a>
247215
<div className="flex flex-wrap gap-2">
@@ -283,31 +251,16 @@ export function NMRResultView({ result, debug }: { result: SearchResult; debug?:
283251
)}
284252
{isMetadataFor.length > 0 && (
285253
<div className="flex items-center">
286-
<Button
287-
className="grow rounded-r-none"
288-
size="sm"
289-
variant="secondary"
290-
onClick={showRelatedItems}
291-
>
254+
<Button className="grow rounded-r-none" size="sm" variant="secondary" onClick={showRelatedItems}>
292255
<GitFork className="mr-1 size-4" /> Show Related Items
293256
</Button>
294-
<Button
295-
className="rounded-l-none border-l border-l-border text-xs font-bold"
296-
size="sm"
297-
variant="secondary"
298-
onClick={showRelatedItems}
299-
>
257+
<Button className="rounded-l-none border-l border-l-border text-xs font-bold" size="sm" variant="secondary" onClick={showRelatedItems}>
300258
{isMetadataFor.length}
301259
</Button>
302260
</div>
303261
)}
304262
{hasMetadata && (
305-
<Button
306-
className=""
307-
size="sm"
308-
variant="secondary"
309-
onClick={goToMetadata}
310-
>
263+
<Button className="" size="sm" variant="secondary" onClick={goToMetadata}>
311264
<BookText className="mr-1 size-4" /> Find Metadata
312265
</Button>
313266
)}
@@ -330,15 +283,9 @@ export function NMRResultView({ result, debug }: { result: SearchResult; debug?:
330283
<LinkIcon className="mr-1 size-4" /> Open Source
331284
</DropdownMenuItem>
332285
</a>
333-
<a
334-
href={`https://kit-data-manager.github.io/fairdoscope/?pid=${
335-
pid
336-
}`}
337-
target="_blank"
338-
>
286+
<a href={`https://kit-data-manager.github.io/fairdoscope/?pid=${pid}`} target="_blank">
339287
<DropdownMenuItem>
340-
<Microscope className="mr-1 size-4" /> Open in
341-
FAIR-DOscope
288+
<Microscope className="mr-1 size-4" /> Open in FAIR-DOscope
342289
</DropdownMenuItem>
343290
</a>
344291
</DropdownMenuContent>

0 commit comments

Comments
 (0)