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

[$250] Android - Category - "Default tax rate" briefly changes back to the default one #50078

Open
1 of 6 tasks
lanitochka17 opened this issue Oct 2, 2024 · 37 comments
Open
1 of 6 tasks
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Help Wanted Apply this label when an issue is open to proposals by contributors Weekly KSv2

Comments

@lanitochka17
Copy link

lanitochka17 commented Oct 2, 2024

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Version Number: 9.0.43-1
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

Issue found when executing PR #49867

Action Performed:

  1. Open the app
  2. Log in with a new expensifail account
  3. Create a workspace
  4. Navigate to Workspace settings - More features
  5. Enable Taxes, Rules and Workflows
  6. Navigate to Workspace settings - Categories
  7. Tap on any category
  8. Tap on "Default tax rate"
  9. Select "Tax Rate 1 - 5%"
  10. Tap on "Name"
  11. Add a few characters after the current name and tap on the "Save" button

Expected Result:

"Default tax rate" should be the one I have set before

Actual Result:

"Default tax rate" briefly changes back to the default one when changing category name for the first time

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

Bug6622187_1727880113686.az_recorder_20241002_162644.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021844119049804579315
  • Upwork Job ID: 1844119049804579315
  • Last Price Increase: 2024-11-13
Issue OwnerCurrent Issue Owner: @abdulrahuman5196
@lanitochka17 lanitochka17 added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Oct 2, 2024
Copy link

melvin-bot bot commented Oct 2, 2024

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

@daledah
Copy link
Contributor

daledah commented Oct 2, 2024

Proposal

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

"Default tax rate" briefly changes back to the default one when changing category name for the first time

What is the root cause of that problem?

In

const defaultTaxRateText = useMemo(() => {
const taxID = CategoryUtils.getCategoryDefaultTaxRate(policy?.rules?.expenseRules ?? [], categoryName, policy?.taxRates?.defaultExternalID);

We use categoryName from url params to get tax rate name. However, after changing catefory name, categoryName remains old value for a brief moment before it gets updated:

useEffect(() => {
if (policyCategory?.name === categoryName || !policyCategory) {
return;
}
navigation.setParams({categoryName: policyCategory?.name});
}, [categoryName, navigation, policyCategory]);

And policy?.rules?.expenseRules would have data of new category name, which will make categoryName doesn't exist in the rules, CategoryUtils.getCategoryDefaultTaxRate returns default rate value.

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

We should use policyCategory?.name, as this value also gets updated simultaneously when changing category name.

const taxID = CategoryUtils.getCategoryDefaultTaxRate(policy?.rules?.expenseRules ?? [], categoryName, policy?.taxRates?.defaultExternalID);

        const taxID = CategoryUtils.getCategoryDefaultTaxRate(policy?.rules?.expenseRules ?? [], policyCategory?.name ?? categoryName, policy?.taxRates?.defaultExternalID);

What alternative solutions did you explore? (Optional)

NA

@huult
Copy link
Contributor

huult commented Oct 3, 2024

Edited by proposal-police: This proposal was edited at 2024-10-16 16:07:27 UTC.

Proposal

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

"Default tax rate" briefly changes back to the default one

What is the root cause of that problem?

When we return to the category page from the edit category page, the function defaultTaxRateText is executed before categoryName is updated, so the function defaultTaxRateText still receives the old categoryName. However, since policy?.rules?.expenseRules has been updated, the logic inside the defaultTaxRateText function will return the defaultTaxRate. Because of this, we will see Tax displaying the old tax text that is defaultTaxRate.

The reason defaultTaxRateText is executed before categoryName is updated is that policy?.rules?.expenseRules was changed when we called RENAME_WORKSPACE_CATEGORY, and it is in the dependency of the useMemo hook of the function defaultTaxRateText.

}, [categoryName, policy?.rules?.expenseRules, policy?.taxRates, translate]);

After that, categoryName will update and set the new value in the URL parameters. Consequently, defaultTaxRateText will re-render again because categoryName changed in the dependencies of the useMemo hook, and defaultTaxRateText will update with the correct tax text.

navigation.setParams({categoryName: policyCategory?.name});

Because defaultTaxRateText renders twice, the first time it receives the old category and returns the default tax text, and the second time it receives the new category name and returns the correct tax text. So, this issue happens, and it only happens once.

This video describes what I mentioned above.
Screen.Recording.2024-10-24.at.19.03.25.mp4

This issue happened only once after the first editing of the category name due to changes in the policy?.rules?.expenseRules data object structure. In React, useEffect or useMemo use shallow comparison: React only compares references of objects/arrays, not their contents.

You can see in the JSON below that policy?.rules?.expenseRules changes after the first editing of the category name, and it will not change for the next edited category name because the policy?.rules?.expenseRules object structure does not change. Therefore, this issue will not happen with the next edited category name.

and policy?.rules?.expenseRules

This is policy?.rules?.expenseRules data

// Before editing the category name (from SetPolicyCategoryTax response)
[
  {
    "tax": { "field_id_TAX": { "externalID": "id_TAX_RATE_1" } },
    "applyWhen": [
      { "condition": "matches", "field": "category", "value": "Taxes" }
    ]
  }
]

// After editing the category name and going back to the category page(from RenameWorkspaceCategory response)

[
  {
    "applyWhen": [
      { "condition": "matches", "field": "category", "value": "Taxes" }
    ],
    "id": "671a27db42e27",
    "tax": { "field_id_TAX": { "externalID": "id_TAX_RATE_1" } }
  }
]

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

To resolve this issue, we must call defaultTaxRateText after the category name update is complete. To do that, we must delay going back until the category name has finished updating. Something like this:

// .src/pages/workspace/categories/EditCategoryPage.tsx#L52

    const editCategory = useCallback(
        (values: FormOnyxValues<typeof ONYXKEYS.FORMS.WORKSPACE_CATEGORY_FORM>) => {
            ....
+              InteractionManager.runAfterInteractions(() => {
+                requestAnimationFrame(() => {
 Navigation.goBack(
                isQuickSettingsFlow
                    ? ROUTES.SETTINGS_CATEGORY_SETTINGS.getRoute(route.params.policyID, route.params.categoryName, backTo)
                    : ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(route.params.policyID, route.params.categoryName),
            );
+                });
+            });
        },
        [backTo, currentCategoryName, route.params.categoryName, route.params.policyID],
    );

What alternative solutions did you explore? (Optional)

alternative solutions 1

Or we can use the policyCategory data to get the new category name after editing to retrieve the default tax rate, because policyCategory has updated values that match with expenseRules

-     const taxID = CategoryUtils.getCategoryDefaultTaxRate(policy?.rules?.expenseRules ?? [], categoryName, policy?.taxRates?.defaultExternalID);
+    const taxID = CategoryUtils.getCategoryDefaultTaxRate(
+            policy?.rules?.expenseRules ?? [],
+            !policyCategory?.name 
+                ? categoryName 
+                : (policyCategory?.name !== categoryName 
+                    ? policyCategory?.name 
+                    : categoryName)
+            policy?.taxRates?.defaultExternalID,
+        );
POC
Screen.Recording.2024-10-03.at.23.19.38.mov

@melvin-bot melvin-bot bot added the Overdue label Oct 4, 2024
Copy link

melvin-bot bot commented Oct 7, 2024

@JmillsExpensify Eep! 4 days overdue now. Issues have feelings too...

Copy link

melvin-bot bot commented Oct 9, 2024

@JmillsExpensify 6 days overdue. This is scarier than being forced to listen to Vogon poetry!

@JmillsExpensify JmillsExpensify added the External Added to denote the issue can be worked on by a contributor label Oct 9, 2024
Copy link

melvin-bot bot commented Oct 9, 2024

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

@melvin-bot melvin-bot bot changed the title Android - Category - "Default tax rate" briefly changes back to the default one [$250] Android - Category - "Default tax rate" briefly changes back to the default one Oct 9, 2024
@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Oct 9, 2024
Copy link

melvin-bot bot commented Oct 9, 2024

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

@melvin-bot melvin-bot bot removed the Overdue label Oct 9, 2024
@JmillsExpensify
Copy link

Opened up for proposal review

Copy link

melvin-bot bot commented Oct 15, 2024

@JmillsExpensify, @abdulrahuman5196 Huh... This is 4 days overdue. Who can take care of this?

@melvin-bot melvin-bot bot added the Overdue label Oct 15, 2024
Copy link

melvin-bot bot commented Oct 16, 2024

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

Copy link

melvin-bot bot commented Oct 16, 2024

@JmillsExpensify @abdulrahuman5196 this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!

@JmillsExpensify
Copy link

Still waiting on proposal review.

@abdulrahuman5196
Copy link
Contributor

Checking now

@melvin-bot melvin-bot bot removed the Overdue label Oct 17, 2024
@abdulrahuman5196
Copy link
Contributor

I don't see the issue anymore, can we check if its still reproducible?

Screen.Recording.2024-10-17.at.6.54.31.PM.mov

@huult
Copy link
Contributor

huult commented Oct 17, 2024

Still able to be reproduced

Screen.Recording.2024-10-17.at.20.40.44.mov

@huult
Copy link
Contributor

huult commented Oct 23, 2024

@abdulrahuman5196 Can you create a new workspace and follow the steps in this ticket? This issue just happened once.

@huult
Copy link
Contributor

huult commented Oct 24, 2024

Proposal updated

  • Update RCA
  • Add alternative solutions

@abdulrahuman5196 I would like to share this video with you to show how we can reproduce this issue.

Screen.Recording.2024-10-24.at.19.44.03.mov

@abdulrahuman5196
Copy link
Contributor

Thank you for this. Let me try again a couple of times today and update here.

Copy link

melvin-bot bot commented Oct 30, 2024

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

@melvin-bot melvin-bot bot added the Overdue label Oct 30, 2024
@JmillsExpensify
Copy link

Still in progress

@JmillsExpensify JmillsExpensify added Weekly KSv2 and removed Daily KSv2 labels Oct 30, 2024
@melvin-bot melvin-bot bot removed the Overdue label Oct 30, 2024
Copy link

melvin-bot bot commented Oct 30, 2024

@JmillsExpensify @abdulrahuman5196 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!

@wildan-m
Copy link
Contributor

wildan-m commented Nov 1, 2024

Proposal

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

Android: "Default tax rate" temporarily reverts to the default value.

What is the root cause of that problem?

There is a chance that we navigated before execute Onyx.update first. The blinking actually also affect the category name itself, not only rate.

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

In this case, it's important to execute Onyx.update first before proceeding with the navigation action. We can achieve this by using Navigation.setNavigationActionToMicrotaskQueue as it's a commonly used pattern.

https://github.com/search?q=repo%3AExpensify%2FApp+Navigation.setNavigationActionToMicrotaskQueue%28&type=code

Modify this code:

Navigation.goBack(
isQuickSettingsFlow
? ROUTES.SETTINGS_CATEGORY_SETTINGS.getRoute(route.params.policyID, route.params.categoryName, backTo)
: ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(route.params.policyID, route.params.categoryName),
);

To

            Navigation.setNavigationActionToMicrotaskQueue(()=>{
                Navigation.goBack(
                    isQuickSettingsFlow
                        ? ROUTES.SETTINGS_CATEGORY_SETTINGS.getRoute(route.params.policyID, route.params.categoryName, backTo)
                        : ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(route.params.policyID, route.params.categoryName),
                );
            });

or only to this if category name changes

    const editCategory = useCallback(
        (values: FormOnyxValues<typeof ONYXKEYS.FORMS.WORKSPACE_CATEGORY_FORM>) => {
            const newCategoryName = values.categoryName.trim();
            const navigateBack = () => {
                Navigation.goBack(
                    isQuickSettingsFlow
                        ? ROUTES.SETTINGS_CATEGORY_SETTINGS.getRoute(route.params.policyID, route.params.categoryName, backTo)
                        : ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(route.params.policyID, route.params.categoryName),
                );
            };
    
            // Do not call the API if the edited category name is the same as the current category name
            if (currentCategoryName !== newCategoryName) {
                Category.renamePolicyCategory(route.params.policyID, {oldName: currentCategoryName, newName: values.categoryName});
                Navigation.setNavigationActionToMicrotaskQueue(navigateBack);
                return;
            }
    
            navigateBack();
        },
        [isQuickSettingsFlow, currentCategoryName, route.params.categoryName, route.params.policyID, backTo],
    );

Branch for this solution

What alternative solutions did you explore? (Optional)

N/A

@melvin-bot melvin-bot bot added Daily KSv2 and removed Weekly KSv2 labels Nov 1, 2024
Copy link

melvin-bot bot commented Nov 4, 2024

@JmillsExpensify, @abdulrahuman5196 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 Nov 4, 2024
Copy link

melvin-bot bot commented Nov 6, 2024

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

@JmillsExpensify
Copy link

@abdulrahuman5196 any thoughts on the latest proposal posted?

@JmillsExpensify JmillsExpensify added Weekly KSv2 and removed Daily KSv2 labels Nov 6, 2024
@melvin-bot melvin-bot bot removed the Overdue label Nov 6, 2024
@abdulrahuman5196
Copy link
Contributor

Hi, Checking now

@garrettmknight garrettmknight moved this to Bugs and Follow Up Issues in [#whatsnext] #expense Nov 11, 2024
Copy link

melvin-bot bot commented Nov 13, 2024

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

@abdulrahuman5196
Copy link
Contributor

Checking now again

@abdulrahuman5196
Copy link
Contributor

Hi, I am still unable to repro the issue. I reached out in C+ channel to see, if any one is able to repro this and takeover.
https://expensify.slack.com/archives/C02NK2DQWUX/p1731523034411719

@allgandalf
Copy link
Contributor

allgandalf commented Nov 13, 2024

I am able to reproduce taking over! @JmillsExpensify please assign me here

Screen.Recording.2024-11-14.at.12.21.22.AM.mov

@wildan-m
Copy link
Contributor

I consistently reproduce it by creating a new workspace for each test rather than reusing the same one.

@abdulrahuman5196
Copy link
Contributor

@JmillsExpensify Kindly assign this issue to @allgandalf . Unassigning myself.

@abdulrahuman5196 abdulrahuman5196 removed their assignment Nov 14, 2024
@allgandalf
Copy link
Contributor

bump for assignment @JmillsExpensify

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Help Wanted Apply this label when an issue is open to proposals by contributors Weekly KSv2
Projects
Status: Bugs and Follow Up Issues
Development

No branches or pull requests

7 participants