-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve the layout of the Workflow Visualizer #8372
Conversation
… zoom transform which made pixels computations hard
06a5fb6
to
f9ff8d1
Compare
I will fix the dark mode in another PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
This PR improves the Workflow Visualizer's layout and interaction design with significant changes to node dimensions and viewport handling.
- Removed node scaling (from 1.3x to 1.0x) and increased base dimensions for better width calculations in
/packages/twenty-front/src/modules/workflow/components/WorkflowDiagramCanvasBase.tsx
- Moved node type labels inside nodes and improved visual hierarchy in
/packages/twenty-front/src/modules/workflow/components/WorkflowDiagramBaseStepNode.tsx
- Added viewport centering logic when flow mounts and right drawer state changes
- Increased icon sizes from 'sm' to 'lg' across all node types for better visibility
- Added
deletable: false
to workflow edges to prevent accidental connection removal
Note: There's a known issue with right drawer flickering that needs refactoring (Issue #8387).
9 file(s) reviewed, 4 comment(s)
Edit PR Review Bot Settings | Greptile
const viewportX = | ||
(containerRef.current.offsetWidth + visibleRightDrawerWidth) / 2 - | ||
flowBounds.width / 2; | ||
|
||
reactflow.setViewport( | ||
{ | ||
...currentViewport, | ||
x: viewportX - visibleRightDrawerWidth, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: viewport calculation may cause layout shift when drawer width changes - consider caching previous drawer state to prevent unnecessary recalculations
useEffect(() => { | ||
if (!isDefined(containerRef.current) || !reactflow.viewportInitialized) { | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: missing cleanup function in useEffect - could cause memory leaks if component unmounts during animation
onInit={() => { | ||
if (!isDefined(containerRef.current)) { | ||
throw new Error('Expect the container ref to be defined'); | ||
} | ||
|
||
const flowBounds = getNodesBounds(reactflow.getNodes()); | ||
|
||
reactflow.setViewport({ | ||
x: containerRef.current.offsetWidth / 2 - flowBounds.width / 2, | ||
y: 150, | ||
zoom: defaultFitViewOptions.maxZoom, | ||
}); | ||
}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: onInit runs before nodes are measured, which could cause incorrect initial positioning
<ReactFlowProvider> | ||
<WorkflowDiagramCanvasBase | ||
key={workflowWithCurrentVersion.currentVersion.id} | ||
diagram={diagram} | ||
status={workflowWithCurrentVersion.currentVersion.status} | ||
nodeTypes={{ | ||
default: WorkflowDiagramStepNodeEditable, | ||
'create-step': WorkflowDiagramCreateStepNode, | ||
'empty-trigger': WorkflowDiagramEmptyTrigger, | ||
}} | ||
> | ||
<WorkflowDiagramCanvasEditableEffect /> | ||
</WorkflowDiagramCanvasBase> | ||
</ReactFlowProvider> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: ReactFlowProvider should be at a higher level in the component tree to avoid re-initializing the flow context on re-renders
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job, I wonder if we can get rid from the useEffect but I don't see a way to remove it. Behavior looks really nice. LGTM
Thanks @Devessier for your contribution! |
We'll have to make a refactor so the viewport can be animated properly: #8387.
CleanShot.2024-11-12.at.16.03.03.mp4