traceTimelineTooltip.tsx 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. import styled from '@emotion/styled';
  2. import type {Location} from 'history';
  3. import {useAnalyticsArea} from 'sentry/components/analyticsArea';
  4. import ProjectBadge from 'sentry/components/idBadge/projectBadge';
  5. import Link from 'sentry/components/links/link';
  6. import {generateTraceTarget} from 'sentry/components/quickTrace/utils';
  7. import {t, tn} from 'sentry/locale';
  8. import {space} from 'sentry/styles/space';
  9. import type {Event} from 'sentry/types/event';
  10. import {trackAnalytics} from 'sentry/utils/analytics';
  11. import {useLocation} from 'sentry/utils/useLocation';
  12. import useOrganization from 'sentry/utils/useOrganization';
  13. import useProjects from 'sentry/utils/useProjects';
  14. import type {TimelineEvent} from './useTraceTimelineEvents';
  15. interface TraceTimelineTooltipProps {
  16. event: Event;
  17. timelineEvents: TimelineEvent[];
  18. }
  19. export function TraceTimelineTooltip({event, timelineEvents}: TraceTimelineTooltipProps) {
  20. const organization = useOrganization();
  21. const location = useLocation();
  22. const area = useAnalyticsArea();
  23. // TODO: should handling of current event + other events look different
  24. if (timelineEvents.length === 1 && timelineEvents[0].id === event.id) {
  25. return <YouAreHere>{t('You are here')}</YouAreHere>;
  26. }
  27. const filteredTimelineEvents = timelineEvents.filter(
  28. timelineEvent => timelineEvent.id !== event.id
  29. );
  30. const displayYouAreHere = filteredTimelineEvents.length !== timelineEvents.length;
  31. const hasTitle = filteredTimelineEvents.length > 1 || displayYouAreHere;
  32. return (
  33. <UnstyledUnorderedList>
  34. {displayYouAreHere && <YouAreHereItem>{t('You are here')}</YouAreHereItem>}
  35. <EventItemsWrapper hasTitle={hasTitle}>
  36. {hasTitle && <EventItemsTitle>{t('Around the same time')}</EventItemsTitle>}
  37. {filteredTimelineEvents.slice(0, 3).map(timelineEvent => {
  38. return (
  39. <EventItem
  40. key={timelineEvent.id}
  41. timelineEvent={timelineEvent}
  42. location={location}
  43. />
  44. );
  45. })}
  46. </EventItemsWrapper>
  47. {filteredTimelineEvents.length > 3 && (
  48. <TraceItem>
  49. <Link
  50. to={generateTraceTarget(event, organization, location)}
  51. onClick={() => {
  52. if (area.startsWith('issue_details')) {
  53. // Track this event for backwards compatibility. TODO: remove after issues team dashboards/queries are migrated
  54. trackAnalytics(
  55. 'issue_details.issue_tab.trace_timeline_more_events_clicked',
  56. {
  57. organization,
  58. num_hidden: filteredTimelineEvents.length - 3,
  59. }
  60. );
  61. }
  62. trackAnalytics('trace_timeline_more_events_clicked', {
  63. organization,
  64. num_hidden: filteredTimelineEvents.length - 3,
  65. area,
  66. });
  67. }}
  68. >
  69. {tn(
  70. 'View %s more event',
  71. 'View %s more events',
  72. filteredTimelineEvents.length - 3
  73. )}
  74. </Link>
  75. </TraceItem>
  76. )}
  77. </UnstyledUnorderedList>
  78. );
  79. }
  80. interface EventItemProps {
  81. location: Location;
  82. timelineEvent: TimelineEvent;
  83. }
  84. function EventItem({timelineEvent, location}: EventItemProps) {
  85. const organization = useOrganization();
  86. const {projects} = useProjects({
  87. slugs: [timelineEvent.project],
  88. orgId: organization.slug,
  89. });
  90. const project = projects.find(p => p.slug === timelineEvent.project);
  91. const area = useAnalyticsArea();
  92. return (
  93. <EventItemRoot
  94. to={{
  95. pathname: `/organizations/${organization.slug}/issues/${timelineEvent['issue.id']}/events/${timelineEvent.id}/`,
  96. query: {
  97. ...location.query,
  98. project: undefined,
  99. referrer: area.includes('issue_details')
  100. ? 'issues_trace_timeline' // TODO: remove this condition after queries are migrated
  101. : area,
  102. },
  103. }}
  104. onClick={() => {
  105. if (area.includes('issue_details')) {
  106. // Track this event for backwards compatibility. TODO: remove after issues team dashboards/queries are migrated
  107. trackAnalytics('issue_details.issue_tab.trace_timeline_clicked', {
  108. organization,
  109. event_id: timelineEvent.id,
  110. group_id: `${timelineEvent['issue.id']}`,
  111. });
  112. }
  113. trackAnalytics('trace_timeline_clicked', {
  114. organization,
  115. event_id: timelineEvent.id,
  116. group_id: `${timelineEvent['issue.id']}`,
  117. area,
  118. });
  119. }}
  120. >
  121. {project && <ProjectBadge project={project} avatarSize={18} hideName disableLink />}
  122. <EventTitleWrapper>
  123. <EventTitle>{timelineEvent.title}</EventTitle>
  124. <EventDescription>
  125. {timelineEvent.transaction
  126. ? timelineEvent.transaction
  127. : 'stack.function' in timelineEvent
  128. ? timelineEvent['stack.function'].at(-1)
  129. : null}
  130. </EventDescription>
  131. </EventTitleWrapper>
  132. </EventItemRoot>
  133. );
  134. }
  135. const UnstyledUnorderedList = styled('div')`
  136. display: flex;
  137. flex-direction: column;
  138. text-align: left;
  139. width: 220px;
  140. `;
  141. const EventItemsWrapper = styled('div')<{hasTitle: boolean}>`
  142. display: flex;
  143. flex-direction: column;
  144. padding: ${p => space(p.hasTitle ? 1 : 0.5)} ${space(0.5)} ${space(0.5)} ${space(0.5)};
  145. `;
  146. const EventItemsTitle = styled('div')`
  147. padding-left: ${space(1)};
  148. text-transform: uppercase;
  149. font-size: ${p => p.theme.fontSizeExtraSmall};
  150. font-weight: ${p => p.theme.fontWeightBold};
  151. color: ${p => p.theme.subText};
  152. `;
  153. const YouAreHere = styled('div')`
  154. padding: ${space(1)} ${space(2)};
  155. text-align: center;
  156. font-size: ${p => p.theme.fontSizeMedium};
  157. `;
  158. const YouAreHereItem = styled('div')`
  159. padding: ${space(1)} ${space(2)};
  160. text-align: center;
  161. border-bottom: 1px solid ${p => p.theme.innerBorder};
  162. font-size: ${p => p.theme.fontSizeMedium};
  163. `;
  164. const EventItemRoot = styled(Link)`
  165. display: grid;
  166. grid-template-columns: max-content auto;
  167. color: ${p => p.theme.textColor};
  168. gap: ${space(1)};
  169. width: 100%;
  170. padding: ${space(1)} ${space(1)} ${space(0.5)} ${space(1)};
  171. border-radius: ${p => p.theme.borderRadius};
  172. font-size: ${p => p.theme.fontSizeSmall};
  173. &:hover {
  174. background-color: ${p => p.theme.surface200};
  175. color: ${p => p.theme.textColor};
  176. }
  177. `;
  178. const EventTitleWrapper = styled('div')`
  179. width: 100%;
  180. overflow: hidden;
  181. line-height: 1.2;
  182. `;
  183. const EventTitle = styled('div')`
  184. ${p => p.theme.overflowEllipsis};
  185. font-weight: ${p => p.theme.fontWeightBold};
  186. `;
  187. const EventDescription = styled('div')`
  188. ${p => p.theme.overflowEllipsis};
  189. direction: rtl;
  190. `;
  191. const TraceItem = styled('div')`
  192. padding: ${space(1)} ${space(1.5)};
  193. border-radius: ${p => p.theme.borderRadius};
  194. border-top: 1px solid ${p => p.theme.innerBorder};
  195. `;