eventToolbar.tsx 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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 className="flat">
  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. <StyledDataSection>
  102. <StyledNavigationButtonGroup
  103. hasPrevious={!!evt.previousEventID}
  104. hasNext={!!evt.nextEventID}
  105. links={[
  106. {pathname: `${baseEventsPath}oldest/`, query: location.query},
  107. {pathname: `${baseEventsPath}${evt.previousEventID}/`, query: location.query},
  108. {pathname: `${baseEventsPath}${evt.nextEventID}/`, query: location.query},
  109. {pathname: `${baseEventsPath}latest/`, query: location.query},
  110. ]}
  111. onOldestClick={() => this.handleNavigationClick('oldest')}
  112. onOlderClick={() => this.handleNavigationClick('older')}
  113. onNewerClick={() => this.handleNavigationClick('newer')}
  114. onNewestClick={() => this.handleNavigationClick('newest')}
  115. size="sm"
  116. />
  117. <Heading>
  118. {t('Event')}{' '}
  119. <EventIdLink to={`${baseEventsPath}${evt.id}/`}>{evt.eventID}</EventIdLink>
  120. <LinkContainer>
  121. <ExternalLink
  122. href={jsonUrl}
  123. onClick={() =>
  124. trackAdvancedAnalyticsEvent('issue_details.event_json_clicked', {
  125. organization,
  126. group_id: parseInt(`${evt.groupID}`, 10),
  127. })
  128. }
  129. >
  130. {'JSON'} (<FileSize bytes={evt.size} />)
  131. </ExternalLink>
  132. </LinkContainer>
  133. </Heading>
  134. <Tooltip title={this.getDateTooltip()} showUnderline disableForVisualTest>
  135. <StyledDateTime
  136. format={is24Hours ? 'MMM D, YYYY HH:mm:ss zz' : 'll LTS z'}
  137. date={getDynamicText({
  138. value: evt.dateCreated,
  139. fixed: 'Dummy timestamp',
  140. })}
  141. />
  142. {isOverLatencyThreshold && <StyledIconWarning color="yellow300" />}
  143. </Tooltip>
  144. <StyledGlobalAppStoreConnectUpdateAlert
  145. project={project}
  146. organization={organization}
  147. />
  148. <QuickTrace
  149. event={evt}
  150. group={group}
  151. organization={organization}
  152. location={location}
  153. />
  154. </StyledDataSection>
  155. );
  156. }
  157. }
  158. const StyledDataSection = styled(DataSection)`
  159. position: relative;
  160. display: block;
  161. border-top: 0;
  162. /* z-index seems unnecessary, but increasing (instead of removing) just in case(billy) */
  163. /* Fixes tooltips in toolbar having lower z-index than .btn-group .btn.active */
  164. z-index: 3;
  165. @media (max-width: 767px) {
  166. display: none;
  167. }
  168. `;
  169. const EventIdLink = styled(Link)`
  170. font-weight: normal;
  171. `;
  172. const Heading = styled('h4')`
  173. line-height: 1.3;
  174. margin: 0;
  175. font-size: ${p => p.theme.fontSizeLarge};
  176. `;
  177. const StyledNavigationButtonGroup = styled(NavigationButtonGroup)`
  178. float: right;
  179. `;
  180. const StyledIconWarning = styled(IconWarning)`
  181. margin-left: ${space(0.5)};
  182. position: relative;
  183. top: ${space(0.25)};
  184. `;
  185. const StyledDateTime = styled(DateTime)`
  186. color: ${p => p.theme.subText};
  187. `;
  188. const StyledGlobalAppStoreConnectUpdateAlert = styled(GlobalAppStoreConnectUpdateAlert)`
  189. margin-top: ${space(0.5)};
  190. margin-bottom: ${space(1)};
  191. `;
  192. const LinkContainer = styled('span')`
  193. margin-left: ${space(1)};
  194. padding-left: ${space(1)};
  195. position: relative;
  196. font-weight: normal;
  197. &:before {
  198. display: block;
  199. position: absolute;
  200. content: '';
  201. left: 0;
  202. top: 2px;
  203. height: 14px;
  204. border-left: 1px solid ${p => p.theme.border};
  205. }
  206. `;
  207. const DescriptionList = styled('dl')`
  208. text-align: left;
  209. margin: 0;
  210. min-width: 200px;
  211. max-width: 250px;
  212. `;
  213. export default GroupEventToolbar;