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

[$500] IOU - After editing a Distance request in offline mode, TBD does not appear in the Amount field #29899

Closed
6 tasks done
lanitochka17 opened this issue Oct 18, 2023 · 24 comments
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Weekly KSv2

Comments

@lanitochka17
Copy link

lanitochka17 commented Oct 18, 2023

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.3.86-1

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: Applause - Internal Team

Slack conversation:

Action Performed:

Prerequisites:
The account must have a distance request or create one

  1. Open New Expensify app
  2. Log in with your HT account
  3. Navigate to a distance request details conversation
  4. Disable the internet connection
  5. Select the distance item
  6. Add a new stop to the route
  7. Save the change
  8. Navigate to the report conversation

Expected Result:

After changing the route in offline mode the receipt route image should be pending, and the distance and amount should show as TBD

Actual Result:

The receipt route image is not in a pending state, and the distance and amount are not displayed as TBD when editing Distance expense request offline

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

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
Bug6242084_1697652502355.Recording__497.mp4
MacOS: Desktop

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01a882c54a16f7ff85
  • Upwork Job ID: 1714715676869181440
  • Last Price Increase: 2023-10-18
  • Automatic offers:
    • Tony-MK | Contributor | 27294889
@lanitochka17 lanitochka17 added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Oct 18, 2023
@melvin-bot
Copy link

melvin-bot bot commented Oct 18, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented Oct 18, 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

@lanitochka17 lanitochka17 added the External Added to denote the issue can be worked on by a contributor label Oct 18, 2023
@melvin-bot melvin-bot bot changed the title IOU - After editing a Distance request in offline mode, TBD does not appear in the Amount field [$500] IOU - After editing a Distance request in offline mode, TBD does not appear in the Amount field Oct 18, 2023
@melvin-bot
Copy link

melvin-bot bot commented Oct 18, 2023

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

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

melvin-bot bot commented Oct 18, 2023

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

@FitseTLT
Copy link
Contributor

FitseTLT commented Oct 18, 2023

Proposal

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

After editing waypoints in offline mode, the amount and distance don't change to TBD

What is the root cause of that problem?

Our IOU.updateDistanceRequest doesn't handle the offline case on which it can't determine the updated amount and distance

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

In IOU.updateDistanceRequest we need to set the amount and distance value to TBD by checking if the user is offline.

What alternative solutions did you explore? (Optional)

We can also use OptimisticData to set the values to TBD until the user goes online.

@Tony-MK
Copy link
Contributor

Tony-MK commented Oct 19, 2023

Proposal

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

After editing a Distance request in offline mode, TBD does not appear in the Amount field

What is the root cause of that problem?

The root cause of the problem is that when the user changes the waypoints when offline the transaction data remains the same until the new data, with the correct distance and amount, is fetched from the server changes it. The receipt data stays the same as well. Currently, there is only one handler for displaying common.tbd but it only does this when the transaction.amount and transaction.modifiedAmount are both set to zero. For example:

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

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

Firstly, we need to handle the text to be displayed when the waypoints key is present in the transaction.pendingFields object. Therefore, we need to create new handlers near the lines where transaction.amount and transaction.merchant are used across the MoneyRequestView, MoneyRequestAction and ReportPreview components. This is to ensure consistency. Here is an example of the handlers on the MoneyRequestView component:

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

const hasPendingWaypoints = lodashGet(transaction, 'pendingFields.waypoints');
if (isDistanceRequest && (!formattedTransactionAmount || hasPendingWaypoints)) {
     formattedTransactionAmount = translate('common.tbd');
}

Also for the merchant string.

title={transactionMerchant}

// For replaceMerchantForTBD, probably use regex to replace the distance in the merchant string with 
// common.tbd or use the Distance.Utils.getDistanceMerchant function to generate a merchant string
// with common.tbd
title={hasPendingWaypoints ? replaceMerchantForTBD() : transactionMerchant}

Lastly, to render the default receipt, we need to add some logic such as !Object.hasOwn(transaction?.pendingFields, 'waypoints') to allow the getThumbnailAndImageURIs function, in the ReceiptUtils.ts file, to output the ReceiptGeneric. This will happen when the waypoints key is in the transaction.pendingFields.

@ArekChr
Copy link
Contributor

ArekChr commented Oct 19, 2023

I chose the proposal from @Tony-MK, it provides a more detailed description of the problem and clearly defined solutions that cover a broader range of use cases.

🎀 👀 🎀 C+ reviewed

@melvin-bot
Copy link

melvin-bot bot commented Oct 19, 2023

Triggered auto assignment to @arosiclair, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

@paultsimura
Copy link
Contributor

paultsimura commented Oct 19, 2023

Proposal

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

When editing a Distance request offline, the distance and amount fields are not set to "TBD"

What is the root cause of that problem?

We are not handling the loading state of the distance transaction properly.

We set the transaction.isLoading when modifying the distance request here:

App/src/libs/actions/IOU.js

Lines 757 to 766 in cd9cd57

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

And we handle this state in other places, like here:

const isLoading = lodashGet(transaction, 'isLoading', false);

But we do not handle this state on the MoneyRequestView page.

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

On MoneyRequestView, add the following variable:

const isLoading = lodashGet(transaction, 'isLoading', false);

And use it accordingly here:

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

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

And here:

title={isLoading ? translate('common.tbd') : transactionMerchant}

{isDistanceRequest ? (
<OfflineWithFeedback pendingAction={lodashGet(transaction, 'pendingFields.waypoints') || lodashGet(transaction, 'pendingAction')}>
<MenuItemWithTopDescription
description={translate('common.distance')}
title={transactionMerchant}
interactive={canEdit}
shouldShowRightIcon={canEdit}
titleStyle={styles.flex1}
onPress={() => Navigation.navigate(ROUTES.EDIT_REQUEST.getRoute(report.reportID, CONST.EDIT_REQUEST_FIELD.DISTANCE))}
/>
</OfflineWithFeedback>
) : (

As for me, this is a cleaner approach as it doesn't modify any data in the transactions, which looks more like a hack compared to using the transaction.isLoading state, and we don't need to explicitly check for the online/offline state.

Also, I don't think we should modify the map preview before #28965, as the receipt will be replaced with an actual map for loading distance requests.

Result:

Screen.Recording.2023-10-19.at.10.11.12.mov

What alternative solutions did you explore? (Optional)

@paultsimura
Copy link
Contributor

@ArekChr let me kindly disagree with your decision as from my POV there is a cleaner solution. Just posted the proposal here: #29899 (comment)

@arosiclair
Copy link
Contributor

@Tony-MK I think we should just show TBD when pendingFields.waypoints is set rather than clearing the old amount and modifiedAmount fields. Can you update your proposal to do so?

@paultsimura
Copy link
Contributor

@arosiclair that's exactly what my proposal suggests, isn't it?

@Tony-MK
Copy link
Contributor

Tony-MK commented Oct 19, 2023

@arosiclair, I updated my prospal according to your comment

@arosiclair
Copy link
Contributor

@arosiclair that's exactly what my proposal suggests, isn't it?

I saw your proposal but it is not the same because isLoading isn't granular enough. We only want to show TBD when there are pending changes on the route and it was always the attention to use pendingFields.waypoints for this. Also your RCA isn't quite as good as it more or less just says "the root cause of the problem is that we aren't using my solution".

Your proposal is okay but for these reasons I'm going to stick to @Tony-MK's updated proposal.

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

melvin-bot bot commented Oct 20, 2023

📣 @Tony-MK 🎉 An offer has been automatically sent to your Upwork account for the Contributor role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job
Please accept the offer and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻
Keep in mind: Code of Conduct | Contributing 📖

@paultsimura
Copy link
Contributor

I saw your proposal but it is not the same because isLoading isn't granular enough. We only want to show TBD when there are pending changes on the route and it was always the attention to use pendingFields.waypoints for this. Also your RCA isn't quite as good as it more or less just says "the root cause of the problem is that we aren't using my solution".

Thank you for the explanation @arosiclair, I agree with your decision.

Just to clarify, the only place where we set transaction.isLoading is here:

isLoading: _.has(transactionChanges, 'waypoints'),

This is exactly what you described as "it was always the attention to use pendingFields.waypoints for this". Other transaction types do not have the isLoading state, that's why I don't think it isn't granular enough - that's just a shorthand property for the suggested check.

As for the RCA – agree, it was made a bit in a hurry.

@melvin-bot melvin-bot bot added the Overdue label Oct 23, 2023
@Tony-MK Tony-MK mentioned this issue Oct 24, 2023
59 tasks
@melvin-bot melvin-bot bot added Reviewing Has a PR in review and removed Overdue labels Oct 24, 2023
@melvin-bot melvin-bot bot added Weekly KSv2 and removed Daily KSv2 labels Oct 24, 2023
@Tony-MK
Copy link
Contributor

Tony-MK commented Oct 24, 2023

Hey @ArekChr, can you kindly review the PR and tell me what you think. Thank you

@JmillsExpensify
Copy link

PR review in progress

@melvin-bot melvin-bot bot added Monthly KSv2 and removed Weekly KSv2 labels Nov 20, 2023
Copy link

melvin-bot bot commented Nov 20, 2023

This issue has not been updated in over 15 days. @JmillsExpensify, @arosiclair, @Tony-MK, @ArekChr eroding to Monthly issue.

P.S. Is everyone reading this sure this is really a near-term priority? Be brave: if you disagree, go ahead and close it out. If someone disagrees, they'll reopen it, and if they don't: one less thing to do!

@arosiclair arosiclair removed the Reviewing Has a PR in review label Nov 20, 2023
@arosiclair
Copy link
Contributor

Looks like automations failed here for some reason? Fixes we're deployed a week ago. cc @JmillsExpensify

@JmillsExpensify
Copy link

Ah, nice thanks for the heads up. Payment summary is as follows:

  • Issue reporter: N/A
  • Contributor: @Tony-MK $500
  • Contributor+: @ArekChr expert agency (no payment)

@JmillsExpensify
Copy link

Contributor has been paid out. @ArekChr Also do you mind confirming whether a regression test should be created before I close this issue?

@ArekChr
Copy link
Contributor

ArekChr commented Nov 27, 2023

Sure, we can add a regression test here.

Regression Test Proposal

  1. Log in to the app with a high-traffic account.
  2. Navigate to a distance request details conversation.
  3. Disable the internet connection.
  4. Select the distance item.
  5. Add a new stop to the route and save.
  6. Navigate to the report conversation.
  7. Verify that after adding a stop in offline mode, the receipt route image should be pending, and the distance and amount should show as TBD.

Do we agree 👍 or 👎

@JmillsExpensify
Copy link

Regression test issue created. Closing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Weekly KSv2
Projects
None yet
Development

No branches or pull requests

7 participants