header.tsx 5.6 KB

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