Skip to content

Search - The Tax Rate filter does not display results when the query is manually entered #54380

Closed

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: 9.0.77-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: #53688
**Issue reported by:**Applause - Internal Team

Action Performed:

Preconditions:
User has at least one workspace with Taxes enabled.
The user has expenses with the tax rate that will be used to filter the results.
Steps:

  1. Login to ND (can be Gmail or expensifail account)
  2. Go to any chat or expense report
  3. In the Search Router, enter a query using the Tax Rate filter, eg. tax-rate:"Tax Rate 1" and press Intro - or tap the Magnifier button in the keypad -

Expected Result:

The Tax Rate filter displays results when the query is entered manually, similar to when the query is selected from Suggestions or entered in Filters (on the Reports tab)

Actual Result:

The Tax Rate filter does not display results when the query is manually entered

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
Bug6698296_1734552361897.taxRate_filter.mp4

View all open jobs on GitHub

Activity

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

    @melvin-bot

    Triggered auto assignment to @RachCHopkins (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. jaydamani commented on Dec 19, 2024

    @jaydamani
    Contributor

    Proposal

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

    Tax rate filter not working when entering filter manually.

    What is the root cause of that problem?

    The query send to backend when we manually enter is different from when we search for tax rates
    When we manually enter, it is:

    {"operator":"eq","left":"taxRate","right":"Tax Rate 1"}

    When we select from suggestions, it is:

    {"operator":"eq","left":"taxRate","right":"id_TAX_RATE_1"}

    due to this, the results are not visible when manually entering

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

    We need to replace tax rate names with tax rate ids and similar replacement is being done for email-ids by getQueryWithUpdatedValues which calls getUpdatedFilterValue so, we need to update getUpdatedFilterValue and add logic to replace tax-rate names with their ids.

    function getUpdatedFilterValue(filterName: ValueOf<typeof CONST.SEARCH.SYNTAX_FILTER_KEYS>, filterValue: string | string[]) {
    if (filterName === CONST.SEARCH.SYNTAX_FILTER_KEYS.FROM || filterName === CONST.SEARCH.SYNTAX_FILTER_KEYS.TO) {
    if (typeof filterValue === 'string') {
    return PersonalDetailsUtils.getPersonalDetailByEmail(filterValue)?.accountID.toString() ?? filterValue;
    }
    return filterValue.map((email) => PersonalDetailsUtils.getPersonalDetailByEmail(email)?.accountID.toString() ?? email);
    }
    if (filterName === CONST.SEARCH.SYNTAX_FILTER_KEYS.AMOUNT) {
    if (typeof filterValue === 'string') {
    const backendAmount = CurrencyUtils.convertToBackendAmount(Number(filterValue));
    return Number.isNaN(backendAmount) ? filterValue : backendAmount.toString();
    }
    return filterValue.map((amount) => {
    const backendAmount = CurrencyUtils.convertToBackendAmount(Number(amount));
    return Number.isNaN(backendAmount) ? amount : backendAmount.toString();
    });
    }
    return filterValue;
    }

    We need to add policy id as param for getUpdatedFilterValue and then add below code in the getUpdatedFilterValue function:

        if (filterName === CONST.SEARCH.SYNTAX_FILTER_KEYS.TAX_RATE) {
            if (typeof filterValue === 'string') {
                return PolicyUtils.getTaxRateKey(filterValue, policyId)
            }
    
            return filterValue.map(taxRates => PolicyUtils.getTaxRateKey(filterValue, policyId)).flat()
        }

    We will also need to add below policy utils to get tax rate id from the names

    function getTaxRateKey(name: string, policyId?: string) {
        if (policyId) {
            const policy = getPolicy(polictId)
            return getTaxRateKeyForPolicy(policy) ?? name
        }
    
        const taxRateKeys = []
        Object.values(allPolicies).forEach(policy => {
            const taxRateKey = getTaxRateKeyForPolicy(policy)
    
            if (taxRateKey) {
                taxRateKeys.push(taxRateKey)
            }
        })
    
        return taxRateKeys
    }
    
    function getTaxRateKeyForPolicy(taxRateName: string, policy: Policy) {
        if (!policy?.taxRates?.taxes) {
            return
        }
    
        return Object.entries(policy.taxRates.taxes)
        .find(([taxRateKey, taxRate]) => taxRate === taxRateName)?.[0]
    }

    Update here and here to pass policy id to getUpdatedFilterValue

    What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

    We need to add unit tests for getQueryWithUpdatedValues to check if tax rates are being replaced. The new cases will check that tax rates are subsituted properly, tax rate ids are preserved properly and update the existing tests for all subsitutions

  4. Tony-MK commented on Dec 20, 2024

    @Tony-MK
    Contributor

    Proposal

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

    The Tax Rate filter does not display results when the query is manually entered

    What is the root cause of that problem?

    getUpdatedFilterValue does not update the taxRate or filterValue, in the search payload to its respective tax key or id, eg: "Tax Rate 1" should be converted to id_TAX_RATE_1

    * Returns an updated filter value for some query filters.
    * - for `AMOUNT` it formats value to "backend" amount
    * - for personal filters it tries to substitute any user emails with accountIDs
    */
    function getUpdatedFilterValue(filterName: ValueOf<typeof CONST.SEARCH.SYNTAX_FILTER_KEYS>, filterValue: string | string[]) {

    Therefore, the backend can not find any results because it searches the tax filter based on the tax IDs or keys instead of its name which is sent to /api/Search? in the built jsonQuery.

    Screenshot 2024-12-20 at 18 57 55

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

    Convert the filterValue if the filterName is CONST.SEARCH.SYNTAX_FILTER_KEYS.TAX_RATE to the tax key by finding which tax key the filterValue belongs to.

    Let's add the following statement getUpdatedFilterValue over here

    if (filterName === CONST.SEARCH.SYNTAX_FILTER_KEYS.TAX_RATE) {
            const allTaxRates = Object.entries(PolicyUtils.getAllTaxRates());
            if (typeof filterValue === 'string') {
                return (
                    allTaxRates
                        .find(([taxRateName, taxRateKeys]) => {
                            return taxRateName === filterValue ? taxRateKeys : undefined;
                        })?.[1]
                        .at(0) ?? filterValue
                );
            }
    
            return filterValue
                .map(
                    (value) =>
                        allTaxRates
                            .find(([taxRateName, taxRateKeys]) => {
                                return taxRateName === value ? taxRateKeys : undefined;
                            })?.[1]
                            .at(0) ?? value,
                )
                .flat();
        }

    Optionally, we can create a function to handle the update and simplify getUpdatedFilterValue.

    What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

    Test getUpdatedFilterValue with other search filters and values.

  5. melvin-bot commented on Dec 23, 2024

    @melvin-bot

    @RachCHopkins Whoops! This issue is 2 days overdue. Let's get this updated quick!

  6. RachCHopkins commented on Dec 24, 2024

    @RachCHopkins
    Contributor

    @lanitochka17 I don't understand this bug - how does a customer know to do this:

    In the Search Router, enter a query using the Tax Rate filter, eg. tax-rate:"Tax Rate 1"

    i.e how can we guarantee that the query is correct without the list of filters - I tried and clearly didn't get it right.

    We don't have any guidance online for how users take this action. I don't think this is something that we need to focus on right now, as we have no current plans for adding this to our help docs.

  7. jaydamani commented on Dec 25, 2024

    @jaydamani
    Contributor

    We already do something similar for from/to filters where from:jay@mail.com will work even if you press enter without using suggestions and the search router is relatively new so maybe this is worth fixing
    cc: @luacmartins as they manage search related stuff

  8. luacmartins commented on Dec 30, 2024

    @luacmartins
    Contributor

    The reason it works for emails is that email is a unique identifier. The same cannot be said about other filter/values, e.g. tags, categories, tax rates, etc so in those cases we need to rely on autocomplete.

  9. jaydamani commented on Dec 30, 2024

    @jaydamani
    Contributor

    I understand now, thanks for the confirmation.

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

Metadata

Metadata

Assignees

Labels

BugSomething is broken. Auto assigns a BugZero manager.DailyKSv2

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions