Skip to content

Commit

Permalink
Filter mention suggestions by login
Browse files Browse the repository at this point in the history
  • Loading branch information
MonilBhavsar committed Jun 19, 2023
1 parent edade12 commit 8cbc40c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 16 deletions.
5 changes: 0 additions & 5 deletions src/components/MentionSuggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ function MentionSuggestions(props) {
const styledDisplayName = getStyledTextArray(item.text, props.prefix);
const styledHandle = getStyledTextArray(item.alternateText, props.prefix);

console.debug('~~Monil styledDisplayName');
console.debug(styledDisplayName);
console.debug('~~Monil styledHandle');
console.debug(styledHandle);

return (
<View style={[styles.autoCompleteSuggestionContainer, styles.ph2]}>
<View style={styles.mentionSuggestionsAvatarContainer}>
Expand Down
4 changes: 0 additions & 4 deletions src/libs/GetStyledTextArray.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import Str from 'expensify-common/lib/str';
*/
const getStyledTextArray = (name, prefix) => {
const texts = [];
console.log(`~~Monil logs name ${name} and prefix ${prefix}`);
if (!name) {
return texts;
}
const prefixLowercase = prefix.toLowerCase();
const prefixLocation = name.toLowerCase().search(Str.escapeForRegExp(prefixLowercase));

Expand Down
12 changes: 5 additions & 7 deletions src/pages/home/report/ReportActionCompose.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,6 @@ class ReportActionCompose extends React.Component {
* @returns {Object}
*/
getMentionOptions(personalDetails, searchValue = '') {
console.debug(`~~Monil logs personalDetails`);
console.debug(personalDetails);
const suggestions = [];

if (CONST.AUTO_COMPLETE_SUGGESTER.HERE_TEXT.includes(searchValue.toLowerCase())) {
Expand All @@ -454,6 +452,10 @@ class ReportActionCompose extends React.Component {
}

const filteredPersonalDetails = _.filter(_.values(personalDetails), (detail) => {
// If we don't have user's primary login, that member is not known to the current user and hence we do not allow them to be mentioned
if (!detail.login) {
return false;
}
if (searchValue && !`${detail.displayName} ${detail.login}`.toLowerCase().includes(searchValue.toLowerCase())) {
return false;
}
Expand All @@ -462,7 +464,6 @@ class ReportActionCompose extends React.Component {

const sortedPersonalDetails = _.sortBy(filteredPersonalDetails, (detail) => detail.displayName || detail.login);
_.each(_.first(sortedPersonalDetails, CONST.AUTO_COMPLETE_SUGGESTER.MAX_AMOUNT_OF_ITEMS - suggestions.length), (detail) => {
console.debug(`~~Monil logs detail ${JSON.stringify(detail)}`);
suggestions.push({
text: detail.displayName,
alternateText: detail.login,
Expand Down Expand Up @@ -637,14 +638,11 @@ class ReportActionCompose extends React.Component {
* @param {Number} highlightedMentionIndex
*/
insertSelectedMention(highlightedMentionIndex) {
console.debug(`~~Monil selected mention ${highlightedMentionIndex}`);
console.debug(this.state.suggestedMentions);
const commentBeforeAtSign = this.state.value.slice(0, this.state.atSignIndex);
const mentionObject = this.state.suggestedMentions[highlightedMentionIndex];
const mentionCode = mentionObject.text === CONST.AUTO_COMPLETE_SUGGESTER.HERE_TEXT ? CONST.AUTO_COMPLETE_SUGGESTER.HERE_TEXT : `@${mentionObject.text}`;
const mentionCode = mentionObject.text === CONST.AUTO_COMPLETE_SUGGESTER.HERE_TEXT ? CONST.AUTO_COMPLETE_SUGGESTER.HERE_TEXT : `@${mentionObject.alternateText}`;
const commentAfterAtSignWithMentionRemoved = this.state.value.slice(this.state.atSignIndex).replace(CONST.REGEX.MENTION_REPLACER, '');

console.debug(`~~Monil mentionCode ${mentionCode}`);
this.updateComment(`${commentBeforeAtSign}${mentionCode} ${this.trimLeadingSpace(commentAfterAtSignWithMentionRemoved)}`, true);
this.setState((prevState) => ({
selection: {
Expand Down

0 comments on commit 8cbc40c

Please sign in to comment.