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

[HOLD for payment 2024-06-13] [$250] Distance rate can be deleted from 3-dot menu when there is only one rate #41594

Closed
6 tasks done
m-natarajan opened this issue May 3, 2024 · 33 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor

Comments

@m-natarajan
Copy link

m-natarajan commented May 3, 2024

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.70-0
Reproducible in staging?: Yes
Reproducible in production?: No
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by: Applause Internal Team
Slack conversation:

Action Performed:

Precondition:

  • There is only one default distance rate in the workspace.
  1. Go to staging.new.expensify.com
  2. Go to Account settings > Workspaces > any workspace.
  3. Go to Distance rates.
  4. Go offline.
  5. Add a distance rate,
  6. Delete the default workspace rate (not the newly-added rate).
  7. Click on the checkbox of the newly added distance rate.
  8. Select Delete option from the dropdown.
  9. Note that the distance rate cannot be deleted because there must be at least one distance rate.
  10. Click on the distance rate row.
  11. Delete it from the three-dot menu.

Expected Result:

App will show the same pop-up in Step 9 that the distance rate cannot be deleted as there is only one distance rate.

Actual Result:

Distance rate can be deleted from 3-dot menu when there is only one distance rate.

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

Bug6470164_1714748306876.bandicam_2024-05-03_22-51-33-950.mp4

Add any screenshot/video evidence

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~0144c3fd2f5960b3c2
  • Upwork Job ID: 1786441064248098816
  • Last Price Increase: 2024-05-03
  • Automatic offers:
    • cretadn22 | Contributor | 0
Issue OwnerCurrent Issue Owner: @sobitneupane / @kevinksullivan
@m-natarajan m-natarajan added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels May 3, 2024
Copy link

melvin-bot bot commented May 3, 2024

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

@m-natarajan
Copy link
Author

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

@m-natarajan
Copy link
Author

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

@slafortune slafortune added the External Added to denote the issue can be worked on by a contributor label May 3, 2024
Copy link

melvin-bot bot commented May 3, 2024

Job added to Upwork: https://www.upwork.com/jobs/~0144c3fd2f5960b3c2

@melvin-bot melvin-bot bot changed the title Distance rate can be deleted from 3-dot menu when there is only one rate [$250] Distance rate can be deleted from 3-dot menu when there is only one rate May 3, 2024
@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label May 3, 2024
Copy link

melvin-bot bot commented May 3, 2024

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

@slafortune slafortune moved this to Release 1: Spring 2024 (May) in [#whatsnext] #wave-collect May 3, 2024
@Krishna2323
Copy link
Contributor

Krishna2323 commented May 3, 2024

Proposal

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

Distance rate can be deleted from 3-dot menu when there is only one rate

What is the root cause of that problem?

The condition canDeleteRate isn't correct.

const canDeleteRate = Object.values(customUnit.rates).filter((distanceRate) => distanceRate.enabled).length > 1 || !rate.enabled;
const canDisableRate = Object.values(customUnit.rates).filter((distanceRate) => distanceRate.enabled).length > 1;

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

Remove || !rate.enabled check because user should not be able to delete the receipt until there is one more rate with enabled state. Also, I think we should canDeleteRate and canDisableRate filter out the rates that has pending action value delete. We might also want to filter out the rates with pending action value add. If we are going to filter out rates with pending action value add then we would also need to update that in PolicyDistanceRatesPage.

Optionally, we can filter out as stated above without removing || !rate.enabled check

Also check for other policy pages that has similar functionality

What alternative solutions did you explore? (Optional)

Only change the canDisableRate condition to exclude the rates with pending action delete and also add if needed.

@Krishna2323
Copy link
Contributor

Proposal Upadated

  • Updated main solution

@Krishna2323
Copy link
Contributor

Proposal Upadated

  • Added alternative

@cretadn22
Copy link
Contributor

Proposal

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

Users can delete all distance rate

What is the root cause of that problem?

const canDeleteRate = Object.values(customUnit.rates).filter((distanceRate) => distanceRate.enabled).length > 1 || !rate.enabled;
const canDisableRate = Object.values(customUnit.rates).filter((distanceRate) => distanceRate.enabled).length > 1;

We don't filter out the distance rate with a pendingAction of DELETE

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

See the logic in PolicyDistanceRatesPage, It works well

const canDisableOrDeleteSelectedRates = useMemo(
() => allSelectableRates.filter((rate: Rate) => !selectedDistanceRates.some((selectedRate) => selectedRate.customUnitRateID === rate.customUnitRateID)).some((rate) => rate.enabled),
[allSelectableRates, selectedDistanceRates],

To ensure consistency, we should implement the same solution for PolicyDistanceRatesPage: (but using the current rate instead of selectedDistanceRates)

  1. Introduce a new variable
const allSelectableRates = Object.values(customUnit.rates).filter((rate) => rate.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE)
const canDisableOrDeleteSelectedRates = allSelectableRates.filter((rate: Rate) => rateID !== rate.customUnitRateID).some((rate) => rate.enabled)

  1. Utilize canDisableOrDeleteSelectedRates instead of canDeleteRate and canDisableRate, similar to what was done in the PolicyDistanceRatesPage

Moreover, creating a utility function could help maintain a DRY (Don't Repeat Yourself) codebase.

What alternative solutions did you explore? (Optional)

Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

@jainilparikh
Copy link

jainilparikh commented May 4, 2024

Proposal

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

User is able to delete ALL distance rates when application is offline. Expected scenario is that there should be at-least one distance rate and user should NOT be allowed to delete the last remaining distance rate.

What is the root cause of that problem?

Let's assume that there are N distance rates in the list. Since the user is offline, when the user deletes one of the rates, it become's "disabled" but internally it is still considered to be "enabled". Hence, this condition:

 const canDeleteRate = Object.values(customUnit.rates).filter((distanceRate) => distanceRate.enabled).length > 1 || !rate.enabled; 

More specifically:

Object.values(customUnit.rates).filter((distanceRate) => distanceRate.enabled).length

continues to have a value of N and not N - 1. Because of this, when the user attempt's to delete the last rate, since the value of the above condition is still N, canDeleteRate will be false, hence allowing the user to delete the last entry.

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

set enabled as false in optimisticRates and failureRates in deletePolicyDistanceRates function in

App/src/libs/actions/Policy.ts

Lines 4792 to 4808 in 951c7b3

function deletePolicyDistanceRates(policyID: string, customUnit: CustomUnit, rateIDsToDelete: string[]) {
const currentRates = customUnit.rates;
const optimisticRates: Record<string, Rate> = {};
const successRates: Record<string, Rate> = {};
const failureRates: Record<string, Rate> = {};
for (const rateID of Object.keys(currentRates)) {
if (rateIDsToDelete.includes(rateID)) {
optimisticRates[rateID] = {
...currentRates[rateID],
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
};
failureRates[rateID] = {
...currentRates[rateID],
pendingAction: null,
errors: ErrorUtils.getMicroSecondOnyxError('common.genericErrorMessage'),
};

What alternative solutions did you explore? (Optional)

Option 2:
Adding RED_BRICK_ROAD_PENDING_ACTION in the existing canDeleteRate and canDisableRate conditions

Object.values(customUnit.rates).filter((distanceRate) => distanceRate.enabled && distanceRate.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE).length

Option 3:
Using a logic similar to what's used in PolicyDistanceRatesPage by creating a allSelectableRates variable.

const allSelectableRates = Object.values(customUnit.rates).filter((rate) => rate.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE)
const canDisableOrDeleteSelectedRates = allSelectableRates.filter((rate: Rate) => rateID !== rate.customUnitRateID).some((rate) => rate.enabled)

The problem with the above approaches however is that it does not solve the root of the problem, i.e setting the enabled flag to false for that rate.

Copy link

melvin-bot bot commented May 7, 2024

@slafortune, @sobitneupane Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

@melvin-bot melvin-bot bot added the Overdue label May 7, 2024
@sobitneupane
Copy link
Contributor

Will review the proposals shortly.

@melvin-bot melvin-bot bot removed the Overdue label May 7, 2024
@sobitneupane
Copy link
Contributor

sobitneupane commented May 8, 2024

Thanks for the proposal everyone.

All the proposals are almost same. @Krishna2323 Your proposal needs few refinement. Can you please separate all the options as different solutions in your proposal. You can take this proposal as an example.

Why should we remove pending action add as well? Regarding!rate.enabled, I believe if the rate is disabled there is already an enabled rate (as there is always at least one enabled rate). So, we can safely remove the disabled rate.

@sobitneupane
Copy link
Contributor

sobitneupane commented May 8, 2024

Thanks for the proposal @cretadn22

Your proposal looks good to be. Instead of canDisableOrDeleteSelectedRates, let's name the variable canDisableorDeleteRate and I believe simply adding rate.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE condition in the following should be enough.

const canDeleteRate = Object.values(customUnit.rates).filter((distanceRate) => distanceRate.enabled).length > 1 || !rate.enabled;

const canDisableorDeleteRate = Object.values(customUnit.rates).filter((distanceRate) => distanceRate.enabled && distanceRate.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE).length > 1 || !rate.enabled; 

🎀 👀 🎀 C+ reviewed

Copy link

melvin-bot bot commented May 8, 2024

Triggered auto assignment to @tgolen, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

@Krishna2323
Copy link
Contributor

@sobitneupane, isn't @cretadn22's proposal same as mine with small refactor?

@sobitneupane
Copy link
Contributor

sobitneupane commented May 8, 2024

@Krishna2323 I would say your proposal is rather unclear. You have added multiple things in one place, many of which seem unnecessary.

@Krishna2323
Copy link
Contributor

Remove || !rate.enabled check because user should not be able to delete the receipt until there is one more rate with enabled state. Also, I think we should canDeleteRate and canDisableRate filter out the rates that has pending action value delete.

@sobitneupane, I think this is pretty clear, I mentioned about removing || !rate.enabled check and filtering out with pending action check.

I try to provide solutions for various scenarios because I've encountered situations where the expected outcome changed during discussions, and those who were actively involved at the time took advantage of that.

cc: @tgolen

Copy link

melvin-bot bot commented May 23, 2024

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

@melvin-bot melvin-bot bot added Daily KSv2 and removed Weekly KSv2 labels May 23, 2024
@slafortune slafortune added Weekly KSv2 and removed Daily KSv2 labels May 23, 2024
@slafortune slafortune self-assigned this May 23, 2024
@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels Jun 6, 2024
@melvin-bot melvin-bot bot changed the title [$250] Distance rate can be deleted from 3-dot menu when there is only one rate [HOLD for payment 2024-06-13] [$250] Distance rate can be deleted from 3-dot menu when there is only one rate Jun 6, 2024
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Jun 6, 2024
Copy link

melvin-bot bot commented Jun 6, 2024

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

Copy link

melvin-bot bot commented Jun 6, 2024

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.4.79-11 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-13. 🎊

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

Copy link

melvin-bot bot commented Jun 6, 2024

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:

  • [@sobitneupane] The PR that introduced the bug has been identified. Link to the PR:
  • [@sobitneupane] 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:
  • [@sobitneupane] 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:
  • [@sobitneupane] Determine if we should create a regression test for this bug.
  • [@sobitneupane] 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.
  • [@slafortune / @kevinksullivan] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

@melvin-bot melvin-bot bot added Daily KSv2 and removed Weekly KSv2 labels Jun 12, 2024
@slafortune
Copy link
Contributor

slafortune commented Jun 13, 2024

@cretadn22 Paid ✔️
@sobitneupane can you please complete the checklist?

@melvin-bot melvin-bot bot added the Overdue label Jun 17, 2024
Copy link

melvin-bot bot commented Jun 17, 2024

@tgolen, @slafortune, @sobitneupane, @cretadn22 Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

@tgolen
Copy link
Contributor

tgolen commented Jun 19, 2024

bump @sobitneupane to complete the checklist, please.

@melvin-bot melvin-bot bot removed the Overdue label Jun 19, 2024
@sobitneupane
Copy link
Contributor

sobitneupane commented Jun 20, 2024

Regression Test Proposal

  • Precondition: There is only one default distance rate in the workspace.
  1. Go to Settings > Workspaces > any workspace.
  2. Go to Distance rates.
  3. Go offline.
  4. Add a distance rate,
  5. Delete the default workspace rate (not the newly-added rate).
  6. Click on the checkbox of the newly added distance rate.
  7. Select Delete option from the dropdown.
  8. Verify that the distance rate cannot be deleted because there must be at least one distance rate.
  9. Click on the distance rate row.
  10. Delete it from the three-dot menu.
  11. Verify that the distance rate cannot be deleted because there must be at least one distance rate.

Do we agree 👍 or 👎

@sobitneupane
Copy link
Contributor

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:

  • [@sobitneupane] The PR that introduced the bug has been identified. Link to the PR:

#38237

  • [@sobitneupane] 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:

#38237 (comment)

  • [@sobitneupane] Determine if we should create a regression test for this bug.

yes

  • [@sobitneupane] 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.

#41594 (comment)

@slafortune
Copy link
Contributor

@sobitneupane C+ is due $250 via NewDot

@github-project-automation github-project-automation bot moved this from Release 1: Spring 2024 (May) to Done in [#whatsnext] #wave-collect Jun 20, 2024
@JmillsExpensify
Copy link

$250 approved for @sobitneupane

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor
Projects
No open projects
Archived in project
Development

No branches or pull requests

9 participants