A platform for community discussion. Free, open, simple.
FEATURE: Support dynamic expressions for workflow boolean fields (#42161)
Renato Atilioc604b93c0bee
diff --git a/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/configurators/assignment-collection.gjs b/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/configurators/assignment-collection.gjsindex e84c6fb142c..0d0b35ea13a 100644--- a/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/configurators/assignment-collection.gjs+++ b/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/configurators/assignment-collection.gjs@@ -5,6 +5,7 @@ import DButton from "discourse/ui-kit/d-button";import { i18n } from "discourse-i18n";import {findNodeType,+ isExpression,propertyDescription,propertyLabel,} from "../../../lib/workflows/property-engine";@@ -21,6 +22,24 @@ const DEFAULT_ASSIGNMENT_TYPES = ["object",];+// Expressions are type-agnostic; plain values only survive a type change when+// they still make sense for the new type.+function valueForType(value, type) {+ if (isExpression(value)) {+ return value;+ }++ if (type === "boolean") {+ return value === true;+ }++ if (typeof value === "boolean") {+ return "";+ }++ return value;+}+function normalizeAssignmentType(type) {const option = typeof type === "object" ? { ...type } : { value: type };@@ -103,13 +122,25 @@ export default class AssignmentCollection extends Component {this.args.onChange?.();}+ @action+ handleTypeChange(index, type, { set, name }) {+ set(name, type);++ if (!this.args.formApi) {+ return;+ }++ const valuePath = `${this.assignmentsPath}.${index}.value`;+ set(valuePath, valueForType(this.args.formApi.get(valuePath), type));+ }+@actionvalueSchema(item) {switch (item?.type) {case "number":return { type: "number" };case "boolean":- return { type: "boolean" };+ return { type: "boolean", ui: { expression: true } };case "array":case "object":return {@@ -181,6 +212,7 @@ export default class AssignmentCollection extends Component {@label={{i18n"discourse_workflows.property_engine.assignment_type"}}+ @onSet={{fn this.handleTypeChange index}}@node={{@node}}@nodeDefinition={{this.nodeDefinition}}@nodeParameters={{@nodeParameters}}@@ -194,6 +226,7 @@ export default class AssignmentCollection extends Component {<Field@form={{object}}@formApi={{@formApi}}+ @configuration={{item}}@connections={{@connections}}@credentials={{@credentials}}@fieldName="value"diff --git a/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/configurators/boolean-control.gjs b/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/configurators/boolean-control.gjsindex bad9a640199..bd1318b62d7 100644--- a/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/configurators/boolean-control.gjs+++ b/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/configurators/boolean-control.gjs@@ -1,9 +1,4 @@import Component from "@glimmer/component";-import { tracked } from "@glimmer/tracking";-import { fn } from "@ember/helper";-import { action } from "@ember/object";-import DSegmentedControl from "discourse/components/d-segmented-control";-import { i18n } from "discourse-i18n";import {fieldFormat,fieldShowDescription,@@ -15,41 +10,13 @@ import {} from "../../../lib/workflows/property-engine";import ExpressionWrapper from "./expression-wrapper";-const MODE_ITEMS = [- {- value: "plain",- icon: "paragraph",- label: i18n("discourse_workflows.parameter_field.plain"),- },- {- value: "dynamic",- icon: "code",- label: i18n("discourse_workflows.parameter_field.dynamic"),- },-];--function valueForModeToggle(value) {- if (value === null || value === undefined) {- return "";- }-- return String(value);-}--function booleanValueForPlainMode(value) {- const plainValue = value.startsWith("=") ? value.slice(1) : value;-- return ["true", "1"].includes(plainValue.trim().toLowerCase());-}-export default class BooleanControl extends Component {- @tracked expressionMode = this.#initialExpressionMode();-- #initialExpressionMode() {- if (!fieldSupportsExpression(this.args.schema)) {- return false;- }- return isExpression(this.args.configuration?.[this.args.fieldName]);+ // Derived, not tracked, so a dropped variable flips the mode.+ get expressionMode() {+ return (+ this.supportsExpression &&+ isExpression(this.args.configuration?.[this.args.fieldName])+ );}get supportsExpression() {@@ -82,48 +49,27 @@ export default class BooleanControl extends Component {return this.args.schema?.required ? "required" : undefined;}- @action- onModeChange(field, value) {- const wantsDynamic = value === "dynamic";- if (wantsDynamic === this.expressionMode) {- return;- }-- this.expressionMode = wantsDynamic;- const currentValue = valueForModeToggle(field.value);-- if (wantsDynamic) {- field.set(- currentValue.startsWith("=") ? currentValue : `=${currentValue}`- );- } else {- field.set(booleanValueForPlainMode(currentValue));- }- }-<template>{{#if this.expressionMode}}<@form.Field@name={{@fieldName}}@title={{this.label}}- @showTitle={{true}}+ @tooltip={{this.tooltip}}@showOptional={{@showOptional}}@type="custom"@format={{this.format}}+ @validation={{this.validation}}@onSet={{@onSet}}as |field|><field.Control><ExpressionWrapper- @expressionMode={{true}}@field={{field}}@schema={{@schema}}@placeholder={{this.placeholder}}@supportsExpression={{this.supportsExpression}}@dynamicValueHint={{@dynamicValueHint}}@session={{@session}}- @modeItems={{MODE_ITEMS}}- @onModeChange={{fn this.onModeChange field}}/></field.Control></@form.Field>@@ -132,22 +78,21 @@ export default class BooleanControl extends Component {@name={{@fieldName}}@title={{this.label}}@tooltip={{this.tooltip}}+ @showOptional={{@showOptional}}@type="toggle"@format={{this.format}}- @showOptional={{@showOptional}}@validation={{this.validation}}+ @onSet={{@onSet}}as |field|>- <field.Control />- {{#if this.supportsExpression}}- <DSegmentedControl- @items={{MODE_ITEMS}}- @value="plain"- @onSelect={{fn this.onModeChange field}}- @size="small"- class="workflows-property-engine__mode-control --toggle"- />- {{/if}}+ <ExpressionWrapper+ @field={{field}}+ @schema={{@schema}}+ @supportsExpression={{this.supportsExpression}}+ @session={{@session}}+ >+ <field.Control />+ </ExpressionWrapper></@form.Field>{{/if}}</template>diff --git a/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/configurators/expression-wrapper.gjs b/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/configurators/expression-wrapper.gjsindex 2536f119463..dac70b77c43 100644--- a/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/configurators/expression-wrapper.gjs+++ b/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/configurators/expression-wrapper.gjs@@ -127,6 +127,11 @@ function plainValueForModeToggle(value, schema = {}) {return plainArrayValueForModeToggle(value);}+ if (type === "boolean") {+ const literal = wholeExpressionBody(value) ?? value.slice(1);+ return ["true", "1"].includes(literal.trim().toLowerCase());+ }+const body = wholeExpressionBody(value);if (body) {const parsedLiteral = parseJsonLiteral(body);@@ -153,24 +158,11 @@ export default class ExpressionWrapper extends Component {}get expressionMode() {- if (this.args.expressionMode !== undefined) {- return Boolean(this.args.expressionMode);- }-return isExpression(this.args.field?.value);}- get modeItems() {- return this.args.modeItems || MODE_ITEMS;- }-@actiontoggleMode(value) {- if (this.args.onModeChange) {- this.args.onModeChange(value);- return;- }-const wantsDynamic = value === "dynamic";if (wantsDynamic === this.expressionMode) {return;@@ -278,7 +270,7 @@ export default class ExpressionWrapper extends Component {{{#if @supportsExpression}}<DSegmentedControl- @items={{this.modeItems}}+ @items={{MODE_ITEMS}}@value={{if this.expressionMode "dynamic" "plain"}}@onSelect={{this.toggleMode}}@size="small"diff --git a/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/configurators/fixed-collection.gjs b/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/configurators/fixed-collection.gjsindex 1257cb825a3..b42c486e259 100644--- a/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/configurators/fixed-collection.gjs+++ b/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/configurators/fixed-collection.gjs@@ -405,7 +405,7 @@ export default class FixedCollection extends Component {><subCollection.Objectclass="workflows-property-engine__nested-collection-item"- as |subObject|+ as |subObject subItem|>{{#each@@ -415,6 +415,7 @@ export default class FixedCollection extends Component {<Field@form={{subObject}}@formApi={{@formApi}}+ @configuration={{subItem}}@connections={{@connections}}@credentials={{@credentials}}@fieldName={{subField.name}}@@ -459,6 +460,7 @@ export default class FixedCollection extends Component {<Field@form={{object}}@formApi={{@formApi}}+ @configuration={{item}}@connections={{@connections}}@credentials={{@credentials}}@fieldName={{extraField.name}}diff --git a/plugins/discourse-workflows/assets/stylesheets/common/configurator/configurator.scss b/plugins/discourse-workflows/assets/stylesheets/common/configurator/configurator.scssindex bab31208105..c17f1d63520 100644--- a/plugins/discourse-workflows/assets/stylesheets/common/configurator/configurator.scss+++ b/plugins/discourse-workflows/assets/stylesheets/common/configurator/configurator.scss@@ -112,6 +112,10 @@position: relative;width: 100%;+ > .d-toggle-switch {+ justify-content: flex-end;+ }+> .combo-box,> .d-select,> .icon-picker,@@ -130,7 +134,7 @@transform: translateY(-100%);inset-inline-end: 0;- &.--toggle {+ .form-kit__field-toggle & {inset-block-start: 50%;transform: translateY(-50%);inset-inline-end: 50px;@@ -156,6 +160,14 @@border-color: var(--tertiary) !important;background: var(--tertiary-50);}++ // The toggle class lands on the hidden checkbox, so target its visible sibling.+ &.is-drag-over+ .form-kit__control-toggle+ + .d-toggle-switch__checkbox-slider {+ outline: 2px solid var(--tertiary);+ outline-offset: 2px;+ }}&__collection-row {diff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/set_fields_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/set_fields_spec.rbindex 258115612fb..7ee1f3e9ebb 100644--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/set_fields_spec.rb+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/set_fields_spec.rb@@ -69,6 +69,38 @@ RSpec.describe DiscourseWorkflows::Nodes::SetFields::V1 doexpect(result).to eq({ "a" => false, "b" => false, "c" => false, "d" => true })end+ it "casts boolean values resolved from expressions" do+ config = { "include_other_fields" => false }.merge(+ assignments(+ assignment("from_true", "={{ $json.enabled }}", "boolean"),+ assignment("from_false", "={{ $json.disabled }}", "boolean"),+ assignment("from_number", "={{ $json.count }}", "boolean"),+ assignment("from_missing", "={{ $json.nope }}", "boolean"),+ ),+ )++ result =+ execute_node(+ configuration: config,+ item: {+ "json" => {+ "enabled" => true,+ "disabled" => false,+ "count" => 1,+ },+ },+ )++ expect(result).to eq(+ {+ "from_true" => true,+ "from_false" => false,+ "from_number" => true,+ "from_missing" => false,+ },+ )+ end+it "casts float values" doconfig = { "include_other_fields" => false }.merge(assignments(assignment("score", "3.14", "float"), assignment("whole", "7", "float")),diff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/workflow_call_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/workflow_call_spec.rbindex bbc5904544c..e0827b11530 100644--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/workflow_call_spec.rb+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/workflow_call_spec.rb@@ -264,7 +264,7 @@ RSpec.describe DiscourseWorkflows::Nodes::WorkflowCall::V1 do"assignments" => [assignment("full_name", "={{ $json.name }}"),assignment("profile.score", "12.5", type: "number"),- assignment("active", "true", type: "boolean"),+ assignment("active", "={{ $json.enabled }}", type: "boolean"),assignment("tags", '["workflow"]', type: "array"),assignment("source", "={{ $json }}", type: "object"),],@@ -273,7 +273,13 @@ RSpec.describe DiscourseWorkflows::Nodes::WorkflowCall::V1 do)execution =- execute_workflow(caller, trigger_data: [{ "name" => "Ada" }, { "name" => "Grace" }])+ execute_workflow(+ caller,+ trigger_data: [+ { "name" => "Ada", "enabled" => true },+ { "name" => "Grace", "enabled" => false },+ ],+ )expect_parent_waiting_at_call(execution)expect(run_workflow_call_jobs).to eq(1)@@ -293,6 +299,7 @@ RSpec.describe DiscourseWorkflows::Nodes::WorkflowCall::V1 do"tags" => ["workflow"],"source" => {"name" => "Ada",+ "enabled" => true,},},{@@ -300,10 +307,11 @@ RSpec.describe DiscourseWorkflows::Nodes::WorkflowCall::V1 do"profile" => {"score" => 12.5,},- "active" => true,+ "active" => false,"tags" => ["workflow"],"source" => {"name" => "Grace",+ "enabled" => false,},},]diff --git a/plugins/discourse-workflows/test/javascripts/integration/components/workflows/boolean-control-test.gjs b/plugins/discourse-workflows/test/javascripts/integration/components/workflows/boolean-control-test.gjsindex 9cf8536378a..9d5f1b10450 100644--- a/plugins/discourse-workflows/test/javascripts/integration/components/workflows/boolean-control-test.gjs+++ b/plugins/discourse-workflows/test/javascripts/integration/components/workflows/boolean-control-test.gjs@@ -1,9 +1,32 @@-import { click, render } from "@ember/test-helpers";+import { click, render, triggerEvent } from "@ember/test-helpers";import { module, test } from "qunit";import Form from "discourse/components/form";import { setupRenderingTest } from "discourse/tests/helpers/component-test";import pretender, { response } from "discourse/tests/helpers/create-pretender";import BooleanControl from "discourse/plugins/discourse-workflows/admin/components/workflows/configurators/boolean-control";+import { WORKFLOW_VARIABLE_MIME } from "discourse/plugins/discourse-workflows/admin/lib/workflows/expression-context";++const CONTROL_WRAPPER = ".workflows-property-engine__control-wrapper";++function variableTransfer(variable) {+ return {+ types: [WORKFLOW_VARIABLE_MIME],+ getData: (type) =>+ type === WORKFLOW_VARIABLE_MIME ? JSON.stringify(variable) : "",+ };+}++function dragVariableOver(variable) {+ return triggerEvent(CONTROL_WRAPPER, "dragover", {+ dataTransfer: variableTransfer(variable),+ });+}++function dropVariable(variable) {+ return triggerEvent(CONTROL_WRAPPER, "drop", {+ dataTransfer: variableTransfer(variable),+ });+}module("Integration | Component | workflows boolean control", function (hooks) {setupRenderingTest(hooks);@@ -42,7 +65,9 @@ module("Integration | Component | workflows boolean control", function (hooks) {);assert.dom(".form-kit__control-toggle").exists();- assert.dom(".workflows-property-engine__mode-control").exists();+ assert+ .dom(".form-kit__field-toggle .workflows-property-engine__mode-control")+ .exists("positions the switcher inside the toggle field");});test("switches to expression mode", async function (assert) {@@ -155,6 +180,43 @@ module("Integration | Component | workflows boolean control", function (hooks) {assert.false(this.formApi.get("enabled"));});+ test("converts literal expressions back to plain booleans", async function (assert) {+ this.setProperties({+ configuration: { enabled: "={{ true }}" },+ formApi: null,+ schema: { type: "boolean", ui: { expression: true } },+ registerApi: (api) => this.set("formApi", api),+ });++ await render(+ <template>+ <Form+ @data={{this.configuration}}+ @onRegisterApi={{this.registerApi}}+ as |form transientData|+ >+ <BooleanControl+ @form={{form}}+ @formApi={{this.formApi}}+ @configuration={{transientData}}+ @fieldName="enabled"+ @label="Enabled"+ @schema={{this.schema}}+ />+ </Form>+ </template>+ );++ await click(+ '.workflows-property-engine__mode-control input[value="plain"]'+ );++ assert.true(+ this.formApi.get("enabled"),+ "unwraps the literal instead of discarding it"+ );+ });+test("renders in expression mode when value starts with =", async function (assert) {this.setProperties({configuration: { enabled: "=true" },@@ -182,14 +244,21 @@ module("Integration | Component | workflows boolean control", function (hooks) {test("renders plain toggle without mode control when expressions disabled", async function (assert) {this.setProperties({configuration: { enabled: false },+ formApi: null,schema: { type: "boolean", no_data_expression: true },+ registerApi: (api) => this.set("formApi", api),});await render(<template>- <Form @data={{this.configuration}} as |form transientData|>+ <Form+ @data={{this.configuration}}+ @onRegisterApi={{this.registerApi}}+ as |form transientData|+ ><BooleanControl@form={{form}}+ @formApi={{this.formApi}}@configuration={{transientData}}@fieldName="enabled"@label="Enabled"@@ -201,5 +270,65 @@ module("Integration | Component | workflows boolean control", function (hooks) {assert.dom(".form-kit__control-toggle").exists();assert.dom(".workflows-property-engine__mode-control").doesNotExist();+ assert+ .dom(CONTROL_WRAPPER)+ .doesNotHaveAttribute(+ "data-supports-expression",+ "does not advertise itself as a drop target"+ );++ await dropVariable({ id: "enabled" });++ assert.false(+ this.formApi.get("enabled"),+ "ignores a dropped variable instead of storing an expression"+ );+ assert.dom(".form-kit__control-toggle").exists("stays a plain toggle");+ });++ test("dropping a variable on the plain toggle switches to expression mode", async function (assert) {+ this.setProperties({+ configuration: { enabled: false },+ formApi: null,+ schema: { type: "boolean", ui: { expression: true } },+ registerApi: (api) => this.set("formApi", api),+ });++ await render(+ <template>+ <Form+ @data={{this.configuration}}+ @onRegisterApi={{this.registerApi}}+ as |form transientData|+ >+ <BooleanControl+ @form={{form}}+ @formApi={{this.formApi}}+ @configuration={{transientData}}+ @fieldName="enabled"+ @label="Enabled"+ @schema={{this.schema}}+ />+ </Form>+ </template>+ );++ await dragVariableOver({ id: "enabled" });++ assert+ .dom(CONTROL_WRAPPER)+ .hasClass("is-drag-over", "highlights the toggle as a drop target");++ await dropVariable({ id: "enabled" });++ assert.strictEqual(+ this.formApi.get("enabled"),+ "={{ $json.enabled }}",+ "stores the dropped variable as an expression, prefixed with the item path"+ );+ assert+ .dom(".form-kit__control-toggle")+ .doesNotExist("replaces the toggle rather than leaving a stale switch");+ assert.dom(".workflows-variable-input").exists();});});diff --git a/plugins/discourse-workflows/test/javascripts/integration/components/workflows/property-engine-test.gjs b/plugins/discourse-workflows/test/javascripts/integration/components/workflows/property-engine-test.gjsindex 1210230aad1..d5828b57983 100644--- a/plugins/discourse-workflows/test/javascripts/integration/components/workflows/property-engine-test.gjs+++ b/plugins/discourse-workflows/test/javascripts/integration/components/workflows/property-engine-test.gjs@@ -2004,4 +2004,276 @@ module("Integration | Component | workflows property engine", function (hooks) {"converts the dynamic expression back into a fixed list");});++ test("boolean assignment values convert between fixed and dynamic", async function (assert) {+ this.setProperties({+ configuration: {+ fields: {+ assignments: [{ name: "active", type: "boolean", value: false }],+ },+ },+ formApi: null,+ nodeType: "action:workflow_call",+ schema: {+ fields: {+ type: "assignment_collection",+ },+ },+ registerApi: (api) => {+ this.set("formApi", api);+ },+ });++ await render(+ <template>+ <Form+ @data={{this.configuration}}+ @onRegisterApi={{this.registerApi}}+ as |form transientData|+ >+ <PropertyEngineConfigurator+ @form={{form}}+ @formApi={{this.formApi}}+ @configuration={{transientData}}+ @nodeType={{this.nodeType}}+ @schema={{this.schema}}+ @session={{this.session}}+ />+ </Form>+ </template>+ );++ const row = ".workflows-property-engine__collection-row";++ assert+ .dom(`${row} .form-kit__control-toggle`)+ .exists("starts as a plain toggle");+ assert+ .dom(`${row} .workflows-property-engine__mode-control`)+ .exists("offers a dynamic mode for boolean assignments");++ await click(+ `${row} .workflows-property-engine__mode-control input[value="dynamic"]`+ );++ assert+ .dom(`${row} .workflows-variable-input`)+ .exists("swaps the toggle for an expression input");+ assert.strictEqual(+ this.formApi.get("fields.assignments.0.value"),+ "=false",+ "seeds the expression with the previous fixed value"+ );++ await click(+ `${row} .workflows-property-engine__mode-control input[value="plain"]`+ );++ assert.false(+ this.formApi.get("fields.assignments.0.value"),+ "converts the expression back into a fixed boolean, not the string 'false'"+ );+ });++ test("boolean assignment values saved as expressions render in dynamic mode", async function (assert) {+ this.setProperties({+ configuration: {+ fields: {+ assignments: [+ { name: "active", type: "boolean", value: "={{ $json.enabled }}" },+ ],+ },+ },+ nodeType: "action:workflow_call",+ schema: {+ fields: {+ type: "assignment_collection",+ },+ },+ });++ await render(+ <template>+ <Form @data={{this.configuration}} as |form transientData|>+ <PropertyEngineConfigurator+ @form={{form}}+ @configuration={{transientData}}+ @nodeType={{this.nodeType}}+ @schema={{this.schema}}+ @session={{this.session}}+ />+ </Form>+ </template>+ );++ assert.dom(".form-kit__control-toggle").doesNotExist();+ assert.dom(".workflows-variable-input").includesText("enabled");+ });++ test("switching an assignment to boolean keeps an expression it already holds", async function (assert) {+ this.setProperties({+ configuration: {+ fields: {+ assignments: [+ { name: "active", type: "string", value: "={{ $json.enabled }}" },+ ],+ },+ },+ formApi: null,+ nodeType: "action:workflow_call",+ schema: {+ fields: {+ type: "assignment_collection",+ },+ },+ registerApi: (api) => {+ this.set("formApi", api);+ },+ });++ await render(+ <template>+ <Form+ @data={{this.configuration}}+ @onRegisterApi={{this.registerApi}}+ as |form transientData|+ >+ <PropertyEngineConfigurator+ @form={{form}}+ @formApi={{this.formApi}}+ @configuration={{transientData}}+ @nodeType={{this.nodeType}}+ @schema={{this.schema}}+ @session={{this.session}}+ />+ </Form>+ </template>+ );++ await select(+ ".workflows-property-engine__collection-row select",+ "boolean"+ );++ assert.strictEqual(+ this.formApi.get("fields.assignments.0.value"),+ "={{ $json.enabled }}",+ "keeps the expression when the type changes"+ );+ assert+ .dom(".form-kit__control-toggle")+ .doesNotExist("does not fall back to a toggle over an expression");+ assert.dom(".workflows-variable-input").includesText("enabled");+ });++ test("resets plain assignment values that don't fit the new type", async function (assert) {+ this.setProperties({+ configuration: {+ fields: {+ assignments: [{ name: "active", type: "string", value: "hello" }],+ },+ },+ formApi: null,+ nodeType: "action:workflow_call",+ schema: {+ fields: {+ type: "assignment_collection",+ },+ },+ registerApi: (api) => {+ this.set("formApi", api);+ },+ });++ await render(+ <template>+ <Form+ @data={{this.configuration}}+ @onRegisterApi={{this.registerApi}}+ as |form transientData|+ >+ <PropertyEngineConfigurator+ @form={{form}}+ @formApi={{this.formApi}}+ @configuration={{transientData}}+ @nodeType={{this.nodeType}}+ @schema={{this.schema}}+ @session={{this.session}}+ />+ </Form>+ </template>+ );++ const typeSelect = ".workflows-property-engine__collection-row select";++ await select(typeSelect, "boolean");++ assert.false(+ this.formApi.get("fields.assignments.0.value"),+ "a string is not carried into the toggle as truthy"+ );++ await select(typeSelect, "array");++ assert.strictEqual(+ this.formApi.get("fields.assignments.0.value"),+ "",+ "a boolean is not carried into the JSON editor"+ );+ });++ // Rows are keyed by index, so the survivor reuses the deleted row's component.+ test("removing a boolean assignment row keeps the survivor's expression", async function (assert) {+ this.setProperties({+ configuration: {+ fields: {+ assignments: [+ { name: "flagged", type: "boolean", value: false },+ { name: "active", type: "boolean", value: "={{ $json.enabled }}" },+ ],+ },+ },+ formApi: null,+ nodeType: "action:workflow_call",+ schema: {+ fields: {+ type: "assignment_collection",+ },+ },+ registerApi: (api) => {+ this.set("formApi", api);+ },+ });++ await render(+ <template>+ <Form+ @data={{this.configuration}}+ @onRegisterApi={{this.registerApi}}+ as |form transientData|+ >+ <PropertyEngineConfigurator+ @form={{form}}+ @formApi={{this.formApi}}+ @configuration={{transientData}}+ @nodeType={{this.nodeType}}+ @schema={{this.schema}}+ @session={{this.session}}+ />+ </Form>+ </template>+ );++ await click(findAll(".workflows-property-engine__collection-delete")[0]);++ assert.strictEqual(+ this.formApi.get("fields.assignments.0.value"),+ "={{ $json.enabled }}",+ "leaves the surviving expression untouched"+ );+ assert+ .dom(".form-kit__control-toggle")+ .doesNotExist("does not offer a toggle that would overwrite it");+ assert.dom(".workflows-variable-input").includesText("enabled");+ });});diff --git a/plugins/discourse-workflows/test/javascripts/unit/lib/workflows-property-engine-test.js b/plugins/discourse-workflows/test/javascripts/unit/lib/workflows-property-engine-test.jsindex c35cc5f63a3..93713e81a50 100644--- a/plugins/discourse-workflows/test/javascripts/unit/lib/workflows-property-engine-test.js+++ b/plugins/discourse-workflows/test/javascripts/unit/lib/workflows-property-engine-test.js@@ -295,6 +295,10 @@ module("Unit | Utility | workflows property engine", function () {assert.true(fieldSupportsExpression({ type: "options", ui: { expression: true } }));+ assert.false(fieldSupportsExpression({ type: "boolean" }));+ assert.true(+ fieldSupportsExpression({ type: "boolean", ui: { expression: true } })+ );});test("multi_options defaults to an empty array", function (assert) {