From ee4c3cfd9475b57118f06eb5dedc82707af92e26 Mon Sep 17 00:00:00 2001 From: Jason Ng Date: Thu, 15 May 2025 15:10:38 -0400 Subject: [PATCH] [PM-21663] nudge service name refactor (#14789) * update names of vault nudge service and their corresponding files, convert components using showNudge$ to instead target spotlight and badges directly with new observables. Core logic for dismiss remains the same --- .../popup/settings/autofill.component.ts | 20 ++--- apps/browser/src/popup/tabs-v2.component.ts | 6 +- .../popup/settings/settings-v2.component.html | 6 +- .../popup/settings/settings-v2.component.ts | 26 +++--- .../vault-v2/vault-v2.component.html | 4 +- .../components/vault-v2/vault-v2.component.ts | 18 ++-- .../settings/download-bitwarden.component.ts | 6 +- .../src/platform/state/state-definitions.ts | 2 +- .../src/cipher-form/cipher-form.stories.ts | 4 +- .../new-item-nudge.component.spec.ts | 23 +++-- .../new-item-nudge.component.ts | 28 +++--- libs/vault/src/index.ts | 2 +- .../autofill-nudge.service.ts | 6 +- .../download-bitwarden-nudge.service.ts | 4 +- .../empty-vault-nudge.service.ts | 4 +- .../has-items-nudge.service.ts | 6 +- .../new-item-nudge.service.ts | 14 +-- .../services/default-single-nudge.service.ts | 24 ++---- ...service.spec.ts => nudges.service.spec.ts} | 62 +++++++++---- ...lt-nudges.service.ts => nudges.service.ts} | 86 +++++++++++++------ 20 files changed, 199 insertions(+), 152 deletions(-) rename libs/vault/src/services/{vault-nudges.service.spec.ts => nudges.service.spec.ts} (72%) rename libs/vault/src/services/{vault-nudges.service.ts => nudges.service.ts} (56%) diff --git a/apps/browser/src/autofill/popup/settings/autofill.component.ts b/apps/browser/src/autofill/popup/settings/autofill.component.ts index d63f9a4589..2d29067cf0 100644 --- a/apps/browser/src/autofill/popup/settings/autofill.component.ts +++ b/apps/browser/src/autofill/popup/settings/autofill.component.ts @@ -4,14 +4,14 @@ import { CommonModule } from "@angular/common"; import { Component, DestroyRef, OnInit } from "@angular/core"; import { takeUntilDestroyed } from "@angular/core/rxjs-interop"; import { + FormBuilder, + FormControl, + FormGroup, FormsModule, ReactiveFormsModule, - FormBuilder, - FormGroup, - FormControl, } from "@angular/forms"; import { RouterModule } from "@angular/router"; -import { Observable, filter, firstValueFrom, map, switchMap } from "rxjs"; +import { filter, firstValueFrom, Observable, switchMap } from "rxjs"; import { JslibModule } from "@bitwarden/angular/jslib.module"; import { Account, AccountService } from "@bitwarden/common/auth/abstractions/account.service"; @@ -55,7 +55,7 @@ import { SelectModule, TypographyModule, } from "@bitwarden/components"; -import { SpotlightComponent, VaultNudgesService, VaultNudgeType } from "@bitwarden/vault"; +import { NudgesService, NudgeType, SpotlightComponent } from "@bitwarden/vault"; import { AutofillBrowserSettingsService } from "../../../autofill/services/autofill-browser-settings.service"; import { BrowserApi } from "../../../platform/browser/browser-api"; @@ -108,9 +108,7 @@ export class AutofillComponent implements OnInit { protected showSpotlightNudge$: Observable = this.accountService.activeAccount$.pipe( filter((account): account is Account => account !== null), switchMap((account) => - this.vaultNudgesService - .showNudge$(VaultNudgeType.AutofillNudge, account.id) - .pipe(map((nudgeStatus) => !nudgeStatus.hasSpotlightDismissed)), + this.nudgesService.showNudgeSpotlight$(NudgeType.AutofillNudge, account.id), ), ); @@ -155,7 +153,7 @@ export class AutofillComponent implements OnInit { private configService: ConfigService, private formBuilder: FormBuilder, private destroyRef: DestroyRef, - private vaultNudgesService: VaultNudgesService, + private nudgesService: NudgesService, private accountService: AccountService, private autofillBrowserSettingsService: AutofillBrowserSettingsService, ) { @@ -343,8 +341,8 @@ export class AutofillComponent implements OnInit { } async dismissSpotlight() { - await this.vaultNudgesService.dismissNudge( - VaultNudgeType.AutofillNudge, + await this.nudgesService.dismissNudge( + NudgeType.AutofillNudge, await firstValueFrom(this.accountService.activeAccount$.pipe(getUserId)), ); } diff --git a/apps/browser/src/popup/tabs-v2.component.ts b/apps/browser/src/popup/tabs-v2.component.ts index 5df8fb85d6..0ca763d510 100644 --- a/apps/browser/src/popup/tabs-v2.component.ts +++ b/apps/browser/src/popup/tabs-v2.component.ts @@ -6,7 +6,7 @@ import { getUserId } from "@bitwarden/common/auth/services/account.service"; import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum"; import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service"; import { Icons } from "@bitwarden/components"; -import { VaultNudgesService } from "@bitwarden/vault"; +import { NudgesService } from "@bitwarden/vault"; import { NavButton } from "../platform/popup/layout/popup-tab-navigation.component"; @@ -18,7 +18,7 @@ import { NavButton } from "../platform/popup/layout/popup-tab-navigation.compone export class TabsV2Component { private hasActiveBadges$ = this.accountService.activeAccount$ .pipe(getUserId) - .pipe(switchMap((userId) => this.vaultNudgesService.hasActiveBadges$(userId))); + .pipe(switchMap((userId) => this.nudgesService.hasActiveBadges$(userId))); protected navButtons$: Observable = combineLatest([ this.configService.getFeatureFlag$(FeatureFlag.PM8851_BrowserOnboardingNudge), this.hasActiveBadges$, @@ -54,7 +54,7 @@ export class TabsV2Component { }), ); constructor( - private vaultNudgesService: VaultNudgesService, + private nudgesService: NudgesService, private accountService: AccountService, private readonly configService: ConfigService, ) {} diff --git a/apps/browser/src/tools/popup/settings/settings-v2.component.html b/apps/browser/src/tools/popup/settings/settings-v2.component.html index 8d31ccf837..dc53f95a7c 100644 --- a/apps/browser/src/tools/popup/settings/settings-v2.component.html +++ b/apps/browser/src/tools/popup/settings/settings-v2.component.html @@ -41,7 +41,7 @@
@@ -51,7 +51,7 @@ Will make this dynamic when more nudges are added -->

{{ "downloadBitwardenOnAllDevices" | i18n }}

= this.authenticatedAccount$.pipe( + downloadBitwardenNudgeStatus$: Observable = this.authenticatedAccount$.pipe( switchMap((account) => - this.vaultNudgesService.showNudge$(VaultNudgeType.DownloadBitwarden, account.id), + this.nudgesService.showNudgeBadge$(NudgeType.DownloadBitwarden, account.id), ), ); - showVaultBadge$: Observable = this.authenticatedAccount$.pipe( + showVaultBadge$: Observable = this.authenticatedAccount$.pipe( switchMap((account) => - this.vaultNudgesService.showNudge$(VaultNudgeType.EmptyVaultNudge, account.id), + this.nudgesService.showNudgeBadge$(NudgeType.EmptyVaultNudge, account.id), ), ); @@ -68,9 +68,9 @@ export class SettingsV2Component implements OnInit { this.authenticatedAccount$, ]).pipe( switchMap(([defaultBrowserAutofillDisabled, account]) => - this.vaultNudgesService.showNudge$(VaultNudgeType.AutofillNudge, account.id).pipe( - map((nudgeStatus) => { - return !defaultBrowserAutofillDisabled && nudgeStatus.hasBadgeDismissed === false; + this.nudgesService.showNudgeBadge$(NudgeType.AutofillNudge, account.id).pipe( + map((badgeStatus) => { + return !defaultBrowserAutofillDisabled && badgeStatus; }), ), ), @@ -81,7 +81,7 @@ export class SettingsV2Component implements OnInit { ); constructor( - private readonly vaultNudgesService: VaultNudgesService, + private readonly nudgesService: NudgesService, private readonly accountService: AccountService, private readonly autofillBrowserSettingsService: AutofillBrowserSettingsService, private readonly configService: ConfigService, @@ -94,10 +94,10 @@ export class SettingsV2Component implements OnInit { ); } - async dismissBadge(type: VaultNudgeType) { - if (!(await firstValueFrom(this.showVaultBadge$)).hasBadgeDismissed) { + async dismissBadge(type: NudgeType) { + if (await firstValueFrom(this.showVaultBadge$)) { const account = await firstValueFrom(this.authenticatedAccount$); - await this.vaultNudgesService.dismissNudge(type, account.id as UserId, true); + await this.nudgesService.dismissNudge(type, account.id as UserId, true); } } } diff --git a/apps/browser/src/vault/popup/components/vault-v2/vault-v2.component.html b/apps/browser/src/vault/popup/components/vault-v2/vault-v2.component.html index 43a96fc616..42e772be06 100644 --- a/apps/browser/src/vault/popup/components/vault-v2/vault-v2.component.html +++ b/apps/browser/src/vault/popup/components/vault-v2/vault-v2.component.html @@ -36,7 +36,7 @@ [subtitle]="'emptyVaultNudgeBody' | i18n" [buttonText]="'emptyVaultNudgeButton' | i18n" (onButtonClick)="navigateToImport()" - (onDismiss)="dismissVaultNudgeSpotlight(VaultNudgeType.EmptyVaultNudge)" + (onDismiss)="dismissVaultNudgeSpotlight(NudgeType.EmptyVaultNudge)" > @@ -44,7 +44,7 @@