react-querybuilder/react-querybuilder

Change formatQuery (jsonlogic) output structure avoiding subgroup collapsion

Coooi opened this issue · 1 comments

As a follow up of #609,

Ideally, the queryFormat with jsonLogic should follow the RQB structure as in.

Current implementation:

Query:

{
  "combinator": "and",
  "not": false,
  "rules": [
    {
      "field": "firstName",
      "value": "Stev",
      "operator": "beginsWith"
    },
    {
      "rules": [
        {
          "field": "age",
          "operator": "=",
          "valueSource": "value",
          "value": "23"
        }
      ],
      "combinator": "or",
      "not": false
    }
  ]
}

formatQuery jsonLogic output:

{
  "and": [
    {
      "startsWith": [
        {
          "var": "firstName"
        },
        "Stev"
      ]
    },
    {
      "==": [
        {
          "var": "age"
        },
        "23"
      ]
    }
  ]
}

Since it doesn't follow the query structure by collapsing the subgroup that contains a single rule, we want to prevent subgroups from collapsing.

Desired jsonLogic output:

{
  "and": [
    {
      "startsWith": [
        {
          "var": "firstName"
        },
        "Stev"
      ]
    },
    {
      "or": [
        {
          "==": [
            {
              "var": "age"
            },
            "23"
          ]
        }
      ]
    }
  ]
}

Thanks for reporting this! It should be fixed in v7, to be released soon. I'll include it in version 7.0.0-rc.1.