1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-13 06:43:35 +00:00
Files
browser/bitwarden_license/bit-web/src/app/secrets-manager/projects/project/project-secrets.component.ts
Will Martin e11e4db356 [SM-632] fix copy secret value in Safari (#4974)
* add async copy method

* be more DRY
2023-03-10 10:13:07 -05:00

97 lines
2.8 KiB
TypeScript

import { Component } from "@angular/core";
import { ActivatedRoute } from "@angular/router";
import { combineLatestWith, Observable, startWith, switchMap } from "rxjs";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
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";
import { SecretsListComponent } from "../../shared/secrets-list.component";
@Component({
selector: "sm-project-secrets",
templateUrl: "./project-secrets.component.html",
})
export class ProjectSecretsComponent {
secrets$: Observable<SecretListView[]>;
private organizationId: string;
private projectId: string;
constructor(
private route: ActivatedRoute,
private secretService: SecretService,
private dialogService: DialogService,
private platformUtilsService: PlatformUtilsService,
private i18nService: I18nService
) {}
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<SecretListView[]> {
return await this.secretService.getSecretsByProject(this.organizationId, this.projectId);
}
openEditSecret(secretId: string) {
this.dialogService.open<unknown, SecretOperation>(SecretDialogComponent, {
data: {
organizationId: this.organizationId,
operation: OperationType.Edit,
secretId: secretId,
},
});
}
openDeleteSecret(event: SecretListView[]) {
this.dialogService.open<unknown, SecretDeleteOperation>(SecretDeleteDialogComponent, {
data: {
secrets: event,
},
});
}
openNewSecretDialog() {
this.dialogService.open<unknown, SecretOperation>(SecretDialogComponent, {
data: {
organizationId: this.organizationId,
operation: OperationType.Add,
projectId: this.projectId,
},
});
}
copySecretName(name: string) {
SecretsListComponent.copySecretName(name, this.platformUtilsService, this.i18nService);
}
copySecretValue(id: string) {
SecretsListComponent.copySecretValue(
id,
this.platformUtilsService,
this.i18nService,
this.secretService
);
}
}