diff --git a/apps/browser/src/_locales/en/messages.json b/apps/browser/src/_locales/en/messages.json index 51fb3a0a770..7db06f37d36 100644 --- a/apps/browser/src/_locales/en/messages.json +++ b/apps/browser/src/_locales/en/messages.json @@ -445,6 +445,18 @@ "generatePassphrase": { "message": "Generate passphrase" }, + "passwordGenerated": { + "message": "Password generated" + }, + "passphraseGenerated": { + "message": "Passphrase generated" + }, + "usernameGenerated": { + "message": "Username generated" + }, + "emailGenerated": { + "message": "Email generated" + }, "regeneratePassword": { "message": "Regenerate password" }, diff --git a/libs/tools/generator/components/src/credential-generator-history.component.ts b/libs/tools/generator/components/src/credential-generator-history.component.ts index 69ed0b0336d..7e476564de6 100644 --- a/libs/tools/generator/components/src/credential-generator-history.component.ts +++ b/libs/tools/generator/components/src/credential-generator-history.component.ts @@ -72,6 +72,6 @@ export class CredentialGeneratorHistoryComponent { protected getGeneratedValueText(credential: GeneratedCredential) { const info = this.generatorService.algorithm(credential.category); - return info.generatedValue; + return info.credentialType; } } diff --git a/libs/tools/generator/components/src/credential-generator.component.html b/libs/tools/generator/components/src/credential-generator.component.html index ce86abe80ae..91ede6f9151 100644 --- a/libs/tools/generator/components/src/credential-generator.component.html +++ b/libs/tools/generator/components/src/credential-generator.component.html @@ -37,6 +37,7 @@ [disabled]="!(algorithm$ | async)" > +
{{ credentialGeneratedMessage$ | async }}
!!algorithm), - map(({ generatedValue }) => generatedValue), + map(({ credentialType }) => credentialType), ); /** Emits hint key for the currently selected credential type */ @@ -491,6 +493,14 @@ export class CredentialGeneratorComponent implements OnInit, OnDestroy { /** Emits when a new credential is requested */ private readonly generate$ = new Subject(); + /** + * Emits the credential generated message whenever the generator runs + */ + protected credentialGeneratedMessage$ = this.value$.pipe( + withLatestFrom(this.algorithm$), + concatMap(([, algorithm]) => of("", algorithm.onGeneratedMessage)), + ); + /** Request a new value from the generator * @param requestor a label used to trace generation request * origin in the debugger. diff --git a/libs/tools/generator/components/src/password-generator.component.html b/libs/tools/generator/components/src/password-generator.component.html index a6aa5ebdd02..519846351e8 100644 --- a/libs/tools/generator/components/src/password-generator.component.html +++ b/libs/tools/generator/components/src/password-generator.component.html @@ -35,6 +35,7 @@ [disabled]="!(algorithm$ | async)" > +
{{ credentialGeneratedMessage$ | async }}
!!algorithm), - map(({ generatedValue }) => generatedValue), + map(({ credentialType }) => credentialType), + ); + + /** + * Emits the credential generated message whenever the generator runs + */ + protected credentialGeneratedMessage$ = this.value$.pipe( + withLatestFrom(this.algorithm$), + concatMap(([, algorithm]) => of("", algorithm.onGeneratedMessage)), ); private toOptions(algorithms: AlgorithmInfo[]) { diff --git a/libs/tools/generator/components/src/username-generator.component.html b/libs/tools/generator/components/src/username-generator.component.html index 31e224713ed..58f4c379d9d 100644 --- a/libs/tools/generator/components/src/username-generator.component.html +++ b/libs/tools/generator/components/src/username-generator.component.html @@ -26,6 +26,7 @@ {{ credentialTypeCopyLabel$ | async }} +
{{ credentialGeneratedMessage$ | async }}
diff --git a/libs/tools/generator/components/src/username-generator.component.ts b/libs/tools/generator/components/src/username-generator.component.ts index 63c1adc602b..9d053007726 100644 --- a/libs/tools/generator/components/src/username-generator.component.ts +++ b/libs/tools/generator/components/src/username-generator.component.ts @@ -8,9 +8,11 @@ import { catchError, combineLatest, combineLatestWith, + concatMap, distinctUntilChanged, filter, map, + of, ReplaySubject, Subject, switchMap, @@ -375,6 +377,18 @@ export class UsernameGeneratorComponent implements OnInit, OnDestroy { /** tracks the currently selected credential type */ protected algorithm$ = new ReplaySubject(1); + /** Emits hint key for the currently selected credential type */ + protected credentialTypeHint$ = new ReplaySubject(1); + + /** Emits the last generated value. */ + protected readonly value$ = new BehaviorSubject(""); + + /** Emits when the userId changes */ + protected readonly userId$ = new BehaviorSubject(null); + + /** Emits when a new credential is requested */ + private readonly generate$ = new Subject(); + protected showAlgorithm$ = this.algorithm$.pipe( combineLatestWith(this.showForwarder$), map(([algorithm, showForwarder]) => (showForwarder ? null : algorithm)), @@ -401,20 +415,16 @@ export class UsernameGeneratorComponent implements OnInit, OnDestroy { */ protected credentialTypeLabel$ = this.algorithm$.pipe( filter((algorithm) => !!algorithm), - map(({ generatedValue }) => generatedValue), + map(({ credentialType }) => credentialType), ); - /** Emits hint key for the currently selected credential type */ - protected credentialTypeHint$ = new ReplaySubject(1); - - /** Emits the last generated value. */ - protected readonly value$ = new BehaviorSubject(""); - - /** Emits when the userId changes */ - protected readonly userId$ = new BehaviorSubject(null); - - /** Emits when a new credential is requested */ - private readonly generate$ = new Subject(); + /** + * Emits the credential generated message whenever the generator runs + */ + protected credentialGeneratedMessage$ = this.value$.pipe( + withLatestFrom(this.algorithm$), + concatMap(([, algorithm]) => of("", algorithm.onGeneratedMessage)), + ); /** Request a new value from the generator * @param requestor a label used to trace generation request diff --git a/libs/tools/generator/core/src/data/generators.ts b/libs/tools/generator/core/src/data/generators.ts index 92b20b02b75..0f957f2cecf 100644 --- a/libs/tools/generator/core/src/data/generators.ts +++ b/libs/tools/generator/core/src/data/generators.ts @@ -56,7 +56,8 @@ const PASSPHRASE: CredentialGeneratorConfiguration< category: "password", nameKey: "passphrase", generateKey: "generatePassphrase", - generatedValueKey: "passphrase", + onGeneratedMessageKey: "passphraseGenerated", + credentialTypeKey: "passphrase", copyKey: "copyPassphrase", useGeneratedValueKey: "useThisPassphrase", onlyOnRequest: false, @@ -118,7 +119,8 @@ const PASSWORD: CredentialGeneratorConfiguration< category: "password", nameKey: "password", generateKey: "generatePassword", - generatedValueKey: "password", + onGeneratedMessageKey: "passwordGenerated", + credentialTypeKey: "password", copyKey: "copyPassword", useGeneratedValueKey: "useThisPassword", onlyOnRequest: false, @@ -195,7 +197,8 @@ const USERNAME: CredentialGeneratorConfiguration