Skip to content

Commit c0c3c1e

Browse files
authored
fix(rich-text-editor): NO-JIRA add channelKey (#1031)
1 parent a47da13 commit c0c3c1e

File tree

6 files changed

+33
-5
lines changed

6 files changed

+33
-5
lines changed

packages/dialtone-vue/components/rich_text_editor/channel_suggestion.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,23 @@ export default {
55
{
66
id: 'dialpad',
77
name: 'dialpad',
8+
channelKey: 'ch-001',
89
},
910
{
1011
id: 'dialtone',
1112
name: 'dialtone',
13+
channelKey: 'ch-002',
1214
},
1315
{
1416
id: 'dialtone-vue',
1517
name: 'dialtone-vue',
18+
channelKey: 'ch-003',
1619
},
1720
{
1821
id: 'dialtone-internal',
1922
name: 'dialtone-internal',
2023
locked: true,
24+
channelKey: 'ch-004',
2125
},
2226
];
2327

packages/dialtone-vue/components/rich_text_editor/extensions/channels/ChannelComponent.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export default {
5555
name: this.$props.node.attrs.name,
5656
id: this.$props.node.attrs.id,
5757
locked: this.$props.node.attrs.locked,
58+
channelKey: this.$props.node.attrs.channelKey,
5859
};
5960
this.$props.editor.emit('channel-click', channelData);
6061
},

packages/dialtone-vue/components/rich_text_editor/extensions/channels/channel.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ export const ChannelPlugin = Mention.extend({
3232
locked: {
3333
default: false,
3434
},
35+
channelKey: {
36+
default: '',
37+
},
3538
};
3639
},
3740

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export default {
128128
this.command({ name: item.name, id: item.id, avatarSrc: item.avatarSrc, contactKey: item.contactKey });
129129
break;
130130
case 'channel':
131-
this.command({ name: item.name, id: item.id, locked: item.locked });
131+
this.command({ name: item.name, id: item.id, locked: item.locked, channelKey: item.channelKey });
132132
break;
133133
case 'slash-command':
134134
this.command({ command: item.command });

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ describe('DtRichTextEditor tests', () => {
352352
{ type: 'text', text: ' channel' },
353353
]);
354354
const output = jsonToMarkdownConverter.convertToMarkdown(jsonInput);
355-
expect(output).toBe('Check out <!-- @channel: {"id": "general", "name": "general", "locked": "false"} --> channel\n');
355+
expect(output).toBe('Check out <!-- @channel: {"id": "general", "channelKey": "", "name": "general", "locked": "false"} --> channel\n');
356356
});
357357

358358
it('should convert locked channels to markdown comments correctly', async () => {
@@ -369,7 +369,25 @@ describe('DtRichTextEditor tests', () => {
369369
{ type: 'text', text: ' channel' },
370370
]);
371371
const output = jsonToMarkdownConverter.convertToMarkdown(jsonInput);
372-
expect(output).toBe('Check out <!-- @channel: {"id": "dialtone-internal", "name": "dialtone-internal", "locked": "true"} --> channel\n');
372+
expect(output).toBe('Check out <!-- @channel: {"id": "dialtone-internal", "channelKey": "", "name": "dialtone-internal", "locked": "true"} --> channel\n');
373+
});
374+
375+
it('should convert channels with channelKey to markdown comments correctly', async () => {
376+
const jsonInput = jsonInputBase([
377+
{ type: 'text', text: 'Check out ' },
378+
{
379+
type: 'channel',
380+
attrs: {
381+
id: 'general',
382+
name: 'general',
383+
locked: false,
384+
channelKey: 'channel-456',
385+
},
386+
},
387+
{ type: 'text', text: ' channel' },
388+
]);
389+
const output = jsonToMarkdownConverter.convertToMarkdown(jsonInput);
390+
expect(output).toBe('Check out <!-- @channel: {"id": "general", "channelKey": "channel-456", "name": "general", "locked": "false"} --> channel\n');
373391
});
374392
});
375393
});
@@ -639,6 +657,7 @@ describe('DtRichTextEditor tests', () => {
639657
id: 'general',
640658
name: 'general',
641659
locked: false,
660+
channelKey: 'ch-123',
642661
};
643662

644663
await wrapper.setProps({

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ export default {
265265
* The only required key is the items function which is used to query the channels for suggestion.
266266
* items({ query }) => { return [ChannelObject]; }
267267
* ChannelObject format:
268-
* { name: string, id: string, locked: boolean }
268+
* { name: string, id: string, locked: boolean, channelKey?: string }
269269
*
270270
* When null, it does not add the plugin. Setting locked to true will display a lock rather than hash.
271271
*/
@@ -611,7 +611,8 @@ export default {
611611
const channelName = node.attrs?.name || '';
612612
const channelId = node.attrs?.id || '';
613613
const locked = node.attrs?.locked.toString() || '';
614-
return `<!-- @channel: {"id": "${channelId}", "name": "${channelName}", "locked": "${locked}"} -->`;
614+
const channelKey = node.attrs?.channelKey || '';
615+
return `<!-- @channel: {"id": "${channelId}", "channelKey": "${channelKey}", "name": "${channelName}", "locked": "${locked}"} -->`;
615616
},
616617
617618
processSlashCommandsNode (node) {

0 commit comments

Comments
 (0)