Skip to content

Commit 3143ebb

Browse files
committed
Clear workspaces on reconnect and fetch immediately on return
My thinking here is that if you try connecting to a new URL you still see the old workspaces until the new connection is successful which could be confusing (the new URL shows in the text field yet the workspaces below it belong to something else and the list will no longer update since the poller was stopped). Also thought it might make sense to fetch immediately if you come back to this step since it is not clear that the data there is possibly stale (especially if you were on a previous/next step for a long time); I think I would assume a fresh fetch when I interact with the next/previous buttons but this is just my personal assumption. Fetching immediately also "fixes" an interesting bug where if you hit back you are unable to connect to a workspace until the next poll goes through. I considered looking more into this but figured it would be best to block the next step on fresh data anyway.
1 parent 14019eb commit 3143ebb

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,13 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
214214
tfUrl = textField().resizableColumn().horizontalAlign(HorizontalAlign.FILL).gap(RightGap.SMALL).bindText(localWizardModel::coderURL).applyToComponent {
215215
addActionListener {
216216
poller?.cancel()
217+
listTableModelOfWorkspaces.items = emptyList()
217218
askTokenAndOpenSession()
218219
}
219220
}.component
220221
button(CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.connect.text")) {
221222
poller?.cancel()
223+
listTableModelOfWorkspaces.items = emptyList()
222224
askTokenAndOpenSession()
223225
}.applyToComponent {
224226
background = WelcomeScreenUIManager.getMainAssociatedComponentBackground()
@@ -308,7 +310,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
308310
override fun onInit(wizardModel: CoderWorkspacesWizardModel) {
309311
enableNextButtonCallback(false)
310312
if (localWizardModel.coderURL.isNotBlank() && localWizardModel.token.isNotBlank()) {
311-
triggerWorkspacePolling()
313+
triggerWorkspacePolling(true)
312314
} else {
313315
val url = appPropertiesService.getValue(CODER_URL_KEY)
314316
val token = appPropertiesService.getValue(SESSION_TOKEN)
@@ -454,7 +456,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
454456

455457
this.indicator.fraction = 1.0
456458
updateWorkspaceActions()
457-
triggerWorkspacePolling()
459+
triggerWorkspacePolling(false)
458460
}
459461
}
460462

@@ -480,10 +482,13 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
480482
}
481483
}
482484

483-
private fun triggerWorkspacePolling() {
485+
private fun triggerWorkspacePolling(fetchNow: Boolean) {
484486
poller?.cancel()
485487

486488
poller = cs.launch {
489+
if (fetchNow) {
490+
loadWorkspaces()
491+
}
487492
while (isActive) {
488493
delay(5000)
489494
loadWorkspaces()

0 commit comments

Comments
 (0)