traceTimelineTooltip.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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} from 'sentry/locale';
  6. import {space} from 'sentry/styles/space';
  7. import type {Event} from 'sentry/types';
  8. import useOrganization from 'sentry/utils/useOrganization';
  9. import useProjects from 'sentry/utils/useProjects';
  10. import type {TimelineEvent} from './useTraceTimelineEvents';
  11. export function TraceTimelineTooltip({
  12. event,
  13. timelineEvents,
  14. }: {event: Event; timelineEvents: TimelineEvent[]}) {
  15. const organization = useOrganization();
  16. const {projects} = useProjects({
  17. slugs: [
  18. ...timelineEvents.reduce((acc, cur) => acc.add(cur.project), new Set<string>()),
  19. ],
  20. orgId: organization.slug,
  21. });
  22. // TODO: should handling of current event + other events look different
  23. if (timelineEvents.length === 1 && timelineEvents[0].id === event.id) {
  24. return <YouAreHere>{t('You are here')}</YouAreHere>;
  25. }
  26. return (
  27. <UnstyledUnorderedList>
  28. <EventItemsWrapper>
  29. {timelineEvents.slice(0, 3).map(timelineEvent => {
  30. const titleSplit = timelineEvent.title.split(':');
  31. const project = projects.find(p => p.slug === timelineEvent.project);
  32. return (
  33. <EventItem
  34. key={timelineEvent.id}
  35. to={`/organizations/${organization.slug}/issues/${timelineEvent['issue.id']}/events/${timelineEvent.id}/`}
  36. >
  37. <div>
  38. {project && <ProjectBadge project={project} avatarSize={18} hideName />}
  39. </div>
  40. <EventTitleWrapper>
  41. <EventTitle>{titleSplit[0]}</EventTitle>
  42. <EventDescription>{titleSplit.slice(1).join('')}</EventDescription>
  43. </EventTitleWrapper>
  44. </EventItem>
  45. );
  46. })}
  47. </EventItemsWrapper>
  48. {timelineEvents.length > 3 && (
  49. <TraceItem>
  50. <Link to={generateTraceTarget(event, organization)}>
  51. {t('View trace for %s more', timelineEvents.length - 3)}
  52. </Link>
  53. </TraceItem>
  54. )}
  55. </UnstyledUnorderedList>
  56. );
  57. }
  58. const UnstyledUnorderedList = styled('div')`
  59. display: flex;
  60. flex-direction: column;
  61. text-align: left;
  62. `;
  63. const EventItemsWrapper = styled('div')`
  64. display: flex;
  65. flex-direction: column;
  66. padding: ${space(0.5)};
  67. `;
  68. const YouAreHere = styled('div')`
  69. padding: ${space(1)};
  70. font-weight: bold;
  71. text-align: center;
  72. `;
  73. const EventItem = styled(Link)`
  74. display: grid;
  75. grid-template-columns: max-content auto;
  76. color: ${p => p.theme.textColor};
  77. gap: ${space(1)};
  78. width: 100%;
  79. padding: ${space(1)};
  80. border-radius: ${p => p.theme.borderRadius};
  81. min-height: 44px;
  82. &:hover {
  83. background-color: ${p => p.theme.surface200};
  84. color: ${p => p.theme.textColor};
  85. }
  86. `;
  87. const EventTitleWrapper = styled('div')`
  88. width: 100%;
  89. overflow: hidden;
  90. line-height: 1.2;
  91. `;
  92. const EventTitle = styled('div')`
  93. ${p => p.theme.overflowEllipsis};
  94. font-weight: 600;
  95. `;
  96. const EventDescription = styled('div')`
  97. ${p => p.theme.overflowEllipsis};
  98. `;
  99. const TraceItem = styled('div')`
  100. padding: ${space(1)} ${space(1.5)};
  101. border-radius: ${p => p.theme.borderRadius};
  102. border-top: 1px solid ${p => p.theme.innerBorder};
  103. `;