Refactor appendNewCondition

This commit is contained in:
Fayaz Ahmed 2022-05-13 23:00:18 +05:30
parent ff57e99fa2
commit a3323c9a5c
2 changed files with 52 additions and 54 deletions

View file

@ -150,3 +150,43 @@ export const getFileName = (action, files = []) => {
} }
return ''; return '';
}; };
export const getDefaultConditions = eventName => {
if (eventName === 'message_created') {
return [
{
attribute_key: 'message_type',
filter_operator: 'equal_to',
values: '',
query_operator: 'and',
},
];
}
return [
{
attribute_key: 'status',
filter_operator: 'equal_to',
values: '',
query_operator: 'and',
},
];
};
export const getDefaultActions = () => {
return [
{
action_name: 'assign_team',
action_params: [],
},
];
};
export const filterCustomAttributes = customAttributes => {
return customAttributes.map(attr => {
return {
key: attr.attribute_key,
name: attr.attribute_display_name,
type: attr.attribute_display_type,
};
});
};

View file

@ -8,6 +8,9 @@ import {
getOperatorTypes, getOperatorTypes,
isACustomAttribute, isACustomAttribute,
getFileName, getFileName,
getDefaultConditions,
getDefaultActions,
filterCustomAttributes,
} from '../../helper/automationHelper.js'; } from '../../helper/automationHelper.js';
import { mapGetters } from 'vuex'; import { mapGetters } from 'vuex';
@ -53,31 +56,10 @@ export default {
methods: { methods: {
getFileName, getFileName,
onEventChange() { onEventChange() {
if (this.automation.event_name === 'message_created') { this.automation.conditions = getDefaultConditions(
this.automation.conditions = [ this.automation.event_name
{ );
attribute_key: 'message_type', this.automation.actions = getDefaultActions();
filter_operator: 'equal_to',
values: '',
query_operator: 'and',
},
];
} else {
this.automation.conditions = [
{
attribute_key: 'status',
filter_operator: 'equal_to',
values: '',
query_operator: 'and',
},
];
}
this.automation.actions = [
{
action_name: 'assign_team',
action_params: [],
},
];
}, },
getAttributes(key) { getAttributes(key) {
return this.automationTypes[key].conditions; return this.automationTypes[key].conditions;
@ -147,30 +129,12 @@ export default {
].query_operator = 'and'; ].query_operator = 'and';
} }
} }
switch (this.automation.event_name) { this.automation.conditions.push(
case 'message_created': ...getDefaultConditions(this.automation.event_name)
this.automation.conditions.push({ );
attribute_key: 'message_type',
filter_operator: 'equal_to',
values: '',
query_operator: 'and',
});
break;
default:
this.automation.conditions.push({
attribute_key: 'status',
filter_operator: 'equal_to',
values: '',
query_operator: 'and',
});
break;
}
}, },
appendNewAction() { appendNewAction() {
this.automation.actions.push({ this.automation.actions.push(...getDefaultActions());
action_name: 'assign_team',
action_params: [],
});
}, },
removeFilter(index) { removeFilter(index) {
if (this.automation.conditions.length <= 1) { if (this.automation.conditions.length <= 1) {
@ -229,13 +193,7 @@ export default {
this.automation.actions[index].action_params = []; this.automation.actions[index].action_params = [];
}, },
manifestConditions(automation) { manifestConditions(automation) {
const customAttributes = this.allCustomAttributes.map(attr => { const customAttributes = filterCustomAttributes(this.allCustomAttributes);
return {
key: attr.attribute_key,
name: attr.attribute_display_name,
type: attr.attribute_display_type,
};
});
const conditions = automation.conditions.map(condition => { const conditions = automation.conditions.map(condition => {
const isCustomAttribute = customAttributes.find( const isCustomAttribute = customAttributes.find(
attr => attr.key === condition.attribute_key attr => attr.key === condition.attribute_key