Fix loop step ids on insert (#14515)

Existing loop step ids should now be part of the inserted step next step
ids, but not be part of the initialLoopStepIds
This commit is contained in:
Thomas Trompette
2025-09-15 18:15:09 +02:00
committed by GitHub
parent 755ffe0561
commit 3f112a23a0
2 changed files with 40 additions and 2 deletions
@@ -228,4 +228,35 @@ describe('insertStep', () => {
'existing-loop-step',
]);
});
it('should handle inserting a step between two steps within an iterator', () => {
const existingTrigger = createMockTrigger(['1']);
const insertedStep = createMockAction('2');
const result = insertStep({
existingTrigger,
existingSteps: [mockIteratorStep],
insertedStep,
parentStepId: '1',
nextStepId: 'existing-loop-step',
parentStepConnectionOptions: {
connectedStepType: WorkflowActionType.ITERATOR,
settings: {
isConnectedToLoop: true,
},
},
});
const updatedIteratorStep = result.updatedSteps.find(
(step) => step.id === mockIteratorStep.id,
) as WorkflowIteratorAction;
const updatedInsertedStep = result.updatedSteps.find(
(step) => step.id === insertedStep.id,
) as WorkflowAction;
expect(updatedIteratorStep.settings.input.initialLoopStepIds).toEqual([
insertedStep.id,
]);
expect(updatedInsertedStep.nextStepIds).toEqual(['existing-loop-step']);
});
});
@@ -83,6 +83,7 @@ const updateParentStep = ({
insertedStepId,
parentStepConnectionOptions,
trigger,
nextStepId,
});
} else {
return updateParentStepNextStepIds({
@@ -162,12 +163,14 @@ const updateStepsWithOptions = ({
steps,
parentStepConnectionOptions,
trigger,
nextStepId,
}: {
parentStepId: string;
insertedStepId: string;
steps: WorkflowAction[];
parentStepConnectionOptions: WorkflowStepConnectionOptions;
trigger: WorkflowTrigger | null;
nextStepId?: string;
}) => {
let updatedSteps = steps;
@@ -193,8 +196,12 @@ const updateStepsWithOptions = ({
input: {
...step.settings.input,
initialLoopStepIds: [
...(step.settings.input.initialLoopStepIds || []),
insertedStepId,
...new Set([
...(step.settings.input.initialLoopStepIds?.filter(
(id) => id !== nextStepId,
) || []),
insertedStepId,
]),
],
},
} satisfies WorkflowIteratorActionSettings,