Skip to content

Commit 7e4b531

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 c871cbf commit 7e4b531

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
@@ -690,86 +690,57 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
690690
}
691691

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

775746
override fun onPrevious() {

0 commit comments

Comments
 (0)