From b2e657b159e1b65abf5ece44ca5a7a569c51ff34 Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Mon, 18 Nov 2019 12:56:01 -0300 Subject: [PATCH] MM-19991 Filtering search by channel should also show the channel name and not only its ID (#3561) --- .../autocomplete/channel_mention_item/index.js | 6 +++--- app/selectors/autocomplete.js | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/components/autocomplete/channel_mention_item/index.js b/app/components/autocomplete/channel_mention_item/index.js index c70208684..1671fd391 100644 --- a/app/components/autocomplete/channel_mention_item/index.js +++ b/app/components/autocomplete/channel_mention_item/index.js @@ -20,7 +20,7 @@ function mapStateToProps(state, ownProps) { let isBot = false; let isGuest = false; - if (channel.type === General.DM_CHANNEL) { + if (channel?.type === General.DM_CHANNEL) { const teammate = getUser(state, channel.teammate_id); if (teammate) { displayName = teammate.username; @@ -31,8 +31,8 @@ function mapStateToProps(state, ownProps) { return { displayName, - name: channel.name, - type: channel.type, + name: channel?.name, + type: channel?.type, isBot, isGuest, theme: getTheme(state), diff --git a/app/selectors/autocomplete.js b/app/selectors/autocomplete.js index 838202a11..926a44a48 100644 --- a/app/selectors/autocomplete.js +++ b/app/selectors/autocomplete.js @@ -48,11 +48,11 @@ export const getMatchTermForChannelMention = (() => { lastIsSearch = isSearch; if (match) { if (isSearch) { - lastMatchTerm = match[1]; + lastMatchTerm = match[1].toLowerCase(); } else if (match.index > 0 && value[match.index - 1] === '~') { lastMatchTerm = null; } else { - lastMatchTerm = match[2]; + lastMatchTerm = match[2].toLowerCase(); } } else { lastMatchTerm = null; @@ -152,7 +152,7 @@ export const filterMyChannels = createSelector( if (matchTerm) { channels = myChannels.filter((c) => { return (c.type === General.OPEN_CHANNEL || c.type === General.PRIVATE_CHANNEL) && - (c.name.startsWith(matchTerm) || c.display_name.startsWith(matchTerm)); + (c.name.toLowerCase().startsWith(matchTerm) || c.display_name.toLowerCase().startsWith(matchTerm)); }); } else { channels = myChannels.filter((c) => { @@ -175,7 +175,7 @@ export const filterOtherChannels = createSelector( let channels; if (matchTerm) { channels = otherChannels.filter((c) => { - return (c.name.startsWith(matchTerm) || c.display_name.startsWith(matchTerm)); + return (c.name.toLowerCase().startsWith(matchTerm) || c.display_name.toLowerCase().startsWith(matchTerm)); }); } else { channels = otherChannels; @@ -200,9 +200,9 @@ export const filterPublicChannels = createSelector( if (matchTerm) { channels = myChannels.filter((c) => { return c.type === General.OPEN_CHANNEL && - (c.name.startsWith(matchTerm) || c.display_name.startsWith(matchTerm)); + (c.name.toLowerCase().startsWith(matchTerm) || c.display_name.toLowerCase().startsWith(matchTerm)); }).concat( - otherChannels.filter((c) => c.name.startsWith(matchTerm) || c.display_name.startsWith(matchTerm)) + otherChannels.filter((c) => c.name.toLowerCase().startsWith(matchTerm) || c.display_name.toLowerCase().startsWith(matchTerm)) ); } else { channels = myChannels.filter((c) => { @@ -232,7 +232,7 @@ export const filterPrivateChannels = createSelector( if (matchTerm) { channels = myChannels.filter((c) => { return c.type === General.PRIVATE_CHANNEL && - (c.name.startsWith(matchTerm) || c.display_name.startsWith(matchTerm)); + (c.name.toLowerCase().startsWith(matchTerm) || c.display_name.toLowerCase().startsWith(matchTerm)); }); } else { channels = myChannels.filter((c) => { @@ -261,10 +261,10 @@ export const filterDirectAndGroupMessages = createSelector( let channels; if (matchTerm) { channels = myChannels.filter((c) => { - if (c.type === General.DM_CHANNEL && (originalChannels[c.id].display_name.startsWith(matchTerm))) { + if (c.type === General.DM_CHANNEL && (originalChannels[c.id].display_name.toLowerCase().startsWith(matchTerm))) { return true; } - if (c.type === General.GM_CHANNEL && (c.name.startsWith(matchTerm) || c.display_name.replace(/ /g, '').startsWith(matchTerm))) { + if (c.type === General.GM_CHANNEL && (c.name.toLowerCase().startsWith(matchTerm) || c.display_name.toLowerCase().replace(/ /g, '').startsWith(matchTerm))) { return true; } return false;