traceTimelineTooltip.tsx 5.7 KB

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