Skip to content

Commit

Permalink
added another invalid trigger check (#668)
Browse files Browse the repository at this point in the history
Signed-off-by: Amardeepsingh Siglani <amardeep7194@gmail.com>
  • Loading branch information
amsiglan authored Aug 2, 2023
1 parent 92a9994 commit 1741371
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const FormikInputWrapper = ({ name, fieldProps, render }) => (

FormikInputWrapper.propTypes = {
name: PropTypes.string.isRequired,
fieldProps: PropTypes.object.isRequired,
fieldProps: PropTypes.object,
render: PropTypes.func.isRequired,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,18 @@ const ExpressionBuilder = ({
);

const hasInvalidExpression = () =>
!!usedExpressions.filter((expression) => expression.monitor_id === '')?.length;
!!usedExpressions.filter((expression) => expression.monitor_id === '')?.length ||
options.length < usedExpressions.length;

const isValid = () => options.length > 1 && usedExpressions.length > 1 && !hasInvalidExpression();

const validate = () => {
if (options.length < 2) return 'Trigger condition requires at least two associated monitors.';
if (usedExpressions.length < 2)
return 'Trigger condition requires at least two monitors selected.';
if (options.length < usedExpressions.length) {
return 'Trigger condition is using unselected Delegate monitor.';
}
if (hasInvalidExpression()) return 'Invalid expressions.';
};

Expand Down Expand Up @@ -307,7 +311,7 @@ const ExpressionBuilder = ({
<FormikInputWrapper
name={formikFullFieldValue}
fieldProps={{
validate: () => validate(),
validate,
}}
render={({ form }) => (
<FormikFormRow
Expand Down

0 comments on commit 1741371

Please sign in to comment.