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

Highlight mentions when rendering annotation text #6818

Merged
merged 1 commit into from
Feb 12, 2025
Merged

Conversation

acelaya
Copy link
Contributor

@acelaya acelaya commented Feb 11, 2025

Closes #6803

This PR adds the logic to parse annotation texts when rendering them in the list of annotations or the annotation editor preview, look for mention tags, and render them so that they are highlighted.

Mention tags can be highlighted in three different ways:

  1. Proper mentions with a link to the user profile: rendered as a link with brand color, underline and bold text.
    Captura desde 2025-02-11 10-26-13
  2. Proper mentions without a link to the user profile: rendered as a non-interactive element, with brand color and bold text.
    Captura desde 2025-02-11 10-25-54
  3. Invalid mentions (the tag appears in the text, but the backend did not include a corresponding entry in the mentions array): rendered as a non-interactive element, with lighter bold text and wavy red underline.
    image

In addition, this PR also ensures all mentions are styled as plain text by default, and only after being processed they look like in the screenshots above.

This is important to ensure invalid mentions do not look like regular links if processing them failed for any reason, as this could confuse users and think the mentions did in fact "work"

This PR does not cover displaying a popover when hovering over a rendered mention. That'll be covered on a follow-up PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed anything related to styling from here, and moved it to StyledText.scss

@acelaya acelaya force-pushed the highlight-mentions branch 6 times, most recently from f3c8d7c to faf3990 Compare February 11, 2025 09:53
Copy link

codecov bot commented Feb 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.45%. Comparing base (eca9044) to head (c989091).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6818   +/-   ##
=======================================
  Coverage   99.45%   99.45%           
=======================================
  Files         271      271           
  Lines       10406    10409    +3     
  Branches     2488     2488           
=======================================
+ Hits        10349    10352    +3     
  Misses         57       57           

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

@robertknight
Copy link
Member

Invalid mentions (the tag appears in the text, but the backend did not include a corresponding entry in the mentions array): rendered as a non-interactive element, with lighter text, and italic bold font.

I think the difference compared to a valid mention may be too subtle for users who cannot perceive the color difference. Perhaps invalid mentions could use a style that reminds of a spelling or grammar error (text-decoration-style: wavy)? Other ideas welcome.

I can't remember what you already had planned here, but I think there needs to be some kind of popover for invalid mentions as well as valid ones to spell out the issue more explicitly.

@acelaya
Copy link
Contributor Author

acelaya commented Feb 11, 2025

I think the difference compared to a valid mention may be too subtle for users who cannot perceive the color difference.

Good point. I have been experimenting with some style that includes a different border, but they ended up cropped when the mention is at the very top of very bottom.

Perhaps invalid mentions could use a style that reminds of a spelling or grammar error (text-decoration-style: wavy)?

Good idea. Let me see if I can put something together.

I can't remember what you already had planned here, but I think there needs to be some kind of popover for invalid mentions as well as valid ones to spell out the issue more explicitly.

Yes! I will address popovers on a follow-up PR.

@acelaya acelaya force-pushed the highlight-mentions branch 2 times, most recently from d368b76 to 2e41561 Compare February 11, 2025 10:17
@acelaya acelaya marked this pull request as ready for review February 11, 2025 10:20
@acelaya acelaya requested a review from robertknight February 11, 2025 10:20
Copy link
Member

@robertknight robertknight left a comment

Choose a reason for hiding this comment

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

I got confused when testing initially because mentions are only parsed when an annotation is created rather than edited. I think we should change that on the backend soon because that is going to cause a lot of confusion.

In this PR I found an issue that invalid mentions are not styled as such if the annotation contains no valid mentions, because the annotation tags created when the text is submitted to the server are tags that match the styling for valid mentions, and if the mentions payload from the server is empty, these don't get updated when the annotation is rendered.

@@ -35,6 +41,12 @@ export default function MarkdownView({
});
}, [markdown]);

useEffect(() => {
if (hasMentions) {
renderMentionTags(content.current!, mentions);
Copy link
Member

Choose a reason for hiding this comment

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

I'm looking at the code for renderMentionTags and it is a bit confusing because it looks like it doesn't change anything at first glance. The elementForMention function does actually modify the element, but this isn't obvious from the name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When you say "it looks like it doesn't change anything at first glance", do you mean that it is not obvious that the function has side effects? If so, I agree.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, exactly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, since the function is not new from this PR, I'll add that to my todo list and address it separately, if that's ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@acelaya acelaya force-pushed the highlight-mentions branch 2 times, most recently from 51e0f0a to bc353c1 Compare February 11, 2025 13:44
@acelaya
Copy link
Contributor Author

acelaya commented Feb 11, 2025

I got confused when testing initially because mentions are only parsed when an annotation is created rather than edited. I think we should change that on the backend soon because that is going to cause a lot of confusion.

I'll give this a thought. Thanks!

Comment on lines 109 to 121
a[data-hyp-mention][data-hyp-mention-type='link'] {
@apply text-brand font-bold underline;
}

// Valid processed mention without link
span[data-hyp-mention][data-hyp-mention-type='no-link'] {
@apply text-brand font-bold;
}

// Invalid processed mention
span[data-hyp-mention][data-hyp-mention-type='invalid'] {
@apply text-grey-6 font-bold underline decoration-wavy decoration-red-error;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Processed mentions will include the data-hyp-mention-type attribute with values 'link' | 'no-link' | 'invalid'. That way we can make mentions look like plain text until they have been processed.

@acelaya acelaya requested a review from robertknight February 11, 2025 13:55
@acelaya acelaya merged commit 1e1103f into main Feb 12, 2025
2 checks passed
@acelaya acelaya deleted the highlight-mentions branch February 12, 2025 09:29
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.

Highlight @mention when rendering an annotation in the client
2 participants