Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
335061a
build: rename project to coder-toolbox
fioan89 Feb 18, 2025
4fe83ce
chore: update license
fioan89 Feb 18, 2025
7151981
import code from coder/jetbrains-coder
fioan89 Feb 18, 2025
36fba63
fix: remove Gateway string from title
fioan89 Feb 18, 2025
e39cd05
impl: initial support for opening urls
fioan89 Feb 19, 2025
94a6ff3
fix: use new URL opener
fioan89 Feb 19, 2025
915d347
chore: replaces references to Gateway with Toolbox
fioan89 Feb 19, 2025
5973b0d
impl: go to main page after signing in
fioan89 Feb 20, 2025
b031c65
fix: connection status rendering
fioan89 Feb 20, 2025
8faed95
fix: url glitch on new environment page
fioan89 Feb 20, 2025
90d199c
impl: read plugin version from the extension.json
fioan89 Feb 21, 2025
38e3e2b
fix: user agent did not have a proper version
fioan89 Feb 21, 2025
33b4a60
Merge branch 'main' into fix-connection-issues
fioan89 Feb 24, 2025
383ee49
build: upgrade plugin api dependencies to 0.7.2.6.0.38311
fioan89 Feb 24, 2025
7a6b512
build: upgrade kotlin dependencies
fioan89 Feb 24, 2025
aa24f03
fix: compiler errors (1)
fioan89 Feb 24, 2025
3023aea
fix: compiler errors (2)
fioan89 Feb 24, 2025
ce35939
fix: compiler errors (3)
fioan89 Feb 25, 2025
500d397
fix: message logging
fioan89 Feb 25, 2025
2d69d5e
Merge branch 'main' into support-for-toolbox-2_6_0_38311
fioan89 Feb 26, 2025
b025c64
impl: initial stubs for removing a workspace
fioan89 Feb 26, 2025
9f059a4
impl: support for removing the workspace
fioan89 Feb 27, 2025
3e7edda
Merge branch 'main' into support-for-deleting-workspaces
fioan89 Feb 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions src/main/kotlin/com/coder/toolbox/CoderRemoteEnvironment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class CoderRemoteEnvironment(
},
)
actionsList.add(
Action("Stop", enabled = { status.ready() || status.pending() }) {
Action("Stop", enabled = { status.canStop() }) {
val build = client.stopWorkspace(workspace)
workspace = workspace.copy(latestBuild = build)
update(workspace, agent)
Expand Down Expand Up @@ -128,7 +128,32 @@ class CoderRemoteEnvironment(
}

override fun onDelete() {
throw NotImplementedError()
cs.launch {
// TODO info and cancel pop-ups only appear on the main page where all environments are listed.
// However, #showSnackbar works on other pages. Until JetBrains fixes this issue we are going to use the snackbar
val shouldDelete = if (status.canStop()) {
ui.showOkCancelPopup(
"Delete running workspace?",
"Workspace will be closed and all the information in this workspace will be lost, including all files, unsaved changes and historical.",
"Delete",
"Cancel"
)
} else {
ui.showOkCancelPopup(
"Delete workspace?",
"All the information in this workspace will be lost, including all files, unsaved changes and historical.",
"Delete",
"Cancel"
)
}
if (shouldDelete) {
if (status.canStop()) {
client.stopWorkspace(workspace)
}

client.removeWorkspace(workspace)
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ enum class WorkspaceAndAgentStatus(val label: String, val description: String) {
fun canStart(): Boolean = listOf(STOPPED, FAILED, CANCELED)
.contains(this)

/**
* Return true if the workspace can be stopped.
*/
fun canStop(): Boolean = ready() || pending()

// We want to check that the workspace is `running`, the agent is
// `connected`, and the agent lifecycle state is `ready` to ensure the best
// possible scenario for attempting a connection.
Expand Down
14 changes: 12 additions & 2 deletions src/main/kotlin/com/coder/toolbox/sdk/CoderRestClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import retrofit2.converter.moshi.MoshiConverterFactory
import java.net.HttpURLConnection
import java.net.ProxySelector
import java.net.URL
import java.util.*
import java.util.UUID
import javax.net.ssl.X509TrustManager

/**
Expand Down Expand Up @@ -229,7 +229,6 @@ open class CoderRestClient(
}

/**
* @throws [APIResponseException].
*/
fun stopWorkspace(workspace: Workspace): WorkspaceBuild {
val buildRequest = CreateWorkspaceBuildRequest(null, WorkspaceTransition.STOP)
Expand All @@ -240,6 +239,17 @@ open class CoderRestClient(
return buildResponse.body()!!
}

/**
* @throws [APIResponseException] if issues are encountered during deletion
*/
fun removeWorkspace(workspace: Workspace) {
val buildRequest = CreateWorkspaceBuildRequest(null, WorkspaceTransition.DELETE, false)
val buildResponse = retroRestClient.createWorkspaceBuild(workspace.id, buildRequest).execute()
if (buildResponse.code() != HttpURLConnection.HTTP_CREATED) {
throw APIResponseException("delete workspace ${workspace.name}", url, buildResponse)
}
}

/**
* Start the workspace with the latest template version. Best practice is
* to STOP a workspace before doing an update if it is started.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import java.util.UUID
data class CreateWorkspaceBuildRequest(
// Use to update the workspace to a new template version.
@Json(name = "template_version_id") val templateVersionID: UUID?,
// Use to start and stop the workspace.
// Use to start, stop and delete the workspace.
@Json(name = "transition") val transition: WorkspaceTransition,
@Json(name = "orphan") var orphan: Boolean? = null
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
Expand Down