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 <tackadam@amazon.com>

* Memorize the gnatt chart, fixes flicker

Signed-off-by: Adam Tackett <tackadam@amazon.com>

* useCallback added to click actions

Signed-off-by: Adam Tackett <tackadam@amazon.com>

---------

Signed-off-by: Adam Tackett <tackadam@amazon.com>
Co-authored-by: Adam Tackett <tackadam@amazon.com>
(cherry picked from commit cc193f6)
Signed-off-by: Adam Tackett <tackadam@amazon.com>
  • Loading branch information
TackAdam and Adam Tackett committed Jun 20, 2024
1 parent b209721 commit a3da30f
Showing 1 changed file with 33 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import {
EuiPanel,
EuiSpacer,
} from '@elastic/eui';
import _ from 'lodash';
import React, { useEffect, useMemo, useState } from 'react';
import debounce from 'lodash/debounce';
import isEmpty from 'lodash/isEmpty';
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 @@ -185,15 +186,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 @@ -210,15 +214,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 @@ -252,6 +256,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 @@ -278,17 +295,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 a3da30f

Please sign in to comment.