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

[$250][P2P Distance] - Amount field is not grayed out when changing distance rate offline #46880

Closed
5 tasks done
m-natarajan opened this issue Aug 6, 2024 · 36 comments
Closed
5 tasks done
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. Engineering External Added to denote the issue can be worked on by a contributor Reviewing Has a PR in review Weekly KSv2

Comments

@m-natarajan
Copy link

m-natarajan commented Aug 6, 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!


Issue found when validating #40021
Version Number: 9.0.17-0
Reproducible in staging?: y
Reproducible in production?: no, new feature
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers): applausetester+kh05081@applause.expensifail.com
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by: Applause internal team
Slack conversation:

Action Performed:

Precondition:

  • Workspace has a few distance rates.
  1. Go to staging.new.expensify.com
  2. Go to workspace chat.
  3. Submit a distance expense.
  4. Go to transaction thread.
  5. Go offline.
  6. Click Rate.
  7. Select a different rate.

Expected Result:

Amount field should be grayed out because it is changed from the rate offline.

Actual Result:

Amount field is not grayed out when changing distance rate 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
  • [x]MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Bug6563316_1722946380136.bandicam_2024-08-06_20-08-53-476.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01199ead94cf3782d9
  • Upwork Job ID: 1820883188663849553
  • Last Price Increase: 2024-08-06
  • Automatic offers:
    • jjcoffee | Reviewer | 103451212
    • etCoderDysto | Contributor | 103451215
Issue OwnerCurrent Issue Owner: @jjcoffee
@m-natarajan m-natarajan added DeployBlockerCash This issue or pull request should block deployment Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. DeployBlocker Indicates it should block deploying the API labels Aug 6, 2024
Copy link

melvin-bot bot commented Aug 6, 2024

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

Copy link

melvin-bot bot commented Aug 6, 2024

Triggered auto assignment to @johnmlee101 (DeployBlockerCash), see https://stackoverflowteams.com/c/expensify/questions/9980/ for more details.

Copy link
Contributor

github-actions bot commented Aug 6, 2024

👋 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.

@etCoderDysto
Copy link
Contributor

etCoderDysto commented Aug 6, 2024

Proposal

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

Amount field is not grayed out when changing distance rate offline

What is the root cause of that problem?

We are checking for amount change pending action only here

<OfflineWithFeedback pendingAction={getPendingFieldAction('amount')}>

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

We should also check for tax rate change pending action too

<OfflineWithFeedback pendingAction={getPendingFieldAction('amount') ?? getPendingFieldAction('customUnitRateID')}>

What alternative solutions did you explore? (Optional)

@Krishna2323
Copy link
Contributor

Krishna2323 commented Aug 6, 2024

Edited by proposal-police: This proposal was edited at 2024-08-08 07:31:44 UTC.

Proposal

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

Distance - Amount field is not grayed out when changing distance rate offline

What is the root cause of that problem?

In getUpdateMoneyRequestParams the amount is recalculated if hasPendingWaypoints || hasModifiedDistanceRate is true but the pending action/error for amount is not added.

App/src/libs/actions/IOU.ts

Lines 2527 to 2553 in 963f8ce

const hasPendingWaypoints = 'waypoints' in transactionChanges;
const hasModifiedDistanceRate = 'customUnitRateID' in transactionChanges;
if (transaction && updatedTransaction && (hasPendingWaypoints || hasModifiedDistanceRate)) {
updatedTransaction = {
...updatedTransaction,
...TransactionUtils.calculateAmountForUpdatedWaypointOrRate(transaction, transactionChanges, policy, ReportUtils.isExpenseReport(iouReport)),
};
// Delete the draft transaction when editing waypoints when the server responds successfully and there are no errors
successData.push({
onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`,
value: null,
});
// Revert the transaction's amount to the original value on failure.
// The IOU Report will be fully reverted in the failureData further below.
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`,
value: {
amount: transaction.amount,
modifiedAmount: transaction.modifiedAmount,
modifiedMerchant: transaction.modifiedMerchant,
},
});
}

App/src/libs/actions/IOU.ts

Lines 2498 to 2500 in 963f8ce

const pendingFields = Object.fromEntries(Object.keys(transactionChanges).map((key) => [key, CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE]));
const clearedPendingFields = Object.fromEntries(Object.keys(transactionChanges).map((key) => [key, null]));
const errorFields = Object.fromEntries(Object.keys(pendingFields).map((key) => [key, {[DateUtils.getMicroseconds()]: Localize.translateLocal('iou.error.genericEditFailureMessage')}]));

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

Define pendingFields, clearedPendingFields & errorFields using let instead of const and when we update the amount update all these.

    if (transaction && updatedTransaction && (hasPendingWaypoints || hasModifiedDistanceRate)) {
        updatedTransaction = {
            ...updatedTransaction,
            ...TransactionUtils.calculateAmountForUpdatedWaypointOrRate(transaction, transactionChanges, policy, ReportUtils.isExpenseReport(iouReport)),
        };

        pendingFields = {...pendingFields, amount: 'update'};
        clearedPendingFields = {...clearedPendingFields, amount: null};
        errorFields = {...errorFields, amount: {[DateUtils.getMicroseconds()]: Localize.translateLocal('iou.error.genericEditFailureMessage')}};
  • The same should be done in getUpdateTrackExpenseParams also.

Note: We only need to update the pending action for amount. modifiedAmount, modifiedMerchant, and modifiedCurrency are only used to show the update messages.

} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.MODIFIED_EXPENSE) {
children = <ReportActionItemBasicMessage message={ModifiedExpenseMessage.getForReportAction(report.reportID, action)} />;

function getForReportAction(reportID: string | undefined, reportAction: OnyxEntry<ReportAction>): string {
if (!ReportActionsUtils.isModifiedExpenseAction(reportAction)) {
return '';
}
const reportActionOriginalMessage = ReportActionsUtils.getOriginalMessage(reportAction);
const policyID = ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]?.policyID ?? '-1';
const removalFragments: string[] = [];
const setFragments: string[] = [];
const changeFragments: string[] = [];
const hasModifiedAmount =
reportActionOriginalMessage &&
'oldAmount' in reportActionOriginalMessage &&
'oldCurrency' in reportActionOriginalMessage &&
'amount' in reportActionOriginalMessage &&
'currency' in reportActionOriginalMessage;
const hasModifiedMerchant = reportActionOriginalMessage && 'oldMerchant' in reportActionOriginalMessage && 'merchant' in reportActionOriginalMessage;
if (hasModifiedAmount) {
const oldCurrency = reportActionOriginalMessage?.oldCurrency;
const oldAmountValue = reportActionOriginalMessage?.oldAmount ?? 0;
const oldAmount = oldAmountValue > 0 ? CurrencyUtils.convertToDisplayString(reportActionOriginalMessage?.oldAmount ?? 0, oldCurrency) : '';

What alternative solutions did you explore? (Optional)

@neil-marcellini
Copy link
Contributor

Not a blocker since the rate field is still behind a beta.

@neil-marcellini neil-marcellini added External Added to denote the issue can be worked on by a contributor Daily KSv2 and removed DeployBlockerCash This issue or pull request should block deployment Hourly KSv2 DeployBlocker Indicates it should block deploying the API labels Aug 6, 2024
Copy link

melvin-bot bot commented Aug 6, 2024

Job added to Upwork: https://www.upwork.com/jobs/~01199ead94cf3782d9

@melvin-bot melvin-bot bot changed the title Distance - Amount field is not grayed out when changing distance rate offline [$250] Distance - Amount field is not grayed out when changing distance rate offline Aug 6, 2024
@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Aug 6, 2024
Copy link

melvin-bot bot commented Aug 6, 2024

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

@jjcoffee
Copy link
Contributor

jjcoffee commented Aug 7, 2024

Reviewing proposals tomorrow!

@wildan-m
Copy link
Contributor

wildan-m commented Aug 8, 2024

Proposal

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

Distance - Amount field is not grayed out when changing distance rate offline

What is the root cause of that problem?

In calculateAmountForUpdatedWaypointOrRate Dependent pending fields not added when the affected value changes

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

By following this pattern. We can modify
calculateAmountForUpdatedWaypointOrRate to

....
        modifiedAmount: updatedAmount,
        modifiedMerchant: updatedMerchant,
        modifiedCurrency: updatedCurrency,

        pendingFields: {
            ...transaction?.pendingFields,
            ...(!lodashIsEqual(updatedAmount, transaction?.modifiedAmount ?? transaction?.amount) && { amount: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE }),
            ...(!lodashIsEqual(updatedMerchant, transaction?.modifiedMerchant ?? transaction?.merchant) && { merchant: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE }),
            ...(!lodashIsEqual(updatedCurrency, transaction?.modifiedCurrency ?? transaction?.currency) && { currency: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE })
        },
    };

This way we only add pending fields, if the value actually change. the pending field not only amount, it can also merchant or currency.

Then we can move / modify this step to the step after we finished modify updatedTransaction.

Modify the transactionChanges to also include affected fields.

src/libs/actions/IOU.ts getUpdateTrackExpenseParams and getUpdateMoneyRequestParams

....
    // Set any "pending fields"  (ones updated while the user was offline), includes the fields that affected to have error messages in the failureData
    const allTransactionChanges = { ...transactionChanges, ...(updatedTransaction ? updatedTransaction.pendingFields : {}) }
    const pendingFields = Object.fromEntries(Object.keys(allTransactionChanges).map((key) => [key, CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE]));
    const clearedPendingFields = Object.fromEntries(Object.keys(allTransactionChanges).map((key) => [key, null]));
    const errorFields = Object.fromEntries(Object.keys(allTransactionChanges).map((key) => [key, {[DateUtils.getMicroseconds()]: Localize.translateLocal('iou.error.genericEditFailureMessage')}]));

Branch draft for this solution

What alternative solutions did you explore? (Optional)

@Krishna2323
Copy link
Contributor

Proposal Updated

  • Added a note

@jjcoffee
Copy link
Contributor

jjcoffee commented Aug 8, 2024

@etCoderDysto's proposal LGTM - it's a nice and simple solution, and a pattern that we use elsewhere, e.g. here

pendingAction={rate?.pendingFields?.rate ?? rate?.pendingFields?.currency}

I'm not aware of any other reason to specifically set the amount field as pending as the other two proposals have, so it seems much simpler to just rely on the field that's actually changed.

🎀👀🎀 C+ reviewed

@etCoderDysto
Copy link
Contributor

Hi @paultsimura, amount is not blank when editing waypoint followed by editing rate. It is only blank when editing waypoints.

Screen.Recording.2024-08-11.at.1.50.33.in.the.afternoon.mp4

@melvin-bot melvin-bot bot added the Overdue label Aug 11, 2024
@paultsimura
Copy link
Contributor

paultsimura commented Aug 11, 2024

@etCoderDysto this should be fixed by #47145, we can hold for it.

@etCoderDysto
Copy link
Contributor

@etCoderDysto this should be fixed by #47145, we can hold for it.

Sounds good to me. I will wait till the pr is merged to main

@jjcoffee
Copy link
Contributor

@RachCHopkins Can you add a hold for #47145? Thanks!

@melvin-bot melvin-bot bot removed the Overdue label Aug 12, 2024
@neil-marcellini neil-marcellini changed the title [$250] Distance - Amount field is not grayed out when changing distance rate offline [$250][P2P Distance] - Amount field is not grayed out when changing distance rate offline Aug 13, 2024
Copy link

melvin-bot bot commented Aug 15, 2024

@johnmlee101, @jjcoffee, @RachCHopkins, @etCoderDysto Whoops! This issue is 2 days overdue. Let's get this updated quick!

@melvin-bot melvin-bot bot added the Overdue label Aug 15, 2024
@etCoderDysto
Copy link
Contributor

Waiting for #47145 to be merged to main

@jjcoffee
Copy link
Contributor

Waiting for #47145 to be merged to main

Confirming to remove the overdue label 😅

@melvin-bot melvin-bot bot removed the Overdue label Aug 16, 2024
@jjcoffee
Copy link
Contributor

@etCoderDysto #47145 has been merged. Let's go! 🚀

@etCoderDysto
Copy link
Contributor

@etCoderDysto #47145 has been merged. Let's go! 🚀

Great! I will raise a PR soon.

Copy link

melvin-bot bot commented Aug 20, 2024

@johnmlee101 @jjcoffee @RachCHopkins @etCoderDysto this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!

@RachCHopkins
Copy link
Contributor

Sorry guys, missed this one - I'm a little swamped and not really watching closely unless I'm starred.

@jjcoffee
Copy link
Contributor

@RachCHopkins No worries, we're just waiting on a PR from @etCoderDysto here!

@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Daily KSv2 labels Aug 21, 2024
@etCoderDysto
Copy link
Contributor

@jjcoffee PR is ready for review. Sorry for the delay.

@jjcoffee
Copy link
Contributor

jjcoffee commented Sep 4, 2024

Note

The production deploy automation failed: This should be on [HOLD for Payment 2024-09-06] according to #48035 prod deploy checklist, confirmed in https://expensify.slack.com/archives/C01GTK53T8Q/p1725051480370659?thread_ts=1725050431.962859&cid=C01GTK53T8Q.

cc @RachCHopkins

@etCoderDysto
Copy link
Contributor

Note

The production deploy automation failed: This should be on [HOLD for Payment 2024-09-06] according to #48035 prod deploy checklist, confirmed in https://expensify.slack.com/archives/C01GTK53T8Q/p1725051480370659?thread_ts=1725050431.962859&cid=C01GTK53T8Q.

cc @RachCHopkins

I think this issue is ready for payout.
cc @RachCHopkins

@jjcoffee
Copy link
Contributor

jjcoffee commented Sep 6, 2024

  • The PR that introduced the bug has been identified. Link to the PR: feat: Edit Distance Rate flow #40021
  • 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: feat: Edit Distance Rate flow #40021 (comment)
  • 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: N/A - more thorough testing should have caught it
  • Determine if we should create a regression test for this bug. Yes
  • 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 Proposal

  1. Go to any workspace chat.
  2. Submit a distance expense.
  3. Go to the transaction thread.
  4. Go offline.
  5. Click Rate and select a different rate.
  6. Verify that the amount field is greyed out.

Do we agree 👍 or 👎

@RachCHopkins
Copy link
Contributor

Payment Summary:

Upwork job here

@RachCHopkins
Copy link
Contributor

Contributor has been paid, the contract has been completed, and the Upwork post has been closed.

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. Engineering External Added to denote the issue can be worked on by a contributor Reviewing Has a PR in review Weekly KSv2
Projects
None yet
Development

No branches or pull requests

10 participants