Skip to content

Commit

Permalink
feat(element-templates): remove old template properties
Browse files Browse the repository at this point in the history
  • Loading branch information
smbea committed Jul 3, 2023
1 parent 696b7cd commit a2c1b20
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/element-templates/cmd/ChangeElementTemplateHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,13 @@ export default class ChangeElementTemplateHandler {
return newBindingType === 'property';
});

const oldProperties = oldTemplate && oldTemplate.properties.filter((oldProperty) => {
const oldBinding = oldProperty.binding,
oldBindingType = oldBinding.type;

return oldBindingType === 'property';
});

if (!newProperties.length) {
return;
}
Expand All @@ -799,6 +806,10 @@ export default class ChangeElementTemplateHandler {
let changedElement,
properties;

if (oldProperty) {
remove(oldProperties, oldProperty);
}

if (newBindingName === 'conditionExpression') {
this._updateConditionExpression(element, oldProperty, newProperty);
} else {
Expand Down Expand Up @@ -835,6 +846,17 @@ export default class ChangeElementTemplateHandler {
});
}
});

// remove old properties not present in new template
oldProperties && oldProperties.forEach((oldProperty) => {
commandStack.execute('element.updateModdleProperties', {
element,
moddleElement: businessObject,
properties: {
[oldProperty.binding.name]: null
}
});
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1933,6 +1933,48 @@ describe('element-templates/cmd - ChangeElementTemplateHandler', function() {

});


describe('complex', function() {

beforeEach(bootstrap(require('./service-task.bpmn').default));

it('remove old properties', inject(function(elementRegistry) {

// given
var serviceTask = elementRegistry.get('ServiceTask_1'),
businessObject = getBusinessObject(serviceTask);

var oldTemplate = createTemplate({
value: '${foo}',
binding: {
type: 'property',
name: 'camunda:expression'
}
});

var newTemplate = createTemplate({
value: '${bar}',
binding: {
type: 'property',
name: 'camunda:type'
}
});

changeTemplate('ServiceTask_1', oldTemplate);


// when
changeTemplate(serviceTask, newTemplate, oldTemplate);

// then
var expression = businessObject.get('camunda:expression');
expect(expression).to.not.exist;

var type = businessObject.get('camunda:type');
expect(type).to.equal('${bar}');
}));
});

});


Expand Down

0 comments on commit a2c1b20

Please sign in to comment.