-
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
Conversation
I want to write a unit test for the selection logic.
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.
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.
👍 Nice
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.
👍 Nice test. I'm not a huge Groovy fan, but I do like the table-driven Spock DSL.
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.
Same!
} | ||
} | ||
|
||
companion object { | ||
val logger = Logger.getInstance(CoderWorkspacesStepView::class.java.simpleName) | ||
private fun getNewSelection(oldSelection: WorkspaceAgentModel?): Int { |
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 -1
when 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 indexOf
functions return -1
for no match so I did the same. But I also explicitly check for -1
and avoid selecting in that case so really we could return null
for example if we wanted. I am not sure what would happen if we passed -1
for 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 example convertRowIndexToView
returns a -1
if the row is not visible) so I think using -1
is generally the preferred pattern.
When the workspace is stopped we have a row for the workspace. When it starts we replace that row with the agent(s) and selection is lost. Same thing happens when the workspace stops and we go back from agent rows to a workspace row.
This will select the first agent in the first case and the matching workspace in the second case.
Broke out the table so I could test this more easily.