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

Refactor popover positioning service #1

Conversation

cjcenizal
Copy link

@cjcenizal cjcenizal commented Jun 18, 2018

I broke this PR into the following steps, with corresponding commits:

  1. I grouped related variables in getPopoverScreenCoordinates into discrete steps:
    a) Find original cross-axis position.
    b) Apply shift to cross-axis position, if necessary.
    c) Find primary axis position.
  2. I extracted these steps into getCrossAxisPosition and getPrimaryAxisPosition helper functions, which also encapsulate the arrow-positioning logic for each axis. The primary axis arrow positioning logic was both adding and subtracting positioning[primaryAxisPositionName], so I removed those operations.
  3. I defined an iterationPositions array in getPopoverScreenCoordinates, which we traverse to get the best-fitting position, instead of defining the next iteration position in each loop. I found it easier to understand the strategy this way.


const {
bestPosition,
} = iterationPositions.reduce(({ bestFit, bestPosition }, iterationPosition) => {
Copy link
Author

Choose a reason for hiding this comment

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

I like the encapsulation of using reduce because you don't need to mutate external variables, but it's a little inefficient because it always loops 4 times, even if the best fit has already been found. I don't mind if you want to switch this back to a for loop.

Copy link
Owner

Choose a reason for hiding this comment

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

I really like seeing it this way


// the popover's original position on the cross-axis is determined by:
const crossAxisPositionOriginal =
anchorBoundingBox[crossAxisFirstSide] // where the anchor is located
Copy link
Owner

Choose a reason for hiding this comment

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

nice formatting!

Copy link
Owner

@chandlerprall chandlerprall left a comment

Choose a reason for hiding this comment

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

love it!

@chandlerprall chandlerprall merged commit 3e1dd5b into chandlerprall:feature/popover-service Jun 19, 2018
@cjcenizal cjcenizal deleted the popover-service-refactor branch June 19, 2018 16:41
chandlerprall pushed a commit that referenced this pull request Apr 3, 2019
Altered styles and added some props
chandlerprall pushed a commit that referenced this pull request Aug 23, 2019
Update defazio fork to 13.0
chandlerprall pushed a commit that referenced this pull request Oct 25, 2019
chandlerprall pushed a commit that referenced this pull request Oct 28, 2019
Thread generics throughout EuiBasicTable
chandlerprall pushed a commit that referenced this pull request Feb 28, 2020
* removed duplicate icons

* Fixing changelog and updating tests (#1)

Co-authored-by: Caroline Horn <[email protected]>
chandlerprall pushed a commit that referenced this pull request Jan 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants