Skip to content

Commit

Permalink
Fix - AlertValidation when updated count rule and add second stream
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentD06 committed Jun 18, 2024
1 parent eb9b980 commit 0d47fb1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
21 changes: 9 additions & 12 deletions src/web/wizard/logic/AlertValidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@ function _isRuleValid(rule) {
return true;
}

function _isFieldRulesValid(field_rules) {
if (field_rules.length <= 0) {
function _isFieldRulesValid(stream) {
if (stream === null) {
return true;
}
if (stream.field_rule.length <= 0) {
return false;
}
for (let i = 0; i < field_rules.length; i++) {
if (!_isRuleValid(field_rules[i])){
for (let i = 0; i < stream.field_rule.length; i++) {
if (!_isRuleValid(stream.field_rule[i])){
return false;
}
}
Expand All @@ -61,16 +64,10 @@ export default {
if (isNaN(alert.condition_parameters.threshold)) {
return false;
}
if (!_isFieldRulesValid(alert.stream.field_rule)) {
return false;
}
if (alert.condition_type === 'THEN' && !_isFieldRulesValid(alert.second_stream.field_rule)) {
return false;
}
if (alert.condition_type === 'AND' && !_isFieldRulesValid(alert.second_stream.field_rule)) {
if (!_isFieldRulesValid(alert.stream)) {
return false;
}
if (alert.condition_type === 'OR' && !_isFieldRulesValid(alert.second_stream.field_rule)) {
if (['THEN', 'AND', 'OR'].includes(alert.condition_type) && !_isFieldRulesValid(alert.second_stream)) {
return false;
}
return true;
Expand Down
4 changes: 3 additions & 1 deletion src/web/wizard/logic/AlertValidation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ describe('AlertValidation.isAlertValid', () => {
type: '1',
value: 'a'
}]
}
},
condition_type: 'AND',
second_stream: null
};
const result = AlertValidation.isAlertValid(alert);
expect(result).toBe(true);
Expand Down

0 comments on commit 0d47fb1

Please sign in to comment.