Thanks to visit codestin.com
Credit goes to github.com

Skip to content

revise recent projects flow to be less confusing #464

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Aug 19, 2024
Prev Previous commit
Next Next commit
disable link when appropriate and show loading states
  • Loading branch information
bcpeinhardt committed Aug 16, 2024
commit 7cd80fb0aac118dff8574eed1a5bc67b3f0e135a
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import com.coder.gateway.models.toIdeWithStatus
import com.coder.gateway.models.toRawString
import com.coder.gateway.models.withWorkspaceProject
import com.coder.gateway.sdk.CoderRestClient

Check warning on line 10 in src/main/kotlin/com/coder/gateway/CoderRemoteConnectionHandle.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import directive

Unused import directive
import com.coder.gateway.sdk.v2.models.Workspace

Check warning on line 11 in src/main/kotlin/com/coder/gateway/CoderRemoteConnectionHandle.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import directive

Unused import directive
import com.coder.gateway.sdk.v2.models.WorkspaceStatus

Check warning on line 12 in src/main/kotlin/com/coder/gateway/CoderRemoteConnectionHandle.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import directive

Unused import directive
import com.coder.gateway.services.CoderRecentWorkspaceConnectionsService
import com.coder.gateway.services.CoderSettingsService
import com.coder.gateway.util.SemVer
Expand Down Expand Up @@ -65,6 +68,7 @@
private val localTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MMM-dd HH:mm")

fun connect(getParameters: (indicator: ProgressIndicator) -> WorkspaceProjectIDE) {

val clientLifetime = LifetimeDefinition()
clientLifetime.launchUnderBackgroundProgress(CoderGatewayBundle.message("gateway.connector.coder.connection.provider.title")) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.coder.gateway.CoderRemoteConnectionHandle
import com.coder.gateway.icons.CoderIcons
import com.coder.gateway.models.WorkspaceAgentListModel
import com.coder.gateway.models.WorkspaceAndAgentStatus

Check warning on line 10 in src/main/kotlin/com/coder/gateway/views/CoderGatewayRecentWorkspaceConnectionsView.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import directive

Unused import directive
import com.coder.gateway.models.WorkspaceProjectIDE
import com.coder.gateway.models.toWorkspaceProjectIDE
import com.coder.gateway.sdk.CoderRestClient
Expand All @@ -18,10 +18,10 @@
import com.coder.gateway.services.CoderSettingsService
import com.coder.gateway.util.humanizeConnectionError
import com.coder.gateway.util.toURL
import com.coder.gateway.util.withPath

Check warning on line 21 in src/main/kotlin/com/coder/gateway/views/CoderGatewayRecentWorkspaceConnectionsView.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import directive

Unused import directive
import com.coder.gateway.util.withoutNull
import com.intellij.icons.AllIcons
import com.intellij.ide.BrowserUtil

Check warning on line 24 in src/main/kotlin/com/coder/gateway/views/CoderGatewayRecentWorkspaceConnectionsView.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import directive

Unused import directive
import com.intellij.openapi.Disposable
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.application.ModalityState
Expand All @@ -33,7 +33,7 @@
import com.intellij.openapi.wm.impl.welcomeScreen.WelcomeScreenUIManager
import com.intellij.ui.AnimatedIcon
import com.intellij.ui.DocumentAdapter
import com.intellij.ui.JBColor

Check warning on line 36 in src/main/kotlin/com/coder/gateway/views/CoderGatewayRecentWorkspaceConnectionsView.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import directive

Unused import directive
import com.intellij.ui.SearchTextField
import com.intellij.ui.components.ActionLink
import com.intellij.ui.components.JBScrollPane
Expand Down Expand Up @@ -203,38 +203,35 @@
foreground = UIUtil.getContextHelpForeground()
font = ComponentPanelBuilder.getCommentFont(font)
}
label("").resizableColumn().align(AlignX.FILL) }.topGap(gap)
label("").resizableColumn().align(AlignX.FILL)
}.topGap(gap)

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

val actionLink = ActionLink(workspaceProjectIDE.projectPathDisplay) {
if (workspaceWithAgent?.workspace?.latestBuild?.status == WorkspaceStatus.RUNNING && workspaceWithAgent.status == WorkspaceAndAgentStatus.READY) {
CoderRemoteConnectionHandle().connect { workspaceProjectIDE }
GatewayUI.getInstance().reset()
} else {
// Start the workspace
withoutNull(workspaceWithAgent?.workspace, deployment?.client) { workspace, client ->
jobs[workspace.id]?.cancel()
jobs[workspace.id] =
cs.launch(ModalityState.current().asContextElement()) {
withContext(Dispatchers.IO) {
try {
client.startWorkspace(workspace)
fetchWorkspaces()
} catch (e: Exception) {
logger.error("Could not start workspace ${workspace.name}", e)
}
}
}
cs.launch {
jobs[workspace.id]?.join()
CoderRemoteConnectionHandle().connect { workspaceProjectIDE }
GatewayUI.getInstance().reset()
withoutNull(deployment?.client, workspaceWithAgent?.workspace) { client, workspace ->
CoderRemoteConnectionHandle().connect {
if (listOf(WorkspaceStatus.STOPPED, WorkspaceStatus.CANCELED, WorkspaceStatus.FAILED).contains(workspace.latestBuild.status)) {
client.startWorkspace(workspace)
}
workspaceProjectIDE
}
GatewayUI.getInstance().reset()
}
}

if (!enableLinks) {
actionLink.foreground = Color.GRAY
actionLink.actionListeners.forEach { actionLink.removeActionListener(it) }
}

row {
if (inLoadingState) {
icon(AnimatedIcon.Default())
}
label(workspaceWithAgent?.status?.description.orEmpty())
}

row {
Expand Down
Loading