From cc193f6665f0f6a87846cd15016346f030a32545 Mon Sep 17 00:00:00 2001 From: Adam Tackett <105462877+TackAdam@users.noreply.github.com> Date: Thu, 20 Jun 2024 11:42:51 -0700 Subject: [PATCH] [Bug fix] Trace analytics scroll bar reset (#1917) * Bugfix: Remember scroll bar position on opening flyout. Signed-off-by: Adam Tackett * Memorize the gnatt chart, fixes flicker Signed-off-by: Adam Tackett * useCallback added to click actions Signed-off-by: Adam Tackett --------- Signed-off-by: Adam Tackett Co-authored-by: Adam Tackett --- .../components/traces/span_detail_panel.tsx | 56 ++++++++++--------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/public/components/trace_analytics/components/traces/span_detail_panel.tsx b/public/components/trace_analytics/components/traces/span_detail_panel.tsx index 8a851a79f..dedbd58aa 100644 --- a/public/components/trace_analytics/components/traces/span_detail_panel.tsx +++ b/public/components/trace_analytics/components/traces/span_detail_panel.tsx @@ -15,7 +15,7 @@ import { } from '@elastic/eui'; import debounce from 'lodash/debounce'; import isEmpty from 'lodash/isEmpty'; -import React, { useEffect, useMemo, useState } from 'react'; +import React, { useCallback, useEffect, useMemo, useState } from 'react'; import { HttpSetup } from '../../../../../../../src/core/public'; import { Plt } from '../../../visualizations/plotly/plot'; import { TraceAnalyticsMode } from '../../home'; @@ -187,15 +187,18 @@ export function SpanDetailPanel(props: { const [currentSpan, setCurrentSpan] = useState(''); - const onClick = (event: any) => { - if (!event?.points) return; - const point = event.points[0]; - if (fromApp) { - props.openSpanFlyout(point.data.spanId); - } else { - setCurrentSpan(point.data.spanId); - } - }; + const onClick = useCallback( + (event: any) => { + if (!event?.points) return; + const point = event.points[0]; + if (fromApp) { + props.openSpanFlyout(point.data.spanId); + } else { + setCurrentSpan(point.data.spanId); + } + }, + [props.openSpanFlyout, setCurrentSpan, fromApp] + ); const renderFilters = useMemo(() => { return spanFilters.map(({ field, value }) => ( @@ -212,15 +215,15 @@ export function SpanDetailPanel(props: { )); }, [spanFilters]); - const onHover = () => { + const onHover = useCallback(() => { const dragLayer = document.getElementsByClassName('nsewdrag')?.[0]; dragLayer.style.cursor = 'pointer'; - }; + }, []); - const onUnhover = () => { + const onUnhover = useCallback(() => { const dragLayer = document.getElementsByClassName('nsewdrag')?.[0]; dragLayer.style.cursor = ''; - }; + }, []); const toggleOptions = [ { @@ -254,6 +257,19 @@ export function SpanDetailPanel(props: { [DSL, setCurrentSpan] ); + const ganttChart = useMemo( + () => ( + + ), + [data.gantt, layout, onClick, onHover, onUnhover] + ); + return ( <> @@ -280,17 +296,7 @@ export function SpanDetailPanel(props: { )}
- {toggleIdSelected === 'timeline' ? ( - - ) : ( - spanDetailTable - )} + {toggleIdSelected === 'timeline' ? ganttChart : spanDetailTable}
{!!currentSpan && (