header.tsx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 space from 'sentry/styles/space';
  12. import {Organization} from 'sentry/types';
  13. type Props = {
  14. activeTab: 'stream' | 'rules';
  15. organization: Organization;
  16. projectSlugs: string[];
  17. router: InjectedRouter;
  18. };
  19. const AlertHeader = ({router, organization, activeTab, projectSlugs}: Props) => {
  20. /**
  21. * Incidents list is currently at the organization level, but the link needs to
  22. * go down to a specific project scope.
  23. */
  24. const handleNavigateToSettings = (e: React.MouseEvent) => {
  25. e.preventDefault();
  26. navigateTo(`/settings/${organization.slug}/projects/:projectId/alerts/`, router);
  27. };
  28. const alertRulesLink = (
  29. <li className={activeTab === 'rules' ? 'active' : ''}>
  30. <GlobalSelectionLink to={`/organizations/${organization.slug}/alerts/rules/`}>
  31. {t('Alert Rules')}
  32. </GlobalSelectionLink>
  33. </li>
  34. );
  35. return (
  36. <Layout.Header>
  37. <Layout.HeaderContent>
  38. <StyledLayoutTitle>{t('Alerts')}</StyledLayoutTitle>
  39. </Layout.HeaderContent>
  40. <Layout.HeaderActions>
  41. <Actions gap={1}>
  42. <CreateAlertButton
  43. organization={organization}
  44. iconProps={{size: 'sm'}}
  45. priority="primary"
  46. referrer="alert_stream"
  47. showPermissionGuide
  48. projectSlug={projectSlugs.length === 1 ? projectSlugs[0] : undefined}
  49. >
  50. {t('Create Alert')}
  51. </CreateAlertButton>
  52. <Button
  53. onClick={handleNavigateToSettings}
  54. href="#"
  55. icon={<IconSettings size="sm" />}
  56. aria-label={t('Settings')}
  57. />
  58. </Actions>
  59. </Layout.HeaderActions>
  60. <Layout.HeaderNavTabs underlined>
  61. {alertRulesLink}
  62. <li className={activeTab === 'stream' ? 'active' : ''}>
  63. <GlobalSelectionLink to={`/organizations/${organization.slug}/alerts/`}>
  64. {t('History')}
  65. </GlobalSelectionLink>
  66. </li>
  67. </Layout.HeaderNavTabs>
  68. </Layout.Header>
  69. );
  70. };
  71. export default AlertHeader;
  72. const StyledLayoutTitle = styled(Layout.Title)`
  73. margin-top: ${space(0.5)};
  74. `;
  75. const Actions = styled(ButtonBar)`
  76. height: 32px;
  77. `;