diff --git a/x-pack/plugins/stack_alerts/public/rule_types/components/source_fields_select.tsx b/x-pack/plugins/stack_alerts/public/rule_types/components/source_fields_select.tsx index 3cd34a3cd0015..79b2e6ca4ed16 100644 --- a/x-pack/plugins/stack_alerts/public/rule_types/components/source_fields_select.tsx +++ b/x-pack/plugins/stack_alerts/public/rule_types/components/source_fields_select.tsx @@ -7,7 +7,7 @@ import React, { useEffect, useState } from 'react'; import { uniqBy } from 'lodash'; -import { EuiComboBox, EuiFormRow, EuiSpacer, EuiTitle } from '@elastic/eui'; +import { EuiComboBox, EuiFormRow } from '@elastic/eui'; import { FieldOption } from '@kbn/triggers-actions-ui-plugin/public/common'; import { IErrorObject } from '@kbn/triggers-actions-ui-plugin/public'; import { FormattedMessage } from '@kbn/i18n-react'; @@ -77,44 +77,39 @@ export const SourceFields: React.FC = ({ fullWidth isInvalid={errors.length > 0 && sourceFields !== undefined} error={errors} + label={ + + } > - <> - -
- -
-
- - 0 && sourceFields !== undefined} + selectedOptions={(sourceFields || []).map((f) => ({ + label: f.label, + value: f.searchPath, + 'data-test-subj': `option-${f.label}`, + }))} + onChange={(options) => { + const fields: SourceField[] = []; + options.forEach((f) => { + if (f.value) { + fields.push({ label: f.label, searchPath: f.value }); } - )} - data-test-subj="sourceFields" - isInvalid={errors.length > 0 && sourceFields !== undefined} - selectedOptions={(sourceFields || []).map((f) => ({ - label: f.label, - value: f.searchPath, - 'data-test-subj': `option-${f.label}`, - }))} - onChange={(options) => { - const fields: SourceField[] = []; - options.forEach((f) => { - if (f.value) { - fields.push({ label: f.label, searchPath: f.value }); - } - }); - onChangeSourceFields(fields); - }} - options={sourceFieldsOptions} - /> - + }); + onChangeSourceFields(fields); + }} + options={sourceFieldsOptions} + /> ) : null; }; diff --git a/x-pack/plugins/stack_alerts/public/rule_types/es_query/expression/es_query_expression.tsx b/x-pack/plugins/stack_alerts/public/rule_types/es_query/expression/es_query_expression.tsx index 1cf901ecae8f9..66a1ca82feff5 100644 --- a/x-pack/plugins/stack_alerts/public/rule_types/es_query/expression/es_query_expression.tsx +++ b/x-pack/plugins/stack_alerts/public/rule_types/es_query/expression/es_query_expression.tsx @@ -11,7 +11,7 @@ import { lastValueFrom } from 'rxjs'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n-react'; -import { EuiFormRow, EuiLink, EuiSpacer, EuiTitle } from '@elastic/eui'; +import { EuiFormRow, EuiLink, EuiSpacer } from '@elastic/eui'; import { XJson } from '@kbn/es-ui-shared-plugin/public'; import { CodeEditor } from '@kbn/kibana-react-plugin/public'; @@ -195,60 +195,49 @@ export const EsQueryExpression: React.FC< return ( - -
+ -
-
- - - - { - setParam('index', indices); - - // reset expression fields if indices are deleted - if (indices.length === 0) { - setRuleProperty('params', { - timeField: ruleParams.timeField, - index: indices, - esQuery: DEFAULT_VALUES.QUERY, - size: DEFAULT_VALUES.SIZE, - thresholdComparator: DEFAULT_VALUES.THRESHOLD_COMPARATOR, - timeWindowSize: DEFAULT_VALUES.TIME_WINDOW_SIZE, - timeWindowUnit: DEFAULT_VALUES.TIME_WINDOW_UNIT, - threshold: DEFAULT_VALUES.THRESHOLD, - aggType: DEFAULT_VALUES.AGGREGATION_TYPE, - groupBy: DEFAULT_VALUES.GROUP_BY, - termSize: DEFAULT_VALUES.TERM_SIZE, - searchType: SearchType.esQuery, - excludeHitsFromPreviousRun: DEFAULT_VALUES.EXCLUDE_PREVIOUS_HITS, - sourceFields: undefined, - }); - } else { - await refreshEsFields(indices); - } - }} - onTimeFieldChange={(updatedTimeField: string) => setParam('timeField', updatedTimeField)} - /> - + } + > + { + setParam('index', indices); - -
- -
-
+ // reset expression fields if indices are deleted + if (indices.length === 0) { + setRuleProperty('params', { + timeField: ruleParams.timeField, + index: indices, + esQuery: DEFAULT_VALUES.QUERY, + size: DEFAULT_VALUES.SIZE, + thresholdComparator: DEFAULT_VALUES.THRESHOLD_COMPARATOR, + timeWindowSize: DEFAULT_VALUES.TIME_WINDOW_SIZE, + timeWindowUnit: DEFAULT_VALUES.TIME_WINDOW_UNIT, + threshold: DEFAULT_VALUES.THRESHOLD, + aggType: DEFAULT_VALUES.AGGREGATION_TYPE, + groupBy: DEFAULT_VALUES.GROUP_BY, + termSize: DEFAULT_VALUES.TERM_SIZE, + searchType: SearchType.esQuery, + excludeHitsFromPreviousRun: DEFAULT_VALUES.EXCLUDE_PREVIOUS_HITS, + sourceFields: undefined, + }); + } else { + await refreshEsFields(indices); + } + }} + onTimeFieldChange={(updatedTimeField: string) => setParam('timeField', updatedTimeField)} + /> + } + label={ + + } > - -
+ -
-
- - + } + > { @@ -215,20 +215,17 @@ export const EsqlQueryExpression: React.FC< errors={errors.sourceFields} /> - -
- -
-
- 0 && timeField !== undefined} error={errors.timeField} + label={ + + } > - -
- -
-
- - + 0} error={errors.timeWindowSize} + label={ + + } > - -
+ -
-
- - + } + > + +
{Boolean(dataView?.id) && ( <> diff --git a/x-pack/plugins/stack_alerts/public/rule_types/es_query/rule_common_expressions/rule_common_expressions.tsx b/x-pack/plugins/stack_alerts/public/rule_types/es_query/rule_common_expressions/rule_common_expressions.tsx index 313d3f586c73e..c356104ed831f 100644 --- a/x-pack/plugins/stack_alerts/public/rule_types/es_query/rule_common_expressions/rule_common_expressions.tsx +++ b/x-pack/plugins/stack_alerts/public/rule_types/es_query/rule_common_expressions/rule_common_expressions.tsx @@ -7,15 +7,7 @@ import React, { useEffect, useState } from 'react'; import { FormattedMessage } from '@kbn/i18n-react'; -import { - EuiCheckbox, - EuiFlexGroup, - EuiFlexItem, - EuiFormRow, - EuiIconTip, - EuiSpacer, - EuiTitle, -} from '@elastic/eui'; +import { EuiCheckbox, EuiFormRow, EuiIconTip, EuiSpacer } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { builtInAggregationTypes, @@ -98,22 +90,23 @@ export const RuleCommonExpressions: React.FC = ({ }, [groupBy]); return ( <> - -

+ {' '} - -

-
- - + />, + , + ]} + > + +
{aggType && builtInAggregationTypes[aggType].fieldRequired ? ( = ({ onChangeWindowUnit={onChangeWindowUnit} /> - - - -
- -
-
-
- + , = ({ defaultMessage: 'Specify the number of documents to pass to the configured actions when the threshold condition is met.', })} - /> - -
- - + />, + ]} + > + +
) : null} - -
+ -
-
- - { - setRuleParams('index', indices); + } + > + { + setRuleParams('index', indices); - // reset expression fields if indices are deleted - if (indices.length === 0) { - setRuleProperty('params', { - ...ruleParams, - index: indices, - aggType: DEFAULT_VALUES.AGGREGATION_TYPE, - termSize: DEFAULT_VALUES.TERM_SIZE, - thresholdComparator: DEFAULT_VALUES.THRESHOLD_COMPARATOR, - timeWindowSize: DEFAULT_VALUES.TIME_WINDOW_SIZE, - timeWindowUnit: DEFAULT_VALUES.TIME_WINDOW_UNIT, - groupBy: DEFAULT_VALUES.GROUP_BY, - threshold: DEFAULT_VALUES.THRESHOLD, - timeField: '', - }); - } else { - await refreshEsFields(indices); + // reset expression fields if indices are deleted + if (indices.length === 0) { + setRuleProperty('params', { + ...ruleParams, + index: indices, + aggType: DEFAULT_VALUES.AGGREGATION_TYPE, + termSize: DEFAULT_VALUES.TERM_SIZE, + thresholdComparator: DEFAULT_VALUES.THRESHOLD_COMPARATOR, + timeWindowSize: DEFAULT_VALUES.TIME_WINDOW_SIZE, + timeWindowUnit: DEFAULT_VALUES.TIME_WINDOW_UNIT, + groupBy: DEFAULT_VALUES.GROUP_BY, + threshold: DEFAULT_VALUES.THRESHOLD, + timeField: '', + }); + } else { + await refreshEsFields(indices); + } + }} + onTimeFieldChange={(updatedTimeField: string) => + setRuleParams('timeField', updatedTimeField) } - }} - onTimeFieldChange={(updatedTimeField: string) => - setRuleParams('timeField', updatedTimeField) - } - /> + /> + - -
+ -
-
- - - setRuleParams('aggType', selectedAggType) } - /> + > + + setRuleParams('aggType', selectedAggType) + } + /> + {aggType && builtInAggregationTypes[aggType].fieldRequired ? (