header.tsx 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 {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. function IssueListHeaderTabContent({
  44. count = 0,
  45. hasMore = false,
  46. name,
  47. query,
  48. tooltipHoverable,
  49. tooltipTitle,
  50. }: IssueListHeaderTabProps) {
  51. return (
  52. <Tooltip
  53. title={tooltipTitle}
  54. position="bottom"
  55. isHoverable={tooltipHoverable}
  56. delay={SLOW_TOOLTIP_DELAY}
  57. >
  58. {name}{' '}
  59. {count > 0 && (
  60. <Badge type={query === Query.FOR_REVIEW && count > 0 ? 'review' : 'default'}>
  61. <QueryCount hideParens count={count} max={hasMore ? TAB_MAX_COUNT : 1000} />
  62. </Badge>
  63. )}
  64. </Tooltip>
  65. );
  66. }
  67. function IssueListHeader({
  68. organization,
  69. query,
  70. sort,
  71. queryCounts,
  72. realtimeActive,
  73. onRealtimeChange,
  74. router,
  75. displayReprocessingTab,
  76. selectedProjectIds,
  77. }: IssueListHeaderProps) {
  78. const {projects} = useProjects();
  79. const tabs = getTabs(organization);
  80. const visibleTabs = displayReprocessingTab
  81. ? tabs
  82. : tabs.filter(([tab]) => tab !== Query.REPROCESSING);
  83. // Remove cursor and page when switching tabs
  84. const {cursor: _, page: __, ...queryParms} = router?.location?.query ?? {};
  85. const sortParam =
  86. queryParms.sort === IssueSortOptions.INBOX ? undefined : queryParms.sort;
  87. const selectedProjects = projects.filter(({id}) =>
  88. selectedProjectIds.includes(Number(id))
  89. );
  90. const realtimeTitle = realtimeActive
  91. ? t('Pause real-time updates')
  92. : t('Enable real-time updates');
  93. return (
  94. <Layout.Header noActionWrap>
  95. <Layout.HeaderContent>
  96. <Layout.Title>
  97. {t('Issues')}
  98. <PageHeadingQuestionTooltip
  99. docsUrl="https://docs.sentry.io/product/issues/"
  100. title={t(
  101. 'Detailed views of errors and performance problems in your application grouped by events with a similar set of characteristics.'
  102. )}
  103. />
  104. </Layout.Title>
  105. </Layout.HeaderContent>
  106. <Layout.HeaderActions>
  107. <ButtonBar gap={1}>
  108. <IssueListSetAsDefault {...{sort, query, organization}} />
  109. <Button
  110. size="sm"
  111. data-test-id="real-time"
  112. title={realtimeTitle}
  113. aria-label={realtimeTitle}
  114. icon={realtimeActive ? <IconPause size="xs" /> : <IconPlay size="xs" />}
  115. onClick={() => onRealtimeChange(!realtimeActive)}
  116. />
  117. </ButtonBar>
  118. </Layout.HeaderActions>
  119. <StyledGlobalEventProcessingAlert projects={selectedProjects} />
  120. <StyledTabs selectedKey={query} onSelectionChange={() => {}}>
  121. <TabList hideBorder>
  122. {[
  123. ...visibleTabs.map(
  124. ([tabQuery, {name: queryName, tooltipTitle, tooltipHoverable}]) => {
  125. const to = normalizeUrl({
  126. query: {
  127. ...queryParms,
  128. query: tabQuery,
  129. sort:
  130. tabQuery === Query.FOR_REVIEW ? IssueSortOptions.INBOX : sortParam,
  131. },
  132. pathname: `/organizations/${organization.slug}/issues/`,
  133. });
  134. return (
  135. <TabList.Item key={tabQuery} to={to} textValue={queryName}>
  136. <GuideAnchor
  137. disabled={tabQuery !== Query.ARCHIVED}
  138. target="issue_stream_archive_tab"
  139. position="bottom"
  140. >
  141. <IssueListHeaderTabContent
  142. tooltipTitle={tooltipTitle}
  143. tooltipHoverable={tooltipHoverable}
  144. name={queryName}
  145. count={queryCounts[tabQuery]?.count}
  146. hasMore={queryCounts[tabQuery]?.hasMore}
  147. query={tabQuery}
  148. />
  149. </GuideAnchor>
  150. </TabList.Item>
  151. );
  152. }
  153. ),
  154. ]}
  155. </TabList>
  156. </StyledTabs>
  157. </Layout.Header>
  158. );
  159. }
  160. export default IssueListHeader;
  161. const StyledGlobalEventProcessingAlert = styled(GlobalEventProcessingAlert)`
  162. grid-column: 1/-1;
  163. margin-top: ${space(1)};
  164. margin-bottom: ${space(1)};
  165. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  166. margin-top: ${space(2)};
  167. margin-bottom: 0;
  168. }
  169. `;
  170. const StyledTabs = styled(Tabs)`
  171. grid-column: 1/-1;
  172. `;