header.tsx 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. import {ReactNode} from 'react';
  2. import {InjectedRouter} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import Badge from 'sentry/components/badge';
  5. import {Button} from 'sentry/components/button';
  6. import ButtonBar from 'sentry/components/buttonBar';
  7. import GlobalEventProcessingAlert from 'sentry/components/globalEventProcessingAlert';
  8. import * as Layout from 'sentry/components/layouts/thirds';
  9. import {PageHeadingQuestionTooltip} from 'sentry/components/pageHeadingQuestionTooltip';
  10. import QueryCount from 'sentry/components/queryCount';
  11. import {TabList, Tabs} from 'sentry/components/tabs';
  12. import {Tooltip} from 'sentry/components/tooltip';
  13. import {SLOW_TOOLTIP_DELAY} from 'sentry/constants';
  14. import {IconPause, IconPlay} from 'sentry/icons';
  15. import {t} from 'sentry/locale';
  16. import {space} from 'sentry/styles/space';
  17. import {Organization} from 'sentry/types';
  18. import {trackAnalyticsEvent} from 'sentry/utils/analytics';
  19. import useProjects from 'sentry/utils/useProjects';
  20. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  21. import IssueListSetAsDefault from 'sentry/views/issueList/issueListSetAsDefault';
  22. import {getTabs, IssueSortOptions, Query, QueryCounts, TAB_MAX_COUNT} from './utils';
  23. type IssueListHeaderProps = {
  24. displayReprocessingTab: boolean;
  25. onRealtimeChange: (realtime: boolean) => void;
  26. organization: Organization;
  27. query: string;
  28. queryCounts: QueryCounts;
  29. realtimeActive: boolean;
  30. router: InjectedRouter;
  31. selectedProjectIds: number[];
  32. sort: string;
  33. queryCount?: number;
  34. };
  35. type IssueListHeaderTabProps = {
  36. name: string;
  37. query: string;
  38. count?: number;
  39. hasMore?: boolean;
  40. tooltipHoverable?: boolean;
  41. tooltipTitle?: ReactNode;
  42. };
  43. const EXTRA_TAB_KEY = 'extra-tab-key';
  44. function IssueListHeaderTabContent({
  45. count = 0,
  46. hasMore = false,
  47. name,
  48. query,
  49. tooltipHoverable,
  50. tooltipTitle,
  51. }: IssueListHeaderTabProps) {
  52. return (
  53. <Tooltip
  54. title={tooltipTitle}
  55. position="bottom"
  56. isHoverable={tooltipHoverable}
  57. delay={SLOW_TOOLTIP_DELAY}
  58. >
  59. {name}{' '}
  60. {count > 0 && (
  61. <Badge type={query === Query.FOR_REVIEW && count > 0 ? 'review' : 'default'}>
  62. <QueryCount hideParens count={count} max={hasMore ? TAB_MAX_COUNT : 1000} />
  63. </Badge>
  64. )}
  65. </Tooltip>
  66. );
  67. }
  68. function IssueListHeader({
  69. organization,
  70. query,
  71. sort,
  72. queryCounts,
  73. realtimeActive,
  74. onRealtimeChange,
  75. router,
  76. displayReprocessingTab,
  77. selectedProjectIds,
  78. }: IssueListHeaderProps) {
  79. const {projects} = useProjects();
  80. const tabs = getTabs(organization);
  81. const visibleTabs = displayReprocessingTab
  82. ? tabs
  83. : tabs.filter(([tab]) => tab !== Query.REPROCESSING);
  84. // Remove cursor and page when switching tabs
  85. const {cursor: _, page: __, ...queryParms} = router?.location?.query ?? {};
  86. const sortParam =
  87. queryParms.sort === IssueSortOptions.INBOX ? undefined : queryParms.sort;
  88. function trackTabClick(tabQuery: string) {
  89. // Clicking on inbox tab and currently another tab is active
  90. if (tabQuery === Query.FOR_REVIEW && query !== Query.FOR_REVIEW) {
  91. trackAnalyticsEvent({
  92. eventKey: 'inbox_tab.clicked',
  93. eventName: 'Clicked Inbox Tab',
  94. organization_id: organization.id,
  95. });
  96. }
  97. }
  98. const selectedProjects = projects.filter(({id}) =>
  99. selectedProjectIds.includes(Number(id))
  100. );
  101. const realtimeTitle = realtimeActive
  102. ? t('Pause real-time updates')
  103. : t('Enable real-time updates');
  104. return (
  105. <Layout.Header noActionWrap>
  106. <Layout.HeaderContent>
  107. <Layout.Title>
  108. {t('Issues')}
  109. <PageHeadingQuestionTooltip
  110. docsUrl="https://docs.sentry.io/product/issues/"
  111. title={t(
  112. 'Detailed views of errors and performance problems in your application grouped by events with a similar set of characteristics.'
  113. )}
  114. />
  115. </Layout.Title>
  116. </Layout.HeaderContent>
  117. <Layout.HeaderActions>
  118. <ButtonBar gap={1}>
  119. <IssueListSetAsDefault {...{sort, query, organization}} />
  120. <Button
  121. size="sm"
  122. data-test-id="real-time"
  123. title={realtimeTitle}
  124. aria-label={realtimeTitle}
  125. icon={realtimeActive ? <IconPause size="xs" /> : <IconPlay size="xs" />}
  126. onClick={() => onRealtimeChange(!realtimeActive)}
  127. />
  128. </ButtonBar>
  129. </Layout.HeaderActions>
  130. <StyledGlobalEventProcessingAlert projects={selectedProjects} />
  131. <StyledTabs
  132. onSelectionChange={key =>
  133. trackTabClick(key === EXTRA_TAB_KEY ? query : key.toString())
  134. }
  135. selectedKey={query}
  136. >
  137. <TabList hideBorder>
  138. {[
  139. ...visibleTabs.map(
  140. ([tabQuery, {name: queryName, tooltipTitle, tooltipHoverable}]) => {
  141. const to = normalizeUrl({
  142. query: {
  143. ...queryParms,
  144. query: tabQuery,
  145. sort:
  146. tabQuery === Query.FOR_REVIEW ? IssueSortOptions.INBOX : sortParam,
  147. },
  148. pathname: `/organizations/${organization.slug}/issues/`,
  149. });
  150. return (
  151. <TabList.Item key={tabQuery} to={to} textValue={queryName}>
  152. <IssueListHeaderTabContent
  153. tooltipTitle={tooltipTitle}
  154. tooltipHoverable={tooltipHoverable}
  155. name={queryName}
  156. count={queryCounts[tabQuery]?.count}
  157. hasMore={queryCounts[tabQuery]?.hasMore}
  158. query={tabQuery}
  159. />
  160. </TabList.Item>
  161. );
  162. }
  163. ),
  164. ]}
  165. </TabList>
  166. </StyledTabs>
  167. </Layout.Header>
  168. );
  169. }
  170. export default IssueListHeader;
  171. const StyledGlobalEventProcessingAlert = styled(GlobalEventProcessingAlert)`
  172. grid-column: 1/-1;
  173. margin-top: ${space(1)};
  174. margin-bottom: ${space(1)};
  175. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  176. margin-top: ${space(2)};
  177. margin-bottom: 0;
  178. }
  179. `;
  180. const StyledTabs = styled(Tabs)`
  181. grid-column: 1/-1;
  182. `;