Skip to content

Commit b65adcc

Browse files
committed
3140 - bug fix: paste multiple nested task dispatchers
1 parent d57cd16 commit b65adcc

2 files changed

Lines changed: 21 additions & 7 deletions

File tree

client/src/pages/platform/workflow-editor/utils/getFormattedName.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {isPlainObject} from '../../cluster-element-editor/utils/clusterElementsU
55
import useWorkflowDataStore from '../stores/useWorkflowDataStore';
66
import getAllTasksRecursively from './getAllTasksRecursively';
77

8-
export default function getFormattedName(itemName: string): string {
8+
export default function getFormattedName(itemName: string, reservedNames?: Set<string>): string {
99
const {nodes, workflow} = useWorkflowDataStore.getState();
1010

1111
const nodeNames = nodes.map((node) => (node.data as NodeDataType).name);
@@ -66,7 +66,9 @@ export default function getFormattedName(itemName: string): string {
6666
return names?.includes(itemName) ? [names] : [];
6767
});
6868

69-
const allExistingNodes = [...existingNodes, ...existingClusterElementNodes];
69+
const reservedMatchingNames = reservedNames ? [...reservedNames].filter((name) => name?.includes(itemName)) : [];
70+
71+
const allExistingNodes = [...existingNodes, ...existingClusterElementNodes, ...reservedMatchingNames];
7072

7173
if (!allExistingNodes.length) {
7274
return `${itemName}_1`;

client/src/pages/platform/workflow-editor/utils/pasteNode.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,26 @@ const TASK_DISPATCHER_NAMES = new Set([
2727

2828
const isTaskDispatcher = (componentName: string): boolean => TASK_DISPATCHER_NAMES.has(componentName);
2929

30-
function renameNestedTasks(parameters: TaskParametersType, componentName: string): TaskParametersType {
30+
function renameNestedTasks(
31+
parameters: TaskParametersType,
32+
componentName: string,
33+
reservedNames: Set<string>
34+
): TaskParametersType {
3135
const renameTask = (task: WorkflowTask) => {
3236
const subtaskComponentName = task.type?.split('/')?.[0];
3337

3438
if (!subtaskComponentName) {
3539
return;
3640
}
3741

38-
task.name = getFormattedName(subtaskComponentName);
42+
const newName = getFormattedName(subtaskComponentName, reservedNames);
43+
44+
reservedNames.add(newName);
45+
46+
task.name = newName;
3947

4048
if (isTaskDispatcher(subtaskComponentName) && task.parameters) {
41-
task.parameters = renameNestedTasks(task.parameters, subtaskComponentName);
49+
task.parameters = renameNestedTasks(task.parameters, subtaskComponentName, reservedNames);
4250
}
4351
};
4452

@@ -197,12 +205,16 @@ export default function pasteNode({
197205
}
198206
}
199207

200-
const newName = getFormattedName(copiedNode.componentName);
208+
const reservedNames = new Set<string>();
209+
210+
const newName = getFormattedName(copiedNode.componentName, reservedNames);
211+
212+
reservedNames.add(newName);
201213

202214
const clonedParameters = structuredClone(copiedNode.parameters ?? {});
203215

204216
if (isTaskDispatcher(copiedNode.componentName)) {
205-
renameNestedTasks(clonedParameters, copiedNode.componentName);
217+
renameNestedTasks(clonedParameters, copiedNode.componentName, reservedNames);
206218
}
207219

208220
const newNodeData = {

0 commit comments

Comments
 (0)