Define edge types and create React Flow custom edge components#135
Define edge types and create React Flow custom edge components#135handreyrc wants to merge 1 commit intoserverlessworkflow:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds custom React Flow edge types (default, condition, error) to the Serverless Workflow diagram editor, including waypoint-based routing, labels, and arrow markers, plus accompanying styling and tests.
Changes:
- Introduces
EdgeTypesmapping and custom edge renderers with label rendering and waypoint path support. - Updates the sample
Diagramto use edge types, show labels/waypoints, and apply default arrow markers. - Adds CSS styling for edge strokes and edge labels, plus a new test suite for edge types and waypoint path generation.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/serverless-workflow-diagram-editor/tests/react-flow/edges/Edges.test.tsx | New tests for edge type registration/rendering and createPathFromWayPoints. |
| packages/serverless-workflow-diagram-editor/src/styles.css | Registers a new CSS layer for custom edge labels. |
| packages/serverless-workflow-diagram-editor/src/react-flow/edges/Edges.tsx | Adds custom edge components, label renderer, and waypoint-to-SVG-path helper. |
| packages/serverless-workflow-diagram-editor/src/react-flow/diagram/Diagram.tsx | Wires edgeTypes, edge sample data (types/labels/waypoints), and default arrow markers into React Flow. |
| packages/serverless-workflow-diagram-editor/src/react-flow/diagram/Diagram.css | Adds styling for edge lines and edge labels (including layer usage). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
4fd7b01 to
55418e9
Compare
| const default_n4n5 = waitFor(() => screen.getByTestId("n4-n5")); | ||
| const error_n5n6 = waitFor(() => screen.getByTestId("n5-n6")); | ||
|
|
||
| expect(default_n1n2).not.toBeNull(); |
There was a problem hiding this comment.
waitFor returns a promise so will never be null, if you change to toBeInDocument()
There was a problem hiding this comment.
@lornakelly
Testing react flow edge components is a bit complicated, the content is later injected into an <svg> tag so it is basically a path with styles.
I refactored the tests with a different approach to get them tested properly.
| /* Condition Edge */ | ||
| export type ConditionEdgeType = RF.Edge<BaseEdgeData, typeof GraphEdgeType.Condition>; | ||
| export function ConditionEdge({ | ||
| id, |
There was a problem hiding this comment.
There is a lot of repetition in the 3 edge types, what do you think about making one CustomEdge that accepts className, type, ...props and then, for example, have ErrorEdge return the CustomEdge specifying a className and type (GraphEdgeType.Error?)
Or you think moving forward they will have to be spearate?
There was a problem hiding this comment.
We may need it if we need to handle task types, we don't need it for now.
I created a CustomBaseEdge to avoid repetition.
| cursor: grabbing !important; | ||
| } | ||
| .dec-root .diagram-background { | ||
| --xy-background-pattern-color: #ccc; |
There was a problem hiding this comment.
are these changes form running pnpm format?
There was a problem hiding this comment.
I opened those files with a different IDE to solve some comflics and I let it format the file.
I ran the pnpm format to adjust it back to what it should be.
It should be fixed.
| }); | ||
|
|
||
| it("render custom edge types", async () => { | ||
| const nodes: RF.Node[] = [ |
There was a problem hiding this comment.
Maybe we move the nodes and edges here into file(s) in the test fixtures folder? can be reused easily then and less clutter in test file?
There was a problem hiding this comment.
The tests were refactored.
Please check it again.
|
Thanks for Pr @handreyrc just added a few comments |
55418e9 to
26ef7c6
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
26ef7c6 to
588825c
Compare
588825c to
d47810e
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: handreyrc <handrey.cunha@gmail.com>
d47810e to
38573d6
Compare
Closes #52
Summary
This PR adds react flow edge types, customizable edge components and support to calculated waypoints.
Changes
custom-edges.mp4