platform.tsx 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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. return (
  93. <Fragment>
  94. <StyledPageHeader>
  95. <h2>{t('Configure %(platform)s', {platform: platform.name})}</h2>
  96. <ButtonBar gap={1}>
  97. <Button
  98. icon={<IconChevron direction="left" size="sm" />}
  99. size="sm"
  100. to={gettingStartedLink}
  101. >
  102. {t('Back')}
  103. </Button>
  104. <Button size="sm" href={platformLink} external>
  105. {t('Full Documentation')}
  106. </Button>
  107. </ButtonBar>
  108. </StyledPageHeader>
  109. <div>
  110. <Alert type="info" showIcon>
  111. {tct(
  112. `
  113. This is a quick getting started guide. For in-depth instructions
  114. on integrating Sentry with [platform], view
  115. [docLink:our complete documentation].`,
  116. {
  117. platform: platform.name,
  118. docLink: <a href={platformLink} />,
  119. }
  120. )}
  121. </Alert>
  122. {this.state.loading ? (
  123. <LoadingIndicator />
  124. ) : this.state.error ? (
  125. <LoadingError onRetry={this.fetchData} />
  126. ) : (
  127. <Fragment>
  128. <SentryDocumentTitle
  129. title={`${t('Configure')} ${platform.name}`}
  130. projectSlug={projectId}
  131. />
  132. <DocumentationWrapper dangerouslySetInnerHTML={{__html: this.state.html}} />
  133. </Fragment>
  134. )}
  135. {this.isGettingStarted && showPerformancePrompt && (
  136. <Feature
  137. features={['performance-view']}
  138. hookName="feature-disabled:performance-new-project"
  139. >
  140. {({hasFeature}) => {
  141. if (hasFeature) {
  142. return null;
  143. }
  144. return (
  145. <StyledAlert type="info" showIcon>
  146. {t(
  147. `Your selected platform supports performance, but your organization does not have performance enabled.`
  148. )}
  149. </StyledAlert>
  150. );
  151. }}
  152. </Feature>
  153. )}
  154. {this.isGettingStarted &&
  155. !!organization?.features.includes('onboarding-heartbeat-footer') ? (
  156. <HeartbeatFooter
  157. projectSlug={projectId}
  158. route={this.props.route}
  159. router={this.props.router}
  160. location={this.props.location}
  161. />
  162. ) : (
  163. <Projects
  164. key={`${organization.slug}-${projectId}`}
  165. orgId={organization.slug}
  166. slugs={[projectId]}
  167. passthroughPlaceholderProject={false}
  168. >
  169. {({projects, initiallyLoaded, fetching, fetchError}) => {
  170. const projectsLoading = !initiallyLoaded && fetching;
  171. const projectFilter =
  172. !projectsLoading && !fetchError && projects.length
  173. ? {
  174. project: (projects[0] as Project).id,
  175. }
  176. : {};
  177. return (
  178. <StyledButtonBar gap={1}>
  179. <Button
  180. priority="primary"
  181. busy={projectsLoading}
  182. to={{
  183. pathname: issueStreamLink,
  184. query: projectFilter,
  185. hash: '#welcome',
  186. }}
  187. >
  188. {t('Take me to Issues')}
  189. </Button>
  190. <Button
  191. busy={projectsLoading}
  192. to={{
  193. pathname: performanceOverviewLink,
  194. query: projectFilter,
  195. }}
  196. >
  197. {t('Take me to Performance')}
  198. </Button>
  199. </StyledButtonBar>
  200. );
  201. }}
  202. </Projects>
  203. )}
  204. </div>
  205. </Fragment>
  206. );
  207. }
  208. }
  209. const DocumentationWrapper = styled('div')`
  210. line-height: 1.5;
  211. .gatsby-highlight {
  212. margin-bottom: ${space(3)};
  213. &:last-child {
  214. margin-bottom: 0;
  215. }
  216. }
  217. .alert {
  218. margin-bottom: ${space(3)};
  219. border-radius: ${p => p.theme.borderRadius};
  220. }
  221. blockquote {
  222. padding: ${space(1)};
  223. margin-left: 0;
  224. background: ${p => p.theme.alert.info.backgroundLight};
  225. border-left: 2px solid ${p => p.theme.alert.info.border};
  226. }
  227. blockquote > *:last-child {
  228. margin-bottom: 0;
  229. }
  230. `;
  231. const StyledButtonBar = styled(ButtonBar)`
  232. margin-top: ${space(3)};
  233. width: max-content;
  234. @media (max-width: ${p => p.theme.breakpoints.small}) {
  235. width: auto;
  236. grid-row-gap: ${space(1)};
  237. grid-auto-flow: row;
  238. }
  239. `;
  240. const StyledPageHeader = styled('div')`
  241. display: flex;
  242. justify-content: space-between;
  243. margin-bottom: ${space(3)};
  244. h2 {
  245. margin: 0;
  246. }
  247. @media (max-width: ${p => p.theme.breakpoints.small}) {
  248. flex-direction: column;
  249. align-items: flex-start;
  250. h2 {
  251. margin-bottom: ${space(2)};
  252. }
  253. }
  254. `;
  255. const StyledAlert = styled(Alert)`
  256. margin-top: ${space(2)};
  257. `;
  258. export {ProjectInstallPlatform};
  259. export default withApi(withOrganization(ProjectInstallPlatform));