header.tsx 3.3 KB

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