header.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import {InjectedRouter} from 'react-router';
  2. import styled from '@emotion/styled';
  3. import {navigateTo} from 'sentry/actionCreators/navigation';
  4. import Button from 'sentry/components/button';
  5. import ButtonBar from 'sentry/components/buttonBar';
  6. import CreateAlertButton from 'sentry/components/createAlertButton';
  7. import GlobalSelectionLink from 'sentry/components/globalSelectionLink';
  8. import * as Layout from 'sentry/components/layouts/thirds';
  9. import {IconSettings} from 'sentry/icons';
  10. import {t} from 'sentry/locale';
  11. import ProjectsStore from 'sentry/stores/projectsStore';
  12. import space from 'sentry/styles/space';
  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. const 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. <StyledLayoutTitle>{t('Alerts')}</StyledLayoutTitle>
  41. </Layout.HeaderContent>
  42. <Layout.HeaderActions>
  43. <Actions gap={1}>
  44. <CreateAlertButton
  45. organization={organization}
  46. iconProps={{size: 'sm'}}
  47. size="sm"
  48. priority="primary"
  49. referrer="alert_stream"
  50. showPermissionGuide
  51. projectSlug={
  52. selection.projects.length === 1
  53. ? ProjectsStore.getById(`${selection.projects[0]}`)?.slug
  54. : undefined
  55. }
  56. >
  57. {t('Create Alert')}
  58. </CreateAlertButton>
  59. <Button
  60. size="sm"
  61. onClick={handleNavigateToSettings}
  62. href="#"
  63. icon={<IconSettings size="sm" />}
  64. aria-label={t('Settings')}
  65. />
  66. </Actions>
  67. </Layout.HeaderActions>
  68. <Layout.HeaderNavTabs underlined>
  69. {alertRulesLink}
  70. <li className={activeTab === 'stream' ? 'active' : ''}>
  71. <GlobalSelectionLink to={`/organizations/${organization.slug}/alerts/`}>
  72. {t('History')}
  73. </GlobalSelectionLink>
  74. </li>
  75. </Layout.HeaderNavTabs>
  76. </Layout.Header>
  77. );
  78. };
  79. export default AlertHeader;
  80. const StyledLayoutTitle = styled(Layout.Title)`
  81. margin-top: ${space(0.5)};
  82. `;
  83. const Actions = styled(ButtonBar)`
  84. height: 32px;
  85. `;