Set up React Flow and add a base Diagram component #10#47
Set up React Flow and add a base Diagram component #10#47handreyrc wants to merge 2 commits intoserverlessworkflow:mainfrom
Conversation
Signed-off-by: handreyrc <handrey.cunha@gmail.com>
fcd4e90 to
9d9ef44
Compare
There was a problem hiding this comment.
Pull request overview
Sets up React Flow (@xyflow/react) in the diagram editor package and introduces a baseline Diagram component so the editor can render and interact with a simple hardcoded node/edge workflow (as a wiring/smoke test for the diagram layer).
Changes:
- Added
@xyflow/reactto the workspace catalog and theserverless-workflow-diagram-editorpackage dependencies. - Introduced
src/react-flow/diagram/Diagram(with CSS) and updatedDiagramEditorto render it. - Updated Storybook + Vitest setup/tests to accommodate React Flow rendering requirements (e.g., DOM mocks).
Reviewed changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| pnpm-workspace.yaml | Adds @xyflow/react to the central pnpm catalog. |
| pnpm-lock.yaml | Locks @xyflow/react and its transitive deps; includes incidental lock updates. |
| packages/serverless-workflow-diagram-editor/package.json | Adds @xyflow/react as a runtime dependency via catalog:. |
| packages/serverless-workflow-diagram-editor/src/react-flow/diagram/Diagram.tsx | New baseline React Flow diagram rendering + interactions. |
| packages/serverless-workflow-diagram-editor/src/react-flow/diagram/Diagram.css | Adds diagram container/background styling used by React Flow. |
| packages/serverless-workflow-diagram-editor/src/diagram-editor/DiagramEditor.tsx | Replaces placeholder UI with Diagram embedding + (placeholder) imperative API. |
| packages/serverless-workflow-diagram-editor/stories/DiagramEditor.tsx | Ensures Storybook story provides height for React Flow to render. |
| packages/serverless-workflow-diagram-editor/stories/DiagramEditor.stories.ts | Updates story args to match the new DiagramEditor props. |
| packages/serverless-workflow-diagram-editor/tests/setupTests.ts | Adds global DOM mocks (ResizeObserver/DOMMatrix/PointerEvent) for React Flow tests. |
| packages/serverless-workflow-diagram-editor/tests/react-flow/diagram/Diagram.test.tsx | Adds a basic render smoke test for diagram node labels. |
| packages/serverless-workflow-diagram-editor/tests/diagram-editor/DiagramEditor.test.tsx | Updates editor test to assert the diagram container renders. |
| packages/serverless-workflow-diagram-editor/tests/diagram-editor/DiagramEditor.story.test.tsx | Updates story test to assert the diagram container renders. |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
packages/serverless-workflow-diagram-editor/src/diagram-editor/DiagramEditor.tsx
Outdated
Show resolved
Hide resolved
packages/serverless-workflow-diagram-editor/src/diagram-editor/DiagramEditor.tsx
Outdated
Show resolved
Hide resolved
packages/serverless-workflow-diagram-editor/src/diagram-editor/DiagramEditor.tsx
Outdated
Show resolved
Hide resolved
packages/serverless-workflow-diagram-editor/tests/setupTests.ts
Outdated
Show resolved
Hide resolved
packages/serverless-workflow-diagram-editor/src/react-flow/diagram/Diagram.tsx
Show resolved
Hide resolved
packages/serverless-workflow-diagram-editor/src/react-flow/diagram/Diagram.tsx
Outdated
Show resolved
Hide resolved
packages/serverless-workflow-diagram-editor/src/diagram-editor/DiagramEditor.tsx
Outdated
Show resolved
Hide resolved
packages/serverless-workflow-diagram-editor/src/diagram-editor/DiagramEditor.tsx
Show resolved
Hide resolved
Signed-off-by: handreyrc <handrey.cunha@gmail.com>
| (changes) => setEdges((edgesSnapshot) => RF.applyEdgeChanges(changes, edgesSnapshot)), | ||
| [], | ||
| ); | ||
| const onConnect = React.useCallback<RF.OnConnect>( |
There was a problem hiding this comment.
Do we need this for MVP as it will be readonly?
| args: { | ||
| isReadOnly: true, | ||
| content: "Sample Content", | ||
| locale: "EN", |
There was a problem hiding this comment.
Should lowercase en here as thats the i18next standard
| test("Render DiagramEditor Component", async () => { | ||
| const content = "Sample Content"; | ||
| test("Renders react flow Diagram component", async () => { | ||
| const locale = "EN"; |
There was a problem hiding this comment.
Same as before if we can change to lowercase
fantonangeli
left a comment
There was a problem hiding this comment.
Thanks a lot @handreyrc for your PR. I only have a few comments, but this PR already looks great
|
|
||
| export const DiagramEditor = (props: DiagramEditorProps) => { | ||
| //TODO: Implement the actual component this is just a placeholder | ||
| export const DiagramEditor = ({ isReadOnly, locale, ref }: DiagramEditorProps) => { |
There was a problem hiding this comment.
Because oxlint was only showing a warning but nothing was clearly shown in CI with an error, I would also change the root settings in line /.oxlintrc.json:6 to the following, so also arguments are ignored when they start with "_":
"typescript/no-unused-vars": ["error", {"argsIgnorePattern": "^_", "varsIgnorePattern": "^_" }],
| export const DiagramEditor = ({ isReadOnly, locale, ref }: DiagramEditorProps) => { | |
| // oxlint-disable-next-line no-unused-vars remove this after the real implementation | |
| export const DiagramEditor = ({ isReadOnly, locale, ref }: DiagramEditorProps) => { |
| <SWDiagramEditor content={props.content} isReadOnly={props.isReadOnly} /> | ||
| </> | ||
| <div style={{ height: "100vh" }}> | ||
| <SWDiagramEditor isReadOnly={props.isReadOnly} locale={props.locale} /> |
There was a problem hiding this comment.
I would rename this with SWF and the import alias
| <SWDiagramEditor isReadOnly={props.isReadOnly} locale={props.locale} /> | |
| <SWFDiagramEditor isReadOnly={props.isReadOnly} locale={props.locale} /> |
| edges={edges} | ||
| onNodesChange={onNodesChange} | ||
| onEdgesChange={onEdgesChange} | ||
| onConnect={onConnect} |
There was a problem hiding this comment.
here, I would implement something like this, to have disable the nodes connections when is read-only
| onConnect={onConnect} | |
| onConnect={isReadOnly ? undefined : onConnect} |
Closes #10
Summary
This PR sets up react flow lib and introduces the Diagram component allowing to render, visualize and interact with a hardcoded sample workflow.
Changes