From fe2bf47fce4a9309f60a29bc4524e8efe89a6a1e Mon Sep 17 00:00:00 2001 From: Fayaz Ahmed Date: Fri, 13 May 2022 12:41:55 +0530 Subject: [PATCH] Bug fixes and Code Climate issue fix --- .../settings/automation/AddAutomationRule.vue | 1 + .../shared/mixins/automationMixin.js | 54 +++++++++---------- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/app/javascript/dashboard/routes/dashboard/settings/automation/AddAutomationRule.vue b/app/javascript/dashboard/routes/dashboard/settings/automation/AddAutomationRule.vue index 888ed0cc0..36463f932 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/automation/AddAutomationRule.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/automation/AddAutomationRule.vue @@ -218,6 +218,7 @@ export default { }, }, mounted() { + this.allCustomAttributes = this.$store.getters['attributes/getAttributes']; this.manifestCustomAttributes(); }, }; diff --git a/app/javascript/shared/mixins/automationMixin.js b/app/javascript/shared/mixins/automationMixin.js index 8c4e16ca4..15d2003fa 100644 --- a/app/javascript/shared/mixins/automationMixin.js +++ b/app/javascript/shared/mixins/automationMixin.js @@ -123,11 +123,8 @@ export default { }, getConditionDropdownValues(type) { const statusFilters = this.$t('CHAT_LIST.CHAT_STATUS_FILTER_ITEMS'); - const allCustomAttributes = this.$store.getters[ - 'attributes/getAttributes' - ]; - const isCustomAttributeCheckbox = allCustomAttributes.find(attr => { + const isCustomAttributeCheckbox = this.allCustomAttributes.find(attr => { return ( attr.attribute_key === type && attr.attribute_display_type === 'checkbox' @@ -146,14 +143,13 @@ export default { ]; } - const isCustomAttributeList = allCustomAttributes.find(attr => { + const isCustomAttributeList = this.allCustomAttributes.find(attr => { return ( attr.attribute_key === type && attr.attribute_display_type === 'list' ); }); - if (isCustomAttributeList) { - return allCustomAttributes + return this.allCustomAttributes .find(attr => attr.attribute_key === type) .attribute_values.map(item => { return { @@ -162,7 +158,6 @@ export default { }; }); } - switch (type) { case 'status': return [ @@ -331,7 +326,7 @@ export default { ].conditions.find(item => item.key === condition.attribute_key) .inputType; } - if (inputType === 'plain_text') { + if (inputType === 'plain_text' || inputType === 'date') { return { ...condition, values: condition.values[0], @@ -346,27 +341,32 @@ export default { }); return conditions; }, + generateActionsArray(action) { + let actionParams = []; + const inputType = this.automationActionTypes.find( + item => item.key === action.action_name + ).inputType; + if (inputType === 'multi_select') { + actionParams = [ + ...this.getActionDropdownValues(action.action_name), + ].filter(item => [...action.action_params].includes(item.id)); + } else if (inputType === 'team_message') { + actionParams = { + team_ids: [ + ...this.getActionDropdownValues(action.action_name), + ].filter(item => + [...action.action_params[0].team_ids].includes(item.id) + ), + message: action.action_params[0].message, + }; + } else actionParams = [...action.action_params]; + return actionParams; + }, manifestActions(automation) { + let actionParams = []; const actions = automation.actions.map(action => { - let actionParams = []; if (action.action_params.length) { - const inputType = this.automationActionTypes.find( - item => item.key === action.action_name - ).inputType; - if (inputType === 'multi_select') { - actionParams = [ - ...this.getActionDropdownValues(action.action_name), - ].filter(item => [...action.action_params].includes(item.id)); - } else if (inputType === 'team_message') { - actionParams = { - team_ids: [ - ...this.getActionDropdownValues(action.action_name), - ].filter(item => - [...action.action_params[0].team_ids].includes(item.id) - ), - message: action.action_params[0].message, - }; - } else actionParams = [...action.action_params]; + actionParams = this.generateActionsArray(action); } return { ...action,