Commit 5b40b435 authored by Simon Knox's avatar Simon Knox

Merge branch '330511-fix-autocomplete-showing-non-matches' into 'master'

Fix members autocomplete showing non-matches

See merge request gitlab-org/gitlab!61574
parents e6c5b189 23693d59
......@@ -834,10 +834,10 @@ GfmAutoComplete.Members = {
const lowercaseQuery = query.toLowerCase();
const { nameOrUsernameStartsWith, nameOrUsernameIncludes } = GfmAutoComplete.Members;
return sortBy(members, [
return sortBy(
members.filter((member) => nameOrUsernameIncludes(member, lowercaseQuery)),
(member) => (nameOrUsernameStartsWith(member, lowercaseQuery) ? -1 : 0),
(member) => (nameOrUsernameIncludes(member, lowercaseQuery) ? -1 : 0),
]);
);
},
};
GfmAutoComplete.Labels = {
......
......@@ -691,12 +691,9 @@ describe('GfmAutoComplete', () => {
{ search: 'ErlindaMayert nicolle' },
{ search: 'PhoebeSchaden salina' },
{ search: 'KinaCummings robena' },
// Remaining members are grouped last
{ search: 'Administrator root' },
{ search: 'AntoineLedner ammie' },
];
it('sorts by match with start of name/username, then match with any part of name/username, and maintains sort order', () => {
it('filters out non-matches, then puts matches with start of name/username first', () => {
expect(GfmAutoComplete.Members.sort(query, items)).toMatchObject(expected);
});
});
......
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