Skip to content

Commit

Permalink
feat: Ability filter blocked contacts (#9048)
Browse files Browse the repository at this point in the history
- This PR introduces the ability to filter blocked contacts from the contacts filter UI
  • Loading branch information
sojan-official committed Mar 20, 2024
1 parent f78f278 commit 1303469
Show file tree
Hide file tree
Showing 6 changed files with 197 additions and 156 deletions.
24 changes: 11 additions & 13 deletions app/helpers/filter_helper.rb
Expand Up @@ -34,7 +34,7 @@ def build_condition_query_string(current_filter, query_hash, current_index)

case current_filter['attribute_type']
when 'additional_attributes'
handle_additional_attributes(query_hash, filter_operator_value)
handle_additional_attributes(query_hash, filter_operator_value, current_filter['data_type'])
else
handle_standard_attributes(current_filter, query_hash, current_index, filter_operator_value)
end
Expand All @@ -45,10 +45,8 @@ def handle_nil_filter(query_hash, current_index)
custom_attribute_query(query_hash, attribute_type, current_index)
end

# TODO: Change the reliance on entity instead introduce datatype text_case_insensive
# Then we can remove the condition for Contact
def handle_additional_attributes(query_hash, filter_operator_value)
if filter_config[:entity] == 'Contact'
def handle_additional_attributes(query_hash, filter_operator_value, data_type)
if data_type == 'text_case_insensitive'
"LOWER(#{filter_config[:table_name]}.additional_attributes ->> '#{query_hash[:attribute_key]}') " \
"#{filter_operator_value} #{query_hash[:query_operator]}"
else
Expand All @@ -63,6 +61,8 @@ def handle_standard_attributes(current_filter, query_hash, current_index, filter
date_filter(current_filter, query_hash, filter_operator_value)
when 'labels'
tag_filter_query(query_hash, current_index)
when 'text_case_insensitive'
text_case_insensitive_filter(query_hash, filter_operator_value)
else
default_filter(query_hash, filter_operator_value)
end
Expand All @@ -73,14 +73,12 @@ def date_filter(current_filter, query_hash, filter_operator_value)
"#{filter_operator_value}#{current_filter['data_type']} #{query_hash[:query_operator]}"
end

# TODO: Change the reliance on entity instead introduce datatype text_case_insensive
# Then we can remove the condition for Contact
def text_case_insensitive_filter(query_hash, filter_operator_value)
"LOWER(#{filter_config[:table_name]}.#{query_hash[:attribute_key]}) " \
"#{filter_operator_value} #{query_hash[:query_operator]}"
end

def default_filter(query_hash, filter_operator_value)
if filter_config[:entity] == 'Contact'
"LOWER(#{filter_config[:table_name]}.#{query_hash[:attribute_key]}) " \
"#{filter_operator_value} #{query_hash[:query_operator]}"
else
"#{filter_config[:table_name]}.#{query_hash[:attribute_key]} #{filter_operator_value} #{query_hash[:query_operator]}"
end
"#{filter_config[:table_name]}.#{query_hash[:attribute_key]} #{filter_operator_value} #{query_hash[:query_operator]}"
end
end
3 changes: 2 additions & 1 deletion app/javascript/dashboard/i18n/locale/en/contactFilters.json
Expand Up @@ -44,7 +44,8 @@
"CUSTOM_ATTRIBUTE_CHECKBOX": "Checkbox",
"CREATED_AT": "Created At",
"LAST_ACTIVITY": "Last Activity",
"REFERER_LINK": "Referrer link"
"REFERER_LINK": "Referrer link",
"BLOCKED": "Blocked"
},
"GROUPS": {
"STANDARD_FILTERS": "Standard Filters",
Expand Down
Expand Up @@ -243,7 +243,7 @@ export default {
attr.attribute_display_type === 'checkbox'
);
});
if (isCustomAttributeCheckbox) {
if (isCustomAttributeCheckbox || type === 'blocked') {
return [
{
id: true,
Expand Down
Expand Up @@ -76,6 +76,14 @@ const filterTypes = [
filterOperators: OPERATOR_TYPES_5,
attributeModel: 'standard',
},
{
attributeKey: 'blocked',
attributeI18nKey: 'BLOCKED',
inputType: 'search_select',
dataType: 'text',
filterOperators: OPERATOR_TYPES_1,
attributeModel: 'standard',
},
];

export const filterAttributeGroups = [
Expand Down Expand Up @@ -115,6 +123,10 @@ export const filterAttributeGroups = [
key: 'last_activity_at',
i18nKey: 'LAST_ACTIVITY',
},
{
key: 'blocked',
i18nKey: 'BLOCKED',
},
],
},
];
Expand Down
22 changes: 14 additions & 8 deletions lib/filters/filter_keys.yml
Expand Up @@ -8,7 +8,7 @@
# - Parent Key (conversation, contact, messages)
# - Key (attribute_name)
# - attribute_type: "standard" : supported ["standard", "additional_attributes (only for conversations and messages)"]
# - data_type: "text" : supported ["text", "number", "labels", "date", "link"]
# - data_type: "text" : supported ["text", "text_case_insensitive", "number", "boolean", "labels", "date", "link"]
# - filter_operators: ["equal_to", "not_equal_to", "contains", "does_not_contain", "is_present", "is_not_present", "is_greater_than", "is_less_than", "days_before", "starts_with"]

### ----- Conversation Filters ----- ###
Expand Down Expand Up @@ -124,15 +124,15 @@ conversations:
contacts:
name:
attribute_type: "standard"
data_type: "text"
data_type: "text_case_insensitive"
filter_operators:
- "equal_to"
- "not_equal_to"
- "contains"
- "does_not_contain"
phone_number:
attribute_type: "standard"
data_type: "text"
data_type: "text_case_insensitive"
filter_operators:
- "equal_to"
- "not_equal_to"
Expand All @@ -141,35 +141,35 @@ contacts:
- "starts_with"
email:
attribute_type: "standard"
data_type: "text"
data_type: "text_case_insensitive"
filter_operators:
- "equal_to"
- "not_equal_to"
- "contains"
- "does_not_contain"
identifier:
attribute_type: "standard"
data_type: "text"
data_type: "text_case_insensitive"
filter_operators:
- "equal_to"
- "not_equal_to"
country_code:
attribute_type: "additional_attributes"
data_type: "text"
data_type: "text_case_insensitive"
filter_operators:
- "equal_to"
- "not_equal_to"
city:
attribute_type: "additional_attributes"
data_type: "text"
data_type: "text_case_insensitive"
filter_operators:
- "equal_to"
- "not_equal_to"
- "contains"
- "does_not_contain"
company:
attribute_type: "additional_attributes"
data_type: "text"
data_type: "text_case_insensitive"
filter_operators:
- "equal_to"
- "not_equal_to"
Expand Down Expand Up @@ -197,6 +197,12 @@ contacts:
- "is_greater_than"
- "is_less_than"
- "days_before"
blocked:
attribute_type: "standard"
data_type: "boolean"
filter_operators:
- "equal_to"
- "not_equal_to"

### ----- End of Contact Filters ----- ###

Expand Down

0 comments on commit 1303469

Please sign in to comment.