From c2333214afc71556db940798bb3b485b8249abba Mon Sep 17 00:00:00 2001 From: Fayaz Ahmed <15716057+fayazara@users.noreply.github.com> Date: Thu, 18 Nov 2021 19:15:02 +0530 Subject: [PATCH] feat: Add Advanced Conversation Filters (#3239) Co-authored-by: Muhsin Keloth Co-authored-by: Pranav Raj S Co-authored-by: Tejaswini --- .codeclimate.yml | 3 + .../dashboard/api/inbox/conversation.js | 10 +- .../api/specs/inbox/conversation.spec.js | 37 +++ .../scss/widgets/_conversation-view.scss | 2 +- .../dashboard/assets/scss/widgets/_modal.scss | 8 +- .../dashboard/components/ChatList.vue | 133 +++++++- .../ConversationAdvancedFilter.vue | 284 ++++++++++++++++++ .../advancedFilterItems/countries.js | 257 ++++++++++++++++ .../conversation/advancedFilterItems/index.js | 230 ++++++++++++++ .../advancedFilterItems/languages.js | 132 ++++++++ .../conversation/components/FilterInput.vue | 197 ++++++++++++ .../dashboard/helper/filterQueryGenerator.js | 18 ++ .../helper/specs/filterQueryGenerator.spec.js | 68 +++++ .../i18n/locale/en/advancedFilters.json | 37 +++ .../dashboard/i18n/locale/en/index.js | 2 + .../dashboard/store/modules/campaigns.js | 3 + .../store/modules/conversationPage.js | 3 + .../store/modules/conversations/actions.js | 93 ++++-- .../store/modules/conversations/getters.js | 3 + .../store/modules/conversations/index.js | 61 ++-- .../modules/specs/campaigns/getters.spec.js | 5 + .../specs/conversationPage/mutations.spec.js | 9 +- .../specs/conversations/actions.spec.js | 85 +++++- .../specs/conversations/getters.spec.js | 17 ++ .../specs/conversations/mutations.spec.js | 39 +++ .../conversations/testConversationResponse.js | 97 ++++++ .../dashboard/store/mutation-types.js | 2 + .../shared/assets/stylesheets/font-size.scss | 8 +- .../shared/assets/stylesheets/spacing.scss | 12 +- .../shared/assets/stylesheets/z-index.scss | 1 + 30 files changed, 1778 insertions(+), 78 deletions(-) create mode 100644 app/javascript/dashboard/components/widgets/conversation/ConversationAdvancedFilter.vue create mode 100644 app/javascript/dashboard/components/widgets/conversation/advancedFilterItems/countries.js create mode 100644 app/javascript/dashboard/components/widgets/conversation/advancedFilterItems/index.js create mode 100644 app/javascript/dashboard/components/widgets/conversation/advancedFilterItems/languages.js create mode 100644 app/javascript/dashboard/components/widgets/conversation/components/FilterInput.vue create mode 100644 app/javascript/dashboard/helper/filterQueryGenerator.js create mode 100644 app/javascript/dashboard/helper/specs/filterQueryGenerator.spec.js create mode 100644 app/javascript/dashboard/i18n/locale/en/advancedFilters.json create mode 100644 app/javascript/dashboard/store/modules/specs/conversations/testConversationResponse.js diff --git a/.codeclimate.yml b/.codeclimate.yml index 667b0f340..9e8b209bd 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -40,3 +40,6 @@ exclude_patterns: - "app/javascript/dashboard/i18n/locale" - "**/*.stories.js" - "stories/" + - "app/javascript/dashboard/components/widgets/conversation/advancedFilterItems/index.js" + - "app/javascript/dashboard/components/widgets/conversation/advancedFilterItems/countries.js" + - "app/javascript/dashboard/components/widgets/conversation/advancedFilterItems/languages.js" diff --git a/app/javascript/dashboard/api/inbox/conversation.js b/app/javascript/dashboard/api/inbox/conversation.js index 0c90f3fd4..8fca2b83c 100644 --- a/app/javascript/dashboard/api/inbox/conversation.js +++ b/app/javascript/dashboard/api/inbox/conversation.js @@ -19,6 +19,14 @@ class ConversationApi extends ApiClient { }); } + filter(payload) { + return axios.post(`${this.url}/filter`, payload.queryData, { + params: { + page: payload.page, + }, + }); + } + search({ q }) { return axios.get(`${this.url}/search`, { params: { @@ -54,7 +62,7 @@ class ConversationApi extends ApiClient { toggleTyping({ conversationId, status, isPrivate }) { return axios.post(`${this.url}/${conversationId}/toggle_typing_status`, { typing_status: status, - is_private: isPrivate + is_private: isPrivate, }); } diff --git a/app/javascript/dashboard/api/specs/inbox/conversation.spec.js b/app/javascript/dashboard/api/specs/inbox/conversation.spec.js index 814b83446..d276b8053 100644 --- a/app/javascript/dashboard/api/specs/inbox/conversation.spec.js +++ b/app/javascript/dashboard/api/specs/inbox/conversation.spec.js @@ -19,6 +19,7 @@ describe('#ConversationAPI', () => { expect(conversationAPI).toHaveProperty('unmute'); expect(conversationAPI).toHaveProperty('meta'); expect(conversationAPI).toHaveProperty('sendEmailTranscript'); + expect(conversationAPI).toHaveProperty('filter'); }); describeWithAPIMock('API calls', context => { @@ -173,5 +174,41 @@ describe('#ConversationAPI', () => { } ); }); + + it('#filter', () => { + const payload = { + page: 1, + queryData: { + payload: [ + { + attribute_key: 'status', + filter_operator: 'equal_to', + values: ['pending', 'resolved'], + query_operator: 'and', + }, + { + attribute_key: 'assignee', + filter_operator: 'equal_to', + values: [3], + query_operator: 'and', + }, + { + attribute_key: 'id', + filter_operator: 'equal_to', + values: ['This is a test'], + query_operator: null, + }, + ], + }, + }; + conversationAPI.filter(payload); + expect( + context.axiosMock.post + ).toHaveBeenCalledWith( + '/api/v1/conversations/filter', + payload.queryData, + { params: { page: payload.page } } + ); + }); }); }); diff --git a/app/javascript/dashboard/assets/scss/widgets/_conversation-view.scss b/app/javascript/dashboard/assets/scss/widgets/_conversation-view.scss index 70bf16b95..39cf6ad54 100644 --- a/app/javascript/dashboard/assets/scss/widgets/_conversation-view.scss +++ b/app/javascript/dashboard/assets/scss/widgets/_conversation-view.scss @@ -93,7 +93,7 @@ .status--filter { @include padding($zero null $zero $space-normal); - @include margin($space-smaller $space-slab $zero $zero); + @include margin($zero); background-color: $color-background-light; border: 1px solid $color-border; float: right; diff --git a/app/javascript/dashboard/assets/scss/widgets/_modal.scss b/app/javascript/dashboard/assets/scss/widgets/_modal.scss index a017f776a..f1a36a87c 100644 --- a/app/javascript/dashboard/assets/scss/widgets/_modal.scss +++ b/app/javascript/dashboard/assets/scss/widgets/_modal.scss @@ -29,7 +29,6 @@ } } - .page-top-bar { @include padding($space-large $space-large $zero); @@ -48,13 +47,11 @@ position: relative; width: 60rem; - .content-box { @include padding($zero); height: auto; } - h2 { color: $color-heading; font-size: $font-size-medium; @@ -89,6 +86,10 @@ button { font-size: $font-size-small; } + + &.justify-content-end { + justify-content: end; + } } .delete-item { @@ -97,7 +98,6 @@ @include margin($zero); } } - } .modal-enter, diff --git a/app/javascript/dashboard/components/ChatList.vue b/app/javascript/dashboard/components/ChatList.vue index f8c628a80..919105c2f 100644 --- a/app/javascript/dashboard/components/ChatList.vue +++ b/app/javascript/dashboard/components/ChatList.vue @@ -1,14 +1,39 @@ -