addIntegrationButton.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import {Button, ButtonProps} from 'sentry/components/button';
  2. import {Tooltip} from 'sentry/components/tooltip';
  3. import {t} from 'sentry/locale';
  4. import {IntegrationWithConfig} from 'sentry/types';
  5. import AddIntegration from './addIntegration';
  6. interface AddIntegrationButtonProps
  7. extends Omit<ButtonProps, 'children' | 'analyticsParams'>,
  8. Pick<
  9. React.ComponentProps<typeof AddIntegration>,
  10. 'provider' | 'organization' | 'analyticsParams' | 'modalParams'
  11. > {
  12. onAddIntegration: (data: IntegrationWithConfig) => void;
  13. buttonText?: string;
  14. reinstall?: boolean;
  15. }
  16. export function AddIntegrationButton({
  17. provider,
  18. buttonText,
  19. onAddIntegration,
  20. organization,
  21. reinstall,
  22. analyticsParams,
  23. modalParams,
  24. ...buttonProps
  25. }: AddIntegrationButtonProps) {
  26. const label =
  27. buttonText ?? (reinstall ? t('Enable') : t('Add %s', provider.metadata.noun));
  28. return (
  29. <Tooltip
  30. disabled={provider.canAdd}
  31. title={`Integration cannot be added on Sentry. Enable this integration via the ${provider.name} instance.`}
  32. >
  33. <AddIntegration
  34. provider={provider}
  35. onInstall={onAddIntegration}
  36. organization={organization}
  37. analyticsParams={analyticsParams}
  38. modalParams={modalParams}
  39. >
  40. {onClick => (
  41. <Button
  42. disabled={!provider.canAdd}
  43. {...buttonProps}
  44. onClick={() => onClick()}
  45. aria-label={t('Add integration')}
  46. >
  47. {label}
  48. </Button>
  49. )}
  50. </AddIntegration>
  51. </Tooltip>
  52. );
  53. }