-
Notifications
You must be signed in to change notification settings - Fork 16
Preserve selection when workspace starts/stops #233
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 1 commit
Commits
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
Prev
Previous commit
Preserve selection when workspaces starts or stops
When a workspace starts the workspace row is replaced with a row for the agent(s) and you have to select it again which is annoying (similarly for when the workspace stops). This preserves the selection when the workspace transitions.
- Loading branch information
commit a83b0bc0329000f94ee96e5f2bf73ac66fa59fe2
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
|
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. 👍 Nice test. I'm not a huge Groovy fan, but I do like the table-driven Spock DSL.
Member
Author
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. Same! |
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,54 @@ | ||
| import com.coder.gateway.views.steps.WorkspacesTable | ||
| import spock.lang.Specification | ||
| import spock.lang.Unroll | ||
|
|
||
| @Unroll | ||
| class CoderWorkspacesStepViewTest extends Specification { | ||
| def "gets new selection"() { | ||
| given: | ||
| def table = new WorkspacesTable() | ||
| table.listTableModel.items = List.of( | ||
| // An off workspace. | ||
| DataGen.workspace("ws1", "ws1"), | ||
|
|
||
| // On workspaces. | ||
| DataGen.workspace("agent1", "ws2"), | ||
| DataGen.workspace("agent2", "ws2"), | ||
| DataGen.workspace("agent3", "ws3"), | ||
|
|
||
| // Another off workspace. | ||
| DataGen.workspace("ws4", "ws4"), | ||
|
|
||
| // In practice we do not list both agents and workspaces | ||
| // together but here test that anyway with an agent first and | ||
| // then with a workspace first. | ||
| DataGen.workspace("agent2", "ws5"), | ||
| DataGen.workspace("ws5", "ws5"), | ||
| DataGen.workspace("ws6", "ws6"), | ||
| DataGen.workspace("agent3", "ws6"), | ||
| ) | ||
|
|
||
| expect: | ||
| table.getNewSelection(selected) == expected | ||
|
|
||
| where: | ||
| selected | expected | ||
| null | -1 // No selection. | ||
| DataGen.workspace("gone", "gone") | -1 // No workspace that matches. | ||
| DataGen.workspace("ws1", "ws1") | 0 // Workspace exact match. | ||
| DataGen.workspace("gone", "ws1") | 0 // Agent gone, select workspace. | ||
| DataGen.workspace("ws2", "ws2") | 1 // Workspace gone, select first agent. | ||
| DataGen.workspace("agent1", "ws2") | 1 // Agent exact match. | ||
| DataGen.workspace("agent2", "ws2") | 2 // Agent exact match. | ||
| DataGen.workspace("ws3", "ws3") | 3 // Workspace gone, select first agent. | ||
| DataGen.workspace("agent3", "ws3") | 3 // Agent exact match. | ||
| DataGen.workspace("gone", "ws4") | 4 // Agent gone, select workspace. | ||
| DataGen.workspace("ws4", "ws4") | 4 // Workspace exact match. | ||
| DataGen.workspace("agent2", "ws5") | 5 // Agent exact match. | ||
| DataGen.workspace("gone", "ws5") | 5 // Agent gone, another agent comes first. | ||
| DataGen.workspace("ws5", "ws5") | 6 // Workspace exact match. | ||
| DataGen.workspace("ws6", "ws6") | 7 // Workspace exact match. | ||
| DataGen.workspace("gone", "ws6") | 7 // Agent gone, workspace comes first. | ||
| DataGen.workspace("agent3", "ws6") | 8 // Agent exact match. | ||
| } | ||
| } |
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.
I'm assuming that returning
-1when not found is an explicit thing you're meant to do with a UI table?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.
I think it is more related to lists in general than the table per se; we use an index to select an item and the various
indexOffunctions return-1for no match so I did the same. But I also explicitly check for-1and avoid selecting in that case so really we could returnnullfor example if we wanted. I am not sure what would happen if we passed-1for the selection index directly to the table.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.
Tested and it errors with
invalid index.It does have some other functions that will return a
-1(for exampleconvertRowIndexToViewreturns a-1if the row is not visible) so I think using-1is generally the preferred pattern.