platformIntegrationSetup.tsx 6.2 KB

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