-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathuseLoadDataSource.ts
More file actions
37 lines (32 loc) · 1.15 KB
/
useLoadDataSource.ts
File metadata and controls
37 lines (32 loc) · 1.15 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
import { useContext } from "react";
import { useParams } from "react-router-dom";
import RegistryPathContext from "../../contexts/RegistryPathContext";
import { FEAST_FCO_TYPES } from "../../parsers/types";
import useLoadRegistry from "../../queries/useLoadRegistry";
const useLoadDataSource = (dataSourceName: string) => {
const registryUrl = useContext(RegistryPathContext);
const { projectName } = useParams();
const registryQuery = useLoadRegistry(registryUrl, projectName);
const data =
registryQuery.data === undefined
? undefined
: registryQuery.data.objects.dataSources?.find(
(ds) => ds.name === dataSourceName,
);
const consumingFeatureViews =
registryQuery.data === undefined
? undefined
: registryQuery.data.relationships.filter((relationship) => {
return (
relationship.source.type === FEAST_FCO_TYPES.dataSource &&
relationship.source.name === data?.name &&
relationship.target.type === FEAST_FCO_TYPES.featureView
);
});
return {
...registryQuery,
data,
consumingFeatureViews,
};
};
export default useLoadDataSource;