@@ -12,17 +12,18 @@ import com.coder.toolbox.sdk.v2.models.WorkspaceAgent
12
12
import com.coder.toolbox.util.waitForFalseWithTimeout
13
13
import com.coder.toolbox.util.withPath
14
14
import com.coder.toolbox.views.Action
15
+ import com.coder.toolbox.views.CoderDelimiter
15
16
import com.coder.toolbox.views.EnvironmentView
16
17
import com.jetbrains.toolbox.api.localization.LocalizableString
17
18
import com.jetbrains.toolbox.api.remoteDev.AfterDisconnectHook
18
19
import com.jetbrains.toolbox.api.remoteDev.BeforeConnectionHook
19
- import com.jetbrains.toolbox.api.remoteDev.DeleteEnvironmentConfirmationParams
20
20
import com.jetbrains.toolbox.api.remoteDev.EnvironmentVisibilityState
21
21
import com.jetbrains.toolbox.api.remoteDev.RemoteProviderEnvironment
22
22
import com.jetbrains.toolbox.api.remoteDev.environments.EnvironmentContentsView
23
23
import com.jetbrains.toolbox.api.remoteDev.states.EnvironmentDescription
24
24
import com.jetbrains.toolbox.api.remoteDev.states.RemoteEnvironmentState
25
25
import com.jetbrains.toolbox.api.ui.actions.ActionDescription
26
+ import com.jetbrains.toolbox.api.ui.components.TextType
26
27
import com.squareup.moshi.Moshi
27
28
import kotlinx.coroutines.CoroutineName
28
29
import kotlinx.coroutines.Job
@@ -79,7 +80,7 @@ class CoderRemoteEnvironment(
79
80
fun asPairOfWorkspaceAndAgent (): Pair <Workspace , WorkspaceAgent > = Pair (workspace, agent)
80
81
81
82
private fun getAvailableActions (): List <ActionDescription > {
82
- val actions = mutableListOf<Action >()
83
+ val actions = mutableListOf<ActionDescription >()
83
84
if (wsRawStatus.canStop()) {
84
85
actions.add(Action (context, " Open web terminal" ) {
85
86
context.desktop.browse(client.url.withPath(" /${workspace.ownerName} /$name /terminal" ).toString()) {
@@ -137,6 +138,28 @@ class CoderRemoteEnvironment(
137
138
}
138
139
)
139
140
}
141
+ actions.add(CoderDelimiter (context.i18n.pnotr(" " )))
142
+ actions.add(Action (context, " Delete workspace" , highlightInRed = true ) {
143
+ context.cs.launch(CoroutineName (" Delete Workspace Action" )) {
144
+ var dialogText =
145
+ if (wsRawStatus.canStop()) " This will close the workspace and remove all its information, including files, unsaved changes, history, and usage data."
146
+ else " This will remove all information from the workspace, including files, unsaved changes, history, and usage data."
147
+ dialogText + = " \n\n Type \" ${workspace.name} \" below to confirm:"
148
+
149
+ val confirmation = context.ui.showTextInputPopup(
150
+ if (wsRawStatus.canStop()) context.i18n.ptrl(" Delete running workspace?" ) else context.i18n.ptrl(" Delete workspace?" ),
151
+ context.i18n.pnotr(dialogText),
152
+ context.i18n.ptrl(" Workspace name" ),
153
+ TextType .General ,
154
+ context.i18n.ptrl(" OK" ),
155
+ context.i18n.ptrl(" Cancel" )
156
+ )
157
+ if (confirmation != workspace.name) {
158
+ return @launch
159
+ }
160
+ deleteWorkspace()
161
+ }
162
+ })
140
163
return actions
141
164
}
142
165
@@ -266,43 +289,32 @@ class CoderRemoteEnvironment(
266
289
return false
267
290
}
268
291
269
- override fun getDeleteEnvironmentConfirmationParams (): DeleteEnvironmentConfirmationParams ? {
270
- return object : DeleteEnvironmentConfirmationParams {
271
- override val cancelButtonText: String = " Cancel"
272
- override val confirmButtonText: String = " Delete"
273
- override val message: String =
274
- if (wsRawStatus.canStop()) " Workspace will be closed and all the information will be lost, including all files, unsaved changes, historical info and usage data."
275
- else " All the information in this workspace will be lost, including all files, unsaved changes, historical info and usage data."
276
- override val title: String = if (wsRawStatus.canStop()) " Delete running workspace?" else " Delete workspace?"
277
- }
278
- }
292
+ override val deleteActionFlow: StateFlow < (() -> Unit )? > = MutableStateFlow (null )
279
293
280
- override val deleteActionFlow: StateFlow < (() -> Unit )? > = MutableStateFlow {
281
- context.cs.launch(CoroutineName (" Delete Workspace Action" )) {
282
- try {
283
- client.removeWorkspace(workspace)
284
- // mark the env as deleting otherwise we will have to
285
- // wait for the poller to update the status in the next 5 seconds
286
- state.update {
287
- WorkspaceAndAgentStatus .DELETING .toRemoteEnvironmentState(context)
288
- }
294
+ suspend fun deleteWorkspace () {
295
+ try {
296
+ client.removeWorkspace(workspace)
297
+ // mark the env as deleting otherwise we will have to
298
+ // wait for the poller to update the status in the next 5 seconds
299
+ state.update {
300
+ WorkspaceAndAgentStatus .DELETING .toRemoteEnvironmentState(context)
301
+ }
289
302
290
- context.cs.launch(CoroutineName (" Workspace Deletion Poller" )) {
291
- withTimeout(5 .minutes) {
292
- var workspaceStillExists = true
293
- while (context.cs.isActive && workspaceStillExists) {
294
- if (wsRawStatus == WorkspaceAndAgentStatus .DELETING || wsRawStatus == WorkspaceAndAgentStatus .DELETED ) {
295
- workspaceStillExists = false
296
- context.envPageManager.showPluginEnvironmentsPage()
297
- } else {
298
- delay(1 .seconds)
299
- }
303
+ context.cs.launch(CoroutineName (" Workspace Deletion Poller" )) {
304
+ withTimeout(5 .minutes) {
305
+ var workspaceStillExists = true
306
+ while (context.cs.isActive && workspaceStillExists) {
307
+ if (wsRawStatus == WorkspaceAndAgentStatus .DELETING || wsRawStatus == WorkspaceAndAgentStatus .DELETED ) {
308
+ workspaceStillExists = false
309
+ context.envPageManager.showPluginEnvironmentsPage()
310
+ } else {
311
+ delay(1 .seconds)
300
312
}
301
313
}
302
314
}
303
- } catch (e: APIResponseException ) {
304
- context.ui.showErrorInfoPopup(e)
305
315
}
316
+ } catch (e: APIResponseException ) {
317
+ context.ui.showErrorInfoPopup(e)
306
318
}
307
319
}
308
320
0 commit comments