Fix: sidebar filters not applying bug for chatlist (#1938)
This commit is contained in:
committed by
GitHub
parent
4657e5c713
commit
484c32fae3
@@ -150,24 +150,16 @@ export default {
|
|||||||
},
|
},
|
||||||
conversationList() {
|
conversationList() {
|
||||||
let conversationList = [];
|
let conversationList = [];
|
||||||
|
const filters = this.conversationFilters;
|
||||||
if (this.activeAssigneeTab === 'me') {
|
if (this.activeAssigneeTab === 'me') {
|
||||||
conversationList = this.mineChatsList.slice();
|
conversationList = [...this.mineChatsList(filters)];
|
||||||
} else if (this.activeAssigneeTab === 'unassigned') {
|
} else if (this.activeAssigneeTab === 'unassigned') {
|
||||||
conversationList = this.unAssignedChatsList.slice();
|
conversationList = [...this.unAssignedChatsList(filters)];
|
||||||
} else {
|
} else {
|
||||||
conversationList = this.allChatList.slice();
|
conversationList = [...this.allChatList(filters)];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.label) {
|
return conversationList;
|
||||||
return conversationList;
|
|
||||||
}
|
|
||||||
|
|
||||||
return conversationList.filter(conversation => {
|
|
||||||
const labels = this.$store.getters[
|
|
||||||
'conversationLabels/getConversationLabels'
|
|
||||||
](conversation.id);
|
|
||||||
return labels.includes(this.label);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
activeTeam() {
|
activeTeam() {
|
||||||
if (this.teamId) {
|
if (this.teamId) {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import authAPI from '../../../api/auth';
|
import authAPI from '../../../api/auth';
|
||||||
|
import { applyPageFilters } from './helpers';
|
||||||
|
|
||||||
export const getSelectedChatConversation = ({
|
export const getSelectedChatConversation = ({
|
||||||
allConversations,
|
allConversations,
|
||||||
@@ -18,24 +19,30 @@ const getters = {
|
|||||||
);
|
);
|
||||||
return selectedChat || {};
|
return selectedChat || {};
|
||||||
},
|
},
|
||||||
getMineChats(_state) {
|
getMineChats: _state => activeFilters => {
|
||||||
const currentUserID = authAPI.getCurrentUser().id;
|
const currentUserID = authAPI.getCurrentUser().id;
|
||||||
return _state.allConversations.filter(chat =>
|
|
||||||
!chat.meta.assignee
|
return _state.allConversations.filter(conversation => {
|
||||||
? false
|
const { assignee } = conversation.meta;
|
||||||
: chat.status === _state.chatStatusFilter &&
|
const isAssignedToMe = assignee && assignee.id === currentUserID;
|
||||||
chat.meta.assignee.id === currentUserID
|
const shouldFilter = applyPageFilters(conversation, activeFilters);
|
||||||
);
|
const isChatMine = isAssignedToMe && shouldFilter;
|
||||||
|
|
||||||
|
return isChatMine;
|
||||||
|
});
|
||||||
},
|
},
|
||||||
getUnAssignedChats(_state) {
|
getUnAssignedChats: _state => activeFilters => {
|
||||||
return _state.allConversations.filter(
|
return _state.allConversations.filter(conversation => {
|
||||||
chat => !chat.meta.assignee && chat.status === _state.chatStatusFilter
|
const isUnAssigned = !conversation.meta.assignee;
|
||||||
);
|
const shouldFilter = applyPageFilters(conversation, activeFilters);
|
||||||
|
return isUnAssigned && shouldFilter;
|
||||||
|
});
|
||||||
},
|
},
|
||||||
getAllStatusChats(_state) {
|
getAllStatusChats: _state => activeFilters => {
|
||||||
return _state.allConversations.filter(
|
return _state.allConversations.filter(conversation => {
|
||||||
chat => chat.status === _state.chatStatusFilter
|
const shouldFilter = applyPageFilters(conversation, activeFilters);
|
||||||
);
|
return shouldFilter;
|
||||||
|
});
|
||||||
},
|
},
|
||||||
getChatListLoadingStatus: ({ listLoadingStatus }) => listLoadingStatus,
|
getChatListLoadingStatus: ({ listLoadingStatus }) => listLoadingStatus,
|
||||||
getAllMessagesLoaded(_state) {
|
getAllMessagesLoaded(_state) {
|
||||||
@@ -56,18 +63,6 @@ const getters = {
|
|||||||
},
|
},
|
||||||
getChatStatusFilter: ({ chatStatusFilter }) => chatStatusFilter,
|
getChatStatusFilter: ({ chatStatusFilter }) => chatStatusFilter,
|
||||||
getSelectedInbox: ({ currentInbox }) => currentInbox,
|
getSelectedInbox: ({ currentInbox }) => currentInbox,
|
||||||
getNextChatConversation: _state => {
|
|
||||||
const [selectedChat] = getSelectedChatConversation(_state);
|
|
||||||
const conversations = getters.getAllStatusChats(_state);
|
|
||||||
if (conversations.length <= 1) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
const currentIndex = conversations.findIndex(
|
|
||||||
conversation => conversation.id === selectedChat.id
|
|
||||||
);
|
|
||||||
const nextIndex = (currentIndex + 1) % conversations.length;
|
|
||||||
return conversations[nextIndex];
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default getters;
|
export default getters;
|
||||||
|
|||||||
@@ -4,3 +4,32 @@ export const findPendingMessageIndex = (chat, message) => {
|
|||||||
m => m.id === message.id || m.id === tempMessageId
|
m => m.id === message.id || m.id === tempMessageId
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const applyPageFilters = (conversation, filters) => {
|
||||||
|
const { inboxId, status, labels = [], teamId } = filters;
|
||||||
|
const {
|
||||||
|
status: chatStatus,
|
||||||
|
inbox_id: chatInboxId,
|
||||||
|
labels: chatLabels = [],
|
||||||
|
meta = {},
|
||||||
|
} = conversation;
|
||||||
|
const { team = {} } = meta;
|
||||||
|
const { id: chatTeamId } = team;
|
||||||
|
const filterByStatus = chatStatus === status;
|
||||||
|
let shouldFilter = filterByStatus;
|
||||||
|
|
||||||
|
if (inboxId) {
|
||||||
|
const filterByInbox = Number(inboxId) === chatInboxId;
|
||||||
|
shouldFilter = shouldFilter && filterByInbox;
|
||||||
|
}
|
||||||
|
if (teamId) {
|
||||||
|
const filterByTeam = Number(teamId) === chatTeamId;
|
||||||
|
shouldFilter = shouldFilter && filterByTeam;
|
||||||
|
}
|
||||||
|
if (labels.length) {
|
||||||
|
const filterByLabels = labels.every(label => chatLabels.includes(label));
|
||||||
|
shouldFilter = shouldFilter && filterByLabels;
|
||||||
|
}
|
||||||
|
|
||||||
|
return shouldFilter;
|
||||||
|
};
|
||||||
|
|||||||
@@ -47,33 +47,59 @@ describe('#getters', () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('#getNextChatConversation', () => {
|
describe('#getUnAssignedChats', () => {
|
||||||
it('return the next chat', () => {
|
it('order returns only chats assigned to user', () => {
|
||||||
const state = {
|
const conversationList = [
|
||||||
allConversations: [
|
{
|
||||||
{
|
id: 1,
|
||||||
id: 1,
|
inbox_id: 2,
|
||||||
},
|
status: 1,
|
||||||
{
|
meta: { assignee: { id: 1 } },
|
||||||
id: 2,
|
labels: ['sales', 'dev'],
|
||||||
},
|
},
|
||||||
],
|
{
|
||||||
selectedChatId: 1,
|
id: 2,
|
||||||
};
|
inbox_id: 2,
|
||||||
expect(getters.getNextChatConversation(state)).toEqual({
|
status: 1,
|
||||||
id: 2,
|
meta: {},
|
||||||
});
|
labels: ['dev'],
|
||||||
});
|
},
|
||||||
it('return null when there is only one chat', () => {
|
{
|
||||||
const state = {
|
id: 11,
|
||||||
allConversations: [
|
inbox_id: 3,
|
||||||
{
|
status: 1,
|
||||||
id: 1,
|
meta: { assignee: { id: 1 } },
|
||||||
},
|
labels: [],
|
||||||
],
|
},
|
||||||
selectedChatId: 1,
|
{
|
||||||
};
|
id: 22,
|
||||||
expect(getters.getNextChatConversation(state)).toBeNull();
|
inbox_id: 4,
|
||||||
|
status: 1,
|
||||||
|
meta: { team: { id: 5 } },
|
||||||
|
labels: ['sales'],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
expect(
|
||||||
|
getters.getUnAssignedChats({ allConversations: conversationList })({
|
||||||
|
status: 1,
|
||||||
|
})
|
||||||
|
).toEqual([
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
inbox_id: 2,
|
||||||
|
status: 1,
|
||||||
|
meta: {},
|
||||||
|
labels: ['dev'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 22,
|
||||||
|
inbox_id: 4,
|
||||||
|
status: 1,
|
||||||
|
meta: { team: { id: 5 } },
|
||||||
|
labels: ['sales'],
|
||||||
|
},
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,38 @@
|
|||||||
import { findPendingMessageIndex } from '../../conversations/helpers';
|
import {
|
||||||
|
findPendingMessageIndex,
|
||||||
|
applyPageFilters,
|
||||||
|
} from '../../conversations/helpers';
|
||||||
|
|
||||||
|
const conversationList = [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
inbox_id: 2,
|
||||||
|
status: 1,
|
||||||
|
meta: {},
|
||||||
|
labels: ['sales', 'dev'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
inbox_id: 2,
|
||||||
|
status: 1,
|
||||||
|
meta: {},
|
||||||
|
labels: ['dev'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 11,
|
||||||
|
inbox_id: 3,
|
||||||
|
status: 1,
|
||||||
|
meta: { team: { id: 5 } },
|
||||||
|
labels: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 22,
|
||||||
|
inbox_id: 4,
|
||||||
|
status: 1,
|
||||||
|
meta: { team: { id: 5 } },
|
||||||
|
labels: ['sales'],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
describe('#findPendingMessageIndex', () => {
|
describe('#findPendingMessageIndex', () => {
|
||||||
it('returns the correct index of pending message with id', () => {
|
it('returns the correct index of pending message with id', () => {
|
||||||
@@ -18,20 +52,64 @@ describe('#findPendingMessageIndex', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#addOrUpdateChat', () => {
|
describe('#applyPageFilters', () => {
|
||||||
it('returns the correct index of pending message with id', () => {
|
describe('#filter-team', () => {
|
||||||
const chat = {
|
it('returns true if conversation has team and team filter is active', () => {
|
||||||
messages: [{ id: 1, status: 'progress' }],
|
const filters = {
|
||||||
};
|
status: 1,
|
||||||
const message = { echo_id: 1 };
|
teamId: 5,
|
||||||
expect(findPendingMessageIndex(chat, message)).toEqual(0);
|
};
|
||||||
|
expect(applyPageFilters(conversationList[3], filters)).toEqual(true);
|
||||||
|
});
|
||||||
|
it('returns true if conversation has no team and team filter is active', () => {
|
||||||
|
const filters = {
|
||||||
|
status: 1,
|
||||||
|
teamId: 5,
|
||||||
|
};
|
||||||
|
expect(applyPageFilters(conversationList[0], filters)).toEqual(false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns -1 if pending message with id is not present', () => {
|
describe('#filter-inbox', () => {
|
||||||
const chat = {
|
it('returns true if conversation has inbox and inbox filter is active', () => {
|
||||||
messages: [{ id: 1, status: 'progress' }],
|
const filters = {
|
||||||
};
|
status: 1,
|
||||||
const message = { echo_id: 2 };
|
inboxId: 4,
|
||||||
expect(findPendingMessageIndex(chat, message)).toEqual(-1);
|
};
|
||||||
|
expect(applyPageFilters(conversationList[3], filters)).toEqual(true);
|
||||||
|
});
|
||||||
|
it('returns true if conversation has no inbox and inbox filter is active', () => {
|
||||||
|
const filters = {
|
||||||
|
status: 1,
|
||||||
|
inboxId: 5,
|
||||||
|
};
|
||||||
|
expect(applyPageFilters(conversationList[0], filters)).toEqual(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#filter-labels', () => {
|
||||||
|
it('returns true if conversation has labels and labels filter is active', () => {
|
||||||
|
const filters = {
|
||||||
|
status: 1,
|
||||||
|
labels: ['dev'],
|
||||||
|
};
|
||||||
|
expect(applyPageFilters(conversationList[0], filters)).toEqual(true);
|
||||||
|
});
|
||||||
|
it('returns true if conversation has no inbox and inbox filter is active', () => {
|
||||||
|
const filters = {
|
||||||
|
status: 1,
|
||||||
|
labels: ['dev'],
|
||||||
|
};
|
||||||
|
expect(applyPageFilters(conversationList[2], filters)).toEqual(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#filter-status', () => {
|
||||||
|
it('returns true if conversation has status and status filter is active', () => {
|
||||||
|
const filters = {
|
||||||
|
status: 1,
|
||||||
|
};
|
||||||
|
expect(applyPageFilters(conversationList[1], filters)).toEqual(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user