Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Omnichannel): Contact Center sort by date #32566

Merged
merged 12 commits into from
Jun 19, 2024
5 changes: 5 additions & 0 deletions .changeset/proud-coats-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fix the sorting by last chat in Contact Center table
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { useCurrentContacts } from './hooks/useCurrentContacts';

function ContactTable(): ReactElement {
const { current, itemsPerPage, setItemsPerPage, setCurrent, ...paginationProps } = usePagination();
const { sortBy, sortDirection, setSort } = useSort<'username' | 'phone' | 'name' | 'visitorEmails.address' | 'lastchat'>('username');
const { sortBy, sortDirection, setSort } = useSort<'username' | 'phone' | 'name' | 'visitorEmails.address' | 'lastChat.ts'>('username');
const isCallReady = useIsCallReady();

const [term, setTerm] = useDebouncedState('', 500);
Expand Down Expand Up @@ -90,7 +90,13 @@ function ContactTable(): ReactElement {
>
{t('Email')}
</GenericTableHeaderCell>
<GenericTableHeaderCell key='lastchat' direction={sortDirection} active={sortBy === 'lastchat'} onClick={setSort} sort='lastchat'>
<GenericTableHeaderCell
key='lastchat'
direction={sortDirection}
active={sortBy === 'lastChat.ts'}
onClick={setSort}
sort='lastChat.ts'
>
{t('Last_Chat')}
</GenericTableHeaderCell>
<GenericTableHeaderCell key='call' width={44} />
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/tests/data/livechat/rooms.ts
tiagoevanp marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const createLivechatRoom = async (visitorToken: string, extraRoomParams?:
return response.body.room;
};

export const createVisitor = (department?: string): Promise<ILivechatVisitor> =>
export const createVisitor = (department?: string, visitorName?: string): Promise<ILivechatVisitor> =>
new Promise((resolve, reject) => {
const token = getRandomVisitorToken();
const email = `${token}@${token}.com`;
Expand All @@ -46,7 +46,7 @@ export const createVisitor = (department?: string): Promise<ILivechatVisitor> =>
.set(credentials)
.send({
visitor: {
name: `Visitor ${Date.now()}`,
name: visitorName || `Visitor ${Date.now()}`,
email,
token,
phone,
Expand Down
48 changes: 46 additions & 2 deletions apps/meteor/tests/end-to-end/api/livechat/11-livechat.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { expect } from 'chai';
import { before, describe, it } from 'mocha';
import { after, before, describe, it } from 'mocha';

import { sleep } from '../../../../lib/utils/sleep';
import { getCredentials, api, request, credentials } from '../../../data/api-data';
import { createCustomField, deleteCustomField } from '../../../data/livechat/custom-fields';
import { addOrRemoveAgentFromDepartment, createDepartmentWithAnOnlineAgent } from '../../../data/livechat/department';
import { createVisitor, createLivechatRoom, makeAgentUnavailable, closeOmnichannelRoom, sendMessage } from '../../../data/livechat/rooms';
import {
createVisitor,
createLivechatRoom,
makeAgentUnavailable,
closeOmnichannelRoom,
sendMessage,
deleteVisitor,
} from '../../../data/livechat/rooms';
import { createBotAgent, getRandomVisitorToken } from '../../../data/livechat/users';
import { removePermissionFromAllRoles, restorePermissionToRoles, updatePermission, updateSetting } from '../../../data/permissions.helper';
import { IS_EE } from '../../../e2e/config/constants';
Expand All @@ -19,6 +26,11 @@ describe('LIVECHAT - Utils', function () {
await updateSetting('Livechat_enabled', true);
});

after(async () => {
await updateSetting('Livechat_enabled', false);
tiagoevanp marked this conversation as resolved.
Show resolved Hide resolved
await updateSetting('Livechat_offline_email', '');
tiagoevanp marked this conversation as resolved.
Show resolved Hide resolved
});

describe('livechat/offline.message', () => {
it('should fail if name is not sent as body parameter', async () => {
const { body } = await request.post(api('livechat/offline.message')).set(credentials).send({});
Expand Down Expand Up @@ -453,6 +465,38 @@ describe('LIVECHAT - Utils', function () {
expect(body).to.have.property('token', visitor.token);
});
});
describe('livechat/visitors.search', () => {
it('should bring sorted data by last chat time', async () => {
const visitor1 = await createVisitor(undefined, 'VisitorInPast');
tiagoevanp marked this conversation as resolved.
Show resolved Hide resolved
const room1 = await createLivechatRoom(visitor1.token);

const visitor2 = await createVisitor(undefined, 'VisitorInPresent');
tiagoevanp marked this conversation as resolved.
Show resolved Hide resolved
const room2 = await createLivechatRoom(visitor2.token);

const { body: result1 } = await request
.get(api('livechat/visitors.search?term=VisitorIn&sort={"lastChat.ts":1}'))
.set(credentials)
.send();

expect(result1).to.have.property('visitors').that.is.an('array');
expect(result1.visitors[0]).to.have.property('name');
expect(result1.visitors[0].name).to.be.eq('VisitorInPast');

const { body: result2 } = await request
.get(api('livechat/visitors.search?term=VisitorIn&sort={"lastChat.ts":-1}'))
.set(credentials)
.send();

expect(result2).to.have.property('visitors').that.is.an('array');
expect(result2.visitors[0]).to.have.property('name');
expect(result2.visitors[0].name).to.be.eq('VisitorInPresent');

await deleteVisitor(visitor1.token);
await deleteVisitor(visitor2.token);
await closeOmnichannelRoom(room1._id);
await closeOmnichannelRoom(room2._id);
});
});

describe('livechat/message', () => {
it('should fail if no token', async () => {
Expand Down
Loading