header.tsx 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import type {InjectedRouter} from 'react-router';
  2. import {navigateTo} from 'sentry/actionCreators/navigation';
  3. import {Button} from 'sentry/components/button';
  4. import ButtonBar from 'sentry/components/buttonBar';
  5. import CreateAlertButton from 'sentry/components/createAlertButton';
  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 useOrganization from 'sentry/utils/useOrganization';
  13. import usePageFilters from 'sentry/utils/usePageFilters';
  14. type Props = {
  15. activeTab: 'stream' | 'rules';
  16. router: InjectedRouter;
  17. };
  18. function AlertHeader({router, activeTab}: Props) {
  19. const organization = useOrganization();
  20. const {selection} = usePageFilters();
  21. /**
  22. * Incidents list is currently at the organization level, but the link needs to
  23. * go down to a specific project scope.
  24. */
  25. const handleNavigateToSettings = (e: React.MouseEvent) => {
  26. e.preventDefault();
  27. navigateTo(`/settings/${organization.slug}/projects/:projectId/alerts/`, router);
  28. };
  29. const alertRulesLink = (
  30. <li className={activeTab === 'rules' ? 'active' : ''}>
  31. <GlobalSelectionLink to={`/organizations/${organization.slug}/alerts/rules/`}>
  32. {t('Alert Rules')}
  33. </GlobalSelectionLink>
  34. </li>
  35. );
  36. return (
  37. <Layout.Header>
  38. <Layout.HeaderContent>
  39. <Layout.Title>
  40. {t('Alerts')}
  41. <PageHeadingQuestionTooltip
  42. docsUrl="https://docs.sentry.io/product/alerts/"
  43. title={t(
  44. '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.'
  45. )}
  46. />
  47. </Layout.Title>
  48. </Layout.HeaderContent>
  49. <Layout.HeaderActions>
  50. <ButtonBar gap={1}>
  51. <CreateAlertButton
  52. organization={organization}
  53. iconProps={{size: 'sm'}}
  54. size="sm"
  55. priority="primary"
  56. referrer="alert_stream"
  57. showPermissionGuide
  58. projectSlug={
  59. selection.projects.length === 1
  60. ? ProjectsStore.getById(`${selection.projects[0]}`)?.slug
  61. : undefined
  62. }
  63. >
  64. {t('Create Alert')}
  65. </CreateAlertButton>
  66. <Button
  67. size="sm"
  68. onClick={handleNavigateToSettings}
  69. href="#"
  70. icon={<IconSettings size="sm" />}
  71. aria-label={t('Settings')}
  72. />
  73. </ButtonBar>
  74. </Layout.HeaderActions>
  75. <Layout.HeaderNavTabs underlined>
  76. {alertRulesLink}
  77. <li className={activeTab === 'stream' ? 'active' : ''}>
  78. <GlobalSelectionLink to={`/organizations/${organization.slug}/alerts/`}>
  79. {t('History')}
  80. </GlobalSelectionLink>
  81. </li>
  82. </Layout.HeaderNavTabs>
  83. </Layout.Header>
  84. );
  85. }
  86. export default AlertHeader;