feat: Add all filter for conversations (#3102)

This commit is contained in:
Pranav Raj S 2021-09-29 16:23:39 +05:30 committed by GitHub
parent d55a48037a
commit cc244833d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 81 additions and 22 deletions

View file

@ -94,6 +94,8 @@ class ConversationFinder
end end
def filter_by_status def filter_by_status
return if params[:status] == 'all'
@conversations = @conversations.where(status: params[:status] || DEFAULT_STATUS) @conversations = @conversations.where(status: params[:status] || DEFAULT_STATUS)
end end

View file

@ -26,6 +26,7 @@
:active-label="label" :active-label="label"
:team-id="teamId" :team-id="teamId"
:chat="chat" :chat="chat"
:show-assignee="showAssigneeInConversationCard"
/> />
<div v-if="chatListLoading" class="text-center"> <div v-if="chatListLoading" class="text-center">
@ -119,6 +120,9 @@ export default {
}; };
}); });
}, },
showAssigneeInConversationCard() {
return this.activeAssigneeTab === wootConstants.ASSIGNEE_TYPE.ALL;
},
inbox() { inbox() {
return this.$store.getters['inboxes/getInbox'](this.activeInbox); return this.$store.getters['inboxes/getInbox'](this.activeInbox);
}, },

View file

@ -7,6 +7,9 @@
> >
{{ item['TEXT'] }} {{ item['TEXT'] }}
</option> </option>
<option value="all">
{{ $t('CHAT_LIST.FILTER_ALL') }}
</option>
</select> </select>
</template> </template>
@ -30,6 +33,8 @@ export default {
} else if (this.activeStatus === wootConstants.STATUS_TYPE.PENDING) { } else if (this.activeStatus === wootConstants.STATUS_TYPE.PENDING) {
this.activeStatus = wootConstants.STATUS_TYPE.SNOOZED; this.activeStatus = wootConstants.STATUS_TYPE.SNOOZED;
} else if (this.activeStatus === wootConstants.STATUS_TYPE.SNOOZED) { } else if (this.activeStatus === wootConstants.STATUS_TYPE.SNOOZED) {
this.activeStatus = wootConstants.STATUS_TYPE.ALL;
} else if (this.activeStatus === wootConstants.STATUS_TYPE.ALL) {
this.activeStatus = wootConstants.STATUS_TYPE.OPEN; this.activeStatus = wootConstants.STATUS_TYPE.OPEN;
} }
} }

View file

@ -8,7 +8,7 @@
}" }"
@click="cardClick(chat)" @click="cardClick(chat)"
> >
<Thumbnail <thumbnail
v-if="!hideThumbnail" v-if="!hideThumbnail"
:src="currentContact.thumbnail" :src="currentContact.thumbnail"
:badge="inboxBadge" :badge="inboxBadge"
@ -18,10 +18,20 @@
size="40px" size="40px"
/> />
<div class="conversation--details columns"> <div class="conversation--details columns">
<span v-if="showInboxName" class="label"> <div class="conversation--metadata">
<i :class="computedInboxClass" /> <span v-if="showInboxName" class="label">
{{ inboxName }} <i :class="computedInboxClass" />
</span> {{ inboxName }}
</span>
<span
v-if="showAssignee && assignee"
class="label assignee-label text-truncate"
>
<i class="ion-person" />
{{ assignee.name }}
</span>
</div>
<h4 class="conversation--user"> <h4 class="conversation--user">
{{ currentContact.name }} {{ currentContact.name }}
</h4> </h4>
@ -97,6 +107,10 @@ export default {
type: [String, Number], type: [String, Number],
default: 0, default: 0,
}, },
showAssignee: {
type: Boolean,
default: false,
},
}, },
computed: { computed: {
@ -109,7 +123,11 @@ export default {
}), }),
chatMetadata() { chatMetadata() {
return this.chat.meta; return this.chat.meta || {};
},
assignee() {
return this.chatMetadata.assignee || {};
}, },
currentContact() { currentContact() {
@ -252,4 +270,14 @@ export default {
color: var(--s-600); color: var(--s-600);
font-size: var(--font-size-mini); font-size: var(--font-size-mini);
} }
.conversation--metadata {
display: flex;
justify-content: space-between;
padding-right: var(--space-normal);
.assignee-label {
max-width: 50%;
}
}
</style> </style>

View file

@ -10,6 +10,7 @@ export default {
RESOLVED: 'resolved', RESOLVED: 'resolved',
PENDING: 'pending', PENDING: 'pending',
SNOOZED: 'snoozed', SNOOZED: 'snoozed',
ALL: 'all',
}, },
}; };
export const DEFAULT_REDIRECT_URL = '/app/'; export const DEFAULT_REDIRECT_URL = '/app/';

View file

@ -10,6 +10,7 @@
"SEARCH": { "SEARCH": {
"INPUT": "Search for People, Chats, Saved Replies .." "INPUT": "Search for People, Chats, Saved Replies .."
}, },
"FILTER_ALL": "All",
"STATUS_TABS": [ "STATUS_TABS": [
{ {
"NAME": "Open", "NAME": "Open",

View file

@ -5,6 +5,9 @@ export const findPendingMessageIndex = (chat, message) => {
); );
}; };
const filterByStatus = (chatStatus, filterStatus) =>
filterStatus === 'all' ? true : chatStatus === filterStatus;
export const applyPageFilters = (conversation, filters) => { export const applyPageFilters = (conversation, filters) => {
const { inboxId, status, labels = [], teamId } = filters; const { inboxId, status, labels = [], teamId } = filters;
const { const {
@ -15,9 +18,8 @@ export const applyPageFilters = (conversation, filters) => {
} = conversation; } = conversation;
const team = meta.team || {}; const team = meta.team || {};
const { id: chatTeamId } = team; const { id: chatTeamId } = team;
const filterByStatus = chatStatus === status;
let shouldFilter = filterByStatus;
let shouldFilter = filterByStatus(chatStatus, status);
if (inboxId) { if (inboxId) {
const filterByInbox = Number(inboxId) === chatInboxId; const filterByInbox = Number(inboxId) === chatInboxId;
shouldFilter = shouldFilter && filterByInbox; shouldFilter = shouldFilter && filterByInbox;

View file

@ -7,28 +7,28 @@ const conversationList = [
{ {
id: 1, id: 1,
inbox_id: 2, inbox_id: 2,
status: 1, status: 'open',
meta: {}, meta: {},
labels: ['sales', 'dev'], labels: ['sales', 'dev'],
}, },
{ {
id: 2, id: 2,
inbox_id: 2, inbox_id: 2,
status: 1, status: 'open',
meta: {}, meta: {},
labels: ['dev'], labels: ['dev'],
}, },
{ {
id: 11, id: 11,
inbox_id: 3, inbox_id: 3,
status: 1, status: 'resolved',
meta: { team: { id: 5 } }, meta: { team: { id: 5 } },
labels: [], labels: [],
}, },
{ {
id: 22, id: 22,
inbox_id: 4, inbox_id: 4,
status: 1, status: 'pending',
meta: { team: { id: 5 } }, meta: { team: { id: 5 } },
labels: ['sales'], labels: ['sales'],
}, },
@ -56,14 +56,14 @@ describe('#applyPageFilters', () => {
describe('#filter-team', () => { describe('#filter-team', () => {
it('returns true if conversation has team and team filter is active', () => { it('returns true if conversation has team and team filter is active', () => {
const filters = { const filters = {
status: 1, status: 'resolved',
teamId: 5, teamId: 5,
}; };
expect(applyPageFilters(conversationList[3], filters)).toEqual(true); expect(applyPageFilters(conversationList[2], filters)).toEqual(true);
}); });
it('returns true if conversation has no team and team filter is active', () => { it('returns true if conversation has no team and team filter is active', () => {
const filters = { const filters = {
status: 1, status: 'open',
teamId: 5, teamId: 5,
}; };
expect(applyPageFilters(conversationList[0], filters)).toEqual(false); expect(applyPageFilters(conversationList[0], filters)).toEqual(false);
@ -73,14 +73,14 @@ describe('#applyPageFilters', () => {
describe('#filter-inbox', () => { describe('#filter-inbox', () => {
it('returns true if conversation has inbox and inbox filter is active', () => { it('returns true if conversation has inbox and inbox filter is active', () => {
const filters = { const filters = {
status: 1, status: 'pending',
inboxId: 4, inboxId: 4,
}; };
expect(applyPageFilters(conversationList[3], filters)).toEqual(true); expect(applyPageFilters(conversationList[3], filters)).toEqual(true);
}); });
it('returns true if conversation has no inbox and inbox filter is active', () => { it('returns true if conversation has no inbox and inbox filter is active', () => {
const filters = { const filters = {
status: 1, status: 'open',
inboxId: 5, inboxId: 5,
}; };
expect(applyPageFilters(conversationList[0], filters)).toEqual(false); expect(applyPageFilters(conversationList[0], filters)).toEqual(false);
@ -90,14 +90,14 @@ describe('#applyPageFilters', () => {
describe('#filter-labels', () => { describe('#filter-labels', () => {
it('returns true if conversation has labels and labels filter is active', () => { it('returns true if conversation has labels and labels filter is active', () => {
const filters = { const filters = {
status: 1, status: 'open',
labels: ['dev'], labels: ['dev'],
}; };
expect(applyPageFilters(conversationList[0], filters)).toEqual(true); expect(applyPageFilters(conversationList[0], filters)).toEqual(true);
}); });
it('returns true if conversation has no inbox and inbox filter is active', () => { it('returns true if conversation has no inbox and inbox filter is active', () => {
const filters = { const filters = {
status: 1, status: 'open',
labels: ['dev'], labels: ['dev'],
}; };
expect(applyPageFilters(conversationList[2], filters)).toEqual(false); expect(applyPageFilters(conversationList[2], filters)).toEqual(false);
@ -107,7 +107,13 @@ describe('#applyPageFilters', () => {
describe('#filter-status', () => { describe('#filter-status', () => {
it('returns true if conversation has status and status filter is active', () => { it('returns true if conversation has status and status filter is active', () => {
const filters = { const filters = {
status: 1, status: 'open',
};
expect(applyPageFilters(conversationList[1], filters)).toEqual(true);
});
it('returns true if conversation has status and status filter is all', () => {
const filters = {
status: 'all',
}; };
expect(applyPageFilters(conversationList[1], filters)).toEqual(true); expect(applyPageFilters(conversationList[1], filters)).toEqual(true);
}); });

View file

@ -48,6 +48,15 @@ describe ::ConversationFinder do
end end
end end
context 'with status all' do
let(:params) { { status: 'all' } }
it 'returns all conversations' do
result = conversation_finder.perform
expect(result[:conversations].length).to be 5
end
end
context 'with assignee_type assigned' do context 'with assignee_type assigned' do
let(:params) { { assignee_type: 'assigned' } } let(:params) { { assignee_type: 'assigned' } }

View file

@ -15,7 +15,7 @@ get:
- name: status - name: status
in: query in: query
type: string type: string
enum: ['open', 'resolved', 'pending'] enum: ['open', 'resolved', 'pending', 'all']
- name: page - name: page
in: query in: query
type: integer type: integer

View file

@ -1488,7 +1488,8 @@
"enum": [ "enum": [
"open", "open",
"resolved", "resolved",
"pending" "pending",
"all"
] ]
}, },
{ {