feat: allow multiple filter values, fixes #7328#7329
feat: allow multiple filter values, fixes #7328#7329paulroub wants to merge 11 commits intodecaporg:mainfrom
Conversation
|
@paulroub, thanks for your contribution. Before we review, can you please ensure the tests are passing? |
e507ff3 to
ed53741
Compare
|
@martinjagodic Fixed the linting issues, along the way had to tell stylelint to ignore |
74e69f2 to
7300752
Compare
|
Rebased on current |
7300752 to
e8d3ef2
Compare
There was a problem hiding this comment.
Pull Request Overview
Adds the ability for collection filters to match against multiple values by updating the value type, normalizing inputs, and enhancing the filter logic.
- Expand
FilterRule.valueto accept arrays, ImmutableList, or typed records - Normalize raw filter and field values via a new
valuesAsArrayhelper - Update
filterEntriesto use normalized arrays and add a corresponding unit test - Ignore
backend.tsin Stylelint to prevent lint failures on new code
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/decap-cms-core/src/types/redux.ts | Broaden FilterRule.value type to support multi-value inputs |
| packages/decap-cms-core/src/backend.ts | Implement valuesAsArray and update filterEntries for arrays |
| packages/decap-cms-core/src/tests/backend.spec.js | Add test covering array-based filter values |
| .stylelintrc | Include src/backend.ts in lint ignore list |
Comments suppressed due to low confidence (1)
packages/decap-cms-core/src/tests/backend.spec.js:98
- This test covers plain arrays but doesn't verify behavior when
valueorentry.data[field]are ImmutableListorStaticallyTypedRecord<List<string>>. Add tests for those types to ensure full coverage of the new normalization logic.
it('filters multiple values', () => {
|
@paulroub it's been a while, I hope this is still relevant to you. When I try this with my test config, the collection fails to load entries - even before I tried the list of filters. See screenshot below. I also have an idea of extending this further by adding an operator like with the Condition example: Maybe we should combine these functions, as it's potentially the same feature on a different level.
|
I'm so far unable to reproduce this -- any chance you could share your test config? |
Reproduced, fixed, added a test case. We were assuming the presence of the filtered-on field on all
I had considered that as well, and poked at it a bit. I hadn't considered extending the syntax, that would make things much more doable. Perhaps a follow-on? This version seems useful on its own. |
|
Great, thanks! We can do that in a later PR, I agree. If all is ok now, we should merge this for the 3.9 release. |
martinjagodic
left a comment
There was a problem hiding this comment.
If I add an array as value in dev-test.yaml to the Posts collection like this
collections: # A list of collections the CMS should be able to edit
- name: 'posts' # Used in routes, ie.: /admin/collections/:slug/edit
filter: {field: title, value: ['This is post # 20']}I should see one post entry, but I get these errors in console:
Warning: Failed prop type: Invalid prop `children` supplied to `ErrorBoundary`, expected a ReactNode.
Warning: Failed prop type: Invalid prop `children` supplied to `Modal`, expected a ReactNode.
Uncaught (in promise) {type: 'ENTRIES_FAILURE', error: 'Failed to load entries', payload: 'TypeError: rawValue.toJS(...).toArray is not a function', meta: {…}}

Summary
Allows a collection filter to match one of a number of values; still allows the existing single-value syntax, as well as an array of values.
Need to manage a collection that's a combination of existing categories (rather than re-categorize all those posts).
Test plan
Checklist
Please add a
xinside each checkbox:A picture of a cute animal (not mandatory but encouraged)