From 40aed585c8d03d48b94beb4c95bdb535f202e302 Mon Sep 17 00:00:00 2001 From: Giordano Ricci Date: Wed, 4 Oct 2023 08:48:44 +0100 Subject: [PATCH] Explore: decouple ExploreGraph and GraphContainer series limit implementation (#75806) * Explore: decouple ExploreGraph and GraphContainer series limit implementation * slice data up --- .../features/explore/Graph/ExploreGraph.tsx | 8 ++----- .../features/explore/Graph/GraphContainer.tsx | 21 ++++++++++++------- .../features/explore/Logs/LogsVolumePanel.tsx | 1 - 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/public/app/features/explore/Graph/ExploreGraph.tsx b/public/app/features/explore/Graph/ExploreGraph.tsx index 159e9726841..ec0ccb3e8c4 100644 --- a/public/app/features/explore/Graph/ExploreGraph.tsx +++ b/public/app/features/explore/Graph/ExploreGraph.tsx @@ -37,8 +37,6 @@ import { useExploreDataLinkPostProcessor } from '../hooks/useExploreDataLinkPost import { applyGraphStyle, applyThresholdsConfig } from './exploreGraphStyleUtils'; import { useStructureRev } from './useStructureRev'; -export const MAX_NUMBER_OF_TIME_SERIES = 20; - interface Props { data: DataFrame[]; height: number; @@ -57,7 +55,6 @@ interface Props { thresholdsConfig?: ThresholdsConfig; thresholdsStyle?: GraphThresholdsStyleConfig; eventBus: EventBus; - showAllTimeSeries: boolean; } export function ExploreGraph({ @@ -78,7 +75,6 @@ export function ExploreGraph({ thresholdsConfig, thresholdsStyle, eventBus, - showAllTimeSeries, }: Props) { const theme = useTheme2(); @@ -125,14 +121,14 @@ export function ExploreGraph({ const dataWithConfig = useMemo(() => { return applyFieldOverrides({ fieldConfig: styledFieldConfig, - data: showAllTimeSeries ? data : data.slice(0, MAX_NUMBER_OF_TIME_SERIES), + data, timeZone, replaceVariables: (value) => value, // We don't need proper replace here as it is only used in getLinks and we use getFieldLinks theme, fieldConfigRegistry, dataLinkPostProcessor, }); - }, [fieldConfigRegistry, data, timeZone, theme, styledFieldConfig, showAllTimeSeries, dataLinkPostProcessor]); + }, [fieldConfigRegistry, data, timeZone, theme, styledFieldConfig, dataLinkPostProcessor]); const annotationsWithConfig = useMemo(() => { return applyFieldOverrides({ diff --git a/public/app/features/explore/Graph/GraphContainer.tsx b/public/app/features/explore/Graph/GraphContainer.tsx index 41fc092c1d8..52f42c51ab4 100644 --- a/public/app/features/explore/Graph/GraphContainer.tsx +++ b/public/app/features/explore/Graph/GraphContainer.tsx @@ -1,5 +1,6 @@ import { css } from '@emotion/css'; -import React, { useCallback, useState } from 'react'; +import React, { useCallback, useMemo, useState } from 'react'; +import { useToggle } from 'react-use'; import { DataFrame, @@ -24,10 +25,12 @@ import { ExploreGraphStyle } from 'app/types'; import { storeGraphStyle } from '../state/utils'; -import { ExploreGraph, MAX_NUMBER_OF_TIME_SERIES } from './ExploreGraph'; +import { ExploreGraph } from './ExploreGraph'; import { ExploreGraphLabel } from './ExploreGraphLabel'; import { loadGraphStyle } from './utils'; +const MAX_NUMBER_OF_TIME_SERIES = 20; + interface Props extends Pick { width: number; height: number; @@ -58,7 +61,7 @@ export const GraphContainer = ({ loadingState, statusMessage, }: Props) => { - const [showAllTimeSeries, setShowAllTimeSeries] = useState(false); + const [showAllSeries, toggleShowAllSeries] = useToggle(false); const [graphStyle, setGraphStyle] = useState(loadGraphStyle); const styles = useStyles2(getStyles); @@ -67,16 +70,21 @@ export const GraphContainer = ({ setGraphStyle(graphStyle); }, []); + const slicedData = useMemo(() => { + return showAllSeries ? data : data.slice(0, MAX_NUMBER_OF_TIME_SERIES); + }, [data, showAllSeries]); + return ( - @@ -91,7 +99,7 @@ export const GraphContainer = ({ {(innerWidth, innerHeight) => ( )} diff --git a/public/app/features/explore/Logs/LogsVolumePanel.tsx b/public/app/features/explore/Logs/LogsVolumePanel.tsx index 600d19ba245..cd31dcce517 100644 --- a/public/app/features/explore/Logs/LogsVolumePanel.tsx +++ b/public/app/features/explore/Logs/LogsVolumePanel.tsx @@ -80,7 +80,6 @@ export function LogsVolumePanel(props: Props) { anchorToZero yAxisMaximum={allLogsVolumeMaximum} eventBus={props.eventBus} - showAllTimeSeries /> {extraInfoComponent &&
{extraInfoComponent}
}