eventNavigation.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import {LinkButton} from 'sentry/components/button';
  4. import ButtonBar from 'sentry/components/buttonBar';
  5. import Count from 'sentry/components/count';
  6. import DropdownButton from 'sentry/components/dropdownButton';
  7. import {DropdownMenu} from 'sentry/components/dropdownMenu';
  8. import {IconTelescope} from 'sentry/icons';
  9. import {t} from 'sentry/locale';
  10. import {space} from 'sentry/styles/space';
  11. import type {Event} from 'sentry/types/event';
  12. import type {Group} from 'sentry/types/group';
  13. import {trackAnalytics} from 'sentry/utils/analytics';
  14. import {SavedQueryDatasets} from 'sentry/utils/discover/types';
  15. import {getConfigForIssueType} from 'sentry/utils/issueTypeConfig';
  16. import parseLinkHeader from 'sentry/utils/parseLinkHeader';
  17. import {keepPreviousData} from 'sentry/utils/queryClient';
  18. import useReplayCountForIssues from 'sentry/utils/replayCount/useReplayCountForIssues';
  19. import {useLocation} from 'sentry/utils/useLocation';
  20. import useOrganization from 'sentry/utils/useOrganization';
  21. import {hasDatasetSelector} from 'sentry/views/dashboards/utils';
  22. import {useGroupEventAttachments} from 'sentry/views/issueDetails/groupEventAttachments/useGroupEventAttachments';
  23. import {useIssueDetails} from 'sentry/views/issueDetails/streamline/context';
  24. import {useIssueDetailsEventView} from 'sentry/views/issueDetails/streamline/hooks/useIssueDetailsDiscoverQuery';
  25. import {IssueDetailsEventNavigation} from 'sentry/views/issueDetails/streamline/issueDetailsEventNavigation';
  26. import {Tab, TabPaths} from 'sentry/views/issueDetails/types';
  27. import {useGroupDetailsRoute} from 'sentry/views/issueDetails/useGroupDetailsRoute';
  28. const TabName: Partial<Record<Tab, string>> = {
  29. [Tab.DETAILS]: t('Events'),
  30. [Tab.EVENTS]: t('Events'),
  31. [Tab.REPLAYS]: t('Replays'),
  32. [Tab.ATTACHMENTS]: t('Attachments'),
  33. [Tab.USER_FEEDBACK]: t('Feedback'),
  34. };
  35. interface IssueEventNavigationProps {
  36. event: Event | undefined;
  37. group: Group;
  38. }
  39. export function IssueEventNavigation({event, group}: IssueEventNavigationProps) {
  40. const organization = useOrganization();
  41. const {baseUrl, currentTab} = useGroupDetailsRoute();
  42. const location = useLocation();
  43. const eventView = useIssueDetailsEventView({group});
  44. const {eventCount} = useIssueDetails();
  45. const issueTypeConfig = getConfigForIssueType(group, group.project);
  46. const hideDropdownButton =
  47. !issueTypeConfig.attachments.enabled &&
  48. !issueTypeConfig.userFeedback.enabled &&
  49. !issueTypeConfig.replays.enabled;
  50. const discoverUrl = eventView.getResultsViewUrlTarget(
  51. organization.slug,
  52. false,
  53. hasDatasetSelector(organization) ? SavedQueryDatasets.ERRORS : undefined
  54. );
  55. const {getReplayCountForIssue} = useReplayCountForIssues({
  56. statsPeriod: '90d',
  57. });
  58. const replaysCount = getReplayCountForIssue(group.id, group.issueCategory) ?? 0;
  59. const attachments = useGroupEventAttachments({
  60. group,
  61. activeAttachmentsTab: 'all',
  62. options: {placeholderData: keepPreviousData},
  63. });
  64. const attachmentPagination = parseLinkHeader(
  65. attachments.getResponseHeader?.('Link') ?? null
  66. );
  67. // Since we reuse whatever page the user was on, we can look at pagination to determine if there are more attachments
  68. const hasManyAttachments =
  69. attachmentPagination.next?.results || attachmentPagination.previous?.results;
  70. return (
  71. <EventNavigationWrapper role="navigation">
  72. <LargeDropdownButtonWrapper>
  73. <DropdownMenu
  74. onAction={key => {
  75. trackAnalytics('issue_details.issue_content_selected', {
  76. organization,
  77. // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
  78. content: TabName[key],
  79. });
  80. }}
  81. items={[
  82. {
  83. key: Tab.DETAILS,
  84. label: (
  85. <DropdownCountWrapper isCurrentTab={currentTab === Tab.DETAILS}>
  86. {TabName[Tab.DETAILS]} <ItemCount value={eventCount ?? 0} />
  87. </DropdownCountWrapper>
  88. ),
  89. textValue: TabName[Tab.DETAILS],
  90. to: {
  91. ...location,
  92. pathname: `${baseUrl}${TabPaths[Tab.DETAILS]}`,
  93. },
  94. },
  95. {
  96. key: Tab.REPLAYS,
  97. label: (
  98. <DropdownCountWrapper isCurrentTab={currentTab === Tab.REPLAYS}>
  99. {TabName[Tab.REPLAYS]}{' '}
  100. {replaysCount > 50 ? (
  101. <CustomItemCount>50+</CustomItemCount>
  102. ) : (
  103. <ItemCount value={replaysCount} />
  104. )}
  105. </DropdownCountWrapper>
  106. ),
  107. textValue: TabName[Tab.REPLAYS],
  108. to: {
  109. ...location,
  110. pathname: `${baseUrl}${TabPaths[Tab.REPLAYS]}`,
  111. },
  112. hidden: !issueTypeConfig.replays.enabled,
  113. },
  114. {
  115. key: Tab.ATTACHMENTS,
  116. label: (
  117. <DropdownCountWrapper isCurrentTab={currentTab === Tab.ATTACHMENTS}>
  118. {TabName[Tab.ATTACHMENTS]}
  119. <CustomItemCount>
  120. {hasManyAttachments ? '50+' : attachments.attachments.length}
  121. </CustomItemCount>
  122. </DropdownCountWrapper>
  123. ),
  124. textValue: TabName[Tab.ATTACHMENTS],
  125. to: {
  126. ...location,
  127. pathname: `${baseUrl}${TabPaths[Tab.ATTACHMENTS]}`,
  128. },
  129. hidden: !issueTypeConfig.attachments.enabled,
  130. },
  131. {
  132. key: Tab.USER_FEEDBACK,
  133. label: (
  134. <DropdownCountWrapper isCurrentTab={currentTab === Tab.USER_FEEDBACK}>
  135. {TabName[Tab.USER_FEEDBACK]} <ItemCount value={group.userReportCount} />
  136. </DropdownCountWrapper>
  137. ),
  138. textValue: TabName[Tab.USER_FEEDBACK],
  139. to: {
  140. ...location,
  141. pathname: `${baseUrl}${TabPaths[Tab.USER_FEEDBACK]}`,
  142. },
  143. hidden: !issueTypeConfig.userFeedback.enabled,
  144. },
  145. ]}
  146. offset={[-2, 1]}
  147. trigger={(triggerProps, isOpen) =>
  148. hideDropdownButton ? (
  149. <NavigationLabel>
  150. {TabName[currentTab] ?? TabName[Tab.DETAILS]}
  151. </NavigationLabel>
  152. ) : (
  153. <NavigationDropdownButton
  154. {...triggerProps}
  155. isOpen={isOpen}
  156. borderless
  157. size="sm"
  158. disabled={hideDropdownButton}
  159. aria-label={t('Select issue content')}
  160. aria-description={TabName[currentTab]}
  161. analyticsEventName="Issue Details: Issue Content Dropdown Opened"
  162. analyticsEventKey="issue_details.issue_content_dropdown_opened"
  163. >
  164. {TabName[currentTab] ?? TabName[Tab.DETAILS]}
  165. </NavigationDropdownButton>
  166. )
  167. }
  168. />
  169. <LargeInThisIssueText aria-hidden>{t('in this issue')}</LargeInThisIssueText>
  170. </LargeDropdownButtonWrapper>
  171. <NavigationWrapper>
  172. {currentTab === Tab.DETAILS && (
  173. <Fragment>
  174. <IssueDetailsEventNavigation event={event} group={group} />
  175. <LinkButton
  176. to={{
  177. pathname: `${baseUrl}${TabPaths[Tab.EVENTS]}`,
  178. query: location.query,
  179. }}
  180. size="xs"
  181. analyticsEventKey="issue_details.all_events_clicked"
  182. analyticsEventName="Issue Details: All Events Clicked"
  183. >
  184. {issueTypeConfig.customCopy.allEvents || t('All Events')}
  185. </LinkButton>
  186. </Fragment>
  187. )}
  188. {currentTab === Tab.EVENTS && (
  189. <ButtonBar gap={1}>
  190. <LinkButton
  191. to={discoverUrl}
  192. aria-label={t('Open in Discover')}
  193. size="xs"
  194. icon={<IconTelescope />}
  195. analyticsEventKey="issue_details.discover_clicked"
  196. analyticsEventName="Issue Details: Discover Clicked"
  197. >
  198. {t('Discover')}
  199. </LinkButton>
  200. <LinkButton
  201. to={{
  202. pathname: `${baseUrl}${TabPaths[Tab.DETAILS]}`,
  203. query: {...location.query, cursor: undefined},
  204. }}
  205. aria-label={t('Return to event details')}
  206. size="xs"
  207. >
  208. {t('Close')}
  209. </LinkButton>
  210. </ButtonBar>
  211. )}
  212. </NavigationWrapper>
  213. </EventNavigationWrapper>
  214. );
  215. }
  216. const LargeDropdownButtonWrapper = styled('div')`
  217. display: flex;
  218. align-items: center;
  219. gap: ${space(0.25)};
  220. `;
  221. const NavigationDropdownButton = styled(DropdownButton)`
  222. font-size: ${p => p.theme.fontSizeLarge};
  223. font-weight: ${p => p.theme.fontWeightBold};
  224. padding-right: ${space(0.5)};
  225. `;
  226. const NavigationLabel = styled('div')`
  227. font-size: ${p => p.theme.fontSizeLarge};
  228. font-weight: ${p => p.theme.fontWeightBold};
  229. padding-right: ${space(0.25)};
  230. padding-left: ${space(1.5)};
  231. `;
  232. const LargeInThisIssueText = styled('div')`
  233. font-size: ${p => p.theme.fontSizeLarge};
  234. font-weight: ${p => p.theme.fontWeightBold};
  235. color: ${p => p.theme.subText};
  236. `;
  237. const EventNavigationWrapper = styled('div')`
  238. flex-grow: 1;
  239. display: flex;
  240. flex-direction: column;
  241. justify-content: space-between;
  242. font-size: ${p => p.theme.fontSizeSmall};
  243. @media (min-width: ${p => p.theme.breakpoints.xsmall}) {
  244. flex-direction: row;
  245. align-items: center;
  246. }
  247. `;
  248. const NavigationWrapper = styled('div')`
  249. display: flex;
  250. gap: ${space(0.25)};
  251. justify-content: space-between;
  252. @media (min-width: ${p => p.theme.breakpoints.xsmall}) {
  253. gap: ${space(0.5)};
  254. }
  255. `;
  256. const DropdownCountWrapper = styled('div')<{isCurrentTab: boolean}>`
  257. display: flex;
  258. align-items: center;
  259. justify-content: space-between;
  260. gap: ${space(3)};
  261. font-variant-numeric: tabular-nums;
  262. font-weight: ${p =>
  263. p.isCurrentTab ? p.theme.fontWeightBold : p.theme.fontWeightNormal};
  264. `;
  265. const ItemCount = styled(Count)`
  266. color: ${p => p.theme.subText};
  267. `;
  268. const CustomItemCount = styled('div')`
  269. color: ${p => p.theme.subText};
  270. `;