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

feat: Property filter token type Enum #85

Merged
merged 2 commits into from
Oct 15, 2024

Conversation

pan-kot
Copy link
Member

@pan-kot pan-kot commented Oct 1, 2024

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.

Copy link

codecov bot commented Oct 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (main@26f4e95). Learn more about missing BASE report.
Report is 2 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

@pan-kot pan-kot marked this pull request as ready for review October 11, 2024 14:02
@pan-kot pan-kot requested a review from a team as a code owner October 11, 2024 14:02
@pan-kot pan-kot requested review from gethinwebster and removed request for a team October 11, 2024 14:02
expect(processed).toEqual([]);
});

test.each([{ token: ['NOT_ACTIVE', 'ACTIVE'] }])('matches some when token=$token and operator="="', ({ token }) => {
Copy link
Member

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)?

Copy link
Member Author

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 => {
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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' }?

Copy link
Member Author

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?

Copy link
Member

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.

@@ -70,7 +71,7 @@ function matchDateValue({
case '!=':
return comparisonResult !== 0;
default:
// Other operators are not supported.
warnOnce(`Unsupported operator given for match="${match}".`);
Copy link
Member

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

@pan-kot pan-kot force-pushed the feat-property-filter-enum-props-3 branch from 5df280e to 4ec73ab Compare October 15, 2024 13:08
@pan-kot pan-kot added this pull request to the merge queue Oct 15, 2024
Merged via the queue into main with commit 519f411 Oct 15, 2024
35 checks passed
@pan-kot pan-kot deleted the feat-property-filter-enum-props-3 branch October 15, 2024 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants