addIntegrationButton.tsx 1.7 KB

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