Store the current flow definition in a state to not depend on a specific workflow version (#10352)

This PR introduces a new Recoil state to store the flow.

A few parts of the application need to know the definition of the
current flow. Previously, we stored the workflow version's ID and
fetched its definition with the `useWorkflowVersion` hook. However, we
must use another strategy to visualize workflow runs. Indeed, we now
store the definition of the workflow in the workflow run output when it
is executed. This is useful for draft versions, which can change between
the moment they were executed and the moment they are visualized.
This commit is contained in:
Baptiste Devessier
2025-02-20 17:12:03 +01:00
committed by GitHub
parent d96865abc3
commit 05d00e6604
14 changed files with 180 additions and 92 deletions

View File

@ -1,17 +1,19 @@
import { WorkflowVersion } from '@/workflow/types/Workflow';
import { WorkflowAction, WorkflowTrigger } from '@/workflow/types/Workflow';
import { findStepPosition } from '@/workflow/utils/findStepPosition';
import { TRIGGER_STEP_ID } from '@/workflow/workflow-trigger/constants/TriggerStepId';
import { isDefined } from 'twenty-shared';
export const getStepDefinitionOrThrow = ({
stepId,
workflowVersion,
trigger,
steps,
}: {
stepId: string;
workflowVersion: WorkflowVersion;
trigger: WorkflowTrigger | null;
steps: Array<WorkflowAction> | null;
}) => {
if (stepId === TRIGGER_STEP_ID) {
if (!isDefined(workflowVersion.trigger)) {
if (!isDefined(trigger)) {
return {
type: 'trigger',
definition: undefined,
@ -20,18 +22,18 @@ export const getStepDefinitionOrThrow = ({
return {
type: 'trigger',
definition: workflowVersion.trigger,
definition: trigger,
} as const;
}
if (!isDefined(workflowVersion.steps)) {
if (!isDefined(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,
steps,
stepId: stepId,
});
if (!isDefined(selectedNodePosition)) {