-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathIndex.tsx
More file actions
112 lines (98 loc) · 3.16 KB
/
Index.tsx
File metadata and controls
112 lines (98 loc) · 3.16 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
import React, { useContext } from "react";
import { useParams } from "react-router-dom";
import {
EuiPageTemplate,
EuiLoadingSpinner,
EuiFlexGroup,
EuiFlexItem,
EuiTitle,
EuiFieldSearch,
EuiSpacer,
} from "@elastic/eui";
import useLoadRegistry from "../../queries/useLoadRegistry";
import DatasourcesListingTable from "./DataSourcesListingTable";
import { useDocumentTitle } from "../../hooks/useDocumentTitle";
import RegistryPathContext from "../../contexts/RegistryPathContext";
import DataSourceIndexEmptyState from "./DataSourceIndexEmptyState";
import { DataSourceIcon } from "../../graphics/DataSourceIcon";
import { useSearchQuery } from "../../hooks/useSearchInputWithTags";
import { feast } from "../../protos";
import ExportButton from "../../components/ExportButton";
const useLoadDatasources = () => {
const registryUrl = useContext(RegistryPathContext);
const { projectName } = useParams();
const registryQuery = useLoadRegistry(registryUrl, projectName);
const data =
registryQuery.data === undefined
? undefined
: registryQuery.data.objects.dataSources;
return {
...registryQuery,
data,
};
};
const filterFn = (data: feast.core.IDataSource[], searchTokens: string[]) => {
let filteredByTags = data;
if (searchTokens.length) {
return filteredByTags.filter((entry) => {
return searchTokens.find((token) => {
return (
token.length >= 3 && entry.name && entry.name.indexOf(token) >= 0
);
});
});
}
return filteredByTags;
};
const Index = () => {
const { isLoading, isSuccess, isError, data } = useLoadDatasources();
useDocumentTitle(`Data Sources | Feast`);
const { searchString, searchTokens, setSearchString } = useSearchQuery();
const filterResult = data ? filterFn(data, searchTokens) : data;
return (
<EuiPageTemplate panelled>
<EuiPageTemplate.Header
restrictWidth
iconType={DataSourceIcon}
pageTitle="Data Sources"
rightSideItems={[
<ExportButton
data={filterResult ?? []}
fileName="data_sources"
formats={["json"]}
/>,
]}
/>
<EuiPageTemplate.Section>
{isLoading && (
<p>
<EuiLoadingSpinner size="m" /> Loading
</p>
)}
{isError && <p>We encountered an error while loading.</p>}
{isSuccess && !data && <DataSourceIndexEmptyState />}
{isSuccess && data && data.length > 0 && 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>
</EuiFlexGroup>
<EuiSpacer size="m" />
<DatasourcesListingTable dataSources={filterResult} />
</React.Fragment>
)}
</EuiPageTemplate.Section>
</EuiPageTemplate>
);
};
export default Index;