Skip to content
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

Merged
merged 12 commits into from
Nov 12, 2024
Merged

Conversation

Devessier
Copy link
Contributor

@Devessier Devessier commented Nov 6, 2024

  • Increase the dimensions of the ReactFlow nodes. This allows to ditch scaling which made it hard to get the width of the nodes as they were visually scaled by 1.3.
  • Center the flow when the flow mounts and when the state of the right drawer opens.
  • Put the node type inside of the node so it doesn't overlap with the arrow
  • Make the edges non deletable

We'll have to make a refactor so the viewport can be animated properly: #8387.

CleanShot.2024-11-12.at.16.03.03.mp4

@FelixMalfait
Copy link
Member

Great! Make sure to check dark mode
Screenshot 2024-11-11 at 09 36 20

@Devessier
Copy link
Contributor Author

I will fix the dark mode in another PR.

@Devessier Devessier marked this pull request as ready for review November 12, 2024 15:06
Copy link
Contributor

@greptile-apps greptile-apps bot left a 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

Comment on lines +163 to +171
const viewportX =
(containerRef.current.offsetWidth + visibleRightDrawerWidth) / 2 -
flowBounds.width / 2;

reactflow.setViewport(
{
...currentViewport,
x: viewportX - visibleRightDrawerWidth,
},
Copy link
Contributor

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

Comment on lines +149 to +152
useEffect(() => {
if (!isDefined(containerRef.current) || !reactflow.viewportInitialized) {
return;
}
Copy link
Contributor

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

Comment on lines +179 to 191
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,
});
}}
Copy link
Contributor

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

Comment on lines +18 to +31
<ReactFlowProvider>
<WorkflowDiagramCanvasBase
key={workflowWithCurrentVersion.currentVersion.id}
diagram={diagram}
status={workflowWithCurrentVersion.currentVersion.status}
nodeTypes={{
default: WorkflowDiagramStepNodeEditable,
'create-step': WorkflowDiagramCreateStepNode,
'empty-trigger': WorkflowDiagramEmptyTrigger,
}}
>
<WorkflowDiagramCanvasEditableEffect />
</WorkflowDiagramCanvasBase>
</ReactFlowProvider>
Copy link
Contributor

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

Copy link
Contributor

@martmull martmull left a 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

@Devessier
Copy link
Contributor Author

Thank you, @martmull. I created an issue to refactor the useEffect. Maybe we can give it a look later.

See #8387

@Devessier Devessier merged commit 31f0376 into main Nov 12, 2024
18 of 19 checks passed
@Devessier Devessier deleted the improve-visualizer-layout branch November 12, 2024 16:52
Copy link

Thanks @Devessier for your contribution!
This marks your 25th PR on the repo. You're top 2% of all our contributors 🎉
See contributor page - Share on LinkedIn - Share on Twitter

Contributions

@Devessier
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants