Skip to content

Commit eb89d2c

Browse files
committed
Fix: enable or disable the workspace actions depending on the workspace state
1 parent cce4f39 commit eb89d2c

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

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

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import com.coder.gateway.models.CoderWorkspacesWizardModel
66
import com.coder.gateway.models.WorkspaceAgentModel
77
import com.coder.gateway.models.WorkspaceAgentStatus
88
import com.coder.gateway.models.WorkspaceAgentStatus.DELETING
9+
import com.coder.gateway.models.WorkspaceAgentStatus.FAILED
910
import com.coder.gateway.models.WorkspaceAgentStatus.RUNNING
1011
import com.coder.gateway.models.WorkspaceAgentStatus.STARTING
12+
import com.coder.gateway.models.WorkspaceAgentStatus.STOPPED
1113
import com.coder.gateway.models.WorkspaceAgentStatus.STOPPING
1214
import com.coder.gateway.models.WorkspaceVersionStatus
1315
import com.coder.gateway.sdk.Arch
@@ -19,8 +21,6 @@ import com.coder.gateway.sdk.getOS
1921
import com.coder.gateway.sdk.toURL
2022
import com.coder.gateway.sdk.v2.models.Workspace
2123
import com.coder.gateway.sdk.withPath
22-
import com.intellij.CommonBundle
23-
import com.intellij.icons.AllIcons
2424
import com.intellij.ide.BrowserUtil
2525
import com.intellij.ide.IdeBundle
2626
import com.intellij.openapi.Disposable
@@ -81,7 +81,11 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
8181
WorkspaceNameColumnInfo("Name"),
8282
WorkspaceTemplateNameColumnInfo("Template"),
8383
WorkspaceVersionColumnInfo("Version"),
84-
WorkspaceStatusColumnInfo("Status"))
84+
WorkspaceStatusColumnInfo("Status")
85+
)
86+
87+
private val startWorkspaceAction = StartWorkspaceAction()
88+
private val stopWorkspaceAction = StopWorkspaceAction()
8589

8690
private var tableOfWorkspaces = TableView(listTableModelOfWorkspaces).apply {
8791
setEnableAntialiasing(true)
@@ -98,16 +102,30 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
98102
setSelectionMode(ListSelectionModel.SINGLE_SELECTION)
99103
selectionModel.addListSelectionListener {
100104
enableNextButtonCallback(selectedObject != null && selectedObject?.agentStatus == RUNNING)
101-
}
105+
when (selectedObject?.agentStatus) {
106+
RUNNING -> {
107+
startWorkspaceAction.isEnabled = false
108+
stopWorkspaceAction.isEnabled = true
109+
}
102110

111+
STOPPED, FAILED -> {
112+
startWorkspaceAction.isEnabled = true
113+
stopWorkspaceAction.isEnabled = false
114+
}
115+
116+
else -> {
117+
disableAllWorkspaceActions()
118+
}
119+
}
120+
}
103121
}
104-
122+
105123
private val toolbar = ToolbarDecorator.createDecorator(tableOfWorkspaces)
106124
.disableAddAction()
107125
.disableRemoveAction()
108126
.disableUpDownActions()
109-
.addExtraAction(StartWorkspaceAction())
110-
.addExtraAction(StopWorkspaceAction())
127+
.addExtraAction(startWorkspaceAction)
128+
.addExtraAction(stopWorkspaceAction)
111129

112130
private var poller: Job? = null
113131

@@ -163,8 +181,14 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
163181
}
164182
}
165183

184+
private fun disableAllWorkspaceActions() {
185+
startWorkspaceAction.isEnabled = false
186+
stopWorkspaceAction.isEnabled = false
187+
}
188+
166189
override fun onInit(wizardModel: CoderWorkspacesWizardModel) {
167190
enableNextButtonCallback(false)
191+
disableAllWorkspaceActions()
168192
}
169193

170194
private fun loginAndLoadWorkspace() {

0 commit comments

Comments
 (0)