Skip to content

The open alternative to Salesforce, designed for AI.

715 B
Raw Blame
import { type WorkflowStep } from '@/workflow/types/Workflow';
import { isDefined } from 'twenty-shared/utils';
import { TRIGGER_STEP_ID } from 'twenty-shared/workflow';

export const findStepPosition = ({
  steps,
  stepId,
}: {
  steps: Array<WorkflowStep>;
  stepId: string | undefined;
}): { steps: Array<WorkflowStep>; index: number } | undefined => {
  if (!isDefined(stepId) || stepId === TRIGGER_STEP_ID) {
    return {
      steps,
      index: 0,
    };
  }

  for (const [index, step] of steps.entries()) {
    if (step.id === stepId) {
      return {
        steps,
        index,
      };
    }

    // TODO: When condition will have been implemented, put recursivity here.
  }

  return undefined;
};