Skip to content

Commit 7fee7f1

Browse files
Fix validation for index threshold when selecting an index (#61615) (#62148)
* Fix validation for index threshold when selecting an index * Ensure timeField gets validation message Co-authored-by: Elastic Machine <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
1 parent 3ae71d1 commit 7fee7f1

File tree

1 file changed

+11
-8
lines changed
  • x-pack/plugins/triggers_actions_ui/public/application/components/builtin_alert_types/threshold

1 file changed

+11
-8
lines changed

x-pack/plugins/triggers_actions_ui/public/application/components/builtin_alert_types/threshold/expression.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,13 @@ export const IndexThresholdAlertTypeExpression: React.FunctionComponent<IndexThr
145145
}
146146
};
147147

148+
const closeIndexPopover = () => {
149+
setIndexPopoverOpen(false);
150+
if (timeField === undefined) {
151+
setAlertParams('timeField', '');
152+
}
153+
};
154+
148155
useEffect(() => {
149156
const indexPatternsFunction = async () => {
150157
setIndexPatterns(await getIndexPatterns());
@@ -293,18 +300,16 @@ export const IndexThresholdAlertTypeExpression: React.FunctionComponent<IndexThr
293300
defaultMessage: 'index',
294301
}
295302
)}
296-
value={index ? index.join(' ') : firstFieldOption.text}
303+
value={index && index.length > 0 ? index.join(' ') : firstFieldOption.text}
297304
isActive={indexPopoverOpen}
298305
onClick={() => {
299306
setIndexPopoverOpen(true);
300307
}}
301-
color={index ? 'secondary' : 'danger'}
308+
color={index && index.length > 0 && timeField !== '' ? 'secondary' : 'danger'}
302309
/>
303310
}
304311
isOpen={indexPopoverOpen}
305-
closePopover={() => {
306-
setIndexPopoverOpen(false);
307-
}}
312+
closePopover={closeIndexPopover}
308313
ownFocus
309314
withTitle
310315
anchorPosition="downLeft"
@@ -331,9 +336,7 @@ export const IndexThresholdAlertTypeExpression: React.FunctionComponent<IndexThr
331336
defaultMessage: 'Close',
332337
}
333338
)}
334-
onClick={() => {
335-
setIndexPopoverOpen(false);
336-
}}
339+
onClick={closeIndexPopover}
337340
/>
338341
</EuiFlexItem>
339342
</EuiFlexGroup>

0 commit comments

Comments
 (0)