eclipsesource / jsonforms

Customizable JSON Schema-based forms with React, Angular and Vue support out of the box.
http://jsonforms.io
Other
2.2k stars 371 forks source link

If/then/else in array context not rendered #2005

Closed UweStolz closed 2 years ago

UweStolz commented 2 years ago

Describe the bug

I try to use if/then/else in a context with ListWithDetail but it seems that the input element doesn't render properly and I am unsure if this is a bug or the schemata is simply wrong. I provide a simple working example and a more complex one in an array context.

Jsonforms version: 3.0.0-rc.0

Expected behavior

The input element should render and display if the input value is valid depending on the select "Operating System".

Steps to reproduce the issue

  1. Go to https://react-ts-hdzzvs.stackblitz.io/
  2. Click on the plus button to add element to array
  3. Select added element
  4. Click "Add Cloud Server" checkbox
  5. Click on the "Next" button

Screenshots

Working example: image

Complex failing example: image

See: https://react-ts-hdzzvs.stackblitz.io/

In which browser are you experiencing the issue?

Edge Version 104.0.1293.54, Chrome 104.0.5112.81

Framework

React

RendererSet

Material

Additional context

Schemata

Working example
Schema
{
    type: 'object',
    properties: {
      os: {
        type: 'string',
        enum: ['Linux', 'Windows', 'Disabled'],
      },
    },
    allOf: [
      {
        if: {
          properties: {
            os: {
              const: 'Windows',
            },
          },
        },
        then: {
          properties: {
            ram: {
              type: 'integer',
              minimum: 4,
              default: 4,
            },
          },
        },
      },
      {
        if: {
          properties: {
            os: {
              const: 'Linux',
            },
          },
        },
        then: {
          properties: {
            ram: {
              type: 'integer',
              minimum: 1,
              default: 1,
            },
          },
        },
      },
    ],
  }
UIschema
{
    type: 'HorizontalLayout',
    elements: [
      {
        type: 'VerticalLayout',
        elements: [
          {
            type: 'Control',
            label: 'OS',
            scope: '#/properties/os',
          },
          {
            type: 'Control',
            label: 'RAM',
            scope: '#/properties/ram',
            rule: {
              effect: 'ENABLE',
              condition: {
                scope: '#/properties/os',
                schema: {
                  enum: ['Linux', 'Windows'],
                },
              },
            },
          },
        ],
      },
    ],
  }


Failing example
Schema
{
  type: 'object',
  properties: {
    systemConfiguration: {
      title: 'System Configuration(s)',
      type: 'array',
      items: {
        type: 'object',
        properties: {
          baInSystemDescription: {
            type: 'string',
          },
          baInOrderId: {
            type: 'string',
          },
          addVirtualCloudServer: {
            type: 'boolean',
          },
          virtualCloudServerProperties: {
            type: 'object',
            properties: {
              serverDescription: {
                type: 'string',
              },
              orderId: {
                type: 'string',
              },
              cloud: {
                type: 'string',
                enum: ['VPC', 'Azure', 'AWS', 'GPC'],
              },
              cloudAccount: {
                type: 'string',
              },
              cloudRegion: {
                type: 'string',
              },
              plannedServerFunction: {
                type: 'string',
                enum: [
                  'Other',
                  'Web Application',
                  'Oracle',
                  'SAP',
                  'MSSQL',
                  'Citrix',
                  'Domain Controller',
                  'SCOM Gateway',
                  'TSM Proxy',
                ],
              },
              operatingSystem: {
                type: 'string',
                enum: [
                  'Win2022',
                  'Win2019',
                  'Win2016',
                  'SLES15',
                  'SLES12',
                  'CENTOS7',
                ],
              },
              domain: {
                type: 'string',
              },
              vpcVcpu: {
                type: 'integer',
                minimum: 1,
                maximum: 20,
              },
              serverNetwork: {
                type: 'string',
              },
              serverPatchWindow: {
                type: 'string',
                enum: [
                  'PW1MW2WED',
                  'PW1MW1THU',
                  'PW1MW2THU',
                  'PW1MW3THU',
                  'PW1MW1FRI',
                  'PW1MW2FRI',
                  'PW1MW1SAT',
                  'PW1MW2SUN',
                  'PW2MW1MON',
                  'PW2MW2MON',
                  'PW2MW1TUE',
                  'PW2MW2TUE',
                  'PW2MW3TUE',
                  'PW2MW1WED',
                  'PW2MW2WED',
                  'PW2MW1THU',
                  'PW2MW2THU',
                  'PW2MW2FRI',
                  'PW2MW1SUN',
                ],
              },
              serverPatchIntervallLinux: {
                type: 'string',
                enum: ['03/09', '06/12'],
              },
              serverPatchIntervallWindows: {
                type: 'string',
                default: '1,2,3,4,5,6,7,8,9,10,11,12',
                readOnly: true,
              },
            },
          },
        },
      },
    },
  },
  anyOf: [
    {
      if: {
        properties: {
          operatingSystem: {
            enum: ['Win2022', 'Win2019', 'Win2016'],
          },
        },
      },
      then: {
        properties: {
          vpcRam: {
            type: 'integer',
            minimum: 4,
            maximum: 96,
          },
        },
      },
      else: {
        properties: {
          vpcRam: {
            type: 'integer',
            minimum: 1,
            maximum: 96,
          },
        },
      },
    },
  ],
}
UIschema
{
  type: 'ListWithDetail',
  scope: '#/properties/systemConfiguration',
  options: {
    detail: {
      type: 'Categorization',
      elements: [
        {
          type: 'Category',
          label: 'Basic Informationen',
          elements: [
            {
              type: 'HorizontalLayout',
              elements: [
                {
                  type: 'Control',
                  scope: '#/properties/baInSystemDescription',
                  label: 'Geben Sie bitte eine Beschreibung für dieses System',
                },
                {
                  type: 'Control',
                  scope: '#/properties/baInOrderId',
                  label: 'Geben Sie bitte eine SDMS Order ID an',
                },
              ],
            },
            {
              type: 'Group',
              elements: [
                {
                  type: 'HorizontalLayout',
                  elements: [
                    {
                      type: 'VerticalLayout',
                      elements: [
                        {
                          type: 'Control',
                          scope: '#/properties/addVirtualCloudServer',
                          label: 'Add Cloud Server',
                        },
                      ],
                    },
                  ],
                },
              ],
            },
          ],
        },
        {
          type: 'Category',
          label: 'New Cloud Server',
          elements: [
            {
              type: 'HorizontalLayout',
              elements: [
                {
                  type: 'Control',
                  scope:
                    '#/properties/virtualCloudServerProperties/properties/serverDescription',
                  label:
                    'Geben Sie eine Serverbeschreibung für diesen Server an',
                },
                {
                  type: 'Control',
                  scope: '#/properties/baInOrderId',
                  label: 'Ihre Order ID (unter Basic Information angegeben',
                  readonly: true,
                },
              ],
            },
            {
              type: 'HorizontalLayout',
              elements: [
                {
                  type: 'Control',
                  scope:
                    '#/properties/virtualCloudServerProperties/properties/cloud',
                  label: 'Wählen Sie bitte den Cloud Provider aus',
                },
                {
                  type: 'Control',
                  scope:
                    '#/properties/virtualCloudServerProperties/properties/cloudAccount',
                  label:
                    'Geben Sie bitte den Cloud Account zu der ausgewählten Cloud an',
                },
              ],
            },
            {
              type: 'HorizontalLayout',
              elements: [
                {
                  type: 'Control',
                  scope:
                    '#/properties/virtualCloudServerProperties/properties/cloudRegion',
                },
                {
                  type: 'Control',
                  scope:
                    '#/properties/virtualCloudServerProperties/properties/plannedServerFunction',
                },
              ],
            },
            {
              type: 'HorizontalLayout',
              elements: [
                {
                  type: 'Control',
                  scope:
                    '#/properties/virtualCloudServerProperties/properties/operatingSystem',
                },
                {
                  type: 'Control',
                  scope:
                    '#/properties/virtualCloudServerProperties/properties/domain',
                },
              ],
            },
            {
              type: 'HorizontalLayout',
              elements: [
                {
                  type: 'Control',
                  scope:
                    '#/properties/virtualCloudServerProperties/properties/vpcVcpu',
                  label: 'Geben Sie bitte Die Anzahl der virtuellen CPUs an',
                },
                {
                  type: 'Control',
                  scope:
                    '#/properties/virtualCloudServerProperties/properties/vpcRam',
                  label: 'RAM für den Server',
                },
              ],
            },
          ],
          rule: {
            effect: 'SHOW',
            condition: {
              scope: '#/properties/addVirtualCloudServer',
              schema: {
                const: true,
              },
            },
          },
        },
      ],
      options: {
        variant: 'stepper',
        showNavButtons: true,
      },
    },
  },
}
sdirix commented 2 years ago

Hi!

In the failing example the last control points to #/properties/virtualCloudServerProperties/properties/vpcRam but this property simply does not exist in the schema at that location, therefore it can't render anything. In the schema it's part of the anyOf/if chain at the root level, so it would be #/properties/vpcRam.

My guess is that you want to move the anyOf/if further in, e.g.

{
  "type":"object",
  "properties":{
    "systemConfiguration":{
      "title":"System Configuration(s)",
      "type":"array",
      "items":{
        "type":"object",
        "properties":{
          "baInSystemDescription":{
            "type":"string"
          },
          "baInOrderId":{
            "type":"string"
          },
          "addVirtualCloudServer":{
            "type":"boolean"
          },
          "virtualCloudServerProperties":{
            "type":"object",
            "anyOf":[
              {
                "if":{
                  "properties":{
                    "operatingSystem":{
                      "enum":[
                        "Win2022",
                        "Win2019",
                        "Win2016"
                      ]
                    }
                  }
                },
                "then":{
                  "properties":{
                    "vpcRam":{
                      "type":"integer",
                      "minimum":4,
                      "maximum":96
                    }
                  }
                },
                "else":{
                  "properties":{
                    "vpcRam":{
                      "type":"integer",
                      "minimum":1,
                      "maximum":96
                    }
                  }
                }
              }
            ],
            "properties":{
              "serverDescription":{
                "type":"string"
              },
              "orderId":{
                "type":"string"
              },
              "cloud":{
                "type":"string",
                "enum":[
                  "VPC",
                  "Azure",
                  "AWS",
                  "GPC"
                ]
              },
              "cloudAccount":{
                "type":"string"
              },
              "cloudRegion":{
                "type":"string"
              },
              "plannedServerFunction":{
                "type":"string",
                "enum":[
                  "Other",
                  "Web Application",
                  "Oracle",
                  "SAP",
                  "MSSQL",
                  "Citrix",
                  "Domain Controller",
                  "SCOM Gateway",
                  "TSM Proxy"
                ]
              },
              "operatingSystem":{
                "type":"string",
                "enum":[
                  "Win2022",
                  "Win2019",
                  "Win2016",
                  "SLES15",
                  "SLES12",
                  "CENTOS7"
                ]
              },
              "domain":{
                "type":"string"
              },
              "vpcVcpu":{
                "type":"integer",
                "minimum":1,
                "maximum":20
              },
              "serverNetwork":{
                "type":"string"
              },
              "serverPatchWindow":{
                "type":"string",
                "enum":[
                  "PW1MW2WED",
                  "PW1MW1THU",
                  "PW1MW2THU",
                  "PW1MW3THU",
                  "PW1MW1FRI",
                  "PW1MW2FRI",
                  "PW1MW1SAT",
                  "PW1MW2SUN",
                  "PW2MW1MON",
                  "PW2MW2MON",
                  "PW2MW1TUE",
                  "PW2MW2TUE",
                  "PW2MW3TUE",
                  "PW2MW1WED",
                  "PW2MW2WED",
                  "PW2MW1THU",
                  "PW2MW2THU",
                  "PW2MW2FRI",
                  "PW2MW1SUN"
                ]
              },
              "serverPatchIntervallLinux":{
                "type":"string",
                "enum":[
                  "03/09",
                  "06/12"
                ]
              },
              "serverPatchIntervallWindows":{
                "type":"string",
                "default":"1,2,3,4,5,6,7,8,9,10,11,12",
                "readOnly":true
              }
            }
          }
        }
      }
    }
  }
}

I hope this helps. For questions like this feel free to ask in the forum instead of opening an issue.