-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathuseLoadDataSource.ts
More file actions
37 lines (31 loc) · 1001 Bytes
/
Copy pathuseLoadDataSource.ts
File metadata and controls
37 lines (31 loc) · 1001 Bytes
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 { useParams } from "react-router-dom";
import useResourceQuery, {
dataSourceDetailPath,
} from "../../queries/useResourceQuery";
const useLoadDataSource = (dataSourceName: string) => {
const { projectName } = useParams();
const dsQuery = useResourceQuery<any>({
resourceType: `data-source:${dataSourceName}`,
project: projectName,
restPath: dataSourceDetailPath(dataSourceName, projectName || ""),
restSelect: (d) => ({
dataSource: d,
relationships: d?.relationships || [],
}),
enabled: !!dataSourceName,
});
const dataSource = dsQuery.data?.dataSource;
const relationships = dsQuery.data?.relationships || [];
const consumingFeatureViews = relationships.filter(
(rel: any) =>
rel?.source?.type === "dataSource" &&
(rel?.target?.type === "featureView" ||
rel?.target?.type === "labelView"),
);
return {
...dsQuery,
data: dataSource,
consumingFeatureViews,
};
};
export default useLoadDataSource;