Fix if-else node drag-to-create (#16944)

Co-authored-by: Félix Malfait <felix.malfait@gmail.com>
This commit is contained in:
Abdul Rahman
2026-01-06 17:58:29 +05:30
committed by GitHub
parent 3539f5cb7a
commit e51cf607c9
4 changed files with 141 additions and 7 deletions
@@ -3,11 +3,17 @@ import { CommandMenuWorkflowSelectAction } from '@/command-menu/pages/workflow/a
import { commandMenuNavigationStackState } from '@/command-menu/states/commandMenuNavigationStackState';
import { useRecoilComponentState } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentState';
import { useRecoilComponentValue } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValue';
import { useWorkflowWithCurrentVersion } from '@/workflow/hooks/useWorkflowWithCurrentVersion';
import { workflowVisualizerWorkflowIdComponentState } from '@/workflow/states/workflowVisualizerWorkflowIdComponentState';
import { type WorkflowActionType } from '@/workflow/types/Workflow';
import {
type WorkflowActionType,
type WorkflowIfElseAction,
} from '@/workflow/types/Workflow';
import { useCloseRightClickMenu } from '@/workflow/workflow-diagram/hooks/useCloseRightClickMenu';
import { useCreateStep } from '@/workflow/workflow-steps/hooks/useCreateStep';
import { useUpdateStep } from '@/workflow/workflow-steps/hooks/useUpdateStep';
import { workflowInsertStepIdsComponentState } from '@/workflow/workflow-steps/states/workflowInsertStepIdsComponentState';
import { prepareIfElseStepWithNewBranch } from '@/workflow/workflow-steps/workflow-actions/if-else-action/utils/prepareIfElseStepWithNewBranch';
import { getActionIcon } from '@/workflow/workflow-steps/workflow-actions/utils/getActionIcon';
import { useSetRecoilState } from 'recoil';
import { isDefined } from 'twenty-shared/utils';
@@ -20,6 +26,10 @@ export const CommandMenuWorkflowCreateStepContent = () => {
);
const { createStep } = useCreateStep();
const { updateStep } = useUpdateStep();
const workflowWithCurrentVersion = useWorkflowWithCurrentVersion(
workflowVisualizerWorkflowId,
);
const { openWorkflowEditStepInCommandMenu } = useWorkflowCommandMenu();
const { closeRightClickMenu } = useCloseRightClickMenu();
@@ -30,6 +40,21 @@ export const CommandMenuWorkflowCreateStepContent = () => {
const [workflowInsertStepIds, setWorkflowInsertStepIds] =
useRecoilComponentState(workflowInsertStepIdsComponentState);
const handleIfElseParentStep = async ({
parentStep,
createdStepId,
}: {
parentStep: WorkflowIfElseAction;
createdStepId: string;
}) => {
const updatedStep = prepareIfElseStepWithNewBranch({
parentStep,
targetStepId: createdStepId,
});
await updateStep(updatedStep);
};
const handleCreateStep = async (actionType: WorkflowActionType) => {
if (!isDefined(workflowVisualizerWorkflowId)) {
throw new Error(
@@ -52,6 +77,19 @@ export const CommandMenuWorkflowCreateStepContent = () => {
return;
}
const steps = workflowWithCurrentVersion?.currentVersion?.steps;
const parentStep =
isDefined(parentStepId) && isDefined(steps) && isDefined(position)
? steps.find((step) => step.id === parentStepId)
: undefined;
if (parentStep?.type === 'IF_ELSE') {
await handleIfElseParentStep({
parentStep,
createdStepId: createdStep.id,
});
}
setWorkflowInsertStepIds({
parentStepId: undefined,
nextStepId: undefined,