-
Notifications
You must be signed in to change notification settings - Fork 204
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
Conversation
src/sidebar/helpers/mentions.ts
Outdated
There was a problem hiding this comment.
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
f3c8d7c
to
faf3990
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
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 ( 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. |
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.
Good idea. Let me see if I can put something together.
Yes! I will address popovers on a follow-up PR. |
d368b76
to
2e41561
Compare
2e41561
to
d28d4c6
Compare
There was a problem hiding this 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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, exactly.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
51e0f0a
to
bc353c1
Compare
I'll give this a thought. Thanks! |
bc353c1
to
2f22ac3
Compare
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; | ||
} |
There was a problem hiding this comment.
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.
2f22ac3
to
c989091
Compare
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:
mentions
array): rendered as a non-interactive element, with lighter bold text and wavy red underline.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"