integrationButton.tsx 2.2 KB

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