Stop propagating full workflow in components (#13900)

Workflow, workflow version and workflow runs should not be passed
through props or context. These are set in recoil component states and
that's where all hooks should look for these.

This PR stop propagating workflow with version through all components.
This commit is contained in:
Thomas Trompette
2025-08-13 18:02:13 +02:00
committed by GitHub
parent 5eba2a8011
commit 88735f6788
33 changed files with 299 additions and 389 deletions
@@ -0,0 +1,37 @@
import { useRecoilComponentValue } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValue';
import { useCreateDraftFromWorkflowVersion } from '@/workflow/hooks/useCreateDraftFromWorkflowVersion';
import { useWorkflowWithCurrentVersion } from '@/workflow/hooks/useWorkflowWithCurrentVersion';
import { workflowVisualizerWorkflowIdComponentState } from '@/workflow/states/workflowVisualizerWorkflowIdComponentState';
import { isDefined } from 'twenty-shared/utils';
export const useGetUpdatableWorkflowVersionOrThrow = () => {
const { createDraftFromWorkflowVersion } =
useCreateDraftFromWorkflowVersion();
const workflowVisualizerWorkflowId = useRecoilComponentValue(
workflowVisualizerWorkflowIdComponentState,
);
const workflow = useWorkflowWithCurrentVersion(workflowVisualizerWorkflowId);
const getUpdatableWorkflowVersion = async (): Promise<string> => {
if (!isDefined(workflowVisualizerWorkflowId) || !isDefined(workflow)) {
throw new Error('Failed to get updatable workflow version');
}
if (workflow.currentVersion.status === 'DRAFT') {
return workflow.currentVersion.id;
}
const draftVersionId = await createDraftFromWorkflowVersion({
workflowId: workflowVisualizerWorkflowId,
workflowVersionIdToCopy: workflow.currentVersion.id,
});
if (!isDefined(draftVersionId)) {
throw new Error('Failed to create draft version');
}
return draftVersionId;
};
return { getUpdatableWorkflowVersion };
};