header.tsx 5.5 KB

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