Skip to content

Commit

Permalink
Bugfix: Remember scroll bar position on opening flyout.
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Tackett <[email protected]>
  • Loading branch information
Adam Tackett committed Jun 19, 2024
1 parent 3da9814 commit 4fa3705
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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, { useEffect, useMemo, useRef, useState } from 'react';
import { HttpSetup } from '../../../../../../../src/core/public';
import { Plt } from '../../../visualizations/plotly/plot';
import { TraceAnalyticsMode } from '../../home';
Expand Down Expand Up @@ -187,14 +187,27 @@ export function SpanDetailPanel(props: {

const [currentSpan, setCurrentSpan] = useState('');

const spanContainerRef = useRef<HTMLDivElement | null>(null);
const prevScrollPositionRef = useRef<number | null>(null);

useEffect(() => {
if (spanContainerRef.current) {
setTimeout(() => {
spanContainerRef.current.scrollTop = prevScrollPositionRef.current || 0;
}, 0);
}
}, [currentSpan]);

const onClick = (event: any) => {
const currentScrollPosition = spanContainerRef.current?.scrollTop || 0;
if (!event?.points) return;
const point = event.points[0];
if (fromApp) {
props.openSpanFlyout(point.data.spanId);
} else {
setCurrentSpan(point.data.spanId);
}
prevScrollPositionRef.current = currentScrollPosition;
};

const renderFilters = useMemo(() => {
Expand Down Expand Up @@ -279,7 +292,7 @@ export function SpanDetailPanel(props: {
</>
)}
<EuiHorizontalRule margin="m" />
<div style={{ overflowY: 'auto', maxHeight: 500 }}>
<div style={{ overflowY: 'auto', maxHeight: 500 }} ref={spanContainerRef}>
{toggleIdSelected === 'timeline' ? (
<Plt
data={data.gantt}
Expand Down

0 comments on commit 4fa3705

Please sign in to comment.