Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug fix] Trace analytics scroll bar reset #1917

Merged
merged 3 commits into from
Jun 20, 2024

Conversation

TackAdam
Copy link
Collaborator

Description

This change resets the scroll bar to the position it was at prior to opening the fly-out.

Issues Resolved

#1916

Check List

  • New functionality includes testing.
    • All tests pass, including unit test, integration test and doctest
  • New functionality has been documented.
    • New functionality has javadoc added
    • New functionality has user manual doc added
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Copy link
Member

@joshuali925 joshuali925 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@ps48 ps48 added the bug Something isn't working label Jun 19, 2024
Comment on lines 195 to 197
setTimeout(() => {
spanContainerRef.current.scrollTop = prevScrollPositionRef.current || 0;
}, 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: why do we need setTimeout with delay 0 here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without it, closing the fly-out will reset the scroll bar. I believe this happens because the fly-out table closing behavior is handled in span_detail_table and it needs a delay for the use-effect.

@TackAdam
Copy link
Collaborator Author

This fix results in a slight flicker as the scroll bar adjust after being rendered to the correct position. I have not been able to find a fix that prevents this. Have tried using useMemo as it is handled in the SpanList menu but the click event for Timeline is happening in a different area.

@joshuali925
Copy link
Member

scrollbar resetting on rerender is not normal behavior, it might be caused by the plot rerendering. if recovering scroll position flickers, you can try to memorize the plot component instead

@Swiddis
Copy link
Collaborator

Swiddis commented Jun 19, 2024

I see that we rely on a memo for generating the span list and inject that value directly, but I wonder why we need a memo at all? Can we use the spans as JSX and let React do the rendering? I suspect that memo is where the reset is sneaking in to begin with.

@joshuali925
Copy link
Member

i don't think the span list is relevant for this bug, since triggering the bug doesn't need user to go to the span list view, that component was never mounted

@Swiddis
Copy link
Collaborator

Swiddis commented Jun 19, 2024

Ah, got confused between this being the span view as a whole and there being a timeline option under the span view. But the same thing applies to the timeline, both of them are being memoized.

@joshuali925
Copy link
Member

the gantt chart is not memorized, memorizing it could workaround this bug. you can try adding this above return,

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

and change

{toggleIdSelected === 'timeline' ? (
<Plt
data={data.gantt}
layout={layout}
onClickHandler={onClick}
onHoverHandler={onHover}
onUnhoverHandler={onUnhover}
/>
) : (
spanDetailTable
)}

to

{toggleIdSelected === 'timeline' ? ganttChart : spanDetailTable}

@TackAdam
Copy link
Collaborator Author

Implemented Josh's suggestion and tested. All working correctly.

@joshuali925
Copy link
Member

for completeness and good practice, the dependency array should include all dependencies. so the correct way would be using useCallback to memorize the event handlers

  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 onHover = useCallback(() => {
    const dragLayer = document.getElementsByClassName('nsewdrag')?.[0];
    dragLayer.style.cursor = 'pointer';
  }, []);

  const onUnhover = useCallback(() => {
    const dragLayer = document.getElementsByClassName('nsewdrag')?.[0];
    dragLayer.style.cursor = '';
  }, []);

and put them in the dependency array

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

some functions like setCurrentSpan would never change. but if something like fromApp changes, onClick will be re-created with the correct behavior. And since onClick changed and ganttChart depends on it, ganttChart component will also be re-created with the correct click behavior.

it likely won't make a real difference, since fromApp shouldn't change

@ps48 ps48 merged commit cc193f6 into opensearch-project:main Jun 20, 2024
16 of 21 checks passed
@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 128

To backport manually, run these commands in your terminal:

# Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/dashboards-observability/backport-2.x 2.x
# Navigate to the new working tree
pushd ../.worktrees/dashboards-observability/backport-2.x
# Create a new branch
git switch --create backport/backport-1917-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 cc193f6665f0f6a87846cd15016346f030a32545
# Push it to GitHub
git push --set-upstream origin backport/backport-1917-to-2.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/dashboards-observability/backport-2.x

Then, create a pull request where the base branch is 2.x and the compare/head branch is backport/backport-1917-to-2.x.

TackAdam added a commit to TackAdam/dashboards-observability that referenced this pull request Jun 20, 2024
* 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]>
(cherry picked from commit cc193f6)
Signed-off-by: Adam Tackett <[email protected]>
joshuali925 pushed a commit that referenced this pull request Jun 21, 2024
Signed-off-by: Adam Tackett <[email protected]>
Co-authored-by: Adam Tackett <[email protected]>
(cherry picked from commit cc193f6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants