Skip to content

[HOLD for payment 2024-08-14] [$250] Distance - Distance still shows Pending when preview and report header already show distance #43569

Closed

Description

@lanitochka17

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: 1.4.82-0
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught during regression testing, add the test name, ID and link from TestRail: https://expensify.testrail.io/index.php?/tests/view/4620914
Issue reported by: Applause - Internal Team

Action Performed:

  1. Go to staging.new.expensify.com
  2. Go to workspace chat
  3. Submit a distance expense
  4. Go to expense report while the receipt is being generated
  5. Note that the distance is already computed in the expense preview
  6. Go to transaction thread while the receipt is being generated
  7. Note that the distance in transaction thread header is also computed
  8. Note that the Distance row still shows "Pending" while it is computed in Step 6 and 7

Expected Result:

The Distance row in transaction thread should display the distance when the distance is computed

Actual Result:

The Distance row in transaction thread displays "Pending" when the expense preview and transaction thread header already display the distance

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

Bug6510345_1718175159906.bandicam_2024-06-12_14-45-41-618.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01531942e35c6e84c9
  • Upwork Job ID: 1801172514335645153
  • Last Price Increase: 2024-07-18
Issue OwnerCurrent Issue Owner: @trjExpensify

Activity

  1. added
    Daily
    Bug
    on Jun 12, 2024
  2. melvin-bot commented on Jun 12, 2024

    @melvin-bot

    Triggered auto assignment to @trjExpensify (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. lanitochka17 commented on Jun 12, 2024

    @lanitochka17
    Author

    @trjExpensify FYI I haven't added the External label as I wasn't 100% sure about this issue. Please take a look and add the label if you agree it's a bug and can be handled by external contributors

  4. lanitochka17 commented on Jun 12, 2024

    @lanitochka17
    Author

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

  5. bernhardoj commented on Jun 12, 2024

    @bernhardoj
    Contributor

    Proposal

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

    Distance value shows Pending... even though the distance is shown/calculated in the confirmation list and in the preview.

    What is the root cause of that problem?

    If there is a pending action of waypoints, it will show Pending...

    title={getPendingFieldAction('waypoints') ? translate('iou.fieldPending') : distanceToDisplay}

    When we create a new request, an ADD pending action is set, that's why the Pending... is shown.

    isDistanceRequest ? {waypoints: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD} : undefined,

    It's to address this comment where the distance value still shows the old value after update, so Pending... is shown while waiting for the updated distance value.

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

    In main, when we change the waypoints, the distance value is already updated from GetRoute request, so I don't think we need to show Pending... anymore by always showing the distanceToDisplay here.

    title={getPendingFieldAction('waypoints') ? translate('iou.fieldPending') : distanceToDisplay}

    title={distanceToDisplay}
    

    (or update the condition to specifically check for update pending action)

    However, I see another issue. The distance shown is in meters even though the unit is in miles.

    Screen.Recording.2024-06-13.at.00.20.01.mov

    It's because, GetRoute API returns the distance in meters, but we try to convert it from miles to meters here,

    const distance = DistanceRequestUtils.convertToDistanceInMeters(TransactionUtils.getDistance(transaction), unit);

    The reason we try to convert it from miles to meters is because after the transaction is created (RequestMoney)/waypoints is updated (UpdateMoneyRequestDistance), the distance value is in miles instead of meters which is different from GetRoute response. I think this needs to be discussed first how to fix it. Maybe we can update GetRoute to returns the distance value based on the workspace unit (miles/km).

    Based on the discussion, we want to get the distance from transaction.routes.route0.distance if it exist (which is in meters), otherwise, we get it from transaction.comment.customUnit.quantity (which is in saved unit). The first thing to do is to clear the routes object from the transaction when the create/update distance request is completed.

    App/src/libs/actions/IOU.ts

    Lines 689 to 696 in 7c37886

    {
    onyxMethod: Onyx.METHOD.MERGE,
    key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`,
    value: {
    pendingAction: null,
    pendingFields: clearedPendingFields,
    },
    },

    App/src/libs/actions/IOU.ts

    Lines 2707 to 2715 in 7c37886

    successData.push({
    onyxMethod: Onyx.METHOD.MERGE,
    key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`,
    value: {
    pendingFields: clearedPendingFields,
    isLoading: false,
    errorFields: null,
    },
    });

    Next, we create a new TransactionUtils function called getDistanceInMeters which contains the logic above.

    function getDistanceInMeters(transaction, unit) {
        if (transaction.routes.route0.distance) return transaction.routes.route0.distance;
        if (transaction.comment.customUnit.quantity && unit) return DistanceRequestUtils.convertToDistanceInMeters(transaction.comment.customUnit.quantity, unit);
        return 0;
    }
    

    Then, replace all TransactionUtils.getDistance usage with TransactionUtils.getDistanceInMeters.

    For MoneyRequestView, we want to replace the whole line with TransactionUtils.getDistanceInMeters.

    const distance = DistanceRequestUtils.convertToDistanceInMeters(TransactionUtils.getDistance(transaction), unit);

  6. trjExpensify commented on Jun 13, 2024

    @trjExpensify
    Contributor

    Hm, I think this was a vip-vsb initiative originally. @paultsimura and @neil-marcellini I recall have the subject matter knowledge on this one.

  7. added
    External
    on Jun 13, 2024
  8. changed the title [-]Distance - Distance still shows Pending when preview and report header already show distance[/-] [+][$250] Distance - Distance still shows Pending when preview and report header already show distance[/+] on Jun 13, 2024
  9. melvin-bot commented on Jun 13, 2024

    @melvin-bot
  10. added
    Help Wanted
    on Jun 13, 2024
  11. melvin-bot commented on Jun 13, 2024

    @melvin-bot

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

  12. parasharrajat commented on Jun 17, 2024

    @parasharrajat
    Member

    However, I see another issue. The distance shown is in meters even though the unit is in miles.

    Nice catch.

    Maybe we can update GetRoute to return the distance value based on the workspace unit (miles/km).

    I like this suggestion. However, it might create more issues if we are supposed to use a static unit in calculations. But I differ this to internal team who has better idea on this.


    Other than this, @bernhardoj Did you check for the offline behaviour?

  13. 78 remaining items

  14. trjExpensify commented on Aug 15, 2024

    @trjExpensify
    Contributor

    Thanks! @neil-marcellini will regression tests for the P2P Distance project be added centrally when the project is wrapped?

  15. trjExpensify commented on Aug 15, 2024

    @trjExpensify
    Contributor

    Payment summary as follows:

    Feel free to go ahead and submit on ND!

  16. bernhardoj commented on Aug 15, 2024

    @bernhardoj
    Contributor

    Requested in ND.

  17. melvin-bot commented on Aug 20, 2024

    @melvin-bot

    @trjExpensify, @parasharrajat, @neil-marcellini, @bernhardoj Huh... This is 4 days overdue. Who can take care of this?

  18. JmillsExpensify commented on Aug 21, 2024

    @JmillsExpensify
    Contributor

    $250 approved for @bernhardoj

  19. melvin-bot commented on Aug 22, 2024

    @melvin-bot

    @trjExpensify, @parasharrajat, @neil-marcellini, @bernhardoj 6 days overdue. This is scarier than being forced to listen to Vogon poetry!

  20. trjExpensify commented on Aug 23, 2024

    @trjExpensify
    Contributor

    I'm back, reached out to @neil-marcellini on this Q before closing this out.

  21. neil-marcellini commented on Aug 23, 2024

    @neil-marcellini
    Contributor

    Thanks! @neil-marcellini will regression tests for the P2P Distance project be added centrally when the project is wrapped?

    Yes

  22. trjExpensify commented on Aug 23, 2024

    @trjExpensify
    Contributor

    Great, closing!

  23. parasharrajat commented on Aug 30, 2024

    @parasharrajat
    Member

    Payment requested as per #43569 (comment)

  24. JmillsExpensify commented on Sep 2, 2024

    @JmillsExpensify
    Contributor

    $250 approved for @parasharrajat

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

Metadata

Metadata

Labels

Awaiting PaymentBugDailyExternal

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions