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 for offline money request issues #32698

Merged
merged 27 commits into from
Jan 9, 2024

Conversation

rojiphil
Copy link
Contributor

@rojiphil rojiphil commented Dec 7, 2023

@fedirjh @blimpich

Details

This PR covers various offline scenarios during the deletion of Money Request in IOU Report. The issues are listed in detail under the Tests section.

Fixed Issues

$ #26511
PROPOSAL: #26511 (comment)

Tests

Issue 1:

Problem: When Offline, deleting the last Money Request (without any comments) in IOU Report removes Report Preview from parent Chat Report
Steps:

  1. Go Offline
  2. Add Money Request in Chat Report.
  3. Go to IOU Report for the Money Request
  4. Delete Money Request
  5. Verify the following: Report Preview should be shown with amount 0. Further, Money Request preview in IOU Report should also be shown with striked-out amount

Issue 2:

Problem: When Offline, Report Preview shows TBD on deletion of last Money Request in IOU Report with comments
Steps:

  1. Go Offline
  2. Add Money Request in Chat Report
  3. Go to IOU Report for Money Request
  4. Add a message in IOU Report
  5. Delete the only Money Request in IOU Report (created in Step 2)
  6. Go to parent Chat Report
  7. Verify the following: Amount 0 should be shown in Report Preview in Chat Report

Issue 3:

Problem : When Offline, Report Preview does not update amount when a new Money Request is added
Steps:

  1. Go Offline
  2. Add Money Request in 1:1 DM Chat Report (Note: Chat Report is not a Workspace Chat)
  3. Go to IOU Report for Money Request
  4. Add a message in IOU Report
  5. Delete the only Money Request in IOU Report (created in Step 2)
  6. Go to parent Chat Report.
  7. Go to IOU Report again by clicking on the Report Preview and add a new Money Request
  8. Go to parent Chat Report and review Report Preview amount.
  9. Verify the following: Report Preview amount should be updated with money request amount of step 7

Issue 4:

Problem : When Offline, IOU Report page shows blank on navigating back from parent Chat Report via click on Reply link
Steps:

  1. Go Offline
  2. Add Money Request in Chat Report
  3. Go to IOU Report for Money Request
  4. Add a message in IOU Report
  5. Go to parent Chat Report. Verify that the Report Preview shows with Reply Count.
  6. Click on Reply link to go to IOU Report
  7. IOU Report Screen should be shown instead of showing blank.
  • Verify that no errors appear in the JS console

Offline tests

Same as the Steps for Tests Section.

QA Steps

Same as the Steps for Tests Section.

  • 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 />.
    • [x ] 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
      • 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-Safari
Issue-1
26511-web-safari-01_r.mp4
Issue-2
26511-web-safari-02_r.mp4
Issue-3
26511-web-safari-03-.mp4
Issue-4
26511-web-safari-04-.mp4
Desktop
Issue-1
26511-desktop-01_r.mp4
Issue-2
26511-desktop-02_r.mp4
Issue-3
26511-6-desktop-03.mp4
Issue-4
26511-6-desktop-04.mp4
Mobile Web - Chrome
Issue-1
26511-mweb-chrome-01_r.mp4
Issue-2
26511-mweb-chrome-02_r.mp4
Issue-3
26511-5-mweb-chrome-03.mp4
Issue-4
26511-5-mweb-chrome-04.mp4
Mobile Web - Safari
Issue-1
26511-mweb-safari-01_r.mp4
Issue-2
26511-mweb-safari-02_r.mp4
Issue-3
26511-3-mweb-safari-03.mp4
Issue-4
26511-3-mweb-safari-04.mp4
iOS
Issue-1
26511-ios-native-01_r.mp4
Issue-2
26511-ios-native-02_r.mp4
Issue-3
26511-ios-native-03-.mp4
Issue-4
26511-ios-native-04-.mp4
Android
Issue-1
26511-android-native-01_r.mp4
Issue-2
26511-android-native-02.mp4
Issue-3
26511-4-android-native-03.mp4
Issue-4
26511-4-android-native-04.mp4

@rojiphil rojiphil marked this pull request as ready for review December 8, 2023 15:16
@rojiphil rojiphil requested a review from a team as a code owner December 8, 2023 15:16
@melvin-bot melvin-bot bot requested review from fedirjh and removed request for a team December 8, 2023 15:16
Copy link

melvin-bot bot commented Dec 8, 2023

@fedirjh 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]

@rojiphil rojiphil marked this pull request as draft December 9, 2023 02:31
@rojiphil
Copy link
Contributor Author

rojiphil commented Dec 9, 2023

@fedirjh

The PR is ready for review for the proposed issues.
I have tested across all platforms and it seems to work well.
Over to you for review.

@rojiphil
Copy link
Contributor Author

@fedirjh

While testing, I found one more issue which is as below.
Can you please check this and let me know if we can add this to the scope?

Issue 5:

Please re-state the problem that we are trying to solve in this issue.

Problem : When Offline, deletion of a Money Request which has visible comments does not show greyed Money Request review in IOU Report
Steps:
1 Go Offline
2 Add Money Request (A) in Chat Report
3 Go to IOU Report for Money Request
4 Add a message to the IOU Report.
5 Click on the Money Request Preview for (A) to show the Transaction Thread.
6 Add a message to Transaction Thread
7 Delete the Money Request using 3dots menu. Verify that the focus comes back to IOU Report.
Actual Result: Deleted request is displayed for the deleted Money Request in offline scenario.
Expected Result: When offline, greyed Money Request preview should still be shown instead of Deleted request

Issue-5 Video
26511-Issue-5.mp4

What is the root cause of that problem?

Here, we check if we need to show the preview or the deleted/reversed transaction message. During deletion of Money Request, we set the pending action as delete or update here. However, when offline, we do not use this information to decide on showing the preview even when there is a delete or update pending action. This is the root cause.

What changes do you think we should make in order to solve the problem?

  1. We can check for pending action and show the preview instead of the deleted/reversed transaction text here like this.
    const isOfflinePendingForDeleteOrUpdate =
        network.isOffline &&
        (lodashGet(action, 'pendingAction', null) === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE || lodashGet(action, 'pendingAction', null) === CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE);

    return (isDeletedParentAction || isReversedTransaction) && !isOfflinePendingForDeleteOrUpdate ? (
  1. Also, pass the isOfflinePendingForDeleteOrUpdate to MoneyRequestPreview here like this:

         isOfflinePendingForDeleteOrUpdate={isOfflinePendingForDeleteOrUpdate}
    
  2. Further, in MoneyRequestPreview, we must add a boolean property for isOfflinePendingForDeleteOrUpdate.

Then, use isOfflinePendingForDeleteOrUpdate to ensure that a) the original amount text is displayed instead of the updated amount and b) Line through style is applied to the amount.

That is, use isOfflinePendingForDeleteOrUpdate for display amount here with const displayAmount = isOfflinePendingForDeleteOrUpdate ? getDisplayDeleteAmountText() : getDisplayAmountText();

and line through style here with isOfflinePendingForDeleteOrUpdate && styles.lineThrough,

What alternative solutions did you explore? (Optional)

Copy link
Contributor

@fedirjh fedirjh left a comment

Choose a reason for hiding this comment

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

@rojiphil Thank you the work here , I just updated my xcode and got some issues with my simulator, I couldn’t test it in IOS. I will try to run the checklist by tomorrow.

@@ -524,7 +524,7 @@ function ReportActionItem(props) {
{shouldDisplayThreadReplies && (
<View style={draftMessageRightAlign}>
<ReportActionItemThread
childReportID={`${props.action.childReportID}`}
childReportID={`${props.action.childReportID || ReportActionsUtils.getIOUReportIDFromReportActionPreview(props.action)}`}
Copy link
Contributor

Choose a reason for hiding this comment

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

@rojiphil As you have already updated the optimistic data , there is no further need for this code.

Copy link
Contributor Author

@rojiphil rojiphil Dec 14, 2023

Choose a reason for hiding this comment

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

Got it. I have removed the redundant code.

Comment on lines 378 to 381
// Ignore Report Preview as last action for LHN display if the action is deleted and is also pending for deletion.
if (isReportPreviewAction(reportAction) && isMessageDeleted(reportAction) && reportAction.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) {
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please explain a little bit this one, what to ignore ? and why we have to do it ?

Copy link
Contributor Author

@rojiphil rojiphil Dec 14, 2023

Choose a reason for hiding this comment

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

Could you please explain a little bit this one, what to ignore ? and why we have to do it ?

Sure. Here we use shouldReportActionBeVisibleAsLastAction to check if an action (in our case Report Preview action) can be considered as last Report Action for display of LHN subtitle display text for the Chat Report.

Before our fix, the Report Preview action was deleted in offline scenarios because of which LHN would display the subtitle text of the action that was immediately previous to the deleted Report Preview. Now, since we do not remove the Report Preview in offline scenario until app comes online, the last action would turn up to be the Report Preview thereby resulting in the text message of Report Preview as subtitle in LHN. So, we need to ignore the Report Preview action as last action for LHN if the IOU Report is deleted offline. This is the reason why we added the condition here.

So, here, we ignore the Report Preview if the message was deleted as set here and if the pending action is delete which we set here. In all other cases, we will not ignore and show the Report Preview text in LHN.

Hope this will suffice. Please let me know otherwise.

Copy link
Contributor

@fedirjh fedirjh Dec 21, 2023

Choose a reason for hiding this comment

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

@rojiphil Why we can't just dispaly the action as it is in offline ? when user goes online , it will be deleted and removed from Onyx. why not keeping it visible in offline ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have responded here.
Let me know what you think.

@rojiphil
Copy link
Contributor Author

rojiphil commented Dec 30, 2023

I encountered this weird bug, go offline and create some requests and delete them, then send new comments inside the IOU report, then send a new request and go online.

  • This PR allows me to consistently reproduce the bug on all platforms.
  • I suspect that the changes made in this PR are related to the bug.
  • I believe that both the frontend and backend are responsible for reproducing this bug.

I was able to reproduce without adding any comments inside the IOU report.

@fedirjh
Issue 1:
I will investigate further today and get back.
Also, if you are following some simple steps to reproduce the issue, can you please share?
This will help me in my investigation too.

@fedirjh
Copy link
Contributor

fedirjh commented Dec 30, 2023

Also, if you are following some simple steps to reproduce the issue, can you please share?

@rojiphil Just test with a new report with another user:

  1. Go offline
  2. Add new money request inside the report
  3. Delete the money request
  4. Add other money requests inside the same report
  5. Go to the main report
  6. Go online
  7. check the IOU preview disappear for a moment
  8. once the preview is back, navigate to the IOU report
  9. Check the IOU report

@rojiphil
Copy link
Contributor Author

I also noticed another bug , the IOU report preview disappears for some moments when you go back online. Here is a video on dev demonstrating the bug:

Issue 2:
Thanks for the test video that demonstrates the bug.
I will investigate this too.

@rojiphil
Copy link
Contributor Author

Just test with a new report with another user:

  1. Go offline
  2. Add new money request inside the report
  3. Delete the money request
  4. Add other money requests inside the same report
  5. Go to the main report
  6. Go online
  7. check the IOU preview disappear for a moment
  8. once the preview is back, navigate to the IOU report
  9. Check the IOU report

@fedirjh

Thanks for the steps. That was a good catch. And the steps were also helpful in investigating this.

The root cause is that after deleting the last Money Request in offline scenarios (Step 3), FE continues to add any further Money Requests (Step 4) to the same IOU Report. The BE is expecting no activity in the IOU Report once the last Money Request is deleted. The BE even creates a new IOU Report to honor subsequent money requests.

So, looks like the fix from the FE is to ensure that all subsequent Money Requests are considered part of a new IOU Report. We can do so by resetting the iouReportID to null as it was already done here. This will make sure that it will create a new IOU Report as shown here. This change seems to avoid both Issue 1 (i.e. unwanted actions in deleted IOU Report) and Issue 2 (i.e. Report Preview disappearing for few seconds) in the tests.

I have committed the changes. Let me know if this is fine.

@rojiphil
Copy link
Contributor Author

@fedirjh

But there is one more related issue I see. When offline, the user can go to the deleted IOU Report and attempt further actions using composer FAB which does not seem right.
Do you think hiding the composer makes sense here?

We can add a property hideComposer to ReportFooter and use the condition like this here.

hideComposer={report.type === CONST.REPORT.TYPE.IOU && parentReportAction.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE}

Let me know what you think.

@fedirjh
Copy link
Contributor

fedirjh commented Jan 2, 2024

But there is one more related issue I see. When offline, the user can go to the deleted IOU Report and attempt further actions using composer FAB which does not seem right.

@rojiphil I think we can do similar to settled reports , we can remove the money request option from the composer action list

Screenshot 2024-01-02 at 9 17 30 AM

@rojiphil
Copy link
Contributor Author

rojiphil commented Jan 2, 2024

I think we can do similar to settled reports , we can remove the money request option from the composer action list

@fedirjh
That is a better thing to do than hiding everything.
For this, we can add changes like this here to resolve this.

        // If the Money Request report is marked for deletion, let us prevent any further money requests from being generated.
        const parentReportAction = ReportActionsUtils.getReportAction(report?.parentReportID ?? '', report?.parentReportActionID ?? '');
        if (parentReportAction?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) {
            return false;
        }

This tests well too. I have committed these changes.
Let me know if this is fine.

@rojiphil
Copy link
Contributor Author

rojiphil commented Jan 5, 2024

@fedirjh
Gentle bump on reviewing the latest commits.

@fedirjh
Copy link
Contributor

fedirjh commented Jan 5, 2024

@rojiphil I just retested it and it looks good now. However, I found another case that we should cover. When offline, if you create a money request and then delete it, you will still be able to submit other comments inside the IOU report. However, when the user goes online, the IOU will be deleted and the comments will be lost. I think the problem arises from the backend; when the report is empty, at some point the server removes the IOU report and any further comments sent to that report will be lost. I think we should disable the composer when the last money request, inside an IOU report that doesn’t have any comments, is removed. With this fix, all aspects should be resolved, and we can proceed with the merge.

Steps to reproduce

  1. Go offline
  2. Request money
  3. Open IOU
  4. Verify IOU onlu has one request
  5. Delete the money reuest
  6. Send new comment
  7. Go online
  8. IOU report is removed and comment is lost

@fedirjh
Copy link
Contributor

fedirjh commented Jan 5, 2024

@rojiphil As for hiding the composer, I think we can make an update to this util function canUserPerformWriteAction

function canUserPerformWriteAction(report: OnyxEntry<Report>) {

@rojiphil
Copy link
Contributor Author

rojiphil commented Jan 5, 2024

As for hiding the composer, I think we can make an update to this util function canUserPerformWriteAction

@fedirjh
Yes. That's a good place to make changes.
So, the change can look like this in canUserPerformWriteAction

    // If the Money Request report is marked for deletion, let us prevent any further write action.
    if (isMoneyRequestReport(report)) {
        const parentReportAction = ReportActionsUtils.getReportAction(report?.parentReportID ?? '', report?.parentReportActionID ?? '');
        if (parentReportAction?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) {
            return false;
        }
    }

Tested and works well for me. I have committed the changes as well.
Let me know if this is fine.

Copy link
Contributor

@fedirjh fedirjh left a comment

Choose a reason for hiding this comment

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

This looks good and tests well.

@melvin-bot melvin-bot bot requested a review from blimpich January 8, 2024 20:14
Copy link
Contributor

@blimpich blimpich left a comment

Choose a reason for hiding this comment

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

Great work! Thank you @rojiphil and thank you @fedirjh for doing a thorough review 🙂

Approved ✅

@blimpich blimpich merged commit 35a6916 into Expensify:main Jan 9, 2024
16 of 17 checks passed
@OSBotify
Copy link
Contributor

OSBotify commented Jan 9, 2024

✋ 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/blimpich in version: 1.4.24-0 🚀

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

@blimpich
Copy link
Contributor

This PR appears to have caused this deploy blocker. @rojiphil @fedirjh can you take a look soon and see if we can get a fix out quickly for this? Looking at the PR its not immediately clear to me what is causing the issue. Without a fix we'll have to revert.

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/thienlnam in version: 1.4.24-3 🚀

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