eventToolbar.tsx 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. Replay
  148. </Button>
  149. ) : null}
  150. <NavigationButtonGroup
  151. hasPrevious={!!evt.previousEventID}
  152. hasNext={!!evt.nextEventID}
  153. links={[
  154. {pathname: `${baseEventsPath}oldest/`, query: location.query},
  155. {
  156. pathname: `${baseEventsPath}${evt.previousEventID}/`,
  157. query: location.query,
  158. },
  159. {pathname: `${baseEventsPath}${evt.nextEventID}/`, query: location.query},
  160. {pathname: `${baseEventsPath}latest/`, query: location.query},
  161. ]}
  162. onOldestClick={() => this.handleNavigationClick('oldest')}
  163. onOlderClick={() => this.handleNavigationClick('older')}
  164. onNewerClick={() => this.handleNavigationClick('newer')}
  165. onNewestClick={() => this.handleNavigationClick('newest')}
  166. size="sm"
  167. />
  168. </NavigationContainer>
  169. </Wrapper>
  170. );
  171. }
  172. }
  173. const Wrapper = styled(DataSection)`
  174. position: relative;
  175. flex-direction: row;
  176. justify-content: space-between;
  177. align-items: flex-start;
  178. gap: ${space(3)};
  179. @media (max-width: 767px) {
  180. display: none;
  181. }
  182. `;
  183. const EventIdLink = styled(Link)`
  184. font-weight: normal;
  185. `;
  186. const Heading = styled('h4')`
  187. line-height: 1.3;
  188. margin: 0;
  189. font-size: ${p => p.theme.fontSizeLarge};
  190. `;
  191. const StyledIconWarning = styled(IconWarning)`
  192. margin-left: ${space(0.5)};
  193. position: relative;
  194. top: ${space(0.25)};
  195. `;
  196. const StyledDateTime = styled(DateTime)`
  197. color: ${p => p.theme.subText};
  198. `;
  199. const StyledGlobalAppStoreConnectUpdateAlert = styled(GlobalAppStoreConnectUpdateAlert)`
  200. margin-top: ${space(0.5)};
  201. margin-bottom: ${space(1)};
  202. `;
  203. const LinkContainer = styled('span')`
  204. margin-left: ${space(1)};
  205. padding-left: ${space(1)};
  206. position: relative;
  207. font-weight: normal;
  208. &:before {
  209. display: block;
  210. position: absolute;
  211. content: '';
  212. left: 0;
  213. top: 2px;
  214. height: 14px;
  215. border-left: 1px solid ${p => p.theme.border};
  216. }
  217. `;
  218. const DescriptionList = styled('dl')`
  219. display: grid;
  220. grid-template-columns: max-content 1fr;
  221. gap: ${space(0.75)} ${space(1)};
  222. text-align: left;
  223. margin: 0;
  224. `;
  225. const NavigationContainer = styled('div')`
  226. display: flex;
  227. align-items: center;
  228. justify-content: flex-end;
  229. gap: 0 ${space(1)};
  230. `;
  231. export default GroupEventToolbar;