createMetricAlertFeature.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import Feature, {type ChildrenRenderFn} from 'sentry/components/acl/feature';
  2. import FeatureDisabled from 'sentry/components/acl/featureDisabled';
  3. import {Hovercard} from 'sentry/components/hovercard';
  4. import {Tooltip} from 'sentry/components/tooltip';
  5. import {t} from 'sentry/locale';
  6. import useOrganization from 'sentry/utils/useOrganization';
  7. interface Props {
  8. children: React.ReactNode | ChildrenRenderFn;
  9. }
  10. export function CreateMetricAlertFeature({children}: Props) {
  11. const organization = useOrganization();
  12. const hasPermission = organization.access.includes('alerts:write');
  13. return (
  14. <Feature
  15. features={['organizations:incidents']}
  16. organization={organization}
  17. hookName="feature-disabled:create-metrics-alert-tooltip"
  18. renderDisabled={p => (
  19. <Hovercard
  20. body={
  21. <FeatureDisabled
  22. features={p.features}
  23. hideHelpToggle
  24. featureName={t('Metric Alerts')}
  25. />
  26. }
  27. >
  28. {typeof p.children === 'function' ? p.children(p) : p.children}
  29. </Hovercard>
  30. )}
  31. >
  32. {p => (
  33. <Tooltip
  34. title={t('You do not have permission to create alerts')}
  35. disabled={!p.hasFeature || hasPermission}
  36. >
  37. {typeof children === 'function'
  38. ? children({...p, hasFeature: p.hasFeature && hasPermission})
  39. : children}
  40. </Tooltip>
  41. )}
  42. </Feature>
  43. );
  44. }