-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Canned Response custom tags break the GUI on enterprise (#29694)
Co-authored-by: Kevin Aleman <kaleman960@gmail.com>
- Loading branch information
1 parent
7f54572
commit 28b41fb
Showing
20 changed files
with
191 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@rocket.chat/meteor': patch | ||
--- | ||
|
||
Fixed Canned Response custom tags breaking the GUI on enterprise |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
apps/meteor/client/views/omnichannel/directory/chats/hooks/useTagsLabels.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { useEndpoint } from '@rocket.chat/ui-contexts'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { useMemo } from 'react'; | ||
|
||
// TODO: Remove this hook when the endpoint is changed | ||
// to return labels instead of tag id's | ||
export const useTagsLabels = (initialTags: string[] = []) => { | ||
const getTags = useEndpoint('GET', '/v1/livechat/tags'); | ||
const { data: tagsData, isInitialLoading } = useQuery(['/v1/livechat/tags'], () => getTags({ text: '' }), { | ||
enabled: Boolean(initialTags.length), | ||
}); | ||
|
||
const labels = useMemo(() => { | ||
const { tags = [] } = tagsData || {}; | ||
return tags.reduce<Record<string, string>>((acc, tag) => ({ ...acc, [tag._id]: tag.name }), {}); | ||
}, [tagsData]); | ||
|
||
return useMemo(() => { | ||
return isInitialLoading ? initialTags : initialTags.map((tag) => labels[tag] || tag); | ||
}, [initialTags, isInitialLoading, labels]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { ILivechatTag, IOmnichannelCannedResponse } from '@rocket.chat/core-typings'; | ||
import { LivechatTag } from '@rocket.chat/models'; | ||
|
||
const filterTags = (tags: string[], serverTags: ILivechatTag[]) => { | ||
return tags.reduce((acc, tag) => { | ||
const found = serverTags.find((serverTag) => serverTag._id === tag); | ||
if (found) { | ||
acc.push(found.name); | ||
} else { | ||
acc.push(tag); | ||
} | ||
return acc; | ||
}, [] as string[]); | ||
}; | ||
|
||
export const getTagsInformation = async (cannedResponses: IOmnichannelCannedResponse[]) => { | ||
return Promise.all( | ||
cannedResponses.map(async (cannedResponse) => { | ||
const { tags } = cannedResponse; | ||
|
||
if (!Array.isArray(tags) || !tags.length) { | ||
return cannedResponse; | ||
} | ||
|
||
const serverTags = await LivechatTag.findInIds(tags, { projection: { _id: 1, name: 1 } }).toArray(); | ||
|
||
// Known limitation: if a tag was added and removed before this, it will return the tag id instead of the name | ||
cannedResponse.tags = filterTags(tags, serverTags); | ||
|
||
return cannedResponse; | ||
}), | ||
); | ||
}; |
14 changes: 14 additions & 0 deletions
14
apps/meteor/ee/app/livechat-enterprise/server/hooks/afterTagRemoved.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { CannedResponse } from '@rocket.chat/models'; | ||
|
||
import { callbacks } from '../../../../../lib/callbacks'; | ||
|
||
callbacks.add( | ||
'livechat.afterTagRemoved', | ||
async (tag) => { | ||
const { _id } = tag; | ||
|
||
await CannedResponse.removeTagFromCannedResponses(_id); | ||
}, | ||
callbacks.priority.MEDIUM, | ||
'on-tag-removed-remove-references', | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.