decap-cms icon indicating copy to clipboard operation
decap-cms copied to clipboard

feat: allow multiple filter values, fixes #7328

Open paulroub opened this issue 1 year ago • 3 comments
trafficstars

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)

rp

paulroub avatar Nov 14 '24 18:11 paulroub

@paulroub, thanks for your contribution. Before we review, can you please ensure the tests are passing?

martinjagodic avatar Nov 15 '24 08:11 martinjagodic

@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.

paulroub avatar Nov 15 '24 17:11 paulroub

Rebased on current main, confirmed npx run test:all still succeeds.

paulroub avatar Jan 23 '25 20:01 paulroub

@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.

Screenshot 2025-07-10 at 13 48 40

martinjagodic avatar Jul 10 '25 11:07 martinjagodic

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?

paulroub avatar Jul 11 '25 15:07 paulroub

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 condition field.

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.

paulroub avatar Jul 11 '25 16:07 paulroub

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 avatar Jul 14 '25 07:07 martinjagodic