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] Tax - Enable/disable option shows rates text in plural instead rate #51017

Open
8 tasks
lanitochka17 opened this issue Oct 17, 2024 · 22 comments
Open
8 tasks
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 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

Comments

@lanitochka17
Copy link

lanitochka17 commented Oct 17, 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.50-0
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught on HybridApp, is this reproducible on New Expensify Standalone?: N/A
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 https://staging.new.expensify.com/home
  2. Tap profile icon - workspaces -- workspace
  3. Tap more features - enable taxes
  4. Create few tax rates
  5. Disable a tax rate
  6. Long press and select one disabled and one enabled tax rate
  7. Tap dropdown on top and view options

Expected Result:

Enable/disable option must not show rates text in plural and it must show rate

Actual Result:

Enable/disable option shows rates text in plural instead rate when only one enabled and disabled rate are selected

Workaround:

Unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

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

Screenshots/Videos

Add any screenshot/video evidence
Bug6637276_1729142094339.rate.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021846961178055724837
  • Upwork Job ID: 1846961178055724837
  • Last Price Increase: 2024-10-24
Issue OwnerCurrent Issue Owner: @getusha
@lanitochka17 lanitochka17 added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Oct 17, 2024
Copy link

melvin-bot bot commented Oct 17, 2024

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

@lanitochka17
Copy link
Author

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

Copy link
Contributor

rzghnsy Your proposal will be dismissed because you did not follow the proposal template.

@nyomanjyotisa
Copy link
Contributor

nyomanjyotisa commented Oct 17, 2024

Edited by proposal-police: This proposal was edited at 2024-10-17 13:37:10 UTC.

Proposal

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

Tax - Enable/disable option shows rates text in plural instead rate

What is the root cause of that problem?

We show plural text base on isMultiple variable, without checking the enable/disable status of the selected tax

const isMultiple = selectedTaxesIDs.length > 1;

text: isMultiple ? translate('workspace.taxes.actions.disableMultiple') : translate('workspace.taxes.actions.disable'),

text: isMultiple ? translate('workspace.taxes.actions.enableMultiple') : translate('workspace.taxes.actions.enable'),

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

Create new variables to check is there multiple enabled tax selected and is there multiple disabled tax selected

        const isMultipleEnabled = selectedTaxesIDs.filter((taxID) => !policy?.taxRates?.taxes[taxID]?.isDisabled).length > 1;
        const isMultipleDisabled = selectedTaxesIDs.filter((taxID) => policy?.taxRates?.taxes[taxID]?.isDisabled).length > 1;
// `Disable rates` when at least one enabled rate is selected.
        if (selectedTaxesIDs.some((taxID) => !policy?.taxRates?.taxes[taxID]?.isDisabled)) {
            options.push({
                icon: Expensicons.DocumentSlash,
                text: isMultipleEnabled ? translate('workspace.taxes.actions.disableMultiple') : translate('workspace.taxes.actions.disable'),
                value: CONST.POLICY.BULK_ACTION_TYPES.DISABLE,
                onSelected: () => toggleTaxes(false),
            });
        }

        // `Enable rates` when at least one disabled rate is selected.
        if (selectedTaxesIDs.some((taxID) => policy?.taxRates?.taxes[taxID]?.isDisabled)) {
            options.push({
                icon: Expensicons.Document,
                text: isMultipleDisabled ? translate('workspace.taxes.actions.enableMultiple') : translate('workspace.taxes.actions.enable'),
                value: CONST.POLICY.BULK_ACTION_TYPES.ENABLE,
                onSelected: () => toggleTaxes(true),
            });
        }

What alternative solutions did you explore? (Optional)

@Nodebrute
Copy link
Contributor

Proposal

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

Enable/disable option shows rates text in plural instead rate

What is the root cause of that problem?

Here we only see if selected tags are more than 1 instead of checking disable/enable tags count

const isMultiple = selectedTaxesIDs.length > 1;

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

We can create 2 new variables

        const disableTaxes = selectedTaxesIDs.filter((taxID) => policy?.taxRates?.taxes[taxID]?.isDisabled);
        const enabledTaxes = selectedTaxesIDs.filter((taxID) => !policy?.taxRates?.taxes[taxID]?.isDisabled);

and then in here we can check

   if (disableTaxes.length > 0)

and in here we can change this to

 text: disableTaxes.length === 1 ?  translate('workspace.taxes.actions.disable') : translate('workspace.taxes.actions.disableMultiple'),

We can do same for enable tags

What alternative solutions did you explore? (Optional)

@ChavdaSachin
Copy link
Contributor

ChavdaSachin commented Oct 17, 2024

Edited by proposal-police: This proposal was edited at 2024-10-17 13:57:28 UTC.

Proposal

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

Tax - Enable/disable option shows rates text in plural instead rate

What is the root cause of that problem?

Irrespective of number of available rates to enable/disable, we check only for number of selections here.

const isMultiple = selectedTaxesIDs.length > 1;

text: isMultiple ? translate('workspace.taxes.actions.disableMultiple') : translate('workspace.taxes.actions.disable'),

text: isMultiple ? translate('workspace.taxes.actions.enableMultiple') : translate('workspace.taxes.actions.enable'),

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

Rather create new objects enabledRates and disabledRates

        const enbledRates = selectedTaxesIDs.filter((taxID) => policy?.taxRates?.taxes[taxID]?.isDisabled);
        const disabledRates = selectedTaxesIDs.filter((taxID) => !policy?.taxRates?.taxes[taxID]?.isDisabled);

now use enabledRates?.length here to saw the option

        if (enabledRates?.length) {

if (selectedTaxesIDs.some((taxID) => !policy?.taxRates?.taxes[taxID]?.isDisabled)) {

and use enabledRates?.length > 1 instead of isMultiple here
text: isMultiple ? translate('workspace.taxes.actions.disableMultiple') : translate('workspace.taxes.actions.disable'),

Similar for Enable option use 'disabledRates?.length' here.

        if (disabledRates?.length) {

if (selectedTaxesIDs.some((taxID) => policy?.taxRates?.taxes[taxID]?.isDisabled)) {

And use disabledRates?.length > 1 instead of isMultiple here.
text: isMultiple ? translate('workspace.taxes.actions.enableMultiple') : translate('workspace.taxes.actions.enable'),

This way we optimize the solution and do not have to filter array twice.

What alternative solutions did you explore? (Optional)

And since we make use of this logic only to determine length of selections, we could optimize it further.

Only create 1 object which holds count of enabled selections and use it to determine length of disabledSelectionCount.

        const enabledRatesCount = selectedTaxesIDs.filter((taxID) => !policy?.taxRates?.taxes[taxID]?.isDisabled).length;
        const disabledRatesCount = selectedTaxesIDs.length - enabledRatesCount;

and use those variables for check here

if (selectedTaxesIDs.some((taxID) => !policy?.taxRates?.taxes[taxID]?.isDisabled)) {

text: isMultiple ? translate('workspace.taxes.actions.disableMultiple') : translate('workspace.taxes.actions.disable'),

if (selectedTaxesIDs.some((taxID) => policy?.taxRates?.taxes[taxID]?.isDisabled)) {

text: isMultiple ? translate('workspace.taxes.actions.enableMultiple') : translate('workspace.taxes.actions.enable'),

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.

@ChavdaSachin
Copy link
Contributor

Updated Proposal
Added perfectly optimized way to solve the issue as alternate solution.

@twilight2294
Copy link
Contributor

Proposal

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

Enable/disable option shows rates text in plural instead rate

What is the root cause of that problem?

We check if multiple are selected:

const isMultiple = selectedTaxesIDs.length > 1;

If so then without checking if there are multiple selected or not, we directly show plural form of texts:

text: isMultiple ? translate('workspace.taxes.actions.disableMultiple') : translate('workspace.taxes.actions.disable'),

text: isMultiple ? translate('workspace.taxes.actions.enableMultiple') : translate('workspace.taxes.actions.enable'),

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

First we need to get the disabled and enabled taxes:

        const enabledRatesCount = selectedTaxesIDs.filter((taxID) => !policy?.taxRates?.taxes[taxID]?.isDisabled).length;
        const disabledRatesCount = selectedTaxesIDs.length - enabledRatesCount;

Now according to our Readme:

Here’s an example of how to implement plural translations:

messages: () => ({ zero: 'No messages', one: 'One message', two: 'Two messages', few: (count) => ${count} messages, many: (count) => You have ${count} messages, other: (count) => You have ${count} unread messages, })

So we should not do condition rendering here, instead we should update the text to match this plural forms:

First update the en.ts and es.ts file to unify the multi tags messages:

           disableTaxTitle: () => ({
                one: 'Disable rate',
                other: 'Disable rates',
            }),
            enableTaxTitle: () => ({
                one: 'enable rate',
                other: 'enable rates',
            }),
            
        // `Disable rates` when at least one enabled rate is selected.
        if (selectedTaxesIDs.some((taxID) => !policy?.taxRates?.taxes[taxID]?.isDisabled)) {
            options.push({
                icon: Expensicons.DocumentSlash,
                text: translate('workspace.taxes.actions.disableTaxTitle', {count: disabledRatesCount}),
                value: CONST.POLICY.BULK_ACTION_TYPES.DISABLE,
                onSelected: () => toggleTaxes(false),
            });
        }

        // `Enable rates` when at least one disabled rate is selected.
        if (selectedTaxesIDs.some((taxID) => policy?.taxRates?.taxes[taxID]?.isDisabled)) {
            options.push({
                icon: Expensicons.Document,
                text: translate('workspace.taxes.actions.enableTaxTitle', {count: enabledRatesCount}),
                value: CONST.POLICY.BULK_ACTION_TYPES.ENABLE,
                onSelected: () => toggleTaxes(true),
            });
        }

We can even optimise the conditions during PR phase

What alternative solutions did you explore? (Optional)

@isabelastisser isabelastisser added 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 labels Oct 17, 2024
@melvin-bot melvin-bot bot changed the title Tax - Enable/disable option shows rates text in plural instead rate [$250] Tax - Enable/disable option shows rates text in plural instead rate Oct 17, 2024
Copy link

melvin-bot bot commented Oct 17, 2024

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

Copy link

melvin-bot bot commented Oct 17, 2024

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

Copy link

melvin-bot bot commented Oct 22, 2024

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

@melvin-bot melvin-bot bot added the Overdue label Oct 22, 2024
@isabelastisser
Copy link
Contributor

@getusha, can you please review the proposals above and provide an update? Thanks!

@isabelastisser
Copy link
Contributor

Bump @getusha for an update, thanks!

@getusha
Copy link
Contributor

getusha commented Oct 24, 2024

Reviewing

@melvin-bot melvin-bot bot removed the Overdue label Oct 24, 2024
@getusha
Copy link
Contributor

getusha commented Oct 24, 2024

there are 3 cases we need to handle

1 disabled
1 enabled rate
- Disable rate
- Enable rate

1 disabled
2 enabled rate
- Disable rates
- Enable rate

2 disabled
1 enabled
- Disable rate
- Enable rates

Copy link

melvin-bot bot commented Oct 24, 2024

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

@getusha
Copy link
Contributor

getusha commented Oct 24, 2024

Not sure if this is worth fixing though @techievivek what do you think?

@twilight2294
Copy link
Contributor

Not sure if this is worth fixing though @techievivek what do you think?

@getusha , this is supposed to be fixed, we recently fixed a similar issue on members page as well:

c.c. @techievivek

Copy link

melvin-bot bot commented Oct 24, 2024

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

@isabelastisser
Copy link
Contributor

@twilight2294 @getusha, to clarify, is this issue fixed?

#51017 (comment)

@twilight2294
Copy link
Contributor

@twilight2294 @getusha, to clarify, is this issue fixed?

No, this bug still exits, I pointed out a PR which fixed a similar bug in the workspace members page

@twilight2294
Copy link
Contributor

we are waiting for @techievivek to reply

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. Daily KSv2 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
Projects
None yet
Development

No branches or pull requests

8 participants