import { Component, OnInit } from "@angular/core"; import { ActivatedRoute } from "@angular/router"; import { combineLatestWith, Observable, startWith, switchMap } from "rxjs"; import { DialogService } from "@bitwarden/components"; import { AccessTokenView } from "../models/view/access-token.view"; import { AccessService } from "./access.service"; import { AccessTokenCreateDialogComponent } from "./dialogs/access-token-create-dialog.component"; @Component({ selector: "sm-access-tokens", templateUrl: "./access-tokens.component.html", }) export class AccessTokenComponent implements OnInit { accessTokens$: Observable; private serviceAccountId: string; private organizationId: string; constructor( private route: ActivatedRoute, private accessService: AccessService, private dialogService: DialogService ) {} ngOnInit() { this.accessTokens$ = this.accessService.accessToken$.pipe( startWith(null), combineLatestWith(this.route.params), switchMap(async ([_, params]) => { this.organizationId = params.organizationId; this.serviceAccountId = params.serviceAccountId; return await this.getAccessTokens(); }) ); } private async getAccessTokens(): Promise { return await this.accessService.getAccessTokens(this.organizationId, this.serviceAccountId); } protected openNewAccessTokenDialog() { AccessTokenCreateDialogComponent.openNewAccessTokenDialog( this.dialogService, this.serviceAccountId, this.organizationId ); } }