Skip to content

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 3 commits into from
Apr 27, 2023
Merged

Conversation

code-asher
Copy link
Member

@code-asher code-asher commented Apr 26, 2023

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.

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.
@code-asher code-asher requested a review from johnstcn April 26, 2023 20:41
@code-asher code-asher marked this pull request as ready for review April 27, 2023 00:32
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Nice

Copy link
Member

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.

Copy link
Member Author

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 {
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

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.

@code-asher code-asher merged commit 1f2cc4e into main Apr 27, 2023
@code-asher code-asher deleted the fix-selection branch April 27, 2023 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants