From b0015c5a5dfd527f6da69e51d6bc90ce657dd155 Mon Sep 17 00:00:00 2001 From: Scott Bishel Date: Tue, 27 Feb 2024 17:40:45 -0700 Subject: [PATCH] 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 --- .../mattermost-redux/src/utils/group_utils.test.ts | 12 ++++++++---- .../mattermost-redux/src/utils/group_utils.ts | 10 +++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/webapp/channels/src/packages/mattermost-redux/src/utils/group_utils.test.ts b/webapp/channels/src/packages/mattermost-redux/src/utils/group_utils.test.ts index ec06b10862..3ff6120cfc 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/utils/group_utils.test.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/utils/group_utils.test.ts @@ -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, @@ -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', @@ -63,7 +63,7 @@ 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', () => { @@ -71,6 +71,10 @@ describe('group utils', () => { 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]); }); diff --git a/webapp/channels/src/packages/mattermost-redux/src/utils/group_utils.ts b/webapp/channels/src/packages/mattermost-redux/src/utils/group_utils.ts index e38d66fb27..b34295537e 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/utils/group_utils.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/utils/group_utils.ts @@ -3,7 +3,7 @@ import type {Group} from '@mattermost/types/groups'; -import {getSuggestionsSplitByMultiple} from './user_utils'; +import {getSuggestionsSplitBy, getSuggestionsSplitByMultiple} from './user_utils'; import {General} from '../constants'; @@ -11,7 +11,7 @@ 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) => { @@ -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 !== '').