Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HOLD for payment 2023-06-02] [$1000] Mention auto-suggester adds extra spaces when same mention is selected #18742

Closed
puneetlath opened this issue May 10, 2023 · 31 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor

Comments

@puneetlath
Copy link
Contributor

puneetlath commented May 10, 2023

Screen.Recording.2023-05-10.at.3.55.29.PM.mov

When you select the same mention again via the auto-suggestion menu extra spaces are added. We shouldn't do that.

@szebniok do you want to take this one?

Reported by @0xmiroslav

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~0179550c85e09022ec
  • Upwork Job ID: 1658193553722515456
  • Last Price Increase: 2023-05-15
@puneetlath puneetlath added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels May 10, 2023
@melvin-bot
Copy link

melvin-bot bot commented May 10, 2023

Triggered auto assignment to @isabelastisser (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

@melvin-bot
Copy link

melvin-bot bot commented May 10, 2023

Bug0 Triage Checklist (Main S/O)

  • This "bug" occurs on a supported platform (ensure Platforms in OP are ✅)
  • This bug is not a duplicate report (check E/App issues and #expensify-bugs)
    • If it is, comment with a link to the original report, close the issue and add any novel details to the original issue instead
  • This bug is reproducible using the reproduction steps in the OP. S/O
    • If the reproduction steps are clear and you're unable to reproduce the bug, check with the reporter and QA first, then close the issue.
    • If the reproduction steps aren't clear and you determine the correct steps, please update the OP.
  • This issue is filled out as thoroughly and clearly as possible
    • Pay special attention to the title, results, platforms where the bug occurs, and if the bug happens on staging/production.
  • I have reviewed and subscribed to the linked Slack conversation to ensure Slack/Github stay in sync

@allroundexperts
Copy link
Contributor

allroundexperts commented May 10, 2023

Proposal

Please re-state the problem that we are trying to solve in this issue.

Mention auto suggester adds extra space when same mentioned is selected

What is the root cause of that problem?

The root cause of this problem is that we're always adding an extra space here regardless if the commentAfterAtSignWithMentionRemoved starts with a space.

The same error occurs with emoji selection as well.

What changes do you think we should make in order to solve the problem?

We need to replace this line with:

`${commentBeforeAtSign}${mentionCode} ${
                commentAfterAtSignWithMentionRemoved.slice(0, 1) === ' ' ? commentAfterAtSignWithMentionRemoved.slice(1) : commentAfterAtSignWithMentionRemoved
            }`

We'll need to do the same in the insertSelectedEmoji function as well.

What alternative solutions did you explore? (Optional)

None

The insertSelectedEmoji and insertSelectedMention have almost the same functionality and we're really violating the DRY principle here. As such, we should just create a single generic function here that replaces the both and does the job.

@melvin-bot melvin-bot bot added the Overdue label May 15, 2023
@puneetlath puneetlath added the External Added to denote the issue can be worked on by a contributor label May 15, 2023
@melvin-bot melvin-bot bot changed the title Mention auto-suggester adds extra spaces when same mention is selected [$1000] Mention auto-suggester adds extra spaces when same mention is selected May 15, 2023
@melvin-bot
Copy link

melvin-bot bot commented May 15, 2023

Job added to Upwork: https://www.upwork.com/jobs/~0179550c85e09022ec

@melvin-bot
Copy link

melvin-bot bot commented May 15, 2023

Current assignee @puneetlath is eligible for the External assigner, not assigning anyone new.

@melvin-bot
Copy link

melvin-bot bot commented May 15, 2023

Triggered auto assignment to Contributor-plus team member for initial proposal review - @thesahindia (External)

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label May 15, 2023
@melvin-bot
Copy link

melvin-bot bot commented May 15, 2023

Current assignee @puneetlath is eligible for the External assigner, not assigning anyone new.

@puneetlath
Copy link
Contributor Author

Marking external since @szebniok is off for the rest of the week.

@melvin-bot melvin-bot bot removed the Overdue label May 15, 2023
@puneetlath
Copy link
Contributor Author

@thesahindia note that @allroundexperts has already posted a proposal for review above.

@dukenv0307
Copy link
Contributor

dukenv0307 commented May 16, 2023

Proposal

Please re-state the problem that we are trying to solve in this issue.

Mention auto-suggester adds extra spaces when the same mention is selected

What is the root cause of that problem?

We are adding space every time we update the comment in both insertSelectedEmoji insertSelectedMention

insertSelectedMention(highlightedMentionIndex) {
const commentBeforeAtSign = this.state.value.slice(0, this.state.atSignIndex);
const mentionObject = this.state.suggestedMentions[highlightedMentionIndex];
const mentionCode = `@${mentionObject.alternateText}`;
const commentAfterAtSignWithMentionRemoved = this.state.value.slice(this.state.atSignIndex).replace(CONST.REGEX.MENTION_REPLACER, '');
this.updateComment(`${commentBeforeAtSign}${mentionCode} ${commentAfterAtSignWithMentionRemoved}`, true);
this.setState((prevState) => ({
selection: {
start: prevState.atSignIndex + mentionCode.length + CONST.SPACE_LENGTH,
end: prevState.atSignIndex + mentionCode.length + CONST.SPACE_LENGTH,
},
suggestedMentions: [],
}));
}

insertSelectedEmoji(highlightedEmojiIndex) {
const commentBeforeColon = this.state.value.slice(0, this.state.colonIndex);
const emojiObject = this.state.suggestedEmojis[highlightedEmojiIndex];
const emojiCode = emojiObject.types && emojiObject.types[this.props.preferredSkinTone] ? emojiObject.types[this.props.preferredSkinTone] : emojiObject.code;
const commentAfterColonWithEmojiNameRemoved = this.state.value.slice(this.state.selection.end).replace(CONST.REGEX.EMOJI_REPLACER, CONST.SPACE);
this.updateComment(`${commentBeforeColon}${emojiCode} ${commentAfterColonWithEmojiNameRemoved}`, true);
this.setState((prevState) => ({
selection: {
start: prevState.colonIndex + emojiCode.length + CONST.SPACE_LENGTH,
end: prevState.colonIndex + emojiCode.length + CONST.SPACE_LENGTH,
},
suggestedEmojis: [],
}));
EmojiUtils.addToFrequentlyUsedEmojis(emojiObject);
}

What changes do you think we should make in order to solve the problem?

We should check if the first character of commentAfterAtSignWithMentionRemoved is ' ' we will don't add space like this

this.updateComment(`${commentBeforeAtSign}${mentionCode}${commentAfterAtSignWithMentionRemoved.slice(0, 1) === ' ' ? commentAfterAtSignWithMentionRemoved : ` ${commentAfterAtSignWithMentionRemoved}`}`, true);

We also do the same thing in insertSelectedEmoji like this

this.updateComment(`${commentBeforeColon}${emojiCode}${commentAfterColonWithEmojiNameRemoved.slice(0, 1) === ' ' ? commentAfterColonWithEmojiNameRemoved : ` ${commentAfterColonWithEmojiNameRemoved}`}`, true);

Result

My solution will make the behavior like Slack

Screen.Recording.2023-05-19.at.12.36.34.1.mp4

@thesahindia

This comment was marked as outdated.

@allroundexperts
Copy link
Contributor

@thesahindia I think the selected approach will not work as it will not add a space if we have an emoji directly after the text. For example, this is how it works on Slack:
https://github.com/Expensify/App/assets/30054992/a8dd6004-f19c-4fe5-a602-09465f110b73

After #19004 is merged, our app will essentially behave the same as above. With the proposal that we're currently choosing, following will happen:
https://github.com/Expensify/App/assets/30054992/af2a32ba-0f1e-42bb-b8ee-ee3d34ca45e8

@dukenv0307
Copy link
Contributor

@thesahindia I think we should hold this issue until this thread is resolved

@dukenv0307
Copy link
Contributor

@thesahindia we will remain the logic to get mention suggestion as @puneetlath mentioned here
So I just updated my proposal. My solution is built on top of this PR #19004

@thesahindia
Copy link
Member

@dukenv0307, your updated proposal is similar to @allroundexperts. They proposed the solution first so I am going to go with them.

@puneetlath, I like @allroundexperts's proposal

🎀👀🎀 C+ reviewed

@dukenv0307

This comment was marked as off-topic.

@thesahindia
Copy link
Member

thesahindia commented May 19, 2023

Are you sure that you have tested it correctly? Because I didn't see any problem. It works fine for me.
Also @allroundexperts, can you check @dukenv0307's comment?

@dukenv0307
Copy link
Contributor

@thesahindia Sorry, my bad. please ignore my comment

@thesahindia
Copy link
Member

No worries @dukenv0307!

@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label May 19, 2023
@melvin-bot
Copy link

melvin-bot bot commented May 19, 2023

📣 @allroundexperts You have been assigned to this job by @puneetlath!
Please apply to this job in Upwork and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻
Keep in mind: Code of Conduct | Contributing 📖

@allroundexperts
Copy link
Contributor

PR created #19304

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Daily KSv2 labels May 26, 2023
@melvin-bot melvin-bot bot changed the title [$1000] Mention auto-suggester adds extra spaces when same mention is selected [HOLD for payment 2023-06-02] [$1000] Mention auto-suggester adds extra spaces when same mention is selected May 26, 2023
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label May 26, 2023
@melvin-bot
Copy link

melvin-bot bot commented May 26, 2023

Reviewing label has been removed, please complete the "BugZero Checklist".

@melvin-bot
Copy link

melvin-bot bot commented May 26, 2023

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.3.18-2 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

If no regressions arise, payment will be issued on 2023-06-02. 🎊

After the hold period is over and BZ checklist items are completed, please complete any of the applicable payments for this issue, and check them off once done.

  • External issue reporter @0xmiroslav
  • Contributor that fixed the issue @allroundexperts
  • Contributor+ that helped on the issue and/or PR @thesahindia

As a reminder, here are the bonuses/penalties that should be applied for any External issue:

  • Merged PR within 3 business days of assignment - 50% bonus
  • Merged PR more than 9 business days after assignment - 50% penalty

@melvin-bot
Copy link

melvin-bot bot commented May 26, 2023

BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

  • [@allroundexperts / @thesahindia] The PR that introduced the bug has been identified. Link to the PR:
  • [@allroundexperts / @thesahindia] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment:
  • [@allroundexperts / @thesahindia] A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion:
  • [@allroundexperts / @thesahindia] Determine if we should create a regression test for this bug.
  • [@allroundexperts / @thesahindia] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
  • [@puneetlath] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

@puneetlath
Copy link
Contributor Author

Sent contracts to @0xmiroslav @allroundexperts @thesahindia.

@thesahindia friendly reminder about the checklist!

@melvin-bot melvin-bot bot added Daily KSv2 and removed Weekly KSv2 labels Jun 1, 2023
@puneetlath
Copy link
Contributor Author

Paid @0xmiroslav and @allroundexperts.

@thesahindia will get you once the checklist is done.

@melvin-bot melvin-bot bot added the Overdue label Jun 5, 2023
@thesahindia
Copy link
Member

Sorry for the delay. Dealing with it now.

@melvin-bot melvin-bot bot removed the Overdue label Jun 5, 2023
@thesahindia
Copy link
Member

BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

#18469

  • [@allroundexperts / @thesahindia] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment:

https://github.com/Expensify/App/pull/18469/files#r1218352520

  • [@allroundexperts / @thesahindia] A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion:

https://expensify.slack.com/archives/C049HHMV9SM/p1685985155886849

I don't think we need a test case for this but let me know if we wanna add tests.

@puneetlath
Copy link
Contributor Author

I think we're good on tests. We're going to add a suite specifically for mentions. Thanks!

@puneetlath
Copy link
Contributor Author

@thesahindia I paid the contract but upwork seems to be having issues and won't let me close it. I'll try again tomorrow.

@puneetlath
Copy link
Contributor Author

Ok, managed to close it. Thanks everyone!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor
Projects
None yet
Development

No branches or pull requests

5 participants