]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1566079 - User autocomplete doesn’t work for requestee for certain flags
authorKohei Yoshino <kohei.yoshino@gmail.com>
Mon, 15 Jul 2019 22:31:43 +0000 (18:31 -0400)
committerGitHub <noreply@github.com>
Mon, 15 Jul 2019 22:31:43 +0000 (18:31 -0400)
js/field.js

index 639484ac15eaf49f840c86877431f8c8205f4f39..5631e6cf9d2344a134cffd9b8f13ca763d236e29 100644 (file)
@@ -738,28 +738,27 @@ $(function() {
         },
         formatResult: function(suggestion) {
             const $input = this;
-            const user = suggestion.data;
+            const { email, real_name, requests, gravatar } = suggestion.data;
             const request_type = $input.getAttribute('data-request-type');
-            const blocked = user.requests && request_type ? user.requests[request_type].blocked : false;
-            const pending = user.requests && request_type ? user.requests[request_type].pending : 0;
-            const image = user.gravatar ? `<img itemprop="image" alt="" src="${user.gravatar}">` : '';
+            const { blocked, pending } = requests ? (requests[request_type] || {}) : {};
+            const image = gravatar ? `<img itemprop="image" alt="" src="${gravatar}">` : '';
             const description = blocked ? '<span class="icon" aria-hidden="true"></span> Requests blocked' :
                 pending ? `${pending} pending ${request_type}${pending === 1 ? '' : 's'}` : '';
 
             return `<div itemscope itemtype="http://schema.org/Person">${image} ` +
-                `<span itemprop="name">${user.real_name.htmlEncode()}</span> ` +
-                `<span class="minor" itemprop="email">${user.email.htmlEncode()}</span> ` +
+                `<span itemprop="name">${real_name.htmlEncode()}</span> ` +
+                `<span class="minor" itemprop="email">${email.htmlEncode()}</span> ` +
                 `<span class="minor${blocked ? ' blocked' : ''}" itemprop="description">${description}</span></div>`;
         },
         onSelect: function (suggestion) {
             const $input = this;
-            const user = suggestion.data;
+            const { real_name, requests } = suggestion.data;
             const is_multiple = !!$input.getAttribute('data-multiple');
             const request_type = $input.getAttribute('data-request-type');
-            const blocked = user.requests && request_type ? user.requests[request_type].blocked : false;
+            const { blocked } = requests ? (requests[request_type] || {}) : {};
 
             if (blocked) {
-                window.alert(`${user.real_name} is not accepting ${request_type} requests at this time. ` +
+                window.alert(`${real_name} is not accepting ${request_type} requests at this time. ` +
                     'If you’re in a hurry, ask someone else for help.');
             } else if (is_multiple) {
                 const _values = $input.value.split(',').map(value => value.trim());