platform.tsx 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. import {Component, Fragment} from 'react';
  2. import {browserHistory, RouteComponentProps} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import {loadDocs} from 'sentry/actionCreators/projects';
  5. import {Client} from 'sentry/api';
  6. import Feature from 'sentry/components/acl/feature';
  7. import {Alert} from 'sentry/components/alert';
  8. import {Button} from 'sentry/components/button';
  9. import ButtonBar from 'sentry/components/buttonBar';
  10. import NotFound from 'sentry/components/errors/notFound';
  11. import LoadingError from 'sentry/components/loadingError';
  12. import LoadingIndicator from 'sentry/components/loadingIndicator';
  13. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  14. import {
  15. performance as performancePlatforms,
  16. PlatformKey,
  17. } from 'sentry/data/platformCategories';
  18. import platforms from 'sentry/data/platforms';
  19. import {IconChevron} from 'sentry/icons';
  20. import {t, tct} from 'sentry/locale';
  21. import space from 'sentry/styles/space';
  22. import {Organization, Project} from 'sentry/types';
  23. import Projects from 'sentry/utils/projects';
  24. import withApi from 'sentry/utils/withApi';
  25. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  26. import withOrganization from 'sentry/utils/withOrganization';
  27. import {HeartbeatFooter} from 'sentry/views/onboarding/components/heartbeatFooter';
  28. type Props = {
  29. api: Client;
  30. organization: Organization;
  31. } & RouteComponentProps<{platform: string; projectId: string}, {}>;
  32. type State = {
  33. error: boolean;
  34. html: string;
  35. loading: boolean;
  36. };
  37. class ProjectInstallPlatform extends Component<Props, State> {
  38. state: State = {
  39. loading: true,
  40. error: false,
  41. html: '',
  42. };
  43. componentDidMount() {
  44. this.fetchData();
  45. window.scrollTo(0, 0);
  46. const {platform} = this.props.params;
  47. // redirect if platform is not known.
  48. if (!platform || platform === 'other') {
  49. this.redirectToNeutralDocs();
  50. }
  51. }
  52. get isGettingStarted() {
  53. return window.location.href.indexOf('getting-started') > 0;
  54. }
  55. fetchData = async () => {
  56. const {api, organization, params} = this.props;
  57. const {projectId, platform} = params;
  58. this.setState({loading: true});
  59. try {
  60. const {html} = await loadDocs(
  61. api,
  62. organization.slug,
  63. projectId,
  64. platform as PlatformKey
  65. );
  66. this.setState({html});
  67. } catch (error) {
  68. this.setState({error});
  69. }
  70. this.setState({loading: false});
  71. };
  72. redirectToNeutralDocs() {
  73. const {organization} = this.props;
  74. const {projectId} = this.props.params;
  75. const url = `/organizations/${organization.slug}/projects/${projectId}/getting-started/`;
  76. browserHistory.push(normalizeUrl(url));
  77. }
  78. render() {
  79. const {params, organization} = this.props;
  80. const {projectId} = params;
  81. const platform = platforms.find(p => p.id === params.platform);
  82. if (!platform) {
  83. return <NotFound />;
  84. }
  85. const issueStreamLink = `/organizations/${organization.slug}/issues/`;
  86. const performanceOverviewLink = `/organizations/${organization.slug}/performance/`;
  87. const gettingStartedLink = `/organizations/${organization.slug}/projects/${projectId}/getting-started/`;
  88. const platformLink = platform.link ?? undefined;
  89. const showPerformancePrompt = performancePlatforms.includes(
  90. platform.id as PlatformKey
  91. );
  92. const heartbeatFooter = !!organization?.features.includes(
  93. 'onboarding-heartbeat-footer'
  94. );
  95. return (
  96. <Fragment>
  97. <StyledPageHeader>
  98. <h2>{t('Configure %(platform)s', {platform: platform.name})}</h2>
  99. <ButtonBar gap={1}>
  100. <Button
  101. icon={<IconChevron direction="left" size="sm" />}
  102. size="sm"
  103. to={gettingStartedLink}
  104. >
  105. {t('Back')}
  106. </Button>
  107. <Button size="sm" href={platformLink} external>
  108. {t('Full Documentation')}
  109. </Button>
  110. </ButtonBar>
  111. </StyledPageHeader>
  112. <div>
  113. <Alert type="info" showIcon>
  114. {tct(
  115. `
  116. This is a quick getting started guide. For in-depth instructions
  117. on integrating Sentry with [platform], view
  118. [docLink:our complete documentation].`,
  119. {
  120. platform: platform.name,
  121. docLink: <a href={platformLink} />,
  122. }
  123. )}
  124. </Alert>
  125. {this.state.loading ? (
  126. <LoadingIndicator />
  127. ) : this.state.error ? (
  128. <LoadingError onRetry={this.fetchData} />
  129. ) : (
  130. <Fragment>
  131. <SentryDocumentTitle
  132. title={`${t('Configure')} ${platform.name}`}
  133. projectSlug={projectId}
  134. />
  135. <DocumentationWrapper dangerouslySetInnerHTML={{__html: this.state.html}} />
  136. </Fragment>
  137. )}
  138. {this.isGettingStarted && showPerformancePrompt && (
  139. <Feature
  140. features={['performance-view']}
  141. hookName="feature-disabled:performance-new-project"
  142. >
  143. {({hasFeature}) => {
  144. if (hasFeature) {
  145. return null;
  146. }
  147. return (
  148. <StyledAlert type="info" showIcon>
  149. {t(
  150. `Your selected platform supports performance, but your organization does not have performance enabled.`
  151. )}
  152. </StyledAlert>
  153. );
  154. }}
  155. </Feature>
  156. )}
  157. {this.isGettingStarted && heartbeatFooter ? (
  158. <HeartbeatFooter
  159. projectSlug={projectId}
  160. route={this.props.route}
  161. router={this.props.router}
  162. location={this.props.location}
  163. />
  164. ) : (
  165. <Projects
  166. key={`${organization.slug}-${projectId}`}
  167. orgId={organization.slug}
  168. slugs={[projectId]}
  169. passthroughPlaceholderProject={false}
  170. >
  171. {({projects, initiallyLoaded, fetching, fetchError}) => {
  172. const projectsLoading = !initiallyLoaded && fetching;
  173. const projectFilter =
  174. !projectsLoading && !fetchError && projects.length
  175. ? {
  176. project: (projects[0] as Project).id,
  177. }
  178. : {};
  179. return (
  180. <StyledButtonBar gap={1}>
  181. <Button
  182. priority="primary"
  183. busy={projectsLoading}
  184. to={{
  185. pathname: issueStreamLink,
  186. query: projectFilter,
  187. hash: '#welcome',
  188. }}
  189. >
  190. {t('Take me to Issues')}
  191. </Button>
  192. <Button
  193. busy={projectsLoading}
  194. to={{
  195. pathname: performanceOverviewLink,
  196. query: projectFilter,
  197. }}
  198. >
  199. {t('Take me to Performance')}
  200. </Button>
  201. </StyledButtonBar>
  202. );
  203. }}
  204. </Projects>
  205. )}
  206. </div>
  207. </Fragment>
  208. );
  209. }
  210. }
  211. const DocumentationWrapper = styled('div')`
  212. line-height: 1.5;
  213. .gatsby-highlight {
  214. margin-bottom: ${space(3)};
  215. &:last-child {
  216. margin-bottom: 0;
  217. }
  218. }
  219. .alert {
  220. margin-bottom: ${space(3)};
  221. border-radius: ${p => p.theme.borderRadius};
  222. }
  223. blockquote {
  224. padding: ${space(1)};
  225. margin-left: 0;
  226. background: ${p => p.theme.alert.info.backgroundLight};
  227. border-left: 2px solid ${p => p.theme.alert.info.border};
  228. }
  229. blockquote > *:last-child {
  230. margin-bottom: 0;
  231. }
  232. `;
  233. const StyledButtonBar = styled(ButtonBar)`
  234. margin-top: ${space(3)};
  235. width: max-content;
  236. @media (max-width: ${p => p.theme.breakpoints.small}) {
  237. width: auto;
  238. grid-row-gap: ${space(1)};
  239. grid-auto-flow: row;
  240. }
  241. `;
  242. const StyledPageHeader = styled('div')`
  243. display: flex;
  244. justify-content: space-between;
  245. margin-bottom: ${space(3)};
  246. h2 {
  247. margin: 0;
  248. }
  249. @media (max-width: ${p => p.theme.breakpoints.small}) {
  250. flex-direction: column;
  251. align-items: flex-start;
  252. h2 {
  253. margin-bottom: ${space(2)};
  254. }
  255. }
  256. `;
  257. const StyledAlert = styled(Alert)`
  258. margin-top: ${space(2)};
  259. `;
  260. export {ProjectInstallPlatform};
  261. export default withApi(withOrganization(ProjectInstallPlatform));