Skip to content

Commit

Permalink
chore: internalize multi-command executor
Browse files Browse the repository at this point in the history
Reduces unnecessary ties to properties panel.
  • Loading branch information
nikku authored and barmac committed Jan 23, 2024
1 parent f5dcbea commit 940e085
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand Down
7 changes: 7 additions & 0 deletions src/cloud-element-templates/cmd/index.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/cloud-element-templates/util/propertyUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand Down Expand Up @@ -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
);

Expand Down
28 changes: 28 additions & 0 deletions src/element-templates/cmd/MultiCommandHandler.js
Original file line number Diff line number Diff line change
@@ -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' ];
6 changes: 6 additions & 0 deletions src/element-templates/cmd/index.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/element-templates/properties/CustomProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand Down
2 changes: 1 addition & 1 deletion src/utils/ExtensionElementsUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 940e085

Please sign in to comment.