react-awesome-query-builder icon indicating copy to clipboard operation
react-awesome-query-builder copied to clipboard

jsonLogic expression loading issue with some-in

Open nicopadu opened this issue 1 year ago • 2 comments

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"]]}]}]}

image

But we cannot load it back: image

Following the same steps with equals operator, all works as expected.

nicopadu avatar Nov 06 '23 13:11 nicopadu

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;

Ketler13 avatar Dec 05 '23 17:12 Ketler13

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?

Delaramv avatar Jan 19 '24 15:01 Delaramv