-
Notifications
You must be signed in to change notification settings - Fork 73
Fix converging edges swapping positions when selected #4348
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 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
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,90 @@ | ||
| import { describe, expect, test } from 'vitest'; | ||
|
|
||
| import { sortOrderForSvg } from '../../js/workflow-diagram/styles'; | ||
|
|
||
| describe.concurrent('sortOrderForSvg', () => { | ||
| test('sorts disabled edges before enabled edges', () => { | ||
| const edges = [ | ||
| { data: { enabled: true }, selected: false }, | ||
| { data: { enabled: false }, selected: false }, | ||
| ]; | ||
|
|
||
| const sorted = [...edges].sort(sortOrderForSvg); | ||
|
|
||
| expect(sorted[0].data.enabled).toBe(false); | ||
| expect(sorted[1].data.enabled).toBe(true); | ||
| }); | ||
|
|
||
| test('maintains stable order for edges with same enabled status', () => { | ||
| const edges = [ | ||
| { id: 'edge1', data: { enabled: true }, selected: false }, | ||
| { id: 'edge2', data: { enabled: true }, selected: false }, | ||
| { id: 'edge3', data: { enabled: true }, selected: false }, | ||
| ]; | ||
|
|
||
| const sorted = [...edges].sort(sortOrderForSvg); | ||
|
|
||
| // Order should remain unchanged when all have same enabled status | ||
| expect(sorted[0].id).toBe('edge1'); | ||
| expect(sorted[1].id).toBe('edge2'); | ||
| expect(sorted[2].id).toBe('edge3'); | ||
| }); | ||
|
|
||
| test('preserves stable order when selection state changes', () => { | ||
| // This test ensures that selecting edges doesn't cause layout shifts | ||
| const edges = [ | ||
| { id: 'edge1', data: { enabled: true }, selected: false }, | ||
| { id: 'edge2', data: { enabled: true }, selected: false }, | ||
| { id: 'edge3', data: { enabled: true }, selected: false }, | ||
| ]; | ||
|
|
||
| // Sort once with no selection | ||
| const sortedBefore = [...edges].sort(sortOrderForSvg); | ||
|
|
||
| // Simulate selecting middle edge | ||
| const edgesWithSelection = [ | ||
| { id: 'edge1', data: { enabled: true }, selected: false }, | ||
| { id: 'edge2', data: { enabled: true }, selected: true }, | ||
| { id: 'edge3', data: { enabled: true }, selected: false }, | ||
| ]; | ||
|
|
||
| const sortedAfter = [...edgesWithSelection].sort(sortOrderForSvg); | ||
|
|
||
| // Order should NOT change when selection changes | ||
| expect(sortedBefore[0].id).toBe(sortedAfter[0].id); | ||
| expect(sortedBefore[1].id).toBe(sortedAfter[1].id); | ||
| expect(sortedBefore[2].id).toBe(sortedAfter[2].id); | ||
| }); | ||
|
|
||
| test('handles mix of enabled and disabled edges correctly', () => { | ||
| const edges = [ | ||
| { id: 'disabled1', data: { enabled: false }, selected: false }, | ||
| { id: 'enabled1', data: { enabled: true }, selected: false }, | ||
| { id: 'disabled2', data: { enabled: false }, selected: false }, | ||
| { id: 'enabled2', data: { enabled: true }, selected: false }, | ||
| ]; | ||
|
|
||
| const sorted = [...edges].sort(sortOrderForSvg); | ||
|
|
||
| // All disabled edges should come before enabled edges | ||
| expect(sorted[0].id).toBe('disabled1'); | ||
| expect(sorted[1].id).toBe('disabled2'); | ||
| expect(sorted[2].id).toBe('enabled1'); | ||
| expect(sorted[3].id).toBe('enabled2'); | ||
| }); | ||
|
|
||
| test('maintains stable order within disabled edge group', () => { | ||
| const edges = [ | ||
| { id: 'disabled1', data: { enabled: false }, selected: false }, | ||
| { id: 'disabled2', data: { enabled: false }, selected: true }, | ||
| { id: 'disabled3', data: { enabled: false }, selected: false }, | ||
| ]; | ||
|
|
||
| const sorted = [...edges].sort(sortOrderForSvg); | ||
|
|
||
| // Order within disabled group should remain stable regardless of selection | ||
| expect(sorted[0].id).toBe('disabled1'); | ||
| expect(sorted[1].id).toBe('disabled2'); | ||
| expect(sorted[2].id).toBe('disabled3'); | ||
| }); | ||
| }); |
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.