Skip to content

Commit

Permalink
MM-56090 Group Search fix (mattermost#26128)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
sbishel and mattermost-build authored Feb 28, 2024
1 parent 18f7c37 commit b0015c5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ describe('group utils', () => {
describe('filterGroupsMatchingTerm', () => {
const groupA = {
id: 'groupid1',
name: 'board-group',
name: 'board.group',
description: 'group1 description',
display_name: 'board-group',
display_name: 'board.group',
source: 'ldap',
remote_id: 'group1',
create_at: 1,
Expand Down Expand Up @@ -39,7 +39,7 @@ describe('group utils', () => {
};
const groupC = {
id: 'groupid3',
name: 'software-engineers',
name: 'softwareengineers',
description: 'group3 description',
display_name: 'software engineers',
source: 'ldap',
Expand All @@ -63,14 +63,18 @@ describe('group utils', () => {
});

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', () => {
expect(filterGroupsMatchingTerm(groups, 'group')).toEqual([groupA, groupB]);
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', () => {
expect(filterGroupsMatchingTerm(groups, 'software engineers')).toEqual([groupC]);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

import type {Group} from '@mattermost/types/groups';

import {getSuggestionsSplitByMultiple} from './user_utils';
import {getSuggestionsSplitBy, getSuggestionsSplitByMultiple} from './user_utils';

import {General} from '../constants';

export function filterGroupsMatchingTerm(groups: Group[], term: string): Group[] {
const lowercasedTerm = term.toLowerCase();
let trimmedTerm = lowercasedTerm;
if (trimmedTerm.startsWith('@')) {
trimmedTerm = trimmedTerm.substr(1);
trimmedTerm = trimmedTerm.slice(1);
}

return groups.filter((group: Group) => {
Expand All @@ -22,10 +22,10 @@ export function filterGroupsMatchingTerm(groups: Group[], term: string): Group[]
const groupSuggestions: string[] = [];

const groupnameSuggestions = getSuggestionsSplitByMultiple((group.name || '').toLowerCase(), General.AUTOCOMPLETE_SPLIT_CHARACTERS);

groupSuggestions.push(...groupnameSuggestions);
const displayname = (group.display_name || '').toLowerCase();
groupSuggestions.push(displayname);

const suggestions = getSuggestionsSplitBy(group.display_name.toLowerCase(), ' ');
groupSuggestions.push(...suggestions);

return groupSuggestions.
filter((suggestion) => suggestion !== '').
Expand Down

0 comments on commit b0015c5

Please sign in to comment.