Skip to content

Commit 7cd80fb

Browse files
committed
disable link when appropriate and show loading states
1 parent 6aeb88d commit 7cd80fb

File tree

2 files changed

+25
-24
lines changed

2 files changed

+25
-24
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import com.coder.gateway.models.WorkspaceProjectIDE
77
import com.coder.gateway.models.toIdeWithStatus
88
import com.coder.gateway.models.toRawString
99
import com.coder.gateway.models.withWorkspaceProject
10+
import com.coder.gateway.sdk.CoderRestClient
11+
import com.coder.gateway.sdk.v2.models.Workspace
12+
import com.coder.gateway.sdk.v2.models.WorkspaceStatus
1013
import com.coder.gateway.services.CoderRecentWorkspaceConnectionsService
1114
import com.coder.gateway.services.CoderSettingsService
1215
import com.coder.gateway.util.SemVer
@@ -65,6 +68,7 @@ class CoderRemoteConnectionHandle {
6568
private val localTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MMM-dd HH:mm")
6669

6770
fun connect(getParameters: (indicator: ProgressIndicator) -> WorkspaceProjectIDE) {
71+
6872
val clientLifetime = LifetimeDefinition()
6973
clientLifetime.launchUnderBackgroundProgress(CoderGatewayBundle.message("gateway.connector.coder.connection.provider.title")) {
7074
try {

src/main/kotlin/com/coder/gateway/views/CoderGatewayRecentWorkspaceConnectionsView.kt

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -203,38 +203,35 @@ class CoderGatewayRecentWorkspaceConnectionsView(private val setContentCallback:
203203
foreground = UIUtil.getContextHelpForeground()
204204
font = ComponentPanelBuilder.getCommentFont(font)
205205
}
206-
label("").resizableColumn().align(AlignX.FILL) }.topGap(gap)
206+
label("").resizableColumn().align(AlignX.FILL)
207+
}.topGap(gap)
207208

208-
row { label("Select a project to launch.") }
209209
connections.forEach { workspaceProjectIDE ->
210+
val enableLinks = listOf(WorkspaceStatus.STOPPED, WorkspaceStatus.CANCELED, WorkspaceStatus.FAILED, WorkspaceStatus.STARTING, WorkspaceStatus.RUNNING).contains(workspaceWithAgent?.workspace?.latestBuild?.status)
211+
val inLoadingState = listOf(WorkspaceStatus.STARTING, WorkspaceStatus.CANCELING, WorkspaceStatus.DELETING, WorkspaceStatus.STOPPING).contains(workspaceWithAgent?.workspace?.latestBuild?.status)
210212

211213
val actionLink = ActionLink(workspaceProjectIDE.projectPathDisplay) {
212-
if (workspaceWithAgent?.workspace?.latestBuild?.status == WorkspaceStatus.RUNNING && workspaceWithAgent.status == WorkspaceAndAgentStatus.READY) {
213-
CoderRemoteConnectionHandle().connect { workspaceProjectIDE }
214-
GatewayUI.getInstance().reset()
215-
} else {
216-
// Start the workspace
217-
withoutNull(workspaceWithAgent?.workspace, deployment?.client) { workspace, client ->
218-
jobs[workspace.id]?.cancel()
219-
jobs[workspace.id] =
220-
cs.launch(ModalityState.current().asContextElement()) {
221-
withContext(Dispatchers.IO) {
222-
try {
223-
client.startWorkspace(workspace)
224-
fetchWorkspaces()
225-
} catch (e: Exception) {
226-
logger.error("Could not start workspace ${workspace.name}", e)
227-
}
228-
}
229-
}
230-
cs.launch {
231-
jobs[workspace.id]?.join()
232-
CoderRemoteConnectionHandle().connect { workspaceProjectIDE }
233-
GatewayUI.getInstance().reset()
214+
withoutNull(deployment?.client, workspaceWithAgent?.workspace) { client, workspace ->
215+
CoderRemoteConnectionHandle().connect {
216+
if (listOf(WorkspaceStatus.STOPPED, WorkspaceStatus.CANCELED, WorkspaceStatus.FAILED).contains(workspace.latestBuild.status)) {
217+
client.startWorkspace(workspace)
234218
}
219+
workspaceProjectIDE
235220
}
221+
GatewayUI.getInstance().reset()
222+
}
223+
}
236224

225+
if (!enableLinks) {
226+
actionLink.foreground = Color.GRAY
227+
actionLink.actionListeners.forEach { actionLink.removeActionListener(it) }
228+
}
229+
230+
row {
231+
if (inLoadingState) {
232+
icon(AnimatedIcon.Default())
237233
}
234+
label(workspaceWithAgent?.status?.description.orEmpty())
238235
}
239236

240237
row {

0 commit comments

Comments
 (0)