From 0ef2156b3f017d0c20875276fd281e17cfbf756e Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Mon, 16 Sep 2019 17:02:52 -0300 Subject: [PATCH] MM-17953 Do not show deactivated users in autocomplete (#3251) * MM-17953 Do not show deactivated users in autocomplete * feedback review --- .../__snapshots__/channel_item.test.js.snap | 104 +++++++++++++++++- .../channel_item/channel_item.js | 5 +- .../channel_item/channel_item.test.js | 1 + .../main/channels_list/channel_item/index.js | 3 + app/selectors/autocomplete.js | 8 +- 5 files changed, 113 insertions(+), 8 deletions(-) diff --git a/app/components/sidebars/main/channels_list/channel_item/__snapshots__/channel_item.test.js.snap b/app/components/sidebars/main/channels_list/channel_item/__snapshots__/channel_item.test.js.snap index aee95be22..5084f4ccd 100644 --- a/app/components/sidebars/main/channels_list/channel_item/__snapshots__/channel_item.test.js.snap +++ b/app/components/sidebars/main/channels_list/channel_item/__snapshots__/channel_item.test.js.snap @@ -484,7 +484,7 @@ exports[`ChannelItem should match snapshot for deactivated user and is searchRes channelId="channel_id" hasDraft={false} isActive={false} - isArchived={true} + isArchived={false} isBot={false} isInfo={false} isUnread={true} @@ -550,7 +550,107 @@ exports[`ChannelItem should match snapshot for deactivated user and is searchRes `; -exports[`ChannelItem should match snapshot for deactivated user and not searchResults or currentChannel 1`] = `null`; +exports[`ChannelItem should match snapshot for deactivated user and not searchResults or currentChannel 1`] = ` + + + + + + + display_name + + + + + +`; exports[`ChannelItem should match snapshot for no displayName 1`] = `null`; diff --git a/app/components/sidebars/main/channels_list/channel_item/channel_item.js b/app/components/sidebars/main/channels_list/channel_item/channel_item.js index 58654311b..5a6ea5e63 100644 --- a/app/components/sidebars/main/channels_list/channel_item/channel_item.js +++ b/app/components/sidebars/main/channels_list/channel_item/channel_item.js @@ -27,6 +27,7 @@ export default class ChannelItem extends PureComponent { channel: PropTypes.object, currentChannelId: PropTypes.string.isRequired, displayName: PropTypes.string.isRequired, + isArchived: PropTypes.bool, isChannelMuted: PropTypes.bool, currentUserId: PropTypes.string.isRequired, isUnread: PropTypes.bool, @@ -44,6 +45,7 @@ export default class ChannelItem extends PureComponent { }; static defaultProps = { + isArchived: false, mentions: 0, }; @@ -89,6 +91,7 @@ export default class ChannelItem extends PureComponent { channelId, currentChannelId, displayName, + isArchived, isChannelMuted, currentUserId, isUnread, @@ -102,8 +105,6 @@ export default class ChannelItem extends PureComponent { isLandscape, } = this.props; - const isArchived = channel.delete_at > 0; - // Only ever show an archived channel if it's the currently viewed channel. // It should disappear as soon as one navigates to another channel. if (isArchived && (currentChannelId !== channelId) && !isSearchResult) { diff --git a/app/components/sidebars/main/channels_list/channel_item/channel_item.test.js b/app/components/sidebars/main/channels_list/channel_item/channel_item.test.js index 5b0fa7558..c6dca8ec7 100644 --- a/app/components/sidebars/main/channels_list/channel_item/channel_item.test.js +++ b/app/components/sidebars/main/channels_list/channel_item/channel_item.test.js @@ -115,6 +115,7 @@ describe('ChannelItem', () => { ...baseProps, channel: channelObj, currentChannelId: 'channel_id', + isArchived: true, }; const wrapper = shallow( diff --git a/app/components/sidebars/main/channels_list/channel_item/index.js b/app/components/sidebars/main/channels_list/channel_item/index.js index c5a11e534..d4d655305 100644 --- a/app/components/sidebars/main/channels_list/channel_item/index.js +++ b/app/components/sidebars/main/channels_list/channel_item/index.js @@ -32,6 +32,7 @@ function makeMapStateToProps() { let displayName = channel.display_name; let isBot = false; let isGuest = false; + let isArchived = channel.delete_at > 0; if (channel.type === General.DM_CHANNEL) { if (ownProps.isSearchResult) { @@ -39,6 +40,7 @@ function makeMapStateToProps() { } else { const teammateId = getUserIdFromChannelName(currentUserId, channel.name); const teammate = getUser(state, teammateId); + isArchived = teammate.delete_at > 0; const teammateNameDisplay = getTeammateNameDisplaySetting(state); displayName = displayUsername(teammate, teammateNameDisplay, false); if (teammate && teammate.is_bot) { @@ -75,6 +77,7 @@ function makeMapStateToProps() { channel, currentChannelId, displayName, + isArchived, isChannelMuted: isChannelMuted(member), currentUserId, hasDraft: Boolean(channelDraft.draft.trim() || channelDraft.files.length), diff --git a/app/selectors/autocomplete.js b/app/selectors/autocomplete.js index 4c4bb8baf..d50e7e3c6 100644 --- a/app/selectors/autocomplete.js +++ b/app/selectors/autocomplete.js @@ -74,12 +74,12 @@ export const filterMembersInChannel = createSelector( let profiles; if (matchTerm) { profiles = profilesInChannel.filter((p) => { - return ((p.id !== currentUserId) && ( + return ((p.id !== currentUserId && p.delete_at === 0) && ( p.username.toLowerCase().includes(matchTerm) || p.email.toLowerCase().includes(matchTerm) || p.first_name.toLowerCase().includes(matchTerm) || p.last_name.toLowerCase().includes(matchTerm))); }); } else { - profiles = profilesInChannel.filter((p) => p.id !== currentUserId); + profiles = profilesInChannel.filter((p) => p.id !== currentUserId && p.delete_at === 0); } // already sorted @@ -99,12 +99,12 @@ export const filterMembersNotInChannel = createSelector( let profiles; if (matchTerm) { profiles = profilesNotInChannel.filter((p) => { - return ((p.id !== currentUserId) && ( + return ((p.id !== currentUserId && p.detele_at === 0) && ( p.username.toLowerCase().includes(matchTerm) || p.email.toLowerCase().includes(matchTerm) || p.first_name.toLowerCase().includes(matchTerm) || p.last_name.toLowerCase().includes(matchTerm))); }); } else { - profiles = profilesNotInChannel; + profiles = profilesNotInChannel.filter((p) => p.delete_at === 0); } return profiles.map((p) => p.id);