Skip to content

Commit 972a386

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 f51b551 commit 972a386

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
@@ -212,11 +212,13 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
212212
tfUrl = textField().resizableColumn().align(AlignX.FILL).gap(RightGap.SMALL).bindText(localWizardModel::coderURL).applyToComponent {
213213
addActionListener {
214214
poller?.cancel()
215+
listTableModelOfWorkspaces.items = emptyList()
215216
askTokenAndOpenSession(true)
216217
}
217218
}.component
218219
button(CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.connect.text")) {
219220
poller?.cancel()
221+
listTableModelOfWorkspaces.items = emptyList()
220222
askTokenAndOpenSession(true)
221223
}.applyToComponent {
222224
background = WelcomeScreenUIManager.getMainAssociatedComponentBackground()
@@ -311,7 +313,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
311313
override fun onInit(wizardModel: CoderWorkspacesWizardModel) {
312314
enableNextButtonCallback(false)
313315
if (localWizardModel.coderURL.isNotBlank() && localWizardModel.token.isNotBlank()) {
314-
triggerWorkspacePolling()
316+
triggerWorkspacePolling(true)
315317
} else {
316318
val url = appPropertiesService.getValue(CODER_URL_KEY)
317319
val token = appPropertiesService.getValue(SESSION_TOKEN)
@@ -434,7 +436,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
434436

435437
this.indicator.fraction = 1.0
436438
updateWorkspaceActions()
437-
triggerWorkspacePolling()
439+
triggerWorkspacePolling(false)
438440
}
439441
}
440442

@@ -465,10 +467,13 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
465467
return tokenFromUser
466468
}
467469

468-
private fun triggerWorkspacePolling() {
470+
private fun triggerWorkspacePolling(fetchNow: Boolean) {
469471
poller?.cancel()
470472

471473
poller = cs.launch {
474+
if (fetchNow) {
475+
loadWorkspaces()
476+
}
472477
while (isActive) {
473478
delay(5000)
474479
loadWorkspaces()

0 commit comments

Comments
 (0)