traceTimelineTooltip.tsx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. project: undefined,
  50. referrer: 'issues_trace_timeline',
  51. },
  52. }}
  53. onClick={() => {
  54. trackAnalytics('issue_details.issue_tab.trace_timeline_clicked', {
  55. organization,
  56. event_id: timelineEvent.id,
  57. group_id: `${timelineEvent['issue.id']}`,
  58. });
  59. }}
  60. >
  61. <div>
  62. {project && (
  63. <ProjectBadge project={project} avatarSize={18} hideName disableLink />
  64. )}
  65. </div>
  66. <EventTitleWrapper>
  67. <EventTitle>{timelineEvent.title}</EventTitle>
  68. <EventDescription>
  69. {timelineEvent.transaction
  70. ? timelineEvent.transaction
  71. : 'stack.function' in timelineEvent
  72. ? timelineEvent['stack.function'].at(-1)
  73. : null}
  74. </EventDescription>
  75. </EventTitleWrapper>
  76. </EventItem>
  77. );
  78. })}
  79. </EventItemsWrapper>
  80. {filteredTimelineEvents.length > 3 && (
  81. <TraceItem>
  82. <Link
  83. to={generateTraceTarget(event, organization)}
  84. onClick={() => {
  85. trackAnalytics(
  86. 'issue_details.issue_tab.trace_timeline_more_events_clicked',
  87. {
  88. organization,
  89. num_hidden: filteredTimelineEvents.length - 3,
  90. }
  91. );
  92. }}
  93. >
  94. {tn(
  95. 'View %s more event',
  96. 'View %s more events',
  97. filteredTimelineEvents.length - 3
  98. )}
  99. </Link>
  100. </TraceItem>
  101. )}
  102. </UnstyledUnorderedList>
  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: 600;
  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 EventItem = 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: 600;
  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. `;