-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathRegistrySearch.tsx
More file actions
90 lines (80 loc) · 2.53 KB
/
RegistrySearch.tsx
File metadata and controls
90 lines (80 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import React, { useState } from "react";
import { EuiText, EuiFieldSearch, EuiSpacer } from "@elastic/eui";
import EuiCustomLink from "./EuiCustomLink";
interface RegistrySearchProps {
categories: {
name: string;
data: any[];
getLink: (item: any) => string;
}[];
}
const RegistrySearch: React.FC<RegistrySearchProps> = ({ categories }) => {
const [searchText, setSearchText] = useState("");
const searchResults = categories.map(({ name, data, getLink }) => {
const filteredItems = searchText
? data.filter((item) => {
const itemName =
"name" in item
? String(item.name)
: "spec" in item && item.spec && "name" in item.spec
? String(item.spec.name ?? "Unknown")
: "Unknown";
return itemName.toLowerCase().includes(searchText.toLowerCase());
})
: [];
return { name, items: filteredItems, getLink };
});
return (
<>
<EuiSpacer size="l" />
<EuiText>
<h3>Search in registry</h3>
</EuiText>
<EuiSpacer size="s" />
<EuiFieldSearch
placeholder="Search across Feature Views, Features, Entities, etc."
value={searchText}
onChange={(e) => setSearchText(e.target.value)}
isClearable
fullWidth
/>
<EuiSpacer size="m" />
{searchText && (
<EuiText>
<h3>Search Results</h3>
{searchResults.some(({ items }) => items.length > 0) ? (
searchResults.map(({ name, items, getLink }, index) =>
items.length > 0 ? (
<div key={index}>
<h4>{name}</h4>
<ul>
{items.map((item, idx) => {
const itemName =
"name" in item
? item.name
: "spec" in item
? item.spec?.name
: "Unknown";
const itemLink = getLink(item);
return (
<li key={idx}>
<EuiCustomLink to={itemLink}>
{itemName}
</EuiCustomLink>
</li>
);
})}
</ul>
<EuiSpacer size="m" />
</div>
) : null,
)
) : (
<p>No matches found.</p>
)}
</EuiText>
)}
</>
);
};
export default RegistrySearch;