Skip to content

Commit ef1a102

Browse files
committed
Click to copy tags and graph error handling
1 parent d1ab714 commit ef1a102

File tree

4 files changed

+41
-17
lines changed

4 files changed

+41
-17
lines changed

package-lock.json

Lines changed: 16 additions & 1 deletion
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
@@ -60,6 +60,7 @@
6060
"swr": "^2.3.0",
6161
"tailwind-merge": "^2.5.5",
6262
"tailwindcss-animate": "^1.0.7",
63+
"usehooks-ts": "^3.1.0",
6364
"zod": "^3.24.1",
6465
"zustand": "^5.0.2"
6566
},

src/components/result/GenericResultView.tsx

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -249,22 +249,27 @@ export function GenericResultView({
249249

250250
const fetchRelatedItems = useCallback(
251251
async (term: string, amount: number) => {
252-
const search = await elasticConnector?.onSearch(
253-
{ searchTerm: term, resultsPerPage: amount + 5 },
254-
{
255-
result_fields: {},
256-
searchTerm: term,
257-
search_fields: relatedItemsPrefetch?.searchFields ?? { [pidField ?? "pid"]: {} },
258-
resultsPerPage: amount
259-
}
260-
)
252+
try {
253+
const search = await elasticConnector?.onSearch(
254+
{ searchTerm: term, resultsPerPage: amount + 5 },
255+
{
256+
result_fields: {},
257+
searchTerm: term,
258+
search_fields: relatedItemsPrefetch?.searchFields ?? { [pidField ?? "pid"]: {} },
259+
resultsPerPage: amount
260+
}
261+
)
261262

262-
if (search) {
263-
for (const entry of search.results) {
264-
const pid = autoUnwrap(entry[pidField ?? "pid"])
265-
if (!pid) continue
266-
addToResultCache(pid, entry)
263+
if (search) {
264+
for (const entry of search.results) {
265+
const pid = autoUnwrap(entry[pidField ?? "pid"])
266+
if (!pid) continue
267+
addToResultCache(pid, entry)
268+
}
267269
}
270+
} catch (e) {
271+
console.warn("Failed to fetch related items", e)
272+
alert("Failed to fetch related items, graph may be incomplete")
268273
}
269274
},
270275
[addToResultCache, elasticConnector, pidField, relatedItemsPrefetch?.searchFields]

src/components/result/GenericResultViewTag.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip
33
import { Badge } from "@/components/ui/badge"
44
import { SearchResult } from "@elastic/search-ui"
55
import { autoUnwrap } from "@/components/result/utils"
6+
import { useCopyToClipboard } from "usehooks-ts"
67

78
export interface GenericResultViewTagProps {
89
field: string
@@ -20,17 +21,19 @@ export function GenericResultViewTag({ field, result, icon, label, valueMapper }
2021
else return value
2122
}, [field, result, valueMapper])
2223

24+
const [_, copy] = useCopyToClipboard()
25+
2326
const base = useCallback(
2427
(value: string) => {
2528
return (
26-
<Badge variant="secondary" className="rfs-truncate">
29+
<Badge variant="secondary" className="rfs-truncate" onClick={() => copy(value)}>
2730
<span className="rfs-flex rfs-truncate">
2831
{icon} {value}
2932
</span>
3033
</Badge>
3134
)
3235
},
33-
[icon]
36+
[copy, icon]
3437
)
3538

3639
if (!label) return base(value)

0 commit comments

Comments
 (0)