diff --git a/frontend/src/container/NewWidget/index.tsx b/frontend/src/container/NewWidget/index.tsx index 5044c63269..f2067c1bd0 100644 --- a/frontend/src/container/NewWidget/index.tsx +++ b/frontend/src/container/NewWidget/index.tsx @@ -21,6 +21,7 @@ import { AppState } from 'store/reducers'; import AppActions from 'types/actions'; import { GlobalTime } from 'types/actions/globalTime'; import DashboardReducer from 'types/reducer/dashboards'; +import { GlobalReducer } from 'types/reducer/globalTime'; import LeftContainer from './LeftContainer'; import RightContainer from './RightContainer'; @@ -42,9 +43,10 @@ const NewWidget = ({ const { dashboards } = useSelector( (state) => state.dashboards, ); - const { maxTime, minTime } = useSelector( - (state) => state.globalTime, - ); + const { maxTime, minTime, selectedTime: globalSelectedInterval } = useSelector< + AppState, + GlobalReducer + >((state) => state.globalTime); const [selectedDashboard] = dashboards; @@ -146,12 +148,11 @@ const NewWidget = ({ const getQueryResult = useCallback(() => { if (selectedWidget?.id.length !== 0) { getQueryResults({ - maxTime, - minTime, query: selectedWidget?.query || [], selectedTime: selectedTime.enum, widgetId: selectedWidget?.id || '', graphType: selectedGraph, + globalSelectedInterval, }); } }, [ diff --git a/frontend/src/store/actions/dashboard/getQueryResults.ts b/frontend/src/store/actions/dashboard/getQueryResults.ts index 90a74b84f1..b779a665d2 100644 --- a/frontend/src/store/actions/dashboard/getQueryResults.ts +++ b/frontend/src/store/actions/dashboard/getQueryResults.ts @@ -3,10 +3,13 @@ import { AxiosError } from 'axios'; import { ITEMS } from 'container/NewDashboard/ComponentsSlider/menuItems'; import { timePreferenceType } from 'container/NewWidget/RightContainer/timeItems'; import GetMaxMinTime from 'lib/getMaxMinTime'; +import GetMinMax from 'lib/getMinMax'; import GetStartAndEndTime from 'lib/getStartAndEndTime'; import { Dispatch } from 'redux'; import AppActions from 'types/actions'; import { Query } from 'types/api/dashboard/getAll'; +import { GlobalReducer } from 'types/reducer/globalTime'; +import store from 'store'; export const GetQueryResults = ( props: GetQueryResultsProps, @@ -15,10 +18,17 @@ export const GetQueryResults = ( try { const queryData = props.query; + const { globalTime } = store.getState(); + + const minMax = GetMinMax(props.globalSelectedInterval, [ + globalTime.minTime / 1000000, + globalTime.maxTime / 1000000, + ]); + const getMaxMinTime = GetMaxMinTime({ graphType: props.graphType, - maxTime: props.maxTime, - minTime: props.minTime, + maxTime: minMax.maxTime, + minTime: minMax.minTime, }); const { end, start } = GetStartAndEndTime({ @@ -92,8 +102,7 @@ export const GetQueryResults = ( export interface GetQueryResultsProps { widgetId: string; selectedTime: timePreferenceType; - maxTime: number; - minTime: number; query: Query[]; graphType: ITEMS; + globalSelectedInterval: GlobalReducer['selectedTime']; }