Skip to content

Commit

Permalink
[Bug fix] Trace analytics scroll bar reset (opensearch-project#1917)
Browse files Browse the repository at this point in the history
* Bugfix: Remember scroll bar position on opening flyout.

Signed-off-by: Adam Tackett <[email protected]>

* Memorize the gnatt chart, fixes flicker

Signed-off-by: Adam Tackett <[email protected]>

* useCallback added to click actions

Signed-off-by: Adam Tackett <[email protected]>

---------

Signed-off-by: Adam Tackett <[email protected]>
Co-authored-by: Adam Tackett <[email protected]>
  • Loading branch information
TackAdam and Adam Tackett authored Jun 20, 2024
1 parent 3da9814 commit cc193f6
Showing 1 changed file with 31 additions and 25 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, { useCallback, useEffect, useMemo, useState } from 'react';
import { HttpSetup } from '../../../../../../../src/core/public';
import { Plt } from '../../../visualizations/plotly/plot';
import { TraceAnalyticsMode } from '../../home';
Expand Down Expand Up @@ -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 }) => (
Expand All @@ -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 = [
{
Expand Down Expand Up @@ -254,6 +257,19 @@ export function SpanDetailPanel(props: {
[DSL, setCurrentSpan]
);

const ganttChart = useMemo(
() => (
<Plt
data={data.gantt}
layout={layout}
onClickHandler={onClick}
onHoverHandler={onHover}
onUnhoverHandler={onUnhover}
/>
),
[data.gantt, layout, onClick, onHover, onUnhover]
);

return (
<>
<EuiPanel data-test-subj="span-gantt-chart-panel">
Expand All @@ -280,17 +296,7 @@ export function SpanDetailPanel(props: {
)}
<EuiHorizontalRule margin="m" />
<div style={{ overflowY: 'auto', maxHeight: 500 }}>
{toggleIdSelected === 'timeline' ? (
<Plt
data={data.gantt}
layout={layout}
onClickHandler={onClick}
onHoverHandler={onHover}
onUnhoverHandler={onUnhover}
/>
) : (
spanDetailTable
)}
{toggleIdSelected === 'timeline' ? ganttChart : spanDetailTable}
</div>
</EuiPanel>
{!!currentSpan && (
Expand Down

0 comments on commit cc193f6

Please sign in to comment.