Skip to content

Commit

Permalink
Select org in UiPage
Browse files Browse the repository at this point in the history
  • Loading branch information
mustard-mh committed Apr 23, 2024
1 parent 3dd0057 commit 3b38f77
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,28 @@ 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<OrganizationOuterClass.Organization>()
private lateinit var orgField: AutocompleteTextField

fun loadData() {
Utils.coroutineScope.launch {
organizations = publicApi.listOrganizations()
}

suspend fun loadData() {
organizations = publicApi.listOrganizations()
}

private fun getOrgField() = run {
val options = mutableListOf<AutocompleteItem>()
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")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -163,7 +160,10 @@ class GitpodRemoteProvider(
}
},
SimpleButton("Select organization") {

Utils.coroutineScope.launch {
organizationPage.loadData()
Utils.toolboxUi.showUiPage(organizationPage)
}
}
)
}
Expand Down

0 comments on commit 3b38f77

Please sign in to comment.