Skip to content

Commit 195ba3d

Browse files
implement signal for premium badge component
1 parent 916f8ae commit 195ba3d

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

apps/desktop/src/vault/app/vault/vault-filter/filters/status-filter.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ <h2 class="sr-only">{{ "filters" | i18n }}</h2>
3838
<button
3939
type="button"
4040
class="filter-button"
41-
(click)="handleArchiveFilter()"
41+
(click)="handleArchiveFilter($event)"
4242
[attr.aria-pressed]="activeFilter.status === 'archive'"
4343
>
4444
<i class="bwi bwi-fw bwi-archive" aria-hidden="true"></i>&nbsp;{{ "archiveNoun" | i18n }}

apps/desktop/src/vault/app/vault/vault-filter/filters/status-filter.component.spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ describe("StatusFilterComponent", () => {
2424
let accountService: FakeAccountService;
2525

2626
const mockUserId = Utils.newGuid() as UserId;
27+
const event = new Event("click");
2728

2829
beforeEach(async () => {
2930
accountService = mockAccountServiceWith(mockUserId);
@@ -58,14 +59,14 @@ describe("StatusFilterComponent", () => {
5859
applyFilter.mockClear();
5960
component["applyFilter"] = applyFilter;
6061

61-
promptForPremiumSpy = jest.spyOn(component["premiumBadgeComponent"]!, "promptForPremium");
62+
promptForPremiumSpy = jest.spyOn(component["premiumBadgeComponent"]()!, "promptForPremium");
6263
});
6364

6465
it("should apply archive filter when userCanArchive returns true", async () => {
6566
cipherArchiveService.userCanArchive$.mockReturnValue(of(true));
6667
cipherArchiveService.archivedCiphers$.mockReturnValue(of([]));
6768

68-
await component["handleArchiveFilter"]();
69+
await component["handleArchiveFilter"](event);
6970

7071
expect(applyFilter).toHaveBeenCalledWith("archive");
7172
expect(promptForPremiumSpy).not.toHaveBeenCalled();
@@ -78,7 +79,7 @@ describe("StatusFilterComponent", () => {
7879
cipherArchiveService.userCanArchive$.mockReturnValue(of(false));
7980
cipherArchiveService.archivedCiphers$.mockReturnValue(of([mockCipher]));
8081

81-
await component["handleArchiveFilter"]();
82+
await component["handleArchiveFilter"](event);
8283

8384
expect(applyFilter).toHaveBeenCalledWith("archive");
8485
expect(promptForPremiumSpy).not.toHaveBeenCalled();
@@ -88,7 +89,7 @@ describe("StatusFilterComponent", () => {
8889
cipherArchiveService.userCanArchive$.mockReturnValue(of(false));
8990
cipherArchiveService.archivedCiphers$.mockReturnValue(of([]));
9091

91-
await component["handleArchiveFilter"]();
92+
await component["handleArchiveFilter"](event);
9293

9394
expect(applyFilter).not.toHaveBeenCalled();
9495
expect(promptForPremiumSpy).toHaveBeenCalled();

apps/desktop/src/vault/app/vault/vault-filter/filters/status-filter.component.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, ViewChild } from "@angular/core";
1+
import { Component, viewChild } from "@angular/core";
22
import { combineLatest, firstValueFrom, map, switchMap } from "rxjs";
33

44
import { PremiumBadgeComponent } from "@bitwarden/angular/billing/components/premium-badge";
@@ -15,7 +15,7 @@ import { CipherArchiveService } from "@bitwarden/common/vault/abstractions/ciphe
1515
standalone: false,
1616
})
1717
export class StatusFilterComponent extends BaseStatusFilterComponent {
18-
@ViewChild(PremiumBadgeComponent) private premiumBadgeComponent?: PremiumBadgeComponent;
18+
private readonly premiumBadgeComponent = viewChild(PremiumBadgeComponent);
1919

2020
private userId$ = this.accountService.activeAccount$.pipe(getUserId);
2121
protected canArchive$ = this.userId$.pipe(
@@ -35,17 +35,17 @@ export class StatusFilterComponent extends BaseStatusFilterComponent {
3535
super();
3636
}
3737

38-
protected async handleArchiveFilter() {
38+
protected async handleArchiveFilter(event: Event) {
3939
const [canArchive, hasArchivedCiphers] = await firstValueFrom(
4040
combineLatest([this.canArchive$, this.hasArchivedCiphers$]),
4141
);
4242

4343
if (canArchive || hasArchivedCiphers) {
4444
this.applyFilter("archive");
45-
} else if (this.premiumBadgeComponent) {
45+
} else if (this.premiumBadgeComponent()) {
4646
// The `premiumBadgeComponent` should always be defined here, adding the
4747
// if to satisfy TypeScript.
48-
await this.premiumBadgeComponent.promptForPremium();
48+
await this.premiumBadgeComponent().promptForPremium(event);
4949
}
5050
}
5151
}

0 commit comments

Comments
 (0)