Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jsonLogic expression loading issue with some-in #1005

Closed
nicopadu opened this issue Nov 6, 2023 · 2 comments · Fixed by #1034
Closed

jsonLogic expression loading issue with some-in #1005

nicopadu opened this issue Nov 6, 2023 · 2 comments · Fixed by #1034

Comments

@nicopadu
Copy link

nicopadu commented Nov 6, 2023

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.

@Ketler13
Copy link

Ketler13 commented Dec 5, 2023

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:

and here:

let opKeys = conv.operators[(isRevArgs ? "#" : "") + opk];

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;

@Delaramv
Copy link

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?

ukrbublik added a commit that referenced this issue Feb 29, 2024
@ukrbublik ukrbublik linked a pull request Mar 13, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants