From 50a88a8726c046cb7c036da77579f40264952175 Mon Sep 17 00:00:00 2001 From: palash-signoz <88981777+palash-signoz@users.noreply.github.com> Date: Wed, 26 Jan 2022 21:46:59 +0530 Subject: [PATCH] BUG: refresh button is now fixed (#590) * chore: issue is fixed * chore: unused import is removed --- .../GridGraphLayout/Graph/FullView/index.tsx | 41 +++++++++++++------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/frontend/src/container/GridGraphLayout/Graph/FullView/index.tsx b/frontend/src/container/GridGraphLayout/Graph/FullView/index.tsx index b2cbc0366d..61aae23128 100644 --- a/frontend/src/container/GridGraphLayout/Graph/FullView/index.tsx +++ b/frontend/src/container/GridGraphLayout/Graph/FullView/index.tsx @@ -9,18 +9,21 @@ import GridGraphComponent from 'container/GridGraphComponent'; import { timeItems, timePreferance, + timePreferenceType, } from 'container/NewWidget/RightContainer/timeItems'; +import convertToNanoSecondsToSecond from 'lib/convertToNanoSecondsToSecond'; import getChartData from 'lib/getChartData'; import GetMaxMinTime from 'lib/getMaxMinTime'; +import GetMinMax from 'lib/getMinMax'; import getStartAndEndTime from 'lib/getStartAndEndTime'; import React, { useCallback, useEffect, useState } from 'react'; import { useSelector } from 'react-redux'; import { AppState } from 'store/reducers'; -import { GlobalTime } from 'types/actions/globalTime'; import { Widgets } from 'types/api/dashboard/getAll'; +import { GlobalReducer } from 'types/reducer/globalTime'; import EmptyGraph from './EmptyGraph'; -import { GraphContainer, NotFoundContainer, TimeContainer } from './styles'; +import { NotFoundContainer, TimeContainer } from './styles'; const FullView = ({ widget, @@ -29,9 +32,10 @@ const FullView = ({ noDataGraph = false, name, }: FullViewProps): JSX.Element => { - const { minTime, maxTime } = useSelector( - (state) => state.globalTime, - ); + const { minTime, maxTime, selectedTime: globalSelectedTime } = useSelector< + AppState, + GlobalReducer + >((state) => state.globalTime); const [state, setState] = useState({ error: false, @@ -59,20 +63,33 @@ const FullView = ({ minTime, }); - const { end, start } = getStartAndEndTime({ - type: selectedTime.enum, - maxTime: maxMinTime.maxTime, - minTime: maxMinTime.minTime, - }); + const getMinMax = (time: timePreferenceType) => { + if (time === 'GLOBAL_TIME') { + const minMax = GetMinMax(globalSelectedTime); + return { + min: convertToNanoSecondsToSecond(minMax.minTime / 1000), + max: convertToNanoSecondsToSecond(minMax.maxTime / 1000), + }; + } + + const minMax = getStartAndEndTime({ + type: selectedTime.enum, + maxTime: maxMinTime.maxTime, + minTime: maxMinTime.minTime, + }); + return { min: parseInt(minMax.start, 10), max: parseInt(minMax.end, 10) }; + }; + + const queryMinMax = getMinMax(selectedTime.enum); const response = await Promise.all( widget.query .filter((e) => e.query.length !== 0) .map(async (query) => { const result = await getQueryResult({ - end, + end: queryMinMax.max.toString(), query: query.query, - start: start, + start: queryMinMax.min.toString(), step: '60', }); return {