addIntegrationButton.tsx 2.0 KB

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