From a68aa303aa1ecf1b8fd930744e569fd17d3c5162 Mon Sep 17 00:00:00 2001 From: Baptiste Devessier Date: Wed, 1 Oct 2025 14:44:11 +0200 Subject: [PATCH] Hide iteration switcher for steps following iterators (#14810) ## Before https://github.com/user-attachments/assets/a8eca1aa-b2b6-4fdb-8848-65c8235a330c ## After https://github.com/user-attachments/assets/84b7e969-423b-4f0e-8f53-524bfb11e2ca --- .../workflow-diagram/utils/isParentStep.ts | 33 ------------------- .../getIsDescendantOfIterator.test.ts | 7 ++-- .../utils/getIsDescendantOfIterator.ts | 33 ++++++++++++++++++- .../utils/getWorkflowPreviousSteps.ts | 33 ++++++++++++++++++- 4 files changed, 66 insertions(+), 40 deletions(-) delete mode 100644 packages/twenty-front/src/modules/workflow/workflow-diagram/utils/isParentStep.ts diff --git a/packages/twenty-front/src/modules/workflow/workflow-diagram/utils/isParentStep.ts b/packages/twenty-front/src/modules/workflow/workflow-diagram/utils/isParentStep.ts deleted file mode 100644 index 6f6b2b54c6..0000000000 --- a/packages/twenty-front/src/modules/workflow/workflow-diagram/utils/isParentStep.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { type WorkflowStep } from '@/workflow/types/Workflow'; -import { isLastStepOfLoop } from '@/workflow/workflow-diagram/utils/isLastStepOfLoop'; - -export const isParentStep = ({ - currentStep, - potentialParentStep, - steps, -}: { - currentStep: WorkflowStep; - potentialParentStep: WorkflowStep; - steps: WorkflowStep[]; -}): boolean => { - if (potentialParentStep.type === 'ITERATOR') { - return !!( - potentialParentStep.settings.input.initialLoopStepIds?.includes( - currentStep.id, - ) || potentialParentStep.nextStepIds?.includes(currentStep.id) - ); - } - - if (currentStep.type === 'ITERATOR') { - return !!( - potentialParentStep.nextStepIds?.includes(currentStep.id) && - !isLastStepOfLoop({ - iterator: currentStep, - stepId: potentialParentStep.id, - steps, - }) - ); - } - - return !!potentialParentStep.nextStepIds?.includes(currentStep.id); -}; diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/utils/__tests__/getIsDescendantOfIterator.test.ts b/packages/twenty-front/src/modules/workflow/workflow-steps/utils/__tests__/getIsDescendantOfIterator.test.ts index 630cc94dfc..a8f86db740 100644 --- a/packages/twenty-front/src/modules/workflow/workflow-steps/utils/__tests__/getIsDescendantOfIterator.test.ts +++ b/packages/twenty-front/src/modules/workflow/workflow-steps/utils/__tests__/getIsDescendantOfIterator.test.ts @@ -68,11 +68,10 @@ describe('getIsDescendantOfIterator', () => { ).toBe(true); }); - it('returns true for indirect descendant', () => { - // step3 is pointed to by iterator1.nextStepIds + it('returns false for indirect descendant', () => { expect( getIsDescendantOfIterator({ stepId: codeStep3.id, steps: workflow }), - ).toBe(true); + ).toBe(false); }); it('returns false for iterator itself', () => { @@ -109,5 +108,3 @@ describe('getIsDescendantOfIterator', () => { ).toBe(false); }); }); - -// ...existing test code... diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/utils/getIsDescendantOfIterator.ts b/packages/twenty-front/src/modules/workflow/workflow-steps/utils/getIsDescendantOfIterator.ts index 580b7efc25..c668e4760c 100644 --- a/packages/twenty-front/src/modules/workflow/workflow-steps/utils/getIsDescendantOfIterator.ts +++ b/packages/twenty-front/src/modules/workflow/workflow-steps/utils/getIsDescendantOfIterator.ts @@ -1,7 +1,38 @@ import { type WorkflowStep } from '@/workflow/types/Workflow'; -import { isParentStep } from '@/workflow/workflow-diagram/utils/isParentStep'; +import { isLastStepOfLoop } from '@/workflow/workflow-diagram/utils/isLastStepOfLoop'; import { TRIGGER_STEP_ID } from 'twenty-shared/workflow'; +const isParentStep = ({ + currentStep, + potentialParentStep, + steps, +}: { + currentStep: WorkflowStep; + potentialParentStep: WorkflowStep; + steps: WorkflowStep[]; +}): boolean => { + if (potentialParentStep.type === 'ITERATOR') { + return ( + potentialParentStep.settings.input.initialLoopStepIds?.includes( + currentStep.id, + ) === true + ); + } + + if (currentStep.type === 'ITERATOR') { + return ( + potentialParentStep.nextStepIds?.includes(currentStep.id) === true && + !isLastStepOfLoop({ + iterator: currentStep, + stepId: potentialParentStep.id, + steps, + }) + ); + } + + return potentialParentStep.nextStepIds?.includes(currentStep.id) === true; +}; + export const getIsDescendantOfIterator = ({ stepId, steps, diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/utils/getWorkflowPreviousSteps.ts b/packages/twenty-front/src/modules/workflow/workflow-steps/utils/getWorkflowPreviousSteps.ts index 574ec3091d..bd5f88b21a 100644 --- a/packages/twenty-front/src/modules/workflow/workflow-steps/utils/getWorkflowPreviousSteps.ts +++ b/packages/twenty-front/src/modules/workflow/workflow-steps/utils/getWorkflowPreviousSteps.ts @@ -1,5 +1,36 @@ import { type WorkflowStep } from '@/workflow/types/Workflow'; -import { isParentStep } from '@/workflow/workflow-diagram/utils/isParentStep'; +import { isLastStepOfLoop } from '@/workflow/workflow-diagram/utils/isLastStepOfLoop'; + +const isParentStep = ({ + currentStep, + potentialParentStep, + steps, +}: { + currentStep: WorkflowStep; + potentialParentStep: WorkflowStep; + steps: WorkflowStep[]; +}): boolean => { + if (potentialParentStep.type === 'ITERATOR') { + return !!( + potentialParentStep.settings.input.initialLoopStepIds?.includes( + currentStep.id, + ) || potentialParentStep.nextStepIds?.includes(currentStep.id) + ); + } + + if (currentStep.type === 'ITERATOR') { + return !!( + potentialParentStep.nextStepIds?.includes(currentStep.id) && + !isLastStepOfLoop({ + iterator: currentStep, + stepId: potentialParentStep.id, + steps, + }) + ); + } + + return !!potentialParentStep.nextStepIds?.includes(currentStep.id); +}; export const getPreviousSteps = ({ steps,