From 29259731b824fca8ae70bae083536cb94ac28ea5 Mon Sep 17 00:00:00 2001 From: Fayaz Ahmed Date: Fri, 13 May 2022 15:52:17 +0530 Subject: [PATCH] Refactor --- .../dashboard/helper/automationHelper.js | 16 ++++++ .../mixins/automations/methodsMixin.js | 53 +++++++------------ .../mixins/automations/validationsMixin.js | 0 .../settings/automation/AddAutomationRule.vue | 4 +- 4 files changed, 36 insertions(+), 37 deletions(-) create mode 100644 app/javascript/dashboard/helper/automationHelper.js rename app/javascript/{shared => dashboard}/mixins/automations/methodsMixin.js (90%) rename app/javascript/{shared => dashboard}/mixins/automations/validationsMixin.js (100%) diff --git a/app/javascript/dashboard/helper/automationHelper.js b/app/javascript/dashboard/helper/automationHelper.js new file mode 100644 index 000000000..8b9b737ed --- /dev/null +++ b/app/javascript/dashboard/helper/automationHelper.js @@ -0,0 +1,16 @@ +export const getCustomAttributeInputType = key => { + const customAttributeMap = { + date: 'date', + text: 'plain_text', + list: 'search_select', + checkbox: 'search_select', + }; + + return customAttributeMap[key] || 'plain_text'; +}; + +export const isACustomAttribute = (customAttributes, key) => { + return customAttributes.find(attr => { + return attr.attribute_key === key; + }); +}; diff --git a/app/javascript/shared/mixins/automations/methodsMixin.js b/app/javascript/dashboard/mixins/automations/methodsMixin.js similarity index 90% rename from app/javascript/shared/mixins/automations/methodsMixin.js rename to app/javascript/dashboard/mixins/automations/methodsMixin.js index 0a1018486..4a2b457e9 100644 --- a/app/javascript/shared/mixins/automations/methodsMixin.js +++ b/app/javascript/dashboard/mixins/automations/methodsMixin.js @@ -1,9 +1,12 @@ -import * as OPERATORS from '../../../dashboard/routes/dashboard/settings/automation/operators'; -import languages from '../../../dashboard/components/widgets/conversation/advancedFilterItems/languages'; -import countries from '../../constants/countries'; -import filterQueryGenerator from '../../../dashboard/helper/filterQueryGenerator.js'; -import actionQueryGenerator from '../../../dashboard/helper/actionQueryGenerator.js'; - +import * as OPERATORS from '../../routes/dashboard/settings/automation/operators'; +import languages from '../../components/widgets/conversation/advancedFilterItems/languages'; +import countries from '../../../shared/constants/countries'; +import filterQueryGenerator from '../../helper/filterQueryGenerator.js'; +import actionQueryGenerator from '../../helper/actionQueryGenerator.js'; +import { + getCustomAttributeInputType, + isACustomAttribute, +} from '../../helper/automationHelper.js'; const MESASAGE_CONDITION_VALUES = [ { id: 'incoming', @@ -16,20 +19,6 @@ const MESASAGE_CONDITION_VALUES = [ ]; export default { methods: { - customAttributeInputType(key) { - switch (key) { - case 'date': - return 'date'; - case 'text': - return 'plain_text'; - case 'list': - return 'search_select'; - case 'checkbox': - return 'search_select'; - default: - return 'plain_text'; - } - }, onEventChange() { if (this.automation.event_name === 'message_created') { this.automation.conditions = [ @@ -60,15 +49,10 @@ export default { getAttributes(key) { return this.automationTypes[key].conditions; }, - isACustomAttribute(key) { - return this.allCustomAttributes.find(attr => { - return attr.attribute_key === key; - }); - }, getInputType(key) { - const customAttribute = this.isACustomAttribute(key); + const customAttribute = isACustomAttribute(this.allCustomAttributes, key); if (customAttribute) { - return this.customAttributeInputType( + return getCustomAttributeInputType( customAttribute.attribute_display_type ); } @@ -77,7 +61,10 @@ export default { }, getOperators(key) { if (this.mode === 'edit') { - const customAttribute = this.isACustomAttribute(key); + const customAttribute = isACustomAttribute( + this.allCustomAttributes, + key + ); if (customAttribute) { return this.getOperatorTypes(customAttribute.attribute_display_type); } @@ -290,7 +277,7 @@ export default { ); let inputType = 'plain_text'; if (isCustomAttribute) { - inputType = this.customAttributeInputType(isCustomAttribute.type); + inputType = getCustomAttributeInputType(isCustomAttribute.type); } else { inputType = this.automationTypes[ automation.event_name @@ -409,9 +396,7 @@ export default { return { key: attr.attribute_key, name: attr.attribute_display_name, - inputType: this.customAttributeInputType( - attr.attribute_display_type - ), + inputType: getCustomAttributeInputType(attr.attribute_display_type), filterOperators: this.getOperatorTypes(attr.attribute_display_type), }; } @@ -422,9 +407,7 @@ export default { return { key: attr.attribute_key, name: attr.attribute_display_name, - inputType: this.customAttributeInputType( - attr.attribute_display_type - ), + inputType: getCustomAttributeInputType(attr.attribute_display_type), filterOperators: this.getOperatorTypes(attr.attribute_display_type), }; } diff --git a/app/javascript/shared/mixins/automations/validationsMixin.js b/app/javascript/dashboard/mixins/automations/validationsMixin.js similarity index 100% rename from app/javascript/shared/mixins/automations/validationsMixin.js rename to app/javascript/dashboard/mixins/automations/validationsMixin.js diff --git a/app/javascript/dashboard/routes/dashboard/settings/automation/AddAutomationRule.vue b/app/javascript/dashboard/routes/dashboard/settings/automation/AddAutomationRule.vue index 2aa79d87b..a449eb3ab 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/automation/AddAutomationRule.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/automation/AddAutomationRule.vue @@ -138,8 +138,8 @@