From e3eca47c31b981721b3280df6c0d9db6b7b94b51 Mon Sep 17 00:00:00 2001 From: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Date: Thu, 30 May 2024 12:29:55 +0530 Subject: [PATCH] feat: Split reconnect logic PR (store) (#9520) # Pull Request Template ## Description This PR includes store filter parts split from this [Reconnect PR](https://github.com/chatwoot/chatwoot/pull/9453) --- .../dashboard/api/inbox/conversation.js | 2 + .../api/specs/inbox/conversation.spec.js | 2 + .../dashboard/components/ChatList.vue | 26 +++-- .../routes/dashboard/inbox/InboxList.vue | 12 ++ .../store/modules/conversations/actions.js | 11 +- .../store/modules/conversations/getters.js | 6 + .../store/modules/conversations/index.js | 22 ++++ .../dashboard/store/modules/customViews.js | 11 ++ .../store/modules/notifications/actions.js | 7 ++ .../store/modules/notifications/getters.js | 3 + .../store/modules/notifications/index.js | 1 + .../store/modules/notifications/mutations.js | 20 ++++ .../specs/conversations/actions.spec.js | 28 +++++ .../specs/conversations/getters.spec.js | 41 +++++++ .../specs/conversations/mutations.spec.js | 110 ++++++++++++++++++ .../modules/specs/customViews/actions.spec.js | 9 ++ .../modules/specs/customViews/getters.spec.js | 7 ++ .../specs/customViews/mutations.spec.js | 8 ++ .../specs/notifications/actions.spec.js | 30 +++++ .../specs/notifications/getters.spec.js | 14 +++ .../specs/notifications/mutations.spec.js | 18 +-- .../dashboard/store/mutation-types.js | 6 + 22 files changed, 374 insertions(+), 20 deletions(-) diff --git a/app/javascript/dashboard/api/inbox/conversation.js b/app/javascript/dashboard/api/inbox/conversation.js index 94cc81354..ebc6176e7 100644 --- a/app/javascript/dashboard/api/inbox/conversation.js +++ b/app/javascript/dashboard/api/inbox/conversation.js @@ -15,6 +15,7 @@ class ConversationApi extends ApiClient { teamId, conversationType, sortBy, + updatedWithin, }) { return axios.get(this.url, { params: { @@ -26,6 +27,7 @@ class ConversationApi extends ApiClient { labels, conversation_type: conversationType, sort_by: sortBy, + updated_within: updatedWithin, }, }); } diff --git a/app/javascript/dashboard/api/specs/inbox/conversation.spec.js b/app/javascript/dashboard/api/specs/inbox/conversation.spec.js index ecc833e16..3287d7477 100644 --- a/app/javascript/dashboard/api/specs/inbox/conversation.spec.js +++ b/app/javascript/dashboard/api/specs/inbox/conversation.spec.js @@ -46,6 +46,7 @@ describe('#ConversationAPI', () => { page: 1, labels: [], teamId: 1, + updatedWithin: 20, }); expect(axiosMock.get).toHaveBeenCalledWith('/api/v1/conversations', { params: { @@ -55,6 +56,7 @@ describe('#ConversationAPI', () => { assignee_type: 'me', page: 1, labels: [], + updated_within: 20, }, }); }); diff --git a/app/javascript/dashboard/components/ChatList.vue b/app/javascript/dashboard/components/ChatList.vue index 5b592a1f7..3e251f42b 100644 --- a/app/javascript/dashboard/components/ChatList.vue +++ b/app/javascript/dashboard/components/ChatList.vue @@ -268,6 +268,7 @@ export default { chatLists: 'getAllConversations', mineChatsList: 'getMineChats', allChatList: 'getAllStatusChats', + chatListFilters: 'getChatListFilters', unAssignedChatsList: 'getUnAssignedChats', chatListLoading: 'getChatListLoadingStatus', currentUserID: 'getCurrentUserID', @@ -293,13 +294,6 @@ export default { hasAppliedFiltersOrActiveFolders() { return this.hasAppliedFilters || this.hasActiveFolders; }, - savedFoldersValue() { - if (this.hasActiveFolders) { - const payload = this.activeFolder.query; - this.fetchSavedFilteredConversations(payload); - } - return {}; - }, showEndOfListMessage() { return ( this.conversationList.length && @@ -375,7 +369,6 @@ export default { labels: this.label ? [this.label] : undefined, teamId: this.teamId || undefined, conversationType: this.conversationType || undefined, - folders: this.hasActiveFolders ? this.savedFoldersValue : undefined, }; }, conversationListPagination() { @@ -488,7 +481,13 @@ export default { this.resetAndFetchData(); this.updateVirtualListProps('conversationType', this.conversationType); }, - activeFolder() { + activeFolder(newVal, oldVal) { + if (newVal !== oldVal) { + this.$store.dispatch( + 'customViews/setActiveConversationFolder', + newVal || null + ); + } this.resetAndFetchData(); this.updateVirtualListProps('foldersId', this.foldersId); }, @@ -498,8 +497,14 @@ export default { showAssigneeInConversationCard(newVal) { this.updateVirtualListProps('showAssignee', newVal); }, + conversationFilters(newVal, oldVal) { + if (newVal !== oldVal) { + this.$store.dispatch('updateChatListFilters', newVal); + } + }, }, mounted() { + this.$store.dispatch('setChatListFilters', this.conversationFilters); this.setFiltersFromUISettings(); this.$store.dispatch('setChatStatusFilter', this.activeStatus); this.$store.dispatch('setChatSortFilter', this.activeSortBy); @@ -695,8 +700,9 @@ export default { this.fetchConversations(); }, fetchConversations() { + this.$store.dispatch('updateChatListFilters', this.conversationFilters); this.$store - .dispatch('fetchAllConversations', this.conversationFilters) + .dispatch('fetchAllConversations') .then(this.emitConversationLoaded); }, loadMoreConversations() { diff --git a/app/javascript/dashboard/routes/dashboard/inbox/InboxList.vue b/app/javascript/dashboard/routes/dashboard/inbox/InboxList.vue index 93ba310c3..f120bbea5 100644 --- a/app/javascript/dashboard/routes/dashboard/inbox/InboxList.vue +++ b/app/javascript/dashboard/routes/dashboard/inbox/InboxList.vue @@ -47,6 +47,7 @@