44 * you may not use this file except in compliance with the Elastic License.
55 */
66import { EuiSelect } from '@elastic/eui' ;
7+ import { useParams } from 'react-router-dom' ;
78import { i18n } from '@kbn/i18n' ;
89import { map } from 'lodash' ;
910import React from 'react' ;
10- import { useParams } from 'react-router-dom' ;
11- import { useFetcher } from '../../../../../observability/public' ;
1211import { ForLastExpression } from '../../../../../triggers_actions_ui/public' ;
1312import { ALERT_TYPES_CONFIG } from '../../../../common/alert_types' ;
14- import { ENVIRONMENT_ALL } from '../../../../common/environment_filter_values' ;
15- import { TimeSeries } from '../../../../typings/timeseries' ;
16- import { useApmServiceContext } from '../../../context/apm_service/use_apm_service_context' ;
17- import { useUrlParams } from '../../../context/url_params_context/use_url_params' ;
1813import { useEnvironmentsFetcher } from '../../../hooks/use_environments_fetcher' ;
19- import { callApmApi } from '../../../services/rest/createCallApmApi ' ;
20- import { getResponseTimeTickFormatter } from '../../shared/charts/transaction_charts/helper ' ;
21- import { useFormatter } from '../../shared/charts/transaction_charts/use_formatter ' ;
22- import { ChartPreview } from '../chart_preview ' ;
14+ import { useUrlParams } from '../../../context/url_params_context/use_url_params ' ;
15+ import { ServiceAlertTrigger } from '../ServiceAlertTrigger ' ;
16+ import { PopoverExpression } from '../ServiceAlertTrigger/PopoverExpression ' ;
17+ import { ENVIRONMENT_ALL } from '../../../../common/environment_filter_values ' ;
2318import {
2419 EnvironmentField ,
25- IsAboveField ,
2620 ServiceField ,
2721 TransactionTypeField ,
22+ IsAboveField ,
2823} from '../fields' ;
29- import { getAbsoluteTimeRange } from '../helper' ;
30- import { ServiceAlertTrigger } from '../service_alert_trigger' ;
31- import { PopoverExpression } from '../service_alert_trigger/popover_expression' ;
24+ import { useApmServiceContext } from '../../../context/apm_service/use_apm_service_context' ;
3225
3326interface AlertParams {
3427 windowSize : number ;
@@ -70,58 +63,14 @@ interface Props {
7063export function TransactionDurationAlertTrigger ( props : Props ) {
7164 const { setAlertParams, alertParams, setAlertProperty } = props ;
7265 const { urlParams } = useUrlParams ( ) ;
73- const { transactionTypes, transactionType } = useApmServiceContext ( ) ;
66+ const { transactionTypes } = useApmServiceContext ( ) ;
7467 const { serviceName } = useParams < { serviceName ?: string } > ( ) ;
75- const { start, end } = urlParams ;
68+ const { start, end, transactionType } = urlParams ;
7669 const { environmentOptions } = useEnvironmentsFetcher ( {
7770 serviceName,
7871 start,
7972 end,
8073 } ) ;
81- const {
82- aggregationType,
83- environment,
84- threshold,
85- windowSize,
86- windowUnit,
87- } = alertParams ;
88-
89- const { data } = useFetcher ( ( ) => {
90- if ( windowSize && windowUnit ) {
91- return callApmApi ( {
92- endpoint : 'GET /api/apm/alerts/chart_preview/transaction_duration' ,
93- params : {
94- query : {
95- ...getAbsoluteTimeRange ( windowSize , windowUnit ) ,
96- aggregationType,
97- environment,
98- serviceName,
99- transactionType : alertParams . transactionType ,
100- } ,
101- } ,
102- } ) ;
103- }
104- } , [
105- aggregationType ,
106- environment ,
107- serviceName ,
108- alertParams . transactionType ,
109- windowSize ,
110- windowUnit ,
111- ] ) ;
112-
113- const { formatter } = useFormatter ( [ { data : data ?? [ ] } as TimeSeries ] ) ;
114- const yTickFormat = getResponseTimeTickFormatter ( formatter ) ;
115- // The threshold from the form is in ms. Convert to µs.
116- const thresholdMs = threshold * 1000 ;
117-
118- const chartPreview = (
119- < ChartPreview
120- data = { data }
121- threshold = { thresholdMs }
122- yTickFormat = { yTickFormat }
123- />
124- ) ;
12574
12675 if ( ! transactionTypes . length || ! serviceName ) {
12776 return null ;
@@ -132,7 +81,9 @@ export function TransactionDurationAlertTrigger(props: Props) {
13281 aggregationType : 'avg' ,
13382 windowSize : 5 ,
13483 windowUnit : 'm' ,
135- transactionType,
84+
85+ // use the current transaction type or default to the first in the list
86+ transactionType : transactionType || transactionTypes [ 0 ] ,
13687 environment : urlParams . environment || ENVIRONMENT_ALL . value ,
13788 } ;
13889
@@ -176,7 +127,7 @@ export function TransactionDurationAlertTrigger(props: Props) {
176127 unit = { i18n . translate ( 'xpack.apm.transactionDurationAlertTrigger.ms' , {
177128 defaultMessage : 'ms' ,
178129 } ) }
179- onChange = { ( value ) => setAlertParams ( 'threshold' , value || 0 ) }
130+ onChange = { ( value ) => setAlertParams ( 'threshold' , value ) }
180131 /> ,
181132 < ForLastExpression
182133 onChangeWindowSize = { ( timeWindowSize ) =>
@@ -197,9 +148,8 @@ export function TransactionDurationAlertTrigger(props: Props) {
197148 return (
198149 < ServiceAlertTrigger
199150 alertTypeName = { ALERT_TYPES_CONFIG [ 'apm.transaction_duration' ] . name }
200- chartPreview = { chartPreview }
201- defaults = { defaults }
202151 fields = { fields }
152+ defaults = { defaults }
203153 setAlertParams = { setAlertParams }
204154 setAlertProperty = { setAlertProperty }
205155 />
0 commit comments