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:
+37
@@ -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 };
|
||||
};
|
||||
Reference in New Issue
Block a user