react-awesome-query-builder
react-awesome-query-builder copied to clipboard
jsonLogic expression loading issue with some-in
Issue description
It seems to be an issue when loading a jsonLogic expression that includes some-in operator. The same expression generated from the component itself cannot be loaded back. Having an expression like the following:
{"and":[{"some":[{"var":"CategoryA"},{"in":[{"var":"FieldX"},["1"]]}]}]}
We cannot load it using loadFromJsonLogic
Steps to reproduce
Working sample can be found here https://stackblitz.com/edit/react-rdkejr?file=src%2FApp.js
These are the key parts:
-
A custom type to include reduced widgets and operators list:
const customTextType = { defaultOperator: 'equal', mainWidget: 'text', valueSources: ['value'], widgets: { text: { operators: ['equal', 'not_equal'], }, multiselect: { operators: ['select_any_in', 'select_not_any_in'], }, }, };
-
A field definition that uses that custom type. We need an operator that allows multiple items typed by user,
select_any_in
produces our expected jsonLogic expression format:const config = { ...InitialConfig, types: { ...InitialConfig.types, customTextType, }, fields: { CategoryA: { type: '!group', subfields: { FieldX: { type: 'customTextType', fieldSettings: { showSearch: true, allowCustomValues: true, }, }, }, }, }, };
Expected behavior
We can generate the following expression that matches our needs (based on how data is structured):
{"and":[{"some":[{"var":"CategoryA"},{"in":[{"var":"FieldX"},["1"]]}]}]}
But we cannot load it back:
Following the same steps with equals
operator, all works as expected.
I experienced the same problem during regression testing after migration from v5 to v6.
For more context, there is a warning in a console during importing json logic: Errors while importing from JsonLogic: ['some-in/2']
Looks like there is a mismatch between handling for 'some-in' operator here:
https://github.com/ukrbublik/react-awesome-query-builder/blob/d17da0103e90c96d3aa081304129b2b355b89c9a/packages/core/modules/import/jsonLogic.js#L646
and here:
https://github.com/ukrbublik/react-awesome-query-builder/blob/d17da0103e90c96d3aa081304129b2b355b89c9a/packages/core/modules/import/jsonLogic.js#L590
because for the simplest config with only 2 operators select_any_in/select_not_any_in conv.operators has following value:
{
"some/0": [
"some"
],
"in/1": [
"select_any_in"
]
}
where opk equals "some-in/1" and that's "if" block below is called:
let opKeys = conv.operators[(isRevArgs ? "#" : "") + opk];
if (!opKeys)
return;
I have the same issue. When is it going to be fixed? is there any urgent fix that I can use in my code for now?