@@ -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.Job
2829import kotlinx.coroutines.delay
@@ -78,7 +79,7 @@ class CoderRemoteEnvironment(
7879 fun asPairOfWorkspaceAndAgent (): Pair <Workspace , WorkspaceAgent > = Pair (workspace, agent)
7980
8081 private fun getAvailableActions (): List <ActionDescription > {
81- val actions = mutableListOf<Action >()
82+ val actions = mutableListOf<ActionDescription >()
8283 if (wsRawStatus.canStop()) {
8384 actions.add(Action (context.i18n.ptrl(" Open web terminal" )) {
8485 context.cs.launch {
@@ -143,6 +144,24 @@ class CoderRemoteEnvironment(
143144 }
144145 })
145146 }
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+ })
146165 return actions
147166 }
148167
@@ -272,43 +291,32 @@ class CoderRemoteEnvironment(
272291 return false
273292 }
274293
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 )
285295
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+ }
295304
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)
306314 }
307315 }
308316 }
309- } catch (e: APIResponseException ) {
310- context.ui.showErrorInfoPopup(e)
311317 }
318+ } catch (e: APIResponseException ) {
319+ context.ui.showErrorInfoPopup(e)
312320 }
313321 }
314322
0 commit comments