Skip to content

Commit

Permalink
Fix selection when workspace name collides
Browse files Browse the repository at this point in the history
This can happen if multiple users are using the same name for their
workspaces.

Turns out we can just match the workspace ID.

It hardly seems worth a test to see that a == is working, so I did not
bother to update it.
  • Loading branch information
code-asher committed Oct 4, 2024
1 parent 0f66e3e commit 30839c8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ data class WorkspaceAgentListModel(
var icon: Icon? = null,
// The combined status of the workspace and agent to display on the row.
val status: WorkspaceAndAgentStatus = WorkspaceAndAgentStatus.from(workspace, agent),
// The combined `workspace.agent` name to display on the row.
// The combined `workspace.agent` name to display on the row. Users can have workspaces with the same name, so it
// must not be used as a unique identifier.
val name: String = if (agent != null) "${workspace.name}.${agent.name}" else workspace.name,
)
Original file line number Diff line number Diff line change
Expand Up @@ -989,17 +989,19 @@ class WorkspacesTable : TableView<WorkspaceAgentListModel>(WorkspacesTableModel(
}
}

fun getNewSelection(oldSelection: WorkspaceAgentListModel?): Int {
/**
* If a row becomes unselected because the workspace turned on, find the
* first agent row and select that.
*
* If a row becomes unselected because the workspace turned off, find the
* workspace row and select that.
*/
private fun getNewSelection(oldSelection: WorkspaceAgentListModel?): Int {
if (oldSelection == null) {
return -1
}
val index = listTableModel.items.indexOfFirst { it.name == oldSelection.name }
if (index > -1) {
return index
}
// If there is no matching agent, try matching on just the workspace.
// It is possible it turned off so it no longer has agents displaying;
// in this case we want to keep it highlighted.
return listTableModel.items.indexOfFirst { it.workspace.name == oldSelection.workspace.name }
// Both cases are handled by just looking for the ID, since we only ever
// show agents or a workspace but never both.
return listTableModel.items.indexOfFirst { it.workspace.id == oldSelection.workspace.id }
}
}

This file was deleted.

0 comments on commit 30839c8

Please sign in to comment.