From 34e588b0437d0939d97083e7d1ea9d707dcddb4c Mon Sep 17 00:00:00 2001 From: mustard Date: Tue, 23 Apr 2024 19:22:44 +0800 Subject: [PATCH] Select org in UiPage --- .../io/gitpod/toolbox/auth/GitpodAuthManager.kt | 3 +-- .../gitpod/toolbox/auth/GitpodOrganizationPage.kt | 13 ++++++------- .../gitpod/toolbox/gateway/GitpodRemoteProvider.kt | 8 ++++---- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/auth/GitpodAuthManager.kt b/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/auth/GitpodAuthManager.kt index 04b4fa0c64ca3a..0bd959892e6565 100644 --- a/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/auth/GitpodAuthManager.kt +++ b/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/auth/GitpodAuthManager.kt @@ -146,8 +146,7 @@ class GitpodAccount( private fun getStoreKey(key: String) = "USER:${id}:${key}" var organizationId: String? - get() = "ed51b786-24c7-4e58-b977-ef08b300a4bd" -// get() = Utils.settingStore[getStoreKey("ORG")] + get() = Utils.settingStore[getStoreKey("ORG")] set(value){ if (value == null) { return diff --git a/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/auth/GitpodOrganizationPage.kt b/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/auth/GitpodOrganizationPage.kt index b42fee191c7bbd..5d7c35ae496c34 100644 --- a/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/auth/GitpodOrganizationPage.kt +++ b/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/auth/GitpodOrganizationPage.kt @@ -13,19 +13,16 @@ import io.gitpod.publicapi.v1.OrganizationOuterClass import io.gitpod.toolbox.components.AbstractUiPage import io.gitpod.toolbox.service.GitpodPublicApiManager import io.gitpod.toolbox.service.Utils -import kotlinx.coroutines.launch import java.util.function.Consumer class GitpodOrganizationPage(val authManager: GitpodAuthManager, val publicApi: GitpodPublicApiManager) : AbstractUiPage() { - private var organizations = emptyList() private lateinit var orgField: AutocompleteTextField - fun loadData() { - Utils.coroutineScope.launch { - organizations = publicApi.listOrganizations() - } + + suspend fun loadData() { + organizations = publicApi.listOrganizations() } private fun getOrgField() = run { @@ -33,9 +30,11 @@ class GitpodOrganizationPage(val authManager: GitpodAuthManager, val publicApi: options.addAll(organizations.map { org -> MenuItem(org.name, null, null) { authManager.getCurrentAccount()?.organizationId = org.id + Utils.toolboxUi.hideUiPage(this) } }) - AutocompleteTextField("Organization", authManager.getCurrentAccount()?.organizationId ?: "", options, 1.0f) { + val orgName = organizations.find { it.id == authManager.getCurrentAccount()?.organizationId }?.name ?: "" + AutocompleteTextField("Organization", orgName, options, 1.0f) { if (it.isNullOrEmpty()) { ValidationResult.Invalid("Organization is required") } diff --git a/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/gateway/GitpodRemoteProvider.kt b/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/gateway/GitpodRemoteProvider.kt index 2b7995e27c56d8..23ef461c3e6056 100644 --- a/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/gateway/GitpodRemoteProvider.kt +++ b/components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/gateway/GitpodRemoteProvider.kt @@ -105,17 +105,14 @@ class GitpodRemoteProvider( val orgId = account.organizationId logger.info("user logged in, current selected org: $orgId") if (orgId != null) { - logger.info("try startWatchWorkspaces.1") Utils.dataManager.startWatchWorkspaces(publicApi) } else { Utils.coroutineScope.launch { - kotlinx.coroutines.delay(3000) organizationPage.loadData() Utils.toolboxUi.showUiPage(organizationPage) } } authManger.getCurrentAccount()?.onOrgSelected { - logger.info("try startWatchWorkspaces.2") Utils.dataManager.startWatchWorkspaces(publicApi) } } @@ -163,7 +160,10 @@ class GitpodRemoteProvider( } }, SimpleButton("Select organization") { - + Utils.coroutineScope.launch { + organizationPage.loadData() + Utils.toolboxUi.showUiPage(organizationPage) + } } ) }