From 73254e1f1114b2646ab7210386ae8337c9bbbdbc Mon Sep 17 00:00:00 2001 From: Phillip Burch Date: Tue, 14 Apr 2020 14:11:40 -0500 Subject: [PATCH 1/3] Disable adding conditions when in alert manament context. --- .../alerting/metrics/expression.tsx | 179 ++++++++++++------ 1 file changed, 117 insertions(+), 62 deletions(-) diff --git a/x-pack/plugins/infra/public/components/alerting/metrics/expression.tsx b/x-pack/plugins/infra/public/components/alerting/metrics/expression.tsx index 2e43ede2480ce5..2784b777c1d719 100644 --- a/x-pack/plugins/infra/public/components/alerting/metrics/expression.tsx +++ b/x-pack/plugins/infra/public/components/alerting/metrics/expression.tsx @@ -17,6 +17,9 @@ import { import { IFieldType } from 'src/plugins/data/public'; import { FormattedMessage } from '@kbn/i18n/react'; import { i18n } from '@kbn/i18n'; +import { EuiExpression } from '@elastic/eui'; +import { EuiCallOut } from '@elastic/eui'; +import { EuiLink } from '@elastic/eui'; import { MetricExpressionParams, Comparator, @@ -208,6 +211,37 @@ export const Expressions: React.FC = props => { } }, [alertsContext.metadata, defaultExpression, source]); // eslint-disable-line react-hooks/exhaustive-deps + // INFO: If there is metadata, you're in the metrics explorer context + const canAddConditions = !!alertsContext.metadata; + + if (!canAddConditions && !alertParams.criteria) { + return ( + <> + + + {' '} + + + + . + + } + color="warning" + iconType="help" + /> + + + ); + } + return ( <> @@ -224,6 +258,7 @@ export const Expressions: React.FC = props => { alertParams.criteria.map((e, idx) => { return ( 1} fields={derivedIndexPattern.fields} remove={removeExpression} @@ -246,61 +281,64 @@ export const Expressions: React.FC = props => { />
- - - + {canAddConditions && ( + + + + )}
- - - - - - - {alertsContext.metadata && ( - - - + <> + + + + + + + + + + )} ); @@ -308,6 +346,7 @@ export const Expressions: React.FC = props => { interface ExpressionRowProps { fields: IFieldType[]; + canEditAggField: boolean; expressionId: number; expression: MetricExpression; errors: IErrorObject; @@ -378,17 +417,20 @@ export const ExpressionRow: React.FC = props => { {aggType !== 'count' && ( - ({ - normalizedType: f.type, - name: f.name, - }))} - aggType={aggType} - errors={errors} - onChangeSelectedAggField={updateMetric} - /> + {!props.canEditAggField && } + {props.canEditAggField && ( + ({ + normalizedType: f.type, + name: f.name, + }))} + aggType={aggType} + errors={errors} + onChangeSelectedAggField={updateMetric} + /> + )} )} @@ -420,6 +462,19 @@ export const ExpressionRow: React.FC = props => { ); }; +export const DiasabledAggField = ({ text }: { text: string }) => { + return ( + + ); +}; + export const aggregationType: { [key: string]: any } = { avg: { text: i18n.translate('xpack.infra.metrics.alertFlyout.aggregationText.avg', { From d2a8912ef6a135df28a69f2bf206542883ee0fbc Mon Sep 17 00:00:00 2001 From: Phillip Burch Date: Tue, 14 Apr 2020 14:15:54 -0500 Subject: [PATCH 2/3] Fix typo --- .../infra/public/components/alerting/metrics/expression.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/infra/public/components/alerting/metrics/expression.tsx b/x-pack/plugins/infra/public/components/alerting/metrics/expression.tsx index 2784b777c1d719..29c5fba3342855 100644 --- a/x-pack/plugins/infra/public/components/alerting/metrics/expression.tsx +++ b/x-pack/plugins/infra/public/components/alerting/metrics/expression.tsx @@ -417,7 +417,7 @@ export const ExpressionRow: React.FC = props => { {aggType !== 'count' && ( - {!props.canEditAggField && } + {!props.canEditAggField && } {props.canEditAggField && ( = props => { ); }; -export const DiasabledAggField = ({ text }: { text: string }) => { +export const DisabledAggField = ({ text }: { text: string }) => { return ( Date: Tue, 14 Apr 2020 16:15:38 -0500 Subject: [PATCH 3/3] Change id for i18n string --- .../infra/public/components/alerting/metrics/expression.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/infra/public/components/alerting/metrics/expression.tsx b/x-pack/plugins/infra/public/components/alerting/metrics/expression.tsx index 22b42eba5e22a3..6cf4e5bed2e6f9 100644 --- a/x-pack/plugins/infra/public/components/alerting/metrics/expression.tsx +++ b/x-pack/plugins/infra/public/components/alerting/metrics/expression.tsx @@ -466,7 +466,7 @@ export const ExpressionRow: React.FC = props => { export const DisabledAggField = ({ text }: { text: string }) => { return (