diff --git a/polygerrit-ui/app/elements/core/gr-search-bar/gr-search-bar.html b/polygerrit-ui/app/elements/core/gr-search-bar/gr-search-bar.html index 44a1c0d9e2..6a6036325a 100644 --- a/polygerrit-ui/app/elements/core/gr-search-bar/gr-search-bar.html +++ b/polygerrit-ui/app/elements/core/gr-search-bar/gr-search-bar.html @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. --> + diff --git a/polygerrit-ui/app/elements/core/gr-search-bar/gr-search-bar.js b/polygerrit-ui/app/elements/core/gr-search-bar/gr-search-bar.js index 07e306a29e..9dd7901e00 100644 --- a/polygerrit-ui/app/elements/core/gr-search-bar/gr-search-bar.js +++ b/polygerrit-ui/app/elements/core/gr-search-bar/gr-search-bar.js @@ -94,6 +94,7 @@ is: 'gr-search-bar', behaviors: [ + Gerrit.AnonymousNameBehavior, Gerrit.KeyboardShortcutBehavior, Gerrit.URLEncodingBehavior, ], @@ -128,6 +129,13 @@ type: Number, value: 1, }, + _config: Object, + }, + + attached() { + this.$.restAPI.getConfig().then(cfg => { + this._config = cfg; + }); }, _valueChanged(value) { @@ -161,6 +169,10 @@ } }, + _accountOrAnon(name) { + return this.getUserName(this._config, name, false); + }, + /** * Fetch from the API the predicted accounts. * @param {string} predicate - The first part of the search term, e.g. @@ -177,8 +189,14 @@ MAX_AUTOCOMPLETE_RESULTS) .then(accounts => { if (!accounts) { return []; } - return accounts.map(acct => - predicate + ':"' + acct.name + ' <' + acct.email + '>"'); + return accounts.map(acct => { + if (acct.email) { + return predicate + ':"' + this._accountOrAnon(acct) + + ' <' + acct.email + '>"'; + } else { + return predicate + ':"' + this._accountOrAnon(acct) + '"'; + } + }); }).then(accounts => { // When the expression supplied is a beginning substring of 'self', // add it as an autocomplete option. diff --git a/polygerrit-ui/app/elements/core/gr-search-bar/gr-search-bar_test.html b/polygerrit-ui/app/elements/core/gr-search-bar/gr-search-bar_test.html index 059ea7de35..b5cdcd0c8e 100644 --- a/polygerrit-ui/app/elements/core/gr-search-bar/gr-search-bar_test.html +++ b/polygerrit-ui/app/elements/core/gr-search-bar/gr-search-bar_test.html @@ -37,11 +37,17 @@ limitations under the License.