feat: add contact filter for conversations (#14629)
# Pull Request Template ## Description Adds a Contact condition to the conversation advanced filter so agents can search for an existing contact and filter conversations by `conversations.contact_id`. Fixes [CW-7239](https://linear.app/chatwoot/issue/CW-7239/contact-filter-for-conversations) ## Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality not to work as expected) - [ ] This change requires a documentation update ## How Has This Been Tested? - `eval "$(rbenv init -)" && bundle exec rspec spec/services/conversations/filter_service_spec.rb` - `pnpm exec vitest --no-watch --no-cache --no-coverage --logHeapUsage app/javascript/dashboard/components-next/filter/helper/filterHelper.spec.js app/javascript/dashboard/store/modules/conversations/helpers/specs/filterHelpers.spec.js app/javascript/dashboard/helper/specs/customViewsHelper.spec.js app/javascript/dashboard/helper/specs/filterQueryGenerator.spec.js` - `pnpm eslint` - `eval "$(rbenv init -)" && bundle exec rubocop spec/services/conversations/filter_service_spec.rb` ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [x] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules --------- Co-authored-by: iamsivin <iamsivin@gmail.com> Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
This commit is contained in:
co-authored by
iamsivin
Sivin Varghese
parent
7718f2a62c
commit
e919a2cef5
@@ -15,6 +15,12 @@ const FILTER_KEYS = {
|
||||
[VIEW_TYPES.CONTACT]: VIEW_TYPES.CONTACT,
|
||||
};
|
||||
|
||||
// a folder's contact_id filter stores only the id, extract it so the
|
||||
// contact can be fetched and its name shown in the edit folder modal
|
||||
const getFolderContactId = folder =>
|
||||
folder?.query?.payload?.find(filter => filter.attribute_key === 'contact_id')
|
||||
?.values?.[0];
|
||||
|
||||
export const state = {
|
||||
[VIEW_TYPES.CONVERSATION]: {
|
||||
records: [],
|
||||
@@ -47,6 +53,9 @@ export const getters = {
|
||||
getActiveConversationFolder(_state) {
|
||||
return _state.activeConversationFolder;
|
||||
},
|
||||
getActiveFolderContactId(_state) {
|
||||
return getFolderContactId(_state.activeConversationFolder);
|
||||
},
|
||||
};
|
||||
|
||||
export const actions = {
|
||||
@@ -104,8 +113,11 @@ export const actions = {
|
||||
commit(types.SET_CUSTOM_VIEW_UI_FLAG, { isDeleting: false });
|
||||
}
|
||||
},
|
||||
setActiveConversationFolder({ commit }, data) {
|
||||
setActiveConversationFolder({ commit, dispatch }, data) {
|
||||
commit(types.SET_ACTIVE_CONVERSATION_FOLDER, data);
|
||||
// prefetch the contact of a contact filter so the UI can show its name
|
||||
const contactId = getFolderContactId(data);
|
||||
if (contactId) dispatch('contacts/show', { id: contactId }, { root: true });
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user