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

Add popovers without overlay #19011

Merged
merged 60 commits into from
Aug 4, 2023
Merged

Conversation

allroundexperts
Copy link
Contributor

@allroundexperts allroundexperts commented May 16, 2023

Details

This PR creates new popover that does not have an overlay. This mimics the behaviour of the popovers that are there on other popular websites such as gmail.

Fixed Issues

$ #15289
PROPOSAL: #15289 (comment)

Tests

  1. Open ND and go to any chat.
  2. Click on any of the popover menu such as emoji picker menu
  3. Verify that the elements below the popover are still hoverable / clickable.
  4. Click out of the popover menu
  5. Right click to open the secondary menu
  6. Right click again elsewhere on the screen
  7. Ensure the right click menu appears in the new location.
  • Verify that no errors appear in the JS console

Offline tests

N/A

QA Steps

  1. Open ND and go to any chat.
  2. Click on any of the popover menu such as emoji picker menu
  3. Verify that the elements below the popover are still hoverable / clickable.
  4. Click out of the popover menu
  5. Right click to open the secondary menu
  6. Right click again elsewhere on the screen
  7. Ensure the right click menu appears in the new location.
  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
    • MacOS / Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • If we are not using the full Onyx data that we loaded, I've added the proper selector in order to ensure the component only re-renders when the data it is using changes
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
Screen.Recording.2023-05-16.at.5.58.21.PM.mov
Mobile Web - Chrome
Screen.Recording.2023-05-16.at.6.03.00.PM.mov
Mobile Web - Safari
Screen.Recording.2023-05-16.at.6.05.39.PM.mov
Desktop
Screen.Recording.2023-05-16.at.5.59.15.PM_compressed.mp4
iOS
Screen.Recording.2023-05-16.at.6.04.43.PM.mov
Android
Screen.Recording.2023-05-16.at.6.04.11.PM.mov

@allroundexperts allroundexperts requested a review from a team as a code owner May 16, 2023 13:20
@melvin-bot melvin-bot bot requested review from aimane-chnaif and dangrous and removed request for a team May 16, 2023 13:20
@melvin-bot
Copy link

melvin-bot bot commented May 16, 2023

@dangrous @aimane-chnaif One of you needs to copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

Copy link
Contributor

@aimane-chnaif aimane-chnaif left a comment

Choose a reason for hiding this comment

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

Is it really impossible to implement non-modal popover without introducing anchor ref or name constants?

src/CONST.js Outdated
@@ -664,7 +665,6 @@ const CONST = {
VALIDATE_CODE_FAILED: 'Validate code failed',
},
},

Copy link
Contributor

Choose a reason for hiding this comment

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

why line removed? unnecessary change

...modalStyle,
...popoverAnchorPosition,
...{
position: 'fixed',
Copy link
Contributor

Choose a reason for hiding this comment

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

you introduced new modal type just because of this?
what issue you have if position: 'absolute'?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With position:'absolute' is for nearest relative positioned element. We need it to be against the window.

Copy link
Contributor

Choose a reason for hiding this comment

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

Still not convinced about this change. I don't like introducing new popover style just because of this.
If absolute, what regression occurs?
Why is it working in old popover?

@aimane-chnaif
Copy link
Contributor

aimane-chnaif commented May 17, 2023

Lint failing. Please pull main and fix all lint errors

@allroundexperts
Copy link
Contributor Author

Lint failing. Please pull main and fix all lint errors

@aimane-chnaif Lint is failing because of a warning that React.useEffect has missing dependencies. Our linter is currently expecting callbacks passed as props to be present inside the useEffect dependencies. I think this is incorrect as this sometimes causes a re-render loop. This is because the function identity changes on each render. I would prefer to remove this rule. Let me know your thoughts.

@aimane-chnaif
Copy link
Contributor

@aimane-chnaif Lint is failing because of a warning that React.useEffect has missing dependencies. Our linter is currently expecting callbacks passed as props to be present inside the useEffect dependencies. I think this is incorrect as this sometimes causes a re-render loop. This is because the function identity changes on each render. I would prefer to remove this rule. Let me know your thoughts.

There's a discussion on that - https://expensify.slack.com/archives/C01GTK53T8Q/p1680256754764159
You can disable case by case.

Is it really impossible to implement non-modal popover without introducing anchor ref or name constants?

what's your answer?

@allroundexperts
Copy link
Contributor Author

@aimane-chnaif Lint is failing because of a warning that React.useEffect has missing dependencies. Our linter is currently expecting callbacks passed as props to be present inside the useEffect dependencies. I think this is incorrect as this sometimes causes a re-render loop. This is because the function identity changes on each render. I would prefer to remove this rule. Let me know your thoughts.

There's a discussion on that - https://expensify.slack.com/archives/C01GTK53T8Q/p1680256754764159 You can disable case by case.

Is it really impossible to implement non-modal popover without introducing anchor ref or name constants?

what's your answer?

@aimane-chnaif I don't believe that anything is impossible. It's better to dive into the reason why we need these in the first place. We're using click listener with capture. This means that it gets called whenever we click anywhere on the screen. This is fine if we click anywhere on the screen other than the original button that triggered the popover. If we click on the anchor button while the popover is visible, the following will happen:
a. The global click handler gets triggered and tries to close the popover.
b. The event then reaches on the anchor listener, and since the state of the popover is not visible (because of click getting to popover context before the anchor button), the anchor handler will change the state back to visible. This will make it not possible to close the popover by clicking on the anchor button.

You might say that we can stop the propagation of event once it reaches the context. But in order to do so, we need to make sure that the click came from within the anchor element. So we will still need a ref of the anchor. However, with this, we wont be needing to add the anchor check to the individual anchor button callbacks.

@allroundexperts
Copy link
Contributor Author

@narefyev91 Would love to hear your feedback here as well!

Copy link
Contributor

@dangrous dangrous left a comment

Choose a reason for hiding this comment

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

Alright, let's go for it! I'm going to merge.

I modified the QA steps for this particular issue to include the original "bug". They are still a bit light BUT I think that's fine because ideally we shouldn't really see any changed behavior, and if we do it'll be caught by QA.

Incredible job pushing this over the line, everyone! I really appreciate the time everyone put into it, this was definitely a long and intense project.

@allroundexperts
Copy link
Contributor Author

Looks like we need to update the checklist as well 😄

Doing that now.

@dangrous
Copy link
Contributor

dangrous commented Aug 4, 2023

LOL @allroundexperts the checklist has changed since we made this PR. Do you mind pulling the new checklist from the template and copying it into the description, then filling it out?

EDIT: nvm, I see you noticed first

@allroundexperts
Copy link
Contributor Author

@dangrous Good to go!

@dangrous dangrous merged commit c32fb5a into Expensify:main Aug 4, 2023
13 of 15 checks passed
@OSBotify
Copy link
Contributor

OSBotify commented Aug 4, 2023

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@aimane-chnaif
Copy link
Contributor

I keep looking for bugs on slack reported from our good testers so that we can fix them quickly as follow-up before being deploy blocker.

chrispader pushed a commit to margelo/expensify-app-fork that referenced this pull request Aug 6, 2023
@aimane-chnaif
Copy link
Contributor

@allroundexperts popover doesn't close on Esc key. Only happens on emoji picker

Screen.Recording.2023-08-07.at.1.56.16.AM.mov

@allroundexperts
Copy link
Contributor Author

@aimane-chnaif Fixed here

@OSBotify
Copy link
Contributor

OSBotify commented Aug 7, 2023

🚀 Deployed to staging by https://github.com/dangrous in version: 1.3.51-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

OSBotify commented Aug 9, 2023

🚀 Deployed to production by https://github.com/Julesssss in version: 1.3.51-2 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

OSBotify commented Aug 9, 2023

🚀 Deployed to staging by https://github.com/dangrous in version: 1.3.52-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 failure ❌
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

OSBotify commented Aug 9, 2023

🚀 Deployed to staging by https://github.com/dangrous in version: 1.3.52-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/puneetlath in version: 1.3.52-5 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@parasharrajat
Copy link
Member

I have a question about the implementation here. A long back we were able to open multiple context menus like those implemented here without the need for this new PopoverWithoutOverlay. IMO, we can disable the overlay with just a simple prop called hasBackdrop on Modal. How this is different from using the props? cc: @allroundexperts @aimane-chnaif

@parasharrajat
Copy link
Member

parasharrajat commented Oct 8, 2023

@allroundexperts I would love to hear some thoughts on this as it is holding a PR.

@allroundexperts
Copy link
Contributor Author

@parasharrajat Please refer to the discussion following this proposal.

Copy link
Member

Choose a reason for hiding this comment

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

Please keep the same name as class.


Popover.propTypes = propTypes;
Popover.defaultProps = defaultProps;
Popover.displayName = 'Popover';
Copy link
Member

Choose a reason for hiding this comment

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

This should be PopoverWithoutOverlay. There is another Popover in the app.

close(props.anchorRef);
}
Modal.willAlertModalBecomeVisible(props.isVisible);
Modal.setCloseModal(props.isVisible ? () => props.onClose(props.anchorRef) : null);
Copy link
Contributor

Choose a reason for hiding this comment

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

✋ Coming from #27244

There will be a chance of race condition when the new popover setCloseModal will be overwritten by the previous popover, which isVisible property is changed into false (about to be closed) and make one of the pop over stuck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants