Refactor Automion mixin
This commit is contained in:
parent
29259731b8
commit
1ebdd0e573
2 changed files with 78 additions and 63 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
import {
|
||||||
|
OPERATOR_TYPES_1,
|
||||||
|
OPERATOR_TYPES_3,
|
||||||
|
OPERATOR_TYPES_4,
|
||||||
|
} from '../routes/dashboard/settings/automation/operators';
|
||||||
|
|
||||||
export const getCustomAttributeInputType = key => {
|
export const getCustomAttributeInputType = key => {
|
||||||
const customAttributeMap = {
|
const customAttributeMap = {
|
||||||
date: 'date',
|
date: 'date',
|
||||||
|
@ -14,3 +20,59 @@ export const isACustomAttribute = (customAttributes, key) => {
|
||||||
return attr.attribute_key === key;
|
return attr.attribute_key === key;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getCustomAttributeListDropdownValues = (
|
||||||
|
customAttributes,
|
||||||
|
type
|
||||||
|
) => {
|
||||||
|
return customAttributes
|
||||||
|
.find(attr => attr.attribute_key === type)
|
||||||
|
.attribute_values.map(item => {
|
||||||
|
return {
|
||||||
|
id: item,
|
||||||
|
name: item,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getCustomAttributeCheckboxDropdownValues = () => {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
id: true,
|
||||||
|
name: this.$t('FILTER.ATTRIBUTE_LABELS.TRUE'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: false,
|
||||||
|
name: this.$t('FILTER.ATTRIBUTE_LABELS.FALSE'),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const isCustomAttributeCheckbox = (customAttributes, key) => {
|
||||||
|
return customAttributes.find(attr => {
|
||||||
|
return (
|
||||||
|
attr.attribute_key === key && attr.attribute_display_type === 'checkbox'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const isCustomAttributeList = (customAttributes, type) => {
|
||||||
|
return customAttributes.find(attr => {
|
||||||
|
return (
|
||||||
|
attr.attribute_key === type && attr.attribute_display_type === 'list'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getOperatorTypes = key => {
|
||||||
|
const operatorMap = {
|
||||||
|
list: OPERATOR_TYPES_1,
|
||||||
|
text: OPERATOR_TYPES_3,
|
||||||
|
number: OPERATOR_TYPES_1,
|
||||||
|
link: OPERATOR_TYPES_1,
|
||||||
|
date: OPERATOR_TYPES_4,
|
||||||
|
checkbox: OPERATOR_TYPES_1,
|
||||||
|
};
|
||||||
|
|
||||||
|
return operatorMap[key] || OPERATOR_TYPES_1;
|
||||||
|
};
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import * as OPERATORS from '../../routes/dashboard/settings/automation/operators';
|
|
||||||
import languages from '../../components/widgets/conversation/advancedFilterItems/languages';
|
import languages from '../../components/widgets/conversation/advancedFilterItems/languages';
|
||||||
import countries from '../../../shared/constants/countries';
|
import countries from '../../../shared/constants/countries';
|
||||||
import filterQueryGenerator from '../../helper/filterQueryGenerator.js';
|
import filterQueryGenerator from '../../helper/filterQueryGenerator.js';
|
||||||
|
@ -6,7 +5,13 @@ import actionQueryGenerator from '../../helper/actionQueryGenerator.js';
|
||||||
import {
|
import {
|
||||||
getCustomAttributeInputType,
|
getCustomAttributeInputType,
|
||||||
isACustomAttribute,
|
isACustomAttribute,
|
||||||
|
getCustomAttributeListDropdownValues,
|
||||||
|
getCustomAttributeCheckboxDropdownValues,
|
||||||
|
isCustomAttributeCheckbox,
|
||||||
|
isCustomAttributeList,
|
||||||
|
getOperatorTypes,
|
||||||
} from '../../helper/automationHelper.js';
|
} from '../../helper/automationHelper.js';
|
||||||
|
|
||||||
const MESASAGE_CONDITION_VALUES = [
|
const MESASAGE_CONDITION_VALUES = [
|
||||||
{
|
{
|
||||||
id: 'incoming',
|
id: 'incoming',
|
||||||
|
@ -66,7 +71,7 @@ export default {
|
||||||
key
|
key
|
||||||
);
|
);
|
||||||
if (customAttribute) {
|
if (customAttribute) {
|
||||||
return this.getOperatorTypes(customAttribute.attribute_display_type);
|
return getOperatorTypes(customAttribute.attribute_display_type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const type = this.getAutomationType(key);
|
const type = this.getAutomationType(key);
|
||||||
|
@ -77,43 +82,6 @@ export default {
|
||||||
condition => condition.key === key
|
condition => condition.key === key
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
customAttributeCheckboxDropdownValues() {
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
id: true,
|
|
||||||
name: this.$t('FILTER.ATTRIBUTE_LABELS.TRUE'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: false,
|
|
||||||
name: this.$t('FILTER.ATTRIBUTE_LABELS.FALSE'),
|
|
||||||
},
|
|
||||||
];
|
|
||||||
},
|
|
||||||
customAttributeListDropdownValues(type) {
|
|
||||||
return this.allCustomAttributes
|
|
||||||
.find(attr => attr.attribute_key === type)
|
|
||||||
.attribute_values.map(item => {
|
|
||||||
return {
|
|
||||||
id: item,
|
|
||||||
name: item,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
},
|
|
||||||
isCustomAttributeCheckbox(type) {
|
|
||||||
return this.allCustomAttributes.find(attr => {
|
|
||||||
return (
|
|
||||||
attr.attribute_key === type &&
|
|
||||||
attr.attribute_display_type === 'checkbox'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
isCustomAttributeList(type) {
|
|
||||||
return this.allCustomAttributes.find(attr => {
|
|
||||||
return (
|
|
||||||
attr.attribute_key === type && attr.attribute_display_type === 'list'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
statusFilterDropdownValues() {
|
statusFilterDropdownValues() {
|
||||||
const statusFilters = this.$t('CHAT_LIST.CHAT_STATUS_FILTER_ITEMS');
|
const statusFilters = this.$t('CHAT_LIST.CHAT_STATUS_FILTER_ITEMS');
|
||||||
return [
|
return [
|
||||||
|
@ -130,11 +98,14 @@ export default {
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
getConditionDropdownValues(type) {
|
getConditionDropdownValues(type) {
|
||||||
if (this.isCustomAttributeCheckbox(type))
|
if (isCustomAttributeCheckbox(this.allCustomAttributes, type))
|
||||||
return this.customAttributeCheckboxDropdownValues();
|
return getCustomAttributeCheckboxDropdownValues();
|
||||||
|
|
||||||
if (this.isCustomAttributeList(type))
|
if (isCustomAttributeList(this.allCustomAttributes, type))
|
||||||
return this.customAttributeListDropdownValues(type);
|
return getCustomAttributeListDropdownValues(
|
||||||
|
this.allCustomAttributes,
|
||||||
|
type
|
||||||
|
);
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'status':
|
case 'status':
|
||||||
|
@ -340,24 +311,6 @@ export default {
|
||||||
actions: this.manifestActions(automation),
|
actions: this.manifestActions(automation),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
getOperatorTypes(key) {
|
|
||||||
switch (key) {
|
|
||||||
case 'list':
|
|
||||||
return OPERATORS.OPERATOR_TYPES_1;
|
|
||||||
case 'text':
|
|
||||||
return OPERATORS.OPERATOR_TYPES_3;
|
|
||||||
case 'number':
|
|
||||||
return OPERATORS.OPERATOR_TYPES_1;
|
|
||||||
case 'link':
|
|
||||||
return OPERATORS.OPERATOR_TYPES_1;
|
|
||||||
case 'date':
|
|
||||||
return OPERATORS.OPERATOR_TYPES_4;
|
|
||||||
case 'checkbox':
|
|
||||||
return OPERATORS.OPERATOR_TYPES_1;
|
|
||||||
default:
|
|
||||||
return OPERATORS.OPERATOR_TYPES_1;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
getFileName(id, actionType) {
|
getFileName(id, actionType) {
|
||||||
if (!id) return '';
|
if (!id) return '';
|
||||||
if (actionType === 'send_attachment') {
|
if (actionType === 'send_attachment') {
|
||||||
|
@ -397,7 +350,7 @@ export default {
|
||||||
key: attr.attribute_key,
|
key: attr.attribute_key,
|
||||||
name: attr.attribute_display_name,
|
name: attr.attribute_display_name,
|
||||||
inputType: getCustomAttributeInputType(attr.attribute_display_type),
|
inputType: getCustomAttributeInputType(attr.attribute_display_type),
|
||||||
filterOperators: this.getOperatorTypes(attr.attribute_display_type),
|
filterOperators: getOperatorTypes(attr.attribute_display_type),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -408,7 +361,7 @@ export default {
|
||||||
key: attr.attribute_key,
|
key: attr.attribute_key,
|
||||||
name: attr.attribute_display_name,
|
name: attr.attribute_display_name,
|
||||||
inputType: getCustomAttributeInputType(attr.attribute_display_type),
|
inputType: getCustomAttributeInputType(attr.attribute_display_type),
|
||||||
filterOperators: this.getOperatorTypes(attr.attribute_display_type),
|
filterOperators: getOperatorTypes(attr.attribute_display_type),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue