Skip to content

Commit b85e6fe

Browse files
committed
fix: url refresh after log out and log in
- the main env header page API is quite limiting, in the sense that the title is never allowed to change. Today we display the Coder URL as the title. However, if the user switches between two deployments by logging out and then logging in, the URL is never refreshed, leading to a confusing UI (URL is old, while workspaces are from the new deployment) - to workaround the issue we redesigned the page, to have a static string as the page, and bellow the first row, have a link field reflecting the new URL. - resolves #66
1 parent 91a91d7 commit b85e6fe

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
### Fixed
66

7-
- after log out, user is redirected back to the initial log in screen
7+
- after log out, user is redirected back to the initial log in screen
8+
- url on the main page is now refreshed when switching between multiple deployments (via logout/login or URI handling)
89

910
## 0.1.1 - 2025-04-03
1011

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class CoderRemoteEnvironment(
177177
while (context.cs.isActive && workspaceStillExists) {
178178
if (wsRawStatus == WorkspaceAndAgentStatus.DELETING || wsRawStatus == WorkspaceAndAgentStatus.DELETED) {
179179
workspaceStillExists = false
180-
context.envPageManager.showPluginEnvironmentsPage()
180+
context.envPageManager.showPluginEnvironmentsPage(true)
181181
} else {
182182
delay(1.seconds)
183183
}

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ class CoderRemoteProvider(
6767
// On the first load, automatically log in if we can.
6868
private var firstRun = true
6969
private val isInitialized: MutableStateFlow<Boolean> = MutableStateFlow(false)
70-
private var coderHeaderPage = NewEnvironmentPage(context, context.i18n.pnotr(getDeploymentURL()?.first ?: ""))
70+
private var coderHeaderPage =
71+
NewEnvironmentPage(context, context.i18n.pnotr("Coder"), getDeploymentURL()?.first ?: "")
7172
private val linkHandler = CoderProtocolHandler(context, dialogUi, isInitialized)
7273
override val environments: MutableStateFlow<LoadableState<List<RemoteProviderEnvironment>>> = MutableStateFlow(
7374
LoadableState.Value(emptyList())
@@ -243,7 +244,7 @@ class CoderRemoteProvider(
243244
* this changes it would be nice to have a new spot to show the
244245
* URL.
245246
*/
246-
override val canCreateNewEnvironments: Boolean = false
247+
override val canCreateNewEnvironments: Boolean = true
247248

248249
/**
249250
* Just displays the deployment URL at the moment, but we could use this as
@@ -273,7 +274,7 @@ class CoderRemoteProvider(
273274
close()
274275
// start initialization with the new settings
275276
this@CoderRemoteProvider.client = restClient
276-
coderHeaderPage = NewEnvironmentPage(context, context.i18n.pnotr(restClient.url.toString()))
277+
coderHeaderPage.refreshUrl(restClient.url.toString())
277278
pollJob = poll(restClient, cli)
278279
}
279280
}
@@ -287,7 +288,7 @@ class CoderRemoteProvider(
287288
* than using multiple root pages.
288289
*/
289290
private fun goToEnvironmentsPage() {
290-
context.envPageManager.showPluginEnvironmentsPage()
291+
context.envPageManager.showPluginEnvironmentsPage(true)
291292
}
292293

293294
/**
@@ -359,6 +360,7 @@ class CoderRemoteProvider(
359360
pollError = null
360361
pollJob?.cancel()
361362
pollJob = poll(client, cli)
363+
coderHeaderPage.refreshUrl(getDeploymentURL()?.first ?: "")
362364
goToEnvironmentsPage()
363365
}
364366

src/main/kotlin/com/coder/toolbox/views/NewEnvironmentPage.kt

+12-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package com.coder.toolbox.views
22

33
import com.coder.toolbox.CoderToolboxContext
44
import com.jetbrains.toolbox.api.localization.LocalizableString
5+
import com.jetbrains.toolbox.api.ui.components.LinkField
56
import com.jetbrains.toolbox.api.ui.components.UiField
67
import kotlinx.coroutines.flow.MutableStateFlow
7-
import kotlinx.coroutines.flow.StateFlow
8+
import kotlinx.coroutines.flow.update
89

910

1011
/**
@@ -14,7 +15,14 @@ import kotlinx.coroutines.flow.StateFlow
1415
* For now we just use this to display the deployment URL since we do not
1516
* support creating environments from the plugin.
1617
*/
17-
class NewEnvironmentPage(context: CoderToolboxContext, deploymentURL: LocalizableString) :
18-
CoderPage(context, deploymentURL) {
19-
override val fields: StateFlow<List<UiField>> = MutableStateFlow(emptyList())
18+
class NewEnvironmentPage(private val context: CoderToolboxContext, title: LocalizableString, initialUrl: String) :
19+
CoderPage(context, title) {
20+
override val fields: MutableStateFlow<List<UiField>> =
21+
MutableStateFlow(listOf(LinkField(context.i18n.pnotr(initialUrl), initialUrl)))
22+
23+
fun refreshUrl(url: String) {
24+
fields.update {
25+
listOf(LinkField(context.i18n.pnotr(url), url))
26+
}
27+
}
2028
}

0 commit comments

Comments
 (0)