forked from SigNoz/signoz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
useQueryService.ts
33 lines (31 loc) · 984 Bytes
/
useQueryService.ts
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
import getService from 'api/metrics/getService';
import { AxiosError } from 'axios';
import { Time } from 'container/TopNav/DateTimeSelection/config';
import { Time as TimeV2 } from 'container/TopNav/DateTimeSelectionV2/config';
import {
QueryKey,
useQuery,
UseQueryOptions,
UseQueryResult,
} from 'react-query';
import { PayloadProps } from 'types/api/metrics/getService';
import { Tags } from 'types/reducer/trace';
export const useQueryService = ({
minTime,
maxTime,
selectedTime,
selectedTags,
options,
}: UseQueryServiceProps): UseQueryResult<PayloadProps, AxiosError> =>
useQuery<PayloadProps, AxiosError>({
queryFn: () => getService({ end: maxTime, selectedTags, start: minTime }),
queryKey: [minTime, maxTime, selectedTime, selectedTags],
...options,
});
interface UseQueryServiceProps {
minTime: number;
maxTime: number;
selectedTime: Time | TimeV2;
selectedTags: Tags[];
options?: UseQueryOptions<PayloadProps, AxiosError, PayloadProps, QueryKey>;
}