Skip to content

Commit

Permalink
feat(camunda-platform): clean up camunda:formData#values on type change
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme committed Sep 15, 2021
1 parent 9d6dd49 commit b2d2665
Show file tree
Hide file tree
Showing 4 changed files with 208 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';

import { is } from 'bpmn-js/lib/util/ModelUtil';


/**
* Camunda BPMN specific user task generated forms behavior removing camunda:FormField#values if camunda:FormField#type
* is changed to something other than enum.
*/
export default class UserTaskFormsBehavior extends CommandInterceptor {
constructor(eventBus) {
super(eventBus);

this.preExecute([
'element.updateModdleProperties',
'properties-panel.update-businessobject'
], function(context) {
let {
businessObject,
moddleElement,
properties
} = context;

businessObject = businessObject || moddleElement;

if (is(businessObject, 'camunda:FormField')
&& 'camunda:type' in properties
&& properties[ 'camunda:type' ] !== 'enum') {
properties[ 'camunda:values' ] = undefined;
}
}, true);
}
}


UserTaskFormsBehavior.$inject = [ 'eventBus' ];
7 changes: 5 additions & 2 deletions lib/camunda-platform/features/modeling/behavior/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import UpdateCamundaExclusiveBehavior from './UpdateCamundaExclusiveBehavior';
import UpdateInputOutputBehavior from './UpdateInputOutputBehavior';
import UpdateResultVariableBehavior from './UpdateResultVariableBehavior';
import UserTaskFormsBehavior from './UserTaskFormsBehavior';
import UserTaskGeneratedFormsBehavior from './UserTaskGeneratedFormsBehavior';

export default {
__init__: [
Expand All @@ -12,12 +13,14 @@ export default {
'updateCamundaExclusiveBehavior',
'updateResultVariableBehavior',
'updateInputOutputBehavior',
'userTaskFormsBehavior'
'userTaskFormsBehavior',
'userTaskGeneratedFormsBehavior'
],
deleteErrorEventDefinitionBehavior: [ 'type', DeleteErrorEventDefinitionBehavior ],
deleteRetryTimeCycleBehavior: [ 'type', DeleteRetryTimeCycleBehavior ],
updateCamundaExclusiveBehavior: [ 'type', UpdateCamundaExclusiveBehavior ],
updateResultVariableBehavior: [ 'type', UpdateResultVariableBehavior ],
updateInputOutputBehavior: [ 'type', UpdateInputOutputBehavior ],
userTaskFormsBehavior: [ 'type', UserTaskFormsBehavior ]
userTaskFormsBehavior: [ 'type', UserTaskFormsBehavior ],
userTaskGeneratedFormsBehavior: [ 'type', UserTaskGeneratedFormsBehavior ]
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import {
bootstrapCamundaPlatformModeler,
inject
} from 'test/TestHelper';

import {
getBpmnJS
} from 'bpmn-js/test/helper';

import coreModule from 'bpmn-js/lib/core';

import modelingModule from 'bpmn-js/lib/features/modeling';

import {
getBusinessObject,
is
} from 'bpmn-js/lib/util/ModelUtil';

import camundaModdleExtensions from 'camunda-bpmn-moddle/resources/camunda';

import camundaPlatformModelingModules from 'lib/camunda-platform/features/modeling';

import propertiesPanelCommandHandler from 'bpmn-js-properties-panel/lib/cmd';

import diagramXML from './camunda-user-task-generated-forms-diagram.bpmn';


describe('camunda-platform/features/modeling - UserTaskGeneratedFormsBehavior', function() {

const testModules = [
camundaPlatformModelingModules,
coreModule,
modelingModule,
propertiesPanelCommandHandler
];

const moddleExtensions = {
camunda: camundaModdleExtensions
};

beforeEach(bootstrapCamundaPlatformModeler(diagramXML, {
modules: testModules,
moddleExtensions
}));

function updateModdleProperties(element, moddleElement, properties) {
getBpmnJS().invoke(function(modeling) {
modeling.updateModdleProperties(element, moddleElement, properties);
});
}

function updateBusinessObject(element, businessObject, properties) {
getBpmnJS().invoke(function(commandStack) {
commandStack.execute('properties-panel.update-businessobject', {
element,
businessObject,
properties
});
});
}

[
[ 'element.updateModdleProperties', updateModdleProperties ],
[ 'properties-panel.update-businessobject', updateBusinessObject ]
].forEach(([ command, fn ]) => {

describe(command, function() {

[
[ 'start event', 'StartEvent' ],
[ 'user task', 'UserTask' ]
].forEach(([ type, prefix ]) => {

describe('setting camunda:FormField#type to boolean', function() {

describe(type, function() {

it('should delete camunda:FormField#values', inject(function(elementRegistry) {

// when
const element = elementRegistry.get(`${ prefix }_1`);

const businessObject = getFormField(element);

// when
fn(element, businessObject, { 'camunda:type': 'boolean' });

// then
expect(businessObject.get('camunda:values')).to.be.empty;
}));


it('should not delete camunda:FormField#values', inject(function(elementRegistry) {

// when
const element = elementRegistry.get(`${ prefix }_1`);

const businessObject = getFormField(element);

// when
fn(element, businessObject, { 'camunda:type': 'enum' });

// then
expect(businessObject.get('camunda:values')).not.to.be.empty;
}));

});

});

});

});

});

});

// helpers //////////

function getFormField(element, index = 0) {
const businessObject = getBusinessObject(element);

const extensionElements = businessObject.get('extensionElements'),
values = extensionElements.get('values');

const formData = values.find((value) => {
return is(value, 'camunda:FormData');
});

return formData.get('camunda:fields')[ index ];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?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:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0fjxb6c" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.9.0" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.15.0">
<bpmn:process id="Process_1" isExecutable="true">
<bpmn:startEvent id="StartEvent_1" camunda:formKey="embedded:deployment:FORM_NAME.html">
<bpmn:extensionElements>
<camunda:formData>
<camunda:formField id="FormField_1" type="enum">
<camunda:value id="Value_1" />
<camunda:value id="Value_2" />
</camunda:formField>
</camunda:formData>
</bpmn:extensionElements>
</bpmn:startEvent>
<bpmn:userTask id="UserTask_1" camunda:formKey="embedded:deployment:FORM_NAME.html">
<bpmn:extensionElements>
<camunda:formData>
<camunda:formField id="FormField_2" type="enum">
<camunda:value id="Value_3" />
<camunda:value id="Value_4" />
</camunda:formField>
</camunda:formData>
</bpmn:extensionElements>
</bpmn:userTask>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="Event_0b9cna2_di" bpmnElement="StartEvent_1">
<dc:Bounds x="152" y="102" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0pn8rby_di" bpmnElement="UserTask_1">
<dc:Bounds x="260" y="80" width="100" height="80" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

0 comments on commit b2d2665

Please sign in to comment.