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

Incosistent behavior of boolean property conditions #84

Closed
chillleader opened this issue Apr 16, 2024 · 3 comments · Fixed by #90
Closed

Incosistent behavior of boolean property conditions #84

chillleader opened this issue Apr 16, 2024 · 3 comments · Fixed by #90
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@chillleader
Copy link

Describe the Bug

Boolean properties behave inconsistently when it comes to referencing them in conditions:

  • When condition expects a boolean property to be true, it works as expected
  • When condition expects a boolean property to be false, nothing happens
  • Additionally, the boolean property's initial state is visually false (checkbox not active), however, the default element template value is "" (empty string).

Steps to Reproduce

  1. Use the following element template
Element template
{
  "$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema/resources/schema.json",
  "name": "Boolean prop bug demo",
  "id": "9741b537-6b04-4540-9fbc-e136dcbcb5bc",
  "version": 1713266932057,
  "appliesTo": [
    "bpmn:Task"
  ],
  "properties": [
    {
      "id": "myBooleanProp",
      "type": "Boolean",
      "label": "Checkbox",
      "binding": {
        "type": "zeebe:property",
        "name": "myBooleanProp"
      }
    },
    {
      "id": "inputForActiveCheckbox",
      "type": "String",
      "label": "Input that appears when checkbox is ACTIVE",
      "binding": {
        "type": "zeebe:property",
        "name": "inputActive"
      },
      "condition": {
        "property": "myBooleanProp",
        "equals": true
      }
    },
    {
      "id": "inputForInactiveCheckbox",
      "type": "String",
      "label": "Input that appears when checkbox is INACTIVE",
      "binding": {
        "type": "zeebe:property",
        "name": "inputInactive"
      },
      "condition": {
        "property": "myBooleanProp",
        "equals": false
      }
    }
  ]
}
  1. Apply it to a task in a BPMN diagram
  2. Observe that inputForActiveCheckbox is added when the checkbox is active, however when it's not active, inputForInactiveCheckbox is not added.

Expected Behavior

  • Conditions that expect boolean properties to be false should work as expected
  • Boolean properties should have a default value of false unless specified otherwise to be consistent with the UI representation

Environment

  • Desktop Modeler 5.22.0 / Web Modeler 8.5.0
@chillleader chillleader added the bug Something isn't working label Apr 16, 2024
@marstamm
Copy link
Collaborator

I can reproduce this bug. Root cause is this line, where we check if the condition has an equals.

if (equals) {
return propertyValue === equals;
}

The Code only checks if equals has a truthy value, rather than if the property exists. This blocks use-cases like checking for "false" or "undefined". We should therefore use condition.hasOwnProperty('equals') here.

@marstamm marstamm added ready Ready to be worked on good first issue Good for newcomers labels Apr 18, 2024
@marstamm
Copy link
Collaborator

When implementing, I noticed that initially, the value will be '' (empty string) instead of false. To ensure the conditional property is displayed on the first render, you need to add a default value to it:

    {
      "id": "myBooleanProp",
      "type": "Boolean",
      "label": "Checkbox",
      "binding": {
        "type": "zeebe:property",
        "name": "myBooleanProp"
      },
      "value": false
    },

I'll go ahead with the identified fix and open a follow-up issue to decide if we always want to persist "false" by default

@nikku
Copy link
Member

nikku commented Apr 26, 2024

Released v1.15.2 with the fix.

nikku added a commit to camunda/camunda-modeler that referenced this issue Apr 26, 2024
fix: correctly handle failsy properties in element template conditions

  Related to bpmn-io/bpmn-js-element-templates#84
marstamm pushed a commit to camunda/camunda-modeler that referenced this issue Apr 26, 2024
fix: correctly handle failsy properties in element template conditions

  Related to bpmn-io/bpmn-js-element-templates#84
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Development

Successfully merging a pull request may close this issue.

3 participants