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

[HOLD for payment 2024-07-22] [HOLD for payment 2024-07-17] [$250] Optimistic map missing when tracking distance expense #41653

Closed
6 tasks done
m-natarajan opened this issue May 5, 2024 · 53 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Internal Requires API changes or must be handled by Expensify staff Weekly KSv2

Comments

@m-natarajan
Copy link

m-natarajan commented May 5, 2024

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 1.4.70-2
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by: @neil-marcellini
Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1714782868884039

Action Performed:

  1. Go to a workspace chat
  2. Delete any existing tracked expenses if needed
  3. Click plus and track expense
  4. Choose distance, enter waypoints, Next, Track Expense

Expected Result:

Expense appears optimistically showing a map, the amount, and the merchant with distance info. After the response the same thing should be shown, although the map is expected to be slightly different.

Actual Result:

Expense appears optimistically showing the amount and the merchant with distance info only, no map. After the response it displays correctly.

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

Screen.Recording.2024-06-26.at.8.43.14.AM.mov

Add any screenshot/video evidence

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~017f6ca9bb1a7123b8
  • Upwork Job ID: 1787504876858716160
  • Last Price Increase: 2024-06-10
Issue OwnerCurrent Issue Owner: @
Issue OwnerCurrent Issue Owner: @JmillsExpensify
@m-natarajan m-natarajan added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels May 5, 2024
Copy link

melvin-bot bot commented May 5, 2024

Triggered auto assignment to @JmillsExpensify (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.

@m-natarajan m-natarajan added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. and removed Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels May 5, 2024
Copy link

melvin-bot bot commented May 5, 2024

Current assignee @JmillsExpensify is eligible for the Bug assigner, not assigning anyone new.

@Krishna2323
Copy link
Contributor

Krishna2323 commented May 5, 2024

Proposal

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

Report preview doesn't show distance merchant for tracked workspace expense

What is the root cause of that problem?

The description/merchant is only shown when numberOfRequests is 1 and buildOptimisticReportPreview returns 1 for childMoneyRequestCount, but when we get data from backend the childMoneyRequestCount is again set to 0.

childMoneyRequestCount: 1,

const numberOfRequests = ReportActionUtils.getNumberOfMoneyRequests(action);

let formattedMerchant = numberOfRequests === 1 ? TransactionUtils.getMerchant(allTransactions[0]) : null;

The map shouldn't be shown optimistically instead ReceiptGeneric should be shown. This is also what we do when we create submit expense distance request but the ReceiptGeneric also isn't shown because we haven't included in optimistic transaction.

App/src/libs/actions/IOU.ts

Lines 2027 to 2044 in ab1e924

let optimisticTransaction = TransactionUtils.buildOptimisticTransaction(
ReportUtils.isExpenseReport(iouReport) ? -amount : amount,
currency,
shouldUseMoneyReport && iouReport ? iouReport.reportID : '0',
comment,
created,
'',
'',
merchant,
receiptObject,
filename,
existingTransactionID ?? null,
category,
tag,
billable,
isDistanceRequest ? {waypoints: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD} : undefined,
false,
);

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

We can check for number of transaction(allTransactions.length) instead of numberOfRequests (money request) to show/hide the merchant/description and for the receipt we need to pass optimisticReceipt instead of receiptObject when isDistanceRequest is true.

   // getTrackExpenseInformation util function changes
    const optimisticReceipt: Receipt = {
        source: ReceiptGeneric as ReceiptSource,
        state: CONST.IOU.RECEIPT_STATE.OPEN,
    };
    const existingTransaction = allTransactionDrafts[`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${existingTransactionID ?? CONST.IOU.OPTIMISTIC_TRANSACTION_ID}`];
    const isDistanceRequest = existingTransaction && existingTransaction.iouRequestType === CONST.IOU.REQUEST_TYPE.DISTANCE;
    let optimisticTransaction = TransactionUtils.buildOptimisticTransaction(
        ReportUtils.isExpenseReport(iouReport) ? -amount : amount,
        currency,
        shouldUseMoneyReport && iouReport ? iouReport.reportID : '0',
        comment,
        created,
        '',
        '',
        merchant,
        isDistanceRequest ? optimisticReceipt : receiptObject,
        filename,
        existingTransactionID ?? null,
        category,
        tag,
        billable,
        isDistanceRequest ? {waypoints: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD} : undefined,
        false,
    );
    
    // In ReportPreview.tsx
    const allTransactions = TransactionUtils.getAllReportTransactions(iouReportID);
    const numberOfRequests = allTransactions.length;

What alternative solutions did you explore? (Optional)

Result

report_preview_track_expense.mp4

@neil-marcellini neil-marcellini added the External Added to denote the issue can be worked on by a contributor label May 6, 2024
@melvin-bot melvin-bot bot changed the title Report preview doesn't show distance merchant for tracked workspace expense [$250] Report preview doesn't show distance merchant for tracked workspace expense May 6, 2024
Copy link

melvin-bot bot commented May 6, 2024

Job added to Upwork: https://www.upwork.com/jobs/~017f6ca9bb1a7123b8

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label May 6, 2024
Copy link

melvin-bot bot commented May 6, 2024

Triggered auto assignment to Contributor-plus team member for initial proposal review - @parasharrajat (External)

@parasharrajat
Copy link
Member

parasharrajat commented May 6, 2024

The map shouldn't be shown optimistically instead ReceiptGeneric should be shown. This is also what we do when we create submit expense distance request but the ReceiptGeneric also isn't shown because we haven't included in optimistic transaction.

@neil-marcellini Is this something we are expecting #41653 (comment)?

Or we show map while online and ReceiptGeneric while offline.

@nkdengineer
Copy link
Contributor

Proposal

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

Expense appears optimistically showing the amount and the merchant with distance info only, no map. After the response it shows the map and the amount only.

What is the root cause of that problem?

  1. When we create a track expense, we update childMoneyRequestCount in optimistic data but BE doesn't expect that so after API is complete, the merchant in preview disappears.

let formattedMerchant = numberOfRequests === 1 ? TransactionUtils.getMerchant(allTransactions[0]) : null;

  1. We don't create a optimistic receipt as we do here so the preview doesn't show ReceiptGeneric

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

  1. Because the track-expense doesn't increase the childMoneyRequestCount, we should get numberOfTransactions here by filtering the transaction that isn't deleted from allTransactions and then use it in the condition to show merchant, description
const numberOfTransactions = allTransactions.filter((transaction) => transaction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE).length;

let formattedMerchant = numberOfTransactions === 1 ? TransactionUtils.getMerchant(allTransactions[0]) : null;
const formattedDescription = numberOfTransactions === 1 ? TransactionUtils.getDescription(allTransactions[0]) : null;

const shouldShowSingleRequestMerchantOrDescription =
numberOfTransactions === 1 && (!!formattedMerchant || !!formattedDescription) && !(hasOnlyTransactionsWithPendingRoutes && !totalDisplaySpend);

let formattedMerchant = numberOfRequests === 1 ? TransactionUtils.getMerchant(allTransactions[0]) : null;

OPTIONAL: We can also count the number of track-expenses and display it in the support text here

supportText: translate('iou.expenseCount', {

  1. We shouldn't increase childMoneyRequestCount of REPORTPREVIEW action when we create a track-expense since it's not the expected from BE and childMoneyRequestCount is also used to display the number of expenses in ReportPreview.

  2. We should update the receiptObject as we do here if the transaction is the distance request

if (isDistanceRequest) {
    receiptObject.source = ReceiptGeneric as ReceiptSource,
    receiptObject.state = CONST.IOU.RECEIPT_STATE.OPEN
}

const receiptObject: Receipt = {};

What alternative solutions did you explore? (Optional)

NA

@kaushiktd
Copy link
Contributor

kaushiktd commented May 7, 2024

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

Report preview doesn't show distance merchant for tracked workspace expense

What is the root cause of that problem?

The inconsistency between the optimistic data and the backend response stems from the handling of childMoneyRequestCount. Initially, during expense creation, the optimistic data sets childMoneyRequestCount to 1, leading to an optimistic display showing only the amount and merchant with distance information but no map. However, upon receiving the backend response, childMoneyRequestCount is reset to 0. Consequently, the optimistic display only shows the map and amount.
Cause:
The getNumberOfMoneyRequests function determines the display of expense details in the optimistic state based on childMoneyRequestCount. This count is set to 1 in the optimistic data during initial expense creation but is reset to 0 in the backend response.

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

To ensure consistency between the optimistic and backend states and address the issue of differing displays, we propose using childStatusNum instead of childMoneyRequestCount in the getNumberOfMoneyRequests function. Given that childStatusNum is always set to 1 during expense creation, it provides a reliable basis for determining the display of expense details optimistically.

function getNumberOfMoneyRequests(reportPreviewAction: OnyxEntry<ReportAction>): number {

function getNumberOfMoneyRequests(reportPreviewAction: OnyxEntry<ReportAction>): number {

    return reportPreviewAction?.childStatusNum ?? 0;
}

Video:

https://drive.google.com/file/d/1Ali5HXxIeN_qo7Ky4xRWjOp1yfUeGfDG/view?usp=sharing

@neil-marcellini
Copy link
Contributor

The map shouldn't be shown optimistically instead ReceiptGeneric should be shown. This is also what we do when we create submit expense distance request but the ReceiptGeneric also isn't shown because we haven't included in optimistic transaction.

@neil-marcellini Is this something we are expecting #41653 (comment)?

Or we show map while online and ReceiptGeneric while offline.

As mentioned in the issue description expected result, it should show the map optimistically (for the online case). While offline we should show a pending view. That's getting handled in this PR #39243. Maybe we can just focus on the merchant info for now, and see if we need to fix the map later?

@parasharrajat
Copy link
Member

parasharrajat commented May 8, 2024

Maybe we can just focus on the merchant info for now, and see if we need to fix the map later?

Got it. Thanks. I will focus on showing merchant info for now.

Copy link

melvin-bot bot commented May 13, 2024

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

@melvin-bot melvin-bot bot added the Overdue label May 13, 2024
@parasharrajat
Copy link
Member

parasharrajat commented May 13, 2024

@Gonals Trying to understand the correct behaviour here around childMoneyRequestCount which was added in #23651. Should childMoneyRequestCount increase as well for track expenses?

@melvin-bot melvin-bot bot removed the Overdue label May 13, 2024
Copy link

melvin-bot bot commented May 13, 2024

@JmillsExpensify, @parasharrajat, @neil-marcellini Eep! 4 days overdue now. Issues have feelings too...

Copy link

melvin-bot bot commented May 17, 2024

@JmillsExpensify, @parasharrajat, @neil-marcellini Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

@melvin-bot melvin-bot bot added Weekly KSv2 and removed Weekly KSv2 labels Jul 1, 2024
@neil-marcellini
Copy link
Contributor

@parasharrajat the PR is ready for review.

@parasharrajat
Copy link
Member

Will review it in 1 hour.

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels Jul 10, 2024
@melvin-bot melvin-bot bot changed the title [$250] Optimistic map missing when tracking distance expense [HOLD for payment 2024-07-17] [$250] Optimistic map missing when tracking distance expense Jul 10, 2024
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Jul 10, 2024
Copy link

melvin-bot bot commented Jul 10, 2024

Reviewing label has been removed, please complete the "BugZero Checklist".

Copy link

melvin-bot bot commented Jul 10, 2024

The solution for this issue has been 🚀 deployed to production 🚀 in version 9.0.5-13 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

If no regressions arise, payment will be issued on 2024-07-17. 🎊

For reference, here are some details about the assignees on this issue:

Copy link

melvin-bot bot commented Jul 10, 2024

BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

  • [@parasharrajat] The PR that introduced the bug has been identified. Link to the PR:
  • [@parasharrajat] 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:
  • [@parasharrajat] 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:
  • [@parasharrajat] Determine if we should create a regression test for this bug.
  • [@parasharrajat] 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.
  • [@JmillsExpensify] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

@parasharrajat parasharrajat removed their assignment Jul 10, 2024
@melvin-bot melvin-bot bot added Weekly KSv2 and removed Weekly KSv2 labels Jul 15, 2024
@melvin-bot melvin-bot bot changed the title [HOLD for payment 2024-07-17] [$250] Optimistic map missing when tracking distance expense [HOLD for payment 2024-07-22] [HOLD for payment 2024-07-17] [$250] Optimistic map missing when tracking distance expense Jul 15, 2024
Copy link

melvin-bot bot commented Jul 15, 2024

The solution for this issue has been 🚀 deployed to production 🚀 in version 9.0.6-8 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

If no regressions arise, payment will be issued on 2024-07-22. 🎊

Copy link

melvin-bot bot commented Jul 15, 2024

BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

  • [@neil-marcellini] The PR that introduced the bug has been identified. Link to the PR:
  • [@neil-marcellini] 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:
  • [@neil-marcellini] 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:
  • [@neil-marcellini] Determine if we should create a regression test for this bug.
  • [@neil-marcellini] 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.
  • [@JmillsExpensify] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

@melvin-bot melvin-bot bot added Daily KSv2 Overdue and removed Weekly KSv2 labels Jul 16, 2024
Copy link

melvin-bot bot commented Jul 22, 2024

Skipping the payment summary for this issue since all the assignees are employees or vendors. If this is incorrect, please manually add the payment summary SO.

Copy link

melvin-bot bot commented Jul 23, 2024

@JmillsExpensify, @neil-marcellini 6 days overdue. This is scarier than being forced to listen to Vogon poetry!

Copy link

melvin-bot bot commented Jul 30, 2024

@JmillsExpensify, @neil-marcellini 12 days overdue now... This issue's end is nigh!

@melvin-bot melvin-bot bot added Weekly KSv2 and removed Daily KSv2 labels Aug 1, 2024
Copy link

melvin-bot bot commented Aug 1, 2024

This issue has not been updated in over 14 days. @JmillsExpensify, @neil-marcellini eroding to Weekly issue.

@melvin-bot melvin-bot bot removed the Overdue label Aug 1, 2024
@JmillsExpensify
Copy link

It looks like the PR was never C+ reviewed so I don't believe that any payment is due. Closing.

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. Internal Requires API changes or must be handled by Expensify staff Weekly KSv2
Projects
No open projects
Development

No branches or pull requests

7 participants