Skip to content

Commit

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

* Fix validation for index threshold when selecting an index

* Ensure timeField gets validation message

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
mikecote and elasticmachine authored Apr 1, 2020
1 parent d78bfba commit 46a605b
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 46a605b

Please sign in to comment.