Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Signed-off-by: Jovan Cvetkovic <[email protected]>
  • Loading branch information
jovancvetkovic3006 committed Jun 22, 2023
1 parent 64aca92 commit f989735
Showing 1 changed file with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React, { useEffect, useState, useCallback } from 'react';
import {
EuiFlexItem,
EuiFlexGroup,
Expand Down Expand Up @@ -121,16 +121,19 @@ const ExpressionQuery = ({
form.setFieldTouched(`expressionQueries_${idx}`, true);
};

const onRemoveExpression = (idx) => {
const expressions = _.cloneDeep(usedExpressions);
expressions.splice(idx, 1);
expressions.length && (expressions[0].description = '');
const onRemoveExpression = useCallback(
(idx) => {
const expressions = _.cloneDeep(usedExpressions);
expressions.splice(idx, 1);
expressions.length && (expressions[0].description = '');

if (!expressions?.length) {
expressions.push(DEFAULT_EXPRESSION);
}
setUsedExpressions([...expressions]);
};
if (!expressions?.length) {
expressions.push(DEFAULT_EXPRESSION);
}
setUsedExpressions([...expressions]);
},
[usedExpressions]
);

const hasInvalidExpression = () => {
return !!usedExpressions.filter((expression) => expression.monitor_id === '')?.length;
Expand Down Expand Up @@ -214,7 +217,7 @@ const ExpressionQuery = ({
fieldProps={{
validate: () => graphUi && validate(),
}}
render={({ field, form }) => (
render={({ form }) => (
<FormikFormRow
name={'expressionQueries'}
form={form}
Expand Down Expand Up @@ -248,7 +251,7 @@ const ExpressionQuery = ({
description={expression.description}
value={expression.monitor_name}
isActive={!!selections?.length}
onClick={(e) => openPopover(idx)}
onClick={() => openPopover(idx)}
/>
}
isOpen={expression.isOpen}
Expand Down

0 comments on commit f989735

Please sign in to comment.