-
Notifications
You must be signed in to change notification settings - Fork 4
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
feat: Property filter token type Enum #85
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #85 +/- ##
=======================================
Coverage ? 99.21%
=======================================
Files ? 14
Lines ? 509
Branches ? 180
=======================================
Hits ? 505
Misses ? 4
Partials ? 0 ☔ View full report in Codecov by Sentry. |
expect(processed).toEqual([]); | ||
}); | ||
|
||
test.each([{ token: ['NOT_ACTIVE', 'ACTIVE'] }])('matches some when token=$token and operator="="', ({ token }) => { |
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.
why test.each
here (and below)?
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.
That is partially for convenience with other tests so that the tokens are defined here and not in the test body and partially to reflect the token in the test description (with $token).
expect(processed).toEqual([items[0], items[1], items[2], items[3], items[4]]); | ||
}); | ||
|
||
test.each([['ACTIVE'], 'ACTIVE'])('matches nothing when token=%s and operator=":"', token => { |
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.
why does :'ACTIVE'
not match 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.
That is because the token type for ":" is set as "enum" so the enum matchers are used and those are only defined for "=" and "!=". It will work should the token type be "value" or missing.
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.
Got it, I'd missed the line { operator: '!:', tokenType: 'value' }
above, so was missing why :
and !:
were behaving differently. Do we need any test coverage for { operator: '!:', tokenType: 'enum' }
?
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'd say it is enough to ensure the =
and !=
are working as expected as every other operator is supposed to return false no matter what is the value.
Btw, we can alternatively throw instead of returning false when an unsupported configuration is used. What do you think?
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.
Throwing might be excessive, but I think a dev time warning would make sense, sounds a good improvement.
src/operations/property-filter.ts
Outdated
@@ -70,7 +71,7 @@ function matchDateValue({ | |||
case '!=': | |||
return comparisonResult !== 0; | |||
default: | |||
// Other operators are not supported. | |||
warnOnce(`Unsupported operator given for match="${match}".`); |
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 think it'd be useful to include the operator in the message too
5df280e
to
4ec73ab
Compare
The PR introduces tokenType="enum" support for property filter. The setting is to be used by the property filter component (see cloudscape-design/components#2739) to replace the default autosuggest form with a multi-select one, use a default formatter to join the values and to save the token value as an array. In collection hooks the token value is then assumed to be an array and a different matching logic is used for "=" and "!=" operators.
Rel: [Tz3OAr3i2ni1]
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.