Skip to content

Commit

Permalink
fix(cloud-templates): search replace option in local group
Browse files Browse the repository at this point in the history
  • Loading branch information
nikku committed Dec 2, 2022
1 parent dcaf8ca commit 96abacd
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from 'bpmn-js/lib/util/ModelUtil';

import {
getReplaceOptions
getReplaceOptionGroups
} from './ReplaceOptionsUtil';

/**
Expand Down Expand Up @@ -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: () => {
Expand Down Expand Up @@ -214,4 +212,33 @@ function getOptionIndex(options, index, entries) {
return entries.findIndex(
([ key ]) => key === option.actionName
);
}

/**
* @param {ModdleElement} element
*
* @return { { options: Array<any>, 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);
}
4 changes: 2 additions & 2 deletions lib/camunda-cloud/features/replace/ReplaceOptionsUtil.js
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 1 addition & 1 deletion test/camunda-cloud/ElementTemplatesReplaceProviderSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('<ElementTemplatesReplaceProvider>', 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');
Expand Down

0 comments on commit 96abacd

Please sign in to comment.