index.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import {cloneElement, isValidElement} from 'react';
  2. import {useRedirectNavV2Routes} from 'sentry/components/nav/useRedirectNavV2Routes';
  3. import NoProjectMessage from 'sentry/components/noProjectMessage';
  4. import Redirect from 'sentry/components/redirect';
  5. import useOrganization from 'sentry/utils/useOrganization';
  6. type Props = {
  7. children: React.ReactNode;
  8. };
  9. function AlertsContainer({children}: Props) {
  10. const organization = useOrganization();
  11. const hasMetricAlerts = organization.features.includes('incidents');
  12. // Uptime alerts are not behind a feature flag at the moment
  13. const hasUptimeAlerts = true;
  14. const content =
  15. children && isValidElement(children)
  16. ? cloneElement<any>(children, {
  17. organization,
  18. hasMetricAlerts,
  19. hasUptimeAlerts,
  20. })
  21. : children;
  22. const redirectPath = useRedirectNavV2Routes({
  23. oldPathPrefix: '/alerts/',
  24. newPathPrefix: '/issues/alerts/',
  25. });
  26. if (redirectPath) {
  27. return <Redirect to={redirectPath} />;
  28. }
  29. return <NoProjectMessage organization={organization}>{content}</NoProjectMessage>;
  30. }
  31. export default AlertsContainer;