From e1434d8dd5d192bf732a332d7f0dfb8ffd3ad80c Mon Sep 17 00:00:00 2001
From: Jordan Aasen <166539328+jaasen-livefront@users.noreply.github.com>
Date: Fri, 10 Jan 2025 17:21:12 -0800
Subject: [PATCH] [PM-16858] - adjust generator dialog action button to match
browser extension UI (#12788)
* adjust generator dialog buttons to match browser extension UI
* put dialog label into generator config
* fix types. remove i18n key
* use event emitted pattern for getting algorithm config
* favor arrow function
* move function call
* append key to i18n prop
* fix test
---
apps/desktop/src/locales/en/messages.json | 6 ++++++
.../app/vault/credential-generator-dialog.component.html | 8 +++-----
.../app/vault/credential-generator-dialog.component.ts | 6 ++++++
.../components/src/password-generator.component.ts | 5 +++++
.../components/src/username-generator.component.ts | 5 +++++
libs/tools/generator/core/src/data/generators.ts | 6 ++++++
.../src/services/credential-generator.service.spec.ts | 2 ++
.../core/src/services/credential-generator.service.ts | 1 +
.../core/src/types/credential-generator-configuration.ts | 6 ++++++
.../cipher-generator/cipher-form-generator.component.html | 2 ++
.../cipher-generator/cipher-form-generator.component.ts | 5 ++++-
11 files changed, 46 insertions(+), 6 deletions(-)
diff --git a/apps/desktop/src/locales/en/messages.json b/apps/desktop/src/locales/en/messages.json
index 35d5cf8c03..1a02e5db4e 100644
--- a/apps/desktop/src/locales/en/messages.json
+++ b/apps/desktop/src/locales/en/messages.json
@@ -2879,6 +2879,12 @@
"weakAndBreachedMasterPasswordDesc": {
"message": "Weak password identified and found in a data breach. Use a strong and unique password to protect your account. Are you sure you want to use this password?"
},
+ "useThisPassword": {
+ "message": "Use this password"
+ },
+ "useThisUsername": {
+ "message": "Use this username"
+ },
"checkForBreaches": {
"message": "Check known data breaches for this password"
},
diff --git a/apps/desktop/src/vault/app/vault/credential-generator-dialog.component.html b/apps/desktop/src/vault/app/vault/credential-generator-dialog.component.html
index a294ce1f63..d16f8e4f1c 100644
--- a/apps/desktop/src/vault/app/vault/credential-generator-dialog.component.html
+++ b/apps/desktop/src/vault/app/vault/credential-generator-dialog.component.html
@@ -4,6 +4,7 @@
-
diff --git a/apps/desktop/src/vault/app/vault/credential-generator-dialog.component.ts b/apps/desktop/src/vault/app/vault/credential-generator-dialog.component.ts
index abf7437191..ae6f031005 100644
--- a/apps/desktop/src/vault/app/vault/credential-generator-dialog.component.ts
+++ b/apps/desktop/src/vault/app/vault/credential-generator-dialog.component.ts
@@ -14,6 +14,7 @@ import {
CredentialGeneratorHistoryDialogComponent,
GeneratorModule,
} from "@bitwarden/generator-components";
+import { AlgorithmInfo } from "@bitwarden/generator-core";
import { CipherFormGeneratorComponent } from "@bitwarden/vault";
type CredentialGeneratorParams = {
@@ -38,12 +39,17 @@ type CredentialGeneratorParams = {
})
export class CredentialGeneratorDialogComponent {
credentialValue?: string;
+ buttonLabel?: string;
constructor(
@Inject(DIALOG_DATA) protected data: CredentialGeneratorParams,
private dialogService: DialogService,
) {}
+ algorithm = (selected: AlgorithmInfo) => {
+ this.buttonLabel = selected.useGeneratedValue;
+ };
+
applyCredentials = () => {
this.data.onCredentialGenerated(this.credentialValue);
};
diff --git a/libs/tools/generator/components/src/password-generator.component.ts b/libs/tools/generator/components/src/password-generator.component.ts
index 67a1bf2183..85363412ff 100644
--- a/libs/tools/generator/components/src/password-generator.component.ts
+++ b/libs/tools/generator/components/src/password-generator.component.ts
@@ -93,6 +93,10 @@ export class PasswordGeneratorComponent implements OnInit, OnDestroy {
@Output()
readonly onGenerated = new EventEmitter();
+ /** emits algorithm info when the selected algorithm changes */
+ @Output()
+ readonly onAlgorithm = new EventEmitter();
+
async ngOnInit() {
if (this.userId) {
this.userId$.next(this.userId);
@@ -185,6 +189,7 @@ export class PasswordGeneratorComponent implements OnInit, OnDestroy {
// template bindings refresh immediately
this.zone.run(() => {
this.algorithm$.next(algorithm);
+ this.onAlgorithm.next(algorithm);
});
});
diff --git a/libs/tools/generator/components/src/username-generator.component.ts b/libs/tools/generator/components/src/username-generator.component.ts
index d0230dcba4..63c1adc602 100644
--- a/libs/tools/generator/components/src/username-generator.component.ts
+++ b/libs/tools/generator/components/src/username-generator.component.ts
@@ -78,6 +78,10 @@ export class UsernameGeneratorComponent implements OnInit, OnDestroy {
@Output()
readonly onGenerated = new EventEmitter();
+ /** emits algorithm info when the selected algorithm changes */
+ @Output()
+ readonly onAlgorithm = new EventEmitter();
+
/** Removes bottom margin from internal elements */
@Input({ transform: coerceBooleanProperty }) disableMargin = false;
@@ -247,6 +251,7 @@ export class UsernameGeneratorComponent implements OnInit, OnDestroy {
// template bindings refresh immediately
this.zone.run(() => {
this.algorithm$.next(algorithm);
+ this.onAlgorithm.next(algorithm);
});
});
diff --git a/libs/tools/generator/core/src/data/generators.ts b/libs/tools/generator/core/src/data/generators.ts
index afd7da6499..92b20b02b7 100644
--- a/libs/tools/generator/core/src/data/generators.ts
+++ b/libs/tools/generator/core/src/data/generators.ts
@@ -58,6 +58,7 @@ const PASSPHRASE: CredentialGeneratorConfiguration<
generateKey: "generatePassphrase",
generatedValueKey: "passphrase",
copyKey: "copyPassphrase",
+ useGeneratedValueKey: "useThisPassphrase",
onlyOnRequest: false,
request: [],
engine: {
@@ -119,6 +120,7 @@ const PASSWORD: CredentialGeneratorConfiguration<
generateKey: "generatePassword",
generatedValueKey: "password",
copyKey: "copyPassword",
+ useGeneratedValueKey: "useThisPassword",
onlyOnRequest: false,
request: [],
engine: {
@@ -195,6 +197,7 @@ const USERNAME: CredentialGeneratorConfiguration = {
@@ -83,6 +84,7 @@ const SomeConfiguration: CredentialGeneratorConfiguration
diff --git a/libs/vault/src/cipher-form/components/cipher-generator/cipher-form-generator.component.ts b/libs/vault/src/cipher-form/components/cipher-generator/cipher-form-generator.component.ts
index 1a2bac2ce5..fdde5e15d9 100644
--- a/libs/vault/src/cipher-form/components/cipher-generator/cipher-form-generator.component.ts
+++ b/libs/vault/src/cipher-form/components/cipher-generator/cipher-form-generator.component.ts
@@ -5,7 +5,7 @@ import { CommonModule } from "@angular/common";
import { Component, EventEmitter, Input, Output } from "@angular/core";
import { GeneratorModule } from "@bitwarden/generator-components";
-import { GeneratedCredential } from "@bitwarden/generator-core";
+import { AlgorithmInfo, GeneratedCredential } from "@bitwarden/generator-core";
/**
* Renders a password or username generator UI and emits the most recently generated value.
@@ -18,6 +18,9 @@ import { GeneratedCredential } from "@bitwarden/generator-core";
imports: [CommonModule, GeneratorModule],
})
export class CipherFormGeneratorComponent {
+ @Input()
+ algorithm: (selected: AlgorithmInfo) => void;
+
/**
* The type of generator form to show.
*/