integrationButton.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import {useContext} from 'react';
  2. import {LinkButton} from 'sentry/components/button';
  3. import {IconOpen} from 'sentry/icons';
  4. import type {Integration} from 'sentry/types/integrations';
  5. import useOrganization from 'sentry/utils/useOrganization';
  6. import {AddIntegrationButton} from 'sentry/views/settings/organizationIntegrations/addIntegrationButton';
  7. import {IntegrationContext} from 'sentry/views/settings/organizationIntegrations/integrationContext';
  8. import RequestIntegrationButton from 'sentry/views/settings/organizationIntegrations/integrationRequest/RequestIntegrationButton';
  9. type Props = {
  10. buttonProps: ButtonProps;
  11. onAddIntegration: (integration: Integration) => void;
  12. onExternalClick: () => void;
  13. userHasAccess: boolean;
  14. externalInstallText?: string;
  15. };
  16. type ButtonProps = {
  17. disabled?;
  18. priority?;
  19. size?;
  20. style?;
  21. } | null;
  22. function IntegrationButton({
  23. userHasAccess,
  24. onAddIntegration,
  25. onExternalClick,
  26. externalInstallText,
  27. buttonProps,
  28. }: Props) {
  29. const organization = useOrganization();
  30. const {provider, type, installStatus, analyticsParams, modalParams} =
  31. useContext(IntegrationContext) ?? {};
  32. if (!provider || !type) {
  33. return null;
  34. }
  35. const {metadata} = provider;
  36. if (!userHasAccess) {
  37. return (
  38. <RequestIntegrationButton
  39. organization={organization}
  40. name={provider.name}
  41. slug={provider.slug}
  42. type={type}
  43. />
  44. );
  45. }
  46. if (provider.canAdd) {
  47. return (
  48. <AddIntegrationButton
  49. provider={provider}
  50. onAddIntegration={onAddIntegration}
  51. installStatus={installStatus}
  52. analyticsParams={analyticsParams}
  53. modalParams={modalParams}
  54. organization={organization}
  55. {...buttonProps}
  56. />
  57. );
  58. }
  59. if (metadata.aspects.externalInstall) {
  60. return (
  61. <LinkButton
  62. icon={externalInstallText ? null : <IconOpen />}
  63. href={metadata.aspects.externalInstall.url}
  64. onClick={onExternalClick}
  65. external
  66. {...buttonProps}
  67. >
  68. {externalInstallText
  69. ? externalInstallText
  70. : metadata.aspects.externalInstall.buttonText}
  71. </LinkButton>
  72. );
  73. }
  74. return null;
  75. }
  76. export default IntegrationButton;