Skip to content

Commit a70a32b

Browse files
committed
Extract ready logic to WorkspaceAndAgentStatus
1 parent 596934c commit a70a32b

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ enum class WorkspaceAndAgentStatus(val label: String, val description: String) {
4747
else -> if (JBColor.isBright()) JBColor.LIGHT_GRAY else JBColor.DARK_GRAY
4848
}
4949

50+
/**
51+
* Return true if the agent is in a connectable state.
52+
*/
53+
fun ready(): Boolean {
54+
return listOf(READY, START_ERROR, AGENT_STARTING_READY, START_TIMEOUT_READY)
55+
.contains(this)
56+
}
57+
5058
// We want to check that the workspace is `running`, the agent is
5159
// `connected`, and the agent lifecycle state is `ready` to ensure the best
5260
// possible scenario for attempting a connection.

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,8 @@ class CoderWorkspacesStepView(val setNextButtonEnabled: (Boolean) -> Unit) : Cod
132132
setEmptyState("Disconnected")
133133
setSelectionMode(ListSelectionModel.SINGLE_SELECTION)
134134
selectionModel.addListSelectionListener {
135-
val ready = listOf(
136-
WorkspaceAndAgentStatus.READY,
137-
WorkspaceAndAgentStatus.START_ERROR,
138-
WorkspaceAndAgentStatus.AGENT_STARTING_READY,
139-
WorkspaceAndAgentStatus.START_TIMEOUT_READY,
140-
).contains(selectedObject?.agentStatus)
141-
setNextButtonEnabled(ready && selectedObject?.agentOS == OS.LINUX)
142-
if (ready && selectedObject?.agentOS != OS.LINUX) {
135+
setNextButtonEnabled(selectedObject?.agentStatus?.ready() == true && selectedObject?.agentOS == OS.LINUX)
136+
if (selectedObject?.agentStatus?.ready() == true && selectedObject?.agentOS != OS.LINUX) {
143137
notificationBanner.apply {
144138
component.isVisible = true
145139
showInfo(CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.unsupported.os.info"))

0 commit comments

Comments
 (0)