addIntegrationRow.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import {useContext} from 'react';
  2. import styled from '@emotion/styled';
  3. import Access from 'sentry/components/acl/access';
  4. import {LinkButton} from 'sentry/components/button';
  5. import PluginIcon from 'sentry/plugins/components/pluginIcon';
  6. import ConfigStore from 'sentry/stores/configStore';
  7. import {space} from 'sentry/styles/space';
  8. import useOrganization from 'sentry/utils/useOrganization';
  9. import IntegrationButton from 'sentry/views/settings/organizationIntegrations/integrationButton';
  10. import {IntegrationContext} from 'sentry/views/settings/organizationIntegrations/integrationContext';
  11. type Props = {
  12. onClick: () => void;
  13. };
  14. function AddIntegrationRow({onClick}: Props) {
  15. const organization = useOrganization();
  16. const {isSelfHosted} = ConfigStore.getState();
  17. const integration = useContext(IntegrationContext);
  18. if (!integration) {
  19. return null;
  20. }
  21. const provider = integration.provider;
  22. const onAddIntegration = () => {
  23. integration.onAddIntegration?.();
  24. onClick();
  25. };
  26. const buttonProps = {
  27. size: 'sm',
  28. priority: 'primary',
  29. 'data-test-id': 'install-button',
  30. };
  31. return (
  32. <RowWrapper>
  33. <IconTextWrapper>
  34. <PluginIcon pluginId={provider.slug} size={40} />
  35. <NameHeader>Connect {provider.name}</NameHeader>
  36. </IconTextWrapper>
  37. <Access access={['org:integrations']} organization={organization}>
  38. {({hasAccess}) => {
  39. return isSelfHosted ? (
  40. <LinkButton
  41. href={`https://develop.sentry.dev/integrations/${provider.slug}`}
  42. priority="primary"
  43. external
  44. >
  45. Add {provider.metadata.noun}
  46. </LinkButton>
  47. ) : (
  48. <StyledButton
  49. userHasAccess={hasAccess}
  50. onAddIntegration={onAddIntegration}
  51. onExternalClick={onClick}
  52. externalInstallText={`Add ${provider.metadata.noun}`}
  53. buttonProps={buttonProps}
  54. />
  55. );
  56. }}
  57. </Access>
  58. </RowWrapper>
  59. );
  60. }
  61. const RowWrapper = styled('div')`
  62. display: flex;
  63. border-radius: 4px;
  64. border: 1px solid ${p => p.theme.gray200};
  65. justify-content: space-between;
  66. align-items: center;
  67. padding: ${space(3)} ${space(4)};
  68. `;
  69. const IconTextWrapper = styled('div')`
  70. display: flex;
  71. align-items: center;
  72. gap: ${space(3)};
  73. `;
  74. const NameHeader = styled('h6')`
  75. margin: 0;
  76. `;
  77. const StyledButton = styled(IntegrationButton)`
  78. margin: 0;
  79. `;
  80. export default AddIntegrationRow;