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

Close all popovers when Keyboard shortcut modal is displayed #13956

Merged
merged 11 commits into from
Feb 14, 2023

Conversation

pecanoro
Copy link
Contributor

@pecanoro pecanoro commented Jan 3, 2023

By keeping the modal in BaseSidebarScreen.js, it wasn't being rendered on top of everything and so we were getting weird behavior in which you could still click on menus even though the shortcut was opened.

Fixed Issues

$ #13871

Tests / Offline tests / QA Steps

  1. Login with any account
  2. Go to any chat
  3. Click on "+" (don't choose anything)
  4. Press the combination "CTRL+I" on the keyboard
  5. Background should be disabled and modal should show on top of everything
  6. Repeat the process in different parts of the app and make sure the behavior is consistent
  • 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 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 correct English and 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
    • 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 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 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.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
Monosnap.screencast.2023-02-08.16-03-33.mp4
Mobile Web - Chrome
Monosnap.screencast.2023-02-08.16-43-56.mp4
Mobile Web - Safari
Monosnap.screencast.2023-02-08.16-20-14.mp4
Desktop
Monosnap.screencast.2023-02-08.16-14-48.mp4
iOS
Monosnap.screencast.2023-02-08.16-29-42.mp4
Android
Monosnap.screencast.2023-02-08.16-40-43.mp4

@pecanoro pecanoro requested a review from a team as a code owner January 3, 2023 15:25
@pecanoro pecanoro self-assigned this Jan 3, 2023
@melvin-bot melvin-bot bot requested review from mananjadhav and thienlnam and removed request for a team January 3, 2023 15:25
@melvin-bot
Copy link

melvin-bot bot commented Jan 3, 2023

@mananjadhav @thienlnam 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]

@pecanoro
Copy link
Contributor Author

pecanoro commented Jan 3, 2023

@mananjadhav PR is pretty simple, no need to review this one!

@pecanoro pecanoro removed the request for review from mananjadhav January 3, 2023 15:26
@pecanoro pecanoro changed the title Move KeyboardShortcut modal to ReportScreen component [HOLD] Move KeyboardShortcut modal to ReportScreen component Jan 3, 2023
@pecanoro
Copy link
Contributor Author

pecanoro commented Jan 3, 2023

@thienlnam Don't review it yet, it seems that moving it doesn't solve all issues completely

@pecanoro pecanoro changed the title [HOLD] Move KeyboardShortcut modal to ReportScreen component Move KeyboardShortcut modal to ReportScreen component Feb 8, 2023
@pecanoro
Copy link
Contributor Author

pecanoro commented Feb 8, 2023

This PR ended up not being that simple hehe

The main problem here is that popovers are also modals and react native does not work well with opening multiple modals. In theory, clicking away from one popover should let the modal go away, but we are opening the shortcut modal using a key listener so any other popovers won't get the memo to get closed.

The problem with being one on top of the other is something related to the styles that the modal gets here. However, since this is not supported behavior either way, I decided to simply dismiss any popovers that were already opened if we were to show the shortcut modal.

I am going to require a review from @mananjadhav as well because I think it needs two pair of eyes.

@mananjadhav
Copy link
Collaborator

Okay @pecanoro I'll review and test this today.

@pecanoro pecanoro changed the title Move KeyboardShortcut modal to ReportScreen component Close all popovers when Keyboard shortcut modal is displayed Feb 9, 2023
if (!props.fullscreen && !props.isSmallScreenWidth) {
return createPortal(

class Popover extends React.Component {
Copy link
Collaborator

@mananjadhav mananjadhav Feb 9, 2023

Choose a reason for hiding this comment

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

qq, any specific reason why we needed this to be moved to a class component?

Wouldn't the following check suffice the requirement?

  if ( this.props.isShortcutsModalOpen && this.props.isVisible) {
      this.props.onClose();
      return null;
  }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, the linter was complaining that I should return early 😞

Copy link
Contributor Author

Choose a reason for hiding this comment

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

32:35 error Prefer an early return to a conditionally-wrapped function body rulesdir/prefer-early-return

Copy link
Collaborator

Choose a reason for hiding this comment

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

I just attempted:

diff --git a/src/components/Popover/index.js b/src/components/Popover/index.js
index 9a2e20ed3d..8205db0c1e 100644
--- a/src/components/Popover/index.js
+++ b/src/components/Popover/index.js
@@ -1,15 +1,23 @@
 import React from 'react';
+import {withOnyx} from 'react-native-onyx';
 import {createPortal} from 'react-dom';
 import {propTypes, defaultProps} from './popoverPropTypes';
 import CONST from '../../CONST';
 import Modal from '../Modal';
+import compose from '../../libs/compose';
 import withWindowDimensions from '../withWindowDimensions';
+import ONYXKEYS from '../../ONYXKEYS';

 /*
  * This is a convenience wrapper around the Modal component for a responsive Popover.
  * On small screen widths, it uses BottomDocked modal type, and a Popover type on wide screen widths.
  */
 const Popover = (props) => {
+    if (props.isShortcutsModalOpen && props.isVisible) {
+        props.onClose();
+        return null;
+    }
+
     if (!props.fullscreen && !props.isSmallScreenWidth) {
         return createPortal(
             <Modal
@@ -41,4 +49,9 @@ Popover.propTypes = propTypes;
 Popover.defaultProps = defaultProps;
 Popover.displayName = 'Popover';

-export default withWindowDimensions(Popover);
+export default compose(
+    withWindowDimensions,
+    withOnyx({
+        isShortcutsModalOpen: {key: ONYXKEYS.IS_SHORTCUTS_MODAL_OPEN},
+    }),
+)(Popover);

and I didn't get any lint errors

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh you mean why I moved it to a class and not exactly about the if condition?

Copy link
Contributor Author

@pecanoro pecanoro Feb 9, 2023

Choose a reason for hiding this comment

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

About the class, yeah, I guess we didn't need it anymore, I played with the prevProps at the beginning and that's why I created it for componentDidUpdate, but then I realized the condition was redundant and worked well without checking any prevProps. I can revert it back now that I am only using the props and nothing else.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I can revert it back now that I am only using the props and nothing else

yeah, exactly. Thank you.

Copy link
Collaborator

@mananjadhav mananjadhav left a comment

Choose a reason for hiding this comment

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

Raised one question.

@@ -66,7 +65,6 @@ class BaseSidebarScreen extends Component {
onLayout={this.props.onLayout}
/>
</View>
<KeyboardShortcutsModal />
Copy link
Collaborator

Choose a reason for hiding this comment

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

We moved the KeybaordShoftcutsModal from BaseSidebarScreen to Expensify.js as a refactor or for any specific reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since it'a high level modal that should displayed at any level, I thought the highest would be the best. We need to mount it at least one. We do something similar with UpdateAppModal for example

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agreed with the reasoning, even I wasn't sure why it was in BaseSidebarScreen. I asked because the Popover changes worked even without moving the KeyboardsModal to Expensify.js.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this was to prevent shortcut modal when user logged out.
BaseSidebarScreen is highest level on auth screens.
Expensify.js is highest level on all screens (including unauthorized screens).

Now I can see shortcut modal open on login page. This is not an issue though 🙂
image

@pecanoro
Copy link
Contributor Author

pecanoro commented Feb 9, 2023

Updated!

@mananjadhav
Copy link
Collaborator

@pecanoro Thanks for the changes. They look ok. I'll be testing them by Monday.

@mananjadhav
Copy link
Collaborator

@pecanoro This tests well with different Popovers. We have a similar case for the Modal, I think we can deal with that as a separate issue right?

keyboard-modal-delete-modal-overlap

@mananjadhav
Copy link
Collaborator

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible 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 checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
    • MacOS / Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (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 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
    • 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 correct English and 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 verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • 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
  • 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
    • 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 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 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.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
web-keyboard-modal-popover.mov
Mobile Web - Chrome
mweb-chrome-keyboard-modal-popover.mov
Mobile Web - Safari
mweb-safari-keyboard-modal-popover.mov
Desktop
web-keyboard-modal-popover.mov
iOS
ios-keyboard-modal-popover.mov
Android
android-keyboard-modal-popover.mov

Thanks for the patience here. This tests well, except for the ConfirmModal case that I mentioned in the previous comment. @thienlnam All yours.

@pecanoro
Copy link
Contributor Author

ConfirmModal is not a "Popover", right? Yeah, I focused only on popovers and not the other types of modals because it is more unclear what we would want to do in those cases when we also add the backdrop.

@mananjadhav
Copy link
Collaborator

Yeah not a Popover. It's a Modal. Hence, I mentioned here let's do it as a separate follow up PR.

Copy link
Contributor

@thienlnam thienlnam left a comment

Choose a reason for hiding this comment

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

The main problem here is that popovers are also modals and react native does not work well with opening multiple modals. In theory, clicking away from one popover should let the modal go away, but we are opening the shortcut modal using a key listener so any other popovers won't get the memo to get closed.

I agree with the solution, but it seems like what we're doing here is specific to just the keyboardShortcut modal, and if we were to add additional modals we are adding more onyx keys and logic checks

Is this something that would be possible to add inside the popover or modal component so that this works generally?

@pecanoro
Copy link
Contributor Author

The keyboard shortcut one is the only one that opens from the keyboard (unless I am missing something), any other will trigger the "click outside the modal" event and will get closed. This needs to listen to the Onyx key that keeps track if the modal is opened. If we need to do this for any of the modals, then I agree we can generalize it and use maybe a general Onyx key for all of them, but I feel that is getting ahead of it.

@thienlnam
Copy link
Contributor

Sure, we can definitely address when it comes up

@thienlnam thienlnam merged commit 38a48d9 into main Feb 14, 2023
@thienlnam thienlnam deleted the rocio-KeyboardShortCut branch February 14, 2023 21:45
@OSBotify
Copy link
Contributor

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

@situchan
Copy link
Contributor

The keyboard shortcut one is the only one that opens from the keyboard (unless I am missing something), any other will trigger the "click outside the modal" event and will get closed.

There are other cases of opening modal using shortcut key:
Ctrl+K opens Search page
Ctrl+Shift+K opens Create group page

@pecanoro
Copy link
Contributor Author

@situchan I tested the keyboard opening over these and it was working but guess what I didn't test, actually using the shortcut for them. I will create another PR to fix that case as well, it wasn't working before no matter what so at least we didn;t break anything (yet)

@situchan
Copy link
Contributor

There's already issue involving all these cases and I proposed solution for these 3 shortcuts but this still doesn't fix this case @mananjadhav reported since this is non-popover.
I have more general solution which fixes even non-popover cases. I will post this proposal soon after full test.

@pecanoro
Copy link
Contributor Author

pecanoro commented Feb 15, 2023

@situchan If I am following properly, you are saying you will propose a fix even for this case in the other issue, right? If so, all good, we can keep this one closed then!

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/thienlnam in version: 1.2.72-0 🚀

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

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/francoisl in version: 1.2.72-1 🚀

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

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.

5 participants