integrationButton.tsx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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) return null;
  33. const {metadata} = provider;
  34. if (!userHasAccess) {
  35. return (
  36. <RequestIntegrationButton
  37. organization={organization}
  38. name={provider.name}
  39. slug={provider.slug}
  40. type={type}
  41. />
  42. );
  43. }
  44. if (provider.canAdd) {
  45. return (
  46. <AddIntegrationButton
  47. provider={provider}
  48. onAddIntegration={onAddIntegration}
  49. installStatus={installStatus}
  50. analyticsParams={analyticsParams}
  51. modalParams={modalParams}
  52. organization={organization}
  53. {...buttonProps}
  54. />
  55. );
  56. }
  57. if (metadata.aspects.externalInstall) {
  58. return (
  59. <LinkButton
  60. icon={externalInstallText ? null : <IconOpen />}
  61. href={metadata.aspects.externalInstall.url}
  62. onClick={onExternalClick}
  63. external
  64. {...buttonProps}
  65. >
  66. {externalInstallText
  67. ? externalInstallText
  68. : metadata.aspects.externalInstall.buttonText}
  69. </LinkButton>
  70. );
  71. }
  72. return null;
  73. }
  74. export default IntegrationButton;