-
Notifications
You must be signed in to change notification settings - Fork 3.8k
fix(workflow): draw a highlighted edge over the ordinary ones #6642
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 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
40 changes: 40 additions & 0 deletions
40
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/utils/edge-highlight.ts
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 |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /** | ||
| * Whether an edge is drawn highlighted. | ||
| * | ||
| * Three places need this answer and each reaches it from a different source — | ||
| * the edge itself from the React Flow store, a card from the same store while | ||
| * deciding which of its knobs to darken, and the canvas while assigning the | ||
| * edge's z so a highlighted line is not crossed by an ordinary one. They have | ||
| * to agree: a knob checking fewer conditions than the line leaves a dark line | ||
| * running into a light knob, and a z checking fewer leaves the highlight cut in | ||
| * half by whatever crosses it. | ||
| * | ||
| * They agreed by being copied, which is the arrangement that produced both of | ||
| * those bugs. This is the one definition. | ||
| */ | ||
| export function isEdgeHighlighted(state: { | ||
| /** Either endpoint is selected on the canvas. */ | ||
| isEndpointSelected?: boolean | ||
| /** Either endpoint is the block open in the editor panel. */ | ||
| isConnectedToEditor?: boolean | ||
| /** The edge itself is selected. */ | ||
| isEdgeSelected?: boolean | ||
| }): boolean { | ||
| return Boolean(state.isEndpointSelected || state.isConnectedToEditor || state.isEdgeSelected) | ||
| } | ||
|
|
||
| /** | ||
| * Whether an edge touches the block currently open in the editor panel. | ||
| * | ||
| * `null` while the panel is on another tab, so a block left open behind the | ||
| * console does not keep its edges lit. | ||
| */ | ||
| export function isEdgeConnectedToEditor( | ||
| editorOpenBlockId: string | null, | ||
| source: string, | ||
| target: string | ||
| ): boolean { | ||
| return ( | ||
| editorOpenBlockId !== null && (source === editorOpenBlockId || target === editorOpenBlockId) | ||
| ) | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /** | ||
| * @vitest-environment node | ||
| */ | ||
| import { describe, expect, it } from 'vitest' | ||
| import { | ||
| BLOCK_Z_BASE, | ||
| CONTAINER_CHILD_Z_BASE, | ||
| EDGE_Z_BASE, | ||
| EDGE_Z_MAX, | ||
| getBlockZIndex, | ||
| getEdgeZIndex, | ||
| } from './canvas-layers' | ||
|
|
||
| /** | ||
| * Nesting depths an edge is tiered by. Stops short of the band's ceiling: past | ||
| * it every edge saturates at the same tier, which is checked on its own below. | ||
| */ | ||
| const DEPTHS = [undefined, 0, 1, 2, 5] | ||
|
|
||
| describe('getEdgeZIndex', () => { | ||
| it('puts a highlighted edge over every ordinary one, however deeply nested', () => { | ||
| /* The reported bug: a highlighted edge kept its own container's depth, so an | ||
| ordinary edge one level deeper painted over it and cut the highlight. */ | ||
| const highlighted = getEdgeZIndex(undefined, { isHighlighted: true }) | ||
|
|
||
| for (const depth of DEPTHS) { | ||
| expect(getEdgeZIndex(depth)).toBeLessThan(highlighted) | ||
| } | ||
| }) | ||
|
|
||
| it('keeps a highlighted edge below the cards', () => { | ||
| /* Elevating highlighted edges over the cards drew them across the chrome of | ||
| their own endpoints, so the highlighted tier stays inside the edge band. */ | ||
| const highlighted = getEdgeZIndex(undefined, { isHighlighted: true }) | ||
|
|
||
| expect(highlighted).toBeLessThan(BLOCK_Z_BASE) | ||
| expect(highlighted).toBeLessThan(getBlockZIndex(BLOCK_Z_BASE)) | ||
| expect(highlighted).toBeLessThan(CONTAINER_CHILD_Z_BASE) | ||
| }) | ||
|
|
||
| it('leaves the in-flight connection line above everything in the band', () => { | ||
| expect(getEdgeZIndex(undefined, { isHighlighted: true })).toBeLessThan(EDGE_Z_MAX) | ||
| for (const depth of DEPTHS) { | ||
| expect(getEdgeZIndex(depth)).toBeLessThan(EDGE_Z_MAX) | ||
| } | ||
| }) | ||
|
|
||
| it('still orders ordinary edges by the depth they are nested at', () => { | ||
| expect(getEdgeZIndex(undefined)).toBe(EDGE_Z_BASE) | ||
| expect(getEdgeZIndex(0)).toBeGreaterThan(getEdgeZIndex(undefined)) | ||
| expect(getEdgeZIndex(1)).toBeGreaterThan(getEdgeZIndex(0)) | ||
| }) | ||
|
|
||
| it('keeps every edge clear of the container bodies it crosses', () => { | ||
| /* Containers are numbered from 0 by nesting depth; an edge sharing a body's | ||
| z loses the equal-z tiebreak to DOM order and is drawn behind it. */ | ||
| for (const depth of DEPTHS) { | ||
| expect(getEdgeZIndex(depth)).toBeGreaterThan(depth ?? 0) | ||
| expect(getEdgeZIndex(depth, { isHighlighted: true })).toBeGreaterThan(depth ?? 0) | ||
| } | ||
| }) | ||
|
|
||
| it('saturates rather than growing past the band', () => { | ||
| /* The band is fixed, so beyond its ceiling every edge shares the deepest | ||
| tier and no longer clears a container nested that far — true before this | ||
| change too, at a ceiling of `EDGE_Z_MAX` rather than one below the | ||
| highlighted tier. Nothing in the editor nests anywhere near it. */ | ||
| expect(getEdgeZIndex(40)).toBe(getEdgeZIndex(8)) | ||
| expect(getEdgeZIndex(8)).toBeLessThan(getEdgeZIndex(undefined, { isHighlighted: true })) | ||
| }) | ||
| }) |
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
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.
Uh oh!
There was an error while loading. Please reload this page.