@@ -8,31 +8,17 @@ import { PidDisplay } from "@/components/result/PidDisplay"
8
8
import { Badge } from "@/components/ui/badge"
9
9
import { Button } from "@/components/ui/button"
10
10
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"
17
12
import { BasicRelationNode } from "@/lib/RelationNode"
18
13
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"
31
15
import { DateTime } from "luxon"
32
16
import { useCallback , useContext , useEffect , useMemo } from "react"
33
17
import { useStore } from "zustand"
34
18
import Image from "next/image"
35
19
20
+ const HTTP_REGEX = / h t t p s ? : \/ \/ [ a - z ] + \. [ a - z ] + .* / gm
21
+
36
22
function autoUnwrap ( item : string | { raw : string } ) {
37
23
if ( typeof item === "string" ) {
38
24
return item
@@ -112,7 +98,9 @@ export function NMRResultView({ result, debug }: { result: SearchResult; debug?:
112
98
} , [ getField ] )
113
99
114
100
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 } `
116
104
} , [ getField ] )
117
105
118
106
const previewImage = useMemo ( ( ) => {
@@ -178,15 +166,7 @@ export function NMRResultView({ result, debug }: { result: SearchResult; debug?:
178
166
return new BasicRelationNode ( pid , "Dataset" , cached ?. name )
179
167
} )
180
168
)
181
- } , [
182
- doLocation ,
183
- fetchRelatedItems ,
184
- getResultFromCache ,
185
- isMetadataFor ,
186
- openRelationGraph ,
187
- pid ,
188
- title
189
- ] )
169
+ } , [ doLocation , fetchRelatedItems , getResultFromCache , isMetadataFor , openRelationGraph , pid , title ] )
190
170
191
171
const goToMetadata = useCallback ( ( ) => {
192
172
searchFor ( hasMetadata )
@@ -206,19 +186,11 @@ export function NMRResultView({ result, debug }: { result: SearchResult; debug?:
206
186
} , [ addToResultCache , pid , title ] )
207
187
208
188
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" : "" } ` } >
212
190
< 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" >
213
191
< div className = "flex justify-center rounded dark:bg-white md:items-center md:p-2" >
214
192
{ 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 } />
222
194
) : (
223
195
< div className = "flex flex-col justify-center dark:text-background" >
224
196
< ImageOff className = "size-6 text-muted-foreground/50" />
@@ -237,11 +209,7 @@ export function NMRResultView({ result, debug }: { result: SearchResult; debug?:
237
209
{ identifier } -{ creationDate }
238
210
</ span >
239
211
</ 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" >
245
213
< span className = "text-sm text-muted-foreground" > { id } </ span >
246
214
</ a >
247
215
< div className = "flex flex-wrap gap-2" >
@@ -283,31 +251,16 @@ export function NMRResultView({ result, debug }: { result: SearchResult; debug?:
283
251
) }
284
252
{ isMetadataFor . length > 0 && (
285
253
< 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 } >
292
255
< GitFork className = "mr-1 size-4" /> Show Related Items
293
256
</ 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 } >
300
258
{ isMetadataFor . length }
301
259
</ Button >
302
260
</ div >
303
261
) }
304
262
{ hasMetadata && (
305
- < Button
306
- className = ""
307
- size = "sm"
308
- variant = "secondary"
309
- onClick = { goToMetadata }
310
- >
263
+ < Button className = "" size = "sm" variant = "secondary" onClick = { goToMetadata } >
311
264
< BookText className = "mr-1 size-4" /> Find Metadata
312
265
</ Button >
313
266
) }
@@ -330,15 +283,9 @@ export function NMRResultView({ result, debug }: { result: SearchResult; debug?:
330
283
< LinkIcon className = "mr-1 size-4" /> Open Source
331
284
</ DropdownMenuItem >
332
285
</ 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" >
339
287
< DropdownMenuItem >
340
- < Microscope className = "mr-1 size-4" /> Open in
341
- FAIR-DOscope
288
+ < Microscope className = "mr-1 size-4" /> Open in FAIR-DOscope
342
289
</ DropdownMenuItem >
343
290
</ a >
344
291
</ DropdownMenuContent >
0 commit comments