header.tsx 5.8 KB

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