signoz/frontend/src/hooks/useQueryService.ts
Yunus M 6eced60bf5
feat: update time range selection flows to handle relative and absolu… (#4742)
* feat: update time range selection flows to handle relative and absolute times

* fix: lint error

* fix: lint error

* feat: update logic to handle custom relative times on load and standardize relative time formats

* fix: type issue

* fix: handle light mode and on custom time range select

* chore: update alert frequency corresponding times

* chore: update copy URL

* feat: update styles
2024-03-29 14:53:48 +05:30

37 lines
1020 B
TypeScript

import getService from 'api/metrics/getService';
import { AxiosError } from 'axios';
import { Time } from 'container/TopNav/DateTimeSelection/config';
import {
CustomTimeType,
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 | CustomTimeType;
selectedTags: Tags[];
options?: UseQueryOptions<PayloadProps, AxiosError, PayloadProps, QueryKey>;
}