From 210170be2d35f181ca1068932aa9e187f83f835f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adina=20=C8=9Aeudan?= Date: Thu, 5 Oct 2023 16:44:54 +0300 Subject: [PATCH] RED-7512: Fixed switching workspaces --- .../tenants-menu/tenants-menu.component.html | 4 +-- .../tenants-menu/tenants-menu.component.ts | 27 +++---------------- 2 files changed, 6 insertions(+), 25 deletions(-) diff --git a/apps/red-ui/src/app/components/tenants-menu/tenants-menu.component.html b/apps/red-ui/src/app/components/tenants-menu/tenants-menu.component.html index d69983e1e..aaa7f3525 100644 --- a/apps/red-ui/src/app/components/tenants-menu/tenants-menu.component.html +++ b/apps/red-ui/src/app/components/tenants-menu/tenants-menu.component.html @@ -1,6 +1,6 @@
- +
diff --git a/apps/red-ui/src/app/components/tenants-menu/tenants-menu.component.ts b/apps/red-ui/src/app/components/tenants-menu/tenants-menu.component.ts index 36bf18837..5d6c114a3 100644 --- a/apps/red-ui/src/app/components/tenants-menu/tenants-menu.component.ts +++ b/apps/red-ui/src/app/components/tenants-menu/tenants-menu.component.ts @@ -1,8 +1,5 @@ import { Component, inject } from '@angular/core'; -import { getConfig } from '@iqser/common-ui'; -import { getKeycloakOptions, IStoredTenantId, KeycloakStatusService, TenantsService } from '@iqser/common-ui/lib/tenants'; -import { BASE_HREF } from '@iqser/common-ui/lib/utils'; -import { KeycloakService } from 'keycloak-angular'; +import { IStoredTenantId, KeycloakStatusService, TenantsService } from '@iqser/common-ui/lib/tenants'; interface ITenant extends IStoredTenantId { readonly isCurrent: boolean; @@ -14,12 +11,9 @@ interface ITenant extends IStoredTenantId { styleUrls: ['./tenants-menu.component.scss'], }) export class TenantsMenuComponent { - readonly #baseHref = inject(BASE_HREF); - readonly #keycloakService = inject(KeycloakService); - readonly #keycloakStatusService = inject(KeycloakStatusService); - readonly #config = getConfig(); readonly tenantsService = inject(TenantsService); readonly storedTenants: ITenant[]; + readonly #keycloakStatusService = inject(KeycloakStatusService); constructor() { this.storedTenants = this.#getStoredTenants(); @@ -29,21 +23,8 @@ export class TenantsMenuComponent { return item.tenantId; } - // TODO: this should be moved to the keycloak status service - async selectTenant(tenantId?: string) { - if (tenantId && tenantId !== this.tenantsService.activeTenantId) { - await this.#keycloakService.init(getKeycloakOptions(this.#baseHref, this.#config, tenantId)); - } - - if (tenantId) { - const url = this.#keycloakService.getKeycloakInstance().createLoginUrl({ - redirectUri: this.#keycloakStatusService.createLoginUrl(tenantId), - idpHint: this.#config.OAUTH_IDP_HINT, - }); - return this.#keycloakService.logout(url); - } - - return this.#keycloakService.logout(window.location.origin + this.#baseHref); + async switchTenant(tenantId?: string) { + await this.#keycloakStatusService.switchTenant(tenantId); } #getStoredTenants(): ITenant[] {