header.tsx 5.9 KB

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