Integrate ELKjs for automatic diagram layout#152
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Integrates ELK-based auto-layout into the diagram editor and expands test coverage around layout graph conversion, application, and error handling.
Changes:
- Add
elkjsdependency and introduceprocessElkLayoutcore helper. - Replace the previous placeholder auto-layout with ELK graph building + layout application (including edge bendpoints).
- Update Diagram rendering/tests to use
ReactFlowProviderand add extensive layout-focused tests.
Reviewed changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| pnpm-workspace.yaml | Adds elkjs to the workspace catalog for consistent versioning. |
| packages/serverless-workflow-diagram-editor/package.json | Consumes elkjs from the workspace catalog. |
| packages/serverless-workflow-diagram-editor/src/core/index.ts | Re-exports new ELK layout helper from core. |
| packages/serverless-workflow-diagram-editor/src/core/elkjs.ts | Adds processElkLayout wrapper around ELK with error handling. |
| packages/serverless-workflow-diagram-editor/src/react-flow/diagram/autoLayout.ts | Implements ELK graph conversion, layout application, and bendpoint mapping. |
| packages/serverless-workflow-diagram-editor/src/react-flow/diagram/diagramBuilder.ts | Stops applying auto-layout inside the builder; returns raw nodes/edges. |
| packages/serverless-workflow-diagram-editor/src/react-flow/diagram/Diagram.tsx | Applies auto-layout asynchronously on model changes and fits view. |
| packages/serverless-workflow-diagram-editor/src/diagram-editor/DiagramEditor.tsx | Adds ReactFlowProvider to support useReactFlow() usage. |
| packages/serverless-workflow-diagram-editor/tests/react-flow/diagram/Diagram.test.tsx | Wraps Diagram with ReactFlowProvider in tests. |
| packages/serverless-workflow-diagram-editor/tests/react-flow/diagram/autoLayout.integration.test.ts | Replaces old placeholder assertions with detailed auto-layout unit/integration coverage. |
| packages/serverless-workflow-diagram-editor/tests/core/elkjs.test.ts | Adds unit tests for processElkLayout success and error scenarios. |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
fantonangeli
left a comment
There was a problem hiding this comment.
@handreyrc I left some comment. Please let me know what you think
| if (isActive) { | ||
| setNodes(nodes); | ||
| setEdges(edges); | ||
| reactFlowInstance.fitView(); |
There was a problem hiding this comment.
Because useStates are async, reactFlowInstance.fitView(); will be executed before nodes and edges are updated.
I would suggest to move fitView() in a separate useEffect() bounded to nodes and edges
There was a problem hiding this comment.
I too agree with this.
There was a problem hiding this comment.
@fantonangeli @kumaradityaraj ,
This one is interesting because we cannot move fitView() to a separate useEffect(). It would be executed on every change on nodes and edges such as dragging a node (x/y changes).
I digged a bit about this matter and the recommended approach for cases like that is to create a microtask with setTimeout, so fitView will be queued to run after React updates the DOM.
e.g.
setTimeout(() => reactFlowInstance.fitView() , 0);
I fixed it this way.
WDYT?
There was a problem hiding this comment.
Should we also add a test to verify applyAutoLayout() is called. Wdyt?
| }); | ||
|
|
||
| // Helper function to setup ELK mock with success or error response | ||
| function setupElkMock(returnValue: ElkNode | Error | string | null | undefined | object) { |
There was a problem hiding this comment.
- have you tried to take this function out from the describe, taking
elkMockLayoutas an input? returnValue: ElkNode | Error | string | null | undefined | objectI think is just likereturnValue: any
| } | ||
|
|
||
| // Test data factory for simple graphs | ||
| function createSimpleGraph(nodeCount: number = 2): ElkNode { |
There was a problem hiding this comment.
Same as my previous comment
|
@fantonangeli @kumaradityaraj, This PR is ready for reviews again. Thanks! |
Signed-off-by: handreyrc <handrey.cunha@gmail.com>
Signed-off-by: handreyrc <handrey.cunha@gmail.com> # Conflicts: # packages/serverless-workflow-diagram-editor/src/diagram-editor/DiagramEditor.tsx
Signed-off-by: handreyrc <handrey.cunha@gmail.com>
Signed-off-by: handreyrc <handrey.cunha@gmail.com>
Signed-off-by: handreyrc <handrey.cunha@gmail.com>
40c903f to
96b2245
Compare
Signed-off-by: handreyrc <handrey.cunha@gmail.com>
Closes #54
Summary
This PR replaces the dummy auto-layout placeholder for an actual layout engine capable of layout nodes and edges.
Changes