Skip to content

Commit c40e6ef

Browse files
committed
Merge branch 'wip'
# Conflicts: # package-lock.json # src/components/search/DefaultFacet.tsx
2 parents 4ced6ce + 542c780 commit c40e6ef

File tree

5 files changed

+77
-16
lines changed

5 files changed

+77
-16
lines changed

.prettierrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
"tabWidth": 4,
44
"useTabs": false,
55
"trailingComma": "none",
6-
"printWidth": 200
6+
"printWidth": 150
77
}

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"@radix-ui/react-select": "^2.1.2",
3939
"@radix-ui/react-slot": "^1.1.0",
4040
"@types/luxon": "^3.4.2",
41+
"@types/sparql-http-client": "^3.0.5",
4142
"@xyflow/react": "^12.3.6",
4243
"class-variance-authority": "^0.7.1",
4344
"clsx": "^2.1.1",
@@ -49,6 +50,7 @@
4950
"prettier": "^3.4.2",
5051
"react": "^18.3.1",
5152
"react-dom": "^18.3.1",
53+
"sparql-http-client": "^3.0.1",
5254
"swr": "^2.3.0",
5355
"tailwind-merge": "^2.5.5",
5456
"tailwindcss-animate": "^1.0.7",

src/components/search/DefaultFacet.tsx

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import type { FairDOConfigProvider } from "@/config/FairDOConfigProvider"
22
import type { FacetViewProps } from "@elastic/react-search-ui-views"
33
import { Button } from "@/components/ui/button"
4-
import { Checkbox } from "@/components/ui/checkbox"
54
import { Input } from "@/components/ui/input"
65
import { Label } from "@/components/ui/label"
76
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"
87
import { PlusIcon, Search } from "lucide-react"
98
import { useEffect, useMemo, useRef, useState } from "react"
10-
import { PidDisplay } from "@/components/result/PidDisplay"
11-
import { tryURLPrettyPrint } from "@/lib/utils"
9+
import { DefaultFacetOption } from "@/components/search/DefaultFacetOption"
1210

1311
export function DefaultFacet(props: FacetViewProps & { config: FairDOConfigProvider }) {
1412
const [search, setSearch] = useState("")
@@ -45,18 +43,15 @@ export function DefaultFacet(props: FacetViewProps & { config: FairDOConfigProvi
4543
)}
4644
</div>
4745

48-
{props.options.map((option) => {
49-
const value = option.value.toString()
50-
return (
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>}
55-
</Label>
56-
<div className="text-xs text-muted-foreground">{option.count}</div>
57-
</div>
58-
)
59-
})}
46+
{props.options.map((option) => (
47+
<DefaultFacetOption
48+
key={option.value.toString()}
49+
option={option}
50+
facetConfig={selfConfig}
51+
onSelect={props.onSelect}
52+
onRemove={props.onRemove}
53+
/>
54+
))}
6055

6156
{props.showMore ? (
6257
<Button className="p-1" onClick={props.onMoreClick} size="sm" variant="link">
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { Checkbox } from "@/components/ui/checkbox"
2+
import { Label } from "@/components/ui/label"
3+
import { PidDisplay } from "@/components/result/PidDisplay"
4+
import { FacetValue } from "@elastic/search-ui"
5+
import { FairDOFacetConfig } from "@/config/FairDOConfig"
6+
import { useEffect, useMemo } from "react"
7+
import { ontobeeResolver } from "@/lib/OntobeeResolver"
8+
9+
export function DefaultFacetOption({
10+
option,
11+
facetConfig,
12+
onSelect,
13+
onRemove
14+
}: {
15+
option: FacetValue
16+
facetConfig: FairDOFacetConfig
17+
onSelect(v: string): void
18+
onRemove(v: string): void
19+
}) {
20+
const value = useMemo(() => {
21+
return option.value.toString()
22+
}, [option.value])
23+
24+
useEffect(() => {
25+
if (value.startsWith("http://purl.obolibrary.org")) {
26+
ontobeeResolver.parse(value)
27+
}
28+
}, [value])
29+
30+
return (
31+
<div key={value} className="flex max-w-full items-center gap-2 break-words p-1 pb-2">
32+
<Checkbox id={value} checked={option.selected} onCheckedChange={(v) => (v ? onSelect(value) : onRemove(value))} />
33+
<Label htmlFor={value} className="min-w-0 grow break-words">
34+
{value ? facetConfig.usePidResolver ? <PidDisplay pid={value} /> : value : <span className="text-muted-foreground">None</span>}
35+
</Label>
36+
<div className="text-xs text-muted-foreground">{option.count}</div>
37+
</div>
38+
)
39+
}

src/lib/OntobeeResolver.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { ParsingClient } from "sparql-http-client"
2+
3+
export class OntobeeResolver {
4+
private client: ParsingClient
5+
6+
constructor() {
7+
this.client = new ParsingClient({ endpointUrl: "https://sparql.hegroup.org/sparql", fetch: (a, b) => fetch(a, { ...b, mode: "no-cors" }) })
8+
}
9+
10+
async parse(url: string) {
11+
try {
12+
const result = await this.client.query.select(`
13+
DEFINE sql:describe-mode "CBD"
14+
DESCRIBE <${url}>
15+
FROM <http://purl.obolibrary.org/obo/merged/CHMO>
16+
`)
17+
18+
console.log(result)
19+
} catch (e) {
20+
console.error(e)
21+
}
22+
}
23+
}
24+
25+
export const ontobeeResolver = new OntobeeResolver()

0 commit comments

Comments
 (0)