traceTimelineTooltip.tsx 5.6 KB

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