Files
zitadel/console/src/app/modules/accounts-card/accounts-card.component.ts
T
f963ea9f86 feat(console): rehauled navigation for instances including breadcrumb (#10283)
This PR significantly improves user navigation by introducing a new
instance-level navigation bar. This new bar, positioned above the
existing organization navigation, provides quick access to key sections:
Home, Organizations, Actions, and Settings.

Additionally, the breadcrumb component has been refined for more
consistent behavior, reintroducing intuitive breadcrumb buttons to
easily navigate up the hierarchy. These changes also include design
improvements for a cleaner and more streamlined appearance across the
interface.

<img width="423" height="138" alt="Screenshot 2025-07-17 at 14 55 46"
src="https://github.com/user-attachments/assets/ba9e40a1-1077-4cb6-8735-ac7ab637abe7"
/>
<img width="562" height="132" alt="Screenshot 2025-07-17 at 14 56 41"
src="https://github.com/user-attachments/assets/d85dc673-0df8-4677-9d2b-dc031dde42c3"
/>
<img width="545" height="254" alt="Screenshot 2025-07-17 at 14 56 10"
src="https://github.com/user-attachments/assets/eaf10117-079e-4181-8dbb-60c89b24556a"
/>
<img width="689" height="261" alt="Screenshot 2025-07-17 at 14 56 20"
src="https://github.com/user-attachments/assets/510ad550-1d9a-4c6a-8af1-66cb0b23619c"
/>

---------

Co-authored-by: conblem <[email protected]>
Co-authored-by: Stefan Benz <[email protected]>
Co-authored-by: Florian Forster <[email protected]>
2025-08-28 11:23:14 +02:00

175 lines
5.1 KiB
TypeScript

import { Component, EventEmitter, Input, Output } from '@angular/core';
import { Router } from '@angular/router';
import { AuthConfig } from 'angular-oauth2-oidc';
import { SessionState as V1SessionState, User, UserState } from 'src/app/proto/generated/zitadel/user_pb';
import { AuthenticationService } from 'src/app/services/authentication.service';
import { GrpcAuthService } from 'src/app/services/grpc-auth.service';
import { toSignal } from '@angular/core/rxjs-interop';
import { SessionService } from 'src/app/services/session.service';
import {
catchError,
defer,
from,
map,
mergeMap,
Observable,
of,
ReplaySubject,
shareReplay,
switchMap,
timeout,
TimeoutError,
toArray,
} from 'rxjs';
import { NewFeatureService } from 'src/app/services/new-feature.service';
import { ToastService } from 'src/app/services/toast.service';
import { SessionState as V2SessionState } from '@zitadel/proto/zitadel/user_pb';
import { filter, withLatestFrom } from 'rxjs/operators';
interface V1AndV2Session {
displayName: string;
avatarUrl: string;
loginName: string;
userName: string;
authState: V1SessionState | V2SessionState;
}
@Component({
selector: 'cnsl-accounts-card',
templateUrl: './accounts-card.component.html',
styleUrls: ['./accounts-card.component.scss'],
})
export class AccountsCardComponent {
@Input({ required: true })
public set user(user: User.AsObject) {
this.user$.next(user);
}
@Input() public iamuser: boolean | null = false;
@Output() public closedCard = new EventEmitter<void>();
protected readonly user$ = new ReplaySubject<User.AsObject>(1);
protected readonly UserState = UserState;
private readonly labelpolicy = toSignal(this.userService.labelpolicy$, { initialValue: undefined });
protected readonly sessions$: Observable<V1AndV2Session[]>;
constructor(
protected readonly authService: AuthenticationService,
private readonly router: Router,
private readonly userService: GrpcAuthService,
private readonly sessionService: SessionService,
private readonly featureService: NewFeatureService,
private readonly toast: ToastService,
) {
this.sessions$ = this.getSessions().pipe(shareReplay({ refCount: true, bufferSize: 1 }));
}
private getUseLoginV2() {
return defer(() => this.featureService.getInstanceFeatures()).pipe(
map(({ loginV2 }) => loginV2?.required ?? false),
timeout(1000),
catchError((err) => {
if (!(err instanceof TimeoutError)) {
this.toast.showError(err);
}
return of(false);
}),
);
}
private getSessions(): Observable<V1AndV2Session[]> {
const useLoginV2$ = this.getUseLoginV2();
return useLoginV2$.pipe(
switchMap((useLoginV2) => {
if (useLoginV2) {
return this.getV2Sessions();
} else {
return this.getV1Sessions();
}
}),
catchError((err) => {
this.toast.showError(err);
return of([]);
}),
);
}
private getV1Sessions(): Observable<V1AndV2Session[]> {
return defer(() => this.userService.listMyUserSessions()).pipe(
mergeMap(({ resultList }) => from(resultList)),
withLatestFrom(this.user$),
filter(([{ loginName }, user]) => loginName !== user.preferredLoginName),
map(([s]) => ({
displayName: s.displayName,
avatarUrl: s.avatarUrl,
loginName: s.loginName,
authState: s.authState,
userName: s.userName,
})),
toArray(),
);
}
private getV2Sessions(): Observable<V1AndV2Session[]> {
return defer(() =>
this.sessionService.listSessions({
queries: [
{
query: {
case: 'userAgentQuery',
value: {},
},
},
],
}),
).pipe(
mergeMap(({ sessions }) => from(sessions)),
withLatestFrom(this.user$),
filter(([s, user]) => s.factors?.user?.loginName !== user.preferredLoginName),
map(([s]) => ({
displayName: s.factors?.user?.displayName ?? '',
avatarUrl: '',
loginName: s.factors?.user?.loginName ?? '',
authState: V2SessionState.ACTIVE,
userName: s.factors?.user?.loginName ?? '',
})),
map((s) => [s.loginName, s] as const),
toArray(),
map((sessions) => Array.from(new Map(sessions).values())), // Ensure unique loginNames
);
}
public editUserProfile(): void {
this.router.navigate(['users/me']).then();
this.closedCard.emit();
}
public async selectAccount(loginHint: string): Promise<void> {
const configWithPrompt: Partial<AuthConfig> = {
customQueryParams: {
login_hint: loginHint,
},
};
await this.authService.authenticate(configWithPrompt);
}
public async selectNewAccount(): Promise<void> {
const configWithPrompt: Partial<AuthConfig> = {
customQueryParams: {
prompt: 'login',
},
};
await this.authService.authenticate(configWithPrompt);
}
public logout(): void {
const lP = JSON.stringify(this.labelpolicy());
localStorage.setItem('labelPolicyOnSignout', lP);
this.authService.signout();
this.closedCard.emit();
}
}