overview.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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={this.redirectToDocs}
  90. showOther={false}
  91. organization={this.props.organization}
  92. />
  93. <p>
  94. {tct(
  95. `For a complete list of client integrations, please see
  96. [docLink:our in-depth documentation].`,
  97. {docLink: <ExternalLink href="https://docs.sentry.io" />}
  98. )}
  99. </p>
  100. </div>
  101. );
  102. }
  103. }
  104. const DsnValue = styled(p => (
  105. <code {...p}>
  106. <AutoSelectText>{p.children}</AutoSelectText>
  107. </code>
  108. ))`
  109. overflow: hidden;
  110. `;
  111. const DsnInfo = styled('div')`
  112. margin-bottom: ${space(3)};
  113. `;
  114. const DsnContainer = styled('div')`
  115. display: grid;
  116. grid-template-columns: max-content 1fr;
  117. gap: ${space(1.5)} ${space(2)};
  118. align-items: center;
  119. margin-bottom: ${space(2)};
  120. `;
  121. export default withOrganization(ProjectInstallOverview);