From 734818790fc52263f05bf0fac56941330b5a77e0 Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Mon, 4 Jul 2016 11:03:43 -0400 Subject: PLT-2640 Added searching users by additional field when autocompleting @mentions (#3412) * Added the ability to search users by their first/last name or nickname when using @mentions * Changed @mention autocomplete to display a user's nickname --- .../components/suggestion/at_mention_provider.jsx | 54 ++++++++++++++++------ webapp/sass/components/_mentions.scss | 1 - 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/webapp/components/suggestion/at_mention_provider.jsx b/webapp/components/suggestion/at_mention_provider.jsx index aec1252ea..e650ad3e7 100644 --- a/webapp/components/suggestion/at_mention_provider.jsx +++ b/webapp/components/suggestion/at_mention_provider.jsx @@ -16,12 +16,13 @@ const MaxUserSuggestions = 40; class AtMentionSuggestion extends Suggestion { render() { - const {item, isSelection} = this.props; + const isSelection = this.props.isSelection; + const user = this.props.item; let username; let description; let icon; - if (item.username === 'all') { + if (user.username === 'all') { username = 'all'; description = ( ); icon = ; - } else if (item.username === 'channel') { + } else if (user.username === 'channel') { username = 'channel'; description = ( ; } else { - username = item.username; - description = Utils.getFullName(item); + username = user.username; + + if ((user.first_name || user.last_name) && user.nickname) { + description = ` - ${Utils.getFullName(user)} (${user.nickname})`; + } else if (user.nickname) { + description = ` - (${user.nickname})`; + } else if (user.first_name || user.last_name) { + description = ` - ${Utils.getFullName(user)}`; + } + icon = ( a.username.localeCompare(b.username)); + filtered.sort((a, b) => { + const aPrefix = a.username.startsWith(prefix); + const bPrefix = b.username.startsWith(prefix); + + if (aPrefix === bPrefix) { + return a.username.localeCompare(b.username); + } else if (aPrefix) { + return -1; + } + + return 1; + }); const mentions = filtered.map((user) => '@' + user.username); diff --git a/webapp/sass/components/_mentions.scss b/webapp/sass/components/_mentions.scss index 82f626eaf..17f67d080 100644 --- a/webapp/sass/components/_mentions.scss +++ b/webapp/sass/components/_mentions.scss @@ -50,7 +50,6 @@ .mention__fullname { @include opacity(.5); - padding-left: 10px; } .mention--highlight { -- cgit v1.2.3-1-g7c22