feat: Add a sort option for conversations waiting for a reply from an agent (#7364)

This commit is contained in:
Pranav Raj S
2023-06-21 13:20:39 -07:00
committed by GitHub
parent e6a49b5800
commit 93daaea19b
15 changed files with 166 additions and 39 deletions

View File

@@ -16,6 +16,7 @@ export default {
LATEST: 'latest',
CREATED_AT: 'sort_on_created_at',
PRIORITY: 'sort_on_priority',
WATIING_SINCE: 'waiting_since',
},
ARTICLE_STATUS_TYPES: {
DRAFT: 0,

View File

@@ -50,6 +50,9 @@
},
"sort_on_priority": {
"TEXT": "Priority"
},
"sort_on_waiting_since": {
"TEXT": "Pending Response"
}
},
"ATTACHMENTS": {

View File

@@ -10,21 +10,36 @@ export const getSelectedChatConversation = ({
}) =>
allConversations.filter(conversation => conversation.id === selectedChatId);
const sortComparator = {
latest: (a, b) => b.last_activity_at - a.last_activity_at,
sort_on_created_at: (a, b) => a.created_at - b.created_at,
sort_on_priority: (a, b) => {
return (
CONVERSATION_PRIORITY_ORDER[a.priority] -
CONVERSATION_PRIORITY_ORDER[b.priority]
);
},
sort_on_waiting_since: (a, b) => {
if (!a.waiting_since && !b.waiting_since) {
return a.created_at - b.created_at;
}
if (!a.waiting_since) {
return 1;
}
if (!b.waiting_since) {
return -1;
}
return a.waiting_since - b.waiting_since;
},
};
// getters
const getters = {
getAllConversations: ({ allConversations, chatSortFilter }) => {
const comparator = {
latest: (a, b) => b.last_activity_at - a.last_activity_at,
sort_on_created_at: (a, b) => a.created_at - b.created_at,
sort_on_priority: (a, b) => {
return (
CONVERSATION_PRIORITY_ORDER[a.priority] -
CONVERSATION_PRIORITY_ORDER[b.priority]
);
},
};
return allConversations.sort(comparator[chatSortFilter]);
return allConversations.sort(sortComparator[chatSortFilter]);
},
getSelectedChat: ({ selectedChatId, allConversations }) => {
const selectedChat = allConversations.find(

View File

@@ -190,6 +190,56 @@ describe('#getters', () => {
},
]);
});
it('order conversations based on waiting_since', () => {
const state = {
allConversations: [
{
id: 3,
created_at: 1683645800,
waiting_since: 0,
},
{
id: 4,
created_at: 1683645799,
waiting_since: 0,
},
{
id: 1,
created_at: 1683645801,
waiting_since: 1683645802,
},
{
id: 2,
created_at: 1683645803,
waiting_since: 1683645800,
},
],
chatSortFilter: 'sort_on_waiting_since',
};
expect(getters.getAllConversations(state)).toEqual([
{
id: 2,
created_at: 1683645803,
waiting_since: 1683645800,
},
{
id: 1,
created_at: 1683645801,
waiting_since: 1683645802,
},
{
id: 4,
created_at: 1683645799,
waiting_since: 0,
},
{
id: 3,
created_at: 1683645800,
waiting_since: 0,
},
]);
});
});
describe('#getUnAssignedChats', () => {
it('order returns only chats assigned to user', () => {