mirror of
https://github.com/SigNoz/signoz.git
synced 2025-12-17 15:36:48 +00:00
* feat: changes for the query stats websockets * chore: remove unwanted files * fix: work on random id rather than hash * fix: improve the icons and design * feat: webpack and docker file changes * fix: test cases * chore: format the units * chore: address review comments * chore: update the id to uuid package * fix: build issues * chore: remove docker file changes * chore: remove docker file changes
55 lines
1.5 KiB
TypeScript
55 lines
1.5 KiB
TypeScript
import { PANEL_TYPES } from 'constants/queryBuilder';
|
|
import { REACT_QUERY_KEY } from 'constants/reactQueryKeys';
|
|
import {
|
|
GetMetricQueryRange,
|
|
GetQueryResultsProps,
|
|
} from 'lib/dashboard/getQueryResults';
|
|
import { useMemo } from 'react';
|
|
import { useQuery, UseQueryOptions, UseQueryResult } from 'react-query';
|
|
import { SuccessResponse } from 'types/api';
|
|
import { MetricRangePayloadProps } from 'types/api/metrics/getQueryRange';
|
|
|
|
type UseGetQueryRange = (
|
|
requestData: GetQueryResultsProps,
|
|
version: string,
|
|
options?: UseQueryOptions<SuccessResponse<MetricRangePayloadProps>, Error>,
|
|
headers?: Record<string, string>,
|
|
) => UseQueryResult<SuccessResponse<MetricRangePayloadProps>, Error>;
|
|
|
|
export const useGetQueryRange: UseGetQueryRange = (
|
|
requestData,
|
|
version,
|
|
options,
|
|
headers,
|
|
) => {
|
|
const newRequestData: GetQueryResultsProps = useMemo(
|
|
() => ({
|
|
...requestData,
|
|
graphType:
|
|
requestData.graphType === PANEL_TYPES.BAR
|
|
? PANEL_TYPES.TIME_SERIES
|
|
: requestData.graphType,
|
|
}),
|
|
[requestData],
|
|
);
|
|
|
|
const queryKey = useMemo(() => {
|
|
if (options?.queryKey && Array.isArray(options.queryKey)) {
|
|
return [...options.queryKey];
|
|
}
|
|
|
|
if (options?.queryKey && typeof options.queryKey === 'string') {
|
|
return options.queryKey;
|
|
}
|
|
|
|
return [REACT_QUERY_KEY.GET_QUERY_RANGE, newRequestData];
|
|
}, [options?.queryKey, newRequestData]);
|
|
|
|
return useQuery<SuccessResponse<MetricRangePayloadProps>, Error>({
|
|
queryFn: async ({ signal }) =>
|
|
GetMetricQueryRange(requestData, version, signal, headers),
|
|
...options,
|
|
queryKey,
|
|
});
|
|
};
|