Skip to content

Commit 5f17562

Browse files
committed
impl: hide unavailable actions
- instead of disabling the env actions when they are not available we should hide them instead. - resolves #31
1 parent efea667 commit 5f17562

File tree

1 file changed

+44
-34
lines changed

1 file changed

+44
-34
lines changed

src/main/kotlin/com/coder/toolbox/CoderRemoteEnvironment.kt

+44-34
Original file line numberDiff line numberDiff line change
@@ -45,44 +45,54 @@ class CoderRemoteEnvironment(
4545

4646
override val actionsList: MutableStateFlow<List<ActionDescription>> = MutableStateFlow(getAvailableActions())
4747

48-
private fun getAvailableActions(): List<ActionDescription> = listOf(
49-
Action(context.i18n.ptrl("Open web terminal")) {
50-
context.cs.launch {
51-
BrowserUtil.browse(client.url.withPath("/${workspace.ownerName}/$name/terminal").toString()) {
52-
context.ui.showErrorInfoPopup(it)
48+
private fun getAvailableActions(): List<ActionDescription> {
49+
val actions = mutableListOf(
50+
Action(context.i18n.ptrl("Open web terminal")) {
51+
context.cs.launch {
52+
BrowserUtil.browse(client.url.withPath("/${workspace.ownerName}/$name/terminal").toString()) {
53+
context.ui.showErrorInfoPopup(it)
54+
}
5355
}
54-
}
55-
},
56-
Action(context.i18n.ptrl("Open in dashboard")) {
57-
context.cs.launch {
58-
BrowserUtil.browse(client.url.withPath("/@${workspace.ownerName}/${workspace.name}").toString()) {
59-
context.ui.showErrorInfoPopup(it)
56+
},
57+
Action(context.i18n.ptrl("Open in dashboard")) {
58+
context.cs.launch {
59+
BrowserUtil.browse(client.url.withPath("/@${workspace.ownerName}/${workspace.name}").toString()) {
60+
context.ui.showErrorInfoPopup(it)
61+
}
6062
}
61-
}
62-
},
63+
},
6364

64-
Action(context.i18n.ptrl("View template")) {
65-
context.cs.launch {
66-
BrowserUtil.browse(client.url.withPath("/templates/${workspace.templateName}").toString()) {
67-
context.ui.showErrorInfoPopup(it)
65+
Action(context.i18n.ptrl("View template")) {
66+
context.cs.launch {
67+
BrowserUtil.browse(client.url.withPath("/templates/${workspace.templateName}").toString()) {
68+
context.ui.showErrorInfoPopup(it)
69+
}
6870
}
69-
}
70-
},
71-
Action(context.i18n.ptrl("Start"), enabled = { wsRawStatus.canStart() && !workspace.outdated }) {
72-
val build = client.startWorkspace(workspace)
73-
workspace = workspace.copy(latestBuild = build)
74-
update(workspace, agent)
75-
},
76-
Action(context.i18n.ptrl("Stop"), enabled = { wsRawStatus.canStop() }) {
77-
val build = client.stopWorkspace(workspace)
78-
workspace = workspace.copy(latestBuild = build)
79-
update(workspace, agent)
80-
},
81-
Action(context.i18n.ptrl("Update and start"), enabled = { workspace.outdated }) {
82-
val build = client.updateWorkspace(workspace)
83-
workspace = workspace.copy(latestBuild = build)
84-
update(workspace, agent)
85-
})
71+
})
72+
if (wsRawStatus.canStart() && !workspace.outdated) {
73+
actions.add(Action(context.i18n.ptrl("Start")) {
74+
val build = client.startWorkspace(workspace)
75+
workspace = workspace.copy(latestBuild = build)
76+
update(workspace, agent)
77+
})
78+
}
79+
if (wsRawStatus.canStop()) {
80+
actions.add(Action(context.i18n.ptrl("Stop")) {
81+
val build = client.stopWorkspace(workspace)
82+
workspace = workspace.copy(latestBuild = build)
83+
update(workspace, agent)
84+
})
85+
}
86+
if (workspace.outdated) {
87+
actions.add(Action(context.i18n.ptrl("Update and start")) {
88+
val build = client.updateWorkspace(workspace)
89+
workspace = workspace.copy(latestBuild = build)
90+
update(workspace, agent)
91+
})
92+
}
93+
94+
return actions
95+
}
8696

8797
/**
8898
* Update the workspace/agent status to the listeners, if it has changed.

0 commit comments

Comments
 (0)