Skip to content

Commit

Permalink
fix: added time range key for query and local storage handling
Browse files Browse the repository at this point in the history
  • Loading branch information
vikrantgupta25 committed Sep 18, 2024
1 parent 0077714 commit ee5e7c8
Showing 1 changed file with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable sonarjs/cognitive-complexity */
/* eslint-disable jsx-a11y/click-events-have-key-events */
/* eslint-disable jsx-a11y/no-static-element-interactions */
/* eslint-disable @typescript-eslint/no-explicit-any */
Expand Down Expand Up @@ -25,8 +26,11 @@ import { debounce, isArray, isString } from 'lodash-es';
import map from 'lodash-es/map';
import { ChangeEvent, memo, useEffect, useMemo, useState } from 'react';
import { useQuery } from 'react-query';
import { useSelector } from 'react-redux';
import { AppState } from 'store/reducers';
import { IDashboardVariable } from 'types/api/dashboard/getAll';
import { VariableResponseProps } from 'types/api/dashboard/variables/query';
import { GlobalReducer } from 'types/reducer/globalTime';
import { popupContainer } from 'utils/selectPopupContainer';

import { variablePropsToPayloadVariables } from '../utils';
Expand Down Expand Up @@ -80,6 +84,10 @@ function VariableItem({
[],
);

const { maxTime, minTime } = useSelector<AppState, GlobalReducer>(
(state) => state.globalTime,
);

const [errorMessage, setErrorMessage] = useState<null | string>(null);

const getDependentVariables = (queryValue: string): string[] => {
Expand Down Expand Up @@ -111,7 +119,14 @@ function VariableItem({

const variableKey = dependentVariablesStr.replace(/\s/g, '');

return [REACT_QUERY_KEY.DASHBOARD_BY_ID, variableName, variableKey];
// added this time dependency for variables query as API respects the passed time range now
return [
REACT_QUERY_KEY.DASHBOARD_BY_ID,
variableName,
variableKey,
`${minTime}`,
`${maxTime}`,
];
};

// eslint-disable-next-line sonarjs/cognitive-complexity
Expand Down Expand Up @@ -151,10 +166,14 @@ function VariableItem({
valueNotInList = true;
}
}
// variablesData.allSelected is added for the case where on change of options we need to update the
// local storage
if (
variableData.type === 'QUERY' &&
variableData.name &&
(variablesToGetUpdated.includes(variableData.name) || valueNotInList)
(variablesToGetUpdated.includes(variableData.name) ||
valueNotInList ||
variableData.allSelected)
) {
let value = variableData.selectedValue;
let allSelected = false;
Expand Down

0 comments on commit ee5e7c8

Please sign in to comment.