diff --git a/lib/camunda-cloud/features/replace/ElementTemplatesReplaceProvider.js b/lib/camunda-cloud/features/replace/ElementTemplatesReplaceProvider.js index ceaca0a7..9cf1ddab 100644 --- a/lib/camunda-cloud/features/replace/ElementTemplatesReplaceProvider.js +++ b/lib/camunda-cloud/features/replace/ElementTemplatesReplaceProvider.js @@ -8,7 +8,7 @@ import { } from 'bpmn-js/lib/util/ModelUtil'; import { - getReplaceOptions + getReplaceOptionGroups } from './ReplaceOptionsUtil'; /** @@ -94,18 +94,16 @@ ElementTemplatesReplaceProvider.prototype._addPlainElementEntry = function(eleme */ ElementTemplatesReplaceProvider.prototype._getPlainEntry = function(element, entries) { - const options = getReplaceOptions(); + const { + options, + option, + optionIndex + } = findReplaceOptions(element) || { }; - const isSameType = (element, option) => option.target && !isDifferentType(element)(option); - - const optionIndex = options.findIndex(option => isSameType(element, option)); - - if (optionIndex === -1) { + if (!options) { return; } - const option = options[optionIndex]; - const entry = { id: option.actionName, action: () => { @@ -214,4 +212,33 @@ function getOptionIndex(options, index, entries) { return entries.findIndex( ([ key ]) => key === option.actionName ); +} + +/** + * @param {ModdleElement} element + * + * @return { { options: Array, option: any, optionIndex: number } | null } + */ +function findReplaceOptions(element) { + + const isSameType = (element, option) => option.target && !isDifferentType(element)(option); + + return getReplaceOptionGroups().reduce((result, options) => { + + if (result) { + return result; + } + + const optionIndex = options.findIndex(option => isSameType(element, option)); + + if (optionIndex === -1) { + return; + } + + return { + options, + option: options[optionIndex], + optionIndex + }; + }, null); } \ No newline at end of file diff --git a/lib/camunda-cloud/features/replace/ReplaceOptionsUtil.js b/lib/camunda-cloud/features/replace/ReplaceOptionsUtil.js index 9c9e2674..7b5942cc 100644 --- a/lib/camunda-cloud/features/replace/ReplaceOptionsUtil.js +++ b/lib/camunda-cloud/features/replace/ReplaceOptionsUtil.js @@ -1,7 +1,7 @@ import * as replaceOptions from 'bpmn-js/lib/features/replace/ReplaceOptions'; -const ALL_OPTIONS = Object.values(replaceOptions).flat(); +const ALL_OPTIONS = Object.values(replaceOptions); -export function getReplaceOptions() { +export function getReplaceOptionGroups() { return ALL_OPTIONS; } \ No newline at end of file diff --git a/test/camunda-cloud/ElementTemplatesReplaceProviderSpec.js b/test/camunda-cloud/ElementTemplatesReplaceProviderSpec.js index fd37d830..bc168a4f 100644 --- a/test/camunda-cloud/ElementTemplatesReplaceProviderSpec.js +++ b/test/camunda-cloud/ElementTemplatesReplaceProviderSpec.js @@ -91,7 +91,7 @@ describe('', function() { })); - it.skip('template task -> task', inject(function(elementRegistry, elementTemplates) { + it('template task -> task', inject(function(elementRegistry, elementTemplates) { // given const task = elementRegistry.get('Task_1');