addIntegrationButton.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 {trackAnalytics} from 'sentry/utils/analytics';
  6. import AddIntegration from './addIntegration';
  7. interface AddIntegrationButtonProps
  8. extends Omit<ButtonProps, 'children' | 'analyticsParams'>,
  9. Pick<
  10. React.ComponentProps<typeof AddIntegration>,
  11. 'provider' | 'organization' | 'analyticsParams' | 'modalParams'
  12. > {
  13. onAddIntegration: (data: IntegrationWithConfig) => void;
  14. buttonText?: string;
  15. installStatus?: string;
  16. reinstall?: boolean;
  17. }
  18. export function AddIntegrationButton({
  19. provider,
  20. buttonText,
  21. onAddIntegration,
  22. organization,
  23. reinstall,
  24. analyticsParams,
  25. modalParams,
  26. installStatus,
  27. ...buttonProps
  28. }: AddIntegrationButtonProps) {
  29. const label =
  30. buttonText ?? reinstall
  31. ? t('Enable')
  32. : installStatus === 'Disabled'
  33. ? t('Reinstall')
  34. : t('Add %s', provider.metadata.noun);
  35. return (
  36. <Tooltip
  37. disabled={provider.canAdd}
  38. title={`Integration cannot be added on Sentry. Enable this integration via the ${provider.name} instance.`}
  39. >
  40. <AddIntegration
  41. provider={provider}
  42. onInstall={onAddIntegration}
  43. organization={organization}
  44. analyticsParams={analyticsParams}
  45. modalParams={modalParams}
  46. >
  47. {onClick => (
  48. <Button
  49. disabled={!provider.canAdd}
  50. {...buttonProps}
  51. onClick={() => {
  52. if (label === t('Reinstall')) {
  53. trackAnalytics('integrations.integration_reinstall_clicked', {
  54. organization,
  55. provider: provider.metadata.noun,
  56. });
  57. }
  58. onClick();
  59. }}
  60. aria-label={t('Add integration')}
  61. >
  62. {label}
  63. </Button>
  64. )}
  65. </AddIntegration>
  66. </Tooltip>
  67. );
  68. }