@@ -4,6 +4,11 @@ import com.coder.gateway.CoderGatewayBundle
44import com.coder.gateway.icons.CoderIcons
55import com.coder.gateway.models.CoderWorkspacesWizardModel
66import com.coder.gateway.models.WorkspaceAgentModel
7+ import com.coder.gateway.models.WorkspaceAgentStatus
8+ import com.coder.gateway.models.WorkspaceAgentStatus.DELETING
9+ import com.coder.gateway.models.WorkspaceAgentStatus.RUNNING
10+ import com.coder.gateway.models.WorkspaceAgentStatus.STARTING
11+ import com.coder.gateway.models.WorkspaceAgentStatus.STOPPING
712import com.coder.gateway.sdk.Arch
813import com.coder.gateway.sdk.CoderCLIManager
914import com.coder.gateway.sdk.CoderRestClientService
@@ -28,6 +33,7 @@ import com.intellij.openapi.progress.Task
2833import com.intellij.openapi.ui.panel.ComponentPanelBuilder
2934import com.intellij.openapi.wm.impl.welcomeScreen.WelcomeScreenUIManager
3035import com.intellij.ui.AppIcon
36+ import com.intellij.ui.JBColor
3137import com.intellij.ui.components.JBTextField
3238import com.intellij.ui.components.dialog
3339import com.intellij.ui.dsl.builder.BottomGap
@@ -78,7 +84,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
7884
7985 setSelectionMode(ListSelectionModel .SINGLE_SELECTION )
8086 selectionModel.addListSelectionListener {
81- enableNextButtonCallback(selectedObject != null )
87+ enableNextButtonCallback(selectedObject != null && selectedObject?.agentStatus == RUNNING )
8288 }
8389 }
8490
@@ -221,26 +227,55 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
221227 }
222228
223229 private fun List<Workspace>.collectAgents (): List <WorkspaceAgentModel > {
224- return this .flatMap { workspace ->
225- try {
226- val agents = coderClient.workspaceAgents(workspace)
227- val shouldContainAgentName = agents.size > 1
228- return @flatMap agents.map { agent ->
229- val workspaceName = if (shouldContainAgentName) " ${workspace.name} .${agent.name} " else workspace.name
230+ return this .flatMap { it.agentModels() }.toList()
231+ }
232+
233+ private fun Workspace.agentModels (): List <WorkspaceAgentModel > {
234+ return try {
235+ val agents = coderClient.workspaceAgents(this )
236+ when (agents.size) {
237+ 0 -> {
238+ listOf (
239+ WorkspaceAgentModel (
240+ this .name,
241+ this .templateName,
242+ WorkspaceAgentStatus .from(this ),
243+ null ,
244+ null ,
245+ null
246+ )
247+ )
248+ }
249+
250+ 1 -> {
251+ listOf (
252+ WorkspaceAgentModel (
253+ this .name,
254+ this .templateName,
255+ WorkspaceAgentStatus .from(this ),
256+ OS .from(agents[0 ].operatingSystem),
257+ Arch .from(agents[0 ].architecture),
258+ agents[0 ].directory
259+ )
260+ )
261+ }
262+
263+ else -> agents.map { agent ->
264+ val workspaceName = " ${this .name} .${agent.name} "
230265 WorkspaceAgentModel (
231266 workspaceName,
232- workspace.templateName,
233- workspace.latestBuild.job.status,
234- workspace.latestBuild.workspaceTransition,
267+ this .templateName,
268+ WorkspaceAgentStatus .from(this ),
235269 OS .from(agent.operatingSystem),
236270 Arch .from(agent.architecture),
237271 agent.directory
238272 )
239273 }
240- } catch (e: Exception ) {
241- logger.error(" Skipping workspace ${workspace.name} because we could not retrieve the agent(s). Reason: $e " )
242- emptyList()
274+ .toList()
243275 }
276+ } catch (e: Exception ) {
277+ logger.error(" Skipping workspace ${this .name} because we could not retrieve the agent(s). Reason: $e " )
278+ emptyList()
244279 }
245280 }
246281
@@ -322,7 +357,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
322357
323358 private class WorkspaceStatusColumnInfo (columnName : String ) : ColumnInfo<WorkspaceAgentModel, String>(columnName) {
324359 override fun valueOf (workspace : WorkspaceAgentModel ? ): String? {
325- return workspace?.statusLabel()
360+ return workspace?.agentStatus?.label
326361 }
327362
328363 override fun getRenderer (item : WorkspaceAgentModel ? ): TableCellRenderer {
@@ -339,32 +374,10 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
339374 }
340375 }
341376
342- private fun WorkspaceAgentModel.statusLabel () = when (this .jobStatus) {
343- ProvisionerJobStatus .PENDING -> " ◍ Queued"
344- ProvisionerJobStatus .RUNNING -> when (this .buildTransition) {
345- WorkspaceBuildTransition .START -> " ⦿ Starting"
346- WorkspaceBuildTransition .STOP -> " ◍ Stopping"
347- WorkspaceBuildTransition .DELETE -> " ⦸ Deleting"
348- }
349-
350- ProvisionerJobStatus .SUCCEEDED -> when (this .buildTransition) {
351- WorkspaceBuildTransition .START -> " ⦿ Running"
352- WorkspaceBuildTransition .STOP -> " ◍ Stopped"
353- WorkspaceBuildTransition .DELETE -> " ⦸ Deleted"
354- }
355-
356- ProvisionerJobStatus .CANCELING -> " ◍ Canceling action"
357- ProvisionerJobStatus .CANCELED -> " ◍ Canceled action"
358- ProvisionerJobStatus .FAILED -> " ⓧ Failed"
359- }
360-
361- private fun WorkspaceAgentModel.statusColor () = when (this .jobStatus) {
362- ProvisionerJobStatus .SUCCEEDED -> if (this .buildTransition == WorkspaceBuildTransition .START ) Color .GREEN else Color .RED
363- ProvisionerJobStatus .RUNNING -> when (this .buildTransition) {
364- WorkspaceBuildTransition .START , WorkspaceBuildTransition .STOP , WorkspaceBuildTransition .DELETE -> Color .GRAY
365- }
366-
367- else -> Color .RED
377+ private fun WorkspaceAgentModel.statusColor () = when (this .agentStatus) {
378+ RUNNING -> JBColor .GREEN
379+ STARTING , STOPPING , DELETING -> if (JBColor .isBright()) JBColor .LIGHT_GRAY else JBColor .DARK_GRAY
380+ else -> JBColor .RED
368381 }
369382 }
370383
0 commit comments