eventToolbar.tsx 7.2 KB

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