-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathuseLoadDataSourcesREST.ts
More file actions
41 lines (37 loc) · 961 Bytes
/
Copy pathuseLoadDataSourcesREST.ts
File metadata and controls
41 lines (37 loc) · 961 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
38
39
40
41
import { useQuery } from "react-query";
import { fetchApi } from "./restApi";
interface DataSourceListResponse {
dataSources: any[];
pagination: Record<string, any>;
relationships?: Record<string, any[]>;
}
const useLoadDataSourcesREST = (project: string) => {
return useQuery(
["data-sources-rest", project],
() =>
fetchApi<DataSourceListResponse>("/data_sources", {
project,
allow_cache: "false",
}),
{
enabled: !!project,
staleTime: 30000,
},
);
};
const useLoadDataSourceREST = (name: string, project: string) => {
return useQuery(
["data-source-rest", name, project],
() =>
fetchApi<any>(`/data_sources/${encodeURIComponent(name)}`, {
project,
include_relationships: "true",
allow_cache: "false",
}),
{
enabled: !!name && !!project,
staleTime: 30000,
},
);
};
export { useLoadDataSourcesREST, useLoadDataSourceREST };