1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-19 09:43:23 +00:00
Files
browser/libs/vault/src/components/can-delete-cipher.directive.ts
Oscar Hinton f3ff1e98ec Remove standalone true from vault (#15040)
Remove standalone: true from every instance since it's the default as of Angular 19.
2025-06-02 13:22:57 -07:00

42 lines
1.2 KiB
TypeScript

import { Directive, Input, OnDestroy, TemplateRef, ViewContainerRef } from "@angular/core";
import { Subject, takeUntil } from "rxjs";
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
import { CipherAuthorizationService } from "@bitwarden/common/vault/services/cipher-authorization.service";
/**
* Only shows the element if the user can delete the cipher.
*/
@Directive({
selector: "[appCanDeleteCipher]",
})
export class CanDeleteCipherDirective implements OnDestroy {
private destroy$ = new Subject<void>();
@Input("appCanDeleteCipher") set cipher(cipher: CipherView) {
this.viewContainer.clear();
this.cipherAuthorizationService
.canDeleteCipher$(cipher)
.pipe(takeUntil(this.destroy$))
.subscribe((canDelete: boolean) => {
if (canDelete) {
this.viewContainer.createEmbeddedView(this.templateRef);
} else {
this.viewContainer.clear();
}
});
}
constructor(
private templateRef: TemplateRef<any>,
private viewContainer: ViewContainerRef,
private cipherAuthorizationService: CipherAuthorizationService,
) {}
ngOnDestroy() {
this.destroy$.next();
this.destroy$.complete();
}
}