addIntegrationButton.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import Button, {ButtonPropsWithoutAriaLabel} 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<ButtonPropsWithoutAriaLabel, 'children'>,
  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 = buttonText || t(reinstall ? 'Enable' : 'Add %s', provider.metadata.noun);
  27. return (
  28. <Tooltip
  29. disabled={provider.canAdd}
  30. title={`Integration cannot be added on Sentry. Enable this integration via the ${provider.name} instance.`}
  31. >
  32. <AddIntegration
  33. provider={provider}
  34. onInstall={onAddIntegration}
  35. organization={organization}
  36. analyticsParams={analyticsParams}
  37. modalParams={modalParams}
  38. >
  39. {onClick => (
  40. <Button
  41. disabled={!provider.canAdd}
  42. {...buttonProps}
  43. onClick={() => onClick()}
  44. aria-label={t('Add integration')}
  45. >
  46. {label}
  47. </Button>
  48. )}
  49. </AddIntegration>
  50. </Tooltip>
  51. );
  52. }