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

Distance - Distance field does not show "Pending" after changing distance offline #46952

Open
6 tasks done
IuliiaHerets opened this issue Aug 7, 2024 · 16 comments
Open
6 tasks done
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. Engineering Monthly KSv2 Reviewing Has a PR in review

Comments

@IuliiaHerets
Copy link

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: v9.0.17-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/4827863
Email or phone of affected tester (no customers): applausetester+kh050806@applause.expensifail.com
Issue reported by: Applause Internal Team

Action Performed:

  1. Go to staging.new.expensify.com
  2. Go to workspace chat.
  3. Create a distance expense with three waypoints.
  4. Go to transaction thread.
  5. Go offline.
  6. Click Distance.
  7. Remove one waypoint and save it.

Expected Result:

The Distance row will show "Pending".

Actual Result:

The Distance row still shows the previous distance instead of "Pending".

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

Bug6564228_1723023574708.20240807_173718.mp4

View all open jobs on GitHub

@IuliiaHerets IuliiaHerets 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 7, 2024
Copy link

melvin-bot bot commented Aug 7, 2024

Triggered auto assignment to @anmurali (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 7, 2024

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

@github-actions github-actions bot added Engineering Hourly KSv2 and removed Daily KSv2 labels Aug 7, 2024
Copy link
Contributor

github-actions bot commented Aug 7, 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.

@IuliiaHerets
Copy link
Author

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

@trjExpensify
Copy link
Contributor

Discussing with @paultsimura here.

@nyomanjyotisa
Copy link
Contributor

Proposal

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

Distance field does not show "Pending" after changing distance offline

What is the root cause of that problem?

We don't show "Pending" if waypoints pendingFields is update

function getDistanceForDisplay(hasRoute: boolean, distanceInMeters: number, unit: Unit | undefined, rate: number | undefined, translate: LocaleContextProps['translate']): string {
if (!hasRoute || !rate || !unit || !distanceInMeters) {
return translate('iou.fieldPending');
}

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

show "Pending" if waypoints pendingFields is update

Add new param on getDistanceForDisplay called isPendingUpdate here and add it in the condition to show Pending

    if (!hasRoute || !rate || !unit || !distanceInMeters || isPendingUpdate) {
        return translate('iou.fieldPending');
    }

create new const to store if waypoints pendingFields is update here

const isPendingUpdate = getPendingFieldAction('waypoints') == CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE

Then pass the isPendingUpdate here

const distanceToDisplay = DistanceRequestUtils.getDistanceForDisplay(hasRoute, distance, unit, rate, translate, isPendingUpdateDistance);

Might need to listen to pendingFields other then waypoints if needed
Also might need to show Pending for fields other than distance if needed,

What alternative solutions did you explore? (Optional)

@paultsimura
Copy link
Contributor

I believe this is a regression from #46165 – we changed the way we calculate the distance in MoneyRequestView there.

@trjExpensify
Copy link
Contributor

Thanks! Under the regression period, assigning back to @parasharrajat and @bernhardoj, though Bernhard I need you to comment please. :)

@trjExpensify
Copy link
Contributor

@paultsimura confirming this is a bug only on the p2pDistanceRequests beta, so it shouldn't be a deploy blocker, right?

@paultsimura
Copy link
Contributor

Confirmed that it's only visible under the p2pDistanceRequests beta.

image

@trjExpensify trjExpensify added 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 7, 2024
@trjExpensify
Copy link
Contributor

Thanks, demoting. @bernhardoj please follow up and fix this!

@melvin-bot melvin-bot bot added the Weekly KSv2 label Aug 7, 2024
@bernhardoj
Copy link
Contributor

The root cause of the issue is actually not directly related to the PR. We already have a logic here to show Pending... if the distance is 0 or doesn't exist.

function getDistanceForDisplay(hasRoute: boolean, distanceInMeters: number, unit: Unit | undefined, rate: number | undefined, translate: LocaleContextProps['translate']): string {
if (!hasRoute || !rate || !unit || !distanceInMeters) {
return translate('iou.fieldPending');
}

The distance comes from either customUnit.quantity or routes.route0.distance. However, when we remove the waypoint, we don't clear the customUnit.quantity.

let newTransaction: Transaction = {
// eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style
...(transaction as Transaction),
comment: {
...transaction?.comment,
waypoints: reIndexedWaypoints,
},
// We want to reset the amount only for draft transactions (when creating the expense).
// When modifying an existing transaction, the amount will be updated on the actual IOU update operation.
...(isDraft && {amount: CONST.IOU.DEFAULT_AMOUNT}),
};
if (!isRemovedWaypointEmpty) {
newTransaction = {
...newTransaction,
// Clear any errors that may be present, which apply to the old route
errorFields: {
route: null,
},
// Clear the existing route so that we don't show an old route
routes: {
route0: {
// Clear the existing distance to recalculate next time
distance: null,
geometry: {
coordinates: null,
},
},
},
};
}

But we did remove it when adding waypoints.

Onyx.merge(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {
comment: {
waypoints: {
[`waypoint${index}`]: waypoint,
},
customUnit: {
quantity: null,
},
},
// We want to reset the amount only for draft transactions (when creating the expense).
// When modifying an existing transaction, the amount will be updated on the actual IOU update operation.
...(isDraft && {amount: CONST.IOU.DEFAULT_AMOUNT}),
// Empty out errors when we're saving a new waypoint as this indicates the user is updating their input
errorFields: {
route: null,
},
// Clear the existing route so that we don't show an old route
routes: {
route0: {
// Clear the existing distance to recalculate next time
distance: null,
geometry: {
coordinates: null,
},
},
},
});

That's why the issue doesn't happen when adding waypoint while offline. This issue just became apparent after my PR. Previously, we shows Pending when updating the waypoint even if the distance value is already updated. Now, Pending will only show if the distance value is not available yet.

I have open a new PR to address this issue without breaking #43569

Copy link

melvin-bot bot commented Aug 8, 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 Monthly KSv2 and removed Weekly KSv2 labels Aug 30, 2024
Copy link

melvin-bot bot commented Aug 30, 2024

This issue has not been updated in over 15 days. @anmurali, @parasharrajat, @grgia, @bernhardoj 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!

@bernhardoj
Copy link
Contributor

We can close this one

@parasharrajat
Copy link
Member

Good to close @anmurali

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 Monthly KSv2 Reviewing Has a PR in review
Projects
None yet
Development

No branches or pull requests

8 participants