import { Component } from "@angular/core"; import { ActivatedRoute } from "@angular/router"; import { combineLatestWith, Observable, startWith, switchMap } from "rxjs"; import { DialogService } from "@bitwarden/components"; import { SecretListView } from "../../models/view/secret-list.view"; import { SecretDeleteDialogComponent, SecretDeleteOperation, } from "../../secrets/dialog/secret-delete.component"; import { OperationType, SecretDialogComponent, SecretOperation, } from "../../secrets/dialog/secret-dialog.component"; import { SecretService } from "../../secrets/secret.service"; @Component({ selector: "sm-project-secrets", templateUrl: "./project-secrets.component.html", }) export class ProjectSecretsComponent { secrets$: Observable; private organizationId: string; private projectId: string; constructor( private route: ActivatedRoute, private secretService: SecretService, private dialogService: DialogService ) {} ngOnInit() { this.secrets$ = this.secretService.secret$.pipe( startWith(null), combineLatestWith(this.route.params), switchMap(async ([_, params]) => { this.organizationId = params.organizationId; this.projectId = params.projectId; return await this.getSecretsByProject(); }) ); } private async getSecretsByProject(): Promise { return await this.secretService.getSecretsByProject(this.organizationId, this.projectId); } openEditSecret(secretId: string) { this.dialogService.open(SecretDialogComponent, { data: { organizationId: this.organizationId, operation: OperationType.Edit, secretId: secretId, }, }); } openDeleteSecret(secretIds: string[]) { this.dialogService.open(SecretDeleteDialogComponent, { data: { secretIds: secretIds, }, }); } openNewSecretDialog() { this.dialogService.open(SecretDialogComponent, { data: { organizationId: this.organizationId, operation: OperationType.Add, projectId: this.projectId, }, }); } }