-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace account service with Input #13045
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,12 @@ | |
// @ts-strict-ignore | ||
import { DialogRef } from "@angular/cdk/dialog"; | ||
import { CommonModule } from "@angular/common"; | ||
import { Component } from "@angular/core"; | ||
import { Component, Input } from "@angular/core"; | ||
import { takeUntilDestroyed } from "@angular/core/rxjs-interop"; | ||
import { BehaviorSubject, distinctUntilChanged, firstValueFrom, map, switchMap } from "rxjs"; | ||
import { BehaviorSubject, firstValueFrom, map, switchMap } from "rxjs"; | ||
|
||
import { JslibModule } from "@bitwarden/angular/jslib.module"; | ||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; | ||
import { Account } from "@bitwarden/common/auth/abstractions/account.service"; | ||
import { UserId } from "@bitwarden/common/types/guid"; | ||
import { ButtonModule, DialogModule, DialogService } from "@bitwarden/components"; | ||
import { GeneratorHistoryService } from "@bitwarden/generator-history"; | ||
|
@@ -28,22 +28,18 @@ import { EmptyCredentialHistoryComponent } from "./empty-credential-history.comp | |
], | ||
}) | ||
export class CredentialGeneratorHistoryDialogComponent { | ||
@Input() account: Account | null = null; | ||
protected readonly hasHistory$ = new BehaviorSubject<boolean>(false); | ||
protected readonly userId$ = new BehaviorSubject<UserId>(null); | ||
|
||
constructor( | ||
private accountService: AccountService, | ||
private history: GeneratorHistoryService, | ||
private dialogService: DialogService, | ||
private dialogRef: DialogRef, | ||
) { | ||
this.accountService.activeAccount$ | ||
.pipe( | ||
takeUntilDestroyed(), | ||
map(({ id }) => id), | ||
distinctUntilChanged(), | ||
) | ||
.subscribe(this.userId$); | ||
if (this.account) { | ||
this.userId$.next(this.account.id); | ||
} | ||
Comment on lines
+40
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. โ ๐ This feedback also applies to |
||
|
||
this.userId$ | ||
.pipe( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ import { | |
withLatestFrom, | ||
} from "rxjs"; | ||
|
||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service"; | ||
import { Account } from "@bitwarden/common/auth/abstractions/account.service"; | ||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; | ||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; | ||
import { IntegrationId } from "@bitwarden/common/tools/integration"; | ||
|
@@ -57,7 +57,6 @@ export class CredentialGeneratorComponent implements OnInit, OnDestroy { | |
private toastService: ToastService, | ||
private logService: LogService, | ||
private i18nService: I18nService, | ||
private accountService: AccountService, | ||
private zone: NgZone, | ||
private formBuilder: FormBuilder, | ||
) {} | ||
|
@@ -68,6 +67,9 @@ export class CredentialGeneratorComponent implements OnInit, OnDestroy { | |
@Input() | ||
userId: UserId | null; | ||
|
||
@Input() | ||
account: Account | null = null; | ||
|
||
/** Emits credentials created from a generation request. */ | ||
@Output() | ||
readonly onGenerated = new EventEmitter<GeneratedCredential>(); | ||
|
@@ -97,13 +99,9 @@ export class CredentialGeneratorComponent implements OnInit, OnDestroy { | |
if (this.userId) { | ||
this.userId$.next(this.userId); | ||
} else { | ||
this.accountService.activeAccount$ | ||
.pipe( | ||
map((acct) => acct.id), | ||
distinctUntilChanged(), | ||
takeUntil(this.destroyed), | ||
) | ||
.subscribe(this.userId$); | ||
if (this.account) { | ||
this.userId$.next(this.account.id); | ||
} | ||
Comment on lines
+102
to
+104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๐จ Once you've implemented |
||
} | ||
|
||
this.generatorService | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๐ All of the generator components should have a consistent implementation; these comments apply to all of them.
โ๏ธ The
account
property should replace theUserId
property in all of the modified generator components.โ These components should implement
OnChanges
and populate anaccount$
member when theaccount
input changes. That member then replaces the existing uses ofsingleUserId$
. Without theOnChange
implementation, Angular won't update the component when a new account is transmitted to the component through the@Input
.References:
OnChanges
interfacengOnChanges
handler