diff --git a/Dashboard/src/Components/Form/Monitor/MetricMonitor/MetricMonitorStepForm.tsx b/Dashboard/src/Components/Form/Monitor/MetricMonitor/MetricMonitorStepForm.tsx index 4d56f518a7..f4438b7f7e 100644 --- a/Dashboard/src/Components/Form/Monitor/MetricMonitor/MetricMonitorStepForm.tsx +++ b/Dashboard/src/Components/Form/Monitor/MetricMonitor/MetricMonitorStepForm.tsx @@ -1,7 +1,7 @@ import MonitorStepMetricMonitor, { MonitorStepMetricMonitorUtil, } from "Common/Types/Monitor/MonitorStepMetricMonitor"; -import React, { FunctionComponent, ReactElement } from "react"; +import React, { FunctionComponent, ReactElement, useEffect } from "react"; import MetricView from "../../../Metrics/MetricView"; import RollingTime from "Common/Types/RollingTime/RollingTime"; import InBetween from "Common/Types/BaseDatabase/InBetween"; @@ -21,10 +21,24 @@ const MetricMonitorStepForm: FunctionComponent = ( const monitorStepMetricMonitor: MonitorStepMetricMonitor = props.monitorStepMetricMonitor || MonitorStepMetricMonitorUtil.getDefault(); - const startAndEndDate: InBetween = - RollingTimeUtil.convertToStartAndEndDate( - monitorStepMetricMonitor.rollingTime || RollingTime.Past1Minute, + const [startAndEndTime, setStartAndEndTime] = + React.useState | null>(null); + + useEffect(() => { + setStartAndEndTime( + RollingTimeUtil.convertToStartAndEndDate( + monitorStepMetricMonitor.rollingTime || RollingTime.Past1Minute, + ), + ); + }, [monitorStepMetricMonitor.rollingTime]); + + useEffect(() => { + setStartAndEndTime( + RollingTimeUtil.convertToStartAndEndDate( + monitorStepMetricMonitor.rollingTime || RollingTime.Past1Minute, + ), ); + }, []); return (
@@ -56,7 +70,7 @@ const MetricMonitorStepForm: FunctionComponent = ( = ( [], ); + const metricViewDataRef: React.MutableRefObject = + React.useRef(props.data); + useEffect(() => { loadAllMetricsTypes().catch((err: Error) => { setPageError(API.getFriendlyErrorMessage(err as Error)); @@ -103,7 +107,13 @@ const MetricView: FunctionComponent = ( }, []); useEffect(() => { + const hasChanged: boolean = JSONFunctions.isJSONObjectDifferent( + metricViewDataRef.current, + props.data, + ); + if ( + hasChanged && props.data && props.data.startAndEndDate && props.data.startAndEndDate.startValue && @@ -115,6 +125,8 @@ const MetricView: FunctionComponent = ( fetchAggregatedResults().catch((err: Error) => { setMetricResultsError(API.getFriendlyErrorMessage(err as Error)); }); + + metricViewDataRef.current = props.data; } }, [props.data]);