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
make the link just start the workspace
  • Loading branch information
bcpeinhardt committed Aug 15, 2024
commit 6aeb88d2a035714265abe3a1fc7f146da59b4dc7
Original file line number Diff line number Diff line change
Expand Up @@ -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,6 +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 All @@ -57,6 +58,7 @@
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.awt.Color

Check warning on line 61 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 java.awt.Component
import java.awt.Dimension
import java.util.Locale
Expand Down Expand Up @@ -194,26 +196,24 @@
TopGap.MEDIUM
}
row {
// icon(status.first).applyToComponent {
// foreground = status.second
// }.align(AlignX.LEFT).gap(RightGap.SMALL).applyToComponent {
// size = Dimension(JBUI.scale(16), JBUI.scale(16))
// }
label(workspaceName).applyToComponent {
font = JBFont.h3().asBold()
}.align(AlignX.LEFT).gap(RightGap.SMALL)
label(deploymentURL).applyToComponent {
foreground = UIUtil.getContextHelpForeground()
font = ComponentPanelBuilder.getCommentFont(font)
}
label("").resizableColumn().align(AlignX.FILL)
actionButton(
object : DumbAwareAction(
CoderGatewayBundle.message("gateway.connector.recent-connections.start.button.tooltip"),
"",
CoderIcons.RUN,
) {
override fun actionPerformed(e: AnActionEvent) {
label("").resizableColumn().align(AlignX.FILL) }.topGap(gap)

row { label("Select a project to launch.") }
connections.forEach { workspaceProjectIDE ->

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] =
Expand All @@ -227,78 +227,20 @@
}
}
}
cs.launch {
jobs[workspace.id]?.join()
CoderRemoteConnectionHandle().connect { workspaceProjectIDE }
GatewayUI.getInstance().reset()
}
}

}
},
).applyToComponent {
isEnabled =
listOf(
WorkspaceStatus.STOPPED,
WorkspaceStatus.FAILED,
).contains(workspaceWithAgent?.workspace?.latestBuild?.status)
}
.gap(RightGap.SMALL)
actionButton(
object : DumbAwareAction(
CoderGatewayBundle.message("gateway.connector.recent-connections.stop.button.tooltip"),
"",
CoderIcons.STOP,
) {
override fun actionPerformed(e: AnActionEvent) {
withoutNull(workspaceWithAgent?.workspace, deployment?.client) { workspace, client ->
jobs[workspace.id]?.cancel()
jobs[workspace.id] =
cs.launch(ModalityState.current().asContextElement()) {
withContext(Dispatchers.IO) {
try {
client.stopWorkspace(workspace)
fetchWorkspaces()
} catch (e: Exception) {
logger.error("Could not stop workspace ${workspace.name}", e)
}
}
}
}
}
},
).applyToComponent { isEnabled = workspaceWithAgent?.workspace?.latestBuild?.status == WorkspaceStatus.RUNNING }
.gap(RightGap.SMALL)
actionButton(
object : DumbAwareAction(
CoderGatewayBundle.message("gateway.connector.recent-connections.terminal.button.tooltip"),
"",
CoderIcons.OPEN_TERMINAL,
) {
override fun actionPerformed(e: AnActionEvent) {
withoutNull(workspaceWithAgent, deployment?.client) { ws, client ->
val link = client.url.withPath("/me/${ws.name}/terminal")
BrowserUtil.browse(link.toString())
}
}
},
)
}.topGap(gap)
if (deploymentError == null || showError) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we might want to add this check back or something similar to it. It is poorly named but basically it was making sure we only display an API error on the first workspace rather than duplicating it on each workspace (it was pretty noisy, especially since the API errors can get long).

For example, say you have 5 workspaces and your token expires, you see a message about being unauthorized and to check your token 5 times on the page.

Or we could group workspaces under a deployment heading and show the API error under the deployment heading, but that might be out of scope for this PR.

Copy link
Collaborator Author

@bcpeinhardt bcpeinhardt Aug 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like atm the moment I actually have this inside the connections.foEach loop (which makes me think with multiple WorkpaceProjectIDE combos it would render multiple times). I didn't notice because I was visually testing with one recent connection.
I'll pull it out of the loop and add the check.

^^^ My adhd is going to quickly become a driving force for building out E2E suites.

row {
// There must be a way to make this properly wrap?
if (status.first == CoderIcons.PENDING) {
icon(AnimatedIcon.Default())
}
label("<html><body style='width:350px;'>" + status.third + "</html>").applyToComponent {
foreground = status.second
}
}
}
if (workspaceWithAgent?.workspace?.latestBuild?.status == WorkspaceStatus.RUNNING && workspaceWithAgent.status == WorkspaceAndAgentStatus.READY) {
row { label("Select a project to launch.") }
connections.forEach { workspaceProjectIDE ->

row {
icon(workspaceProjectIDE.ideProduct.icon)
cell(
ActionLink(workspaceProjectIDE.projectPathDisplay) {
CoderRemoteConnectionHandle().connect { workspaceProjectIDE }
GatewayUI.getInstance().reset()
},
actionLink,
)
label("").resizableColumn().align(AlignX.FILL)
label(workspaceProjectIDE.ideName).applyToComponent {
Expand All @@ -323,7 +265,7 @@
)
}
}
}

}
}
}.apply {
Expand Down
Loading