styles.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. import {Fragment, useMemo} from 'react';
  2. import styled from '@emotion/styled';
  3. import * as qs from 'query-string';
  4. import {Button as CommonButton, LinkButton} from 'sentry/components/button';
  5. import {DataSection} from 'sentry/components/events/styles';
  6. import {t} from 'sentry/locale';
  7. import {space} from 'sentry/styles/space';
  8. import {getDuration} from 'sentry/utils/formatters';
  9. const DetailContainer = styled('div')`
  10. display: flex;
  11. flex-direction: column;
  12. gap: ${space(2)};
  13. padding: ${space(1)};
  14. ${DataSection} {
  15. padding: 0;
  16. }
  17. `;
  18. const FlexBox = styled('div')`
  19. display: flex;
  20. align-items: center;
  21. `;
  22. const Actions = styled(FlexBox)`
  23. gap: ${space(0.5)};
  24. `;
  25. const Title = styled(FlexBox)`
  26. gap: ${space(1)};
  27. flex: none;
  28. `;
  29. const Type = styled('div')`
  30. font-size: ${p => p.theme.fontSizeSmall};
  31. `;
  32. const TitleOp = styled('div')`
  33. font-size: 15px;
  34. font-weight: bold;
  35. max-width: 600px;
  36. ${p => p.theme.overflowEllipsis}
  37. `;
  38. const Table = styled('table')`
  39. margin-bottom: 0 !important;
  40. td {
  41. overflow: hidden;
  42. }
  43. `;
  44. const IconTitleWrapper = styled(FlexBox)`
  45. gap: ${space(1)};
  46. `;
  47. const IconBorder = styled('div')<{backgroundColor: string; errored?: boolean}>`
  48. background-color: ${p => p.backgroundColor};
  49. border-radius: ${p => p.theme.borderRadius};
  50. padding: 0;
  51. display: flex;
  52. align-items: center;
  53. justify-content: center;
  54. width: 30px;
  55. height: 30px;
  56. svg {
  57. fill: ${p => p.theme.white};
  58. width: 14px;
  59. height: 14px;
  60. }
  61. `;
  62. const Button = styled(CommonButton)`
  63. position: absolute;
  64. top: ${space(0.75)};
  65. right: ${space(0.5)};
  66. `;
  67. const HeaderContainer = styled(Title)`
  68. justify-content: space-between;
  69. `;
  70. function EventDetailsLink(props: {eventId: string; projectSlug?: string}) {
  71. const query = useMemo(() => {
  72. return {...qs.parse(location.search), legacy: 1};
  73. }, []);
  74. return (
  75. <LinkButton
  76. disabled={!props.eventId || !props.projectSlug}
  77. title={
  78. !props.eventId || !props.projectSlug
  79. ? t('Event ID or Project Slug missing')
  80. : undefined
  81. }
  82. size="xs"
  83. to={{
  84. pathname: `/performance/${props.projectSlug}:${props.eventId}/`,
  85. query: query,
  86. }}
  87. >
  88. {t('View Event Details')}
  89. </LinkButton>
  90. );
  91. }
  92. const DURATION_COMPARISON_STATUS_COLORS = {
  93. faster: {
  94. light: 'green100',
  95. normal: 'green300',
  96. },
  97. slower: {
  98. light: 'red100',
  99. normal: 'red300',
  100. },
  101. equal: {
  102. light: 'gray100',
  103. normal: 'gray300',
  104. },
  105. };
  106. const MIN_PCT_DURATION_DIFFERENCE = 10;
  107. type DurationProps = {
  108. baseline: number | undefined;
  109. duration: number;
  110. ratio?: number;
  111. };
  112. function Duration(props: DurationProps) {
  113. if (typeof props.duration !== 'number' || Number.isNaN(props.duration)) {
  114. return <DurationContainer>{t('unknown')}</DurationContainer>;
  115. }
  116. if (props.baseline === undefined || props.baseline === 0) {
  117. return <DurationContainer>{getDuration(props.duration, 2, true)}</DurationContainer>;
  118. }
  119. const delta = props.duration - props.baseline;
  120. const deltaPct = Math.round(Math.abs((delta / props.baseline) * 100));
  121. const formattedAvgDuration = getDuration(props.baseline, 2, true);
  122. const status = delta > 0 ? 'slower' : delta < 0 ? 'faster' : 'equal';
  123. const deltaText =
  124. status === 'equal'
  125. ? t(`Equal to avg %s`, `${deltaPct}%`, formattedAvgDuration)
  126. : status === 'faster'
  127. ? t(`%s faster than avg %s`, `${deltaPct}%`, formattedAvgDuration)
  128. : t(`%s slower than avg %s`, `${deltaPct}%`, formattedAvgDuration);
  129. return (
  130. <Fragment>
  131. <DurationContainer>
  132. {getDuration(props.duration, 2, true)}{' '}
  133. {props.ratio ? `(${(props.ratio * 100).toFixed()}%)` : null}
  134. </DurationContainer>
  135. {deltaPct >= MIN_PCT_DURATION_DIFFERENCE ? (
  136. <Comparison status={status}>{deltaText}</Comparison>
  137. ) : null}
  138. </Fragment>
  139. );
  140. }
  141. const DurationContainer = styled('span')`
  142. font-weight: bold;
  143. margin-right: ${space(1)};
  144. `;
  145. const Comparison = styled('span')<{status: 'faster' | 'slower' | 'equal'}>`
  146. color: ${p => p.theme[DURATION_COMPARISON_STATUS_COLORS[p.status].normal]};
  147. `;
  148. const TraceDrawerComponents = {
  149. DetailContainer,
  150. FlexBox,
  151. Title,
  152. Type,
  153. TitleOp,
  154. HeaderContainer,
  155. Actions,
  156. Table,
  157. IconTitleWrapper,
  158. IconBorder,
  159. EventDetailsLink,
  160. Button,
  161. Duration,
  162. };
  163. export {TraceDrawerComponents};