feat: Order conversations by priority (#7053)

This commit is contained in:
Muhsin Keloth
2023-05-11 12:56:43 +05:30
committed by GitHub
parent d0a1ad746a
commit 87f758ee1f
7 changed files with 85 additions and 2 deletions

View File

@@ -1,4 +1,7 @@
import { MESSAGE_TYPE } from 'shared/constants/messages';
import {
MESSAGE_TYPE,
CONVERSATION_PRIORITY_ORDER,
} from 'shared/constants/messages';
import { applyPageFilters } from './helpers';
export const getSelectedChatConversation = ({
@@ -13,6 +16,12 @@ const getters = {
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]);

View File

@@ -130,6 +130,66 @@ describe('#getters', () => {
},
]);
});
it('order conversations based on priority', () => {
const state = {
allConversations: [
{
id: 1,
messages: [
{
content: 'test1',
},
],
priority: 'low',
created_at: 1683645801,
last_activity_at: 2466424490,
},
{
id: 2,
messages: [{ content: 'test2' }],
priority: 'urgent',
created_at: 1652109801,
last_activity_at: 1466424480,
},
{
id: 3,
messages: [{ content: 'test3' }],
priority: 'medium',
created_at: 1652109801,
last_activity_at: 1466421280,
},
],
chatSortFilter: 'sort_on_priority',
};
expect(getters.getAllConversations(state)).toEqual([
{
id: 2,
messages: [{ content: 'test2' }],
priority: 'urgent',
created_at: 1652109801,
last_activity_at: 1466424480,
},
{
id: 3,
messages: [{ content: 'test3' }],
priority: 'medium',
created_at: 1652109801,
last_activity_at: 1466421280,
},
{
id: 1,
messages: [
{
content: 'test1',
},
],
priority: 'low',
created_at: 1683645801,
last_activity_at: 2466424490,
},
]);
});
});
describe('#getUnAssignedChats', () => {
it('order returns only chats assigned to user', () => {