import { format } from 'url' ; import { Transaction } from '../../../../typings/es_schemas/ui/transaction' ; export const getRedirectToTransactionDetailPageUrl = ( { transaction , rangeFrom , rangeTo , } ) => { return format ( { pathname : `/services/${ transaction . service . name }/transactions/view` , query : { traceId : transaction . trace . id , transactionId : transaction . transaction . id , transactionName : transaction . transaction . name , transactionType : transaction . transaction . type , rangeFrom : rangeFrom || roundToNearestMinute ( { timestamp : transaction [ '@timestamp' ] , direction : 'down' , } ) , rangeTo : rangeTo || roundToNearestMinute ( { timestamp : transaction [ '@timestamp' ] , diff : transaction . transaction . duration . us / 1000 , direction : 'up' , } ) , } , } ) ; } ; function roundToNearestMinute ( { timestamp , diff = 0 , direction = 'up' , } ) { const date = new Date ( timestamp ) ; const fiveMinutes = 1000 * 60 * 5 ; const ms = date . getTime ( ) + diff ; return new Date ( direction === 'down' ? Math . floor ( ms / fiveMinutes ) * fiveMinutes : Math . ceil ( ms / fiveMinutes ) * fiveMinutes ) . toISOString ( ) ; }