Skip to content

Commit ff7de4d

Browse files
committed
Add tooltips to facets
1 parent b29e0eb commit ff7de4d

File tree

3 files changed

+140
-1
lines changed

3 files changed

+140
-1
lines changed

src/components/search/DefaultFacet.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { ComponentType, useEffect, useMemo, useRef, useState } from "react"
99
import { DefaultFacetOption } from "@/components/search/DefaultFacetOption"
1010
import type { FacetValue } from "@elastic/search-ui"
1111
import type { FairDOFacetConfig } from "@/config/FairDOConfig"
12+
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"
1213

1314
export interface OptionViewProps {
1415
option: FacetValue
@@ -40,7 +41,13 @@ export function DefaultFacet(props: FacetViewProps & { config: FairDOConfigBuild
4041
return (
4142
<div className="rfs-px-4 rfs-pt-0 rfs-pb-8">
4243
<div className="rfs-flex rfs-items-center rfs-justify-between rfs-pb-2">
43-
<div className="rfs-text-sm rfs-font-bold">{props.label}</div>
44+
<Tooltip disableHoverableContent={true} open={selfConfig.description ? undefined : false}>
45+
<TooltipTrigger asChild>
46+
<div className="rfs-text-sm rfs-font-bold">{props.label}</div>
47+
</TooltipTrigger>
48+
<TooltipContent>{selfConfig.description}</TooltipContent>
49+
</Tooltip>
50+
4451
{props.showSearch && (
4552
<Popover>
4653
<PopoverTrigger asChild>

src/config/FairDOConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { RequestState, SearchFieldConfiguration } from "@elastic/search-ui"
33
export interface FairDOCoreFacetConfig {
44
key: string
55
label: string
6+
description?: string
67
/**
78
* Not properly implemented at the moment
89
*/

src/stories/DefaultFacet.stories.tsx

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
import type { Meta, StoryObj } from "@storybook/react"
2+
3+
import { DefaultFacet } from "@/components/search/DefaultFacet"
4+
import { FairDOConfigBuilder } from "@/config/FairDOConfigBuilder"
5+
import { TooltipProvider } from "@/components/ui/tooltip"
6+
import { GlobalModalProvider } from "@/components/GlobalModalProvider"
7+
import { GenericResultView } from "@/components/result"
8+
import type { FairDOConfig } from "@/config/FairDOConfig"
9+
10+
const meta = {
11+
component: DefaultFacet
12+
} satisfies Meta<typeof DefaultFacet>
13+
14+
export default meta
15+
16+
const demoConfig: FairDOConfig = {
17+
debug: false,
18+
alwaysSearchOnInitialLoad: true,
19+
// host: "https://matwerk.datamanager.kit.edu/search-proxy/api/v1",
20+
host: "",
21+
apiKey: "",
22+
indices: [
23+
{
24+
name: "fdo-prod",
25+
facets: [
26+
{ label: "My Facet", key: "facet1" },
27+
{ label: "Pretty URLs", key: "facet2", prettyPrintURLs: true },
28+
{ label: "With Pid Resolver", key: "facet3", usePidResolver: true }
29+
],
30+
resultFields: [], // Leave empty to get all fields
31+
searchFields: []
32+
}
33+
]
34+
}
35+
36+
type Story = StoryObj<typeof meta>
37+
38+
export const Default: Story = {
39+
decorators: [
40+
(Story) => (
41+
<TooltipProvider>
42+
<GlobalModalProvider resultView={GenericResultView}>
43+
<div className="rfs-max-w-60">
44+
<Story />
45+
</div>
46+
</GlobalModalProvider>
47+
</TooltipProvider>
48+
)
49+
],
50+
args: {
51+
label: "My Facet",
52+
onMoreClick: () => {},
53+
onRemove: () => {},
54+
onChange: () => {},
55+
onSelect: () => {},
56+
options: [
57+
{ count: 10, value: "First entry" },
58+
{ count: 20, value: "Second entry" },
59+
{ count: 30, value: "Third entry" },
60+
{ count: 42, value: "Fourth entry" }
61+
],
62+
showMore: false,
63+
values: [],
64+
showSearch: false,
65+
onSearch: () => {},
66+
searchPlaceholder: "",
67+
config: new FairDOConfigBuilder(demoConfig)
68+
}
69+
}
70+
71+
export const PrettyURL: Story = {
72+
decorators: [
73+
(Story) => (
74+
<TooltipProvider>
75+
<GlobalModalProvider resultView={GenericResultView}>
76+
<div className="rfs-max-w-60">
77+
<Story />
78+
</div>
79+
</GlobalModalProvider>
80+
</TooltipProvider>
81+
)
82+
],
83+
args: {
84+
label: "Pretty URLs",
85+
onMoreClick: () => {},
86+
onRemove: () => {},
87+
onChange: () => {},
88+
onSelect: () => {},
89+
options: [
90+
{ count: 10, value: "https://kit.edu/test" },
91+
{ count: 20, value: "https://www.example.org/" }
92+
],
93+
showMore: false,
94+
values: [],
95+
showSearch: false,
96+
onSearch: () => {},
97+
searchPlaceholder: "",
98+
config: new FairDOConfigBuilder(demoConfig)
99+
}
100+
}
101+
102+
export const WithPidResolver: Story = {
103+
decorators: [
104+
(Story) => (
105+
<TooltipProvider>
106+
<GlobalModalProvider resultView={GenericResultView}>
107+
<div className="rfs-max-w-60">
108+
<Story />
109+
</div>
110+
</GlobalModalProvider>
111+
</TooltipProvider>
112+
)
113+
],
114+
args: {
115+
label: "With Pid Resolver",
116+
onMoreClick: () => {},
117+
onRemove: () => {},
118+
onChange: () => {},
119+
onSelect: () => {},
120+
options: [
121+
{ count: 10, value: "21.T11148/010acb220a9c2c8c0ee6" },
122+
{ count: 20, value: "21.T11148/ca9fd0b2414177b79ac2" }
123+
],
124+
showMore: false,
125+
values: [],
126+
showSearch: false,
127+
onSearch: () => {},
128+
searchPlaceholder: "",
129+
config: new FairDOConfigBuilder(demoConfig)
130+
}
131+
}

0 commit comments

Comments
 (0)