Skip to content

[C+ Checklist Needs Completion] [$250] Distance rates - Order of distance rates is not preserved after clearing cache and restarting #42939

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.78-2
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught during regression testing, add the test name, ID and link from TestRail: N/A
Issue reported by: Applause - Internal Team

Action Performed:

  1. Go to staging.new.expensify.com
  2. Go to workspace settings > Distance rates
  3. Add a few distance rates
  4. Note that order of distance rates is A, B, C, D, E etc
  5. Go to Troubleshoot > Clear cache and restart
  6. Select Reset and refresh
  7. Return to Distance rates page

Expected Result:

The order of distance rates will remain as A, B, C, D, E etc

Actual Result:

The order of distance rates is no longer A, B, C, D, E etc

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

Bug6497628_1717166582761.20240531_223747.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~0149693392cec4578c
  • Upwork Job ID: 1796700279945052160
  • Last Price Increase: 2024-06-01
  • Automatic offers:
    • Krishna2323 | Contributor | 102631316
Issue OwnerCurrent Issue Owner: @greg-schroeder

Activity

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

    @melvin-bot

    Triggered auto assignment to @greg-schroeder (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 May 31, 2024

    @lanitochka17
    Author

    @greg-schroeder 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 May 31, 2024

    @lanitochka17
    Author

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

  5. Krishna2323 commented on May 31, 2024

    @Krishna2323
    Contributor

    Proposal

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

    Distance rates - Order of distance rates is not preserved after clearing cache and restarting

    What is the root cause of that problem?

    We don't sort the distanceRatesList.

    const distanceRatesList = useMemo<RateForList[]>(
    () =>
    Object.values(customUnitRates).map((value) => ({
    value: value.customUnitRateID ?? '',
    text: `${CurrencyUtils.convertAmountToDisplayString(value.rate, value.currency ?? CONST.CURRENCY.USD)} / ${translate(
    `common.${customUnit?.attributes?.unit ?? CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES}`,
    )}`,
    keyForList: value.customUnitRateID ?? '',
    isSelected: selectedDistanceRates.find((rate) => rate.customUnitRateID === value.customUnitRateID) !== undefined,
    isDisabled: value.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
    pendingAction: value.pendingAction ?? value.pendingFields?.rate ?? value.pendingFields?.enabled ?? value.pendingFields?.currency,
    errors: value.errors ?? undefined,
    rightElement: <ListItemRightCaretWithLabel labelText={value.enabled ? translate('workspace.common.enabled') : translate('workspace.common.disabled')} />,
    })),
    [customUnit?.attributes?.unit, customUnitRates, selectedDistanceRates, translate],
    );

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

    We can sort the list by the text or the value.

    If we decide to sort it by the text then we can add:

    .sort((a, b) => localeCompare(a.text, b.text)) ?? []

    If we decide to sort by the rate then we can simply add rate property in each object and then sort:

        const distanceRatesList = useMemo<RateForList[]>(
            () =>
                Object.values(customUnitRates)
                    .map((value) => ({
                        value: value.customUnitRateID ?? '',
                        rate: value.rate ?? 0,
                        text: `${CurrencyUtils.convertAmountToDisplayString(value.rate, value.currency ?? CONST.CURRENCY.USD)} / ${translate(
                            `common.${customUnit?.attributes?.unit ?? CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES}`,
                        )}`,
                        keyForList: value.customUnitRateID ?? '',
                        isSelected: selectedDistanceRates.find((rate) => rate.customUnitRateID === value.customUnitRateID) !== undefined,
                        isDisabled: value.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
                        pendingAction: value.pendingAction ?? value.pendingFields?.rate ?? value.pendingFields?.enabled ?? value.pendingFields?.currency,
                        errors: value.errors ?? undefined,
                        rightElement: <ListItemRightCaretWithLabel labelText={value.enabled ? translate('workspace.common.enabled') : translate('workspace.common.disabled')} />,
                    }))
                    .sort((a, b) => a.rate - b.rate) ?? [],
            [customUnit?.attributes?.unit, customUnitRates, selectedDistanceRates, translate],
        );

    We can also sort in descending order and with any suggested field.

    What alternative solutions did you explore? (Optional)

  6. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Jun 1, 2024
  7. changed the title [-]Distance rates - Order of distance rates is not preserved after clearing cache and restarting[/-] [+][$250] Distance rates - Order of distance rates is not preserved after clearing cache and restarting[/+] on Jun 1, 2024
  8. melvin-bot commented on Jun 1, 2024

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

    @melvin-bot

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

  11. cretadn22 commented on Jun 1, 2024

    @cretadn22
    Contributor

    Proposal

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

    Order of distance rates is not preserved after clearing cache and restarting

    What is the root cause of that problem?

    We haven't yet applied the sorting algorithm to the distance rate page

    const distanceRatesList = useMemo<RateForList[]>(
    () =>
    Object.values(customUnitRates).map((value) => ({
    value: value.customUnitRateID ?? '',
    text: `${CurrencyUtils.convertAmountToDisplayString(value.rate, value.currency ?? CONST.CURRENCY.USD)} / ${translate(

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

    const distanceRatesList = useMemo<RateForList[]>(
    () =>
    Object.values(customUnitRates).map((value) => ({
    value: value.customUnitRateID ?? '',
    text: `${CurrencyUtils.convertAmountToDisplayString(value.rate, value.currency ?? CONST.CURRENCY.USD)} / ${translate(

    we should sort distance rate by rate field, we must sort them beforehand as the rate field is not included in the distanceRatesList, ensuring sorting is done prior to the map function.

    const distanceRatesList = useMemo<RateForList[]>(
            () =>
                Object.values(customUnitRates)
                    .sort((taxA, taxB) => (taxA?.rate ?? 0) - (taxB?.rate ?? 0))
                    .map((value) => ({
                        value: value.customUnitRateID ?? '',
    

    We shouldn't include a rate field in the returned value as suggested earlier, as it serves no purpose.

    What alternative solutions did you explore? (Optional)

  12. 42 remaining items

  13. melvin-bot commented on Jun 21, 2024

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 1.4.85-7 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-06-28. 🎊

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

  14. melvin-bot commented on Jun 21, 2024

    @melvin-bot

    BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

    • [@allroundexperts] The PR that introduced the bug has been identified. Link to the PR:
    • [@allroundexperts] 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:
    • [@allroundexperts] 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:
    • [@allroundexperts] Determine if we should create a regression test for this bug.
    • [@allroundexperts] 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.
    • [@greg-schroeder] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:
  15. greg-schroeder commented on Jun 27, 2024

    @greg-schroeder
    Contributor

    @allroundexperts - $250 - You can make a manual request via ND
    @Krishna2323 - $250 - Paid through Upwork

  16. greg-schroeder commented on Jun 27, 2024

    @greg-schroeder
    Contributor

    C+ checklist is all we need for tomorrow and we can close!

  17. changed the title [-][HOLD for payment 2024-06-28] [$250] Distance rates - Order of distance rates is not preserved after clearing cache and restarting[/-] [+][C+ Checklist Needs Completion] [$250] Distance rates - Order of distance rates is not preserved after clearing cache and restarting[/+] on Jun 27, 2024
  18. melvin-bot commented on Jun 28, 2024

    @melvin-bot

    @tgolen @greg-schroeder @allroundexperts @Krishna2323 this issue is now 4 weeks old, please consider:

    • Finding a contributor to fix the bug
    • Closing the issue if BZ has been unable to add the issue to a VIP or Wave project
    • If you have any questions, don't hesitate to start a discussion in #expensify-open-source

    Thanks!

  19. allroundexperts commented on Jun 30, 2024

    @allroundexperts
    Contributor

    Checklist

    1. We never implemented sorting of distance rates on the frontend. As such, this issue exists since the beginning when this feature was added ie here.
    2. N/A
    3. N/A
    4. A regression test would be helpful here. The steps given in the OP look good enough to me.
  20. greg-schroeder commented on Jul 1, 2024

    @greg-schroeder
    Contributor

    Okay filing using OP steps

  21. JmillsExpensify commented on Jul 20, 2024

    @JmillsExpensify
    Contributor

    $250 approved for @allroundexperts

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

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions