RED-7512: Fixed switching workspaces
This commit is contained in:
parent
59723cc7d1
commit
210170be2d
@ -1,6 +1,6 @@
|
||||
<div id="tenants-menu-items">
|
||||
<a
|
||||
(click)="!stored.isCurrent && selectTenant(stored.tenantId)"
|
||||
(click)="!stored.isCurrent && switchTenant(stored.tenantId)"
|
||||
*ngFor="let stored of storedTenants; trackBy: trackBy"
|
||||
[class.disabled]="stored.isCurrent"
|
||||
[class.reverse-icon]="stored.isCurrent"
|
||||
@ -15,7 +15,7 @@
|
||||
|
||||
<mat-divider class="pb-3 pt-3"></mat-divider>
|
||||
|
||||
<a (click)="selectTenant()" mat-menu-item>
|
||||
<a (click)="switchTenant()" mat-menu-item>
|
||||
<span translate="top-bar.navigation-items.my-account.children.join-another-tenant"> </span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
@ -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[] {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user