diff --git a/app/javascript/dashboard/components-next/filter/helper/filterHelper.js b/app/javascript/dashboard/components-next/filter/helper/filterHelper.js index e275c58a8..274eecb49 100644 --- a/app/javascript/dashboard/components-next/filter/helper/filterHelper.js +++ b/app/javascript/dashboard/components-next/filter/helper/filterHelper.js @@ -11,7 +11,6 @@ export const CONVERSATION_ATTRIBUTES = { CAMPAIGN_ID: 'campaign_id', LABELS: 'labels', BROWSER_LANGUAGE: 'browser_language', - COUNTRY_CODE: 'country_code', REFERER: 'referer', CREATED_AT: 'created_at', LAST_ACTIVITY_AT: 'last_activity_at', diff --git a/app/javascript/dashboard/components-next/filter/provider.js b/app/javascript/dashboard/components-next/filter/provider.js index 7fd600da9..fc418b132 100644 --- a/app/javascript/dashboard/components-next/filter/provider.js +++ b/app/javascript/dashboard/components-next/filter/provider.js @@ -7,7 +7,6 @@ import { buildAttributesFilterTypes, CONVERSATION_ATTRIBUTES, } from './helper/filterHelper'; -import countries from 'shared/constants/countries.js'; import languages from 'dashboard/components/widgets/conversation/advancedFilterItems/languages.js'; /** @@ -218,17 +217,6 @@ export function useConversationFilterContext() { filterOperators: equalityOperators.value, attributeModel: 'additional', }, - { - attributeKey: CONVERSATION_ATTRIBUTES.COUNTRY_CODE, - value: CONVERSATION_ATTRIBUTES.COUNTRY_CODE, - attributeName: t('FILTER.ATTRIBUTES.COUNTRY_NAME'), - label: t('FILTER.ATTRIBUTES.COUNTRY_NAME'), - inputType: 'searchSelect', - options: countries, - dataType: 'text', - filterOperators: equalityOperators.value, - attributeModel: 'additional', - }, { attributeKey: CONVERSATION_ATTRIBUTES.REFERER, value: CONVERSATION_ATTRIBUTES.REFERER, diff --git a/app/javascript/dashboard/components/widgets/conversation/advancedFilterItems/index.js b/app/javascript/dashboard/components/widgets/conversation/advancedFilterItems/index.js index 08b456002..2c3c2fd13 100644 --- a/app/javascript/dashboard/components/widgets/conversation/advancedFilterItems/index.js +++ b/app/javascript/dashboard/components/widgets/conversation/advancedFilterItems/index.js @@ -78,14 +78,6 @@ const filterTypes = [ filterOperators: OPERATOR_TYPES_1, attributeModel: 'additional', }, - { - attributeKey: 'country_code', - attributeI18nKey: 'COUNTRY_NAME', - inputType: 'search_select', - dataType: 'text', - filterOperators: OPERATOR_TYPES_1, - attributeModel: 'additional', - }, { attributeKey: 'referer', attributeI18nKey: 'REFERER_LINK', @@ -171,10 +163,6 @@ export const filterAttributeGroups = [ key: 'browser_language', i18nKey: 'BROWSER_LANGUAGE', }, - { - key: 'country_code', - i18nKey: 'COUNTRY_NAME', - }, { key: 'referer', i18nKey: 'REFERER_LINK', diff --git a/app/javascript/dashboard/store/modules/conversations/helpers/filterHelpers.js b/app/javascript/dashboard/store/modules/conversations/helpers/filterHelpers.js index 96f4a0123..c7060bee3 100644 --- a/app/javascript/dashboard/store/modules/conversations/helpers/filterHelpers.js +++ b/app/javascript/dashboard/store/modules/conversations/helpers/filterHelpers.js @@ -78,7 +78,6 @@ const getValueFromConversation = (conversation, attributeKey) => { case 'team_id': return conversation.meta?.team?.id; case 'browser_language': - case 'country_code': case 'referer': return conversation.additional_attributes?.[attributeKey]; default: diff --git a/db/migrate/20260112092041_remove_country_code_from_conversation_filters.rb b/db/migrate/20260112092041_remove_country_code_from_conversation_filters.rb new file mode 100644 index 000000000..b2d176451 --- /dev/null +++ b/db/migrate/20260112092041_remove_country_code_from_conversation_filters.rb @@ -0,0 +1,32 @@ +class RemoveCountryCodeFromConversationFilters < ActiveRecord::Migration[7.1] + def up + CustomFilter.conversation + .where('query::text LIKE ?', '%country_code%') + .find_each do |custom_filter| + query = custom_filter.query || {} + payload = query['payload'] + + next unless payload.is_a?(Array) + + updated_payload = payload.reject do |filter| + filter.is_a?(Hash) && filter['attribute_key'] == 'country_code' + end + + next if updated_payload == payload + + if updated_payload.empty? + custom_filter.delete + next + end + + # rubocop:disable Rails/SkipsModelValidations + # we will skip model validation, since we don't want any callbacks running + custom_filter.update_columns(query: query.merge('payload' => updated_payload)) + # rubocop:enable Rails/SkipsModelValidations + end + end + + def down + # no-op: removed filters cannot be restored reliably + end +end diff --git a/db/schema.rb b/db/schema.rb index ebdcffed0..bd4f0f968 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2025_12_29_081141) do +ActiveRecord::Schema[7.1].define(version: 2026_01_12_092041) do # These extensions should be enabled to support this database enable_extension "pg_stat_statements" enable_extension "pg_trgm" diff --git a/lib/filters/filter_keys.yml b/lib/filters/filter_keys.yml index 626a0cbd5..bfaf39325 100644 --- a/lib/filters/filter_keys.yml +++ b/lib/filters/filter_keys.yml @@ -86,12 +86,6 @@ conversations: filter_operators: - "equal_to" - "not_equal_to" - country_code: - attribute_type: "additional_attributes" - data_type: "text" - filter_operators: - - "equal_to" - - "not_equal_to" referer: attribute_type: "additional_attributes" data_type: "link" diff --git a/spec/services/automation_rules/conditions_filter_service_spec.rb b/spec/services/automation_rules/conditions_filter_service_spec.rb index 5efd26341..426cb533e 100644 --- a/spec/services/automation_rules/conditions_filter_service_spec.rb +++ b/spec/services/automation_rules/conditions_filter_service_spec.rb @@ -215,5 +215,25 @@ RSpec.describe AutomationRules::ConditionsFilterService do end end end + + context 'when conditions based on contact country_code' do + before do + conversation.update(additional_attributes: { country_code: 'US' }) + conversation.contact.update(additional_attributes: { country_code: 'IN' }) + rule.conditions = [ + { 'values': ['IN'], 'attribute_key': 'country_code', 'query_operator': nil, 'filter_operator': 'equal_to' } + ] + rule.save + end + + it 'matches against the contact additional_attributes' do + expect(described_class.new(rule, conversation, { changed_attributes: {} }).perform).to be(true) + end + + it 'returns false when the contact country_code does not match' do + conversation.contact.update(additional_attributes: { country_code: 'GB' }) + expect(described_class.new(rule, conversation, { changed_attributes: {} }).perform).to be(false) + end + end end end