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-02-19] [$500] Distance - Receipt shows original amount and distance instead of TBD when editing distance offline #33362

Closed
6 tasks done
kbecciv opened this issue Dec 20, 2023 · 45 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor

Comments

@kbecciv
Copy link

kbecciv commented Dec 20, 2023

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: v1.4.14-2
Reproducible in staging?: y
Reproducible in production?: y
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: Applause - Internal Team
Slack conversation:

Action Performed:

Precondition: There is a distance expense request in the workspace chat.

  1. Navigate to the workspace chat from the precondition.
  2. Open the distance request details page.
  3. Click on the receipt.
  4. Close the receipt.
  5. Go offline.
  6. Click Distance.
  7. Add a stop and save it.
  8. Click on the receipt.

Expected Result:

The amount and distance will show TBD.

Actual Result:

The amount and distance are not showing TBD. The values are still showing the original value before edit.

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

Bug6321335_1703081373259.bandicam_2023-12-15_03-44-39-835.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01d635e8deae97ab55
  • Upwork Job ID: 1737476292940328960
  • Last Price Increase: 2024-01-03
  • Automatic offers:
    • paultsimura | Contributor | 28089473
Issue OwnerCurrent Issue Owner: @kevinksullivan
@kbecciv kbecciv added External Added to denote the issue can be worked on by a contributor Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Dec 20, 2023
@melvin-bot melvin-bot bot changed the title Distance - Receipt shows original amount and distance instead of TBD when editing distance offline [$500] Distance - Receipt shows original amount and distance instead of TBD when editing distance offline Dec 20, 2023
Copy link

melvin-bot bot commented Dec 20, 2023

Job added to Upwork: https://www.upwork.com/jobs/~01d635e8deae97ab55

Copy link

melvin-bot bot commented Dec 20, 2023

Triggered auto assignment to @kevinksullivan (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Dec 20, 2023
Copy link

melvin-bot bot commented Dec 20, 2023

Bug0 Triage Checklist (Main S/O)

  • This "bug" occurs on a supported platform (ensure Platforms in OP are ✅)
  • This bug is not a duplicate report (check E/App issues and #expensify-bugs)
    • If it is, comment with a link to the original report, close the issue and add any novel details to the original issue instead
  • This bug is reproducible using the reproduction steps in the OP. S/O
    • If the reproduction steps are clear and you're unable to reproduce the bug, check with the reporter and QA first, then close the issue.
    • If the reproduction steps aren't clear and you determine the correct steps, please update the OP.
  • This issue is filled out as thoroughly and clearly as possible
    • Pay special attention to the title, results, platforms where the bug occurs, and if the bug happens on staging/production.
  • I have reviewed and subscribed to the linked Slack conversation to ensure Slack/Github stay in sync

Copy link

melvin-bot bot commented Dec 20, 2023

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

@dukenv0307
Copy link
Contributor

dukenv0307 commented Dec 20, 2023

Proposal

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

The amount and distance are not showing TBD. The values are still showing the original value before edit.

What is the root cause of that problem?

We don't use the same condition to show TDB as we do in MoneyRequestView. The same for merchant

const formattedTransactionAmount = transactionAmount ? CurrencyUtils.convertToDisplayString(transactionAmount, transactionCurrency) : translate('common.tbd');

if (isDistanceRequest && (!formattedTransactionAmount || hasPendingWaypoints)) {
formattedTransactionAmount = translate('common.tbd');
}

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

We should use the same condition to show the amount and merchant as we do in MoneyRequestView here

const formattedTransactionAmount = transactionAmount ? CurrencyUtils.convertToDisplayString(transactionAmount, transactionCurrency) : translate('common.tbd');

if (isDistanceRequest && (!formattedTransactionAmount || hasPendingWaypoints)) {
formattedTransactionAmount = translate('common.tbd');
}

What alternative solutions did you explore? (Optional)

NA

@paultsimura
Copy link
Contributor

paultsimura commented Dec 20, 2023

Proposal

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

Amount and Distance are not replaced with TBD in the eReceipt.

What is the root cause of that problem?

We currently show TBD only if the request has no initial amount:

const formattedTransactionAmount = transactionAmount ? CurrencyUtils.convertToDisplayString(transactionAmount, transactionCurrency) : translate('common.tbd');

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

We should add a check for transaction.isLoading, and show TBD in this case as well:

const formattedTransactionAmount = !transaction.isLoading && transactionAmount ? CurrencyUtils.convertToDisplayString(transactionAmount, transactionCurrency) : translate('common.tbd');
const formattedMerchant = transaction.isLoading ? transactionMerchant.replace(CONST.REGEX.FIRST_SPACE, translate('common.tbd')) : transactionMerchant;

And use this formattedMerchant instead of transactionMerchant here:

<Text style={styles.eReceiptMerchant}>{transactionMerchant}</Text>

What alternative solutions did you explore? (Optional)

Instead of using transaction.isLoading, we can use the hasPendingWaypoints approach, but it was already discussed in a couple of places that we should move towards using transaction.isLoading instead of checking for pending waypoints, as it can be more dynamically controlled in one single place instead of later modifying the hasPendingWaypoints check in every single place where we use the TBD.

This transaction.isLoading is being set in one single place when modifying the transaction, so it should be relied on as the source of truth for the distance transaction being in pending status:

App/src/libs/actions/IOU.js

Lines 936 to 946 in 249096e

// Optimistically modify the transaction
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`,
value: {
...updatedTransaction,
pendingFields,
isLoading: _.has(transactionChanges, 'waypoints'),
errorFields: null,
},
});

@kevinksullivan
Copy link
Contributor

Hi @parasharrajat please review the proposal!

@parasharrajat
Copy link
Member

Checking this in 2 hours.

@Tony-MK
Copy link
Contributor

Tony-MK commented Dec 24, 2023

Proposal

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

Distance - Receipt shows original amount and distance instead of TBD when editing distance offline

What is the root cause of that problem?

This issue was supposed to be part of PR #30232 but I was advised that it was out of scope. The root cause arises when the waypoints are changed and no condition or transaction flag is there to check whether the amount and distance have changed and are pending recalculation. The amount and merchant are not modified in the onyx until the user gets a stable internet connection. Hence, we show the previous amount and distance instead of TBD.

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

  1. Create a boolean variable called hasPendingWaypoints in DistanceEReceipt.js, borrowed from MoneyRequestView.js. For granularity, hasPendingWaypoints is solely used to check if the transaction has any changed waypoints. Hence, the amount and distance are wrong and need recalculation.
const hasPendingWaypoints = lodashGet(props.transaction, 'pendingFields.waypoints', false);
  1. Set the formattedTransactionAmount string appropriately.
const formattedTransactionAmount = hasPendingWaypoints && transactionAmount ? CurrencyUtils.convertToDisplayString(transactionAmount, transactionCurrency) : translate('common.tbd');
  1. Replace the distance substring in the merchant string with TBD.
<Text style={styles.eReceiptMerchant}>{hasPendingWaypoints ? requestMerchant.replace(CONST.REGEX.FIRST_SPACE, translate('common.tbd')) : requestMerchant}</Text>
  1. Render PendingMapView because ReceiptUtils.getThumbnailAndImageURIs will return the default receipt thumbnail. Hence, if the user is offline, the default receipt thumbnail is displayed instead of the pending map thumbnail.
    {isOffline || !thumbnailSource ? (

isOffline || !thumbnailSource || hasPendingWaypoints

Result
Result

Important Note
I discovered a couple of inconsistent components that don't appear as they should when a distance request is created offline. I believe we can address them because they were left out from PR #30232 To mention a few:

  1. The amount field opacity should be dimmed when it shows TBD.
  2. In MoneyRequestView, there are three components that should show TBD because the distance and amount have not been recalculated. We could also address this.
    MoneyRequestView

@melvin-bot melvin-bot bot added the Overdue label Dec 24, 2023
@paultsimura
Copy link
Contributor

Regarding the notes from the proposal above:

Important Note
I discovered a couple of inconsistent components that don't appear as they should when a distance request is created offline. For example in MoneyRequestView, there are components that should show TBD because the distance and amount have not been recalculated. I believe we can also address this.

This should have been handled in #33060, but that was closed as not important at the moment. If it should still be fixed – the original issue should be reopened.

Render PendingMapView because ReceiptUtils.getThumbnailAndImageURIs will return the default receipt thumbnail. Hence, if the user is offline, the default receipt thumbnail is displayed instead of the pending map thumbnail.

This should be handled in #28965, where the green receipt thumbnail will be replaced by an actual map.

Besides these points, the rest is almost the same as in the first 2 proposals.

Copy link

melvin-bot bot commented Dec 26, 2023

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

Copy link

melvin-bot bot commented Dec 27, 2023

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

@parasharrajat
Copy link
Member

I will review this by tomorrow.

@melvin-bot melvin-bot bot removed the Overdue label Dec 27, 2023
@Tony-MK
Copy link
Contributor

Tony-MK commented Dec 27, 2023

@parasharrajat, would you know why we display the PendingMap instead of the actual map image in the DistanceEReceipt? Since the rest of the app displays the map image, it shouldn't be a caching problem. Even if the user is offline. Thank you 😄

{isOffline || !thumbnailSource ? (
<PendingMapView />
) : (
<ThumbnailImage

@Tony-MK
Copy link
Contributor

Tony-MK commented Dec 28, 2023

Thank you @paultsimura for your feedback on my proposal. After reading #28965, I would like to ask you a question.

This should be handled in #28965, where the green receipt thumbnail will be replaced by an actual map.

Depending on the user's internet connection, if the user changes the waypoints while the device is offline then the thumbnailSource will be the default receipt.

The default receipt will be displayed instead of the PendingMapView for some time until the updated map image is fetched.

Is this correct? Thank you 😄

@parasharrajat
Copy link
Member

It's good to solve other inconsistencies but I will let @kevinksullivan decide those if they should be solved in this issue.

@kevinksullivan There are some suggestions from #33362 (comment) but the are out of scope of the expected behaviour of this issue. Should we pursue those as well?

Important Note
I discovered a couple of inconsistent components that don't appear as they should when a distance request is created offline. I believe we can address them because they were left out from #30232 To mention a few:

The amount field opacity should be dimmed when it shows TBD.
In MoneyRequestView, there are three components that should show TBD because the distance and amount have not been recalculated. We could also address this.

@parasharrajat
Copy link
Member

but it was already discussed in a couple of places that we should move towards using transaction.isLoading instead of checking for pending waypoints

@paultsimura Can you please share the context where this was discussed?

@paultsimura
Copy link
Contributor

Can you please share the context where this was discussed?

Sorry, I don't remember the exact issues as they were eventually closed (that's why we don't see transaction.isLoading being used for TBD yet).

I just remember the pro-points were:

  • Centralised control over the transaction's loading state in a single place instead of using _.has(transactionChanges, 'waypoints') in different places, as it is set here:

    App/src/libs/actions/IOU.js

    Lines 936 to 946 in 249096e

    // Optimistically modify the transaction
    optimisticData.push({
    onyxMethod: Onyx.METHOD.MERGE,
    key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`,
    value: {
    ...updatedTransaction,
    pendingFields,
    isLoading: _.has(transactionChanges, 'waypoints'),
    errorFields: null,
    },
    });
  • It's already used here to handle the loading state of a Distance request:
    const isLoading = lodashGet(transaction, 'isLoading', false);

@parasharrajat
Copy link
Member

@kevinksullivan Can you please confirm this #33362 (comment)?

@melvin-bot melvin-bot bot added the Overdue label Jan 1, 2024
@parasharrajat
Copy link
Member

We need to discuss the above point before moving forward. I am one step away from finalizing the review.

@parasharrajat
Copy link
Member

parasharrajat commented Jan 9, 2024

Hmm, I don't have much idea of this part. I will let know after some testing.

Meanwhile, @Tony-MK Do you mind proposing the suggestions as problems following https://github.com/Expensify/App/blob/main/contributingGuides/HOW_TO_CREATE_A_PLAN.md#step-1-define-the-problem?

Why should we make these changes?

@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Daily KSv2 labels Jan 9, 2024
@paultsimura
Copy link
Contributor

Thanks. The PR is ready for review: #34135

@neil-marcellini
Copy link
Contributor

neil-marcellini commented Feb 8, 2024

As I mentioned here, we need to update the regression tests for offline distance requests to match up with this change. @kevinksullivan would you please help out with that? The new expected results can be found in the QA/test steps on the PR.

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels Feb 12, 2024
@melvin-bot melvin-bot bot changed the title [$500] Distance - Receipt shows original amount and distance instead of TBD when editing distance offline [HOLD for payment 2024-02-19] [$500] Distance - Receipt shows original amount and distance instead of TBD when editing distance offline Feb 12, 2024
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Feb 12, 2024
Copy link

melvin-bot bot commented Feb 12, 2024

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

Copy link

melvin-bot bot commented Feb 12, 2024

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.4.39-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-02-19. 🎊

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

Copy link

melvin-bot bot commented Feb 12, 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.
  • [@kevinksullivan] 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 and removed Weekly KSv2 labels Feb 18, 2024
Copy link

melvin-bot bot commented Feb 20, 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.

@melvin-bot melvin-bot bot added the Overdue label Feb 20, 2024
@paultsimura
Copy link
Contributor

False alert – I used this issue as a reference.

@parasharrajat
Copy link
Member

I think the issue is eligible for a bonus due to the scope change on the PR. @paultsimura did great job in handling and managing the discussion till the end.

Copy link

melvin-bot bot commented Feb 21, 2024

@amyevans, @paultsimura, @kevinksullivan, @parasharrajat Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

@kevinksullivan
Copy link
Contributor

Payment summary:

@parasharrajat
Copy link
Member

Payment requested as per #33362 (comment)

@JmillsExpensify
Copy link

$500 approved for @parasharrajat

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 External Added to denote the issue can be worked on by a contributor
Projects
None yet
Development

No branches or pull requests

10 participants