Skip to content

Commit e481ccb

Browse files
Alejandro Celayaacelaya
authored andcommitted
Display description and joining date in mentioned user popover
1 parent 386628e commit e481ccb

File tree

6 files changed

+104
-16
lines changed

6 files changed

+104
-16
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"@babel/preset-react": "^7.0.0",
1515
"@babel/preset-typescript": "^7.16.7",
1616
"@hypothesis/frontend-build": "^3.0.0",
17-
"@hypothesis/frontend-shared": "^9.0.0",
17+
"@hypothesis/frontend-shared": "^9.1.0",
1818
"@hypothesis/frontend-testing": "^1.3.1",
1919
"@npmcli/arborist": "^9.0.0",
2020
"@octokit/rest": "^21.0.0",

src/sidebar/components/MarkdownView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export default function MarkdownView(props: MarkdownViewProps) {
164164
open={!!popoverContent}
165165
onClose={() => setPopoverContentAfterDelay(null)}
166166
anchorElementRef={mentionsPopoverAnchorRef}
167-
classes="px-3 py-2"
167+
classes="px-3 py-2 !max-w-[75%]"
168168
>
169169
{popoverContent !== null && (
170170
<MentionPopoverContent content={popoverContent} />

src/sidebar/components/mentions/MentionPopoverContent.tsx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { formatDateTime } from '@hypothesis/frontend-shared';
2+
13
import type { Mention } from '../../../types/api';
24
import type { InvalidUsername } from '../../helpers/mentions';
35

@@ -21,15 +23,25 @@ export default function MentionPopoverContent({
2123
}
2224

2325
return (
24-
<div className="flex flex-col gap-y-1.5">
25-
<div data-testid="username" className="text-md font-bold">
26-
@{content.username}
26+
<div className="flex flex-col gap-y-4">
27+
<div className="flex flex-col gap-y-1.5">
28+
<div data-testid="username" className="text-md font-bold">
29+
@{content.username}
30+
</div>
31+
{content.display_name && (
32+
<div data-testid="display-name" className="text-color-text-light">
33+
{content.display_name}
34+
</div>
35+
)}
2736
</div>
28-
{content.display_name && (
29-
<div data-testid="display-name" className="text-color-text-light">
30-
{content.display_name}
37+
{content.description && (
38+
<div data-testid="description" className="line-clamp-2">
39+
{content.description}
3140
</div>
3241
)}
42+
<div data-testid="created" className="text-color-text-light">
43+
Joined <b>{formatDateTime(content.joined, { includeTime: false })}</b>
44+
</div>
3345
</div>
3446
);
3547
}

src/sidebar/components/mentions/test/MentionPopoverContent-test.js

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { mount } from '@hypothesis/frontend-testing';
1+
import { formatDateTime } from '@hypothesis/frontend-shared';
2+
import { checkAccessibility, mount } from '@hypothesis/frontend-testing';
23

34
import MentionPopoverContent from '../MentionPopoverContent';
45

@@ -15,14 +16,15 @@ describe('MentionPopoverContent', () => {
1516
assert.isFalse(wrapper.exists('[data-testid="display-name"]'));
1617
});
1718

18-
it('renders username when valid mention without display name is provided', () => {
19+
it('renders no display name nor description when not provided', () => {
1920
const wrapper = createComponent({ username: 'janedoe' });
2021

2122
assert.equal(wrapper.find('[data-testid="username"]').text(), '@janedoe');
2223
assert.isFalse(wrapper.exists('[data-testid="display-name"]'));
24+
assert.isFalse(wrapper.exists('[data-testid="description"]'));
2325
});
2426

25-
it('renders username and display name when valid mention with display name is provided', () => {
27+
it('renders display name when provided', () => {
2628
const wrapper = createComponent({
2729
username: 'janedoe',
2830
display_name: 'Jane Doe',
@@ -33,5 +35,72 @@ describe('MentionPopoverContent', () => {
3335
wrapper.find('[data-testid="display-name"]').text(),
3436
'Jane Doe',
3537
);
38+
assert.isFalse(wrapper.exists('[data-testid="description"]'));
3639
});
40+
41+
it('renders description when provided', () => {
42+
const wrapper = createComponent({
43+
username: 'janedoe',
44+
description: 'This is my bio',
45+
});
46+
47+
assert.equal(wrapper.find('[data-testid="username"]').text(), '@janedoe');
48+
assert.isFalse(wrapper.exists('[data-testid="display-name"]'));
49+
assert.equal(
50+
wrapper.find('[data-testid="description"]').text(),
51+
'This is my bio',
52+
);
53+
});
54+
55+
it('renders both display name and description when provided', () => {
56+
const wrapper = createComponent({
57+
username: 'janedoe',
58+
display_name: 'Jane Doe',
59+
description: 'This is my bio',
60+
});
61+
62+
assert.equal(wrapper.find('[data-testid="username"]').text(), '@janedoe');
63+
assert.equal(
64+
wrapper.find('[data-testid="display-name"]').text(),
65+
'Jane Doe',
66+
);
67+
assert.equal(
68+
wrapper.find('[data-testid="description"]').text(),
69+
'This is my bio',
70+
);
71+
});
72+
73+
[
74+
'2025-01-23T15:36:52.100817+00:00',
75+
'2022-08-16T00:00:00.000000+00:00',
76+
'2008-02-29T13:00:00.000000+00:00',
77+
].forEach(joined => {
78+
it('formats created date', () => {
79+
const wrapper = createComponent({ username: 'janedoe', joined });
80+
assert.equal(
81+
wrapper.find('[data-testid="created"]').text(),
82+
`Joined ${formatDateTime(joined, { includeTime: false })}`,
83+
);
84+
});
85+
});
86+
87+
it(
88+
'should pass a11y checks',
89+
checkAccessibility([
90+
{
91+
name: 'Invalid mention',
92+
content: () => createComponent('invalid'),
93+
},
94+
{
95+
name: 'Valid mention',
96+
content: () =>
97+
createComponent({
98+
username: 'janedoe',
99+
display_name: 'Jane Doe',
100+
description: 'This is my bio',
101+
created: '2025-01-23T15:36:52.100817+00:00',
102+
}),
103+
},
104+
]),
105+
);
37106
});

src/types/api.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ export type IndexResponse = {
3737
*/
3838
export type LinksResponse = Record<string, string>;
3939

40+
/** A date and time in ISO format (eg. "2024-12-09T07:17:52+00:00") */
41+
export type ISODateTime = string;
42+
4043
/**
4144
* Selector which indicates the time range within a video or audio file that
4245
* an annotation refers to.
@@ -167,6 +170,10 @@ export type Mention = {
167170
display_name: string | null;
168171
/** Link to the user profile, if applicable */
169172
link: string | null;
173+
/** The user description/bio */
174+
description: string | null;
175+
/** The date when the user joined, in ISO format */
176+
joined: ISODateTime;
170177

171178
/**
172179
* The userid at the moment the mention was created.

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2359,15 +2359,15 @@ __metadata:
23592359
languageName: node
23602360
linkType: hard
23612361

2362-
"@hypothesis/frontend-shared@npm:^9.0.0":
2363-
version: 9.0.0
2364-
resolution: "@hypothesis/frontend-shared@npm:9.0.0"
2362+
"@hypothesis/frontend-shared@npm:^9.1.0":
2363+
version: 9.1.0
2364+
resolution: "@hypothesis/frontend-shared@npm:9.1.0"
23652365
dependencies:
23662366
highlight.js: ^11.6.0
23672367
wouter-preact: ^3.0.0
23682368
peerDependencies:
23692369
preact: ^10.25.1
2370-
checksum: 203f8562d9d0dd5fc6e26cd2e56d0264ea3129ed8e54673d13a15646f501221139f12c9a092b82e15a0c60f476821937617a7db9c9e5715b03aeebe082b0f986
2370+
checksum: 97a8590c9fa1aa7df63711a49c7b50563a65a3dfa2aa5f50ed3b7f9c33167734146afb2ad49fe7da216a4030f7a9bdb3b036059cc2258a13c74a73fc6ca9d8d3
23712371
languageName: node
23722372
linkType: hard
23732373

@@ -8906,7 +8906,7 @@ __metadata:
89068906
"@babel/preset-react": ^7.0.0
89078907
"@babel/preset-typescript": ^7.16.7
89088908
"@hypothesis/frontend-build": ^3.0.0
8909-
"@hypothesis/frontend-shared": ^9.0.0
8909+
"@hypothesis/frontend-shared": ^9.1.0
89108910
"@hypothesis/frontend-testing": ^1.3.1
89118911
"@npmcli/arborist": ^9.0.0
89128912
"@octokit/rest": ^21.0.0

0 commit comments

Comments
 (0)