eventToolbar.tsx 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. import {Component, Fragment} 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 ConfigStore from 'sentry/stores/configStore';
  17. import space from 'sentry/styles/space';
  18. import {Group, Organization, Project} from 'sentry/types';
  19. import {Event} from 'sentry/types/event';
  20. import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
  21. import {shouldUse24Hours} from 'sentry/utils/dates';
  22. import getDynamicText from 'sentry/utils/getDynamicText';
  23. import QuickTrace from './quickTrace';
  24. const formatDateDelta = (reference: moment.Moment, observed: moment.Moment) => {
  25. const duration = moment.duration(Math.abs(+observed - +reference));
  26. const hours = Math.floor(+duration / (60 * 60 * 1000));
  27. const minutes = duration.minutes();
  28. const results: string[] = [];
  29. if (hours) {
  30. results.push(`${hours} hour${hours !== 1 ? 's' : ''}`);
  31. }
  32. if (minutes) {
  33. results.push(`${minutes} minute${minutes !== 1 ? 's' : ''}`);
  34. }
  35. if (results.length === 0) {
  36. results.push('a few seconds');
  37. }
  38. return results.join(', ');
  39. };
  40. type Props = {
  41. event: Event;
  42. group: Group;
  43. location: Location;
  44. organization: Organization;
  45. project: Project;
  46. hasReplay?: boolean;
  47. };
  48. class GroupEventToolbar extends Component<Props> {
  49. shouldComponentUpdate(nextProps: Props) {
  50. return this.props.event.id !== nextProps.event.id;
  51. }
  52. handleNavigationClick(button: string) {
  53. trackAdvancedAnalyticsEvent('issue_details.event_navigation_clicked', {
  54. organization: this.props.organization,
  55. project_id: parseInt(this.props.project.id, 10),
  56. button,
  57. });
  58. }
  59. getDateTooltip() {
  60. const evt = this.props.event;
  61. const user = ConfigStore.get('user');
  62. const options = user?.options ?? {};
  63. const format = options.clock24Hours ? 'HH:mm:ss z' : 'LTS z';
  64. const dateCreated = moment(evt.dateCreated);
  65. const dateReceived = evt.dateReceived ? moment(evt.dateReceived) : null;
  66. return (
  67. <DescriptionList>
  68. <dt>Occurred</dt>
  69. <dd>
  70. {dateCreated.format('ll')}
  71. <br />
  72. {dateCreated.format(format)}
  73. </dd>
  74. {dateReceived && (
  75. <Fragment>
  76. <dt>Received</dt>
  77. <dd>
  78. {dateReceived.format('ll')}
  79. <br />
  80. {dateReceived.format(format)}
  81. </dd>
  82. <dt>Latency</dt>
  83. <dd>{formatDateDelta(dateCreated, dateReceived)}</dd>
  84. </Fragment>
  85. )}
  86. </DescriptionList>
  87. );
  88. }
  89. render() {
  90. const is24Hours = shouldUse24Hours();
  91. const evt = this.props.event;
  92. const {group, organization, location, project, hasReplay} = this.props;
  93. const groupId = group.id;
  94. const isReplayEnabled = organization.features.includes('session-replay-ui');
  95. const baseEventsPath = `/organizations/${organization.slug}/issues/${groupId}/events/`;
  96. // TODO: possible to define this as a route in react-router, but without a corresponding
  97. // React component?
  98. const jsonUrl = `/organizations/${organization.slug}/issues/${groupId}/events/${evt.id}/json/`;
  99. const latencyThreshold = 30 * 60 * 1000; // 30 minutes
  100. const isOverLatencyThreshold =
  101. evt.dateReceived &&
  102. Math.abs(+moment(evt.dateReceived) - +moment(evt.dateCreated)) > latencyThreshold;
  103. return (
  104. <Wrapper>
  105. <div>
  106. <Heading>
  107. {t('Event ID')}{' '}
  108. <EventIdLink to={`${baseEventsPath}${evt.id}/`}>{evt.eventID}</EventIdLink>
  109. <LinkContainer>
  110. <ExternalLink
  111. href={jsonUrl}
  112. onClick={() =>
  113. trackAdvancedAnalyticsEvent('issue_details.event_json_clicked', {
  114. organization,
  115. group_id: parseInt(`${evt.groupID}`, 10),
  116. })
  117. }
  118. >
  119. {'JSON'} (<FileSize bytes={evt.size} />)
  120. </ExternalLink>
  121. </LinkContainer>
  122. </Heading>
  123. <Tooltip title={this.getDateTooltip()} showUnderline disableForVisualTest>
  124. <StyledDateTime
  125. format={is24Hours ? 'MMM D, YYYY HH:mm:ss zz' : 'll LTS z'}
  126. date={getDynamicText({
  127. value: evt.dateCreated,
  128. fixed: 'Dummy timestamp',
  129. })}
  130. />
  131. {isOverLatencyThreshold && <StyledIconWarning color="yellow300" />}
  132. </Tooltip>
  133. <StyledGlobalAppStoreConnectUpdateAlert
  134. project={project}
  135. organization={organization}
  136. />
  137. <QuickTrace
  138. event={evt}
  139. group={group}
  140. organization={organization}
  141. location={location}
  142. />
  143. </div>
  144. <NavigationContainer>
  145. {hasReplay && isReplayEnabled ? (
  146. <Button href="#breadcrumbs" size="sm" icon={<IconPlay size="xs" />}>
  147. {t('Replay')}
  148. </Button>
  149. ) : null}
  150. <NavigationButtonGroup
  151. hasPrevious={!!evt.previousEventID}
  152. hasNext={!!evt.nextEventID}
  153. links={[
  154. {
  155. pathname: `${baseEventsPath}oldest/`,
  156. query: {...location.query, referrer: 'oldest-event'},
  157. },
  158. {
  159. pathname: `${baseEventsPath}${evt.previousEventID}/`,
  160. query: {...location.query, referrer: 'previous-event'},
  161. },
  162. {
  163. pathname: `${baseEventsPath}${evt.nextEventID}/`,
  164. query: {...location.query, referrer: 'next-event'},
  165. },
  166. {
  167. pathname: `${baseEventsPath}latest/`,
  168. query: {...location.query, referrer: 'latest-event'},
  169. },
  170. ]}
  171. onOldestClick={() => this.handleNavigationClick('oldest')}
  172. onOlderClick={() => this.handleNavigationClick('older')}
  173. onNewerClick={() => this.handleNavigationClick('newer')}
  174. onNewestClick={() => this.handleNavigationClick('newest')}
  175. size="sm"
  176. />
  177. </NavigationContainer>
  178. </Wrapper>
  179. );
  180. }
  181. }
  182. const Wrapper = styled(DataSection)`
  183. position: relative;
  184. flex-direction: row;
  185. justify-content: space-between;
  186. align-items: flex-start;
  187. gap: ${space(3)};
  188. @media (max-width: 767px) {
  189. display: none;
  190. }
  191. `;
  192. const EventIdLink = styled(Link)`
  193. font-weight: normal;
  194. `;
  195. const Heading = styled('h4')`
  196. line-height: 1.3;
  197. margin: 0;
  198. font-size: ${p => p.theme.fontSizeLarge};
  199. `;
  200. const StyledIconWarning = styled(IconWarning)`
  201. margin-left: ${space(0.5)};
  202. position: relative;
  203. top: ${space(0.25)};
  204. `;
  205. const StyledDateTime = styled(DateTime)`
  206. color: ${p => p.theme.subText};
  207. `;
  208. const StyledGlobalAppStoreConnectUpdateAlert = styled(GlobalAppStoreConnectUpdateAlert)`
  209. margin-top: ${space(0.5)};
  210. margin-bottom: ${space(1)};
  211. `;
  212. const LinkContainer = styled('span')`
  213. margin-left: ${space(1)};
  214. padding-left: ${space(1)};
  215. position: relative;
  216. font-weight: normal;
  217. &:before {
  218. display: block;
  219. position: absolute;
  220. content: '';
  221. left: 0;
  222. top: 2px;
  223. height: 14px;
  224. border-left: 1px solid ${p => p.theme.border};
  225. }
  226. `;
  227. const DescriptionList = styled('dl')`
  228. display: grid;
  229. grid-template-columns: max-content 1fr;
  230. gap: ${space(0.75)} ${space(1)};
  231. text-align: left;
  232. margin: 0;
  233. `;
  234. const NavigationContainer = styled('div')`
  235. display: flex;
  236. align-items: center;
  237. justify-content: flex-end;
  238. gap: 0 ${space(1)};
  239. `;
  240. export default GroupEventToolbar;