Skip to content

Commit a906728

Browse files
committed
Pretty print URLs
1 parent 8e73af5 commit a906728

File tree

3 files changed

+29
-26
lines changed

3 files changed

+29
-26
lines changed

src/components/result/NMRResultView.tsx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ import type { SearchResult } from "@elastic/search-ui"
44
import { FairDOSearchContext } from "@/components/FairDOSearchContext"
55
import { GlobalModalContext } from "@/components/GlobalModalContext"
66
import { ObjectRender } from "@/components/result/ObjectRender"
7-
import { PidDisplay } from "@/components/result/PidDisplay"
87
import { Badge } from "@/components/ui/badge"
98
import { Button } from "@/components/ui/button"
109
import { Dialog, DialogContent, DialogTrigger } from "@/components/ui/dialog"
1110
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"
1211
import { BasicRelationNode } from "@/lib/RelationNode"
1312
import { resultCache } from "@/lib/ResultCache"
14-
import { BookText, ChevronDown, File, GitFork, Globe, GraduationCap, ImageOff, LinkIcon, Microscope, Scale } from "lucide-react"
13+
import { BookText, ChevronDown, GitFork, Globe, GraduationCap, ImageOff, LinkIcon, Microscope, Scale } from "lucide-react"
1514
import { DateTime } from "luxon"
1615
import { useCallback, useContext, useEffect, useMemo } from "react"
1716
import { useStore } from "zustand"
1817
import Image from "next/image"
18+
import { tryURLPrettyPrint } from "@/lib/utils"
1919

2020
const HTTP_REGEX = /https?:\/\/[a-z]+\.[a-z]+.*/gm
2121

@@ -86,16 +86,18 @@ export function NMRResultView({ result, debug }: { result: SearchResult; debug?:
8686
}, [getField])
8787

8888
const hadPrimarySource = useMemo(() => {
89-
return getField("hadPrimarySource")
89+
const value = getField("hadPrimarySource")
90+
return tryURLPrettyPrint(value)
9091
}, [getField])
9192

9293
const license = useMemo(() => {
93-
return getField("licenseURL")
94+
const value = getField("licenseURL")
95+
return tryURLPrettyPrint(value)
9496
}, [getField])
9597

96-
const fileType = useMemo(() => {
97-
return getField("digitalObjectType")
98-
}, [getField])
98+
// const fileType = useMemo(() => {
99+
// return getField("digitalObjectType")
100+
// }, [getField])
99101

100102
const doLocation = useMemo(() => {
101103
const value = getField("digitalObjectLocation")
@@ -228,12 +230,12 @@ export function NMRResultView({ result, debug }: { result: SearchResult; debug?:
228230
<Scale className="mr-2 size-4 shrink-0" />{license}
229231
</span>
230232
</Badge>
231-
<Badge variant="secondary" className="truncate">
232-
<span className="flex truncate">
233-
<File className="mr-2 size-4 shrink-0" />
234-
<PidDisplay pid={fileType} />
235-
</span>
236-
</Badge>
233+
{/*<Badge variant="secondary" className="truncate">*/}
234+
{/* <span className="flex truncate">*/}
235+
{/* <File className="mr-2 size-4 shrink-0" />*/}
236+
{/* <PidDisplay pid={fileType} />*/}
237+
{/* </span>*/}
238+
{/*</Badge>*/}
237239
</div>
238240
<div className="grow"></div>
239241
<div className="mt-8 flex flex-col flex-wrap justify-end gap-2 md:flex-row md:items-center md:gap-4">

src/components/search/DefaultFacet.tsx

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover
88
import { PlusIcon, Search } from "lucide-react"
99
import { useEffect, useMemo, useRef, useState } from "react"
1010
import { PidDisplay } from "@/components/result/PidDisplay"
11+
import { tryURLPrettyPrint } from "@/lib/utils"
1112

1213
export function DefaultFacet(props: FacetViewProps & { config: FairDOConfigProvider }) {
1314
const [search, setSearch] = useState("")
@@ -45,20 +46,12 @@ export function DefaultFacet(props: FacetViewProps & { config: FairDOConfigProvi
4546
</div>
4647

4748
{props.options.map((option) => {
48-
const id = option.value.toString()
49+
const value = option.value.toString()
4950
return (
50-
<div key={id} className="flex max-w-full items-center gap-2 break-words p-1 pb-2">
51-
<Checkbox id={id} checked={option.selected} onCheckedChange={(v) => (v ? props.onSelect(option.value.toString()) : props.onRemove(option.value.toString()))} />
52-
<Label htmlFor={id} className="min-w-0 grow break-words">
53-
{option.value.toString() ? (
54-
selfConfig.usePidResolver ? (
55-
<PidDisplay pid={option.value.toString()} />
56-
) : (
57-
option.value.toString()
58-
)
59-
) : (
60-
<span className="text-muted-foreground">None</span>
61-
)}
51+
<div key={value} className="flex max-w-full items-center gap-2 break-words p-1 pb-2">
52+
<Checkbox id={value} checked={option.selected} onCheckedChange={(v) => (v ? props.onSelect(option.value.toString()) : props.onRemove(option.value.toString()))} />
53+
<Label htmlFor={value} className="min-w-0 grow break-words">
54+
{value ? selfConfig.usePidResolver ? <PidDisplay pid={value} /> : tryURLPrettyPrint(value) : <span className="text-muted-foreground">None</span>}
6255
</Label>
6356
<div className="text-xs text-muted-foreground">{option.count}</div>
6457
</div>

src/lib/utils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,11 @@ export function arrayToObjectEntries(array: string[]) {
1212
}
1313
return obj
1414
}
15+
16+
export function tryURLPrettyPrint(url: string) {
17+
if (URL.canParse(url)) {
18+
const parsed = new URL(url)
19+
const path = parsed.pathname
20+
return parsed.hostname.replace("www.", "") + (path === "/" ? "" : path)
21+
} else return url
22+
}

0 commit comments

Comments
 (0)