-
Notifications
You must be signed in to change notification settings - Fork 8
Make workflow read only by disabling drag-and-drop and edge handles #165
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
Open
handreyrc
wants to merge
2
commits into
serverlessworkflow:main
Choose a base branch
from
handreyrc:read-only-mode
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+120
−13
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,35 @@ import { en } from "../../../src/i18n/locales/en"; | |
| import { ReactFlowProvider } from "@xyflow/react"; | ||
| import * as autoLayoutModule from "../../../src/react-flow/diagram/autoLayout"; | ||
|
|
||
| /** | ||
| * Helper function to render the Diagram component with all required providers | ||
| * @param options - Configuration options for the diagram | ||
| * @param options.isReadOnly - Whether the diagram should be in read-only mode | ||
| * @param options.content - The workflow content to render | ||
| * @param options.locale - The locale to use for i18n | ||
| */ | ||
| function renderDiagram({ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wondering is it worth moving this to common |
||
| isReadOnly = true, | ||
| content = "", | ||
| locale = "en", | ||
| }: { | ||
| isReadOnly?: boolean; | ||
| content?: string; | ||
| locale?: string; | ||
| } = {}) { | ||
| return render( | ||
| <ReactFlowProvider> | ||
| <DiagramEditorContextProvider content={content} isReadOnly={isReadOnly} locale={locale}> | ||
| <I18nProvider locale="en" dictionaries={{ en }}> | ||
| <SidebarProvider> | ||
| <Diagram /> | ||
| </SidebarProvider> | ||
| </I18nProvider> | ||
| </DiagramEditorContextProvider> | ||
| </ReactFlowProvider>, | ||
| ); | ||
| } | ||
|
|
||
| describe("Diagram Component", () => { | ||
| let applyAutoLayoutSpy: ReturnType<typeof vi.spyOn>; | ||
|
|
||
|
|
@@ -40,17 +69,7 @@ describe("Diagram Component", () => { | |
| }); | ||
|
|
||
| it("render Diagram component and canvas", async () => { | ||
| render( | ||
| <ReactFlowProvider> | ||
| <DiagramEditorContextProvider content={""} isReadOnly={true} locale={"en"}> | ||
| <I18nProvider locale="en" dictionaries={{ en }}> | ||
| <SidebarProvider> | ||
| <Diagram /> | ||
| </SidebarProvider> | ||
| </I18nProvider> | ||
| </DiagramEditorContextProvider> | ||
| </ReactFlowProvider>, | ||
| ); | ||
| renderDiagram({ isReadOnly: true }); | ||
|
|
||
| const diagram = screen.getByTestId("diagram-container"); | ||
| const canvas = screen.getByTestId("react-flow-canvas"); | ||
|
|
@@ -63,4 +82,75 @@ describe("Diagram Component", () => { | |
| expect(applyAutoLayoutSpy).toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
|
|
||
| it("should apply read-only class when isReadOnly is true", async () => { | ||
| renderDiagram({ isReadOnly: true }); | ||
|
|
||
| const diagram = screen.getByTestId("diagram-container"); | ||
|
|
||
| // Verify that the read-only class is applied | ||
| expect(diagram).toHaveClass("read-only"); | ||
|
|
||
| await waitFor(() => { | ||
| expect(applyAutoLayoutSpy).toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
|
|
||
| it("should not apply read-only class when isReadOnly is false", async () => { | ||
| renderDiagram({ isReadOnly: false }); | ||
|
|
||
| const diagram = screen.getByTestId("diagram-container"); | ||
|
|
||
| // Verify that the read-only class is not applied | ||
| expect(diagram).not.toHaveClass("read-only"); | ||
|
|
||
| await waitFor(() => { | ||
| expect(applyAutoLayoutSpy).toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
|
|
||
| it("should disable node interaction when isReadOnly is true", async () => { | ||
| renderDiagram({ isReadOnly: true }); | ||
|
|
||
| const diagram = screen.getByTestId("diagram-container"); | ||
|
|
||
| // Verify that the read-only class is applied | ||
| // This class applies CSS rule: .read-only .react-flow__handle { visibility: hidden !important; } | ||
| expect(diagram).toHaveClass("read-only"); | ||
|
|
||
| // Verify ReactFlow canvas is rendered | ||
| const canvas = screen.getByTestId("react-flow-canvas"); | ||
| expect(canvas).toBeInTheDocument(); | ||
|
|
||
| // Note: The actual CSS visibility of handles cannot be tested in JSDOM as it doesn't apply stylesheets. | ||
| // The read-only behavior is enforced through: | ||
| // 1. CSS class "read-only" which hides .react-flow__handle elements | ||
| // 2. ReactFlow props nodesDraggable={false} and nodesConnectable={false} | ||
| // For full verification of handle visibility, use e2e tests where CSS is applied. | ||
|
|
||
| await waitFor(() => { | ||
| expect(applyAutoLayoutSpy).toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
|
|
||
| it("should enable node interaction when isReadOnly is false", async () => { | ||
| renderDiagram({ isReadOnly: false }); | ||
|
|
||
| const diagram = screen.getByTestId("diagram-container"); | ||
|
|
||
| // Verify that the read-only class is not applied | ||
| expect(diagram).not.toHaveClass("read-only"); | ||
|
|
||
| // Verify ReactFlow canvas is rendered | ||
| const canvas = screen.getByTestId("react-flow-canvas"); | ||
| expect(canvas).toBeInTheDocument(); | ||
|
|
||
| // Note: When read-only class is not present, handles are visible via CSS | ||
| // and ReactFlow props nodesDraggable={true} and nodesConnectable={true} enable interaction. | ||
| // For full verification of handle visibility and interaction, use e2e tests. | ||
|
|
||
| await waitFor(() => { | ||
| expect(applyAutoLayoutSpy).toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
we are mixing strings and boolean in the same array.
if we are only conditionally adding
read-only, can we use a ternary condition to make it more readable?