@@ -12,17 +12,18 @@ import com.coder.toolbox.sdk.v2.models.WorkspaceAgent
1212import com.coder.toolbox.util.waitForFalseWithTimeout
1313import com.coder.toolbox.util.withPath
1414import com.coder.toolbox.views.Action
15+ import com.coder.toolbox.views.CoderDelimiter
1516import com.coder.toolbox.views.EnvironmentView
1617import com.jetbrains.toolbox.api.localization.LocalizableString
1718import com.jetbrains.toolbox.api.remoteDev.AfterDisconnectHook
1819import com.jetbrains.toolbox.api.remoteDev.BeforeConnectionHook
19- import com.jetbrains.toolbox.api.remoteDev.DeleteEnvironmentConfirmationParams
2020import com.jetbrains.toolbox.api.remoteDev.EnvironmentVisibilityState
2121import com.jetbrains.toolbox.api.remoteDev.RemoteProviderEnvironment
2222import com.jetbrains.toolbox.api.remoteDev.environments.EnvironmentContentsView
2323import com.jetbrains.toolbox.api.remoteDev.states.EnvironmentDescription
2424import com.jetbrains.toolbox.api.remoteDev.states.RemoteEnvironmentState
2525import com.jetbrains.toolbox.api.ui.actions.ActionDescription
26+ import com.jetbrains.toolbox.api.ui.components.TextType
2627import com.squareup.moshi.Moshi
2728import kotlinx.coroutines.CoroutineName
2829import kotlinx.coroutines.Job
@@ -79,7 +80,7 @@ class CoderRemoteEnvironment(
7980 fun asPairOfWorkspaceAndAgent (): Pair <Workspace , WorkspaceAgent > = Pair (workspace, agent)
8081
8182 private fun getAvailableActions (): List <ActionDescription > {
82- val actions = mutableListOf<Action >()
83+ val actions = mutableListOf<ActionDescription >()
8384 if (wsRawStatus.canStop()) {
8485 actions.add(Action (context, " Open web terminal" ) {
8586 context.desktop.browse(client.url.withPath(" /${workspace.ownerName} /$name /terminal" ).toString()) {
@@ -137,6 +138,28 @@ class CoderRemoteEnvironment(
137138 }
138139 )
139140 }
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+ })
140163 return actions
141164 }
142165
@@ -266,43 +289,32 @@ class CoderRemoteEnvironment(
266289 return false
267290 }
268291
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 )
279293
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+ }
289302
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)
300312 }
301313 }
302314 }
303- } catch (e: APIResponseException ) {
304- context.ui.showErrorInfoPopup(e)
305315 }
316+ } catch (e: APIResponseException ) {
317+ context.ui.showErrorInfoPopup(e)
306318 }
307319 }
308320
0 commit comments