Flagsmith / flagsmith

Open Source Feature Flagging and Remote Config Service. Host on-prem or use our hosted version at https://flagsmith.com/
https://flagsmith.com/
BSD 3-Clause "New" or "Revised" License
4.78k stars 364 forks source link

Support OR-ing multiple sets of segment conditions together #3947

Open rolodato opened 4 months ago

rolodato commented 4 months ago

Is your feature request related to a problem? Please describe.

When defining a segment, we can only define conditions in the shape (A or B or ...) AND/AND NOT (D or E or ...) AND/AND NOT .... It's not possible to OR multiple sets of conditions together.

Describe the solution you'd like.

Support OR-ing multiple sets of conditions together when defining a segment. Unsure what the UI would look like for this yet.

Describe alternatives you've considered

Implementing the logic in the application (i.e. using Flagsmith as a remote config store and not for its evaluation engine)

Additional context

No response

matthewelwell commented 4 months ago

@kyle-ssg I believe the BE can already support this, but I'm not sure how easy it will be to represent on the FE.

kyle-ssg commented 4 months ago

Im really unsure as to what the UI would look like, it might be worth getting Akveo to mock a design. I haven't seen this attempted before in products I don't think.

I feel like this could lead to people getting very confused if it's not done right.

rolodato commented 4 months ago

I can't think of anything feasible besides a tree-style editor to build arbitrarily complex boolean conditions, similar to https://querybuilder.js.org/ but with an actually nice design :)

This will likely require extracting "New Segment" from the current modal into its own page, to get a reasonable amount of screen space to work with.

If we do allow customers to define more complex conditions, IMO we should provide some "tester" functionality that lets customers play around with sample values to sanity-check their segment definitions and explain what is causing a certain result. This could be part of the segment editor or its own page (separate page would be my preference), which could help explain if segment or identity overrides are being applied and not need to create fake identities just for testing.

rolodato commented 1 month ago

As a workaround for anyone running into this limitation, it's possible to rewrite any logical formula into conjunctive normal form (CNF) so that it's expressed as an AND chain of OR statements. For example: https://www.wolframalpha.com/input?i=%28A+and+B%29+or+%28C+and+D%29