ukrbublik / react-awesome-query-builder

User-friendly query builder for React
https://ukrbublik.github.io/react-awesome-query-builder
MIT License
1.96k stars 493 forks source link

Ability to add sub-group under array type so we can have nested AND and OR conditionals #1108

Open chintanvora7 opened 1 month ago

chintanvora7 commented 1 month ago

Feature Description:

We are using RAQB along with JSONLogic output generated from it in our project. We have a use case where we need to add "AND" and few "OR" conditions under an array to check certain values. Natively, JSONLogic supports this however so far I can't seem to add sub-groupings under array type using the RAQB library. Example rule from the demo UI here:

Example JSON Object:

{ "cars": [ { "vendor": "Toyota", "year": "2015 }, { "vendor": "Toyota", "year": "2010 } ] }

Example Human Rule:

Check if ALL objects under the cars array have vendor == Toyota AND (year == 2010 or year == 2015)

The max I can see is only the ability to add one global "AND" or "OR" condition. Please let me know if there is any configuration I'm missing but so far I haven't found anything that allows me to enable this

Screenshot:

Screenshot 2024-08-10 at 9 23 57 PM

Describe the solution you'd like Ideally, I would just have a 'add sub group' option under Arrays like we have at the struct level above to enable this. I assume adding a group allows us to add queries with multiple "AND" and "OR" conditionals but maybe I'm oversimplifying it.

Describe alternatives you've considered Currently, we are creating these rules by hand so it isn't ideal and it is blocking our UI from critical features we're building

ukrbublik commented 1 month ago

Thanks for the feature request. Makes total sense.

chintanvora7 commented 1 month ago

@ukrbublik thanks for the quick response!

I was playing around with this by trying the reverse where I wrote a JSONLogic rule where I had an array condition with AND and OR and then imported it in the RAQB UI by converting the JSONLogic to a Tree representation. It sort of works as shown below:

Screenshot 2024-08-12 at 1 37 01 AM

I can add rules to the sub-group and it seems to function normally however the fields look wonky. The output JSONLogic seems to be as expected

JSONLogic Rule:

{ "and": [ { "all": [ { "var": "accounts" }, { "and": [ { "==": [ { "var": "acctBalanceTier" }, 1 ] }, { "or": [ { "==": [ { "var": "accountProductCode" }, "3500" ] }, { "==": [ { "var": "accountProductCode" }, "3800" ] } ] } ] } ] } ] }

I know you work on the project in your free time but any chance you can let us know if this feature is something you are planning to prioritize and if so, any timelines? The data model we use relies on arrays and we can't call our UI feature complete unless we can claim parity with JSONLogic feature set which supports this as a core capability when dealing with list/arrays.

We'd really appreciate any help!

ukrbublik commented 1 month ago

I'll prioritize this. Probably can work on it next week or two

chintanvora7 commented 3 weeks ago

@ukrbublik wondering if you had time to look into the above? Apologies for bugging you!

ukrbublik commented 3 weeks ago

Sorry, I'm on vacation. Will work on this issue next week.

chintanvora7 commented 1 day ago

@ukrbublik thanks for the progress here! I was able to pull down the branch and it seems to work as expected for JSONLogic based output. Once this PR is integrated, would we get a new version of RAQB to pull in so we can unlock this capability?

ukrbublik commented 1 day ago

Yes, I plan to make a release once the PR is ready.

Core changes are done in the PR. Some minor UI fixes and drag-n-drop fixes needs to be done.