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

Account for logicalOperator inside UISearchFilter groups #14904

Merged
merged 4 commits into from
Oct 29, 2024

Conversation

aptkingston
Copy link
Member

Description

Fixes an issue where logical operators inside groups in frontend filter structures were ignored when converting to a query.

Given a sample frontend filter group (SearchFilterGroup) of:

{
    "logicalOperator": "any",
    "filters": [
        {
            "valueType": "Binding",
            "field": "Country",
            "type": "string",
            "constraints": {
                "type": "string",
                "length": {},
                "presence": false
            },
            "operator": "fuzzy",
            "noValue": false,
            "value": ""
        },
        {
            "valueType": "Binding",
            "field": "Region",
            "type": "string",
            "constraints": {
                "type": "string",
                "length": {},
                "presence": false
            },
            "operator": "fuzzy",
            "noValue": false,
            "value": ""
        }
    ]
}

Notice the any value for logicalOperator, meaning perform an "or".

This was previously converted into:

{
    "$and": {
        "conditions": [
            {
                "fuzzy": {
                    "Country": ""
                }
            },
            {
                "fuzzy": {
                    "Region": ""
                }
            }
        ]
    }
}

Notice the $and operator which is incorrect.

With this PR it is now correctly converted into:

{
    "$or": {
        "conditions": [
            {
                "fuzzy": {
                    "Country": ""
                }
            },
            {
                "fuzzy": {
                    "Region": ""
                }
            }
        ]
    }
}

This is safe to go to v3-ui rather than master as these structures do not exist in master yet.

Copy link

qa-wolf bot commented Oct 29, 2024

QA Wolf here! As you write new code it's important that your test coverage is keeping up.
Click here to request test coverage for this PR!

@aptkingston aptkingston requested a review from samwho October 29, 2024 13:02
@aptkingston aptkingston marked this pull request as ready for review October 29, 2024 13:02
Copy link
Collaborator

@samwho samwho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test for this? 🙏 There's a big group of them in viewV2.spec.ts around line 4059.

@aptkingston
Copy link
Member Author

Could you add a test for this? 🙏 There's a big group of them in viewV2.spec.ts around line 4059.

I looked for tests inside shared-core where this resides and there were none, but looks like that's because the tests for it live elsewhere! Will do - I was going to if I had found them.

@aptkingston aptkingston requested a review from a team as a code owner October 29, 2024 15:10
@aptkingston aptkingston requested review from mike12345567 and removed request for a team October 29, 2024 15:10
@github-actions github-actions bot added size/s and removed size/xs labels Oct 29, 2024
@aptkingston aptkingston removed the request for review from mike12345567 October 29, 2024 15:11
@samwho
Copy link
Collaborator

samwho commented Oct 29, 2024

Yeah, sorry about that. I didn't want to make assertions on the output of buildQuery because it would be quite brittle. Fundamentally what matters is whether it results in the right rows coming back to you, so I decided to put them in viewV2.spec.ts.

@aptkingston aptkingston merged commit 7d7dd31 into v3-ui Oct 29, 2024
11 checks passed
@aptkingston aptkingston deleted the fix-filter-query-conversion branch October 29, 2024 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants