Skip to content

[HOLD for payment 2024-11-18] [$250] Distance - Blank map preview on employee side when selecting distance rate with different unit #51285

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.52-2
Reproducible in staging?: Y
Reproducible in production?: Y
Email or phone of affected tester (no customers): applausetester+ck11020@applause.expensifail.com
Issue reported by: Applause Internal Team

Action Performed:

Precondition:

  1. Admin invited employee to workspace
  2. Distance rates enabled in WS settings & Unit set to Miles in distance rates settings

Employee' side:

  1. Navigate to staging.new.expensify.com
  2. Click >> FAB >> Submit Expense >> Distance tab
  3. Submit distance expense
  4. Go to expense details page

Admin's side:

  1. Go to WS settings >> Distance rates
  2. Select settings option
  3. Change the unit to Kilometer

Employee's side:

  1. On the expense details page, select distance rate field
  2. Select a different rate

Expected Result:

When admin changes the distance unit setting, map preview for distance expense should update on employee side on selecting distance rate with different unit
However, map preview on admin's side in expense details page gets updated as expected

Actual Result:

Blank map preview on employee side when selecting distance rate with different unit

Workaround:

Unknown

Platforms:

  • Android: Standalone
  • Android: HybridApp
  • Android: mWeb Chrome
  • iOS: Standalone
  • iOS: HybridApp
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Bug6642204_1729611204693.Recording__4__4_.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021849108498732119693
  • Upwork Job ID: 1849108498732119693
  • Last Price Increase: 2024-10-23
  • Automatic offers:
    • ishpaul777 | Reviewer | 104675461
    • nkdengineer | Contributor | 104675465
Issue OwnerCurrent Issue Owner: @Christinadobrzyn

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Oct 22, 2024
  2. melvin-bot commented on Oct 22, 2024

    @melvin-bot

    Triggered auto assignment to @lschurr (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. IuliiaHerets commented on Oct 22, 2024

    @IuliiaHerets
    Author

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

  4. IuliiaHerets commented on Oct 22, 2024

    @IuliiaHerets
    Author

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

  5. FitseTLT commented on Oct 23, 2024

    @FitseTLT
    Contributor

    Proposal

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

    Distance - Blank map preview on employee side when selecting distance rate with different unit

    What is the root cause of that problem?

    When the newDistanceUnit is different from existingDistanceUnit we are setting pendingFields waypoints here

    lodashSet(updatedTransaction, 'pendingFields.waypoints', CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE);

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

    When newDistanceUnit is different from existingDistanceUnit we are changing comment.customUnit.quantity and we aren't touching the waypoints in any way so we do not need to set pendinFields waypoints. Hence, we should remove this line

    lodashSet(updatedTransaction, 'pendingFields.waypoints', CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE);

    What alternative solutions did you explore? (Optional)

  6. nkdengineer commented on Oct 23, 2024

    @nkdengineer
    Contributor

    Edited by proposal-police: This proposal was edited at 2024-10-30 04:59:47 UTC.

    Proposal

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

    Blank map preview on employee side when selecting distance rate with different unit

    What is the root cause of that problem?

    When we change the distance rate if the unit is changed, we will add pendingFields.waypoints to updatedTransaction

    // Get the new distance unit from the rate's unit
    const newDistanceUnit = DistanceRequestUtils.getUpdatedDistanceUnit({transaction: updatedTransaction, policy});
    // If the distanceUnit is set and the rate is changed to one that has a different unit, convert the distance to the new unit
    if (existingDistanceUnit && newDistanceUnit !== existingDistanceUnit) {
    const conversionFactor = existingDistanceUnit === CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES ? CONST.CUSTOM_UNITS.MILES_TO_KILOMETERS : CONST.CUSTOM_UNITS.KILOMETERS_TO_MILES;
    const distance = NumberUtils.roundToTwoDecimalPlaces((transaction?.comment?.customUnit?.quantity ?? 0) * conversionFactor);
    lodashSet(updatedTransaction, 'comment.customUnit.quantity', distance);
    lodashSet(updatedTransaction, 'pendingFields.waypoints', CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE);

    We override pendingFields here which causes updatedTransaction.pendingFields to be an empty object

    updatedTransaction.pendingFields = {

    But updatedTransaction is only a shadow clone of transaction then transaction that is getting from allTransactions is updated when we use lodashSet. Then when optimistic data is merged pendingFields.waypoints is update in Onyx

    const updatedTransaction = {...transaction};

    And this pendingFields isn't cleared in success data because updatedTransaction.pendingFields is an empty object which causes clearedPendingFields not to include waypoint field

    const clearedPendingFields = Object.fromEntries(Object.keys(updatedTransaction?.pendingFields ?? transactionChanges).map((key) => [key, null]));

    After all, pendingFields.waypoints isn't cleared then the map view isn't shown here

    const hasPendingWaypoints = transaction && TransactionUtils.isFetchingWaypointsFromServer(transaction);
    const hasErrors = !isEmptyObject(transaction?.errors) || !isEmptyObject(transaction?.errorFields);
    const showMapAsImage = isDistanceRequest && (hasErrors || hasPendingWaypoints);

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

    1. I guess we add pendingFields.waypoints here to gray out the distance field when we change the distance rate offline.

    // Get the new distance unit from the rate's unit
    const newDistanceUnit = DistanceRequestUtils.getUpdatedDistanceUnit({transaction: updatedTransaction, policy});
    // If the distanceUnit is set and the rate is changed to one that has a different unit, convert the distance to the new unit
    if (existingDistanceUnit && newDistanceUnit !== existingDistanceUnit) {
    const conversionFactor = existingDistanceUnit === CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES ? CONST.CUSTOM_UNITS.MILES_TO_KILOMETERS : CONST.CUSTOM_UNITS.KILOMETERS_TO_MILES;
    const distance = NumberUtils.roundToTwoDecimalPlaces((transaction?.comment?.customUnit?.quantity ?? 0) * conversionFactor);
    lodashSet(updatedTransaction, 'comment.customUnit.quantity', distance);
    lodashSet(updatedTransaction, 'pendingFields.waypoints', CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE);

    But pendingFields.waypoints is also used to check whether we're fetching the waypoints from the server or not then I think we should separate these cases to use two pendingFields

    For this case, I think we can use pendingFields.merchant because only the display distance text is changed

    // Get the new distance unit from the rate's unit
    const newDistanceUnit = DistanceRequestUtils.getUpdatedDistanceUnit({transaction: updatedTransaction, policy});
    // If the distanceUnit is set and the rate is changed to one that has a different unit, convert the distance to the new unit
    if (existingDistanceUnit && newDistanceUnit !== existingDistanceUnit) {
    const conversionFactor = existingDistanceUnit === CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES ? CONST.CUSTOM_UNITS.MILES_TO_KILOMETERS : CONST.CUSTOM_UNITS.KILOMETERS_TO_MILES;
    const distance = NumberUtils.roundToTwoDecimalPlaces((transaction?.comment?.customUnit?.quantity ?? 0) * conversionFactor);
    lodashSet(updatedTransaction, 'comment.customUnit.quantity', distance);
    lodashSet(updatedTransaction, 'pendingFields.waypoints', CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE);

    <OfflineWithFeedback pendingAction={getPendingFieldAction('waypoints') || getPendingFieldAction('merchant')}> 
    

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

    1. We should update this line not to override the existing pending field that we updated at the logic here
    updatedTransaction.pendingFields = {
            ...(updatedTransaction.pendingFields ?? {}),
            ....
            }
    

    updatedTransaction.pendingFields = {

    1. We should use deep clone here by using lodashCloneDeep from lodash/cloneDeep
    const updatedTransaction = lodashCloneDeep(transaction);
    

    const updatedTransaction = {...transaction};

    1. We should update pendingFields variable then it can be updated correctly in optimistic data.
    if (updatedTransaction?.pendingFields) {
        pendingFields = {
            ...pendingFields,
            ...updatedTransaction?.pendingFields,
        };
    }
    

    What alternative solutions did you explore? (Optional)

    If we still want to display a blank view until the API is complete we can skip point 1 above

    Or if we don't want to gray out the distance field when updating to a different unit, we can remove this line but we still need to deep clone the transaction to prevent the same case can happen in the feature.

    lodashSet(updatedTransaction, 'pendingFields.waypoints', CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE);

  7. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Oct 23, 2024
  8. changed the title [-]Distance - Blank map preview on employee side when selecting distance rate with different unit[/-] [+][$250] Distance - Blank map preview on employee side when selecting distance rate with different unit[/+] on Oct 23, 2024
  9. melvin-bot commented on Oct 23, 2024

    @melvin-bot
  10. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Oct 23, 2024
  11. melvin-bot commented on Oct 23, 2024

    @melvin-bot

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

  12. melvin-bot commented on Oct 28, 2024

    @melvin-bot

    @lschurr, @ishpaul777 Eep! 4 days overdue now. Issues have feelings too...

  13. 22 remaining items

  14. melvin-bot commented on Nov 11, 2024

    @melvin-bot

    Reviewing label has been removed, please complete the "BugZero Checklist".

  15. melvin-bot commented on Nov 11, 2024

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.0.59-3 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

    If no regressions arise, payment will be issued on 2024-11-18. 🎊

    For reference, here are some details about the assignees on this issue:

  16. melvin-bot commented on Nov 11, 2024

    @melvin-bot

    @ishpaul777 @lschurr The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]

  17. removed
    BugSomething is broken. Auto assigns a BugZero manager.
    on Nov 18, 2024
  18. twisterdotcom commented on Nov 18, 2024

    @twisterdotcom
    Contributor

    Relabelling as Lauren is OOO now.

  19. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Nov 18, 2024
  20. melvin-bot commented on Nov 18, 2024

    @melvin-bot

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

  21. Christinadobrzyn commented on Nov 19, 2024

    @Christinadobrzyn
    Contributor

    @ishpaul777 do we need a regression test for this?

  22. ishpaul777 commented on Nov 19, 2024

    @ishpaul777
    Contributor

    BugZero Checklist:

    • [Contributor] Classify the bug:
    Bug classification

    Source of bug:

    • 1a. Result of the original design (eg. a case wasn't considered)
    • 1b. Mistake during implementation
    • 1c. Backend bug
    • 1z. Other:

    Where bug was reported:

    • 2a. Reported on production
    • 2b. Reported on staging (deploy blocker)
    • 2c. Reported on both staging and production
    • 2d. Reported on a PR
    • 2z. Other:

    Who reported the bug:

    • 3a. Expensify user
    • 3b. Expensify employee
    • 3c. Contributor
    • 3d. QA
    • 3z. Other:
    • [Contributor] 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: https://github.com/Expensify/App/pull/50001/files#r1847961062

    • [Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source 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: Not Critical but a edge case now its fixed no neeed to start a discussion

    • [Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.

    Yes, it would be good to have a regression test

    Regression Test Proposal

    Precondition:

    • Admin invited employee to workspace
    • Distance rates enabled in WS settings & Unit set to Miles in distance rates settings

    Test:

    Employee' side:

    1. Navigate to staging.new.expensify.com
    2. Click >> FAB >> Submit Expense >> Distance tab
    3. Submit distance expense
    4. Go to expense details page

    Admin's side:

    1. Go to WS settings >> Distance rates
    2. Select settings option
    3. Change the unit to Kilometer

    Employee's side:

    1. On the expense details page, select distance rate field
    2. Select a different rate

    Verify Expected Result:

    Map preview for distance expense should update on employee side on selecting distance rate with different unit and should not be blank.

    Do we agree 👍 or 👎

  23. Christinadobrzyn commented on Nov 20, 2024

    @Christinadobrzyn
    Contributor

    Thanks @ishpaul777! I paid out through Upwork based on this payment summary.

    Closing!

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

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions