Baptiste Devessier
2025-10-01 14:44:11 +02:00
committed by GitHub
parent f302b7c74e
commit a68aa303aa
4 changed files with 66 additions and 40 deletions
@@ -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);
};
@@ -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...
@@ -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,
@@ -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,