From 7f8e3ccbbc4653945b8a2bde87b4598b9bb109da Mon Sep 17 00:00:00 2001 From: Abhinav Raut Date: Tue, 15 Apr 2025 21:31:19 +0530 Subject: [PATCH] fix[automation]: handle empty `fieldType` in the frontend breaking the automation view. fix: Previously removed operators for Number type field. Fixes #68 --- frontend/src/constants/filterConfig.js | 2 +- .../src/features/admin/automation/RuleBox.vue | 19 +++++++++++++++---- internal/automation/evaluator.go | 2 +- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/frontend/src/constants/filterConfig.js b/frontend/src/constants/filterConfig.js index 5c6098bb..5c994e1d 100644 --- a/frontend/src/constants/filterConfig.js +++ b/frontend/src/constants/filterConfig.js @@ -38,5 +38,5 @@ export const FIELD_OPERATORS = { OPERATOR.GREATER_THAN, OPERATOR.LESS_THAN ], - NUMBER: [OPERATOR.EQUALS, OPERATOR.NOT_EQUALS], + NUMBER: [OPERATOR.EQUALS, OPERATOR.NOT_EQUALS, OPERATOR.GREATER_THAN, OPERATOR.LESS_THAN], } diff --git a/frontend/src/features/admin/automation/RuleBox.vue b/frontend/src/features/admin/automation/RuleBox.vue index 6e5816cc..13b29f99 100644 --- a/frontend/src/features/admin/automation/RuleBox.vue +++ b/frontend/src/features/admin/automation/RuleBox.vue @@ -206,9 +206,7 @@ -
-
- +
@@ -380,6 +378,10 @@ const emitUpdate = () => { } const getFieldOperators = (field, fieldType) => { + // Set default field type if not set for backwards compatibility as this field was added later. + if (!fieldType) { + fieldType = fieldTypeConstants.conversation + } if (fieldType === fieldTypeConstants.contact_custom_attribute) { return contactCustomAttributes.value[field]?.operators || [] } @@ -390,6 +392,10 @@ const getFieldOperators = (field, fieldType) => { } const getFieldOptions = (field, fieldType) => { + // Set default field type if not set for backwards compatibility as this field was added later. + if (!fieldType) { + fieldType = fieldTypeConstants.conversation + } if (fieldType === fieldTypeConstants.contact_custom_attribute) { return contactCustomAttributes.value[field]?.options || [] } @@ -401,9 +407,14 @@ const getFieldOptions = (field, fieldType) => { const inputType = (index) => { const field = ruleGroup.value.rules[index]?.field - const fieldType = ruleGroup.value.rules[index]?.field_type const operator = ruleGroup.value.rules[index]?.operator + let fieldType = ruleGroup.value.rules[index]?.field_type if (['contains', 'not contains'].includes(operator)) return 'tag' + + // Set default field type if not set for backwards compatibility as this field was added later. + if (!fieldType) { + fieldType = fieldTypeConstants.conversation + } if (field && fieldType) { if (fieldType === fieldTypeConstants.contact_custom_attribute) { return contactCustomAttributes.value[field]?.type || '' diff --git a/internal/automation/evaluator.go b/internal/automation/evaluator.go index 1ca1825e..58774919 100644 --- a/internal/automation/evaluator.go +++ b/internal/automation/evaluator.go @@ -111,7 +111,7 @@ func (e *Engine) evaluateRule(rule models.RuleDetail, conversation cmodels.Conve customAttributes map[string]any ) - // Assign default field type if not provided + // Assign default field type if not provided for backward compatibility. if rule.FieldType == "" { rule.FieldType = models.FieldTypeConversationField }