This commit is contained in:
Fayaz Ahmed 2022-05-13 15:52:17 +05:30
parent 403b4f22ec
commit 29259731b8
4 changed files with 36 additions and 37 deletions

View file

@ -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;
});
};

View file

@ -1,9 +1,12 @@
import * as OPERATORS from '../../../dashboard/routes/dashboard/settings/automation/operators'; import * as OPERATORS from '../../routes/dashboard/settings/automation/operators';
import languages from '../../../dashboard/components/widgets/conversation/advancedFilterItems/languages'; import languages from '../../components/widgets/conversation/advancedFilterItems/languages';
import countries from '../../constants/countries'; import countries from '../../../shared/constants/countries';
import filterQueryGenerator from '../../../dashboard/helper/filterQueryGenerator.js'; import filterQueryGenerator from '../../helper/filterQueryGenerator.js';
import actionQueryGenerator from '../../../dashboard/helper/actionQueryGenerator.js'; import actionQueryGenerator from '../../helper/actionQueryGenerator.js';
import {
getCustomAttributeInputType,
isACustomAttribute,
} from '../../helper/automationHelper.js';
const MESASAGE_CONDITION_VALUES = [ const MESASAGE_CONDITION_VALUES = [
{ {
id: 'incoming', id: 'incoming',
@ -16,20 +19,6 @@ const MESASAGE_CONDITION_VALUES = [
]; ];
export default { export default {
methods: { 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() { onEventChange() {
if (this.automation.event_name === 'message_created') { if (this.automation.event_name === 'message_created') {
this.automation.conditions = [ this.automation.conditions = [
@ -60,15 +49,10 @@ export default {
getAttributes(key) { getAttributes(key) {
return this.automationTypes[key].conditions; return this.automationTypes[key].conditions;
}, },
isACustomAttribute(key) {
return this.allCustomAttributes.find(attr => {
return attr.attribute_key === key;
});
},
getInputType(key) { getInputType(key) {
const customAttribute = this.isACustomAttribute(key); const customAttribute = isACustomAttribute(this.allCustomAttributes, key);
if (customAttribute) { if (customAttribute) {
return this.customAttributeInputType( return getCustomAttributeInputType(
customAttribute.attribute_display_type customAttribute.attribute_display_type
); );
} }
@ -77,7 +61,10 @@ export default {
}, },
getOperators(key) { getOperators(key) {
if (this.mode === 'edit') { if (this.mode === 'edit') {
const customAttribute = this.isACustomAttribute(key); const customAttribute = isACustomAttribute(
this.allCustomAttributes,
key
);
if (customAttribute) { if (customAttribute) {
return this.getOperatorTypes(customAttribute.attribute_display_type); return this.getOperatorTypes(customAttribute.attribute_display_type);
} }
@ -290,7 +277,7 @@ export default {
); );
let inputType = 'plain_text'; let inputType = 'plain_text';
if (isCustomAttribute) { if (isCustomAttribute) {
inputType = this.customAttributeInputType(isCustomAttribute.type); inputType = getCustomAttributeInputType(isCustomAttribute.type);
} else { } else {
inputType = this.automationTypes[ inputType = this.automationTypes[
automation.event_name automation.event_name
@ -409,9 +396,7 @@ export default {
return { return {
key: attr.attribute_key, key: attr.attribute_key,
name: attr.attribute_display_name, name: attr.attribute_display_name,
inputType: this.customAttributeInputType( inputType: getCustomAttributeInputType(attr.attribute_display_type),
attr.attribute_display_type
),
filterOperators: this.getOperatorTypes(attr.attribute_display_type), filterOperators: this.getOperatorTypes(attr.attribute_display_type),
}; };
} }
@ -422,9 +407,7 @@ export default {
return { return {
key: attr.attribute_key, key: attr.attribute_key,
name: attr.attribute_display_name, name: attr.attribute_display_name,
inputType: this.customAttributeInputType( inputType: getCustomAttributeInputType(attr.attribute_display_type),
attr.attribute_display_type
),
filterOperators: this.getOperatorTypes(attr.attribute_display_type), filterOperators: this.getOperatorTypes(attr.attribute_display_type),
}; };
} }

View file

@ -138,8 +138,8 @@
<script> <script>
import alertMixin from 'shared/mixins/alertMixin'; import alertMixin from 'shared/mixins/alertMixin';
import automationMethodsMixin from 'shared/mixins/automations/methodsMixin'; import automationMethodsMixin from 'dashboard/mixins/automations/methodsMixin';
import automationValidationsMixin from 'shared/mixins/automations/validationsMixin'; import automationValidationsMixin from 'dashboard/mixins/automations/validationsMixin';
import filterInputBox from 'dashboard/components/widgets/FilterInput/Index.vue'; import filterInputBox from 'dashboard/components/widgets/FilterInput/Index.vue';
import automationActionInput from 'dashboard/components/widgets/AutomationActionInput.vue'; import automationActionInput from 'dashboard/components/widgets/AutomationActionInput.vue';