Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit547fdea

Browse files
authored
[toolbox] Add workspace actions (#486)
You can now start, stop, and update workspaces. Since you can startworkspaces yourself now, I marked non-ready states as unreachable, whichprevents JetBrains from overriding with their own text ("disconnected"and "connected"). So now you will be able to see "stopped", "starting",and so on. For the ready states you will still see "disconnected" or"connected" unfortunately. Ideally this would be a completely separatestate displayed next to the workspace state.
1 parentc0db226 commit547fdea

File tree

6 files changed

+61
-10
lines changed

6 files changed

+61
-10
lines changed

‎src/main/kotlin/com/coder/gateway/CoderRemoteEnvironment.kt‎

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ import com.coder.gateway.models.WorkspaceAndAgentStatus
44
importcom.coder.gateway.sdk.CoderRestClient
55
importcom.coder.gateway.sdk.v2.models.Workspace
66
importcom.coder.gateway.sdk.v2.models.WorkspaceAgent
7+
importcom.coder.gateway.util.withPath
8+
importcom.coder.gateway.views.Action
79
importcom.coder.gateway.views.EnvironmentView
810
importcom.jetbrains.toolbox.gateway.AbstractRemoteProviderEnvironment
911
importcom.jetbrains.toolbox.gateway.EnvironmentVisibilityState
1012
importcom.jetbrains.toolbox.gateway.environments.EnvironmentContentsView
1113
importcom.jetbrains.toolbox.gateway.states.EnvironmentStateConsumer
1214
importcom.jetbrains.toolbox.gateway.ui.ObservablePropertiesFactory
15+
importcom.jetbrains.toolbox.gateway.ui.ToolboxUi
1316
importjava.util.concurrent.CompletableFuture
1417

1518
/**
@@ -19,18 +22,60 @@ import java.util.concurrent.CompletableFuture
1922
*/
2023
classCoderRemoteEnvironment(
2124
privatevalclient:CoderRestClient,
22-
privatevalworkspace:Workspace,
23-
privatevalagent:WorkspaceAgent,
25+
privatevarworkspace:Workspace,
26+
privatevaragent:WorkspaceAgent,
27+
privatevalui:ToolboxUi,
2428
observablePropertiesFactory:ObservablePropertiesFactory,
2529
) : AbstractRemoteProviderEnvironment(observablePropertiesFactory) {
2630
overridefungetId():String="${workspace.name}.${agent.name}"
2731
overridefungetName():String="${workspace.name}.${agent.name}"
2832
privatevar status=WorkspaceAndAgentStatus.from(workspace, agent)
2933

34+
init {
35+
actionsList.add(
36+
Action("Open web terminal") {
37+
ui.openUrl(client.url.withPath("/${workspace.ownerName}/$name/terminal").toString())
38+
},
39+
)
40+
actionsList.add(
41+
Action("Open in dashboard") {
42+
ui.openUrl(client.url.withPath("/@${workspace.ownerName}/${workspace.name}").toString())
43+
},
44+
)
45+
actionsList.add(
46+
Action("View template") {
47+
ui.openUrl(client.url.withPath("/templates/${workspace.templateName}").toString())
48+
},
49+
)
50+
actionsList.add(
51+
Action("Start", enabled= { status.canStart() }) {
52+
val build= client.startWorkspace(workspace)
53+
workspace= workspace.copy(latestBuild= build)
54+
update(workspace, agent)
55+
},
56+
)
57+
actionsList.add(
58+
Action("Stop", enabled= { status.ready()|| status.pending() }) {
59+
val build= client.stopWorkspace(workspace)
60+
workspace= workspace.copy(latestBuild= build)
61+
update(workspace, agent)
62+
},
63+
)
64+
actionsList.add(
65+
Action("Update", enabled= { workspace.outdated }) {
66+
val build= client.updateWorkspace(workspace)
67+
workspace= workspace.copy(latestBuild= build)
68+
update(workspace, agent)
69+
},
70+
)
71+
}
72+
3073
/**
3174
* Update the workspace/agent status to the listeners, if it has changed.
3275
*/
3376
funupdate(workspace:Workspace,agent:WorkspaceAgent) {
77+
this.workspace= workspace
78+
this.agent= agent
3479
val newStatus=WorkspaceAndAgentStatus.from(workspace, agent)
3580
if (newStatus!= status) {
3681
status= newStatus
@@ -58,6 +103,11 @@ class CoderRemoteEnvironment(
58103
* Immediately send the state to the listener and store for updates.
59104
*/
60105
overridefunaddStateListener(consumer:EnvironmentStateConsumer):Boolean {
106+
// TODO@JB: It would be ideal if we could have the workspace state and
107+
// the connected state listed separately, since right now the
108+
// connected state can mask the workspace state.
109+
// TODO@JB: You can still press connect if the environment is
110+
// unreachable. Is that expected?
61111
consumer.consume(status.toRemoteEnvironmentState())
62112
returnsuper.addStateListener(consumer)
63113
}

‎src/main/kotlin/com/coder/gateway/CoderRemoteProvider.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class CoderRemoteProvider(
9797
it.name
9898
}?.map { agent->
9999
// If we have an environment already, update that.
100-
val env=CoderRemoteEnvironment(client, ws, agent, observablePropertiesFactory)
100+
val env=CoderRemoteEnvironment(client, ws, agent,ui,observablePropertiesFactory)
101101
lastEnvironments?.firstOrNull { it== env }?.let {
102102
it.update(ws, agent)
103103
it

‎src/main/kotlin/com/coder/gateway/models/WorkspaceAndAgentStatus.kt‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,8 @@ enum class WorkspaceAndAgentStatus(val label: String, val description: String) {
5252
* Return the environment state for Toolbox, which tells it the label, color
5353
* and whether the environment is reachable.
5454
*
55-
* We mark all ready and pending states as reachable since if the workspace
56-
* is pending the cli will wait for it anyway.
57-
*
58-
* Additionally, terminal states like stopped are also marked as reachable,
59-
* since the cli will start them.
55+
* Note that a reachable environment will always display "connected" or
56+
* "disconnected" regardless of the label we give that status.
6057
*/
6158
funtoRemoteEnvironmentState():CustomRemoteEnvironmentState {
6259
// Use comments; no named arguments for non-Kotlin functions.
@@ -67,7 +64,7 @@ enum class WorkspaceAndAgentStatus(val label: String, val description: String) {
6764
Color(104,112,128,255),// lightThemeColor
6865
Color(224,224,240,26),// darkThemeBackgroundColor
6966
Color(224,224,245,250),// lightThemeBackgroundColor
70-
ready()|| pending()|| canStart(),// reachable
67+
ready(),// reachable
7168
// TODO@JB: How does this work? Would like a spinner for pending states.
7269
null,// iconId
7370
)

‎src/main/kotlin/com/coder/gateway/sdk/v2/models/Workspace.kt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ data class Workspace(
1818
@Json(name="latest_build")vallatestBuild:WorkspaceBuild,
1919
@Json(name="outdated")valoutdated:Boolean,
2020
@Json(name="name")valname:String,
21+
@Json(name="owner_name")valownerName:String,
2122
)

‎src/main/kotlin/com/coder/gateway/views/CoderPage.kt‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,13 @@ abstract class CoderPage(
116116
*/
117117
classAction(
118118
privatevallabel:String,
119-
privatevalclosesPage:Boolean,
119+
privatevalclosesPage:Boolean =false,
120+
privatevalenabled: ()->Boolean = {true },
120121
privatevalcb: ()->Unit,
121122
) : RunnableActionDescription {
122123
overridefungetLabel():String= label
123124
overridefungetShouldClosePage():Boolean= closesPage
125+
overridefunisEnabled():Boolean= enabled()
124126
overridefunrun() {
125127
cb()
126128
}

‎src/test/kotlin/com/coder/gateway/sdk/DataGen.kt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class DataGen {
5353
),
5454
outdated=false,
5555
name= name,
56+
ownerName="owner",
5657
)
5758
}
5859

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp