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

[Lens] Make the dimension flyout panel stay close on outside click #83059

Merged
merged 9 commits into from
Nov 16, 2020

Conversation

dej611
Copy link
Contributor

@dej611 dej611 commented Nov 10, 2020

Summary

This PR addresses a bug identified in #82455 : if a popover inside the flyout was open, then clicking outside the panel would close first both popover and flyout, then quickly reopen the latter.

Why that happen? That's because on flyout panel close multiple updates happen at the same time (well, sequentially), and in particular multiple calls to the setActiveDimension state update were triggered: in particular one calls would refresh the state adding a tiny partial isNew: false property, while re-using the previous state.
Due to the multiple updates and React didn't have time to redraw the component, the activeDimension variable used was stale, causing the reopening: using the functional version of the setActiveDimension hook made it use the "last" version of the state in order to update.

Why that happened (2)? The main issue here was the double mechanism to toggle the popover, together with some state updates happening.
Removed the state update on close, the popover were still visible for a fraction of a second on the top left of the screen (easy to check with the Filter operation popover). While this seemed a minor issue it was only the effect of a bigger problem: the way the internal popover was closed was not correct, as it had to make sure to notify the parent component first, then its own state. On top of this beautiful dnd did not have the time to unmount in some scenarios showing a pretty big warning + error in development.

The fix has addressed in this PR only the popover close commands order, leaving the mount/unmount problem. A new issue on the EUI repo has been created to address this problem upstream.

The solution was to have the popover correctly check its state and close only via the correct call, and delay a bit the flyout panel closing in order to give time to the popover and beautiful dnd to unmount correctly. The 150 delay has been empirically measured on my machine and it was the smallest value by which the visual glitch was not visible.

Not really sure on how to test this (maybe functional?). Any suggestion is welcome.

Fixes: #82455

@dej611 dej611 added v8.0.0 release_note:skip Skip the PR/issue when compiling release notes Feature:Lens v7.11.0 labels Nov 10, 2020
@dej611 dej611 requested a review from mbondyra November 10, 2020 14:45
@dej611 dej611 added the Team:Visualizations Visualization editors, elastic-charts and infrastructure label Nov 11, 2020
@dej611 dej611 marked this pull request as ready for review November 11, 2020 14:20
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app (Team:KibanaApp)

@flash1293
Copy link
Contributor

flash1293 commented Nov 11, 2020

I tested this PR and it fixes the issue, but why is it happening in the first place? Where are these setState calls coming from? They don't seem required and I would like to fix this problem at the root if possible.

I debugged a little and it seems like they are triggered by the useEffects hook like the problem with double fetch, maybe they are related?

@dej611
Copy link
Contributor Author

dej611 commented Nov 11, 2020

I suspected they are related at some level.
Managed to isolate the issue at the operation level. Some dnd warnings are still shown in some scenarios, but the update on close should be gone.

@dej611
Copy link
Contributor Author

dej611 commented Nov 11, 2020

Note the latest change introduce a small delay on panel closing (150ms). While the number does not seem too big, the delay (even if small) is noticeable.

@dej611 dej611 requested a review from a team November 12, 2020 09:01
@dej611
Copy link
Contributor Author

dej611 commented Nov 12, 2020

@elasticmachine merge upstream

setTimeout(() => {
handleClose();
setFocusTrapIsEnabled(false);
}, 150); // <= 150 has been chosen from empirical testing
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm really concerned about this approach. As you said it will add a delay as well as not even work in all cases depending on the timing of things.

I think I wasn't really clear in my original review, I think it's fine to use the updater function setState approach to make sure the flyout stays closed if the additional setStates triggered on closing the popover are really necessary, but I was under the impression the state update happening in this scenario doesn't even make sense and we can just avoid it all together.

So, in summary

  • Let's please not introduce constant waiting times in the UI if avoidable
  • See if it's possible to not update the state on unmount like this
  • If we have to, use the updater function to make sure the flyout stays closed, but limit the cases where this is happening

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll move the issue upstream and have EUI fix it at component level.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created issue elastic/eui#4265 on EUI repo and will remove the code here.

@dej611
Copy link
Contributor Author

dej611 commented Nov 16, 2020

@elasticmachine merge upstream

Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

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

Tested in Chrome and Firefox, works as expected.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
lens 918.4KB 918.5KB +91.0B

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@dej611 dej611 merged commit e1500bf into elastic:master Nov 16, 2020
@dej611 dej611 deleted the fix/82455 branch November 16, 2020 16:22
@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Nov 18, 2020
@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create backports run node scripts/backport --pr 83059 or prevent reminders by adding the backport:skip label.

cqliu1 pushed a commit to cqliu1/kibana that referenced this pull request Nov 18, 2020
…lastic#83059)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
@kibanamachine kibanamachine removed the backport missing Added to PRs automatically when the are determined to be missing a backport. label Nov 19, 2020
dej611 added a commit that referenced this pull request Nov 19, 2020
…ick (#83059) (#83669)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
phillipb added a commit to phillipb/kibana that referenced this pull request Nov 19, 2020
…ode-details

* 'master' of github.com:elastic/kibana:
  Remove dependency of tests on strict SyntaxKind values (elastic#83440)
  [SecuritySolution] override timerange for prebuilt templates (elastic#82468)
  [Enterprise Search] Added a shouldShowActiveForSubroutes option (elastic#83338)
  [Lens] Make the dimension flyout panel stay close on outside click (elastic#83059)
  [Security Solution] Gracefully handle errors in detection rules install (elastic#83306)
  Fix advanced settings category sorting (elastic#83394)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Lens release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.11.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Lens] Dimension flyout reopens when closed by click outside while filter/range popover is open
4 participants