Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions apps/meteor/client/components/Omnichannel/Tags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ const Tags = ({ tags = [], handler, error, tagRequired, department }: TagsProps)

const { data: tagsResult, isInitialLoading } = useLivechatTags({
department,
viewAll: !department,
});

const customTags = useMemo(() => {
return tags.filter((tag) => !tagsResult?.tags.find((rtag) => rtag._id === tag));
return tags.filter((tag) => !tagsResult?.tags.find((rtag) => rtag.name === tag));
}, [tags, tagsResult?.tags]);

const dispatchToastMessage = useToastMessageDispatch();
Expand All @@ -56,7 +57,7 @@ const Tags = ({ tags = [], handler, error, tagRequired, department }: TagsProps)
return;
}

if (tags.some((tag) => tag === tagValue)) {
if (tags.includes(tagValue)) {
dispatchToastMessage({ type: 'error', message: t('Tag_already_exists') });
return;
}
Expand All @@ -79,9 +80,10 @@ const Tags = ({ tags = [], handler, error, tagRequired, department }: TagsProps)
<EETagsComponent
value={paginatedTagValue}
handler={(tags: { label: string; value: string }[]): void => {
handler(tags.map((tag) => tag.value));
handler(tags.map((tag) => tag.label));
}}
department={department}
viewAll={!department}
/>
</Field.Row>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ import { useQuery } from '@tanstack/react-query';
type Props = {
department?: string;
text?: string;
viewAll?: boolean;
};

export const useLivechatTags = (options: Props) => {
const getTags = useEndpoint('GET', '/v1/livechat/tags');

const { department, text } = options;
const { department, text, viewAll } = options;
return useQuery(['/v1/livechat/tags', text, department], () =>
getTags({
text: text || '',
...(department && { department }),
viewAll: viewAll ? 'true' : 'false',
}),
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { UserStatus } from '../../../../../components/UserStatus';
import UserAvatar from '../../../../../components/avatar/UserAvatar';
import { useIsCallReady } from '../../../../../contexts/CallContext';
import AgentInfoDetails from '../../../components/AgentInfoDetails';
import { useTagsLabels } from '../../chats/hooks/useTagsLabels';
import AgentField from '../../components/AgentField';
import { InfoField } from './InfoField';
import { VoipInfoCallButton } from './VoipInfoCallButton';
Expand All @@ -43,7 +42,6 @@ export const VoipInfo = ({ room, onClickClose /* , onClickReport */ }: VoipInfo
const shouldShowWrapup = useMemo(() => lastMessage?.t === 'voip-call-wrapup' && lastMessage?.msg, [lastMessage]);
const shouldShowTags = useMemo(() => tags && tags.length > 0, [tags]);
const _name = fname || name;
const getTagLabel = useTagsLabels();

return (
<>
Expand Down Expand Up @@ -85,7 +83,7 @@ export const VoipInfo = ({ room, onClickClose /* , onClickReport */ }: VoipInfo
<Box display='flex' flexDirection='row' alignItems='center'>
{tags?.map((tag: string) => (
<Chip mie='x4' key={tag} value={tag}>
{getTagLabel(tag)}
{tag}
</Chip>
))}
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
import { usePagination } from '../../../../components/GenericTable/hooks/usePagination';
import { useSort } from '../../../../components/GenericTable/hooks/useSort';
import { useCurrentChats } from '../../currentChats/hooks/useCurrentChats';
import { useTagsLabels } from './hooks/useTagsLabels';

const ChatTable = () => {
const t = useTranslation();
Expand All @@ -29,8 +28,6 @@ const ChatTable = () => {
const { current, itemsPerPage, setItemsPerPage: onSetItemsPerPage, setCurrent: onSetCurrent, ...paginationProps } = usePagination();
const { sortBy, sortDirection, setSort } = useSort<'fname' | 'department' | 'ts' | 'chatDuration' | 'closedAt'>('fname');

const getTagLabel = useTagsLabels();

const query = useMemo(
() => ({
sort: `{ "${sortBy}": ${sortDirection === 'asc' ? 1 : -1} }`,
Expand Down Expand Up @@ -114,7 +111,7 @@ const ChatTable = () => {
mie='x4'
>
<Tag style={{ display: 'inline' }} disabled>
{getTagLabel(tag)}
{tag}
</Tag>
</Box>
))}
Expand All @@ -128,7 +125,7 @@ const ChatTable = () => {
<GenericTableCell withTruncatedText>{moment(closedAt).format('L LTS')}</GenericTableCell>
</GenericTableRow>
),
[getTagLabel, onRowClick],
[onRowClick],
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import Label from '../../../components/Label';
import { AgentField, SlaField, ContactField, SourceField } from '../../components';
import PriorityField from '../../components/PriorityField';
import { useOmnichannelRoomInfo } from '../../hooks/useOmnichannelRoomInfo';
import { useTagsLabels } from '../hooks/useTagsLabels';
import DepartmentField from './DepartmentField';
import VisitorClientInfo from './VisitorClientInfo';

Expand Down Expand Up @@ -50,7 +49,6 @@ function ChatInfo({ id, route }) {
queuedAt,
} = room || { room: { v: {} } };

const getTagLabel = useTagsLabels(!!tags?.length);
const routePath = useRoute(route || 'omnichannel-directory');
const canViewCustomFields = usePermission('view-livechat-room-customfields');
const subscription = useUserSubscription(id);
Expand Down Expand Up @@ -110,7 +108,7 @@ function ChatInfo({ id, route }) {
{tags.map((tag) => (
<Box key={tag} mie='x4' display='inline'>
<Tag style={{ display: 'inline' }} disabled>
{getTagLabel(tag)}
{tag}
</Tag>
</Box>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import Info from '../../../components/Info';
import Label from '../../../components/Label';
import { AgentField, ContactField, SlaField } from '../../components';
import PriorityField from '../../components/PriorityField';
import { useTagsLabels } from '../hooks/useTagsLabels';
import DepartmentField from './DepartmentField';
import VisitorClientInfo from './VisitorClientInfo';

Expand Down Expand Up @@ -45,7 +44,6 @@ function ChatInfoDirectory({ id, route = undefined, room }) {
queuedAt,
} = room || { room: { v: {} } };

const getTagLabel = useTagsLabels();
const routePath = useRoute(route || 'omnichannel-directory');
const canViewCustomFields = () => hasPermission('view-livechat-room-customfields');
const subscription = useUserSubscription(id);
Expand Down Expand Up @@ -106,7 +104,7 @@ function ChatInfoDirectory({ id, route = undefined, room }) {
{tags.map((tag) => (
<Box key={tag} mie='x4' display='inline'>
<Tag style={{ display: 'inline' }} disabled>
{getTagLabel(tag)}
{tag}
</Tag>
</Box>
))}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { escapeRegExp } from '@rocket.chat/string-helpers';
import { CannedResponse } from '@rocket.chat/models';

import { hasPermissionAsync } from '../../../../../app/authorization/server/functions/hasPermission';
import { getTagsInformation } from './tags';
import { getDepartmentsWhichUserCanAccess } from '../../../livechat-enterprise/server/api/lib/departments';

export async function findAllCannedResponses({ userId }) {
Expand All @@ -22,7 +21,7 @@ export async function findAllCannedResponses({ userId }) {
},
],
}).toArray();
return getTagsInformation(cannedResponses);
return cannedResponses;
}

// If the user it not any of the previous roles nor an agent, then get only his own responses
Expand All @@ -31,7 +30,7 @@ export async function findAllCannedResponses({ userId }) {
scope: 'user',
userId,
}).toArray();
return getTagsInformation(cannedResponses);
return cannedResponses;
}

// Last scenario: user is an agent, so get his own responses and those from the departments he is in
Expand All @@ -55,7 +54,7 @@ export async function findAllCannedResponses({ userId }) {
],
}).toArray();

return getTagsInformation(cannedResponses);
return cannedResponses;
}

export async function findAllCannedResponsesFilter({ userId, shortcut, text, departmentId, scope, createdBy, tags = [], options = {} }) {
Expand Down Expand Up @@ -129,7 +128,7 @@ export async function findAllCannedResponsesFilter({ userId, shortcut, text, dep
});
const [cannedResponses, total] = await Promise.all([cursor.toArray(), totalCount]);
return {
cannedResponses: await getTagsInformation(cannedResponses),
cannedResponses,
total,
};
}
Expand Down
33 changes: 0 additions & 33 deletions apps/meteor/ee/app/api-enterprise/server/lib/tags.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { callbacks } from '../../../../../lib/callbacks';
callbacks.add(
'livechat.afterTagRemoved',
async (tag) => {
const { _id } = tag;
const { name } = tag;

await CannedResponse.removeTagFromCannedResponses(_id);
await CannedResponse.removeTagFromCannedResponses(name);
},
callbacks.priority.MEDIUM,
'on-tag-removed-remove-references',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export const LivechatEnterprise = {
async removeTag(_id: string) {
check(_id, String);

const tag = await LivechatTag.findOneById(_id, { projection: { _id: 1 } });
const tag = await LivechatTag.findOneById(_id, { projection: { _id: 1, name: 1 } });

if (!tag) {
throw new Meteor.Error('tag-not-found', 'Tag not found', { method: 'livechat:removeTag' });
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/ee/client/hooks/useTagsList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const useTagsList = (options: TagsListOptions): UseTagsListResult => {
items: tags.map<any>((tag: any) => ({
_id: tag._id,
label: tag.name,
value: tag._id,
value: tag.name,
_updatedAt: new Date(tag._updatedAt),
})),
itemCount: total,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ import { removeTag, saveTags } from '../../../data/livechat/tags';
const { body } = await request
.post(api('canned-responses'))
.set(credentials)
.send({ shortcut: 'shortcutxxx', scope: 'user', tags: [tag._id], text: 'text' })
.send({ shortcut: 'shortcutxxx', scope: 'user', tags: [tag.name], text: 'text' })
.expect(200);

expect(body).to.have.property('success', true);

const { body: getResult } = await request.get(api('canned-responses')).set(credentials).query({ 'tags[]': tag._id }).expect(200);
const { body: getResult } = await request.get(api('canned-responses')).set(credentials).query({ 'tags[]': tag.name }).expect(200);

expect(getResult).to.have.property('success', true);
expect(getResult.cannedResponses).to.be.an('array').with.lengthOf(1);
Expand All @@ -154,14 +154,14 @@ import { removeTag, saveTags } from '../../../data/livechat/tags';
const { body } = await request
.post(api('canned-responses'))
.set(credentials)
.send({ shortcut: 'shortcutxxxx', scope: 'user', tags: [tag._id], text: 'text' })
.send({ shortcut: 'shortcutxxxx', scope: 'user', tags: [tag.name], text: 'text' })
.expect(200);

expect(body).to.have.property('success', true);

await removeTag(tag._id);

const { body: getResult } = await request.get(api('canned-responses')).set(credentials).query({ 'tags[]': tag._id }).expect(200);
const { body: getResult } = await request.get(api('canned-responses')).set(credentials).query({ 'tags[]': tag.name }).expect(200);

expect(getResult).to.have.property('success', true);
expect(getResult.cannedResponses).to.be.an('array').with.lengthOf(0);
Expand Down