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

fix "Closing split bill doesn't refocus on composer" on web/desktop #12031

Merged
merged 7 commits into from
Dec 7, 2022

Conversation

aimane-chnaif
Copy link
Contributor

@aimane-chnaif aimane-chnaif commented Oct 20, 2022

Details

In PopoverMenu component, props.onItemSelected(item); should be called first. And then item.onSelected(); should be called after onModalHide callback.
This is already done in native side: https://github.com/Expensify/App/blob/main/src/components/PopoverMenu/index.native.js
We no longer need platform specific handling for this component.
So remove current index.js and rename index.native.js to index.js

Fixed Issues

$ #10888
PROPOSAL: #10888 (comment)

Tests

  1. Login with any account on desktop or web.
  2. Click on any report in LHN.
  3. Click on + icon on left end of composer.
  4. Click one of Request money / Split money / Split bill.
  5. Click cross icon to close this modal page.
  6. Verify that composer input is focused automatically

NOTE: It's intended behavior to prevent focus on touchable devices (native, mWeb) after navigating back from modal screens. reference:

// We want to focus or refocus the input when a modal has been closed and the underlying screen is focused.
// We avoid doing this on native platforms since the software keyboard popping
// open creates a jarring and broken UX.
if (this.shouldFocusInputOnScreenFocus && this.props.isFocused
&& prevProps.modal.isVisible && !this.props.modal.isVisible) {
this.focus();
}

  • Verify that no errors appear in the JS console

QA Steps

  1. Login with any account on desktop or web.
  2. Click on any report in LHN.
  3. Click on + icon on left end of composer.
  4. Click one of Request money / Split money / Split bill.
  5. Click cross icon to close this modal page.
  6. Verify that composer input is focused automatically
  • Verify that no errors appear in the JS console

PR Review Checklist

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 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 included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • 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 was added in all src/languages/* files
    • 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
  • 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 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.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

PR Reviewer Checklist

The reviewer will copy/paste it into a new comment and complete it after the author checklist is completed

  • 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:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • 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 was added in all src/languages/* files
    • 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 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.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots

Web

web.mov

Mobile Web - Chrome

mchrome.mp4

Mobile Web - Safari

msafari.mov

Desktop

desktop.mov

iOS

ios.mov

Android

android.mp4

@aimane-chnaif aimane-chnaif requested a review from a team as a code owner October 20, 2022 04:01
@melvin-bot melvin-bot bot requested review from Luke9389 and mananjadhav and removed request for a team October 20, 2022 04:01
@mananjadhav
Copy link
Collaborator

@Luke9389 @aimane-chnaif I was just about to test and while checking the code locally, I think we can further refactor this.

We have BasePopoverMenu currently, only because we have two files, index.js and index.native.js. With us merging all code into index.js, BasePopoverMenu is redundant. I feel we should merge BasePopoverMenu itno PopoverMenu/index.js

What do you folks think?

@aimane-chnaif
Copy link
Contributor Author

We have BasePopoverMenu currently, only because we have two files, index.js and index.native.js. With us merging all code into index.js, BasePopoverMenu is redundant. I feel we should merge BasePopoverMenu itno PopoverMenu/index.js

I agree

@mananjadhav
Copy link
Collaborator

@aimane-chnaif Can you implement the changes requested?

cc - @Luke9389

@aimane-chnaif
Copy link
Contributor Author

@mananjadhav ready for review

@mananjadhav
Copy link
Collaborator

thanks @aimane-chnaif. Will need 1-2 days to test this as it'll required a good amount of regression suite to test.

@mananjadhav
Copy link
Collaborator

Thanks for the changes and patience on this one @aimane-chnaif. Changes look good and test well. I agree with your comment that for mobile devices (app and mweb) we don't want to refocus as it'll popup the keyboard.

@Luke9389 All yours

🎀 👀 🎀 
C+ reviewed

  • 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:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • 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 was added in all src/languages/* files
    • 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 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.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots

Web

web-refocus-composer.mov

Mobile Web - Chrome

mweb-chrome-dont-refocus-composer.mov

Mobile Web - Safari

mweb-safari-dont-refocus-composer.mov

Desktop

desktop-refocus-composer.mov

iOS

ios-dont-refocus-composer.mov

Android

android-dont-refocus-composer.mov

Copy link
Contributor

@Luke9389 Luke9389 left a comment

Choose a reason for hiding this comment

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

I'll be coming around to this one tomorrow. Thanks for the changes.

@mananjadhav
Copy link
Collaborator

@Luke9389 Quick bump on this one

@mananjadhav
Copy link
Collaborator

@Luke9389 did you get a chance to look at this PR?

@Luke9389
Copy link
Contributor

Oh man, missed it. Thanks for the bump(s)

this.onMenuHide = () => {
item.onSelected();

// Clean up: open and immediately cancel should not re-trigger the last action
Copy link
Contributor

Choose a reason for hiding this comment

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

Where do we stand with this? Have we tested that?

I know this came from the previous code but now that we're changing this component we should be sure it works in all contexts.

Copy link
Contributor Author

@aimane-chnaif aimane-chnaif Nov 15, 2022

Choose a reason for hiding this comment

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

This code is inside selectItem(item) to get item and call item.onSelected() after modal fully closed, which was selected before triggering modal close.
But I suggest to refactor this to use variable instead of function inside function:

    constructor(props) {
        super(props);
        this.state = {
            focusedIndex: -1,
        };
        this.updateFocusedIndex = this.updateFocusedIndex.bind(this);
        this.resetFocusAndHideModal = this.resetFocusAndHideModal.bind(this);
        this.removeKeyboardListener = this.removeKeyboardListener.bind(this);
        this.attachKeyboardListener = this.attachKeyboardListener.bind(this);
-       this.onMenuHide = () => {};
+       this.selectedItem = null;
    }
-   /**
-    * Set the item's `onSelected` action to fire after the menu popup closes
-    * @param {{onSelected: function}} item
-    */
    selectItem(item) {
-       this.onMenuHide = () => {
-           item.onSelected();
-
-           // Clean up: open and immediately cancel should not re-trigger the last action
-           this.onMenuHide = () => {};
-       };
+       this.selectedItem = item;

        this.props.onItemSelected(item);
    }
    resetFocusAndHideModal() {
        this.updateFocusedIndex(-1); // Reset the focusedIndex on modal hide
        this.removeKeyboardListener();
-       this.onMenuHide();
+       if (this.selectedItem) {
+           this.selectedItem.onSelected();
+           this.selectedItem = null;
+       }
    }

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I like that change. Go ahead and commit it and test it out!

Comment on lines 84 to 89
/**
* @param {Number} index
*/
updateFocusedIndex(index) {
this.setState({focusedIndex: index});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this should be it's own function. Just use setState when you need it.

src/components/PopoverMenu/index.js Outdated Show resolved Hide resolved
@aimane-chnaif
Copy link
Contributor Author

@Luke9389 ready for review

@Luke9389
Copy link
Contributor

@aimane-chnaif did you test this on all platforms (multiple pop-overs, not just the bill split one)?

@aimane-chnaif
Copy link
Contributor Author

@aimane-chnaif did you test this on all platforms (multiple pop-overs, not just the bill split one)?

yes, tested all Popover modals and accessibility

@mananjadhav
Copy link
Collaborator

@Luke9389 @aimane-chnaif Is there anything pending here? Then I can retest with the latest changes and update the checklist again.

@aimane-chnaif
Copy link
Contributor Author

@Luke9389 @aimane-chnaif Is there anything pending here? Then I can retest with the latest changes and update the checklist again.

yes please. tests well on my side

@mananjadhav
Copy link
Collaborator

I've tested again with the updated changes. Thanks for the changes @aimane-chnaif.

@Luke9389 All yours.

🎀 👀 🎀 
C+ reviewed

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:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • 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 was added in all src/languages/* files
    • 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 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.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots

Web

web-refocus-composer.mov

Mobile Web - Chrome

mweb-chrome-refocus-compoer.mov

Mobile Web - Safari

mweb-safari-refocus-compoer.mov

Desktop

desktop-refocus-composer.mov

iOS

ios-refocus-compoer.mov

Android

android-refocus-composer.mov

@mananjadhav
Copy link
Collaborator

@Luke9389 Did you get a chance to look at the previous comments?

@mananjadhav
Copy link
Collaborator

@Luke9389 This PR is blocked by your review and approval.

@Luke9389 Luke9389 assigned Luke9389 and aimane-chnaif and unassigned Luke9389 Dec 7, 2022
@Luke9389 Luke9389 merged commit 28851c9 into Expensify:main Dec 7, 2022
@OSBotify
Copy link
Contributor

OSBotify commented Dec 7, 2022

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

@marcaaron
Copy link
Contributor

Hi this PR has been linked to a regression here: #13435

I think since this is a lower level change more care could have been applied to test all the existing popovers. In fact, that is what this checkbox is asking us to do.

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)

@mananjadhav @aimane-chnaif please keep this in mind in the future. If we are making changes to something that is used multiple places it's a good idea to quickly check all the usages of that thing, thanks!

@OSBotify
Copy link
Contributor

🚀 Deployed to production by @chiragsalian in version: 1.2.38-6 🚀

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