diff --git a/app/javascript/dashboard/components/widgets/FilterInput/Index.vue b/app/javascript/dashboard/components/widgets/FilterInput/Index.vue index 6745e76dc..b3dd67dc3 100644 --- a/app/javascript/dashboard/components/widgets/FilterInput/Index.vue +++ b/app/javascript/dashboard/components/widgets/FilterInput/Index.vue @@ -237,7 +237,10 @@ export default { watch: { customAttributeType: { handler(value) { - if (value === 'conversation_attribute' || value === 'contact_attribute') { + if ( + value === 'conversation_attribute' || + value === 'contact_attribute' + ) { this.value.custom_attribute_type = this.customAttributeType; } else this.value.custom_attribute_type = ''; }, diff --git a/app/services/automation_rules/conditions_filter_service.rb b/app/services/automation_rules/conditions_filter_service.rb index e71f0a8f5..7e79fcf5e 100644 --- a/app/services/automation_rules/conditions_filter_service.rb +++ b/app/services/automation_rules/conditions_filter_service.rb @@ -39,7 +39,7 @@ class AutomationRules::ConditionsFilterService < FilterService @query_string += message_query_string(message_filter, query_hash.with_indifferent_access, current_index) elsif custom_attribute(query_hash['attribute_key'], @account, query_hash['custom_attribute_type']) # send table name according to attribute key right now we are supporting contact based custom attribute filter - @query_string += custom_attribute_query(query_hash.with_indifferent_access, current_index) + @query_string += custom_attribute_query(query_hash.with_indifferent_access, query_hash[:custom_attribute_type], current_index) end end diff --git a/app/services/contacts/filter_service.rb b/app/services/contacts/filter_service.rb index 22ed9891b..aedeb172b 100644 --- a/app/services/contacts/filter_service.rb +++ b/app/services/contacts/filter_service.rb @@ -26,7 +26,7 @@ class Contacts::FilterService < FilterService query_operator = query_hash[:query_operator] filter_operator_value = filter_operation(query_hash, current_index) - return custom_attribute_query(query_hash, 'contacts', current_index) if current_filter.nil? + return custom_attribute_query(query_hash, 'contact_attribute', current_index) if current_filter.nil? case current_filter['attribute_type'] when 'additional_attributes' diff --git a/app/services/conversations/filter_service.rb b/app/services/conversations/filter_service.rb index e52fd279d..d91916b12 100644 --- a/app/services/conversations/filter_service.rb +++ b/app/services/conversations/filter_service.rb @@ -32,7 +32,7 @@ class Conversations::FilterService < FilterService query_operator = query_hash[:query_operator] filter_operator_value = filter_operation(query_hash, current_index) - return custom_attribute_query(query_hash, 'conversations', current_index) if current_filter.nil? + return custom_attribute_query(query_hash, 'conversation_attribute', current_index) if current_filter.nil? case current_filter['attribute_type'] when 'additional_attributes' diff --git a/app/services/filter_service.rb b/app/services/filter_service.rb index 40cdaf868..fea478c27 100644 --- a/app/services/filter_service.rb +++ b/app/services/filter_service.rb @@ -52,8 +52,6 @@ class FilterService query_hash['values'].map { |x| Conversation.statuses[x.to_sym] } when 'message_type' query_hash['values'].map { |x| Message.message_types[x.to_sym] } - when 'list_attributes', 'text_attributes', 'link_attributes' - query_hash['values'].map { |x| x.downcase } else query_hash['values'] end @@ -67,7 +65,7 @@ class FilterService def lt_gt_filter_values(query_hash) attribute_key = query_hash[:attribute_key] - attribute_type = custom_attribute(attribute_key).try(:attribute_display_type) + attribute_type = custom_attribute(attribute_key, @account, query_hash[:custom_attribute_type]).try(:attribute_display_type) attribute_data_type = self.class::ATTRIBUTE_TYPES[attribute_type] value = query_hash['values'][0] operator = query_hash['filter_operator'] == 'is_less_than' ? '<' : '>' @@ -89,10 +87,10 @@ class FilterService ] end - def custom_attribute_query(query_hash, current_index) + def custom_attribute_query(query_hash, custom_attribute_type, current_index) attribute_key = query_hash[:attribute_key] query_operator = query_hash[:query_operator] - attribute_model = query_hash[:custom_attribute_type] || self.class::ATTRIBUTE_MODEL + attribute_model = custom_attribute_type || self.class::ATTRIBUTE_MODEL attribute_type = custom_attribute(attribute_key, @account, attribute_model).try(:attribute_display_type) filter_operator_value = filter_operation(query_hash, current_index) @@ -109,7 +107,7 @@ class FilterService private - def custom_attribute(attribute_key, account = nil, custom_attribute_type) + def custom_attribute(attribute_key, account, custom_attribute_type) current_account = account || Current.account attribute_model = custom_attribute_type || self.class::ATTRIBUTE_MODEL @custom_attribute = current_account.custom_attribute_definitions.where(