1
0
mirror of https://github.com/bitwarden/browser.git synced 2025-02-23 02:31:26 +01:00

wip - copy button overhaul

This commit is contained in:
jaasen-livefront 2025-02-20 17:02:19 -08:00
parent 657902cdcc
commit 6acd671f35
No known key found for this signature in database
3 changed files with 103 additions and 18 deletions

View File

@ -4175,6 +4175,20 @@
}
}
},
"copyFieldValue": {
"message": "Copy $FIELD$, $VALUE$",
"description": "Title for a button that copies a field value to the clipboard.",
"placeholders": {
"field": {
"content": "$1",
"example": "Username"
},
"value": {
"content": "$2",
"example": "Foo"
}
}
},
"noValuesToCopy": {
"message": "No values to copy"
},

View File

@ -40,28 +40,41 @@
bitIconButton="bwi-clone"
size="small"
[appA11yTitle]="
hasLoginValues ? ('copyInfoTitle' | i18n: cipher.name) : ('noValuesToCopy' | i18n)
'copyFieldValue' | i18n: singleCopiableLogin.field : singleCopiableLogin.value
"
[disabled]="!hasLoginValues"
[bitMenuTriggerFor]="loginOptions"
[appCopyClick]="singleCopiableLogin.value"
[valueLabel]="singleCopiableLogin.field"
*ngIf="singleCopiableLogin"
></button>
<bit-menu #loginOptions>
<button type="button" bitMenuItem appCopyField="username" [cipher]="cipher">
{{ "copyUsername" | i18n }}
</button>
<ng-container *ngIf="!singleCopiableLogin">
<button
*ngIf="cipher.viewPassword"
type="button"
bitMenuItem
appCopyField="password"
[cipher]="cipher"
>
{{ "copyPassword" | i18n }}
</button>
<button type="button" bitMenuItem appCopyField="totp" [cipher]="cipher">
{{ "copyVerificationCode" | i18n }}
</button>
</bit-menu>
bitIconButton="bwi-clone"
size="small"
[appA11yTitle]="
hasLoginValues ? ('copyInfoTitle' | i18n: cipher.name) : ('noValuesToCopy' | i18n)
"
[disabled]="!hasLoginValues"
[bitMenuTriggerFor]="loginOptions"
></button>
<bit-menu #loginOptions>
<button type="button" bitMenuItem appCopyField="username" [cipher]="cipher">
{{ "copyUsername" | i18n }}
</button>
<button
*ngIf="cipher.viewPassword"
type="button"
bitMenuItem
appCopyField="password"
[cipher]="cipher"
>
{{ "copyPassword" | i18n }}
</button>
<button type="button" bitMenuItem appCopyField="totp" [cipher]="cipher">
{{ "copyVerificationCode" | i18n }}
</button>
</bit-menu>
</ng-container>
</bit-item-action>
</ng-template>
</ng-container>

View File

@ -37,6 +37,64 @@ export class ItemCopyActionsComponent {
);
}
get singleCopiableLogin() {
const { username, password, hasTotp, totp } = this.cipher.login;
// If there is both a username and password but the password is not viewable, then the username is the only copiable value
if (username && password && !this.cipher.viewPassword) {
return {
value: username,
field: "username",
};
}
if (username && !password && !hasTotp) {
return {
value: username,
field: "username",
};
}
if (!username && password && !hasTotp) {
return {
value: password,
field: "password",
};
}
if (!username && !password && hasTotp) {
return {
value: totp,
field: "totp",
};
}
return null;
}
get singleCopiableCardValue() {
const { code, number } = this.cipher.card;
if (code && !number) {
return code;
}
if (!code && number) {
return number;
}
return null;
}
get singleCopiableIdentityValue() {
const { fullAddressForCopy, email, username, phone } = this.cipher.identity;
if (fullAddressForCopy && !email && !username && !phone) {
return fullAddressForCopy;
}
if (!fullAddressForCopy && email && !username && !phone) {
return email;
}
if (!fullAddressForCopy && !email && username && !phone) {
return username;
}
if (!fullAddressForCopy && !email && !username && phone) {
return phone;
}
return null;
}
get hasCardValues() {
return !!this.cipher.card.code || !!this.cipher.card.number;
}