overview.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import {browserHistory, RouteComponentProps} from 'react-router';
  2. import styled from '@emotion/styled';
  3. import AsyncComponent from 'sentry/components/asyncComponent';
  4. import AutoSelectText from 'sentry/components/autoSelectText';
  5. import {Button} from 'sentry/components/button';
  6. import ExternalLink from 'sentry/components/links/externalLink';
  7. import PlatformPicker from 'sentry/components/platformPicker';
  8. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  9. import {PlatformKey} from 'sentry/data/platformCategories';
  10. import {t, tct} from 'sentry/locale';
  11. import {space} from 'sentry/styles/space';
  12. import {Organization} from 'sentry/types';
  13. import recreateRoute from 'sentry/utils/recreateRoute';
  14. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  15. import withOrganization from 'sentry/utils/withOrganization';
  16. import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader';
  17. import TextBlock from 'sentry/views/settings/components/text/textBlock';
  18. import {ProjectKey} from 'sentry/views/settings/project/projectKeys/types';
  19. type Props = RouteComponentProps<{projectId: string}, {}> & {
  20. organization: Organization;
  21. } & AsyncComponent['props'];
  22. type State = {
  23. keyList: Array<ProjectKey> | null;
  24. } & AsyncComponent['state'];
  25. class ProjectInstallOverview extends AsyncComponent<Props, State> {
  26. get isGettingStarted() {
  27. return window.location.href.indexOf('getting-started') > 0;
  28. }
  29. getEndpoints(): ReturnType<AsyncComponent['getEndpoints']> {
  30. const {organization} = this.props;
  31. const {projectId} = this.props.params;
  32. return [['keyList', `/projects/${organization.slug}/${projectId}/keys/`]];
  33. }
  34. redirectToDocs = (platform: PlatformKey | null) => {
  35. const {organization} = this.props;
  36. const {projectId} = this.props.params;
  37. const installUrl = this.isGettingStarted
  38. ? `/organizations/${organization.slug}/projects/${projectId}/getting-started/${platform}/`
  39. : recreateRoute(`${platform}/`, {
  40. ...this.props,
  41. stepBack: -1,
  42. });
  43. browserHistory.push(normalizeUrl(installUrl));
  44. };
  45. toggleDsn = () => {
  46. this.setState(state => ({showDsn: !state.showDsn}));
  47. };
  48. render() {
  49. const {organization} = this.props;
  50. const {projectId} = this.props.params;
  51. const {keyList, showDsn} = this.state;
  52. const issueStreamLink = `/organizations/${organization.slug}/issues/#welcome`;
  53. return (
  54. <div>
  55. <SentryDocumentTitle title={t('Instrumentation')} projectSlug={projectId} />
  56. <SettingsPageHeader title={t('Configure your application')} />
  57. <TextBlock>
  58. {t(
  59. 'Get started by selecting the platform or language that powers your application.'
  60. )}
  61. </TextBlock>
  62. {showDsn ? (
  63. <DsnInfo>
  64. <DsnContainer>
  65. <strong>{t('DSN')}</strong>
  66. <DsnValue>{keyList?.[0].dsn.public}</DsnValue>
  67. </DsnContainer>
  68. <Button priority="primary" to={issueStreamLink}>
  69. {t('Got it! Take me to the Issue Stream.')}
  70. </Button>
  71. </DsnInfo>
  72. ) : (
  73. <p>
  74. <small>
  75. {tct('Already have things setup? [link:Get your DSN]', {
  76. link: (
  77. <Button
  78. priority="link"
  79. onClick={this.toggleDsn}
  80. aria-label={t('Get your DSN')}
  81. />
  82. ),
  83. })}
  84. .
  85. </small>
  86. </p>
  87. )}
  88. <PlatformPicker
  89. setPlatform={selectedPlatform =>
  90. this.redirectToDocs(selectedPlatform?.id ?? null)
  91. }
  92. showOther={false}
  93. organization={this.props.organization}
  94. />
  95. <p>
  96. {tct(
  97. `For a complete list of client integrations, please see
  98. [docLink:our in-depth documentation].`,
  99. {docLink: <ExternalLink href="https://docs.sentry.io" />}
  100. )}
  101. </p>
  102. </div>
  103. );
  104. }
  105. }
  106. const DsnValue = styled(p => (
  107. <code {...p}>
  108. <AutoSelectText>{p.children}</AutoSelectText>
  109. </code>
  110. ))`
  111. overflow: hidden;
  112. `;
  113. const DsnInfo = styled('div')`
  114. margin-bottom: ${space(3)};
  115. `;
  116. const DsnContainer = styled('div')`
  117. display: grid;
  118. grid-template-columns: max-content 1fr;
  119. gap: ${space(1.5)} ${space(2)};
  120. align-items: center;
  121. margin-bottom: ${space(2)};
  122. `;
  123. export default withOrganization(ProjectInstallOverview);