1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-23 03:33:54 +00:00
Files
browser/bitwarden_license/bit-web/src/app/secrets-manager/secrets/secrets.component.ts
Oscar Hinton 4e1867682f [PM-1504] Migrate Dialogs to DialogService (#5013)
This PR introduces a generic `DialogService` which can be used by all the clients. This allows us to decouple dialogs from the `PlatformUtilsHelper`.

The `DialogService` provides a new method, `openSimpleDialog` which is the new interface for that type of dialogs.

This gives us 3 different implementations: 
- Web: DialogService modern dialogs
- Browser: SweetAlert
- Desktop: Native electron based
2023-05-02 18:46:03 +02:00

100 lines
2.8 KiB
TypeScript

import { Component, OnInit } from "@angular/core";
import { ActivatedRoute } from "@angular/router";
import { combineLatestWith, Observable, startWith, switchMap } from "rxjs";
import { DialogServiceAbstraction } from "@bitwarden/angular/services/dialog";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
import { SecretListView } from "../models/view/secret-list.view";
import { SecretsListComponent } from "../shared/secrets-list.component";
import {
SecretDeleteDialogComponent,
SecretDeleteOperation,
} from "./dialog/secret-delete.component";
import {
OperationType,
SecretDialogComponent,
SecretOperation,
} from "./dialog/secret-dialog.component";
import { SecretService } from "./secret.service";
@Component({
selector: "sm-secrets",
templateUrl: "./secrets.component.html",
})
export class SecretsComponent implements OnInit {
protected secrets$: Observable<SecretListView[]>;
protected search: string;
private organizationId: string;
constructor(
private route: ActivatedRoute,
private secretService: SecretService,
private dialogService: DialogServiceAbstraction,
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;
return await this.getSecrets();
})
);
if (this.route.snapshot.queryParams.search) {
this.search = this.route.snapshot.queryParams.search;
}
}
private async getSecrets(): Promise<SecretListView[]> {
return await this.secretService.getSecrets(this.organizationId);
}
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,
},
});
}
copySecretName(name: string) {
SecretsListComponent.copySecretName(name, this.platformUtilsService, this.i18nService);
}
copySecretValue(id: string) {
SecretsListComponent.copySecretValue(
id,
this.platformUtilsService,
this.i18nService,
this.secretService
);
}
}