Skip to content

Commit b24a324

Browse files
authored
fix: override default delete confirmation dialog (#61)
- right now there are two confirmation dialogs when removing a workspace from Toolbox - with this patch we force Toolbox to discard its default dialog and show a custom one with the Coder titles and messages. - resolves #60
1 parent 2ce2aa1 commit b24a324

File tree

4 files changed

+33
-46
lines changed

4 files changed

+33
-46
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Fixed
66

77
- SSH config is regenerated correctly when Workspaces are added or removed
8+
- only one confirmation dialog is shown when removing a Workspace
89

910
## 0.1.0 - 2025-04-01
1011

src/main/kotlin/com/coder/toolbox/CoderRemoteEnvironment.kt

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import com.coder.toolbox.sdk.v2.models.WorkspaceAgent
99
import com.coder.toolbox.util.withPath
1010
import com.coder.toolbox.views.Action
1111
import com.coder.toolbox.views.EnvironmentView
12+
import com.jetbrains.toolbox.api.remoteDev.DeleteEnvironmentConfirmationParams
1213
import com.jetbrains.toolbox.api.remoteDev.EnvironmentVisibilityState
1314
import com.jetbrains.toolbox.api.remoteDev.RemoteProviderEnvironment
1415
import com.jetbrains.toolbox.api.remoteDev.environments.EnvironmentContentsView
@@ -149,42 +150,42 @@ class CoderRemoteEnvironment(
149150
}
150151
}
151152

153+
override fun getDeleteEnvironmentConfirmationParams(): DeleteEnvironmentConfirmationParams? {
154+
return object : DeleteEnvironmentConfirmationParams {
155+
override val cancelButtonText: String = "Cancel"
156+
override val confirmButtonText: String = "Delete"
157+
override val message: String =
158+
if (wsRawStatus.canStop()) "Workspace will be closed and all the information will be lost, including all files, unsaved changes, historical info and usage data."
159+
else "All the information in this workspace will be lost, including all files, unsaved changes, historical info and usage data."
160+
override val title: String = if (wsRawStatus.canStop()) "Delete running workspace?" else "Delete workspace?"
161+
}
162+
}
163+
152164
override fun onDelete() {
153165
context.cs.launch {
154-
val shouldDelete = if (wsRawStatus.canStop()) {
155-
context.ui.showOkCancelPopup(
156-
context.i18n.ptrl("Delete running workspace?"),
157-
context.i18n.ptrl("Workspace will be closed and all the information in this workspace will be lost, including all files, unsaved changes and historical."),
158-
context.i18n.ptrl("Delete"),
159-
context.i18n.ptrl("Cancel")
160-
)
161-
} else {
162-
context.ui.showOkCancelPopup(
163-
context.i18n.ptrl("Delete workspace?"),
164-
context.i18n.ptrl("All the information in this workspace will be lost, including all files, unsaved changes and historical."),
165-
context.i18n.ptrl("Delete"),
166-
context.i18n.ptrl("Cancel")
167-
)
168-
}
169-
if (shouldDelete) {
170-
try {
171-
client.removeWorkspace(workspace)
172-
context.cs.launch {
173-
withTimeout(5.minutes) {
174-
var workspaceStillExists = true
175-
while (context.cs.isActive && workspaceStillExists) {
176-
if (wsRawStatus == WorkspaceAndAgentStatus.DELETING || wsRawStatus == WorkspaceAndAgentStatus.DELETED) {
177-
workspaceStillExists = false
178-
context.envPageManager.showPluginEnvironmentsPage()
179-
} else {
180-
delay(1.seconds)
181-
}
166+
try {
167+
client.removeWorkspace(workspace)
168+
// mark the env as deleting otherwise we will have to
169+
// wait for the poller to update the status in the next 5 seconds
170+
state.update {
171+
WorkspaceAndAgentStatus.DELETING.toRemoteEnvironmentState(context)
172+
}
173+
174+
context.cs.launch {
175+
withTimeout(5.minutes) {
176+
var workspaceStillExists = true
177+
while (context.cs.isActive && workspaceStillExists) {
178+
if (wsRawStatus == WorkspaceAndAgentStatus.DELETING || wsRawStatus == WorkspaceAndAgentStatus.DELETED) {
179+
workspaceStillExists = false
180+
context.envPageManager.showPluginEnvironmentsPage()
181+
} else {
182+
delay(1.seconds)
182183
}
183184
}
184185
}
185-
} catch (e: APIResponseException) {
186-
context.ui.showErrorInfoPopup(e)
187186
}
187+
} catch (e: APIResponseException) {
188+
context.ui.showErrorInfoPopup(e)
188189
}
189190
}
190191
}

src/main/kotlin/com/coder/toolbox/CoderRemoteProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class CoderRemoteProvider(
131131
}
132132
lastEnvironments.apply {
133133
clear()
134-
addAll(resolvedEnvironments)
134+
addAll(resolvedEnvironments.sortedBy { it.id })
135135
}
136136
} catch (_: CancellationException) {
137137
context.logger.debug("${client.url} polling loop canceled")

src/main/resources/localization/defaultMessages.po

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,9 @@ msgstr ""
2828
msgid "Save"
2929
msgstr ""
3030

31-
msgid "Delete"
32-
msgstr ""
33-
3431
msgid "Cancel"
3532
msgstr ""
3633

37-
msgid "Delete running workspace?"
38-
msgstr ""
39-
40-
msgid "Delete workspace?"
41-
msgstr ""
42-
43-
msgid "Workspace will be closed and all the information in this workspace will be lost, including all files, unsaved changes and historical."
44-
msgstr ""
45-
46-
msgid "All the information in this workspace will be lost, including all files, unsaved changes and historical."
47-
msgstr ""
48-
4934
msgid "Session Token"
5035
msgstr ""
5136

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy