diff --git a/web/frontend/src/components/Run/RunningStatus/EndpointCharts/RunEndpointCharts.js b/web/frontend/src/components/Run/RunningStatus/EndpointCharts/RunEndpointCharts.js index b0a2f379..53c7dd27 100644 --- a/web/frontend/src/components/Run/RunningStatus/EndpointCharts/RunEndpointCharts.js +++ b/web/frontend/src/components/Run/RunningStatus/EndpointCharts/RunEndpointCharts.js @@ -14,45 +14,36 @@ import { import { orderBy } from "lodash"; import React, { useEffect, useState } from "react"; -import { fetchMetrics } from "../../../../lib/api/endpoints/runMetric"; import PageSpinner from "../../../layout/PageSpinner"; import HitsErrorsLabelLine from "./HitsErrorsLabelLine"; -const RunEndpointsCharts = ({ run, labelToShowGraph }) => { - const defaultTimeInterval = 5; - const showLabels = true; +const RunEndpointsCharts = ({ + run, + metrics, + isLoading, + labelToShowGraph, + setTimeInterval +}) => { const [runMetrics, setRunMetrics] = useState([]); const [copyRunMetrics, setCopyRunMetrics] = useState([]); const [labelsToShow, setLabelsToShow] = useState([labelToShowGraph]); - const [timeInterval, setTimeInterval] = useState(defaultTimeInterval); - const [isLoading, setIsLoading] = useState(false); const [excludedPrefix, setExcludedPrefix] = useState("UJ"); const [excludedPrefixes, setExcludedPrefixes] = useState([]); + const [currentTimeInterval, setCurrentTimeInterval] = useState(5); - const updateRunMetrics = async (runIdToFetch) => { - setIsLoading(true); - const metrics = await fetchMetrics(runIdToFetch, timeInterval, showLabels); - + useEffect(() => { setRunMetrics(metrics); setCopyRunMetrics(metrics); - setIsLoading(false); - }; - - useEffect(() => { - updateRunMetrics(run.id); // eslint-disable-next-line react-hooks/exhaustive-deps - }, [run]); + }, [metrics]); const refreshChart = async () => { - let metrics = []; if (run.runStatus === "RUNNING") { - metrics = await fetchMetrics(run.id, timeInterval, showLabels); + setRunMetrics(metrics); } else { - metrics = copyRunMetrics; + setRunMetrics(copyRunMetrics); setExcludedPrefixes([]); } - - setRunMetrics(metrics); }; const labels = orderBy( @@ -112,6 +103,10 @@ const RunEndpointsCharts = ({ run, labelToShowGraph }) => { setLabelsToShow([]); }; + const handleOnTimeIntervalChange = (value) => { + setTimeInterval(value); + setCurrentTimeInterval(value); + }; return (