import { EuiButton , EuiFlexItem , EuiToolTip } from '@elastic/eui' ; import { i18n } from '@kbn/i18n' ; import React from 'react' ; import { getNextEnvironmentUrlParam } from '../../../../../common/environment_filter_values' ; import { useLegacyUrlParams } from '../../../../context/url_params_context/use_url_params' ; import { Transaction as ITransaction } from '../../../../../typings/es_schemas/ui/transaction' ; import { TransactionDetailLink } from '../../../shared/links/apm/transaction_detail_link' ; import { IWaterfall } from './waterfall_container/waterfall/waterfall_helpers/waterfall_helpers' ; import { Environment } from '../../../../../common/environment_rt' ; export function MaybeViewTraceLink ( { transaction , waterfall , environment , } ) { const { urlParams : { latencyAggregationType , comparisonEnabled , comparisonType } , } = useLegacyUrlParams ( ) ; const viewFullTraceButtonLabel = i18n . translate ( 'xpack.apm.transactionDetails.viewFullTraceButtonLabel' , { defaultMessage : 'View full trace' , } ) ; const { rootTransaction } = waterfall ; if ( ! rootTransaction ) { return ( < EuiFlexItem grow = { false } > < EuiToolTip content = { i18n . translate ( 'xpack.apm.transactionDetails.noTraceParentButtonTooltip' , { defaultMessage : 'The trace parent cannot be found' , } ) } > < EuiButton fill iconType = "apmTrace" disabled = { true } > { viewFullTraceButtonLabel } < /EuiButton> < /EuiToolTip> < /EuiFlexItem>); } const isRoot = transaction . transaction . id === rootTransaction . transaction . id ; if ( isRoot ) { return ( < EuiFlexItem grow = { false } > < EuiToolTip content = { i18n . translate ( 'xpack.apm.transactionDetails.viewingFullTraceButtonTooltip' , { defaultMessage : 'Currently viewing the full trace' , } ) } > < EuiButton fill iconType = "apmTrace" disabled = { true } > { viewFullTraceButtonLabel } < /EuiButton> < /EuiToolTip> < /EuiFlexItem>); } else { const nextEnvironment = getNextEnvironmentUrlParam ( { requestedEnvironment : rootTransaction ?. service . environment , currentEnvironmentUrlParam : environment , } ) ; return ( < EuiFlexItem grow = { false } > < TransactionDetailLink serviceName = { rootTransaction . service . name } transactionId = { rootTransaction . transaction . id } traceId = { rootTransaction . trace . id } transactionName = { rootTransaction . transaction . name } transactionType = { rootTransaction . transaction . type } environment = { nextEnvironment } latencyAggregationType = { latencyAggregationType } comparisonEnabled = { comparisonEnabled } comparisonType = { comparisonType } > < EuiButton fill iconType = "apmTrace" > { viewFullTraceButtonLabel } < /EuiButton> < /TransactionDetailLink> < /EuiFlexItem>); } }