Skip to content

Commit 9b3e3f1

Browse files
committed
Fix: tag input in automations not being selected
- Add translated error messages for invalid automation rules. - add support for warning sooner Fixes #251 #230
1 parent 89141a8 commit 9b3e3f1

File tree

4 files changed

+39
-19
lines changed

4 files changed

+39
-19
lines changed

frontend/src/App.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ const initToaster = () => {
254254
emitter.on(EMITTER_EVENTS.SHOW_TOAST, (message) => {
255255
if (message.variant === 'destructive') {
256256
sooner.error(message.description)
257+
} else if (message.variant === 'warning') {
258+
sooner.warning(message.description)
257259
} else {
258260
sooner.success(message.description)
259261
}

frontend/src/features/admin/automation/RuleBox.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@
115115
<TagsInput
116116
:defaultValue="fieldValueAsArray(rule.value)"
117117
@update:modelValue="(value) => handleValueChange(value, index)"
118+
:addOnBlur="true"
119+
:addOnTab="true"
120+
:addOnPaste="true"
118121
>
119122
<TagsInputItem
120123
v-for="item in fieldValueAsArray(rule.value)"

frontend/src/views/admin/automations/CreateOrEditRule.vue

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,11 @@ const onSubmit = form.handleSubmit(async (values) => {
366366
})
367367
368368
const handleSave = async (values) => {
369-
if (!areRulesValid()) {
369+
const validationError = getRulesValidationError()
370+
if (validationError) {
370371
emitter.emit(EMITTER_EVENTS.SHOW_TOAST, {
371-
variant: 'destructive',
372-
description: t('admin.automation.invalid')
372+
variant: 'warning',
373+
description: validationError
373374
})
374375
return
375376
}
@@ -401,58 +402,65 @@ const handleSave = async (values) => {
401402
}
402403
}
403404
404-
// TODO: Maybe we can do some vee validate magic here.
405-
const areRulesValid = () => {
405+
// Returns a specific validation error message, or empty string if valid.
406+
const getRulesValidationError = () => {
406407
// Must have groups.
407408
if (rule.value.rules[0].groups.length == 0) {
408-
return false
409+
return t('admin.automation.validation.addCondition')
409410
}
410411
411-
// At least one group should have at least one rule
412+
// At least one group should have at least one rule.
412413
const group1HasRules = rule.value.rules[0].groups[0].rules.length > 0
413414
const group2HasRules = rule.value.rules[0].groups[1].rules.length > 0
414415
if (!group1HasRules && !group2HasRules) {
415-
return false
416+
return t('admin.automation.validation.addCondition')
416417
}
417418
418-
// For both groups, each rule should have value, operator and field.
419+
// For both groups, each rule should have field, operator, and value.
419420
for (const group of rule.value.rules[0].groups) {
420421
for (const rule of group.rules) {
421-
if (!rule.field || !rule.operator) {
422-
return false
422+
if (!rule.field) {
423+
return t('admin.automation.validation.selectField')
424+
}
425+
if (!rule.operator) {
426+
return t('admin.automation.validation.selectOperator')
423427
}
424-
// For 'set' and `not set` operator, value is not required.
428+
// For 'set' and 'not set' operator, value is not required.
425429
if (rule.operator !== OPERATOR.SET && rule.operator !== OPERATOR.NOT_SET && !rule.value) {
426-
return false
430+
return t('admin.automation.validation.setConditionValue')
427431
}
428432
}
429433
}
430434
431-
// Must have atleast one action.
435+
// Must have at least one action.
432436
if (rule.value.rules[0].actions.length == 0) {
433-
return false
437+
return t('admin.automation.validation.addAction')
434438
}
435439
436-
// Make sure each action has value.
440+
// Make sure each action has a type and value.
437441
for (const action of rule.value.rules[0].actions) {
442+
if (!action.type) {
443+
return t('admin.automation.validation.selectActionType')
444+
}
445+
438446
// CSAT action does not require value, set dummy value.
439447
if (action.type === 'send_csat') {
440448
action.value = ['0']
441449
}
442450
443451
// Empty array, no value selected.
444452
if (action.value.length === 0) {
445-
return false
453+
return t('admin.automation.validation.setActionValue')
446454
}
447455
448456
// Check if all values are present.
449457
for (const key in action.value) {
450458
if (!action.value[key]) {
451-
return false
459+
return t('admin.automation.validation.setActionValue')
452460
}
453461
}
454462
}
455-
return true
463+
return ''
456464
}
457465
458466
onMounted(async () => {

i18n/en.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,13 @@
608608
"admin.automation.event.message.outgoing": "Outgoing message",
609609
"admin.automation.event.message.incoming": "Incoming message",
610610
"admin.automation.invalid": "Make sure you have atleast one action and one rule and their values are not empty.",
611+
"admin.automation.validation.addCondition": "Please add at least one condition.",
612+
"admin.automation.validation.selectField": "Please select a field for all conditions.",
613+
"admin.automation.validation.selectOperator": "Please select an operator for all conditions.",
614+
"admin.automation.validation.setConditionValue": "Please set a value for all conditions.",
615+
"admin.automation.validation.addAction": "Please add at least one action.",
616+
"admin.automation.validation.selectActionType": "Please select a type for all actions.",
617+
"admin.automation.validation.setActionValue": "Please set a value for all actions.",
611618
"admin.notification.restartApp": "Settings updated successfully, Please restart the app for changes to take effect.",
612619
"admin.banner.restartMessage": "Some settings have been changed that require an application restart to take effect.",
613620
"admin.template.outgoingEmailTemplates": "Outgoing email templates",

0 commit comments

Comments
 (0)