From bf400fb02e0c343d34f1ffd023778e5030de4e59 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Fri, 19 Sep 2025 15:01:45 +0530 Subject: [PATCH] feat: use allConversations for filtered view --- .../store/modules/conversations/getters.js | 27 ++++++++++++++----- .../conversations/helpers/actionHelpers.js | 24 +++++++++-------- .../store/modules/conversations/index.js | 6 +++++ 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/app/javascript/dashboard/store/modules/conversations/getters.js b/app/javascript/dashboard/store/modules/conversations/getters.js index b2337968c..296dd9c02 100644 --- a/app/javascript/dashboard/store/modules/conversations/getters.js +++ b/app/javascript/dashboard/store/modules/conversations/getters.js @@ -74,9 +74,14 @@ const getters = { }, getMineChats: (_state, _, __, rootGetters) => activeFilters => { const currentUserID = rootGetters.getCurrentUser?.id; - const tabConversations = _state.conversationsByTab.me || []; - return tabConversations.filter(conversation => { + // Use allConversations if there are applied filters, otherwise use tab cache + const hasAppliedFilters = _state.appliedFilters?.length > 0; + const conversations = hasAppliedFilters + ? _state.allConversations + : _state.conversationsByTab.me || []; + + return conversations.filter(conversation => { const { assignee } = conversation.meta; const isAssignedToMe = assignee && assignee.id === currentUserID; const shouldFilter = applyPageFilters(conversation, activeFilters); @@ -97,8 +102,13 @@ const getters = { return hasAppliedFilters ? filterQueryGenerator(_state.appliedFilters) : []; }, getUnAssignedChats: _state => activeFilters => { - const tabConversations = _state.conversationsByTab.unassigned || []; - return tabConversations.filter(conversation => { + // Use allConversations if there are applied filters, otherwise use tab cache + const hasAppliedFilters = _state.appliedFilters?.length > 0; + const conversations = hasAppliedFilters + ? _state.allConversations + : _state.conversationsByTab.unassigned || []; + + return conversations.filter(conversation => { const isUnAssigned = !conversation.meta.assignee; const shouldFilter = applyPageFilters(conversation, activeFilters); return isUnAssigned && shouldFilter; @@ -108,12 +118,17 @@ const getters = { const currentUser = rootGetters.getCurrentUser; const currentUserId = rootGetters.getCurrentUser.id; const currentAccountId = rootGetters.getCurrentAccountId; - const tabConversations = _state.conversationsByTab.all || []; + + // Use allConversations if there are applied filters, otherwise use tab cache + const hasAppliedFilters = _state.appliedFilters?.length > 0; + const conversations = hasAppliedFilters + ? _state.allConversations + : _state.conversationsByTab.all || []; const permissions = getUserPermissions(currentUser, currentAccountId); const userRole = getUserRole(currentUser, currentAccountId); - return tabConversations.filter(conversation => { + return conversations.filter(conversation => { const shouldFilter = applyPageFilters(conversation, activeFilters); const allowedForRole = applyRoleFilter( conversation, diff --git a/app/javascript/dashboard/store/modules/conversations/helpers/actionHelpers.js b/app/javascript/dashboard/store/modules/conversations/helpers/actionHelpers.js index cbd5f18e8..21181aa2d 100644 --- a/app/javascript/dashboard/store/modules/conversations/helpers/actionHelpers.js +++ b/app/javascript/dashboard/store/modules/conversations/helpers/actionHelpers.js @@ -42,8 +42,8 @@ const getTabFromFilterType = filterType => { if (filterType === 'me') return 'me'; if (filterType === 'unassigned') return 'unassigned'; if (filterType === 'all') return 'all'; - // For appliedFilters and other cases, default to 'all' - return 'all'; + // For appliedFilters and other cases, return null to use allConversations + return null; }; export const buildConversationList = ( @@ -55,15 +55,17 @@ export const buildConversationList = ( const { payload: conversationList, meta: metaData } = responseData; const tab = getTabFromFilterType(filterType); - // Use tab-scoped mutation - context.commit(types.SET_TAB_CONVERSATION, { - conversations: conversationList, - tab, - }); - context.commit(types.SET_ACTIVE_TAB, tab); - - // Keep legacy mutation for backward compatibility during migration - context.commit(types.SET_ALL_CONVERSATION, conversationList); + if (tab) { + // Use tab-scoped mutation for basic assignee tabs + context.commit(types.SET_TAB_CONVERSATION, { + conversations: conversationList, + tab, + }); + context.commit(types.SET_ACTIVE_TAB, tab); + } else { + // Use allConversations for filtered views (appliedFilters, folders, etc.) + context.commit(types.SET_ALL_CONVERSATION, conversationList); + } context.dispatch('conversationStats/set', metaData); context.dispatch( diff --git a/app/javascript/dashboard/store/modules/conversations/index.js b/app/javascript/dashboard/store/modules/conversations/index.js index 112b7e2bb..0b9ce6086 100644 --- a/app/javascript/dashboard/store/modules/conversations/index.js +++ b/app/javascript/dashboard/store/modules/conversations/index.js @@ -92,6 +92,12 @@ export const mutations = { [types.EMPTY_ALL_CONVERSATION](_state) { _state.allConversations = []; _state.selectedChatId = null; + // Also clear all tab caches so UI renders empty state immediately + _state.conversationsByTab = { + me: [], + unassigned: [], + all: [], + }; }, [types.EMPTY_TAB_CONVERSATION](_state, tab) { if (_state.conversationsByTab[tab]) {