eventToolbar.tsx 7.5 KB

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