MM-56090 Group Search fix (#26128)

* make group search on modal and invite to work like group mentions

* update tests for better coverage

* change it back to startsWith

* update test

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
This commit is contained in:
Scott Bishel 2024-02-27 17:40:45 -07:00 committed by GitHub
parent 18f7c3775a
commit b0015c5a5d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 9 deletions

View File

@ -9,9 +9,9 @@ describe('group utils', () => {
describe('filterGroupsMatchingTerm', () => { describe('filterGroupsMatchingTerm', () => {
const groupA = { const groupA = {
id: 'groupid1', id: 'groupid1',
name: 'board-group', name: 'board.group',
description: 'group1 description', description: 'group1 description',
display_name: 'board-group', display_name: 'board.group',
source: 'ldap', source: 'ldap',
remote_id: 'group1', remote_id: 'group1',
create_at: 1, create_at: 1,
@ -39,7 +39,7 @@ describe('group utils', () => {
}; };
const groupC = { const groupC = {
id: 'groupid3', id: 'groupid3',
name: 'software-engineers', name: 'softwareengineers',
description: 'group3 description', description: 'group3 description',
display_name: 'software engineers', display_name: 'software engineers',
source: 'ldap', source: 'ldap',
@ -63,7 +63,7 @@ describe('group utils', () => {
}); });
it('should match by name', () => { it('should match by name', () => {
expect(filterGroupsMatchingTerm(groups, 'software-engineers')).toEqual([groupC]); expect(filterGroupsMatchingTerm(groups, 'softwareengineers')).toEqual([groupC]);
}); });
it('should match by split part of the name', () => { it('should match by split part of the name', () => {
@ -71,6 +71,10 @@ describe('group utils', () => {
expect(filterGroupsMatchingTerm(groups, 'board')).toEqual([groupA]); expect(filterGroupsMatchingTerm(groups, 'board')).toEqual([groupA]);
}); });
it('should match by split part of the display name', () => {
expect(filterGroupsMatchingTerm(groups, 'engineers')).toEqual([groupC]);
});
it('should match by display_name fully', () => { it('should match by display_name fully', () => {
expect(filterGroupsMatchingTerm(groups, 'software engineers')).toEqual([groupC]); expect(filterGroupsMatchingTerm(groups, 'software engineers')).toEqual([groupC]);
}); });

View File

@ -3,7 +3,7 @@
import type {Group} from '@mattermost/types/groups'; import type {Group} from '@mattermost/types/groups';
import {getSuggestionsSplitByMultiple} from './user_utils'; import {getSuggestionsSplitBy, getSuggestionsSplitByMultiple} from './user_utils';
import {General} from '../constants'; import {General} from '../constants';
@ -11,7 +11,7 @@ export function filterGroupsMatchingTerm(groups: Group[], term: string): Group[]
const lowercasedTerm = term.toLowerCase(); const lowercasedTerm = term.toLowerCase();
let trimmedTerm = lowercasedTerm; let trimmedTerm = lowercasedTerm;
if (trimmedTerm.startsWith('@')) { if (trimmedTerm.startsWith('@')) {
trimmedTerm = trimmedTerm.substr(1); trimmedTerm = trimmedTerm.slice(1);
} }
return groups.filter((group: Group) => { return groups.filter((group: Group) => {
@ -22,10 +22,10 @@ export function filterGroupsMatchingTerm(groups: Group[], term: string): Group[]
const groupSuggestions: string[] = []; const groupSuggestions: string[] = [];
const groupnameSuggestions = getSuggestionsSplitByMultiple((group.name || '').toLowerCase(), General.AUTOCOMPLETE_SPLIT_CHARACTERS); const groupnameSuggestions = getSuggestionsSplitByMultiple((group.name || '').toLowerCase(), General.AUTOCOMPLETE_SPLIT_CHARACTERS);
groupSuggestions.push(...groupnameSuggestions); groupSuggestions.push(...groupnameSuggestions);
const displayname = (group.display_name || '').toLowerCase();
groupSuggestions.push(displayname); const suggestions = getSuggestionsSplitBy(group.display_name.toLowerCase(), ' ');
groupSuggestions.push(...suggestions);
return groupSuggestions. return groupSuggestions.
filter((suggestion) => suggestion !== ''). filter((suggestion) => suggestion !== '').