decap-cms
decap-cms copied to clipboard
feat: allow multiple filter values, fixes #7328
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
- Added a unit test for the array variation, existing (non-array) tests still path.
- Tested against my collections, with single-value, single-element-array and multiple-element-array variations all working as expected.
Checklist
Please add a x inside each checkbox:
- [X] I have read the contribution guidelines.
- [X] I have added a documentation update PR at https://github.com/decaporg/decap-website/pull/92
A picture of a cute animal (not mandatory but encouraged)
@paulroub, thanks for your contribution. Before we review, can you please ensure the tests are passing?
@martinjagodic Fixed the linting issues, along the way had to tell stylelint to ignore backend.ts as it was trying to parse a cast as CSS and was not happy with the result. No actual styles in this file, of course, so that should be harmless.
Rebased on current main, confirmed npx run test:all still succeeds.
@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 field.
Condition example:
condition: {
field: layout,
value: list-filters,
operator: '!='
}
Maybe we should combine these functions, as it's potentially the same feature on a different level.
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'm so far unable to reproduce this -- any chance you could share your test config?
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.
Reproduced, fixed, added a test case. We were assuming the presence of the filtered-on field on all entries in the collection. Now just failing the match if (e.g.) we're filtering on "category" but a post doesn't have one.
I also have an idea of extending this further by adding an operator like with the
conditionfield.
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.