Skip to content

Commit 6e2334f

Browse files
authored
feat(rich-text-editor): NO-JIRA add mention click handling (#1009)
1 parent 9f2b25f commit 6e2334f

File tree

7 files changed

+73
-3
lines changed

7 files changed

+73
-3
lines changed

packages/dialtone-vue3/components/rich_text_editor/extensions/mentions/MentionComponent.vue

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
>
66
<dt-link
77
kind="mention"
8+
@click.prevent="handleClick"
89
>
910
{{ text }}
1011
</dt-link>
@@ -31,5 +32,17 @@ export default {
3132
return '@' + this.$props.node.attrs.name;
3233
},
3334
},
35+
36+
methods: {
37+
handleClick () {
38+
const mentionData = {
39+
name: this.$props.node.attrs.name,
40+
id: this.$props.node.attrs.id,
41+
avatarSrc: this.$props.node.attrs.avatarSrc,
42+
contactKey: this.$props.node.attrs.contactKey,
43+
};
44+
this.$props.editor.emit('mention-click', mentionData);
45+
},
46+
},
3447
};
3548
</script>

packages/dialtone-vue3/components/rich_text_editor/extensions/suggestion/SuggestionList.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export default {
125125
this.command(item);
126126
return;
127127
case 'mention':
128-
this.command({ name: item.name, id: item.id, avatarSrc: item.avatarSrc });
128+
this.command({ name: item.name, id: item.id, avatarSrc: item.avatarSrc, contactKey: item.contactKey });
129129
break;
130130
case 'channel':
131131
this.command({ name: item.name, id: item.id, locked: item.locked });

packages/dialtone-vue3/components/rich_text_editor/mention_suggestion.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import defaultImage from '@/common/assets/avatar2.png';
22

3-
/* eslint-disable max-len */
3+
44
const CONTACT_LIST = [
55
{
66
id: 'test.person',
77
name: 'Test Person',
8+
contactKey: '123',
89
avatarSrc: defaultImage,
910
showDetails: true,
1011
presence: 'active',
@@ -14,6 +15,7 @@ const CONTACT_LIST = [
1415
{
1516
id: 'test.person2',
1617
name: 'Test Person 2',
18+
contactKey: '1234',
1719
avatarSrc: defaultImage,
1820
showDetails: true,
1921
presence: 'busy',
@@ -23,6 +25,7 @@ const CONTACT_LIST = [
2325
{
2426
id: 'test.person3',
2527
name: 'Test Person 3',
28+
contactKey: '12345',
2629
avatarSrc: defaultImage,
2730
showDetails: true,
2831
presence: 'busy',
@@ -32,6 +35,7 @@ const CONTACT_LIST = [
3235
{
3336
id: 'brad.paugh',
3437
name: 'Brad Paugh',
38+
contactKey: '123456',
3539
avatarSrc: defaultImage,
3640
showDetails: true,
3741
presence: 'offline',
@@ -40,6 +44,7 @@ const CONTACT_LIST = [
4044
{
4145
id: 'bradley.hawkins',
4246
name: 'Bradley Hawkins',
47+
contactKey: '1234567',
4348
avatarSrc: defaultImage,
4449
showDetails: true,
4550
presence: 'away',
@@ -50,27 +55,32 @@ const CONTACT_LIST = [
5055
{
5156
id: 'julio.ortega',
5257
name: 'Tico Ortega',
58+
contactKey: '12345678',
5359
avatarSrc: defaultImage,
5460
},
5561
{
5662
id: 'ignacio.ropolo',
5763
name: 'Ignacio Ropolo',
64+
contactKey: '123456789',
5865
avatarSrc: defaultImage,
5966
},
6067
{
6168
id: 'nina.repetto',
6269
name: 'Nina Repetto',
70+
contactKey: '123456789',
6371
avatarSrc: defaultImage,
6472
},
6573
{
6674
id: 'long.name',
6775
name: 'LongnameLongnameLongnameLongnameLongnameLongnameLongnameLongnameLongnameLongnameLongnameLongnameLongnameLongnameLongname',
6876
avatarSrc: defaultImage,
77+
contactKey: '1234567890',
6978
},
7079
{
7180
id: 'long.name.with.spaces',
7281
name: 'Long Name Long Name Long Name Long NameLong Name Long Name Long Name Long NameLong Name Long Name Long Name Long NameLong Name Long Name Long Name Long NameLong Name Long Name Long Name Long Name ',
7382
avatarSrc: defaultImage,
83+
contactKey: '12345678901',
7484
},
7585
];
7686

packages/dialtone-vue3/components/rich_text_editor/rich_text_editor.stories.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const argsData = {
2929
onMarkdownInput: action('markdown-input'),
3030
onEditLink: action('edit-link'),
3131
onSelectedCommand: action('selected-command'),
32+
onMentionClick: action('mention-click'),
3233
};
3334

3435
export const argTypesData = {
@@ -123,6 +124,11 @@ export const argTypesData = {
123124
disable: true,
124125
},
125126
},
127+
onMentionClick: {
128+
table: {
129+
disable: true,
130+
},
131+
},
126132
};
127133

128134
// Story Collection

packages/dialtone-vue3/components/rich_text_editor/rich_text_editor.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,34 @@ describe('DtRichTextEditor tests', () => {
604604
});
605605

606606
describe('Interactivity Tests', () => {
607+
describe('Mention click functionality', () => {
608+
describe('When a mention is clicked', () => {
609+
it('should emit mention-click event with mention data', async () => {
610+
const mentionData = {
611+
id: 'john.doe',
612+
name: 'John Doe',
613+
avatarSrc: 'avatar.jpg',
614+
contactKey: 'contact-123',
615+
};
616+
617+
await wrapper.setProps({
618+
mentionSuggestion: { items: vi.fn(() => [mentionData]) },
619+
});
620+
621+
const editorInstance = wrapper.vm.editor;
622+
const mentionNode = editorInstance.schema.nodes.mention.create(mentionData);
623+
editorInstance.view.dispatch(editorInstance.state.tr.insert(0, mentionNode));
624+
await wrapper.vm.$nextTick();
625+
626+
const mentionLink = wrapper.find('a.d-link');
627+
expect(mentionLink.text()).toBe('@John Doe');
628+
629+
await mentionLink.trigger('click');
630+
expect(wrapper.emitted('mention-click')[0][0]).toEqual(mentionData);
631+
});
632+
});
633+
});
634+
607635
describe('Link keyboard shortcut functionality', () => {
608636
describe('When Mod+K is pressed and link is enabled', () => {
609637
it('should emit edit-link event', async () => {

packages/dialtone-vue3/components/rich_text_editor/rich_text_editor.vue

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,13 @@ export default {
494494
* @type {String}
495495
*/
496496
'selected-command',
497+
498+
/**
499+
* Event fired when a mention is clicked
500+
* @event mention-click
501+
* @type {Object}
502+
*/
503+
'mention-click',
497504
],
498505
499506
data () {
@@ -1188,10 +1195,15 @@ export default {
11881195
this.$emit('focus', event);
11891196
});
11901197
1191-
// The editor isnt focused anymore.
1198+
// The editor isn't focused anymore.
11921199
this.editor.on('blur', ({ event }) => {
11931200
this.$emit('blur', event);
11941201
});
1202+
1203+
// Mention is clicked
1204+
this.editor.on('mention-click', (mentionData) => {
1205+
this.$emit('mention-click', mentionData);
1206+
});
11951207
},
11961208
11971209
getOutput () {

packages/dialtone-vue3/components/rich_text_editor/rich_text_editor_default.story.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
@text-input="$attrs.onTextInput"
3434
@markdown-input="$attrs.onMarkdownInput"
3535
@selected-command="$attrs.onSelectedCommand"
36+
@mention-click="$attrs.onMentionClick"
3637
@focus="$attrs.onFocus"
3738
@enter="$attrs.onEnter"
3839
/>

0 commit comments

Comments
 (0)