header.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import {navigateTo} from 'sentry/actionCreators/navigation';
  2. import {LinkButton} from 'sentry/components/button';
  3. import ButtonBar from 'sentry/components/buttonBar';
  4. import CreateAlertButton from 'sentry/components/createAlertButton';
  5. import FeedbackWidgetButton from 'sentry/components/feedback/widget/feedbackWidgetButton';
  6. import GlobalSelectionLink from 'sentry/components/globalSelectionLink';
  7. import * as Layout from 'sentry/components/layouts/thirds';
  8. import {PageHeadingQuestionTooltip} from 'sentry/components/pageHeadingQuestionTooltip';
  9. import {IconSettings} from 'sentry/icons';
  10. import {t} from 'sentry/locale';
  11. import ProjectsStore from 'sentry/stores/projectsStore';
  12. import type {InjectedRouter} from 'sentry/types/legacyReactRouter';
  13. import useOrganization from 'sentry/utils/useOrganization';
  14. import usePageFilters from 'sentry/utils/usePageFilters';
  15. type Props = {
  16. activeTab: 'stream' | 'rules';
  17. router: InjectedRouter;
  18. };
  19. function AlertHeader({router, activeTab}: Props) {
  20. const organization = useOrganization();
  21. const {selection} = usePageFilters();
  22. /**
  23. * Incidents list is currently at the organization level, but the link needs to
  24. * go down to a specific project scope.
  25. */
  26. const handleNavigateToSettings = (e: React.MouseEvent) => {
  27. e.preventDefault();
  28. navigateTo(`/settings/${organization.slug}/projects/:projectId/alerts/`, router);
  29. };
  30. const alertRulesLink = (
  31. <li className={activeTab === 'rules' ? 'active' : ''}>
  32. <GlobalSelectionLink to={`/organizations/${organization.slug}/alerts/rules/`}>
  33. {t('Alert Rules')}
  34. </GlobalSelectionLink>
  35. </li>
  36. );
  37. return (
  38. <Layout.Header>
  39. <Layout.HeaderContent>
  40. <Layout.Title>
  41. {t('Alerts')}
  42. <PageHeadingQuestionTooltip
  43. docsUrl="https://docs.sentry.io/product/alerts/"
  44. title={t(
  45. 'Real-time visibility into problems with your code and the impact on your users, along with a view of your existing alert rules, their status, project, team, and creation date.'
  46. )}
  47. />
  48. </Layout.Title>
  49. </Layout.HeaderContent>
  50. <Layout.HeaderActions>
  51. <ButtonBar gap={1}>
  52. <CreateAlertButton
  53. organization={organization}
  54. iconProps={{size: 'sm'}}
  55. size="sm"
  56. priority="primary"
  57. referrer="alert_stream"
  58. showPermissionGuide
  59. projectSlug={
  60. selection.projects.length === 1
  61. ? ProjectsStore.getById(`${selection.projects[0]}`)?.slug
  62. : undefined
  63. }
  64. >
  65. {t('Create Alert')}
  66. </CreateAlertButton>
  67. <FeedbackWidgetButton />
  68. <LinkButton
  69. size="sm"
  70. onClick={handleNavigateToSettings}
  71. href="#"
  72. icon={<IconSettings size="sm" />}
  73. aria-label={t('Settings')}
  74. />
  75. </ButtonBar>
  76. </Layout.HeaderActions>
  77. <Layout.HeaderNavTabs underlined>
  78. {alertRulesLink}
  79. <li className={activeTab === 'stream' ? 'active' : ''}>
  80. <GlobalSelectionLink to={`/organizations/${organization.slug}/alerts/`}>
  81. {t('History')}
  82. </GlobalSelectionLink>
  83. </li>
  84. </Layout.HeaderNavTabs>
  85. </Layout.Header>
  86. );
  87. }
  88. export default AlertHeader;