Skip to content

Commit a20d3e1

Browse files
committed
Better config for facet options and truncate long words
1 parent a440c8e commit a20d3e1

File tree

10 files changed

+47
-67
lines changed

10 files changed

+47
-67
lines changed

.storybook/main.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ import type { StorybookConfig } from "@storybook/react-vite"
22

33
const config: StorybookConfig = {
44
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
5-
addons: ["@storybook/addon-essentials", "@chromatic-com/storybook", "@storybook/addon-interactions", "@storybook/addon-themes"],
5+
addons: [
6+
"@storybook/addon-essentials",
7+
"@chromatic-com/storybook",
8+
"@storybook/addon-interactions",
9+
"@storybook/addon-themes",
10+
"@storybook/addon-docs"
11+
],
612
framework: {
713
name: "@storybook/react-vite",
814
options: {}

package-lock.json

Lines changed: 2 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"@radix-ui/react-popover": "^1.1.2",
3838
"@radix-ui/react-select": "^2.1.2",
3939
"@radix-ui/react-slot": "^1.1.0",
40+
"@storybook/addon-docs": "^8.5.0",
4041
"@types/luxon": "^3.4.2",
4142
"@types/sparql-http-client": "^3.0.5",
4243
"@xyflow/react": "^12.3.6",

src/components/search/DefaultFacetOption.tsx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { PidDisplay } from "@/components/result/PidDisplay"
44
import { FacetValue } from "@elastic/search-ui"
55
import { FairDOFacetConfig } from "@/config/FairDOConfig"
66
import { useMemo } from "react"
7+
import { tryURLPrettyPrint } from "@/lib/utils"
78

89
export function DefaultFacetOption({
910
option,
@@ -20,18 +21,25 @@ export function DefaultFacetOption({
2021
return option.value.toString()
2122
}, [option.value])
2223

23-
// TODO find a way to query obolibrary
24-
// useEffect(() => {
25-
// if (value.startsWith("http://purl.obolibrary.org")) {
26-
// ontobeeResolver.parse(value)
27-
// }
28-
// }, [value])
24+
const modifiedValue = useMemo(() => {
25+
if (facetConfig.prettyPrintURLs) {
26+
return tryURLPrettyPrint(value)
27+
} else return value
28+
}, [facetConfig.prettyPrintURLs, value])
2929

3030
return (
3131
<div key={value} className="flex max-w-full items-center gap-2 break-words p-1 pb-2">
3232
<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>}
33+
<Label htmlFor={value} className="min-w-0 grow break-words [&:not(:hover)]:truncate">
34+
{value ? (
35+
facetConfig.usePidResolver ? (
36+
<PidDisplay pid={value} />
37+
) : (
38+
modifiedValue
39+
)
40+
) : (
41+
<span className="text-muted-foreground">None</span>
42+
)}
3543
</Label>
3644
<div className="text-xs text-muted-foreground">{option.count}</div>
3745
</div>

src/config/FairDOConfig.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
export interface FairDOCoreFacetConfig {
22
key: string
33
label: string
4+
/**
5+
* Not properly implemented at the moment
6+
*/
47
isFilterable?: boolean
58
usePidResolver?: boolean
9+
prettyPrintURLs?: boolean
610
}
711

812
export interface FairDONumericRangeFacetConfig extends FairDOCoreFacetConfig {
@@ -43,18 +47,10 @@ export interface FairDOIndexConfig {
4347
* Configuration for the {@link FairDOElasticSearch} component
4448
*/
4549
export interface FairDOConfig {
46-
/**
47-
* Unused
48-
*/
49-
logo: string
50-
/**
51-
* Unused
52-
*/
53-
title: string
5450
/**
5551
* Enables debug features. Should be disabled in production
5652
*/
57-
debug: boolean
53+
debug?: boolean
5854
/**
5955
* Directly issue a search query to the elastic endpoint when the component is loaded
6056
*/
@@ -75,7 +71,7 @@ export interface FairDOConfig {
7571
* Disjunctive facets as specified in the elastic search ui documentation
7672
* @link https://www.elastic.co/guide/en/search-ui/current/api-react-components-facet.html#api-react-components-facet-example-of-an-or-based-facet-filter
7773
*/
78-
disjunctiveFacets: string[]
74+
disjunctiveFacets?: string[]
7975

8076
/**
8177
* Specify connection options, like an Authorization header

src/config/FairDOConfigBuilder.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@ export class FairDOConfigBuilder {
5252
return facets
5353
}
5454

55-
getFieldMappings(index: string) {
56-
const indexConfig = this.getConfig().indices.find((c) => c.name === index)
57-
return indexConfig?.fieldMappings
58-
}
59-
6055
getSearchOptions() {
6156
const config = this.getConfig()
6257
const index_names: string[] = []

src/stories/Configure.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Meta } from "@storybook/blocks";
1+
import { Meta } from "@storybook/blocks"
22

33
import "../index.css"
44

0 commit comments

Comments
 (0)