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 error props being incorrectly accessed in components #23394

Merged
merged 8 commits into from
Aug 9, 2023

Conversation

Nikhil-Vats
Copy link
Contributor

@Nikhil-Vats Nikhil-Vats commented Jul 22, 2023

Details

errors props were being incorrectly accessed in IOUCurrencySelection, ReportScreen, and MoneyRequestAmountPage. This fixes that by getting the errors from the report object using a new function to keep code DRY.

Fixed Issues

$ #23373
PROPOSAL: #23373 (comment)

Tests

  1. Open the app in two tabs.
  2. On first tab, open settings and click on force offline.
  3. On second tab, go to search and enter a long email like a@_.cd or 2f34d2be9bce77da59b2e91f1a2bd25e0b85f2142f34d2be9bce77da59b2e91f1a2bd25e0b85f2142f34d2be9bce77da59b2e91f1a2bd25e0b85f214@gmail.com.
  4. Now, send some messages in the chat and open emoji picker from composer.
  5. Go to first tab and toggle force offline to come back online.
  6. Verify that both composer and emoji picker automatically hide in the second tab and chat shows the error that email address is invalid.

Since we can't open multiple tabs in apps (android/ios/desktop), we can test the same by switching off wifi in our device in step 2 and then switching on wifi in step 5 again.

  • Verify that no errors appear in the JS console

Offline tests

Same as above.

QA Steps

Same as above.

  • 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 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
23394_web1.mov
23394_web2.mov
Mobile Web - Chrome
23394_mchrome1.mov
23394_mchrome2.mov
Mobile Web - Safari
23394_safari1.mov
23394_safari2.mov
23394_safari3.mov
Desktop
23394_desktop1.mov
iOS
23394_ios1.mov
23394_ios2.mov
Android
23394_android1.mov
23394_android2.mov

@Nikhil-Vats Nikhil-Vats requested a review from a team as a code owner July 22, 2023 11:33
@melvin-bot melvin-bot bot removed the request for review from a team July 22, 2023 11:33
@melvin-bot
Copy link

melvin-bot bot commented Jul 22, 2023

@mollfpr Please 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]

@melvin-bot melvin-bot bot requested a review from mollfpr July 22, 2023 11:33
@Nikhil-Vats
Copy link
Contributor Author

Nikhil-Vats commented Jul 22, 2023

Hey @mollfpr @marcaaron, here's the behaviour of emoji picker after applying the fix. Follow the test steps in PR description to verify yourself. It is working as expected.

Before fix -

before_fix.mov

After fix -

after_fix.mov
Here's what happens for the other two pages -

For the other two pages (IOUCurrencySelection and MoneyRequestAmountPage), when there is an error the modal is closed but we are also redirected to the concierge chat because of this PR that was merged two weeks ago and is now on production -

This is the piece of code that is responsible and was added in that PR (see line 183) -

// navigate to concierge when the room removed from another device (e.g. user leaving a room)
// the report will not really null when removed, it will have defaultProps properties and values
if (
prevOnyxReportID &&
prevOnyxReportID === routeReportID &&
!onyxReportID &&
// non-optimistic case
(_.isEqual(this.props.report, defaultProps.report) ||
// optimistic case
(prevProps.report.statusNum === CONST.REPORT.STATUS.OPEN && this.props.report.statusNum === CONST.REPORT.STATUS.CLOSED))
) {
Navigation.goBack();
Report.navigateToConciergeChat();
// isReportRemoved will prevent <FullPageNotFoundView> showing when navigating
this.setState({isReportRemoved: true});
return;
}

The behaviour of the app (prod/staging/local) right now -

Screen.Recording.2023-07-24.at.1.34.12.AM.mov

When I undo the changes in that PR and apply the fix in this PR -

Screen.Recording.2023-07-24.at.1.34.47.AM.mov

@marcaaron I just wanted to confirm the expected behaviour here before I proceed. If there is an error and the request money/split bill/assign task modal is opened, is it okay that we are redirected to concierge chat?

Or should we stay on the same report because as you can see in the video below the chat still exists even after we are redirected to concierge.

Screen.Recording.2023-07-24.at.1.57.00.AM.mov

@mollfpr
Copy link
Contributor

mollfpr commented Jul 24, 2023

I just wanted to confirm the expected behaviour here before I proceed. If there is an error and the request money/split bill/assign task modal is opened, is it okay that we are redirected to concierge chat?

I'm okay with that.

@Nikhil-Vats
Copy link
Contributor Author

Hey @marcaaron, what do you think of the behaviour mentioned above in case of IOUCurrencySelection and MoneyRequestAmountPage?

@marcaaron
Copy link
Contributor

If there is an error and the request money/split bill/assign task modal is opened, is it okay that we are redirected to concierge chat?

That sounds like a bug to me caused by the PR you mentioned. I would expect to see some error on the page itself and not to get redirected.

@Nikhil-Vats
Copy link
Contributor Author

Apologies, I was sick these last 2 days so couldn't dedicate much time to this. I am better now so will update the PR tomorrow morning.

I will try to find the solution for the issue caused by the referenced PR so that we stay on the same page after an error.

@Nikhil-Vats
Copy link
Contributor Author

Updated the branch to resolve merge conflicts.

I also noticed that the regression from the other PR was identified and there is a new PR to fix it, I added a comment there since they are also trying to fix an issue with the same root cause -
User is navigated to concierge when there is an error in the report.

@marcaaron what should be done now? Should we put this PR on hold until that new PR is merged or something else?

@marcaaron
Copy link
Contributor

Mind directing that question to @mollfpr? I'll jump in here when this is looking ready to merge. Thanks!

@Nikhil-Vats
Copy link
Contributor Author

Nikhil-Vats commented Jul 31, 2023

@mollfpr what do you think? I think we have two options -

  1. Wait for the regression to be fixed but it will take a long time since from what I can read on the new PR it will also require a Backend change.
  2. The PR that introduced the regression (which is stopping us from testing) is pretty small. Just a few lines in 1 file. I can undo that within this PR or in a new one and then we will be unblocked for this PR. The reverted PR can be readded with the regression PR they have opened.

@koko57 koko57 mentioned this pull request Aug 1, 2023
56 tasks
@mollfpr
Copy link
Contributor

mollfpr commented Aug 1, 2023

@Nikhil-Vats We can do option two since they will add it back with the fix for the regression. But let's notify them about this and wait for their feedback, then apply the necessary change here.

@Nikhil-Vats
Copy link
Contributor Author

@mollfpr They provided confirmation here. Should I revert the changes in this PR or a separate one?

@mollfpr
Copy link
Contributor

mollfpr commented Aug 1, 2023

@Nikhil-Vats Great! Let's do it here.

@@ -71,15 +60,6 @@ function IOUCurrencySelection(props) {
const iouType = lodashGet(props.route, 'params.iouType', CONST.IOU.MONEY_REQUEST_TYPE.REQUEST);
const reportID = lodashGet(props.route, 'params.reportID', '');

const shouldDismissModal = ReportUtils.shouldHideComposer(props.report, props.errors);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mollfpr I removed this from IOUCurrencySelection page because we don't need to add it here. We check this in MoneyRequestAmountPage page and they both belong to the same stack of navigators so it works, I tested.

I even tried by pressing browser forward button but it did not let me go to that screen.

I did see your comment here and wondered why it was not working before. Anyway, please let me know if it doesn't work for you.

@Nikhil-Vats
Copy link
Contributor Author

@mollfpr PR is ready for review.

const hideComposer = ReportUtils.shouldHideComposer(props.report, errors);
const shouldOmitBottomSpace = hideComposer || isArchivedRoom;
// If composer is hidden, omit the bottom space.
const shouldOmitBottomSpace = ReportUtils.shouldHideComposer(props.report);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Archived report is already checked in shouldHideComposer so removed the duplicate condition.

@@ -158,36 +156,17 @@ class ReportScreen extends React.Component {

componentDidUpdate(prevProps) {
// If composer should be hidden, hide emoji picker as well
if (ReportUtils.shouldHideComposer(this.props.report, this.props.errors)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

except this line and line 389 where errors are no longer passed to ReportFooter, the rest code in this file is reverting the PR that was blocking us - https://github.com/Expensify/App/pull/22787/files

@mollfpr
Copy link
Contributor

mollfpr commented Aug 2, 2023

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 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
    • 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 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 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 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 reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
23394.Web.mov
Mobile Web - Chrome
Screen_Recording_20230809_213949_Chrome.mp4
Mobile Web - Safari
23394.mWeb.Safari.mp4
Desktop
23394.Desktop.mov
iOS
23394.iOS.mp4
Android
Screen_Recording_20230809_215256_New.Expensify.mp4

@mollfpr
Copy link
Contributor

mollfpr commented Aug 2, 2023

@Nikhil-Vats The behavior on the IOU pages is different; sometimes, the RHN is closed and shows the reported error, and sometimes keep, the RHN and showing the not found page.

Screen.Recording.2023-08-02.at.18.33.12.mov
Screen.Recording.2023-08-02.at.18.34.48.mov

@Nikhil-Vats
Copy link
Contributor Author

@mollfpr This was reported here in the regression we were discussing about. It is a backend bug where sometimes the report is cleared from onyx before the error is sent by backend due to which we are redirected to not found page. I believe they will handle it in the new PR as they already reported it. I will paste your video there to make sure they test this as I never faced this.

@mollfpr
Copy link
Contributor

mollfpr commented Aug 2, 2023

@Nikhil-Vats I constantly got the not found page on the Desktop while testing the IOU flow. I'm afraid the QA team will bump into this issue, and the QA will fail.

Screen.Recording.2023-08-02.at.21.23.37.mov

@Nikhil-Vats
Copy link
Contributor Author

What should be done here then @mollfpr? It is a backend issue and they are still discussing the approach over there so it will take some time for it to be fixed.

@mollfpr
Copy link
Contributor

mollfpr commented Aug 2, 2023

Ideally, we should get the same expected result on all platforms. So if the attached PR needed to be deployed first, we should wait.

@Nikhil-Vats
Copy link
Contributor Author

Sure @mollfpr, should we put a comment on the main issue and put it on hold then?

I commented on the other issue asking their confirmation on if they are going to fix this redirect to 404 page error in their issue.

@mollfpr
Copy link
Contributor

mollfpr commented Aug 3, 2023

@Nikhil-Vats I agree with Marc's explanation here. We can skip the test case on the IOU flow for the platform constantly showing the issue.

What do you think?

@Nikhil-Vats
Copy link
Contributor Author

Nikhil-Vats commented Aug 3, 2023

@mollfpr Sure, I will open a separate issue for that.

Let me know if it happens constantly on any other platform for you as well so I can put that in the test steps.

@mollfpr
Copy link
Contributor

mollfpr commented Aug 4, 2023

@Nikhil-Vats Could you resolve the conflicts? I'll test all the platforms and let you know. Thanks!

@Nikhil-Vats
Copy link
Contributor Author

Done @mollfpr

@Nikhil-Vats
Copy link
Contributor Author

There are conflicts again, I'll resolve them today.

@Nikhil-Vats
Copy link
Contributor Author

Hey @mollfpr, conflicts resolved. You can retest.

@mollfpr
Copy link
Contributor

mollfpr commented Aug 8, 2023

Sorry for the delay, I'll give you an update shortly regarding the test.

@mollfpr
Copy link
Contributor

mollfpr commented Aug 8, 2023

@Nikhil-Vats The test on IOU flow only works for Web and mWeb. On Desktop, iOS, and Android, it redirects to the not found page after online.

We can skip the test on IOU flow and just put the test case for the emoji picker to be closed after being back online.

@Nikhil-Vats
Copy link
Contributor Author

Nikhil-Vats commented Aug 8, 2023

@mollfpr Okay, I will update the PR description to reflect that and create a separate issue for the IOU flow because for that report is also removed from LHN when user is redirected to 404 page.

@Nikhil-Vats
Copy link
Contributor Author

PR description updated.

@Nikhil-Vats
Copy link
Contributor Author

@mollfpr Please let me know if there's anything else left for me to do.

@mollfpr
Copy link
Contributor

mollfpr commented Aug 9, 2023

@Nikhil-Vats Looks good to me. I need to finish the test for Android.

Copy link
Contributor

@mollfpr mollfpr left a comment

Choose a reason for hiding this comment

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

LGTM and tests well 👍

@marcaaron marcaaron merged commit d1c4970 into Expensify:main Aug 9, 2023
13 checks passed
@OSBotify
Copy link
Contributor

OSBotify commented Aug 9, 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.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/marcaaron in version: 1.3.53-0 🚀

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

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/yuwenmemon in version: 1.3.53-2 🚀

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.

4 participants