eventToolbar.tsx 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. import {Component} from 'react';
  2. import styled from '@emotion/styled';
  3. import {Location} from 'history';
  4. import moment from 'moment-timezone';
  5. import {Button} from 'sentry/components/button';
  6. import DateTime from 'sentry/components/dateTime';
  7. import {DataSection} from 'sentry/components/events/styles';
  8. import FileSize from 'sentry/components/fileSize';
  9. import GlobalAppStoreConnectUpdateAlert from 'sentry/components/globalAppStoreConnectUpdateAlert';
  10. import ExternalLink from 'sentry/components/links/externalLink';
  11. import Link from 'sentry/components/links/link';
  12. import NavigationButtonGroup from 'sentry/components/navigationButtonGroup';
  13. import {Tooltip} from 'sentry/components/tooltip';
  14. import {IconPlay, IconWarning} from 'sentry/icons';
  15. import {t} from 'sentry/locale';
  16. import {space} from 'sentry/styles/space';
  17. import {Group, Organization, Project} from 'sentry/types';
  18. import {Event} from 'sentry/types/event';
  19. import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
  20. import {shouldUse24Hours} from 'sentry/utils/dates';
  21. import getDynamicText from 'sentry/utils/getDynamicText';
  22. import {TraceLink} from 'sentry/views/issueDetails/quickTrace/traceLink';
  23. import EventCreatedTooltip from './eventCreatedTooltip';
  24. import QuickTrace from './quickTrace';
  25. type Props = {
  26. event: Event;
  27. group: Group;
  28. location: Location;
  29. organization: Organization;
  30. project: Project;
  31. hasReplay?: boolean;
  32. };
  33. class GroupEventToolbar extends Component<Props> {
  34. shouldComponentUpdate(nextProps: Props) {
  35. return this.props.event.id !== nextProps.event.id;
  36. }
  37. handleNavigationClick(button: string) {
  38. trackAdvancedAnalyticsEvent('issue_details.event_navigation_clicked', {
  39. organization: this.props.organization,
  40. project_id: parseInt(this.props.project.id, 10),
  41. button,
  42. });
  43. }
  44. render() {
  45. const is24Hours = shouldUse24Hours();
  46. const evt = this.props.event;
  47. const {group, organization, location, project, hasReplay} = this.props;
  48. const groupId = group.id;
  49. const isReplayEnabled = organization.features.includes('session-replay-ui');
  50. const baseEventsPath = `/organizations/${organization.slug}/issues/${groupId}/events/`;
  51. // TODO: possible to define this as a route in react-router, but without a corresponding
  52. // React component?
  53. const jsonUrl = `/organizations/${organization.slug}/issues/${groupId}/events/${evt.id}/json/`;
  54. const latencyThreshold = 30 * 60 * 1000; // 30 minutes
  55. const isOverLatencyThreshold =
  56. evt.dateReceived &&
  57. Math.abs(+moment(evt.dateReceived) - +moment(evt.dateCreated)) > latencyThreshold;
  58. return (
  59. <Wrapper>
  60. <HeadingAndNavWrapper>
  61. <div>
  62. <Heading>
  63. {t('Event ID')}{' '}
  64. <EventIdLink to={`${baseEventsPath}${evt.id}/`}>{evt.eventID}</EventIdLink>
  65. <LinkContainer>
  66. <ExternalLink
  67. href={jsonUrl}
  68. onClick={() =>
  69. trackAdvancedAnalyticsEvent('issue_details.event_json_clicked', {
  70. organization,
  71. group_id: parseInt(`${evt.groupID}`, 10),
  72. })
  73. }
  74. >
  75. {'JSON'} (<FileSize bytes={evt.size} />)
  76. </ExternalLink>
  77. </LinkContainer>
  78. </Heading>
  79. <Tooltip
  80. title={<EventCreatedTooltip event={evt} />}
  81. showUnderline
  82. disableForVisualTest
  83. >
  84. <StyledDateTime
  85. format={is24Hours ? 'MMM D, YYYY HH:mm:ss zz' : 'll LTS z'}
  86. date={getDynamicText({
  87. value: evt.dateCreated,
  88. fixed: 'Dummy timestamp',
  89. })}
  90. />
  91. {isOverLatencyThreshold && <StyledIconWarning color="warningText" />}
  92. </Tooltip>
  93. <TraceLink event={evt} />
  94. </div>
  95. <NavigationContainer>
  96. {hasReplay && isReplayEnabled ? (
  97. <Button href="#breadcrumbs" size="sm" icon={<IconPlay size="xs" />}>
  98. {t('Replay')}
  99. </Button>
  100. ) : null}
  101. <NavigationButtonGroup
  102. hasPrevious={!!evt.previousEventID}
  103. hasNext={!!evt.nextEventID}
  104. links={[
  105. {
  106. pathname: `${baseEventsPath}oldest/`,
  107. query: {...location.query, referrer: 'oldest-event'},
  108. },
  109. {
  110. pathname: `${baseEventsPath}${evt.previousEventID}/`,
  111. query: {...location.query, referrer: 'previous-event'},
  112. },
  113. {
  114. pathname: `${baseEventsPath}${evt.nextEventID}/`,
  115. query: {...location.query, referrer: 'next-event'},
  116. },
  117. {
  118. pathname: `${baseEventsPath}latest/`,
  119. query: {...location.query, referrer: 'latest-event'},
  120. },
  121. ]}
  122. onOldestClick={() => this.handleNavigationClick('oldest')}
  123. onOlderClick={() => this.handleNavigationClick('older')}
  124. onNewerClick={() => this.handleNavigationClick('newer')}
  125. onNewestClick={() => this.handleNavigationClick('newest')}
  126. size="sm"
  127. />
  128. </NavigationContainer>
  129. </HeadingAndNavWrapper>
  130. <QuickTrace
  131. event={evt}
  132. group={group}
  133. organization={organization}
  134. location={location}
  135. />
  136. <StyledGlobalAppStoreConnectUpdateAlert
  137. project={project}
  138. organization={organization}
  139. />
  140. </Wrapper>
  141. );
  142. }
  143. }
  144. const Wrapper = styled(DataSection)`
  145. @media (max-width: 767px) {
  146. display: none;
  147. }
  148. `;
  149. const HeadingAndNavWrapper = styled('div')`
  150. display: flex;
  151. position: relative;
  152. flex-direction: row;
  153. justify-content: space-between;
  154. align-items: flex-start;
  155. gap: ${space(3)};
  156. `;
  157. const EventIdLink = styled(Link)`
  158. font-weight: normal;
  159. `;
  160. const Heading = styled('h4')`
  161. line-height: 1.3;
  162. margin: 0;
  163. font-size: ${p => p.theme.fontSizeLarge};
  164. `;
  165. const StyledIconWarning = styled(IconWarning)`
  166. margin-left: ${space(0.5)};
  167. position: relative;
  168. top: ${space(0.25)};
  169. `;
  170. const StyledDateTime = styled(DateTime)`
  171. color: ${p => p.theme.subText};
  172. `;
  173. const StyledGlobalAppStoreConnectUpdateAlert = styled(GlobalAppStoreConnectUpdateAlert)`
  174. margin: ${space(0.5)} 0;
  175. `;
  176. const LinkContainer = styled('span')`
  177. margin-left: ${space(1)};
  178. padding-left: ${space(1)};
  179. position: relative;
  180. font-weight: normal;
  181. &:before {
  182. display: block;
  183. position: absolute;
  184. content: '';
  185. left: 0;
  186. top: 2px;
  187. height: 14px;
  188. border-left: 1px solid ${p => p.theme.border};
  189. }
  190. `;
  191. const NavigationContainer = styled('div')`
  192. display: flex;
  193. align-items: center;
  194. justify-content: flex-end;
  195. gap: 0 ${space(1)};
  196. `;
  197. export default GroupEventToolbar;