Skip to content

Commit 23a4fb1

Browse files
committed
Fix selection when workspace name collides
1 parent 0f66e3e commit 23a4fb1

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspacesStepView.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -993,13 +993,19 @@ class WorkspacesTable : TableView<WorkspaceAgentListModel>(WorkspacesTableModel(
993993
if (oldSelection == null) {
994994
return -1
995995
}
996-
val index = listTableModel.items.indexOfFirst { it.name == oldSelection.name }
996+
val index = listTableModel.items.indexOfFirst {
997+
it.workspace.ownerName == oldSelection.workspace.ownerName &&
998+
it.name == oldSelection.name
999+
}
9971000
if (index > -1) {
9981001
return index
9991002
}
10001003
// If there is no matching agent, try matching on just the workspace.
10011004
// It is possible it turned off so it no longer has agents displaying;
10021005
// in this case we want to keep it highlighted.
1003-
return listTableModel.items.indexOfFirst { it.workspace.name == oldSelection.workspace.name }
1006+
return listTableModel.items.indexOfFirst {
1007+
it.workspace.ownerName == oldSelection.workspace.ownerName &&
1008+
it.workspace.name == oldSelection.workspace.name
1009+
}
10041010
}
10051011
}

src/test/kotlin/com/coder/gateway/sdk/DataGen.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ class DataGen {
2020
// Create a list of random agents for a random workspace.
2121
fun agentList(
2222
workspaceName: String,
23+
ownerName: String = "tester",
2324
vararg agentName: String,
2425
): List<WorkspaceAgentListModel> {
25-
val workspace = workspace(workspaceName, agents = agentName.associateWith { UUID.randomUUID().toString() })
26+
val workspace = workspace(
27+
workspaceName,
28+
ownerName = ownerName,
29+
agents = agentName.associateWith { UUID.randomUUID().toString() },
30+
)
2631
return workspace.toAgentList()
2732
}
2833

0 commit comments

Comments
 (0)