header.tsx 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 FeedbackWidgetButton from 'sentry/components/feedback/widget/feedbackWidgetButton';
  7. import GlobalSelectionLink from 'sentry/components/globalSelectionLink';
  8. import * as Layout from 'sentry/components/layouts/thirds';
  9. import {PageHeadingQuestionTooltip} from 'sentry/components/pageHeadingQuestionTooltip';
  10. import {IconSettings} from 'sentry/icons';
  11. import {t} from 'sentry/locale';
  12. import ProjectsStore from 'sentry/stores/projectsStore';
  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. <Button
  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;