From e919a2cef5fd69d84da4a03f8c430ba9051084b6 Mon Sep 17 00:00:00 2001 From: Sony Mathew Date: Mon, 8 Jun 2026 16:00:17 +0530 Subject: [PATCH] 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 Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> --- .../helpers/composeConversationHelper.js | 7 +- .../components-next/filter/ConditionRow.vue | 46 +++++++- .../filter/helper/filterHelper.js | 1 + .../filter/helper/filterHelper.spec.js | 89 +++++++++++++++ .../filter/inputs/SingleSelect.vue | 34 +++++- .../components-next/filter/provider.js | 39 ++++++- .../dashboard/components/ChatList.vue | 4 + .../conversation/advancedFilterItems/index.js | 12 ++ .../dashboard/helper/customViewsHelper.js | 10 ++ .../helper/specs/customViewsHelper.spec.js | 35 ++++++ .../helper/specs/filterQueryGenerator.spec.js | 21 ++++ .../i18n/locale/en/advancedFilters.json | 3 + .../conversations/helpers/filterHelpers.js | 6 + .../helpers/specs/filterHelpers.spec.js | 26 +++++ .../dashboard/store/modules/customViews.js | 14 ++- .../modules/specs/customViews/actions.spec.js | 30 ++++- .../modules/specs/customViews/fixtures.js | 15 +++ .../modules/specs/customViews/getters.spec.js | 18 ++- lib/filters/filter_keys.yml | 6 + .../conversations/filter_service_spec.rb | 108 +++++++++++++++--- 20 files changed, 496 insertions(+), 28 deletions(-) diff --git a/app/javascript/dashboard/components-next/NewConversation/helpers/composeConversationHelper.js b/app/javascript/dashboard/components-next/NewConversation/helpers/composeConversationHelper.js index 5c002d9bd..8e933cd84 100644 --- a/app/javascript/dashboard/components-next/NewConversation/helpers/composeConversationHelper.js +++ b/app/javascript/dashboard/components-next/NewConversation/helpers/composeConversationHelper.js @@ -182,7 +182,10 @@ const MIN_SEARCH_LENGTH = 2; export const createContactSearcher = () => { let controller = null; - return async (query, { skipMinLength = false } = {}) => { + return async ( + query, + { skipMinLength = false, reachableOnly = true } = {} + ) => { const trimmed = typeof query === 'string' ? query.trim() : ''; controller?.abort(); @@ -199,6 +202,8 @@ export const createContactSearcher = () => { } = await ContactAPI.search(trimmed, 1, 'name', '', { signal }); const camelCasedPayload = camelcaseKeys(payload, { deep: true }); + if (!reachableOnly) return camelCasedPayload || []; + // Filter contacts that have either phone_number or email const filteredPayload = camelCasedPayload?.filter( contact => contact.phoneNumber || contact.email diff --git a/app/javascript/dashboard/components-next/filter/ConditionRow.vue b/app/javascript/dashboard/components-next/filter/ConditionRow.vue index cc620de32..30709babd 100644 --- a/app/javascript/dashboard/components-next/filter/ConditionRow.vue +++ b/app/javascript/dashboard/components-next/filter/ConditionRow.vue @@ -1,6 +1,7 @@