Skip to content

Commit

Permalink
feat(cloud): don't apply length and pattern validation to FEEL
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme committed Aug 12, 2024
1 parent e7b60db commit c11a626
Show file tree
Hide file tree
Showing 8 changed files with 234 additions and 7 deletions.
8 changes: 8 additions & 0 deletions src/cloud-element-templates/util/propertyUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,10 @@ export function validateProperty(value, property, translate = defaultTranslate)
return `${label} ${translate('must not be empty.')}`;
}

if (property.feel && isFeel(value)) {
return;
}

if (maxLength && (value || '').length > maxLength) {
return `${label} ${translate('must have max length {maxLength}.', { maxLength })}`;
}
Expand Down Expand Up @@ -968,3 +972,7 @@ function defaultTranslate(template, replacements) {
return replacements[key] || '{' + key + '}';
});
}

function isFeel(value) {
return isString(value) && value.trim().startsWith('=');
}
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,10 @@ function propertyValidator(translate, property) {
return translate('Must not be empty.');
}

if (property.feel && isFeel(value)) {
return;
}

if (maxLength && value.length > maxLength) {
return translate('Must have max length {maxLength}.', { maxLength });
}
Expand Down Expand Up @@ -989,4 +993,8 @@ function groupByGroupId(properties) {

function findCustomGroup(groups, id) {
return find(groups, g => g.id === id);
}

function isFeel(value) {
return isString(value) && value.trim().startsWith('=');
}
66 changes: 66 additions & 0 deletions test/spec/cloud-element-templates/linting/LinterPlugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,71 @@
}
}
]
},
{
"$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema/resources/schema.json",
"name": "FEEL - Min Length",
"id": "feel.minLength",
"appliesTo": [
"bpmn:Task"
],
"properties": [
{
"label": "Test Property",
"type": "String",
"binding": {
"type": "property",
"name": "name"
},
"constraints": {
"minLength": 5
},
"feel": "optional"
}
]
},
{
"$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema/resources/schema.json",
"name": "FEEL - Max Length",
"id": "feel.maxLength",
"appliesTo": [
"bpmn:Task"
],
"properties": [
{
"label": "Test Property",
"type": "String",
"binding": {
"type": "property",
"name": "name"
},
"constraints": {
"maxLength": 5
},
"feel": "optional"
}
]
},
{
"$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema/resources/schema.json",
"name": "FEEL - Pattern",
"id": "feel.pattern",
"appliesTo": [
"bpmn:Task"
],
"properties": [
{
"label": "Test Property",
"type": "String",
"binding": {
"type": "property",
"name": "name"
},
"constraints": {
"pattern": "OOF"
},
"feel": "optional"
}
]
}
]
21 changes: 21 additions & 0 deletions test/spec/cloud-element-templates/linting/LinterPlugin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,27 @@ const valid = [
config: {
templates
}
},
{
name: 'FEEL (Min Length)',
moddleElement: createModdle(createProcess('<bpmn:task id="Task_1" name="=FOO" zeebe:modelerTemplate="feel.minLength" />')),
config: {
templates
}
},
{
name: 'FEEL (Max Length)',
moddleElement: createModdle(createProcess('<bpmn:task id="Task_1" name="=FOOBAR" zeebe:modelerTemplate="feel.maxLength" />')),
config: {
templates
}
},
{
name: 'FEEL (Pattern)',
moddleElement: createModdle(createProcess('<bpmn:task id="Task_1" name="=FOO" zeebe:modelerTemplate="feel.pattern" />')),
config: {
templates
}
}
];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_165ah7c" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.13.0-nightly.20220113" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="1.3.0">
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_165ah7c" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.23.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="1.3.0">
<bpmn:process id="Process_1" isExecutable="false">
<bpmn:userTask id="stringTask" name="Feel Task" zeebe:modelerTemplate="my.custom.FeelTask.String">
</bpmn:userTask>
<bpmn:userTask id="textTask" name="Text Feel Task" zeebe:modelerTemplate="my.custom.FeelTask.Text">
</bpmn:userTask>
<bpmn:userTask id="stringTask" name="Feel Task" zeebe:modelerTemplate="my.custom.FeelTask.String" />
<bpmn:userTask id="textTask" name="Text Feel Task" zeebe:modelerTemplate="my.custom.FeelTask.Text" />
<bpmn:userTask id="validationTask" name="Validation Feel Task" zeebe:modelerTemplate="my.custom.FeelTask.Validation" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="Task_0zadlfo_di" bpmnElement="stringTask">
<dc:Bounds x="79" y="53" width="100" height="80" />
<dc:Bounds x="159" y="53" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Task_2_di" bpmnElement="textTask">
<dc:Bounds x="250" y="53" width="100" height="80" />
<dc:Bounds x="330" y="53" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1tdcc3k_di" bpmnElement="validationTask">
<dc:Bounds x="500" y="53" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,57 @@
}
],
"entriesVisible": false
},
{
"name": "Custom FeelTask with Validation",
"$schema": "https://unpkg.com/@camunda/zeebe-element-templates-json-schema/resources/schema.json",
"id": "my.custom.FeelTask.Validation",
"appliesTo": [
"bpmn:ServiceTask"
],
"properties": [
{
"label": "A FEEL expression with validation (min length)",
"type": "String",
"feel": "optional",
"editable": true,
"binding": {
"type": "property",
"name": "optionalFeelProp"
},
"constraints": {
"minLength": 5
}
},
{
"label": "A FEEL expression with validation (max length)",
"type": "String",
"feel": "optional",
"editable": true,
"binding": {
"type": "property",
"name": "optionalFeelProp"
},
"constraints": {
"maxLength": 5
}
},
{
"label": "A FEEL expression with validation (pattern)",
"type": "String",
"feel": "optional",
"editable": true,
"binding": {
"type": "property",
"name": "optionalFeelProp"
},
"constraints": {
"pattern": {
"value": "BAR"
}
}
}
],
"entriesVisible": false
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -2116,6 +2116,73 @@ describe('provider/cloud-element-templates - CustomProperties', function() {
expect(optionalIcon).to.exist;
});


describe('validation', function() {

it('should validate minLength', async function() {

// given
await expectSelected('validationTask');

const entry = findEntry('custom-entry-my.custom.FeelTask.Validation-0', container),
input = domQuery('input', entry);

// assume
expectError(entry, 'A FEEL expression with validation (min length) must have min length 5.');

// when
changeInput(input, '=FOO');

// then
expectValid(entry);
});


it('should not validate maxLength', async function() {

// given
await expectSelected('validationTask');

const entry = findEntry('custom-entry-my.custom.FeelTask.Validation-1', container),
input = domQuery('input', entry);

// when
changeInput(input, 'FOOBAR');

// assume
expectError(entry, 'A FEEL expression with validation (max length) must have max length 5.');

// when
changeInput(input, '=FOOBAR');

// then
expectValid(entry);
});


it('should not validate pattern', async function() {

// given
await expectSelected('validationTask');

const entry = findEntry('custom-entry-my.custom.FeelTask.Validation-2', container),
input = domQuery('input', entry);

// when
changeInput(input, 'FOO');

// assume
expectError(entry, 'A FEEL expression with validation (pattern) must match pattern BAR.');

// when
changeInput(input, '=FOO');

// then
expectValid(entry);
});

});

});


Expand Down Expand Up @@ -2230,6 +2297,7 @@ describe('provider/cloud-element-templates - CustomProperties', function() {
expect(input.textContent).to.eql('Placeholder');
});
});

});


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,7 @@ describe('provider/element-templates - CustomProperties', function() {

expect(input).to.have.property('disabled', true);
});

});


Expand Down

0 comments on commit c11a626

Please sign in to comment.