diff --git a/frontend/src/container/FormAlertRules/QuerySection.tsx b/frontend/src/container/FormAlertRules/QuerySection.tsx index 07f5be4f3a..b8c88ab683 100644 --- a/frontend/src/container/FormAlertRules/QuerySection.tsx +++ b/frontend/src/container/FormAlertRules/QuerySection.tsx @@ -38,10 +38,6 @@ function QuerySection({ /> ); - const handleRunQuery = (): void => { - runQuery(); - }; - const tabs = [ { label: t('tab_qb'), @@ -76,7 +72,7 @@ function QuerySection({ onChange={handleQueryCategoryChange} tabBarExtraContent={ - @@ -95,7 +91,7 @@ function QuerySection({ onChange={handleQueryCategoryChange} tabBarExtraContent={ - @@ -132,7 +128,7 @@ interface QuerySectionProps { queryCategory: EQueryType; setQueryCategory: (n: EQueryType) => void; alertType: AlertTypes; - runQuery: () => void; + runQuery: VoidFunction; } export default QuerySection; diff --git a/frontend/src/hooks/queryBuilder/useGetQueryRange.ts b/frontend/src/hooks/queryBuilder/useGetQueryRange.ts index dbd35d5ede..7091ffb15b 100644 --- a/frontend/src/hooks/queryBuilder/useGetQueryRange.ts +++ b/frontend/src/hooks/queryBuilder/useGetQueryRange.ts @@ -1,5 +1,7 @@ import { REACT_QUERY_KEY } from 'constants/reactQueryKeys'; +import { useMemo } from 'react'; import { useQuery, UseQueryOptions, UseQueryResult } from 'react-query'; +import { useLocation } from 'react-router-dom'; import { GetMetricQueryRange, GetQueryResultsProps, @@ -10,9 +12,19 @@ import { MetricRangePayloadProps } from 'types/api/metrics/getQueryRange'; export const useGetQueryRange = ( requestData: GetQueryResultsProps, options?: UseQueryOptions, Error>, -): UseQueryResult, Error> => - useQuery, Error>({ - queryKey: [REACT_QUERY_KEY.GET_QUERY_RANGE, requestData], +): UseQueryResult, Error> => { + const { key } = useLocation(); + + const queryKey = useMemo(() => { + if (options?.queryKey) { + return [...options.queryKey, key]; + } + return [REACT_QUERY_KEY.GET_QUERY_RANGE, key, requestData]; + }, [key, options?.queryKey, requestData]); + + return useQuery, Error>({ queryFn: async () => GetMetricQueryRange(requestData), ...options, + queryKey, }); +};