Files
twenty/packages/twenty-front/src/modules/workflow/utils/getStepDefinitionOrThrow.ts
T
Thomas Trompette 9e74ffae52 Refacto workflow folders (#9302)
- Create separated folders for sections
- Add components
- Add utils and clean old ones
- Add constants
- Rename search variables folder and components

Next steps:
- clean hooks
- clean states
2024-12-31 16:08:14 +00:00

46 lines
1.1 KiB
TypeScript

import { WorkflowVersion } from '@/workflow/types/Workflow';
import { findStepPosition } from '@/workflow/utils/findStepPosition';
import { TRIGGER_STEP_ID } from '@/workflow/workflow-trigger/constants/TriggerStepId';
import { isDefined } from 'twenty-ui';
export const getStepDefinitionOrThrow = ({
stepId,
workflowVersion,
}: {
stepId: string;
workflowVersion: WorkflowVersion;
}) => {
if (stepId === TRIGGER_STEP_ID) {
if (!isDefined(workflowVersion.trigger)) {
return {
type: 'trigger',
definition: undefined,
} as const;
}
return {
type: 'trigger',
definition: workflowVersion.trigger,
} as const;
}
if (!isDefined(workflowVersion.steps)) {
throw new Error(
'Malformed workflow version: missing steps information; be sure to create at least one step before trying to edit one',
);
}
const selectedNodePosition = findStepPosition({
steps: workflowVersion.steps,
stepId: stepId,
});
if (!isDefined(selectedNodePosition)) {
return undefined;
}
return {
type: 'action',
definition: selectedNodePosition.steps[selectedNodePosition.index],
} as const;
};