Skip to content

Commit 030f696

Browse files
authored
Show direct match on top for user search (#17303)
This PR makes sure that direct matches in the user search always show on top of the result list. The following places were checked to follow the desired behavior now: - Search when adding a user to a team - Search when adding a user as a collaborator to a repository Signed-off-by: Maximilian Weiler <[email protected]>
1 parent fa8b8c0 commit 030f696

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

web_src/js/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,15 +2233,21 @@ function searchUsers() {
22332233
url: `${AppSubUrl}/api/v1/users/search?q={query}`,
22342234
onResponse(response) {
22352235
const items = [];
2236+
const searchQueryUppercase = $searchUserBox.find('input').val().toUpperCase();
22362237
$.each(response.data, (_i, item) => {
22372238
let title = item.login;
22382239
if (item.full_name && item.full_name.length > 0) {
22392240
title += ` (${htmlEscape(item.full_name)})`;
22402241
}
2241-
items.push({
2242+
const resultItem = {
22422243
title,
22432244
image: item.avatar_url
2244-
});
2245+
};
2246+
if (searchQueryUppercase === item.login.toUpperCase()) {
2247+
items.unshift(resultItem);
2248+
} else {
2249+
items.push(resultItem);
2250+
}
22452251
});
22462252

22472253
return {results: items};

0 commit comments

Comments
 (0)