Fix 'undefined' showing up in account labels
Previously, when there was an account label with an email address but not a username, the username appeared as 'anonymous' along with the email address. This updates the label to either show a name or an email, but not both. In the case of cc's, which always have an email but often not a username, the email will be shown. Bug: Issue 7068 Change-Id: I0dad6bca3cec72d90e7807c5efd9f897e66e7189
This commit is contained in:
@@ -42,15 +42,23 @@ limitations under the License.
|
||||
.text:hover {
|
||||
@apply --gr-account-label-text-hover-style;
|
||||
}
|
||||
.email,
|
||||
.showEmail .name {
|
||||
display: none;
|
||||
}
|
||||
.showEmail .email {
|
||||
display: inline-block;
|
||||
}
|
||||
</style>
|
||||
<span>
|
||||
<template is="dom-if" if="[[!hideAvatar]]">
|
||||
<gr-avatar account="[[account]]"
|
||||
image-size="[[avatarImageSize]]"></gr-avatar>
|
||||
</template>
|
||||
<span class="text">
|
||||
<span>[[_computeName(account, _serverConfig)]]</span>
|
||||
<span hidden$="[[!_computeShowEmail(showEmail, account)]]">
|
||||
<span class$="text [[_computeShowEmailClass(account)]]">
|
||||
<span class="name">
|
||||
[[_computeName(account, _serverConfig)]]</span>
|
||||
<span class="email">
|
||||
[[_computeEmailStr(account)]]
|
||||
</span>
|
||||
<template is="dom-if" if="[[account.status]]">
|
||||
|
@@ -26,10 +26,6 @@
|
||||
type: Number,
|
||||
value: 32,
|
||||
},
|
||||
showEmail: {
|
||||
type: Boolean,
|
||||
value: false,
|
||||
},
|
||||
title: {
|
||||
type: String,
|
||||
reflectToAttribute: true,
|
||||
@@ -76,8 +72,9 @@
|
||||
return result;
|
||||
},
|
||||
|
||||
_computeShowEmail(showEmail, account) {
|
||||
return !!(showEmail && account && account.email);
|
||||
_computeShowEmailClass(account) {
|
||||
if (!account || account.name || !account.email) { return ''; }
|
||||
return 'showEmail';
|
||||
},
|
||||
|
||||
_computeEmailStr(account) {
|
||||
|
@@ -78,23 +78,21 @@ limitations under the License.
|
||||
}),
|
||||
'Anonymous <andybons+gerrit@gmail.com>');
|
||||
|
||||
assert.equal(element._computeShowEmail(true,
|
||||
assert.equal(element._computeShowEmailClass(
|
||||
{
|
||||
name: 'Andrew Bonventre',
|
||||
email: 'andybons+gerrit@gmail.com',
|
||||
}), true);
|
||||
}), '');
|
||||
|
||||
assert.equal(element._computeShowEmail(true,
|
||||
{name: 'Andrew Bonventre'}), false);
|
||||
assert.equal(element._computeShowEmailClass(
|
||||
{
|
||||
email: 'andybons+gerrit@gmail.com',
|
||||
}), 'showEmail');
|
||||
|
||||
assert.equal(element._computeShowEmail(false,
|
||||
{name: 'Andrew Bonventre'}), false);
|
||||
assert.equal(element._computeShowEmailClass({name: 'Andrew Bonventre'}),
|
||||
'');
|
||||
|
||||
assert.equal(element._computeShowEmail(
|
||||
true, undefined), false);
|
||||
|
||||
assert.equal(element._computeShowEmail(
|
||||
false, undefined), false);
|
||||
assert.equal(element._computeShowEmailClass(undefined), '');
|
||||
|
||||
assert.equal(
|
||||
element._computeEmailStr({name: 'test', email: 'test'}), '(test)');
|
||||
|
@@ -39,8 +39,7 @@ limitations under the License.
|
||||
<span>
|
||||
<a href$="[[_computeOwnerLink(account)]]" tabindex="-1">
|
||||
<gr-account-label account="[[account]]"
|
||||
avatar-image-size="[[avatarImageSize]]"
|
||||
show-email="[[_computeShowEmail(account)]]"></gr-account-label>
|
||||
avatar-image-size="[[avatarImageSize]]"></gr-account-label>
|
||||
</a>
|
||||
</span>
|
||||
</template>
|
||||
|
@@ -35,9 +35,5 @@
|
||||
account.email || account.username || account.name ||
|
||||
account._account_id);
|
||||
},
|
||||
|
||||
_computeShowEmail(account) {
|
||||
return !!(account && !account.name);
|
||||
},
|
||||
});
|
||||
})();
|
||||
|
@@ -34,17 +34,44 @@ limitations under the License.
|
||||
<script>
|
||||
suite('gr-account-link tests', () => {
|
||||
let element;
|
||||
let sandbox;
|
||||
|
||||
setup(() => {
|
||||
stub('gr-rest-api-interface', {
|
||||
getConfig() { return Promise.resolve({}); },
|
||||
});
|
||||
element = fixture('basic');
|
||||
sandbox = sinon.sandbox.create();
|
||||
});
|
||||
|
||||
teardown(() => {
|
||||
sandbox.restore();
|
||||
});
|
||||
|
||||
test('computed fields', () => {
|
||||
assert.equal(element._computeShowEmail({name: 'asd'}), false);
|
||||
assert.equal(element._computeShowEmail({}), true);
|
||||
const url = 'test/url';
|
||||
const urlStub = sandbox.stub(Gerrit.Nav, 'getUrlForOwner').returns(url);
|
||||
const account = {
|
||||
email: 'email',
|
||||
username: 'username',
|
||||
name: 'name',
|
||||
_account_id: '_account_id',
|
||||
};
|
||||
assert.isNotOk(element._computeOwnerLink());
|
||||
assert.equal(element._computeOwnerLink(account), url);
|
||||
assert.isTrue(urlStub.lastCall.calledWithExactly('email'));
|
||||
|
||||
delete account.email;
|
||||
assert.equal(element._computeOwnerLink(account), url);
|
||||
assert.isTrue(urlStub.lastCall.calledWithExactly('username'));
|
||||
|
||||
delete account.username;
|
||||
assert.equal(element._computeOwnerLink(account), url);
|
||||
assert.isTrue(urlStub.lastCall.calledWithExactly('name'));
|
||||
|
||||
delete account.name;
|
||||
assert.equal(element._computeOwnerLink(account), url);
|
||||
assert.isTrue(urlStub.lastCall.calledWithExactly('_account_id'));
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
Reference in New Issue
Block a user