header.tsx 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. priority="primary"
  48. referrer="alert_stream"
  49. showPermissionGuide
  50. projectSlug={
  51. selection.projects.length === 1
  52. ? ProjectsStore.getById(`${selection.projects[0]}`)?.slug
  53. : undefined
  54. }
  55. >
  56. {t('Create Alert')}
  57. </CreateAlertButton>
  58. <Button
  59. onClick={handleNavigateToSettings}
  60. href="#"
  61. icon={<IconSettings size="sm" />}
  62. aria-label={t('Settings')}
  63. />
  64. </Actions>
  65. </Layout.HeaderActions>
  66. <Layout.HeaderNavTabs underlined>
  67. {alertRulesLink}
  68. <li className={activeTab === 'stream' ? 'active' : ''}>
  69. <GlobalSelectionLink to={`/organizations/${organization.slug}/alerts/`}>
  70. {t('History')}
  71. </GlobalSelectionLink>
  72. </li>
  73. </Layout.HeaderNavTabs>
  74. </Layout.Header>
  75. );
  76. };
  77. export default AlertHeader;
  78. const StyledLayoutTitle = styled(Layout.Title)`
  79. margin-top: ${space(0.5)};
  80. `;
  81. const Actions = styled(ButtonBar)`
  82. height: 32px;
  83. `;