martmull
2025-08-05 11:25:20 +02:00
committed by GitHub
parent 6af99ab1ea
commit 497fc2c0b2
5 changed files with 59 additions and 16 deletions
@@ -91,6 +91,7 @@ export const WorkflowDiagramDefaultEdgeEditable = ({
startNodeCreation({
parentStepId: source,
nextStepId: target,
position: { x: labelX, y: labelY },
});
};
@@ -148,6 +148,17 @@ export const WorkflowDiagramFilterEdgeEditable = ({
});
};
const handleAddNodeButtonClick = () => {
closeDropdown(dropdownId);
setHovered(false);
startNodeCreation({
parentStepId: data.stepId,
nextStepId: target,
position: { x: labelX, y: labelY },
});
};
return (
<>
<BaseEdge
@@ -250,15 +261,7 @@ export const WorkflowDiagramFilterEdgeEditable = ({
<MenuItem
text="Add Node"
LeftIcon={IconPlus}
onClick={() => {
closeDropdown(dropdownId);
setHovered(false);
startNodeCreation({
parentStepId: data.stepId,
nextStepId: target,
});
}}
onClick={handleAddNodeButtonClick}
/>
</DropdownMenuItemsContainer>
</DropdownContent>
@@ -58,6 +58,14 @@ export const WorkflowDiagramFilteringDisabledEdgeEditable = ({
nextStepId: target,
});
const handleAddNodeButtonClick = () => {
startNodeCreation({
parentStepId: source,
nextStepId: target,
position: { x: labelX, y: labelY },
});
};
return (
<>
<BaseEdge
@@ -83,12 +91,7 @@ export const WorkflowDiagramFilteringDisabledEdgeEditable = ({
iconButtons={[
{
Icon: IconPlus,
onClick: () => {
startNodeCreation({
parentStepId: source,
nextStepId: target,
});
},
onClick: handleAddNodeButtonClick,
},
]}
/>
@@ -12,6 +12,7 @@ import { useWorkflowWithCurrentVersion } from '@/workflow/hooks/useWorkflowWithC
import { useStartNodeCreation } from '@/workflow/workflow-diagram/hooks/useStartNodeCreation';
import { useCloseRightClickMenu } from '@/workflow/workflow-diagram/hooks/useCloseRightClickMenu';
import { useTidyUpWorkflowVersion } from '@/workflow/workflow-version/hooks/useTidyUpWorkflowVersion';
import { useWorkflowDiagramScreenToFlowPosition } from '@/workflow/workflow-diagram/hooks/useWorkflowDiagramScreenToFlowPosition';
const StyledContainer = styled.div<{ x: number; y: number }>`
background: ${({ theme }) => theme.background.primary};
@@ -31,6 +32,9 @@ export const WorkflowDiagramRightClickCommandMenu = () => {
const { t } = useLingui();
const rightClickCommandMenuRef = useRef<HTMLDivElement>(null);
const { workflowDiagramScreenToFlowPosition } =
useWorkflowDiagramScreenToFlowPosition();
const { startNodeCreation } = useStartNodeCreation();
const { closeRightClickMenu } = useCloseRightClickMenu();
@@ -57,10 +61,13 @@ export const WorkflowDiagramRightClickCommandMenu = () => {
};
const addNode = () => {
const position = workflowDiagramScreenToFlowPosition(
workflowDiagramRightClickMenuPosition,
);
startNodeCreation({
parentStepId: undefined,
nextStepId: undefined,
position: workflowDiagramRightClickMenuPosition,
position,
});
};
@@ -0,0 +1,29 @@
import { useReactFlow } from '@xyflow/react';
import { isDefined } from 'twenty-shared/utils';
import { THEME_COMMON } from 'twenty-ui/theme';
export const useWorkflowDiagramScreenToFlowPosition = () => {
const { screenToFlowPosition } = useReactFlow();
const workflowDiagramScreenToFlowPosition = (position?: {
x: number;
y: number;
}) => {
if (!isDefined(position)) {
return;
}
const visibleRightDrawerWidth = Number(
THEME_COMMON.rightDrawerWidth.replace('px', ''),
);
const flowPosition = screenToFlowPosition(position);
return {
x: flowPosition.x + visibleRightDrawerWidth / 2,
y: flowPosition.y,
};
};
return { workflowDiagramScreenToFlowPosition };
};