Skip to content

Commit

Permalink
Fix validation for index threshold when selecting an index (elastic#6…
Browse files Browse the repository at this point in the history
…1615)

* Fix validation for index threshold when selecting an index

* Ensure timeField gets validation message

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
mikecote and elasticmachine committed Apr 1, 2020
1 parent 9d6d320 commit c25f30c
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ export const IndexThresholdAlertTypeExpression: React.FunctionComponent<IndexThr
}
};

const closeIndexPopover = () => {
setIndexPopoverOpen(false);
if (timeField === undefined) {
setAlertParams('timeField', '');
}
};

useEffect(() => {
const indexPatternsFunction = async () => {
setIndexPatterns(await getIndexPatterns());
Expand Down Expand Up @@ -293,18 +300,16 @@ export const IndexThresholdAlertTypeExpression: React.FunctionComponent<IndexThr
defaultMessage: 'index',
}
)}
value={index ? index.join(' ') : firstFieldOption.text}
value={index && index.length > 0 ? index.join(' ') : firstFieldOption.text}
isActive={indexPopoverOpen}
onClick={() => {
setIndexPopoverOpen(true);
}}
color={index ? 'secondary' : 'danger'}
color={index && index.length > 0 && timeField !== '' ? 'secondary' : 'danger'}
/>
}
isOpen={indexPopoverOpen}
closePopover={() => {
setIndexPopoverOpen(false);
}}
closePopover={closeIndexPopover}
ownFocus
withTitle
anchorPosition="downLeft"
Expand All @@ -331,9 +336,7 @@ export const IndexThresholdAlertTypeExpression: React.FunctionComponent<IndexThr
defaultMessage: 'Close',
}
)}
onClick={() => {
setIndexPopoverOpen(false);
}}
onClick={closeIndexPopover}
/>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down

0 comments on commit c25f30c

Please sign in to comment.