Skip to content

Commit 3b06d9f

Browse files
committed
Simplify agent model list
We can just check if the list is empty then add the workspace-only "agent" model rather than duplicate the block.
1 parent ed37ab0 commit 3b06d9f

File tree

1 file changed

+46
-75
lines changed

1 file changed

+46
-75
lines changed

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

Lines changed: 46 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -687,86 +687,57 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
687687
}
688688

689689
private fun Workspace.toAgentModels(): Set<WorkspaceAgentModel> {
690-
return when (this.latestBuild.resources.size) {
691-
0 -> {
692-
val wm = WorkspaceAgentModel(
693-
this.id,
694-
this.name,
695-
this.name,
696-
this.templateID,
697-
this.templateName,
698-
this.templateIcon,
699-
null,
700-
WorkspaceVersionStatus.from(this),
701-
WorkspaceAgentStatus.from(this),
702-
this.latestBuild.transition,
703-
null,
704-
null,
705-
null
706-
)
707-
cs.launch(Dispatchers.IO) {
708-
wm.templateIcon = iconDownloader.load(wm.templateIconPath, wm.name)
709-
withContext(Dispatchers.Main) {
710-
tableOfWorkspaces.updateUI()
711-
}
690+
val wam = this.latestBuild.resources.filter { it.agents != null }.flatMap { it.agents!! }.map { agent ->
691+
val workspaceWithAgentName = "${this.name}.${agent.name}"
692+
val wm = WorkspaceAgentModel(
693+
this.id,
694+
this.name,
695+
workspaceWithAgentName,
696+
this.templateID,
697+
this.templateName,
698+
this.templateIcon,
699+
null,
700+
WorkspaceVersionStatus.from(this),
701+
WorkspaceAgentStatus.from(this),
702+
this.latestBuild.transition,
703+
OS.from(agent.operatingSystem),
704+
Arch.from(agent.architecture),
705+
agent.expandedDirectory ?: agent.directory,
706+
)
707+
cs.launch(Dispatchers.IO) {
708+
wm.templateIcon = iconDownloader.load(wm.templateIconPath, wm.name)
709+
withContext(Dispatchers.Main) {
710+
tableOfWorkspaces.updateUI()
712711
}
713-
setOf(wm)
714712
}
715-
716-
else -> {
717-
val wam = this.latestBuild.resources.filter { it.agents != null }.flatMap { it.agents!! }.map { agent ->
718-
val workspaceWithAgentName = "${this.name}.${agent.name}"
719-
val wm = WorkspaceAgentModel(
720-
this.id,
721-
this.name,
722-
workspaceWithAgentName,
723-
this.templateID,
724-
this.templateName,
725-
this.templateIcon,
726-
null,
727-
WorkspaceVersionStatus.from(this),
728-
WorkspaceAgentStatus.from(this),
729-
this.latestBuild.transition,
730-
OS.from(agent.operatingSystem),
731-
Arch.from(agent.architecture),
732-
agent.expandedDirectory ?: agent.directory,
733-
)
734-
cs.launch(Dispatchers.IO) {
735-
wm.templateIcon = iconDownloader.load(wm.templateIconPath, wm.name)
736-
withContext(Dispatchers.Main) {
737-
tableOfWorkspaces.updateUI()
738-
}
739-
}
740-
wm
741-
}.toSet()
742-
743-
if (wam.isNullOrEmpty()) {
744-
val wm = WorkspaceAgentModel(
745-
this.id,
746-
this.name,
747-
this.name,
748-
this.templateID,
749-
this.templateName,
750-
this.templateIcon,
751-
null,
752-
WorkspaceVersionStatus.from(this),
753-
WorkspaceAgentStatus.from(this),
754-
this.latestBuild.transition,
755-
null,
756-
null,
757-
null
758-
)
759-
cs.launch(Dispatchers.IO) {
760-
wm.templateIcon = iconDownloader.load(wm.templateIconPath, wm.name)
761-
withContext(Dispatchers.Main) {
762-
tableOfWorkspaces.updateUI()
763-
}
764-
}
765-
return setOf(wm)
713+
wm
714+
}.toSet()
715+
716+
if (wam.isNullOrEmpty()) {
717+
val wm = WorkspaceAgentModel(
718+
this.id,
719+
this.name,
720+
this.name,
721+
this.templateID,
722+
this.templateName,
723+
this.templateIcon,
724+
null,
725+
WorkspaceVersionStatus.from(this),
726+
WorkspaceAgentStatus.from(this),
727+
this.latestBuild.transition,
728+
null,
729+
null,
730+
null
731+
)
732+
cs.launch(Dispatchers.IO) {
733+
wm.templateIcon = iconDownloader.load(wm.templateIconPath, wm.name)
734+
withContext(Dispatchers.Main) {
735+
tableOfWorkspaces.updateUI()
766736
}
767-
return wam
768737
}
738+
return setOf(wm)
769739
}
740+
return wam
770741
}
771742

772743
override fun onPrevious() {

0 commit comments

Comments
 (0)