fix: query key is updated (#2894)

This commit is contained in:
Palash Gupta 2023-06-13 16:26:12 +05:30 committed by GitHub
parent a649ced337
commit 148889e198
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 10 deletions

View File

@ -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={
<span style={{ display: 'flex', gap: '1rem', alignItems: 'center' }}>
<Button type="primary" onClick={handleRunQuery}>
<Button type="primary" onClick={runQuery}>
Run Query
</Button>
</span>
@ -95,7 +91,7 @@ function QuerySection({
onChange={handleQueryCategoryChange}
tabBarExtraContent={
<span style={{ display: 'flex', gap: '1rem', alignItems: 'center' }}>
<Button type="primary" onClick={handleRunQuery}>
<Button type="primary" onClick={runQuery}>
Run Query
</Button>
</span>
@ -132,7 +128,7 @@ interface QuerySectionProps {
queryCategory: EQueryType;
setQueryCategory: (n: EQueryType) => void;
alertType: AlertTypes;
runQuery: () => void;
runQuery: VoidFunction;
}
export default QuerySection;

View File

@ -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<SuccessResponse<MetricRangePayloadProps>, Error>,
): UseQueryResult<SuccessResponse<MetricRangePayloadProps>, Error> =>
useQuery<SuccessResponse<MetricRangePayloadProps>, Error>({
queryKey: [REACT_QUERY_KEY.GET_QUERY_RANGE, requestData],
): UseQueryResult<SuccessResponse<MetricRangePayloadProps>, 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<SuccessResponse<MetricRangePayloadProps>, Error>({
queryFn: async () => GetMetricQueryRange(requestData),
...options,
queryKey,
});
};