header.tsx 5.7 KB

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