From 50018da780beb21c92dc72898beb1d2606629ef7 Mon Sep 17 00:00:00 2001 From: Fayaz Ahmed Date: Wed, 25 May 2022 13:40:11 +0530 Subject: [PATCH] Send custom_attr key --- .../components/widgets/FilterInput/Index.vue | 27 +++++++++++++++++++ .../dashboard/helper/automationHelper.js | 5 +++- .../mixins/automations/methodsMixin.js | 13 ++++++--- .../settings/automation/AddAutomationRule.vue | 4 +++ .../automation/EditAutomationRule.vue | 4 ++- .../dashboard/settings/automation/Index.vue | 6 +++++ 6 files changed, 54 insertions(+), 5 deletions(-) diff --git a/app/javascript/dashboard/components/widgets/FilterInput/Index.vue b/app/javascript/dashboard/components/widgets/FilterInput/Index.vue index d46503c8d..7ea32f3ec 100644 --- a/app/javascript/dashboard/components/widgets/FilterInput/Index.vue +++ b/app/javascript/dashboard/components/widgets/FilterInput/Index.vue @@ -174,6 +174,10 @@ export default { type: Array, default: () => [], }, + customAttributeType: { + type: String, + default: '', + }, }, computed: { attributeKey: { @@ -216,6 +220,29 @@ export default { this.$emit('input', { ...payload, query_operator: value }); }, }, + custom_attribute_type: { + get() { + if (!this.customAttributeType) return ''; + return this.customAttributeType; + }, + set() { + const payload = this.value || {}; + this.$emit('input', { + ...payload, + custom_attribute_type: this.customAttributeType, + }); + }, + }, + }, + watch: { + customAttributeType: { + handler(value) { + if (value === 'conversation' || value === 'contact') { + this.value.custom_attribute_type = this.customAttributeType; + } else this.value.custom_attribute_type = ''; + }, + immediate: true, + }, }, methods: { removeFilter() { diff --git a/app/javascript/dashboard/helper/automationHelper.js b/app/javascript/dashboard/helper/automationHelper.js index 197a6ec4b..65c4a5313 100644 --- a/app/javascript/dashboard/helper/automationHelper.js +++ b/app/javascript/dashboard/helper/automationHelper.js @@ -76,13 +76,14 @@ export const getOperatorTypes = key => { return operatorMap[key] || OPERATOR_TYPES_1; }; -export const generateCustomAttributeTypes = customAttributes => { +export const generateCustomAttributeTypes = (customAttributes, type) => { return customAttributes.map(attr => { return { key: attr.attribute_key, name: attr.attribute_display_name, inputType: getCustomAttributeInputType(attr.attribute_display_type), filterOperators: getOperatorTypes(attr.attribute_display_type), + customAttributeType: type, }; }); }; @@ -159,6 +160,7 @@ export const getDefaultConditions = eventName => { filter_operator: 'equal_to', values: '', query_operator: 'and', + custom_attribute_type: '', }, ]; } @@ -168,6 +170,7 @@ export const getDefaultConditions = eventName => { filter_operator: 'equal_to', values: '', query_operator: 'and', + custom_attribute_type: '', }, ]; }; diff --git a/app/javascript/dashboard/mixins/automations/methodsMixin.js b/app/javascript/dashboard/mixins/automations/methodsMixin.js index df14fd00e..1d8605e71 100644 --- a/app/javascript/dashboard/mixins/automations/methodsMixin.js +++ b/app/javascript/dashboard/mixins/automations/methodsMixin.js @@ -95,7 +95,12 @@ export default { condition => condition.key === key ); }, - + getCustomAttributeType(key) { + const type = this.automationTypes[ + this.automation.event_name + ].conditions.find(i => i.key === key).customAttributeType; + return type; + }, getConditionDropdownValues(type) { const { agents, @@ -257,10 +262,12 @@ export default { ]('contact_attribute'); const conversationCustomAttributeTypes = generateCustomAttributeTypes( - conversationCustomAttributesRaw + conversationCustomAttributesRaw, + 'conversation' ); const contactCustomAttributeTypes = generateCustomAttributeTypes( - contactCustomAttributesRaw + contactCustomAttributesRaw, + 'contact' ); const manifestedCustomAttributes = [ diff --git a/app/javascript/dashboard/routes/dashboard/settings/automation/AddAutomationRule.vue b/app/javascript/dashboard/routes/dashboard/settings/automation/AddAutomationRule.vue index 25063930d..8b5a13585 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/automation/AddAutomationRule.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/automation/AddAutomationRule.vue @@ -68,6 +68,9 @@ ) " :show-query-operator="i !== automation.conditions.length - 1" + :custom-attribute-type=" + getCustomAttributeType(automation.conditions[i].attribute_key) + " :v="$v.automation.conditions.$each[i]" @resetFilter="resetFilter(i, automation.conditions[i])" @removeFilter="removeFilter(i)" @@ -179,6 +182,7 @@ export default { filter_operator: 'equal_to', values: '', query_operator: 'and', + custom_attribute_type: '', }, ], actions: [ diff --git a/app/javascript/dashboard/routes/dashboard/settings/automation/EditAutomationRule.vue b/app/javascript/dashboard/routes/dashboard/settings/automation/EditAutomationRule.vue index 9bb1480d0..cc696cc80 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/automation/EditAutomationRule.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/automation/EditAutomationRule.vue @@ -64,6 +64,9 @@ automation.conditions[i].attribute_key ) " + :custom-attribute-type=" + getCustomAttributeType(automation.conditions[i].attribute_key) + " :show-query-operator="i !== automation.conditions.length - 1" :v="$v.automation.conditions.$each[i]" @resetFilter="resetFilter(i, automation.conditions[i])" @@ -187,7 +190,6 @@ export default { }, }, mounted() { - this.$store.dispatch('agents/get'); this.manifestCustomAttributes(); this.allCustomAttributes = this.$store.getters['attributes/getAttributes']; this.formatAutomation(this.selectedResponse); diff --git a/app/javascript/dashboard/routes/dashboard/settings/automation/Index.vue b/app/javascript/dashboard/routes/dashboard/settings/automation/Index.vue index 657ef3445..19f8c2f54 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/automation/Index.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/automation/Index.vue @@ -174,6 +174,12 @@ export default { }, }, mounted() { + this.$store.dispatch('inboxes/get'); + this.$store.dispatch('agents/get'); + this.$store.dispatch('contacts/get'); + this.$store.dispatch('teams/get'); + this.$store.dispatch('labels/get'); + this.$store.dispatch('campaigns/get'); this.$store.dispatch('automations/get'); }, methods: {