traceTimelineTooltip.tsx 5.7 KB

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