@@ -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.Job
28
29
import kotlinx.coroutines.delay
@@ -78,7 +79,7 @@ class CoderRemoteEnvironment(
78
79
fun asPairOfWorkspaceAndAgent (): Pair <Workspace , WorkspaceAgent > = Pair (workspace, agent)
79
80
80
81
private fun getAvailableActions (): List <ActionDescription > {
81
- val actions = mutableListOf<Action >()
82
+ val actions = mutableListOf<ActionDescription >()
82
83
if (wsRawStatus.canStop()) {
83
84
actions.add(Action (context.i18n.ptrl(" Open web terminal" )) {
84
85
context.cs.launch {
@@ -143,6 +144,24 @@ class CoderRemoteEnvironment(
143
144
}
144
145
})
145
146
}
147
+ actions.add(CoderDelimiter (context.i18n.pnotr(" " )))
148
+ actions.add(Action (context.i18n.ptrl(" Delete workspace" )) {
149
+ context.cs.launch {
150
+ val confirmation = context.ui.showTextInputPopup(
151
+ if (wsRawStatus.canStop()) context.i18n.ptrl(" Delete running workspace?" ) else context.i18n.ptrl(" Delete workspace?" ),
152
+ if (wsRawStatus.canStop()) context.i18n.ptrl(" This will close the workspace and remove all its information, including files, unsaved changes, history, and usage data." )
153
+ else context.i18n.ptrl(" This will remove all information from the workspace, including files, unsaved changes, history, and usage data." ),
154
+ context.i18n.ptrl(" Workspace name" ),
155
+ TextType .General ,
156
+ context.i18n.ptrl(" OK" ),
157
+ context.i18n.ptrl(" Cancel" )
158
+ )
159
+ if (confirmation != workspace.name) {
160
+ return @launch
161
+ }
162
+ deleteWorkspace()
163
+ }
164
+ })
146
165
return actions
147
166
}
148
167
@@ -272,43 +291,32 @@ class CoderRemoteEnvironment(
272
291
return false
273
292
}
274
293
275
- override fun getDeleteEnvironmentConfirmationParams (): DeleteEnvironmentConfirmationParams ? {
276
- return object : DeleteEnvironmentConfirmationParams {
277
- override val cancelButtonText: String = " Cancel"
278
- override val confirmButtonText: String = " Delete"
279
- override val message: String =
280
- if (wsRawStatus.canStop()) " This will close the workspace and remove all its information, including files, unsaved changes, history, and usage data."
281
- else " This will remove all information from the workspace, including files, unsaved changes, history, and usage data."
282
- override val title: String = if (wsRawStatus.canStop()) " Delete running workspace?" else " Delete workspace?"
283
- }
284
- }
294
+ override val deleteActionFlow: StateFlow < (() -> Unit )? > = MutableStateFlow (null )
285
295
286
- override val deleteActionFlow: StateFlow < (() -> Unit )? > = MutableStateFlow {
287
- context.cs.launch {
288
- try {
289
- client.removeWorkspace(workspace)
290
- // mark the env as deleting otherwise we will have to
291
- // wait for the poller to update the status in the next 5 seconds
292
- state.update {
293
- WorkspaceAndAgentStatus .DELETING .toRemoteEnvironmentState(context)
294
- }
296
+ suspend fun deleteWorkspace () {
297
+ try {
298
+ client.removeWorkspace(workspace)
299
+ // mark the env as deleting otherwise we will have to
300
+ // wait for the poller to update the status in the next 5 seconds
301
+ state.update {
302
+ WorkspaceAndAgentStatus .DELETING .toRemoteEnvironmentState(context)
303
+ }
295
304
296
- context.cs.launch {
297
- withTimeout(5 .minutes) {
298
- var workspaceStillExists = true
299
- while (context.cs.isActive && workspaceStillExists) {
300
- if (wsRawStatus == WorkspaceAndAgentStatus .DELETING || wsRawStatus == WorkspaceAndAgentStatus .DELETED ) {
301
- workspaceStillExists = false
302
- context.envPageManager.showPluginEnvironmentsPage()
303
- } else {
304
- delay(1 .seconds)
305
- }
305
+ context.cs.launch {
306
+ withTimeout(5 .minutes) {
307
+ var workspaceStillExists = true
308
+ while (context.cs.isActive && workspaceStillExists) {
309
+ if (wsRawStatus == WorkspaceAndAgentStatus .DELETING || wsRawStatus == WorkspaceAndAgentStatus .DELETED ) {
310
+ workspaceStillExists = false
311
+ context.envPageManager.showPluginEnvironmentsPage()
312
+ } else {
313
+ delay(1 .seconds)
306
314
}
307
315
}
308
316
}
309
- } catch (e: APIResponseException ) {
310
- context.ui.showErrorInfoPopup(e)
311
317
}
318
+ } catch (e: APIResponseException ) {
319
+ context.ui.showErrorInfoPopup(e)
312
320
}
313
321
}
314
322
0 commit comments