-
Notifications
You must be signed in to change notification settings - Fork 9
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
Pdtvt 1725 filter duplicates #1148
base: master
Are you sure you want to change the base?
Conversation
…er certain circumstances
…er certain circumstances
🦋 Changeset detectedLatest commit: d8dc3fd The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@jamiek-acl I may have fixed the flicker you noticed in the Panel with #1166 |
I updated component in my app but still seeing the flicker |
…n some circumstances)
processedColumnIds.push(filter.columnId); | ||
} | ||
|
||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't understand the logic of this method. Why we do processedColumnIds.push(filter.columnId)
and then return false
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return false
is within a .filter()
, so it gets removed from the array (i.e. it is not an illogical filter).
The function first sorts all the the filters that exist (to simplify the following code), then goes over each.
If the current filter has a boolean rule (=
, !=
, etc) and is on a column
that was already used by a filter, this one is illogical (so it will be removed).
For example, if the current one is goals = 1
and there was already a filter on goals
, goals = 1
is illogical and will be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, and the .push()
is because we keep a tally of the columnIds
that already have filters... so if we see another filter on that column, we know to look into it more deeply.
import { logicalFilterOperators } from "../rules"; | ||
import ruleIsBoolean from "./ruleIsBoolean"; | ||
|
||
export default function removeIllogicalRules(operator, rule, existingFilters, columnId, filterId = "") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function is called removeIllogicalRules
but it doesn't remove anything
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I struggled with some names. I thought it made sense from the context of where it is used (in a filter()
):
{rulesByType[selectedColumnType]
.filter(rule => removeIllogicalRules(...))
.map()
}
Suggestions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i went with isIllogicalRule
Co-authored-by: Mike Polowick <mikrotron@users.noreply.github.com>
Leaving for @AndreyChernykh to finish this off, then update in projects (thanks Andrey!). We discussed and a few changes are to be made:
Andrey wrote:
|
https://aclgrc.atlassian.net/browse/PDTVT-1725
Background
Before this PR, if someone added two filters:
goals = 100
andgoals = 200
and submitted, that would get sent to the server like this:&filter[goals]=100&filter[goals]=200
. What do you think should be returned?100
and200
goals)In our case, it is Rails that decides to return the players with 200 goals (the second query param overwrites the first). Using a different framework could have a different result.
And generally, it is weird that we allow the user to add an illogical/duplicate filter like this in the first place.
Purpose 🚀
AND
Filter, and if one of the rules is a boolean rule (IS, IS NOT, etc).Add filter
button once they have applied all the filters (with same rules as above).EQUALS
if already filtering by a field when doingAND
)Examples
This is allowed:
goals = 100 OR goals = 200
This is allowed:
goals > 100 AND goals < 200
This is not:
goals = 100 AND goals = 200
This is not:
goals > 100 AND goals = 200
To prevent it, hide the
goals
field if:AND
Filter, andgoals
field, andEdge case 1
Imagine I do this in this order:
OR
goals = 100
goals = 200
OR
toAND
In this case the component has to delete the
goals = 200
filter automatically (jonathan wants a prompt in a perfect world, but this is a lot of work and this is just an edge case)Edge case 2
Imagine I do this in this order:
AND
goals > 100
goals = 200
(goals
is still an option because there is no othergoals =
filter yet)In this case, the
=
comparator should not be an option for the secondgoals
filter.Storybook 📕
http://storybooks.highbond-s3.com/paprika/pdtvt-1725--filter-duplicates
Here I am already filtering on
Goals = 1
. When I add another filter, notice howGoals
is not an option again:Here I have these filters:
Goals = 1 OR Goals = 2 OR Name = joe
. When I switch toAnd
, the conflicting filter (Goals = 2
) is deleted automatically:Here I already have a filter
Goals > 1 AND ...
. Notice how I can add another filter on theGoals
column, but I can't do aboolean rule
(e.g.=
,!=
) because that would be an illogical filter.