-
Notifications
You must be signed in to change notification settings - Fork 8
Fix edge labels rendered behind nodes and selected edges #203
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Member
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. I think this file will be very useful in the future, and we won't lose track of the |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* | ||
| * Copyright 2021-Present The Serverless Workflow Specification Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| /** | ||
| * Z-index layering constants for diagram edges and labels. | ||
| * | ||
| * Layering hierarchy (bottom to top): | ||
| * 1. Regular edges (0) | ||
| * 2. Selected edges (100) | ||
| * 3. Edge labels - regular (1000) | ||
| * 4. Edge labels - selected (1001) | ||
| * | ||
| * This ensures: | ||
| * - Selected edges appear above regular edges | ||
| * - All labels appear above all edges (preventing overlap) | ||
| * - Selected edge labels appear above regular labels | ||
| */ | ||
| export const ZINDEX = { | ||
| /** Regular (unselected) edges */ | ||
| EDGE_REGULAR: 0, | ||
|
|
||
| /** Selected edges - appear above regular edges but below all labels */ | ||
| EDGE_SELECTED: 100, | ||
|
|
||
| /** Regular (unselected) edge labels - appear above all edges */ | ||
| EDGE_LABEL_REGULAR: 1000, | ||
|
|
||
| /** Selected edge labels - appear above everything */ | ||
| EDGE_LABEL_SELECTED: 1001, | ||
| } as const; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ import { | |
| createPathFromWayPoints, | ||
| getWayPointsMidpoint, | ||
| } from "../../../src/react-flow/edges/Edges"; | ||
| import { ZINDEX } from "../../../src/react-flow/zIndexConstants"; | ||
| import * as RF from "@xyflow/react"; | ||
|
|
||
| describe("React Flow custom edge types", () => { | ||
|
|
@@ -498,3 +499,91 @@ describe("EdgeLabel positioning", () => { | |
| expect(JSON.stringify(result)).toContain(`translate(${labelX}px,${labelY}px)`); | ||
| }); | ||
| }); | ||
|
|
||
| describe("EdgeLabel z-index behavior", () => { | ||
| it.each([ | ||
| { | ||
| selected: false, | ||
| expectedZIndex: ZINDEX.EDGE_LABEL_REGULAR, | ||
| description: "applies regular label z-index when selected=false", | ||
| }, | ||
| { | ||
| selected: true, | ||
| expectedZIndex: ZINDEX.EDGE_LABEL_SELECTED, | ||
| description: "applies selected label z-index when selected=true", | ||
| }, | ||
| { | ||
| selected: undefined, | ||
| expectedZIndex: ZINDEX.EDGE_LABEL_REGULAR, | ||
| description: "applies default regular label z-index when selected=undefined", | ||
| }, | ||
| ])("$description", ({ selected, expectedZIndex }) => { | ||
| const result = EdgeLabel({ | ||
| sourceX: 0, | ||
| sourceY: 0, | ||
| targetX: 100, | ||
| targetY: 100, | ||
| data: { label: "Test Label" }, | ||
| selected, | ||
| }); | ||
|
|
||
| const resultString = JSON.stringify(result); | ||
| expect(resultString).toContain(`"zIndex":${expectedZIndex}`); | ||
| }); | ||
|
|
||
| it("applies default regular label z-index when selected prop is not provided", () => { | ||
|
Member
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. I think this test is already covered by the |
||
| const result = EdgeLabel({ | ||
| sourceX: 0, | ||
| sourceY: 0, | ||
| targetX: 100, | ||
| targetY: 100, | ||
| data: { label: "Test Label" }, | ||
| }); | ||
|
|
||
| const resultString = JSON.stringify(result); | ||
| expect(resultString).toContain(`"zIndex":${ZINDEX.EDGE_LABEL_REGULAR}`); | ||
| }); | ||
|
|
||
| describe("integration with edge components", () => { | ||
| it.each([ | ||
| { component: DefaultEdge, edgeType: "default", edgeClass: "", selected: true }, | ||
| { component: ErrorEdge, edgeType: "error", edgeClass: "error", selected: true }, | ||
| { component: ConditionEdge, edgeType: "condition", edgeClass: "condition", selected: true }, | ||
| { component: DefaultEdge, edgeType: "default", edgeClass: "", selected: false }, | ||
| { component: ErrorEdge, edgeType: "error", edgeClass: "error", selected: false }, | ||
| { component: ConditionEdge, edgeType: "condition", edgeClass: "condition", selected: false }, | ||
| ])( | ||
| "$edgeType edge applies selected class when selected=$selected", | ||
| ({ component: Component, edgeClass, selected }) => { | ||
| const { container } = render( | ||
| <RF.ReactFlowProvider> | ||
| <Component | ||
| id="e1" | ||
| source="n1" | ||
| target="n2" | ||
| sourceX={0} | ||
| sourceY={0} | ||
| targetX={100} | ||
| targetY={100} | ||
| sourcePosition={RF.Position.Right} | ||
| targetPosition={RF.Position.Left} | ||
| data={{ label: "Test Label" }} | ||
| selected={selected} | ||
| /> | ||
| </RF.ReactFlowProvider>, | ||
| ); | ||
|
|
||
| // Verify the edge path is rendered with correct selected class | ||
| const pathSelector = edgeClass ? `path.edge-line.${edgeClass}` : "path.edge-line"; | ||
| const path = container.querySelector(pathSelector); | ||
| expect(path).toBeInTheDocument(); | ||
|
|
||
| if (selected) { | ||
| expect(path).toHaveClass("selected"); | ||
| } else { | ||
| expect(path).not.toHaveClass("selected"); | ||
| } | ||
| }, | ||
| ); | ||
| }); | ||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.