platformIntegrationSetup.tsx 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. import {Fragment} from 'react';
  2. import type {RouteComponentProps} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import {Button} from 'sentry/components/button';
  5. import ButtonBar from 'sentry/components/buttonBar';
  6. import DeprecatedAsyncComponent from 'sentry/components/deprecatedAsyncComponent';
  7. import platforms from 'sentry/data/platforms';
  8. import {t} from 'sentry/locale';
  9. import {space} from 'sentry/styles/space';
  10. import type {IntegrationProvider, Organization, Project} from 'sentry/types';
  11. import {trackAnalytics} from 'sentry/utils/analytics';
  12. import {browserHistory} from 'sentry/utils/browserHistory';
  13. import {trackIntegrationAnalytics} from 'sentry/utils/integrationUtil';
  14. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  15. import withOrganization from 'sentry/utils/withOrganization';
  16. import AddInstallationInstructions from 'sentry/views/onboarding/components/integrations/addInstallationInstructions';
  17. import PostInstallCodeSnippet from 'sentry/views/onboarding/components/integrations/postInstallCodeSnippet';
  18. import {AddIntegrationButton} from 'sentry/views/settings/organizationIntegrations/addIntegrationButton';
  19. import FirstEventFooter from './components/firstEventFooter';
  20. import PlatformHeaderButtonBar from './components/platformHeaderButtonBar';
  21. type Props = {
  22. integrationSlug: string;
  23. organization: Organization;
  24. } & RouteComponentProps<{platform: string; projectId: string}, {}> &
  25. DeprecatedAsyncComponent['props'];
  26. type State = {
  27. installed: boolean;
  28. integrations: {providers: IntegrationProvider[]};
  29. project: Project | null;
  30. } & DeprecatedAsyncComponent['state'];
  31. class PlatformIntegrationSetup extends DeprecatedAsyncComponent<Props, State> {
  32. getDefaultState() {
  33. return {
  34. ...super.getDefaultState(),
  35. installed: false,
  36. integrations: {providers: []},
  37. project: null,
  38. };
  39. }
  40. componentDidMount() {
  41. super.componentDidMount();
  42. window.scrollTo(0, 0);
  43. const {platform} = this.props.params;
  44. // redirect if platform is not known.
  45. if (!platform || platform === 'other') {
  46. this.redirectToNeutralDocs();
  47. }
  48. }
  49. get provider() {
  50. const {providers} = this.state.integrations;
  51. return providers.length ? providers[0] : null;
  52. }
  53. getEndpoints(): ReturnType<DeprecatedAsyncComponent['getEndpoints']> {
  54. const {organization, integrationSlug, params} = this.props;
  55. if (!integrationSlug) {
  56. return [];
  57. }
  58. return [
  59. [
  60. 'integrations',
  61. `/organizations/${organization.slug}/config/integrations/?provider_key=${integrationSlug}`,
  62. ],
  63. ['project', `/projects/${organization.slug}/${params.projectId}/`],
  64. ];
  65. }
  66. handleFullDocsClick = () => {
  67. const {organization} = this.props;
  68. trackAnalytics('growth.onboarding_view_full_docs', {organization});
  69. };
  70. redirectToNeutralDocs() {
  71. const {organization} = this.props;
  72. const {projectId} = this.props.params;
  73. const url = `/organizations/${organization.slug}/projects/${projectId}/getting-started/`;
  74. browserHistory.push(normalizeUrl(url));
  75. }
  76. handleAddIntegration = () => {
  77. this.setState({installed: true});
  78. };
  79. trackSwitchToManual = () => {
  80. const {organization, integrationSlug} = this.props;
  81. trackIntegrationAnalytics('integrations.switch_manual_sdk_setup', {
  82. integration_type: 'first_party',
  83. integration: integrationSlug,
  84. view: 'project_creation',
  85. organization,
  86. });
  87. };
  88. render() {
  89. const {organization, params} = this.props;
  90. const {installed, project} = this.state;
  91. const {projectId, platform} = params;
  92. const provider = this.provider;
  93. const platformIntegration = platforms.find(p => p.id === platform);
  94. if (!provider || !platformIntegration || !project) {
  95. return null;
  96. }
  97. const gettingStartedLink = `/organizations/${organization.slug}/projects/${projectId}/getting-started/`;
  98. // TODO: make dynamic when adding more integrations
  99. const docsLink =
  100. 'https://docs.sentry.io/product/integrations/cloud-monitoring/aws-lambda/';
  101. return (
  102. <OuterWrapper>
  103. <InnerWrapper>
  104. <StyledTitle>
  105. {t('Automatically instrument %s', platformIntegration.name)}
  106. </StyledTitle>
  107. <HeaderButtons>
  108. <PlatformHeaderButtonBar
  109. gettingStartedLink={gettingStartedLink}
  110. docsLink={docsLink}
  111. />
  112. </HeaderButtons>
  113. {!installed ? (
  114. <Fragment>
  115. <AddInstallationInstructions />
  116. <StyledButtonBar gap={1}>
  117. <AddIntegrationButton
  118. provider={provider}
  119. onAddIntegration={this.handleAddIntegration}
  120. organization={organization}
  121. priority="primary"
  122. size="sm"
  123. analyticsParams={{view: 'project_creation', already_installed: false}}
  124. modalParams={{projectId: project.id}}
  125. aria-label={t('Add integration')}
  126. />
  127. <Button
  128. size="sm"
  129. to={{
  130. pathname: window.location.pathname,
  131. query: {manual: '1'},
  132. }}
  133. onClick={this.trackSwitchToManual}
  134. >
  135. {t('Manual Setup')}
  136. </Button>
  137. </StyledButtonBar>
  138. </Fragment>
  139. ) : (
  140. <Fragment>
  141. <PostInstallCodeSnippet provider={provider} />
  142. <FirstEventFooter
  143. project={project}
  144. organization={organization}
  145. docsLink={docsLink}
  146. docsOnClick={this.handleFullDocsClick}
  147. />
  148. </Fragment>
  149. )}
  150. </InnerWrapper>
  151. </OuterWrapper>
  152. );
  153. }
  154. }
  155. const StyledButtonBar = styled(ButtonBar)`
  156. margin-top: ${space(3)};
  157. width: max-content;
  158. @media (max-width: ${p => p.theme.breakpoints.small}) {
  159. width: auto;
  160. grid-row-gap: ${space(1)};
  161. grid-auto-flow: row;
  162. }
  163. `;
  164. const InnerWrapper = styled('div')`
  165. max-width: 850px;
  166. `;
  167. const OuterWrapper = styled('div')`
  168. display: flex;
  169. flex-direction: column;
  170. align-items: center;
  171. margin-top: 50px;
  172. `;
  173. const HeaderButtons = styled('div')`
  174. width: min-content;
  175. margin-bottom: ${space(3)};
  176. `;
  177. const StyledTitle = styled('h2')`
  178. margin: 0;
  179. margin-bottom: ${space(2)};
  180. `;
  181. export default withOrganization(PlatformIntegrationSetup);