35361093bf
- Allows the deletion of triggers and steps in workflows. If the workflow can not be edited right now, we create a new draft version. - The workflow right drawer can now render nothing. It's necessary to behave that way because a deleted step will still be displayed for a short amount of time in the drawer. The drawer will be filled with blank content when it disappears. https://github.com/user-attachments/assets/abd5184e-d3db-4fe7-8870-ccc78ff23d41 Closes #7057
42 lines
1001 B
TypeScript
42 lines
1001 B
TypeScript
import { TRIGGER_STEP_ID } from '@/workflow/constants/TriggerStepId';
|
|
import { WorkflowStep } from '@/workflow/types/Workflow';
|
|
import { isDefined } from 'twenty-ui';
|
|
|
|
/**
|
|
* This function returns the reference of the array where the step should be positioned
|
|
* and at which index.
|
|
*/
|
|
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.
|
|
// if (step.type === "CONDITION") {
|
|
// return findNodePosition({
|
|
// workflowSteps: step.conditions,
|
|
// stepId,
|
|
// })
|
|
// }
|
|
}
|
|
|
|
return undefined;
|
|
};
|