Skip to content

Commit 3b38f77

Browse files
committed
Select org in UiPage
1 parent 3dd0057 commit 3b38f77

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/auth/GitpodAuthManager.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,7 @@ class GitpodAccount(
146146
private fun getStoreKey(key: String) = "USER:${id}:${key}"
147147

148148
var organizationId: String?
149-
get() = "ed51b786-24c7-4e58-b977-ef08b300a4bd"
150-
// get() = Utils.settingStore[getStoreKey("ORG")]
149+
get() = Utils.settingStore[getStoreKey("ORG")]
151150
set(value){
152151
if (value == null) {
153152
return

components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/auth/GitpodOrganizationPage.kt

+6-7
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,28 @@ import io.gitpod.publicapi.v1.OrganizationOuterClass
1313
import io.gitpod.toolbox.components.AbstractUiPage
1414
import io.gitpod.toolbox.service.GitpodPublicApiManager
1515
import io.gitpod.toolbox.service.Utils
16-
import kotlinx.coroutines.launch
1716
import java.util.function.Consumer
1817

1918
class GitpodOrganizationPage(val authManager: GitpodAuthManager, val publicApi: GitpodPublicApiManager) :
2019
AbstractUiPage() {
21-
2220
private var organizations = emptyList<OrganizationOuterClass.Organization>()
2321
private lateinit var orgField: AutocompleteTextField
2422

25-
fun loadData() {
26-
Utils.coroutineScope.launch {
27-
organizations = publicApi.listOrganizations()
28-
}
23+
24+
suspend fun loadData() {
25+
organizations = publicApi.listOrganizations()
2926
}
3027

3128
private fun getOrgField() = run {
3229
val options = mutableListOf<AutocompleteItem>()
3330
options.addAll(organizations.map { org ->
3431
MenuItem(org.name, null, null) {
3532
authManager.getCurrentAccount()?.organizationId = org.id
33+
Utils.toolboxUi.hideUiPage(this)
3634
}
3735
})
38-
AutocompleteTextField("Organization", authManager.getCurrentAccount()?.organizationId ?: "", options, 1.0f) {
36+
val orgName = organizations.find { it.id == authManager.getCurrentAccount()?.organizationId }?.name ?: ""
37+
AutocompleteTextField("Organization", orgName, options, 1.0f) {
3938
if (it.isNullOrEmpty()) {
4039
ValidationResult.Invalid("Organization is required")
4140
}

components/ide/jetbrains/toolbox/src/main/kotlin/io/gitpod/toolbox/gateway/GitpodRemoteProvider.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,14 @@ class GitpodRemoteProvider(
105105
val orgId = account.organizationId
106106
logger.info("user logged in, current selected org: $orgId")
107107
if (orgId != null) {
108-
logger.info("try startWatchWorkspaces.1")
109108
Utils.dataManager.startWatchWorkspaces(publicApi)
110109
} else {
111110
Utils.coroutineScope.launch {
112-
kotlinx.coroutines.delay(3000)
113111
organizationPage.loadData()
114112
Utils.toolboxUi.showUiPage(organizationPage)
115113
}
116114
}
117115
authManger.getCurrentAccount()?.onOrgSelected {
118-
logger.info("try startWatchWorkspaces.2")
119116
Utils.dataManager.startWatchWorkspaces(publicApi)
120117
}
121118
}
@@ -163,7 +160,10 @@ class GitpodRemoteProvider(
163160
}
164161
},
165162
SimpleButton("Select organization") {
166-
163+
Utils.coroutineScope.launch {
164+
organizationPage.loadData()
165+
Utils.toolboxUi.showUiPage(organizationPage)
166+
}
167167
}
168168
)
169169
}

0 commit comments

Comments
 (0)