Skip to content

Commit

Permalink
fix: fix kudos in standups in nested lists (#9412)
Browse files Browse the repository at this point in the history
* Fix: fix kudos in standups in nested lists

* fix test
  • Loading branch information
igorlesnenko committed Feb 8, 2024
1 parent d8f006c commit 7e78d20
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,67 @@ describe('findMentionsByEmoji', () => {
text: ' both mentioned ❤️'
}
]
},
{
type: 'bulletList',
content: [
{
type: 'listItem',
content: [
{
type: 'paragraph',
content: [
{
type: 'text',
text: 'List item with mention '
},
{
type: 'mention',
attrs: {
id: 'user_id_list_1',
label: 'userlistone'
}
},
{
type: 'text',
text: ' ❤️ in a list'
}
]
},
{
type: 'listItem',
content: [
{
type: 'bulletList',
content: [
{
type: 'listItem',
content: [
{
type: 'paragraph',
content: [
{
type: 'mention',
attrs: {
id: 'user_id_nested_list',
label: 'usernestedlist'
}
},
{
type: 'text',
text: ' Nested mention ❤️'
}
]
}
]
}
]
}
]
}
]
}
]
}
]
}
Expand All @@ -159,7 +220,15 @@ describe('findMentionsByEmoji', () => {
it('returns correct mention user IDs for emoji ❤️', () => {
const emoji = '❤️'
const result = getKudosUserIdsFromJson(doc, emoji)
expect(result).toEqual(['user_id_1', 'user_id_2', 'user_id_3', 'user_id_4', 'user_id_5'])
expect(result).toEqual([
'user_id_1',
'user_id_2',
'user_id_3',
'user_id_4',
'user_id_5',
'user_id_list_1',
'user_id_nested_list'
])
})

it('returns correct mention user IDs for different emoji (🌮)', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,33 @@ import {JSONContent} from '@tiptap/core'
export const getKudosUserIdsFromJson = (doc: JSONContent, emoji: string): string[] => {
const mentionedIds = new Set<string>()

if (!doc.content) return []
for (const paragraph of doc.content) {
if (paragraph.content) {
let emojiFound = false
const tempMentions = new Set<string>()
const searchForMentionsAndEmojis = (node: JSONContent | undefined) => {
if (!node || !node.content) return

for (const node of paragraph.content) {
if (node.type === 'text' && node.text?.includes(emoji)) {
emojiFound = true
}
node.content.forEach((contentNode) => {
if (contentNode.type === 'paragraph') {
const tempMentions: string[] = []
let emojiFound = false

if (node.type === 'mention') {
tempMentions.add(node.attrs?.id)
}
}
contentNode.content?.forEach((item) => {
if (item.type === 'text' && item.text?.includes(emoji)) {
emojiFound = true
}
if (item.type === 'mention') {
tempMentions.push(item.attrs?.id)
}
})

if (emojiFound) {
tempMentions.forEach((id) => mentionedIds.add(id))
if (emojiFound) {
tempMentions.forEach((id) => mentionedIds.add(id))
}
} else if (contentNode.content) {
searchForMentionsAndEmojis(contentNode)
}
}
})
}

searchForMentionsAndEmojis(doc)

return Array.from(mentionedIds)
}

0 comments on commit 7e78d20

Please sign in to comment.