Skip to content

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

Closed

Description

@IuliiaHerets

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

Activity

  1. added
    DeployBlockerCashThis issue or pull request should block deployment
    BugSomething is broken. Auto assigns a BugZero manager.
    DeployBlockerIndicates it should block deploying the API
    on Aug 7, 2024
  2. melvin-bot commented on Aug 7, 2024

    @melvin-bot

    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.

  3. melvin-bot commented on Aug 7, 2024

    @melvin-bot

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

  4. github-actions commented on Aug 7, 2024

    @github-actions
    Contributor

    👋 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.
  5. IuliiaHerets commented on Aug 7, 2024

    @IuliiaHerets
    Author

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

  6. trjExpensify commented on Aug 7, 2024

    @trjExpensify
    Contributor

    Discussing with @paultsimura here.

  7. nyomanjyotisa commented on Aug 7, 2024

    @nyomanjyotisa
    Member

    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)

  8. 9 remaining items

  9. trjExpensify commented on Aug 7, 2024

    @trjExpensify
    Contributor

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

  10. added
    ReviewingHas a PR in review
    and removed on Aug 7, 2024
  11. bernhardoj commented on Aug 7, 2024

    @bernhardoj
    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

  12. melvin-bot commented on Aug 8, 2024

    @melvin-bot

    ⚠️ 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.

  13. melvin-bot commented on Aug 30, 2024

    @melvin-bot

    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!

  14. bernhardoj commented on Aug 31, 2024

    @bernhardoj
    Contributor

    We can close this one

  15. parasharrajat commented on Sep 2, 2024

    @parasharrajat
    Member

    Good to close @anmurali

  16. melvin-bot commented on Oct 29, 2024

    @melvin-bot

    @anmurali, @parasharrajat, @grgia, @bernhardoj, this Monthly task hasn't been acted upon in 6 weeks; closing.

    If you disagree, feel encouraged to reopen it -- but pick your least important issue to close instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions