Skip to content

Commit 55b5b11

Browse files
authored
Merge pull request coder#116 from coder/impl-go-to-dashboard
Impl: action to open dashboard in the browser
2 parents ae718ed + 98f7e7e commit 55b5b11

File tree

7 files changed

+41
-24
lines changed

7 files changed

+41
-24
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- warning system when plugin might not be compatible with Coder REST API
99
- a `Create workspace` button which links to Coder's templates page
1010
- workspace icons
11+
- quick toolbar action to open Coder Dashboard in the browser
1112

1213
### Changed
1314
- redesigned the information&warning banner. Messages can now include hyperlinks

src/main/kotlin/com/coder/gateway/icons/CoderIcons.kt

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ object CoderIcons {
88

99
val OPEN_TERMINAL = IconLoader.getIcon("open_terminal.svg", javaClass)
1010

11+
val HOME = IconLoader.getIcon("homeFolder.svg", javaClass)
1112
val CREATE = IconLoader.getIcon("create.svg", javaClass)
1213
val RUN = IconLoader.getIcon("run.svg", javaClass)
1314
val STOP = IconLoader.getIcon("stop.svg", javaClass)

src/main/kotlin/com/coder/gateway/sdk/CoderRestClientService.kt

+7-16
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import java.util.UUID
2828

2929
@Service(Service.Level.APP)
3030
class CoderRestClientService {
31+
var isReady: Boolean = false
32+
private set
3133
private lateinit var httpClient: OkHttpClient
3234
private lateinit var retroRestClient: CoderV2RestFacade
3335
private lateinit var sessionToken: String
@@ -40,21 +42,10 @@ class CoderRestClientService {
4042
* @throws [AuthenticationResponseException] if authentication failed.
4143
*/
4244
fun initClientSession(url: URL, token: String): User {
43-
val gson: Gson = GsonBuilder()
44-
.registerTypeAdapter(Instant::class.java, InstantConverter())
45-
.setPrettyPrinting()
46-
.create()
47-
httpClient = OkHttpClient.Builder()
48-
.addInterceptor { it.proceed(it.request().newBuilder().addHeader("Coder-Session-Token", token).build()) }
49-
.addInterceptor(HttpLoggingInterceptor().apply { setLevel(HttpLoggingInterceptor.Level.BASIC) })
50-
.build()
51-
52-
retroRestClient = Retrofit.Builder()
53-
.baseUrl(url.toString())
54-
.client(httpClient)
55-
.addConverterFactory(GsonConverterFactory.create(gson))
56-
.build()
57-
.create(CoderV2RestFacade::class.java)
45+
val gson: Gson = GsonBuilder().registerTypeAdapter(Instant::class.java, InstantConverter()).setPrettyPrinting().create()
46+
httpClient = OkHttpClient.Builder().addInterceptor { it.proceed(it.request().newBuilder().addHeader("Coder-Session-Token", token).build()) }.addInterceptor(HttpLoggingInterceptor().apply { setLevel(HttpLoggingInterceptor.Level.BASIC) }).build()
47+
48+
retroRestClient = Retrofit.Builder().baseUrl(url.toString()).client(httpClient).addConverterFactory(GsonConverterFactory.create(gson)).build().create(CoderV2RestFacade::class.java)
5849

5950
val userResponse = retroRestClient.me().execute()
6051
if (!userResponse.isSuccessful) {
@@ -65,7 +56,7 @@ class CoderRestClientService {
6556
sessionToken = token
6657
me = userResponse.body()!!
6758
buildVersion = buildInfo().version
68-
59+
isReady = true
6960
return me
7061
}
7162

src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspacesStepView.kt

+17-8
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
125125
}
126126
}
127127

128+
private val goToDashboardAction = GoToDashboardAction()
128129
private val startWorkspaceAction = StartWorkspaceAction()
129130
private val stopWorkspaceAction = StopWorkspaceAction()
130131
private val updateWorkspaceTemplateAction = UpdateWorkspaceTemplateAction()
@@ -134,6 +135,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
134135
.disableAddAction()
135136
.disableRemoveAction()
136137
.disableUpDownActions()
138+
.addExtraAction(goToDashboardAction)
137139
.addExtraAction(startWorkspaceAction)
138140
.addExtraAction(stopWorkspaceAction)
139141
.addExtraAction(updateWorkspaceTemplateAction)
@@ -183,6 +185,12 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
183185
override val previousActionText = IdeBundle.message("button.back")
184186
override val nextActionText = CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.next.text")
185187

188+
private inner class GoToDashboardAction : AnActionButton(CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.dashboard.text"), CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.dashboard.text"), CoderIcons.HOME) {
189+
override fun actionPerformed(p0: AnActionEvent) {
190+
BrowserUtil.browse(coderClient.coderURL)
191+
}
192+
}
193+
186194
private inner class StartWorkspaceAction : AnActionButton(CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.start.text"), CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.start.text"), CoderIcons.RUN) {
187195
override fun actionPerformed(p0: AnActionEvent) {
188196
if (tableOfWorkspaces.selectedObject != null) {
@@ -221,12 +229,6 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
221229
}
222230
}
223231

224-
private inner class CreateWorkspaceAction : AnActionButton(CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.create.text"), CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.create.text"), CoderIcons.CREATE) {
225-
override fun actionPerformed(p0: AnActionEvent) {
226-
BrowserUtil.browse(coderClient.coderURL.toURI().resolve("/templates"))
227-
}
228-
}
229-
230232
private inner class StopWorkspaceAction : AnActionButton(CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.stop.text"), CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.stop.text"), CoderIcons.STOP) {
231233
override fun actionPerformed(p0: AnActionEvent) {
232234
if (tableOfWorkspaces.selectedObject != null) {
@@ -245,6 +247,12 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
245247
}
246248
}
247249

250+
private inner class CreateWorkspaceAction : AnActionButton(CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.create.text"), CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.create.text"), CoderIcons.CREATE) {
251+
override fun actionPerformed(p0: AnActionEvent) {
252+
BrowserUtil.browse(coderClient.coderURL.toURI().resolve("/templates"))
253+
}
254+
}
255+
248256
override fun onInit(wizardModel: CoderWorkspacesWizardModel) {
249257
enableNextButtonCallback(false)
250258
if (localWizardModel.coderURL.isNotBlank() && localWizardModel.token.isNotBlank()) {
@@ -265,8 +273,8 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
265273
}
266274

267275
private fun updateWorkspaceActions() {
268-
createWorkspaceAction.isEnabled = true
269-
276+
goToDashboardAction.isEnabled = coderClient.isReady
277+
createWorkspaceAction.isEnabled = coderClient.isReady
270278
when (tableOfWorkspaces.selectedObject?.agentStatus) {
271279
RUNNING -> {
272280
startWorkspaceAction.isEnabled = false
@@ -380,6 +388,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
380388
cs.launch {
381389
ProgressManager.getInstance().run(authTask)
382390
}
391+
updateWorkspaceActions()
383392
triggerWorkspacePolling()
384393
}
385394

src/main/resources/homeFolder.svg

+7
Loading
+7
Loading

src/main/resources/messages/CoderGatewayBundle.properties

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ gateway.connector.view.coder.workspaces.connect.text=Connect
1111
gateway.connector.view.coder.workspaces.cli.downloader.dialog.title=Authenticate and setup Coder
1212
gateway.connector.view.coder.workspaces.cli.configssh.dialog.title=Coder Config SSH
1313
gateway.connector.view.coder.workspaces.next.text=Select IDE and Project
14+
gateway.connector.view.coder.workspaces.dashboard.text=Open Dashboard
1415
gateway.connector.view.coder.workspaces.start.text=Start Workspace
1516
gateway.connector.view.coder.workspaces.stop.text=Stop Workspace
1617
gateway.connector.view.coder.workspaces.update.text=Update Workspace Template

0 commit comments

Comments
 (0)