-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathhooks.ts
More file actions
62 lines (54 loc) · 1.74 KB
/
hooks.ts
File metadata and controls
62 lines (54 loc) · 1.74 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
'use client';
import { useTRPC } from '@/lib/trpc/utils';
import { useQuery } from '@tanstack/react-query';
type CloudAgentNextFilters = {
/** Inclusive ISO datetime lower bound for observed-outcome reporting. */
startDate: string;
/** Exclusive ISO datetime upper bound for observed-outcome reporting. */
endDate: string;
};
export type CloudAgentNextHealthFilters = CloudAgentNextFilters & {
bucket: 'hour' | 'day';
createdOnPlatform?: string | null;
};
type CloudAgentNextHealthError = {
source: 'setup' | 'run';
stage: string;
code: string;
};
function enabledForInterval(params: CloudAgentNextFilters) {
return Boolean(params.startDate && params.endDate);
}
export function useCloudAgentNextHealthPlatforms() {
const trpc = useTRPC();
return useQuery(trpc.admin.cloudAgentNext.listHealthPlatforms.queryOptions());
}
export function useCloudAgentNextHealthOverview(
params: CloudAgentNextHealthFilters,
enabled = true
) {
const trpc = useTRPC();
return useQuery({
...trpc.admin.cloudAgentNext.getHealthOverview.queryOptions(params),
enabled: enabled && enabledForInterval(params),
refetchOnReconnect: false,
refetchOnWindowFocus: false,
});
}
export function useCloudAgentNextHealthErrorSessions(
params: CloudAgentNextHealthFilters,
error: CloudAgentNextHealthError | null
) {
const trpc = useTRPC();
return useQuery({
...trpc.admin.cloudAgentNext.listHealthErrorSessions.queryOptions({
startDate: params.startDate,
endDate: params.endDate,
source: error?.source ?? 'run',
stage: error?.stage ?? 'not-selected',
code: error?.code ?? 'not-selected',
createdOnPlatform: params.createdOnPlatform,
}),
enabled: enabledForInterval(params) && Boolean(error),
});
}