diff --git a/src/cloud-element-templates/UpdateTemplatePropertiesOrder.js b/src/cloud-element-templates/UpdateTemplatePropertiesOrder.js index b3f2efae..61b8bd59 100644 --- a/src/cloud-element-templates/UpdateTemplatePropertiesOrder.js +++ b/src/cloud-element-templates/UpdateTemplatePropertiesOrder.js @@ -68,7 +68,7 @@ export default class UpdateTemplatePropertiesOrder extends CommandInterceptor { const commandsToExecute = commands.filter((command) => command !== null); commandsToExecute.length && this._commandStack.execute( - 'properties-panel.multi-command-executor', + 'element-templates.multi-command-executor', commandsToExecute ); diff --git a/src/cloud-element-templates/cmd/index.js b/src/cloud-element-templates/cmd/index.js index 75efc5dd..e5d62e08 100644 --- a/src/cloud-element-templates/cmd/index.js +++ b/src/cloud-element-templates/cmd/index.js @@ -1,7 +1,14 @@ import ChangeElementTemplateHandler from './ChangeElementTemplateHandler'; import RemoveElementTemplateHandler from '../../element-templates/cmd/RemoveElementTemplateHandler'; +import MultiCommandHandler from '../../element-templates/cmd/MultiCommandHandler'; function registerHandlers(commandStack, elementTemplates, eventBus) { + + commandStack.registerHandler( + 'element-templates.multi-command-executor', + MultiCommandHandler + ); + commandStack.registerHandler( 'propertiesPanel.zeebe.changeTemplate', ChangeElementTemplateHandler diff --git a/src/cloud-element-templates/util/propertyUtil.js b/src/cloud-element-templates/util/propertyUtil.js index 401efdee..55ce20ed 100644 --- a/src/cloud-element-templates/util/propertyUtil.js +++ b/src/cloud-element-templates/util/propertyUtil.js @@ -572,7 +572,7 @@ export function setPropertyValue(bpmnFactory, commandStack, element, property, v const commandsToExecute = commands.filter((command) => command !== NO_OP); commandsToExecute.length && commandStack.execute( - 'properties-panel.multi-command-executor', + 'element-templates.multi-command-executor', commandsToExecute ); @@ -849,7 +849,7 @@ export function unsetProperty(commandStack, element, property) { if (commands.length) { commandStack.execute( - 'properties-panel.multi-command-executor', + 'element-templates.multi-command-executor', commands ); diff --git a/src/element-templates/cmd/MultiCommandHandler.js b/src/element-templates/cmd/MultiCommandHandler.js new file mode 100644 index 00000000..b7940419 --- /dev/null +++ b/src/element-templates/cmd/MultiCommandHandler.js @@ -0,0 +1,28 @@ +import { + forEach +} from 'min-dash'; + +/** + * A handler that combines and executes multiple commands. + * + * All updates are bundled on the command stack and executed in one step. + * This also makes it possible to revert the changes in one step. + * + * Example use case: remove the camunda:formKey attribute and in addition + * add all form fields needed for the camunda:formData property. + */ +export default class MultiCommandHandler { + constructor(commandStack) { + this._commandStack = commandStack; + } + + preExecute(context) { + const commandStack = this._commandStack; + + forEach(context, function(command) { + commandStack.execute(command.cmd, command.context); + }); + } +} + +MultiCommandHandler.$inject = [ 'commandStack' ]; \ No newline at end of file diff --git a/src/element-templates/cmd/index.js b/src/element-templates/cmd/index.js index 871afcf7..a98e68f1 100644 --- a/src/element-templates/cmd/index.js +++ b/src/element-templates/cmd/index.js @@ -1,7 +1,13 @@ import ChangeElementTemplateHandler from './ChangeElementTemplateHandler'; import RemoveElementTemplateHandler from './RemoveElementTemplateHandler'; +import MultiCommandHandler from './MultiCommandHandler'; function registerHandlers(commandStack, elementTemplates, eventBus) { + commandStack.registerHandler( + 'element-templates.multi-command-executor', + MultiCommandHandler + ); + commandStack.registerHandler( 'propertiesPanel.camunda.changeTemplate', ChangeElementTemplateHandler diff --git a/src/element-templates/properties/CustomProperties.js b/src/element-templates/properties/CustomProperties.js index 0e65767e..da669c4c 100644 --- a/src/element-templates/properties/CustomProperties.js +++ b/src/element-templates/properties/CustomProperties.js @@ -886,7 +886,7 @@ function propertySetter(bpmnFactory, commandStack, element, property, scope) { if (commands.length) { commandStack.execute( - 'properties-panel.multi-command-executor', + 'element-templates.multi-command-executor', commands ); diff --git a/src/utils/ExtensionElementsUtil.js b/src/utils/ExtensionElementsUtil.js index ad80c061..d1a9cbd3 100644 --- a/src/utils/ExtensionElementsUtil.js +++ b/src/utils/ExtensionElementsUtil.js @@ -81,7 +81,7 @@ export function addExtensionElements(element, businessObject, extensionElementTo } }); - commandStack.execute('properties-panel.multi-command-executor', commands); + commandStack.execute('element-templates.multi-command-executor', commands); } /**