@@ -4,6 +4,11 @@ import com.coder.gateway.CoderGatewayBundle
4
4
import com.coder.gateway.icons.CoderIcons
5
5
import com.coder.gateway.models.CoderWorkspacesWizardModel
6
6
import 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
7
12
import com.coder.gateway.sdk.Arch
8
13
import com.coder.gateway.sdk.CoderCLIManager
9
14
import com.coder.gateway.sdk.CoderRestClientService
@@ -28,6 +33,7 @@ import com.intellij.openapi.progress.Task
28
33
import com.intellij.openapi.ui.panel.ComponentPanelBuilder
29
34
import com.intellij.openapi.wm.impl.welcomeScreen.WelcomeScreenUIManager
30
35
import com.intellij.ui.AppIcon
36
+ import com.intellij.ui.JBColor
31
37
import com.intellij.ui.components.JBTextField
32
38
import com.intellij.ui.components.dialog
33
39
import com.intellij.ui.dsl.builder.BottomGap
@@ -78,7 +84,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
78
84
79
85
setSelectionMode(ListSelectionModel .SINGLE_SELECTION )
80
86
selectionModel.addListSelectionListener {
81
- enableNextButtonCallback(selectedObject != null )
87
+ enableNextButtonCallback(selectedObject != null && selectedObject?.agentStatus == RUNNING )
82
88
}
83
89
}
84
90
@@ -221,26 +227,55 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
221
227
}
222
228
223
229
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} "
230
265
WorkspaceAgentModel (
231
266
workspaceName,
232
- workspace.templateName,
233
- workspace.latestBuild.job.status,
234
- workspace.latestBuild.workspaceTransition,
267
+ this .templateName,
268
+ WorkspaceAgentStatus .from(this ),
235
269
OS .from(agent.operatingSystem),
236
270
Arch .from(agent.architecture),
237
271
agent.directory
238
272
)
239
273
}
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()
243
275
}
276
+ } catch (e: Exception ) {
277
+ logger.error(" Skipping workspace ${this .name} because we could not retrieve the agent(s). Reason: $e " )
278
+ emptyList()
244
279
}
245
280
}
246
281
@@ -322,7 +357,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
322
357
323
358
private class WorkspaceStatusColumnInfo (columnName : String ) : ColumnInfo<WorkspaceAgentModel, String>(columnName) {
324
359
override fun valueOf (workspace : WorkspaceAgentModel ? ): String? {
325
- return workspace?.statusLabel()
360
+ return workspace?.agentStatus?.label
326
361
}
327
362
328
363
override fun getRenderer (item : WorkspaceAgentModel ? ): TableCellRenderer {
@@ -339,32 +374,10 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
339
374
}
340
375
}
341
376
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
368
381
}
369
382
}
370
383
0 commit comments