Skip to content

Change formatQuery (jsonlogic) output structure avoiding subgroup collapsion  #664

Closed
@Coooi

Description

@Coooi

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions