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

Display suggestions popover when at-mentioning #6727

Merged
merged 1 commit into from
Dec 19, 2024
Merged

Conversation

acelaya
Copy link
Contributor

@acelaya acelaya commented Dec 16, 2024

This PR adds logic to display a suggestions popover when an @mention is typed in the annotations text. The popover is displayed as long as the text right before the caret looks like a mention, and hidden otherwise.

The logic takes the at_mentions feature flag into consideration, disabling the logic entirely otherwise.

suggestions-popover-2024-12-16_15.55.45.mp4

Out of scope

This PR only covers the logic to decide when to show/hide the popover, but it does not:

  1. Display actual user suggestions in the popover.
  2. Calculate the popover position based on where the caret is.

Those will be implemented in follow-up PRs.

Test steps

  1. Go to http://localhost:5000/admin/features and enable at_mentions
  2. Try to edit/create an annotation.
  3. Type an @mention. The popover should be displayed under the textarea.
  4. Remove the @mention. The popover should be closed.

You can see other combinations in the screen recording above.

TODO

  • Allow popover to be closed via Esc even if the caret is next to an @mention.
  • Add tests

anchorElementRef={textareaRef}
classes="p-2"
>
Suggestions
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Temporary placeholder

@acelaya acelaya force-pushed the at-mentions-popover branch 2 times, most recently from b397746 to 0ac0205 Compare December 17, 2024 10:26
Copy link

codecov bot commented Dec 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.42%. Comparing base (d0aed76) to head (07ebc15).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6727   +/-   ##
=======================================
  Coverage   99.42%   99.42%           
=======================================
  Files         269      270    +1     
  Lines       10175    10194   +19     
  Branches     2427     2433    +6     
=======================================
+ Hits        10116    10135   +19     
  Misses         59       59           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@acelaya acelaya marked this pull request as ready for review December 17, 2024 10:29
@acelaya acelaya requested a review from robertknight December 17, 2024 10:29
src/sidebar/components/MarkdownEditor.tsx Outdated Show resolved Hide resolved
src/sidebar/components/MarkdownEditor.tsx Outdated Show resolved Hide resolved
src/sidebar/components/test/MarkdownEditor-test.js Outdated Show resolved Hide resolved
@acelaya acelaya force-pushed the at-mentions-popover branch 2 times, most recently from 62c5232 to 412f14c Compare December 18, 2024 10:26
@acelaya acelaya requested a review from robertknight December 18, 2024 10:27
src/shared/test/term-before-position-test.js Outdated Show resolved Hide resolved
src/shared/test/term-before-position-test.js Outdated Show resolved Hide resolved
src/shared/test/term-before-position-test.js Outdated Show resolved Hide resolved
src/shared/term-before-position.ts Outdated Show resolved Hide resolved
src/sidebar/components/test/MarkdownEditor-test.js Outdated Show resolved Hide resolved

// We listen for `keyup` to make sure the text in the textarea reflects the
// just-pressed key when we evaluate it
listenerCollection.add(textarea, 'keyup', e => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suggestions popup does not currently appear if the caret is repositioned by clicking in the middle of a mention. I haven't checked, but I'd guess that also applies to using the caret movement UIs on mobile. I think that's fine for this PR but you could instead use the selectionchange event. The downside is that I don't think that event provides a way to determine why the selection changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. There's another thing to take into consideration actually, which is that the popover is closed when clicking away, so I'll probably try to address that separately to try different combinations and even handlers.

@acelaya acelaya force-pushed the at-mentions-popover branch 3 times, most recently from 4bd2815 to 07dc484 Compare December 18, 2024 14:22
@acelaya acelaya requested a review from robertknight December 18, 2024 14:22
src/sidebar/components/MarkdownEditor.tsx Show resolved Hide resolved
src/sidebar/util/term-before-position.ts Outdated Show resolved Hide resolved
src/sidebar/util/term-before-position.ts Outdated Show resolved Hide resolved
@acelaya acelaya force-pushed the at-mentions-popover branch from 07dc484 to 07ebc15 Compare December 19, 2024 08:44
@acelaya acelaya merged commit 4b7f380 into main Dec 19, 2024
4 checks passed
@acelaya acelaya deleted the at-mentions-popover branch December 19, 2024 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants