Skip to content

Commit 783221b

Browse files
authored
Merge pull request #61 from coder/show-all-workspaces
Show all workspaces - working and non working
2 parents 278a0b6 + 9ec0858 commit 783221b

File tree

6 files changed

+91
-48
lines changed

6 files changed

+91
-48
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
# coder-gateway Changelog
44

55
## [Unreleased]
6+
### Added
7+
- support for displaying working and non-working workspaces
8+
- better support for Light and Dark themes in the "Status" column
9+
610
### Fixed
711

812
- left panel is no longer visible when a new connection is triggered from Coder's "Recent Workspaces" panel.
@@ -31,8 +35,6 @@
3135
### Added
3236
- support for Gateway 2022.2
3337

34-
35-
3638
### Changed
3739
- Java 17 is now required to run the plugin
3840
- adapted the code to the new SSH API provided by Gateway

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
pluginGroup=com.coder.gateway
44
pluginName=coder-gateway
55
# SemVer format -> https://semver.org
6-
pluginVersion=2.0.1
6+
pluginVersion=2.0.2
77
# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
88
# for insight into build numbers and IntelliJ Platform versions.
99
pluginSinceBuild=222.3739.24

src/main/kotlin/com/coder/gateway/CoderGatewayConnectionProvider.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import java.time.format.DateTimeFormatter
3030

3131
class CoderGatewayConnectionProvider : GatewayConnectionProvider {
3232
private val recentConnectionsService = service<CoderRecentWorkspaceConnectionsService>()
33-
private val sshConfigService = service<SshConfigManager>()
3433

3534
private val connections = mutableSetOf<CoderConnectionMetadata>()
3635
private val localTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MMM-dd HH:mm")

src/main/kotlin/com/coder/gateway/models/WorkspaceAgentModel.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ import com.coder.gateway.sdk.v2.models.WorkspaceBuildTransition
88
data class WorkspaceAgentModel(
99
val name: String,
1010
val templateName: String,
11-
12-
val jobStatus: ProvisionerJobStatus,
13-
val buildTransition: WorkspaceBuildTransition,
14-
11+
val agentStatus: WorkspaceAgentStatus,
1512
val agentOS: OS?,
1613
val agentArch: Arch?,
1714
val homeDirectory: String?
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.coder.gateway.models
2+
3+
import com.coder.gateway.sdk.v2.models.ProvisionerJobStatus
4+
import com.coder.gateway.sdk.v2.models.Workspace
5+
import com.coder.gateway.sdk.v2.models.WorkspaceBuildTransition
6+
7+
enum class WorkspaceAgentStatus(val label: String) {
8+
QUEUED("◍ Queued"), STARTING("⦿ Starting"), STOPPING("◍ Stopping"), DELETING("⦸ Deleting"),
9+
RUNNING("⦿ Running"), STOPPED("◍ Stopped"), DELETED("⦸ Deleted"),
10+
CANCELING("◍ Canceling action"), CANCELED("◍ Canceled action"), FAILED("ⓧ Failed");
11+
12+
companion object {
13+
fun from(workspace: Workspace) = when (workspace.latestBuild.job.status) {
14+
ProvisionerJobStatus.PENDING -> QUEUED
15+
ProvisionerJobStatus.RUNNING -> when (workspace.latestBuild.workspaceTransition) {
16+
WorkspaceBuildTransition.START -> STARTING
17+
WorkspaceBuildTransition.STOP -> STOPPING
18+
WorkspaceBuildTransition.DELETE -> DELETING
19+
}
20+
21+
ProvisionerJobStatus.SUCCEEDED -> when (workspace.latestBuild.workspaceTransition) {
22+
WorkspaceBuildTransition.START -> RUNNING
23+
WorkspaceBuildTransition.STOP -> STOPPED
24+
WorkspaceBuildTransition.DELETE -> DELETED
25+
}
26+
27+
ProvisionerJobStatus.CANCELING -> CANCELING
28+
ProvisionerJobStatus.CANCELED -> CANCELED
29+
ProvisionerJobStatus.FAILED -> FAILED
30+
}
31+
}
32+
}

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

Lines changed: 53 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import com.coder.gateway.CoderGatewayBundle
44
import com.coder.gateway.icons.CoderIcons
55
import com.coder.gateway.models.CoderWorkspacesWizardModel
66
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
712
import com.coder.gateway.sdk.Arch
813
import com.coder.gateway.sdk.CoderCLIManager
914
import com.coder.gateway.sdk.CoderRestClientService
@@ -28,6 +33,7 @@ import com.intellij.openapi.progress.Task
2833
import com.intellij.openapi.ui.panel.ComponentPanelBuilder
2934
import com.intellij.openapi.wm.impl.welcomeScreen.WelcomeScreenUIManager
3035
import com.intellij.ui.AppIcon
36+
import com.intellij.ui.JBColor
3137
import com.intellij.ui.components.JBTextField
3238
import com.intellij.ui.components.dialog
3339
import 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

Comments
 (0)