-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathIndex.tsx
More file actions
176 lines (157 loc) · 4.97 KB
/
Index.tsx
File metadata and controls
176 lines (157 loc) · 4.97 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import React, { useContext } from "react";
import { useParams } from "react-router-dom";
import {
EuiPageTemplate,
EuiLoadingSpinner,
EuiTitle,
EuiSpacer,
EuiFlexGroup,
EuiFlexItem,
EuiFieldSearch,
} from "@elastic/eui";
import { FeatureServiceIcon } from "../../graphics/FeatureServiceIcon";
import useLoadRegistry from "../../queries/useLoadRegistry";
import FeatureServiceListingTable from "./FeatureServiceListingTable";
import {
useSearchQuery,
useTagsWithSuggestions,
filterInputInterface,
tagTokenGroupsType,
} from "../../hooks/useSearchInputWithTags";
import { useDocumentTitle } from "../../hooks/useDocumentTitle";
import RegistryPathContext from "../../contexts/RegistryPathContext";
import FeatureServiceIndexEmptyState from "./FeatureServiceIndexEmptyState";
import TagSearch from "../../components/TagSearch";
import ExportButton from "../../components/ExportButton";
import { useFeatureServiceTagsAggregation } from "../../hooks/useTagsAggregation";
import { feast } from "../../protos";
const useLoadFeatureServices = () => {
const registryUrl = useContext(RegistryPathContext);
const { projectName } = useParams();
const registryQuery = useLoadRegistry(registryUrl, projectName);
const data =
registryQuery.data === undefined
? undefined
: registryQuery.data.objects.featureServices;
return {
...registryQuery,
data,
};
};
const shouldIncludeFSsGivenTokenGroups = (
entry: feast.core.IFeatureService,
tagTokenGroups: tagTokenGroupsType,
) => {
return Object.entries(tagTokenGroups).every(([key, values]) => {
const entryTagValue = entry?.spec?.tags ? entry.spec.tags[key] : undefined;
if (entryTagValue) {
return values.every((value) => {
return value.length > 0 ? entryTagValue.indexOf(value) >= 0 : true; // Don't filter if the string is empty
});
} else {
return false;
}
});
};
const filterFn = (
data: feast.core.IFeatureService[],
filterInput: filterInputInterface,
) => {
let filteredByTags = data;
if (Object.keys(filterInput.tagTokenGroups).length) {
filteredByTags = data.filter((entry) => {
return shouldIncludeFSsGivenTokenGroups(
entry,
filterInput.tagTokenGroups,
);
});
}
if (filterInput.searchTokens.length) {
return filteredByTags.filter((entry) => {
return filterInput.searchTokens.find((token) => {
return token.length >= 3 && entry?.spec?.name?.indexOf(token)! >= 0;
});
});
}
return filteredByTags;
};
const Index = () => {
const { isLoading, isSuccess, isError, data } = useLoadFeatureServices();
const tagAggregationQuery = useFeatureServiceTagsAggregation();
useDocumentTitle(`Feature Services | Feast`);
const { searchString, searchTokens, setSearchString } = useSearchQuery();
const {
currentTag,
tagsString,
tagTokenGroups,
tagKeysSet,
tagSuggestions,
suggestionMode,
setTagsString,
acceptSuggestion,
setCursorPosition,
} = useTagsWithSuggestions(tagAggregationQuery.data);
const filterResult = data
? filterFn(data, { tagTokenGroups, searchTokens })
: data;
return (
<EuiPageTemplate panelled>
<EuiPageTemplate.Header
restrictWidth
iconType={FeatureServiceIcon}
pageTitle="Feature Services"
rightSideItems={[
<ExportButton
data={filterResult ?? []}
fileName="feature_services"
formats={["json"]}
/>,
]}
/>
<EuiPageTemplate.Section>
{isLoading && (
<p>
<EuiLoadingSpinner size="m" /> Loading
</p>
)}
{isError && <p>We encountered an error while loading.</p>}
{isSuccess && !data && <FeatureServiceIndexEmptyState />}
{isSuccess && filterResult && (
<React.Fragment>
<EuiFlexGroup>
<EuiFlexItem grow={2}>
<EuiTitle size="xs">
<h2>Search</h2>
</EuiTitle>
<EuiFieldSearch
value={searchString}
fullWidth={true}
onChange={(e) => {
setSearchString(e.target.value);
}}
/>
</EuiFlexItem>
<EuiFlexItem grow={3}>
<TagSearch
currentTag={currentTag}
tagsString={tagsString}
setTagsString={setTagsString}
acceptSuggestion={acceptSuggestion}
tagSuggestions={tagSuggestions}
suggestionMode={suggestionMode}
setCursorPosition={setCursorPosition}
/>
</EuiFlexItem>
</EuiFlexGroup>
<EuiSpacer size="m" />
<FeatureServiceListingTable
featureServices={filterResult}
tagKeysSet={tagKeysSet}
/>
</React.Fragment>
)}
</EuiPageTemplate.Section>
</EuiPageTemplate>
);
};
export default Index;