Commit ce7fc0b6 authored by Coung Ngo's avatar Coung Ngo

Search across full name for mentions autocomplete

Right now, you cannot search across the full name in at.js
mentions autocomplete due to the space between the first and
second name. This commit updates the search so that
typing @johndoe will match name `John Doe`, and the name
is matched first then username.
parent 1318891b
...@@ -14,6 +14,10 @@ function sanitize(str) { ...@@ -14,6 +14,10 @@ function sanitize(str) {
return str.replace(/<(?:.|\n)*?>/gm, ''); return str.replace(/<(?:.|\n)*?>/gm, '');
} }
function createMemberSearchString(member) {
return `${member.name.replace(/ /g, '')} ${member.username}`;
}
export function membersBeforeSave(members) { export function membersBeforeSave(members) {
return members.map((member) => { return members.map((member) => {
const GROUP_TYPE = 'Group'; const GROUP_TYPE = 'Group';
...@@ -40,7 +44,7 @@ export function membersBeforeSave(members) { ...@@ -40,7 +44,7 @@ export function membersBeforeSave(members) {
username: member.username, username: member.username,
avatarTag: autoCompleteAvatar.length === 1 ? txtAvatar : imgAvatar, avatarTag: autoCompleteAvatar.length === 1 ? txtAvatar : imgAvatar,
title: sanitize(title), title: sanitize(title),
search: sanitize(`${member.username} ${member.name}`), search: sanitize(createMemberSearchString(member)),
icon: avatarIcon, icon: avatarIcon,
availability: member?.availability, availability: member?.availability,
}; };
...@@ -298,9 +302,7 @@ class GfmAutoComplete { ...@@ -298,9 +302,7 @@ class GfmAutoComplete {
// Cache assignees list for easier filtering later // Cache assignees list for easier filtering later
assignees = assignees =
SidebarMediator.singleton?.store?.assignees?.map( SidebarMediator.singleton?.store?.assignees?.map(createMemberSearchString) || [];
(assignee) => `${assignee.username} ${assignee.name}`,
) || [];
const match = GfmAutoComplete.defaultMatcher(flag, subtext, this.app.controllers); const match = GfmAutoComplete.defaultMatcher(flag, subtext, this.app.controllers);
return match && match.length ? match[1] : null; return match && match.length ? match[1] : null;
......
---
title: Search across full name for mentions autocomplete
merge_request: 52488
author:
type: added
...@@ -183,6 +183,16 @@ RSpec.describe 'GFM autocomplete', :js do ...@@ -183,6 +183,16 @@ RSpec.describe 'GFM autocomplete', :js do
expect(find('#at-view-users')).to have_content(user.name) expect(find('#at-view-users')).to have_content(user.name)
end end
it 'searches across full name for assignees' do
page.within '.timeline-content-form' do
find('#note-body').native.send_keys('@speciąlsome')
end
wait_for_requests
expect(find('.atwho-view li', visible: true)).to have_content(user.name)
end
it 'selects the first item for non-assignee dropdowns if a query is entered' do it 'selects the first item for non-assignee dropdowns if a query is entered' do
page.within '.timeline-content-form' do page.within '.timeline-content-form' do
find('#note-body').native.send_keys(':1') find('#note-body').native.send_keys(':1')
......
...@@ -493,7 +493,7 @@ describe('GfmAutoComplete', () => { ...@@ -493,7 +493,7 @@ describe('GfmAutoComplete', () => {
username: 'my-group', username: 'my-group',
avatarTag: '<div class="avatar rect-avatar center avatar-inline s26">M</div>', avatarTag: '<div class="avatar rect-avatar center avatar-inline s26">M</div>',
title: 'My Group (2)', title: 'My Group (2)',
search: 'my-group My Group', search: 'MyGroup my-group',
icon: '', icon: '',
}, },
]); ]);
...@@ -506,7 +506,7 @@ describe('GfmAutoComplete', () => { ...@@ -506,7 +506,7 @@ describe('GfmAutoComplete', () => {
avatarTag: avatarTag:
'<img src="./group.jpg" alt="my-group" class="avatar rect-avatar avatar-inline center s26"/>', '<img src="./group.jpg" alt="my-group" class="avatar rect-avatar avatar-inline center s26"/>',
title: 'My Group (2)', title: 'My Group (2)',
search: 'my-group My Group', search: 'MyGroup my-group',
icon: '', icon: '',
}, },
]); ]);
...@@ -519,7 +519,7 @@ describe('GfmAutoComplete', () => { ...@@ -519,7 +519,7 @@ describe('GfmAutoComplete', () => {
avatarTag: avatarTag:
'<img src="./group.jpg" alt="my-group" class="avatar rect-avatar avatar-inline center s26"/>', '<img src="./group.jpg" alt="my-group" class="avatar rect-avatar avatar-inline center s26"/>',
title: 'My Group', title: 'My Group',
search: 'my-group My Group', search: 'MyGroup my-group',
icon: icon:
'<svg class="s16 vertical-align-middle gl-ml-2"><use xlink:href="undefined#notifications-off" /></svg>', '<svg class="s16 vertical-align-middle gl-ml-2"><use xlink:href="undefined#notifications-off" /></svg>',
}, },
...@@ -537,7 +537,7 @@ describe('GfmAutoComplete', () => { ...@@ -537,7 +537,7 @@ describe('GfmAutoComplete', () => {
avatarTag: avatarTag:
'<img src="./users.jpg" alt="my-user" class="avatar avatar-inline center s26"/>', '<img src="./users.jpg" alt="my-user" class="avatar avatar-inline center s26"/>',
title: 'My User', title: 'My User',
search: 'my-user My User', search: 'MyUser my-user',
icon: '', icon: '',
}, },
]); ]);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment