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

Web - Workspace - IOU moves in the LHN every time the merchant is changed #38425

Closed
1 of 6 tasks
kbecciv opened this issue Mar 15, 2024 · 28 comments
Closed
1 of 6 tasks
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 Engineering

Comments

@kbecciv
Copy link

kbecciv commented Mar 15, 2024

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Version Number: 1.4.53.1
Reproducible in staging?: y
Reproducible in production?: n
If this was caught during regression testing, add the test name, ID and link from TestRail: https://expensify.testrail.io/index.php?/tests/view/4428435&group_by=cases:section_id&group_id=294998&group_order=asc
Issue reported by: Applause - Internal Team

Action Performed:

  1. Admin: Log in with a new Gmail account
  2. Admin: Create a workspace
  3. Admin: Invite a member to the workspace
  4. Member: Create a scan IOU in the workspace chat
  5. Member: Open the IOU and add the "Amount" and "Merchant" fields manually
  6. Admin: Open the IOU and edit the "Merchant" field

Expected Result:

It shouldn't move. If an order change is needed due to the unread status, it should only happen once.

Actual Result:

IOU moves in the LHN every time the merchant is changed.

Workaround:

Unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android: Native
  • Android: mWeb Chrome
  • iOS: Native
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence

Bug6415247_1710525981908.bandicam_2024-03-15_18-47-10-675.mp4

View all open jobs on GitHub

@kbecciv kbecciv added the DeployBlockerCash This issue or pull request should block deployment label Mar 15, 2024
Copy link
Contributor

👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open `StagingDeployCash` deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:

  1. Identify the pull request that introduced this issue and revert it.
  2. Find someone who can quickly fix the issue.
  3. Fix the issue yourself.

Copy link

melvin-bot bot commented Mar 15, 2024

Triggered auto assignment to @hayata-suenaga (Engineering), see https://stackoverflowteams.com/c/expensify/questions/9980/ for more details.

@kbecciv
Copy link
Author

kbecciv commented Mar 15, 2024

We think that this bug might be related to #wave-collect - Release 1

@kbecciv
Copy link
Author

kbecciv commented Mar 15, 2024

Issue is not reproduce in Prod

bandicam.2024-03-15.22-26-02-304.mp4

@hayata-suenaga
Copy link
Contributor

taking a look at this issue

@hayata-suenaga
Copy link
Contributor

@hayata-suenaga
Copy link
Contributor

asking for help in Slack

@paultsimura
Copy link
Contributor

paultsimura commented Mar 15, 2024

This might be considered a regression from #38027 – now, every time we update the MoneyRequest field, we call OpenReport because of this hook:

// If a user has chosen to leave a thread, and then returns to it (e.g. with the back button), we need to call `openReport` again in order to allow the user to rejoin and to receive real-time updates
useEffect(() => {
if (!isFocused || prevIsFocused || !ReportUtils.isChatThread(report) || report.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) {
return;
}
Report.openReport(report.reportID);
// We don't want to run this useEffect every time `report` is changed
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [prevIsFocused, report.notificationPreference, isFocused]);

The reason why the issue happens is that on updating the money request, we set the hasOutstandingChildRequest: false for the chat report in the optimistic data – that's why the chat report moves below the money request in LHN – it has to RBR for a moment. But after we call OpenReport, the chat report gets updated with hasOutstandingChildRequest: true, and the RBR appears again, moving the chat report above the open Money Request.

However, I would blame this PR: #34866 – it changed the way we calculate the optimistic hasOutstandingChildRequest, so now we are setting it to false, when we shouldn't.

@paultsimura
Copy link
Contributor

paultsimura commented Mar 15, 2024

Proposal

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

The chat report's GBR disappears for a moment when modifying the money request data.

Note: this shouldn't really be a blocker, because the version on Staging only allowed this bug to be more visible – it exists in Prod as well.

What is the root cause of that problem?

The reason why the issue happens is that on updating the money request, we set the hasOutstandingChildRequest: false for the chat report in the optimistic data – that's why the chat report moves below the money request in LHN – it has no GBR for a moment.

In this PR, we've added the logic for calculating the optimistic hasOutstandingChildRequest:

App/src/libs/actions/IOU.ts

Lines 1261 to 1262 in 2979e3c

hasOutstandingChildRequest:
iouReport && needsToBeManuallySubmitted(iouReport) && updatedMoneyRequestReport.managerID === userAccountID && updatedMoneyRequestReport.total !== 0,

However, this code doesn't work as expected. e.g. it strongly checks needsToBeManuallySubmitted(iouReport) for every iouReport, but I should have the GBR if I'm the admin of the workspace even if the request doesn't need to be manually submitted. Also, the mentioned PR broke the existing logic: #33030 (the first test).

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

First, we should modify the getOutstandingChildRequest to correctly calculate the GBR for different scenarios (it may require some further alterations, need to test different cases deeper):

function getOutstandingChildRequest(policy: OnyxEntry<Policy> | EmptyObject, iouReport: OnyxEntry<Report> | EmptyObject): OutstandingChildRequest {
    if (!iouReport || isEmptyObject(iouReport)) {
        return {};
    }

    if (!isPolicyExpenseChat(iouReport)) {
        return {
            hasOutstandingChildRequest: iouReport.managerID === currentUserAccountID && iouReport.total !== 0,
        };
    }

    if (!needsToBeManuallySubmitted(iouReport)) {
        return {
            hasOutstandingChildRequest: false,
        };
    }

    if (PolicyUtils.isPolicyAdmin(policy)) {
        return {
            hasOutstandingChildRequest: true,
        };
    }

    // We don't need to update hasOutstandingChildRequest in this case
    return {};
}

App/src/libs/actions/IOU.ts

Lines 419 to 438 in 5770e23

/**
* Return the object to update hasOutstandingChildRequest
*/
function getOutstandingChildRequest(policy: OnyxEntry<OnyxTypes.Policy> | EmptyObject, iouReport: OnyxTypes.Report): OutstandingChildRequest {
if (!needsToBeManuallySubmitted(iouReport)) {
return {
hasOutstandingChildRequest: false,
};
}
if (PolicyUtils.isPolicyAdmin(policy)) {
return {
hasOutstandingChildRequest: true,
};
}
return {
hasOutstandingChildRequest: iouReport.managerID === userAccountID && iouReport.total !== 0,
};
}

Second, use this function instead of the incorrect custom checks:

        {
            onyxMethod: Onyx.METHOD.MERGE,
            key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport?.parentReportID}`,
            value: ReportUtils.getOutstandingChildRequest(policy, updatedMoneyRequestReport),
        },

App/src/libs/actions/IOU.ts

Lines 1257 to 1264 in 5770e23

{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport?.parentReportID}`,
value: {
hasOutstandingChildRequest:
iouReport && needsToBeManuallySubmitted(iouReport) && updatedMoneyRequestReport.managerID === userAccountID && updatedMoneyRequestReport.total !== 0,
},
},

App/src/libs/actions/IOU.ts

Lines 3029 to 3035 in 5770e23

{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport?.reportID}`,
value: {
hasOutstandingChildRequest: iouReport && needsToBeManuallySubmitted(iouReport) && updatedIOUReport?.managerID === userAccountID && updatedIOUReport.total !== 0,
},
},

What alternative solutions did you explore? (Optional)

@hayata-suenaga
Copy link
Contributor

@paultsimura, I opened a PR to implement the fix you suggested. As you're also a C+, I assigned in the PR as a reviewer.

@paultsimura
Copy link
Contributor

Updated proposal: #38425 (comment)
Added more details after deeper testing of the initial PR.

@hayata-suenaga
Copy link
Contributor

@paultsimura let's go with your updated proposal. Please open a PR when you have time 🙇

@situchan
Copy link
Contributor

Looks like I was recommended as C+ 😄
Happy to help

@hayata-suenaga
Copy link
Contributor

I'm sorry @situchan, but a C+ seems to be automatically assigned to the PR and they already reviewed it 🙇

@hayata-suenaga hayata-suenaga assigned akinwale and unassigned situchan Apr 3, 2024
@paultsimura
Copy link
Contributor

I'm sorry @situchan, but a C+ seems to be automatically assigned to the PR and they already reviewed it 🙇

It's OK, Situ went OOO and asked to re-assign this issue 👍

Copy link

melvin-bot bot commented Apr 9, 2024

⚠️ Looks like this issue was linked to a Deploy Blocker here

If you are the assigned CME please investigate whether the linked PR caused a regression and leave a comment with the results.

If a regression has occurred and you are the assigned CM follow the instructions here.

If this regression could have been avoided please consider also proposing a recommendation to the PR checklist so that we can avoid it in the future.

@paultsimura
Copy link
Contributor

This was deployed to production yesterday, the automation didn't work: #38675 (comment)

@hayata-suenaga hayata-suenaga added Awaiting Payment Auto-added when associated PR is deployed to production and removed Reviewing Has a PR in review Awaiting Payment Auto-added when associated PR is deployed to production labels Apr 11, 2024
@paultsimura
Copy link
Contributor

This is due payment tomorrow.
@hayata-suenaga could you please add a corresponding label to assign a BZ member?

@hayata-suenaga hayata-suenaga added the Awaiting Payment Auto-added when associated PR is deployed to production label Apr 16, 2024
@hayata-suenaga
Copy link
Contributor

sorry about that. apparently, i added and then removed the label 😆

@paultsimura
Copy link
Contributor

Also @akinwale bump for a checklist, please 🙏

@paultsimura
Copy link
Contributor

@hayata-suenaga I'm not sure that was the correct label though because it didn't assign a BZ member. I think you should have added & removed the External & Help Wanted labels first 🤔

@akinwale
Copy link
Contributor

akinwale commented Apr 17, 2024

@hayata-suenaga @paultsimura I believe adding the Bug label should assign a BZ member.

@akinwale
Copy link
Contributor

akinwale commented Apr 17, 2024

  • [@akinwale] The PR that introduced the bug has been identified. Link to the PR:
  • [@akinwale] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment:
  • [@akinwale] A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion:

Likely regression from #34866, where the way the value for hasOutstandingChildRequest is determined was changed.

  • [@akinwale] Determine if we should create a regression test for this bug.
  • [@akinwale] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.

Regression Test Steps

Test 1

  1. Launch Expensify.
  2. Request money from a workspace that you own.
  3. Open the report for the IOU request.
  4. Set the device offline.
  5. Modify the amount on the request.
  6. Verify that the GBR is displayed for the workspace chat in the LHN.
  7. Go back online.
  8. Verify that the GBR is still visible for the workspace chat in the LHN.

Test 2 (Scheduled Submit disabled)

Prerequisites

  • Log in as an employee in a Collect workspace with the Scheduled Submit option disabled
  • The employee has no pending money requests in the workspace
  1. Go offline on the device.
  2. Request money from the workspace.
  3. Verify that the GBR is displayed for the workspace chat in the LHN.
  4. Go back online.
  5. Verify that the GBR is still visible for the workspace chat in the LHN.

Test 3 (Scheduled Submit enabled)

Prerequisites

  • Log in as an employee in a Collect workspace with the Scheduled Submit option enabled
  • The employee has no pending money requests in the workspace
  1. Go offline on the device.
  2. Request money from the workspace.
  3. Verify that the GBR is not displayed for the workspace chat in the LHN.
  4. Go back online.
  5. Verify that the GBR is still not visible for the workspace chat in the LHN.

Test 4

Prerequisite: The money request currency should match the workspace currency

  • Log in to Expensify as user A and user B on different devices
  • Request money from each user as the other as follows:
    • User A to User B: Request $20
    • User B to User A: Request $10

As User A

  1. Verify that the GBR is not displayed on the chat report with B in the LHN.
  2. Go offline on the device.
  3. Edit the amount on the request to $5
  4. Verify that the GBR is displayed on the chat report with user B as A now owes money to B.
  5. Go back online.
  6. Verify that the GBR is still displayed.
  7. Go offline again.
  8. Create a new request to user B, with the total amount being larger than what B requested from A ($10). For example, send a request for $10, so that the total amount becomes $15 ($10 + $5).
  9. Verify that the GBR is not displayed on the chat report with user B as A does not owe money to B.
  10. Go back online.
  11. Verify that the GBR is still not displayed.
  12. Go offline again.
  13. Delete the request created in step 8 ($10).
  14. Verify that the GBR is displayed on the chat report with user B as A now owes money to B.
  15. Go back online.
  16. Verify that the GBR is still displayed.

Do we agree 👍 or 👎?

@hayata-suenaga hayata-suenaga added the Bug Something is broken. Auto assigns a BugZero manager. label Apr 17, 2024
Copy link

melvin-bot bot commented Apr 17, 2024

Triggered auto assignment to @laurenreidexpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

@laurenreidexpensify
Copy link
Contributor

@paultsimura @akinwale offers sent in Upwork 👍

@akinwale
Copy link
Contributor

@laurenreidexpensify Accepted. Thanks!

@paultsimura
Copy link
Contributor

@laurenreidexpensify accepted, thanks

@laurenreidexpensify
Copy link
Contributor

Payment Summary:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 Engineering
Projects
None yet
Development

No branches or pull requests

6 participants