Skip to content

Commit

Permalink
[Composite monitor] Fixed condition selection of first expression in …
Browse files Browse the repository at this point in the history
…visual editor (#622)

* fixed expression builder

Signed-off-by: Amardeepsingh Siglani <[email protected]>

* fixed chained alerts api call

Signed-off-by: Amardeepsingh Siglani <[email protected]>

* revert api change

Signed-off-by: Amardeepsingh Siglani <[email protected]>

---------

Signed-off-by: Amardeepsingh Siglani <[email protected]>
  • Loading branch information
amsiglan authored Jul 12, 2023
1 parent bca0a0a commit 4a9ecd4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ export const conditionToExpressions = (condition = '', monitors) => {
'||': 'OR',
'!': 'NOT',
'': '',
'&& !': 'AND_NOT',
'|| !': 'OR_NOT',
'&& !': 'AND NOT',
'|| !': 'OR NOT',
};
const queryToExpressionRegex = new RegExp(
/( && || \|\| || && \!|| \|\| \!)?(monitor\[id=(.*?)\])/,
/(!|| && || \|\| || && \!|| \|\| \!)?(monitor\[id=(.*?)\])/,
'gm'
);
const matcher = condition.matchAll(queryToExpressionRegex);
Expand Down Expand Up @@ -74,12 +74,15 @@ const ExpressionBuilder = ({
...DEFAULT_EXPRESSION,
description: DEFAULT_CONDITION,
};
const FIRST_EXPRESSION_CONDITIONS_MAP = [{ description: 'NOT', label: 'NOT' }];
const FIRST_EXPRESSION_CONDITIONS_MAP = [
{ description: '', label: '' },
{ description: 'NOT', label: 'NOT' },
];
const EXPRESSION_CONDITIONS_MAP = [
{ description: 'AND', label: 'AND' },
{ description: 'OR', label: 'OR' },
{ description: 'AND_NOT', label: 'AND NOT' },
{ description: 'OR_NOT', label: 'OR NOT' },
{ description: 'AND NOT', label: 'AND NOT' },
{ description: 'OR NOT', label: 'OR NOT' },
];

const [usedExpressions, setUsedExpressions] = useState([DEFAULT_EXPRESSION]);
Expand Down Expand Up @@ -144,8 +147,8 @@ const ExpressionBuilder = ({
OR: '|| ',
NOT: '!',
'': '',
AND_NOT: '&& !',
OR_NOT: '|| !',
'AND NOT': '&& !',
'OR NOT': '|| !',
};

const condition = expressions.reduce((query, expression) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import PropTypes from 'prop-types';
import _ from 'lodash';
import { EuiSpacer, EuiText, EuiTitle, EuiAccordion, EuiButton } from '@elastic/eui';
import { FormikFieldText, FormikSelect } from '../../../../components/FormControls';
import { hasError, isInvalid } from '../../../../utils/validate';
import { hasError, isInvalid, required } from '../../../../utils/validate';
import { DEFAULT_TRIGGER_NAME, SEVERITY_OPTIONS } from '../../utils/constants';
import CompositeTriggerCondition from '../../components/CompositeTriggerCondition/CompositeTriggerCondition';
import TriggerNotifications from './TriggerNotifications';
Expand Down Expand Up @@ -110,7 +110,9 @@ class DefineCompositeLevelTrigger extends Component {

<FormikFieldText
name={`${formikFieldPath}name`}
fieldProps={{}}
fieldProps={{
validate: required,
}}
formRow
rowProps={{
...defaultRowProps,
Expand Down

0 comments on commit 4a9ecd4

Please sign in to comment.