diff --git a/x-pack/plugins/infra/public/alerting/log_threshold/components/expression_editor/criterion.tsx b/x-pack/plugins/infra/public/alerting/log_threshold/components/expression_editor/criterion.tsx index 969845ada1be..47ba580c272b 100644 --- a/x-pack/plugins/infra/public/alerting/log_threshold/components/expression_editor/criterion.tsx +++ b/x-pack/plugins/infra/public/alerting/log_threshold/components/expression_editor/criterion.tsx @@ -17,6 +17,7 @@ import { EuiFieldText, EuiButtonIcon, EuiFormRow, + EuiComboBox, } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { isNumber, isFinite } from 'lodash'; @@ -112,7 +113,7 @@ export const Criterion: React.FC = ({ const fieldOptions = useMemo(() => { return fields.map((field) => { - return { value: field.name, text: field.name }; + return { label: field.name }; }); }, [fields]); @@ -129,8 +130,14 @@ export const Criterion: React.FC = ({ }, [fieldInfo]); const handleFieldChange = useCallback( - (e) => { - const fieldName = e.target.value; + ([selectedOption]) => { + if (!selectedOption) { + updateCriterion(idx, { field: '' }); + return; + } + + const fieldName = selectedOption.label; + const nextFieldInfo = getFieldInfo(fields, fieldName); // If the field information we're dealing with has changed, reset the comparator and value. if ( @@ -146,10 +153,14 @@ export const Criterion: React.FC = ({ } else { updateCriterion(idx, { field: fieldName }); } + + setIsFieldPopoverOpen(false); }, [fieldInfo, fields, idx, updateCriterion] ); + const selectedField = criterion.field ? [{ label: criterion.field }] : []; + return ( @@ -181,13 +192,19 @@ export const Criterion: React.FC = ({ >
{criterionFieldTitle} - 0} error={errors.field}> - 0} + error={errors.field} + > +