33 * or more contributor license agreements. Licensed under the Elastic License;
44 * you may not use this file except in compliance with the Elastic License.
55 */
6- import { EuiFieldNumber , EuiSelect } from '@elastic/eui' ;
6+ import { EuiFieldNumber , EuiSelect , EuiExpression } from '@elastic/eui' ;
7+ import { useParams } from 'react-router-dom' ;
78import { i18n } from '@kbn/i18n' ;
89import { map } from 'lodash' ;
910import React from 'react' ;
1011import { ForLastExpression } from '../../../../../triggers_actions_ui/public' ;
11- import {
12- ALERT_TYPES_CONFIG ,
13- TRANSACTION_ALERT_AGGREGATION_TYPES ,
14- } from '../../../../common/alert_types' ;
12+ import { ALERT_TYPES_CONFIG } from '../../../../common/alert_types' ;
1513import { useEnvironments } from '../../../hooks/useEnvironments' ;
1614import { useServiceTransactionTypes } from '../../../hooks/useServiceTransactionTypes' ;
1715import { useUrlParams } from '../../../hooks/useUrlParams' ;
@@ -22,7 +20,7 @@ import {
2220 getEnvironmentLabel ,
2321} from '../../../../common/environment_filter_values' ;
2422
25- interface Params {
23+ interface AlertParams {
2624 windowSize : number ;
2725 windowUnit : string ;
2826 threshold : number ;
@@ -32,23 +30,42 @@ interface Params {
3230 environment : string ;
3331}
3432
33+ const TRANSACTION_ALERT_AGGREGATION_TYPES = {
34+ avg : i18n . translate (
35+ 'xpack.apm.transactionDurationAlert.aggregationType.avg' ,
36+ {
37+ defaultMessage : 'Average' ,
38+ }
39+ ) ,
40+ '95th' : i18n . translate (
41+ 'xpack.apm.transactionDurationAlert.aggregationType.95th' ,
42+ {
43+ defaultMessage : '95th percentile' ,
44+ }
45+ ) ,
46+ '99th' : i18n . translate (
47+ 'xpack.apm.transactionDurationAlert.aggregationType.99th' ,
48+ {
49+ defaultMessage : '99th percentile' ,
50+ }
51+ ) ,
52+ } ;
53+
3554interface Props {
36- alertParams : Params ;
55+ alertParams : AlertParams ;
3756 setAlertParams : ( key : string , value : any ) => void ;
3857 setAlertProperty : ( key : string , value : any ) => void ;
3958}
4059
4160export function TransactionDurationAlertTrigger ( props : Props ) {
4261 const { setAlertParams, alertParams, setAlertProperty } = props ;
43- const { serviceName } = alertParams ;
4462 const { urlParams } = useUrlParams ( ) ;
45-
4663 const transactionTypes = useServiceTransactionTypes ( urlParams ) ;
47-
48- const { start, end } = urlParams ;
64+ const { serviceName } = useParams < { serviceName ?: string } > ( ) ;
65+ const { start, end, transactionType } = urlParams ;
4966 const { environmentOptions } = useEnvironments ( { serviceName, start, end } ) ;
5067
51- if ( ! transactionTypes . length ) {
68+ if ( ! transactionTypes . length || ! serviceName ) {
5269 return null ;
5370 }
5471
@@ -57,7 +74,9 @@ export function TransactionDurationAlertTrigger(props: Props) {
5774 aggregationType : 'avg' ,
5875 windowSize : 5 ,
5976 windowUnit : 'm' ,
60- transactionType : transactionTypes [ 0 ] ,
77+
78+ // use the current transaction type or default to the first in the list
79+ transactionType : transactionType || transactionTypes [ 0 ] ,
6180 environment : urlParams . environment || ENVIRONMENT_ALL . value ,
6281 } ;
6382
@@ -67,6 +86,15 @@ export function TransactionDurationAlertTrigger(props: Props) {
6786 } ;
6887
6988 const fields = [
89+ < EuiExpression
90+ description = { i18n . translate (
91+ 'xpack.apm.transactionDurationAnomalyAlertTrigger.service' ,
92+ {
93+ defaultMessage : 'Service' ,
94+ }
95+ ) }
96+ value = { serviceName }
97+ /> ,
7098 < PopoverExpression
7199 value = { getEnvironmentLabel ( params . environment ) }
72100 title = { i18n . translate (
@@ -80,7 +108,10 @@ export function TransactionDurationAlertTrigger(props: Props) {
80108 value = { params . environment }
81109 options = { environmentOptions }
82110 onChange = { ( e ) =>
83- setAlertParams ( 'environment' , e . target . value as Params [ 'environment' ] )
111+ setAlertParams (
112+ 'environment' ,
113+ e . target . value as AlertParams [ 'environment' ]
114+ )
84115 }
85116 compressed
86117 />
@@ -102,7 +133,7 @@ export function TransactionDurationAlertTrigger(props: Props) {
102133 onChange = { ( e ) =>
103134 setAlertParams (
104135 'transactionType' ,
105- e . target . value as Params [ 'transactionType' ]
136+ e . target . value as AlertParams [ 'transactionType' ]
106137 )
107138 }
108139 compressed
@@ -125,7 +156,7 @@ export function TransactionDurationAlertTrigger(props: Props) {
125156 onChange = { ( e ) =>
126157 setAlertParams (
127158 'aggregationType' ,
128- e . target . value as Params [ 'aggregationType' ]
159+ e . target . value as AlertParams [ 'aggregationType' ]
129160 )
130161 }
131162 compressed
0 commit comments