From 1e2551677ebb92fee39fe8648479401471d89eb5 Mon Sep 17 00:00:00 2001 From: Valentin Serra Date: Mon, 27 May 2024 07:27:58 +0200 Subject: [PATCH] fix: expressions are properly included in `getSchemaVariables` Closes #1186 --- .../src/util/getSchemaVariables.js | 1 + .../test/spec/expressionField.json | 18 ++++++++++++++++++ .../test/spec/util/GetSchemaVariables.spec.js | 7 +++++++ 3 files changed, 26 insertions(+) create mode 100644 packages/form-js-viewer/test/spec/expressionField.json diff --git a/packages/form-js-viewer/src/util/getSchemaVariables.js b/packages/form-js-viewer/src/util/getSchemaVariables.js index a6f629213..d5615ce85 100644 --- a/packages/form-js-viewer/src/util/getSchemaVariables.js +++ b/packages/form-js-viewer/src/util/getSchemaVariables.js @@ -22,6 +22,7 @@ const EXPRESSION_PROPERTIES = [ 'url', 'dataSource', 'columnsExpression', + 'expression', ]; const TEMPLATE_PROPERTIES = [ diff --git a/packages/form-js-viewer/test/spec/expressionField.json b/packages/form-js-viewer/test/spec/expressionField.json new file mode 100644 index 000000000..ef29ac2fc --- /dev/null +++ b/packages/form-js-viewer/test/spec/expressionField.json @@ -0,0 +1,18 @@ +{ + "id": "Form_1lywnv3", + "components": [ + { + "computeOn": "change", + "label": "Expression", + "type": "expression", + "layout": { + "row": "Row_0duk8pr", + "columns": null + }, + "id": "Field_01dikzb", + "key": "exp_expression", + "expression": "=flatten(data[selected = filter].dates)" + } + ], + "type": "default" +} diff --git a/packages/form-js-viewer/test/spec/util/GetSchemaVariables.spec.js b/packages/form-js-viewer/test/spec/util/GetSchemaVariables.spec.js index abf50b2df..590d90a38 100644 --- a/packages/form-js-viewer/test/spec/util/GetSchemaVariables.spec.js +++ b/packages/form-js-viewer/test/spec/util/GetSchemaVariables.spec.js @@ -18,6 +18,7 @@ import groupsSchema from '../groups.json'; import shipsExampleSchema from '../ships-example.json'; import iframesSchema from '../iframes.json'; import htmlSchema from '../html.json'; +import expressionFieldSchema from '../expressionField.json'; describe('util/getSchemaVariables', () => { it('should include form field keys', () => { @@ -204,4 +205,10 @@ describe('util/getSchemaVariables', () => { 'separated2', ]); }); + + it('should include variables in complex templates', () => { + const variables = getSchemaVariables(expressionFieldSchema); + + expect(variables).to.include.members(['exp_expression', 'data', 'selected', 'filter']); + }); });